@@ -6,16 +6,23 @@ use starknet_crypto::{rfc6979_generate_k, sign, verify, SignError, VerifyError};
6
6
mod errors {
7
7
use core:: fmt:: { Display , Formatter , Result } ;
8
8
9
+ /// Errors when performing ECDSA [`sign`](fn.ecdsa_sign) operations.
9
10
#[ derive( Debug ) ]
10
11
pub enum EcdsaSignError {
12
+ /// The message hash is not in the range of `[0, 2^251)`.
11
13
MessageHashOutOfRange ,
12
14
}
13
15
14
16
#[ derive( Debug ) ]
17
+ /// Errors when performing ECDSA [`verify`](fn.ecdsa_verify) operations.
15
18
pub enum EcdsaVerifyError {
19
+ /// The message hash is not in the range of `[0, 2^251)`.
16
20
MessageHashOutOfRange ,
21
+ /// The public key is not a valid point on the STARK curve.
17
22
InvalidPublicKey ,
23
+ /// The `r` value is not in the range of `[0, 2^251)`.
18
24
SignatureROutOfRange ,
25
+ /// The `s` value is not in the range of `[0, 2^251)`.
19
26
SignatureSOutOfRange ,
20
27
}
21
28
@@ -46,6 +53,16 @@ mod errors {
46
53
}
47
54
pub use errors:: { EcdsaSignError , EcdsaVerifyError } ;
48
55
56
+ /// Computes the Pedersen hash of a list of [`Felt`].
57
+ ///
58
+ /// The hash is computed by starting with `0`, hashing it recursively against all elements in
59
+ /// the list, and finally also hashing against the length of the list.
60
+ ///
61
+ /// For example, calling `compute_hash_on_elements([7, 8])` would return:
62
+ ///
63
+ /// ```markdown
64
+ /// pedersen_hash(pedersen_hash(pedersen_hash(0, 7)), 8), 2)
65
+ /// ```
49
66
pub fn compute_hash_on_elements < ' a , ESI , II > ( data : II ) -> Felt
50
67
where
51
68
ESI : ExactSizeIterator < Item = & ' a Felt > ,
62
79
pedersen_hash ( & current_hash, & data_len)
63
80
}
64
81
82
+ /// Signs a hash using deterministic ECDSA on the STARK curve. The signature returned can be used
83
+ /// to recover the public key.
65
84
pub fn ecdsa_sign (
66
85
private_key : & Felt ,
67
86
message_hash : & Felt ,
@@ -89,6 +108,7 @@ pub fn ecdsa_sign(
89
108
}
90
109
}
91
110
111
+ /// Verified an ECDSA signature on the STARK curve.
92
112
pub fn ecdsa_verify (
93
113
public_key : & Felt ,
94
114
message_hash : & Felt ,
0 commit comments