h_test_1 0.0.22 → 0.0.24
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/merkle-tree/getPatchedAccessTokenMerkleTree.cjs +1 -1
- package/data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.mjs +13 -8
- package/functions/snarkjs/getMerkleTreeSiblingsAndRootHashes.cjs +1 -1
- package/functions/snarkjs/getMerkleTreeSiblingsAndRootHashes.mjs +76 -68
- package/package.json +1 -1
- 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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../functions/web3/etherFunctions.cjs"),s=require("../../crypto/poseidon.cjs"),l=require("./MerkleTree.cjs"),g=(n,o,r,t)=>{if(console.log("getPatchedAccessTokenMerkleTree a1",{merkleTreeAccessToken:n,accessKey:o,patchAccessTokenMerkleTree:r,kycRequired:t}),!t||r){const e=l.MerkleTree.create(s.poseidonFunction,0n);return console.log("getPatchedAccessTokenMerkleTree a2",{tree:e}),e.insert(BigInt(o),e.getStartIndex()),t||(e.insert(c.randomBigInt(31),e.getStartIndex()+1n),console.log("getPatchedAccessTokenMerkleTree a3",{tree:e})),console.log("getPatchedAccessTokenMerkleTree a4",{tree:e}),e}return n};exports.getPatchedAccessTokenMerkleTree=g;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { randomBigInt as
|
|
2
|
-
import { poseidonFunction as
|
|
1
|
+
import { randomBigInt as c } from "../../functions/web3/etherFunctions.mjs";
|
|
2
|
+
import { poseidonFunction as g } from "../../crypto/poseidon.mjs";
|
|
3
3
|
import { MerkleTree as s } from "./MerkleTree.mjs";
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const d = (o, r, n, t) => {
|
|
5
|
+
if (console.log("getPatchedAccessTokenMerkleTree a1", {
|
|
6
|
+
merkleTreeAccessToken: o,
|
|
7
|
+
accessKey: r,
|
|
8
|
+
patchAccessTokenMerkleTree: n,
|
|
9
|
+
kycRequired: t
|
|
10
|
+
}), !t || n) {
|
|
11
|
+
const e = s.create(g, 0n);
|
|
12
|
+
return console.log("getPatchedAccessTokenMerkleTree a2", { tree: e }), e.insert(BigInt(r), e.getStartIndex()), t || (e.insert(c(31), e.getStartIndex() + 1n), console.log("getPatchedAccessTokenMerkleTree a3", { tree: e })), console.log("getPatchedAccessTokenMerkleTree a4", { tree: e }), e;
|
|
8
13
|
}
|
|
9
|
-
return
|
|
14
|
+
return o;
|
|
10
15
|
};
|
|
11
16
|
export {
|
|
12
|
-
|
|
17
|
+
d as getPatchedAccessTokenMerkleTree
|
|
13
18
|
};
|
|
@@ -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"),R=require("../../crypto/poseidon.cjs"),C=require("../../constants/vite.constants.cjs"),_=require("./fetchOnChainRootHashes.cjs"),p=async(e,r)=>{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:r,merkleTreeAccessTokenSerialized:e.toJSON()}}});return{accessTokenSiblings:s.accessTokenSiblings,accessTokenSiblingSides:s.accessTokenSiblingSides,rootHashAccessToken:o}},N=async(e,r,o,s,i,n)=>{console.log("hinkalDeposit sa5");const t=o.getAccessKey();console.log("hinkalDeposit sa6",{accessKey:t});const a=A.getPatchedAccessTokenMerkleTree(r,t,i,n),k=e.getRootHash();if(k===void 0)throw new Error("Root hash not available from hinkal merkle tree");let l,c;return C.isNode?(l=await p(a,t),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(a,t),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:k,rootHashAccessToken:l.rootHashAccessToken}},P=async(e,r,o,s,i)=>{console.log("hinkalDeposit sa3");const n=r.getAccessKey();console.log("hinkalDeposit sa4",{accessKey:n});const t=!i||s;if(console.log("ba4",{needsPatching:t}),t){console.log("ba5");const k=W.MerkleTree.create(R.poseidonFunction,0n);console.log("ba6",{emptyMerkleTreeAccessToken:k});const l=A.getPatchedAccessTokenMerkleTree(k,n,s,i);console.log("pre calculating access token siblings and root hash",{accessKey:n});const[c,g]=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:g}),{inCommitmentSiblings:g.inCommitmentSiblings,inCommitmentSiblingSides:g.inCommitmentSiblingSides,accessTokenSiblings:c.accessTokenSiblings,accessTokenSiblingSides:c.accessTokenSiblingSides,rootHashHinkal:H.toBigInt(g.rootHashHinkal),rootHashAccessToken:c.rootHashAccessToken}}console.log("kaksk",{chainId:e,inputUtxosSerialized:o,accessKey:n});const a=await u.fetchMerkleTreeSiblings(e,o,n);return{inCommitmentSiblings:a.inCommitmentSiblings,inCommitmentSiblingSides:a.inCommitmentSiblingSides,accessTokenSiblings:a.accessTokenSiblings,accessTokenSiblingSides:a.accessTokenSiblingSides,rootHashHinkal:H.toBigInt(a.rootHashHinkal),rootHashAccessToken:H.toBigInt(a.rootHashAccessToken)}},I=async(e,r,o)=>{if(!r||!o)return!1;try{const s=r.getRootHash(),i=o.getRootHash();if(!s||!i)return!1;const{hinkalRootHash:n,accessTokenRootHash:t}=await _.fetchOnChainRootHashes(e);return s===n&&i===t}catch{return!1}},y=async(e,r,o,s,i,n,t)=>{const a=await I(e,n,t);return console.log("hinkalDeposit sa2",{isLocalFresh:a}),a?N(n,t,r,o,s,i):P(e,r,o,s,i)},M=async(e,r,o,s,i,n,t,a,k)=>{if(C.isNode){const{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:g,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d}=await y(e,s,i,n,t,r,o),f=await S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:i,onChainCreation:a,proverVersion:k}}});return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:g,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d,inNullifiers:f}}else{const[{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:g,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d},f]=await Promise.all([y(e,s,i,n,t,r,o),S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:i,onChainCreation:a,proverVersion:k}}})]);return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:g,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d,inNullifiers:f}}};exports.getDataFromWorkers=M;exports.getMerkleTreeSiblingsAndRootHashes=y;
|
|
@@ -2,57 +2,57 @@ import { MerkleTree as R } from "../../data-structures/merkle-tree/MerkleTree.mj
|
|
|
2
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
|
-
import { ZKProofWorkerActionType as
|
|
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
|
|
7
|
+
import { toBigInt as p } from "../utils/amounts.utils.mjs";
|
|
8
|
+
import { poseidonFunction as _ } from "../../crypto/poseidon.mjs";
|
|
9
9
|
import { isNode as N } from "../../constants/vite.constants.mjs";
|
|
10
|
-
import { fetchOnChainRootHashes as
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
10
|
+
import { fetchOnChainRootHashes as I } from "./fetchOnChainRootHashes.mjs";
|
|
11
|
+
const d = async (o, c) => {
|
|
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
|
-
type:
|
|
18
|
+
type: b.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,
|
|
19
19
|
data: {
|
|
20
|
-
accessKey:
|
|
20
|
+
accessKey: c,
|
|
21
21
|
merkleTreeAccessTokenSerialized: o.toJSON()
|
|
22
22
|
}
|
|
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,
|
|
30
|
+
}, w = async (o, c, s, e, i, n) => {
|
|
31
31
|
console.log("hinkalDeposit sa5");
|
|
32
|
-
const
|
|
33
|
-
console.log("hinkalDeposit sa6", { accessKey:
|
|
34
|
-
const
|
|
35
|
-
a,
|
|
32
|
+
const t = s.getAccessKey();
|
|
33
|
+
console.log("hinkalDeposit sa6", { accessKey: t });
|
|
34
|
+
const a = A(
|
|
36
35
|
c,
|
|
36
|
+
t,
|
|
37
37
|
i,
|
|
38
38
|
n
|
|
39
39
|
), m = o.getRootHash();
|
|
40
40
|
if (m === void 0)
|
|
41
41
|
throw new Error("Root hash not available from hinkal merkle tree");
|
|
42
42
|
let r, l;
|
|
43
|
-
return N ? (r = await
|
|
43
|
+
return N ? (r = await d(a, t), l = await g({
|
|
44
44
|
type: k.ZKProof,
|
|
45
45
|
payload: {
|
|
46
|
-
type:
|
|
47
|
-
data: { inputUtxosSerialized:
|
|
46
|
+
type: b.CALC_COMMITMENTS_SIBLING_AND_SIDES,
|
|
47
|
+
data: { inputUtxosSerialized: e, merkleTreeSerialized: o.toJSON() }
|
|
48
48
|
}
|
|
49
49
|
})) : [r, l] = await Promise.all([
|
|
50
|
-
|
|
50
|
+
d(a, t),
|
|
51
51
|
g({
|
|
52
52
|
type: k.ZKProof,
|
|
53
53
|
payload: {
|
|
54
|
-
type:
|
|
55
|
-
data: { inputUtxosSerialized:
|
|
54
|
+
type: b.CALC_COMMITMENTS_SIBLING_AND_SIDES,
|
|
55
|
+
data: { inputUtxosSerialized: e, merkleTreeSerialized: o.toJSON() }
|
|
56
56
|
}
|
|
57
57
|
})
|
|
58
58
|
]), {
|
|
@@ -63,88 +63,96 @@ const p = async (o, a) => {
|
|
|
63
63
|
rootHashHinkal: m,
|
|
64
64
|
rootHashAccessToken: r.rootHashAccessToken
|
|
65
65
|
};
|
|
66
|
-
}, D = async (o,
|
|
66
|
+
}, D = async (o, c, s, e, i) => {
|
|
67
67
|
console.log("hinkalDeposit sa3");
|
|
68
|
-
const n =
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const n = c.getAccessKey();
|
|
69
|
+
console.log("hinkalDeposit sa4", { accessKey: n });
|
|
70
|
+
const t = !i || e;
|
|
71
|
+
if (console.log("ba4", { needsPatching: t }), t) {
|
|
72
|
+
console.log("ba5");
|
|
73
|
+
const m = R.create(_, 0n);
|
|
74
|
+
console.log("ba6", { emptyMerkleTreeAccessToken: m });
|
|
75
|
+
const r = A(
|
|
71
76
|
m,
|
|
72
77
|
n,
|
|
73
|
-
|
|
78
|
+
e,
|
|
74
79
|
i
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
);
|
|
81
|
+
console.log("pre calculating access token siblings and root hash", { accessKey: n });
|
|
82
|
+
const [l, S] = await Promise.all([
|
|
83
|
+
d(r, n),
|
|
84
|
+
C(o, s, n)
|
|
78
85
|
]);
|
|
79
|
-
return {
|
|
86
|
+
return console.log("post calculating access token siblings and root hash", { accessTokenResult: l, siblingsResponse: S }), {
|
|
80
87
|
inCommitmentSiblings: S.inCommitmentSiblings,
|
|
81
88
|
inCommitmentSiblingSides: S.inCommitmentSiblingSides,
|
|
82
89
|
accessTokenSiblings: l.accessTokenSiblings,
|
|
83
90
|
accessTokenSiblingSides: l.accessTokenSiblingSides,
|
|
84
|
-
rootHashHinkal:
|
|
91
|
+
rootHashHinkal: p(S.rootHashHinkal),
|
|
85
92
|
rootHashAccessToken: l.rootHashAccessToken
|
|
86
93
|
};
|
|
87
94
|
}
|
|
88
|
-
|
|
95
|
+
console.log("kaksk", { chainId: o, inputUtxosSerialized: s, accessKey: n });
|
|
96
|
+
const a = await C(o, s, n);
|
|
89
97
|
return {
|
|
90
|
-
inCommitmentSiblings:
|
|
91
|
-
inCommitmentSiblingSides:
|
|
92
|
-
accessTokenSiblings:
|
|
93
|
-
accessTokenSiblingSides:
|
|
94
|
-
rootHashHinkal:
|
|
95
|
-
rootHashAccessToken:
|
|
98
|
+
inCommitmentSiblings: a.inCommitmentSiblings,
|
|
99
|
+
inCommitmentSiblingSides: a.inCommitmentSiblingSides,
|
|
100
|
+
accessTokenSiblings: a.accessTokenSiblings,
|
|
101
|
+
accessTokenSiblingSides: a.accessTokenSiblingSides,
|
|
102
|
+
rootHashHinkal: p(a.rootHashHinkal),
|
|
103
|
+
rootHashAccessToken: p(a.rootHashAccessToken)
|
|
96
104
|
};
|
|
97
|
-
}, L = async (o,
|
|
98
|
-
if (!
|
|
105
|
+
}, L = async (o, c, s) => {
|
|
106
|
+
if (!c || !s)
|
|
99
107
|
return !1;
|
|
100
108
|
try {
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
109
|
+
const e = c.getRootHash(), i = s.getRootHash();
|
|
110
|
+
if (!e || !i)
|
|
103
111
|
return !1;
|
|
104
|
-
const { hinkalRootHash: n, accessTokenRootHash:
|
|
105
|
-
return
|
|
112
|
+
const { hinkalRootHash: n, accessTokenRootHash: t } = await I(o);
|
|
113
|
+
return e === n && i === t;
|
|
106
114
|
} catch {
|
|
107
115
|
return !1;
|
|
108
116
|
}
|
|
109
|
-
}, y = async (o,
|
|
110
|
-
const
|
|
111
|
-
return console.log("hinkalDeposit sa2", { isLocalFresh:
|
|
117
|
+
}, y = async (o, c, s, e, i, n, t) => {
|
|
118
|
+
const a = await L(o, n, t);
|
|
119
|
+
return console.log("hinkalDeposit sa2", { isLocalFresh: a }), a ? w(
|
|
112
120
|
n,
|
|
121
|
+
t,
|
|
113
122
|
c,
|
|
114
|
-
a,
|
|
115
|
-
e,
|
|
116
123
|
s,
|
|
124
|
+
e,
|
|
117
125
|
i
|
|
118
|
-
) : D(o,
|
|
119
|
-
}, v = async (o,
|
|
126
|
+
) : D(o, c, s, e, i);
|
|
127
|
+
}, v = async (o, c, s, e, i, n, t, a, m) => {
|
|
120
128
|
if (N) {
|
|
121
129
|
const {
|
|
122
130
|
inCommitmentSiblings: r,
|
|
123
131
|
inCommitmentSiblingSides: l,
|
|
124
132
|
accessTokenSiblings: S,
|
|
125
|
-
accessTokenSiblingSides:
|
|
133
|
+
accessTokenSiblingSides: h,
|
|
126
134
|
rootHashHinkal: T,
|
|
127
135
|
rootHashAccessToken: f
|
|
128
136
|
} = await y(
|
|
129
137
|
o,
|
|
130
|
-
|
|
138
|
+
e,
|
|
131
139
|
i,
|
|
132
140
|
n,
|
|
141
|
+
t,
|
|
133
142
|
c,
|
|
134
|
-
|
|
135
|
-
e
|
|
143
|
+
s
|
|
136
144
|
), H = await g({
|
|
137
145
|
type: k.ZKProof,
|
|
138
146
|
payload: {
|
|
139
|
-
type:
|
|
140
|
-
data: { inputUtxosSerialized: i, onChainCreation:
|
|
147
|
+
type: b.BUILD_IN_NULLIFIERS,
|
|
148
|
+
data: { inputUtxosSerialized: i, onChainCreation: a, proverVersion: m }
|
|
141
149
|
}
|
|
142
150
|
});
|
|
143
151
|
return {
|
|
144
152
|
inCommitmentSiblings: r,
|
|
145
153
|
inCommitmentSiblingSides: l,
|
|
146
154
|
accessTokenSiblings: S,
|
|
147
|
-
accessTokenSiblingSides:
|
|
155
|
+
accessTokenSiblingSides: h,
|
|
148
156
|
rootHashHinkal: T,
|
|
149
157
|
rootHashAccessToken: f,
|
|
150
158
|
inNullifiers: H
|
|
@@ -155,7 +163,7 @@ const p = async (o, a) => {
|
|
|
155
163
|
inCommitmentSiblings: r,
|
|
156
164
|
inCommitmentSiblingSides: l,
|
|
157
165
|
accessTokenSiblings: S,
|
|
158
|
-
accessTokenSiblingSides:
|
|
166
|
+
accessTokenSiblingSides: h,
|
|
159
167
|
rootHashHinkal: T,
|
|
160
168
|
rootHashAccessToken: f
|
|
161
169
|
},
|
|
@@ -163,18 +171,18 @@ const p = async (o, a) => {
|
|
|
163
171
|
] = await Promise.all([
|
|
164
172
|
y(
|
|
165
173
|
o,
|
|
166
|
-
|
|
174
|
+
e,
|
|
167
175
|
i,
|
|
168
176
|
n,
|
|
177
|
+
t,
|
|
169
178
|
c,
|
|
170
|
-
|
|
171
|
-
e
|
|
179
|
+
s
|
|
172
180
|
),
|
|
173
181
|
g({
|
|
174
182
|
type: k.ZKProof,
|
|
175
183
|
payload: {
|
|
176
|
-
type:
|
|
177
|
-
data: { inputUtxosSerialized: i, onChainCreation:
|
|
184
|
+
type: b.BUILD_IN_NULLIFIERS,
|
|
185
|
+
data: { inputUtxosSerialized: i, onChainCreation: a, proverVersion: m }
|
|
178
186
|
}
|
|
179
187
|
})
|
|
180
188
|
]);
|
|
@@ -182,7 +190,7 @@ const p = async (o, a) => {
|
|
|
182
190
|
inCommitmentSiblings: r,
|
|
183
191
|
inCommitmentSiblingSides: l,
|
|
184
192
|
accessTokenSiblings: S,
|
|
185
|
-
accessTokenSiblingSides:
|
|
193
|
+
accessTokenSiblingSides: h,
|
|
186
194
|
rootHashHinkal: T,
|
|
187
195
|
rootHashAccessToken: f,
|
|
188
196
|
inNullifiers: H
|
package/package.json
CHANGED
|
@@ -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();
|