51+ results for 'bech32m' (0 ms)

Not the results you expected?

bech32.cpp (https://github.com/soitun/bitcoin.git) C++ · 43 lines

32 if (input.size() + 3 + 6 <= 90) {

33 // If it's possible to encode input in Bech32(m) without exceeding the 90-character limit:

34 for (auto encoding : {bech32::Encoding::BECH32, bech32::Encoding::BECH32M}) {

35 const std::string encoded = bech32::Encode(encoding, "bc", input);

36 assert(!encoded.empty());

bitcoin-networks.js (https://gitlab.com/YukiteruAmano/simulador-criptografico) JavaScript · 169 lines

157 const words = bitcoin.bech32.toWords(taprootPubkey);

158 words.unshift(1);

159 return bitcoin.bech32m.encode(network.bech32, words);

160 }

161

outputtype.h (https://github.com/soitun/bitcoin.git) C Header · 53 lines

19 P2SH_SEGWIT,

20 BECH32,

21 BECH32M,

22 };

23

26 OutputType::P2SH_SEGWIT,

27 OutputType::BECH32,

28 OutputType::BECH32M,

29 };

30

browserify.js (https://gitlab.com/YukiteruAmano/simulador-criptografico) JavaScript · 47 lines

26 wif: require('wif'),

27 bech32: require('bech32').bech32,

28 bech32m: require('bech32').bech32m,

29 bip32: require('bip32'),

30 bip38: require('bip38'),

bech32.h (https://github.com/soitun/bitcoin.git) C Header · 53 lines

4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.

5

6 // Bech32 and Bech32m are string encoding formats used in newer

7 // address types. The outputs consist of a human-readable part

8 // (alphanumeric), a separator character (1), and a base32 data

26

27 BECH32, //!< Bech32 encoding as defined in BIP173

28 BECH32M, //!< Bech32m encoding as defined in BIP350

29 };

30

31 /** Encode a Bech32 or Bech32m string. If hrp contains uppercase characters, this will cause an

32 * assertion error. Encoding must be one of BECH32 or BECH32M. */

43 };

44

45 /** Decode a Bech32 or Bech32m string. */

46 DecodeResult Decode(const std::string& str);

47

address.js (git://github.com/bitcoinjs/bitcoinjs-lib.git) JavaScript · 140 lines

51 if (version !== 0) throw new TypeError(address + ' uses wrong encoding');

52 } else {

53 result = bech32_1.bech32m.decode(address);

54 version = result.words[0];

55 if (version === 0) throw new TypeError(address + ' uses wrong encoding');

76 return version === 0

77 ? bech32_1.bech32.encode(prefix, words)

78 : bech32_1.bech32m.encode(prefix, words);

79 }

80 exports.toBech32 = toBech32;

outputtype.cpp (https://github.com/soitun/bitcoin.git) C++ · 123 lines

20 static const std::string OUTPUT_TYPE_STRING_P2SH_SEGWIT = "p2sh-segwit";

21 static const std::string OUTPUT_TYPE_STRING_BECH32 = "bech32";

22 static const std::string OUTPUT_TYPE_STRING_BECH32M = "bech32m";

23

24 std::optional<OutputType> ParseOutputType(const std::string& type)

42 case OutputType::P2SH_SEGWIT: return OUTPUT_TYPE_STRING_P2SH_SEGWIT;

43 case OutputType::BECH32: return OUTPUT_TYPE_STRING_BECH32;

44 case OutputType::BECH32M: return OUTPUT_TYPE_STRING_BECH32M;

45 } // no default case, so the compiler can warn about missing cases

46 assert(false);

62 }

63 }

64 case OutputType::BECH32M: {} // This function should never be used with BECH32M, so let it assert

65 } // no default case, so the compiler can warn about missing cases

66 assert(false);

rpc_invalid_address_message.py (https://github.com/syscoin/syscoin.git) Python · 94 lines

14 BECH32_VALID = 'bcrt1qtmp74ayg7p24uslctssvjm06q5phz4yrxucgnv'

15 BECH32_INVALID_BECH32 = 'bcrt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqdmchcc'

16 BECH32_INVALID_BECH32M = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7k35mrzd'

17 BECH32_INVALID_VERSION = 'bcrt130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqynjegk'

18 BECH32_INVALID_SIZE = 'bcrt1s0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav25430mtr'

47 info = node.validateaddress(BECH32_INVALID_BECH32)

48 assert not info['isvalid']

49 assert_equal(info['error'], 'Version 1+ witness address must use Bech32m checksum')

50

51 info = node.validateaddress(BECH32_INVALID_BECH32M)

hd-wallet.js (https://gitlab.com/YukiteruAmano/simulador-criptografico) JavaScript · 167 lines

52 {id: 2, label: 'BIP49 (SegWit P2SH-P2WPKH)', bip: '49', hasCoinType: true, path: 'm/49\'/coin\'/account\'/change/index'},

53 {id: 3, label: 'BIP84 (Native SegWit bech32 P2WPKH)', bip: '84', hasCoinType: true, path: 'm/84\'/coin\'/account\'/change/index'},

54 {id: 4, label: 'BIP86 (Native SegWit v1 bech32m P2TR)', bip: '86', hasCoinType: true, path: 'm/86\'/coin\'/account\'/change/index'},

55 ];

56 vm.selectedBip = vm.bips[1];

key_io.cpp (https://github.com/vertcoin-project/vertcoin-core.git) C++ · 234 lines

64 data.reserve(1 + (id.length * 8 + 4) / 5);

65 ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, id.program, id.program + id.length);

66 return bech32::Encode(bech32::Encoding::BECH32M, m_params.Bech32HRP(), data);

67 }

68

93 data.clear();

94 const auto dec = bech32::Decode(str);

95 if ((dec.encoding == bech32::Encoding::BECH32 || dec.encoding == bech32::Encoding::BECH32M) && dec.data.size() > 0 && dec.hrp == params.Bech32HRP()) {

96 // Bech32 decoding

97 int version = dec.data[0]; // The first 5 bit symbol is the witness version (0-16)

99 return CNoDestination();

100 }

101 if (version != 0 && dec.encoding != bech32::Encoding::BECH32M) {

102 return CNoDestination();

103 }

error.rs (https://github.com/CodeChain-io/codechain.git) Rust · 95 lines

32 InvalidAddress,

33 FailedKeyGeneration,

34 Bech32MissingSeparator,

35 Bech32InvalidChecksum,

36 Bech32InvalidLength,

37 Bech32InvalidChar(u8),

38 Bech32InvalidData(u8),

39 Bech32MixedCase,

40 Bech32UnknownHRP,

41 Custom(String),

57 Error::InvalidAddress => "Invalid Address".into(),

58 Error::FailedKeyGeneration => "Key generation failed".into(),

59 Error::Bech32MissingSeparator => "Missing human-readable separator".into(),

60 Error::Bech32InvalidChecksum => "Invalid checksum".into(),

61 Error::Bech32InvalidLength => "Invalid Length".into(),

address.ts (git://github.com/bitcoinjs/bitcoinjs-lib.git) TypeScript · 175 lines

4 import * as bscript from './script';

5 import * as types from './types';

6 import { bech32, bech32m } from 'bech32';

7 import * as bs58check from 'bs58check';

8 const { typeforce } = types;

72 if (version !== 0) throw new TypeError(address + ' uses wrong encoding');

73 } else {

74 result = bech32m.decode(address);

75 version = result.words[0];

76 if (version === 0) throw new TypeError(address + ' uses wrong encoding');

106 return version === 0

107 ? bech32.encode(prefix, words)

108 : bech32m.encode(prefix, words);

109 }

110

segwit_addr.py (https://github.com/sipa/bech32.git) Python · 137 lines

19 # THE SOFTWARE.

20

21 """Reference implementation for Bech32/Bech32m and segwit addresses."""

22

23

27 """Enumeration type to list the various supported encodings."""

28 BECH32 = 1

29 BECH32M = 2

30

31 CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"

61 """Compute the checksum values given HRP and data."""

62 values = bech32_hrp_expand(hrp) + data

63 const = BECH32M_CONST if spec == Encoding.BECH32M else 1

64 polymod = bech32_polymod(values + [0, 0, 0, 0, 0, 0]) ^ const

65 return [(polymod >> 5 * (5 - i)) & 31 for i in range(6)]

00-bech32m.md (https://github.com/bitcoinops/bitcoinops.github.io.git) Markdown · 36 lines

9 user-provided addresses needs to be able to send to taproot addresses by

10 block {{site.trb}} or risk confusing and disappointing its users. Pay

11 to TapRoot (P2TR) addresses use [bech32m][topic bech32] as specified in [BIP350][], which

12 is slightly different than [BIP173][]'s bech32 algorithm used for segwit

13 v0 P2WPKH and P2WSH addresses. Bech32m uses the constant

15

16 Changing that single constant provides the

17 ability to verify bech32m checksums, but the code still needs to use the original constant for existing

18 P2WPKH and P2WSH addresses. The code needs to decode the address

19 without verifying the checksum, determine whether it uses v0 segwit (bech32) or

20 v1+ segwit (bech32m), and then validate the checksum with the appropriate

21 constant. For examples, see the [PR][bech32#56] that updated the bech32

22 reference implementations for C, C++, JS, and Python. If the code already

bech32_tests.cpp (https://github.com/syscoin/syscoin.git) C++ · 101 lines

31 }

32

33 BOOST_AUTO_TEST_CASE(bech32m_testvectors_valid)

34 {

35 static const std::string CASES[] = {

44 for (const std::string& str : CASES) {

45 const auto dec = bech32::Decode(str);

46 BOOST_CHECK(dec.encoding == bech32::Encoding::BECH32M);

47 std::string recode = bech32::Encode(bech32::Encoding::BECH32M, dec.hrp, dec.data);

75 }

76

77 BOOST_AUTO_TEST_CASE(bech32m_testvectors_invalid)

78 {

79 static const std::string CASES[] = {

segwit_addr.py (https://github.com/bitcoinops/taproot-workshop.git) Python · 124 lines

3 # Distributed under the MIT software license, see the accompanying

4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.

5 """Reference implementation for Bech32/Bech32m and segwit addresses."""

6 from enum import Enum

7

8 CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"

9 BECH32_CONST = 1

10 BECH32M_CONST = 0x2bc830a3

11

12 class Encoding(Enum):

46 """Compute the checksum values given HRP and data."""

47 values = bech32_hrp_expand(hrp) + data

48 const = BECH32M_CONST if encoding == Encoding.BECH32M else BECH32_CONST

49 polymod = bech32_polymod(values + [0, 0, 0, 0, 0, 0]) ^ const

50 return [(polymod >> 5 * (5 - i)) & 31 for i in range(6)]

config.go (https://github.com/mesg-foundation/core.git) Go · 50 lines

7

8 const (

9 // CosmosBech32MainPrefix defines the main Bech32 prefix.

10 CosmosBech32MainPrefix = "mesg"

28 const (

29 // bech32PrefixAccAddr defines the Bech32 prefix of an account's address

30 bech32PrefixAccAddr = CosmosBech32MainPrefix

31 // bech32PrefixAccPub defines the Bech32 prefix of an account's public key

32 bech32PrefixAccPub = CosmosBech32MainPrefix + sdktypes.PrefixPublic

33 // bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address

34 bech32PrefixValAddr = CosmosBech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixOperator

35 // bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key

36 bech32PrefixValPub = CosmosBech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixOperator + sdktypes.PrefixPublic

37 // bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address

38 bech32PrefixConsAddr = CosmosBech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixConsensus

39 // bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key

40 bech32PrefixConsPub = CosmosBech32MainPrefix + sdktypes.PrefixValidator + sdktypes.PrefixConsensus + sdktypes.PrefixPublic

sdkconfig.go (https://github.com/lino-network/lino.git) Go · 50 lines

7 const (

8 // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address

9 Bech32MainPrefix = "lino"

10

11 // LINO is missing in https://github.com/satoshilabs/slips/blob/master/slip-0044.md

28

29 // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address

30 Bech32PrefixAccAddr = Bech32MainPrefix

31 // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key

32 Bech32PrefixAccPub = Bech32MainPrefix + PrefixPublic

33 // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address

34 Bech32PrefixValAddr = Bech32MainPrefix + PrefixValidator + PrefixOperator

35 // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key

36 Bech32PrefixValPub = Bech32MainPrefix + PrefixValidator + PrefixOperator + PrefixPublic

bech32_v2.x.x.js (https://github.com/Emurgo/yoroi-frontend.git) JavaScript · 21 lines

6 declare module "bech32" {

7 declare export var bech32: BechLib;

8 declare export var bech32m: BechLib;

9 declare export interface Decoded {

10 prefix: string;

2021-06-23-preparing-for-taproot.md (https://github.com/bitcoinops/bitcoinops.github.io.git) Markdown · 149 lines

26 {:toc}

27

28 ## bech32m送信のサポート

29

30 *[ニュースレター #154](/ja/newsletters/2021/06/23/#taprootの準備-1-bech32m送信のサポート)に掲載*

31

32 {% include specials/taproot/ja/00-bech32m.md %}

33

34 ## Taprootはシングルシグでも価値があるか?

segwit_addr.rb (https://github.com/sipa/bech32.git) Ruby · 86 lines

43

44 def addr

45 spec = (ver == 0 ? Bech32::Encoding::BECH32 : Bech32::Encoding::BECH32M)

46 Bech32.encode(hrp, [ver] + convert_bits(prog, 8, 5), spec)

47 end

57 raise 'Invalid witness program' if prog.nil? || prog.length < 2 || prog.length > 40

58 raise 'Invalid witness program with version 0' if ver == 0 && (prog.length != 20 && prog.length != 32)

59 raise 'Witness version and encoding spec do not match' if (ver == 0 && spec != Bech32::Encoding::BECH32) || (ver != 0 && spec != Bech32::Encoding::BECH32M)

60 [hrp, ver, prog]

61 end

README.md (https://github.com/sipa/bech32.git) Markdown · 67 lines

23 [0, 14, 20, 15, 7, 13, 26, 0, 25, 18, 6, 11, 13, 8, 21, 4, 20, 3, 17, 2, 29, 3, 12, 29, 3, 4, 15, 24, 20, 6, 14, 30, 22]

24

25 # spec is whether Bech32::Encoding::BECH32 or Bech32::Encoding::BECH32M

26 ```

27

segwit_addr.cpp (https://github.com/sipa/bech32.git) C++ · 86 lines

68 conv.size() < 2 || conv.size() > 40 || witver > 16 || (witver == 0 &&

69 conv.size() != 20 && conv.size() != 32) || (witver == 0 && dec.encoding !=

70 bech32::Encoding::BECH32) || (witver != 0 && dec.encoding != bech32::Encoding::BECH32M)) {

71 return std::make_pair(-1, data());

72 }

79 enc.push_back(witver);

80 convertbits<8, 5, true>(enc, witprog);

81 std::string ret = bech32::encode(hrp, enc, witver > 0 ? bech32::Encoding::BECH32M : bech32::Encoding::BECH32);

82 if (decode(hrp, ret).first == -1) return "";

83 return ret;

Bech32mSpec.scala (https://github.com/bitcoin-s/bitcoin-s-core.git) Scala · 82 lines

9 import scala.util.{Random, Success}

10

11 class Bech32mSpec extends Properties("Bech32mSpec") {

12

13 property("split all Bech32m addresses into HRP and data") = {

14 Prop.forAll(AddressGenerator.bech32mAddress) { address =>

15 val splitT =

16 Bech32.splitToHrpAndData(address.value, Bech32Encoding.Bech32m)

24 ChainParamsGenerator.networkParams) {

25 case ((witSPK, _), network) =>

26 val addr = Bech32mAddress(witSPK, network)

27 val spk = Bech32mAddress.fromStringToWitSPK(addr.value)

31

32 property("checksum must not work if we modify a char") = {

33 Prop.forAll(AddressGenerator.bech32mAddress) { addr: Bech32mAddress =>

34 val old = addr.value

35 val rand = Math.abs(Random.nextInt())

Bech32.scala (https://github.com/ACINQ/bitcoin-lib.git) Scala · 203 lines

4

5 /**

6 * Bech32 and Bech32m address formats.

7 * See https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki and https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki.

8 */

13 sealed trait Encoding

14 case object Bech32Encoding extends Encoding

15 case object Bech32mEncoding extends Encoding

16 // @formatter:on

17

197 if (version == 0) require(encoding == Bech32Encoding, "version 0 must be encoded with Bech32")

198 if (version == 0) require(bin.length == 20 || bin.length == 32, s"invalid witness program length ${bin.length}")

199 if (version != 0) require(encoding == Bech32mEncoding, "version 1 to 16 must be encoded with Bech32m")

200 (hrp, version, ByteVector.view(bin))

201 }

add_witness.rs (https://github.com/input-output-hk/jormungandr.git) Rust · 66 lines

40

41 let (hrp, data) = bech32::decode(bech32_str.trim()).map_err(|source| {

42 Error::WitnessFileBech32Malformed {

43 source,

44 path: self.witness.clone(),

53 }

54 let bytes =

55 Vec::from_base32(&data).map_err(|source| Error::WitnessFileBech32Malformed {

56 source,

57 path: self.witness.clone(),

serde.rs (https://github.com/input-output-hk/jormungandr.git) Rust · 315 lines

177 expected, actual

178 ))),

179 Err(Bech32Error::Bech32Malformed(err)) => {

180 Err(E::custom(format!("Invalid bech32: {}", err)))

181 }

222 expected, actual

223 ))),

224 Err(Bech32Error::Bech32Malformed(err)) => {

225 Err(E::custom(format!("Invalid bech32: {}", err)))

226 }

270 expected, actual

271 ))),

272 Err(Bech32Error::Bech32Malformed(err)) => {

273 Err(E::custom(format!("Invalid bech32: {}", err)))

274 }

2021-06-23-preparing-for-taproot.md (https://github.com/bitcoinops/bitcoinops.github.io.git) Markdown · 150 lines

27 {:toc}

28

29 ## Bech32m sending support

30

31 *Originally published in [Newsletter #154](/en/newsletters/2021/06/23/#preparing-for-taproot-1-bech32m-sending-support)*

32

33 {% include specials/taproot/00-bech32m.md %}

34

35 ## Is taproot even worth it for single-sig?

00-bech32m.md (https://github.com/bitcoinops/bitcoinops.github.io.git) Markdown · 30 lines

9 Pay to TapRoot (P2TR)アドレスは、[BIP350][]で定義されている[bech32m][topic bech32]を使用すます。

10 これはsegwitのv0 P2WPKHおよびP2WSHアドレスに使用されている[BIP173][]のbech32アルゴリズムと少し異なります。

11 bech32mは、チェックサム関数でbech32の`0x01`に代わって、`0x2bc830a3`を使用します。

12

13 この1つの定数を変更することで、bech32mのチェックサムを検証できますが、

19 コードが既に参照ライブラリを使用している場合は、リポジトリから最新のコードに更新することができますが、

20 APIの一部がわずかに変更されていることに注意してください。

21 BIP350と参照実装は、すべてのbech32m実装が使用すべきtest vectorを提供しています。

22

23 Taprootアドレスへの支払いの受け取りは、ブロック{{site.trb}}まで安全ではありませんが、

26 Taprootへの支払いアウトプットを持つトランザクションのリレーや、マイニングをサポートしています。

27 Optechは、ウォレットやサービスの開発者に対して、Taprootがアクティベートされるまで待つことなく、

28 今すぐにbech32mのTaprootアドレスへの支払いのサポートを実装することを推奨しています。

29

30 [bech32#56]: https://github.com/sipa/bech32/pull/56

segwit_addr.js (https://github.com/sipa/bech32.git) JavaScript · 91 lines

54

55 function decode (hrp, addr) {

56 var bech32m = false;

57 var dec = bech32.decode(addr, bech32.encodings.BECH32);

58 if (dec === null) {

59 dec = bech32.decode(addr, bech32.encodings.BECH32M);

60 bech32m = true;

70 return null;

71 }

72 if (dec.data[0] === 0 && bech32m) {

73 return null;

74 }

75 if (dec.data[0] !== 0 && !bech32m) {

76 return null;

77 }

stargate-final.js (https://github.com/cosmostation/cosmosjs.git) JavaScript · 57 lines

10

11 const cosmos = new Cosmos(lcdUrl, chainId);

12 cosmos.setBech32MainPrefix("cosmos");

13 cosmos.setPath("m/44'/118'/0'/0/0");

14 const address = cosmos.getAddress(mnemonic);

cosmoshub.js (https://github.com/cosmostation/cosmosjs.git) JavaScript · 49 lines

8 // (https://hub.cosmos.network/main/gaia-tutorials/join-mainnet.html#enable-the-rest-api)

9 const cosmos = new Cosmos("https://api.cosmos.network", chainId);

10 cosmos.setBech32MainPrefix("cosmos");

11 cosmos.setPath("m/44'/118'/0'/0/0");

12 const address = cosmos.getAddress(mnemonic);

exchange.ts (https://github.com/LedgerHQ/ledger-live-common.git) TypeScript · 41 lines

8 bech32: 2,

9 bitcoin_cash: 3,

10 bech32m: 4,

11 };

12

address.go (https://github.com/maticnetwork/cosmos-sdk.git) Go · 730 lines

33 AddrLen = 20

34 // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address

35 Bech32MainPrefix = "cosmos"

36

37 // Atom in https://github.com/satoshilabs/slips/blob/master/slip-0044.md

57

58 // Bech32PrefixAccAddr defines the Bech32 prefix of an account's address

59 Bech32PrefixAccAddr = Bech32MainPrefix

60 // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key

61 Bech32PrefixAccPub = Bech32MainPrefix + PrefixPublic

62 // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address

63 Bech32PrefixValAddr = Bech32MainPrefix + PrefixValidator + PrefixOperator

64 // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key

65 Bech32PrefixValPub = Bech32MainPrefix + PrefixValidator + PrefixOperator + PrefixPublic

params.go (https://github.com/Kava-Labs/kava.git) Go · 223 lines

12

13 const (

14 bech32MainPrefix = "kava"

15 )

16

AddressGenerator.scala (https://github.com/bitcoin-s/bitcoin-s-core.git) Scala · 45 lines

30 } yield addr

31

32 def bech32mAddress: Gen[Bech32mAddress] =

33 for {

34 (witSPK, _) <- ScriptGenerators.witnessScriptPubKey.suchThat(

35 _._1.witnessVersion != WitnessVersion0)

36 network <- ChainParamsGenerator.networkParams

37 } yield Bech32mAddress(witSPK, network)

38

39 def bitcoinAddress: Gen[BitcoinAddress] =

40 Gen.oneOf(p2pkhAddress, p2shAddress, bech32Address, bech32mAddress)

41

42 def address: Gen[Address] = bitcoinAddress

04-why-wait.md (https://github.com/bitcoinops/bitcoinops.github.io.git) Markdown · 80 lines

58 the [BIP341][] and [BIP342][] rules.

59 - {{safe_trb}}: a reasonable block at which wallets can start giving their

60 users [bech32m][topic bech32] receiving addresses for P2TR outputs

61

62 None of the above changes the advice given in the [first part][taproot

63 series 1] of this series to enable paying to bech32m addresses as soon

64 as possible. If someone requests payment to an address for P2TR

65 before you think it's safe, that's their risk to take.

77

78 [news139 st]: /en/newsletters/2021/03/10/#taproot-activation-discussion

79 [taproot series 1]: /en/preparing-for-taproot/#bech32m-sending-support

80 {% endauto_anchor %}

81

rpc_invalid_address_message.py (https://github.com/vertcoin-project/vertcoin-core.git) Python · 84 lines

11 BECH32_VALID = 'bcrt1qtmp74ayg7p24uslctssvjm06q5phz4yrxucgnv'

12 BECH32_INVALID_BECH32 = 'bcrt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqdmchcc'

13 BECH32_INVALID_BECH32M = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7k35mrzd'

14 BECH32_INVALID_VERSION = 'bcrt130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqynjegk'

15 BECH32_INVALID_SIZE = 'bcrt1s0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav25430mtr'

43 assert not info['isvalid']

44

45 info = node.validateaddress(BECH32_INVALID_BECH32M)

46 assert not info['isvalid']

47

getWalletPublicKey.ts (https://github.com/LedgerHQ/ledger-node-js-api.git) TypeScript · 62 lines

9 | "p2sh"

10 | "bech32"

11 | "bech32m"

12 | "cashaddr";

13 const addressFormatMap = {

InvoiceUtilTest.java (https://github.com/LN-Zap/zap-android.git) Java · 56 lines

34 assertTrue(InvoiceUtil.isBitcoinAddress("bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4")); //bech32, mainnet, lower case

35 assertTrue(InvoiceUtil.isBitcoinAddress("bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4".toUpperCase())); //bech32, mainnet, upper case

36 assertTrue(InvoiceUtil.isBitcoinAddress("bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0")); //bech32m, mainnet (example from BIP 350)

37 assertTrue(InvoiceUtil.isBitcoinAddress("tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx")); //bech32, testnet, lower case

38 assertTrue(InvoiceUtil.isBitcoinAddress("bcrt1q6rhpng9evdsfnn833a4f4vej0asu6dk5srld6x")); //bech32, regtest, lower case

bech32.rb (https://github.com/sipa/bech32.git) Ruby · 99 lines

23 module Encoding

24 BECH32 = 1

25 BECH32M = 2

26 end

27

30 CHARSET = %w(q p z r y 9 x 8 g f 2 t v d w 0 s 3 j n 5 4 k h c e 6 m u a 7 l)

31

32 BECH32M_CONST = 0x2bc830a3

33

34 module_function

62 def create_checksum(hrp, data, spec)

63 values = expand_hrp(hrp) + data

64 const = (spec == Bech32::Encoding::BECH32M ? Bech32::BECH32M_CONST : 1)

65 polymod = polymod(values + [0, 0, 0, 0, 0, 0]) ^ const

66 (0..5).map{|i|(polymod >> 5 * (5 - i)) & 31}

bech32.js (https://github.com/sipa/bech32.git) JavaScript · 131 lines

24 const encodings = {

25 BECH32: "bech32",

26 BECH32M: "bech32m",

27 };

28

36 if (enc == encodings.BECH32) {

37 return 1;

38 } else if (enc == encodings.BECH32M) {

39 return 0x2bc830a3;

40 } else {

segwit_addr.h (https://github.com/sipa/bech32.git) C Header · 113 lines

70 BECH32_ENCODING_NONE,

71 BECH32_ENCODING_BECH32,

72 BECH32_ENCODING_BECH32M

73 } bech32_encoding;

74

75 /** Encode a Bech32 or Bech32m string

76 *

77 * Out: output: Pointer to a buffer of size strlen(hrp) + data_len + 8 that

91 );

92

93 /** Decode a Bech32 or Bech32m string

94 *

95 * Out: hrp: Pointer to a buffer of size strlen(input) - 6. Will be

segwit_addr_ecc.js (https://github.com/sipa/bech32.git) JavaScript · 117 lines

68 if (dec.data_pattern.length - 6 - 1 != ((numbytes * 8 + 4) / 5|0)) continue;

69 if (dec.data_pattern[0] == 0 && encoding != bech32_ecc.encodings.BECH32) continue;

70 if (dec.data_pattern[0] > 0 && dec.data_pattern[0] <= 16 && encoding != bech32_ecc.encodings.BECH32M) continue;

71 if (dec.data_pattern[0] > 16) continue;

72 if (dec.data_pattern[0] == 0 && numbytes != 20 && numbytes != 32) continue;

97 return {error:"Bech32 must be used for witness v0 programs", pos:null};

98 }

99 if (dec.data[0] != 0 && encoding != bech32_ecc.encodings.BECH32M) {

100 return {error:"Bech32m must be used for witness v1+ programs", pos:null};

bech32.h (https://github.com/sipa/bech32.git) C Header · 61 lines

36

37 BECH32, //! Bech32 encoding as defined in BIP173

38 BECH32M, //! Bech32m encoding as defined in BIP350

39 };

40

41 /** Encode a Bech32 or Bech32m string. If hrp contains uppercase characters, this will cause an

42 * assertion error. Encoding must be one of BECH32 or BECH32M. */

54 };

55

56 /** Decode a Bech32 or Bech32m string. */

57 DecodeResult decode(const std::string& str);

58

segwit_addr.c (https://github.com/sipa/bech32.git) C · 209 lines

38 static uint32_t bech32_final_constant(bech32_encoding enc) {

39 if (enc == BECH32_ENCODING_BECH32) return 1;

40 if (enc == BECH32_ENCODING_BECH32M) return 0x2bc830a3;

41 assert(0);

42 }

147 if (chk == bech32_final_constant(BECH32_ENCODING_BECH32)) {

148 return BECH32_ENCODING_BECH32;

149 } else if (chk == bech32_final_constant(BECH32_ENCODING_BECH32M)) {

150 return BECH32_ENCODING_BECH32M;

183 if (witver == 0 && witprog_len != 20 && witprog_len != 32) return 0;

184 if (witprog_len < 2 || witprog_len > 40) return 0;

185 if (witver > 0) enc = BECH32_ENCODING_BECH32M;

186 data[0] = witver;

187 convert_bits(data + 1, &datalen, 5, witprog, witprog_len, 8, 1);

200 if (data[0] > 16) return 0;

201 if (data[0] == 0 && enc != BECH32_ENCODING_BECH32) return 0;

202 if (data[0] > 0 && enc != BECH32_ENCODING_BECH32M) return 0;

203 *witdata_len = 0;

204 if (!convert_bits(witdata, witdata_len, 8, data + 1, data_len - 1, 5, 0)) return 0;

key_io.cpp (https://github.com/syscoin/syscoin.git) C++ · 266 lines

63 data.reserve(1 + (id.length * 8 + 4) / 5);

64 ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, id.program, id.program + id.length);

65 return bech32::Encode(bech32::Encoding::BECH32M, m_params.Bech32HRP(), data);

66 }

67

97 data.clear();

98 const auto dec = bech32::Decode(str);

99 if ((dec.encoding == bech32::Encoding::BECH32 || dec.encoding == bech32::Encoding::BECH32M) && dec.data.size() > 0) {

100 // Bech32 decoding

101 error_str = "";

109 return CNoDestination();

110 }

111 if (version != 0 && dec.encoding != bech32::Encoding::BECH32M) {

112 error_str = "Version 1+ witness address must use Bech32m checksum";

address.ts (https://github.com/trezor/trezor-suite.git) TypeScript · 172 lines

4 // - `toBase58Check` method is using additional "network" param and bs58check.encodeAddress instead of bs58check.encode.

5

6 import { bech32, bech32m } from 'bech32';

7 import * as bs58check from './bs58check';

8 import * as typeforce from 'typeforce';

40 if (version !== 0) throw new TypeError(`${address} uses wrong encoding`);

41 } else {

42 result = bech32m.decode(address);

43 [version] = result.words;

44 if (version === 0) throw new TypeError(`${address} uses wrong encoding`);

64 words.unshift(version);

65

66 return version === 0 ? bech32.encode(prefix, words) : bech32m.encode(prefix, words);

67 }

68

rpc_invalid_address_message.py (https://github.com/xaya/xaya.git) Python · 98 lines

14 BECH32_VALID = 'chirt1qtmp74ayg7p24uslctssvjm06q5phz4yrhskhyn'

15 BECH32_INVALID_BECH32 = 'chirt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqg8447y'

16 BECH32_INVALID_BECH32M = 'chirt1qw508d6qejxtdg4y5r3zarvary0c5xw7kqc4u4j'

17 BECH32_INVALID_VERSION = 'chirt130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqp0lmw2'

18 BECH32_INVALID_SIZE = 'chirt1s0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav25r7vjx8'

44 info = node.validateaddress(BECH32_INVALID_BECH32)

45 assert not info['isvalid']

46 assert_equal(info['error'], 'Version 1+ witness address must use Bech32m checksum')

47

48 info = node.validateaddress(BECH32_INVALID_BECH32M)

params_test.go (https://github.com/regen-network/regen-ledger.git) Go · 231 lines

32 genAddrs := make([]string, 0, 3)

33 for i := 0; i < 3; i++ {

34 genAddrs = append(genAddrs, sdk.MustBech32ifyAddressBytes(sdk.Bech32MainPrefix, []byte(fmt.Sprintf("testaddr-%d", i))))

35 }

36

bech32m-browser.js (https://github.com/bcoin-org/bcrypto.git) JavaScript · 10 lines

1 /*!

2 * bech32m.js - bech32m for bcrypto

3 * Copyright (c) 2021, the bcoin developers (MIT License).

4 * https://github.com/bcoin-org/bcrypto