def test_testnet(self): # bitcoin core derivation style rootxprv = b'tprv8ZgxMBicQKsPe3g3HwF9xxTLiyc5tNyEtjhBBAk29YA3MTQUqULrmg7aj9qTKNfieuu2HryQ6tGVHse9x7ANFGs3f4HgypMc5nSSoxwf7TK' # m/0'/0'/51' addr1 = b'mfXYCCsvWPgeCv8ZYGqcubpNLYy5nYHbbj' indexes = [0x80000000, 0x80000000, 0x80000000 + 51] addr = bip32.p2pkh_address_from_xpub( bip32.xpub_from_xprv(bip32.derive(rootxprv, indexes))) self.assertEqual(addr, addr1) path = "m/0'/0'/51'" addr = bip32.p2pkh_address_from_xpub( bip32.xpub_from_xprv(bip32.derive(rootxprv, path))) self.assertEqual(addr, addr1) # m/0'/1'/150' addr2 = b'mfaUnRFxVvf55uD1P3zWXpprN1EJcKcGrb' indexes = [0x80000000, 0x80000000 + 1, 0x80000000 + 150] addr = bip32.p2pkh_address_from_xpub( bip32.xpub_from_xprv(bip32.derive(rootxprv, indexes))) self.assertEqual(addr, addr2) path = "m/0'/1'/150'" addr = bip32.p2pkh_address_from_xpub( bip32.xpub_from_xprv(bip32.derive(rootxprv, path))) self.assertEqual(addr, addr2)
def test_altnet(self): # non-bitcoin address version addr_version = 0x46.to_bytes(1, 'big') rootxprv = b'xprv9s21ZrQH143K2oxHiQ5f7D7WYgXD9h6HAXDBuMoozDGGiYHWsq7TLBj2yvGuHTLSPCaFmUyN1v3fJRiY2A4YuNSrqQMPVLZKt76goL6LP7L' # m/0'/0'/5' receive = b'VUqyLGVdUADWEqDqL2DeUBAcbPQwZfWDDY' indexes = [0x80000000, 0x80000000, 0x80000005] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv( bip32.derive(rootxprv, indexes)), addr_version) self.assertEqual(addr, receive) path = "m/0'/0'/5'" addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv( bip32.derive(rootxprv, path)), addr_version) self.assertEqual(addr, receive) # m/0'/1'/1' change = b'VMg6DpX7SQUsoECdpXJ8Bv6R7p11PfwHwy' indexes = [0x80000000, 0x80000001, 0x80000001] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv( bip32.derive(rootxprv, indexes)), addr_version) self.assertEqual(addr, change) path = "m/0'/1'/1'" addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv( bip32.derive(rootxprv, path)), addr_version) self.assertEqual(addr, change) xkey_version = bip32.PRV_VERSION[0] seed = "5b56c417303faa3fcba7e57400e120a0ca83ec5a4fc9ffba757fbe63fbd77a89a1a3be4c67196f57c39a88b76373733891bfaba16ed27a813ceed498804c0570" rootxprv = bip32.rootxprv_from_seed(seed, xkey_version) self.assertEqual(rootxprv, b'xprv9s21ZrQH143K3t4UZrNgeA3w861fwjYLaGwmPtQyPMmzshV2owVpfBSd2Q7YsHZ9j6i6ddYjb5PLtUdMZn8LhvuCVhGcQntq5rn7JVMqnie') indexes = [0x80000000, 0, 0] # receive addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv( bip32.derive(rootxprv, indexes)), addr_version) self.assertEqual(addr, b'VTpEhLjvGYE16pLcNrMY53gQB9bbhn581W') indexes = [0x80000000, 1, 0] # change addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv( bip32.derive(rootxprv, indexes)), addr_version) self.assertEqual(addr, b'VRtaZvAe4s29aB3vuXyq7GYEpahsQet2B1')
def test_versions(self): # data cross-checked with Electrum and https://jlopp.github.io/xpub-converter/ # 128 bits raw_entr = bytes.fromhex('6'*32) # 12 words mnemonic = bip39.mnemonic_from_entropy(raw_entr, 'en') seed = bip39.seed_from_mnemonic(mnemonic, '') ##### TESTNET # p2pkh BIP44 m / 44' / coin_type' / account' / change / address_index path = "m/44h/1h/0h" version = bip32.TEST_tprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'tpubDChqWo2Xi2wNsxyJBE8ipcTJHLKWcqeeNUKBVTpUCNPZkHzHTm3qKAeHqgCou1t8PAY5ZnJ9QDa6zXSZxmjDnhiBpgZ7f6Yv88wEm5HXVbm' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external address = bip32.p2pkh_address_from_xpub(xpub_ext) exp_address = b'moutHSzeFWViMNEcvBxKzNCMj2kca8MvE1' self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal address = bip32.p2pkh_address_from_xpub(xpub_int) exp_address = b'myWcXdNais9ExumnGKnNoJwoihQKfNPG9i' self.assertEqual(address, exp_address) # legacy segwit (p2wpkh-p2sh) m / 49'/ coin_type' / account' / change / address_index path = "m/49h/1h/0h" version = bip32.TEST_uprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'upub5Dj8j7YrwodV68mt58QmNpSzjqjso2WMXEpLGLSvskKccGuXhCh3dTedkzVLAePA617UyXAg2vdswJXTYjU4qjMJaHU79GJVVJCAiy9ezZ2' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external # TODO: address = bip32.p2pkh_address_from_xpub(xpub_ext) exp_address = b'2Mw8tQ6uT6mHhybarVhjgomUhHQJTeV9A2c' # TODO: self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal # TODO: address = bip32.p2pkh_address_from_xpub(xpub_int) exp_address = b'2N872CRJ3E1CzWjfixXr3aeC3hkF5Cz4kWb' # TODO: self.assertEqual(address, exp_address) # multi-sig version version = bip32.TEST_Uprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'Upub5QdDrMHJWmBrWhwG1nskCtnoTdn91PBwqWU1BbiUFXA2ETUSTc5KiaWZZhSoj5c4KUBTr7Anv92P4U9Dqxd1zDTyQkaWYfmVP2U3Js1W5cG' self.assertEqual(xpub, exp) # native segwit (p2wpkh) m / 84'/ coin_type' / account' / change / address_index path = "m/84h/1h/0h" version = bip32.TEST_vprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'vpub5ZhJmduYY7M5J2qCJgSW7hunX6zJrr5WuNg2kKt321HseZEYxqJc6Zso47aNXQw3Wf3sA8kppbfsxnLheUNXcL3xhzeBHLNp8fTVBN6DnJF' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external # FIXME: address = bip32.p2pkh_address_from_xpub(xpub_ext) exp_address = b'bcrt1qv8lcnmj09rpdqwgl025h2deygur64z4hqf7me5' # FIXME: self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal # FIXME: address = bip32.p2pkh_address_from_xpub(xpub_int) exp_address = b'bcrt1qqhxvky4y6qkwpvdzqjkdafmj20vs5trmt6y8w5' # FIXME: self.assertEqual(address, exp_address) # multi-sig version version = bip32.TEST_Vprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'Vpub5kbPtsdz74uSibzaFLuUwnFbEu2a5Cm7DeKhfb9aPn8HGjoTjEgtBgjirpXr5r9wk87r2ikwhp4P5wxTwhXUkpAdYTkagjqp2PjMmGPBESU' self.assertEqual(xpub, exp) ##### MAINNET # p2pkh BIP44 m / 44' / coin_type' / account' / change / address_index path = "m/44h/0h/0h" version = bip32.MAIN_xprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'xpub6C3uWu5Go5q62JzJpbjyCLYRGLYvexFeiepZTsYZ6SRexARkNfjG7GKtQVuGR3KHsyKsAwv7Hz3iNucPp6pfHiLvBczyK1j5CtBtpHB3NKx' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external address = bip32.p2pkh_address_from_xpub(xpub_ext) exp_address = b'1DDKKVHoFWGfctyEEJvrusqq6ipEaieGCq' self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal address = bip32.p2pkh_address_from_xpub(xpub_int) exp_address = b'1FhKoffreKHzhtBMVW9NSsg3ZF148JPGoR' self.assertEqual(address, exp_address) # legacy segwit (p2wpkh-p2sh) m / 49'/ coin_type' / account' / change / address_index path = "m/49h/0h/0h" version = bip32.MAIN_yprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'ypub6YBGdYufCVeoPVmNXfdrWhaBCXsQoLKNetNmD9bPTrKmnKVmiyU8f1uJqwGdmBb8kbAZpHoYfXQTLbWpkXc4skQDAreeCUXdbX9k8vtiHsN' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external # FIXME: address = bip32.p2pkh_address_from_xpub(xpub_ext) exp_address = b'3FmNAiTCWe5kPMgc4dtSgEdY8VuaCiJEH8' # FIXME: self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal # FIXME: address = bip32.p2pkh_address_from_xpub(xpub_int) exp_address = b'34FLgkoRYX5Q5fqiZCZDwsK5GpXxmFuLJN' # FIXME: self.assertEqual(address, exp_address) # multi-sig version version = bip32.MAIN_Yprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'Ypub6j5Mkne6mTDAp4vkUL6qLmuyvKug1gzxyA2S8QrvqdABQW4gVNrQk8mEeeE7Kcp2z4EYgsofYjnxTm8b3km22EWt1Km3bszdVFRcipc6rXu' self.assertEqual(xpub, exp) # native segwit (p2wpkh) m / 84'/ coin_type' / account' / change / address_index path = "m/84h/0h/0h" version = bip32.MAIN_zprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'zpub6qg3Uc1BAQkQvcBUYMmZHSzbsshSon3FvJ8yvH3ZZMjFNvJkwSji8UUwghiF3wvpvSvcNWVP8kfUhc2V2RwGp6pTC3ouj6njj956f26TniN' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external # FIXME: address = bip32.p2pkh_address_from_xpub(xpub_ext) exp_address = b'bc1q0hy024867ednvuhy9en4dggflt5w9unw4ztl5a' # FIXME: self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal # FIXME: address = bip32.p2pkh_address_from_xpub(xpub_int) exp_address = b'bc1qy4x03jyl88h2zeg7l287xhv2xrwk4c3ztfpjd2' # FIXME: self.assertEqual(address, exp_address) # multi-sig version version = bip32.MAIN_Zprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'Zpub72a8bqjcjNJnMBLrV2EY7XLQbfji28irEZneqYK6w8Zf16sfhr7zDbLsVQficP9j9uzbF6VW1y3ypmeFKf6Dxaw82WvK8WFjcsLyEvMNZjF' self.assertEqual(xpub, exp)
def test_mainnet(self): # bitcoin core derivation style rootxprv = b'xprv9s21ZrQH143K2ZP8tyNiUtgoezZosUkw9hhir2JFzDhcUWKz8qFYk3cxdgSFoCMzt8E2Ubi1nXw71TLhwgCfzqFHfM5Snv4zboSebePRmLS' # m/0'/0'/463' addr1 = b'1DyfBWxhVLmrJ7keyiHeMbt7N3UdeGU4G5' indexes = [0x80000000, 0x80000000, 0x80000000 + 463] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(rootxprv, indexes))) self.assertEqual(addr, addr1) path = "m/0'/0'/463'" addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(rootxprv, path))) self.assertEqual(addr, addr1) # m/0'/0'/267' addr2 = b'11x2mn59Qy43DjisZWQGRResjyQmgthki' indexes = [0x80000000, 0x80000000, 0x80000000 + 267] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(rootxprv, indexes))) self.assertEqual(addr, addr2) path = "m/0'/0'/267'" addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(rootxprv, path))) self.assertEqual(addr, addr2) xkey_version = bip32.PRV_VERSION[0] seed = "bfc4cbaad0ff131aa97fa30a48d09ae7df914bcc083af1e07793cd0a7c61a03f65d622848209ad3366a419f4718a80ec9037df107d8d12c19b83202de00a40ad" seed = bytes.fromhex(seed) xprv = bip32.rootxprv_from_seed(seed, xkey_version) xpub = b'xpub661MyMwAqRbcFMYjmw8C6dJV97a4oLss6hb3v9wTQn2X48msQB61RCaLGtNhzgPCWPaJu7SvuB9EBSFCL43kTaFJC3owdaMka85uS154cEh' self.assertEqual(bip32.xpub_from_xprv(xprv), xpub) ind = [0, 0] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(xprv, ind))) self.assertEqual(addr, b'1FcfDbWwGs1PmyhMVpCAhoTfMnmSuptH6g') ind = [0, 1] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(xprv, ind))) self.assertEqual(addr, b'1K5GjYkZnPFvMDTGaQHTrVnd8wjmrtfR5x') ind = [0, 2] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(xprv, ind))) self.assertEqual(addr, b'1PQYX2uN7NYFd7Hq22ECMzfDcKhtrHmkfi') ind = [1, 0] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(xprv, ind))) self.assertEqual(addr, b'1BvSYpojWoWUeaMLnzbkK55v42DbizCoyq') ind = [1, 1] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(xprv, ind))) self.assertEqual(addr, b'1NXB59hF4QzYpFrB7o6usLBjbk2D3ZqxAL') ind = [1, 2] addr = bip32.p2pkh_address_from_xpub(bip32.xpub_from_xprv(bip32.derive(xprv, ind))) self.assertEqual(addr, b'16NLYkKtvYhW1Jp86tbocku3gxWcvitY1w') # version/key mismatch in extended parent key temp = base58.decode_check(rootxprv) bad_xprv = base58.encode_check(temp[0:45] + b'\x01' + temp[46:]) self.assertRaises(ValueError, bip32.ckd, bad_xprv, 1) #bip32.ckd(bad_xprv, 1) # version/key mismatch in extended parent key xpub = bip32.xpub_from_xprv(rootxprv) temp = base58.decode_check(xpub) bad_xpub = base58.encode_check(temp[0:45] + b'\x00' + temp[46:]) self.assertRaises(ValueError, bip32.ckd, bad_xpub, 1) #bip32.ckd(bad_xpub, 1) # no private/hardened derivation from pubkey self.assertRaises(ValueError, bip32.ckd, xpub, 0x80000000)
def test_mainnet_versions(self): # data cross-checked with Electrum and https://jlopp.github.io/xpub-converter/ # 128 bits raw_entr = bytes.fromhex('6' * 32) # 12 words mnemonic = bip39.mnemonic_from_entropy(raw_entr, 'en') seed = bip39.seed_from_mnemonic(mnemonic, '') # p2pkh BIP44 m / 44' / coin_type' / account' / change / address_index path = "m/44h/0h/0h" version = bip32.MAIN_xprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'xpub6C3uWu5Go5q62JzJpbjyCLYRGLYvexFeiepZTsYZ6SRexARkNfjG7GKtQVuGR3KHsyKsAwv7Hz3iNucPp6pfHiLvBczyK1j5CtBtpHB3NKx' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external address = bip32.p2pkh_address_from_xpub(xpub_ext) exp_address = b'1DDKKVHoFWGfctyEEJvrusqq6ipEaieGCq' self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal address = bip32.p2pkh_address_from_xpub(xpub_int) exp_address = b'1FhKoffreKHzhtBMVW9NSsg3ZF148JPGoR' self.assertEqual(address, exp_address) # legacy segwit (p2wpkh-p2sh) m / 49'/ coin_type' / account' / change / address_index path = "m/49h/0h/0h" version = bip32.MAIN_yprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'ypub6YBGdYufCVeoPVmNXfdrWhaBCXsQoLKNetNmD9bPTrKmnKVmiyU8f1uJqwGdmBb8kbAZpHoYfXQTLbWpkXc4skQDAreeCUXdbX9k8vtiHsN' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external address = bip32.p2wpkh_p2sh_address_from_xpub(xpub_ext) exp_address = b'3FmNAiTCWe5kPMgc4dtSgEdY8VuaCiJEH8' self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal address = bip32.p2wpkh_p2sh_address_from_xpub(xpub_int) exp_address = b'34FLgkoRYX5Q5fqiZCZDwsK5GpXxmFuLJN' self.assertEqual(address, exp_address) # legacy segwit (p2wsh-p2sh) m / 49'/ coin_type' / account' / change / address_index path = "m/49h/0h/0h" version = bip32.MAIN_Yprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'Ypub6j5Mkne6mTDAp4vkUL6qLmuyvKug1gzxyA2S8QrvqdABQW4gVNrQk8mEeeE7Kcp2z4EYgsofYjnxTm8b3km22EWt1Km3bszdVFRcipc6rXu' self.assertEqual(xpub, exp) # native segwit (p2wpkh) m / 84'/ coin_type' / account' / change / address_index path = "m/84h/0h/0h" version = bip32.MAIN_zprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'zpub6qg3Uc1BAQkQvcBUYMmZHSzbsshSon3FvJ8yvH3ZZMjFNvJkwSji8UUwghiF3wvpvSvcNWVP8kfUhc2V2RwGp6pTC3ouj6njj956f26TniN' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external address = bip32.p2wpkh_address_from_xpub(xpub_ext) exp_address = b'bc1q0hy024867ednvuhy9en4dggflt5w9unw4ztl5a' self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal address = bip32.p2wpkh_address_from_xpub(xpub_int) exp_address = b'bc1qy4x03jyl88h2zeg7l287xhv2xrwk4c3ztfpjd2' self.assertEqual(address, exp_address) # native segwit (p2wsh) m / 84'/ coin_type' / account' / change / address_index path = "m/84h/0h/0h" version = bip32.MAIN_Zprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'Zpub72a8bqjcjNJnMBLrV2EY7XLQbfji28irEZneqYK6w8Zf16sfhr7zDbLsVQficP9j9uzbF6VW1y3ypmeFKf6Dxaw82WvK8WFjcsLyEvMNZjF' self.assertEqual(xpub, exp)
def test_testnet_versions(self): # data cross-checked with Electrum and https://jlopp.github.io/xpub-converter/ # 128 bits raw_entr = bytes.fromhex('6' * 32) # 12 words mnemonic = bip39.mnemonic_from_entropy(raw_entr, 'en') seed = bip39.seed_from_mnemonic(mnemonic, '') # p2pkh BIP44 m / 44' / coin_type' / account' / change / address_index path = "m/44h/1h/0h" version = bip32.TEST_tprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'tpubDChqWo2Xi2wNsxyJBE8ipcTJHLKWcqeeNUKBVTpUCNPZkHzHTm3qKAeHqgCou1t8PAY5ZnJ9QDa6zXSZxmjDnhiBpgZ7f6Yv88wEm5HXVbm' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external address = bip32.p2pkh_address_from_xpub(xpub_ext) exp_address = b'moutHSzeFWViMNEcvBxKzNCMj2kca8MvE1' self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal address = bip32.p2pkh_address_from_xpub(xpub_int) exp_address = b'myWcXdNais9ExumnGKnNoJwoihQKfNPG9i' self.assertEqual(address, exp_address) # legacy segwit (p2wpkh-p2sh) m / 49'/ coin_type' / account' / change / address_index path = "m/49h/1h/0h" version = bip32.TEST_uprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'upub5Dj8j7YrwodV68mt58QmNpSzjqjso2WMXEpLGLSvskKccGuXhCh3dTedkzVLAePA617UyXAg2vdswJXTYjU4qjMJaHU79GJVVJCAiy9ezZ2' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external address = bip32.p2wpkh_p2sh_address_from_xpub(xpub_ext) exp_address = b'2Mw8tQ6uT6mHhybarVhjgomUhHQJTeV9A2c' self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal address = bip32.p2wpkh_p2sh_address_from_xpub(xpub_int) exp_address = b'2N872CRJ3E1CzWjfixXr3aeC3hkF5Cz4kWb' self.assertEqual(address, exp_address) # legacy segwit (p2wsh-p2sh) m / 49'/ coin_type' / account' / change / address_index path = "m/49h/1h/0h" version = bip32.TEST_Uprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'Upub5QdDrMHJWmBrWhwG1nskCtnoTdn91PBwqWU1BbiUFXA2ETUSTc5KiaWZZhSoj5c4KUBTr7Anv92P4U9Dqxd1zDTyQkaWYfmVP2U3Js1W5cG' self.assertEqual(xpub, exp) # native segwit (p2wpkh) m / 84'/ coin_type' / account' / change / address_index path = "m/84h/1h/0h" version = bip32.TEST_vprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'vpub5ZhJmduYY7M5J2qCJgSW7hunX6zJrr5WuNg2kKt321HseZEYxqJc6Zso47aNXQw3Wf3sA8kppbfsxnLheUNXcL3xhzeBHLNp8fTVBN6DnJF' self.assertEqual(xpub, exp) # first addresses xpub_ext = bip32.derive(xpub, "./0/0") # external address = bip32.p2wpkh_address_from_xpub(xpub_ext) # this is regtest, not testnet!! exp_address = b'bcrt1qv8lcnmj09rpdqwgl025h2deygur64z4hqf7me5' # FIXME: self.assertEqual(address, exp_address) xpub_int = bip32.derive(xpub, "./1/0") # internal address = bip32.p2wpkh_address_from_xpub(xpub_int) # this is regtest, not testnet!! exp_address = b'bcrt1qqhxvky4y6qkwpvdzqjkdafmj20vs5trmt6y8w5' # FIXME: self.assertEqual(address, exp_address) # native segwit (p2wsh) m / 84'/ coin_type' / account' / change / address_index path = "m/84h/1h/0h" version = bip32.TEST_Vprv rootprv = bip32.rootxprv_from_seed(seed, version) xprv = bip32.derive(rootprv, path) xpub = bip32.xpub_from_xprv(xprv) exp = b'Vpub5kbPtsdz74uSibzaFLuUwnFbEu2a5Cm7DeKhfb9aPn8HGjoTjEgtBgjirpXr5r9wk87r2ikwhp4P5wxTwhXUkpAdYTkagjqp2PjMmGPBESU' self.assertEqual(xpub, exp)