示例#1
0
    def test_bip84(self):
        """https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki#test-vectors"""

        mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
        m = Xprv.from_mnemonic(mnemonic, addresstype='P2WPKH')
        M = m.to_xpub()

        self.assertEqual(m.encode(), 'zprvAWgYBBk7JR8Gjrh4UJQ2uJdG1r3WNRRfURiABBE3RvMXYSrRJL62XuezvGdPvG6GFBZduosCc1YP5wixPox7zhZLfiUm8aunE96BBa4Kei5')
        self.assertEqual(M.encode(), 'zpub6jftahH18ngZxLmXaKw3GSZzZsszmt9WqedkyZdezFtWRFBZqsQH5hyUmb4pCEeZGmVfQuP5bedXTB8is6fTv19U1GQRyQUKQGUTzyHACMF')

        xprv = m/84./0./0.
        self.assertEqual(xprv.encode(), 'zprvAdG4iTXWBoARxkkzNpNh8r6Qag3irQB8PzEMkAFeTRXxHpbF9z4QgEvBRmfvqWvGp42t42nvgGpNgYSJA9iefm1yYNZKEm7z6qUWCroSQnE')
        self.assertEqual(xprv.to_xpub().encode(), 'zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs')

        xprv = m/84./0./0./0/0
        self.assertEqual(xprv.key.wif(compressed=True), 'KyZpNDKnfs94vbrwhJneDi77V6jF64PWPF8x5cdJb8ifgg2DUc9d')
        self.assertEqual(xprv.to_xpub().key.hex(compressed=True), '0330d54fd0dd420a6e5f8d3624f5f3482cae350f79d5f0753bf5beef9c2d91af3c')
        self.assertEqual(xprv.address(), 'bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu')

        xprv = m/84./0./0./0/1
        self.assertEqual(xprv.key.wif(compressed=True), 'Kxpf5b8p3qX56DKEe5NqWbNUP9MnqoRFzZwHRtsFqhzuvUJsYZCy')
        self.assertEqual(xprv.to_xpub().key.hex(compressed=True), '03e775fd51f0dfb8cd865d9ff1cca2a158cf651fe997fdc9fee9c1d3b5e995ea77')
        self.assertEqual(xprv.address(), 'bc1qnjg0jd8228aq7egyzacy8cys3knf9xvrerkf9g')

        xprv = m/84./0./0./1/0
        self.assertEqual(xprv.key.wif(compressed=True), 'KxuoxufJL5csa1Wieb2kp29VNdn92Us8CoaUG3aGtPtcF3AzeXvF')
        self.assertEqual(xprv.to_xpub().key.hex(compressed=True), '03025324888e429ab8e3dbaf1f7802648b9cd01e9b418485c5fa4c1b9b5700e1a6')
        self.assertEqual(xprv.address(), 'bc1q8c6fshw2dlwun7ekn9qwf37cu2rn755upcp6el')
示例#2
0
    def test_bip49(self):
        """https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki#Test_vectors"""

        import os
        os.environ['CRYPTOTOOLS_NETWORK'] = 'test'

        mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
        m = Xprv.from_mnemonic(mnemonic)
        self.assertEqual(
            m.encode(),
            'tprv8ZgxMBicQKsPe5YMU9gHen4Ez3ApihUfykaqUorj9t6FDqy3nP6eoXiAo2ssvpAjoLroQxHqr3R5nE3a5dU3DHTjTgJDd7zrbniJr6nrCzd'
        )

        xprv = m / 49. / 1. / 0.
        self.assertEqual(
            xprv.encode(),
            'tprv8gRrNu65W2Msef2BdBSUgFdRTGzC8EwVXnV7UGS3faeXtuMVtGfEdidVeGbThs4ELEoayCAzZQ4uUji9DUiAs7erdVskqju7hrBcDvDsdbY'
        )

        xprv = m / 49. / 1. / 0. / 0 / 0
        self.assertEqual(
            xprv.key.wif(compressed=True),
            'cULrpoZGXiuC19Uhvykx7NugygA3k86b3hmdCeyvHYQZSxojGyXJ')
        self.assertEqual(
            xprv.key.hex(),
            'c9bdb49cfbaedca21c4b1f3a7803c34636b1d7dc55a717132443fc3f4c5867e8')
        self.assertEqual(
            xprv.to_xpub().key.hex(compressed=True),
            '03a1af804ac108a8a51782198c2d034b28bf90c8803f5a53f76276fa69a4eae77f'
        )
        self.assertEqual(xprv.key.to_public().to_address('P2WPKH-P2SH'),
                         '2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2')

        os.environ['CRYPTOTOOLS_NETWORK'] = 'main'