Merge remote-tracking branch 'agent/benma-agent/merge-firmware-v9.29.0'
What changed, and why it matters
This firmware update hardens how the BitBox02 handles SwapKit-style cryptocurrency swaps and Bitcoin multisig addresses. It adds a new 'refund memo' to payment requests so the device can verify that any refund address belongs to the same wallet account being spent from, preventing a malicious or compromised swap provider from redirecting refunds to an attacker's address. It also tightens Bitcoin multisig address keypath checks so only normal receive/change branches (0 or 1) are allowed when displaying a receiving address, while still permitting broader paths for spending/recovery. The changelog explicitly calls these 'Bitcoin security fixes' and 'Require wallet-owned refund addresses for SwapKit'.
Treat this as a security-relevant firmware release. Users relying on SwapKit swaps or Bitcoin multisig should upgrade to v9.29.0. Reviewers should verify that the refund-address derivation and source-account matching logic correctly covers all supported script types and cannot be bypassed via malformed memos, and that the multisig branch restriction does not break legitimate spending workflows.
Security signals we found
CHANGELOG labels prior changes as 'Bitcoin security fixes (multisig keypath and previous-transaction hash length validation)'
CHANGELOG labels v9.29.0 as 'Require wallet-owned refund addresses for SwapKit'
New RefundMemo protobuf message with address and optional derivation info
validate_btc now derives the refund address from the provided script_config/keypath and checks it matches the memo address and source account
validate_eth now derives the refund address from the provided keypath and checks it matches the memo address and source keypath
SwapKit identity lookup restricted to explicit allowlist; broad 'contains swapkit' matching removed
Multisig receive address keypath validation now restricts branch to 0 or 1
Previous-transaction hash length validation mentioned in changelog but not visible in this diff
Evidence from the diff
The commit merges firmware v9.29.0. Key changes: (1) In payment_request.rs, SwapKit identity lookup is restricted to an explicit allowlist (‘SWAPKIT (NEAR)’), a refund memo is required for SwapKit providers, and validate_btc/validate_eth now derive the refund address from the supplied keypath/script_config and compare it to the memo’s address, ensuring it matches the source account/keypath. (2) In bitcoin/keypath.rs a new validate_address_multisig function enforces branch 0/1 for receive-mode multisig addresses, and bitcoin.rs and signtx.rs switch multisig address validation to use it. (3) Protobuf messages add RefundMemo to BTCPaymentRequestRequest. (4) The Ethereum signing path passes the source keypath into refund validation. Extensive unit tests cover refund derivation, account matching, and invalid memo combinations.
Changed components
src/rust/bitbox02-rust/src/hww/api/payment_request.rssrc/rust/bitbox02-rust/src/hww/api/bitcoin.rssrc/rust/bitbox02-rust/src/hww/api/bitcoin/keypath.rssrc/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rssrc/rust/bitbox02-rust/src/hww/api/ethereum/sign.rsmessages/btc.protopy/bitbox02/bitbox02/communication/generated/btc_pb2.pypy/bitbox02/bitbox02/communication/generated/btc_pb2.pyisrc/rust/bitbox-proto/src/generated/shiftcrypto.bitbox02.rsInspect captured patch +867 / −124
### CHANGELOG.md
@@ -7,6 +7,12 @@ recorded separately.
## Firmware
### Unreleased
+
+### v9.29.0
+- Require wallet-owned refund addresses for SwapKit
+
+### v9.28.0
+- Bitcoin security fixes (multisig keypath and previous-transaction hash length validation)
- API: include the installed stage0 version in the device info response
- Allow entering the optional BIP39 passphrase on the host, with device approval and confirmation
- Reject malformed microSD backups instead of crashing
### messages/btc.proto
@@ -267,9 +267,18 @@ message BTCPaymentRequestRequest {
BtcAddressDerivation btc = 5;
}
}
+ message RefundMemo {
+ string address = 1;
+ // Derivation info is not part of the SLIP-24 sighash.
+ oneof address_derivation {
+ CoinPurchaseMemo.EthAddressDerivation eth = 2;
+ CoinPurchaseMemo.BtcAddressDerivation btc = 3;
+ }
+ }
oneof memo {
TextMemo text_memo = 1;
CoinPurchaseMemo coin_purchase_memo = 2;
+ RefundMemo refund_memo = 3;
}
}
### py/bitbox02/bitbox02/communication/generated/btc_pb2.py
@@ -15,17 +15,17 @@
from . import antiklepto_pb2 as antiklepto__pb2
-DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\tbtc.proto\x12\x14shiftcrypto.bitbox02\x1a\x0c\x63ommon.proto\x1a\x10\x61ntiklepto.proto\"\xc6\x04\n\x0f\x42TCScriptConfig\x12G\n\x0bsimple_type\x18\x01 \x01(\x0e\x32\x30.shiftcrypto.bitbox02.BTCScriptConfig.SimpleTypeH\x00\x12\x42\n\x08multisig\x18\x02 \x01(\x0b\x32..shiftcrypto.bitbox02.BTCScriptConfig.MultisigH\x00\x12>\n\x06policy\x18\x03 \x01(\x0b\x32,.shiftcrypto.bitbox02.BTCScriptConfig.PolicyH\x00\x1a\xd9\x01\n\x08Multisig\x12\x11\n\tthreshold\x18\x01 \x01(\r\x12)\n\x05xpubs\x18\x02 \x03(\x0b\x32\x1a.shiftcrypto.bitbox02.XPub\x12\x16\n\x0eour_xpub_index\x18\x03 \x01(\r\x12N\n\x0bscript_type\x18\x04 \x01(\x0e\x32\x39.shiftcrypto.bitbox02.BTCScriptConfig.Multisig.ScriptType\"\'\n\nScriptType\x12\t\n\x05P2WSH\x10\x00\x12\x0e\n\nP2WSH_P2SH\x10\x01\x1aK\n\x06Policy\x12\x0e\n\x06policy\x18\x01 \x01(\t\x12\x31\n\x04keys\x18\x02 \x03(\x0b\x32#.shiftcrypto.bitbox02.KeyOriginInfo\"3\n\nSimpleType\x12\x0f\n\x0bP2WPKH_P2SH\x10\x00\x12\n\n\x06P2WPKH\x10\x01\x12\x08\n\x04P2TR\x10\x02\x42\x08\n\x06\x63onfig\"\xfc\x02\n\rBTCPubRequest\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12\x0f\n\x07keypath\x18\x02 \x03(\r\x12\x41\n\txpub_type\x18\x03 \x01(\x0e\x32,.shiftcrypto.bitbox02.BTCPubRequest.XPubTypeH\x00\x12>\n\rscript_config\x18\x04 \x01(\x0b\x32%.shiftcrypto.bitbox02.BTCScriptConfigH\x00\x12\x0f\n\x07\x64isplay\x18\x05 \x01(\x08\"\x8e\x01\n\x08XPubType\x12\x08\n\x04TPUB\x10\x00\x12\x08\n\x04XPUB\x10\x01\x12\x08\n\x04YPUB\x10\x02\x12\x08\n\x04ZPUB\x10\x03\x12\x08\n\x04VPUB\x10\x04\x12\x08\n\x04UPUB\x10\x05\x12\x10\n\x0c\x43\x41PITAL_VPUB\x10\x06\x12\x10\n\x0c\x43\x41PITAL_ZPUB\x10\x07\x12\x10\n\x0c\x43\x41PITAL_UPUB\x10\x08\x12\x10\n\x0c\x43\x41PITAL_YPUB\x10\tB\x08\n\x06output\"\xdf\x01\n\x0f\x42TCXpubsRequest\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12\x41\n\txpub_type\x18\x02 \x01(\x0e\x32..shiftcrypto.bitbox02.BTCXpubsRequest.XPubType\x12/\n\x08keypaths\x18\x03 \x03(\x0b\x32\x1d.shiftcrypto.bitbox02.Keypath\"+\n\x08XPubType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x08\n\x04XPUB\x10\x01\x12\x08\n\x04TPUB\x10\x02\"k\n\x1a\x42TCScriptConfigWithKeypath\x12<\n\rscript_config\x18\x02 \x01(\x0b\x32%.shiftcrypto.bitbox02.BTCScriptConfig\x12\x0f\n\x07keypath\x18\x03 \x03(\r\"\xbf\x03\n\x12\x42TCSignInitRequest\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12H\n\x0escript_configs\x18\x02 \x03(\x0b\x32\x30.shiftcrypto.bitbox02.BTCScriptConfigWithKeypath\x12\x0f\n\x07version\x18\x04 \x01(\r\x12\x12\n\nnum_inputs\x18\x05 \x01(\r\x12\x13\n\x0bnum_outputs\x18\x06 \x01(\r\x12\x10\n\x08locktime\x18\x07 \x01(\r\x12H\n\x0b\x66ormat_unit\x18\x08 \x01(\x0e\x32\x33.shiftcrypto.bitbox02.BTCSignInitRequest.FormatUnit\x12\'\n\x1f\x63ontains_silent_payment_outputs\x18\t \x01(\x08\x12O\n\x15output_script_configs\x18\n \x03(\x0b\x32\x30.shiftcrypto.bitbox02.BTCScriptConfigWithKeypath\"\"\n\nFormatUnit\x12\x0b\n\x07\x44\x45\x46\x41ULT\x10\x00\x12\x07\n\x03SAT\x10\x01\"\xc4\x03\n\x13\x42TCSignNextResponse\x12<\n\x04type\x18\x01 \x01(\x0e\x32..shiftcrypto.bitbox02.BTCSignNextResponse.Type\x12\r\n\x05index\x18\x02 \x01(\r\x12\x15\n\rhas_signature\x18\x03 \x01(\x08\x12\x11\n\tsignature\x18\x04 \x01(\x0c\x12\x12\n\nprev_index\x18\x05 \x01(\r\x12W\n\x1d\x61nti_klepto_signer_commitment\x18\x06 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.AntiKleptoSignerCommitment\x12!\n\x19generated_output_pkscript\x18\x07 \x01(\x0c\x12!\n\x19silent_payment_dleq_proof\x18\x08 \x01(\x0c\"\x82\x01\n\x04Type\x12\t\n\x05INPUT\x10\x00\x12\n\n\x06OUTPUT\x10\x01\x12\x08\n\x04\x44ONE\x10\x02\x12\x0f\n\x0bPREVTX_INIT\x10\x03\x12\x10\n\x0cPREVTX_INPUT\x10\x04\x12\x11\n\rPREVTX_OUTPUT\x10\x05\x12\x0e\n\nHOST_NONCE\x10\x06\x12\x13\n\x0fPAYMENT_REQUEST\x10\x07\"\xea\x01\n\x13\x42TCSignInputRequest\x12\x13\n\x0bprevOutHash\x18\x01 \x01(\x0c\x12\x14\n\x0cprevOutIndex\x18\x02 \x01(\r\x12\x14\n\x0cprevOutValue\x18\x03 \x01(\x04\x12\x10\n\x08sequence\x18\x04 \x01(\r\x12\x0f\n\x07keypath\x18\x06 \x03(\r\x12\x1b\n\x13script_config_index\x18\x07 \x01(\r\x12R\n\x15host_nonce_commitment\x18\x08 \x01(\x0b\x32\x33.shiftcrypto.bitbox02.AntiKleptoHostNonceCommitment\"\x9f\x03\n\x14\x42TCSignOutputRequest\x12\x0c\n\x04ours\x18\x01 \x01(\x08\x12\x31\n\x04type\x18\x02 \x01(\x0e\x32#.shiftcrypto.bitbox02.BTCOutputType\x12\r\n\x05value\x18\x03 \x01(\x04\x12\x0f\n\x07payload\x18\x04 \x01(\x0c\x12\x0f\n\x07keypath\x18\x05 \x03(\r\x12\x1b\n\x13script_config_index\x18\x06 \x01(\r\x12\"\n\x15payment_request_index\x18\x07 \x01(\rH\x00\x88\x01\x01\x12P\n\x0esilent_payment\x18\x08 \x01(\x0b\x32\x38.shiftcrypto.bitbox02.BTCSignOutputRequest.SilentPayment\x12\'\n\x1aoutput_script_config_index\x18\t \x01(\rH\x01\x88\x01\x01\x1a \n\rSilentPayment\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\tB\x18\n\x16_payment_request_indexB\x1d\n\x1b_output_script_config_index\"\x99\x01\n\x1b\x42TCScriptConfigRegistration\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12<\n\rscript_config\x18\x02 \x01(\x0b\x32%.shiftcrypto.bitbox02.BTCScriptConfig\x12\x0f\n\x07keypath\x18\x03 \x03(\r\"\x0c\n\nBTCSuccess\"m\n\"BTCIsScriptConfigRegisteredRequest\x12G\n\x0cregistration\x18\x01 \x01(\x0b\x32\x31.shiftcrypto.bitbox02.BTCScriptConfigRegistration\"<\n#BTCIsScriptConfigRegisteredResponse\x12\x15\n\ris_registered\x18\x01 \x01(\x08\"\xfc\x01\n\x1e\x42TCRegisterScriptConfigRequest\x12G\n\x0cregistration\x18\x01 \x01(\x0b\x32\x31.shiftcrypto.bitbox02.BTCScriptConfigRegistration\x12\x0c\n\x04name\x18\x02 \x01(\t\x12P\n\txpub_type\x18\x03 \x01(\x0e\x32=.shiftcrypto.bitbox02.BTCRegisterScriptConfigRequest.XPubType\"1\n\x08XPubType\x12\x11\n\rAUTO_ELECTRUM\x10\x00\x12\x12\n\x0e\x41UTO_XPUB_TPUB\x10\x01\"b\n\x14\x42TCPrevTxInitRequest\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x12\n\nnum_inputs\x18\x02 \x01(\r\x12\x13\n\x0bnum_outputs\x18\x03 \x01(\r\x12\x10\n\x08locktime\x18\x04 \x01(\r\"r\n\x15\x42TCPrevTxInputRequest\x12\x15\n\rprev_out_hash\x18\x01 \x01(\x0c\x12\x16\n\x0eprev_out_index\x18\x02 \x01(\r\x12\x18\n\x10signature_script\x18\x03 \x01(\x0c\x12\x10\n\x08sequence\x18\x04 \x01(\r\">\n\x16\x42TCPrevTxOutputRequest\x12\r\n\x05value\x18\x01 \x01(\x04\x12\x15\n\rpubkey_script\x18\x02 \x01(\x0c\"\xcd\x06\n\x18\x42TCPaymentRequestRequest\x12\x16\n\x0erecipient_name\x18\x01 \x01(\t\x12\x42\n\x05memos\x18\x02 \x03(\x0b\x32\x33.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo\x12\r\n\x05nonce\x18\x03 \x01(\x0c\x12\x14\n\x0ctotal_amount\x18\x04 \x01(\x04\x12\x11\n\tsignature\x18\x05 \x01(\x0c\x1a\x9c\x05\n\x04Memo\x12Q\n\ttext_memo\x18\x01 \x01(\x0b\x32<.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.TextMemoH\x00\x12\x62\n\x12\x63oin_purchase_memo\x18\x02 \x01(\x0b\x32\x44.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.CoinPurchaseMemoH\x00\x1a\x18\n\x08TextMemo\x12\x0c\n\x04note\x18\x01 \x01(\t\x1a\xba\x03\n\x10\x43oinPurchaseMemo\x12\x11\n\tcoin_type\x18\x01 \x01(\r\x12\x0e\n\x06\x61mount\x18\x02 \x01(\t\x12\x0f\n\x07\x61\x64\x64ress\x18\x03 \x01(\t\x12h\n\x03\x65th\x18\x04 \x01(\x0b\x32Y.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.EthAddressDerivationH\x00\x12h\n\x03\x62tc\x18\x05 \x01(\x0b\x32Y.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.BtcAddressDerivationH\x00\x1a\'\n\x14\x45thAddressDerivation\x12\x0f\n\x07keypath\x18\x01 \x03(\r\x1a_\n\x14\x42tcAddressDerivation\x12G\n\rscript_config\x18\x01 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.BTCScriptConfigWithKeypathB\x14\n\x12\x61\x64\x64ress_derivationB\x06\n\x04memo\"\xee\x01\n\x15\x42TCSignMessageRequest\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12G\n\rscript_config\x18\x02 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.BTCScriptConfigWithKeypath\x12\x0b\n\x03msg\x18\x03 \x01(\x0c\x12R\n\x15host_nonce_commitment\x18\x04 \x01(\x0b\x32\x33.shiftcrypto.bitbox02.AntiKleptoHostNonceCommitment\"+\n\x16\x42TCSignMessageResponse\x12\x11\n\tsignature\x18\x01 \x01(\x0c\"\xb9\x05\n\nBTCRequest\x12_\n\x1bis_script_config_registered\x18\x01 \x01(\x0b\x32\x38.shiftcrypto.bitbox02.BTCIsScriptConfigRegisteredRequestH\x00\x12V\n\x16register_script_config\x18\x02 \x01(\x0b\x32\x34.shiftcrypto.bitbox02.BTCRegisterScriptConfigRequestH\x00\x12\x41\n\x0bprevtx_init\x18\x03 \x01(\x0b\x32*.shiftcrypto.bitbox02.BTCPrevTxInitRequestH\x00\x12\x43\n\x0cprevtx_input\x18\x04 \x01(\x0b\x32+.shiftcrypto.bitbox02.BTCPrevTxInputRequestH\x00\x12\x45\n\rprevtx_output\x18\x05 \x01(\x0b\x32,.shiftcrypto.bitbox02.BTCPrevTxOutputRequestH\x00\x12\x43\n\x0csign_message\x18\x06 \x01(\x0b\x32+.shiftcrypto.bitbox02.BTCSignMessageRequestH\x00\x12P\n\x14\x61ntiklepto_signature\x18\x07 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.AntiKleptoSignatureRequestH\x00\x12I\n\x0fpayment_request\x18\x08 \x01(\x0b\x32..shiftcrypto.bitbox02.BTCPaymentRequestRequestH\x00\x12\x36\n\x05xpubs\x18\t \x01(\x0b\x32%.shiftcrypto.bitbox02.BTCXpubsRequestH\x00\x42\t\n\x07request\"\xc4\x03\n\x0b\x42TCResponse\x12\x33\n\x07success\x18\x01 \x01(\x0b\x32 .shiftcrypto.bitbox02.BTCSuccessH\x00\x12`\n\x1bis_script_config_registered\x18\x02 \x01(\x0b\x32\x39.shiftcrypto.bitbox02.BTCIsScriptConfigRegisteredResponseH\x00\x12>\n\tsign_next\x18\x03 \x01(\x0b\x32).shiftcrypto.bitbox02.BTCSignNextResponseH\x00\x12\x44\n\x0csign_message\x18\x04 \x01(\x0b\x32,.shiftcrypto.bitbox02.BTCSignMessageResponseH\x00\x12X\n\x1c\x61ntiklepto_signer_commitment\x18\x05 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.AntiKleptoSignerCommitmentH\x00\x12\x32\n\x04pubs\x18\x06 \x01(\x0b\x32\".shiftcrypto.bitbox02.PubsResponseH\x00\x42\n\n\x08response*9\n\x07\x42TCCoin\x12\x07\n\x03\x42TC\x10\x00\x12\x08\n\x04TBTC\x10\x01\x12\x07\n\x03LTC\x10\x02\x12\x08\n\x04TLTC\x10\x03\x12\x08\n\x04RBTC\x10\x04*a\n\rBTCOutputType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\t\n\x05P2PKH\x10\x01\x12\x08\n\x04P2SH\x10\x02\x12\n\n\x06P2WPKH\x10\x03\x12\t\n\x05P2WSH\x10\x04\x12\x08\n\x04P2TR\x10\x05\x12\r\n\tOP_RETURN\x10\x06\x62\x06proto3')
+DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\tbtc.proto\x12\x14shiftcrypto.bitbox02\x1a\x0c\x63ommon.proto\x1a\x10\x61ntiklepto.proto\"\xc6\x04\n\x0f\x42TCScriptConfig\x12G\n\x0bsimple_type\x18\x01 \x01(\x0e\x32\x30.shiftcrypto.bitbox02.BTCScriptConfig.SimpleTypeH\x00\x12\x42\n\x08multisig\x18\x02 \x01(\x0b\x32..shiftcrypto.bitbox02.BTCScriptConfig.MultisigH\x00\x12>\n\x06policy\x18\x03 \x01(\x0b\x32,.shiftcrypto.bitbox02.BTCScriptConfig.PolicyH\x00\x1a\xd9\x01\n\x08Multisig\x12\x11\n\tthreshold\x18\x01 \x01(\r\x12)\n\x05xpubs\x18\x02 \x03(\x0b\x32\x1a.shiftcrypto.bitbox02.XPub\x12\x16\n\x0eour_xpub_index\x18\x03 \x01(\r\x12N\n\x0bscript_type\x18\x04 \x01(\x0e\x32\x39.shiftcrypto.bitbox02.BTCScriptConfig.Multisig.ScriptType\"\'\n\nScriptType\x12\t\n\x05P2WSH\x10\x00\x12\x0e\n\nP2WSH_P2SH\x10\x01\x1aK\n\x06Policy\x12\x0e\n\x06policy\x18\x01 \x01(\t\x12\x31\n\x04keys\x18\x02 \x03(\x0b\x32#.shiftcrypto.bitbox02.KeyOriginInfo\"3\n\nSimpleType\x12\x0f\n\x0bP2WPKH_P2SH\x10\x00\x12\n\n\x06P2WPKH\x10\x01\x12\x08\n\x04P2TR\x10\x02\x42\x08\n\x06\x63onfig\"\xfc\x02\n\rBTCPubRequest\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12\x0f\n\x07keypath\x18\x02 \x03(\r\x12\x41\n\txpub_type\x18\x03 \x01(\x0e\x32,.shiftcrypto.bitbox02.BTCPubRequest.XPubTypeH\x00\x12>\n\rscript_config\x18\x04 \x01(\x0b\x32%.shiftcrypto.bitbox02.BTCScriptConfigH\x00\x12\x0f\n\x07\x64isplay\x18\x05 \x01(\x08\"\x8e\x01\n\x08XPubType\x12\x08\n\x04TPUB\x10\x00\x12\x08\n\x04XPUB\x10\x01\x12\x08\n\x04YPUB\x10\x02\x12\x08\n\x04ZPUB\x10\x03\x12\x08\n\x04VPUB\x10\x04\x12\x08\n\x04UPUB\x10\x05\x12\x10\n\x0c\x43\x41PITAL_VPUB\x10\x06\x12\x10\n\x0c\x43\x41PITAL_ZPUB\x10\x07\x12\x10\n\x0c\x43\x41PITAL_UPUB\x10\x08\x12\x10\n\x0c\x43\x41PITAL_YPUB\x10\tB\x08\n\x06output\"\xdf\x01\n\x0f\x42TCXpubsRequest\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12\x41\n\txpub_type\x18\x02 \x01(\x0e\x32..shiftcrypto.bitbox02.BTCXpubsRequest.XPubType\x12/\n\x08keypaths\x18\x03 \x03(\x0b\x32\x1d.shiftcrypto.bitbox02.Keypath\"+\n\x08XPubType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x08\n\x04XPUB\x10\x01\x12\x08\n\x04TPUB\x10\x02\"k\n\x1a\x42TCScriptConfigWithKeypath\x12<\n\rscript_config\x18\x02 \x01(\x0b\x32%.shiftcrypto.bitbox02.BTCScriptConfig\x12\x0f\n\x07keypath\x18\x03 \x03(\r\"\xbf\x03\n\x12\x42TCSignInitRequest\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12H\n\x0escript_configs\x18\x02 \x03(\x0b\x32\x30.shiftcrypto.bitbox02.BTCScriptConfigWithKeypath\x12\x0f\n\x07version\x18\x04 \x01(\r\x12\x12\n\nnum_inputs\x18\x05 \x01(\r\x12\x13\n\x0bnum_outputs\x18\x06 \x01(\r\x12\x10\n\x08locktime\x18\x07 \x01(\r\x12H\n\x0b\x66ormat_unit\x18\x08 \x01(\x0e\x32\x33.shiftcrypto.bitbox02.BTCSignInitRequest.FormatUnit\x12\'\n\x1f\x63ontains_silent_payment_outputs\x18\t \x01(\x08\x12O\n\x15output_script_configs\x18\n \x03(\x0b\x32\x30.shiftcrypto.bitbox02.BTCScriptConfigWithKeypath\"\"\n\nFormatUnit\x12\x0b\n\x07\x44\x45\x46\x41ULT\x10\x00\x12\x07\n\x03SAT\x10\x01\"\xc4\x03\n\x13\x42TCSignNextResponse\x12<\n\x04type\x18\x01 \x01(\x0e\x32..shiftcrypto.bitbox02.BTCSignNextResponse.Type\x12\r\n\x05index\x18\x02 \x01(\r\x12\x15\n\rhas_signature\x18\x03 \x01(\x08\x12\x11\n\tsignature\x18\x04 \x01(\x0c\x12\x12\n\nprev_index\x18\x05 \x01(\r\x12W\n\x1d\x61nti_klepto_signer_commitment\x18\x06 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.AntiKleptoSignerCommitment\x12!\n\x19generated_output_pkscript\x18\x07 \x01(\x0c\x12!\n\x19silent_payment_dleq_proof\x18\x08 \x01(\x0c\"\x82\x01\n\x04Type\x12\t\n\x05INPUT\x10\x00\x12\n\n\x06OUTPUT\x10\x01\x12\x08\n\x04\x44ONE\x10\x02\x12\x0f\n\x0bPREVTX_INIT\x10\x03\x12\x10\n\x0cPREVTX_INPUT\x10\x04\x12\x11\n\rPREVTX_OUTPUT\x10\x05\x12\x0e\n\nHOST_NONCE\x10\x06\x12\x13\n\x0fPAYMENT_REQUEST\x10\x07\"\xea\x01\n\x13\x42TCSignInputRequest\x12\x13\n\x0bprevOutHash\x18\x01 \x01(\x0c\x12\x14\n\x0cprevOutIndex\x18\x02 \x01(\r\x12\x14\n\x0cprevOutValue\x18\x03 \x01(\x04\x12\x10\n\x08sequence\x18\x04 \x01(\r\x12\x0f\n\x07keypath\x18\x06 \x03(\r\x12\x1b\n\x13script_config_index\x18\x07 \x01(\r\x12R\n\x15host_nonce_commitment\x18\x08 \x01(\x0b\x32\x33.shiftcrypto.bitbox02.AntiKleptoHostNonceCommitment\"\x9f\x03\n\x14\x42TCSignOutputRequest\x12\x0c\n\x04ours\x18\x01 \x01(\x08\x12\x31\n\x04type\x18\x02 \x01(\x0e\x32#.shiftcrypto.bitbox02.BTCOutputType\x12\r\n\x05value\x18\x03 \x01(\x04\x12\x0f\n\x07payload\x18\x04 \x01(\x0c\x12\x0f\n\x07keypath\x18\x05 \x03(\r\x12\x1b\n\x13script_config_index\x18\x06 \x01(\r\x12\"\n\x15payment_request_index\x18\x07 \x01(\rH\x00\x88\x01\x01\x12P\n\x0esilent_payment\x18\x08 \x01(\x0b\x32\x38.shiftcrypto.bitbox02.BTCSignOutputRequest.SilentPayment\x12\'\n\x1aoutput_script_config_index\x18\t \x01(\rH\x01\x88\x01\x01\x1a \n\rSilentPayment\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\tB\x18\n\x16_payment_request_indexB\x1d\n\x1b_output_script_config_index\"\x99\x01\n\x1b\x42TCScriptConfigRegistration\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12<\n\rscript_config\x18\x02 \x01(\x0b\x32%.shiftcrypto.bitbox02.BTCScriptConfig\x12\x0f\n\x07keypath\x18\x03 \x03(\r\"\x0c\n\nBTCSuccess\"m\n\"BTCIsScriptConfigRegisteredRequest\x12G\n\x0cregistration\x18\x01 \x01(\x0b\x32\x31.shiftcrypto.bitbox02.BTCScriptConfigRegistration\"<\n#BTCIsScriptConfigRegisteredResponse\x12\x15\n\ris_registered\x18\x01 \x01(\x08\"\xfc\x01\n\x1e\x42TCRegisterScriptConfigRequest\x12G\n\x0cregistration\x18\x01 \x01(\x0b\x32\x31.shiftcrypto.bitbox02.BTCScriptConfigRegistration\x12\x0c\n\x04name\x18\x02 \x01(\t\x12P\n\txpub_type\x18\x03 \x01(\x0e\x32=.shiftcrypto.bitbox02.BTCRegisterScriptConfigRequest.XPubType\"1\n\x08XPubType\x12\x11\n\rAUTO_ELECTRUM\x10\x00\x12\x12\n\x0e\x41UTO_XPUB_TPUB\x10\x01\"b\n\x14\x42TCPrevTxInitRequest\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x12\n\nnum_inputs\x18\x02 \x01(\r\x12\x13\n\x0bnum_outputs\x18\x03 \x01(\r\x12\x10\n\x08locktime\x18\x04 \x01(\r\"r\n\x15\x42TCPrevTxInputRequest\x12\x15\n\rprev_out_hash\x18\x01 \x01(\x0c\x12\x16\n\x0eprev_out_index\x18\x02 \x01(\r\x12\x18\n\x10signature_script\x18\x03 \x01(\x0c\x12\x10\n\x08sequence\x18\x04 \x01(\r\">\n\x16\x42TCPrevTxOutputRequest\x12\r\n\x05value\x18\x01 \x01(\x04\x12\x15\n\rpubkey_script\x18\x02 \x01(\x0c\"\xae\t\n\x18\x42TCPaymentRequestRequest\x12\x16\n\x0erecipient_name\x18\x01 \x01(\t\x12\x42\n\x05memos\x18\x02 \x03(\x0b\x32\x33.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo\x12\r\n\x05nonce\x18\x03 \x01(\x0c\x12\x14\n\x0ctotal_amount\x18\x04 \x01(\x04\x12\x11\n\tsignature\x18\x05 \x01(\x0c\x1a\xfd\x07\n\x04Memo\x12Q\n\ttext_memo\x18\x01 \x01(\x0b\x32<.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.TextMemoH\x00\x12\x62\n\x12\x63oin_purchase_memo\x18\x02 \x01(\x0b\x32\x44.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.CoinPurchaseMemoH\x00\x12U\n\x0brefund_memo\x18\x03 \x01(\x0b\x32>.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.RefundMemoH\x00\x1a\x18\n\x08TextMemo\x12\x0c\n\x04note\x18\x01 \x01(\t\x1a\xba\x03\n\x10\x43oinPurchaseMemo\x12\x11\n\tcoin_type\x18\x01 \x01(\r\x12\x0e\n\x06\x61mount\x18\x02 \x01(\t\x12\x0f\n\x07\x61\x64\x64ress\x18\x03 \x01(\t\x12h\n\x03\x65th\x18\x04 \x01(\x0b\x32Y.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.EthAddressDerivationH\x00\x12h\n\x03\x62tc\x18\x05 \x01(\x0b\x32Y.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.BtcAddressDerivationH\x00\x1a\'\n\x14\x45thAddressDerivation\x12\x0f\n\x07keypath\x18\x01 \x03(\r\x1a_\n\x14\x42tcAddressDerivation\x12G\n\rscript_config\x18\x01 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.BTCScriptConfigWithKeypathB\x14\n\x12\x61\x64\x64ress_derivation\x1a\x87\x02\n\nRefundMemo\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12h\n\x03\x65th\x18\x02 \x01(\x0b\x32Y.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.EthAddressDerivationH\x00\x12h\n\x03\x62tc\x18\x03 \x01(\x0b\x32Y.shiftcrypto.bitbox02.BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.BtcAddressDerivationH\x00\x42\x14\n\x12\x61\x64\x64ress_derivationB\x06\n\x04memo\"\xee\x01\n\x15\x42TCSignMessageRequest\x12+\n\x04\x63oin\x18\x01 \x01(\x0e\x32\x1d.shiftcrypto.bitbox02.BTCCoin\x12G\n\rscript_config\x18\x02 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.BTCScriptConfigWithKeypath\x12\x0b\n\x03msg\x18\x03 \x01(\x0c\x12R\n\x15host_nonce_commitment\x18\x04 \x01(\x0b\x32\x33.shiftcrypto.bitbox02.AntiKleptoHostNonceCommitment\"+\n\x16\x42TCSignMessageResponse\x12\x11\n\tsignature\x18\x01 \x01(\x0c\"\xb9\x05\n\nBTCRequest\x12_\n\x1bis_script_config_registered\x18\x01 \x01(\x0b\x32\x38.shiftcrypto.bitbox02.BTCIsScriptConfigRegisteredRequestH\x00\x12V\n\x16register_script_config\x18\x02 \x01(\x0b\x32\x34.shiftcrypto.bitbox02.BTCRegisterScriptConfigRequestH\x00\x12\x41\n\x0bprevtx_init\x18\x03 \x01(\x0b\x32*.shiftcrypto.bitbox02.BTCPrevTxInitRequestH\x00\x12\x43\n\x0cprevtx_input\x18\x04 \x01(\x0b\x32+.shiftcrypto.bitbox02.BTCPrevTxInputRequestH\x00\x12\x45\n\rprevtx_output\x18\x05 \x01(\x0b\x32,.shiftcrypto.bitbox02.BTCPrevTxOutputRequestH\x00\x12\x43\n\x0csign_message\x18\x06 \x01(\x0b\x32+.shiftcrypto.bitbox02.BTCSignMessageRequestH\x00\x12P\n\x14\x61ntiklepto_signature\x18\x07 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.AntiKleptoSignatureRequestH\x00\x12I\n\x0fpayment_request\x18\x08 \x01(\x0b\x32..shiftcrypto.bitbox02.BTCPaymentRequestRequestH\x00\x12\x36\n\x05xpubs\x18\t \x01(\x0b\x32%.shiftcrypto.bitbox02.BTCXpubsRequestH\x00\x42\t\n\x07request\"\xc4\x03\n\x0b\x42TCResponse\x12\x33\n\x07success\x18\x01 \x01(\x0b\x32 .shiftcrypto.bitbox02.BTCSuccessH\x00\x12`\n\x1bis_script_config_registered\x18\x02 \x01(\x0b\x32\x39.shiftcrypto.bitbox02.BTCIsScriptConfigRegisteredResponseH\x00\x12>\n\tsign_next\x18\x03 \x01(\x0b\x32).shiftcrypto.bitbox02.BTCSignNextResponseH\x00\x12\x44\n\x0csign_message\x18\x04 \x01(\x0b\x32,.shiftcrypto.bitbox02.BTCSignMessageResponseH\x00\x12X\n\x1c\x61ntiklepto_signer_commitment\x18\x05 \x01(\x0b\x32\x30.shiftcrypto.bitbox02.AntiKleptoSignerCommitmentH\x00\x12\x32\n\x04pubs\x18\x06 \x01(\x0b\x32\".shiftcrypto.bitbox02.PubsResponseH\x00\x42\n\n\x08response*9\n\x07\x42TCCoin\x12\x07\n\x03\x42TC\x10\x00\x12\x08\n\x04TBTC\x10\x01\x12\x07\n\x03LTC\x10\x02\x12\x08\n\x04TLTC\x10\x03\x12\x08\n\x04RBTC\x10\x04*a\n\rBTCOutputType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\t\n\x05P2PKH\x10\x01\x12\x08\n\x04P2SH\x10\x02\x12\n\n\x06P2WPKH\x10\x03\x12\t\n\x05P2WSH\x10\x04\x12\x08\n\x04P2TR\x10\x05\x12\r\n\tOP_RETURN\x10\x06\x62\x06proto3')
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'btc_pb2', globals())
if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._options = None
- _BTCCOIN._serialized_start=6097
- _BTCCOIN._serialized_end=6154
- _BTCOUTPUTTYPE._serialized_start=6156
- _BTCOUTPUTTYPE._serialized_end=6253
+ _BTCCOIN._serialized_start=6450
+ _BTCCOIN._serialized_end=6507
+ _BTCOUTPUTTYPE._serialized_start=6509
+ _BTCOUTPUTTYPE._serialized_end=6606
_BTCSCRIPTCONFIG._serialized_start=68
_BTCSCRIPTCONFIG._serialized_end=650
_BTCSCRIPTCONFIG_MULTISIG._serialized_start=293
@@ -79,23 +79,25 @@
_BTCPREVTXOUTPUTREQUEST._serialized_start=3744
_BTCPREVTXOUTPUTREQUEST._serialized_end=3806
_BTCPAYMENTREQUESTREQUEST._serialized_start=3809
- _BTCPAYMENTREQUESTREQUEST._serialized_end=4654
+ _BTCPAYMENTREQUESTREQUEST._serialized_end=5007
_BTCPAYMENTREQUESTREQUEST_MEMO._serialized_start=3986
- _BTCPAYMENTREQUESTREQUEST_MEMO._serialized_end=4654
- _BTCPAYMENTREQUESTREQUEST_MEMO_TEXTMEMO._serialized_start=4177
- _BTCPAYMENTREQUESTREQUEST_MEMO_TEXTMEMO._serialized_end=4201
- _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO._serialized_start=4204
- _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO._serialized_end=4646
- _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO_ETHADDRESSDERIVATION._serialized_start=4488
- _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO_ETHADDRESSDERIVATION._serialized_end=4527
- _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO_BTCADDRESSDERIVATION._serialized_start=4529
- _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO_BTCADDRESSDERIVATION._serialized_end=4624
- _BTCSIGNMESSAGEREQUEST._serialized_start=4657
- _BTCSIGNMESSAGEREQUEST._serialized_end=4895
- _BTCSIGNMESSAGERESPONSE._serialized_start=4897
- _BTCSIGNMESSAGERESPONSE._serialized_end=4940
- _BTCREQUEST._serialized_start=4943
- _BTCREQUEST._serialized_end=5640
- _BTCRESPONSE._serialized_start=5643
- _BTCRESPONSE._serialized_end=6095
+ _BTCPAYMENTREQUESTREQUEST_MEMO._serialized_end=5007
+ _BTCPAYMENTREQUESTREQUEST_MEMO_TEXTMEMO._serialized_start=4264
+ _BTCPAYMENTREQUESTREQUEST_MEMO_TEXTMEMO._serialized_end=4288
+ _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO._serialized_start=4291
+ _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO._serialized_end=4733
+ _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO_ETHADDRESSDERIVATION._serialized_start=4575
+ _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO_ETHADDRESSDERIVATION._serialized_end=4614
+ _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO_BTCADDRESSDERIVATION._serialized_start=4616
+ _BTCPAYMENTREQUESTREQUEST_MEMO_COINPURCHASEMEMO_BTCADDRESSDERIVATION._serialized_end=4711
+ _BTCPAYMENTREQUESTREQUEST_MEMO_REFUNDMEMO._serialized_start=4736
+ _BTCPAYMENTREQUESTREQUEST_MEMO_REFUNDMEMO._serialized_end=4999
+ _BTCSIGNMESSAGEREQUEST._serialized_start=5010
+ _BTCSIGNMESSAGEREQUEST._serialized_end=5248
+ _BTCSIGNMESSAGERESPONSE._serialized_start=5250
+ _BTCSIGNMESSAGERESPONSE._serialized_end=5293
+ _BTCREQUEST._serialized_start=5296
+ _BTCREQUEST._serialized_end=5993
+ _BTCRESPONSE._serialized_start=5996
+ _BTCRESPONSE._serialized_end=6448
# @@protoc_insertion_point(module_scope)
### py/bitbox02/bitbox02/communication/generated/btc_pb2.pyi
@@ -833,21 +833,48 @@ class BTCPaymentRequestRequest(google.protobuf.message.Message):
def ClearField(self, field_name: typing.Literal["address", b"address", "address_derivation", b"address_derivation", "amount", b"amount", "btc", b"btc", "coin_type", b"coin_type", "eth", b"eth"]) -> None: ...
def WhichOneof(self, oneof_group: typing.Literal["address_derivation", b"address_derivation"]) -> typing.Literal["eth", "btc"] | None: ...
+ @typing.final
+ class RefundMemo(google.protobuf.message.Message):
+ DESCRIPTOR: google.protobuf.descriptor.Descriptor
+
+ ADDRESS_FIELD_NUMBER: builtins.int
+ ETH_FIELD_NUMBER: builtins.int
+ BTC_FIELD_NUMBER: builtins.int
+ address: builtins.str
+ @property
+ def eth(self) -> global___BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.EthAddressDerivation: ...
+ @property
+ def btc(self) -> global___BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.BtcAddressDerivation: ...
+ def __init__(
+ self,
+ *,
+ address: builtins.str = ...,
+ eth: global___BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.EthAddressDerivation | None = ...,
+ btc: global___BTCPaymentRequestRequest.Memo.CoinPurchaseMemo.BtcAddressDerivation | None = ...,
+ ) -> None: ...
+ def HasField(self, field_name: typing.Literal["address_derivation", b"address_derivation", "btc", b"btc", "eth", b"eth"]) -> builtins.bool: ...
+ def ClearField(self, field_name: typing.Literal["address", b"address", "address_derivation", b"address_derivation", "btc", b"btc", "eth", b"eth"]) -> None: ...
+ def WhichOneof(self, oneof_group: typing.Literal["address_derivation", b"address_derivation"]) -> typing.Literal["eth", "btc"] | None: ...
+
TEXT_MEMO_FIELD_NUMBER: builtins.int
COIN_PURCHASE_MEMO_FIELD_NUMBER: builtins.int
+ REFUND_MEMO_FIELD_NUMBER: builtins.int
@property
def text_memo(self) -> global___BTCPaymentRequestRequest.Memo.TextMemo: ...
@property
def coin_purchase_memo(self) -> global___BTCPaymentRequestRequest.Memo.CoinPurchaseMemo: ...
+ @property
+ def refund_memo(self) -> global___BTCPaymentRequestRequest.Memo.RefundMemo: ...
def __init__(
self,
*,
text_memo: global___BTCPaymentRequestRequest.Memo.TextMemo | None = ...,
coin_purchase_memo: global___BTCPaymentRequestRequest.Memo.CoinPurchaseMemo | None = ...,
+ refund_memo: global___BTCPaymentRequestRequest.Memo.RefundMemo | None = ...,
) -> None: ...
- def HasField(self, field_name: typing.Literal["coin_purchase_memo", b"coin_purchase_memo", "memo", b"memo", "text_memo", b"text_memo"]) -> builtins.bool: ...
- def ClearField(self, field_name: typing.Literal["coin_purchase_memo", b"coin_purchase_memo", "memo", b"memo", "text_memo", b"text_memo"]) -> None: ...
- def WhichOneof(self, oneof_group: typing.Literal["memo", b"memo"]) -> typing.Literal["text_memo", "coin_purchase_memo"] | None: ...
+ def HasField(self, field_name: typing.Literal["coin_purchase_memo", b"coin_purchase_memo", "memo", b"memo", "refund_memo", b"refund_memo", "text_memo", b"text_memo"]) -> builtins.bool: ...
+ def ClearField(self, field_name: typing.Literal["coin_purchase_memo", b"coin_purchase_memo", "memo", b"memo", "refund_memo", b"refund_memo", "text_memo", b"text_memo"]) -> None: ...
+ def WhichOneof(self, oneof_group: typing.Literal["memo", b"memo"]) -> typing.Literal["text_memo", "coin_purchase_memo", "refund_memo"] | None: ...
RECIPIENT_NAME_FIELD_NUMBER: builtins.int
MEMOS_FIELD_NUMBER: builtins.int
### src/rust/bitbox-proto/src/generated/shiftcrypto.bitbox02.rs
@@ -914,7 +914,7 @@ pub struct BtcPaymentRequestRequest {
pub mod btc_payment_request_request {
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Memo {
- #[prost(oneof = "memo::Memo", tags = "1, 2")]
+ #[prost(oneof = "memo::Memo", tags = "1, 2, 3")]
pub memo: ::core::option::Option<memo::Memo>,
}
/// Nested message and enum types in `Memo`.
@@ -963,12 +963,33 @@ pub mod btc_payment_request_request {
Btc(BtcAddressDerivation),
}
}
+ #[derive(Clone, PartialEq, ::prost::Message)]
+ pub struct RefundMemo {
+ #[prost(string, tag = "1")]
+ pub address: ::prost::alloc::string::String,
+ /// Derivation info is not part of the SLIP-24 sighash.
+ #[prost(oneof = "refund_memo::AddressDerivation", tags = "2, 3")]
+ pub address_derivation: ::core::option::Option<refund_memo::AddressDerivation>,
+ }
+ /// Nested message and enum types in `RefundMemo`.
+ pub mod refund_memo {
+ /// Derivation info is not part of the SLIP-24 sighash.
+ #[derive(Clone, PartialEq, ::prost::Oneof)]
+ pub enum AddressDerivation {
+ #[prost(message, tag = "2")]
+ Eth(super::coin_purchase_memo::EthAddressDerivation),
+ #[prost(message, tag = "3")]
+ Btc(super::coin_purchase_memo::BtcAddressDerivation),
+ }
+ }
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Memo {
#[prost(message, tag = "1")]
TextMemo(TextMemo),
#[prost(message, tag = "2")]
CoinPurchaseMemo(CoinPurchaseMemo),
+ #[prost(message, tag = "3")]
+ RefundMemo(RefundMemo),
}
}
}
### src/rust/bitbox02-rust/src/hww/api/bitcoin.rs
@@ -232,7 +232,7 @@ pub async fn address_multisig(
display: bool,
) -> Result<Response, Error> {
let coin_params = params::get(coin);
- keypath::validate_address_policy(keypath, keypath::ReceiveSpend::Receive)
+ keypath::validate_address_multisig(keypath, keypath::ReceiveSpend::Receive)
.or(Err(Error::InvalidInput))?;
let account_keypath = &keypath[..keypath.len() - 2];
multisig::validate(hal, multisig, account_keypath).await?;
@@ -1128,6 +1128,20 @@ mod tests {
},
]
);
+
+ for display in [false, true] {
+ let mut req = req.clone();
+ req.display = display;
+ req.keypath[account_keypath.len()] = 0;
+ assert!(process_pub(&mut mock_hal, &req).await.is_ok());
+ for branch in [2, 5000, HARDENED - 1] {
+ req.keypath[account_keypath.len()] = branch;
+ assert_eq!(
+ process_pub(&mut mock_hal, &req).await,
+ Err(Error::InvalidInput),
+ );
+ }
+ }
}
}
### src/rust/bitbox02-rust/src/hww/api/bitcoin/keypath.rs
@@ -107,6 +107,18 @@ pub fn validate_address_policy(keypath: &[u32], mode: ReceiveSpend) -> Result<()
}
}
+/// Validates a multisig address keypath with any nonempty account prefix.
+///
+/// Receiving requires branch 0 or 1 and an address index below 10000.
+/// Spending leaves both indices unrestricted so funds at nonstandard paths can be recovered.
+pub fn validate_address_multisig(keypath: &[u32], mode: ReceiveSpend) -> Result<(), ()> {
+ validate_address_policy(keypath, mode)?;
+ if mode == ReceiveSpend::Receive && keypath[keypath.len() - 2] > 1 {
+ return Err(());
+ }
+ Ok(())
+}
+
/// Validates a singlesig keypath.
/// Supported:
/// - P2WPKH-P2SH: m/49'/coin'/account'
@@ -464,6 +476,31 @@ mod tests {
}
}
+ #[test]
+ fn test_validate_address_multisig() {
+ let invalid_keypaths: [&[u32]; 3] = [&[], &[45 + HARDENED], &[45 + HARDENED, 0]];
+ for mode in [ReceiveSpend::Receive, ReceiveSpend::Spend] {
+ for keypath in invalid_keypaths {
+ assert!(validate_address_multisig(keypath, mode).is_err());
+ }
+ for branch in [0, 1] {
+ assert!(validate_address_multisig(&[45 + HARDENED, branch, 0], mode).is_ok());
+ assert!(validate_address_multisig(&[123, 456, branch, 9999], mode).is_ok());
+ }
+ }
+ for (branch, address) in [
+ (0, 10000),
+ (1, 10000),
+ (2, 0),
+ (5000, 9999),
+ (HARDENED - 1, HARDENED - 1),
+ ] {
+ let keypath = [45 + HARDENED, branch, address];
+ assert!(validate_address_multisig(&keypath, ReceiveSpend::Receive).is_err());
+ assert!(validate_address_multisig(&keypath, ReceiveSpend::Spend).is_ok());
+ }
+ }
+
#[test]
fn test_validate_address_policy() {
for mode in [ReceiveSpend::Receive, ReceiveSpend::Spend] {
### src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
@@ -249,7 +249,10 @@ fn validate_keypath(
)
.or(Err(Error::InvalidInput))?;
}
- ValidatedScriptConfig::Multisig { .. } | ValidatedScriptConfig::Policy { .. } => {
+ ValidatedScriptConfig::Multisig { .. } => {
+ keypath::validate_address_multisig(keypath, mode).or(Err(Error::InvalidInput))?;
+ }
+ ValidatedScriptConfig::Policy { .. } => {
keypath::validate_address_policy(keypath, mode).or(Err(Error::InvalidInput))?;
}
}
@@ -1047,9 +1050,17 @@ async fn _process(
let displayed_source_amount = format_amount(coin_params, format_unit, total_value)?;
payment_request::user_verify(hal, &payment_request, &displayed_source_amount)
.await?;
+ let source_account = match &validated_script_configs[0] {
+ ValidatedScriptConfigWithKeypath {
+ keypath,
+ config: ValidatedScriptConfig::SimpleType(_),
+ } => Some(keypath[2]),
+ _ => None,
+ };
match payment_request::validate_btc(
hal,
coin_params,
+ source_account,
&payment_request,
total_value,
&address()?,
@@ -2624,6 +2635,32 @@ mod tests {
}
}
+ #[test]
+ fn test_validate_keypath_multisig() {
+ use keypath::ReceiveSpend::{Receive, Spend};
+
+ let params = super::super::params::get(pb::BtcCoin::Btc);
+ let multisig = pb::btc_script_config::Multisig::default();
+ let config = ValidatedScriptConfigWithKeypath {
+ keypath: &[45 + HARDENED],
+ config: ValidatedScriptConfig::Multisig {
+ name: "test multisig".into(),
+ multisig: &multisig,
+ },
+ };
+ for (branch, mode, expected) in [
+ (0, Receive, Ok(())),
+ (1, Receive, Ok(())),
+ (5000, Receive, Err(Error::InvalidInput)),
+ (5000, Spend, Ok(())),
+ ] {
+ assert_eq!(
+ validate_keypath(params, &config, &[45 + HARDENED, branch, 0], mode),
+ expected,
+ );
+ }
+ }
+
#[async_test::test]
pub async fn test_sign_init_fail() {
*crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() = None;
@@ -3282,6 +3319,77 @@ mod tests {
assert_eq!(result, Err(Error::InvalidInput));
}
+ #[async_test::test]
+ async fn test_process_payment_request_refund_account() {
+ mock_unlocked();
+ let coin = pb::BtcCoin::Btc;
+ let coin_params = super::super::params::get(coin);
+ for refund_account in [10 + HARDENED, 11 + HARDENED] {
+ let transaction = new_transaction(coin).await;
+ let init_request = transaction.borrow().init_request();
+ let mut hal = TestingHal::new();
+ let keypath = vec![49 + HARDENED, coin_params.bip44_coin, refund_account, 1, 42];
+ let address = super::super::derive_address_simple(
+ &mut hal,
+ coin,
+ SimpleType::P2wpkhP2sh,
+ &keypath,
+ Compute::Once,
+ )
+ .await
+ .unwrap();
+ {
+ let mut transaction = transaction.borrow_mut();
+ let output = &mut transaction.outputs[0];
+ output.payment_request_index = Some(0);
+ let output_address = common::Payload {
+ output_type: pb::BtcOutputType::try_from(output.r#type).unwrap(),
+ data: output.payload.clone(),
+ }
+ .address(coin_params)
+ .unwrap();
+ let mut payment_request = pb::BtcPaymentRequestRequest {
+ recipient_name: "Test Merchant".into(),
+ total_amount: output.value,
+ memos: vec![Memo {
+ memo: Some(memo::Memo::RefundMemo(memo::RefundMemo {
+ address,
+ address_derivation: Some(memo::refund_memo::AddressDerivation::Btc(
+ memo::coin_purchase_memo::BtcAddressDerivation {
+ script_config: Some(pb::BtcScriptConfigWithKeypath {
+ script_config: Some(pb::BtcScriptConfig {
+ config: Some(
+ pb::btc_script_config::Config::SimpleType(
+ SimpleType::P2wpkhP2sh as _,
+ ),
+ ),
+ }),
+ keypath,
+ }),
+ },
+ )),
+ })),
+ }],
+ ..Default::default()
+ };
+ payment_request::tst_sign_payment_request_btc(
+ coin,
+ &mut payment_request,
+ output.value,
+ &output_address,
+ );
+ transaction.payment_request = Some(payment_request);
+ }
+ mock_host_responder(transaction);
+ let result = process(&mut hal, &init_request).await;
+ if refund_account == 10 + HARDENED {
+ assert!(result.is_ok());
+ } else {
+ assert_eq!(result, Err(Error::InvalidInput));
+ }
+ }
+ }
+
#[cfg(feature = "app-ethereum")]
#[test]
pub fn test_validate_swap_source_account() {
### src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs
@@ -178,14 +178,22 @@ async fn verify_standard_total_fee(
async fn verify_payment_request_recipient(
hal: &mut impl crate::hal::Hal,
params: &Params,
+ source_keypath: &[u32],
payment_request: &pb::BtcPaymentRequestRequest,
displayed_source_amount: &str,
output_value: &BigUint,
output_address: &str,
) -> Result<(), Error> {
payment_request::user_verify(hal, payment_request, displayed_source_amount).await?;
- match payment_request::validate_eth(hal, params, payment_request, output_value, output_address)
- .await
+ match payment_request::validate_eth(
+ hal,
+ params,
+ source_keypath,
+ payment_request,
+ output_value,
+ output_address,
+ )
+ .await
{
Ok(()) => Ok(()),
Err(_) => {
@@ -383,6 +391,7 @@ async fn verify_erc20_transaction(
verify_payment_request_recipient(
hal,
params,
+ request.keypath(),
payment_request,
&displayed_source_amount,
&erc20_value,
@@ -454,6 +463,7 @@ async fn verify_standard_transaction(
verify_payment_request_recipient(
hal,
params,
+ request.keypath(),
payment_request,
&displayed_source_amount,
&amount_value,
@@ -737,7 +747,9 @@ mod tests {
// Base payment request fixture for ETH-side swap tests.
fn make_eth_swap_payment_request() -> pb::BtcPaymentRequestRequest {
- pb::BtcPaymentRequestRequest {
+ use pb::btc_payment_request_request::{Memo, memo};
+
+ let mut request = pb::BtcPaymentRequestRequest {
recipient_name: "Test Merchant".into(),
memos: vec![pb::btc_payment_request_request::Memo {
memo: Some(pb::btc_payment_request_request::memo::Memo::CoinPurchaseMemo(
@@ -764,7 +776,18 @@ mod tests {
nonce: vec![],
total_amount: 0,
signature: vec![],
- }
+ };
+ request.memos.push(Memo {
+ memo: Some(memo::Memo::RefundMemo(memo::RefundMemo {
+ address: "0x773A77b9D32589be03f9132AF759e294f7851be9".into(),
+ address_derivation: Some(memo::refund_memo::AddressDerivation::Eth(
+ memo::coin_purchase_memo::EthAddressDerivation {
+ keypath: vec![44 + HARDENED, 60 + HARDENED, HARDENED, 0, 0],
+ },
+ )),
+ })),
+ });
+ request
}
#[test]
@@ -1365,32 +1388,40 @@ mod tests {
},
];
+ let mut request = pb::EthSignEip1559Request {
+ keypath: KEYPATH.to_vec(),
+ nonce: hex!("1fdc").to_vec(),
+ max_priority_fee_per_gas: b"".to_vec(),
+ max_fee_per_gas: hex!("0165a0bc00").to_vec(),
+ gas_limit: hex!("5208").to_vec(),
+ recipient: hex!("04f264cf34440313b4a0192a352814fbe927b885").to_vec(),
+ value: value.to_vec(),
+ data: b"".to_vec(),
+ host_nonce_commitment: None,
+ chain_id: 1,
+ address_case: pb::EthAddressCase::Mixed as _,
+ data_length: 0,
+ payment_request: Some(payment_request),
+ };
+
let mut mock_hal = TestingHal::new();
assert_eq!(
process(
&mut mock_hal,
- &Transaction::Eip1559(&pb::EthSignEip1559Request {
- keypath: KEYPATH.to_vec(),
- nonce: hex!("1fdc").to_vec(),
- max_priority_fee_per_gas: b"".to_vec(),
- max_fee_per_gas: hex!("0165a0bc00").to_vec(),
- gas_limit: hex!("5208").to_vec(),
- recipient: hex!("04f264cf34440313b4a0192a352814fbe927b885").to_vec(),
- value: value.to_vec(),
- data: b"".to_vec(),
- host_nonce_commitment: None,
- chain_id: 1,
- address_case: pb::EthAddressCase::Mixed as _,
- data_length: 0,
- payment_request: Some(payment_request),
- }),
+ &Transaction::Eip1559(&request),
).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("289111770dc067895780de3e9b30454e331ba6661f046e9e26431576d7f08a496ffe6deffb07dd8d4713d8c523b6c33b53dd6ef2dc9c394d6e21f64307d2bcf001")
.to_vec()
}))
);
assert_eq!(mock_hal.ui.screens, expected_screens);
+
+ request.keypath[4] = 1;
+ assert_eq!(
+ process(&mut TestingHal::new(), &Transaction::Eip1559(&request)).await,
+ Err(Error::InvalidInput)
+ );
}
#[async_test::test]
@@ -1444,32 +1475,40 @@ mod tests {
},
];
+ let mut request = pb::EthSignEip1559Request {
+ keypath: KEYPATH.to_vec(),
+ nonce: hex!("2367").to_vec(),
+ max_priority_fee_per_gas: hex!("3b9aca00").to_vec(),
+ max_fee_per_gas: hex!("027aca1a80").to_vec(),
+ gas_limit: hex!("01d048").to_vec(),
+ recipient: hex!("dac17f958d2ee523a2206206994597c13d831ec7").to_vec(),
+ value: b"".to_vec(),
+ data: data.to_vec(),
+ host_nonce_commitment: None,
+ chain_id: 1,
+ address_case: pb::EthAddressCase::Mixed as _,
+ data_length: 0,
+ payment_request: Some(payment_request),
+ };
+
let mut mock_hal = TestingHal::new();
assert_eq!(
process(
&mut mock_hal,
- &Transaction::Eip1559(&pb::EthSignEip1559Request {
- keypath: KEYPATH.to_vec(),
- nonce: hex!("2367").to_vec(),
- max_priority_fee_per_gas: hex!("3b9aca00").to_vec(),
- max_fee_per_gas: hex!("027aca1a80").to_vec(),
- gas_limit: hex!("01d048").to_vec(),
- recipient: hex!("dac17f958d2ee523a2206206994597c13d831ec7").to_vec(),
- value: b"".to_vec(),
- data: data.to_vec(),
- host_nonce_commitment: None,
- chain_id: 1,
- address_case: pb::EthAddressCase::Mixed as _,
- data_length: 0,
- payment_request: Some(payment_request),
- }),
+ &Transaction::Eip1559(&request),
).await,
Ok(Response::Sign(pb::EthSignResponse {
signature: hex!("3162487880abdea1f352d9a4e3d56066f122f04ff112117c8ca3cd220f1666302dacd5e5e8da4cd39704e33443a9a7f32602d332bb52567c2e34aafe9ed48feb01")
.to_vec()
}))
);
assert_eq!(mock_hal.ui.screens, expected_screens);
+
+ request.keypath[4] = 1;
+ assert_eq!(
+ process(&mut TestingHal::new(), &Transaction::Eip1559(&request)).await,
+ Err(Error::InvalidInput)
+ );
}
async fn erc20_transfer_screens(contract: [u8; 20], eip1559: bool, value: u64) -> Vec<Screen> {
### src/rust/bitbox02-rust/src/hww/api/payment_request.rs
@@ -27,41 +27,54 @@ const MAX_MEMOS_NUM: usize = 3;
// UI text limit so every supported device can show them in full.
const MAX_COIN_PURCHASE_AMOUNT_LEN: usize = 200;
+// Only providers whose source transactions are verified by the firmware may be trusted.
+const ALLOWED_SWAPKIT_RECIPIENT_NAMES: &[&str] = &["SWAPKIT (NEAR)"];
+
struct Identity {
name: &'static str,
public_key: &'static [u8],
+ requires_refund: bool,
}
const IDENTITIES: &[Identity] = &[
Identity {
name: "POCKET",
public_key: &hex!("022902b4ede482a907ce16a1c634145e728f1de4f249043a8be47df27db9320c2c"),
+ requires_refund: false,
},
Identity {
name: "SWAPKIT",
- public_key: &hex!("02bf5740a2b794b33d73358d7313e9cb260058f3ac6c886fcc388d9f3f0b48a90d"),
+ public_key: &hex!("02442ae21ca5da50d367a4b8bbd64ae71377ae2b4c1ceef8f8ebe43280aa158f17"),
+ requires_refund: true,
},
#[cfg(any(feature = "testing", feature = "c-unit-testing"))]
Identity {
name: "Test Merchant",
// private_key: b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
public_key: &hex!("02e5a018b3a2e155316109d9cdc5eab739759c0e07e0c00bf9fccb8237fe4d7f02"),
+ requires_refund: false,
+ },
+ #[cfg(any(feature = "testing", feature = "c-unit-testing"))]
+ Identity {
+ name: "Test Swap",
+ public_key: &hex!("02e5a018b3a2e155316109d9cdc5eab739759c0e07e0c00bf9fccb8237fe4d7f02"),
+ requires_refund: true,
},
];
/// Looks up the signing identity for a payment request recipient name.
///
-/// Most recipients must match an entry in `IDENTITIES` exactly. `SWAPKIT` is a
-/// special case: any recipient name containing `swapkit`, in any ASCII case,
-/// is matched to the fixed `SWAPKIT` identity so provider-specific or legacy
-/// naming variants are accepted.
+/// SwapKit provider names must be explicitly allowed. The recipient name is
+/// covered by the payment request signature, so the host cannot change it.
fn find_identity(name: &str) -> Option<&Identity> {
- if name.to_ascii_uppercase().contains("SWAPKIT") {
+ if ALLOWED_SWAPKIT_RECIPIENT_NAMES.contains(&name) {
return IDENTITIES
.iter()
.find(|identity| identity.name == "SWAPKIT");
}
- IDENTITIES.iter().find(|identity| identity.name == name)
+ IDENTITIES
+ .iter()
+ .find(|identity| identity.name == name && identity.name != "SWAPKIT")
}
pub(super) fn contains_coin_purchase_memo(payment_request: &pb::BtcPaymentRequestRequest) -> bool {
@@ -184,6 +197,9 @@ pub async fn user_verify(
.confirm_swap(&title, displayed_source_amount, &coin_purchase_memo.amount)
.await?;
}
+ Memo {
+ memo: Some(memo::Memo::RefundMemo(_)),
+ } => {}
_ => return Err(Error::InvalidInput),
}
}
@@ -194,7 +210,6 @@ pub async fn user_verify(
pub enum ValidationError {
UnknownRecipient,
InvalidSignature,
- #[cfg(feature = "app-ethereum")]
AddressMismatch,
#[cfg(not(feature = "app-ethereum"))]
Disabled,
@@ -233,6 +248,12 @@ fn compute_sighash(
sighash.update(1u32.to_le_bytes());
hash_data_lenprefixed(&mut sighash, text_memo.note.as_bytes());
}
+ Memo {
+ memo: Some(memo::Memo::RefundMemo(refund_memo)),
+ } => {
+ sighash.update(2u32.to_le_bytes());
+ hash_data_lenprefixed(&mut sighash, refund_memo.address.as_bytes());
+ }
#[cfg(feature = "app-ethereum")]
Memo {
memo: Some(memo::Memo::CoinPurchaseMemo(coin_purchase_memo)),
@@ -327,8 +348,9 @@ fn ecdsa_verify(sig64: &[u8], msg32: &[u8], pubkey33: &[u8]) -> Result<(), Valid
/// Validate a BTC payment request against the parsed BTC output total.
pub async fn validate_btc(
- #[cfg_attr(not(feature = "app-ethereum"), allow(unused_variables))] hal: &mut impl crate::hal::Hal,
+ hal: &mut impl crate::hal::Hal,
coin_params: &super::bitcoin::params::Params,
+ source_account: Option<u32>,
payment_request: &pb::BtcPaymentRequestRequest,
total_value: u64,
output_address: &str,
@@ -344,14 +366,50 @@ pub async fn validate_btc(
&total_value_bytes,
output_address,
)
- .await
+ .await?;
+ for refund in refund_memos(payment_request) {
+ let Some(memo::refund_memo::AddressDerivation::Btc(derivation)) =
+ &refund.address_derivation
+ else {
+ return Err(ValidationError::Other);
+ };
+ let script_config = derivation
+ .script_config
+ .as_ref()
+ .ok_or(ValidationError::Other)?;
+ let source_account = source_account.ok_or(ValidationError::Other)?;
+ if script_config.keypath.get(2) != Some(&source_account) {
+ return Err(ValidationError::Other);
+ }
+ let simple_type = match script_config.script_config.as_ref() {
+ Some(pb::BtcScriptConfig {
+ config: Some(pb::btc_script_config::Config::SimpleType(simple_type)),
+ }) => pb::btc_script_config::SimpleType::try_from(*simple_type)
+ .map_err(|_| ValidationError::Other)?,
+ _ => return Err(ValidationError::Other),
+ };
+ let derived_address = super::bitcoin::derive_address_simple(
+ hal,
+ coin_params.coin,
+ simple_type,
+ &script_config.keypath,
+ crate::keystore::Compute::Once,
+ )
+ .await
+ .map_err(|_| ValidationError::Other)?;
+ if derived_address != refund.address {
+ return Err(ValidationError::AddressMismatch);
+ }
+ }
+ Ok(())
}
/// Validate an ETH/EVM payment request against the parsed source-side transaction.
#[cfg(feature = "app-ethereum")]
pub async fn validate_eth(
hal: &mut impl crate::hal::Hal,
coin_params: &super::ethereum::params::Params,
+ source_keypath: &[u32],
payment_request: &pb::BtcPaymentRequestRequest,
output_value: &BigUint,
output_address: &str,
@@ -364,7 +422,42 @@ pub async fn validate_eth(
&output_value_padded,
output_address,
)
- .await
+ .await?;
+ for refund in refund_memos(payment_request) {
+ let Some(memo::refund_memo::AddressDerivation::Eth(derivation)) =
+ &refund.address_derivation
+ else {
+ return Err(ValidationError::Other);
+ };
+ if derivation.keypath.get(1) != Some(&coin_params.bip44_coin)
+ || derivation.keypath != source_keypath
+ {
+ return Err(ValidationError::Other);
+ }
+ let derived_address = super::ethereum::derive_address(
+ hal,
+ &derivation.keypath,
+ crate::keystore::Compute::Once,
+ )
+ .await
+ .map_err(|_| ValidationError::Other)?;
+ if derived_address != refund.address {
+ return Err(ValidationError::AddressMismatch);
+ }
+ }
+ Ok(())
+}
+
+fn refund_memos(
+ payment_request: &pb::BtcPaymentRequestRequest,
+) -> impl Iterator<Item = &memo::RefundMemo> {
+ payment_request
+ .memos
+ .iter()
+ .filter_map(|memo| match &memo.memo {
+ Some(memo::Memo::RefundMemo(refund)) => Some(refund),
+ _ => None,
+ })
}
#[cfg(feature = "app-ethereum")]
@@ -403,7 +496,17 @@ async fn validate_common(
if payment_request.memos.len() > MAX_MEMOS_NUM {
return Err(ValidationError::Other);
}
- if contains_coin_purchase_memo(payment_request) && payment_request.memos.len() != 1 {
+ let num_refunds = refund_memos(payment_request).count();
+ let num_purchases = payment_request
+ .memos
+ .iter()
+ .filter(|memo| matches!(&memo.memo, Some(memo::Memo::CoinPurchaseMemo(_))))
+ .count();
+ if num_refunds > 1
+ || num_purchases > 1
+ || (identity.requires_refund && (num_refunds != 1 || num_purchases != 1))
+ || (num_purchases == 1 && payment_request.memos.len() != 1 + num_refunds)
+ {
return Err(ValidationError::Other);
}
for memo in payment_request.memos.iter() {
@@ -565,21 +668,412 @@ mod tests {
#[test]
fn test_find_identity() {
- assert_eq!(find_identity("POCKET").unwrap().name, "POCKET");
+ // Other known recipients retain their own identity and refund policy.
+ for (name, requires_refund) in [
+ ("POCKET", false),
+ ("Test Merchant", false),
+ ("Test Swap", true),
+ ] {
+ let identity = find_identity(name).unwrap();
+ assert_eq!(identity.name, name);
+ assert_eq!(identity.requires_refund, requires_refund);
+ }
- let swapkit_identity = find_identity("SWAPKIT (Provider)").unwrap();
- assert_eq!(swapkit_identity.name, "SWAPKIT");
+ // Only explicitly approved SwapKit providers use the SwapKit signing key.
+ let identity = find_identity("SWAPKIT (NEAR)").unwrap();
+ assert_eq!(identity.name, "SWAPKIT");
+ assert!(identity.requires_refund);
assert_eq!(
- swapkit_identity.public_key,
- hex!("02bf5740a2b794b33d73358d7313e9cb260058f3ac6c886fcc388d9f3f0b48a90d")
+ identity.public_key,
+ hex!("02442ae21ca5da50d367a4b8bbd64ae71377ae2b4c1ceef8f8ebe43280aa158f17")
);
- assert_eq!(find_identity("SWAPKIT Provider").unwrap().name, "SWAPKIT");
- assert_eq!(find_identity("swapkit (Provider)").unwrap().name, "SWAPKIT");
- assert_eq!(find_identity("SWAPKIT").unwrap().name, "SWAPKIT");
- assert_eq!(find_identity("SwapKit").unwrap().name, "SWAPKIT");
+ // Unsupported SwapKit providers must not resolve to a signing identity.
+ for name in [
+ "SWAPKIT (FLASHNET)",
+ "SWAPKIT (THORCHAIN_STREAMING)",
+ "SWAPKIT (MAYA)",
+ ] {
+ assert!(find_identity(name).is_none(), "{name}");
+ }
+
+ // Bare, altered, and unknown names must not resolve to an identity.
+ for name in [
+ "SWAPKIT",
+ "SWAPKIT (NEAR) extra",
+ "swapkit (NEAR)",
+ "SwapKit (NEAR)",
+ "Provider",
+ ] {
+ assert!(find_identity(name).is_none(), "{name}");
+ }
+ }
+
+ #[cfg(all(feature = "app-ethereum", feature = "app-litecoin"))]
+ fn make_swap_request(refund: memo::RefundMemo) -> pb::BtcPaymentRequestRequest {
+ pb::BtcPaymentRequestRequest {
+ recipient_name: "Test Swap".into(),
+ memos: vec![
+ make_coin_purchase_memo(
+ 60,
+ "0.25 ETH",
+ "0x773A77b9D32589be03f9132AF759e294f7851be9",
+ Some(dummy_eth_address_derivation(true)),
+ ),
+ Memo {
+ memo: Some(memo::Memo::RefundMemo(refund)),
+ },
+ ],
+ nonce: vec![],
+ total_amount: 100000,
+ signature: vec![],
+ }
+ }
- assert!(find_identity("Provider").is_none());
+ #[cfg(all(feature = "app-ethereum", feature = "app-litecoin"))]
+ fn make_eth_refund() -> memo::RefundMemo {
+ memo::RefundMemo {
+ address: "0x773A77b9D32589be03f9132AF759e294f7851be9".into(),
+ address_derivation: Some(memo::refund_memo::AddressDerivation::Eth(
+ memo::coin_purchase_memo::EthAddressDerivation {
+ keypath: vec![
+ 44 + util::bip32::HARDENED,
+ 60 + util::bip32::HARDENED,
+ util::bip32::HARDENED,
+ 0,
+ 0,
+ ],
+ },
+ )),
+ }
+ }
+
+ #[cfg(all(feature = "app-ethereum", feature = "app-litecoin"))]
+ #[test]
+ fn test_sighash_refund() {
+ let mut request = make_swap_request(memo::RefundMemo {
+ address: "bc1qaff6ey7a8nztdl8ufluu5eagpwy6sntmaf53pf".into(),
+ address_derivation: None,
+ });
+ let output_address = "bc1qkkweqa5vk942jgevs0x0h8hsmqgfr08n6l7tu9";
+ let value = 100000u64.to_le_bytes();
+ assert_eq!(
+ compute_sighash(0, &request, &value, output_address).unwrap(),
+ hex!("eda7a0a2a0f1e24227e58add144371008744d6fbc14aca0a415f0b1281e10863")
+ );
+ request.memos.swap(0, 1);
+ assert_eq!(
+ compute_sighash(0, &request, &value, output_address).unwrap(),
+ hex!("f71781f2f7ac2a2557ea1b84f93c50291a4facc4d429ac1270923e44cd364754")
+ );
+ }
+
+ #[cfg(all(feature = "app-ethereum", feature = "app-litecoin"))]
+ #[async_test::test]
+ async fn test_validate_swap_refund_required() {
+ crate::keystore::testing::mock_unlocked();
+ let mut hal = TestingHal::new();
+ let request = make_swap_request(make_eth_refund());
+ let purchase = request.memos[0].clone();
+ let refund = request.memos[1].clone();
+ for recipient in ["Test Swap", "SWAPKIT (NEAR)"] {
+ for memos in [
+ vec![],
+ vec![purchase.clone()],
+ vec![refund.clone()],
+ vec![make_text_memo("Swap")],
+ vec![purchase.clone(), make_text_memo("Refund to our wallet")],
+ vec![purchase.clone(), refund.clone(), refund.clone()],
+ vec![purchase.clone(), purchase.clone(), refund.clone()],
+ vec![purchase.clone(), refund.clone(), make_text_memo("extra")],
+ ] {
+ let mut request = request.clone();
+ request.recipient_name = recipient.into();
+ request.memos = memos;
+ tst_sign_payment_request_btc(pb::BtcCoin::Btc, &mut request, 100000, "deposit");
+ assert!(matches!(
+ validate_btc(
+ &mut hal,
+ params::get(pb::BtcCoin::Btc),
+ Some(util::bip32::HARDENED),
+ &request,
+ 100000,
+ "deposit"
+ )
+ .await,
+ Err(ValidationError::Other)
+ ));
+ }
+ }
+ }
+
+ #[cfg(all(feature = "app-ethereum", feature = "app-litecoin"))]
+ #[async_test::test]
+ async fn test_validate_btc_refund() {
+ use crate::keystore::testing::mock_unlocked;
+ use pb::btc_script_config::SimpleType;
+ use util::bip32::HARDENED;
+
+ mock_unlocked();
+ let mut hal = TestingHal::new();
+ for (coin, simple_type, purpose, change) in [
+ (pb::BtcCoin::Btc, SimpleType::P2wpkh, 84, 0),
+ (pb::BtcCoin::Btc, SimpleType::P2wpkhP2sh, 49, 0),
+ (pb::BtcCoin::Btc, SimpleType::P2tr, 86, 1),
+ (pb::BtcCoin::Ltc, SimpleType::P2wpkh, 84, 1),
+ (pb::BtcCoin::Ltc, SimpleType::P2wpkhP2sh, 49, 0),
+ ] {
+ let coin_params = params::get(coin);
+ let source_account = 7 + HARDENED;
+ let keypath = vec![
+ purpose + HARDENED,
+ coin_params.bip44_coin,
+ source_account,
+ change,
+ 0,
+ ];
+ let address = super::super::bitcoin::derive_address_simple(
+ &mut hal,
+ coin,
+ simple_type,
+ &keypath,
+ crate::keystore::Compute::Once,
+ )
+ .await
+ .unwrap();
+ let refund = memo::RefundMemo {
+ address: address.clone(),
+ address_derivation: Some(memo::refund_memo::AddressDerivation::Btc(
+ memo::coin_purchase_memo::BtcAddressDerivation {
+ script_config: Some(pb::BtcScriptConfigWithKeypath {
+ script_config: Some(pb::BtcScriptConfig {
+ config: Some(pb::btc_script_config::Config::SimpleType(
+ simple_type as _,
+ )),
+ }),
+ keypath,
+ }),
+ },
+ )),
+ };
+ let mut request = make_swap_request(refund.clone());
+ tst_sign_payment_request_btc(coin, &mut request, 100000, &address);
+ assert!(
+ validate_btc(
+ &mut hal,
+ coin_params,
+ Some(source_account),
+ &request,
+ 100000,
+ &address
+ )
+ .await
+ .is_ok()
+ );
+
+ for account in [None, Some(source_account + 1)] {
+ assert!(matches!(
+ validate_btc(&mut hal, coin_params, account, &request, 100000, &address).await,
+ Err(ValidationError::Other)
+ ));
+ }
+
+ request.memos.swap(0, 1);
+ assert!(matches!(
+ validate_btc(
+ &mut hal,
+ coin_params,
+ Some(source_account),
+ &request,
+ 100000,
+ &address
+ )
+ .await,
+ Err(ValidationError::InvalidSignature)
+ ));
+ tst_sign_payment_request_btc(coin, &mut request, 100000, &address);
+ assert!(
+ validate_btc(
+ &mut hal,
+ coin_params,
+ Some(source_account),
+ &request,
+ 100000,
+ &address
+ )
+ .await
+ .is_ok()
+ );
+
+ let mut attacker_refund = refund.clone();
+ attacker_refund.address = "bc1qaff6ey7a8nztdl8ufluu5eagpwy6sntmaf53pf".into();
+ let mut request = make_swap_request(attacker_refund);
+ tst_sign_payment_request_btc(coin, &mut request, 100000, &address);
+ assert!(matches!(
+ validate_btc(
+ &mut hal,
+ coin_params,
+ Some(source_account),
+ &request,
+ 100000,
+ &address
+ )
+ .await,
+ Err(ValidationError::AddressMismatch)
+ ));
+
+ for modification in 0..6 {
+ let mut invalid_refund = refund.clone();
+ let Some(memo::refund_memo::AddressDerivation::Btc(derivation)) =
+ &mut invalid_refund.address_derivation
+ else {
+ unreachable!()
+ };
+ let script = derivation.script_config.as_mut().unwrap();
+ match modification {
+ 0 => script.keypath[1] = 1 + HARDENED,
+ 1 => {
+ script.keypath.pop();
+ }
+ 2 => script.script_config = None,
+ 3 => {
+ script.script_config.as_mut().unwrap().config =
+ Some(pb::btc_script_config::Config::SimpleType(999))
+ }
+ 4 => invalid_refund.address_derivation = None,
+ 5 => invalid_refund.address_derivation = make_eth_refund().address_derivation,
+ _ => unreachable!(),
+ }
+ let mut request = make_swap_request(invalid_refund);
+ tst_sign_payment_request_btc(coin, &mut request, 100000, &address);
+ assert!(matches!(
+ validate_btc(
+ &mut hal,
+ coin_params,
+ Some(source_account),
+ &request,
+ 100000,
+ &address
+ )
+ .await,
+ Err(ValidationError::Other)
+ ));
+ }
+ }
+ }
+
+ #[cfg(all(feature = "app-ethereum", feature = "app-litecoin"))]
+ #[async_test::test]
+ async fn test_validate_eth_refund() {
+ use crate::keystore::testing::mock_unlocked;
+ use util::bip32::HARDENED;
+ mock_unlocked();
+ let mut hal = TestingHal::new();
+ let coin_params = ð_params::Params {
+ coin: Some(pb::EthCoin::Eth),
+ bip44_coin: 60 + util::bip32::HARDENED,
+ chain_id: 1,
+ name: "Ethereum",
+ unit: "ETH",
+ };
+ let source_keypath = [44 + HARDENED, 60 + HARDENED, HARDENED, 0, 0];
+ let value = BigUint::from(100000u64);
+ let value_bytes = serialize_eth_output_value(&value).unwrap();
+ let deposit = "0x1111111111111111111111111111111111111111";
+ let mut request = make_swap_request(make_eth_refund());
+ tst_sign_payment_request_eth(60, &mut request, &value_bytes, deposit);
+ assert!(
+ validate_eth(
+ &mut hal,
+ coin_params,
+ &source_keypath,
+ &request,
+ &value,
+ deposit
+ )
+ .await
+ .is_ok()
+ );
+
+ let mut other_keypath = source_keypath;
+ other_keypath[4] += 1;
+ assert!(matches!(
+ validate_eth(
+ &mut hal,
+ coin_params,
+ &other_keypath,
+ &request,
+ &value,
+ deposit
+ )
+ .await,
+ Err(ValidationError::Other)
+ ));
+
+ let mut changed = request.clone();
+ if let Some(memo::Memo::RefundMemo(refund)) = &mut changed.memos[1].memo {
+ refund.address = deposit.into();
+ }
+ assert!(matches!(
+ validate_eth(
+ &mut hal,
+ coin_params,
+ &source_keypath,
+ &changed,
+ &value,
+ deposit
+ )
+ .await,
+ Err(ValidationError::InvalidSignature)
+ ));
+ tst_sign_payment_request_eth(60, &mut changed, &value_bytes, deposit);
+ assert!(matches!(
+ validate_eth(
+ &mut hal,
+ coin_params,
+ &source_keypath,
+ &changed,
+ &value,
+ deposit
+ )
+ .await,
+ Err(ValidationError::AddressMismatch)
+ ));
+
+ for modification in 0..3 {
+ let mut changed = request.clone();
+ let Some(memo::Memo::RefundMemo(refund)) = &mut changed.memos[1].memo else {
+ unreachable!()
+ };
+ let Some(memo::refund_memo::AddressDerivation::Eth(derivation)) =
+ &mut refund.address_derivation
+ else {
+ unreachable!()
+ };
+ match modification {
+ 0 => derivation.keypath[1] = 1 + util::bip32::HARDENED,
+ 1 => {
+ derivation.keypath.pop();
+ }
+ 2 => refund.address_derivation = None,
+ _ => unreachable!(),
+ }
+ assert!(matches!(
+ validate_eth(
+ &mut hal,
+ coin_params,
+ &source_keypath,
+ &changed,
+ &value,
+ deposit
+ )
+ .await,
+ Err(ValidationError::Other)
+ ));
+ }
+ let mut hal = TestingHal::new();
+ user_verify(&mut hal, &request, "0.1 ETH").await.unwrap();
+ assert_eq!(hal.ui.screens.len(), 2);
}
#[test]
@@ -1492,6 +1986,7 @@ mod tests {
validate_btc(
&mut mock_hal,
params::get(pb::BtcCoin::Tbtc),
+ None,
&payment_request,
value + 1,
address
@@ -1544,8 +2039,10 @@ mod tests {
#[async_test::test]
async fn test_user_verify_recipient_name() {
for (recipient_name, valid) in [
- ("SWAPKIT (Provider)", true),
- ("swapkit (Provider)", true),
+ ("SWAPKIT (NEAR)", true),
+ ("SWAPKIT (THORCHAIN_STREAMING)", false),
+ ("SWAPKIT (FLASHNET)", false),
+ ("swapkit (NEAR)", false),
("SWAPKIT\nProvider", false),
("SWAPKIT (Prövider)", false),
("SWAPKIT\tProvider", false),
@@ -1647,35 +2144,6 @@ mod tests {
}
}
- #[async_test::test]
- async fn test_user_verify_long_recipient_name_scrollable() {
- let recipient_name = format!("SWAPKIT ({})", "a".repeat(200));
- let mut mock_hal = TestingHal::new();
- user_verify(
- &mut mock_hal,
- &pb::BtcPaymentRequestRequest {
- recipient_name: recipient_name.clone(),
- memos: vec![make_text_memo("Swap memo")],
- nonce: vec![],
- total_amount: 1234567890,
- signature: vec![],
- },
- "12.34567890 BTC",
- )
- .await
- .unwrap();
-
- assert_eq!(
- mock_hal.ui.screens[1],
- Screen::Confirm {
- title: "".into(),
- body: format!("Memo from: {recipient_name}"),
- longtouch: false,
- }
- );
- assert!(mock_hal.ui.confirm_scrollable[0]);
- }
-
#[cfg(feature = "app-ethereum")]
#[async_test::test]
async fn test_user_verify_swap() {
@@ -1684,7 +2152,7 @@ mod tests {
user_verify(
&mut mock_hal,
&pb::BtcPaymentRequestRequest {
- recipient_name: "SWAPKIT (Provider)".into(),
+ recipient_name: "SWAPKIT (NEAR)".into(),
memos: vec![make_coin_purchase_memo(
60,
"0.25 ETH",
@@ -1704,7 +2172,7 @@ mod tests {
mock_hal.ui.screens,
vec![
Screen::Recipient {
- recipient: "SWAPKIT (Provider)".into(),
+ recipient: "SWAPKIT (NEAR)".into(),
amount: "0.25000000 BTC".into(),
},
Screen::Swap {
@@ -1723,7 +2191,7 @@ mod tests {
user_verify(
&mut mock_hal,
&pb::BtcPaymentRequestRequest {
- recipient_name: "SWAPKIT (Provider)".into(),
+ recipient_name: "SWAPKIT (NEAR)".into(),
memos: vec![make_coin_purchase_memo(
60,
"12.45678901234 ETH",
@@ -1743,7 +2211,7 @@ mod tests {
mock_hal.ui.screens,
vec![
Screen::Recipient {
- recipient: "SWAPKIT (Provider)".into(),
+ recipient: "SWAPKIT (NEAR)".into(),
amount: "0.25000000 BTC".into(),
},
Screen::Swap {
@@ -1763,7 +2231,7 @@ mod tests {
user_verify(
&mut mock_hal,
&pb::BtcPaymentRequestRequest {
- recipient_name: "SWAPKIT (Provider)".into(),
+ recipient_name: "SWAPKIT (NEAR)".into(),
memos: vec![make_coin_purchase_memo(
2,
"0.25 LTC",
@@ -1792,7 +2260,7 @@ mod tests {
mock_hal.ui.screens,
vec![
Screen::Recipient {
- recipient: "SWAPKIT (Provider)".into(),
+ recipient: "SWAPKIT (NEAR)".into(),
amount: "0.25000000 BTC".into(),
},
Screen::Swap {
@@ -1809,6 +2277,13 @@ mod tests {
async fn test_validate_eth() {
crate::keystore::testing::mock_unlocked();
let mut mock_hal = TestingHal::new();
+ let source_keypath = [
+ 44 + util::bip32::HARDENED,
+ 60 + util::bip32::HARDENED,
+ util::bip32::HARDENED,
+ 0,
+ 0,
+ ];
let params = eth_params::Params {
coin: Some(pb::EthCoin::Eth),
bip44_coin: 60 + util::bip32::HARDENED,
@@ -1842,6 +2317,7 @@ mod tests {
validate_eth(
&mut mock_hal,
¶ms,
+ &source_keypath,
&payment_request,
&BigUint::from_bytes_le(&output_value),
output_address,
@@ -1855,6 +2331,7 @@ mod tests {
validate_eth(
&mut TestingHal::new(),
¶ms,
+ &source_keypath,
&payment_request,
&BigUint::from_bytes_le(&output_value[..8]),
output_address,
@@ -1870,6 +2347,7 @@ mod tests {
validate_eth(
&mut TestingHal::new(),
¶ms,
+ &source_keypath,
&payment_request,
&BigUint::from_bytes_le(&wrong_output_value),
output_address,
@@ -1883,6 +2361,7 @@ mod tests {
validate_eth(
&mut TestingHal::new(),
¶ms,
+ &source_keypath,
&payment_request,
&BigUint::from_bytes_le(&output_value),
"0x1111111111111111111111111111111111111111",
@@ -1902,6 +2381,7 @@ mod tests {
name: "Ethereum",
unit: "ETH",
},
+ &source_keypath,
&payment_request,
&BigUint::from_bytes_le(&output_value),
output_address,
@@ -1916,7 +2396,7 @@ mod tests {
async fn test_user_verify_swap_invalid() {
// Display amount must be exactly "<positive-decimal> <unit>".
let payment_request = pb::BtcPaymentRequestRequest {
- recipient_name: "SWAPKIT (Provider)".into(),
+ recipient_name: "SWAPKIT (NEAR)".into(),
memos: vec![make_coin_purchase_memo(
60,
"foo bar baz",
### versions.json
@@ -1,5 +1,5 @@
{
- "firmware": "v9.27.2",
+ "firmware": "v9.29.0",
"bootloader": "v1.2.3",
"stage0": 3
}Why this scored 70/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.