1
- use miden_objects:: crypto:: dsa:: rpo_falcon512:: SecretKey as NativeSecretKey ;
1
+ use miden_objects:: { Word as NativeWord , crypto:: dsa:: rpo_falcon512:: SecretKey as NativeSecretKey } ;
2
2
use rand:: { SeedableRng , rngs:: StdRng } ;
3
3
use wasm_bindgen:: prelude:: * ;
4
+ use wasm_bindgen_futures:: js_sys:: Uint8Array ;
4
5
5
- use crate :: models:: public_key:: PublicKey ;
6
+ use crate :: {
7
+ models:: { public_key:: PublicKey , signature:: Signature , word:: Word } ,
8
+ utils:: { deserialize_from_uint8array, serialize_to_uint8array} ,
9
+ } ;
6
10
7
11
#[ wasm_bindgen]
8
12
pub struct SecretKey ( NativeSecretKey ) ;
@@ -28,6 +32,22 @@ impl SecretKey {
28
32
pub fn public_key ( & self ) -> PublicKey {
29
33
self . 0 . public_key ( ) . into ( )
30
34
}
35
+
36
+ pub fn sign ( & self , message : & Word ) -> Result < Signature , JsValue > {
37
+ let native_message: NativeWord = message. into ( ) ;
38
+ let mut rng = StdRng :: from_os_rng ( ) ;
39
+ let signature = self . 0 . sign_with_rng ( native_message, & mut rng) ;
40
+ Ok ( signature. into ( ) )
41
+ }
42
+
43
+ pub fn serialize ( & self ) -> Uint8Array {
44
+ serialize_to_uint8array ( & self . 0 )
45
+ }
46
+
47
+ pub fn deserialize ( bytes : & Uint8Array ) -> Result < SecretKey , JsValue > {
48
+ let native_secret_key = deserialize_from_uint8array :: < NativeSecretKey > ( bytes) ?;
49
+ Ok ( SecretKey ( native_secret_key) )
50
+ }
31
51
}
32
52
33
53
// CONVERSIONS
0 commit comments