File tree Expand file tree Collapse file tree 3 files changed +25
-13
lines changed Expand file tree Collapse file tree 3 files changed +25
-13
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 @@ -118,7 +118,6 @@ impl<const B: usize> SecretKey<B> {
118
118
_: Mode ,
119
119
curve : Curve ,
120
120
path : BIP32Path < B > ,
121
- ed25519_secret_key_bytes : Option < [ u8 ; 32 ] > ,
122
121
) -> Self {
123
122
let bytes = match curve {
124
123
Curve :: Secp256K1 => {
@@ -132,17 +131,11 @@ impl<const B: usize> SecretKey<B> {
132
131
* secret. to_bytes ( ) . as_ref ( )
133
132
}
134
133
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
- }
134
+ let mut bytes = [ 0u8 ; 32 ] ;
135
+ let mut rng = Self :: rng8 ( path) ;
136
+ use rand_chacha8:: rand_core:: RngCore ;
137
+ rng. fill_bytes ( & mut bytes) ;
138
+ bytes
146
139
}
147
140
Curve :: Stark256 => {
148
141
panic ! ( "invalid curve passed to ecfp256 new" )
You can’t perform that action at this time.
0 commit comments