celestia_types/
error.rs

1use crate::consts::appconsts;
2
3/// Alias for a `Result` with the error type [`celestia_types::Error`].
4///
5/// [`celestia_types::Error`]: crate::Error
6pub type Result<T, E = Error> = std::result::Result<T, E>;
7
8/// `Result` counterpart for functions exposed to uniffi with [`UniffiError`]
9///
10/// [`UniffiError`]: crate::error::UniffiError
11#[cfg(feature = "uniffi")]
12pub type UniffiResult<T> = std::result::Result<T, UniffiError>;
13
14/// Representation of all the errors that can occur when interacting with [`celestia_types`].
15///
16/// [`celestia_types`]: crate
17#[derive(Debug, thiserror::Error)]
18pub enum Error {
19    /// Unsupported namespace version.
20    #[error("Unsupported namespace version: {0}")]
21    UnsupportedNamespaceVersion(u8),
22
23    /// Unsupported app version.
24    #[error("Unsupported app version: {0}")]
25    UnsupportedAppVersion(u64),
26
27    /// Invalid namespace size.
28    #[error("Invalid namespace size")]
29    InvalidNamespaceSize,
30
31    /// Error propagated from the [`tendermint`].
32    #[error(transparent)]
33    Tendermint(#[from] tendermint::Error),
34
35    /// Error propagated from the [`tendermint_proto`].
36    #[error(transparent)]
37    Protobuf(#[from] tendermint_proto::Error),
38
39    /// Error propagated from the [`cid::multihash`].
40    #[error(transparent)]
41    Multihash(#[from] cid::multihash::Error),
42
43    /// Error returned when trying to compute new or parse existing CID. See [`blockstore::block`]
44    #[error(transparent)]
45    CidError(#[from] blockstore::block::CidError),
46
47    /// Error propagated from the [`leopard_codec`].
48    #[error(transparent)]
49    LeopardCodec(#[from] leopard_codec::LeopardError),
50
51    /// Missing header.
52    #[error("Missing header")]
53    MissingHeader,
54
55    /// Missing commit.
56    #[error("Missing commit")]
57    MissingCommit,
58
59    /// Missing validator set.
60    #[error("Missing validator set")]
61    MissingValidatorSet,
62
63    /// Missing data availability header.
64    #[error("Missing data availability header")]
65    MissingDataAvailabilityHeader,
66
67    /// Missing proof.
68    #[error("Missing proof")]
69    MissingProof,
70
71    /// Missing shares.
72    #[error("Missing shares")]
73    MissingShares,
74
75    /// Missing fee field
76    #[error("Missing fee field")]
77    MissingFee,
78
79    /// Missing sum field
80    #[error("Missing sum field")]
81    MissingSum,
82
83    /// Missing mode info field
84    #[error("Missing mode info field")]
85    MissingModeInfo,
86
87    /// Missing bitarray field
88    #[error("Missing bitarray field")]
89    MissingBitarray,
90
91    /// Bit array too large
92    #[error("Bit array to large")]
93    BitarrayTooLarge,
94
95    /// Malformed CompactBitArray
96    #[error("CompactBitArray malformed")]
97    MalformedCompactBitArray,
98
99    /// Wrong proof type.
100    #[error("Wrong proof type")]
101    WrongProofType,
102
103    /// Unsupported share version.
104    #[error("Unsupported share version: {0}")]
105    UnsupportedShareVersion(u8),
106
107    /// Invalid share size.
108    #[error("Invalid share size: {0}")]
109    InvalidShareSize(usize),
110
111    /// Invalid nmt leaf size.
112    #[error("Invalid nmt leaf size: {0}")]
113    InvalidNmtLeafSize(usize),
114
115    /// Invalid nmt node order.
116    #[error("Invalid nmt node order")]
117    InvalidNmtNodeOrder,
118
119    /// Share sequence length exceeded.
120    #[error(
121        "Sequence len must fit into {} bytes, got value {0}",
122        appconsts::SEQUENCE_LEN_BYTES
123    )]
124    ShareSequenceLenExceeded(usize),
125
126    /// Invalid namespace in version 0.
127    #[error("Invalid namespace v0")]
128    InvalidNamespaceV0,
129
130    /// Invalid namespace in version 255.
131    #[error("Invalid namespace v255")]
132    InvalidNamespaceV255,
133
134    /// Invalid namespaced hash.
135    #[error(transparent)]
136    InvalidNamespacedHash(#[from] nmt_rs::InvalidNamespacedHash),
137
138    /// Invalid index of signature in commit.
139    #[error("Invalid index of signature in commit {0}, height {1}")]
140    InvalidSignatureIndex(usize, u64),
141
142    /// Invalid axis.
143    #[error("Invalid axis type: {0}")]
144    InvalidAxis(i32),
145
146    /// Invalid Shwap proof type in Protobuf.
147    #[error("Invalid proof type: {0}")]
148    InvalidShwapProofType(i32),
149
150    /// Could not deserialise Public Key
151    #[error("Could not deserialize public key")]
152    InvalidPublicKey,
153
154    /// Range proof verification error.
155    #[error("Range proof verification failed: {0:?}")]
156    RangeProofError(nmt_rs::simple_merkle::error::RangeProofError),
157
158    /// Row root computed from shares doesn't match one received in `DataAvailabilityHeaderz
159    #[error("Computed root doesn't match received one")]
160    RootMismatch,
161
162    /// Unexpected signature in absent commit.
163    #[error("Unexpected absent commit signature")]
164    UnexpectedAbsentSignature,
165
166    /// Error that happened during validation.
167    #[error("Validation error: {0}")]
168    Validation(#[from] ValidationError),
169
170    /// Error that happened during verification.
171    #[error("Verification error: {0}")]
172    Verification(#[from] VerificationError),
173
174    /// Max share version exceeded.
175    #[error(
176        "Share version has to be at most {}, got {0}",
177        appconsts::MAX_SHARE_VERSION
178    )]
179    MaxShareVersionExceeded(u8),
180
181    /// An error related to the namespaced merkle tree.
182    #[error("Nmt error: {0}")]
183    Nmt(&'static str),
184
185    /// Invalid address bech32 prefix.
186    #[error("Invalid address prefix: {0}")]
187    InvalidAddressPrefix(String),
188
189    /// Invalid size of the address.
190    #[error("Invalid address size: {0}")]
191    InvalidAddressSize(usize),
192
193    /// Invalid address.
194    #[error("Invalid address: {0}")]
195    InvalidAddress(String),
196
197    /// Invalid coin amount.
198    #[error("Invalid coin amount: {0}")]
199    InvalidCoinAmount(String),
200
201    /// Invalid coin denomination.
202    #[error("Invalid coin denomination: {0}")]
203    InvalidCoinDenomination(String),
204
205    /// Invalid balance
206    #[error("Invalid balance: {0:?}")]
207    InvalidBalance(String),
208
209    /// Invalid Public Key
210    #[error("Invalid Public Key")]
211    InvalidPublicKeyType(String),
212
213    /// Unsupported fraud proof type.
214    #[error("Unsupported fraud proof type: {0}")]
215    UnsupportedFraudProofType(String),
216
217    /// Data square index out of range.
218    #[error("Index ({0}) out of range ({1})")]
219    IndexOutOfRange(usize, usize),
220
221    /// Data square index out of range.
222    #[error("Data square index out of range. row: {0}, column: {1}")]
223    EdsIndexOutOfRange(u16, u16),
224
225    /// Could not create EDS, provided number of shares doesn't form a pefect square.
226    #[error("Invalid dimensions of EDS")]
227    EdsInvalidDimentions,
228
229    /// Zero block height.
230    #[error("Invalid zero block height")]
231    ZeroBlockHeight,
232
233    /// Expected first share of a blob
234    #[error("Expected first share of a blob")]
235    ExpectedShareWithSequenceStart,
236
237    /// Unexpected share from reserved namespace.
238    #[error("Unexpected share from reserved namespace")]
239    UnexpectedReservedNamespace,
240
241    /// Unexpected start of a new blob
242    #[error("Unexpected start of a new blob")]
243    UnexpectedSequenceStart,
244
245    /// Metadata mismatch between shares in blob.
246    #[error("Metadata mismatch between shares in blob: {0}")]
247    BlobSharesMetadataMismatch(String),
248
249    /// Blob too large, length must fit u32
250    #[error("Blob too large")]
251    BlobTooLarge,
252
253    /// Invalid comittment length
254    #[error("Invalid committment length")]
255    InvalidComittmentLength,
256
257    /// Missing signer field in blob with share version 1
258    #[error("Missing signer field in blob")]
259    MissingSigner,
260
261    /// Signer is not supported in share version 0
262    #[error("Signer is not supported in share version 0")]
263    SignerNotSupported,
264
265    /// Empty blob list provided when creating MsgPayForBlobs
266    #[error("Empty blob list")]
267    EmptyBlobList,
268
269    /// Missing delegation response
270    #[error("Missing belegation response")]
271    MissingDelegationResponse,
272
273    /// Missing delegation
274    #[error("Missing delegation")]
275    MissingDelegation,
276
277    /// Missing balance
278    #[error("Missing balance")]
279    MissingBalance,
280
281    /// Missing unbond
282    #[error("Missing unbond")]
283    MissingUnbond,
284
285    /// Missing completion time
286    #[error("Missing completion time")]
287    MissingCompletionTime,
288
289    /// Missing redelegation
290    #[error("Missing redelegation")]
291    MissingRedelegation,
292
293    /// Missing redelegation entry
294    #[error("Missing redelegation entry")]
295    MissingRedelegationEntry,
296
297    /// Invalid Cosmos decimal
298    #[error("Invalid Cosmos decimal: {0}")]
299    InvalidCosmosDecimal(String),
300}
301
302impl From<prost::DecodeError> for Error {
303    fn from(value: prost::DecodeError) -> Self {
304        Error::Protobuf(tendermint_proto::Error::decode_message(value))
305    }
306}
307
308#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))]
309impl From<Error> for wasm_bindgen::JsValue {
310    fn from(value: Error) -> Self {
311        js_sys::Error::new(&value.to_string()).into()
312    }
313}
314
315/// Representation of the errors that can occur when validating data.
316///
317/// See [`ValidateBasic`]
318///
319/// [`ValidateBasic`]: crate::ValidateBasic
320#[derive(Debug, thiserror::Error)]
321pub enum ValidationError {
322    /// Not enough voting power for a commit.
323    #[error("Not enought voting power (got {0}, needed {1})")]
324    NotEnoughVotingPower(u64, u64),
325
326    /// Other errors that can happen during validation.
327    #[error("{0}")]
328    Other(String),
329}
330
331/// Representation of the errors that can occur when verifying data.
332///
333/// See [`ExtendedHeader::verify`].
334///
335/// [`ExtendedHeader::verify`]: crate::ExtendedHeader::verify
336#[derive(Debug, thiserror::Error)]
337pub enum VerificationError {
338    /// Not enough voting power for a commit.
339    #[error("Not enought voting power (got {0}, needed {1})")]
340    NotEnoughVotingPower(u64, u64),
341
342    /// Other errors that can happen during verification.
343    #[error("{0}")]
344    Other(String),
345}
346
347macro_rules! validation_error {
348    ($fmt:literal $(,)?) => {
349        $crate::ValidationError::Other(std::format!($fmt))
350    };
351    ($fmt:literal, $($arg:tt)*) => {
352        $crate::ValidationError::Other(std::format!($fmt, $($arg)*))
353    };
354}
355
356macro_rules! bail_validation {
357    ($($arg:tt)*) => {
358        return Err($crate::validation_error!($($arg)*).into())
359    };
360}
361
362macro_rules! verification_error {
363    ($fmt:literal $(,)?) => {
364        $crate::VerificationError::Other(std::format!($fmt))
365    };
366    ($fmt:literal, $($arg:tt)*) => {
367        $crate::VerificationError::Other(std::format!($fmt, $($arg)*))
368    };
369}
370
371macro_rules! bail_verification {
372    ($($arg:tt)*) => {
373        return Err($crate::verification_error!($($arg)*).into())
374    };
375}
376
377// NOTE: This need to be always after the macro definitions
378pub(crate) use bail_validation;
379pub(crate) use bail_verification;
380pub(crate) use validation_error;
381pub(crate) use verification_error;
382
383/// Errors raised when converting from uniffi helper types
384#[cfg(feature = "uniffi")]
385#[derive(Debug, uniffi::Error, thiserror::Error)]
386pub enum UniffiConversionError {
387    /// Invalid namespace length
388    #[error("Invalid namespace length")]
389    InvalidNamespaceLength,
390
391    /// Invalid commitment length
392    #[error("Invalid commitment hash length")]
393    InvalidCommitmentLength,
394
395    /// Invalid account id length
396    #[error("Invalid account id length")]
397    InvalidAccountIdLength,
398
399    /// Invalid hash length
400    #[error("Invalid hash length")]
401    InvalidHashLength,
402
403    /// Invalid chain ID lenght
404    #[error("Invalid chain id length")]
405    InvalidChainIdLength,
406
407    /// Invalid public key
408    #[error("Invalid public key")]
409    InvalidPublicKey,
410
411    /// Invalid parts header
412    #[error("Invalid parts header {msg}")]
413    InvalidPartsHeader {
414        /// error message
415        msg: String,
416    },
417
418    /// Timestamp out of range
419    #[error("Timestamp out of range")]
420    TimestampOutOfRange,
421
422    /// Header height out of range
423    #[error("Header heigth out of range")]
424    HeaderHeightOutOfRange,
425
426    /// Invalid signature length
427    #[error("Invalid signature length")]
428    InvalidSignatureLength,
429
430    /// Invalid round index
431    #[error("Invalid round index")]
432    InvalidRoundIndex,
433
434    /// Invalid validator index
435    #[error("Invalid validator index")]
436    InvalidValidatorIndex,
437
438    /// Invalid voting power
439    #[error("Voting power out of range")]
440    InvalidVotingPower,
441
442    /// Invalid signed header
443    #[error("Invalid signed header")]
444    InvalidSignedHeader,
445
446    /// Could not generate commitment
447    #[error("Could not generate commitment")]
448    CouldNotGenerateCommitment {
449        /// error message
450        msg: String,
451    },
452
453    /// Invalid address
454    #[error("Invalid address")]
455    InvalidAddress {
456        /// error message
457        msg: String,
458    },
459}
460
461/// Representation of all the errors that can occur when interacting with [`celestia_types`].
462///
463/// [`celestia_types`]: crate
464#[cfg(feature = "uniffi")]
465#[derive(Debug, uniffi::Error, thiserror::Error)]
466pub enum UniffiError {
467    /// Unsupported namespace version.
468    #[error("Unsupported namespace version: {0}")]
469    UnsupportedNamespaceVersion(u8),
470
471    /// Unsupported app version.
472    #[error("Unsupported app version: {0}")]
473    UnsupportedAppVersion(u64),
474
475    /// Invalid namespace size.
476    #[error("Invalid namespace size")]
477    InvalidNamespaceSize,
478
479    /// Error propagated from the [`tendermint`].
480    #[error("Tendermint error: {0}")]
481    Tendermint(String),
482
483    /// Error propagated from the [`tendermint_proto`].
484    #[error("tendermint_proto error: {0}")]
485    Protobuf(String),
486
487    /// Error propagated from the [`cid::multihash`].
488    #[error("Multihash error: {0}")]
489    Multihash(String),
490
491    /// Error returned when trying to compute new or parse existing CID. See [`blockstore::block`]
492    #[error("Error creating or parsing CID: {0}")]
493    CidError(String),
494
495    /// Error propagated from the [`leopard_codec`].
496    #[error("Leopard codec error: {0}")]
497    LeopardCodec(String),
498
499    /// Missing header.
500    #[error("Missing header")]
501    MissingHeader,
502
503    /// Missing commit.
504    #[error("Missing commit")]
505    MissingCommit,
506
507    /// Missing validator set.
508    #[error("Missing validator set")]
509    MissingValidatorSet,
510
511    /// Missing data availability header.
512    #[error("Missing data availability header")]
513    MissingDataAvailabilityHeader,
514
515    /// Missing proof.
516    #[error("Missing proof")]
517    MissingProof,
518
519    /// Missing shares.
520    #[error("Missing shares")]
521    MissingShares,
522
523    /// Missing fee field
524    #[error("Missing fee field")]
525    MissingFee,
526
527    /// Missing sum field
528    #[error("Missing sum field")]
529    MissingSum,
530
531    /// Missing mode info field
532    #[error("Missing mode info field")]
533    MissingModeInfo,
534
535    /// Missing bitarray field
536    #[error("Missing bitarray field")]
537    MissingBitarray,
538
539    /// Bit array too large
540    #[error("Bit array to large")]
541    BitarrayTooLarge,
542
543    /// Malformed CompactBitArray
544    #[error("CompactBitArray malformed")]
545    MalformedCompactBitArray,
546
547    /// Wrong proof type.
548    #[error("Wrong proof type")]
549    WrongProofType,
550
551    /// Unsupported share version.
552    #[error("Unsupported share version: {0}")]
553    UnsupportedShareVersion(u8),
554
555    /// Invalid share size.
556    #[error("Invalid share size: {0}")]
557    InvalidShareSize(u64),
558
559    /// Invalid nmt leaf size.
560    #[error("Invalid nmt leaf size: {0}")]
561    InvalidNmtLeafSize(u64),
562
563    /// Invalid nmt node order.
564    #[error("Invalid nmt node order")]
565    InvalidNmtNodeOrder,
566
567    /// Share sequence length exceeded.
568    #[error(
569        "Sequence len must fit into {} bytes, got value {0}",
570        appconsts::SEQUENCE_LEN_BYTES
571    )]
572    ShareSequenceLenExceeded(u64),
573
574    /// Invalid namespace in version 0.
575    #[error("Invalid namespace v0")]
576    InvalidNamespaceV0,
577
578    /// Invalid namespace in version 255.
579    #[error("Invalid namespace v255")]
580    InvalidNamespaceV255,
581
582    /// Invalid namespaced hash.
583    #[error("Invalid namespace hash: {0}")]
584    InvalidNamespacedHash(String),
585
586    /// Invalid index of signature in commit.
587    #[error("Invalid index of signature in commit {0}, height {1}")]
588    InvalidSignatureIndex(u64, u64),
589
590    /// Invalid axis.
591    #[error("Invalid axis type: {0}")]
592    InvalidAxis(i32),
593
594    /// Invalid Shwap proof type in Protobuf.
595    #[error("Invalid proof type: {0}")]
596    InvalidShwapProofType(i32),
597
598    /// Could not deserialise Public Key
599    #[error("Could not deserialize public key")]
600    InvalidPublicKey,
601
602    /// Range proof verification error.
603    #[error("Range proof verification failed: {0:?}")]
604    RangeProofError(String),
605
606    /// Row root computed from shares doesn't match one received in `DataAvailabilityHeaderz
607    #[error("Computed root doesn't match received one")]
608    RootMismatch,
609
610    /// Unexpected signature in absent commit.
611    #[error("Unexpected absent commit signature")]
612    UnexpectedAbsentSignature,
613
614    /// Error that happened during validation.
615    #[error("Validation error: {0}")]
616    Validation(String),
617
618    /// Error that happened during verification.
619    #[error("Verification error: {0}")]
620    Verification(String),
621
622    /// Max share version exceeded.
623    #[error(
624        "Share version has to be at most {}, got {0}",
625        appconsts::MAX_SHARE_VERSION
626    )]
627    MaxShareVersionExceeded(u8),
628
629    /// An error related to the namespaced merkle tree.
630    #[error("Nmt error: {0}")]
631    Nmt(String),
632
633    /// Invalid address bech32 prefix.
634    #[error("Invalid address prefix: {0}")]
635    InvalidAddressPrefix(String),
636
637    /// Invalid size of the address.
638    #[error("Invalid address size: {0}")]
639    InvalidAddressSize(u64),
640
641    /// Invalid address.
642    #[error("Invalid address: {0}")]
643    InvalidAddress(String),
644
645    /// Invalid coin amount.
646    #[error("Invalid coin amount: {0}")]
647    InvalidCoinAmount(String),
648
649    /// Invalid coin denomination.
650    #[error("Invalid coin denomination: {0}")]
651    InvalidCoinDenomination(String),
652
653    /// Invalid balance
654    #[error("Invalid balance")]
655    InvalidBalance(String),
656
657    /// Invalid Public Key
658    #[error("Invalid Public Key")]
659    InvalidPublicKeyType(String),
660
661    /// Unsupported fraud proof type.
662    #[error("Unsupported fraud proof type: {0}")]
663    UnsupportedFraudProofType(String),
664
665    /// Data square index out of range.
666    #[error("Index ({0}) out of range ({1})")]
667    IndexOutOfRange(u64, u64),
668
669    /// Data square index out of range.
670    #[error("Data square index out of range. row: {0}, column: {1}")]
671    EdsIndexOutOfRange(u16, u16),
672
673    /// Could not create EDS, provided number of shares doesn't form a pefect square.
674    #[error("Invalid dimensions of EDS")]
675    EdsInvalidDimentions,
676
677    /// Zero block height.
678    #[error("Invalid zero block height")]
679    ZeroBlockHeight,
680
681    /// Expected first share of a blob
682    #[error("Expected first share of a blob")]
683    ExpectedShareWithSequenceStart,
684
685    /// Unexpected share from reserved namespace.
686    #[error("Unexpected share from reserved namespace")]
687    UnexpectedReservedNamespace,
688
689    /// Unexpected start of a new blob
690    #[error("Unexpected start of a new blob")]
691    UnexpectedSequenceStart,
692
693    /// Metadata mismatch between shares in blob.
694    #[error("Metadata mismatch between shares in blob: {0}")]
695    BlobSharesMetadataMismatch(String),
696
697    /// Blob too large, length must fit u32
698    #[error("Blob too large")]
699    BlobTooLarge,
700
701    /// Invalid comittment length
702    #[error("Invalid committment length")]
703    InvalidComittmentLength,
704
705    /// Missing signer field in blob with share version 1
706    #[error("Missing signer field in blob")]
707    MissingSigner,
708
709    /// Signer is not supported in share version 0
710    #[error("Signer is not supported in share version 0")]
711    SignerNotSupported,
712
713    /// Empty blob list provided when creating MsgPayForBlobs
714    #[error("Empty blob list")]
715    EmptyBlobList,
716
717    /// Missing DelegationResponse
718    #[error("Missing DelegationResponse")]
719    MissingDelegationResponse,
720
721    /// Missing Delegation
722    #[error("Missing Delegation")]
723    MissingDelegation,
724
725    /// Missing Balance
726    #[error("Missing Balance")]
727    MissingBalance,
728
729    /// Missing unbond
730    #[error("Missing unbond")]
731    MissingUnbond,
732
733    /// Missing completion time
734    #[error("Missing completion time")]
735    MissingCompletionTime,
736
737    /// Missing redelegation
738    #[error("Missing redelegation")]
739    MissingRedelegation,
740
741    /// Missing redelegation entry
742    #[error("Missing redelegation entry")]
743    MissingRedelegationEntry,
744
745    /// Invalid Cosmos decimal
746    #[error("Invalid Cosmos decimal: {0}")]
747    InvalidCosmosDecimal(String),
748}
749
750#[cfg(feature = "uniffi")]
751impl From<Error> for UniffiError {
752    fn from(value: Error) -> Self {
753        match value {
754            Error::UnsupportedNamespaceVersion(v) => UniffiError::UnsupportedNamespaceVersion(v),
755            Error::UnsupportedAppVersion(v) => UniffiError::UnsupportedAppVersion(v),
756            Error::InvalidNamespaceSize => UniffiError::InvalidNamespaceSize,
757            Error::Tendermint(e) => UniffiError::Tendermint(e.to_string()),
758            Error::Protobuf(e) => UniffiError::Protobuf(e.to_string()),
759            Error::Multihash(e) => UniffiError::Multihash(e.to_string()),
760            Error::CidError(e) => UniffiError::CidError(e.to_string()),
761            Error::LeopardCodec(e) => UniffiError::LeopardCodec(e.to_string()),
762            Error::MissingHeader => UniffiError::MissingHeader,
763            Error::MissingCommit => UniffiError::MissingCommit,
764            Error::MissingValidatorSet => UniffiError::MissingValidatorSet,
765            Error::MissingDataAvailabilityHeader => UniffiError::MissingDataAvailabilityHeader,
766            Error::MissingProof => UniffiError::MissingProof,
767            Error::MissingShares => UniffiError::MissingShares,
768            Error::MissingFee => UniffiError::MissingFee,
769            Error::MissingSum => UniffiError::MissingSum,
770            Error::MissingModeInfo => UniffiError::MissingModeInfo,
771            Error::MissingBitarray => UniffiError::MissingBitarray,
772            Error::BitarrayTooLarge => UniffiError::BitarrayTooLarge,
773            Error::MalformedCompactBitArray => UniffiError::MalformedCompactBitArray,
774            Error::WrongProofType => UniffiError::WrongProofType,
775            Error::UnsupportedShareVersion(v) => UniffiError::UnsupportedShareVersion(v),
776            Error::InvalidShareSize(s) => {
777                UniffiError::InvalidShareSize(s.try_into().expect("size to fit"))
778            }
779            Error::InvalidNmtLeafSize(s) => {
780                UniffiError::InvalidNmtLeafSize(s.try_into().expect("size to fit"))
781            }
782            Error::InvalidNmtNodeOrder => UniffiError::InvalidNmtNodeOrder,
783            Error::ShareSequenceLenExceeded(l) => {
784                UniffiError::ShareSequenceLenExceeded(l.try_into().expect("length to fit"))
785            }
786            Error::InvalidNamespaceV0 => UniffiError::InvalidNamespaceV0,
787            Error::InvalidNamespaceV255 => UniffiError::InvalidNamespaceV255,
788            Error::InvalidNamespacedHash(h) => UniffiError::InvalidNamespacedHash(h.to_string()),
789            Error::InvalidSignatureIndex(i, h) => {
790                UniffiError::InvalidSignatureIndex(i.try_into().expect("index to fit"), h)
791            }
792            Error::InvalidAxis(a) => UniffiError::InvalidAxis(a),
793            Error::InvalidShwapProofType(t) => UniffiError::InvalidShwapProofType(t),
794            Error::InvalidPublicKey => UniffiError::InvalidPublicKey,
795            Error::RangeProofError(e) => UniffiError::RangeProofError(format!("{e:?}")),
796            Error::RootMismatch => UniffiError::RootMismatch,
797            Error::UnexpectedAbsentSignature => UniffiError::UnexpectedAbsentSignature,
798            Error::Validation(e) => UniffiError::Validation(e.to_string()),
799            Error::Verification(e) => UniffiError::Verification(e.to_string()),
800            Error::MaxShareVersionExceeded(v) => UniffiError::MaxShareVersionExceeded(v),
801            Error::Nmt(e) => UniffiError::Nmt(e.to_string()),
802            Error::InvalidAddressPrefix(p) => UniffiError::InvalidAddressPrefix(p),
803            Error::InvalidAddressSize(s) => {
804                UniffiError::InvalidAddressSize(s.try_into().expect("size to fit"))
805            }
806            Error::InvalidAddress(a) => UniffiError::InvalidAddress(a),
807            Error::InvalidCoinAmount(a) => UniffiError::InvalidCoinAmount(a),
808            Error::InvalidCoinDenomination(d) => UniffiError::InvalidCoinDenomination(d),
809            Error::InvalidBalance(b) => UniffiError::InvalidBalance(b),
810            Error::InvalidPublicKeyType(t) => UniffiError::InvalidPublicKeyType(t),
811            Error::UnsupportedFraudProofType(t) => UniffiError::UnsupportedFraudProofType(t),
812            Error::IndexOutOfRange(i, r) => UniffiError::IndexOutOfRange(
813                i.try_into().expect("index to fit"),
814                r.try_into().expect("range to fit"),
815            ),
816            Error::EdsIndexOutOfRange(r, c) => UniffiError::EdsIndexOutOfRange(r, c),
817            Error::EdsInvalidDimentions => UniffiError::EdsInvalidDimentions,
818            Error::ZeroBlockHeight => UniffiError::ZeroBlockHeight,
819            Error::ExpectedShareWithSequenceStart => UniffiError::ExpectedShareWithSequenceStart,
820            Error::UnexpectedReservedNamespace => UniffiError::UnexpectedReservedNamespace,
821            Error::UnexpectedSequenceStart => UniffiError::UnexpectedSequenceStart,
822            Error::BlobSharesMetadataMismatch(s) => UniffiError::BlobSharesMetadataMismatch(s),
823            Error::BlobTooLarge => UniffiError::BlobTooLarge,
824            Error::InvalidComittmentLength => UniffiError::InvalidComittmentLength,
825            Error::MissingSigner => UniffiError::MissingSigner,
826            Error::SignerNotSupported => UniffiError::SignerNotSupported,
827            Error::EmptyBlobList => UniffiError::EmptyBlobList,
828            Error::MissingDelegationResponse => UniffiError::MissingDelegationResponse,
829            Error::MissingDelegation => UniffiError::MissingDelegation,
830            Error::MissingBalance => UniffiError::MissingBalance,
831            Error::MissingUnbond => UniffiError::MissingUnbond,
832            Error::MissingCompletionTime => UniffiError::MissingCompletionTime,
833            Error::MissingRedelegation => UniffiError::MissingRedelegation,
834            Error::MissingRedelegationEntry => UniffiError::MissingRedelegationEntry,
835            Error::InvalidCosmosDecimal(s) => UniffiError::InvalidCosmosDecimal(s),
836        }
837    }
838}