Comparing version 1.5.0 to 1.6.0
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -211,3 +202,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const s = exports.mod.g_ptr[pos]; | ||
if (s == 0) { | ||
if (s === 0) { | ||
console.log(`ERR ${pos}`); | ||
@@ -236,4 +227,4 @@ } | ||
exports._showDebug = _showDebug; | ||
const initializeMcl = (curveType = constants_1.CurveType.BN254) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.mod = yield createModule({ | ||
const initializeMcl = async (curveType = constants_1.CurveType.BN254) => { | ||
exports.mod = await createModule({ | ||
cryptoGetRandomValues: (p, n) => { | ||
@@ -252,3 +243,3 @@ const a = new Uint8Array(n); | ||
throw new Error(`_mclBn_init err ${r}`); | ||
}); | ||
}; | ||
exports.initializeMcl = initializeMcl; |
@@ -173,3 +173,5 @@ declare abstract class Common { | ||
export declare const hashAndMapToG2: (s: string | Uint8Array) => G2; | ||
export declare const pow: (x: GT, y: Fr) => GT; | ||
export declare function pow(x: Fr, y: Fr | Number | BigInt): Fr; | ||
export declare function pow(x: Fp, y: Fp | Number | BigInt): Fp; | ||
export declare function pow(x: GT, y: Fr): GT; | ||
export declare const pairing: (P: G1, Q: G2) => GT; | ||
@@ -176,0 +178,0 @@ export declare const millerLoop: (P: G1, Q: G2) => GT; |
@@ -693,4 +693,2 @@ "use strict"; | ||
const n = xVec.length; | ||
const xSize = xVec[0].a_.length; | ||
const ySize = yVec[0].a_.length; | ||
const z = new Cstr(); | ||
@@ -771,3 +769,48 @@ const stack = mcl_1.mod.stackSave(); | ||
exports.hashAndMapToG2 = hashAndMapToG2; | ||
const pow = (x, y) => { | ||
const IntToArray = (_x) => { | ||
let x = typeof _x === 'number' ? BigInt(_x) : _x; | ||
if (x < 0n) { | ||
throw new Error('IntToArray: negative value'); | ||
} | ||
if (x === 0n) | ||
return new Uint8Array(1); | ||
const a = []; | ||
while (x) { | ||
a.push(Number(BigInt.asUintN(8, x))); | ||
x >>= 8n; | ||
} | ||
return new Uint8Array(a); | ||
}; | ||
const powArray = (cstr, powArray, x, _y) => { | ||
const y = IntToArray(_y.valueOf()); | ||
const z = new cstr(); | ||
const stack = mcl_1.mod.stackSave(); | ||
const zPos = z._salloc(); | ||
const xPos = x._sallocAndCopy(); | ||
const yPos = mcl_1.mod.stackAlloc(y.length); | ||
mcl_1.mod.HEAP8.set(y, yPos); | ||
const r = powArray(zPos, xPos, yPos, y.length); | ||
z._save(zPos); | ||
mcl_1.mod.stackRestore(stack); | ||
if (r < 0) | ||
throw new Error('powArray err'); | ||
return z; | ||
}; | ||
function pow(x, y) { | ||
if (x instanceof Fr) { | ||
if (y instanceof Fr) { | ||
return x._op2(mcl_1.mod._mclBnFr_pow, y); | ||
} | ||
else if (typeof (y) === 'number' || typeof (y) === 'bigint') { | ||
return powArray(Fr, mcl_1.mod._mclBnFr_powArray, x, y); | ||
} | ||
} | ||
if (x instanceof Fp) { | ||
if (y instanceof Fp) { | ||
return x._op2(mcl_1.mod._mclBnFp_pow, y); | ||
} | ||
else if (typeof (y) === 'number' || typeof (y) === 'bigint') { | ||
return powArray(Fp, mcl_1.mod._mclBnFp_powArray, x, y); | ||
} | ||
} | ||
if (x instanceof GT && y instanceof Fr) { | ||
@@ -777,3 +820,3 @@ return x._op2(mcl_1.mod._mclBnGT_pow, y); | ||
throw new Error('pow:bad type'); | ||
}; | ||
} | ||
exports.pow = pow; | ||
@@ -780,0 +823,0 @@ const pairing = (P, Q) => { |
{ | ||
"name": "mcl-wasm", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "mcl ; A portable and fast pairing-based cryptography library for Node.js by WebAssembly", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1371605
4639
1