h_test_1 0.0.26 → 0.0.28
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/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +4 -2
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.mjs +57 -61
- package/data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.cjs +1 -1
- package/data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.mjs +8 -13
- package/data-structures/provider-adapter/IProviderAdapter.d.ts +1 -0
- package/functions/pre-transaction/getKycAndSignatureData.cjs +1 -1
- package/functions/pre-transaction/getKycAndSignatureData.mjs +12 -14
- package/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/functions/snarkjs/constructGeneralZkProof.mjs +99 -105
- 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 +10 -12
- package/functions/snarkjs/getMerkleTreeSiblingsAndRootHashes.cjs +1 -1
- package/functions/snarkjs/getMerkleTreeSiblingsAndRootHashes.mjs +86 -106
- package/package.json +1 -1
- package/providers/EthersProviderAdapter.cjs +1 -1
- package/providers/EthersProviderAdapter.d.ts +1 -0
- package/providers/EthersProviderAdapter.mjs +9 -6
- package/providers/SolanaProviderAdapter.cjs +1 -1
- package/providers/SolanaProviderAdapter.d.ts +1 -0
- package/providers/SolanaProviderAdapter.mjs +9 -6
- package/providers/TronProviderAdapter.cjs +1 -1
- package/providers/TronProviderAdapter.d.ts +1 -0
- package/providers/TronProviderAdapter.mjs +3 -0
- package/providers/WagmiProviderAdapter.cjs +1 -1
- package/providers/WagmiProviderAdapter.d.ts +2 -1
- package/providers/WagmiProviderAdapter.mjs +3 -0
- package/webworker/performTaskWithWorker.cjs +1 -1
- package/webworker/performTaskWithWorker.mjs +21 -21
- 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 +26 -28
|
@@ -1,140 +1,134 @@
|
|
|
1
|
-
import { isTronLike as
|
|
2
|
-
import { zeroAddress as
|
|
3
|
-
import { Utxo as
|
|
4
|
-
import { randomBigInt as
|
|
5
|
-
import { calcAmountChanges as
|
|
6
|
-
import { generateCircomData as
|
|
7
|
-
import { generateZkProof as
|
|
8
|
-
import { defaultHinkalLogicArgs as
|
|
9
|
-
import { generateFeeStructure as
|
|
10
|
-
import { hinkalCheckTronTokenRegistry as
|
|
11
|
-
import { Logger as
|
|
12
|
-
import { getDataFromWorkers as
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
),
|
|
19
|
-
console.log("hinkalDeposit sa1", { userKeys: i });
|
|
20
|
-
const {
|
|
1
|
+
import { isTronLike as q, chainIds as x } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { zeroAddress as i, defaultSignatureData as ee } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { Utxo as te } from "../../data-structures/utxo/Utxo.mjs";
|
|
4
|
+
import { randomBigInt as ae } from "../web3/etherFunctions.mjs";
|
|
5
|
+
import { calcAmountChanges as p, calcEncryptedOutputs as me, buildOutCommitments as ne, calcPublicSignalCount as oe, getSlippageValues as re, createCallDataHash as ie, calcStealthAddressStructure as de } from "./common.snarkjs.mjs";
|
|
6
|
+
import { generateCircomData as se } from "./generateCircomData.mjs";
|
|
7
|
+
import { generateZkProof as ce } from "./generateZkProof.mjs";
|
|
8
|
+
import { defaultHinkalLogicArgs as le } from "../../types/hinkal.types.mjs";
|
|
9
|
+
import { generateFeeStructure as fe } from "../utils/fees.utils.mjs";
|
|
10
|
+
import { hinkalCheckTronTokenRegistry as ke, hinkalCheckTokenRegistry as Se, createHinkalHelperFromData as He } from "../../data-structures/Hinkal/hinkalCheckTokenRegistry.mjs";
|
|
11
|
+
import { Logger as pe } from "../../error-handling/logger.mjs";
|
|
12
|
+
import { getDataFromWorkers as Ae } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
|
|
13
|
+
const ye = async (d, W, j, t, m, s, C, b, c, h, G, P = i, r = x.localhost, l = t.map(() => !1), z = t.map(() => 0n), D = void 0, v = !1, n = void 0, f, k = void 0, J, w = ee, R) => {
|
|
14
|
+
const u = p(t, m), S = t.map((e) => e[0].erc20TokenAddress), A = me(m), g = s.getShieldedPrivateKey(), y = te.findCorrectRandomization(ae(31), g), B = q(r) ? await ke(S, p(t, m, !0), r) : await Se(
|
|
15
|
+
J ?? He(r),
|
|
16
|
+
S,
|
|
17
|
+
p(t, m, !0)
|
|
18
|
+
), Q = q(r) ? v || B : v, X = t.map((e) => e.map((a) => a.getConstructableParams())), {
|
|
21
19
|
inCommitmentSiblings: Y,
|
|
22
20
|
inCommitmentSiblingSides: _,
|
|
23
21
|
accessTokenSiblings: $,
|
|
24
|
-
accessTokenSiblingSides:
|
|
25
|
-
rootHashHinkal:
|
|
26
|
-
rootHashAccessToken:
|
|
27
|
-
inNullifiers:
|
|
28
|
-
} = await
|
|
22
|
+
accessTokenSiblingSides: K,
|
|
23
|
+
rootHashHinkal: I,
|
|
24
|
+
rootHashAccessToken: O,
|
|
25
|
+
inNullifiers: E
|
|
26
|
+
} = await Ae(
|
|
29
27
|
r,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
W,
|
|
29
|
+
j,
|
|
30
|
+
s,
|
|
33
31
|
X,
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
Q,
|
|
33
|
+
B,
|
|
36
34
|
l,
|
|
37
35
|
d
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
inRandomizations: a.map((t) => t.map((e) => e.randomization)),
|
|
47
|
-
inNullifiers: N,
|
|
36
|
+
), F = ne(d, m, l), o = {
|
|
37
|
+
rootHashHinkal: I,
|
|
38
|
+
shieldedPrivateKey: g,
|
|
39
|
+
erc20TokenAddresses: S,
|
|
40
|
+
inAmounts: t.map((e) => e.map((a) => a.amount.toString())),
|
|
41
|
+
inTimeStamps: t.map((e) => e.map((a) => a.timeStamp)),
|
|
42
|
+
inRandomizations: t.map((e) => e.map((a) => a.randomization)),
|
|
43
|
+
inNullifiers: E,
|
|
48
44
|
inCommitmentSiblings: Y,
|
|
49
45
|
inCommitmentSiblingSides: _,
|
|
50
|
-
outAmounts:
|
|
51
|
-
outTimeStamp: BigInt(
|
|
52
|
-
outPublicKeys:
|
|
53
|
-
extraRandomization:
|
|
54
|
-
amountChanges:
|
|
55
|
-
outCommitments:
|
|
56
|
-
rootHashAccessToken:
|
|
46
|
+
outAmounts: m.map((e) => e.map((a) => a.amount.toString())),
|
|
47
|
+
outTimeStamp: BigInt(m[0][0].timeStamp),
|
|
48
|
+
outPublicKeys: m.map((e) => e.map((a) => a.getStealthAddress())),
|
|
49
|
+
extraRandomization: y,
|
|
50
|
+
amountChanges: u,
|
|
51
|
+
outCommitments: F,
|
|
52
|
+
rootHashAccessToken: O,
|
|
57
53
|
accessTokenSiblings: $,
|
|
58
|
-
accessTokenSiblingSides:
|
|
54
|
+
accessTokenSiblingSides: K,
|
|
59
55
|
calldataHash: 0n
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
const T =
|
|
56
|
+
}, H = t.map((e) => e[0].tokenId ?? 0), N = H.reduce((e, a) => e + a, 0) > 0 ? H.length : 0;
|
|
57
|
+
N > 0 && (o.tokenIds = H);
|
|
58
|
+
const T = oe(
|
|
63
59
|
C,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
o.erc20TokenAddresses,
|
|
61
|
+
o.amountChanges,
|
|
62
|
+
o.inNullifiers,
|
|
63
|
+
o.outCommitments,
|
|
64
|
+
N
|
|
69
65
|
);
|
|
70
|
-
if (!
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
66
|
+
if (!n) {
|
|
67
|
+
n = le(u.length, s), n.interactionAddress = c ?? i;
|
|
68
|
+
const e = s.getInHinkalAddress(n.interactionAddress);
|
|
69
|
+
n.inHinkalAddress = e;
|
|
74
70
|
}
|
|
75
71
|
if (d === "v1x1") {
|
|
76
|
-
if (
|
|
72
|
+
if (o.interactionAddress = n?.interactionAddress ?? c ?? i, s.getInHinkalAddress(o.interactionAddress) !== n.inHinkalAddress)
|
|
77
73
|
throw new Error("inHinkalAddress mismatch");
|
|
78
|
-
|
|
79
|
-
({ externalApprovalAddresses:
|
|
80
|
-
) ?? [
|
|
74
|
+
o.externalApprovalAddresses = n.useApprovalUtxoData?.map(
|
|
75
|
+
({ externalApprovalAddresses: e }) => e
|
|
76
|
+
) ?? [i, i, i];
|
|
81
77
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
k || (k = fe(
|
|
79
|
+
z,
|
|
80
|
+
t.map((e) => e[0].erc20TokenAddress)
|
|
85
81
|
));
|
|
86
|
-
const
|
|
87
|
-
|
|
82
|
+
const Z = p(t, m, !0);
|
|
83
|
+
f || (f = re(Z, n)), pe.log({ publicSignalCount: T }), o.calldataHash = ie(
|
|
88
84
|
d,
|
|
89
85
|
T,
|
|
90
|
-
|
|
86
|
+
P,
|
|
91
87
|
c,
|
|
92
|
-
D,
|
|
93
88
|
b,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
l,
|
|
99
|
-
m,
|
|
89
|
+
h,
|
|
90
|
+
A,
|
|
91
|
+
z,
|
|
92
|
+
D,
|
|
100
93
|
f,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
N,
|
|
109
|
-
E,
|
|
94
|
+
l,
|
|
95
|
+
n,
|
|
96
|
+
k,
|
|
97
|
+
w,
|
|
98
|
+
R
|
|
99
|
+
);
|
|
100
|
+
const { zkCallData: M } = await ce(d, r, C, o, G), V = de(y, g), L = se(
|
|
110
101
|
F,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
102
|
+
E,
|
|
103
|
+
I,
|
|
104
|
+
O,
|
|
105
|
+
Z,
|
|
106
|
+
S,
|
|
107
|
+
m,
|
|
108
|
+
A,
|
|
115
109
|
T,
|
|
116
|
-
D,
|
|
117
|
-
c,
|
|
118
110
|
b,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
c,
|
|
112
|
+
h,
|
|
113
|
+
P,
|
|
114
|
+
o.calldataHash,
|
|
115
|
+
H,
|
|
122
116
|
V,
|
|
123
117
|
l,
|
|
124
|
-
|
|
118
|
+
D,
|
|
125
119
|
void 0,
|
|
126
|
-
|
|
127
|
-
k,
|
|
120
|
+
n,
|
|
128
121
|
f,
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
k,
|
|
123
|
+
w,
|
|
124
|
+
R
|
|
131
125
|
), U = {
|
|
132
|
-
tokenNumber:
|
|
133
|
-
nullifierAmount:
|
|
134
|
-
outputAmount:
|
|
126
|
+
tokenNumber: t.length,
|
|
127
|
+
nullifierAmount: t[0].length,
|
|
128
|
+
outputAmount: m[0].length
|
|
135
129
|
};
|
|
136
|
-
return { zkCallData:
|
|
130
|
+
return { zkCallData: M, circomData: L, dimData: U, encryptedOutputs: A };
|
|
137
131
|
};
|
|
138
132
|
export {
|
|
139
|
-
|
|
133
|
+
ye as constructZkProof
|
|
140
134
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../../error-handling/logger.cjs"),c=require("./generateZkProofEnclave.cjs"),f=require("./generateZkProofSelf.cjs"),l=async(e,r,o,t,n)=>{if(n)try{return await c.generateZkProofEnclave(e,r,o,t)}catch(a){g.Logger.error("enclave proof error",a)}return f.generateZkProofSelf(e,r,o,t)};exports.generateZkProof=l;
|
|
@@ -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 c } from "./generateZkProofEnclave.mjs";
|
|
3
|
+
import { generateZkProofSelf as g } from "./generateZkProofSelf.mjs";
|
|
4
|
+
const p = async (r, o, e, t, f) => {
|
|
5
|
+
if (f)
|
|
6
6
|
try {
|
|
7
|
-
return await
|
|
8
|
-
} catch (
|
|
9
|
-
|
|
7
|
+
return await c(r, o, e, t);
|
|
8
|
+
} catch (a) {
|
|
9
|
+
n.error("enclave proof error", a);
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return g(r, o, e, t);
|
|
12
12
|
};
|
|
13
13
|
export {
|
|
14
|
-
|
|
14
|
+
p 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 o=require("./getZKFiles.cjs"),k=require("../../webworker/performTaskWithWorker.cjs"),c=require("../../webworker/snarkjsWorker/snarkjsWorker.types.cjs"),y=require("../../webworker/worker.registry.cjs"),S=async(r,e,t,a)=>{const s=o.getWASMFile(r,t,e),n=o.getZKeyFile(r,t,e),{publicSignals:i,zkCallData:l}=await k.performTaskWithWorker({type:y.WorkerVariant.SnarkJS,payload:{type:c.SnarkJSWorkerActionType.FULL_PROVE,data:{input:a,chainId:e,wasmFilePath:s,zKeyFilePath:n}}});return{zkCallData:l,publicSignals:i}};exports.generateZkProofSelf=S;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { getWASMFile as
|
|
2
|
-
import { performTaskWithWorker as
|
|
3
|
-
import { SnarkJSWorkerActionType as
|
|
4
|
-
import { WorkerVariant as
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const { publicSignals: p, zkCallData: i } = await s({
|
|
9
|
-
type: f.SnarkJS,
|
|
1
|
+
import { getWASMFile as m, getZKeyFile as n } from "./getZKFiles.mjs";
|
|
2
|
+
import { performTaskWithWorker as k } from "../../webworker/performTaskWithWorker.mjs";
|
|
3
|
+
import { SnarkJSWorkerActionType as s } from "../../webworker/snarkjsWorker/snarkjsWorker.types.mjs";
|
|
4
|
+
import { WorkerVariant as y } from "../../webworker/worker.registry.mjs";
|
|
5
|
+
const W = async (o, t, r, a) => {
|
|
6
|
+
const e = m(o, r, t), l = n(o, r, t), { publicSignals: p, zkCallData: i } = await k({
|
|
7
|
+
type: y.SnarkJS,
|
|
10
8
|
payload: {
|
|
11
|
-
type:
|
|
12
|
-
data: { input:
|
|
9
|
+
type: s.FULL_PROVE,
|
|
10
|
+
data: { input: a, chainId: t, wasmFilePath: e, zKeyFilePath: l }
|
|
13
11
|
}
|
|
14
12
|
});
|
|
15
13
|
return { zkCallData: i, publicSignals: p };
|
|
16
14
|
};
|
|
17
15
|
export {
|
|
18
|
-
|
|
16
|
+
W as generateZkProofSelf
|
|
19
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../data-structures/merkle-tree/MerkleTree.cjs"),C=require("../../data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.cjs"),m=require("../../webworker/performTaskWithWorker.cjs"),g=require("../../webworker/worker.registry.cjs"),T=require("../../webworker/zkProofWorker/zkProofWorker.types.cjs"),A=require("./fetchMerkleTreeSiblings.cjs"),H=require("../utils/amounts.utils.cjs"),P=require("../../crypto/poseidon.cjs"),W=require("../../constants/vite.constants.cjs"),_=require("./fetchOnChainRootHashes.cjs"),y=async(e,i)=>{const s=e.getRootHash();if(s===void 0)throw new Error("Root hash not available from patched merkle tree");const o=await m.performTaskWithWorker({type:g.WorkerVariant.ZKProof,payload:{type:T.ZKProofWorkerActionType.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,data:{accessKey:i,merkleTreeAccessTokenSerialized:e.toJSON()}}});return{accessTokenSiblings:o.accessTokenSiblings,accessTokenSiblingSides:o.accessTokenSiblingSides,rootHashAccessToken:s}},N=async(e,i,s,o,t,n)=>{const a=s.getAccessKey(),r=C.getPatchedAccessTokenMerkleTree(i,a,t,n),S=e.getRootHash();if(S===void 0)throw new Error("Root hash not available from hinkal merkle tree");let l,c;return W.isNode?(l=await y(r,a),c=await m.performTaskWithWorker({type:g.WorkerVariant.ZKProof,payload:{type:T.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES,data:{inputUtxosSerialized:o,merkleTreeSerialized:e.toJSON()}}})):[l,c]=await Promise.all([y(r,a),m.performTaskWithWorker({type:g.WorkerVariant.ZKProof,payload:{type:T.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES,data:{inputUtxosSerialized:o,merkleTreeSerialized:e.toJSON()}}})]),{inCommitmentSiblings:c.inCommitmentSiblings,inCommitmentSiblingSides:c.inCommitmentSiblingSides,accessTokenSiblings:l.accessTokenSiblings,accessTokenSiblingSides:l.accessTokenSiblingSides,rootHashHinkal:S,rootHashAccessToken:l.rootHashAccessToken}},R=async(e,i,s,o,t)=>{const n=i.getAccessKey();if(!t||o){const S=u.MerkleTree.create(P.poseidonFunction,0n),l=C.getPatchedAccessTokenMerkleTree(S,n,o,t),[c,k]=await Promise.all([y(l,n),A.fetchMerkleTreeSiblings(e,s,n)]);return{inCommitmentSiblings:k.inCommitmentSiblings,inCommitmentSiblingSides:k.inCommitmentSiblingSides,accessTokenSiblings:c.accessTokenSiblings,accessTokenSiblingSides:c.accessTokenSiblingSides,rootHashHinkal:H.toBigInt(k.rootHashHinkal),rootHashAccessToken:c.rootHashAccessToken}}const r=await A.fetchMerkleTreeSiblings(e,s,n);return{inCommitmentSiblings:r.inCommitmentSiblings,inCommitmentSiblingSides:r.inCommitmentSiblingSides,accessTokenSiblings:r.accessTokenSiblings,accessTokenSiblingSides:r.accessTokenSiblingSides,rootHashHinkal:H.toBigInt(r.rootHashHinkal),rootHashAccessToken:H.toBigInt(r.rootHashAccessToken)}},I=async(e,i,s)=>{if(!i||!s)return!1;try{const o=i.getRootHash(),t=s.getRootHash();if(!o||!t)return!1;const{hinkalRootHash:n,accessTokenRootHash:a}=await _.fetchOnChainRootHashes(e);return o===n&&t===a}catch{return!1}},p=async(e,i,s,o,t,n,a)=>await I(e,n,a)?N(n,a,i,s,o,t):R(e,i,s,o,t),M=async(e,i,s,o,t,n,a,r,S)=>{if(W.isNode){const{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:h,rootHashHinkal:b,rootHashAccessToken:d}=await p(e,o,t,n,a,i,s),f=await m.performTaskWithWorker({type:g.WorkerVariant.ZKProof,payload:{type:T.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:t,onChainCreation:r,proverVersion:S}}});return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:h,rootHashHinkal:b,rootHashAccessToken:d,inNullifiers:f}}else{const[{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:h,rootHashHinkal:b,rootHashAccessToken:d},f]=await Promise.all([p(e,o,t,n,a,i,s),m.performTaskWithWorker({type:g.WorkerVariant.ZKProof,payload:{type:T.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:t,onChainCreation:r,proverVersion:S}}})]);return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:h,rootHashHinkal:b,rootHashAccessToken:d,inNullifiers:f}}};exports.getDataFromWorkers=M;exports.getMerkleTreeSiblingsAndRootHashes=p;
|
|
@@ -1,161 +1,141 @@
|
|
|
1
1
|
import { MerkleTree as R } from "../../data-structures/merkle-tree/MerkleTree.mjs";
|
|
2
|
-
import { getPatchedAccessTokenMerkleTree as
|
|
2
|
+
import { getPatchedAccessTokenMerkleTree as A } from "../../data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.mjs";
|
|
3
3
|
import { performTaskWithWorker as g } from "../../webworker/performTaskWithWorker.mjs";
|
|
4
4
|
import { WorkerVariant as k } from "../../webworker/worker.registry.mjs";
|
|
5
5
|
import { ZKProofWorkerActionType as b } from "../../webworker/zkProofWorker/zkProofWorker.types.mjs";
|
|
6
6
|
import { fetchMerkleTreeSiblings as C } from "./fetchMerkleTreeSiblings.mjs";
|
|
7
|
-
import { toBigInt as
|
|
8
|
-
import { poseidonFunction as
|
|
9
|
-
import { isNode as
|
|
10
|
-
import { fetchOnChainRootHashes as
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
accessKey: i,
|
|
15
|
-
rootHash: s,
|
|
16
|
-
patchedMerkleTree: o,
|
|
17
|
-
tjson: o.toJSON()
|
|
18
|
-
}), s === void 0)
|
|
7
|
+
import { toBigInt as d } from "../utils/amounts.utils.mjs";
|
|
8
|
+
import { poseidonFunction as I } from "../../crypto/poseidon.mjs";
|
|
9
|
+
import { isNode as N } from "../../constants/vite.constants.mjs";
|
|
10
|
+
import { fetchOnChainRootHashes as _ } from "./fetchOnChainRootHashes.mjs";
|
|
11
|
+
const p = async (o, n) => {
|
|
12
|
+
const e = o.getRootHash();
|
|
13
|
+
if (e === void 0)
|
|
19
14
|
throw new Error("Root hash not available from patched merkle tree");
|
|
20
|
-
const
|
|
15
|
+
const s = await g({
|
|
21
16
|
type: k.ZKProof,
|
|
22
17
|
payload: {
|
|
23
18
|
type: b.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,
|
|
24
19
|
data: {
|
|
25
|
-
accessKey:
|
|
20
|
+
accessKey: n,
|
|
26
21
|
merkleTreeAccessTokenSerialized: o.toJSON()
|
|
27
22
|
}
|
|
28
23
|
}
|
|
29
24
|
});
|
|
30
|
-
return
|
|
31
|
-
accessTokenSiblings:
|
|
32
|
-
accessTokenSiblingSides:
|
|
33
|
-
rootHashAccessToken:
|
|
25
|
+
return {
|
|
26
|
+
accessTokenSiblings: s.accessTokenSiblings,
|
|
27
|
+
accessTokenSiblingSides: s.accessTokenSiblingSides,
|
|
28
|
+
rootHashAccessToken: e
|
|
34
29
|
};
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const c = N(
|
|
30
|
+
}, L = async (o, n, e, s, i, t) => {
|
|
31
|
+
const c = e.getAccessKey(), a = A(
|
|
32
|
+
n,
|
|
33
|
+
c,
|
|
40
34
|
i,
|
|
41
|
-
|
|
42
|
-
t,
|
|
43
|
-
n
|
|
35
|
+
t
|
|
44
36
|
), m = o.getRootHash();
|
|
45
37
|
if (m === void 0)
|
|
46
38
|
throw new Error("Root hash not available from hinkal merkle tree");
|
|
47
|
-
let
|
|
48
|
-
return
|
|
39
|
+
let l, r;
|
|
40
|
+
return N ? (l = await p(a, c), r = await g({
|
|
49
41
|
type: k.ZKProof,
|
|
50
42
|
payload: {
|
|
51
43
|
type: b.CALC_COMMITMENTS_SIBLING_AND_SIDES,
|
|
52
|
-
data: { inputUtxosSerialized:
|
|
44
|
+
data: { inputUtxosSerialized: s, merkleTreeSerialized: o.toJSON() }
|
|
53
45
|
}
|
|
54
|
-
})) : [
|
|
55
|
-
|
|
46
|
+
})) : [l, r] = await Promise.all([
|
|
47
|
+
p(a, c),
|
|
56
48
|
g({
|
|
57
49
|
type: k.ZKProof,
|
|
58
50
|
payload: {
|
|
59
51
|
type: b.CALC_COMMITMENTS_SIBLING_AND_SIDES,
|
|
60
|
-
data: { inputUtxosSerialized:
|
|
52
|
+
data: { inputUtxosSerialized: s, merkleTreeSerialized: o.toJSON() }
|
|
61
53
|
}
|
|
62
54
|
})
|
|
63
55
|
]), {
|
|
64
|
-
inCommitmentSiblings:
|
|
65
|
-
inCommitmentSiblingSides:
|
|
66
|
-
accessTokenSiblings:
|
|
67
|
-
accessTokenSiblingSides:
|
|
56
|
+
inCommitmentSiblings: r.inCommitmentSiblings,
|
|
57
|
+
inCommitmentSiblingSides: r.inCommitmentSiblingSides,
|
|
58
|
+
accessTokenSiblings: l.accessTokenSiblings,
|
|
59
|
+
accessTokenSiblingSides: l.accessTokenSiblingSides,
|
|
68
60
|
rootHashHinkal: m,
|
|
69
|
-
rootHashAccessToken:
|
|
61
|
+
rootHashAccessToken: l.rootHashAccessToken
|
|
70
62
|
};
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const a = !t || e;
|
|
76
|
-
if (console.log("ba4", { needsPatching: a }), a) {
|
|
77
|
-
console.log("ba5");
|
|
78
|
-
const m = R.create(_, 0n);
|
|
79
|
-
console.log("ba6", { emptyMerkleTreeAccessToken: m });
|
|
80
|
-
const r = N(
|
|
63
|
+
}, w = async (o, n, e, s, i) => {
|
|
64
|
+
const t = n.getAccessKey();
|
|
65
|
+
if (!i || s) {
|
|
66
|
+
const m = R.create(I, 0n), l = A(
|
|
81
67
|
m,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
d(r, n),
|
|
89
|
-
C(o, s, n)
|
|
68
|
+
t,
|
|
69
|
+
s,
|
|
70
|
+
i
|
|
71
|
+
), [r, S] = await Promise.all([
|
|
72
|
+
p(l, t),
|
|
73
|
+
C(o, e, t)
|
|
90
74
|
]);
|
|
91
|
-
return
|
|
75
|
+
return {
|
|
92
76
|
inCommitmentSiblings: S.inCommitmentSiblings,
|
|
93
77
|
inCommitmentSiblingSides: S.inCommitmentSiblingSides,
|
|
94
|
-
accessTokenSiblings:
|
|
95
|
-
accessTokenSiblingSides:
|
|
96
|
-
rootHashHinkal:
|
|
97
|
-
rootHashAccessToken:
|
|
78
|
+
accessTokenSiblings: r.accessTokenSiblings,
|
|
79
|
+
accessTokenSiblingSides: r.accessTokenSiblingSides,
|
|
80
|
+
rootHashHinkal: d(S.rootHashHinkal),
|
|
81
|
+
rootHashAccessToken: r.rootHashAccessToken
|
|
98
82
|
};
|
|
99
83
|
}
|
|
100
|
-
|
|
101
|
-
const c = await C(o, s, n);
|
|
84
|
+
const a = await C(o, e, t);
|
|
102
85
|
return {
|
|
103
|
-
inCommitmentSiblings:
|
|
104
|
-
inCommitmentSiblingSides:
|
|
105
|
-
accessTokenSiblings:
|
|
106
|
-
accessTokenSiblingSides:
|
|
107
|
-
rootHashHinkal:
|
|
108
|
-
rootHashAccessToken:
|
|
86
|
+
inCommitmentSiblings: a.inCommitmentSiblings,
|
|
87
|
+
inCommitmentSiblingSides: a.inCommitmentSiblingSides,
|
|
88
|
+
accessTokenSiblings: a.accessTokenSiblings,
|
|
89
|
+
accessTokenSiblingSides: a.accessTokenSiblingSides,
|
|
90
|
+
rootHashHinkal: d(a.rootHashHinkal),
|
|
91
|
+
rootHashAccessToken: d(a.rootHashAccessToken)
|
|
109
92
|
};
|
|
110
|
-
},
|
|
111
|
-
if (!
|
|
93
|
+
}, P = async (o, n, e) => {
|
|
94
|
+
if (!n || !e)
|
|
112
95
|
return !1;
|
|
113
96
|
try {
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
97
|
+
const s = n.getRootHash(), i = e.getRootHash();
|
|
98
|
+
if (!s || !i)
|
|
116
99
|
return !1;
|
|
117
|
-
const { hinkalRootHash:
|
|
118
|
-
return
|
|
100
|
+
const { hinkalRootHash: t, accessTokenRootHash: c } = await _(o);
|
|
101
|
+
return s === t && i === c;
|
|
119
102
|
} catch {
|
|
120
103
|
return !1;
|
|
121
104
|
}
|
|
122
|
-
}, y = async (o,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
) : D(o, i, s, e, t);
|
|
132
|
-
}, J = async (o, i, s, e, t, n, a, c, m) => {
|
|
133
|
-
if (A) {
|
|
105
|
+
}, y = async (o, n, e, s, i, t, c) => await P(o, t, c) ? L(
|
|
106
|
+
t,
|
|
107
|
+
c,
|
|
108
|
+
n,
|
|
109
|
+
e,
|
|
110
|
+
s,
|
|
111
|
+
i
|
|
112
|
+
) : w(o, n, e, s, i), v = async (o, n, e, s, i, t, c, a, m) => {
|
|
113
|
+
if (N) {
|
|
134
114
|
const {
|
|
135
|
-
inCommitmentSiblings:
|
|
136
|
-
inCommitmentSiblingSides:
|
|
115
|
+
inCommitmentSiblings: l,
|
|
116
|
+
inCommitmentSiblingSides: r,
|
|
137
117
|
accessTokenSiblings: S,
|
|
138
118
|
accessTokenSiblingSides: h,
|
|
139
119
|
rootHashHinkal: T,
|
|
140
120
|
rootHashAccessToken: f
|
|
141
121
|
} = await y(
|
|
142
122
|
o,
|
|
143
|
-
|
|
123
|
+
s,
|
|
124
|
+
i,
|
|
144
125
|
t,
|
|
126
|
+
c,
|
|
145
127
|
n,
|
|
146
|
-
|
|
147
|
-
i,
|
|
148
|
-
s
|
|
128
|
+
e
|
|
149
129
|
), H = await g({
|
|
150
130
|
type: k.ZKProof,
|
|
151
131
|
payload: {
|
|
152
132
|
type: b.BUILD_IN_NULLIFIERS,
|
|
153
|
-
data: { inputUtxosSerialized:
|
|
133
|
+
data: { inputUtxosSerialized: i, onChainCreation: a, proverVersion: m }
|
|
154
134
|
}
|
|
155
135
|
});
|
|
156
136
|
return {
|
|
157
|
-
inCommitmentSiblings:
|
|
158
|
-
inCommitmentSiblingSides:
|
|
137
|
+
inCommitmentSiblings: l,
|
|
138
|
+
inCommitmentSiblingSides: r,
|
|
159
139
|
accessTokenSiblings: S,
|
|
160
140
|
accessTokenSiblingSides: h,
|
|
161
141
|
rootHashHinkal: T,
|
|
@@ -165,8 +145,8 @@ const d = async (o, i) => {
|
|
|
165
145
|
} else {
|
|
166
146
|
const [
|
|
167
147
|
{
|
|
168
|
-
inCommitmentSiblings:
|
|
169
|
-
inCommitmentSiblingSides:
|
|
148
|
+
inCommitmentSiblings: l,
|
|
149
|
+
inCommitmentSiblingSides: r,
|
|
170
150
|
accessTokenSiblings: S,
|
|
171
151
|
accessTokenSiblingSides: h,
|
|
172
152
|
rootHashHinkal: T,
|
|
@@ -176,24 +156,24 @@ const d = async (o, i) => {
|
|
|
176
156
|
] = await Promise.all([
|
|
177
157
|
y(
|
|
178
158
|
o,
|
|
179
|
-
|
|
159
|
+
s,
|
|
160
|
+
i,
|
|
180
161
|
t,
|
|
162
|
+
c,
|
|
181
163
|
n,
|
|
182
|
-
|
|
183
|
-
i,
|
|
184
|
-
s
|
|
164
|
+
e
|
|
185
165
|
),
|
|
186
166
|
g({
|
|
187
167
|
type: k.ZKProof,
|
|
188
168
|
payload: {
|
|
189
169
|
type: b.BUILD_IN_NULLIFIERS,
|
|
190
|
-
data: { inputUtxosSerialized:
|
|
170
|
+
data: { inputUtxosSerialized: i, onChainCreation: a, proverVersion: m }
|
|
191
171
|
}
|
|
192
172
|
})
|
|
193
173
|
]);
|
|
194
174
|
return {
|
|
195
|
-
inCommitmentSiblings:
|
|
196
|
-
inCommitmentSiblingSides:
|
|
175
|
+
inCommitmentSiblings: l,
|
|
176
|
+
inCommitmentSiblingSides: r,
|
|
197
177
|
accessTokenSiblings: S,
|
|
198
178
|
accessTokenSiblingSides: h,
|
|
199
179
|
rootHashHinkal: T,
|
|
@@ -203,6 +183,6 @@ const d = async (o, i) => {
|
|
|
203
183
|
}
|
|
204
184
|
};
|
|
205
185
|
export {
|
|
206
|
-
|
|
186
|
+
v as getDataFromWorkers,
|
|
207
187
|
y as getMerkleTreeSiblingsAndRootHashes
|
|
208
188
|
};
|