async def get_public_key(ctx, msg):
    coin_name = msg.coin_name or 'Bitcoin'

    curve_name = msg.ecdsa_curve_name
    if not curve_name:
        node = await seed.derive_node(ctx, msg.address_n)
    else:
        node = await seed.derive_node(ctx,
                                      msg.address_n,
                                      curve_name=curve_name)
    coin = coins.by_name(coin_name)

    node_xpub = node.serialize_public(coin.xpub_magic)
    pubkey = node.public_key()
    if pubkey[0] == 1:
        pubkey = b'\x00' + pubkey[1:]
    node_type = HDNodeType(depth=node.depth(),
                           child_num=node.child_num(),
                           fingerprint=node.fingerprint(),
                           chain_code=node.chain_code(),
                           public_key=pubkey)

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

    return PublicKey(node=node_type, xpub=node_xpub)
Beispiel #2
0
async def get_public_key(ctx, msg):
    script_type = msg.script_type or InputScriptType.SPENDADDRESS

    if msg.ecdsa_curve_name is not None:
        # If a curve name is provided, disallow coin-specific features.
        if (
            msg.coin_name is not None
            or msg.script_type is not InputScriptType.SPENDADDRESS
        ):
            raise wire.DataError(
                "Cannot use coin_name or script_type with ecdsa_curve_name"
            )

        coin = coins.by_name("Bitcoin")
        # only allow SLIP-13/17 namespaces
        keychain = await get_keychain_for_curve(ctx, msg.ecdsa_curve_name)

    else:
        # select curve and namespaces based on the requested coin properties
        keychain, coin = await get_keychain_for_coin(ctx, msg.coin_name)

    node = keychain.derive(msg.address_n)

    if (
        script_type in [InputScriptType.SPENDADDRESS, InputScriptType.SPENDMULTISIG]
        and coin.xpub_magic is not None
    ):
        node_xpub = node.serialize_public(coin.xpub_magic)
    elif (
        coin.segwit
        and script_type == InputScriptType.SPENDP2SHWITNESS
        and coin.xpub_magic_segwit_p2sh is not None
    ):
        node_xpub = node.serialize_public(coin.xpub_magic_segwit_p2sh)
    elif (
        coin.segwit
        and script_type == InputScriptType.SPENDWITNESS
        and coin.xpub_magic_segwit_native is not None
    ):
        node_xpub = node.serialize_public(coin.xpub_magic_segwit_native)
    else:
        raise wire.DataError("Invalid combination of coin and script_type")

    pubkey = node.public_key()
    if pubkey[0] == 1:
        pubkey = b"\x00" + pubkey[1:]
    node_type = HDNodeType(
        depth=node.depth(),
        child_num=node.child_num(),
        fingerprint=node.fingerprint(),
        chain_code=node.chain_code(),
        public_key=pubkey,
    )

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

    return PublicKey(node=node_type, xpub=node_xpub)
Beispiel #3
0
async def get_public_key(ctx: wire.Context, msg: GetPublicKey) -> PublicKey:
    coin_name = msg.coin_name or "Bitcoin"
    script_type = msg.script_type or InputScriptType.SPENDADDRESS
    coin = coininfo.by_name(coin_name)
    curve_name = msg.ecdsa_curve_name or coin.curve_name

    keychain = await get_keychain(ctx, curve_name, [paths.AlwaysMatchingSchema])

    node = keychain.derive(msg.address_n)

    if (
        script_type in (InputScriptType.SPENDADDRESS, InputScriptType.SPENDMULTISIG)
        and coin.xpub_magic is not None
    ):
        node_xpub = node.serialize_public(coin.xpub_magic)
    elif (
        coin.segwit
        and script_type == InputScriptType.SPENDP2SHWITNESS
        and (msg.ignore_xpub_magic or coin.xpub_magic_segwit_p2sh is not None)
    ):
        # TODO: resolve type: ignore below
        node_xpub = node.serialize_public(
            coin.xpub_magic if msg.ignore_xpub_magic else coin.xpub_magic_segwit_p2sh  # type: ignore
        )
    elif (
        coin.segwit
        and script_type == InputScriptType.SPENDWITNESS
        and (msg.ignore_xpub_magic or coin.xpub_magic_segwit_native is not None)
    ):
        # TODO: resolve type: ignore below
        node_xpub = node.serialize_public(
            coin.xpub_magic if msg.ignore_xpub_magic else coin.xpub_magic_segwit_native  # type: ignore
        )
    else:
        raise wire.DataError("Invalid combination of coin and script_type")

    pubkey = node.public_key()
    if pubkey[0] == 1:
        pubkey = b"\x00" + pubkey[1:]
    node_type = HDNodeType(
        depth=node.depth(),
        child_num=node.child_num(),
        fingerprint=node.fingerprint(),
        chain_code=node.chain_code(),
        public_key=pubkey,
    )

    if msg.show_display:
        from trezor.ui.layouts import show_xpub

        await show_xpub(ctx, node_xpub, "XPUB", "Cancel")

    return PublicKey(
        node=node_type,
        xpub=node_xpub,
        root_fingerprint=keychain.root_fingerprint(),
    )
async def get_public_key(ctx, msg):
    coin_name = msg.coin_name or 'Bitcoin'

    node = await seed.derive_node(ctx, msg.address_n)
    coin = coins.by_name(coin_name)

    node_xpub = node.serialize_public(coin.xpub_magic)
    node_type = HDNodeType(depth=node.depth(),
                           child_num=node.child_num(),
                           fingerprint=node.fingerprint(),
                           chain_code=node.chain_code(),
                           public_key=node.public_key())
    return PublicKey(node=node_type, xpub=node_xpub)
Beispiel #5
0
async def layout_get_public_key(session_id, msg):
    from trezor.messages.HDNodeType import HDNodeType
    from trezor.messages.PublicKey import PublicKey
    from ..common import seed

    node = await seed.get_root(session_id)
    node.derive_path(msg.address_n or ())

    node_xpub = node.serialize_public()
    node_type = HDNodeType(depth=node.depth(),
                           child_num=node.child_num(),
                           fingerprint=node.fingerprint(),
                           chain_code=node.chain_code(),
                           public_key=node.public_key())
    return PublicKey(node=node_type, xpub=node_xpub)
Beispiel #6
0
async def layout_get_public_key(ctx, msg):
    from trezor.messages.HDNodeType import HDNodeType
    from trezor.messages.PublicKey import PublicKey
    from ..common import coins
    from ..common import seed

    address_n = msg.address_n or ()
    coin_name = msg.coin_name or 'Bitcoin'

    node = await seed.derive_node(ctx, address_n)
    coin = coins.by_name(coin_name)

    node_xpub = node.serialize_public(coin.xpub_magic)
    node_type = HDNodeType(
        depth=node.depth(),
        child_num=node.child_num(),
        fingerprint=node.fingerprint(),
        chain_code=node.chain_code(),
        public_key=node.public_key())
    return PublicKey(node=node_type, xpub=node_xpub)
Beispiel #7
0
async def get_public_key(ctx: wire.Context, msg: GetPublicKey) -> PublicKey:
    coin_name = msg.coin_name or "Bitcoin"
    script_type = msg.script_type or InputScriptType.SPENDADDRESS
    coin = coins.by_name(coin_name)
    curve_name = msg.ecdsa_curve_name or coin.curve_name

    keychain = await get_keychain(ctx, curve_name,
                                  [paths.AlwaysMatchingSchema])

    node = keychain.derive(msg.address_n)

    if (script_type
            in [InputScriptType.SPENDADDRESS, InputScriptType.SPENDMULTISIG]
            and coin.xpub_magic is not None):
        node_xpub = node.serialize_public(coin.xpub_magic)
    elif (coin.segwit and script_type == InputScriptType.SPENDP2SHWITNESS
          and coin.xpub_magic_segwit_p2sh is not None):
        node_xpub = node.serialize_public(coin.xpub_magic_segwit_p2sh)
    elif (coin.segwit and script_type == InputScriptType.SPENDWITNESS
          and coin.xpub_magic_segwit_native is not None):
        node_xpub = node.serialize_public(coin.xpub_magic_segwit_native)
    else:
        raise wire.DataError("Invalid combination of coin and script_type")

    pubkey = node.public_key()
    if pubkey[0] == 1:
        pubkey = b"\x00" + pubkey[1:]
    node_type = HDNodeType(
        depth=node.depth(),
        child_num=node.child_num(),
        fingerprint=node.fingerprint(),
        chain_code=node.chain_code(),
        public_key=pubkey,
    )

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

    return PublicKey(node=node_type, xpub=node_xpub)
Beispiel #8
0
async def get_public_key(ctx, msg):
    coin_name = msg.coin_name or "Bitcoin"
    coin = coins.by_name(coin_name)
    script_type = msg.script_type or InputScriptType.SPENDADDRESS

    curve_name = msg.ecdsa_curve_name
    if not curve_name:
        curve_name = coin.curve_name
    node = await seed.derive_node(ctx, msg.address_n, curve_name=curve_name)

    if (script_type
            in [InputScriptType.SPENDADDRESS, InputScriptType.SPENDMULTISIG]
            and coin.xpub_magic is not None):
        node_xpub = node.serialize_public(coin.xpub_magic)
    elif (coin.segwit and script_type == InputScriptType.SPENDP2SHWITNESS
          and coin.xpub_magic_segwit_p2sh is not None):
        node_xpub = node.serialize_public(coin.xpub_magic_segwit_p2sh)
    elif (coin.segwit and script_type == InputScriptType.SPENDWITNESS
          and coin.xpub_magic_segwit_native is not None):
        node_xpub = node.serialize_public(coin.xpub_magic_segwit_native)
    else:
        raise wire.DataError("Invalid combination of coin and script_type")

    pubkey = node.public_key()
    if pubkey[0] == 1:
        pubkey = b"\x00" + pubkey[1:]
    node_type = HDNodeType(
        depth=node.depth(),
        child_num=node.child_num(),
        fingerprint=node.fingerprint(),
        chain_code=node.chain_code(),
        public_key=pubkey,
    )

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

    return PublicKey(node=node_type, xpub=node_xpub)