Add nip06 private key generation

This commit is contained in:
w3irdrobot
2023-03-10 14:02:43 -05:00
parent 1357b7a903
commit debc9566cc
10 changed files with 107 additions and 11 deletions

View File

@ -5,6 +5,8 @@ import { decode as invoiceDecode } from "light-bolt11-decoder";
import { bech32 } from "bech32";
import base32Decode from "base32-decode";
import { HexKey, TaggedRawEvent, u256, EventKind, encodeTLV, NostrPrefix } from "@snort/nostr";
import * as bip39 from "@scure/bip39";
import { wordlist } from "@scure/bip39/wordlists/english";
import { MetadataCache } from "State/Users";
@ -100,6 +102,14 @@ export function hexToBech32(hrp: string, hex?: string) {
}
}
/**
* Convert hex-encoded entropy into mnemonic phrase
*/
export function hexToMnemonic(hex: string): string {
const bytes = secp.utils.hexToBytes(hex);
return bip39.entropyToMnemonic(bytes, wordlist);
}
/**
* Convert hex pubkey to bech32 link url
*/