tests: functional tests for BIP-322 message signing and proof of funds
What changed, and why it matters
This commit only adds automated tests and test helper code for a new Bitcoin message-signing feature (BIP-322). It does not change the actual Ledger app firmware that users run, so it cannot by itself introduce a security vulnerability in shipped software. The tests exercise both valid and invalid signing requests, including many cases designed to make the device reject malformed or suspicious inputs.
No security action required; treat as routine test coverage. If reviewing the related BIP-322 firmware implementation, ensure the rejection logic exercised by these tests is correctly implemented in the app source (not shown in this commit).
Security signals we found
No firmware/source code changes; test-only commit
Tests include negative/rejection cases for malformed BIP-322 PSBTs
Tests verify signatures against independently recomputed sighashes
Tests cover proof-of-funds external-input rejection and unverified-input warnings
Evidence from the diff
The diff is entirely test-side additions: a new test_utils/bip0322.py helper module, a small extension to test_utils/wallet_policy.py to support musig() descriptor derivation, a navigation helper in tests/instructions.py, a large ragger functional test suite in tests/test_sign_psbt_bip322.py, and golden UI snapshots for five device families. The test suite covers BIP-322 simple signatures and proof-of-funds across P2WPKH, P2PKH, P2TR, registered 2-of-2 multisig, and MuSig2 (keypath and scriptpath) policies, plus rejection tests for malformed to_spend, wrong prevout, non-zero amounts, extra outputs, OP_RETURN data pushes, unsupported tx versions/locktimes/timelocks, external proof-of-funds inputs, and non-SIGHASH_ALL sighashes. No C/firmware source files are modified.
Changed components
tests/test_sign_psbt_bip322.pytest_utils/bip0322.pytest_utils/wallet_policy.pytests/instructions.pytests/snapshots/*Inspect captured patch +989 / −0
### test_utils/bip0322.py
@@ -0,0 +1,240 @@
+"""Helpers to build and verify BIP-322 message-signing PSBTs for the tests.
+
+BIP-322 defines message signing as signing a virtual "to_sign" transaction that spends a
+virtual "to_spend" transaction committing to the message. The PSBT-based flow (BIP-322 v1.0.0+)
+carries the message in the PSBT_GLOBAL_GENERIC_SIGNED_MESSAGE (0x09) global field, which the
+signing device uses to recognize the request and display a message-signing UI.
+"""
+
+import base64
+import struct
+from hashlib import sha256
+from typing import List
+
+from bitcoin_client.ledger_bitcoin import WalletPolicy
+from bitcoin_client.ledger_bitcoin.key import ExtendedKey, KeyOriginInfo
+from bitcoin_client.ledger_bitcoin.psbt import PSBT, PartiallySignedInput, PartiallySignedOutput
+from bitcoin_client.ledger_bitcoin.tx import (CTransaction, CTxIn, CTxOut, COutPoint, CTxWitness)
+from bitcoin_client.ledger_bitcoin._serialize import ser_compact_size, ser_string, ser_uint256
+
+from test_utils import hash160, hash256
+from test_utils.txmaker import (getScriptPubkeyFromWallet, fill_inout,
+ createFakeWalletTransaction)
+from test_utils.wallet_policy import DescriptorTemplate
+
+BIP0322_TAG = b"BIP0322-signed-message"
+
+
+def bip0322_message_hash(message: bytes) -> bytes:
+ """The BIP-340 tagged hash of the message, with tag "BIP0322-signed-message"."""
+ tag_hash = sha256(BIP0322_TAG).digest()
+ return sha256(tag_hash + tag_hash + message).digest()
+
+
+def build_to_spend_tx(message: bytes, challenge_script: bytes) -> CTransaction:
+ """Builds the virtual to_spend transaction for the given message and scriptPubKey."""
+ to_spend = CTransaction()
+ to_spend.nVersion = 0
+ to_spend.nLockTime = 0
+
+ txin = CTxIn()
+ txin.prevout = COutPoint(0, 0xFFFFFFFF)
+ txin.scriptSig = b"\x00\x20" + bip0322_message_hash(message)
+ txin.nSequence = 0
+
+ to_spend.vin = [txin]
+ to_spend.vout = [CTxOut(0, challenge_script)]
+ to_spend.wit = CTxWitness()
+ to_spend.rehash()
+ return to_spend
+
+
+def build_bip322_psbt(wallet_policy: WalletPolicy,
+ message: bytes,
+ *,
+ is_change: bool = False,
+ address_index: int = 0,
+ tx_version: int = 0) -> PSBT:
+ """Builds the PSBT of the BIP-322 to_sign transaction for the given wallet policy address
+ and message, with the PSBT_GLOBAL_GENERIC_SIGNED_MESSAGE global field set."""
+
+ challenge_script = bytes(getScriptPubkeyFromWallet(
+ wallet_policy, is_change, address_index).data)
+ to_spend = build_to_spend_tx(message, challenge_script)
+
+ tx = CTransaction()
+ tx.nVersion = tx_version
+ tx.nLockTime = 0
+
+ txin = CTxIn()
+ txin.prevout = COutPoint(to_spend.sha256, 0)
+ txin.scriptSig = b""
+ txin.nSequence = 0
+
+ tx.vin = [txin]
+ tx.vout = [CTxOut(0, b"\x6a")]
+ tx.wit = CTxWitness()
+
+ psbt = PSBT()
+ psbt.version = 0
+
+ # Fill the global xpub map: each root key in the wallet policy maps to its key origin info
+ for key_info_str in wallet_policy.keys_info:
+ key_origin_end_pos = key_info_str.find("]")
+ if key_origin_end_pos == -1:
+ root_pubkey = ExtendedKey.deserialize(key_info_str)
+ fpr = hash160(root_pubkey.pubkey)[:4]
+ key_origin = KeyOriginInfo(fpr, [])
+ else:
+ root_pubkey = ExtendedKey.deserialize(key_info_str[key_origin_end_pos + 1:])
+ key_origin = KeyOriginInfo.from_string(key_info_str[1:key_origin_end_pos])
+ psbt.xpub[root_pubkey.serialize()] = key_origin
+
+ psbt_input = PartiallySignedInput(0)
+
+ desc_tmpl = DescriptorTemplate.from_string(wallet_policy.descriptor_template)
+ if desc_tmpl.is_segwit():
+ psbt_input.witness_utxo = to_spend.vout[0]
+ if desc_tmpl.is_legacy() or (desc_tmpl.is_segwit() and not desc_tmpl.is_taproot()):
+ psbt_input.non_witness_utxo = to_spend
+
+ fill_inout(wallet_policy, psbt_input, is_change=is_change, address_index=address_index)
+
+ psbt.inputs = [psbt_input]
+ psbt.outputs = [PartiallySignedOutput(0)]
+ psbt.tx = tx
+
+ psbt.generic_signed_message = message
+
+ return psbt
+
+
+def build_bip322_pof_psbt(wallet_policy: WalletPolicy,
+ message: bytes,
+ utxo_amounts: List[int],
+ *,
+ is_change: bool = False,
+ address_index: int = 0) -> PSBT:
+ """Builds a BIP-322 proof-of-funds PSBT: the to_sign transaction additionally spends one
+ real (fake, wallet-owned) UTXO per entry of utxo_amounts."""
+
+ psbt = build_bip322_psbt(wallet_policy, message,
+ is_change=is_change, address_index=address_index)
+
+ desc_tmpl = DescriptorTemplate.from_string(wallet_policy.descriptor_template)
+
+ for amount in utxo_amounts:
+ prevout, prevout_n, prevout_is_change, prevout_addr_idx = createFakeWalletTransaction(
+ 1, 2, amount, wallet_policy)
+
+ txin = CTxIn()
+ txin.prevout = COutPoint(prevout.sha256, prevout_n)
+ txin.scriptSig = b""
+ txin.nSequence = 0
+ psbt.tx.vin.append(txin)
+
+ psbt_input = PartiallySignedInput(0)
+ if desc_tmpl.is_segwit():
+ psbt_input.witness_utxo = prevout.vout[prevout_n]
+ if desc_tmpl.is_legacy() or (desc_tmpl.is_segwit() and not desc_tmpl.is_taproot()):
+ psbt_input.non_witness_utxo = prevout
+
+ fill_inout(wallet_policy, psbt_input, is_change=bool(prevout_is_change),
+ address_index=prevout_addr_idx)
+
+ psbt.inputs.append(psbt_input)
+
+ return psbt
+
+
+def bip322_pof_segwitv0_sighash_all(to_sign_tx: CTransaction,
+ input_index: int,
+ script_code: bytes,
+ amount: int) -> bytes:
+ """BIP-143 SIGHASH_ALL sighash of one input of a (possibly multi-input, proof-of-funds)
+ to_sign transaction."""
+ hash_prevouts = hash256(
+ b"".join(txin.prevout.serialize() for txin in to_sign_tx.vin))
+ hash_sequence = hash256(
+ b"".join(struct.pack("<I", txin.nSequence) for txin in to_sign_tx.vin))
+ hash_outputs = hash256(b"".join(
+ struct.pack("<q", txout.nValue) + ser_string(txout.scriptPubKey)
+ for txout in to_sign_tx.vout))
+
+ this_input = to_sign_tx.vin[input_index]
+ preimage = b"".join([
+ struct.pack("<i", to_sign_tx.nVersion),
+ hash_prevouts,
+ hash_sequence,
+ this_input.prevout.serialize(),
+ ser_string(script_code),
+ struct.pack("<q", amount),
+ struct.pack("<I", this_input.nSequence),
+ hash_outputs,
+ struct.pack("<I", to_sign_tx.nLockTime),
+ struct.pack("<I", 1), # SIGHASH_ALL
+ ])
+ return hash256(preimage)
+
+
+def bip322_segwitv0_sighash_all(to_spend: CTransaction,
+ script_code: bytes,
+ tx_version: int = 0) -> bytes:
+ """BIP-143 SIGHASH_ALL sighash of the (fixed-form) to_sign transaction spending to_spend."""
+ outpoint = ser_uint256(to_spend.sha256) + struct.pack("<I", 0)
+ hash_prevouts = hash256(outpoint)
+ hash_sequence = hash256(struct.pack("<I", 0))
+ hash_outputs = hash256(struct.pack("<q", 0) + ser_string(b"\x6a"))
+
+ preimage = b"".join([
+ struct.pack("<i", tx_version),
+ hash_prevouts,
+ hash_sequence,
+ outpoint,
+ ser_string(script_code),
+ struct.pack("<q", 0), # amount of the spent output
+ struct.pack("<I", 0), # nSequence
+ hash_outputs,
+ struct.pack("<I", 0), # nLockTime
+ struct.pack("<I", 1), # SIGHASH_ALL
+ ])
+ return hash256(preimage)
+
+
+def bip322_legacy_sighash_all(to_spend: CTransaction,
+ script_code: bytes,
+ tx_version: int = 0) -> bytes:
+ """Legacy SIGHASH_ALL sighash of the (fixed-form) to_sign transaction spending to_spend."""
+ ser = b"".join([
+ struct.pack("<i", tx_version),
+ b"\x01", # 1 input
+ ser_uint256(to_spend.sha256),
+ struct.pack("<I", 0), # prevout index
+ ser_string(script_code), # scriptSig replaced with the script code
+ struct.pack("<I", 0), # nSequence
+ b"\x01", # 1 output
+ struct.pack("<q", 0), # value
+ ser_string(b"\x6a"),
+ struct.pack("<I", 0), # nLockTime
+ struct.pack("<I", 1), # SIGHASH_ALL
+ ])
+ return hash256(ser)
+
+
+def p2wpkh_script_code(challenge_script: bytes) -> bytes:
+ """The BIP-143 script code for a P2WPKH scriptPubKey (0x0014{20-byte key hash})."""
+ assert len(challenge_script) == 22 and challenge_script[0:2] == b"\x00\x14"
+ return b"\x76\xa9\x14" + challenge_script[2:22] + b"\x88\xac"
+
+
+def ecdsa_verify(pubkey: bytes, sighash: bytes, sig_der: bytes) -> bool:
+ """Verifies a DER-encoded ECDSA signature (without the sighash-type byte)."""
+ from embit import ec
+ return ec.PublicKey.parse(pubkey).verify(ec.Signature.parse(sig_der), sighash)
+
+
+def encode_simple_signature(witness_stack: List[bytes]) -> str:
+ """Encodes a witness stack as a BIP-322 "simple" signature string (smp prefix)."""
+ ser = ser_compact_size(len(witness_stack)) + \
+ b"".join(ser_string(item) for item in witness_stack)
+ return "smp" + base64.b64encode(ser).decode()
### test_utils/wallet_policy.py
@@ -15,9 +15,40 @@
if _REPO_ROOT not in sys.path:
sys.path.insert(0, _REPO_ROOT)
+import base58
+
from bitcoin_client.ledger_bitcoin._embit.descriptor.miniscript import Miniscript
from bitcoin_client.ledger_bitcoin.key import ExtendedKey
from test_utils.taproot import ser_script, tagged_hash
+from test_utils.bip0327 import get_xonly_pk, key_agg
+
+# BIP-328 chaincode used to derive a synthetic xpub from an aggregated musig2 public key.
+_BIP328_CHAINCODE = bytes.fromhex(
+ "868087ca02a6f974c4598924c36b57762d32cb45717167e300622c7167e38965")
+
+
+def aggregate_musig_pubkey(keys_info: List[str]) -> str:
+ """Returns the BIP-328 synthetic extended public key (as a string) aggregating the
+ participant keys of a musig() key expression, sorted as required by descriptors."""
+ pubkeys: List[bytes] = []
+ versions = set()
+ for ki in keys_info:
+ xpub = ki[ki.find(']') + 1:]
+ xpub_bytes = base58.b58decode_check(xpub)
+ versions.add(xpub_bytes[:4])
+ pubkeys.append(xpub_bytes[-33:])
+
+ if len(versions) > 1:
+ raise ValueError(
+ "All the extended public keys should be from the same network")
+ version_bytes = versions.pop()
+
+ keyagg_ctx = key_agg(sorted(pubkeys))
+ Q = keyagg_ctx.Q
+ compressed_pubkey = (b'\x02' if Q[1] % 2 == 0 else b'\x03') + get_xonly_pk(keyagg_ctx)
+ ext_pubkey = (version_bytes + b'\x00' + b'\x00\x00\x00\x00' + b'\x00\x00\x00\x00' +
+ _BIP328_CHAINCODE + compressed_pubkey)
+ return base58.b58encode_check(ext_pubkey).decode()
def tapleaf_hash(script: Optional[bytes], leaf_version=b'\xC0') -> Optional[bytes]:
@@ -107,6 +138,16 @@ def replace_m_n(match: re.Match[str]):
desc_tmpl = re.sub(r'<([^;]+);([^>]+)>', replace_m_n, desc_tmpl)
+ # Replace each musig(...) expression with the derived aggregate xpub
+ def replace_musig(match: re.Match[str]):
+ key_indexes = [int(i.strip('@')) for i in match.group(1).split(',')]
+ steps = [int(x) for x in match.group(2).split("/")]
+ assert len(steps) == 2
+ agg_xpub = aggregate_musig_pubkey([keys_info[i] for i in key_indexes])
+ return derive_from_key_info(agg_xpub, steps)
+
+ desc_tmpl = re.sub(r'musig\(([^)]+)\)/(\d+/\d+)', replace_musig, desc_tmpl)
+
# Replace @i/a/b with the i-th element in keys_info, deriving the key appropriately
# to get a plain xpub
def replace_key_index(match):
### tests/instructions.py
@@ -20,6 +20,30 @@ def message_instruction_approve(model: Firmware, save_screenshot=True) -> Instru
return instructions
+def bip322_instruction_approve(model: Firmware, save_screenshot=True, *,
+ has_unverifiedwarning: bool = False) -> Instructions:
+ # Navigation for the BIP-322 message review (account/address/message pairs, then sign),
+ # optionally preceded by the warning for segwitv0 inputs missing the non-witness utxo.
+ # The message is streamed from the client between the warning and the review, so they are
+ # in separate request groups.
+ instructions = Instructions(model)
+
+ if model.name.startswith("nano"):
+ if has_unverifiedwarning:
+ instructions.new_request("Continue anyway", save_screenshot=save_screenshot)
+ instructions.nano_skip_screen("Address", save_screenshot=save_screenshot)
+ instructions.same_request("Sign message", save_screenshot=save_screenshot)
+ else:
+ if has_unverifiedwarning:
+ instructions.new_request("Continue anyway", NavInsID.USE_CASE_REVIEW_TAP,
+ NavInsID.USE_CASE_CHOICE_REJECT,
+ save_screenshot=save_screenshot)
+ instructions.review_message(save_screenshot=save_screenshot)
+ instructions.confirm_message(save_screenshot=save_screenshot)
+
+ return instructions
+
+
def message_instruction_approve_long(model: Firmware) -> Instructions:
instructions = Instructions(model)
### tests/snapshots/apex_p/test_sign_bip322_change_address_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_change_address_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_change_address_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_empty_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_empty_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_empty_message_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_long_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_long_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_long_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_long_message_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_multisig_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_multisig_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_multisig_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_nonprintable_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_nonprintable_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_nonprintable_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_nonprintable_message_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_p2pkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_p2pkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_p2pkh_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_p2tr_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_p2wpkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_p2wpkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_p2wpkh_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_pof_unverified_input_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_pof_unverified_input_1_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_pof_unverified_input_1_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_pof_unverified_input_1_1/00001.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_pof_unverified_input_1_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_proof_of_funds_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_proof_of_funds_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_proof_of_funds_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_proof_of_funds_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_proof_of_funds_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_proof_of_funds_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_proof_of_funds_p2tr_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_proof_of_funds_p2tr_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_reject_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_reject_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/apex_p/test_sign_bip322_reject_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_change_address_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_change_address_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_change_address_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_empty_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_empty_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_empty_message_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_long_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_long_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_long_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_long_message_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_multisig_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_multisig_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_multisig_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_nonprintable_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_nonprintable_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_nonprintable_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_nonprintable_message_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_p2pkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_p2pkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_p2pkh_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_p2tr_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_p2wpkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_p2wpkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_p2wpkh_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_pof_unverified_input_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_pof_unverified_input_1_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_pof_unverified_input_1_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_pof_unverified_input_1_1/00001.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_pof_unverified_input_1_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_proof_of_funds_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_proof_of_funds_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_proof_of_funds_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_proof_of_funds_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_proof_of_funds_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_proof_of_funds_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_proof_of_funds_p2tr_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_proof_of_funds_p2tr_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_reject_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_reject_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/flex/test_sign_bip322_reject_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_change_address_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_change_address_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_change_address_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_change_address_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_change_address_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_empty_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_empty_message_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_empty_message_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_empty_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_empty_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_long_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_long_message_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_long_message_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_long_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_long_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_long_message_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_multisig_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_multisig_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_multisig_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_multisig_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_multisig_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_multisig_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_nonprintable_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_nonprintable_message_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_nonprintable_message_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_nonprintable_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_nonprintable_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_nonprintable_message_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2pkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2pkh_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2pkh_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2pkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2pkh_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2tr_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2tr_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2tr_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2tr_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2wpkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2wpkh_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2wpkh_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2wpkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_p2wpkh_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_pof_unverified_input_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_pof_unverified_input_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_pof_unverified_input_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_pof_unverified_input_1_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_pof_unverified_input_1_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_pof_unverified_input_1_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_pof_unverified_input_1_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_pof_unverified_input_1_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_pof_unverified_input_1_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_p2tr_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_p2tr_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_p2tr_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_p2tr_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_proof_of_funds_p2tr_0_1/00003.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_reject_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_reject_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_reject_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_reject_0_0/00003.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_reject_0_0/00004.png
[binary or diff unavailable]
### tests/snapshots/nanosp/test_sign_bip322_reject_0_0/00005.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_change_address_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_change_address_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_change_address_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_change_address_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_change_address_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_empty_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_empty_message_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_empty_message_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_empty_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_empty_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_long_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_long_message_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_long_message_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_long_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_long_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_long_message_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_multisig_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_multisig_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_multisig_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_multisig_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_multisig_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_multisig_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_nonprintable_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_nonprintable_message_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_nonprintable_message_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_nonprintable_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_nonprintable_message_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_nonprintable_message_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2pkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2pkh_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2pkh_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2pkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2pkh_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2tr_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2tr_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2tr_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2tr_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2wpkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2wpkh_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2wpkh_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2wpkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_p2wpkh_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_pof_unverified_input_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_pof_unverified_input_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_pof_unverified_input_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_pof_unverified_input_1_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_pof_unverified_input_1_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_pof_unverified_input_1_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_pof_unverified_input_1_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_pof_unverified_input_1_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_pof_unverified_input_1_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_p2tr_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_p2tr_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_p2tr_0_1/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_p2tr_0_1/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_proof_of_funds_p2tr_0_1/00003.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_reject_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_reject_0_0/00001.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_reject_0_0/00002.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_reject_0_0/00003.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_reject_0_0/00004.png
[binary or diff unavailable]
### tests/snapshots/nanox/test_sign_bip322_reject_0_0/00005.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_change_address_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_change_address_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_change_address_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_empty_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_empty_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_empty_message_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_long_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_long_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_long_message_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_multisig_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_multisig_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_multisig_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_nonprintable_message_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_nonprintable_message_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_nonprintable_message_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_p2pkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_p2pkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_p2pkh_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_p2tr_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_p2wpkh_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_p2wpkh_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_p2wpkh_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_pof_unverified_input_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_pof_unverified_input_1_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_pof_unverified_input_1_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_pof_unverified_input_1_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_proof_of_funds_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_proof_of_funds_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_proof_of_funds_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_proof_of_funds_p2tr_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_proof_of_funds_p2tr_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_proof_of_funds_p2tr_0_2/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_reject_0_0/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_reject_0_1/00000.png
[binary or diff unavailable]
### tests/snapshots/stax/test_sign_bip322_reject_0_2/00000.png
[binary or diff unavailable]
### tests/test_sign_psbt_bip322.py
@@ -0,0 +1,684 @@
+import hmac
+from hashlib import sha256
+from io import BytesIO
+
+import pytest
+
+from ledger_bitcoin import MultisigWallet, WalletPolicy, AddressType, PartialSignature
+from ledger_bitcoin.exception.errors import (DenyError, IncorrectDataError, NotSupportedError,
+ SecurityStatusNotSatisfiedError)
+from ledger_bitcoin.exception.device_exception import DeviceException
+from ledger_bitcoin.key import ExtendedKey
+from ledger_bitcoin.psbt import PSBT, PartiallySignedInput, PartiallySignedOutput
+from ledger_bitcoin.tx import CTxIn, CTxOut, COutPoint
+from ledger_bitcoin._embit.descriptor.miniscript import Miniscript
+
+from ragger.navigator import Navigator
+from ragger.error import ExceptionRAPDU
+from ragger.firmware import Firmware
+
+from ragger_bitcoin import RaggerClient
+
+from test_utils import bip0340, SpeculosGlobals
+from test_utils.bip0322 import (
+ build_bip322_psbt,
+ build_bip322_pof_psbt,
+ build_to_spend_tx,
+ bip322_segwitv0_sighash_all,
+ bip322_pof_segwitv0_sighash_all,
+ bip322_legacy_sighash_all,
+ p2wpkh_script_code,
+ ecdsa_verify,
+ encode_simple_signature,
+)
+from test_utils.musig2 import HotMusig2Cosigner, derive_plain_descriptor, run_musig2_test
+from test_utils.taproot_sighash import TaprootSignatureHash
+
+from .conftest import toggle_nonstandard_sighash_setting
+from .instructions import bip322_instruction_approve, message_instruction_reject
+from .test_sign_psbt_musig import LedgerMusig2Cosigner
+
+# error codes defined in error_codes.h
+EC_SIGN_PSBT_NONDEFAULT_SIGHASH_NOT_ALLOWED = 0x000d
+EC_SIGN_PSBT_BIP322_INVALID_STRUCTURE = 0x0010
+EC_SIGN_PSBT_BIP322_TOSPEND_MISMATCH = 0x0011
+EC_SIGN_PSBT_BIP322_FORBIDDEN_SIGHASH = 0x0012
+EC_SIGN_PSBT_BIP322_UNSUPPORTED = 0x0013
+EC_SIGN_PSBT_BIP322_EXTERNAL_INPUTS = 0x0015
+
+SIGHASH_ALL = 0x01
+SIGHASH_NONE = 0x02
+
+
+wallet_wpkh = WalletPolicy(
+ "",
+ "wpkh(@0/**)",
+ [
+ "[f5acc2fd/84'/1'/0']tpubDCtKfsNyRhULjZ9XMS4VKKtVcPdVDi8MKUbcSD9MJDyjRu1A2ND5MiipozyyspBT9bg8upEp7a8EAgFxNxXn1d7QkdbL52Ty5jiSLcxPt1P"
+ ],
+)
+
+wallet_tr = WalletPolicy(
+ "",
+ "tr(@0/**)",
+ [
+ "[f5acc2fd/86'/1'/0']tpubDDKYE6BREvDsSWMazgHoyQWiJwYaDDYPbCFjYxN3HFXJP5fokeiK4hwK5tTLBNEDBwrDXn8cQ4v9b2xdW62Xr5yxoQdMu1v6c7UDXYVH27U",
+ ],
+)
+
+wallet_pkh = WalletPolicy(
+ "",
+ "pkh(@0/**)",
+ [
+ "[f5acc2fd/44'/1'/0']tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT"
+ ],
+)
+
+
+def test_sign_bip322_p2wpkh(navigator: Navigator, firmware: Firmware, client: RaggerClient,
+ test_name: str):
+ message = b"Hello World"
+ psbt = build_bip322_psbt(wallet_wpkh, message)
+
+ result = client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ assert len(result) == 1
+ input_index, partial_sig = result[0]
+ assert input_index == 0
+ assert isinstance(partial_sig, PartialSignature)
+
+ # verify the returned signature against the independently recomputed BIP-143 sighash of
+ # the to_sign transaction
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ to_spend = build_to_spend_tx(message, challenge_script)
+ sighash = bip322_segwitv0_sighash_all(to_spend, p2wpkh_script_code(challenge_script))
+
+ assert partial_sig.signature[-1] == 1 # SIGHASH_ALL
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+ # assemble and print the final BIP-322 "simple" signature, for reference
+ signature = encode_simple_signature(
+ [partial_sig.signature, partial_sig.pubkey])
+ print(f"BIP-322 signature for {test_name}: {signature}")
+
+
+def test_sign_bip322_p2tr(navigator: Navigator, firmware: Firmware, client: RaggerClient,
+ test_name: str):
+ message = b"Hello World"
+ psbt = build_bip322_psbt(wallet_tr, message)
+
+ result = client.sign_psbt(psbt, wallet_tr, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ assert len(result) == 1
+ input_index, partial_sig = result[0]
+ assert input_index == 0
+
+ # verify the schnorr signature against the recomputed BIP-341 sighash (SIGHASH_DEFAULT)
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ sighash = TaprootSignatureHash(psbt.tx, [CTxOut(0, challenge_script)], 0, 0)
+
+ assert len(partial_sig.signature) == 64 # SIGHASH_DEFAULT: no sighash byte appended
+ assert bip0340.schnorr_verify(sighash, partial_sig.pubkey, partial_sig.signature)
+
+ signature = encode_simple_signature([partial_sig.signature])
+ print(f"BIP-322 signature for {test_name}: {signature}")
+
+
+def test_sign_bip322_p2pkh(navigator: Navigator, firmware: Firmware, client: RaggerClient,
+ test_name: str):
+ # legacy addresses use the "full" variant of BIP-322; the firmware flow is the same
+ message = b"Hello World"
+ psbt = build_bip322_psbt(wallet_pkh, message)
+
+ result = client.sign_psbt(psbt, wallet_pkh, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ assert len(result) == 1
+ _, partial_sig = result[0]
+
+ challenge_script = bytes(psbt.inputs[0].non_witness_utxo.vout[0].scriptPubKey)
+ to_spend = build_to_spend_tx(message, challenge_script)
+ sighash = bip322_legacy_sighash_all(to_spend, challenge_script)
+
+ assert partial_sig.signature[-1] == 1 # SIGHASH_ALL
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_multisig(navigator: Navigator, firmware: Firmware, client: RaggerClient,
+ test_name: str, speculos_globals: SpeculosGlobals):
+ # a registered multisig policy, as used by coordinators like Liana
+ wallet = MultisigWallet(
+ name="Cold storage",
+ address_type=AddressType.WIT,
+ threshold=2,
+ keys_info=[
+ "[76223a6e/48'/1'/0'/2']tpubDE7NQymr4AFtewpAsWtnreyq9ghkzQBXpCZjWLFVRAvnbf7vya2eMTvT2fPapNqL8SuVvLQdbUbMfWLVDCZKnsEBqp6UK93QEzL8Ck23AwF",
+ "[f5acc2fd/48'/1'/0'/2']tpubDFAqEGNyad35aBCKUAXbQGDjdVhNueno5ZZVEn3sQbW5ci457gLR7HyTmHBg93oourBssgUxuWz1jX5uhc1qaqFo9VsybY1J5FuedLfm4dK",
+ ],
+ )
+ wallet_hmac = hmac.new(
+ speculos_globals.wallet_registration_key, wallet.id, sha256).digest()
+
+ message = b"I own this multisig"
+ psbt = build_bip322_psbt(wallet, message)
+
+ result = client.sign_psbt(psbt, wallet, wallet_hmac, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ # the device controls one of the two keys
+ assert len(result) == 1
+ _, partial_sig = result[0]
+
+ # for P2WSH, the BIP-143 script code is the witness script itself
+ witness_script = bytes(psbt.inputs[0].witness_script)
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ assert challenge_script == b"\x00\x20" + sha256(witness_script).digest()
+
+ to_spend = build_to_spend_tx(message, challenge_script)
+ sighash = bip322_segwitv0_sighash_all(to_spend, witness_script)
+
+ assert partial_sig.signature[-1] == 1 # SIGHASH_ALL
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_long_message(navigator: Navigator, firmware: Firmware, client: RaggerClient,
+ test_name: str):
+ # messages that are too long (or not printable) are shown as their sha256 hash
+ message = b"A" * 1000
+ psbt = build_bip322_psbt(wallet_wpkh, message)
+
+ result = client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ assert len(result) == 1
+ _, partial_sig = result[0]
+
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ to_spend = build_to_spend_tx(message, challenge_script)
+ sighash = bip322_segwitv0_sighash_all(to_spend, p2wpkh_script_code(challenge_script))
+
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_empty_message(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # the empty message is valid (it is one of the BIP's test vectors)
+ message = b""
+ psbt = build_bip322_psbt(wallet_wpkh, message)
+
+ result = client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ assert len(result) == 1
+ _, partial_sig = result[0]
+
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ to_spend = build_to_spend_tx(message, challenge_script)
+ sighash = bip322_segwitv0_sighash_all(to_spend, p2wpkh_script_code(challenge_script))
+
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_nonprintable_message(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # a short message that is not printable ASCII (here, UTF-8) is shown as its sha256 hash
+ message = "café".encode()
+ psbt = build_bip322_psbt(wallet_wpkh, message)
+
+ result = client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ assert len(result) == 1
+ _, partial_sig = result[0]
+
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ to_spend = build_to_spend_tx(message, challenge_script)
+ sighash = bip322_segwitv0_sighash_all(to_spend, p2wpkh_script_code(challenge_script))
+
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_change_address(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # the address being proven may be any address of the account, including a change one
+ message = b"Hello World"
+ psbt = build_bip322_psbt(wallet_wpkh, message, is_change=True, address_index=5)
+
+ result = client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ assert len(result) == 1
+ _, partial_sig = result[0]
+
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ to_spend = build_to_spend_tx(message, challenge_script)
+ sighash = bip322_segwitv0_sighash_all(to_spend, p2wpkh_script_code(challenge_script))
+
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_reject(navigator: Navigator, firmware: Firmware, client: RaggerClient,
+ test_name: str):
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World")
+
+ with pytest.raises(ExceptionRAPDU) as e:
+ client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=message_instruction_reject(firmware),
+ testname=test_name)
+
+ assert DeviceException.exc.get(e.value.status) == DenyError
+ assert len(e.value.data) == 0
+
+
+def expect_sign_psbt_error(client: RaggerClient, navigator: Navigator, firmware: Firmware,
+ test_name: str, psbt: PSBT, expected_error, expected_ec: int,
+ wallet=wallet_wpkh, wallet_hmac=None):
+ with pytest.raises(ExceptionRAPDU) as e:
+ client.sign_psbt(psbt, wallet, wallet_hmac, navigator,
+ instructions=bip322_instruction_approve(firmware,
+ save_screenshot=False),
+ testname=test_name)
+
+ assert DeviceException.exc.get(e.value.status) == expected_error
+ assert len(e.value.data) == 2
+ error_code = int.from_bytes(e.value.data, byteorder='big')
+ assert error_code == expected_ec
+
+
+def test_sign_bip322_wrong_message(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # the message in the global field is not the message committed in the transaction:
+ # the device must refuse (it would otherwise display a message different from the one
+ # being signed)
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World")
+ psbt.generic_signed_message = b"Another message"
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ IncorrectDataError, EC_SIGN_PSBT_BIP322_TOSPEND_MISMATCH)
+
+
+def test_sign_bip322_wrong_prevout_index(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # the first input must spend output 0 of to_spend (its only output).
+ # Taproot is used so that no non-witness-utxo cross-check rejects the PSBT before the
+ # BIP-322 validation does (to_spend has no output at index 1).
+ psbt = build_bip322_psbt(wallet_tr, b"Hello World")
+ psbt.tx.vin[0].prevout.n = 1
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ IncorrectDataError, EC_SIGN_PSBT_BIP322_INVALID_STRUCTURE,
+ wallet=wallet_tr)
+
+
+def test_sign_bip322_nonzero_amount(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # a real spend disguised with the BIP-322 global field must be refused.
+ # Taproot is used so that no non-witness-utxo cross-check rejects the PSBT before the
+ # BIP-322 validation does (for segwit v0 inputs, the existing utxo consistency checks
+ # already refuse such a PSBT with a different error code).
+ psbt = build_bip322_psbt(wallet_tr, b"Hello World")
+ psbt.inputs[0].witness_utxo.nValue = 100_000
+ psbt.tx.vout[0].nValue = 100_000
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ IncorrectDataError, EC_SIGN_PSBT_BIP322_INVALID_STRUCTURE,
+ wallet=wallet_tr)
+
+
+def test_sign_bip322_opreturn_with_data(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # the output must be a bare OP_RETURN, with no data push
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World")
+ psbt.tx.vout[0].scriptPubKey = b"\x6a\x04test"
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ IncorrectDataError, EC_SIGN_PSBT_BIP322_INVALID_STRUCTURE)
+
+
+def test_sign_bip322_extra_output(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # exactly one output is allowed
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World")
+ psbt.tx.vout.append(CTxOut(0, b"\x6a"))
+ psbt.outputs.append(PartiallySignedOutput(0))
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ IncorrectDataError, EC_SIGN_PSBT_BIP322_INVALID_STRUCTURE)
+
+
+def test_sign_bip322_wrong_tx_version(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # the to_sign transaction version must be 0 or 2
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World", tx_version=3)
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ IncorrectDataError, EC_SIGN_PSBT_BIP322_INVALID_STRUCTURE)
+
+
+def test_sign_bip322_locktime_unsupported(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # timelocked BIP-322 signatures are valid per the BIP, but not supported yet
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World", tx_version=2)
+ psbt.tx.nLockTime = 800_000
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ NotSupportedError, EC_SIGN_PSBT_BIP322_UNSUPPORTED)
+
+
+def test_sign_bip322_p2tr_explicit_sighash_all(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient):
+ # an explicit SIGHASH_ALL is allowed for taproot inputs too. The review is exactly the one
+ # of test_sign_bip322_p2tr, whose snapshots are therefore reused.
+ message = b"Hello World"
+ psbt = build_bip322_psbt(wallet_tr, message)
+ psbt.inputs[0].sighash = SIGHASH_ALL
+
+ result = client.sign_psbt(psbt, wallet_tr, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname="test_sign_bip322_p2tr")
+
+ assert len(result) == 1
+ _, partial_sig = result[0]
+
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ sighash = TaprootSignatureHash(psbt.tx, [CTxOut(0, challenge_script)], SIGHASH_ALL, 0)
+
+ assert len(partial_sig.signature) == 65
+ assert partial_sig.signature[-1] == SIGHASH_ALL
+ assert bip0340.schnorr_verify(sighash, partial_sig.pubkey, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_nondefault_sighash_setting_disabled(navigator: Navigator,
+ firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # BIP-322 requires SIGHASH_ALL (or SIGHASH_DEFAULT). With the non-standard sighash setting
+ # disabled (the default), such a request is refused by the generic sighash gating, before
+ # any BIP-322 check (its on-device status screen is covered by test_sighash_setting.py)
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World")
+ psbt.inputs[0].sighash = SIGHASH_NONE
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ SecurityStatusNotSatisfiedError,
+ EC_SIGN_PSBT_NONDEFAULT_SIGHASH_NOT_ALLOWED)
+
+
+def test_sign_bip322_nondefault_sighash_setting_enabled(navigator: Navigator,
+ firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # with the non-standard sighash setting enabled, the request passes the generic sighash
+ # gating, and is then refused by the BIP-322 validation
+ toggle_nonstandard_sighash_setting(navigator, firmware)
+
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World")
+ psbt.inputs[0].sighash = SIGHASH_NONE
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ IncorrectDataError, EC_SIGN_PSBT_BIP322_FORBIDDEN_SIGHASH)
+
+
+def test_sign_bip322_proof_of_funds(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # proof-of-funds: the to_sign transaction additionally spends real wallet UTXOs, whose
+ # total amount is shown on the device
+ message = b"I control these coins"
+ utxo_amounts = [123_456, 876_544] # 0.01 BTC total
+ psbt = build_bip322_pof_psbt(wallet_wpkh, message, utxo_amounts)
+
+ result = client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ # one signature per input: the virtual to_spend input plus the two real UTXOs
+ assert len(result) == 3
+ assert sorted(idx for idx, _ in result) == [0, 1, 2]
+
+ for input_index, partial_sig in result:
+ challenge_script = bytes(psbt.inputs[input_index].witness_utxo.scriptPubKey)
+ amount = psbt.inputs[input_index].witness_utxo.nValue
+ sighash = bip322_pof_segwitv0_sighash_all(psbt.tx, input_index,
+ p2wpkh_script_code(challenge_script),
+ amount)
+ assert partial_sig.signature[-1] == 1 # SIGHASH_ALL
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_proof_of_funds_p2tr(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ message = b"I control these coins"
+ utxo_amounts = [42_000]
+ psbt = build_bip322_pof_psbt(wallet_tr, message, utxo_amounts)
+
+ result = client.sign_psbt(psbt, wallet_tr, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname=test_name)
+
+ assert len(result) == 2
+ assert sorted(idx for idx, _ in result) == [0, 1]
+
+ spent_utxos = [CTxOut(inp.witness_utxo.nValue, bytes(inp.witness_utxo.scriptPubKey))
+ for inp in psbt.inputs]
+
+ for input_index, partial_sig in result:
+ sighash = TaprootSignatureHash(psbt.tx, spent_utxos, 0, input_index)
+ assert len(partial_sig.signature) == 64 # SIGHASH_DEFAULT
+ assert bip0340.schnorr_verify(sighash, partial_sig.pubkey, partial_sig.signature)
+
+
+def test_sign_bip322_proof_of_funds_witness_only_to_spend(navigator: Navigator,
+ firmware: Firmware,
+ client: RaggerClient):
+ # the to_spend input is recomputed on-device, so it never triggers the warning for
+ # segwitv0 inputs missing the non-witness utxo, even in a proof-of-funds. The review must
+ # be exactly the one of test_sign_bip322_proof_of_funds (same message and amounts), whose
+ # snapshots are therefore reused: a warning screen would make the comparison fail.
+ message = b"I control these coins"
+ utxo_amounts = [123_456, 876_544]
+ psbt = build_bip322_pof_psbt(wallet_wpkh, message, utxo_amounts)
+ psbt.inputs[0].non_witness_utxo = None
+
+ result = client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=bip322_instruction_approve(firmware),
+ testname="test_sign_bip322_proof_of_funds")
+
+ assert len(result) == 3
+ for input_index, partial_sig in result:
+ challenge_script = bytes(psbt.inputs[input_index].witness_utxo.scriptPubKey)
+ amount = psbt.inputs[input_index].witness_utxo.nValue
+ sighash = bip322_pof_segwitv0_sighash_all(psbt.tx, input_index,
+ p2wpkh_script_code(challenge_script),
+ amount)
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_pof_unverified_input(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # a real (proof-of-funds) segwitv0 input missing the non-witness utxo has an unverified
+ # amount, which is part of the total shown to the user: the usual warning is shown first
+ message = b"I control these coins"
+ psbt = build_bip322_pof_psbt(wallet_wpkh, message, [123_456, 876_544])
+ psbt.inputs[2].non_witness_utxo = None
+
+ result = client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=bip322_instruction_approve(
+ firmware, has_unverifiedwarning=True),
+ testname=test_name)
+
+ assert len(result) == 3
+ for input_index, partial_sig in result:
+ challenge_script = bytes(psbt.inputs[input_index].witness_utxo.scriptPubKey)
+ amount = psbt.inputs[input_index].witness_utxo.nValue
+ sighash = bip322_pof_segwitv0_sighash_all(psbt.tx, input_index,
+ p2wpkh_script_code(challenge_script),
+ amount)
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+def test_sign_bip322_pof_external_input(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # every input of a proof-of-funds must belong to the wallet policy: the proven total
+ # shown to the user must be trustworthy
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World")
+
+ txin = CTxIn()
+ txin.prevout = COutPoint(12345, 0)
+ txin.scriptSig = b""
+ txin.nSequence = 0
+ psbt.tx.vin.append(txin)
+
+ external_input = PartiallySignedInput(0)
+ external_input.witness_utxo = CTxOut(5000, b"\x00\x14" + bytes(20))
+ psbt.inputs.append(external_input)
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ IncorrectDataError, EC_SIGN_PSBT_BIP322_EXTERNAL_INPUTS)
+
+
+def test_sign_bip322_pof_final_sequences(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # BIP-322 gives a timelock meaning only to the first input's sequence: the proof-of-funds
+ # inputs may use the final sequence (explicit, or implied by an omitted PSBT_IN_SEQUENCE,
+ # which is its PSBTv2 default) or any sequence with the BIP-68 disable flag set.
+ # The review is identical to test_sign_bip322_proof_of_funds, so no screenshots are taken.
+ message = b"I control these coins"
+ for sequences in ([0xFFFFFFFF, 0xFFFFFFFE], [None, 0]):
+ psbt = build_bip322_pof_psbt(wallet_wpkh, message, [100_000, 200_000])
+ tx = psbt.tx
+ psbt.convert_to_v2() # so that the client sends the input maps exactly as set below
+ for input_index, sequence in enumerate(sequences, start=1):
+ tx.vin[input_index].nSequence = 0xFFFFFFFF if sequence is None else sequence
+ psbt.inputs[input_index].sequence = sequence # None: PSBT_IN_SEQUENCE is omitted
+
+ result = client.sign_psbt(psbt, wallet_wpkh, None, navigator,
+ instructions=bip322_instruction_approve(firmware,
+ save_screenshot=False),
+ testname=test_name)
+
+ assert len(result) == 3
+ for input_index, partial_sig in result:
+ challenge_script = bytes(psbt.inputs[input_index].witness_utxo.scriptPubKey)
+ amount = psbt.inputs[input_index].witness_utxo.nValue
+ sighash = bip322_pof_segwitv0_sighash_all(tx, input_index,
+ p2wpkh_script_code(challenge_script),
+ amount)
+ assert ecdsa_verify(partial_sig.pubkey, sighash, partial_sig.signature[:-1])
+
+
+@pytest.mark.parametrize("tx_version", [2, 0])
+def test_sign_bip322_pof_relative_timelock_unsupported(navigator: Navigator,
+ firmware: Firmware,
+ client: RaggerClient, test_name: str,
+ tx_version: int):
+ # a proof-of-funds input whose sequence is neither 0 nor has the BIP-68 disable flag set:
+ # with version 2 it would impose a relative timelock on to_sign (a timelocked variant, not
+ # supported); with version 0 it is meaningless, and rejected too
+ psbt = build_bip322_pof_psbt(wallet_wpkh, b"I control these coins", [100_000])
+ psbt.tx.nVersion = tx_version
+ psbt.tx.vin[1].nSequence = 10
+
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ NotSupportedError, EC_SIGN_PSBT_BIP322_UNSUPPORTED)
+
+
+def test_sign_bip322_challenge_sequence_unsupported(navigator: Navigator, firmware: Firmware,
+ client: RaggerClient, test_name: str):
+ # the first input's sequence is the "age" of a timelocked signature: only an explicit 0 is
+ # supported, whether the final sequence is given explicitly or implied by an omitted field
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World")
+ psbt.tx.vin[0].nSequence = 0xFFFFFFFF
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ NotSupportedError, EC_SIGN_PSBT_BIP322_UNSUPPORTED)
+
+ psbt = build_bip322_psbt(wallet_wpkh, b"Hello World")
+ psbt.convert_to_v2()
+ psbt.inputs[0].sequence = None # PSBT_IN_SEQUENCE omitted
+ expect_sign_psbt_error(client, navigator, firmware, test_name, psbt,
+ NotSupportedError, EC_SIGN_PSBT_BIP322_UNSUPPORTED)
+
+
+def test_sign_bip322_musig_keypath(navigator: Navigator, firmware: Firmware, client: RaggerClient,
+ test_name: str, speculos_globals: SpeculosGlobals):
+ # BIP-322 message signing for a taproot keypath musig() policy. The device controls one of
+ # the two musig participants; the two-round MuSig2 flow runs exactly as for a transaction,
+ # except the request is reviewed (and displayed) as a message signature.
+ cosigner_1_xpub = "[f5acc2fd/44'/1'/0']tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT"
+
+ cosigner_2_xpriv = "tprv8gFWbQBTLFhbX3EK3cS7LmenwE3JjXbD9kN9yXfq7LcBm81RSf8vPGPqGPjZSeX41LX9ZN14St3z8YxW48aq5Yhr9pQZVAyuBthfi6quTCf"
+ cosigner_2_xpub = "tpubDCwYjpDhUdPGQWG6wG6hkBJuWFZEtrn7j3xwG3i8XcQabcGC53xWZm1hSXrUPFS5UvZ3QhdPSjXWNfWmFGTioARHuG5J7XguEjgg7p8PxAm"
+
+ wallet_policy = WalletPolicy(
+ name="Musig message signer",
+ descriptor_template="tr(musig(@0,@1)/**)",
+ keys_info=[cosigner_1_xpub, cosigner_2_xpub],
+ )
+ wallet_hmac = hmac.new(
+ speculos_globals.wallet_registration_key, wallet_policy.id, sha256).digest()
+
+ message = b"I control this musig address"
+ psbt = build_bip322_psbt(wallet_policy, message)
+
+ # the to_sign transaction spends the single virtual to_spend output (a zero-value taproot
+ # output), so the sighash is the SIGHASH_DEFAULT taproot keypath sighash over it
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ sighash = TaprootSignatureHash(psbt.tx, [CTxOut(0, challenge_script)], 0, 0)
+
+ # the device controls one musig participant; a hot cosigner supplies the other
+ signer_1 = LedgerMusig2Cosigner(
+ client, wallet_policy, wallet_hmac, navigator=navigator,
+ instructions=bip322_instruction_approve(firmware, save_screenshot=False),
+ testname=test_name)
+ signer_2 = HotMusig2Cosigner(wallet_policy, cosigner_2_xpriv)
+
+ run_musig2_test(wallet_policy, psbt, [signer_1, signer_2], [sighash])
+
+
+def test_sign_bip322_musig_scriptpath(navigator: Navigator, firmware: Firmware, client: RaggerClient,
+ test_name: str, speculos_globals: SpeculosGlobals):
+ # BIP-322 message signing for a musig() key expression sitting in a tapscript leaf. The
+ # device signs the leaf script path, so the sighash uses the tapscript (leaf) variant.
+ cosigner_1_xpub = "[f5acc2fd/44'/1'/0']tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT"
+
+ cosigner_2_xpriv = "tprv8gFWbQBTLFhbX3EK3cS7LmenwE3JjXbD9kN9yXfq7LcBm81RSf8vPGPqGPjZSeX41LX9ZN14St3z8YxW48aq5Yhr9pQZVAyuBthfi6quTCf"
+ cosigner_2_xpub = ExtendedKey.deserialize(cosigner_2_xpriv).neutered().to_string()
+
+ wallet_policy = WalletPolicy(
+ name="Musig script msg",
+ descriptor_template="tr(@0/**,pk(musig(@1,@2)/**))",
+ keys_info=[
+ "tpubD6NzVbkrYhZ4WLczPJWReQycCJdd6YVWXubbVUFnJ5KgU5MDQrD998ZJLSmaB7GVcCnJSDWprxmrGkJ6SvgQC6QAffVpqSvonXmeizXcrkN",
+ cosigner_1_xpub,
+ cosigner_2_xpub,
+ ],
+ )
+ wallet_hmac = hmac.new(
+ speculos_globals.wallet_registration_key, wallet_policy.id, sha256).digest()
+
+ message = b"Musig in a tapscript leaf"
+ psbt = build_bip322_psbt(wallet_policy, message)
+
+ # the device signs the tapscript leaf that contains the musig() key; recompute the leaf
+ # script (change=0, address_index=0) to derive the corresponding tapscript sighash
+ challenge_script = bytes(psbt.inputs[0].witness_utxo.scriptPubKey)
+ leaf_desc = derive_plain_descriptor(
+ "pk(musig(@1,@2)/**)", wallet_policy.keys_info, False, 0)
+ leaf_script = Miniscript.read_from(
+ BytesIO(leaf_desc.encode()), taproot=True).compile()
+ sighash = TaprootSignatureHash(psbt.tx, [CTxOut(0, challenge_script)], 0, 0,
+ scriptpath=True, script=leaf_script)
+
+ signer_1 = LedgerMusig2Cosigner(
+ client, wallet_policy, wallet_hmac, navigator=navigator,
+ instructions=bip322_instruction_approve(firmware, save_screenshot=False),
+ testname=test_name)
+ signer_2 = HotMusig2Cosigner(wallet_policy, cosigner_2_xpriv)
+
+ run_musig2_test(wallet_policy, psbt, [signer_1, signer_2], [sighash])Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.