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.
@@ -1 +1 @@
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
+ "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 i } from "../../functions/web3/etherFunctions.mjs";
2
- import { poseidonFunction as m } from "../../crypto/poseidon.mjs";
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 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;
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 r;
14
+ return o;
10
15
  };
11
16
  export {
12
- g as getPatchedAccessTokenMerkleTree
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"),P=require("../../crypto/poseidon.cjs"),C=require("../../constants/vite.constants.cjs"),R=require("./fetchOnChainRootHashes.cjs"),p=async(e,a)=>{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:a,merkleTreeAccessTokenSerialized:e.toJSON()}}});return{accessTokenSiblings:s.accessTokenSiblings,accessTokenSiblingSides:s.accessTokenSiblingSides,rootHashAccessToken:o}},_=async(e,a,o,s,i,n)=>{console.log("hinkalDeposit sa5");const r=o.getAccessKey();console.log("hinkalDeposit sa6",{accessKey:r});const t=A.getPatchedAccessTokenMerkleTree(a,r,i,n),g=e.getRootHash();if(g===void 0)throw new Error("Root hash not available from hinkal merkle tree");let l,c;return C.isNode?(l=await p(t,r),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(t,r),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:g,rootHashAccessToken:l.rootHashAccessToken}},N=async(e,a,o,s,i)=>{console.log("hinkalDeposit sa3");const n=a.getAccessKey();if(console.log("hinkalDeposit sa4",{accessKey:n}),!i||s){const g=W.MerkleTree.create(P.poseidonFunction,0n),l=A.getPatchedAccessTokenMerkleTree(g,n,s,i);console.log("pre calculating access token siblings and root hash",{accessKey:n});const[c,k]=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:k}),{inCommitmentSiblings:k.inCommitmentSiblings,inCommitmentSiblingSides:k.inCommitmentSiblingSides,accessTokenSiblings:c.accessTokenSiblings,accessTokenSiblingSides:c.accessTokenSiblingSides,rootHashHinkal:H.toBigInt(k.rootHashHinkal),rootHashAccessToken:c.rootHashAccessToken}}const t=await u.fetchMerkleTreeSiblings(e,o,n);return{inCommitmentSiblings:t.inCommitmentSiblings,inCommitmentSiblingSides:t.inCommitmentSiblingSides,accessTokenSiblings:t.accessTokenSiblings,accessTokenSiblingSides:t.accessTokenSiblingSides,rootHashHinkal:H.toBigInt(t.rootHashHinkal),rootHashAccessToken:H.toBigInt(t.rootHashAccessToken)}},I=async(e,a,o)=>{if(!a||!o)return!1;try{const s=a.getRootHash(),i=o.getRootHash();if(!s||!i)return!1;const{hinkalRootHash:n,accessTokenRootHash:r}=await R.fetchOnChainRootHashes(e);return s===n&&i===r}catch{return!1}},y=async(e,a,o,s,i,n,r)=>{const t=await I(e,n,r);return console.log("hinkalDeposit sa2",{isLocalFresh:t}),t?_(n,r,a,o,s,i):N(e,a,o,s,i)},M=async(e,a,o,s,i,n,r,t,g)=>{if(C.isNode){const{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d}=await y(e,s,i,n,r,a,o),f=await S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:i,onChainCreation:t,proverVersion:g}}});return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d,inNullifiers:f}}else{const[{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d},f]=await Promise.all([y(e,s,i,n,r,a,o),S.performTaskWithWorker({type:m.WorkerVariant.ZKProof,payload:{type:h.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:i,onChainCreation:t,proverVersion:g}}})]);return{inCommitmentSiblings:l,inCommitmentSiblingSides:c,accessTokenSiblings:k,accessTokenSiblingSides:T,rootHashHinkal:b,rootHashAccessToken:d,inNullifiers:f}}};exports.getDataFromWorkers=M;exports.getMerkleTreeSiblingsAndRootHashes=y;
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 A } from "../../data-structures/merkle-tree/getPatchedAccessTokenMerkleTree.mjs";
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 h } from "../../webworker/zkProofWorker/zkProofWorker.types.mjs";
5
+ import { ZKProofWorkerActionType as b } from "../../webworker/zkProofWorker/zkProofWorker.types.mjs";
6
6
  import { fetchMerkleTreeSiblings as C } from "./fetchMerkleTreeSiblings.mjs";
7
- import { toBigInt as H } 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, a) => {
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", { rootHash: s, patchedMerkleTree: o }), s === void 0)
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: h.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,
23
+ type: b.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,
19
24
  data: {
20
- accessKey: a,
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, a, s, e, n, i) => {
35
+ }, w = async (o, i, s, e, t, n) => {
31
36
  console.log("hinkalDeposit sa5");
32
- const c = s.getAccessKey();
33
- console.log("hinkalDeposit sa6", { accessKey: c });
34
- const t = A(
37
+ const a = s.getAccessKey();
38
+ console.log("hinkalDeposit sa6", { accessKey: a });
39
+ const c = N(
40
+ i,
35
41
  a,
36
- c,
37
- n,
38
- i
39
- ), S = o.getRootHash();
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 N ? (r = await p(t, c), l = await g({
48
+ return A ? (r = await d(c, a), l = await g({
44
49
  type: k.ZKProof,
45
50
  payload: {
46
- type: h.CALC_COMMITMENTS_SIBLING_AND_SIDES,
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
- p(t, c),
55
+ d(c, a),
51
56
  g({
52
57
  type: k.ZKProof,
53
58
  payload: {
54
- type: h.CALC_COMMITMENTS_SIBLING_AND_SIDES,
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: S,
68
+ rootHashHinkal: m,
64
69
  rootHashAccessToken: r.rootHashAccessToken
65
70
  };
66
- }, D = async (o, a, s, e, n) => {
71
+ }, D = async (o, i, s, e, t) => {
67
72
  console.log("hinkalDeposit sa3");
68
- const i = a.getAccessKey();
69
- if (console.log("hinkalDeposit sa4", { accessKey: i }), !n || e) {
70
- const S = R.create(I, 0n), r = A(
71
- S,
72
- i,
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
- n
84
+ t
75
85
  );
76
- console.log("pre calculating access token siblings and root hash", { accessKey: i });
77
- const [l, m] = await Promise.all([
78
- p(r, i),
79
- C(o, s, i)
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: m }), {
82
- inCommitmentSiblings: m.inCommitmentSiblings,
83
- inCommitmentSiblingSides: m.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: H(m.rootHashHinkal),
96
+ rootHashHinkal: p(S.rootHashHinkal),
87
97
  rootHashAccessToken: l.rootHashAccessToken
88
98
  };
89
99
  }
90
- const t = await C(o, s, i);
100
+ console.log("kaksk", { chainId: o, inputUtxosSerialized: s, accessKey: n });
101
+ const c = await C(o, s, n);
91
102
  return {
92
- inCommitmentSiblings: t.inCommitmentSiblings,
93
- inCommitmentSiblingSides: t.inCommitmentSiblingSides,
94
- accessTokenSiblings: t.accessTokenSiblings,
95
- accessTokenSiblingSides: t.accessTokenSiblingSides,
96
- rootHashHinkal: H(t.rootHashHinkal),
97
- rootHashAccessToken: H(t.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, a, s) => {
100
- if (!a || !s)
110
+ }, L = async (o, i, s) => {
111
+ if (!i || !s)
101
112
  return !1;
102
113
  try {
103
- const e = a.getRootHash(), n = s.getRootHash();
104
- if (!e || !n)
114
+ const e = i.getRootHash(), t = s.getRootHash();
115
+ if (!e || !t)
105
116
  return !1;
106
- const { hinkalRootHash: i, accessTokenRootHash: c } = await _(o);
107
- return e === i && n === c;
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, a, s, e, n, i, c) => {
112
- const t = await L(o, i, c);
113
- return console.log("hinkalDeposit sa2", { isLocalFresh: t }), t ? w(
114
- i,
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
- n
120
- ) : D(o, a, s, e, n);
121
- }, v = async (o, a, s, e, n, i, c, t, S) => {
122
- if (N) {
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: m,
127
- accessTokenSiblingSides: b,
137
+ accessTokenSiblings: S,
138
+ accessTokenSiblingSides: h,
128
139
  rootHashHinkal: T,
129
- rootHashAccessToken: d
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
- ), f = await g({
149
+ ), H = await g({
139
150
  type: k.ZKProof,
140
151
  payload: {
141
- type: h.BUILD_IN_NULLIFIERS,
142
- data: { inputUtxosSerialized: n, onChainCreation: t, proverVersion: S }
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: m,
149
- accessTokenSiblingSides: b,
159
+ accessTokenSiblings: S,
160
+ accessTokenSiblingSides: h,
150
161
  rootHashHinkal: T,
151
- rootHashAccessToken: d,
152
- inNullifiers: f
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: m,
160
- accessTokenSiblingSides: b,
170
+ accessTokenSiblings: S,
171
+ accessTokenSiblingSides: h,
161
172
  rootHashHinkal: T,
162
- rootHashAccessToken: d
173
+ rootHashAccessToken: f
163
174
  },
164
- f
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: h.BUILD_IN_NULLIFIERS,
179
- data: { inputUtxosSerialized: n, onChainCreation: t, proverVersion: S }
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: m,
187
- accessTokenSiblingSides: b,
197
+ accessTokenSiblings: S,
198
+ accessTokenSiblingSides: h,
188
199
  rootHashHinkal: T,
189
- rootHashAccessToken: d,
190
- inNullifiers: f
200
+ rootHashAccessToken: f,
201
+ inNullifiers: H
191
202
  };
192
203
  }
193
204
  };
194
205
  export {
195
- v as getDataFromWorkers,
206
+ J as getDataFromWorkers,
196
207
  y as getMerkleTreeSiblingsAndRootHashes
197
208
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h_test_1",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"
@@ -1 +1 @@
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
+ "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 f } from "../constants/chains.constants.mjs";
2
- import { isDevelopment as w } from "../constants/vite.constants.mjs";
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 W = async (e) => {
5
- const o = await h.getWebWorker(e.type);
6
- return new Promise((n, a) => {
7
- let r = {};
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: t, protocol: i, host: m, port: c, hostname: p, href: d } = window.location;
10
- r = {
11
- origin: t,
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: d
16
+ href: l
17
17
  };
18
18
  }
19
- o.onmessage = (t) => {
20
- n(t.data), o.terminate();
21
- }, o.onerror = (t) => {
22
- a(t), o.terminate();
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 s = {
25
- payload: e.payload,
24
+ const a = {
25
+ payload: r.payload,
26
26
  metadata: {
27
- hostLocation: r,
27
+ hostLocation: t,
28
28
  constants: {
29
29
  chains: {
30
- chainIds: f
30
+ chainIds: W
31
31
  },
32
- isDevelopment: w
32
+ isDevelopment: f
33
33
  }
34
34
  }
35
35
  };
36
- o.postMessage(s);
36
+ console.log("performTaskWithWorker a4", { message: a }), e.postMessage(a);
37
37
  });
38
38
  };
39
39
  export {
40
- W as performTaskWithWorker
40
+ w as performTaskWithWorker
41
41
  };
@@ -1 +1 @@
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
+ "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,4 +1,4 @@
1
- const r = "" + new URL("../../assets/zkProofWorkerLauncher-2a1CGTor.js", import.meta.url).href;
1
+ const r = "" + new URL("../../assets/zkProofWorkerLauncher-DQUaX0hI.js", import.meta.url).href;
2
2
  export {
3
3
  r as default
4
4
  };
@@ -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"),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
+ "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 T, calcAccessTokenSiblingsAndSides as g } from "../../functions/snarkjs/common.snarkjs.mjs";
4
- import { WorkerProxy as k } from "../workerProxy.mjs";
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 k(), u = (o) => {
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 } = T(s, a);
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 } = g(e, a);
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
- }, f = (o) => {
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
- }, A = async (o) => {
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
- f(o.payload);
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(A);
49
+ c.attachWorkerSideOnMessage(f);
49
50
  export {
50
51
  c as default,
51
- f as handleBuildInNullifiers,
52
+ M as handleBuildInNullifiers,
52
53
  C as handleCalcAccessTokenSiblingAndSides,
53
54
  u as handleCalcCommitmentsSiblingAndSides,
54
- A as onWorkerMessage
55
+ f as onWorkerMessage
55
56
  };