1mod address;
17mod builder;
18mod fee;
19mod htlc;
20mod multisig;
21mod network;
22mod script;
23mod sighash;
24mod tx;
25mod zip244;
26
27pub use address::{AddressKind, TransparentAddress, is_transparent_address, script_pubkey_for_address};
28pub use builder::{
29 DUST_LIMIT, FUNDING_EXPIRY_DELTA, FundingRequest, MAX_MONEY, MIN_CHANGE, Payment, SignedTx, TxOptions, Utxo,
30 assert_expiry_height, assert_funding_expiry_height, assert_output_value, build_htlc_claim, build_htlc_funding,
31 build_htlc_refund, build_p2pkh_spend, sign_digest,
32};
33pub use fee::{GRACE_ACTIONS, MARGINAL_FEE, P2PKH_STANDARD_INPUT_SIZE, P2PKH_STANDARD_OUTPUT_SIZE, zip317_fee};
34pub use htlc::{
35 Htlc, HtlcParams, claim_script_sig, extract_preimage, htlc_redeem_script, parse_htlc_redeem_script,
36 refund_script_sig,
37};
38pub use multisig::{
39 Multisig2of2, MultisigSpend, build_multisig_spend, finalize_multisig_spend, multisig_signatures_from_script_sig,
40 sign_multisig_spend, verify_multisig_signature,
41};
42pub use network::Network;
43pub use script::{
44 MAX_SCRIPT_ELEMENT_SIZE, MAX_STANDARD_SCRIPTSIG_SIZE, PREIMAGE_SIZE, ScriptItem, assert_p2sh_sizes, decompile,
45 hash160, op, p2pkh_script, p2sh_script, push_data, push_number, script_num,
46};
47pub use sighash::{PrevOut, SighashType, transparent_sighash};
48pub use tx::{
49 DecodedTx, LOCKTIME_THRESHOLD, OVERWINTERED_FLAG, OutPoint, ParsedTx, RawInput, SEQUENCE_ENABLE_LOCKTIME,
50 SEQUENCE_FINAL, TX_VERSION_5, TransparentTx, TxIn, TxOut, Txid, V5_VERSION_GROUP_ID, decode_tx, parse_tx,
51 transparent_txid,
52};
53pub use zip244::{
54 ShieldedDigests, blake2b256, header_digest, outputs_digest, prevouts_digest, sequence_digest, shielded_digests,
55 transparent_txid_digest, txid_digest, txid_personalization,
56};
57
58use crate::encoding::EncodingError;
59use crate::keys::KeyError;
60
61#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
63#[non_exhaustive]
64pub enum Error {
65 #[error(transparent)]
67 Encoding(#[from] EncodingError),
68 #[error(transparent)]
70 Key(#[from] KeyError),
71
72 #[error("not a transparent address: {0}")]
75 InvalidAddress(String),
76 #[error("Invalid checksum")]
78 InvalidChecksum,
79 #[error("unknown address prefix: {0}")]
81 UnknownAddressPrefix(String),
82 #[error("{address} is a {actual} address, expected {expected}")]
84 WrongNetwork {
85 address: String,
87 actual: Network,
89 expected: Network,
91 },
92
93 #[error("push too large")]
96 PushTooLarge,
97 #[error("push past end of script")]
99 PushPastEnd,
100 #[error("expected a number")]
102 ExpectedNumber,
103 #[error("not a Paralock HTLC script")]
105 NotHtlcScript,
106 #[error("not a Paralock HTLC script: a key is not a curve point")]
108 HtlcKeyNotOnCurve,
109 #[error("not a 2-of-2 multisig script")]
111 NotMultisigScript,
112 #[error("multisig keys are not sorted")]
114 MultisigKeysNotSorted,
115 #[error("not a 2-of-2 spend")]
117 NotMultisigSpend,
118 #[error("{0}")]
120 IdenticalKeys(&'static str),
121 #[error("{what} is not a compressed secp256k1 point: {shown}")]
124 InvalidPubkey {
125 what: &'static str,
127 shown: String,
129 },
130 #[error("pubkeys must be 33-byte compressed keys")]
132 PubkeysNotCompressed,
133 #[error("hashlock must be 32 bytes")]
135 InvalidHashlockLength,
136 #[error("refundHeight must be a block height")]
138 InvalidRefundHeight,
139 #[error("refundHeight must be a block height in [1, 500000000), got {0}")]
141 RefundHeightOutOfRange(u32),
142 #[error("redeem script is {0} bytes; the limit is 520")]
144 RedeemScriptTooLarge(usize),
145 #[error("scriptSig is {0} bytes; the standard limit is 1650")]
147 ScriptSigTooLarge(usize),
148 #[error("preimage must be 32 bytes")]
150 InvalidPreimageLength,
151
152 #[error("only v5 transactions are supported")]
155 UnsupportedVersion,
156 #[error("unsupported transaction version {0}")]
158 UnsupportedTxVersion(u32),
159 #[error("bad version group id")]
161 BadVersionGroupId,
162 #[error("unexpected data after the Orchard bundle")]
164 TrailingData,
165 #[error("unexpected data after the v{0} transaction")]
167 TrailingTxData(u32),
168 #[error("a v{version} transaction must have fOverwintered {}", if *.set { "set" } else { "clear" })]
170 OverwinteredFlag {
171 version: u32,
173 set: bool,
175 },
176 #[error("bad version group id for a v{0} transaction")]
178 BadPreV5VersionGroupId(u32),
179 #[error("txid must be 32 bytes of hex")]
181 InvalidTxid,
182
183 #[error("invalid sighash type {0}: v5 allows only 0x01, 0x02, 0x03, 0x81, 0x82 and 0x83")]
186 InvalidSighashType(u8),
187 #[error("need one prevout per input")]
189 PrevoutCountMismatch,
190 #[error("no input {0}")]
192 NoSuchInput(usize),
193
194 #[error("no UTXOs to spend")]
197 NoUtxos,
198 #[error("no outputs")]
200 NoOutputs,
201 #[error("UTXO {0} is not owned by this key")]
203 UtxoNotOwned(OutPoint),
204 #[error("UTXO {0} has an invalid value")]
206 InvalidUtxoValue(OutPoint),
207 #[error("UTXO {0} is listed twice")]
209 DuplicateUtxo(OutPoint),
210 #[error("output of {0} zat is below the dust limit (1000)")]
212 Dust(u64),
213 #[error("{what} of {value} zat exceeds MAX_MONEY")]
215 ExceedsMaxMoney {
216 what: &'static str,
218 value: u64,
220 },
221 #[error("insufficient funds: have {have}, need {need}")]
223 InsufficientFunds {
224 have: u64,
226 need: u64,
228 },
229 #[error("{0}")]
231 AmountDoesNotCoverFee(&'static str),
232 #[error("{0}")]
234 UtxoScriptMismatch(&'static str),
235 #[error("{0}")]
237 WrongKey(&'static str),
238 #[error("preimage does not match the HTLC hashlock")]
240 WrongPreimage,
241 #[error("invalid expiry height {0}")]
243 InvalidExpiryHeight(u32),
244 #[error("a funding needs an expiry height (tip + FUNDING_EXPIRY_DELTA); 0 never expires")]
246 ExpiryHeightRequired,
247 #[error("branchId must be the next block's consensus branch id (a non-zero 32-bit integer from the node), got {0}")]
249 InvalidBranchId(u32),
250 #[error("fee of {fee} zat is not below the {spent} zat spent")]
252 FeeNotBelowSpent {
253 fee: u64,
255 spent: u64,
257 },
258 #[error("lockTime must be a block height")]
260 InvalidLockTime,
261 #[error("need a signature for both multisig keys")]
263 MissingSignature,
264 #[error("invalid signature for multisig key {0}")]
266 InvalidSignature(String),
267}