dpp/errors/consensus/signature/
signature_error.rs1use crate::consensus::signature::ContractBoundedKeyNonBatchError;
2use crate::consensus::signature::ContractBoundedKeyOutOfBoundsError;
3use crate::consensus::signature::PublicKeyBudgetExhaustedError;
4use crate::consensus::signature::PublicKeyExpiredError;
5use crate::consensus::signature::PublicKeyWithLimitsCannotUpdateKeyLimitsError;
6use crate::consensus::signature::{
7 BasicBLSError, BasicECDSAError, IdentityNotFoundError, InvalidIdentityPublicKeyTypeError,
8 InvalidSignaturePublicKeySecurityLevelError, InvalidStateTransitionSignatureError,
9 MissingPublicKeyError, PublicKeyIsDisabledError, PublicKeySecurityLevelNotMetError,
10 SignatureShouldNotBePresentError, UncompressedPublicKeyNotAllowedError,
11 WrongPublicKeyPurposeError,
12};
13use crate::consensus::ConsensusError;
14use bincode::{Decode, DecodeUntrusted, Encode};
15use thiserror::Error;
16
17use crate::consensus::signature::invalid_signature_public_key_purpose_error::InvalidSignaturePublicKeyPurposeError;
18use crate::errors::ProtocolError;
19use platform_serialization_derive::{
20 PlatformDeserializeTrusted, PlatformDeserializeUntrusted, PlatformSerialize,
21};
22
23#[derive(
24 Error,
25 Debug,
26 PartialEq,
27 Encode,
28 Decode,
29 PlatformSerialize,
30 PlatformDeserializeTrusted,
31 PlatformDeserializeUntrusted,
32 Clone,
33 DecodeUntrusted,
34)]
35pub enum SignatureError {
36 #[error(transparent)]
42 IdentityNotFoundError(IdentityNotFoundError),
43
44 #[error(transparent)]
45 InvalidIdentityPublicKeyTypeError(InvalidIdentityPublicKeyTypeError),
46
47 #[error(transparent)]
48 InvalidStateTransitionSignatureError(InvalidStateTransitionSignatureError),
49
50 #[error(transparent)]
51 MissingPublicKeyError(MissingPublicKeyError),
52
53 #[error(transparent)]
54 InvalidSignaturePublicKeyPurposeError(InvalidSignaturePublicKeyPurposeError),
55
56 #[error(transparent)]
57 InvalidSignaturePublicKeySecurityLevelError(InvalidSignaturePublicKeySecurityLevelError),
58
59 #[error(transparent)]
60 WrongPublicKeyPurposeError(WrongPublicKeyPurposeError),
61
62 #[error(transparent)]
63 PublicKeyIsDisabledError(PublicKeyIsDisabledError),
64
65 #[error(transparent)]
66 PublicKeySecurityLevelNotMetError(PublicKeySecurityLevelNotMetError),
67
68 #[error(transparent)]
69 SignatureShouldNotBePresentError(SignatureShouldNotBePresentError),
70
71 #[error(transparent)]
72 BasicECDSAError(BasicECDSAError),
73
74 #[error(transparent)]
75 BasicBLSError(BasicBLSError),
76
77 #[error(transparent)]
78 UncompressedPublicKeyNotAllowedError(UncompressedPublicKeyNotAllowedError),
79 #[error(transparent)]
80 ContractBoundedKeyNonBatchError(ContractBoundedKeyNonBatchError),
81
82 #[error(transparent)]
83 ContractBoundedKeyOutOfBoundsError(ContractBoundedKeyOutOfBoundsError),
84
85 #[error(transparent)]
87 PublicKeyBudgetExhaustedError(PublicKeyBudgetExhaustedError),
88
89 #[error(transparent)]
90 PublicKeyExpiredError(PublicKeyExpiredError),
91
92 #[error(transparent)]
94 PublicKeyWithLimitsCannotUpdateKeyLimitsError(PublicKeyWithLimitsCannotUpdateKeyLimitsError),
95}
96
97impl From<SignatureError> for ConsensusError {
98 fn from(err: SignatureError) -> Self {
99 Self::SignatureError(err)
100 }
101}
102
103#[cfg(test)]
104mod tests {
105 use super::*;
106 use platform_value::Identifier;
107
108 fn discriminant_of(error: SignatureError) -> u8 {
110 let bytes = bincode::encode_to_vec(error, bincode::config::standard())
111 .expect("expected to encode the signature error");
112 bytes[0]
113 }
114
115 #[test]
116 fn signature_error_discriminants_are_frozen() {
117 assert_eq!(
118 discriminant_of(SignatureError::IdentityNotFoundError(
119 IdentityNotFoundError::new(Identifier::from([1; 32]))
120 )),
121 0
122 );
123 assert_eq!(
124 discriminant_of(SignatureError::UncompressedPublicKeyNotAllowedError(
125 UncompressedPublicKeyNotAllowedError::new(65)
126 )),
127 12
128 );
129 assert_eq!(
130 discriminant_of(SignatureError::ContractBoundedKeyNonBatchError(
131 ContractBoundedKeyNonBatchError::new(1)
132 )),
133 13
134 );
135 assert_eq!(
136 discriminant_of(SignatureError::ContractBoundedKeyOutOfBoundsError(
137 ContractBoundedKeyOutOfBoundsError::new(1)
138 )),
139 14
140 );
141 assert_eq!(
142 discriminant_of(SignatureError::PublicKeyBudgetExhaustedError(
143 PublicKeyBudgetExhaustedError::new(1)
144 )),
145 15
146 );
147 assert_eq!(
148 discriminant_of(SignatureError::PublicKeyExpiredError(
149 PublicKeyExpiredError::new(1, 2, 3)
150 )),
151 16
152 );
153 assert_eq!(
154 discriminant_of(
155 SignatureError::PublicKeyWithLimitsCannotUpdateKeyLimitsError(
156 PublicKeyWithLimitsCannotUpdateKeyLimitsError::new(1)
157 )
158 ),
159 17
160 );
161 }
162}