@0xpolygonid/js-sdk 1.11.1 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -576,7 +576,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
576
576
|
|
|
577
577
|
var commonjsGlobal$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
578
578
|
|
|
579
|
-
function getDefaultExportFromCjs
|
|
579
|
+
function getDefaultExportFromCjs (x) {
|
|
580
580
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
581
581
|
}
|
|
582
582
|
|
|
@@ -1701,7 +1701,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
1701
1701
|
} (pubsub, pubsub.exports));
|
|
1702
1702
|
|
|
1703
1703
|
var pubsubExports = pubsub.exports;
|
|
1704
|
-
var PubSub = /*@__PURE__*/getDefaultExportFromCjs
|
|
1704
|
+
var PubSub = /*@__PURE__*/getDefaultExportFromCjs(pubsubExports);
|
|
1705
1705
|
|
|
1706
1706
|
const SDK_EVENTS = {
|
|
1707
1707
|
TX_RECEIPT_ACCEPTED: 'TX_RECEIPT_ACCEPTED'
|
|
@@ -28082,7 +28082,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
28082
28082
|
} (ajv, ajv.exports));
|
|
28083
28083
|
|
|
28084
28084
|
var ajvExports = ajv.exports;
|
|
28085
|
-
var Ajv = /*@__PURE__*/getDefaultExportFromCjs
|
|
28085
|
+
var Ajv = /*@__PURE__*/getDefaultExportFromCjs(ajvExports);
|
|
28086
28086
|
|
|
28087
28087
|
var _2020 = {exports: {}};
|
|
28088
28088
|
|
|
@@ -29011,7 +29011,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
29011
29011
|
} (_2020, _2020.exports));
|
|
29012
29012
|
|
|
29013
29013
|
var _2020Exports = _2020.exports;
|
|
29014
|
-
var Ajv2020 = /*@__PURE__*/getDefaultExportFromCjs
|
|
29014
|
+
var Ajv2020 = /*@__PURE__*/getDefaultExportFromCjs(_2020Exports);
|
|
29015
29015
|
|
|
29016
29016
|
var _2019 = {exports: {}};
|
|
29017
29017
|
|
|
@@ -29590,7 +29590,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
29590
29590
|
} (_2019, _2019.exports));
|
|
29591
29591
|
|
|
29592
29592
|
var _2019Exports = _2019.exports;
|
|
29593
|
-
var Ajv2019 = /*@__PURE__*/getDefaultExportFromCjs
|
|
29593
|
+
var Ajv2019 = /*@__PURE__*/getDefaultExportFromCjs(_2019Exports);
|
|
29594
29594
|
|
|
29595
29595
|
var dist = {exports: {}};
|
|
29596
29596
|
|
|
@@ -29883,7 +29883,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
29883
29883
|
} (dist, dist.exports));
|
|
29884
29884
|
|
|
29885
29885
|
var distExports = dist.exports;
|
|
29886
|
-
var addFormats = /*@__PURE__*/getDefaultExportFromCjs
|
|
29886
|
+
var addFormats = /*@__PURE__*/getDefaultExportFromCjs(distExports);
|
|
29887
29887
|
|
|
29888
29888
|
// or ESM/TypeScript import
|
|
29889
29889
|
const defaultOpts = { verbose: true, strict: false };
|
|
@@ -55725,10 +55725,6 @@ var PolygonIdSdk = (function (exports) {
|
|
|
55725
55725
|
}
|
|
55726
55726
|
}
|
|
55727
55727
|
|
|
55728
|
-
function getDefaultExportFromCjs (x) {
|
|
55729
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
55730
|
-
}
|
|
55731
|
-
|
|
55732
55728
|
var utils$6 = {};
|
|
55733
55729
|
|
|
55734
55730
|
/*
|
|
@@ -68614,26 +68610,6 @@ var PolygonIdSdk = (function (exports) {
|
|
|
68614
68610
|
return runTask;
|
|
68615
68611
|
}
|
|
68616
68612
|
|
|
68617
|
-
/**
|
|
68618
|
-
* Copyright 2020 Google LLC
|
|
68619
|
-
*
|
|
68620
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
68621
|
-
* you may not use this file except in compliance with the License.
|
|
68622
|
-
* You may obtain a copy of the License at
|
|
68623
|
-
*
|
|
68624
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
68625
|
-
*
|
|
68626
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
68627
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
68628
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
68629
|
-
* See the License for the specific language governing permissions and
|
|
68630
|
-
* limitations under the License.
|
|
68631
|
-
*/
|
|
68632
|
-
|
|
68633
|
-
var browser$1 = Worker;
|
|
68634
|
-
|
|
68635
|
-
var Worker$1 = /*@__PURE__*/getDefaultExportFromCjs(browser$1);
|
|
68636
|
-
|
|
68637
68613
|
/*
|
|
68638
68614
|
Copyright 2019 0KIMS association.
|
|
68639
68615
|
|
|
@@ -68669,15 +68645,19 @@ var PolygonIdSdk = (function (exports) {
|
|
|
68669
68645
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
68670
68646
|
}
|
|
68671
68647
|
|
|
68672
|
-
|
|
68673
|
-
|
|
68674
|
-
return
|
|
68648
|
+
let workerSource;
|
|
68649
|
+
|
|
68650
|
+
const threadStr = `(${"function thread(self) {\n const MAXMEM = 32767;\n let instance;\n let memory;\n\n if (self) {\n self.onmessage = function(e) {\n let data;\n if (e.data) {\n data = e.data;\n } else {\n data = e;\n }\n\n if (data[0].cmd == \"INIT\") {\n init(data[0]).then(function() {\n self.postMessage(data.result);\n });\n } else if (data[0].cmd == \"TERMINATE\") {\n self.close();\n } else {\n const res = runTask(data);\n self.postMessage(res);\n }\n };\n }\n\n async function init(data) {\n const code = new Uint8Array(data.code);\n const wasmModule = await WebAssembly.compile(code);\n memory = new WebAssembly.Memory({initial:data.init, maximum: MAXMEM});\n\n instance = await WebAssembly.instantiate(wasmModule, {\n env: {\n \"memory\": memory\n }\n });\n }\n\n\n\n function alloc(length) {\n const u32 = new Uint32Array(memory.buffer, 0, 1);\n while (u32[0] & 3) u32[0]++; // Return always aligned pointers\n const res = u32[0];\n u32[0] += length;\n if (u32[0] + length > memory.buffer.byteLength) {\n const currentPages = memory.buffer.byteLength / 0x10000;\n let requiredPages = Math.floor((u32[0] + length) / 0x10000)+1;\n if (requiredPages>MAXMEM) requiredPages=MAXMEM;\n memory.grow(requiredPages-currentPages);\n }\n return res;\n }\n\n function allocBuffer(buffer) {\n const p = alloc(buffer.byteLength);\n setBuffer(p, buffer);\n return p;\n }\n\n function getBuffer(pointer, length) {\n const u8 = new Uint8Array(memory.buffer);\n return new Uint8Array(u8.buffer, u8.byteOffset + pointer, length);\n }\n\n function setBuffer(pointer, buffer) {\n const u8 = new Uint8Array(memory.buffer);\n u8.set(new Uint8Array(buffer), pointer);\n }\n\n function runTask(task) {\n if (task[0].cmd == \"INIT\") {\n return init(task[0]);\n }\n const ctx = {\n vars: [],\n out: []\n };\n const u32a = new Uint32Array(memory.buffer, 0, 1);\n const oldAlloc = u32a[0];\n for (let i=0; i<task.length; i++) {\n switch (task[i].cmd) {\n case \"ALLOCSET\":\n ctx.vars[task[i].var] = allocBuffer(task[i].buff);\n break;\n case \"ALLOC\":\n ctx.vars[task[i].var] = alloc(task[i].len);\n break;\n case \"SET\":\n setBuffer(ctx.vars[task[i].var], task[i].buff);\n break;\n case \"CALL\": {\n const params = [];\n for (let j=0; j<task[i].params.length; j++) {\n const p = task[i].params[j];\n if (typeof p.var !== \"undefined\") {\n params.push(ctx.vars[p.var] + (p.offset || 0));\n } else if (typeof p.val != \"undefined\") {\n params.push(p.val);\n }\n }\n instance.exports[task[i].fnName](...params);\n break;\n }\n case \"GET\":\n ctx.out[task[i].out] = getBuffer(ctx.vars[task[i].var], task[i].len).slice();\n break;\n default:\n throw new Error(\"Invalid cmd\");\n }\n }\n const u32b = new Uint32Array(memory.buffer, 0, 1);\n u32b[0] = oldAlloc;\n return ctx.out;\n }\n\n\n return runTask;\n}"})(self)`;
|
|
68651
|
+
{
|
|
68652
|
+
if(globalThis?.Blob) {
|
|
68653
|
+
const threadBytes= new TextEncoder().encode(threadStr);
|
|
68654
|
+
const workerBlob = new Blob([threadBytes], { type: "application/javascript" }) ;
|
|
68655
|
+
workerSource = URL.createObjectURL(workerBlob);
|
|
68656
|
+
} else {
|
|
68657
|
+
workerSource = "data:application/javascript;base64," + globalThis.btoa(threadStr);
|
|
68675
68658
|
}
|
|
68676
68659
|
}
|
|
68677
68660
|
|
|
68678
|
-
const threadSource = stringToBase64("(" + "function thread(self) {\n const MAXMEM = 32767;\n let instance;\n let memory;\n\n if (self) {\n self.onmessage = function(e) {\n let data;\n if (e.data) {\n data = e.data;\n } else {\n data = e;\n }\n\n if (data[0].cmd == \"INIT\") {\n init(data[0]).then(function() {\n self.postMessage(data.result);\n });\n } else if (data[0].cmd == \"TERMINATE\") {\n self.close();\n } else {\n const res = runTask(data);\n self.postMessage(res);\n }\n };\n }\n\n async function init(data) {\n const code = new Uint8Array(data.code);\n const wasmModule = await WebAssembly.compile(code);\n memory = new WebAssembly.Memory({initial:data.init, maximum: MAXMEM});\n\n instance = await WebAssembly.instantiate(wasmModule, {\n env: {\n \"memory\": memory\n }\n });\n }\n\n\n\n function alloc(length) {\n const u32 = new Uint32Array(memory.buffer, 0, 1);\n while (u32[0] & 3) u32[0]++; // Return always aligned pointers\n const res = u32[0];\n u32[0] += length;\n if (u32[0] + length > memory.buffer.byteLength) {\n const currentPages = memory.buffer.byteLength / 0x10000;\n let requiredPages = Math.floor((u32[0] + length) / 0x10000)+1;\n if (requiredPages>MAXMEM) requiredPages=MAXMEM;\n memory.grow(requiredPages-currentPages);\n }\n return res;\n }\n\n function allocBuffer(buffer) {\n const p = alloc(buffer.byteLength);\n setBuffer(p, buffer);\n return p;\n }\n\n function getBuffer(pointer, length) {\n const u8 = new Uint8Array(memory.buffer);\n return new Uint8Array(u8.buffer, u8.byteOffset + pointer, length);\n }\n\n function setBuffer(pointer, buffer) {\n const u8 = new Uint8Array(memory.buffer);\n u8.set(new Uint8Array(buffer), pointer);\n }\n\n function runTask(task) {\n if (task[0].cmd == \"INIT\") {\n return init(task[0]);\n }\n const ctx = {\n vars: [],\n out: []\n };\n const u32a = new Uint32Array(memory.buffer, 0, 1);\n const oldAlloc = u32a[0];\n for (let i=0; i<task.length; i++) {\n switch (task[i].cmd) {\n case \"ALLOCSET\":\n ctx.vars[task[i].var] = allocBuffer(task[i].buff);\n break;\n case \"ALLOC\":\n ctx.vars[task[i].var] = alloc(task[i].len);\n break;\n case \"SET\":\n setBuffer(ctx.vars[task[i].var], task[i].buff);\n break;\n case \"CALL\": {\n const params = [];\n for (let j=0; j<task[i].params.length; j++) {\n const p = task[i].params[j];\n if (typeof p.var !== \"undefined\") {\n params.push(ctx.vars[p.var] + (p.offset || 0));\n } else if (typeof p.val != \"undefined\") {\n params.push(p.val);\n }\n }\n instance.exports[task[i].fnName](...params);\n break;\n }\n case \"GET\":\n ctx.out[task[i].out] = getBuffer(ctx.vars[task[i].var], task[i].len).slice();\n break;\n default:\n throw new Error(\"Invalid cmd\");\n }\n }\n const u32b = new Uint32Array(memory.buffer, 0, 1);\n u32b[0] = oldAlloc;\n return ctx.out;\n }\n\n\n return runTask;\n}" + ")(self)");
|
|
68679
|
-
const workerSource = "data:application/javascript;base64," + threadSource;
|
|
68680
|
-
|
|
68681
68661
|
|
|
68682
68662
|
|
|
68683
68663
|
async function buildThreadManager(wasm, singleThread) {
|
|
@@ -68694,7 +68674,11 @@ var PolygonIdSdk = (function (exports) {
|
|
|
68694
68674
|
"memory": tm.memory
|
|
68695
68675
|
}
|
|
68696
68676
|
});
|
|
68697
|
-
|
|
68677
|
+
|
|
68678
|
+
if(!globalThis?.Worker) {
|
|
68679
|
+
singleThread = true;
|
|
68680
|
+
}
|
|
68681
|
+
|
|
68698
68682
|
tm.singleThread = singleThread;
|
|
68699
68683
|
tm.initalPFree = tm.u32[0]; // Save the Pointer to free space.
|
|
68700
68684
|
tm.pq = wasm.pq;
|
|
@@ -68708,7 +68692,6 @@ var PolygonIdSdk = (function (exports) {
|
|
|
68708
68692
|
// tm.pTmp0 = tm.alloc(curve.G2.F.n8*3);
|
|
68709
68693
|
// tm.pTmp1 = tm.alloc(curve.G2.F.n8*3);
|
|
68710
68694
|
|
|
68711
|
-
|
|
68712
68695
|
if (singleThread) {
|
|
68713
68696
|
tm.code = wasm.code;
|
|
68714
68697
|
tm.taskManager = thread();
|
|
@@ -68725,9 +68708,9 @@ var PolygonIdSdk = (function (exports) {
|
|
|
68725
68708
|
|
|
68726
68709
|
let concurrency = 2;
|
|
68727
68710
|
{
|
|
68728
|
-
|
|
68729
|
-
|
|
68730
|
-
|
|
68711
|
+
if (typeof navigator === "object" && navigator.hardwareConcurrency) {
|
|
68712
|
+
concurrency = navigator.hardwareConcurrency;
|
|
68713
|
+
}
|
|
68731
68714
|
}
|
|
68732
68715
|
|
|
68733
68716
|
if(concurrency == 0){
|
|
@@ -68740,7 +68723,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
68740
68723
|
|
|
68741
68724
|
for (let i = 0; i<concurrency; i++) {
|
|
68742
68725
|
|
|
68743
|
-
tm.workers[i] = new Worker
|
|
68726
|
+
tm.workers[i] = new Worker(workerSource);
|
|
68744
68727
|
|
|
68745
68728
|
tm.workers[i].addEventListener("message", getOnMsg(i));
|
|
68746
68729
|
|
|
@@ -73886,6 +73869,13 @@ var PolygonIdSdk = (function (exports) {
|
|
|
73886
73869
|
}
|
|
73887
73870
|
}
|
|
73888
73871
|
|
|
73872
|
+
// Ref https://github.com/iden3/circom/commit/ec6388cf6eb62463539cb4c40cc3ceae9826de19
|
|
73873
|
+
function normalize(n, prime) {
|
|
73874
|
+
let res = BigInt(n) % prime;
|
|
73875
|
+
if (res < 0) res += prime;
|
|
73876
|
+
return res
|
|
73877
|
+
}
|
|
73878
|
+
|
|
73889
73879
|
function fnvHash(str) {
|
|
73890
73880
|
const uint64_max = BigInt(2) ** BigInt(64);
|
|
73891
73881
|
let hash = BigInt("0xCBF29CE484222325");
|
|
@@ -74295,7 +74285,7 @@ var PolygonIdSdk = (function (exports) {
|
|
|
74295
74285
|
this.n32 = this.instance.exports.getFieldNumLen32();
|
|
74296
74286
|
|
|
74297
74287
|
this.instance.exports.getRawPrime();
|
|
74298
|
-
const arr = new
|
|
74288
|
+
const arr = new Uint32Array(this.n32);
|
|
74299
74289
|
for (let i=0; i<this.n32; i++) {
|
|
74300
74290
|
arr[this.n32-1-i] = this.instance.exports.readSharedRWMemory(i);
|
|
74301
74291
|
}
|
|
@@ -74320,18 +74310,32 @@ var PolygonIdSdk = (function (exports) {
|
|
|
74320
74310
|
const hMSB = parseInt(h.slice(0,8), 16);
|
|
74321
74311
|
const hLSB = parseInt(h.slice(8,16), 16);
|
|
74322
74312
|
const fArr = flatArray(input[k]);
|
|
74313
|
+
// Slight deviation from https://github.com/iden3/circom/blob/v2.1.6/code_producers/src/wasm_elements/common/witness_calculator.js
|
|
74314
|
+
// because I don't know when this exported function was added
|
|
74315
|
+
if (typeof this.instance.exports.getInputSignalSize === 'function') {
|
|
74316
|
+
let signalSize = this.instance.exports.getInputSignalSize(hMSB, hLSB);
|
|
74317
|
+
if (signalSize < 0){
|
|
74318
|
+
throw new Error(`Signal ${k} not found\n`);
|
|
74319
|
+
}
|
|
74320
|
+
if (fArr.length < signalSize) {
|
|
74321
|
+
throw new Error(`Not enough values for input signal ${k}\n`);
|
|
74322
|
+
}
|
|
74323
|
+
if (fArr.length > signalSize) {
|
|
74324
|
+
throw new Error(`Too many values for input signal ${k}\n`);
|
|
74325
|
+
}
|
|
74326
|
+
}
|
|
74323
74327
|
for (let i=0; i<fArr.length; i++) {
|
|
74324
|
-
|
|
74325
|
-
|
|
74326
|
-
|
|
74327
|
-
|
|
74328
|
-
|
|
74328
|
+
const arrFr = toArray32(normalize(fArr[i],this.prime),this.n32);
|
|
74329
|
+
for (let j=0; j<this.n32; j++) {
|
|
74330
|
+
this.instance.exports.writeSharedRWMemory(j,arrFr[this.n32-1-j]);
|
|
74331
|
+
}
|
|
74332
|
+
try {
|
|
74329
74333
|
this.instance.exports.setInputSignal(hMSB, hLSB,i);
|
|
74330
|
-
|
|
74331
|
-
|
|
74332
|
-
|
|
74334
|
+
input_counter++;
|
|
74335
|
+
} catch (err) {
|
|
74336
|
+
// console.log(`After adding signal ${i} of ${k}`)
|
|
74333
74337
|
throw new Error(err);
|
|
74334
|
-
|
|
74338
|
+
}
|
|
74335
74339
|
}
|
|
74336
74340
|
|
|
74337
74341
|
});
|