add nip06.

This commit is contained in:
fiatjaf
2021-12-11 19:28:00 -03:00
parent 57b9bac9b1
commit 93b22e48a6
4 changed files with 23 additions and 4 deletions

17
nip06.js Normal file
View File

@@ -0,0 +1,17 @@
import createHmac from 'create-hmac'
import randomBytes from 'randombytes'
import * as bip39 from 'bip39'
export function privateKeyFromSeed(seed) {
let hmac = createHmac('sha512', Buffer.from('Nostr seed', 'utf8'))
hmac.update(seed)
return hmac.digest().slice(0, 32).toString('hex')
}
export function seedFromWords(mnemonic) {
return bip39.mnemonicToSeedSync(mnemonic)
}
export function generateSeedWords() {
return bip39.entropyToMnemonic(randomBytes(16).toString('hex'))
}