Skip to content

Commit 026aeeb

Browse files
committed
refactor: use @noble/curves
1 parent 1bca065 commit 026aeeb

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

package-lock.json

+1-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"vitest": "1.6.0"
2020
},
2121
"dependencies": {
22-
"@noble/secp256k1": "1.7.1",
22+
"@noble/curves": "1.4.0",
2323
"@scure/bip32": "1.4.0",
2424
"@scure/bip39": "1.3.0",
2525
"bech32": "2.0.0"

src/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as secp256k1 from '@noble/secp256k1'
1+
import { secp256k1, schnorr } from '@noble/curves/secp256k1'
2+
import { hexToBytes, bytesToHex } from '@noble/curves/abstract/utils'
23
import { HDKey } from '@scure/bip32'
34
import {
45
generateMnemonic,
@@ -21,24 +22,24 @@ export function privateKeyFromSeedWords(
2122
throw new Error('could not derive private key')
2223
}
2324
return {
24-
privateKey: secp256k1.utils.bytesToHex(privateKey)
25+
privateKey: bytesToHex(privateKey)
2526
}
2627
}
2728

2829
export function generatePrivateKey(): { privateKey: string } {
2930
return {
30-
privateKey: secp256k1.utils.bytesToHex(secp256k1.utils.randomPrivateKey())
31+
privateKey: bytesToHex(secp256k1.utils.randomPrivateKey())
3132
}
3233
}
3334

3435
export function getPublicKey({ privateKey }: { privateKey: string }): { publicKey: string } {
3536
return {
36-
publicKey: secp256k1.utils.bytesToHex(secp256k1.schnorr.getPublicKey(privateKey))
37+
publicKey: bytesToHex(schnorr.getPublicKey(privateKey))
3738
}
3839
}
3940

4041
function hexToBech32(key: string, prefix: string) {
41-
const words = bech32.toWords(secp256k1.utils.hexToBytes(key))
42+
const words = bech32.toWords(hexToBytes(key))
4243
return bech32.encode(prefix, words)
4344
}
4445

0 commit comments

Comments
 (0)