feat(python): support Cardano derivation type arguments

pull/1882/head
matejcik 3 years ago committed by matejcik
parent 72924a016f
commit f8b9cda05d

@ -123,9 +123,10 @@ Cardano commands.
--help Show this message and exit. --help Show this message and exit.
Commands: Commands:
get-address Get Cardano address. get-address Get Cardano address.
get-public-key Get Cardano public key. get-native-script-hash Get Cardano native script hash.
sign-tx Sign Cardano transaction. get-public-key Get Cardano public key.
sign-tx Sign Cardano transaction.
CoSi (Cothority / collective signing) commands. CoSi (Cothority / collective signing) commands.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@ -611,6 +611,7 @@ def get_address(
protocol_magic: int = PROTOCOL_MAGICS["mainnet"], protocol_magic: int = PROTOCOL_MAGICS["mainnet"],
network_id: int = NETWORK_IDS["mainnet"], network_id: int = NETWORK_IDS["mainnet"],
show_display: bool = False, show_display: bool = False,
derivation_type: messages.CardanoDerivationType = messages.CardanoDerivationType.ICARUS,
) -> messages.CardanoAddress: ) -> messages.CardanoAddress:
return client.call( return client.call(
messages.CardanoGetAddress( messages.CardanoGetAddress(
@ -618,13 +619,22 @@ def get_address(
protocol_magic=protocol_magic, protocol_magic=protocol_magic,
network_id=network_id, network_id=network_id,
show_display=show_display, show_display=show_display,
derivation_type=derivation_type,
) )
) )
@expect(messages.CardanoPublicKey) @expect(messages.CardanoPublicKey)
def get_public_key(client, address_n: List[int]) -> messages.CardanoPublicKey: def get_public_key(
return client.call(messages.CardanoGetPublicKey(address_n=address_n)) client,
address_n: List[int],
derivation_type: messages.CardanoDerivationType = messages.CardanoDerivationType.ICARUS,
) -> messages.CardanoPublicKey:
return client.call(
messages.CardanoGetPublicKey(
address_n=address_n, derivation_type=derivation_type
)
)
@expect(messages.CardanoNativeScriptHash) @expect(messages.CardanoNativeScriptHash)
@ -632,11 +642,13 @@ def get_native_script_hash(
client, client,
native_script: messages.CardanoNativeScript, native_script: messages.CardanoNativeScript,
display_format: messages.CardanoNativeScriptHashDisplayFormat = messages.CardanoNativeScriptHashDisplayFormat.HIDE, display_format: messages.CardanoNativeScriptHashDisplayFormat = messages.CardanoNativeScriptHashDisplayFormat.HIDE,
derivation_type: messages.CardanoDerivationType = messages.CardanoDerivationType.ICARUS,
) -> messages.CardanoNativeScriptHash: ) -> messages.CardanoNativeScriptHash:
return client.call( return client.call(
messages.CardanoGetNativeScriptHash( messages.CardanoGetNativeScriptHash(
script=native_script, script=native_script,
display_format=display_format, display_format=display_format,
derivation_type=derivation_type,
) )
) )
@ -656,6 +668,7 @@ def sign_tx(
auxiliary_data: messages.CardanoTxAuxiliaryData = None, auxiliary_data: messages.CardanoTxAuxiliaryData = None,
mint: List[AssetGroupWithTokens] = (), mint: List[AssetGroupWithTokens] = (),
additional_witness_requests: List[Path] = (), additional_witness_requests: List[Path] = (),
derivation_type: messages.CardanoDerivationType = messages.CardanoDerivationType.ICARUS,
) -> SignTxResponse: ) -> SignTxResponse:
UNEXPECTED_RESPONSE_ERROR = exceptions.TrezorException("Unexpected response") UNEXPECTED_RESPONSE_ERROR = exceptions.TrezorException("Unexpected response")
@ -678,6 +691,7 @@ def sign_tx(
has_auxiliary_data=auxiliary_data is not None, has_auxiliary_data=auxiliary_data is not None,
minting_asset_groups_count=len(mint), minting_asset_groups_count=len(mint),
witness_requests_count=len(witness_requests), witness_requests_count=len(witness_requests),
derivation_type=derivation_type,
) )
) )
if not isinstance(response, messages.CardanoTxItemAck): if not isinstance(response, messages.CardanoTxItemAck):

@ -43,8 +43,16 @@ def cli():
) )
@click.option("-N", "--network-id", type=int, default=cardano.NETWORK_IDS["mainnet"]) @click.option("-N", "--network-id", type=int, default=cardano.NETWORK_IDS["mainnet"])
@click.option("-t", "--testnet", is_flag=True) @click.option("-t", "--testnet", is_flag=True)
@click.option(
"-D",
"--derivation-type",
type=ChoiceType({m.name: m for m in messages.CardanoDerivationType}),
default=messages.CardanoDerivationType.ICARUS,
)
@with_client @with_client
def sign_tx(client, file, signing_mode, protocol_magic, network_id, testnet): def sign_tx(
client, file, signing_mode, protocol_magic, network_id, testnet, derivation_type
):
"""Sign Cardano transaction.""" """Sign Cardano transaction."""
transaction = json.load(file) transaction = json.load(file)
@ -72,6 +80,7 @@ def sign_tx(client, file, signing_mode, protocol_magic, network_id, testnet):
for p in transaction["additional_witness_requests"] for p in transaction["additional_witness_requests"]
] ]
client.init_device(derive_cardano=True)
sign_tx_response = cardano.sign_tx( sign_tx_response = cardano.sign_tx(
client, client,
signing_mode, signing_mode,
@ -87,6 +96,7 @@ def sign_tx(client, file, signing_mode, protocol_magic, network_id, testnet):
auxiliary_data, auxiliary_data,
mint, mint,
additional_witness_requests, additional_witness_requests,
derivation_type=derivation_type,
) )
sign_tx_response["tx_hash"] = sign_tx_response["tx_hash"].hex() sign_tx_response["tx_hash"] = sign_tx_response["tx_hash"].hex()
@ -134,6 +144,12 @@ def sign_tx(client, file, signing_mode, protocol_magic, network_id, testnet):
) )
@click.option("-N", "--network-id", type=int, default=cardano.NETWORK_IDS["mainnet"]) @click.option("-N", "--network-id", type=int, default=cardano.NETWORK_IDS["mainnet"])
@click.option("-e", "--testnet", is_flag=True) @click.option("-e", "--testnet", is_flag=True)
@click.option(
"-D",
"--derivation-type",
type=ChoiceType({m.name: m for m in messages.CardanoDerivationType}),
default=messages.CardanoDerivationType.ICARUS,
)
@with_client @with_client
def get_address( def get_address(
client, client,
@ -150,6 +166,7 @@ def get_address(
network_id, network_id,
show_display, show_display,
testnet, testnet,
derivation_type,
): ):
""" """
Get Cardano address. Get Cardano address.
@ -185,18 +202,31 @@ def get_address(
script_staking_hash_bytes, script_staking_hash_bytes,
) )
client.init_device(derive_cardano=True)
return cardano.get_address( return cardano.get_address(
client, address_parameters, protocol_magic, network_id, show_display client,
address_parameters,
protocol_magic,
network_id,
show_display,
derivation_type=derivation_type,
) )
@cli.command() @cli.command()
@click.option("-n", "--address", required=True, help=PATH_HELP) @click.option("-n", "--address", required=True, help=PATH_HELP)
@click.option(
"-D",
"--derivation-type",
type=ChoiceType({m.name: m for m in messages.CardanoDerivationType}),
default=messages.CardanoDerivationType.ICARUS,
)
@with_client @with_client
def get_public_key(client, address): def get_public_key(client, address, derivation_type):
"""Get Cardano public key.""" """Get Cardano public key."""
address_n = tools.parse_path(address) address_n = tools.parse_path(address)
return cardano.get_public_key(client, address_n) client.init_device(derive_cardano=True)
return cardano.get_public_key(client, address_n, derivation_type=derivation_type)
@cli.command() @cli.command()
@ -207,10 +237,19 @@ def get_public_key(client, address):
type=ChoiceType({m.name: m for m in messages.CardanoNativeScriptHashDisplayFormat}), type=ChoiceType({m.name: m for m in messages.CardanoNativeScriptHashDisplayFormat}),
default="HIDE", default="HIDE",
) )
@click.option(
"-D",
"--derivation-type",
type=ChoiceType({m.name: m for m in messages.CardanoDerivationType}),
default=messages.CardanoDerivationType.ICARUS,
)
@with_client @with_client
def get_native_script_hash(client, file, display_format): def get_native_script_hash(client, file, display_format, derivation_type):
"""Get Cardano native script hash.""" """Get Cardano native script hash."""
native_script_json = json.load(file) native_script_json = json.load(file)
native_script = cardano.parse_native_script(native_script_json) native_script = cardano.parse_native_script(native_script_json)
return cardano.get_native_script_hash(client, native_script, display_format) client.init_device(derive_cardano=True)
return cardano.get_native_script_hash(
client, native_script, display_format, derivation_type=derivation_type
)

Loading…
Cancel
Save