UNPKG

navio-blsct

Version:

TypeScript bindings for the `libblsct` library used by the [Navio](https://nav.io/) blockchain to construct confidential transactions based on the BLS12-381 curve.

65 lines (64 loc) 2.37 kB
import { ManagedObj } from '../managedObj'; import { Point } from '../point'; import { Scalar } from '../scalar'; /** Represents an element in the BLS12-381 G1 curve group that is used as a public key. * * Examples: * ```ts * const { PublicKey, Point, Scalar } = require('navio-blsct') * const s123 = new Scalar(123) * const pk123 = PublicKey.fromScalar(s123) * const s234 = new Scalar(234) * const pk234 = PublicKey.fromScalar(s234) * pk123.equals(pk234) // false * pk123.equals(pk123) // true * const p = Point.random() * const pk = PublicKey.fromPoint(p) * pk.getPoint() * const vk = Scalar.random() * pk.generateNonce(vk) * const ser = pk.serialize() * const deser = PublicKey.deserialize(ser) * ser == deser.serialize() * ``` */ export declare class PublicKey extends ManagedObj { /** Constructs a new `PublicKey` instance. * - If no parameter is provided, a random public key is generated. */ constructor(obj?: any); /** Return the underlying point of the public key * @return {Point} The underlying point of the public key. */ getPoint(): Point; /** Returns a random public key. * @returns A new random `PublicKey`. */ static random(): PublicKey; /** Creates a `PublicKey` from a `Point` object. * @param point - The `Point` object to convert. */ static fromPoint(point: Point): PublicKey; /** Creates a `PublicKey` from a `Scalar` object. * @param scalar - The `Scalar` object to convert. */ static fromScalar(scalar: Scalar): PublicKey; /** Generates a nonce from this `PublicKey` using a `Scalar` view key. * * @param viewKey - The view key. * @returns A new `PublicKey` that represents the nonce. */ generateNonce(viewKey: Scalar): PublicKey; /** Returns if the provied public key is equal to this public key. * @param other - The public key to compare with. * @returns `true` if the public keys are equal, `false` otherwise. */ equals(other: PublicKey): boolean; value(): any; serialize(): string; /** Deserializes a hexadecimal string into a `PublicKey` instance. * @param hex - The hexadecimal string to convert. * @returns The `PublicKey` instance represented by the input string. */ static deserialize(this: new (obj: any) => PublicKey, hex: string): PublicKey; }