libnexa-ts
Version:
A pure and powerful Nexa SDK library.
150 lines • 5.03 kB
TypeScript
import { Networkish } from '../common/types';
import { IPrivateKey, PrivateKeyDto } from '../common/interfaces';
import { Network } from '../core/network/network';
import { default as BN } from '../crypto/bn.extension';
import { default as PublicKey } from './publickey';
import { default as Address } from '../core/address/address';
import { AddressType } from '../core/address/address-formatter';
export type PrivateKeyVariants = BN | string | Uint8Array | PrivateKey | IPrivateKey | PrivateKeyDto | null;
export default class PrivateKey implements IPrivateKey {
private _pubkey?;
bn: BN;
compressed: boolean;
network: Network;
/**
* Instantiate a PrivateKey.
*
* @param data The private key data
*
* @remarks Better to use {@linkcode PrivateKey.from} method to init private key from various formats if the formart unknown.
*
* @example
* ```ts
* // generate a new random key
* let key = new PrivateKey();
*
* // encode into wallet import format
* let exported = key.toWIF();
*
* // instantiate from the exported (and saved) private key
* let imported = PrivateKey.fromWIF(exported);
* ```
*/
constructor(data?: Partial<IPrivateKey>);
get publicKey(): PublicKey;
/**
* Will return an address for the private key with its defined network
*
* @param type - optional parameter specifying the desired type of the address.
* default {@link AddressType.PayToScriptTemplate}
*
* @returns An address generated from the private key
*/
toAddress(type?: AddressType): Address;
/**
* Will output the PrivateKey encoded as hex string
*/
toString(): string;
/**
* Will encode the PrivateKey to a WIF string
*
* @returns A WIF representation of the private key
*/
toWIF(): string;
/**
* Will return the private key as a BN instance
*
* @returns A BN instance of the private key
*/
toBigNumber(): BN;
/**
* Will return the private key as a BN buffer
*
* @returns A buffer of the private key
*/
toBuffer(): Uint8Array;
/**
* Will return the private key as a BN buffer without leading zero padding
*
* @returns A buffer of the private key
*/
toBufferNoPadding(): Uint8Array;
/**
* Will return the corresponding public key
*
* @returns A public key generated from the private key
*/
toPublicKey(): PublicKey;
toObject: () => PrivateKeyDto;
/**
* @returns A plain object representation
*/
toJSON(): PrivateKeyDto;
/**
* Will return a string formatted for the console
*
* @returns Private key details
*/
inspect(): string;
/**
* Instantiate a PrivateKey from a Uint8Array with the DER or WIF representation
*/
static fromBuffer(buf: Uint8Array, network?: Networkish): PrivateKey;
static fromString: typeof PrivateKey.fromWIF;
/**
* Instantiate a PrivateKey from a WIF string
*
* @param str - The WIF encoded private key string
* @returns A new valid instance of PrivateKey
*/
static fromWIF(str: string, network?: Networkish): PrivateKey;
static fromObject: typeof PrivateKey.fromJSON;
/**
* Instantiate a PrivateKey from a plain JavaScript object
*
* @param obj - The output from privateKey.toObject()
*/
static fromJSON(obj: PrivateKeyDto): PrivateKey;
/**
* Instantiate a PrivateKey from random bytes
*
* @param network - Either "mainnet" or "testnet"
* @returns A new valid instance of PrivateKey
*/
static fromRandom(network?: Networkish): PrivateKey;
/**
* Check if there would be any errors when initializing a PrivateKey
*
* @param data - The encoded data in various formats
* @param network - Either "mainnet" or "testnet"
* @returns An error if exists
*/
static getValidationError(data: PrivateKeyVariants, network?: Networkish): Error | undefined;
/**
* Check if the parameters are valid
*
* @param data - The encoded data in various formats
* @param network - Either "mainnet" or "testnet"
* @returns true If the private key would be valid
*/
static isValid(data?: PrivateKeyVariants, network?: Networkish): boolean;
/**
* Helper to instantiate PrivateKey from different kinds of arguments.
*/
static from(data?: PrivateKeyVariants, network?: Networkish): PrivateKey;
private static _isPrivateKeyParams;
private static _getRandomBN;
/**
* Internal function to transform a WIF Uint8Array into a private key
*/
private static _transformBuffer;
/**
* Internal function to transform a JSON object into a private key
*/
private static _transformObject;
/**
* Internal function to transform a WIF string into a private key
*/
private static _transformWIF;
}
//# sourceMappingURL=privatekey.d.ts.map