Repository navigation
Expand file tree
/
Copy patherror_codes.h
More file actions
201 lines (154 loc) · 9.5 KB
/
Copy patherror_codes.h
File metadata and controls
201 lines (154 loc) · 9.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#pragma once
/* SDK headers */
#ifdef HAVE_SWAP
#include "swap_error_code_helpers.h"
#endif /* HAVE_SWAP */
/**
* REGISTER_WALLET
*/
// The name of the policy is not acceptable
#define EC_REGISTER_WALLET_UNACCEPTABLE_POLICY_NAME 0x0000
// The wallet policy does not respect the requirement of BIP-388, or the sanity rules of miniscript
#define EC_REGISTER_WALLET_POLICY_NOT_SANE 0x0001
// No key in the wallet policy was recognized as internal.
#define EC_REGISTER_WALLET_POLICY_HAS_NO_INTERNAL_KEY 0x0002
// A musig() key expression in the wallet policy has more than one internal key.
#define EC_REGISTER_WALLET_MUSIG_WITH_MULTIPLE_INTERNAL_KEYS 0x0003
// The wallet policy has more key expressions with internal keys than supported for signing.
#define EC_REGISTER_WALLET_TOO_MANY_INTERNAL_KEY_EXPRESSIONS 0x0004
/**
* SIGN_PSBT
*/
// The wallet policy is not standard; it must be registered first and the HMAC must be provided.
#define EC_SIGN_PSBT_MISSING_HMAC_FOR_NONDEFAULT_POLICY 0x0000
// For standard wallet policies, the name must be zero-length (empty).
#define EC_SIGN_PSBT_NO_NAME_FOR_DEFAULT_POLICY 0x0001
// No key in the wallet policy was recognized as internal.
#define EC_SIGN_PSBT_WALLET_POLICY_HAS_NO_INTERNAL_KEY 0x0002
// Depending on the transaction type, at least one of the non-witness UTXO or witness UTXO must be
// present in the PSBT. Check in BIP-174 for the specific requirements for the transaction type.
#define EC_SIGN_PSBT_MISSING_NONWITNESSUTXO_AND_WITNESSUTXO 0x0003
// Failed to check the txid recomputed from the non-witness-utxo. Make sure that the
// non-witness-utxo and the PSBT_IN_PREVIOUS_TXID fields are filled correctly.
#define EC_SIGN_PSBT_NONWITNESSUTXO_CHECK_FAILED 0x0004
// The scriptpubkey or the amount in the non-witness-utxo does not match the one in the
// witness-utxo.
#define EC_SIGN_PSBT_NONWITNESSUTXO_AND_WITNESSUTXO_MISMATCH 0x0005
// Per BIP-174, legacy inputs must have the non-witness-utxo, but no witness-utxo.
#define EC_SIGN_PSBT_MISSING_NONWITNESSUTXO_OR_UNEXPECTED_WITNESSUTXO_FOR_LEGACY 0x0006
// Per BIP-174, all segwit (or taproot) inputs must have the witness-utxo field.
#define EC_SIGN_PSBT_MISSING_WITNESSUTXO_FOR_SEGWIT 0x0007
// If an input has SIGHASH_SINGLE, its index must be less than the number of outputs.
#define EC_SIGN_PSBT_UNALLOWED_SIGHASH_SINGLE 0x0008
// The number of change outputs is larger than the maximum that is allowed.
#define EC_SIGN_PSBT_TOO_MANY_CHANGE_OUTPUTS 0x0009
// The witness script in the PSBT is incorrect.
#define EC_SIGN_PSBT_MISMATCHING_WITNESS_SCRIPT 0x000a
// The redeem Script in the PSBT is incorrect.
#define EC_SIGN_PSBT_MISMATCHING_REDEEM_SCRIPT 0x000b
// The wallet policy has too many internal keys.
#define EC_SIGN_PSBT_WALLET_POLICY_TOO_MANY_INTERNAL_KEYS 0x000c
// Non-standard sighash types are not allowed unless the user has explicitly enabled them
// in the application settings. Enable "Allow non-standard sighash" in the app settings to proceed.
#define EC_SIGN_PSBT_NONDEFAULT_SIGHASH_NOT_ALLOWED 0x000d
// At least one input only accepts a height-based lock time (it has
// PSBT_IN_REQUIRED_HEIGHT_LOCKTIME but not PSBT_IN_REQUIRED_TIME_LOCKTIME) while another only
// accepts a time-based one, so no nLockTime satisfies every input. The inputs must be reconciled.
// See BIP-0370, "Determining Lock Time".
#define EC_SIGN_PSBT_UNDETERMINABLE_LOCKTIME 0x000e
// An input declares a required lock time whose value is out of range:
// - a PSBT_IN_REQUIRED_HEIGHT_LOCKTIME must be in [1, 499999999];
// - a PSBT_IN_REQUIRED_TIME_LOCKTIME must be at least 500000000.
#define EC_SIGN_PSBT_REQUIRED_LOCKTIME_OUT_OF_RANGE 0x000f
// The PSBT has the PSBT_GLOBAL_GENERIC_SIGNED_MESSAGE field, but the transaction does not have
// the structure mandated by BIP-322 for a to_sign transaction.
// Note: the app cannot verify whether the additional inputs of a proof of funds spend real coins.
// Therefore, it is not possible to prevent the app from producing invalid BIP-322 signatures.
#define EC_SIGN_PSBT_BIP322_INVALID_STRUCTURE 0x0010
// The first input of the BIP-322 to_sign transaction does not spend the to_spend transaction.
// For a proof-of-funds, this includes a missing message_challenge input (BIP-322 v2.0.0).
#define EC_SIGN_PSBT_BIP322_TOSPEND_MISMATCH 0x0011
// BIP-322 requires all signatures to use SIGHASH_ALL (or SIGHASH_DEFAULT for taproot inputs).
#define EC_SIGN_PSBT_BIP322_FORBIDDEN_SIGHASH 0x0012
// The PSBT uses unsupported features (non-zero locktime, non-zero sequence of the first input,
// or a relative timelock on a proof-of-funds input).
#define EC_SIGN_PSBT_BIP322_UNSUPPORTED 0x0013
// BIP-322 message signing is not allowed when called from the Exchange app.
#define EC_SIGN_PSBT_BIP322_NOT_ALLOWED_IN_SWAP 0x0014
// All the inputs of a BIP-322 proof-of-funds must belong to the wallet policy: the total
// proven amount shown to the user must be trustworthy, and external inputs cannot be signed.
#define EC_SIGN_PSBT_BIP322_EXTERNAL_INPUTS 0x0015
// The MUSIG2_SESSION_ID global field is present, but its value is empty or longer than 32 bytes.
#define EC_SIGN_PSBT_INVALID_MUSIG2_SESSION_ID 0x0016
// The PSBT contains MuSig2 pubnonces, but the device has no corresponding MuSig2 session for it
#define EC_SIGN_PSBT_MUSIG2_SESSION_NOT_FOUND 0x0017
/**
* Swap
*/
// For swap error codes, the first byte is standardized across apps.
// Refer to the documentation of app-exchange.
// Internal application error, forward to the firmware team for analysis.
#define EC_SWAP_ERROR_INTERNAL 0x0000
// The amount does not match the one validated in Exchange.
#define EC_SWAP_ERROR_WRONG_AMOUNT 0x0100
// The destination address does not match the one validated in Exchange.
#define EC_SWAP_ERROR_WRONG_DESTINATION 0x0200
// The fees are different from what was validated in Exchange.
#define EC_SWAP_ERROR_WRONG_FEES 0x0300
// The method used is invalid in Exchange context.
#define EC_SWAP_ERROR_WRONG_METHOD 0x0400
// Only default wallet policies can be used in swaps.
#define EC_SWAP_ERROR_WRONG_METHOD_NONDEFAULT_POLICY 0x0401
// No external inputs allowed in swap transactions.
#define EC_SWAP_ERROR_WRONG_METHOD_EXTERNAL_INPUTS 0x0402
// Segwit transaction in swap must have the non-witness UTXO in the PSBT.
#define EC_SWAP_ERROR_WRONG_METHOD_MISSING_NONWITNESSUTXO 0x0403
// Standard swap transaction must have exactly 1 external output.
#define EC_SWAP_ERROR_WRONG_METHOD_WRONG_N_OF_OUTPUTS 0x0404
// Invalid or unsupported script for external output.
#define EC_SWAP_ERROR_WRONG_METHOD_WRONG_UNSUPPORTED_OUTPUT 0x0405
// The mode used for the cross-chain hash validation is not supported.
#define EC_SWAP_ERROR_CROSSCHAIN_WRONG_MODE 0x0500
// The method used is invalid in cross-chain Exchange context.
#define EC_SWAP_ERROR_CROSSCHAIN_WRONG_METHOD 0x0600
// The first output must be OP_RETURN <data> for a cross-chain swap.
#define EC_SWAP_ERROR_CROSSCHAIN_WRONG_METHOD_INVALID_FIRST_OUTPUT 0x0601
// OP_RETURN with non-zero value is not supported.
#define EC_SWAP_ERROR_CROSSCHAIN_WRONG_METHOD_NONZERO_AMOUNT 0x0602
// The hash for the cross-chain transaction does not match the validated value.
#define EC_SWAP_ERROR_CROSSCHAIN_WRONG_HASH 0x0700
// A generic or unspecified error not covered by the specific error codes above. Refer to the
// remaining bytes for further details on the error.
#define EC_SWAP_ERROR_GENERIC 0xFF00
// Unknown swap mode.
#define EC_SWAP_ERROR_GENERIC_UNKNOWN_MODE 0xFF01
// handle_swap_sign_transaction.c::copy_transaction_parameters failed.
#define EC_SWAP_ERROR_GENERIC_COPY_TRANSACTION_PARAMETERS_FAILED 0xFF02
// Checking the match for the SWAP error codes with the SDK ones
#ifdef HAVE_SWAP
#define ASSERT_SWAP_ERR_CODE(btc_err_code, sdk_err_code) \
_Static_assert(((btc_err_code >> 8) & 0xFF) == sdk_err_code, \
"SWAP error code value does not match the SDK one")
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_INTERNAL, SWAP_EC_ERROR_INTERNAL);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_WRONG_AMOUNT, SWAP_EC_ERROR_WRONG_AMOUNT);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_WRONG_DESTINATION, SWAP_EC_ERROR_WRONG_DESTINATION);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_WRONG_FEES, SWAP_EC_ERROR_WRONG_FEES);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_WRONG_METHOD, SWAP_EC_ERROR_WRONG_METHOD);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_WRONG_METHOD_NONDEFAULT_POLICY, SWAP_EC_ERROR_WRONG_METHOD);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_WRONG_METHOD_EXTERNAL_INPUTS, SWAP_EC_ERROR_WRONG_METHOD);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_WRONG_METHOD_MISSING_NONWITNESSUTXO, SWAP_EC_ERROR_WRONG_METHOD);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_WRONG_METHOD_WRONG_N_OF_OUTPUTS, SWAP_EC_ERROR_WRONG_METHOD);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_WRONG_METHOD_WRONG_UNSUPPORTED_OUTPUT,
SWAP_EC_ERROR_WRONG_METHOD);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_CROSSCHAIN_WRONG_MODE, SWAP_EC_ERROR_CROSSCHAIN_WRONG_MODE);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_CROSSCHAIN_WRONG_METHOD, SWAP_EC_ERROR_CROSSCHAIN_WRONG_METHOD);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_CROSSCHAIN_WRONG_METHOD_INVALID_FIRST_OUTPUT,
SWAP_EC_ERROR_CROSSCHAIN_WRONG_METHOD);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_CROSSCHAIN_WRONG_METHOD_NONZERO_AMOUNT,
SWAP_EC_ERROR_CROSSCHAIN_WRONG_METHOD);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_CROSSCHAIN_WRONG_HASH, SWAP_EC_ERROR_CROSSCHAIN_WRONG_HASH);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_GENERIC, SWAP_EC_ERROR_GENERIC);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_GENERIC_UNKNOWN_MODE, SWAP_EC_ERROR_GENERIC);
ASSERT_SWAP_ERR_CODE(EC_SWAP_ERROR_GENERIC_COPY_TRANSACTION_PARAMETERS_FAILED,
SWAP_EC_ERROR_GENERIC);
#endif /* HAVE_SWAP */