@sabaaa1/common 0.1.1 → 0.1.2
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.
- package/assets/snarkjsWorkerLauncher-CTJxY_k6.js +1176 -0
- package/assets/snarkjsWorkerLogic-BTc2hrlU.js +13660 -0
- package/assets/utxoWorkerLauncher-B6d6svhO.js +1205 -0
- package/assets/{utxoWorkerLauncher-CXiTBW4B.js → utxoWorkerLogic-YPywVy-e.js} +15657 -16806
- package/assets/zkProofWorkerLauncher-CCedBtfh.js +1205 -0
- package/assets/{zkProofWorkerLauncher-bnNs2laX.js → zkProofWorkerLogic-B_sgmDOg.js} +14950 -16099
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +2 -5
- package/data-structures/IndexedDB/activity-db.cjs +1 -1
- package/data-structures/IndexedDB/activity-db.mjs +22 -25
- package/data-structures/IndexedDB/contact-db.cjs +1 -1
- package/data-structures/IndexedDB/contact-db.mjs +21 -24
- package/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
- package/data-structures/TokenDBs/EventsPublicTokensDB.mjs +13 -16
- package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/functions/web3/functionCalls/transactCallRelayer.mjs +2 -5
- package/package.json +1 -1
- package/providers/EthersProviderAdapter.cjs +1 -1
- package/providers/EthersProviderAdapter.mjs +16 -19
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.mjs +2 -5
- package/providers/prepareWagmiHinkal.cjs +1 -1
- package/providers/prepareWagmiHinkal.mjs +2 -5
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.mjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.mjs +38 -6
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.d.ts +0 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.mjs +74 -10
- package/webworker/viteWorkerURL.constant.cjs +1 -1
- package/webworker/viteWorkerURL.constant.d.ts +5 -2
- package/webworker/viteWorkerURL.constant.mjs +2 -2
- package/webworker/workerErrorHandler.d.ts +0 -1
- package/webworker/workerFactory.cjs +1 -1
- package/webworker/workerFactory.d.ts +2 -1
- package/webworker/workerFactory.mjs +35 -25
- package/webworker/workerProxy.cjs +1 -1
- package/webworker/workerProxy.d.ts +11 -1
- package/webworker/workerProxy.mjs +49 -12
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.d.ts +0 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLogic.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLogic.mjs +50 -12
- package/assets/snarkjsWorkerLauncher-ACamUSPf.js +0 -14792
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("../error-handling/error-codes.constants.cjs");require("../data-structures/crypto-keys/keys.cjs");require("libsodium-wrappers");const q=require("../data-structures/Hinkal/Hinkal.cjs");require("../constants/chains.constants.cjs");require("../constants/vite.constants.cjs");require("../
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("../error-handling/error-codes.constants.cjs");require("../data-structures/crypto-keys/keys.cjs");require("libsodium-wrappers");const q=require("../data-structures/Hinkal/Hinkal.cjs");require("../constants/chains.constants.cjs");require("../constants/vite.constants.cjs");require("../types/circom-data.types.cjs");require("node-forge");require("axios");require("../constants/token-data/index.cjs");require("idb-keyval");require("../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../types/transactions.types.cjs");require("../types/activities.types.cjs");require("../constants/server.constants.cjs");require("../API/getServerURL.cjs");require("../constants/reorg-depths.constants.cjs");require("../functions/utils/mutexes.utils.cjs");const t=require("../crypto/preProcessing.cjs");require("../constants/save-depths.cjs");require("../constants/contracts.constants.cjs");require("../constants/kyc.constants.cjs");require("../constants/coingecko.constants.cjs");require("../constants/addresses.constants.cjs");require("../constants/token.limits.constants.cjs");require("../constants/presale.constants.cjs");require("../constants/mystery-boxes.constants.cjs");require("../constants/activity.constants.cjs");require("../constants/tasks.constants.cjs");require("../constants/events.constants.cjs");require("../functions/utils/userAgent.cjs");require("multiformats");require("../API/tenderly.api.cjs");require("ethers-v6h");require("../functions/web3/events/getApprovedBalance.cjs");require("../functions/web3/getTokenHolder.cjs");require("async-mutex");const a=require("./EthersProviderAdapter.cjs"),n=async(i,u)=>{await t.preProcessing();const e=new q.Hinkal(u),r=a.default();return r.initSigner?.(i),await e.initProviderAdapter(void 0,r),await e.initUserKeys(),await e.resetMerkle(),e};exports.prepareEthersHinkal=n;
|
|
@@ -6,9 +6,6 @@ import "libsodium-wrappers";
|
|
|
6
6
|
import { Hinkal as p } from "../data-structures/Hinkal/Hinkal.mjs";
|
|
7
7
|
import "../constants/chains.constants.mjs";
|
|
8
8
|
import "../constants/vite.constants.mjs";
|
|
9
|
-
import "../webworker/snarkjsWorker/snarkjsWorkerLogic.mjs";
|
|
10
|
-
import "../webworker/zkProofWorker/zkProofWorkerLogic.mjs";
|
|
11
|
-
import "../webworker/utxoWorker/utxoWorkerLogic.mjs";
|
|
12
9
|
import "../types/circom-data.types.mjs";
|
|
13
10
|
import "node-forge";
|
|
14
11
|
import "axios";
|
|
@@ -41,11 +38,11 @@ import "../functions/web3/events/getApprovedBalance.mjs";
|
|
|
41
38
|
import "../functions/web3/getTokenHolder.mjs";
|
|
42
39
|
import "async-mutex";
|
|
43
40
|
import e from "./EthersProviderAdapter.mjs";
|
|
44
|
-
const
|
|
41
|
+
const V = async (t, o) => {
|
|
45
42
|
await m();
|
|
46
43
|
const r = new p(o), i = e();
|
|
47
44
|
return i.initSigner?.(t), await r.initProviderAdapter(void 0, i), await r.initUserKeys(), await r.resetMerkle(), r;
|
|
48
45
|
};
|
|
49
46
|
export {
|
|
50
|
-
|
|
47
|
+
V as prepareEthersHinkal
|
|
51
48
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("../error-handling/error-codes.constants.cjs");require("../data-structures/crypto-keys/keys.cjs");require("libsodium-wrappers");const q=require("../data-structures/Hinkal/Hinkal.cjs");require("../constants/chains.constants.cjs");require("../constants/vite.constants.cjs");require("../
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("../error-handling/error-codes.constants.cjs");require("../data-structures/crypto-keys/keys.cjs");require("libsodium-wrappers");const q=require("../data-structures/Hinkal/Hinkal.cjs");require("../constants/chains.constants.cjs");require("../constants/vite.constants.cjs");require("../types/circom-data.types.cjs");require("node-forge");require("axios");require("../constants/token-data/index.cjs");require("idb-keyval");require("../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../types/transactions.types.cjs");require("../types/activities.types.cjs");require("../constants/server.constants.cjs");require("../API/getServerURL.cjs");require("../constants/reorg-depths.constants.cjs");require("../functions/utils/mutexes.utils.cjs");const a=require("../crypto/preProcessing.cjs");require("../constants/save-depths.cjs");require("../constants/contracts.constants.cjs");require("../constants/kyc.constants.cjs");require("../constants/coingecko.constants.cjs");require("../constants/addresses.constants.cjs");require("../constants/token.limits.constants.cjs");require("../constants/presale.constants.cjs");require("../constants/mystery-boxes.constants.cjs");require("../constants/activity.constants.cjs");require("../constants/tasks.constants.cjs");require("../constants/events.constants.cjs");require("../functions/utils/userAgent.cjs");require("multiformats");require("../API/tenderly.api.cjs");require("ethers-v6h");require("../functions/web3/events/getApprovedBalance.cjs");require("../functions/web3/getTokenHolder.cjs");require("async-mutex");const r=require("./WagmiProviderAdapter.cjs"),t=async(i,u)=>{await a.preProcessing();const e=new q.Hinkal;return r.wagmiProviderAdapter.initConfig(u),await e.initProviderAdapter(i,r.wagmiProviderAdapter),await e.initUserKeys(),await e.resetMerkle(),e};exports.prepareWagmiHinkal=t;
|
|
@@ -6,9 +6,6 @@ import "libsodium-wrappers";
|
|
|
6
6
|
import { Hinkal as p } from "../data-structures/Hinkal/Hinkal.mjs";
|
|
7
7
|
import "../constants/chains.constants.mjs";
|
|
8
8
|
import "../constants/vite.constants.mjs";
|
|
9
|
-
import "../webworker/snarkjsWorker/snarkjsWorkerLogic.mjs";
|
|
10
|
-
import "../webworker/zkProofWorker/zkProofWorkerLogic.mjs";
|
|
11
|
-
import "../webworker/utxoWorker/utxoWorkerLogic.mjs";
|
|
12
9
|
import "../types/circom-data.types.mjs";
|
|
13
10
|
import "node-forge";
|
|
14
11
|
import "axios";
|
|
@@ -41,11 +38,11 @@ import "../functions/web3/events/getApprovedBalance.mjs";
|
|
|
41
38
|
import "../functions/web3/getTokenHolder.mjs";
|
|
42
39
|
import "async-mutex";
|
|
43
40
|
import { wagmiProviderAdapter as r } from "./WagmiProviderAdapter.mjs";
|
|
44
|
-
const
|
|
41
|
+
const S = async (t, o) => {
|
|
45
42
|
await m();
|
|
46
43
|
const i = new p();
|
|
47
44
|
return r.initConfig(o), await i.initProviderAdapter(t, r), await i.initUserKeys(), await i.resetMerkle(), i;
|
|
48
45
|
};
|
|
49
46
|
export {
|
|
50
|
-
|
|
47
|
+
S as prepareWagmiHinkal
|
|
51
48
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/snarkjsWorkerLauncher-
|
|
1
|
+
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/snarkjsWorkerLauncher-CTJxY_k6.js").href:new URL("../../assets/snarkjsWorkerLauncher-CTJxY_k6.js",document.currentScript&&document.currentScript.src||document.baseURI).href);module.exports=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M=require("../workerProxy.cjs"),i=require("../../constants/vite.constants.cjs"),O=require("snarkjs"),v=require("axios");function F(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const g=F(O),n=new M.WorkerProxy,c=async e=>{const{data:t}=await v.get(e,{responseType:"arraybuffer"});return new Uint8Array(t)},b=async e=>{try{const{input:t,wasmFilePath:r,zKeyFilePath:s,chainId:w}=e.payload.data,{hostLocation:{origin:l},constants:{isDevelopment:k,chains:{chainIds:P}}}=e.metadata;let a=r,o=s,u,f;const h=a.startsWith("https://");if(i.isNode&&!h){i.isWebpack?(a=`libs/hardhat/test/circuits/${r}`,o=`libs/hardhat/test/circuits/${s}`):!i.isWebpack&&k&&(a=`test/circuits/${r}`,o=`test/circuits/${s}`);const y=require("path");a=y.resolve(a),o=y.resolve(o)}i.isNode&&h?(u=await c(a),f=await c(o)):w===P.localhost&&!i.isNode&&(a=`${l}/${r}`,o=`${l}/${s}`);const{proof:d,publicSignals:p}=await g.groth16.fullProve(t,u??a,f??o),m=await g.groth16.exportSolidityCallData(d,p),$=JSON.parse(`[${m}]`);n.postMessageToMainThread({zkCallData:$,proof:d,publicSignals:p})}catch(t){console.error(t),n.postErrorToMainThread(t)}};n.attachWorkerSideOnMessage(b);exports.default=n;exports.fetchUint8Array=c;exports.onWorkerMessage=b;
|
|
@@ -1,8 +1,40 @@
|
|
|
1
|
-
import { WorkerProxy as
|
|
2
|
-
import "../../constants/vite.constants.mjs";
|
|
3
|
-
import "snarkjs";
|
|
4
|
-
import "axios";
|
|
5
|
-
const
|
|
1
|
+
import { WorkerProxy as b } from "../workerProxy.mjs";
|
|
2
|
+
import { isNode as i, isWebpack as d } from "../../constants/vite.constants.mjs";
|
|
3
|
+
import * as m from "snarkjs";
|
|
4
|
+
import x from "axios";
|
|
5
|
+
const l = new b(), w = async (r) => {
|
|
6
|
+
const { data: e } = await x.get(r, { responseType: "arraybuffer" });
|
|
7
|
+
return new Uint8Array(e);
|
|
8
|
+
}, z = async (r) => {
|
|
9
|
+
try {
|
|
10
|
+
const { input: e, wasmFilePath: s, zKeyFilePath: o, chainId: $ } = r.payload.data, {
|
|
11
|
+
hostLocation: { origin: n },
|
|
12
|
+
constants: {
|
|
13
|
+
isDevelopment: g,
|
|
14
|
+
chains: { chainIds: k }
|
|
15
|
+
}
|
|
16
|
+
} = r.metadata;
|
|
17
|
+
let t = s, a = o, c, h;
|
|
18
|
+
const f = t.startsWith("https://");
|
|
19
|
+
if (i && !f) {
|
|
20
|
+
d ? (t = `libs/hardhat/test/circuits/${s}`, a = `libs/hardhat/test/circuits/${o}`) : !d && g && (t = `test/circuits/${s}`, a = `test/circuits/${o}`);
|
|
21
|
+
const y = require("path");
|
|
22
|
+
t = y.resolve(t), a = y.resolve(a);
|
|
23
|
+
}
|
|
24
|
+
i && f ? (c = await w(t), h = await w(a)) : $ === k.localhost && !i && (t = `${n}/${s}`, a = `${n}/${o}`);
|
|
25
|
+
const { proof: p, publicSignals: u } = await m.groth16.fullProve(
|
|
26
|
+
e,
|
|
27
|
+
c ?? t,
|
|
28
|
+
h ?? a
|
|
29
|
+
), F = await m.groth16.exportSolidityCallData(p, u), P = JSON.parse(`[${F}]`);
|
|
30
|
+
l.postMessageToMainThread({ zkCallData: P, proof: p, publicSignals: u });
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.error(e), l.postErrorToMainThread(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
l.attachWorkerSideOnMessage(z);
|
|
6
36
|
export {
|
|
7
|
-
|
|
37
|
+
l as default,
|
|
38
|
+
w as fetchUint8Array,
|
|
39
|
+
z as onWorkerMessage
|
|
8
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/utxoWorkerLauncher-
|
|
1
|
+
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/utxoWorkerLauncher-B6d6svhO.js").href:new URL("../../assets/utxoWorkerLauncher-B6d6svhO.js",document.currentScript&&document.currentScript.src||document.baseURI).href);module.exports=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("../../crypto/preProcessing.cjs"),a=require("../../data-structures/crypto-keys/keys.cjs"),T=require("../../data-structures/utxo/Utxo.cjs"),h=require("../../data-structures/crypto-keys/encryptDecryptUtxo.cjs"),y=require("../../data-structures/crypto-keys/decodeUTXO.cjs"),k=require("../workerProxy.cjs"),d=require("./utxoWorker.types.cjs"),c=new k.WorkerProxy,p=async({data:e})=>{const{utxos:r,nullifiers:s}=e,o=r.filter(t=>{const u=new T.Utxo(t);return!s.has(u.getNullifier())});c.postMessageToMainThread({utxoConstructors:o,stealthPairCache:a.stealthPairCacheDevice.serialize(),stealthAddressCache:a.stealthAddressCacheDevice.serialize()})},U=async({data:e})=>{const r=new a.UserKeys(e.signature),s=r.getShieldedPrivateKey(),o=e.encryptedOutputs.map(t=>{try{return t.isPositive?h.decryptUtxoConstructorArgs(Buffer.from(t.value.slice(2),"hex"),r):y.decodeUtxoConstructorArgs(t.value,s)}catch{return}}).filter(t=>t!==void 0&&t.amount!==0n);c.postMessageToMainThread(o)},x=async({data:e})=>{const r=new a.UserKeys(e.signature),s=[],{encryptedOutputs:o}=e;let{lastOutput:t}=e;const u=r.getShieldedPrivateKey();for(let l=0;l<o.length;l+=1){const n=o[l];if(t=n.value,n.isPositive)try{const i=h.decryptUtxo(Buffer.from(t.slice(2),"hex"),r);if(!i.erc20TokenAddress||!i.amount||!i.stealthAddress)throw Error("bruh");s.push(n)}catch{}else try{y.checkUtxoSignature(t,u)&&s.push(n)}catch{}}c.postMessageToMainThread({additionalEncryptedOutputs:s,lastOutput:t})},g=async e=>{try{await f.preProcessing();const{type:r}=e.payload;switch(r){case d.UtxoWorkerActionType.BATCH_FILTER_UTXOS_WITH_NULLIFIER:await p(e.payload);return;case d.UtxoWorkerActionType.BUILD_UTXOS:await U(e.payload);return;case d.UtxoWorkerActionType.DECIPHER_OUTPUTS:await x(e.payload);return;default:throw Error(`Unknown worker message type ${r}`)}}catch(r){console.error(r),c.postErrorToMainThread(r)}};c.attachWorkerSideOnMessage(g);exports.default=c;exports.handleBuildUtxosMessage=U;exports.handleDecipherMessage=x;exports.handleFilterUtxosWithNullifier=p;exports.onWorkerMessage=g;
|
|
@@ -1,12 +1,76 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
import "
|
|
7
|
-
import "
|
|
8
|
-
|
|
9
|
-
const
|
|
1
|
+
import { preProcessing as u } from "../../crypto/preProcessing.mjs";
|
|
2
|
+
import { stealthPairCacheDevice as p, stealthAddressCacheDevice as y, UserKeys as h } from "../../data-structures/crypto-keys/keys.mjs";
|
|
3
|
+
import { Utxo as f } from "../../data-structures/utxo/Utxo.mjs";
|
|
4
|
+
import { decryptUtxoConstructorArgs as m, decryptUtxo as g } from "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
|
|
5
|
+
import { decodeUtxoConstructorArgs as x, checkUtxoSignature as U } from "../../data-structures/crypto-keys/decodeUTXO.mjs";
|
|
6
|
+
import { WorkerProxy as T } from "../workerProxy.mjs";
|
|
7
|
+
import { UtxoWorkerActionType as d } from "./utxoWorker.types.mjs";
|
|
8
|
+
const i = new T(), w = async ({ data: e }) => {
|
|
9
|
+
const { utxos: r, nullifiers: s } = e, o = r.filter((t) => {
|
|
10
|
+
const n = new f(t);
|
|
11
|
+
return !s.has(n.getNullifier());
|
|
12
|
+
});
|
|
13
|
+
i.postMessageToMainThread({
|
|
14
|
+
utxoConstructors: o,
|
|
15
|
+
stealthPairCache: p.serialize(),
|
|
16
|
+
stealthAddressCache: y.serialize()
|
|
17
|
+
});
|
|
18
|
+
}, P = async ({ data: e }) => {
|
|
19
|
+
const r = new h(e.signature), s = r.getShieldedPrivateKey(), o = e.encryptedOutputs.map((t) => {
|
|
20
|
+
try {
|
|
21
|
+
return t.isPositive ? m(Buffer.from(t.value.slice(2), "hex"), r) : x(t.value, s);
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
}).filter((t) => t !== void 0 && t.amount !== 0n);
|
|
26
|
+
i.postMessageToMainThread(o);
|
|
27
|
+
}, v = async ({ data: e }) => {
|
|
28
|
+
const r = new h(e.signature), s = [], { encryptedOutputs: o } = e;
|
|
29
|
+
let { lastOutput: t } = e;
|
|
30
|
+
const n = r.getShieldedPrivateKey();
|
|
31
|
+
for (let l = 0; l < o.length; l += 1) {
|
|
32
|
+
const c = o[l];
|
|
33
|
+
if (t = c.value, c.isPositive)
|
|
34
|
+
try {
|
|
35
|
+
const a = g(Buffer.from(t.slice(2), "hex"), r);
|
|
36
|
+
if (!a.erc20TokenAddress || !a.amount || !a.stealthAddress)
|
|
37
|
+
throw Error("bruh");
|
|
38
|
+
s.push(c);
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
try {
|
|
43
|
+
U(t, n) && s.push(c);
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
i.postMessageToMainThread({ additionalEncryptedOutputs: s, lastOutput: t });
|
|
48
|
+
}, k = async (e) => {
|
|
49
|
+
try {
|
|
50
|
+
await u();
|
|
51
|
+
const { type: r } = e.payload;
|
|
52
|
+
switch (r) {
|
|
53
|
+
case d.BATCH_FILTER_UTXOS_WITH_NULLIFIER:
|
|
54
|
+
await w(e.payload);
|
|
55
|
+
return;
|
|
56
|
+
case d.BUILD_UTXOS:
|
|
57
|
+
await P(e.payload);
|
|
58
|
+
return;
|
|
59
|
+
case d.DECIPHER_OUTPUTS:
|
|
60
|
+
await v(e.payload);
|
|
61
|
+
return;
|
|
62
|
+
default:
|
|
63
|
+
throw Error(`Unknown worker message type ${r}`);
|
|
64
|
+
}
|
|
65
|
+
} catch (r) {
|
|
66
|
+
console.error(r), i.postErrorToMainThread(r);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
i.attachWorkerSideOnMessage(k);
|
|
10
70
|
export {
|
|
11
|
-
|
|
71
|
+
i as default,
|
|
72
|
+
P as handleBuildUtxosMessage,
|
|
73
|
+
v as handleDecipherMessage,
|
|
74
|
+
w as handleFilterUtxosWithNullifier,
|
|
75
|
+
k as onWorkerMessage
|
|
12
76
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./zkProofWorker/zkProofWorkerLauncher.cjs"),o=require("./snarkjsWorker/snarkjsWorkerLauncher.cjs"),t=require("./utxoWorker/utxoWorkerLauncher.cjs"),r=require("./worker.registry.cjs"),n=()=>({[r.WorkerVariant.ZKProof]:e,[r.WorkerVariant.SnarkJS]:o,[r.WorkerVariant.UTXO]:t});exports.getWorkerViteURL=n;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./zkProofWorker/zkProofWorkerLauncher.cjs"),o=require("./snarkjsWorker/snarkjsWorkerLauncher.cjs"),t=require("./utxoWorker/utxoWorkerLauncher.cjs"),r=require("./worker.registry.cjs"),n=async()=>({[r.WorkerVariant.ZKProof]:e,[r.WorkerVariant.SnarkJS]:o,[r.WorkerVariant.UTXO]:t});exports.getWorkerViteURL=n;
|
|
@@ -2,5 +2,8 @@
|
|
|
2
2
|
* These imports tell vite to generate and bundle worker file.
|
|
3
3
|
* These are import conditionally because we do not have vite when running on node.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export declare const getWorkerViteURL: () => Promise<{
|
|
6
|
+
ZKProof: any;
|
|
7
|
+
SnarkJS: any;
|
|
8
|
+
UTXO: any;
|
|
9
|
+
}>;
|
|
@@ -2,11 +2,11 @@ import o from "./zkProofWorker/zkProofWorkerLauncher.mjs";
|
|
|
2
2
|
import t from "./snarkjsWorker/snarkjsWorkerLauncher.mjs";
|
|
3
3
|
import e from "./utxoWorker/utxoWorkerLauncher.mjs";
|
|
4
4
|
import { WorkerVariant as r } from "./worker.registry.mjs";
|
|
5
|
-
const
|
|
5
|
+
const a = async () => ({
|
|
6
6
|
[r.ZKProof]: o,
|
|
7
7
|
[r.SnarkJS]: t,
|
|
8
8
|
[r.UTXO]: e
|
|
9
9
|
});
|
|
10
10
|
export {
|
|
11
|
-
|
|
11
|
+
a as getWorkerViteURL
|
|
12
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../constants/vite.constants.cjs"),r=require("./worker.registry.cjs");class t{constructor(){}static resolveWorkerURL=async e=>{const{getWorkerViteURL:s}=await Promise.resolve().then(()=>require("./viteWorkerURL.constant.cjs"));return(await s())[e]};static createWorker=async e=>{if(i.isNode||i.isSandbox){let o;return e===r.WorkerVariant.SnarkJS?o=await Promise.resolve().then(()=>require("./snarkjsWorker/snarkjsWorkerLogic.cjs")):e===r.WorkerVariant.ZKProof?o=await Promise.resolve().then(()=>require("./zkProofWorker/zkProofWorkerLogic.cjs")):e===r.WorkerVariant.UTXO&&(o=await Promise.resolve().then(()=>require("./utxoWorker/utxoWorkerLogic.cjs"))),o.default}const s=await t.resolveWorkerURL(e);return new Worker(s,{type:"module"})};static getWebWorker(e){switch(e){case r.WorkerVariant.ZKProof:return t.createWorker(e);case r.WorkerVariant.SnarkJS:return t.createWorker(e);case r.WorkerVariant.UTXO:return t.createWorker(e);default:throw Error(`Unknown worker type: ${e}`)}}}exports.WorkerFactory=t;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WorkerVariant } from './worker.registry';
|
|
2
2
|
export declare class WorkerFactory {
|
|
3
|
+
private constructor();
|
|
3
4
|
private static resolveWorkerURL;
|
|
4
5
|
private static createWorker;
|
|
5
|
-
static getWebWorker(workerVariant: WorkerVariant):
|
|
6
|
+
static getWebWorker(workerVariant: WorkerVariant): Promise<any>;
|
|
6
7
|
}
|
|
@@ -1,30 +1,40 @@
|
|
|
1
|
-
import { isNode as i, isSandbox as
|
|
2
|
-
import { WorkerVariant as
|
|
3
|
-
import k from "./snarkjsWorker/snarkjsWorkerLogic.mjs";
|
|
4
|
-
import n from "./zkProofWorker/zkProofWorkerLogic.mjs";
|
|
5
|
-
import m from "./utxoWorker/utxoWorkerLogic.mjs";
|
|
6
|
-
import { getWorkerViteURL as c } from "./viteWorkerURL.constant.mjs";
|
|
1
|
+
import { isNode as i, isSandbox as c } from "../constants/vite.constants.mjs";
|
|
2
|
+
import { WorkerVariant as r } from "./worker.registry.mjs";
|
|
7
3
|
class o {
|
|
8
|
-
|
|
9
|
-
return c()[r];
|
|
4
|
+
constructor() {
|
|
10
5
|
}
|
|
11
|
-
static
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
static resolveWorkerURL = async (e) => {
|
|
7
|
+
const { getWorkerViteURL: s } = await import("./viteWorkerURL.constant.mjs");
|
|
8
|
+
return (await s())[e];
|
|
9
|
+
};
|
|
10
|
+
static createWorker = async (e) => {
|
|
11
|
+
if (i || c) {
|
|
12
|
+
let t;
|
|
13
|
+
return e === r.SnarkJS ? t = await import(
|
|
14
|
+
/* @vite-ignore */
|
|
15
|
+
"./snarkjsWorker/snarkjsWorkerLogic.mjs"
|
|
16
|
+
) : e === r.ZKProof ? t = await import(
|
|
17
|
+
/* @vite-ignore */
|
|
18
|
+
"./zkProofWorker/zkProofWorkerLogic.mjs"
|
|
19
|
+
) : e === r.UTXO && (t = await import(
|
|
20
|
+
/* @vite-ignore */
|
|
21
|
+
"./utxoWorker/utxoWorkerLogic.mjs"
|
|
22
|
+
)), t.default;
|
|
23
|
+
}
|
|
24
|
+
const s = await o.resolveWorkerURL(e);
|
|
25
|
+
return new Worker(s, { type: "module" });
|
|
26
|
+
};
|
|
27
|
+
static getWebWorker(e) {
|
|
28
|
+
switch (e) {
|
|
29
|
+
case r.ZKProof:
|
|
30
|
+
return o.createWorker(e);
|
|
31
|
+
case r.SnarkJS:
|
|
32
|
+
return o.createWorker(e);
|
|
33
|
+
case r.UTXO:
|
|
34
|
+
return o.createWorker(e);
|
|
35
|
+
default:
|
|
36
|
+
throw Error(`Unknown worker type: ${e}`);
|
|
37
|
+
}
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class n{isNode=!1;isSandbox=!1;onmessage=null;onerror=null;_eventEmitter;get eventEmitter(){if(this._eventEmitter)return this._eventEmitter;if(this.isNode){const e=require("events");this._eventEmitter=new e}else this._eventEmitter=new EventTarget;return this._eventEmitter}constructor(){this.isNode=typeof process<"u"&&process.versions!=null&&process.versions.node!=null,this.isSandbox=typeof window<"u"&&window.origin==="null"}terminate(){}postMessage(e){this.isNode?this.eventEmitter.emit("message",e):this.isSandbox?this.eventEmitter?.dispatchEvent(new CustomEvent("worker-message",{detail:e})):postMessage(e)}postMessageToMainThread(e){const s={data:e};if(this.onmessage){this.onmessage(s);return}const t=typeof self<"u"?self:globalThis;t.postMessage&&t.postMessage(e)}postErrorToMainThread(e){const s={data:{error:e}};if(this.onerror){this.onerror(s);return}const t={error:!0,message:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0},i=typeof self<"u"?self:globalThis;i.postMessage&&i.postMessage(t)}attachWorkerSideOnMessage(e){if(this.isNode){this.eventEmitter.on("message",t=>{e(t)});return}if(this.isSandbox){this.eventEmitter.addEventListener("worker-message",t=>{e(t.detail)});return}const s=typeof self<"u"?self:globalThis;s.addEventListener&&s.addEventListener("message",t=>{const i=t?.data;i&&e(i)})}}exports.WorkerProxy=n;
|
|
@@ -11,15 +11,25 @@
|
|
|
11
11
|
export declare class WorkerProxy {
|
|
12
12
|
private isNode;
|
|
13
13
|
private isSandbox;
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* This allow browser or main thread to listen for worker response message
|
|
16
|
+
* using the normal `worker.onmessage = () => {}` syntax. Is should only be side on the
|
|
17
|
+
* main thread side, not on worker side.
|
|
18
|
+
*/
|
|
15
19
|
onmessage: ((e: {
|
|
16
20
|
data: any;
|
|
17
21
|
}) => void) | null;
|
|
22
|
+
/**
|
|
23
|
+
* This allow browser or main thread to listen for worker response message
|
|
24
|
+
* using the normal `worker.onerror = () => {}` syntax. Is should only be side on the
|
|
25
|
+
* main thread side, not on worker side.
|
|
26
|
+
*/
|
|
18
27
|
onerror: ((e: {
|
|
19
28
|
data: {
|
|
20
29
|
error: unknown;
|
|
21
30
|
};
|
|
22
31
|
}) => void) | null;
|
|
32
|
+
private _eventEmitter;
|
|
23
33
|
private get eventEmitter();
|
|
24
34
|
constructor();
|
|
25
35
|
terminate(): void;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
class
|
|
1
|
+
class o {
|
|
2
2
|
isNode = !1;
|
|
3
3
|
isSandbox = !1;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This allow browser or main thread to listen for worker response message
|
|
6
|
+
* using the normal `worker.onmessage = () => {}` syntax. Is should only be side on the
|
|
7
|
+
* main thread side, not on worker side.
|
|
8
|
+
*/
|
|
5
9
|
onmessage = null;
|
|
10
|
+
/**
|
|
11
|
+
* This allow browser or main thread to listen for worker response message
|
|
12
|
+
* using the normal `worker.onerror = () => {}` syntax. Is should only be side on the
|
|
13
|
+
* main thread side, not on worker side.
|
|
14
|
+
*/
|
|
6
15
|
onerror = null;
|
|
16
|
+
_eventEmitter;
|
|
17
|
+
// node EventEmitter
|
|
7
18
|
get eventEmitter() {
|
|
8
19
|
if (this._eventEmitter)
|
|
9
20
|
return this._eventEmitter;
|
|
@@ -20,24 +31,50 @@ class i {
|
|
|
20
31
|
terminate() {
|
|
21
32
|
}
|
|
22
33
|
postMessage(e) {
|
|
23
|
-
this.isNode ? this.eventEmitter.emit("message", e) : this.isSandbox ? this.eventEmitter
|
|
34
|
+
this.isNode ? this.eventEmitter.emit("message", e) : this.isSandbox ? this.eventEmitter?.dispatchEvent(new CustomEvent("worker-message", { detail: e })) : postMessage(e);
|
|
24
35
|
}
|
|
25
36
|
postMessageToMainThread(e) {
|
|
26
|
-
const
|
|
27
|
-
|
|
37
|
+
const s = { data: e };
|
|
38
|
+
if (this.onmessage) {
|
|
39
|
+
this.onmessage(s);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const t = typeof self < "u" ? self : globalThis;
|
|
43
|
+
t.postMessage && t.postMessage(e);
|
|
28
44
|
}
|
|
29
45
|
postErrorToMainThread(e) {
|
|
30
|
-
const
|
|
31
|
-
|
|
46
|
+
const s = { data: { error: e } };
|
|
47
|
+
if (this.onerror) {
|
|
48
|
+
this.onerror(s);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const t = {
|
|
52
|
+
error: !0,
|
|
53
|
+
message: e instanceof Error ? e.message : String(e),
|
|
54
|
+
stack: e instanceof Error ? e.stack : void 0
|
|
55
|
+
}, i = typeof self < "u" ? self : globalThis;
|
|
56
|
+
i.postMessage && i.postMessage(t);
|
|
32
57
|
}
|
|
33
58
|
attachWorkerSideOnMessage(e) {
|
|
34
|
-
this.isNode
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
if (this.isNode) {
|
|
60
|
+
this.eventEmitter.on("message", (t) => {
|
|
61
|
+
e(t);
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (this.isSandbox) {
|
|
66
|
+
this.eventEmitter.addEventListener("worker-message", (t) => {
|
|
67
|
+
e(t.detail);
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const s = typeof self < "u" ? self : globalThis;
|
|
72
|
+
s.addEventListener && s.addEventListener("message", (t) => {
|
|
73
|
+
const i = t?.data;
|
|
74
|
+
i && e(i);
|
|
38
75
|
});
|
|
39
76
|
}
|
|
40
77
|
}
|
|
41
78
|
export {
|
|
42
|
-
|
|
79
|
+
o as WorkerProxy
|
|
43
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/zkProofWorkerLauncher-
|
|
1
|
+
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/zkProofWorkerLauncher-CCedBtfh.js").href:new URL("../../assets/zkProofWorkerLauncher-CCedBtfh.js",document.currentScript&&document.currentScript.src||document.baseURI).href);module.exports=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const y=require("../../crypto/preProcessing.cjs"),A=require("../../data-structures/crypto-keys/keys.cjs"),S=require("../../data-structures/utxo/Utxo.cjs"),m=require("../../functions/snarkjs/common.snarkjs.cjs"),C=require("../workerProxy.cjs"),d=require("./zkProofWorker.types.cjs"),u=require("../../functions/utils/merkleTree.utils.cjs"),t=new C.WorkerProxy,p=r=>{const{inputUtxosSerialized:e,merkleTreeSerialized:a}=r.data,c=u.contructMerkleTreeFromSerialized(a),i=e.map(n=>n.map(l=>new S.Utxo(l))),{inCommitmentSiblings:s,inCommitmentSiblingSides:o}=m.calcCommitmentsSiblingAndSides(i,c);t.postMessageToMainThread({inCommitmentSiblings:s,inCommitmentSiblingSides:o})},k=r=>{const{userSignature:e,merkleTreeAccessTokenSerialized:a}=r.data,c=new A.UserKeys(e),i=u.contructMerkleTreeFromSerialized(a),{accessTokenSiblings:s,accessTokenSiblingSides:o}=m.calcAccessTokenSiblingsAndSides(c,i);t.postMessageToMainThread({accessTokenSiblings:s,accessTokenSiblingSides:o})},T=r=>{const{inputUtxosSerialized:e,onChainCreation:a,proverVersion:c}=r.data,i=e.map(o=>o.map(n=>new S.Utxo(n)));let s=[];c==="v1x0"?s=i.map((o,n)=>o.map(l=>a[n]?"0":l.getNullifier())):s=i.map(o=>o.map(n=>n.amount===0n?"0":n.getNullifier())),t.postMessageToMainThread(s)},g=async r=>{try{await y.preProcessing();const{type:e}=r.payload;switch(e){case d.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES:p(r.payload);return;case d.ZKProofWorkerActionType.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES:k(r.payload);return;case d.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS:T(r.payload);return;default:throw Error(`Unknown worker message type ${e}`)}}catch(e){console.error(e),t.postErrorToMainThread(e)}};t.attachWorkerSideOnMessage(g);exports.default=t;exports.handleBuildInNullifiers=T;exports.handleCalcAccessTokenSiblingAndSides=k;exports.handleCalcCommitmentsSiblingAndSides=p;exports.onWorkerMessage=g;
|
|
@@ -1,14 +1,52 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
import "
|
|
7
|
-
import "../../
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { preProcessing as d } from "../../crypto/preProcessing.mjs";
|
|
2
|
+
import { UserKeys as T } from "../../data-structures/crypto-keys/keys.mjs";
|
|
3
|
+
import { Utxo as p } from "../../data-structures/utxo/Utxo.mjs";
|
|
4
|
+
import { calcCommitmentsSiblingAndSides as g, calcAccessTokenSiblingsAndSides as u } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
5
|
+
import { WorkerProxy as k } from "../workerProxy.mjs";
|
|
6
|
+
import { ZKProofWorkerActionType as m } from "./zkProofWorker.types.mjs";
|
|
7
|
+
import { contructMerkleTreeFromSerialized as S } from "../../functions/utils/merkleTree.utils.mjs";
|
|
8
|
+
const c = new k(), C = (r) => {
|
|
9
|
+
const { inputUtxosSerialized: e, merkleTreeSerialized: t } = r.data, a = S(t), i = e.map(
|
|
10
|
+
(n) => n.map((l) => new p(l))
|
|
11
|
+
), { inCommitmentSiblings: s, inCommitmentSiblingSides: o } = g(i, a);
|
|
12
|
+
c.postMessageToMainThread({ inCommitmentSiblings: s, inCommitmentSiblingSides: o });
|
|
13
|
+
}, f = (r) => {
|
|
14
|
+
const { userSignature: e, merkleTreeAccessTokenSerialized: t } = r.data, a = new T(e), i = S(t), { accessTokenSiblings: s, accessTokenSiblingSides: o } = u(a, i);
|
|
15
|
+
c.postMessageToMainThread({ accessTokenSiblings: s, accessTokenSiblingSides: o });
|
|
16
|
+
}, y = (r) => {
|
|
17
|
+
const { inputUtxosSerialized: e, onChainCreation: t, proverVersion: a } = r.data, i = e.map(
|
|
18
|
+
(o) => o.map((n) => new p(n))
|
|
19
|
+
);
|
|
20
|
+
let s = [];
|
|
21
|
+
a === "v1x0" ? s = i.map(
|
|
22
|
+
(o, n) => o.map((l) => t[n] ? "0" : l.getNullifier())
|
|
23
|
+
) : s = i.map((o) => o.map((n) => n.amount === 0n ? "0" : n.getNullifier())), c.postMessageToMainThread(s);
|
|
24
|
+
}, A = async (r) => {
|
|
25
|
+
try {
|
|
26
|
+
await d();
|
|
27
|
+
const { type: e } = r.payload;
|
|
28
|
+
switch (e) {
|
|
29
|
+
case m.CALC_COMMITMENTS_SIBLING_AND_SIDES:
|
|
30
|
+
C(r.payload);
|
|
31
|
+
return;
|
|
32
|
+
case m.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES:
|
|
33
|
+
f(r.payload);
|
|
34
|
+
return;
|
|
35
|
+
case m.BUILD_IN_NULLIFIERS:
|
|
36
|
+
y(r.payload);
|
|
37
|
+
return;
|
|
38
|
+
default:
|
|
39
|
+
throw Error(`Unknown worker message type ${e}`);
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error(e), c.postErrorToMainThread(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
c.attachWorkerSideOnMessage(A);
|
|
12
46
|
export {
|
|
13
|
-
|
|
47
|
+
c as default,
|
|
48
|
+
y as handleBuildInNullifiers,
|
|
49
|
+
f as handleCalcAccessTokenSiblingAndSides,
|
|
50
|
+
C as handleCalcCommitmentsSiblingAndSides,
|
|
51
|
+
A as onWorkerMessage
|
|
14
52
|
};
|