diff --git a/ref/c/tests.c b/ref/c/tests.c index 47b2aba..8942de8 100644 --- a/ref/c/tests.c +++ b/ref/c/tests.c @@ -38,7 +38,7 @@ static struct valid_address_data valid_address[] = { { "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx", 42, { - 0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x51, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6 @@ -47,13 +47,13 @@ static struct valid_address_data valid_address[] = { { "BC1SW50QA3JX3S", 4, { - 0x90, 0x02, 0x75, 0x1e + 0x60, 0x02, 0x75, 0x1e } }, { "bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", 18, { - 0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x52, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23 } }, @@ -81,7 +81,7 @@ static const char* invalid_address[] = { }; static void segwit_scriptpubkey(uint8_t* scriptpubkey, size_t* scriptpubkeylen, int witver, const uint8_t* witprog, size_t witprog_len) { - scriptpubkey[0] = witver ? (0x80 | witver) : 0; + scriptpubkey[0] = witver ? (0x50 + witver) : 0; scriptpubkey[1] = witprog_len; memcpy(scriptpubkey + 2, witprog, witprog_len); *scriptpubkeylen = witprog_len + 2; diff --git a/ref/go/src/bech32/bech32_test.go b/ref/go/src/bech32/bech32_test.go index 4ce22c6..825bfa1 100644 --- a/ref/go/src/bech32/bech32_test.go +++ b/ref/go/src/bech32/bech32_test.go @@ -28,7 +28,7 @@ import ( func segwitScriptpubkey(version int, program []int) []int { if version != 0 { - version += 0x80 + version += 0x50 } return append(append([]int{version}, len(program)), program...) } @@ -63,7 +63,7 @@ var validAddress = []item{ }, item{"bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx", []int{ - 0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x51, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6, @@ -71,12 +71,12 @@ var validAddress = []item{ }, item{"BC1SW50QA3JX3S", []int{ - 0x90, 0x02, 0x75, 0x1e, + 0x60, 0x02, 0x75, 0x1e, }, }, item{"bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", []int{ - 0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x52, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, }, }, diff --git a/ref/haskell/test/Spec.hs b/ref/haskell/test/Spec.hs index 4a588c9..fab65c9 100644 --- a/ref/haskell/test/Spec.hs +++ b/ref/haskell/test/Spec.hs @@ -28,9 +28,9 @@ validAddresses = map mapTuple , ("tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7" ,"00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262") , ("bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx" - ,"8128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6") - , ("BC1SW50QA3JX3S", "9002751e") - , ("bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "8210751e76e8199196d454941c45d1b3a323") + ,"5128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6") + , ("BC1SW50QA3JX3S", "6002751e") + , ("bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "5210751e76e8199196d454941c45d1b3a323") , ("tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy" ,"0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433") ] @@ -56,7 +56,7 @@ hexDecode s = let (ret, rest) = B16.decode s segwitScriptPubkey :: Word8 -> [Word8] -> BS.ByteString segwitScriptPubkey witver witprog = BS.pack $ witver' : (fromIntegral $ length witprog) : witprog - where witver' = if witver == 0 then 0 else witver + 0x80 + where witver' = if witver == 0 then 0 else witver + 0x50 tests :: TestTree tests = testGroup "Tests" diff --git a/ref/javascript/tests.js b/ref/javascript/tests.js index b2e3cee..9b77fbe 100644 --- a/ref/javascript/tests.js +++ b/ref/javascript/tests.js @@ -22,7 +22,7 @@ var segwit_addr = require('./segwit_addr.js'); var bech32 = require('./bech32'); function segwit_scriptpubkey(version, program) { - return [version ? version + 0x80 : 0, program.length].concat(program); + return [version ? version + 0x50 : 0, program.length].concat(program); } var VALID_CHECKSUM = [ @@ -53,7 +53,7 @@ var VALID_ADDRESS = [ [ "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx", [ - 0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x51, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6 @@ -62,13 +62,13 @@ var VALID_ADDRESS = [ [ "BC1SW50QA3JX3S", [ - 0x90, 0x02, 0x75, 0x1e + 0x60, 0x02, 0x75, 0x1e ] ], [ "bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", [ - 0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x52, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23 ] ], diff --git a/ref/python/tests.py b/ref/python/tests.py index cf9cfb3..96dc8d0 100755 --- a/ref/python/tests.py +++ b/ref/python/tests.py @@ -29,7 +29,7 @@ def segwit_scriptpubkey(witver, witprog): """Construct a Segwit scriptPubKey for a given witness program.""" - return bytes([witver + 0x80 if witver else 0, len(witprog)] + witprog) + return bytes([witver + 0x50 if witver else 0, len(witprog)] + witprog) VALID_CHECKSUM = [ "A12UEL5L", @@ -44,9 +44,9 @@ def segwit_scriptpubkey(witver, witprog): ["tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7", "00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262"], ["bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx", - "8128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6"], - ["BC1SW50QA3JX3S", "9002751e"], - ["bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "8210751e76e8199196d454941c45d1b3a323"], + "5128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6"], + ["BC1SW50QA3JX3S", "6002751e"], + ["bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "5210751e76e8199196d454941c45d1b3a323"], ["tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy", "0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433"], ] diff --git a/ref/ruby/segwit_addr.rb b/ref/ruby/segwit_addr.rb index 32d3f8b..2cdfeda 100644 --- a/ref/ruby/segwit_addr.rb +++ b/ref/ruby/segwit_addr.rb @@ -31,7 +31,7 @@ def initialize(addr = nil) end def to_scriptpubkey - v = ver == 0 ? ver : ver + 0x80 + v = ver == 0 ? ver : ver + 0x50 ([v, prog.length].pack("CC") + prog.map{|p|[p].pack("C")}.join).unpack('H*').first end diff --git a/ref/ruby/test_bech32.rb b/ref/ruby/test_bech32.rb index 894a299..19d643a 100644 --- a/ref/ruby/test_bech32.rb +++ b/ref/ruby/test_bech32.rb @@ -37,9 +37,9 @@ class TestBech32 < Test::Unit::TestCase ["tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7", "00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262"], ["bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx", - "8128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6"], - ["BC1SW50QA3JX3S", "9002751e"], - ["bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "8210751e76e8199196d454941c45d1b3a323"], + "5128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6"], + ["BC1SW50QA3JX3S", "6002751e"], + ["bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "5210751e76e8199196d454941c45d1b3a323"], ["tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy", "0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433"], ] diff --git a/ref/rust/src/lib.rs b/ref/rust/src/lib.rs index 9bc1c42..3e61622 100644 --- a/ref/rust/src/lib.rs +++ b/ref/rust/src/lib.rs @@ -170,7 +170,7 @@ mod tests { ( "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx", vec![ - 0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x51, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6 @@ -179,13 +179,13 @@ mod tests { ( "BC1SW50QA3JX3S", vec![ - 0x90, 0x02, 0x75, 0x1e + 0x60, 0x02, 0x75, 0x1e ] ), ( "bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", vec![ - 0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x52, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23 ] ), diff --git a/ref/rust/src/wit_prog.rs b/ref/rust/src/wit_prog.rs index 0d560bc..f3258f6 100644 --- a/ref/rust/src/wit_prog.rs +++ b/ref/rust/src/wit_prog.rs @@ -130,7 +130,7 @@ impl WitnessProgram { let mut pubkey: Vec = Vec::new(); let mut v = self.version; if v > 0 { - v += 0x80; + v += 0x50; } pubkey.push(v); pubkey.push(self.program.len() as u8); @@ -152,8 +152,8 @@ impl WitnessProgram { } // Process script version let mut v: u8 = pubkey[0]; - if v > 0x80 { - v -= 0x80; + if v > 0x50 { + v -= 0x50; } let program = &pubkey[2..]; Ok(WitnessProgram {