h_test_1 0.0.23 → 0.0.25
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 +98 -87
- package/package.json +1 -1
- package/webworker/performTaskWithWorker.cjs +1 -1
- package/webworker/performTaskWithWorker.mjs +21 -21
- 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 +12 -11
|
@@ -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 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"),
|
|
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"),N=require("../../crypto/poseidon.cjs"),C=require("../../constants/vite.constants.cjs"),R=require("./fetchOnChainRootHashes.cjs"),p=async(o,i)=>{const e=o.getRootHash();if(console.log("sss pre calculate access token siblings and root hash",{accessKey:i,rootHash:e,patchedMerkleTree:o,tjson:o.toJSON()}),e===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:i,merkleTreeAccessTokenSerialized:o.toJSON()}}});return console.log({resultFromWorker:s}),{accessTokenSiblings:s.accessTokenSiblings,accessTokenSiblingSides:s.accessTokenSiblingSides,rootHashAccessToken:e}},_=async(o,i,e,s,t,n)=>{console.log("hinkalDeposit sa5");const a=e.getAccessKey();console.log("hinkalDeposit sa6",{accessKey:a});const r=A.getPatchedAccessTokenMerkleTree(i,a,t,n),k=o.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(r,a),c=await S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES,data:{inputUtxosSerialized:s,merkleTreeSerialized:o.toJSON()}}})):[l,c]=await Promise.all([p(r,a),S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES,data:{inputUtxosSerialized:s,merkleTreeSerialized:o.toJSON()}}})]),{inCommitmentSiblings:c.inCommitmentSiblings,inCommitmentSiblingSides:c.inCommitmentSiblingSides,accessTokenSiblings:l.accessTokenSiblings,accessTokenSiblingSides:l.accessTokenSiblingSides,rootHashHinkal:k,rootHashAccessToken:l.rootHashAccessToken}},P=async(o,i,e,s,t)=>{console.log("hinkalDeposit sa3");const n=i.getAccessKey();console.log("hinkalDeposit sa4",{accessKey:n});const a=!t||s;if(console.log("ba4",{needsPatching:a}),a){console.log("ba5");const k=W.MerkleTree.create(N.poseidonFunction,0n);console.log("ba6",{emptyMerkleTreeAccessToken:k});const l=A.getPatchedAccessTokenMerkleTree(k,n,s,t);console.log("pre calculating access token siblings and root hash",{accessKey:n});const[c,g]=await Promise.all([p(l,n),u.fetchMerkleTreeSiblings(o,e,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:o,inputUtxosSerialized:e,accessKey:n});const r=await u.fetchMerkleTreeSiblings(o,e,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(o,i,e)=>{if(!i||!e)return!1;try{const s=i.getRootHash(),t=e.getRootHash();if(!s||!t)return!1;const{hinkalRootHash:n,accessTokenRootHash:a}=await R.fetchOnChainRootHashes(o);return s===n&&t===a}catch{return!1}},y=async(o,i,e,s,t,n,a)=>{const r=await I(o,n,a);return console.log("hinkalDeposit sa2",{isLocalFresh:r}),r?_(n,a,i,e,s,t):P(o,i,e,s,t)},w=async(o,i,e,s,t,n,a,r,k)=>{if(C.isNode){const{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:g,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:f}=await y(o,s,t,n,a,i,e),d=await S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:t,onChainCreation:r,proverVersion:k}}});return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:g,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:f,inNullifiers:d}}else{const[{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:g,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:f},d]=await Promise.all([y(o,s,t,n,a,i,e),S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:t,onChainCreation:r,proverVersion:k}}})]);return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:g,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:f,inNullifiers:d}}};exports.getDataFromWorkers=w;exports.getMerkleTreeSiblingsAndRootHashes=y;
|
|
@@ -1,57 +1,62 @@
|
|
|
1
1
|
import { MerkleTree as R } from "../../data-structures/merkle-tree/MerkleTree.mjs";
|
|
2
|
-
import { getPatchedAccessTokenMerkleTree as
|
|
2
|
+
import { getPatchedAccessTokenMerkleTree as N } 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
|
|
9
|
-
import { isNode as
|
|
10
|
-
import { fetchOnChainRootHashes as
|
|
11
|
-
const
|
|
7
|
+
import { toBigInt as p } from "../utils/amounts.utils.mjs";
|
|
8
|
+
import { poseidonFunction as _ } from "../../crypto/poseidon.mjs";
|
|
9
|
+
import { isNode as A } from "../../constants/vite.constants.mjs";
|
|
10
|
+
import { fetchOnChainRootHashes as I } from "./fetchOnChainRootHashes.mjs";
|
|
11
|
+
const d = async (o, i) => {
|
|
12
12
|
const s = o.getRootHash();
|
|
13
|
-
if (console.log("pre calculate access token siblings and root hash", {
|
|
13
|
+
if (console.log("sss pre calculate access token siblings and root hash", {
|
|
14
|
+
accessKey: i,
|
|
15
|
+
rootHash: s,
|
|
16
|
+
patchedMerkleTree: o,
|
|
17
|
+
tjson: o.toJSON()
|
|
18
|
+
}), s === void 0)
|
|
14
19
|
throw new Error("Root hash not available from patched merkle tree");
|
|
15
20
|
const e = await g({
|
|
16
21
|
type: k.ZKProof,
|
|
17
22
|
payload: {
|
|
18
|
-
type:
|
|
23
|
+
type: b.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,
|
|
19
24
|
data: {
|
|
20
|
-
accessKey:
|
|
25
|
+
accessKey: i,
|
|
21
26
|
merkleTreeAccessTokenSerialized: o.toJSON()
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
});
|
|
25
|
-
return {
|
|
30
|
+
return console.log({ resultFromWorker: e }), {
|
|
26
31
|
accessTokenSiblings: e.accessTokenSiblings,
|
|
27
32
|
accessTokenSiblingSides: e.accessTokenSiblingSides,
|
|
28
33
|
rootHashAccessToken: s
|
|
29
34
|
};
|
|
30
|
-
}, w = async (o,
|
|
35
|
+
}, w = async (o, i, s, e, t, n) => {
|
|
31
36
|
console.log("hinkalDeposit sa5");
|
|
32
|
-
const
|
|
33
|
-
console.log("hinkalDeposit sa6", { accessKey:
|
|
34
|
-
const
|
|
37
|
+
const a = s.getAccessKey();
|
|
38
|
+
console.log("hinkalDeposit sa6", { accessKey: a });
|
|
39
|
+
const c = N(
|
|
40
|
+
i,
|
|
35
41
|
a,
|
|
36
|
-
|
|
37
|
-
n
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (S === void 0)
|
|
42
|
+
t,
|
|
43
|
+
n
|
|
44
|
+
), m = o.getRootHash();
|
|
45
|
+
if (m === void 0)
|
|
41
46
|
throw new Error("Root hash not available from hinkal merkle tree");
|
|
42
47
|
let r, l;
|
|
43
|
-
return
|
|
48
|
+
return A ? (r = await d(c, a), l = await g({
|
|
44
49
|
type: k.ZKProof,
|
|
45
50
|
payload: {
|
|
46
|
-
type:
|
|
51
|
+
type: b.CALC_COMMITMENTS_SIBLING_AND_SIDES,
|
|
47
52
|
data: { inputUtxosSerialized: e, merkleTreeSerialized: o.toJSON() }
|
|
48
53
|
}
|
|
49
54
|
})) : [r, l] = await Promise.all([
|
|
50
|
-
|
|
55
|
+
d(c, a),
|
|
51
56
|
g({
|
|
52
57
|
type: k.ZKProof,
|
|
53
58
|
payload: {
|
|
54
|
-
type:
|
|
59
|
+
type: b.CALC_COMMITMENTS_SIBLING_AND_SIDES,
|
|
55
60
|
data: { inputUtxosSerialized: e, merkleTreeSerialized: o.toJSON() }
|
|
56
61
|
}
|
|
57
62
|
})
|
|
@@ -60,138 +65,144 @@ const p = async (o, a) => {
|
|
|
60
65
|
inCommitmentSiblingSides: l.inCommitmentSiblingSides,
|
|
61
66
|
accessTokenSiblings: r.accessTokenSiblings,
|
|
62
67
|
accessTokenSiblingSides: r.accessTokenSiblingSides,
|
|
63
|
-
rootHashHinkal:
|
|
68
|
+
rootHashHinkal: m,
|
|
64
69
|
rootHashAccessToken: r.rootHashAccessToken
|
|
65
70
|
};
|
|
66
|
-
}, D = async (o,
|
|
71
|
+
}, D = async (o, i, s, e, t) => {
|
|
67
72
|
console.log("hinkalDeposit sa3");
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
const n = i.getAccessKey();
|
|
74
|
+
console.log("hinkalDeposit sa4", { accessKey: n });
|
|
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(
|
|
81
|
+
m,
|
|
82
|
+
n,
|
|
73
83
|
e,
|
|
74
|
-
|
|
84
|
+
t
|
|
75
85
|
);
|
|
76
|
-
console.log("pre calculating access token siblings and root hash", { accessKey:
|
|
77
|
-
const [l,
|
|
78
|
-
|
|
79
|
-
C(o, s,
|
|
86
|
+
console.log("pre calculating access token siblings and root hash", { accessKey: n });
|
|
87
|
+
const [l, S] = await Promise.all([
|
|
88
|
+
d(r, n),
|
|
89
|
+
C(o, s, n)
|
|
80
90
|
]);
|
|
81
|
-
return console.log("post calculating access token siblings and root hash", { accessTokenResult: l, siblingsResponse:
|
|
82
|
-
inCommitmentSiblings:
|
|
83
|
-
inCommitmentSiblingSides:
|
|
91
|
+
return console.log("post calculating access token siblings and root hash", { accessTokenResult: l, siblingsResponse: S }), {
|
|
92
|
+
inCommitmentSiblings: S.inCommitmentSiblings,
|
|
93
|
+
inCommitmentSiblingSides: S.inCommitmentSiblingSides,
|
|
84
94
|
accessTokenSiblings: l.accessTokenSiblings,
|
|
85
95
|
accessTokenSiblingSides: l.accessTokenSiblingSides,
|
|
86
|
-
rootHashHinkal:
|
|
96
|
+
rootHashHinkal: p(S.rootHashHinkal),
|
|
87
97
|
rootHashAccessToken: l.rootHashAccessToken
|
|
88
98
|
};
|
|
89
99
|
}
|
|
90
|
-
|
|
100
|
+
console.log("kaksk", { chainId: o, inputUtxosSerialized: s, accessKey: n });
|
|
101
|
+
const c = await C(o, s, n);
|
|
91
102
|
return {
|
|
92
|
-
inCommitmentSiblings:
|
|
93
|
-
inCommitmentSiblingSides:
|
|
94
|
-
accessTokenSiblings:
|
|
95
|
-
accessTokenSiblingSides:
|
|
96
|
-
rootHashHinkal:
|
|
97
|
-
rootHashAccessToken:
|
|
103
|
+
inCommitmentSiblings: c.inCommitmentSiblings,
|
|
104
|
+
inCommitmentSiblingSides: c.inCommitmentSiblingSides,
|
|
105
|
+
accessTokenSiblings: c.accessTokenSiblings,
|
|
106
|
+
accessTokenSiblingSides: c.accessTokenSiblingSides,
|
|
107
|
+
rootHashHinkal: p(c.rootHashHinkal),
|
|
108
|
+
rootHashAccessToken: p(c.rootHashAccessToken)
|
|
98
109
|
};
|
|
99
|
-
}, L = async (o,
|
|
100
|
-
if (!
|
|
110
|
+
}, L = async (o, i, s) => {
|
|
111
|
+
if (!i || !s)
|
|
101
112
|
return !1;
|
|
102
113
|
try {
|
|
103
|
-
const e =
|
|
104
|
-
if (!e || !
|
|
114
|
+
const e = i.getRootHash(), t = s.getRootHash();
|
|
115
|
+
if (!e || !t)
|
|
105
116
|
return !1;
|
|
106
|
-
const { hinkalRootHash:
|
|
107
|
-
return e ===
|
|
117
|
+
const { hinkalRootHash: n, accessTokenRootHash: a } = await I(o);
|
|
118
|
+
return e === n && t === a;
|
|
108
119
|
} catch {
|
|
109
120
|
return !1;
|
|
110
121
|
}
|
|
111
|
-
}, y = async (o,
|
|
112
|
-
const
|
|
113
|
-
return console.log("hinkalDeposit sa2", { isLocalFresh:
|
|
114
|
-
|
|
115
|
-
c,
|
|
122
|
+
}, y = async (o, i, s, e, t, n, a) => {
|
|
123
|
+
const c = await L(o, n, a);
|
|
124
|
+
return console.log("hinkalDeposit sa2", { isLocalFresh: c }), c ? w(
|
|
125
|
+
n,
|
|
116
126
|
a,
|
|
127
|
+
i,
|
|
117
128
|
s,
|
|
118
129
|
e,
|
|
119
|
-
|
|
120
|
-
) : D(o,
|
|
121
|
-
},
|
|
122
|
-
if (
|
|
130
|
+
t
|
|
131
|
+
) : D(o, i, s, e, t);
|
|
132
|
+
}, J = async (o, i, s, e, t, n, a, c, m) => {
|
|
133
|
+
if (A) {
|
|
123
134
|
const {
|
|
124
135
|
inCommitmentSiblings: r,
|
|
125
136
|
inCommitmentSiblingSides: l,
|
|
126
|
-
accessTokenSiblings:
|
|
127
|
-
accessTokenSiblingSides:
|
|
137
|
+
accessTokenSiblings: S,
|
|
138
|
+
accessTokenSiblingSides: h,
|
|
128
139
|
rootHashHinkal: T,
|
|
129
|
-
rootHashAccessToken:
|
|
140
|
+
rootHashAccessToken: f
|
|
130
141
|
} = await y(
|
|
131
142
|
o,
|
|
132
143
|
e,
|
|
144
|
+
t,
|
|
133
145
|
n,
|
|
134
|
-
i,
|
|
135
|
-
c,
|
|
136
146
|
a,
|
|
147
|
+
i,
|
|
137
148
|
s
|
|
138
|
-
),
|
|
149
|
+
), H = await g({
|
|
139
150
|
type: k.ZKProof,
|
|
140
151
|
payload: {
|
|
141
|
-
type:
|
|
142
|
-
data: { inputUtxosSerialized:
|
|
152
|
+
type: b.BUILD_IN_NULLIFIERS,
|
|
153
|
+
data: { inputUtxosSerialized: t, onChainCreation: c, proverVersion: m }
|
|
143
154
|
}
|
|
144
155
|
});
|
|
145
156
|
return {
|
|
146
157
|
inCommitmentSiblings: r,
|
|
147
158
|
inCommitmentSiblingSides: l,
|
|
148
|
-
accessTokenSiblings:
|
|
149
|
-
accessTokenSiblingSides:
|
|
159
|
+
accessTokenSiblings: S,
|
|
160
|
+
accessTokenSiblingSides: h,
|
|
150
161
|
rootHashHinkal: T,
|
|
151
|
-
rootHashAccessToken:
|
|
152
|
-
inNullifiers:
|
|
162
|
+
rootHashAccessToken: f,
|
|
163
|
+
inNullifiers: H
|
|
153
164
|
};
|
|
154
165
|
} else {
|
|
155
166
|
const [
|
|
156
167
|
{
|
|
157
168
|
inCommitmentSiblings: r,
|
|
158
169
|
inCommitmentSiblingSides: l,
|
|
159
|
-
accessTokenSiblings:
|
|
160
|
-
accessTokenSiblingSides:
|
|
170
|
+
accessTokenSiblings: S,
|
|
171
|
+
accessTokenSiblingSides: h,
|
|
161
172
|
rootHashHinkal: T,
|
|
162
|
-
rootHashAccessToken:
|
|
173
|
+
rootHashAccessToken: f
|
|
163
174
|
},
|
|
164
|
-
|
|
175
|
+
H
|
|
165
176
|
] = await Promise.all([
|
|
166
177
|
y(
|
|
167
178
|
o,
|
|
168
179
|
e,
|
|
180
|
+
t,
|
|
169
181
|
n,
|
|
170
|
-
i,
|
|
171
|
-
c,
|
|
172
182
|
a,
|
|
183
|
+
i,
|
|
173
184
|
s
|
|
174
185
|
),
|
|
175
186
|
g({
|
|
176
187
|
type: k.ZKProof,
|
|
177
188
|
payload: {
|
|
178
|
-
type:
|
|
179
|
-
data: { inputUtxosSerialized:
|
|
189
|
+
type: b.BUILD_IN_NULLIFIERS,
|
|
190
|
+
data: { inputUtxosSerialized: t, onChainCreation: c, proverVersion: m }
|
|
180
191
|
}
|
|
181
192
|
})
|
|
182
193
|
]);
|
|
183
194
|
return {
|
|
184
195
|
inCommitmentSiblings: r,
|
|
185
196
|
inCommitmentSiblingSides: l,
|
|
186
|
-
accessTokenSiblings:
|
|
187
|
-
accessTokenSiblingSides:
|
|
197
|
+
accessTokenSiblings: S,
|
|
198
|
+
accessTokenSiblingSides: h,
|
|
188
199
|
rootHashHinkal: T,
|
|
189
|
-
rootHashAccessToken:
|
|
190
|
-
inNullifiers:
|
|
200
|
+
rootHashAccessToken: f,
|
|
201
|
+
inNullifiers: H
|
|
191
202
|
};
|
|
192
203
|
}
|
|
193
204
|
};
|
|
194
205
|
export {
|
|
195
|
-
|
|
206
|
+
J as getDataFromWorkers,
|
|
196
207
|
y as getMerkleTreeSiblingsAndRootHashes
|
|
197
208
|
};
|
package/package.json
CHANGED
|
@@ -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("../constants/chains.constants.cjs"),h=require("../constants/vite.constants.cjs"),k=require("./workerFactory.cjs"),d=async r=>{const e=await k.WorkerFactory.getWebWorker(r.type);return console.log("performTaskWithWorker a1",{worker:e,workerData:r}),new Promise((s,a)=>{let t={};if(typeof window<"u"&&window.location){const{origin:o,protocol:i,host:c,port:l,hostname:m,href:p}=window.location;t={origin:o,protocol:i,host:c,port:l,hostname:m,href:p}}e.onmessage=o=>{console.log("performTaskWithWorker a3",{result:o}),s(o.data),e.terminate()},e.onerror=o=>{console.error("performTaskWithWorker a2",{err:o}),a(o),e.terminate()};const n={payload:r.payload,metadata:{hostLocation:t,constants:{chains:{chainIds:W.chainIds},isDevelopment:h.isDevelopment}}};console.log("performTaskWithWorker a4",{message:n}),e.postMessage(n)})};exports.performTaskWithWorker=d;
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { chainIds as
|
|
2
|
-
import { isDevelopment as
|
|
1
|
+
import { chainIds as W } from "../constants/chains.constants.mjs";
|
|
2
|
+
import { isDevelopment as f } from "../constants/vite.constants.mjs";
|
|
3
3
|
import { WorkerFactory as h } from "./workerFactory.mjs";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
return new Promise((n,
|
|
7
|
-
let
|
|
4
|
+
const w = async (r) => {
|
|
5
|
+
const e = await h.getWebWorker(r.type);
|
|
6
|
+
return console.log("performTaskWithWorker a1", { worker: e, workerData: r }), new Promise((n, s) => {
|
|
7
|
+
let t = {};
|
|
8
8
|
if (typeof window < "u" && window.location) {
|
|
9
|
-
const { origin:
|
|
10
|
-
|
|
11
|
-
origin:
|
|
9
|
+
const { origin: o, protocol: i, host: m, port: c, hostname: p, href: l } = window.location;
|
|
10
|
+
t = {
|
|
11
|
+
origin: o,
|
|
12
12
|
protocol: i,
|
|
13
13
|
host: m,
|
|
14
14
|
port: c,
|
|
15
15
|
hostname: p,
|
|
16
|
-
href:
|
|
16
|
+
href: l
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
n(
|
|
21
|
-
},
|
|
22
|
-
|
|
19
|
+
e.onmessage = (o) => {
|
|
20
|
+
console.log("performTaskWithWorker a3", { result: o }), n(o.data), e.terminate();
|
|
21
|
+
}, e.onerror = (o) => {
|
|
22
|
+
console.error("performTaskWithWorker a2", { err: o }), s(o), e.terminate();
|
|
23
23
|
};
|
|
24
|
-
const
|
|
25
|
-
payload:
|
|
24
|
+
const a = {
|
|
25
|
+
payload: r.payload,
|
|
26
26
|
metadata: {
|
|
27
|
-
hostLocation:
|
|
27
|
+
hostLocation: t,
|
|
28
28
|
constants: {
|
|
29
29
|
chains: {
|
|
30
|
-
chainIds:
|
|
30
|
+
chainIds: W
|
|
31
31
|
},
|
|
32
|
-
isDevelopment:
|
|
32
|
+
isDevelopment: f
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
console.log("performTaskWithWorker a4", { message: a }), e.postMessage(a);
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
export {
|
|
40
|
-
|
|
40
|
+
w as performTaskWithWorker
|
|
41
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/zkProofWorkerLauncher-DQUaX0hI.js").href:new URL("../../assets/zkProofWorkerLauncher-DQUaX0hI.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 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"),
|
|
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"),k=require("../../functions/utils/merkleTree.utils.cjs"),c=new C.WorkerProxy,u=o=>{const{inputUtxosSerialized:e,merkleTreeSerialized:t}=o.data,a=k.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=k.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})},g=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)},T=async o=>{console.log("worker code onWorkerMessage",{data:o});try{await A.preProcessing();const{type:e}=o.payload;switch(e){case d.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES:u(o.payload);return;case d.ZKProofWorkerActionType.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES:p(o.payload);return;case d.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS:g(o.payload);return;default:throw Error(`Unknown worker message type ${e}`)}}catch(e){console.error(e),c.postErrorToMainThread(e)}};c.attachWorkerSideOnMessage(T);exports.default=c;exports.handleBuildInNullifiers=g;exports.handleCalcAccessTokenSiblingAndSides=p;exports.handleCalcCommitmentsSiblingAndSides=u;exports.onWorkerMessage=T;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { preProcessing as S } from "../../crypto/preProcessing.mjs";
|
|
2
2
|
import { Utxo as d } from "../../data-structures/utxo/Utxo.mjs";
|
|
3
|
-
import { calcCommitmentsSiblingAndSides as
|
|
4
|
-
import { WorkerProxy as
|
|
3
|
+
import { calcCommitmentsSiblingAndSides as g, calcAccessTokenSiblingsAndSides as k } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
4
|
+
import { WorkerProxy as T } from "../workerProxy.mjs";
|
|
5
5
|
import { ZKProofWorkerActionType as m } from "./zkProofWorker.types.mjs";
|
|
6
6
|
import { contructMerkleTreeFromSerialized as p } from "../../functions/utils/merkleTree.utils.mjs";
|
|
7
|
-
const c = new
|
|
7
|
+
const c = new T(), u = (o) => {
|
|
8
8
|
const { inputUtxosSerialized: e, merkleTreeSerialized: t } = o.data, a = p(t), s = e.map(
|
|
9
9
|
(n) => n.map((l) => new d(l))
|
|
10
|
-
), { inCommitmentSiblings: r, inCommitmentSiblingSides: i } =
|
|
10
|
+
), { inCommitmentSiblings: r, inCommitmentSiblingSides: i } = g(s, a);
|
|
11
11
|
c.postMessageToMainThread({ inCommitmentSiblings: r, inCommitmentSiblingSides: i });
|
|
12
12
|
}, C = (o) => {
|
|
13
13
|
const { accessKey: e, merkleTreeAccessTokenSerialized: t } = o.data;
|
|
14
14
|
console.log("worker code a1", { accessKey: e, merkleTreeAccessTokenSerialized: t });
|
|
15
15
|
const a = p(t);
|
|
16
16
|
console.log("worker code a2", { merkleTree: a });
|
|
17
|
-
const { accessTokenSiblings: s, accessTokenSiblingSides: r } =
|
|
17
|
+
const { accessTokenSiblings: s, accessTokenSiblingSides: r } = k(e, a);
|
|
18
18
|
console.log("worker code a3", { accessTokenSiblings: s, accessTokenSiblingSides: r }), c.postMessageToMainThread({ accessTokenSiblings: s, accessTokenSiblingSides: r });
|
|
19
|
-
},
|
|
19
|
+
}, M = (o) => {
|
|
20
20
|
const { inputUtxosSerialized: e, onChainCreation: t, proverVersion: a } = o.data, s = e.map(
|
|
21
21
|
(i) => i.map((n) => new d(n))
|
|
22
22
|
);
|
|
@@ -24,7 +24,8 @@ const c = new k(), u = (o) => {
|
|
|
24
24
|
a === "v1x0" ? r = s.map(
|
|
25
25
|
(i, n) => i.map((l) => t[n] ? "0" : l.getNullifier())
|
|
26
26
|
) : r = s.map((i) => i.map((n) => n.amount === 0n ? "0" : n.getNullifier())), c.postMessageToMainThread(r);
|
|
27
|
-
},
|
|
27
|
+
}, f = async (o) => {
|
|
28
|
+
console.log("worker code onWorkerMessage", { data: o });
|
|
28
29
|
try {
|
|
29
30
|
await S();
|
|
30
31
|
const { type: e } = o.payload;
|
|
@@ -36,7 +37,7 @@ const c = new k(), u = (o) => {
|
|
|
36
37
|
C(o.payload);
|
|
37
38
|
return;
|
|
38
39
|
case m.BUILD_IN_NULLIFIERS:
|
|
39
|
-
|
|
40
|
+
M(o.payload);
|
|
40
41
|
return;
|
|
41
42
|
default:
|
|
42
43
|
throw Error(`Unknown worker message type ${e}`);
|
|
@@ -45,11 +46,11 @@ const c = new k(), u = (o) => {
|
|
|
45
46
|
console.error(e), c.postErrorToMainThread(e);
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
|
-
c.attachWorkerSideOnMessage(
|
|
49
|
+
c.attachWorkerSideOnMessage(f);
|
|
49
50
|
export {
|
|
50
51
|
c as default,
|
|
51
|
-
|
|
52
|
+
M as handleBuildInNullifiers,
|
|
52
53
|
C as handleCalcAccessTokenSiblingAndSides,
|
|
53
54
|
u as handleCalcCommitmentsSiblingAndSides,
|
|
54
|
-
|
|
55
|
+
f as onWorkerMessage
|
|
55
56
|
};
|