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.

57 lines (56 loc) 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChildKey = void 0; const blsct_1 = require("../blsct"); const scalar_1 = require("../scalar"); const txKey_1 = require("./txKey"); /** Represents a child key. A child key is a Scalar and introduces no new functionality; it serves purely as a semantic alias. BlindingKey, TokenKey and TxKey are exclusively derived from a ChildKey. * * Examples: * ```ts * const { Scalar, ChildKey } = require('navio-blsct') * const s = Scalar.random() * const ck = new ChildKey(s) * ck.toBlindingKey() * ck.toTokenKey() * ck.toTxKey() * ``` */ class ChildKey extends scalar_1.Scalar { /** * Creates a new `ChildKey` derived from the given `Scalar`. * * @param obj - The `Scalar` to derive the `ChildKey` from. */ constructor(obj) { if (obj === undefined || obj === null) { super(obj); } else { const childKeyObj = (0, blsct_1.fromSeedToChildKey)(obj.value()); super(childKeyObj); } } /** Derives a ChildKey from a Scalar. * @returns A new ChildKey instance derived from the provided Scalar. */ toBlindingKey() { const obj = (0, blsct_1.fromChildKeyToBlindingKey)(this.value()); return scalar_1.Scalar.fromObj(obj); } /** Derives a TokenKey from a ChildKey. * @returns A new TokenKey instance derived from the ChildKey. */ toTokenKey() { const obj = (0, blsct_1.fromChildKeyToTokenKey)(this.value()); return scalar_1.Scalar.fromObj(obj); } /** Derives a TxKey from a ChildKey. * @returns A new TxKey instance derived from the ChildKey. */ toTxKey() { const obj = (0, blsct_1.fromChildKeyToTxKey)(this.value()); return txKey_1.TxKey.fromObj(obj); } } exports.ChildKey = ChildKey;