@humanjavaenterprises/nostr-nsec-seedphrase
Version:
A comprehensive TypeScript library designed to make Nostr keys human-readable and easier to manage. It supports seedphrase generation, key conversions between nsec/npub and hex formats, and provides secure key management utilities.
67 lines (66 loc) • 2.26 kB
TypeScript
export interface KeyPair {
nsec: string;
npub: string;
privateKeyHex: string;
publicKeyHex: string;
}
export interface KeyPairWithSeed extends KeyPair {
seedPhrase: string;
}
export declare class NostrSeedPhrase {
/**
* Convert a Nostr nsec private key to a BIP39 seed phrase
* @param nsec - The nsec private key to convert
* @returns Object containing the seed phrase and original nsec
*/
static nsecToSeed(nsec: string): {
seedPhrase: string;
};
/**
* Convert a BIP39 seed phrase to a Nostr nsec private key
* @param seedPhrase - The BIP39 mnemonic seed phrase
* @returns Object containing the nsec private key and original seed phrase
*/
static seedToNsec(seedPhrase: string): KeyPair;
/**
* Validate a BIP39 seed phrase
* @param seedPhrase - The seed phrase to validate
* @returns boolean indicating if the seed phrase is valid
*/
static validateSeedPhrase(seedPhrase: string): boolean;
/**
* Generate a new Nostr key pair with corresponding seed phrase
* @returns Object containing the new nsec private key, npub public key, and seed phrase
*/
static generateNew(): KeyPairWithSeed;
/**
* Create a key pair from a hex private key
* @param privateKeyHex - The hex private key to convert
* @returns Object containing the nsec, npub, and hex versions of the keys
*/
static fromHex(privateKeyHex: string): KeyPair;
/**
* Convert an nsec to its hex representation
* @param nsec - The nsec to convert
* @returns The hex private key
*/
static nsecToHex(nsec: string): string;
/**
* Convert an npub to its hex representation
* @param npub - The npub to convert
* @returns The hex public key
*/
static npubToHex(npub: string): string;
/**
* Convert a hex public key to npub format
* @param publicKeyHex - The hex public key to convert
* @returns The npub
*/
static hexToNpub(publicKeyHex: string): string;
/**
* Convert a hex private key to nsec format
* @param privateKeyHex - The hex private key to convert
* @returns The nsec
*/
static hexToNsec(privateKeyHex: string): string;
}