bring back @noble/secp256k1 along with micro-bip32.

This commit is contained in:
fiatjaf
2021-12-31 22:47:43 -03:00
parent 16536340e5
commit 01dd5b7a3c
5 changed files with 13 additions and 33 deletions

16
keys.js
View File

@@ -1,19 +1,9 @@
import randomBytes from 'randombytes'
import {isPrivate, pointFromScalar} from 'tiny-secp256k1'
import * as secp256k1 from '@noble/secp256k1'
export function generatePrivateKey() {
let i = 8
while (i--) {
let r32 = Buffer.from(randomBytes(32))
if (isPrivate(r32)) return r32.toString('hex')
}
throw new Error(
'Valid private key was not found in 8 iterations. PRNG is broken'
)
return Buffer.from(secp256k1.utils.randomPrivateKey()).toString('hex')
}
export function getPublicKey(privateKey) {
return Buffer.from(pointFromScalar(Buffer.from(privateKey, 'hex'), true))
.toString('hex')
.slice(2)
return secp256k1.getPublicKey(privateKey)
}