|
|
@ -13,6 +13,7 @@
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
import base64
|
|
|
|
import base64
|
|
|
|
import json
|
|
|
|
import json
|
|
|
@ -22,10 +23,10 @@ import click
|
|
|
|
import construct as c
|
|
|
|
import construct as c
|
|
|
|
|
|
|
|
|
|
|
|
from .. import btc, messages, protobuf, tools
|
|
|
|
from .. import btc, messages, protobuf, tools
|
|
|
|
from . import ChoiceType, with_client
|
|
|
|
from . import ChoiceType, with_session
|
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..client import TrezorClient
|
|
|
|
from ..transport.new.session import Session
|
|
|
|
|
|
|
|
|
|
|
|
PURPOSE_BIP44 = 44
|
|
|
|
PURPOSE_BIP44 = 44
|
|
|
|
PURPOSE_BIP48 = 48
|
|
|
|
PURPOSE_BIP48 = 48
|
|
|
@ -168,15 +169,15 @@ def cli() -> None:
|
|
|
|
default=2,
|
|
|
|
default=2,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@click.option("-C", "--chunkify", is_flag=True)
|
|
|
|
@click.option("-C", "--chunkify", is_flag=True)
|
|
|
|
@with_client
|
|
|
|
@with_session
|
|
|
|
def get_address(
|
|
|
|
def get_address(
|
|
|
|
client: "TrezorClient",
|
|
|
|
session: "Session",
|
|
|
|
coin: str,
|
|
|
|
coin: str,
|
|
|
|
address: str,
|
|
|
|
address: str,
|
|
|
|
script_type: Optional[messages.InputScriptType],
|
|
|
|
script_type: messages.InputScriptType | None,
|
|
|
|
show_display: bool,
|
|
|
|
show_display: bool,
|
|
|
|
multisig_xpub: List[str],
|
|
|
|
multisig_xpub: List[str],
|
|
|
|
multisig_threshold: Optional[int],
|
|
|
|
multisig_threshold: int | None,
|
|
|
|
multisig_suffix_length: int,
|
|
|
|
multisig_suffix_length: int,
|
|
|
|
chunkify: bool,
|
|
|
|
chunkify: bool,
|
|
|
|
) -> str:
|
|
|
|
) -> str:
|
|
|
@ -220,7 +221,7 @@ def get_address(
|
|
|
|
multisig = None
|
|
|
|
multisig = None
|
|
|
|
|
|
|
|
|
|
|
|
return btc.get_address(
|
|
|
|
return btc.get_address(
|
|
|
|
client,
|
|
|
|
session,
|
|
|
|
coin,
|
|
|
|
coin,
|
|
|
|
address_n,
|
|
|
|
address_n,
|
|
|
|
show_display,
|
|
|
|
show_display,
|
|
|
@ -237,9 +238,9 @@ def get_address(
|
|
|
|
@click.option("-e", "--curve")
|
|
|
|
@click.option("-e", "--curve")
|
|
|
|
@click.option("-t", "--script-type", type=ChoiceType(INPUT_SCRIPTS))
|
|
|
|
@click.option("-t", "--script-type", type=ChoiceType(INPUT_SCRIPTS))
|
|
|
|
@click.option("-d", "--show-display", is_flag=True)
|
|
|
|
@click.option("-d", "--show-display", is_flag=True)
|
|
|
|
@with_client
|
|
|
|
@with_session
|
|
|
|
def get_public_node(
|
|
|
|
def get_public_node(
|
|
|
|
client: "TrezorClient",
|
|
|
|
session: "Session",
|
|
|
|
coin: str,
|
|
|
|
coin: str,
|
|
|
|
address: str,
|
|
|
|
address: str,
|
|
|
|
curve: Optional[str],
|
|
|
|
curve: Optional[str],
|
|
|
@ -251,7 +252,7 @@ def get_public_node(
|
|
|
|
if script_type is None:
|
|
|
|
if script_type is None:
|
|
|
|
script_type = guess_script_type_from_path(address_n)
|
|
|
|
script_type = guess_script_type_from_path(address_n)
|
|
|
|
result = btc.get_public_node(
|
|
|
|
result = btc.get_public_node(
|
|
|
|
client,
|
|
|
|
session,
|
|
|
|
address_n,
|
|
|
|
address_n,
|
|
|
|
ecdsa_curve_name=curve,
|
|
|
|
ecdsa_curve_name=curve,
|
|
|
|
show_display=show_display,
|
|
|
|
show_display=show_display,
|
|
|
@ -277,7 +278,7 @@ def _append_descriptor_checksum(desc: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_descriptor(
|
|
|
|
def _get_descriptor(
|
|
|
|
client: "TrezorClient",
|
|
|
|
session: "Session",
|
|
|
|
coin: Optional[str],
|
|
|
|
coin: Optional[str],
|
|
|
|
account: int,
|
|
|
|
account: int,
|
|
|
|
purpose: Optional[int],
|
|
|
|
purpose: Optional[int],
|
|
|
@ -311,7 +312,7 @@ def _get_descriptor(
|
|
|
|
|
|
|
|
|
|
|
|
n = tools.parse_path(path)
|
|
|
|
n = tools.parse_path(path)
|
|
|
|
pub = btc.get_public_node(
|
|
|
|
pub = btc.get_public_node(
|
|
|
|
client,
|
|
|
|
session,
|
|
|
|
n,
|
|
|
|
n,
|
|
|
|
show_display=show_display,
|
|
|
|
show_display=show_display,
|
|
|
|
coin_name=coin,
|
|
|
|
coin_name=coin,
|
|
|
@ -348,9 +349,9 @@ def _get_descriptor(
|
|
|
|
@click.option("-a", "--account-type", type=ChoiceType(ACCOUNT_TYPE_TO_BIP_PURPOSE))
|
|
|
|
@click.option("-a", "--account-type", type=ChoiceType(ACCOUNT_TYPE_TO_BIP_PURPOSE))
|
|
|
|
@click.option("-t", "--script-type", type=ChoiceType(INPUT_SCRIPTS))
|
|
|
|
@click.option("-t", "--script-type", type=ChoiceType(INPUT_SCRIPTS))
|
|
|
|
@click.option("-d", "--show-display", is_flag=True)
|
|
|
|
@click.option("-d", "--show-display", is_flag=True)
|
|
|
|
@with_client
|
|
|
|
@with_session
|
|
|
|
def get_descriptor(
|
|
|
|
def get_descriptor(
|
|
|
|
client: "TrezorClient",
|
|
|
|
session: "Session",
|
|
|
|
coin: Optional[str],
|
|
|
|
coin: Optional[str],
|
|
|
|
account: int,
|
|
|
|
account: int,
|
|
|
|
account_type: Optional[int],
|
|
|
|
account_type: Optional[int],
|
|
|
@ -360,7 +361,7 @@ def get_descriptor(
|
|
|
|
"""Get descriptor of given account."""
|
|
|
|
"""Get descriptor of given account."""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
return _get_descriptor(
|
|
|
|
return _get_descriptor(
|
|
|
|
client, coin, account, account_type, script_type, show_display
|
|
|
|
session, coin, account, account_type, script_type, show_display
|
|
|
|
)
|
|
|
|
)
|
|
|
|
except ValueError as e:
|
|
|
|
except ValueError as e:
|
|
|
|
raise click.ClickException(str(e))
|
|
|
|
raise click.ClickException(str(e))
|
|
|
@ -375,8 +376,8 @@ def get_descriptor(
|
|
|
|
@click.option("-c", "--coin", is_flag=True, hidden=True, expose_value=False)
|
|
|
|
@click.option("-c", "--coin", is_flag=True, hidden=True, expose_value=False)
|
|
|
|
@click.option("-C", "--chunkify", is_flag=True)
|
|
|
|
@click.option("-C", "--chunkify", is_flag=True)
|
|
|
|
@click.argument("json_file", type=click.File())
|
|
|
|
@click.argument("json_file", type=click.File())
|
|
|
|
@with_client
|
|
|
|
@with_session
|
|
|
|
def sign_tx(client: "TrezorClient", json_file: TextIO, chunkify: bool) -> None:
|
|
|
|
def sign_tx(session: "Session", json_file: TextIO, chunkify: bool) -> None:
|
|
|
|
"""Sign transaction.
|
|
|
|
"""Sign transaction.
|
|
|
|
|
|
|
|
|
|
|
|
Transaction data must be provided in a JSON file. See `transaction-format.md` for
|
|
|
|
Transaction data must be provided in a JSON file. See `transaction-format.md` for
|
|
|
@ -401,7 +402,7 @@ def sign_tx(client: "TrezorClient", json_file: TextIO, chunkify: bool) -> None:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
session,
|
|
|
|
coin,
|
|
|
|
coin,
|
|
|
|
inputs,
|
|
|
|
inputs,
|
|
|
|
outputs,
|
|
|
|
outputs,
|
|
|
@ -432,9 +433,9 @@ def sign_tx(client: "TrezorClient", json_file: TextIO, chunkify: bool) -> None:
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@click.option("-C", "--chunkify", is_flag=True)
|
|
|
|
@click.option("-C", "--chunkify", is_flag=True)
|
|
|
|
@click.argument("message")
|
|
|
|
@click.argument("message")
|
|
|
|
@with_client
|
|
|
|
@with_session
|
|
|
|
def sign_message(
|
|
|
|
def sign_message(
|
|
|
|
client: "TrezorClient",
|
|
|
|
session: "Session",
|
|
|
|
coin: str,
|
|
|
|
coin: str,
|
|
|
|
address: str,
|
|
|
|
address: str,
|
|
|
|
message: str,
|
|
|
|
message: str,
|
|
|
@ -447,7 +448,7 @@ def sign_message(
|
|
|
|
if script_type is None:
|
|
|
|
if script_type is None:
|
|
|
|
script_type = guess_script_type_from_path(address_n)
|
|
|
|
script_type = guess_script_type_from_path(address_n)
|
|
|
|
res = btc.sign_message(
|
|
|
|
res = btc.sign_message(
|
|
|
|
client,
|
|
|
|
session,
|
|
|
|
coin,
|
|
|
|
coin,
|
|
|
|
address_n,
|
|
|
|
address_n,
|
|
|
|
message,
|
|
|
|
message,
|
|
|
@ -468,9 +469,9 @@ def sign_message(
|
|
|
|
@click.argument("address")
|
|
|
|
@click.argument("address")
|
|
|
|
@click.argument("signature")
|
|
|
|
@click.argument("signature")
|
|
|
|
@click.argument("message")
|
|
|
|
@click.argument("message")
|
|
|
|
@with_client
|
|
|
|
@with_session
|
|
|
|
def verify_message(
|
|
|
|
def verify_message(
|
|
|
|
client: "TrezorClient",
|
|
|
|
session: "Session",
|
|
|
|
coin: str,
|
|
|
|
coin: str,
|
|
|
|
address: str,
|
|
|
|
address: str,
|
|
|
|
signature: str,
|
|
|
|
signature: str,
|
|
|
@ -480,7 +481,7 @@ def verify_message(
|
|
|
|
"""Verify message."""
|
|
|
|
"""Verify message."""
|
|
|
|
signature_bytes = base64.b64decode(signature)
|
|
|
|
signature_bytes = base64.b64decode(signature)
|
|
|
|
return btc.verify_message(
|
|
|
|
return btc.verify_message(
|
|
|
|
client, coin, address, signature_bytes, message, chunkify=chunkify
|
|
|
|
session, coin, address, signature_bytes, message, chunkify=chunkify
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|