File tree Expand file tree Collapse file tree 3 files changed +26
-18
lines changed Expand file tree Collapse file tree 3 files changed +26
-18
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ edition = "2018"
11
11
bolos-common = { version = " 0.1" , path = " ../bolos-common" }
12
12
bolos-sys = { version = " 0.1" , path = " ../bolos-sys" }
13
13
zemu-sys = { version = " 0.1" , path = " ../zemu" }
14
-
14
+ ed25519-dalek = { version = " 2.1.1 " , default-features = false }
15
15
cfg-if = " 1.0.0"
16
16
no-std-compat = { version = " 0.4" }
17
17
Original file line number Diff line number Diff line change @@ -143,6 +143,25 @@ impl AsRef<[u8]> for PublicKey {
143
143
}
144
144
}
145
145
146
+ pub fn public_from_bytes_ed25519 (
147
+ bytes : & [ u8 ; 32 ] ,
148
+ out : & mut MaybeUninit < PublicKey > ,
149
+ ) -> Result < ( ) , Error > {
150
+ use ed25519_dalek:: { SigningKey , VerifyingKey } ;
151
+
152
+ // Initialize the PublicKey struct with the appropriate data
153
+ unsafe {
154
+ let out_ptr = out. as_mut_ptr ( ) ;
155
+ ( * out_ptr) . 0 . W [ 0 ] = 0x02 ; // Add prefix for compressed format
156
+ ( * out_ptr) . 0 . W [ 1 ..33 ]
157
+ . copy_from_slice ( & SigningKey :: from_bytes ( bytes) . verifying_key ( ) . to_bytes ( ) ) ;
158
+ ( * out_ptr) . 0 . W_len = 33 ; // Length includes the prefix byte
159
+ ( * out_ptr) . 0 . curve = Curve :: Ed25519 as u32 ;
160
+ }
161
+
162
+ Ok ( ( ) )
163
+ }
164
+
146
165
pub struct SecretKey < const B : usize > {
147
166
mode : Mode ,
148
167
curve : Curve ,
Original file line number Diff line number Diff line change @@ -114,12 +114,7 @@ impl<const B: usize> SecretKey<B> {
114
114
rand_chacha7:: ChaCha8Rng :: from_seed ( seed)
115
115
}
116
116
117
- pub fn new (
118
- _: Mode ,
119
- curve : Curve ,
120
- path : BIP32Path < B > ,
121
- ed25519_secret_key_bytes : Option < [ u8 ; 32 ] > ,
122
- ) -> Self {
117
+ pub fn new ( _: Mode , curve : Curve , path : BIP32Path < B > ) -> Self {
123
118
let bytes = match curve {
124
119
Curve :: Secp256K1 => {
125
120
let secret = k256:: ecdsa:: SigningKey :: random ( & mut Self :: rng8 ( path) ) ;
@@ -132,17 +127,11 @@ impl<const B: usize> SecretKey<B> {
132
127
* secret. to_bytes ( ) . as_ref ( )
133
128
}
134
129
Curve :: Ed25519 => {
135
- if let Some ( bytes) = ed25519_secret_key_bytes {
136
- let secret = ed25519_dalek:: SigningKey :: from_bytes ( & bytes) ;
137
- secret. to_bytes ( )
138
- } else {
139
- // Generate random bytes using the path if no bytes provided
140
- let mut bytes = [ 0u8 ; 32 ] ;
141
- let mut rng = Self :: rng8 ( path) ;
142
- use rand_chacha8:: rand_core:: RngCore ;
143
- rng. fill_bytes ( & mut bytes) ;
144
- bytes
145
- }
130
+ let mut bytes = [ 0u8 ; 32 ] ;
131
+ let mut rng = Self :: rng8 ( path) ;
132
+ use rand_chacha8:: rand_core:: RngCore ;
133
+ rng. fill_bytes ( & mut bytes) ;
134
+ bytes
146
135
}
147
136
Curve :: Stark256 => {
148
137
panic ! ( "invalid curve passed to ecfp256 new" )
You can’t perform that action at this time.
0 commit comments