Skip to content

Commit

Permalink
release: 0.7.0 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored May 7, 2024
1 parent 6d18245 commit cb8b847
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 108 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Commands:
get-address Get Stellar public address.
sign-auth Sign a base64-encoded soroban authorization...
sign-tx Sign a base64-encoded transaction envelope.
sign-tx-hash Sign a hex encoded transaction hash.
sign-tx-hash Sign a hex encoded hash.
version Get strledger version info.
```

Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tool.poetry]
name = "strledger"
version = "0.6.2"
version = "0.7.0"
description = "Sign Stellar Transaction with Ledger on the command line."
authors = ["overcat <4catcode@gmail.com>"]
license = "MIT License"
readme = "README.md"
homepage = "https://github.com/overcat/strledger"
repository = "https://github.com/overcat/strledger"
documentation = "https://github.com/overcat/strledger"
homepage = "https://github.com/lightsail-network/strledger"
repository = "https://github.com/lightsail-network/strledger"
documentation = "https://github.com/lightsail-network/strledger"
keywords = ["stellar", "ledger"]
include = ["strledger/py.typed", "LICENSE"]
classifiers = [
Expand Down
2 changes: 1 addition & 1 deletion strledger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.6.2"
__version__ = "0.7.0"
__issue__ = "https://github.com/lightsail-network/strledger/issues"

from strledger.core import *
125 changes: 71 additions & 54 deletions strledger/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,62 +140,59 @@ def sign_transaction(
"through XDR Viewer - https://laboratory.stellar.org/#xdr-viewer"
)
sys.exit(1)

tx_hash = te.hash_hex()
echo_normal(f"Network Passphrase: {network_passphrase}")
echo_normal(f"Transaction Hash: {tx_hash}")
echo_normal("Please confirm this transaction on Ledger.")
echo_normal("Please confirm the transaction on Ledger.")

if hash_signing:
try:
signature = client.sign_transaction_hash(tx_hash, keypair_index)
except CommException as e:
if e.sw == SW.TX_HASH_SIGNING_MODE_NOT_ENABLED:
echo_error(
"Hash signing is not enabled on this device.\n"
"Please enable it on the device and try again."
)
elif e.sw == SW.DENY:
echo_error("The request to sign the transaction hash was denied.")
sys.exit(1)
else:
raise e
keypair = client.get_keypair(keypair_index=keypair_index)
decorated_signature = DecoratedSignature(keypair.signature_hint(), signature)
te.signatures.append(decorated_signature)
else:
try:
try:
if hash_signing:
signature = client.sign_hash(tx_hash, keypair_index)
keypair = client.get_keypair(keypair_index=keypair_index)
decorated_signature = DecoratedSignature(
keypair.signature_hint(), signature
)
te.signatures.append(decorated_signature)
else:
assert isinstance(te, (TransactionEnvelope, FeeBumpTransactionEnvelope))
client.sign_transaction(
transaction_envelope=te, keypair_index=keypair_index
)
except CommException as e:
if e.sw == SW.DENY:
echo_error("The request to sign the transaction was denied.")
elif e.sw == SW.UNKNOWN_OP:
echo_error("The transaction contains unsupported operation(s).")
elif e.sw == SW.UNKNOWN_ENVELOPE_TYPE:
echo_error(
"The transaction contains unsupported transaction envelope type."
)
else:
echo_error(f"Unknown exception, you can the problem here: {__issue__}")
raise
sys.exit(1)
except CommException as e:
if hash_signing and e.sw == SW.TX_HASH_SIGNING_MODE_NOT_ENABLED:
echo_error(
"Hash signing is not enabled on this device.\n"
"Please enable it on the device and try again."
)
elif e.sw == SW.DENY:
echo_error("The request to sign the transaction was denied.")
elif e.sw == SW.SW_REQUEST_DATA_TOO_LARGE:
echo_error(
"The request data is too large, please try to sign a smaller transaction, or sign the hash only."
)
else:
echo_error(
f"Unknown exception, you can report the problem here: {__issue__}"
)
raise
sys.exit(1)

echo_success("Signed successfully.")
echo_success("Base64-encoded signed transaction envelope:")
echo_success(te.to_xdr())

if submit:
echo_normal("Submitting to the network...")
server = Server(horizon_url)
try:
server.submit_transaction(te)
except BaseRequestError as e:
echo_error("submit failed, error info:")
echo_error("Submit failed, error info:")
echo_error(e)
sys.exit(1)

echo_success(f"Successfully submitted.")
echo_success("Successfully submitted.")
if network_passphrase == Network.PUBLIC_NETWORK_PASSPHRASE:
url = f"https://stellar.expert/explorer/public/tx/{tx_hash}"
elif network_passphrase == Network.TESTNET_NETWORK_PASSPHRASE:
Expand All @@ -205,7 +202,7 @@ def sign_transaction(
echo_success(f"Stellar Explorer: {url}")


@cli.command(name="sign-tx-hash")
@cli.command(name="sign-hash")
@click.option(
"-i",
"--keypair-index",
Expand All @@ -215,17 +212,17 @@ def sign_transaction(
default=DEFAULT_KEYPAIR_INDEX,
show_default=True,
)
@click.argument("transaction_hash")
@click.argument("hash")
@click.pass_obj
def sign_transaction_hash(
def sign_hash(
get_client: Callable[[], StrLedger],
transaction_hash: str,
hash: str,
keypair_index: int,
):
"""Sign a hex encoded transaction hash."""
"""Sign a hex encoded hash."""
client = get_client()
try:
signature = client.sign_transaction_hash(transaction_hash, keypair_index)
signature = client.sign_hash(hash, keypair_index)
except CommException as e:
if e.sw == SW.TX_HASH_SIGNING_MODE_NOT_ENABLED:
echo_error(
Expand All @@ -234,9 +231,9 @@ def sign_transaction_hash(
)
elif e.sw == SW.DENY:
echo_error("The request to sign the transaction hash was denied.")
sys.exit(1)
else:
raise e
sys.exit(1)
signature_base64 = base64.b64encode(signature).decode()
echo_success(signature_base64)

Expand Down Expand Up @@ -279,11 +276,18 @@ def get_address(
default=DEFAULT_KEYPAIR_INDEX,
show_default=True,
)
@click.option(
"-a",
"--hash-signing",
is_flag=True,
help="Only send the hash to the device for signing.",
)
@click.argument("soroban_authorization")
@click.pass_obj
def sign_soroban_authorization(
get_client: Callable[[], StrLedger],
keypair_index: int,
hash_signing: bool,
soroban_authorization: str,
):
"""Sign a base64-encoded soroban authorization (HashIDPreimage)."""
Expand All @@ -297,27 +301,40 @@ def sign_soroban_authorization(
)
sys.exit(1)

echo_normal(f"HashIDPreimage Hash: {sha256(auth.to_xdr_bytes()).hex()}")
echo_normal("Please confirm this transaction on Ledger.")
preimage_hash = sha256(auth.to_xdr_bytes()).hex()
echo_normal(f"HashIDPreimage Hash: {preimage_hash}")
echo_normal("Please confirm the Soroban authorization on Ledger.")

signature = None
try:
signature = client.sign_soroban_authorization(auth, keypair_index=keypair_index)
echo_success("Signed successfully.")
echo_success("Base64-encoded signature:")
echo_success(base64.b64encode(signature).decode())
if hash_signing:
signature = client.sign_hash(preimage_hash, keypair_index)
else:
signature = client.sign_soroban_authorization(
auth, keypair_index=keypair_index
)
except CommException as e:
if e.sw == SW.DENY:
echo_error("The request to sign the soroban auth was denied.")
elif e.sw == SW.UNKNOWN_ENVELOPE_TYPE:
if hash_signing and e.sw == SW.TX_HASH_SIGNING_MODE_NOT_ENABLED:
echo_error(
"Hash signing is not enabled on this device.\n"
"Please enable it on the device and try again."
)
elif e.sw == SW.DENY:
echo_error("The request to sign the Soroban authorization was denied.")
elif e.sw == SW.SW_REQUEST_DATA_TOO_LARGE:
echo_error(
"The transaction contains unsupported transaction envelope type."
"The request data is too large, please try to sign a Soroban authorization, or sign the hash only."
)
else:
echo_error(f"Unknown exception, you can the problem here: {__issue__}")
echo_error(
f"Unknown exception, you can report the problem here: {__issue__}"
)
raise
sys.exit(1)

echo_success("Signed successfully.")
echo_success("Base64-encoded signature:")
echo_success(base64.b64encode(signature).decode())


@cli.command(name="version")
def version() -> None:
Expand Down
Loading

0 comments on commit cb8b847

Please sign in to comment.