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.
54 lines (53 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PublicKey = void 0;
const blsct_1 = require("../blsct");
const managedObj_1 = require("../managedObj");
const point_1 = require("../point");
class PublicKey extends managedObj_1.ManagedObj {
constructor(obj) {
if (typeof obj === 'object') {
super(obj);
}
else {
const rv = (0, blsct_1.genRandomPublicKey)();
super(rv.value);
}
}
getPoint() {
const blsctPoint = (0, blsct_1.getPublicKeyPoint)(this.value());
return point_1.Point.fromObj(blsctPoint);
}
static random() {
const rv = (0, blsct_1.genRandomPublicKey)();
const pk = PublicKey.fromObj(rv.value);
(0, blsct_1.freeObj)(rv);
return pk;
}
static fromPoint(point) {
const blsctPubKey = (0, blsct_1.pointToPublicKey)(point.value());
return PublicKey.fromObj(blsctPubKey);
}
static fromScalar(scalar) {
const blsctPubKey = (0, blsct_1.scalarToPubKey)(scalar.value());
return PublicKey.fromObj(blsctPubKey);
}
static generateNonce(blindingPubKey, viewKey) {
const blsctNonce = (0, blsct_1.calcNonce)(blindingPubKey.value(), viewKey.value());
return PublicKey.fromObj(blsctNonce);
}
equals(other) {
return this.getPoint().equals(other.getPoint());
}
value() {
return (0, blsct_1.castToPubKey)(this.obj);
}
serialize() {
return this.getPoint().serialize();
}
static deserialize(hex) {
const p = point_1.Point.deserialize(hex);
return PublicKey.fromPoint(p);
}
}
exports.PublicKey = PublicKey;