h_test_1 0.0.25 → 0.0.27
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 +8 -13
- 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 +3 -3
- package/webworker/performTaskWithWorker.cjs +1 -1
- package/webworker/performTaskWithWorker.mjs +21 -21
- package/webworker/viteWorkerURL.constant.cjs +3 -3
- package/webworker/viteWorkerURL.constant.mjs +3 -3
- 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 +23 -28
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../functions/web3/etherFunctions.cjs"),c=require("../../crypto/poseidon.cjs"),i=require("./MerkleTree.cjs"),u=(r,n,o,t)=>{if(!t||o){const e=i.MerkleTree.create(c.poseidonFunction,0n);return e.insert(BigInt(n),e.getStartIndex()),t||e.insert(s.randomBigInt(31),e.getStartIndex()+1n),e}return r};exports.getPatchedAccessTokenMerkleTree=u;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { randomBigInt as
|
|
2
|
-
import { poseidonFunction as
|
|
1
|
+
import { randomBigInt as i } from "../../functions/web3/etherFunctions.mjs";
|
|
2
|
+
import { poseidonFunction as m } from "../../crypto/poseidon.mjs";
|
|
3
3
|
import { MerkleTree as s } from "./MerkleTree.mjs";
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
4
|
+
const g = (r, n, o, t) => {
|
|
5
|
+
if (!t || o) {
|
|
6
|
+
const e = s.create(m, 0n);
|
|
7
|
+
return e.insert(BigInt(n), e.getStartIndex()), t || e.insert(i(31), e.getStartIndex() + 1n), e;
|
|
13
8
|
}
|
|
14
|
-
return
|
|
9
|
+
return r;
|
|
15
10
|
};
|
|
16
11
|
export {
|
|
17
|
-
|
|
12
|
+
g as getPatchedAccessTokenMerkleTree
|
|
18
13
|
};
|
|
@@ -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
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "h_test_1",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"homepage": "hinkal.io",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Hinkal Protocol"
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"types": "./index.d.ts",
|
|
52
52
|
"scripts": {
|
|
53
|
-
"prebuild": "nx prebuild:workers",
|
|
54
|
-
"build": "nx build",
|
|
53
|
+
"prebuild": "npx nx prebuild:workers",
|
|
54
|
+
"build": "npx nx build",
|
|
55
55
|
"lint": "nx lint",
|
|
56
56
|
"test": "nx test"
|
|
57
57
|
},
|
|
@@ -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("../constants/chains.constants.cjs"),h=require("../constants/vite.constants.cjs"),w=require("./workerFactory.cjs"),y=async t=>{const e=await w.WorkerFactory.getWebWorker(t.type);return new Promise((r,s)=>{let n={};if(typeof window<"u"&&window.location){const{origin:o,protocol:i,host:c,port:d,hostname:m,href:p}=window.location;n={origin:o,protocol:i,host:c,port:d,hostname:m,href:p}}e.onmessage=o=>{r(o.data),e.terminate()},e.onerror=o=>{s(o),e.terminate()};const a={payload:t.payload,metadata:{hostLocation:n,constants:{chains:{chainIds:l.chainIds},isDevelopment:h.isDevelopment}}};e.postMessage(a)})};exports.performTaskWithWorker=y;
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { chainIds as
|
|
2
|
-
import { isDevelopment as
|
|
1
|
+
import { chainIds as f } from "../constants/chains.constants.mjs";
|
|
2
|
+
import { isDevelopment as w } from "../constants/vite.constants.mjs";
|
|
3
3
|
import { WorkerFactory as h } from "./workerFactory.mjs";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
return
|
|
7
|
-
let
|
|
4
|
+
const W = async (e) => {
|
|
5
|
+
const o = await h.getWebWorker(e.type);
|
|
6
|
+
return new Promise((n, a) => {
|
|
7
|
+
let r = {};
|
|
8
8
|
if (typeof window < "u" && window.location) {
|
|
9
|
-
const { origin:
|
|
10
|
-
|
|
11
|
-
origin:
|
|
9
|
+
const { origin: t, protocol: i, host: m, port: c, hostname: p, href: d } = window.location;
|
|
10
|
+
r = {
|
|
11
|
+
origin: t,
|
|
12
12
|
protocol: i,
|
|
13
13
|
host: m,
|
|
14
14
|
port: c,
|
|
15
15
|
hostname: p,
|
|
16
|
-
href:
|
|
16
|
+
href: d
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
|
|
19
|
+
o.onmessage = (t) => {
|
|
20
|
+
n(t.data), o.terminate();
|
|
21
|
+
}, o.onerror = (t) => {
|
|
22
|
+
a(t), o.terminate();
|
|
23
23
|
};
|
|
24
|
-
const
|
|
25
|
-
payload:
|
|
24
|
+
const s = {
|
|
25
|
+
payload: e.payload,
|
|
26
26
|
metadata: {
|
|
27
|
-
hostLocation:
|
|
27
|
+
hostLocation: r,
|
|
28
28
|
constants: {
|
|
29
29
|
chains: {
|
|
30
|
-
chainIds:
|
|
30
|
+
chainIds: f
|
|
31
31
|
},
|
|
32
|
-
isDevelopment:
|
|
32
|
+
isDevelopment: w
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
o.postMessage(s);
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
export {
|
|
40
|
-
|
|
40
|
+
W as performTaskWithWorker
|
|
41
41
|
};
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
var e = /* @__PURE__ */ ((r) => (r.ZKProof = "ZKProof", r.SnarkJS = "SnarkJS", r.UTXO = "UTXO", r))(e || {});
|
|
15
15
|
|
|
16
16
|
const n = async () => ({
|
|
17
|
-
[e.ZKProof]: await getWorkerURL(domain + '/0.2.
|
|
18
|
-
[e.SnarkJS]: await getWorkerURL(domain + '/0.2.
|
|
19
|
-
[e.UTXO]: await getWorkerURL(domain + '/0.2.
|
|
17
|
+
[e.ZKProof]: await getWorkerURL(domain + '/0.2.20/' + 'zkProofWorkerLauncher.js'),
|
|
18
|
+
[e.SnarkJS]: await getWorkerURL(domain + '/0.2.20/' + 'snarkjsWorkerLauncher.js'),
|
|
19
|
+
[e.UTXO]: await getWorkerURL(domain + '/0.2.20/' + 'utxoWorkerLauncher.js'),
|
|
20
20
|
});
|
|
21
21
|
exports.getWorkerViteURL = n;
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
var e = /* @__PURE__ */ ((r) => (r.ZKProof = "ZKProof", r.SnarkJS = "SnarkJS", r.UTXO = "UTXO", r))(e || {});
|
|
15
15
|
|
|
16
16
|
const n = async () => ({
|
|
17
|
-
[e.ZKProof]: await getWorkerURL(domain + '/0.2.
|
|
18
|
-
[e.SnarkJS]: await getWorkerURL(domain + '/0.2.
|
|
19
|
-
[e.UTXO]: await getWorkerURL(domain + '/0.2.
|
|
17
|
+
[e.ZKProof]: await getWorkerURL(domain + '/0.2.20/' + 'zkProofWorkerLauncher.js'),
|
|
18
|
+
[e.SnarkJS]: await getWorkerURL(domain + '/0.2.20/' + 'snarkjsWorkerLauncher.js'),
|
|
19
|
+
[e.UTXO]: await getWorkerURL(domain + '/0.2.20/' + 'utxoWorkerLauncher.js'),
|
|
20
20
|
});
|
|
21
21
|
export { n as getWorkerViteURL };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/zkProofWorkerLauncher-
|
|
1
|
+
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/zkProofWorkerLauncher-2cfKnA2L.js").href:new URL("../../assets/zkProofWorkerLauncher-2cfKnA2L.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"),u=require("../../functions/utils/merkleTree.utils.cjs"),t=new C.WorkerProxy,p=r=>{const{inputUtxosSerialized:e,merkleTreeSerialized:a}=r.data,c=u.contructMerkleTreeFromSerialized(a),i=e.map(o=>o.map(l=>new S.Utxo(l))),{inCommitmentSiblings:n,inCommitmentSiblingSides:s}=m.calcCommitmentsSiblingAndSides(i,c);t.postMessageToMainThread({inCommitmentSiblings:n,inCommitmentSiblingSides:s})},T=r=>{const{accessKey:e,merkleTreeAccessTokenSerialized:a}=r.data,c=u.contructMerkleTreeFromSerialized(a),{accessTokenSiblings:i,accessTokenSiblingSides:n}=m.calcAccessTokenSiblingsAndSides(e,c);t.postMessageToMainThread({accessTokenSiblings:i,accessTokenSiblingSides:n})},k=r=>{const{inputUtxosSerialized:e,onChainCreation:a,proverVersion:c}=r.data,i=e.map(s=>s.map(o=>new S.Utxo(o)));let n=[];c==="v1x0"?n=i.map((s,o)=>s.map(l=>a[o]?"0":l.getNullifier())):n=i.map(s=>s.map(o=>o.amount===0n?"0":o.getNullifier())),t.postMessageToMainThread(n)},g=async r=>{try{await A.preProcessing();const{type:e}=r.payload;switch(e){case d.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES:p(r.payload);return;case d.ZKProofWorkerActionType.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES:T(r.payload);return;case d.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS:k(r.payload);return;default:throw Error(`Unknown worker message type ${e}`)}}catch(e){console.error(e),t.postErrorToMainThread(e)}};t.attachWorkerSideOnMessage(g);exports.default=t;exports.handleBuildInNullifiers=k;exports.handleCalcAccessTokenSiblingAndSides=T;exports.handleCalcCommitmentsSiblingAndSides=p;exports.onWorkerMessage=g;
|
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
import { preProcessing as S } from "../../crypto/preProcessing.mjs";
|
|
2
|
-
import { Utxo as
|
|
3
|
-
import { calcCommitmentsSiblingAndSides as
|
|
4
|
-
import { WorkerProxy as
|
|
2
|
+
import { Utxo as p } from "../../data-structures/utxo/Utxo.mjs";
|
|
3
|
+
import { calcCommitmentsSiblingAndSides as T, calcAccessTokenSiblingsAndSides as g } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
4
|
+
import { WorkerProxy as k } from "../workerProxy.mjs";
|
|
5
5
|
import { ZKProofWorkerActionType as m } from "./zkProofWorker.types.mjs";
|
|
6
|
-
import { contructMerkleTreeFromSerialized as
|
|
7
|
-
const c = new
|
|
8
|
-
const { inputUtxosSerialized: e, merkleTreeSerialized: t } = o.data, a =
|
|
9
|
-
(
|
|
10
|
-
), { inCommitmentSiblings:
|
|
11
|
-
c.postMessageToMainThread({ inCommitmentSiblings:
|
|
6
|
+
import { contructMerkleTreeFromSerialized as d } from "../../functions/utils/merkleTree.utils.mjs";
|
|
7
|
+
const c = new k(), u = (o) => {
|
|
8
|
+
const { inputUtxosSerialized: e, merkleTreeSerialized: t } = o.data, a = d(t), i = e.map(
|
|
9
|
+
(r) => r.map((l) => new p(l))
|
|
10
|
+
), { inCommitmentSiblings: n, inCommitmentSiblingSides: s } = T(i, a);
|
|
11
|
+
c.postMessageToMainThread({ inCommitmentSiblings: n, inCommitmentSiblingSides: s });
|
|
12
12
|
}, C = (o) => {
|
|
13
|
-
const { accessKey: e, merkleTreeAccessTokenSerialized: t } = o.data;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
console.log("worker code a3", { accessTokenSiblings: s, accessTokenSiblingSides: r }), c.postMessageToMainThread({ accessTokenSiblings: s, accessTokenSiblingSides: r });
|
|
19
|
-
}, M = (o) => {
|
|
20
|
-
const { inputUtxosSerialized: e, onChainCreation: t, proverVersion: a } = o.data, s = e.map(
|
|
21
|
-
(i) => i.map((n) => new d(n))
|
|
13
|
+
const { accessKey: e, merkleTreeAccessTokenSerialized: t } = o.data, a = d(t), { accessTokenSiblings: i, accessTokenSiblingSides: n } = g(e, a);
|
|
14
|
+
c.postMessageToMainThread({ accessTokenSiblings: i, accessTokenSiblingSides: n });
|
|
15
|
+
}, f = (o) => {
|
|
16
|
+
const { inputUtxosSerialized: e, onChainCreation: t, proverVersion: a } = o.data, i = e.map(
|
|
17
|
+
(s) => s.map((r) => new p(r))
|
|
22
18
|
);
|
|
23
|
-
let
|
|
24
|
-
a === "v1x0" ?
|
|
25
|
-
(
|
|
26
|
-
) :
|
|
27
|
-
},
|
|
28
|
-
console.log("worker code onWorkerMessage", { data: o });
|
|
19
|
+
let n = [];
|
|
20
|
+
a === "v1x0" ? n = i.map(
|
|
21
|
+
(s, r) => s.map((l) => t[r] ? "0" : l.getNullifier())
|
|
22
|
+
) : n = i.map((s) => s.map((r) => r.amount === 0n ? "0" : r.getNullifier())), c.postMessageToMainThread(n);
|
|
23
|
+
}, A = async (o) => {
|
|
29
24
|
try {
|
|
30
25
|
await S();
|
|
31
26
|
const { type: e } = o.payload;
|
|
@@ -37,7 +32,7 @@ const c = new T(), u = (o) => {
|
|
|
37
32
|
C(o.payload);
|
|
38
33
|
return;
|
|
39
34
|
case m.BUILD_IN_NULLIFIERS:
|
|
40
|
-
|
|
35
|
+
f(o.payload);
|
|
41
36
|
return;
|
|
42
37
|
default:
|
|
43
38
|
throw Error(`Unknown worker message type ${e}`);
|
|
@@ -46,11 +41,11 @@ const c = new T(), u = (o) => {
|
|
|
46
41
|
console.error(e), c.postErrorToMainThread(e);
|
|
47
42
|
}
|
|
48
43
|
};
|
|
49
|
-
c.attachWorkerSideOnMessage(
|
|
44
|
+
c.attachWorkerSideOnMessage(A);
|
|
50
45
|
export {
|
|
51
46
|
c as default,
|
|
52
|
-
|
|
47
|
+
f as handleBuildInNullifiers,
|
|
53
48
|
C as handleCalcAccessTokenSiblingAndSides,
|
|
54
49
|
u as handleCalcCommitmentsSiblingAndSides,
|
|
55
|
-
|
|
50
|
+
A as onWorkerMessage
|
|
56
51
|
};
|