casper-js-sdk
Version:
SDK to interact with the Casper blockchain
64 lines (63 loc) • 2.51 kB
TypeScript
import { PrivateKeyInternal } from '../PrivateKey';
/**
* Represents a secp256k1 private key, supporting key generation, signing, and PEM encoding.
* The class offers static methods to create instances from bytes, hex, and PEM formats.
*/
export declare class PrivateKey implements PrivateKeyInternal {
/** The raw bytes of the private key. */
private key;
/**
* Creates an instance of PrivateKey.
* @param key - The private key bytes.
*/
constructor(key: Uint8Array);
/**
* Generates a new random secp256k1 private key.
* @returns A promise that resolves to a new PrivateKey instance.
*/
static generate(): PrivateKey;
/**
* Retrieves the byte array of the public key in compressed format.
* @returns A promise that resolves to the compressed public key bytes.
*/
publicKeyBytes(): Uint8Array;
/**
* Retrieves the byte array of the public key in compressed format.
* @returns A promise that resolves to the compressed public key bytes.
*/
getPublicKeyBytes(): Promise<Uint8Array>;
toBytes(): Uint8Array;
/**
* Signs a message using the private key.
* The message is first hashed with SHA-256 before signing.
* @param message - The message to sign.
* @returns A promise that resolves to the signature bytes in compact format.
*/
sign(message: Uint8Array): Uint8Array;
/**
* Creates a PrivateKey instance from a byte array.
* @param key - The byte array representing the private key.
* @returns A new PrivateKey instance.
* @throws Error if the byte array length is not 32.
*/
static fromBytes(key: Uint8Array): PrivateKey;
/**
* Creates a PrivateKey instance from a hexadecimal string.
* @param key - The hexadecimal string representing the private key.
* @returns A new PrivateKey instance.
* @throws Error if the hex length is not 64 characters or if decoding fails.
*/
static fromHex(key: string): PrivateKey;
/**
* Exports the private key to PEM format, which can be used for secure storage or sharing.
* @returns A PEM-encoded string of the private key.
*/
toPem(): string;
/**
* Creates a PrivateKey instance from a PEM-encoded string.
* @param content - The PEM string representing the private key.
* @returns A new PrivateKey instance.
* @throws Error if the content cannot be properly parsed.
*/
static fromPem(content: string): PrivateKey;
}