UNPKG

@hiero-ledger/cryptography

Version:

Cryptographic utilities and primitives for the Hiero SDK

116 lines (115 loc) 3.41 kB
/** * @typedef {object} KeyPair * @property {Uint8Array} publicKey * @property {Uint8Array} privateKey */ export default class EcdsaPrivateKey { /** * Generate a random ECDSA private key. * @returns {EcdsaPrivateKey} */ static generate(): EcdsaPrivateKey; /** * Generate a random Ed25519 private key. * @returns {Promise<EcdsaPrivateKey>} */ static generateAsync(): Promise<EcdsaPrivateKey>; /** * Construct a private key from bytes. * @param {Uint8Array} data * @returns {EcdsaPrivateKey} */ static fromBytes(data: Uint8Array): EcdsaPrivateKey; /** * Construct a private key from bytes. * @param {Uint8Array} data * @returns {EcdsaPrivateKey} */ static fromBytesDer(data: Uint8Array): EcdsaPrivateKey; /** * Construct a private key from bytes. * @param {Uint8Array} data * @returns {EcdsaPrivateKey} */ static fromBytesRaw(data: Uint8Array): EcdsaPrivateKey; /** * Construct a private key from a hex-encoded string. * @param {string} text * @returns {EcdsaPrivateKey} */ static fromString(text: string): EcdsaPrivateKey; /** * Construct a private key from a hex-encoded string. * @param {string} text * @returns {EcdsaPrivateKey} */ static fromStringDer(text: string): EcdsaPrivateKey; /** * Construct a private key from a hex-encoded string. * @param {string} text * @returns {EcdsaPrivateKey} */ static fromStringRaw(text: string): EcdsaPrivateKey; /** * Construct a ECDSA private key from a Uint8Array seed. * @param {Uint8Array} seed * @returns {Promise<EcdsaPrivateKey>} */ static fromSeed(seed: Uint8Array): Promise<EcdsaPrivateKey>; /** * @hideconstructor * @internal * @param {KeyPair} keyPair * @param {(Uint8Array)=} chainCode */ constructor(keyPair: KeyPair, chainCode?: (Uint8Array) | undefined); /** * @type {KeyPair} * @readonly * @private */ private readonly _keyPair; /** * @type {?Uint8Array} * @readonly */ readonly _chainCode: Uint8Array | null; /** * @returns {string} */ get _type(): string; /** * Get the public key associated with this private key. * * The public key can be freely given and used by other parties to verify * the signatures generated by this private key. * @returns {EcdsaPublicKey} */ get publicKey(): EcdsaPublicKey; /** * Sign a message with this private key. * @param {Uint8Array} bytes * @returns {Uint8Array} - The signature bytes without the message */ sign(bytes: Uint8Array): Uint8Array; /** * @returns {Uint8Array} */ toBytesDer(): Uint8Array; /** * @returns {Uint8Array} */ toBytesRaw(): Uint8Array; /** * Recover the recovery ID used in the signature for the given message. * @param {Uint8Array} signature - 64-byte compact signature (r || s) * @param {Uint8Array} message - The original (unhashed) message * @returns {number} Recovery ID (0–3), or -1 if not found */ getRecoveryId(signature: Uint8Array, message: Uint8Array): number; } export type KeyPair = { publicKey: Uint8Array; privateKey: Uint8Array; }; import EcdsaPublicKey from "./EcdsaPublicKey.js";