UNPKG

tiny-crypto-suite

Version:

Tiny tools, big crypto — seamless encryption and certificate handling for modern web and Node apps.

123 lines 5.66 kB
export default TinyBtcSecp256k1; declare class TinyBtcSecp256k1 extends TinySecp256k1 { /** * Creates an instance of TinyBtcSecp256k1. * * @param {Object} [options] - Optional parameters for the instance. * @param {string|null} [options.prefix='bc'] - Crypto prefix used during message verification. * @param {number|null} [options.p2pkhPrefix=0x00] - Crypto prefix used during message verification. * @param {PubKeyTypes} [options.type=this.getType()] - The type of address to generate. * @param {string|null} [options.msgPrefix='Bitcoin Signed Message:\n'] - Message prefix used during message signing. * @param {string|null} [options.privateKey=null] - String representation of the private key. * @param {BufferEncoding} [options.privateKeyEncoding='hex'] - Encoding used for the privateKey string. */ constructor({ type, p2pkhPrefix, prefix, msgPrefix, privateKey, privateKeyEncoding, }?: { prefix?: string | null | undefined; p2pkhPrefix?: number | null | undefined; type?: ("p2pkh" | "bech32") | undefined; msgPrefix?: string | null | undefined; privateKey?: string | null | undefined; privateKeyEncoding?: BufferEncoding | undefined; }); /** @typedef {import('bs58check/index')} Bs58check */ /** @typedef {import('bech32/index')} Bech32 */ /** @typedef {import('elliptic').ec.KeyPair} KeyPair */ /** @typedef {import('./index.mjs').ValidationResult} ValidationResult */ /** @typedef {'p2pkh'|'bech32'} PubKeyTypes */ p2pkhPrefix: number; /** * Returns the p2pkh prefix if it's a number. * * @returns {number} * @throws {Error} If p2pkhPrefix is not a number. */ getP2pkhPrefix(): number; /** * Dynamically imports the `bech32` module and stores it in the instance. * Ensures the module is loaded only once (lazy singleton). * * @returns {Promise<{ base32: Bech32, base32m: Bech32 }>} The loaded `bech32` module. */ fetchBech32(): Promise<{ base32: typeof import("bech32/index"); base32m: typeof import("bech32/index"); }>; bech32Module: typeof import("bech32") | undefined; bech32: import("bech32").BechLib | undefined; bech32m: import("bech32").BechLib | undefined; /** * Returns the initialized `bech32` instance from the bech32 module. * * @returns {Bech32} The bech32 instance. * @throws Will throw an error if `bech32` is not initialized. */ getBech32m(): typeof import("bech32/index"); /** * Returns the initialized `bech32` instance from the bech32 module. * * @returns {Bech32} The bech32 instance. * @throws Will throw an error if `bech32` is not initialized. */ getBech32(): typeof import("bech32/index"); /** * Dynamically imports the `bs58check` module and stores it in the instance. * Ensures the module is loaded only once (lazy singleton). * * @returns {Promise<Bs58check>} The loaded `bs58check` module. */ fetchBs58check(): Promise<{ encode(buffer: Buffer | number[] | Uint8Array): string; decodeUnsafe(string: string): Buffer | undefined; decode(string: string): Buffer; }>; bs58check: { encode: (payload: Uint8Array | number[]) => string; decode: (str: string) => Uint8Array; decodeUnsafe: (str: string) => Uint8Array | undefined; } | undefined; /** * Returns the initialized `bs58check` instance from the bs58check module. * * @returns {Bs58check} The bs58check instance. * @throws Will throw an error if `bs58check` is not initialized. */ getBs58check(): { encode(buffer: Buffer | number[] | Uint8Array): string; decodeUnsafe(string: string): Buffer | undefined; decode(string: string): Buffer; }; /** * Verifies a signed message using the given public key. * * @param {string|Buffer} message - The original message. * @param {string|Buffer} signature - Signature in DER format (base64-encoded or Buffer). * @param {Object} [options] - Verification options. * @param {PubKeyTypes} [options.type=this.getType()] - The type of address to generate. * @param {BufferEncoding} [options.encoding='base64'] - Encoding of the signature if it's a string. * @param {string} [options.prefix=this.getMsgPrefix()] - Message prefix. * @returns {string|null} The recovered compressed public key in hex format, or null if recovery fails. */ recoverMessage(message: string | Buffer, signature: string | Buffer, options?: { type?: ("p2pkh" | "bech32") | undefined; encoding?: BufferEncoding | undefined; prefix?: string | undefined; }): string | null; /** * Signs a message using the instance's private key with a Bitcoin-style prefix and double SHA256 hashing. * * @param {string} message - The message to be signed. * @param {Object} [options={}] - Optional signing parameters. * @param {BufferEncoding} [options.encoding='utf8'] - Encoding for input message if it is a string. * @param {string} [options.prefix] - Optional prefix (defaults to Bitcoin prefix or instance default). * @returns {Buffer} The signature. * @throws {Error} If recovery param could not be calculated. */ signMessage(message: string, options?: { encoding?: BufferEncoding | undefined; prefix?: string | undefined; }): Buffer; #private; } import TinySecp256k1 from './index.mjs'; import { Buffer } from 'buffer'; //# sourceMappingURL=TinyBtcSecp256k1.d.mts.map