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.
51 lines (50 loc) • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Point = void 0;
const blsct_1 = require("./blsct");
const managedObj_1 = require("./managedObj");
class Point extends managedObj_1.ManagedObj {
constructor(obj) {
if (typeof obj === 'object') {
super(obj);
}
else
(super((0, blsct_1.genRandomPoint)().value));
}
value() {
return (0, blsct_1.castToPoint)(this.obj);
}
static random() {
const rv = (0, blsct_1.genRandomPoint)();
const x = Point.fromObj(rv.value);
(0, blsct_1.freeObj)(rv);
return x;
}
static base() {
const rv = (0, blsct_1.genBasePoint)();
const x = Point.fromObj(rv.value);
(0, blsct_1.freeObj)(rv);
return x;
}
static fromScalar(scalar) {
const obj = (0, blsct_1.pointFromScalar)(scalar.value());
return Point.fromObj(obj);
}
isValid() {
return (0, blsct_1.isValidPoint)(this.value());
}
toString() {
const s = (0, blsct_1.pointToStr)(this.value());
return `Point(${s})`;
}
equals(other) {
return (0, blsct_1.isPointEqual)(this.value(), other.value());
}
serialize() {
return (0, blsct_1.serializePoint)(this.value());
}
static deserialize(hex) {
return Point._deserialize(hex, blsct_1.deserializePoint);
}
}
exports.Point = Point;