File tree 1 file changed +8
-10
lines changed
1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -151,16 +151,14 @@ extension secp256k1 {
151
151
152
152
/// Backing initialization that creates a random secp256k1 private key for signing
153
153
@usableFromInline init ( format: secp256k1 . Format = . compressed) throws {
154
- let privateKey = SecureBytes ( count: secp256k1. ByteDetails. count)
155
- self . keyParity = 0
156
- self . format = format
157
- self . privateBytes = privateKey
158
- self . publicBytes = try PublicKeyImplementation . generate ( bytes: & privateBytes, format: format)
159
- self . xonlyBytes = try XonlyKeyImplementation . generate (
160
- bytes: publicBytes,
161
- keyParity: & keyParity,
162
- format: format
163
- )
154
+ for _ in 0 ..< 10 {
155
+ let randomBytes = SecureBytes ( count: secp256k1. ByteDetails. count)
156
+ if let privateKey = try ? PrivateKeyImplementation ( dataRepresentation: Data ( randomBytes) , format: format) {
157
+ self = privateKey
158
+ return
159
+ }
160
+ }
161
+ fatalError ( " Looped more than 10 times trying to generate a key " )
164
162
}
165
163
166
164
/// Backing initialization that creates a secp256k1 private key for signing from a data representation.
You can’t perform that action at this time.
0 commit comments