@hinkal/common 0.1.48 → 0.1.50

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("../../constants/chains.constants.cjs"),n=require("../../functions/web3/events/balanceChangedHandler.cjs");require("../../types/circom-data.types.cjs");const r=require("../../types/ethereum-network.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const c=require("../snapshot/ClientAccessTokenSnapshotService.cjs"),i=require("../snapshot/ClientCommitmentsSnapshotService.cjs"),o=require("../snapshot/ClientNullifierSnapshotService.cjs"),a=async e=>{const{maxPageSize:t}=s.networkRegistry[e.getCurrentChainId()];await e.getEthereumAddress(),e.commitmentsSnapshotService?.intervalClear(),e.commitmentsSnapshotService=new i.ClientCommitmentsSnapshotService(e.getContractWithFetcher(r.ContractType.HinkalContract),t),e.nullifierSnapshotService?.intervalClear(),e.nullifierSnapshotService=new o.ClientNullifierSnapshotService(e.getContractWithFetcher(r.ContractType.HinkalContract),t),e.accessTokenSnapshotService?.intervalClear(),e.accessTokenSnapshotService=new c.ClientAccessTokenSnapshotService(e.getContractWithFetcher(r.ContractType.CrossChainAccessTokenContract),t),await Promise.all([e.commitmentsSnapshotService.init(),e.nullifierSnapshotService.init(),e.accessTokenSnapshotService.init()]),e.merkleTreeHinkal=e.commitmentsSnapshotService.merkleTree,e.merkleTreeAccessToken=e.accessTokenSnapshotService.merkleTree,e.nullifiers=e.nullifierSnapshotService.nullifiers,e.encryptedOutputs=e.commitmentsSnapshotService.encryptedOutputs,e.commitmentsSnapshotService.onNewEvent=n.balanceChangedHandler,e.nullifierSnapshotService.onNewEvent=n.balanceChangedHandler};exports.resetMerkleTrees=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../constants/chains.constants.cjs"),n=require("../../functions/web3/events/balanceChangedHandler.cjs");require("../../types/circom-data.types.cjs");const r=require("../../types/ethereum-network.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const o=require("../snapshot/ClientAccessTokenSnapshotService.cjs"),i=require("../snapshot/ClientCommitmentsSnapshotService.cjs"),a=require("../snapshot/ClientNullifierSnapshotService.cjs"),S=async e=>{const{maxPageSize:t}=c.networkRegistry[e.getCurrentChainId()],s=await e.getEthereumAddress();e.commitmentsSnapshotService?.intervalClear(),e.commitmentsSnapshotService=new i.ClientCommitmentsSnapshotService(e.getContractWithFetcher(r.ContractType.HinkalContract),t,s),e.nullifierSnapshotService?.intervalClear(),e.nullifierSnapshotService=new a.ClientNullifierSnapshotService(e.getContractWithFetcher(r.ContractType.HinkalContract),t),e.accessTokenSnapshotService?.intervalClear(),e.accessTokenSnapshotService=new o.ClientAccessTokenSnapshotService(e.getContractWithFetcher(r.ContractType.CrossChainAccessTokenContract),t),await Promise.all([e.commitmentsSnapshotService.init(),e.nullifierSnapshotService.init(),e.accessTokenSnapshotService.init()]),e.merkleTreeHinkal=e.commitmentsSnapshotService.merkleTree,e.merkleTreeAccessToken=e.accessTokenSnapshotService.merkleTree,e.nullifiers=e.nullifierSnapshotService.nullifiers,e.encryptedOutputs=e.commitmentsSnapshotService.encryptedOutputs,e.commitmentsSnapshotService.onNewEvent=n.balanceChangedHandler,e.nullifierSnapshotService.onNewEvent=n.balanceChangedHandler};exports.resetMerkleTrees=S;
@@ -5,14 +5,15 @@ import { ContractType as r } from "../../types/ethereum-network.types.mjs";
5
5
  import "../../types/transactions.types.mjs";
6
6
  import "../../types/curve.types.mjs";
7
7
  import { ClientAccessTokenSnapshotService as n } from "../snapshot/ClientAccessTokenSnapshotService.mjs";
8
- import { ClientCommitmentsSnapshotService as s } from "../snapshot/ClientCommitmentsSnapshotService.mjs";
9
- import { ClientNullifierSnapshotService as i } from "../snapshot/ClientNullifierSnapshotService.mjs";
10
- const T = async (e) => {
11
- const { maxPageSize: t } = c[e.getCurrentChainId()];
12
- await e.getEthereumAddress(), e.commitmentsSnapshotService?.intervalClear(), e.commitmentsSnapshotService = new s(
8
+ import { ClientCommitmentsSnapshotService as i } from "../snapshot/ClientCommitmentsSnapshotService.mjs";
9
+ import { ClientNullifierSnapshotService as m } from "../snapshot/ClientNullifierSnapshotService.mjs";
10
+ const d = async (e) => {
11
+ const { maxPageSize: t } = c[e.getCurrentChainId()], s = await e.getEthereumAddress();
12
+ e.commitmentsSnapshotService?.intervalClear(), e.commitmentsSnapshotService = new i(
13
13
  e.getContractWithFetcher(r.HinkalContract),
14
- t
15
- ), e.nullifierSnapshotService?.intervalClear(), e.nullifierSnapshotService = new i(
14
+ t,
15
+ s
16
+ ), e.nullifierSnapshotService?.intervalClear(), e.nullifierSnapshotService = new m(
16
17
  e.getContractWithFetcher(r.HinkalContract),
17
18
  t
18
19
  ), e.accessTokenSnapshotService?.intervalClear(), e.accessTokenSnapshotService = new n(
@@ -25,5 +26,5 @@ const T = async (e) => {
25
26
  ]), e.merkleTreeHinkal = e.commitmentsSnapshotService.merkleTree, e.merkleTreeAccessToken = e.accessTokenSnapshotService.merkleTree, e.nullifiers = e.nullifierSnapshotService.nullifiers, e.encryptedOutputs = e.commitmentsSnapshotService.encryptedOutputs, e.commitmentsSnapshotService.onNewEvent = o, e.nullifierSnapshotService.onNewEvent = o;
26
27
  };
27
28
  export {
28
- T as resetMerkleTrees
29
+ d as resetMerkleTrees
29
30
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../utxo/Utxo.cjs"),u=require("../../webworker/utxoWorker/utxoWorker.types.cjs"),y=require("../../webworker/performTaskWithWorker.cjs"),d=require("../../webworker/worker.registry.cjs"),m=require("../../constants/vite.constants.cjs");class S{NUM_WORKERS;NUM_WORKERS_BATCH_PROCESS;constructor(){m.isNode?(this.NUM_WORKERS=1,this.NUM_WORKERS_BATCH_PROCESS=1):(this.NUM_WORKERS=3,this.NUM_WORKERS_BATCH_PROCESS=Math.ceil(navigator.deviceMemory??4))}async createUtxoPromise(s){return await y.performTaskWithWorker({type:d.WorkerVariant.UTXO,payload:s})}async batchFilterUtxosWithNullifier(s,t){const r=this.sliceArrayIntoParts(s,this.NUM_WORKERS).map(o=>this.createUtxoPromise({type:u.UtxoWorkerActionType.BATCH_FILTER_UTXOS_WITH_NULLIFIER,data:{utxos:o.map(a=>a.getConstructableParams()),nullifiers:t}}));return(await Promise.all(r)).flat().map(o=>new p.Utxo(o))}async buildBatchProcess(s,t){const r=this.sliceArrayIntoParts(s,this.NUM_WORKERS).map(a=>this.createUtxoPromise({type:u.UtxoWorkerActionType.BUILD_UTXOS,data:{signature:t.getSignature(),encryptedOutputs:a}}));return(await Promise.all(r)).flat().map(a=>new p.Utxo(a))}sliceArrayIntoParts(s,t){const e=Math.ceil(s.length/t);return Array.from({length:t},(c,o)=>s.slice(e*o,e*(o+1)))}findLastOutput(s,t){let e=t;return s.forEach(r=>{r!==t&&(e=r)}),e}async batchProcess(s,t,e){const r=this.sliceArrayIntoParts(s,this.NUM_WORKERS_BATCH_PROCESS),c=e.getSignature(),o=r.map(i=>{const n={type:u.UtxoWorkerActionType.DECIPHER_OUTPUTS,data:{encryptedOutputs:i,lastOutput:t,signature:c}};return this.createUtxoPromise(n)}),a=await Promise.all(o),R=a.map(({additionalEncryptedOutputs:i})=>i).flat(),l=new Set,h=R.reduce((i,n)=>l.has(n.value)?i:(l.add(n.value),[...i,n]),[]),U=this.findLastOutput(a.map(i=>i.lastOutput),t);return{additionalEncryptedOutputs:h,lastOutput:U??t}}}exports.MultiThreadedUtxoUtils=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("../utxo/Utxo.cjs"),p=require("../../webworker/utxoWorker/utxoWorker.types.cjs"),y=require("../../webworker/performTaskWithWorker.cjs"),d=require("../../webworker/worker.registry.cjs"),m=require("../../constants/vite.constants.cjs");class S{NUM_WORKERS;NUM_WORKERS_BATCH_PROCESS;constructor(){m.isNode?(this.NUM_WORKERS=1,this.NUM_WORKERS_BATCH_PROCESS=1):(this.NUM_WORKERS=3,this.NUM_WORKERS_BATCH_PROCESS=Math.ceil(navigator.deviceMemory??4))}async createUtxoPromise(e){return await y.performTaskWithWorker({type:d.WorkerVariant.UTXO,payload:e})}async batchFilterUtxosWithNullifier(e,t){const r=this.sliceArrayIntoParts(e,this.NUM_WORKERS).map(o=>this.createUtxoPromise({type:p.UtxoWorkerActionType.BATCH_FILTER_UTXOS_WITH_NULLIFIER,data:{utxos:o.map(a=>a.getConstructableParams()),nullifiers:t}}));return(await Promise.all(r)).flat().map(o=>new R.Utxo(o))}async buildBatchProcess(e,t){const r=this.sliceArrayIntoParts(e,this.NUM_WORKERS).map(a=>this.createUtxoPromise({type:p.UtxoWorkerActionType.BUILD_UTXOS,data:{signature:t.getSignature(),encryptedOutputs:a}}));return(await Promise.all(r)).flat().map(a=>new R.Utxo(a))}sliceArrayIntoParts(e,t){const s=Math.ceil(e.length/t);return Array.from({length:t},(c,o)=>e.slice(s*o,s*(o+1)))}findLastOutput(e,t){let s=t;return e.forEach(r=>{r!==t&&(s=r)}),s}async batchProcess(e,t,s){const r=this.sliceArrayIntoParts(e,this.NUM_WORKERS_BATCH_PROCESS),c=s.getSignature(),o=r.map(n=>{const i={type:p.UtxoWorkerActionType.DECIPHER_OUTPUTS,data:{encryptedOutputs:n,lastOutput:t,signature:c}};return this.createUtxoPromise(i)}),a=await Promise.all(o),U=a.map(({additionalEncryptedOutputs:n})=>n).flat(),h=new Set,u=U.reduce((n,i)=>h.has(i.value)?n:(h.add(i.value),[...n,i]),[]),l=this.findLastOutput(a.map(n=>n.lastOutput),t);return u.length<10?console.log({uniqueEncryptedOutputs:u,newLastOutput:l,lastOutput:t}):console.log("number of new unique outputs",u.length,{newLastOutput:l,lastOutput:t}),{additionalEncryptedOutputs:u,lastOutput:l??t}}}exports.MultiThreadedUtxoUtils=S;
@@ -1,13 +1,13 @@
1
- import { Utxo as l } from "../utxo/Utxo.mjs";
2
- import { UtxoWorkerActionType as u } from "../../webworker/utxoWorker/utxoWorker.types.mjs";
1
+ import { Utxo as R } from "../utxo/Utxo.mjs";
2
+ import { UtxoWorkerActionType as p } from "../../webworker/utxoWorker/utxoWorker.types.mjs";
3
3
  import { performTaskWithWorker as S } from "../../webworker/performTaskWithWorker.mjs";
4
4
  import { WorkerVariant as d } from "../../webworker/worker.registry.mjs";
5
- import { isNode as O } from "../../constants/vite.constants.mjs";
5
+ import { isNode as U } from "../../constants/vite.constants.mjs";
6
6
  class W {
7
7
  NUM_WORKERS;
8
8
  NUM_WORKERS_BATCH_PROCESS;
9
9
  constructor() {
10
- O ? (this.NUM_WORKERS = 1, this.NUM_WORKERS_BATCH_PROCESS = 1) : (this.NUM_WORKERS = 3, this.NUM_WORKERS_BATCH_PROCESS = Math.ceil(navigator.deviceMemory ?? 4));
10
+ U ? (this.NUM_WORKERS = 1, this.NUM_WORKERS_BATCH_PROCESS = 1) : (this.NUM_WORKERS = 3, this.NUM_WORKERS_BATCH_PROCESS = Math.ceil(navigator.deviceMemory ?? 4));
11
11
  }
12
12
  async createUtxoPromise(s) {
13
13
  return await S({
@@ -17,30 +17,30 @@ class W {
17
17
  }
18
18
  async batchFilterUtxosWithNullifier(s, t) {
19
19
  const r = this.sliceArrayIntoParts(s, this.NUM_WORKERS).map(
20
- (a) => this.createUtxoPromise({
21
- type: u.BATCH_FILTER_UTXOS_WITH_NULLIFIER,
20
+ (o) => this.createUtxoPromise({
21
+ type: p.BATCH_FILTER_UTXOS_WITH_NULLIFIER,
22
22
  data: {
23
- utxos: a.map((o) => o.getConstructableParams()),
23
+ utxos: o.map((a) => a.getConstructableParams()),
24
24
  nullifiers: t
25
25
  }
26
26
  })
27
27
  );
28
- return (await Promise.all(r)).flat().map((a) => new l(a));
28
+ return (await Promise.all(r)).flat().map((o) => new R(o));
29
29
  }
30
30
  async buildBatchProcess(s, t) {
31
31
  const r = this.sliceArrayIntoParts(s, this.NUM_WORKERS).map(
32
- (o) => this.createUtxoPromise({
33
- type: u.BUILD_UTXOS,
34
- data: { signature: t.getSignature(), encryptedOutputs: o }
32
+ (a) => this.createUtxoPromise({
33
+ type: p.BUILD_UTXOS,
34
+ data: { signature: t.getSignature(), encryptedOutputs: a }
35
35
  })
36
36
  );
37
- return (await Promise.all(r)).flat().map((o) => new l(o));
37
+ return (await Promise.all(r)).flat().map((a) => new R(a));
38
38
  }
39
39
  sliceArrayIntoParts(s, t) {
40
40
  const e = Math.ceil(s.length / t);
41
41
  return Array.from(
42
42
  { length: t },
43
- (c, a) => s.slice(e * a, e * (a + 1))
43
+ (c, o) => s.slice(e * o, e * (o + 1))
44
44
  );
45
45
  }
46
46
  findLastOutput(s, t) {
@@ -50,24 +50,24 @@ class W {
50
50
  }), e;
51
51
  }
52
52
  async batchProcess(s, t, e) {
53
- const r = this.sliceArrayIntoParts(s, this.NUM_WORKERS_BATCH_PROCESS), c = e.getSignature(), a = r.map((i) => {
54
- const n = {
55
- type: u.DECIPHER_OUTPUTS,
53
+ const r = this.sliceArrayIntoParts(s, this.NUM_WORKERS_BATCH_PROCESS), c = e.getSignature(), o = r.map((n) => {
54
+ const i = {
55
+ type: p.DECIPHER_OUTPUTS,
56
56
  data: {
57
- encryptedOutputs: i,
57
+ encryptedOutputs: n,
58
58
  lastOutput: t,
59
59
  // doesn't matter what we pass here, it will not be used regardless
60
60
  signature: c
61
61
  }
62
62
  };
63
- return this.createUtxoPromise(n);
64
- }), o = await Promise.all(a), m = o.map(({ additionalEncryptedOutputs: i }) => i).flat(), p = /* @__PURE__ */ new Set(), R = m.reduce((i, n) => p.has(n.value) ? i : (p.add(n.value), [...i, n]), []), h = this.findLastOutput(
65
- o.map((i) => i.lastOutput),
63
+ return this.createUtxoPromise(i);
64
+ }), a = await Promise.all(o), h = a.map(({ additionalEncryptedOutputs: n }) => n).flat(), m = /* @__PURE__ */ new Set(), u = h.reduce((n, i) => m.has(i.value) ? n : (m.add(i.value), [...n, i]), []), l = this.findLastOutput(
65
+ a.map((n) => n.lastOutput),
66
66
  t
67
67
  );
68
- return {
69
- additionalEncryptedOutputs: R,
70
- lastOutput: h ?? t
68
+ return u.length < 10 ? console.log({ uniqueEncryptedOutputs: u, newLastOutput: l, lastOutput: t }) : console.log("number of new unique outputs", u.length, { newLastOutput: l, lastOutput: t }), {
69
+ additionalEncryptedOutputs: u,
70
+ lastOutput: l ?? t
71
71
  // keep the last output the same if no new output is present
72
72
  };
73
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hinkal/common",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "homepage": "hinkal.pro",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"