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
/// Result type for this crate.
pub type Result<T> = std::result::Result<T, Error>;
/// Everything that can go wrong. Messages match the node's error text where
/// the node has an equivalent check.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
/// ML-DSA-65 key material has an invalid length or encoding.
#[error("invalid ML-DSA-65 key")]
InvalidPQKey,
/// ML-DSA-65 signature has an invalid length or encoding.
#[error("invalid ML-DSA-65 signature")]
InvalidPQSignature,
/// Not a valid secp256k1 private key.
#[error("invalid private key")]
InvalidPrivateKey,
/// Public key is not 32 bytes or not a valid curve point.
#[error("invalid public key length")]
InvalidPublicKey,
/// Recovery phrase is not a valid 24-word BIP39 phrase for a valid key.
#[error("invalid recovery phrase")]
InvalidMnemonic,
/// Address has the wrong length.
#[error("invalid address length")]
AddressLength,
/// Address does not start with `bt1`.
#[error("invalid address prefix")]
AddressPrefix,
/// Address payload is not hex.
#[error("invalid address payload")]
AddressPayload,
/// Address checksum does not match.
#[error("invalid address checksum")]
AddressChecksum,
/// Signature is malformed or does not verify.
#[error("invalid signature")]
InvalidSignature,
/// Transaction has no chain ID.
#[error("missing chain id")]
MissingChainId,
/// UTXO transaction has no inputs.
#[error("utxo transaction has no inputs")]
NoInputs,
/// UTXO transaction has no outputs.
#[error("utxo transaction has no outputs")]
NoOutputs,
/// Data payload is larger than [`tx::MAX_DATA_SIZE`](crate::tx::MAX_DATA_SIZE).
#[error("data payload is {0} bytes, max is 512")]
DataTooLarge(usize),
/// Output has no script.
#[error("utxo output {0} missing script_pub_key")]
MissingScript(usize),
/// Output script fails canonicalization.
#[error("utxo output {0} has an invalid script_pub_key")]
InvalidScript(usize),
/// Spending condition is malformed or exceeds consensus limits.
#[error("invalid condition: {0}")]
InvalidCondition(String),
/// Atomic swap parameters are unsafe or invalid.
#[error("invalid atomic swap: {0}")]
InvalidSwap(String),
/// Output value is zero.
#[error("utxo output {0} has zero value")]
ZeroValue(usize),
/// `from` is not the address of the public key.
#[error("from address does not match public key")]
FromMismatch,
/// Signature scheme is not supported.
#[error("unknown signature scheme")]
UnknownScheme,
/// Transaction version is not 0, 2 or 3.
#[error("unsupported transaction version: {0}")]
UnsupportedVersion(u32),
/// Spendable UTXOs do not cover amount + fee.
#[error("insufficient funds: need {need}, have {have}")]
InsufficientFunds {
/// Amount + fee in nibbles.
need: u64,
/// Total of all spendable UTXOs in nibbles.
have: u64,
},
/// Covering the amount would need more than [`tx::MAX_INPUTS`](crate::tx::MAX_INPUTS) inputs.
#[error("payment needs more than {0} inputs; consolidate UTXOs first")]
TooManyInputs(usize),
/// Arithmetic overflow on amounts.
#[error("amount overflow")]
AmountOverflow,
/// Amount string could not be parsed.
#[error("invalid amount")]
InvalidAmount,
/// Network name is not supported.
#[error("invalid network")]
InvalidNetwork,
/// Wire JSON could not be decoded.
#[error("invalid transaction json: {0}")]
Json(String),
}