UNPKG

libnexa-ts

Version:

A pure and powerful Nexa SDK library.

131 lines 4.49 kB
import { default as Point } from '../crypto/point'; import { Network } from '../core/network/network'; import { IPrivateKey, IPublicKey, PublicKeyDto } from '../common/interfaces'; export type PublicKeyVariants = PublicKey | Point | Partial<IPrivateKey> | Partial<IPublicKey> | PublicKeyDto | Uint8Array | string; /** * Instantiate new PublicKey. * * There are two internal properties, `network` and `compressed`, that deal with importing * a PublicKey from a PrivateKey in WIF format. * * @remarks Better to use {@linkcode PublicKey.from} method to init public key from various formats if the formart unknown. * * @example * ```ts * // export to as a DER hex encoded string * let exported = key.toString(); * * // import the public key * let imported = PublicKey.fromString(exported); * //or * let imported = PublicKey.from(exported); * ``` */ export default class PublicKey implements IPublicKey { point: Point; compressed: boolean; network: Network; /** * @param data - The pubkey data */ constructor(data: Partial<IPublicKey>); toObject: () => PublicKeyDto; toDER: () => Uint8Array; /** * @returns A plain object of the PublicKey */ toJSON(): PublicKeyDto; /** * Will output the PublicKey to a DER Uint8Array * * @returns A DER encoded buffer */ toBuffer(): Uint8Array; /** * Will output the PublicKey to a DER encoded hex string * * @returns A DER hex encoded string */ toString(): string; /** * Will return a string formatted for the console * * @returns Public key string inspection */ inspect(): string; /** * Instantiate a PublicKey from various formats * * @param data The encoded data in various formats * @param compressed If the public key is compressed * @param network The key network * @returns New PublicKey instance */ static from(data: PublicKeyVariants, compressed?: boolean, network?: Network): PublicKey; static fromDER: typeof PublicKey.fromBuffer; static fromObject: typeof PublicKey.fromJSON; /** * Instantiate a PublicKey from a Uint8Array * * @param buf - A DER hex buffer * @param strict - if set to false, will loosen some conditions * @param network - the network of the key * @returns A new valid instance of PublicKey */ static fromBuffer(buf: Uint8Array, strict?: boolean, network?: Network): PublicKey; /** * Instantiate a PublicKey from a Point * * @param point - A Point instance * @param compressed - whether to store this public key as compressed format * @param network - the network of the key * @returns A new valid instance of PublicKey */ static fromPoint(point: Point, compressed?: boolean, network?: Network): PublicKey; /** * Instantiate a PublicKey from a DER hex encoded string * * @param str - A DER hex string * @param network - the network of the key * @returns A new valid instance of PublicKey */ static fromString(str: string, network?: Network): PublicKey; /** * Instantiate a PublicKey from PrivateKey data * * @param data - Object contains data of PrivateKey * @returns A new valid instance of PublicKey */ static fromPrivateKey(data: IPrivateKey): PublicKey; static fromJSON(data: PublicKeyDto): PublicKey; /** * Check if there would be any errors when initializing a PublicKey * * @param data - The encoded data in various formats * @returns An error if exists */ static getValidationError(data: PublicKeyVariants): Error | undefined; /** * Check if the parameters are valid * * @param data - The encoded data in various formats * @returns true If the public key would be valid */ static isValid(data: PublicKeyVariants): boolean; private static _isPublicKeyData; private static _isPublicKeyDto; private static _isPrivateKeyData; /** * Internal function to transform DER into a public key point * * @param buf - An hex encoded buffer * @param strict - if set to false, will loosen some conditions * @returns An object with keys: point and compressed */ private static _transformDER; /** * Internal function to transform a JSON into a public key point */ private static _transformObject; } //# sourceMappingURL=publickey.d.ts.map