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.

46 lines (45 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DoublePublicKey = void 0; const blsct_1 = require("../blsct"); const managedObj_1 = require("../managedObj"); const publicKey_1 = require("./publicKey"); class DoublePublicKey extends managedObj_1.ManagedObj { constructor(obj) { if (typeof obj === 'object') { super(obj); } else { const pk1 = publicKey_1.PublicKey.random(); const pk2 = publicKey_1.PublicKey.random(); const dpk = DoublePublicKey.fromPublicKeys(pk1, pk2); super(dpk.move()); } } // TODO add equals, getPk1 and getPk2 methods in libblsct static random() { const pk1 = publicKey_1.PublicKey.random(); const pk2 = publicKey_1.PublicKey.random(); return DoublePublicKey.fromPublicKeys(pk1, pk2); } static fromPublicKeys(pk1, pk2) { const rv = (0, blsct_1.genDoublePubKey)(pk1.value(), pk2.value()); const dpk = DoublePublicKey.fromObj(rv.value); (0, blsct_1.freeObj)(rv); return dpk; } static fromKeysAndAcctAddr(viewKey, spendingPubKey, account, address) { const obj = (0, blsct_1.genDpkWithKeysAndSubAddrId)(viewKey.value(), spendingPubKey.value(), account, address); return DoublePublicKey.fromObj(obj); } value() { return (0, blsct_1.castToDpk)(this.obj); } serialize() { return (0, blsct_1.serializeDpk)(this.value()); } static deserialize(hex) { return DoublePublicKey._deserialize(hex, blsct_1.deserializeDpk); } } exports.DoublePublicKey = DoublePublicKey;