@roochnetwork/rooch-sdk
Version:
93 lines (92 loc) • 3.38 kB
TypeScript
import { BitcoinAddress, BitcoinNetowkType, RoochAddress } from '../../address/index.js';
import { Authenticator, Keypair, SignatureScheme } from '../../crypto/index.js';
import { Bytes } from '../../types/index.js';
import { Secp256k1PublicKey } from './publickey.js';
import { Transaction } from '../../transactions/index.js';
export declare const DEFAULT_SECP256K1_DERIVATION_PATH = "m/86'/0'/0'/0/1";
/**
* Secp256k1 Keypair data
*/
export interface Secp256k1KeypairData {
publicKey: Bytes;
secretKey: Bytes;
}
/**
* An Secp256k1 Keypair used for signing transactions.
*/
export declare class Secp256k1Keypair extends Keypair {
private keypair;
/**
* Create a new keypair instance.
* Generate random keypair if no {@link Secp256k1Keypair} is provided.
*
* @param keypair secp256k1 keypair
*/
constructor(keypair?: Secp256k1KeypairData);
getBitcoinAddress(): BitcoinAddress;
getBitcoinAddressWith(network: BitcoinNetowkType): BitcoinAddress;
getRoochAddress(): RoochAddress;
/**
* Get the key scheme of the keypair Secp256k1
*/
getKeyScheme(): SignatureScheme;
/**
* Generate a new random keypair
*/
static generate(): Secp256k1Keypair;
/**
* Create a keypair from a raw secret key byte array.
*
* This method should only be used to recreate a keypair from a previously
* generated secret key. Generating keypairs from a random seed should be done
* with the {@link Keypair.fromSeed} method.
*
* @throws error if the provided secret key is invalid and validation is not skipped.
*
* @param secretKey secret key byte array
* @param skipValidation skip secret key validation
*/
static fromSecretKey(secretKey: Uint8Array | string, skipValidation?: boolean): Secp256k1Keypair;
/**
* Generate a keypair from a 32 byte seed.
*
* @param seed seed byte array
*/
static fromSeed(seed: Uint8Array): Secp256k1Keypair;
/**
* The public key for this keypair
*/
getPublicKey(): Secp256k1PublicKey;
getSchnorrPublicKey(): Secp256k1PublicKey;
/**
* The Bech32 secret key string for this Secp256k1 keypair
*/
getSecretKey(): string;
/**
* Return the ecdsa signature for the provided data.
*/
sign(input: Bytes): Promise<Uint8Array>;
/**
* Return the schnorr signature for the provided data.
*/
sign_schnorr(input: Bytes, auxRand?: Bytes): Promise<Uint8Array>;
signTransaction(input: Transaction): Promise<Authenticator>;
/**
* Derive Secp256k1 keypair from mnemonics and path. The mnemonics must be normalized
* and validated against the english wordlist.
*
* If path is none, it will default to m/86'/0'/0'/0/1, otherwise the path must
* be compliant to BIP-32 in form m/86'/0'/{account_index}'/{change_index}/{address_index}.
*/
static deriveKeypair(mnemonics: string, path?: string): Secp256k1Keypair;
/**
* Generate a new mnemonic and derive a keypair from it.
*
* @param path Optional derivation path. If not provided, will use DEFAULT_SECP256K1_DERIVATION_PATH
* @returns An object containing the mnemonic and the derived keypair
*/
static generateWithMnemonic(path?: string): {
mnemonic: string;
keypair: Secp256k1Keypair;
};
}