h_test_1 0.0.21 → 0.0.23
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/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/functions/snarkjs/constructGeneralZkProof.mjs +84 -82
- package/functions/snarkjs/generateZkProof.cjs +1 -1
- package/functions/snarkjs/generateZkProof.mjs +9 -9
- package/functions/snarkjs/generateZkProofSelf.cjs +1 -1
- package/functions/snarkjs/generateZkProofSelf.mjs +12 -10
- package/functions/snarkjs/getMerkleTreeSiblingsAndRootHashes.cjs +1 -1
- package/functions/snarkjs/getMerkleTreeSiblingsAndRootHashes.mjs +69 -67
- package/package.json +1 -1
- 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 +28 -26
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLogic.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLogic.mjs +18 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/chains.constants.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/chains.constants.cjs"),c=require("../../constants/protocol.constants.cjs"),ee=require("../../data-structures/utxo/Utxo.cjs"),ne=require("../web3/etherFunctions.cjs"),r=require("./common.snarkjs.cjs"),te=require("./generateCircomData.cjs"),ae=require("./generateZkProof.cjs"),se=require("../../types/hinkal.types.cjs"),oe=require("../utils/fees.utils.cjs"),b=require("../../data-structures/Hinkal/hinkalCheckTokenRegistry.cjs"),re=require("../../error-handling/logger.cjs"),ie=require("./getMerkleTreeSiblingsAndRootHashes.cjs"),ce=async(m,W,G,n,s,i,p,q,l,z,D,P=c.zeroAddress,d=T.chainIds.localhost,k=n.map(()=>!1),v=n.map(()=>0n),R=void 0,w=!1,o=void 0,g,u=void 0,J,y=c.defaultSignatureData,_)=>{const O=r.calcAmountChanges(n,s),A=n.map(e=>e[0].erc20TokenAddress),S=r.calcEncryptedOutputs(s),f=i.getShieldedPrivateKey(),Z=ee.Utxo.findCorrectRandomization(ne.randomBigInt(31),f),C=T.isTronLike(d)?await b.hinkalCheckTronTokenRegistry(A,r.calcAmountChanges(n,s,!0),d):await b.hinkalCheckTokenRegistry(J??b.createHinkalHelperFromData(d),A,r.calcAmountChanges(n,s,!0)),B=T.isTronLike(d)?w||C:w,Q=n.map(e=>e.map(t=>t.getConstructableParams()));console.log("hinkalDeposit sa1",{userKeys:i});const{inCommitmentSiblings:X,inCommitmentSiblingSides:Y,accessTokenSiblings:$,accessTokenSiblingSides:K,rootHashHinkal:F,rootHashAccessToken:I,inNullifiers:j}=await ie.getDataFromWorkers(d,W,G,i,Q,B,C,k,m);console.log("hinkalDeposit y1",{userKeys:i,effectivePatchAccessTokenMerkleTree:B,kycRequired:C});const E=r.buildOutCommitments(m,s,k),a={rootHashHinkal:F,shieldedPrivateKey:f,erc20TokenAddresses:A,inAmounts:n.map(e=>e.map(t=>t.amount.toString())),inTimeStamps:n.map(e=>e.map(t=>t.timeStamp)),inRandomizations:n.map(e=>e.map(t=>t.randomization)),inNullifiers:j,inCommitmentSiblings:X,inCommitmentSiblingSides:Y,outAmounts:s.map(e=>e.map(t=>t.amount.toString())),outTimeStamp:BigInt(s[0][0].timeStamp),outPublicKeys:s.map(e=>e.map(t=>t.getStealthAddress())),extraRandomization:Z,amountChanges:O,outCommitments:E,rootHashAccessToken:I,accessTokenSiblings:$,accessTokenSiblingSides:K,calldataHash:0n},h=n.map(e=>e[0].tokenId??0),N=h.reduce((e,t)=>e+t,0)>0?h.length:0;N>0&&(a.tokenIds=h);const H=r.calcPublicSignalCount(p,a.erc20TokenAddresses,a.amountChanges,a.inNullifiers,a.outCommitments,N);if(!o){o=se.defaultHinkalLogicArgs(O.length,i),o.interactionAddress=l??c.zeroAddress;const e=i.getInHinkalAddress(o.interactionAddress);o.inHinkalAddress=e}if(m==="v1x1"){if(a.interactionAddress=o?.interactionAddress??l??c.zeroAddress,i.getInHinkalAddress(a.interactionAddress)!==o.inHinkalAddress)throw new Error("inHinkalAddress mismatch");a.externalApprovalAddresses=o.useApprovalUtxoData?.map(({externalApprovalAddresses:e})=>e)??[c.zeroAddress,c.zeroAddress,c.zeroAddress]}u||(u=oe.generateFeeStructure(v,n.map(e=>e[0].erc20TokenAddress)));const M=r.calcAmountChanges(n,s,!0);g||(g=r.getSlippageValues(M,o)),re.Logger.log({publicSignalCount:H}),a.calldataHash=r.createCallDataHash(m,H,P,l,q,z,S,v,R,g,k,o,u,y,_),console.log("hinkalDeposit k2 pre proof",{input:a,generateProofRemotely:D});const{zkCallData:L}=await ae.generateZkProof(m,d,p,a,D);console.log("hinkalDeposit k2 post proof");const V=r.calcStealthAddressStructure(Z,f),U=te.generateCircomData(E,j,F,I,M,A,s,S,H,q,l,z,P,a.calldataHash,h,V,k,R,void 0,o,g,u,y,_),x={tokenNumber:n.length,nullifierAmount:n[0].length,outputAmount:s[0].length};return{zkCallData:L,circomData:U,dimData:x,encryptedOutputs:S}};exports.constructZkProof=ce;
|
|
@@ -1,138 +1,140 @@
|
|
|
1
|
-
import { isTronLike as
|
|
1
|
+
import { isTronLike as j, chainIds as x } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { zeroAddress as s, defaultSignatureData as tt } from "../../constants/protocol.constants.mjs";
|
|
3
3
|
import { Utxo as at } from "../../data-structures/utxo/Utxo.mjs";
|
|
4
4
|
import { randomBigInt as et } from "../web3/etherFunctions.mjs";
|
|
5
|
-
import { calcAmountChanges as
|
|
5
|
+
import { calcAmountChanges as g, calcEncryptedOutputs as nt, buildOutCommitments as ot, calcPublicSignalCount as mt, getSlippageValues as it, createCallDataHash as rt, calcStealthAddressStructure as st } from "./common.snarkjs.mjs";
|
|
6
6
|
import { generateCircomData as dt } from "./generateCircomData.mjs";
|
|
7
7
|
import { generateZkProof as ct } from "./generateZkProof.mjs";
|
|
8
8
|
import { defaultHinkalLogicArgs as lt } from "../../types/hinkal.types.mjs";
|
|
9
|
-
import { generateFeeStructure as
|
|
10
|
-
import { hinkalCheckTronTokenRegistry as
|
|
11
|
-
import { Logger as
|
|
12
|
-
import { getDataFromWorkers as
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
Q ??
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
),
|
|
9
|
+
import { generateFeeStructure as kt } from "../utils/fees.utils.mjs";
|
|
10
|
+
import { hinkalCheckTronTokenRegistry as ft, hinkalCheckTokenRegistry as pt, createHinkalHelperFromData as St } from "../../data-structures/Hinkal/hinkalCheckTokenRegistry.mjs";
|
|
11
|
+
import { Logger as gt } from "../../error-handling/logger.mjs";
|
|
12
|
+
import { getDataFromWorkers as Ht } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
|
|
13
|
+
const Bt = async (d, G, J, a, o, i, C, D, c, b, P, z = s, r = x.localhost, l = a.map(() => !1), v = a.map(() => 0n), w = void 0, R = !1, m = void 0, k, f = void 0, Q, u = tt, B) => {
|
|
14
|
+
const I = g(a, o), p = a.map((t) => t[0].erc20TokenAddress), H = nt(o), A = i.getShieldedPrivateKey(), O = at.findCorrectRandomization(et(31), A), h = j(r) ? await ft(p, g(a, o, !0), r) : await pt(
|
|
15
|
+
Q ?? St(r),
|
|
16
|
+
p,
|
|
17
|
+
g(a, o, !0)
|
|
18
|
+
), y = j(r) ? R || h : R, X = a.map((t) => t.map((e) => e.getConstructableParams()));
|
|
19
19
|
console.log("hinkalDeposit sa1", { userKeys: i });
|
|
20
20
|
const {
|
|
21
21
|
inCommitmentSiblings: Y,
|
|
22
22
|
inCommitmentSiblingSides: _,
|
|
23
23
|
accessTokenSiblings: $,
|
|
24
24
|
accessTokenSiblingSides: M,
|
|
25
|
-
rootHashHinkal:
|
|
26
|
-
rootHashAccessToken:
|
|
27
|
-
inNullifiers:
|
|
28
|
-
} = await
|
|
25
|
+
rootHashHinkal: E,
|
|
26
|
+
rootHashAccessToken: F,
|
|
27
|
+
inNullifiers: N
|
|
28
|
+
} = await Ht(
|
|
29
29
|
r,
|
|
30
|
-
j,
|
|
31
30
|
G,
|
|
31
|
+
J,
|
|
32
32
|
i,
|
|
33
33
|
X,
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
y,
|
|
35
|
+
h,
|
|
36
36
|
l,
|
|
37
37
|
d
|
|
38
38
|
);
|
|
39
|
-
console.log("hinkalDeposit y1", { userKeys: i, effectivePatchAccessTokenMerkleTree:
|
|
40
|
-
const
|
|
41
|
-
rootHashHinkal:
|
|
39
|
+
console.log("hinkalDeposit y1", { userKeys: i, effectivePatchAccessTokenMerkleTree: y, kycRequired: h });
|
|
40
|
+
const Z = ot(d, o, l), n = {
|
|
41
|
+
rootHashHinkal: E,
|
|
42
42
|
shieldedPrivateKey: A,
|
|
43
|
-
erc20TokenAddresses:
|
|
43
|
+
erc20TokenAddresses: p,
|
|
44
44
|
inAmounts: a.map((t) => t.map((e) => e.amount.toString())),
|
|
45
45
|
inTimeStamps: a.map((t) => t.map((e) => e.timeStamp)),
|
|
46
46
|
inRandomizations: a.map((t) => t.map((e) => e.randomization)),
|
|
47
|
-
inNullifiers:
|
|
47
|
+
inNullifiers: N,
|
|
48
48
|
inCommitmentSiblings: Y,
|
|
49
49
|
inCommitmentSiblingSides: _,
|
|
50
|
-
outAmounts:
|
|
51
|
-
outTimeStamp: BigInt(
|
|
52
|
-
outPublicKeys:
|
|
53
|
-
extraRandomization:
|
|
54
|
-
amountChanges:
|
|
55
|
-
outCommitments:
|
|
56
|
-
rootHashAccessToken:
|
|
50
|
+
outAmounts: o.map((t) => t.map((e) => e.amount.toString())),
|
|
51
|
+
outTimeStamp: BigInt(o[0][0].timeStamp),
|
|
52
|
+
outPublicKeys: o.map((t) => t.map((e) => e.getStealthAddress())),
|
|
53
|
+
extraRandomization: O,
|
|
54
|
+
amountChanges: I,
|
|
55
|
+
outCommitments: Z,
|
|
56
|
+
rootHashAccessToken: F,
|
|
57
57
|
accessTokenSiblings: $,
|
|
58
58
|
accessTokenSiblingSides: M,
|
|
59
59
|
calldataHash: 0n
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
}, S = a.map((t) => t[0].tokenId ?? 0), q = S.reduce((t, e) => t + e, 0) > 0 ? S.length : 0;
|
|
61
|
+
q > 0 && (n.tokenIds = S);
|
|
62
|
+
const T = mt(
|
|
63
|
+
C,
|
|
64
|
+
n.erc20TokenAddresses,
|
|
65
|
+
n.amountChanges,
|
|
66
|
+
n.inNullifiers,
|
|
67
|
+
n.outCommitments,
|
|
68
|
+
q
|
|
69
69
|
);
|
|
70
|
-
if (!
|
|
71
|
-
|
|
72
|
-
const t = i.getInHinkalAddress(
|
|
73
|
-
|
|
70
|
+
if (!m) {
|
|
71
|
+
m = lt(I.length, i), m.interactionAddress = c ?? s;
|
|
72
|
+
const t = i.getInHinkalAddress(m.interactionAddress);
|
|
73
|
+
m.inHinkalAddress = t;
|
|
74
74
|
}
|
|
75
75
|
if (d === "v1x1") {
|
|
76
|
-
if (
|
|
76
|
+
if (n.interactionAddress = m?.interactionAddress ?? c ?? s, i.getInHinkalAddress(n.interactionAddress) !== m.inHinkalAddress)
|
|
77
77
|
throw new Error("inHinkalAddress mismatch");
|
|
78
|
-
|
|
78
|
+
n.externalApprovalAddresses = m.useApprovalUtxoData?.map(
|
|
79
79
|
({ externalApprovalAddresses: t }) => t
|
|
80
80
|
) ?? [s, s, s];
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
f || (f = kt(
|
|
83
|
+
v,
|
|
84
84
|
a.map((t) => t[0].erc20TokenAddress)
|
|
85
85
|
));
|
|
86
|
-
const
|
|
87
|
-
|
|
86
|
+
const W = g(a, o, !0);
|
|
87
|
+
k || (k = it(W, m)), gt.log({ publicSignalCount: T }), n.calldataHash = rt(
|
|
88
88
|
d,
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
T,
|
|
90
|
+
z,
|
|
91
91
|
c,
|
|
92
|
-
b,
|
|
93
92
|
D,
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
b,
|
|
94
|
+
H,
|
|
96
95
|
v,
|
|
97
|
-
|
|
98
|
-
l,
|
|
99
|
-
n,
|
|
96
|
+
w,
|
|
100
97
|
k,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
l,
|
|
99
|
+
m,
|
|
100
|
+
f,
|
|
101
|
+
u,
|
|
102
|
+
B
|
|
103
|
+
), console.log("hinkalDeposit k2 pre proof", { input: n, generateProofRemotely: P });
|
|
104
|
+
const { zkCallData: K } = await ct(d, r, C, n, P);
|
|
105
|
+
console.log("hinkalDeposit k2 post proof");
|
|
106
|
+
const V = st(O, A), L = dt(
|
|
107
|
+
Z,
|
|
105
108
|
N,
|
|
106
|
-
F,
|
|
107
|
-
O,
|
|
108
109
|
E,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
m,
|
|
112
|
-
g,
|
|
113
|
-
C,
|
|
114
|
-
b,
|
|
115
|
-
c,
|
|
116
|
-
D,
|
|
117
|
-
P,
|
|
118
|
-
o.calldataHash,
|
|
110
|
+
F,
|
|
111
|
+
W,
|
|
119
112
|
p,
|
|
113
|
+
o,
|
|
114
|
+
H,
|
|
115
|
+
T,
|
|
116
|
+
D,
|
|
117
|
+
c,
|
|
118
|
+
b,
|
|
119
|
+
z,
|
|
120
|
+
n.calldataHash,
|
|
121
|
+
S,
|
|
120
122
|
V,
|
|
121
123
|
l,
|
|
122
|
-
|
|
124
|
+
w,
|
|
123
125
|
void 0,
|
|
124
|
-
|
|
125
|
-
f,
|
|
126
|
+
m,
|
|
126
127
|
k,
|
|
127
|
-
|
|
128
|
-
u
|
|
128
|
+
f,
|
|
129
|
+
u,
|
|
130
|
+
B
|
|
129
131
|
), U = {
|
|
130
132
|
tokenNumber: a.length,
|
|
131
133
|
nullifierAmount: a[0].length,
|
|
132
|
-
outputAmount:
|
|
134
|
+
outputAmount: o[0].length
|
|
133
135
|
};
|
|
134
|
-
return { zkCallData: K, circomData: L, dimData: U, encryptedOutputs:
|
|
136
|
+
return { zkCallData: K, circomData: L, dimData: U, encryptedOutputs: H };
|
|
135
137
|
};
|
|
136
138
|
export {
|
|
137
|
-
|
|
139
|
+
Bt as constructZkProof
|
|
138
140
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../../error-handling/logger.cjs"),c=require("./generateZkProofEnclave.cjs"),g=require("./generateZkProofSelf.cjs"),f=async(e,r,o,t,l)=>{if(l)try{return await c.generateZkProofEnclave(e,r,o,t)}catch(n){console.log("hinkalDeposit k3 enclave proof error",n),a.Logger.error("enclave proof error",n)}return console.log("hinkalDeposit k4 self proof"),g.generateZkProofSelf(e,r,o,t)};exports.generateZkProof=f;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Logger as n } from "../../error-handling/logger.mjs";
|
|
2
|
-
import { generateZkProofEnclave as
|
|
3
|
-
import { generateZkProofSelf as
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
2
|
+
import { generateZkProofEnclave as a } from "./generateZkProofEnclave.mjs";
|
|
3
|
+
import { generateZkProofSelf as c } from "./generateZkProofSelf.mjs";
|
|
4
|
+
const s = async (o, r, e, t, l) => {
|
|
5
|
+
if (l)
|
|
6
6
|
try {
|
|
7
|
-
return await
|
|
8
|
-
} catch (
|
|
9
|
-
n.error("enclave proof error",
|
|
7
|
+
return await a(o, r, e, t);
|
|
8
|
+
} catch (f) {
|
|
9
|
+
console.log("hinkalDeposit k3 enclave proof error", f), n.error("enclave proof error", f);
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return console.log("hinkalDeposit k4 self proof"), c(o, r, e, t);
|
|
12
12
|
};
|
|
13
13
|
export {
|
|
14
|
-
|
|
14
|
+
s as generateZkProof
|
|
15
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./getZKFiles.cjs"),k=require("../../webworker/performTaskWithWorker.cjs"),c=require("../../webworker/snarkjsWorker/snarkjsWorker.types.cjs"),y=require("../../webworker/worker.registry.cjs"),g=async(r,e,t,o)=>{const a=l.getWASMFile(r,t,e),s=l.getZKeyFile(r,t,e);console.log("hinkalDeposit k5 self proof",{input:o,wasmFilePath:a,zKeyFilePath:s});const{publicSignals:n,zkCallData:i}=await k.performTaskWithWorker({type:y.WorkerVariant.SnarkJS,payload:{type:c.SnarkJSWorkerActionType.FULL_PROVE,data:{input:o,chainId:e,wasmFilePath:a,zKeyFilePath:s}}});return{zkCallData:i,publicSignals:n}};exports.generateZkProofSelf=g;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { getWASMFile as
|
|
2
|
-
import { performTaskWithWorker as
|
|
3
|
-
import { SnarkJSWorkerActionType as
|
|
4
|
-
import { WorkerVariant as
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
1
|
+
import { getWASMFile as k, getZKeyFile as n } from "./getZKFiles.mjs";
|
|
2
|
+
import { performTaskWithWorker as s } from "../../webworker/performTaskWithWorker.mjs";
|
|
3
|
+
import { SnarkJSWorkerActionType as m } from "../../webworker/snarkjsWorker/snarkjsWorker.types.mjs";
|
|
4
|
+
import { WorkerVariant as f } from "../../webworker/worker.registry.mjs";
|
|
5
|
+
const F = async (t, o, r, e) => {
|
|
6
|
+
const a = k(t, r, o), l = n(t, r, o);
|
|
7
|
+
console.log("hinkalDeposit k5 self proof", { input: e, wasmFilePath: a, zKeyFilePath: l });
|
|
8
|
+
const { publicSignals: p, zkCallData: i } = await s({
|
|
9
|
+
type: f.SnarkJS,
|
|
8
10
|
payload: {
|
|
9
|
-
type:
|
|
10
|
-
data: { input:
|
|
11
|
+
type: m.FULL_PROVE,
|
|
12
|
+
data: { input: e, chainId: o, wasmFilePath: a, zKeyFilePath: l }
|
|
11
13
|
}
|
|
12
14
|
});
|
|
13
15
|
return { zkCallData: i, publicSignals: p };
|
|
14
16
|
};
|
|
15
17
|
export {
|
|
16
|
-
|
|
18
|
+
F as generateZkProofSelf
|
|
17
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("../../data-structures/merkle-tree/MerkleTree.cjs"),A=require("../../data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.cjs"),S=require("../../webworker/performTaskWithWorker.cjs"),m=require("../../webworker/worker.registry.cjs"),h=require("../../webworker/zkProofWorker/zkProofWorker.types.cjs"),u=require("./fetchMerkleTreeSiblings.cjs"),H=require("../utils/amounts.utils.cjs"),P=require("../../crypto/poseidon.cjs"),C=require("../../constants/vite.constants.cjs"),R=require("./fetchOnChainRootHashes.cjs"),p=async(e,a)=>{const o=e.getRootHash();if(console.log("pre calculate access token siblings and root hash",{rootHash:o,patchedMerkleTree:e}),o===void 0)throw new Error("Root hash not available from patched merkle tree");const s=await S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,data:{accessKey:a,merkleTreeAccessTokenSerialized:e.toJSON()}}});return{accessTokenSiblings:s.accessTokenSiblings,accessTokenSiblingSides:s.accessTokenSiblingSides,rootHashAccessToken:o}},_=async(e,a,o,s,i,n)=>{console.log("hinkalDeposit sa5");const r=o.getAccessKey();console.log("hinkalDeposit sa6",{accessKey:r});const t=A.getPatchedAccessTokenMerkleTree(a,r,i,n),g=e.getRootHash();if(g===void 0)throw new Error("Root hash not available from hinkal merkle tree");let l,c;return C.isNode?(l=await p(t,r),c=await S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES,data:{inputUtxosSerialized:s,merkleTreeSerialized:e.toJSON()}}})):[l,c]=await Promise.all([p(t,r),S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES,data:{inputUtxosSerialized:s,merkleTreeSerialized:e.toJSON()}}})]),{inCommitmentSiblings:c.inCommitmentSiblings,inCommitmentSiblingSides:c.inCommitmentSiblingSides,accessTokenSiblings:l.accessTokenSiblings,accessTokenSiblingSides:l.accessTokenSiblingSides,rootHashHinkal:g,rootHashAccessToken:l.rootHashAccessToken}},N=async(e,a,o,s,i)=>{console.log("hinkalDeposit sa3");const n=a.getAccessKey();if(console.log("hinkalDeposit sa4",{accessKey:n}),!i||s){const g=W.MerkleTree.create(P.poseidonFunction,0n),l=A.getPatchedAccessTokenMerkleTree(g,n,s,i);console.log("pre calculating access token siblings and root hash",{accessKey:n});const[c,k]=await Promise.all([p(l,n),u.fetchMerkleTreeSiblings(e,o,n)]);return console.log("post calculating access token siblings and root hash",{accessTokenResult:c,siblingsResponse:k}),{inCommitmentSiblings:k.inCommitmentSiblings,inCommitmentSiblingSides:k.inCommitmentSiblingSides,accessTokenSiblings:c.accessTokenSiblings,accessTokenSiblingSides:c.accessTokenSiblingSides,rootHashHinkal:H.toBigInt(k.rootHashHinkal),rootHashAccessToken:c.rootHashAccessToken}}const t=await u.fetchMerkleTreeSiblings(e,o,n);return{inCommitmentSiblings:t.inCommitmentSiblings,inCommitmentSiblingSides:t.inCommitmentSiblingSides,accessTokenSiblings:t.accessTokenSiblings,accessTokenSiblingSides:t.accessTokenSiblingSides,rootHashHinkal:H.toBigInt(t.rootHashHinkal),rootHashAccessToken:H.toBigInt(t.rootHashAccessToken)}},I=async(e,a,o)=>{if(!a||!o)return!1;try{const s=a.getRootHash(),i=o.getRootHash();if(!s||!i)return!1;const{hinkalRootHash:n,accessTokenRootHash:r}=await R.fetchOnChainRootHashes(e);return s===n&&i===r}catch{return!1}},y=async(e,a,o,s,i,n,r)=>{const t=await I(e,n,r);return console.log("hinkalDeposit sa2",{isLocalFresh:t}),t?_(n,r,a,o,s,i):N(e,a,o,s,i)},M=async(e,a,o,s,i,n,r,t,g)=>{if(C.isNode){const{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d}=await y(e,s,i,n,r,a,o),f=await S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:i,onChainCreation:t,proverVersion:g}}});return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d,inNullifiers:f}}else{const[{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d},f]=await Promise.all([y(e,s,i,n,r,a,o),S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:i,onChainCreation:t,proverVersion:g}}})]);return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d,inNullifiers:f}}};exports.getDataFromWorkers=M;exports.getMerkleTreeSiblingsAndRootHashes=y;
|
|
@@ -4,15 +4,15 @@ import { performTaskWithWorker as g } from "../../webworker/performTaskWithWorke
|
|
|
4
4
|
import { WorkerVariant as k } from "../../webworker/worker.registry.mjs";
|
|
5
5
|
import { ZKProofWorkerActionType as h } from "../../webworker/zkProofWorker/zkProofWorker.types.mjs";
|
|
6
6
|
import { fetchMerkleTreeSiblings as C } from "./fetchMerkleTreeSiblings.mjs";
|
|
7
|
-
import { toBigInt as
|
|
7
|
+
import { toBigInt as H } from "../utils/amounts.utils.mjs";
|
|
8
8
|
import { poseidonFunction as I } from "../../crypto/poseidon.mjs";
|
|
9
9
|
import { isNode as N } from "../../constants/vite.constants.mjs";
|
|
10
10
|
import { fetchOnChainRootHashes as _ } from "./fetchOnChainRootHashes.mjs";
|
|
11
11
|
const p = async (o, a) => {
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
12
|
+
const s = o.getRootHash();
|
|
13
|
+
if (console.log("pre calculate access token siblings and root hash", { rootHash: s, patchedMerkleTree: o }), s === void 0)
|
|
14
14
|
throw new Error("Root hash not available from patched merkle tree");
|
|
15
|
-
const
|
|
15
|
+
const e = await g({
|
|
16
16
|
type: k.ZKProof,
|
|
17
17
|
payload: {
|
|
18
18
|
type: h.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,
|
|
@@ -23,28 +23,28 @@ const p = async (o, a) => {
|
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
return {
|
|
26
|
-
accessTokenSiblings:
|
|
27
|
-
accessTokenSiblingSides:
|
|
28
|
-
rootHashAccessToken:
|
|
26
|
+
accessTokenSiblings: e.accessTokenSiblings,
|
|
27
|
+
accessTokenSiblingSides: e.accessTokenSiblingSides,
|
|
28
|
+
rootHashAccessToken: s
|
|
29
29
|
};
|
|
30
|
-
}, w = async (o, a, e,
|
|
30
|
+
}, w = async (o, a, s, e, n, i) => {
|
|
31
31
|
console.log("hinkalDeposit sa5");
|
|
32
|
-
const c =
|
|
32
|
+
const c = s.getAccessKey();
|
|
33
33
|
console.log("hinkalDeposit sa6", { accessKey: c });
|
|
34
34
|
const t = A(
|
|
35
35
|
a,
|
|
36
36
|
c,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
),
|
|
40
|
-
if (
|
|
37
|
+
n,
|
|
38
|
+
i
|
|
39
|
+
), S = o.getRootHash();
|
|
40
|
+
if (S === void 0)
|
|
41
41
|
throw new Error("Root hash not available from hinkal merkle tree");
|
|
42
42
|
let r, l;
|
|
43
43
|
return N ? (r = await p(t, c), l = await g({
|
|
44
44
|
type: k.ZKProof,
|
|
45
45
|
payload: {
|
|
46
46
|
type: h.CALC_COMMITMENTS_SIBLING_AND_SIDES,
|
|
47
|
-
data: { inputUtxosSerialized:
|
|
47
|
+
data: { inputUtxosSerialized: e, merkleTreeSerialized: o.toJSON() }
|
|
48
48
|
}
|
|
49
49
|
})) : [r, l] = await Promise.all([
|
|
50
50
|
p(t, c),
|
|
@@ -52,7 +52,7 @@ const p = async (o, a) => {
|
|
|
52
52
|
type: k.ZKProof,
|
|
53
53
|
payload: {
|
|
54
54
|
type: h.CALC_COMMITMENTS_SIBLING_AND_SIDES,
|
|
55
|
-
data: { inputUtxosSerialized:
|
|
55
|
+
data: { inputUtxosSerialized: e, merkleTreeSerialized: o.toJSON() }
|
|
56
56
|
}
|
|
57
57
|
})
|
|
58
58
|
]), {
|
|
@@ -60,132 +60,134 @@ const p = async (o, a) => {
|
|
|
60
60
|
inCommitmentSiblingSides: l.inCommitmentSiblingSides,
|
|
61
61
|
accessTokenSiblings: r.accessTokenSiblings,
|
|
62
62
|
accessTokenSiblingSides: r.accessTokenSiblingSides,
|
|
63
|
-
rootHashHinkal:
|
|
63
|
+
rootHashHinkal: S,
|
|
64
64
|
rootHashAccessToken: r.rootHashAccessToken
|
|
65
65
|
};
|
|
66
|
-
}, D = async (o, a,
|
|
66
|
+
}, D = async (o, a, s, e, n) => {
|
|
67
67
|
console.log("hinkalDeposit sa3");
|
|
68
|
-
const
|
|
69
|
-
if (console.log("hinkalDeposit sa4", { accessKey:
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
const i = a.getAccessKey();
|
|
69
|
+
if (console.log("hinkalDeposit sa4", { accessKey: i }), !n || e) {
|
|
70
|
+
const S = R.create(I, 0n), r = A(
|
|
71
|
+
S,
|
|
72
|
+
i,
|
|
73
|
+
e,
|
|
74
|
+
n
|
|
75
|
+
);
|
|
76
|
+
console.log("pre calculating access token siblings and root hash", { accessKey: i });
|
|
77
|
+
const [l, m] = await Promise.all([
|
|
78
|
+
p(r, i),
|
|
79
|
+
C(o, s, i)
|
|
78
80
|
]);
|
|
79
|
-
return {
|
|
80
|
-
inCommitmentSiblings:
|
|
81
|
-
inCommitmentSiblingSides:
|
|
81
|
+
return console.log("post calculating access token siblings and root hash", { accessTokenResult: l, siblingsResponse: m }), {
|
|
82
|
+
inCommitmentSiblings: m.inCommitmentSiblings,
|
|
83
|
+
inCommitmentSiblingSides: m.inCommitmentSiblingSides,
|
|
82
84
|
accessTokenSiblings: l.accessTokenSiblings,
|
|
83
85
|
accessTokenSiblingSides: l.accessTokenSiblingSides,
|
|
84
|
-
rootHashHinkal:
|
|
86
|
+
rootHashHinkal: H(m.rootHashHinkal),
|
|
85
87
|
rootHashAccessToken: l.rootHashAccessToken
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
|
-
const t = await C(o,
|
|
90
|
+
const t = await C(o, s, i);
|
|
89
91
|
return {
|
|
90
92
|
inCommitmentSiblings: t.inCommitmentSiblings,
|
|
91
93
|
inCommitmentSiblingSides: t.inCommitmentSiblingSides,
|
|
92
94
|
accessTokenSiblings: t.accessTokenSiblings,
|
|
93
95
|
accessTokenSiblingSides: t.accessTokenSiblingSides,
|
|
94
|
-
rootHashHinkal:
|
|
95
|
-
rootHashAccessToken:
|
|
96
|
+
rootHashHinkal: H(t.rootHashHinkal),
|
|
97
|
+
rootHashAccessToken: H(t.rootHashAccessToken)
|
|
96
98
|
};
|
|
97
|
-
}, L = async (o, a,
|
|
98
|
-
if (!a || !
|
|
99
|
+
}, L = async (o, a, s) => {
|
|
100
|
+
if (!a || !s)
|
|
99
101
|
return !1;
|
|
100
102
|
try {
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
103
|
+
const e = a.getRootHash(), n = s.getRootHash();
|
|
104
|
+
if (!e || !n)
|
|
103
105
|
return !1;
|
|
104
|
-
const { hinkalRootHash:
|
|
105
|
-
return
|
|
106
|
+
const { hinkalRootHash: i, accessTokenRootHash: c } = await _(o);
|
|
107
|
+
return e === i && n === c;
|
|
106
108
|
} catch {
|
|
107
109
|
return !1;
|
|
108
110
|
}
|
|
109
|
-
}, y = async (o, a, e,
|
|
110
|
-
const t = await L(o,
|
|
111
|
+
}, y = async (o, a, s, e, n, i, c) => {
|
|
112
|
+
const t = await L(o, i, c);
|
|
111
113
|
return console.log("hinkalDeposit sa2", { isLocalFresh: t }), t ? w(
|
|
112
|
-
|
|
114
|
+
i,
|
|
113
115
|
c,
|
|
114
116
|
a,
|
|
115
|
-
e,
|
|
116
117
|
s,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
e,
|
|
119
|
+
n
|
|
120
|
+
) : D(o, a, s, e, n);
|
|
121
|
+
}, v = async (o, a, s, e, n, i, c, t, S) => {
|
|
120
122
|
if (N) {
|
|
121
123
|
const {
|
|
122
124
|
inCommitmentSiblings: r,
|
|
123
125
|
inCommitmentSiblingSides: l,
|
|
124
|
-
accessTokenSiblings:
|
|
126
|
+
accessTokenSiblings: m,
|
|
125
127
|
accessTokenSiblingSides: b,
|
|
126
128
|
rootHashHinkal: T,
|
|
127
|
-
rootHashAccessToken:
|
|
129
|
+
rootHashAccessToken: d
|
|
128
130
|
} = await y(
|
|
129
131
|
o,
|
|
130
|
-
|
|
131
|
-
i,
|
|
132
|
+
e,
|
|
132
133
|
n,
|
|
134
|
+
i,
|
|
133
135
|
c,
|
|
134
136
|
a,
|
|
135
|
-
|
|
136
|
-
),
|
|
137
|
+
s
|
|
138
|
+
), f = await g({
|
|
137
139
|
type: k.ZKProof,
|
|
138
140
|
payload: {
|
|
139
141
|
type: h.BUILD_IN_NULLIFIERS,
|
|
140
|
-
data: { inputUtxosSerialized:
|
|
142
|
+
data: { inputUtxosSerialized: n, onChainCreation: t, proverVersion: S }
|
|
141
143
|
}
|
|
142
144
|
});
|
|
143
145
|
return {
|
|
144
146
|
inCommitmentSiblings: r,
|
|
145
147
|
inCommitmentSiblingSides: l,
|
|
146
|
-
accessTokenSiblings:
|
|
148
|
+
accessTokenSiblings: m,
|
|
147
149
|
accessTokenSiblingSides: b,
|
|
148
150
|
rootHashHinkal: T,
|
|
149
|
-
rootHashAccessToken:
|
|
150
|
-
inNullifiers:
|
|
151
|
+
rootHashAccessToken: d,
|
|
152
|
+
inNullifiers: f
|
|
151
153
|
};
|
|
152
154
|
} else {
|
|
153
155
|
const [
|
|
154
156
|
{
|
|
155
157
|
inCommitmentSiblings: r,
|
|
156
158
|
inCommitmentSiblingSides: l,
|
|
157
|
-
accessTokenSiblings:
|
|
159
|
+
accessTokenSiblings: m,
|
|
158
160
|
accessTokenSiblingSides: b,
|
|
159
161
|
rootHashHinkal: T,
|
|
160
|
-
rootHashAccessToken:
|
|
162
|
+
rootHashAccessToken: d
|
|
161
163
|
},
|
|
162
|
-
|
|
164
|
+
f
|
|
163
165
|
] = await Promise.all([
|
|
164
166
|
y(
|
|
165
167
|
o,
|
|
166
|
-
|
|
167
|
-
i,
|
|
168
|
+
e,
|
|
168
169
|
n,
|
|
170
|
+
i,
|
|
169
171
|
c,
|
|
170
172
|
a,
|
|
171
|
-
|
|
173
|
+
s
|
|
172
174
|
),
|
|
173
175
|
g({
|
|
174
176
|
type: k.ZKProof,
|
|
175
177
|
payload: {
|
|
176
178
|
type: h.BUILD_IN_NULLIFIERS,
|
|
177
|
-
data: { inputUtxosSerialized:
|
|
179
|
+
data: { inputUtxosSerialized: n, onChainCreation: t, proverVersion: S }
|
|
178
180
|
}
|
|
179
181
|
})
|
|
180
182
|
]);
|
|
181
183
|
return {
|
|
182
184
|
inCommitmentSiblings: r,
|
|
183
185
|
inCommitmentSiblingSides: l,
|
|
184
|
-
accessTokenSiblings:
|
|
186
|
+
accessTokenSiblings: m,
|
|
185
187
|
accessTokenSiblingSides: b,
|
|
186
188
|
rootHashHinkal: T,
|
|
187
|
-
rootHashAccessToken:
|
|
188
|
-
inNullifiers:
|
|
189
|
+
rootHashAccessToken: d,
|
|
190
|
+
inNullifiers: f
|
|
189
191
|
};
|
|
190
192
|
}
|
|
191
193
|
};
|
package/package.json
CHANGED
|
@@ -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-DA6ytEz_.js").href:new URL("../../assets/snarkjsWorkerLauncher-DA6ytEz_.js",document.currentScript&&document.currentScript.src||document.baseURI).href);module.exports=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const j=require("../workerProxy.cjs"),i=require("../../constants/vite.constants.cjs"),M=require("snarkjs"),O=require("../../data-structures/http/HttpClient.cjs");require("axios");const y=require("../../constants/chains.constants.cjs");function W(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(o,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return o.default=e,Object.freeze(o)}const b=W(M),c=new j.WorkerProxy,w=async e=>new Uint8Array(await O.httpClient.get(e,{responseType:"arraybuffer"})),$=async e=>{try{const{input:o,wasmFilePath:t,zKeyFilePath:r,chainId:n}=e.payload.data,{hostLocation:{origin:h},constants:{isDevelopment:v,chains:{chainIds:l}}}=e.metadata;let s=t,a=r,f,g;const u=s.startsWith("https://");if(console.log("hinkalDeposit k6 snarkjs worker logic",{isNode:i.isNode,isOnline:u,isWebpack:i.isWebpack}),i.isNode&&!u){i.isWebpack?(s=`libs/hardhat/test/circuits/${t}`,a=`libs/hardhat/test/circuits/${r}`):!i.isWebpack&&v&&(n===y.chainIds.solanaLocalnet?(s=`tests/circuits/${t}`,a=`tests/circuits/${r}`):(s=`test/circuits/${t}`,a=`test/circuits/${r}`));const k=require("path");s=k.resolve(s),a=k.resolve(a)}i.isNode&&u?(f=await w(s),g=await w(a)):(n===l.localhost||n===y.chainIds.solanaLocalnet||n===l.tronLocalnet)&&!i.isNode&&(s=`${h}/${t}`,a=`${h}/${r}`),console.log("pre pr ",{chainId:n});const{proof:d,publicSignals:p}=await b.groth16.fullProve(o,f??s,g??a,void 0,void 0,i.isNode&&n===l.tronLocalnet?{singleThread:!0}:void 0);console.log("post proof",{proof:d,publicSignals:p});const P=await b.groth16.exportSolidityCallData(d,p),m=JSON.parse(`[${P}]`);c.postMessageToMainThread({zkCallData:m,proof:d,publicSignals:p})}catch(o){console.error("snarkjs worker logic error",o),c.postErrorToMainThread(o)}};c.attachWorkerSideOnMessage($);exports.default=c;exports.onWorkerMessage=$;
|
|
@@ -1,42 +1,44 @@
|
|
|
1
1
|
import { WorkerProxy as T } from "../workerProxy.mjs";
|
|
2
|
-
import { isNode as
|
|
3
|
-
import * as
|
|
2
|
+
import { isNode as s, isWebpack as f } from "../../constants/vite.constants.mjs";
|
|
3
|
+
import * as w from "snarkjs";
|
|
4
4
|
import { httpClient as b } from "../../data-structures/http/HttpClient.mjs";
|
|
5
5
|
import "axios";
|
|
6
|
-
import { chainIds as
|
|
7
|
-
const
|
|
6
|
+
import { chainIds as y } from "../../constants/chains.constants.mjs";
|
|
7
|
+
const d = new T(), $ = async (i) => new Uint8Array(await b.get(i, { responseType: "arraybuffer" })), z = async (i) => {
|
|
8
8
|
try {
|
|
9
|
-
const { input:
|
|
10
|
-
hostLocation: { origin:
|
|
9
|
+
const { input: l, wasmFilePath: r, zKeyFilePath: a, chainId: o } = i.payload.data, {
|
|
10
|
+
hostLocation: { origin: u },
|
|
11
11
|
constants: {
|
|
12
12
|
isDevelopment: F,
|
|
13
|
-
chains: { chainIds:
|
|
13
|
+
chains: { chainIds: n }
|
|
14
14
|
}
|
|
15
|
-
} =
|
|
16
|
-
let t =
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
t =
|
|
15
|
+
} = i.metadata;
|
|
16
|
+
let t = r, e = a, m, g;
|
|
17
|
+
const c = t.startsWith("https://");
|
|
18
|
+
if (console.log("hinkalDeposit k6 snarkjs worker logic", { isNode: s, isOnline: c, isWebpack: f }), s && !c) {
|
|
19
|
+
f ? (t = `libs/hardhat/test/circuits/${r}`, e = `libs/hardhat/test/circuits/${a}`) : !f && F && (o === y.solanaLocalnet ? (t = `tests/circuits/${r}`, e = `tests/circuits/${a}`) : (t = `test/circuits/${r}`, e = `test/circuits/${a}`));
|
|
20
|
+
const k = require("path");
|
|
21
|
+
t = k.resolve(t), e = k.resolve(e);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
const { proof:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
s && c ? (m = await $(t), g = await $(e)) : (o === n.localhost || o === y.solanaLocalnet || o === n.tronLocalnet) && !s && (t = `${u}/${r}`, e = `${u}/${a}`), console.log("pre pr ", { chainId: o });
|
|
24
|
+
const { proof: h, publicSignals: p } = await w.groth16.fullProve(
|
|
25
|
+
l,
|
|
26
|
+
m ?? t,
|
|
27
|
+
g ?? e,
|
|
28
28
|
void 0,
|
|
29
29
|
void 0,
|
|
30
|
-
|
|
30
|
+
s && o === n.tronLocalnet ? { singleThread: !0 } : void 0
|
|
31
31
|
// snarkjs hangs in tronbox enviroment if singleThread: true is not provided, which is weird, since if incorrect input is provided it will error out
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
);
|
|
33
|
+
console.log("post proof", { proof: h, publicSignals: p });
|
|
34
|
+
const v = await w.groth16.exportSolidityCallData(h, p), P = JSON.parse(`[${v}]`);
|
|
35
|
+
d.postMessageToMainThread({ zkCallData: P, proof: h, publicSignals: p });
|
|
36
|
+
} catch (l) {
|
|
37
|
+
console.error("snarkjs worker logic error", l), d.postErrorToMainThread(l);
|
|
36
38
|
}
|
|
37
39
|
};
|
|
38
|
-
|
|
40
|
+
d.attachWorkerSideOnMessage(z);
|
|
39
41
|
export {
|
|
40
|
-
|
|
42
|
+
d as default,
|
|
41
43
|
z as onWorkerMessage
|
|
42
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const r=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/zkProofWorkerLauncher-2a1CGTor.js").href:new URL("../../assets/zkProofWorkerLauncher-2a1CGTor.js",document.currentScript&&document.currentScript.src||document.baseURI).href);module.exports=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const A=require("../../crypto/preProcessing.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"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const A=require("../../crypto/preProcessing.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"),c=new C.WorkerProxy,k=o=>{const{inputUtxosSerialized:e,merkleTreeSerialized:t}=o.data,a=u.contructMerkleTreeFromSerialized(t),s=e.map(n=>n.map(l=>new S.Utxo(l))),{inCommitmentSiblings:r,inCommitmentSiblingSides:i}=m.calcCommitmentsSiblingAndSides(s,a);c.postMessageToMainThread({inCommitmentSiblings:r,inCommitmentSiblingSides:i})},p=o=>{const{accessKey:e,merkleTreeAccessTokenSerialized:t}=o.data;console.log("worker code a1",{accessKey:e,merkleTreeAccessTokenSerialized:t});const a=u.contructMerkleTreeFromSerialized(t);console.log("worker code a2",{merkleTree:a});const{accessTokenSiblings:s,accessTokenSiblingSides:r}=m.calcAccessTokenSiblingsAndSides(e,a);console.log("worker code a3",{accessTokenSiblings:s,accessTokenSiblingSides:r}),c.postMessageToMainThread({accessTokenSiblings:s,accessTokenSiblingSides:r})},T=o=>{const{inputUtxosSerialized:e,onChainCreation:t,proverVersion:a}=o.data,s=e.map(i=>i.map(n=>new S.Utxo(n)));let r=[];a==="v1x0"?r=s.map((i,n)=>i.map(l=>t[n]?"0":l.getNullifier())):r=s.map(i=>i.map(n=>n.amount===0n?"0":n.getNullifier())),c.postMessageToMainThread(r)},g=async o=>{try{await A.preProcessing();const{type:e}=o.payload;switch(e){case d.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES:k(o.payload);return;case d.ZKProofWorkerActionType.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES:p(o.payload);return;case d.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS:T(o.payload);return;default:throw Error(`Unknown worker message type ${e}`)}}catch(e){console.error(e),c.postErrorToMainThread(e)}};c.attachWorkerSideOnMessage(g);exports.default=c;exports.handleBuildInNullifiers=T;exports.handleCalcAccessTokenSiblingAndSides=p;exports.handleCalcCommitmentsSiblingAndSides=k;exports.onWorkerMessage=g;
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import { preProcessing as S } from "../../crypto/preProcessing.mjs";
|
|
2
|
-
import { Utxo as
|
|
2
|
+
import { Utxo as d } from "../../data-structures/utxo/Utxo.mjs";
|
|
3
3
|
import { calcCommitmentsSiblingAndSides as T, calcAccessTokenSiblingsAndSides as g } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
4
4
|
import { WorkerProxy as k } from "../workerProxy.mjs";
|
|
5
5
|
import { ZKProofWorkerActionType as m } from "./zkProofWorker.types.mjs";
|
|
6
|
-
import { contructMerkleTreeFromSerialized as
|
|
6
|
+
import { contructMerkleTreeFromSerialized as p } from "../../functions/utils/merkleTree.utils.mjs";
|
|
7
7
|
const c = new k(), u = (o) => {
|
|
8
|
-
const { inputUtxosSerialized: e, merkleTreeSerialized: t } = o.data, a =
|
|
9
|
-
(
|
|
10
|
-
), { inCommitmentSiblings:
|
|
11
|
-
c.postMessageToMainThread({ inCommitmentSiblings:
|
|
8
|
+
const { inputUtxosSerialized: e, merkleTreeSerialized: t } = o.data, a = p(t), s = e.map(
|
|
9
|
+
(n) => n.map((l) => new d(l))
|
|
10
|
+
), { inCommitmentSiblings: r, inCommitmentSiblingSides: i } = T(s, a);
|
|
11
|
+
c.postMessageToMainThread({ inCommitmentSiblings: r, inCommitmentSiblingSides: i });
|
|
12
12
|
}, C = (o) => {
|
|
13
|
-
const { accessKey: e, merkleTreeAccessTokenSerialized: t } = o.data
|
|
14
|
-
|
|
13
|
+
const { accessKey: e, merkleTreeAccessTokenSerialized: t } = o.data;
|
|
14
|
+
console.log("worker code a1", { accessKey: e, merkleTreeAccessTokenSerialized: t });
|
|
15
|
+
const a = p(t);
|
|
16
|
+
console.log("worker code a2", { merkleTree: a });
|
|
17
|
+
const { accessTokenSiblings: s, accessTokenSiblingSides: r } = g(e, a);
|
|
18
|
+
console.log("worker code a3", { accessTokenSiblings: s, accessTokenSiblingSides: r }), c.postMessageToMainThread({ accessTokenSiblings: s, accessTokenSiblingSides: r });
|
|
15
19
|
}, f = (o) => {
|
|
16
|
-
const { inputUtxosSerialized: e, onChainCreation: t, proverVersion: a } = o.data,
|
|
17
|
-
(
|
|
20
|
+
const { inputUtxosSerialized: e, onChainCreation: t, proverVersion: a } = o.data, s = e.map(
|
|
21
|
+
(i) => i.map((n) => new d(n))
|
|
18
22
|
);
|
|
19
|
-
let
|
|
20
|
-
a === "v1x0" ?
|
|
21
|
-
(
|
|
22
|
-
) :
|
|
23
|
+
let r = [];
|
|
24
|
+
a === "v1x0" ? r = s.map(
|
|
25
|
+
(i, n) => i.map((l) => t[n] ? "0" : l.getNullifier())
|
|
26
|
+
) : r = s.map((i) => i.map((n) => n.amount === 0n ? "0" : n.getNullifier())), c.postMessageToMainThread(r);
|
|
23
27
|
}, A = async (o) => {
|
|
24
28
|
try {
|
|
25
29
|
await S();
|