h_test_1 0.0.21 → 0.0.22
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/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
|
@@ -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
|
};
|
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
|
};
|