mod address;
mod builder;
mod fee;
mod htlc;
mod multisig;
mod network;
mod script;
mod sighash;
mod tx;
mod zip244;
pub use address::{AddressKind, TransparentAddress, is_transparent_address, script_pubkey_for_address};
pub use builder::{
DUST_LIMIT, FUNDING_EXPIRY_DELTA, FundingRequest, MAX_MONEY, MIN_CHANGE, Payment, SignedTx, TxOptions, Utxo,
assert_expiry_height, assert_funding_expiry_height, assert_output_value, build_htlc_claim, build_htlc_funding,
build_htlc_refund, build_p2pkh_spend, sign_digest,
};
pub use fee::{GRACE_ACTIONS, MARGINAL_FEE, P2PKH_STANDARD_INPUT_SIZE, P2PKH_STANDARD_OUTPUT_SIZE, zip317_fee};
pub use htlc::{
Htlc, HtlcParams, claim_script_sig, extract_preimage, htlc_redeem_script, parse_htlc_redeem_script,
refund_script_sig,
};
pub use multisig::{
Multisig2of2, MultisigSpend, build_multisig_spend, finalize_multisig_spend, multisig_signatures_from_script_sig,
sign_multisig_spend, verify_multisig_signature,
};
pub use network::Network;
pub use script::{
MAX_SCRIPT_ELEMENT_SIZE, MAX_STANDARD_SCRIPTSIG_SIZE, PREIMAGE_SIZE, ScriptItem, assert_p2sh_sizes, decompile,
hash160, op, p2pkh_script, p2sh_script, push_data, push_number, script_num,
};
pub use sighash::{PrevOut, SighashType, transparent_sighash};
pub use tx::{
DecodedTx, LOCKTIME_THRESHOLD, OVERWINTERED_FLAG, OutPoint, ParsedTx, RawInput, SEQUENCE_ENABLE_LOCKTIME,
SEQUENCE_FINAL, TX_VERSION_5, TransparentTx, TxIn, TxOut, Txid, V5_VERSION_GROUP_ID, decode_tx, parse_tx,
transparent_txid,
};
pub use zip244::{
ShieldedDigests, blake2b256, header_digest, outputs_digest, prevouts_digest, sequence_digest, shielded_digests,
transparent_txid_digest, txid_digest, txid_personalization,
};
use crate::encoding::EncodingError;
use crate::keys::KeyError;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
Encoding(#[from] EncodingError),
#[error(transparent)]
Key(#[from] KeyError),
#[error("not a transparent address: {0}")]
InvalidAddress(String),
#[error("Invalid checksum")]
InvalidChecksum,
#[error("unknown address prefix: {0}")]
UnknownAddressPrefix(String),
#[error("{address} is a {actual} address, expected {expected}")]
WrongNetwork {
address: String,
actual: Network,
expected: Network,
},
#[error("push too large")]
PushTooLarge,
#[error("push past end of script")]
PushPastEnd,
#[error("expected a number")]
ExpectedNumber,
#[error("not a Paralock HTLC script")]
NotHtlcScript,
#[error("not a Paralock HTLC script: a key is not a curve point")]
HtlcKeyNotOnCurve,
#[error("not a 2-of-2 multisig script")]
NotMultisigScript,
#[error("multisig keys are not sorted")]
MultisigKeysNotSorted,
#[error("not a 2-of-2 spend")]
NotMultisigSpend,
#[error("{0}")]
IdenticalKeys(&'static str),
#[error("{what} is not a compressed secp256k1 point: {shown}")]
InvalidPubkey {
what: &'static str,
shown: String,
},
#[error("pubkeys must be 33-byte compressed keys")]
PubkeysNotCompressed,
#[error("hashlock must be 32 bytes")]
InvalidHashlockLength,
#[error("refundHeight must be a block height")]
InvalidRefundHeight,
#[error("refundHeight must be a block height in [1, 500000000), got {0}")]
RefundHeightOutOfRange(u32),
#[error("redeem script is {0} bytes; the limit is 520")]
RedeemScriptTooLarge(usize),
#[error("scriptSig is {0} bytes; the standard limit is 1650")]
ScriptSigTooLarge(usize),
#[error("preimage must be 32 bytes")]
InvalidPreimageLength,
#[error("only v5 transactions are supported")]
UnsupportedVersion,
#[error("unsupported transaction version {0}")]
UnsupportedTxVersion(u32),
#[error("bad version group id")]
BadVersionGroupId,
#[error("unexpected data after the Orchard bundle")]
TrailingData,
#[error("unexpected data after the v{0} transaction")]
TrailingTxData(u32),
#[error("a v{version} transaction must have fOverwintered {}", if *.set { "set" } else { "clear" })]
OverwinteredFlag {
version: u32,
set: bool,
},
#[error("bad version group id for a v{0} transaction")]
BadPreV5VersionGroupId(u32),
#[error("txid must be 32 bytes of hex")]
InvalidTxid,
#[error("invalid sighash type {0}: v5 allows only 0x01, 0x02, 0x03, 0x81, 0x82 and 0x83")]
InvalidSighashType(u8),
#[error("need one prevout per input")]
PrevoutCountMismatch,
#[error("no input {0}")]
NoSuchInput(usize),
#[error("no UTXOs to spend")]
NoUtxos,
#[error("no outputs")]
NoOutputs,
#[error("UTXO {0} is not owned by this key")]
UtxoNotOwned(OutPoint),
#[error("UTXO {0} has an invalid value")]
InvalidUtxoValue(OutPoint),
#[error("UTXO {0} is listed twice")]
DuplicateUtxo(OutPoint),
#[error("output of {0} zat is below the dust limit (1000)")]
Dust(u64),
#[error("{what} of {value} zat exceeds MAX_MONEY")]
ExceedsMaxMoney {
what: &'static str,
value: u64,
},
#[error("insufficient funds: have {have}, need {need}")]
InsufficientFunds {
have: u64,
need: u64,
},
#[error("{0}")]
AmountDoesNotCoverFee(&'static str),
#[error("{0}")]
UtxoScriptMismatch(&'static str),
#[error("{0}")]
WrongKey(&'static str),
#[error("preimage does not match the HTLC hashlock")]
WrongPreimage,
#[error("invalid expiry height {0}")]
InvalidExpiryHeight(u32),
#[error("a funding needs an expiry height (tip + FUNDING_EXPIRY_DELTA); 0 never expires")]
ExpiryHeightRequired,
#[error("branchId must be the next block's consensus branch id (a non-zero 32-bit integer from the node), got {0}")]
InvalidBranchId(u32),
#[error("fee of {fee} zat is not below the {spent} zat spent")]
FeeNotBelowSpent {
fee: u64,
spent: u64,
},
#[error("lockTime must be a block height")]
InvalidLockTime,
#[error("need a signature for both multisig keys")]
MissingSignature,
#[error("invalid signature for multisig key {0}")]
InvalidSignature(String),
}