Пример #1
0
async def sign_tx(ctx, msg: NEMSignTx):
    validate(msg)
    await validate_path(
        ctx, check_path, path=msg.transaction.address_n, network=msg.transaction.network
    )

    node = await seed.derive_node(ctx, msg.transaction.address_n, NEM_CURVE)

    if msg.multisig:
        public_key = msg.multisig.signer
        common = msg.multisig
        await multisig.ask(ctx, msg)
    else:
        public_key = seed.remove_ed25519_prefix(node.public_key())
        common = msg.transaction

    if msg.transfer:
        tx = await transfer.transfer(ctx, public_key, common, msg.transfer, node)
    elif msg.provision_namespace:
        tx = await namespace.namespace(ctx, public_key, common, msg.provision_namespace)
    elif msg.mosaic_creation:
        tx = await mosaic.mosaic_creation(ctx, public_key, common, msg.mosaic_creation)
    elif msg.supply_change:
        tx = await mosaic.supply_change(ctx, public_key, common, msg.supply_change)
    elif msg.aggregate_modification:
        tx = await multisig.aggregate_modification(
            ctx,
            public_key,
            common,
            msg.aggregate_modification,
            msg.multisig is not None,
        )
    elif msg.importance_transfer:
        tx = await transfer.importance_transfer(
            ctx, public_key, common, msg.importance_transfer
        )
    else:
        raise ValueError("No transaction provided")

    if msg.multisig:
        # wrap transaction in multisig wrapper
        if msg.cosigning:
            tx = multisig.cosign(
                seed.remove_ed25519_prefix(node.public_key()),
                msg.transaction,
                tx,
                msg.multisig.signer,
            )
        else:
            tx = multisig.initiate(
                seed.remove_ed25519_prefix(node.public_key()), msg.transaction, tx
            )

    signature = ed25519.sign(node.private_key(), tx, NEM_HASH_ALG)

    resp = NEMSignedTx()
    resp.data = tx
    resp.signature = signature
    return resp
    def test_root_address_derivation_scheme(self):
        mnemonic = "all all all all all all all all all all all all"
        passphrase = ""
        node = bip32.from_mnemonic_cardano(mnemonic, passphrase)

        # 44'/1815'
        address, _ = derive_address_and_node(
            node, [0x80000000 | 44, 0x80000000 | 1815])
        self.assertEqual(
            address,
            "Ae2tdPwUPEZ2FGHX3yCKPSbSgyuuTYgMxNq652zKopxT4TuWvEd8Utd92w3")

        priv, ext, pub, chain = (
            b"204ec79cbb6502a141de60d274962010c7f1c94a2987b26506433184d228ed51",
            b"975cdd1c8610b44701567f05934c45c8716064263ccfe72ed2167ccb705c09b6",
            b"8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce",
            b"02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a"
        )

        _, n = derive_address_and_node(node,
                                       [0x80000000 | 44, 0x80000000 | 1815])
        self.assertEqual(hexlify(n.private_key()), priv)
        self.assertEqual(hexlify(n.private_key_ext()), ext)
        self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())),
                         pub)
        self.assertEqual(hexlify(n.chain_code()), chain)
Пример #3
0
def _build_byron_witnesses(
    keychain: seed.Keychain,
    inputs: List[CardanoTxInputType],
    tx_body_hash: bytes,
    protocol_magic: int,
) -> List[Tuple[bytes, bytes, bytes, bytes]]:
    byron_witnesses = []

    # include only one witness for each path
    paths = set()
    for input in inputs:
        if not is_byron_path(input.address_n):
            continue
        paths.add(tuple(input.address_n))

    for path in paths:
        node = keychain.derive(list(path))

        public_key = remove_ed25519_prefix(node.public_key())
        signature = ed25519.sign_ext(
            node.private_key(), node.private_key_ext(), tx_body_hash
        )
        chain_code = node.chain_code()
        address_attributes = cbor.encode(get_address_attributes(protocol_magic))

        byron_witnesses.append((public_key, signature, chain_code, address_attributes))

    return byron_witnesses
Пример #4
0
def _get_address_root(node, payload):
    extpubkey = seed.remove_ed25519_prefix(node.public_key()) + node.chain_code()
    if payload:
        payload = {1: cbor.encode(payload)}
    else:
        payload = {}
    return _address_hash([0, [0, extpubkey], payload])
Пример #5
0
    def test_root_address_derivation_scheme(self):
        # 44'/1815'
        address_parameters = CardanoAddressParametersType(
            address_type=CardanoAddressType.BYRON,
            address_n=[0x80000000 | 44, 0x80000000 | 1815],
        )
        address = derive_human_readable_address(self.keychain,
                                                address_parameters,
                                                protocol_magics.MAINNET,
                                                network_ids.MAINNET)
        self.assertEqual(
            address,
            "Ae2tdPwUPEZ2FGHX3yCKPSbSgyuuTYgMxNq652zKopxT4TuWvEd8Utd92w3")

        priv, ext, pub, chain = (
            b"204ec79cbb6502a141de60d274962010c7f1c94a2987b26506433184d228ed51",
            b"975cdd1c8610b44701567f05934c45c8716064263ccfe72ed2167ccb705c09b6",
            b"8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce",
            b"02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a"
        )

        n = self.keychain.derive([0x80000000 | 44, 0x80000000 | 1815])
        self.assertEqual(hexlify(n.private_key()), priv)
        self.assertEqual(hexlify(n.private_key_ext()), ext)
        self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())),
                         pub)
        self.assertEqual(hexlify(n.chain_code()), chain)
Пример #6
0
def _get_public_key(keychain, derivation_path: list):
    _, node = derive_address_and_node(keychain, derivation_path)

    public_key = hexlify(remove_ed25519_prefix(node.public_key())).decode()
    chain_code = hexlify(node.chain_code()).decode()
    xpub_key = public_key + chain_code

    node_type = HDNodeType(
        depth=node.depth(),
        child_num=node.child_num(),
        fingerprint=node.fingerprint(),
        chain_code=node.chain_code(),
        public_key=remove_ed25519_prefix(node.public_key()),
    )

    return CardanoPublicKey(node=node_type, xpub=xpub_key)
def _get_public_key(keychain: seed.Keychain,
                    derivation_path: List[int]) -> CardanoPublicKey:
    node = keychain.derive(derivation_path)

    public_key = hexlify(remove_ed25519_prefix(node.public_key())).decode()
    chain_code = hexlify(node.chain_code()).decode()
    xpub_key = public_key + chain_code

    node_type = HDNodeType(
        depth=node.depth(),
        child_num=node.child_num(),
        fingerprint=node.fingerprint(),
        chain_code=node.chain_code(),
        public_key=remove_ed25519_prefix(node.public_key()),
    )

    return CardanoPublicKey(node=node_type, xpub=xpub_key)
async def get_public_key(ctx, msg: StellarGetPublicKey):
    node = await seed.derive_node(ctx, msg.address_n, helpers.STELLAR_CURVE)
    pubkey = seed.remove_ed25519_prefix(node.public_key())

    if msg.show_display:
        await show_pubkey(ctx, pubkey)

    return StellarPublicKey(public_key=pubkey)
Пример #9
0
def _cborize_shelley_witness(keychain: seed.Keychain, tx_body_hash: bytes,
                             path: List[int]) -> Tuple[bytes, bytes]:
    node = keychain.derive(path)

    signature = ed25519.sign_ext(node.private_key(), node.private_key_ext(),
                                 tx_body_hash)
    public_key = remove_ed25519_prefix(node.public_key())

    return public_key, signature
Пример #10
0
def _sign_message(root_node, message: str, derivation_path: list):
    address, node = derive_address_and_node(root_node, derivation_path)

    signature = ed25519.sign_ext(node.private_key(), node.private_key_ext(), message)

    sig = CardanoMessageSignature()
    sig.public_key = seed.remove_ed25519_prefix(node.public_key())
    sig.signature = signature

    return sig
Пример #11
0
async def get_public_key(ctx, msg):
    node = await seed.derive_node(ctx, msg.address_n, TEZOS_CURVE)

    pk = seed.remove_ed25519_prefix(node.public_key())
    pk_prefixed = base58_encode_check(pk, prefix=TEZOS_PUBLICKEY_PREFIX)

    if msg.show_display:
        await _show_tezos_pubkey(ctx, pk_prefixed)

    return TezosPublicKey(public_key=pk_prefixed)
Пример #12
0
    def test_hardened_address_derivation_scheme(self):
        mnemonic = "all all all all all all all all all all all all"
        passphrase = ""
        node = bip32.from_mnemonic_cardano(mnemonic, passphrase)
        keychain = Keychain(node)

        addresses = [
            "Ae2tdPwUPEZ98eHFwxSsPBDz73amioKpr58Vw85mP1tMkzq8siaftiejJ3j",
            "Ae2tdPwUPEZKA971NCHuHqaEnxZDFWPzH3fEsLpDnbEpG6UeMRHnRzCzEwK",
            "Ae2tdPwUPEZL9Ag1ouS4b1zjuPxKpvEUgjpVpG1KQFs5pNewQb65F1WXVQ2",
        ]

        for i, expected in enumerate(addresses):
            # 44'/1815'/0'/0/i'
            address_parameters = CardanoAddressParametersType(
                address_type=CardanoAddressType.BYRON,
                address_n=[
                    0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0,
                    0x80000000 + i
                ],
            )
            address = derive_human_readable_address(keychain,
                                                    address_parameters,
                                                    protocol_magics.MAINNET,
                                                    network_ids.MAINNET)
            self.assertEqual(expected, address)

        nodes = [
            (b"3881a8de77d069001010d7f7d5211552e7d539b0e253add710367f95e528ed51",
             b"9b77608b38e0a0c7861aa234557c81482f42aae2d17993a8ddaec1868fb04d60",
             b"a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408",
             b"cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0"
             ),
            (b"3003aca659846540b9ed04f2b844f2d8ea964856ca38a7dffedef4f6e528ed51",
             b"8844ccc81d633e1c7126f30c2524c1652617cf58da755014070215bf5070ba38",
             b"be28c00ed6cb9b70310f78028f8e3a2db935baf482d84afa590b0b5b864571cc",
             b"584b4631d752023a249e980779517280e6c0b3ac7a7f27c6e9456bfd228ca60b"
             ),
            (b"68e4482add0a741e14c8f2306bf83206a623e3729dd24175915eedece428ed51",
             b"3165a80c5efe846224d46a0427cdb2be4f31ea3585c51f4131faefc4328ad95a",
             b"9a32499976ffb582daa9988dfc42a303de5ed00c320c929f496be3c6eb1cf405",
             b"da07ca30a3d1c5fe3c34ce5fa197722446a646624a10bdf8889a4b9c347b2ef2"
             ),
        ]

        for i, (priv, ext, pub, chain) in enumerate(nodes):
            n = keychain.derive([
                0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0,
                0x80000000 + i
            ])
            self.assertEqual(hexlify(n.private_key()), priv)
            self.assertEqual(hexlify(n.private_key_ext()), ext)
            self.assertEqual(
                hexlify(seed.remove_ed25519_prefix(n.public_key())), pub)
            self.assertEqual(hexlify(n.chain_code()), chain)
Пример #13
0
async def get_public_key(ctx, msg, keychain):
    await paths.validate_path(ctx, helpers.validate_full_path, keychain, msg.address_n)

    node = keychain.derive(msg.address_n, helpers.TEZOS_CURVE)
    pk = seed.remove_ed25519_prefix(node.public_key())
    pk_prefixed = helpers.base58_encode_check(pk, prefix=helpers.TEZOS_PUBLICKEY_PREFIX)

    if msg.show_display:
        await _show_tezos_pubkey(ctx, pk_prefixed)

    return TezosPublicKey(public_key=pk_prefixed)
Пример #14
0
def _get_public_key(root_node, derivation_path: list):
    _, node = derive_address_and_node(root_node, derivation_path)

    public_key = hexlify(seed.remove_ed25519_prefix(
        node.public_key())).decode()
    chain_code = hexlify(node.chain_code()).decode()
    xpub_key = public_key + chain_code
    root_hd_passphrase = hexlify(_derive_hd_passphrase(root_node)).decode()

    node_type = HDNodeType(
        depth=node.depth(),
        child_num=node.child_num(),
        fingerprint=node.fingerprint(),
        chain_code=node.chain_code(),
        public_key=seed.remove_ed25519_prefix(node.public_key()),
    )

    return CardanoPublicKey(node=node_type,
                            xpub=xpub_key,
                            root_hd_passphrase=root_hd_passphrase)
Пример #15
0
async def get_address(ctx, msg: StellarGetAddress, keychain):
    await paths.validate_path(ctx, keychain, msg.address_n)

    node = keychain.derive(msg.address_n)
    pubkey = seed.remove_ed25519_prefix(node.public_key())
    address = helpers.address_from_public_key(pubkey)

    if msg.show_display:
        desc = address_n_to_str(msg.address_n)
        await show_address(ctx, address=address, address_qr=address.upper(), desc=desc)

    return StellarAddress(address=address)
Пример #16
0
    def test_non_hardened_address_derivation_scheme(self):
        mnemonic = "all all all all all all all all all all all all"
        passphrase = ""
        node = bip32.from_mnemonic_cardano(mnemonic, passphrase)
        keychain = Keychain(node)

        addresses = [
            "Ae2tdPwUPEZ5YUb8sM3eS8JqKgrRLzhiu71crfuH2MFtqaYr5ACNRdsswsZ",
            "Ae2tdPwUPEZJb8r1VZxweSwHDTYtqeYqF39rZmVbrNK62JHd4Wd7Ytsc8eG",
            "Ae2tdPwUPEZFm6Y7aPZGKMyMAK16yA5pWWKU9g73ncUQNZsAjzjhszenCsq",
        ]

        for i, expected in enumerate(addresses):
            # 44'/1815'/0'/0/i
            address_parameters = CardanoAddressParametersType(
                address_type=CardanoAddressType.BYRON,
                address_n=[
                    0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i
                ],
            )
            address = derive_human_readable_address(keychain,
                                                    address_parameters,
                                                    protocol_magics.MAINNET,
                                                    network_ids.MAINNET)
            self.assertEqual(address, expected)

        nodes = [
            (b"d03ba81163fd55af97bd132bf651a0da5b5e6201b15b1caca60b0be8e028ed51",
             b"493f44aa8d25fe0d3fe2935c76ea6b3e9e41c79e9dbcbe7131357c5aa1b6cac5",
             b"b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5",
             b"fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7"
             ),
            (b"08b6438c8dd49d34b71c8e914d6ac3184e5ab3dcc8af023d08503a7edf28ed51",
             b"3fee605fdfaddc1ee2ea0b246b02c9abc54ad741054bc83943e8b21487b5a053",
             b"89053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea",
             b"26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a635"
             ),
            (b"088f0275bf4a1bd18f08d7ef06c6ddb6ce7e3dc415fb4e89fe21bf39e628ed51",
             b"4c44563c7df519ea9b4d1801c1ab98b449db28b87f1c3837759c20f68c4c1e65",
             b"52548cb98e6f46a592bdf7f3598a9abc0126c78dfa3f46d1894ee52a5213e833",
             b"91af0668ee449e613e61bbb2482e5ddee1d9b15785727ec3e362c36861bff923"
             ),
        ]

        for i, (priv, ext, pub, chain) in enumerate(nodes):
            n = keychain.derive(
                [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i])
            self.assertEqual(hexlify(n.private_key()), priv)
            self.assertEqual(hexlify(n.private_key_ext()), ext)
            self.assertEqual(
                hexlify(seed.remove_ed25519_prefix(n.public_key())), pub)
            self.assertEqual(hexlify(n.chain_code()), chain)
Пример #17
0
async def get_address(ctx, msg: StellarGetAddress):
    node = await seed.derive_node(ctx, msg.address_n, helpers.STELLAR_CURVE)
    pubkey = seed.remove_ed25519_prefix(node.public_key())
    address = helpers.address_from_public_key(pubkey)

    if msg.show_display:
        while True:
            if await show_address(ctx, address):
                break
            if await show_qr(ctx, address.upper()):
                break

    return StellarAddress(address=address)
Пример #18
0
async def get_address(ctx, msg, keychain):
    await paths.validate_path(ctx, keychain, msg.address_n)

    node = keychain.derive(msg.address_n)

    pk = seed.remove_ed25519_prefix(node.public_key())
    pkh = hashlib.blake2b(pk, outlen=helpers.PUBLIC_KEY_HASH_SIZE).digest()
    address = helpers.base58_encode_check(
        pkh, prefix=helpers.TEZOS_ED25519_ADDRESS_PREFIX)

    if msg.show_display:
        desc = address_n_to_str(msg.address_n)
        await show_address(ctx, address=address, address_qr=address, desc=desc)

    return TezosAddress(address=address)
Пример #19
0
    def _build_witnesses(self, tx_aux_hash: str):
        witnesses = []
        for index, node in enumerate(self.nodes):
            message = (b"\x01" + cbor.encode(self.protocol_magic) +
                       b"\x58\x20" + tx_aux_hash)
            signature = ed25519.sign_ext(node.private_key(),
                                         node.private_key_ext(), message)
            extended_public_key = (remove_ed25519_prefix(node.public_key()) +
                                   node.chain_code())
            witnesses.append([
                self.types[index],
                cbor.Tagged(24, cbor.encode([extended_public_key, signature])),
            ])

        return witnesses
Пример #20
0
async def get_address(ctx, msg):
    address_n = msg.address_n or ()
    node = await seed.derive_node(ctx, address_n, TEZOS_CURVE)

    pk = seed.remove_ed25519_prefix(node.public_key())
    pkh = hashlib.blake2b(pk, outlen=20).digest()
    address = base58_encode_check(pkh, prefix=TEZOS_ED25519_ADDRESS_PREFIX)

    if msg.show_display:
        while True:
            if await show_address(ctx, address):
                break
            if await show_qr(ctx, address):
                break

    return TezosAddress(address=address)
Пример #21
0
    def _build_witnesses(self, tx_aux_hash: str):
        witnesses = []
        for input in self.inputs:
            _, node = derive_address_and_node(self.keychain, input.address_n)
            message = (b"\x01" + cbor.encode(self.protocol_magic) +
                       b"\x58\x20" + tx_aux_hash)
            signature = ed25519.sign_ext(node.private_key(),
                                         node.private_key_ext(), message)
            extended_public_key = (remove_ed25519_prefix(node.public_key()) +
                                   node.chain_code())
            witnesses.append([
                (input.type or 0),
                cbor.Tagged(24, cbor.encode([extended_public_key, signature])),
            ])

        return witnesses
Пример #22
0
async def get_address(ctx: Context, msg: StellarGetAddress,
                      keychain: Keychain) -> StellarAddress:
    await paths.validate_path(ctx, keychain, msg.address_n)

    node = keychain.derive(msg.address_n)
    pubkey = seed.remove_ed25519_prefix(node.public_key())
    address = helpers.address_from_public_key(pubkey)

    if msg.show_display:
        title = paths.address_n_to_str(msg.address_n)
        await show_address(ctx,
                           address=address,
                           case_sensitive=False,
                           title=title)

    return StellarAddress(address=address)
    def test_hardened_address_derivation(self):
        mnemonic = "plastic that delay conduct police ticket swim gospel intact harsh obtain entire"
        node = bip32.from_mnemonic_cardano(mnemonic)

        addresses = [
            "DdzFFzCqrhtDB6YEgPQqFiVnhKsfyEMe9MLQabhayVUL2WRN1dbLLFS7VfKYBy8n3uemZRcDyqMnv7STCU9vj2eAR8CgFgKMDG2mkQN7",
            "DdzFFzCqrhtCGRQ2UYpcouvRgDnPsAYpmzWVtd5YLvaRrMAMoDmYsKhNMAWePbK7a1XbZ8ghTeyaSLZ2488extnB5F9SwHus4UFaFwkS",
            "DdzFFzCqrhsqHyZLVLeFrgcxUrPA5YMJJRJCxkESHcPkV1EuuDKhKkJNPkEyrWXhPbuMHxSnz1cNYUCN8tJsLwaFiSxMz3ab19GEvaNP",
        ]

        for i, expected in enumerate(addresses):
            # 44'/1815'/0'/0/i'
            address, _ = derive_address_and_node(node, [
                0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0,
                0x80000000 + i
            ])
            self.assertEqual(expected, address)

        nodes = [
            ("d4dd69a2f2a6374f3733f53e03f610d73dd4f1d5131169bc144e6d34c9bcbe04",
             "21d97a697583630e2cef01e5fc1555ea4fd9625ff8fcde1fc72e67aa42f975ec",
             "2df46e04ebf0816e242bfaa1c73e5ebe8863d05d7a96c8aac16f059975e63f30",
             "057658de1308930ad4a5663e4f77477014b04954a9d488e62d73b04fc659a35c"
             ),
            ("3476630290051477e4cc206fd5f6587065d3c9558c9891cc1c0ed5a408d5b60c",
             "3f1d4beaefd2ffff59a45cb75519960d02f4de62c076a165bc39a7d7b1fec168",
             "35b0cc0b770e04d86a9cddb0e2068b3a242f6b6e93c9a9d3c4f0899bd62b4266",
             "35bb811c631b3db3b10559bc15821a39969654ebcad80cedf544ac8bf2a73ce7"
             ),
            ("06a6f53baf84ac6713cd1c441081dff00d1c4abee33091dc5c5ebdec2044270c",
             "4978871e479a3a58adabb030565162832c63a2909442d306c96eaf03823ff5c9",
             "9f26aad725aef1bb0609085f2c961b4d2579bceccfb1b01f3c7d1dbdd02b50b1",
             "70f72ce51d0c984c4bbddd0297f4ffe0b4710c2c3f9a7e17f7d7e3e1810b5c33"
             ),
        ]

        for i, (priv, ext, pub, chain) in enumerate(nodes):
            _, n = derive_address_and_node(node, [
                0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0,
                0x80000000 + i
            ])
            self.assertEqual(unhexlify(priv), n.private_key())
            self.assertEqual(unhexlify(ext), n.private_key_ext())
            self.assertEqual(unhexlify(pub),
                             seed.remove_ed25519_prefix(n.public_key()))
            self.assertEqual(unhexlify(chain), n.chain_code())
Пример #24
0
async def get_address(ctx, msg: StellarGetAddress, keychain):
    await paths.validate_path(ctx, helpers.validate_full_path, keychain,
                              msg.address_n, CURVE)

    node = keychain.derive(msg.address_n, CURVE)
    pubkey = seed.remove_ed25519_prefix(node.public_key())
    address = helpers.address_from_public_key(pubkey)

    if msg.show_display:
        desc = address_n_to_str(msg.address_n)
        while True:
            if await show_address(ctx, address, desc=desc):
                break
            if await show_qr(ctx, address.upper(), desc=desc):
                break

    return StellarAddress(address=address)
Пример #25
0
    def _build_witnesses(self, tx_aux_hash: str):
        witnesses = []
        for index, node in enumerate(self.nodes):
            message = self.CARDANO_WITNESS_MAGIC_PREFIX + tx_aux_hash
            signature = ed25519.sign_ext(
                node.private_key(), node.private_key_ext(), message
            )
            extended_public_key = (
                seed.remove_ed25519_prefix(node.public_key()) + node.chain_code()
            )
            witnesses.append(
                [
                    self.types[index],
                    cbor.Tagged(24, cbor.encode([extended_public_key, signature])),
                ]
            )

        return witnesses
async def get_public_key(ctx, msg, keychain):
    await paths.validate_path(ctx, helpers.validate_full_path, keychain,
                              msg.address_n, CURVE)

    node = keychain.derive(msg.address_n, CURVE)
    pk = seed.remove_ed25519_prefix(node.public_key())
    pk_base58 = base58.encode(pk)
    chain_id = helpers.get_chain_id(msg.address_n)
    address = helpers.get_address_from_public_key(pk_base58, chain_id)

    if msg.show_display:
        await _show_vsys_pubkey(ctx, pk_base58)

    return VsysPublicKey(api=ACCOUNT_API_VER,
                         public_key=pk_base58,
                         address=address,
                         protocol=PROTOCOL,
                         opc=OPC_ACCOUNT)
Пример #27
0
def _build_shelley_witnesses(
    keychain: seed.Keychain,
    inputs: List[CardanoTxInputType],
    tx_body_hash: bytes,
) -> List[Tuple[bytes, bytes]]:
    shelley_witnesses = []
    for input in inputs:
        if not is_shelley_path(input.address_n):
            continue

        node = keychain.derive(input.address_n)

        public_key = remove_ed25519_prefix(node.public_key())
        signature = ed25519.sign_ext(node.private_key(),
                                     node.private_key_ext(), tx_body_hash)
        shelley_witnesses.append((public_key, signature))

    return shelley_witnesses
    def test_non_hardened_address_derivation(self):
        mnemonic = "plastic that delay conduct police ticket swim gospel intact harsh obtain entire"
        node = bip32.from_mnemonic_cardano(mnemonic)

        addresses = [
            "2w1sdSJu3GVezU6nw8LodErz7kSrEQ9hKQhsGLWk4JxTCxg7tkJvSowGKLFE7PMxknbkuYjtaWbpnJLhJgwmwNA98GPX2SGSN1t",
            "2w1sdSJu3GVg7mRbtq2aGUFKxXnpFoP9hesA1n7KJrnQ9QEgyy7DGbLU52L2cytPqCoNNhkvRCF9ZsBLwMv1E35CVh6XBiWj2GE",
            "2w1sdSJu3GVg193D2yhiiH947J9UwrbPAmNao6ciAZi3GeU7sG1D3fTAnQakzHSe1FVyuRdUjcx52Q7575LxBBNE8aCunKFA4kA",
        ]

        for i, expected in enumerate(addresses):
            # 44'/1815'/0'/0/i
            address, _ = derive_address_and_node(
                node, [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i])
            self.assertEqual(expected, address)

        nodes = [
            ("a75a851505db79ee8557a8cb3ef561ab7d6bd24d7cc0e97b8496654431fc2e0c",
             "21fa8154e009a46a1c44709fe23b75735c8abc6256c44cc3c208c1c914f037ce",
             "723fdc0eb1300fe7f2b9b6989216a831835a88695ba2c2d5c50c8470b7d1b239",
             "ae09010e921de259b02f34ce7fd76f9c09ad224d436fe8fa38aa212177937ffe"
             ),
            ("48ded246510a563f759fde920016ad1356238ab5936869e45ccec5b4d8fcce0c",
             "0216c5c777bfe196576b776bd9faf2ac1318966c820edb203754166d5a0f4d92",
             "6dc82a0d40257cfc1ea5d728c6ccfa52ad5673c2dc4cfed239dff642d29fbc46",
             "cd490ae08bd2ff18e8b61c39173f6bf0db85709130baa103b9f00e4160ec150f"
             ),
            ("8e651d540f55a4670bb5ec8cd0812731ce734a1e745059c4f445fd8cd8fcb604",
             "ab7f8d9e7927a1a71b7b08eb3b871246dc4717d9e309b7682df0eee202a5a97a",
             "e55323d6881ca92a0816695def558145ef22f0d0c4f6133aab7a8a3f2f98ef78",
             "6c9313fcf93b55a977184514aefa1c778c1abadb2ba9f2c1351b587b7c1e1572"
             ),
        ]

        for i, (priv, ext, pub, chain) in enumerate(nodes):
            _, n = derive_address_and_node(
                node, [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i])
            self.assertEqual(unhexlify(priv), n.private_key())
            self.assertEqual(unhexlify(ext), n.private_key_ext())
            self.assertEqual(unhexlify(pub),
                             seed.remove_ed25519_prefix(n.public_key()))
            self.assertEqual(unhexlify(chain), n.chain_code())
Пример #29
0
async def get_address(ctx, msg, keychain):
    await paths.validate_path(ctx, helpers.validate_full_path, keychain,
                              msg.address_n, CURVE)

    node = keychain.derive(msg.address_n, CURVE)

    pk = seed.remove_ed25519_prefix(node.public_key())
    pkh = hashlib.blake2b(pk, outlen=20).digest()
    address = helpers.base58_encode_check(
        pkh, prefix=helpers.TEZOS_ED25519_ADDRESS_PREFIX)

    if msg.show_display:
        desc = address_n_to_str(msg.address_n)
        while True:
            if await show_address(ctx, address, desc=desc):
                break
            if await show_qr(ctx, address, desc=desc):
                break

    return TezosAddress(address=address)
Пример #30
0
async def sign_tx(ctx, msg: StellarSignTx):
    if msg.num_operations == 0:
        raise ProcessError("Stellar: At least one operation is required")

    node = await seed.derive_node(ctx, msg.address_n, consts.STELLAR_CURVE)
    pubkey = seed.remove_ed25519_prefix(node.public_key())

    w = bytearray()
    await _init(ctx, w, pubkey, msg)
    _timebounds(w, msg.timebounds_start, msg.timebounds_end)
    await _memo(ctx, w, msg)
    await _operations(ctx, w, msg.num_operations)
    await _final(ctx, w, msg)

    # sign
    digest = sha256(w).digest()
    signature = ed25519.sign(node.private_key(), digest)

    # Add the public key for verification that the right account was used for signing
    return StellarSignedTx(pubkey, signature)