@dfinity/identity-secp256k1
Version:
JavaScript and TypeScript library to manage Secp256k1KeyIdentities for use with the Internet Computer
87 lines (86 loc) • 4.19 kB
TypeScript
import { type DerEncodedPublicKey, type KeyPair, type Signature, type PublicKey, SignIdentity } from '@dfinity/agent';
declare type PublicKeyHex = string;
declare type SecretKeyHex = string;
export declare type JsonableSecp256k1Identity = [PublicKeyHex, SecretKeyHex];
export declare class Secp256k1PublicKey implements PublicKey {
#private;
static fromRaw(rawKey: Uint8Array): Secp256k1PublicKey;
static fromDer(derKey: DerEncodedPublicKey): Secp256k1PublicKey;
/**
* Construct Secp256k1PublicKey from an existing PublicKey
* @param {unknown} maybeKey - existing PublicKey, ArrayBuffer, DerEncodedPublicKey, or hex string
* @returns {Secp256k1PublicKey} Instance of Secp256k1PublicKey
*/
static from(maybeKey: unknown): Secp256k1PublicKey;
private static derEncode;
private static derDecode;
get rawKey(): Uint8Array;
get derKey(): DerEncodedPublicKey;
private constructor();
toDer(): DerEncodedPublicKey;
toRaw(): Uint8Array;
}
export declare class Secp256k1KeyIdentity extends SignIdentity {
protected _privateKey: Uint8Array;
/**
* Generates an identity. If a seed is provided, the keys are generated from the
* seed according to BIP 0032. Otherwise, the key pair is randomly generated.
* This method throws an error in case the seed is not 32 bytes long or invalid
* for use as a private key.
* @param {Uint8Array} seed the optional seed
* @returns {Secp256k1KeyIdentity} Secp256k1KeyIdentity
*/
static generate(seed?: Uint8Array): Secp256k1KeyIdentity;
static fromParsedJson(obj: JsonableSecp256k1Identity): Secp256k1KeyIdentity;
static fromJSON(json: string): Secp256k1KeyIdentity;
/**
* generates an identity from a public and private key. Please ensure that you are generating these keys securely and protect the user's private key
* @param {Uint8Array} publicKey - Uint8Array
* @param {Uint8Array} privateKey - Uint8Array
* @returns {Secp256k1KeyIdentity} Secp256k1KeyIdentity
*/
static fromKeyPair(publicKey: Uint8Array, privateKey: Uint8Array): Secp256k1KeyIdentity;
/**
* generates an identity from an existing secret key, and is the correct method to generate an identity from a seed phrase. Please ensure you protect the user's private key.
* @param {Uint8Array} secretKey - Uint8Array
* @returns {Secp256k1KeyIdentity} - Secp256k1KeyIdentity
*/
static fromSecretKey(secretKey: Uint8Array): Secp256k1KeyIdentity;
/**
* Generates an identity from a seed phrase. Use carefully - seed phrases should only be used in secure contexts, and you should avoid having users copying and pasting seed phrases as much as possible.
* @param {string | string[]} seedPhrase - either an array of words or a string of words separated by spaces.
* @param password - optional password to be used by bip39
* @returns Secp256k1KeyIdentity
*/
static fromSeedPhrase(seedPhrase: string | string[], password?: string | undefined): Secp256k1KeyIdentity;
/**
* Utility method to create a Secp256k1KeyIdentity from a PEM-encoded key.
* @param pemKey - PEM-encoded key as a string
* @returns - Secp256k1KeyIdentity
*/
static fromPem(pemKey: string): Secp256k1KeyIdentity;
_publicKey: Secp256k1PublicKey;
protected constructor(publicKey: Secp256k1PublicKey, _privateKey: Uint8Array);
/**
* Serialize this key to JSON-serializable object.
* @returns {JsonableSecp256k1Identity} JsonableSecp256k1Identity
*/
toJSON(): JsonableSecp256k1Identity;
/**
* Return a copy of the key pair.
* @returns {KeyPair} KeyPair
*/
getKeyPair(): KeyPair;
/**
* Return the public key.
* @returns {Required<PublicKey>} Required<PublicKey>
*/
getPublicKey(): Required<PublicKey>;
/**
* Signs a blob of data, with this identity's private key.
* @param {Uint8Array} data - bytes to hash and sign with this identity's secretKey, producing a signature
* @returns {Promise<Signature>} signature
*/
sign(data: Uint8Array): Promise<Signature>;
}
export default Secp256k1KeyIdentity;