Skip to main content

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