mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-12 10:08:49 +00:00
use tiny-secp256k1, updated nip06 and other utils.
This commit is contained in:
25
nip06.js
25
nip06.js
@@ -1,17 +1,28 @@
|
||||
import createHmac from 'create-hmac'
|
||||
import randomBytes from 'randombytes'
|
||||
import * as bip39 from 'bip39'
|
||||
import {wordlist} from 'micro-bip39/wordlists/english'
|
||||
import {
|
||||
generateMnemonic,
|
||||
mnemonicToSeedSync,
|
||||
validateMnemonic
|
||||
} from 'micro-bip39'
|
||||
import BIP32Factory from 'bip32'
|
||||
import * as ecc from 'tiny-secp256k1'
|
||||
|
||||
const bip32 = BIP32Factory(ecc)
|
||||
|
||||
export function privateKeyFromSeed(seed) {
|
||||
let hmac = createHmac('sha512', Buffer.from('Nostr seed', 'utf8'))
|
||||
hmac.update(seed)
|
||||
return hmac.digest().slice(0, 32).toString('hex')
|
||||
let root = bip32.fromSeed(Buffer.from(seed, 'hex'))
|
||||
return root.derivePath(`m/44'/1237'/0'/0'`).privateKey.toString('hex')
|
||||
}
|
||||
|
||||
export function seedFromWords(mnemonic) {
|
||||
return bip39.mnemonicToSeedSync(mnemonic)
|
||||
return Buffer.from(mnemonicToSeedSync(mnemonic, wordlist)).toString('hex')
|
||||
}
|
||||
|
||||
export function generateSeedWords() {
|
||||
return bip39.entropyToMnemonic(randomBytes(16).toString('hex'))
|
||||
return generateMnemonic(wordlist)
|
||||
}
|
||||
|
||||
export function validateWords(words) {
|
||||
return validateMnemonic(words, wordlist)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user