Esempio n. 1
0
 def test_ckd(self):
     xpub1 = 'xpub661MyMwAqRbcEnKbXcCqD2GT1di5zQxVqoHPAgHNe8dv5JP8gWmDproS6kFHJnLZd23tWevhdn4urGJ6b264DfTGKr8zjmYDjyDTi9U7iyT'
     node1 = ckd_public.deserialize(xpub1)
     node2 = ckd_public.public_ckd(node1, [0])
     node3 = ckd_public.public_ckd(node1, [0, 0])
     xpub2 = ckd_public.serialize(node2)
     xpub3 = ckd_public.serialize(node3)
     self.assertEqual(xpub2, 'xpub67ymn1YTdE2iSGXitxUEZeUdHF2FsejJATroeAxVMtzTAK9o3vjmFLrE7TqE1X76iobkVc3p8h3gNzNRTwPeQGYW3CCmYCG8n5ThVkXaQzs')
     self.assertEqual(xpub3, 'xpub6BD2MwdEg5PJPqiGetL9DJs7oDo6zP3XwAABX2vAQb5eLpY3QhHGUEm25V4nkQhnFMsqEVfTwtax2gKz8EFrt1PnBN6xQjE9jGmWDR6modu')
Esempio n. 2
0
def test_ckd_public():
    xpub1 = 'xpub661MyMwAqRbcEnKbXcCqD2GT1di5zQxVqoHPAgHNe8dv5JP8gWmDproS6kFHJnLZd23tWevhdn4urGJ6b264DfTGKr8zjmYDjyDTi9U7iyT'
    node1 = ckd_public.deserialize(xpub1)
    node2 = ckd_public.public_ckd(node1, [0])
    node3 = ckd_public.public_ckd(node1, [0, 0])
    xpub2 = ckd_public.serialize(node2)
    xpub3 = ckd_public.serialize(node3)
    assert xpub2 == 'xpub67ymn1YTdE2iSGXitxUEZeUdHF2FsejJATroeAxVMtzTAK9o3vjmFLrE7TqE1X76iobkVc3p8h3gNzNRTwPeQGYW3CCmYCG8n5ThVkXaQzs'
    assert xpub3 == 'xpub6BD2MwdEg5PJPqiGetL9DJs7oDo6zP3XwAABX2vAQb5eLpY3QhHGUEm25V4nkQhnFMsqEVfTwtax2gKz8EFrt1PnBN6xQjE9jGmWDR6modu'
    def test_public_ckd(self, client):
        node = btc.get_public_node(client, []).node
        node_sub1 = btc.get_public_node(client, [1]).node
        node_sub2 = bip32.public_ckd(node, [1])

        assert node_sub1.chain_code == node_sub2.chain_code
        assert node_sub1.public_key == node_sub2.public_key

        address1 = btc.get_address(client, "Bitcoin", [1])
        address2 = bip32.get_address(node_sub2, 0)

        assert address2 == "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb"
        assert address1 == address2
    def test_public_ckd(self):
        self.setup_mnemonic_nopin_nopassphrase()

        node = self.client.get_public_node([]).node
        node_sub1 = self.client.get_public_node([1]).node
        node_sub2 = bip32.public_ckd(node, [1])

        assert node_sub1.chain_code == node_sub2.chain_code
        assert node_sub1.public_key == node_sub2.public_key

        address1 = self.client.get_address('Bitcoin', [1])
        address2 = bip32.get_address(node_sub2, 0)

        assert address2 == '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb'
        assert address1 == address2
Esempio n. 5
0
    def test_public_ckd(self):
        self.setup_mnemonic_nopin_nopassphrase()

        node = self.client.get_public_node([]).node
        node_sub1 = self.client.get_public_node([1]).node
        node_sub2 = bip32.public_ckd(node, [1])

        self.assertEqual(node_sub1.chain_code, node_sub2.chain_code)
        self.assertEqual(node_sub1.public_key, node_sub2.public_key)

        address1 = self.client.get_address('Bitcoin', [1])
        address2 = bip32.get_address(node_sub2, 0)

        self.assertEqual(address2, '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb')
        self.assertEqual(address1, address2)
    def test_public_ckd(self):
        self.setup_mnemonic_nopin_nopassphrase()

        node = self.client.get_public_node([])
        node_sub1 = self.client.get_public_node([1])
        node_sub2 = bip32.public_ckd(node, [1])

        self.assertEqual(node_sub1.chain_code, node_sub2.chain_code)
        self.assertEqual(node_sub1.public_key, node_sub2.public_key)

        address1 = self.client.get_address('Bitcoin', [1])
        address2 = bip32.get_address(node_sub2, 0)

        self.assertEqual(address2, '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb')
        self.assertEqual(address1, address2)
Esempio n. 7
0
    def test_public_ckd(self):
        self.client.wipe_device()
        self.client.load_device_by_mnemonic(mnemonic=self.mnemonic1,
                                            pin='',
                                            passphrase_protection=False,
                                            label='test',
                                            language='english')

        node = self.client.get_public_node([])
        node_sub1 = self.client.get_public_node([1])
        node_sub2 = bip32.public_ckd(node, [1])

        self.assertEqual(node_sub1.chain_code, node_sub2.chain_code)
        self.assertEqual(node_sub1.public_key, node_sub2.public_key)

        address1 = self.client.get_address('Bitcoin', [1])
        address2 = bip32.get_address(node_sub2, 0)

        self.assertEqual(address2, '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb')
        self.assertEqual(address1, address2)
Esempio n. 8
0
    def create_inputs(self, numinputs, txsize):
        idx = 0
        sum = 0
        self.inputs = []
        self.txs = {}
        for nr in range(numinputs):
            t = proto_types.TransactionType()
            t.version = 1
            t.lock_time = 0
            i = t.inputs.add()
            i.prev_hash = os.urandom(32)
            i.prev_index = random.randint(0, 4)
            i.script_sig = os.urandom(100)
            i.sequence = 0xffffffff
            if nr % 50 == 0:
                print(nr)
            myout = random.randint(0, txsize - 1)
            segwit = random.randint(0, 2)
            for vout in range(txsize):
                o = t.bin_outputs.add()
                o.amount = random.randint(10000, 1000000)
                if vout == myout:
                    amount = o.amount
                    sum = sum + o.amount
                    node = self.node
                    path = [0, idx]
                    node = bip32.public_ckd(node, path)
                    idx = idx + 1
                    pubkey = tools.hash_160(node.public_key)
                else:
                    pubkey = os.urandom(20)
                if segwit == 2:
                    # p2sh segwit
                    o.script_pubkey = b'\xa9\x14' + hash160(b'\x00\x14' +
                                                            pubkey) + b'\x87'
                elif segwit == 1:
                    o.script_pubkey = b'\x00\x14' + pubkey
                else:
                    o.script_pubkey = b'\x76\xa9\x14' + pubkey + b'\x88\xac'

            txser = self.serialize_tx(t)
            txhash = tools.Hash(txser)[::-1]
            outi = self.inputs.append(
                proto_types.TxInputType(
                    address_n=self.client.expand_path("44'/0'/0'/0/%d" % idx),
                    script_type=(proto_types.SPENDWITNESS if segwit == 1 else
                                 proto_types.SPENDP2SHWITNESS
                                 if segwit == 2 else proto_types.SPENDADDRESS),
                    prev_hash=txhash,
                    prev_index=myout,
                    amount=amount if segwit > 0 else 0))
            # print(binascii.hexlify(txser))
            # print(binascii.hexlify(txhash))
            self.txs[binascii.hexlify(txhash)] = t

        self.outputs = [
            proto_types.TxOutputType(
                amount=sum,
                script_type=proto_types.PAYTOADDRESS,
                address_n=self.client.expand_path("44'/0'/0'/1/0"))
        ]
Esempio n. 9
0
    def create_inputs(self, numinputs, txsize):
        idx = 0
        sum = 0
        self.inputs = []
        self.txs = {}
        for nr in range(numinputs):
            t = proto_types.TransactionType()
            t.version = 1
            t.lock_time = 0
            i = t.inputs.add()
            i.prev_hash = os.urandom(32)
            i.prev_index = random.randint(0,4)
            i.script_sig = os.urandom(100)
            i.sequence = 0xffffffff
            if (nr % 50 == 0):
                print(nr)
            myout = random.randint(0, txsize-1)
            segwit = 1 #random.randint(0,1)
            for vout in range(txsize):
                o = t.bin_outputs.add()
                o.amount = random.randint(10000,1000000)
                if vout == myout:
                    amount = o.amount
                    sum = sum + o.amount
                    node = self.node
                    path = [0, idx]
                    node = bip32.public_ckd(node, path)
                    idx = idx + 1
                    pubkey = tools.hash_160(node.public_key)
                else:
                    pubkey = os.urandom(20)
                if (segwit):
                    o.script_pubkey = binascii.unhexlify('0014') + pubkey
                else:
                    o.script_pubkey = binascii.unhexlify('76a914') + pubkey + binascii.unhexlify('88ac')

            txser = self.serialize_tx(t)
            txhash = tools.Hash(txser)[::-1]
            if (segwit):
                outi = self.inputs.append(
                    proto_types.TxInputType(
                        address_n=self.client.expand_path("44'/0'/0'/0/"+str(idx)),
                        script_type = proto_types.SPENDWADDRESS,
                        prev_hash=txhash,
                        prev_index = myout,
                        amount = amount
                    ))
            else:
                outi = self.inputs.append(
                    proto_types.TxInputType(
                        address_n=self.client.expand_path("44'/0'/0'/0/"+str(idx)),
                        script_type = proto_types.SPENDADDRESS,
                        prev_hash=txhash,
                        prev_index = myout
                    ))
            #print(binascii.hexlify(txser))
            #print(binascii.hexlify(txhash))
            self.txs[binascii.hexlify(txhash)] = t

        self.outputs = [
            proto_types.TxOutputType(
                amount=sum,
                script_type=proto_types.PAYTOADDRESS,
                address_n=self.client.expand_path("44'/0'/0'/1/0")
            )]