@hinkal/common 0.1.68 → 0.2.2
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/event-service/AbstractEventService.cjs +1 -1
- package/data-structures/event-service/AbstractEventService.mjs +30 -42
- package/data-structures/snapshot/ClientAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientAccessTokenSnapshotService.mjs +5 -10
- package/data-structures/snapshot/ClientCommitmentsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientCommitmentsSnapshotService.mjs +5 -10
- package/data-structures/snapshot/ClientNullifierSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientNullifierSnapshotService.mjs +3 -8
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../constants/reorg-depths.constants.cjs"),o=require("../../functions/utils/resolve-sync.utils.cjs");class u{contract;eventConfig;_latestBlockNumber;maxPageSize;isReady=!1;_onNewEvent;isServer;intervalId;inProgress;constructor(e,t,s,r,n){this.contract=e,this.eventConfig=t,this._latestBlockNumber=s,this.maxPageSize=n,this.isServer=r,this.inProgress=!1}get latestBlockNumber(){return this._latestBlockNumber}set onNewEvent(e){this._onNewEvent=e}intervalClear(){this.isReady=!1,this._onNewEvent=void 0,clearInterval(this.intervalId)}async init(){if(this.isReady)throw new Error("Already initialized");this.isReady=!0,await this.retrieveEvents(this._latestBlockNumber+1),this.intervalId=setInterval(async()=>{await this.retrieveEvents(this.latestBlockNumber)},3500)}requireReady(){if(!this.isReady)throw new Error("Not ready")}emitNewEvent(e){this._onNewEvent?.(e)}getLastBlockNumberForEventRequest=async()=>{const e=await this.contract.provider.getBlockNumber();if(!this.isServer)return e;const{chainId:t}=await this.contract.provider.getNetwork();return Math.max(this.latestBlockNumber,e-v.blockReorgDepth[t]+1)};async retrieveEvents(e,t=!1){try{if(this.requireReady(),this.inProgress&&!t)return!1;this.inProgress=!0;const s=await this.getLastBlockNumberForEventRequest();if(s<e)return this.inProgress=!1,!1;const r=o.getSequence(e,s,this.maxPageSize);return await o.resolveSync(r.map(({from:n,to:i})=>async()=>{const c=await this.contract.queryFilter(this.contract.filters[this.eventConfig.name](),n,i);let a=[];c.length>0&&(a=await this.processEventsPage(c)),this._latestBlockNumber=i,await this.afterEventsAccepted(),a.length>0&&this.emitNewEvent()})),this.inProgress=!1,!0}catch{return this.inProgress=!1,!1}}async processEventsPage(e){const t=[];return await o.resolveSync(e.map(s=>async()=>{const{args:r,blockNumber:n}=s;if(!r)throw new Error("Wrong event structure");const i=this.mapEvent(r);await this.acceptEvent(i,n)&&t.push(i)})),t}handleEvent=async(...e)=>{const{args:t}=this.eventConfig,{blockNumber:s}=e[e.length-1],r=e.slice(0,t.length),n=t.reduce((a,l,h)=>(a[l]=r[h],a),{});if(!s)throw new Error("Wrong event structure");const i=this.mapEvent(n);if(!await this.acceptEvent(i,s))throw new Error("Failed to retrieve events");this._latestBlockNumber=s,await this.afterEventsAccepted(),this.emitNewEvent(i)}}exports.AbstractEventService=u;
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
import { blockReorgDepth as v } from "../../constants/reorg-depths.constants.mjs";
|
|
2
|
-
import { getSequence as
|
|
3
|
-
|
|
4
|
-
import "axios";
|
|
5
|
-
import "../../constants/chains.constants.mjs";
|
|
6
|
-
import "../../constants/vite.constants.mjs";
|
|
7
|
-
import "../../types/circom-data.types.mjs";
|
|
8
|
-
import "../../types/transactions.types.mjs";
|
|
9
|
-
import "../../types/curve.types.mjs";
|
|
10
|
-
import "circomlibjs-hinkal-fork";
|
|
11
|
-
import "libsodium-wrappers";
|
|
12
|
-
import "process";
|
|
13
|
-
import "buffer";
|
|
14
|
-
import { logError as u } from "../../error-handling/logError.mjs";
|
|
15
|
-
class q {
|
|
2
|
+
import { getSequence as u, resolveSync as o } from "../../functions/utils/resolve-sync.utils.mjs";
|
|
3
|
+
class g {
|
|
16
4
|
contract;
|
|
17
5
|
eventConfig;
|
|
18
6
|
_latestBlockNumber;
|
|
@@ -23,8 +11,8 @@ class q {
|
|
|
23
11
|
intervalId;
|
|
24
12
|
inProgress;
|
|
25
13
|
// to remove race conditions
|
|
26
|
-
constructor(e,
|
|
27
|
-
this.contract = e, this.eventConfig =
|
|
14
|
+
constructor(e, t, s, r, n) {
|
|
15
|
+
this.contract = e, this.eventConfig = t, this._latestBlockNumber = s, this.maxPageSize = n, this.isServer = r, this.inProgress = !1;
|
|
28
16
|
}
|
|
29
17
|
get latestBlockNumber() {
|
|
30
18
|
return this._latestBlockNumber;
|
|
@@ -53,55 +41,55 @@ class q {
|
|
|
53
41
|
const e = await this.contract.provider.getBlockNumber();
|
|
54
42
|
if (!this.isServer)
|
|
55
43
|
return e;
|
|
56
|
-
const { chainId:
|
|
57
|
-
return Math.max(this.latestBlockNumber, e - v[
|
|
44
|
+
const { chainId: t } = await this.contract.provider.getNetwork();
|
|
45
|
+
return Math.max(this.latestBlockNumber, e - v[t] + 1);
|
|
58
46
|
};
|
|
59
|
-
async retrieveEvents(e,
|
|
47
|
+
async retrieveEvents(e, t = !1) {
|
|
60
48
|
try {
|
|
61
|
-
if (this.requireReady(), this.inProgress && !
|
|
49
|
+
if (this.requireReady(), this.inProgress && !t)
|
|
62
50
|
return !1;
|
|
63
51
|
this.inProgress = !0;
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
52
|
+
const s = await this.getLastBlockNumberForEventRequest();
|
|
53
|
+
if (s < e)
|
|
66
54
|
return this.inProgress = !1, !1;
|
|
67
|
-
const
|
|
68
|
-
return await
|
|
69
|
-
|
|
70
|
-
const
|
|
55
|
+
const r = u(e, s, this.maxPageSize);
|
|
56
|
+
return await o(
|
|
57
|
+
r.map(({ from: n, to: i }) => async () => {
|
|
58
|
+
const c = await this.contract.queryFilter(
|
|
71
59
|
this.contract.filters[this.eventConfig.name](),
|
|
72
60
|
n,
|
|
73
61
|
i
|
|
74
62
|
);
|
|
75
63
|
let a = [];
|
|
76
|
-
|
|
64
|
+
c.length > 0 && (a = await this.processEventsPage(c)), this._latestBlockNumber = i, await this.afterEventsAccepted(), a.length > 0 && this.emitNewEvent();
|
|
77
65
|
})
|
|
78
66
|
), this.inProgress = !1, !0;
|
|
79
|
-
} catch
|
|
80
|
-
return
|
|
67
|
+
} catch {
|
|
68
|
+
return this.inProgress = !1, !1;
|
|
81
69
|
}
|
|
82
70
|
}
|
|
83
71
|
async processEventsPage(e) {
|
|
84
|
-
const
|
|
85
|
-
return await
|
|
86
|
-
e.map((
|
|
87
|
-
const { args:
|
|
88
|
-
if (!
|
|
72
|
+
const t = [];
|
|
73
|
+
return await o(
|
|
74
|
+
e.map((s) => async () => {
|
|
75
|
+
const { args: r, blockNumber: n } = s;
|
|
76
|
+
if (!r)
|
|
89
77
|
throw new Error("Wrong event structure");
|
|
90
|
-
const i = this.mapEvent(
|
|
91
|
-
await this.acceptEvent(i, n) &&
|
|
78
|
+
const i = this.mapEvent(r);
|
|
79
|
+
await this.acceptEvent(i, n) && t.push(i);
|
|
92
80
|
})
|
|
93
|
-
),
|
|
81
|
+
), t;
|
|
94
82
|
}
|
|
95
83
|
handleEvent = async (...e) => {
|
|
96
|
-
const { args:
|
|
97
|
-
if (!
|
|
84
|
+
const { args: t } = this.eventConfig, { blockNumber: s } = e[e.length - 1], r = e.slice(0, t.length), n = t.reduce((a, h, l) => (a[h] = r[l], a), {});
|
|
85
|
+
if (!s)
|
|
98
86
|
throw new Error("Wrong event structure");
|
|
99
87
|
const i = this.mapEvent(n);
|
|
100
|
-
if (!await this.acceptEvent(i,
|
|
88
|
+
if (!await this.acceptEvent(i, s))
|
|
101
89
|
throw new Error("Failed to retrieve events");
|
|
102
|
-
this._latestBlockNumber =
|
|
90
|
+
this._latestBlockNumber = s, await this.afterEventsAccepted(), this.emitNewEvent(i);
|
|
103
91
|
};
|
|
104
92
|
}
|
|
105
93
|
export {
|
|
106
|
-
|
|
94
|
+
g as AbstractEventService
|
|
107
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../event-service/AbstractAccessTokenSnapshotService.cjs");require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../event-service/AbstractAccessTokenSnapshotService.cjs");require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const t=require("../../API/fetchCommitmentsCache.cjs");class c extends s.AbstractAccessTokenSnapshotService{constructor(r,e){super(r,0,!1,e)}async fetchSnapshot(){const{chainId:r}=await this.contract.provider.getNetwork(),e=await t.fetchAccessTokenSnapshot(r);if(e.accessTokenContractAddress!==this.contract.address||e.chainId!==r)throw Error("Commitment Snapshot: incorrect contract or chain id");return{latestBlockNumber:e.latestBlockNumber,merkleTree:e.merkleTree,senderAddresses:e.senderAddresses,senderAddressIndexMap:e.senderAddressIndexMap}}persistSnapshot(r){return Promise.resolve()}}exports.ClientAccessTokenSnapshotService=c;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractAccessTokenSnapshotService as
|
|
1
|
+
import { AbstractAccessTokenSnapshotService as s } from "../event-service/AbstractAccessTokenSnapshotService.mjs";
|
|
2
2
|
import "ethers";
|
|
3
3
|
import "circomlibjs-hinkal-fork";
|
|
4
4
|
import "libsodium-wrappers";
|
|
@@ -6,18 +6,13 @@ import "process";
|
|
|
6
6
|
import "buffer";
|
|
7
7
|
import "../../constants/vite.constants.mjs";
|
|
8
8
|
import "../../constants/reorg-depths.constants.mjs";
|
|
9
|
-
import "
|
|
10
|
-
|
|
11
|
-
import "../../types/circom-data.types.mjs";
|
|
12
|
-
import "../../types/transactions.types.mjs";
|
|
13
|
-
import "../../types/curve.types.mjs";
|
|
14
|
-
import { fetchAccessTokenSnapshot as s } from "../../API/fetchCommitmentsCache.mjs";
|
|
15
|
-
class u extends t {
|
|
9
|
+
import { fetchAccessTokenSnapshot as t } from "../../API/fetchCommitmentsCache.mjs";
|
|
10
|
+
class k extends s {
|
|
16
11
|
constructor(r, e) {
|
|
17
12
|
super(r, 0, !1, e);
|
|
18
13
|
}
|
|
19
14
|
async fetchSnapshot() {
|
|
20
|
-
const { chainId: r } = await this.contract.provider.getNetwork(), e = await
|
|
15
|
+
const { chainId: r } = await this.contract.provider.getNetwork(), e = await t(r);
|
|
21
16
|
if (e.accessTokenContractAddress !== this.contract.address || e.chainId !== r)
|
|
22
17
|
throw Error("Commitment Snapshot: incorrect contract or chain id");
|
|
23
18
|
return {
|
|
@@ -32,5 +27,5 @@ class u extends t {
|
|
|
32
27
|
}
|
|
33
28
|
}
|
|
34
29
|
export {
|
|
35
|
-
|
|
30
|
+
k as ClientAccessTokenSnapshotService
|
|
36
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const r=require("../event-service/AbstractCommitmentsSnapshotService.cjs"),s=require("../../API/fetchCommitmentsCache.cjs");class i extends r.AbstractCommitmentsSnapshotService{constructor(t,e){super(t,0,!1,e)}async fetchSnapshot(){const{chainId:t}=await this.contract.provider.getNetwork(),e=await s.fetchCommitmentsSnapshot(t);if(e.hinkalAddress!==this.contract.address||e.chainId!==t)throw Error("Commitment Snapshot: incorrect contract or chain id");return{latestBlockNumber:e.latestBlockNumber,merkleTree:e.merkleTree,encryptedOutputs:e.encryptedOutputs}}persistSnapshot(t){return Promise.resolve()}}exports.ClientCommitmentsSnapshotService=i;
|
|
@@ -5,19 +5,14 @@ import "process";
|
|
|
5
5
|
import "buffer";
|
|
6
6
|
import "../../constants/vite.constants.mjs";
|
|
7
7
|
import "../../constants/reorg-depths.constants.mjs";
|
|
8
|
-
import "
|
|
9
|
-
import "../../
|
|
10
|
-
|
|
11
|
-
import "../../types/transactions.types.mjs";
|
|
12
|
-
import "../../types/curve.types.mjs";
|
|
13
|
-
import { fetchCommitmentsSnapshot as e } from "../../API/fetchCommitmentsCache.mjs";
|
|
14
|
-
import { AbstractCommitmentsSnapshotService as o } from "../event-service/AbstractCommitmentsSnapshotService.mjs";
|
|
15
|
-
class v extends o {
|
|
8
|
+
import { AbstractCommitmentsSnapshotService as e } from "../event-service/AbstractCommitmentsSnapshotService.mjs";
|
|
9
|
+
import { fetchCommitmentsSnapshot as o } from "../../API/fetchCommitmentsCache.mjs";
|
|
10
|
+
class u extends e {
|
|
16
11
|
constructor(r, t) {
|
|
17
12
|
super(r, 0, !1, t);
|
|
18
13
|
}
|
|
19
14
|
async fetchSnapshot() {
|
|
20
|
-
const { chainId: r } = await this.contract.provider.getNetwork(), t = await
|
|
15
|
+
const { chainId: r } = await this.contract.provider.getNetwork(), t = await o(r);
|
|
21
16
|
if (t.hinkalAddress !== this.contract.address || t.chainId !== r)
|
|
22
17
|
throw Error("Commitment Snapshot: incorrect contract or chain id");
|
|
23
18
|
return {
|
|
@@ -31,5 +26,5 @@ class v extends o {
|
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
28
|
export {
|
|
34
|
-
|
|
29
|
+
u as ClientCommitmentsSnapshotService
|
|
35
30
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const i=require("../event-service/AbstractNullifierSnapshotService.cjs"),t=require("../../API/fetchNullifiers.cjs");class s extends i.AbstractNullifierSnapshotService{constructor(e,r){super(e,0,!1,r)}async fetchSnapshot(){const{chainId:e}=await this.contract.provider.getNetwork(),r=await t.fetchNullifiers(e);return{latestBlockNumber:r.latestBlockNumber,nullifiers:r.nullifiers}}persistSnapshot(e){return Promise.resolve()}}exports.ClientNullifierSnapshotService=s;
|
|
@@ -5,14 +5,9 @@ import "process";
|
|
|
5
5
|
import "buffer";
|
|
6
6
|
import "../../constants/vite.constants.mjs";
|
|
7
7
|
import "../../constants/reorg-depths.constants.mjs";
|
|
8
|
-
import "
|
|
9
|
-
import "../../constants/chains.constants.mjs";
|
|
10
|
-
import "../../types/circom-data.types.mjs";
|
|
11
|
-
import "../../types/transactions.types.mjs";
|
|
12
|
-
import "../../types/curve.types.mjs";
|
|
8
|
+
import { AbstractNullifierSnapshotService as e } from "../event-service/AbstractNullifierSnapshotService.mjs";
|
|
13
9
|
import { fetchNullifiers as i } from "../../API/fetchNullifiers.mjs";
|
|
14
|
-
|
|
15
|
-
class b extends o {
|
|
10
|
+
class h extends e {
|
|
16
11
|
constructor(t, r) {
|
|
17
12
|
super(t, 0, !1, r);
|
|
18
13
|
}
|
|
@@ -28,5 +23,5 @@ class b extends o {
|
|
|
28
23
|
}
|
|
29
24
|
}
|
|
30
25
|
export {
|
|
31
|
-
|
|
26
|
+
h as ClientNullifierSnapshotService
|
|
32
27
|
};
|