bsv_wasm/errors/
mod.rs

1use std::{array::TryFromSliceError, num::ParseIntError};
2
3use thiserror::*;
4
5#[derive(Debug, Error)]
6pub enum BSVErrors {
7    #[error("{0}")]
8    ECDSAError(
9        #[source]
10        #[from]
11        ecdsa::Error,
12    ),
13
14    #[error("ECDSA Error {0}")]
15    CustomECDSAError(String),
16
17    #[error("{0}")]
18    CurveError(
19        #[source]
20        #[from]
21        elliptic_curve::Error,
22    ),
23    #[error("{0}")]
24    HexDecode(
25        #[source]
26        #[from]
27        hex::FromHexError,
28    ),
29
30    #[error("{0}")]
31    Base58Decode(
32        #[source]
33        #[from]
34        bs58::decode::Error,
35    ),
36
37    #[error("{0}")]
38    Io(
39        #[source]
40        #[from]
41        std::io::Error,
42    ),
43
44    #[error("{0}")]
45    ParseInt(
46        #[source]
47        #[from]
48        ParseIntError,
49    ),
50
51    #[error("{0}")]
52    RandomnessGeneration(
53        #[source]
54        #[from]
55        getrandom::Error,
56    ),
57
58    #[error("{0}")]
59    Json(
60        #[source]
61        #[from]
62        serde_json::Error,
63    ),
64
65    #[error("{0}")]
66    InvalidKeyIvLength(
67        #[source]
68        #[from]
69        block_modes::InvalidKeyIvLength,
70    ),
71
72    #[error("{0}")]
73    BlockModeError(
74        #[source]
75        #[from]
76        block_modes::BlockModeError,
77    ),
78
79    #[error("{0}")]
80    CborSerialise(
81        #[source]
82        #[from]
83        ciborium::ser::Error<std::io::Error>,
84    ),
85
86    #[error("{0}")]
87    CborDeserialise(
88        #[source]
89        #[from]
90        ciborium::de::Error<std::io::Error>,
91    ),
92
93    // Custom Errors
94    #[error("Leading byte {0} does not match compressed or uncompressed")]
95    PublicKeyReadCompressionByte(u8),
96
97    #[error("{1}")]
98    PublicKeyRecoveryError(String, #[source] ecdsa::Error),
99
100    #[error("{0}")]
101    PublicKeyError(String),
102
103    #[error("Unable to verify message: {0}")]
104    MessageVerification(String),
105
106    #[error("Error generating Script: {0}")]
107    GenerateScript(String),
108
109    #[error("Could not calculate private key bytes from seed: {0}")]
110    InvalidSeedHmacError(String),
111
112    #[error("Unable to derive child key: {0}")]
113    DerivationError(String),
114
115    #[error("Unable to retrieve private key from WIF: {0}")]
116    FromWIF(String),
117
118    #[error("Unable to convert to sighash: {0}")]
119    ToSighash(String),
120
121    #[error("Unable to convert from sighash: {0}")]
122    FromSighash(String),
123
124    #[error("{0}")]
125    OutOfBounds(String),
126
127    #[error("{0}")]
128    ECIESError(String),
129
130    #[error("{0}")]
131    P2PKHAddress(&'static str),
132
133    #[error("Unable to deserialise P2PKH from slice {0}")]
134    P2PKHAddressFromSlice(#[source] TryFromSliceError),
135
136    #[error("{0}")]
137    SignatureError(&'static str),
138
139    //=========== Serialisation Errors ==============
140    #[error("Error deserialising transaction field {0}: {1}")]
141    DeserialiseTransaction(String, #[source] std::io::Error),
142
143    #[error("Error Serialising transaction field {0}: {1}")]
144    SerialiseTransaction(String, #[source] std::io::Error),
145
146    #[error("Error when deserialising Script: {0}")]
147    DeserialiseScript(String),
148
149    #[error("Error when Serialising Script: {0} {1:?}")]
150    SerialiseScript(String, #[source] Option<std::io::Error>),
151
152    #[error("Error deserialising TxIn field {0}: {1}")]
153    DeserialiseTxIn(String, #[source] std::io::Error),
154
155    #[error("Error serialising TxIn field {0}: {1}")]
156    SerialiseTxIn(String, #[source] std::io::Error),
157
158    #[error("Error deserialising TxOut field {0}: {1}")]
159    DeserialiseTxOut(String, #[source] std::io::Error),
160
161    #[error("Error serialising TxOut field {0}: {1}")]
162    SerialiseTxOut(String, #[source] std::io::Error),
163}