/** * Key Manager * * Utilities for wallet key generation, restoration, and invoice decoding. * Provides high-level wrappers around native RGB operations. * * @module core/KeyManager */ import Rgb from './NativeRgb'; import * as Interfaces from './Interfaces'; /** * Generates new keys for a wallet. * * @param bitcoinNetwork - The Bitcoin network to use (MAINNET, TESTNET, TESTNET4, REGTEST, SIGNET) * @returns Promise resolving to Keys containing mnemonic, xpub, accountXpubVanilla, accountXpubColored, and masterFingerprint * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if: * - Invalid Bitcoin network * - Key generation fails * * @example * ```typescript * import { generateKeys } from 'orbis1-sdk-node'; * * const keys = await generateKeys('TESTNET'); * console.log('Mnemonic:', keys.mnemonic); * console.log('XPub:', keys.xpub); * ``` */ export async function generateKeys( bitcoinNetwork: Interfaces.BitcoinNetwork ): Promise { return Rgb.generateKeys(bitcoinNetwork); } /** * Restores a wallet from a mnemonic. * * @param bitcoinNetwork - The Bitcoin network to use (MAINNET, TESTNET, TESTNET4, REGTEST, SIGNET) * @param mnemonic - The mnemonic to restore the wallet from * @returns Promise resolving to Keys containing mnemonic, xpub, accountXpubVanilla, accountXpubColored, and masterFingerprint * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if: * - Invalid Bitcoin network * - Invalid mnemonic * - Key restoration fails * * @example * ```typescript * import { restoreKeys } from 'orbis1-sdk-node'; * * const mnemonic = 'your twelve word mnemonic phrase here...'; * const keys = await restoreKeys('TESTNET', mnemonic); * ``` */ export async function restoreKeys( bitcoinNetwork: Interfaces.BitcoinNetwork, mnemonic: string ): Promise { return Rgb.restoreKeys(bitcoinNetwork, mnemonic); } /** * Restores a wallet from a backup file. * * @param path - The path to the backup file * @param password - The password to decrypt the backup * @returns Promise resolving to void on success * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if: * - Invalid backup path * - Invalid password * - Backup restoration fails * * @example * ```typescript * import { restoreBackup } from 'orbis1-sdk-node'; * * await restoreBackup('/path/to/backup.dat', 'mypassword'); * ``` */ export async function restoreBackup( path: string, password: string ): Promise { return Rgb.restoreBackup(path, password); } /** * Decodes an RGB invoice to extract payment information. * * @param invoice - The RGB invoice string to decode * @returns Promise resolving to InvoiceData containing parsed invoice information * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if: * - Invalid invoice format * - Decoding fails * * @example * ```typescript * import { decodeInvoice } from 'orbis1-sdk-node'; * * const invoiceData = await decodeInvoice('rgb1invoice...'); * console.log('Asset ID:', invoiceData.assetId); * console.log('Amount:', invoiceData.amount); * ``` */ export async function decodeInvoice( invoice: string ): Promise { return Rgb.decodeInvoice(invoice) as Promise; }