@waku/rln 0.1.6-b7e9b08.0 → 0.1.6-f7778a9.0
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/bundle/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/index.js +2 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/_sha2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/hmac.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/pbkdf2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/scrypt.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha256.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha512.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/utils.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
- package/bundle/node_modules/{@ethersproject/keccak256/node_modules/js-sha3 → js-sha3}/src/sha3.js +2 -2
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +0 -3
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +3 -3
- package/bundle/packages/core/dist/lib/filter/filter.js +0 -3
- package/bundle/packages/core/dist/lib/light_push/light_push.js +0 -3
- package/bundle/packages/core/dist/lib/message/version_0.js +1 -4
- package/bundle/packages/core/dist/lib/metadata/metadata.js +0 -3
- package/bundle/packages/core/dist/lib/store/store.js +3 -3
- package/bundle/packages/rln/dist/codec.js +3 -3
- package/bundle/packages/rln/dist/contract/constants.js +8 -1
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +138 -75
- package/bundle/packages/rln/dist/contract/rln_contract.js +3 -3
- package/bundle/packages/rln/dist/credentials_manager.js +15 -10
- package/bundle/packages/rln/dist/keystore/keystore.js +4 -4
- package/bundle/packages/rln/dist/message.js +11 -0
- package/bundle/packages/rln/dist/rln.js +3 -3
- package/bundle/packages/rln/dist/utils/epoch.js +3 -3
- package/bundle/packages/utils/dist/common/sharding/index.js +4 -4
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/constants.d.ts +6 -0
- package/dist/contract/constants.js +6 -0
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/index.d.ts +1 -0
- package/dist/contract/index.js +1 -0
- package/dist/contract/index.js.map +1 -1
- package/dist/contract/rln_base_contract.d.ts +37 -22
- package/dist/contract/rln_base_contract.js +135 -72
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/types.d.ts +5 -0
- package/dist/contract/types.js.map +1 -1
- package/dist/credentials_manager.js +12 -7
- package/dist/credentials_manager.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +2 -2
- package/dist/message.d.ts +5 -4
- package/dist/message.js +2 -0
- package/dist/message.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +9 -0
- package/src/contract/index.ts +1 -0
- package/src/contract/rln_base_contract.ts +181 -103
- package/src/contract/types.ts +5 -0
- package/src/credentials_manager.ts +20 -7
- package/src/index.ts +3 -1
- package/src/keystore/keystore.ts +4 -2
- package/src/keystore/types.ts +2 -2
- package/src/message.ts +7 -4
- package/bundle/packages/utils/node_modules/@waku/interfaces/dist/connection_manager.js +0 -19
- package/bundle/packages/utils/node_modules/@waku/interfaces/dist/health_indicator.js +0 -12
- package/bundle/packages/utils/node_modules/@waku/interfaces/dist/protocols.js +0 -92
- /package/bundle/packages/{utils/node_modules/@waku/interfaces → interfaces}/dist/constants.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/native.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/rng.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/stringify.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/v4.js +0 -0
package/bundle/_virtual/utils.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {};
|
1
|
+
var utils = {exports: {}};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __module };
|
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {
|
1
|
+
var utils = {};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __exports };
|
package/bundle/index.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
export { RLNDecoder, RLNEncoder } from './packages/rln/dist/codec.js';
|
2
2
|
export { RLN_ABI } from './packages/rln/dist/contract/abi.js';
|
3
3
|
export { RLNContract } from './packages/rln/dist/contract/rln_contract.js';
|
4
|
-
export { LINEA_CONTRACT } from './packages/rln/dist/contract/constants.js';
|
4
|
+
export { DEFAULT_Q, DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS } from './packages/rln/dist/contract/constants.js';
|
5
|
+
export { MembershipState } from './packages/rln/dist/contract/types.js';
|
5
6
|
export { RLNBaseContract } from './packages/rln/dist/contract/rln_base_contract.js';
|
6
7
|
export { createRLN } from './packages/rln/dist/create.js';
|
7
8
|
export { RLNCredentialsManager } from './packages/rln/dist/credentials_manager.js';
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { __exports as _sha2 } from '../../../../../../_virtual/_sha2.js';
|
2
2
|
import './_assert.js';
|
3
3
|
import './utils.js';
|
4
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
4
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
5
5
|
import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
|
6
6
|
|
7
7
|
Object.defineProperty(_sha2, "__esModule", { value: true });
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { __exports as hmac } from '../../../../../../_virtual/hmac.js';
|
2
2
|
import './_assert.js';
|
3
3
|
import './utils.js';
|
4
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
4
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
5
5
|
import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
|
6
6
|
|
7
7
|
(function (exports) {
|
@@ -2,7 +2,7 @@ import { __exports as pbkdf2$1 } from '../../../../../../_virtual/pbkdf22.js';
|
|
2
2
|
import './_assert.js';
|
3
3
|
import './hmac.js';
|
4
4
|
import './utils.js';
|
5
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
5
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
6
6
|
import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
|
7
7
|
import { __exports as hmac } from '../../../../../../_virtual/hmac.js';
|
8
8
|
|
@@ -3,7 +3,7 @@ import './_assert.js';
|
|
3
3
|
import './sha256.js';
|
4
4
|
import './pbkdf2.js';
|
5
5
|
import './utils.js';
|
6
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
6
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
7
7
|
import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
|
8
8
|
import { __exports as pbkdf2 } from '../../../../../../_virtual/pbkdf22.js';
|
9
9
|
import { __exports as sha256 } from '../../../../../../_virtual/sha2562.js';
|
@@ -2,7 +2,7 @@ import { __exports as sha256 } from '../../../../../../_virtual/sha2562.js';
|
|
2
2
|
import './_sha2.js';
|
3
3
|
import './utils.js';
|
4
4
|
import { __exports as _sha2 } from '../../../../../../_virtual/_sha2.js';
|
5
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
5
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
6
6
|
|
7
7
|
Object.defineProperty(sha256, "__esModule", { value: true });
|
8
8
|
sha256.sha224 = sha256.sha256 = void 0;
|
@@ -4,7 +4,7 @@ import './_u64.js';
|
|
4
4
|
import './utils.js';
|
5
5
|
import { __exports as _u64 } from '../../../../../../_virtual/_u64.js';
|
6
6
|
import { __exports as _sha2 } from '../../../../../../_virtual/_sha2.js';
|
7
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
7
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
8
8
|
|
9
9
|
Object.defineProperty(sha512, "__esModule", { value: true });
|
10
10
|
sha512.sha384 = sha512.sha512_256 = sha512.sha512_224 = sha512.sha512 = sha512.SHA512 = void 0;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
1
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
2
2
|
import './cryptoBrowser.js';
|
3
3
|
import { __exports as cryptoBrowser } from '../../../../../../_virtual/cryptoBrowser.js';
|
4
4
|
|
package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { __exports as random } from '../../../../../_virtual/random.js';
|
2
2
|
import '../@noble/hashes/utils.js';
|
3
|
-
import { __exports as utils } from '../../../../../_virtual/
|
3
|
+
import { __exports as utils } from '../../../../../_virtual/utils2.js';
|
4
4
|
|
5
5
|
Object.defineProperty(random, "__esModule", { value: true });
|
6
6
|
random.getRandomBytes = random.getRandomBytesSync = void 0;
|
package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import { commonjsGlobal } from '../../../../../_virtual/_commonjsHelpers.js';
|
2
2
|
import { commonjsRequire } from '../../../../../_virtual/_commonjs-dynamic-modules.js';
|
3
|
-
import { __module as utils } from '../../../../../_virtual/
|
3
|
+
import { __module as utils } from '../../../../../_virtual/utils.js';
|
4
4
|
import '../@noble/hashes/_assert.js';
|
5
5
|
import '../@noble/hashes/utils.js';
|
6
6
|
import { __exports as _assert } from '../../../../../_virtual/_assert.js';
|
7
|
-
import { __exports as utils$1 } from '../../../../../_virtual/
|
7
|
+
import { __exports as utils$1 } from '../../../../../_virtual/utils2.js';
|
8
8
|
|
9
9
|
utils.exports;
|
10
10
|
|
package/bundle/node_modules/{@ethersproject/keccak256/node_modules/js-sha3 → js-sha3}/src/sha3.js
RENAMED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { getDefaultExportFromCjs, commonjsGlobal } from '
|
2
|
-
import { __module as sha3$1 } from '
|
1
|
+
import { getDefaultExportFromCjs, commonjsGlobal } from '../../../_virtual/_commonjsHelpers.js';
|
2
|
+
import { __module as sha3$1 } from '../../../_virtual/sha3.js';
|
3
3
|
|
4
4
|
/**
|
5
5
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
@@ -15,9 +15,6 @@ import '../../../../../node_modules/@multiformats/multiaddr/dist/src/multiaddr.j
|
|
15
15
|
import '../../../../interfaces/dist/protocols.js';
|
16
16
|
import '../../../../interfaces/dist/connection_manager.js';
|
17
17
|
import '../../../../interfaces/dist/health_indicator.js';
|
18
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
|
19
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
|
20
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
|
21
18
|
import { Logger } from '../../../../utils/dist/logger/index.js';
|
22
19
|
import './keep_alive_manager.js';
|
23
20
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import '../../../../
|
2
|
-
import '../../../../
|
3
|
-
import '../../../../
|
1
|
+
import '../../../../interfaces/dist/protocols.js';
|
2
|
+
import '../../../../interfaces/dist/connection_manager.js';
|
3
|
+
import '../../../../interfaces/dist/health_indicator.js';
|
4
4
|
import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
|
5
5
|
import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
|
6
6
|
import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -1,9 +1,6 @@
|
|
1
1
|
import '../../../../interfaces/dist/protocols.js';
|
2
2
|
import '../../../../interfaces/dist/connection_manager.js';
|
3
3
|
import '../../../../interfaces/dist/health_indicator.js';
|
4
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
|
5
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
|
6
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
|
7
4
|
import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
|
8
5
|
import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
|
9
6
|
import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -10,9 +10,6 @@ import '../../../../proto/dist/generated/store_v3.js';
|
|
10
10
|
import '../../../../proto/dist/generated/peer_exchange.js';
|
11
11
|
import '../../../../proto/dist/generated/metadata.js';
|
12
12
|
import '../../../../proto/dist/generated/sds_message.js';
|
13
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
|
14
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
|
15
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
|
16
13
|
import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
|
17
14
|
import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
|
18
15
|
import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -29,9 +29,6 @@ class DecodedMessage {
|
|
29
29
|
get contentTopic() {
|
30
30
|
return this.proto.contentTopic;
|
31
31
|
}
|
32
|
-
get _rawTimestamp() {
|
33
|
-
return this.proto.timestamp;
|
34
|
-
}
|
35
32
|
get timestamp() {
|
36
33
|
// In the case we receive a value that is bigger than JS's max number,
|
37
34
|
// we catch the error and return undefined.
|
@@ -53,7 +50,7 @@ class DecodedMessage {
|
|
53
50
|
get version() {
|
54
51
|
// https://rfc.vac.dev/spec/14/
|
55
52
|
// > If omitted, the value SHOULD be interpreted as version 0.
|
56
|
-
return this.proto.version ??
|
53
|
+
return this.proto.version ?? Version;
|
57
54
|
}
|
58
55
|
get rateLimitProof() {
|
59
56
|
return this.proto.rateLimitProof;
|
@@ -10,9 +10,6 @@ import '../../../../proto/dist/generated/store_v3.js';
|
|
10
10
|
import '../../../../proto/dist/generated/peer_exchange.js';
|
11
11
|
import '../../../../proto/dist/generated/metadata.js';
|
12
12
|
import '../../../../proto/dist/generated/sds_message.js';
|
13
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/protocols.js';
|
14
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/connection_manager.js';
|
15
|
-
import '../../../../utils/node_modules/@waku/interfaces/dist/health_indicator.js';
|
16
13
|
import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
|
17
14
|
import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
|
18
15
|
import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import '../../../../
|
2
|
-
import '../../../../
|
3
|
-
import '../../../../
|
1
|
+
import '../../../../interfaces/dist/protocols.js';
|
2
|
+
import '../../../../interfaces/dist/connection_manager.js';
|
3
|
+
import '../../../../interfaces/dist/health_indicator.js';
|
4
4
|
import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
|
5
5
|
import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
|
6
6
|
import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import '../../
|
2
|
-
import '../../
|
3
|
-
import '../../
|
1
|
+
import '../../interfaces/dist/protocols.js';
|
2
|
+
import '../../interfaces/dist/connection_manager.js';
|
3
|
+
import '../../interfaces/dist/health_indicator.js';
|
4
4
|
import '../../../node_modules/multiformats/dist/src/bases/base10.js';
|
5
5
|
import '../../../node_modules/multiformats/dist/src/bases/base16.js';
|
6
6
|
import '../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -12,6 +12,7 @@ const LINEA_CONTRACT = {
|
|
12
12
|
*/
|
13
13
|
const RATE_LIMIT_TIERS = {
|
14
14
|
LOW: 20, // Suggested minimum rate - 20 messages per epoch
|
15
|
+
MEDIUM: 200,
|
15
16
|
HIGH: 600 // Suggested maximum rate - 600 messages per epoch
|
16
17
|
};
|
17
18
|
// Global rate limit parameters
|
@@ -21,6 +22,12 @@ const RATE_LIMIT_PARAMS = {
|
|
21
22
|
MAX_TOTAL_RATE: 160_000, // Maximum total rate limit across all memberships
|
22
23
|
EPOCH_LENGTH: 600 // Epoch length in seconds (10 minutes)
|
23
24
|
};
|
25
|
+
/**
|
26
|
+
* Default Q value for the RLN contract
|
27
|
+
* This is the upper bound for the ID commitment
|
28
|
+
* @see https://github.com/waku-org/specs/blob/master/standards/core/rln-contract.md#implementation-suggestions
|
29
|
+
*/
|
30
|
+
const DEFAULT_Q = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
24
31
|
const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
|
25
32
|
|
26
|
-
export { DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS };
|
33
|
+
export { DEFAULT_Q, DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS };
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import '../../../
|
2
|
-
import '../../../
|
3
|
-
import '../../../
|
1
|
+
import '../../../interfaces/dist/protocols.js';
|
2
|
+
import '../../../interfaces/dist/connection_manager.js';
|
3
|
+
import '../../../interfaces/dist/health_indicator.js';
|
4
4
|
import '../../../../node_modules/multiformats/dist/src/bases/base10.js';
|
5
5
|
import '../../../../node_modules/multiformats/dist/src/bases/base16.js';
|
6
6
|
import '../../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -14,7 +14,7 @@ import '../../../../node_modules/multiformats/dist/src/bases/identity.js';
|
|
14
14
|
import '../../../../node_modules/multiformats/dist/src/codecs/json.js';
|
15
15
|
import { Logger } from '../../../utils/dist/logger/index.js';
|
16
16
|
import { RLN_ABI } from './abi.js';
|
17
|
-
import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './constants.js';
|
17
|
+
import { DEFAULT_Q, DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './constants.js';
|
18
18
|
import { MembershipState } from './types.js';
|
19
19
|
import { Contract } from '../../../../node_modules/@ethersproject/contracts/lib.esm/index.js';
|
20
20
|
import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
|
@@ -24,15 +24,37 @@ class RLNBaseContract {
|
|
24
24
|
contract;
|
25
25
|
deployBlock;
|
26
26
|
rateLimit;
|
27
|
+
minRateLimit;
|
28
|
+
maxRateLimit;
|
29
|
+
/**
|
30
|
+
* Default Q value for the RLN contract.
|
31
|
+
* @see https://github.com/waku-org/waku-rlnv2-contract/blob/b7e9a9b1bc69256a2a3076c1f099b50ce84e7eff/src/WakuRlnV2.sol#L25
|
32
|
+
*/
|
33
|
+
idCommitmentBigIntLimit = DEFAULT_Q;
|
27
34
|
_members = new Map();
|
28
35
|
_membersFilter;
|
29
36
|
_membershipErasedFilter;
|
30
37
|
_membersExpiredFilter;
|
31
38
|
/**
|
32
|
-
*
|
33
|
-
* Allows injecting a mocked contract for testing purposes.
|
39
|
+
* Private constructor for RLNBaseContract. Use static create() instead.
|
34
40
|
*/
|
35
41
|
constructor(options) {
|
42
|
+
const { address, signer, rateLimit = DEFAULT_RATE_LIMIT, contract } = options;
|
43
|
+
log.info("Initializing RLNBaseContract", { address, rateLimit });
|
44
|
+
this.contract = contract || new Contract(address, RLN_ABI, signer);
|
45
|
+
this.rateLimit = rateLimit;
|
46
|
+
try {
|
47
|
+
log.info("Setting up event filters");
|
48
|
+
// Initialize event filters
|
49
|
+
this._membersFilter = this.contract.filters.MembershipRegistered();
|
50
|
+
this._membershipErasedFilter = this.contract.filters.MembershipErased();
|
51
|
+
this._membersExpiredFilter = this.contract.filters.MembershipExpired();
|
52
|
+
log.info("Event filters initialized successfully");
|
53
|
+
}
|
54
|
+
catch (error) {
|
55
|
+
log.error("Failed to initialize event filters", { error });
|
56
|
+
throw new Error("Failed to initialize event filters: " + error.message);
|
57
|
+
}
|
36
58
|
// Initialize members and subscriptions
|
37
59
|
this.fetchMembers()
|
38
60
|
.then(() => {
|
@@ -41,14 +63,22 @@ class RLNBaseContract {
|
|
41
63
|
.catch((error) => {
|
42
64
|
log.error("Failed to initialize members", { error });
|
43
65
|
});
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
66
|
+
}
|
67
|
+
/**
|
68
|
+
* Static async factory to create and initialize RLNBaseContract
|
69
|
+
*/
|
70
|
+
static async create(options) {
|
71
|
+
const instance = new RLNBaseContract(options);
|
72
|
+
const [min, max, idCommitmentBigIntLimit] = await Promise.all([
|
73
|
+
instance.contract.minMembershipRateLimit(),
|
74
|
+
instance.contract.maxMembershipRateLimit(),
|
75
|
+
instance.contract.Q()
|
76
|
+
]);
|
77
|
+
instance.minRateLimit = BigNumber.from(min).toNumber();
|
78
|
+
instance.maxRateLimit = BigNumber.from(max).toNumber();
|
79
|
+
instance.idCommitmentBigIntLimit = BigInt(idCommitmentBigIntLimit.toString());
|
80
|
+
instance.validateRateLimit(instance.rateLimit);
|
81
|
+
return instance;
|
52
82
|
}
|
53
83
|
/**
|
54
84
|
* Gets the current rate limit for this contract instance
|
@@ -69,20 +99,20 @@ class RLNBaseContract {
|
|
69
99
|
return this.contract.provider;
|
70
100
|
}
|
71
101
|
/**
|
72
|
-
* Gets the minimum allowed rate limit
|
73
|
-
* @returns Promise<number> The minimum rate limit in messages per epoch
|
102
|
+
* Gets the minimum allowed rate limit (cached)
|
74
103
|
*/
|
75
|
-
|
76
|
-
|
77
|
-
|
104
|
+
getMinRateLimit() {
|
105
|
+
if (this.minRateLimit === undefined)
|
106
|
+
throw new Error("minRateLimit not initialized");
|
107
|
+
return this.minRateLimit;
|
78
108
|
}
|
79
109
|
/**
|
80
|
-
* Gets the maximum allowed rate limit
|
81
|
-
* @returns Promise<number> The maximum rate limit in messages per epoch
|
110
|
+
* Gets the maximum allowed rate limit (cached)
|
82
111
|
*/
|
83
|
-
|
84
|
-
|
85
|
-
|
112
|
+
getMaxRateLimit() {
|
113
|
+
if (this.maxRateLimit === undefined)
|
114
|
+
throw new Error("maxRateLimit not initialized");
|
115
|
+
return this.maxRateLimit;
|
86
116
|
}
|
87
117
|
/**
|
88
118
|
* Gets the maximum total rate limit across all memberships
|
@@ -115,7 +145,7 @@ class RLNBaseContract {
|
|
115
145
|
* Updates the rate limit for future registrations
|
116
146
|
* @param newRateLimit The new rate limit to use
|
117
147
|
*/
|
118
|
-
|
148
|
+
setRateLimit(newRateLimit) {
|
119
149
|
this.validateRateLimit(newRateLimit);
|
120
150
|
this.rateLimit = newRateLimit;
|
121
151
|
}
|
@@ -247,75 +277,67 @@ class RLNBaseContract {
|
|
247
277
|
this.processEvents([event]);
|
248
278
|
});
|
249
279
|
}
|
250
|
-
|
251
|
-
* Helper method to get remaining messages in current epoch
|
252
|
-
* @param membershipId The ID of the membership to check
|
253
|
-
* @returns number of remaining messages allowed in current epoch
|
254
|
-
*/
|
255
|
-
async getRemainingMessages(membershipId) {
|
256
|
-
try {
|
257
|
-
const [startTime, , rateLimit] = await this.contract.getMembershipInfo(membershipId);
|
258
|
-
// Calculate current epoch
|
259
|
-
const currentTime = Math.floor(Date.now() / 1000);
|
260
|
-
const epochsPassed = Math.floor((currentTime - startTime) / RATE_LIMIT_PARAMS.EPOCH_LENGTH);
|
261
|
-
const currentEpochStart = startTime + epochsPassed * RATE_LIMIT_PARAMS.EPOCH_LENGTH;
|
262
|
-
// Get message count in current epoch using contract's function
|
263
|
-
const messageCount = await this.contract.getMessageCount(membershipId, currentEpochStart);
|
264
|
-
return Math.max(0, BigNumber.from(rateLimit)
|
265
|
-
.sub(BigNumber.from(messageCount))
|
266
|
-
.toNumber());
|
267
|
-
}
|
268
|
-
catch (error) {
|
269
|
-
log.error(`Error getting remaining messages: ${error.message}`);
|
270
|
-
return 0; // Fail safe: assume no messages remaining on error
|
271
|
-
}
|
272
|
-
}
|
273
|
-
async getMembershipInfo(idCommitment) {
|
280
|
+
async getMembershipInfo(idCommitmentBigInt) {
|
274
281
|
try {
|
275
|
-
const
|
282
|
+
const membershipData = await this.contract.memberships(idCommitmentBigInt);
|
276
283
|
const currentBlock = await this.contract.provider.getBlockNumber();
|
284
|
+
const [depositAmount, activeDuration, gracePeriodStartTimestamp, gracePeriodDuration, rateLimit, index, holder, token] = membershipData;
|
285
|
+
const gracePeriodEnd = gracePeriodStartTimestamp.add(gracePeriodDuration);
|
277
286
|
let state;
|
278
|
-
if (currentBlock <
|
287
|
+
if (currentBlock < gracePeriodStartTimestamp.toNumber()) {
|
279
288
|
state = MembershipState.Active;
|
280
289
|
}
|
281
|
-
else if (currentBlock <
|
290
|
+
else if (currentBlock < gracePeriodEnd.toNumber()) {
|
282
291
|
state = MembershipState.GracePeriod;
|
283
292
|
}
|
284
293
|
else {
|
285
294
|
state = MembershipState.Expired;
|
286
295
|
}
|
287
|
-
const index = await this.getMemberIndex(idCommitment);
|
288
|
-
if (!index)
|
289
|
-
return undefined;
|
290
296
|
return {
|
291
297
|
index,
|
292
|
-
idCommitment,
|
293
|
-
rateLimit: rateLimit
|
294
|
-
startBlock:
|
295
|
-
endBlock:
|
296
|
-
state
|
298
|
+
idCommitment: idCommitmentBigInt.toString(),
|
299
|
+
rateLimit: Number(rateLimit),
|
300
|
+
startBlock: gracePeriodStartTimestamp.toNumber(),
|
301
|
+
endBlock: gracePeriodEnd.toNumber(),
|
302
|
+
state,
|
303
|
+
depositAmount,
|
304
|
+
activeDuration,
|
305
|
+
gracePeriodDuration,
|
306
|
+
holder,
|
307
|
+
token
|
297
308
|
};
|
298
309
|
}
|
299
310
|
catch (error) {
|
311
|
+
log.error("Error in getMembershipInfo:", error);
|
300
312
|
return undefined;
|
301
313
|
}
|
302
314
|
}
|
303
|
-
async extendMembership(
|
304
|
-
|
315
|
+
async extendMembership(idCommitmentBigInt) {
|
316
|
+
const tx = await this.contract.extendMemberships([idCommitmentBigInt]);
|
317
|
+
await tx.wait();
|
318
|
+
return tx;
|
305
319
|
}
|
306
|
-
async eraseMembership(
|
307
|
-
|
320
|
+
async eraseMembership(idCommitmentBigInt, eraseFromMembershipSet = true) {
|
321
|
+
if (!(await this.isExpired(idCommitmentBigInt)) ||
|
322
|
+
!(await this.isInGracePeriod(idCommitmentBigInt))) {
|
323
|
+
throw new Error("Membership is not expired or in grace period");
|
324
|
+
}
|
325
|
+
const estimatedGas = await this.contract.estimateGas["eraseMemberships(uint256[],bool)"]([idCommitmentBigInt], eraseFromMembershipSet);
|
326
|
+
const gasLimit = estimatedGas.add(10000);
|
327
|
+
const tx = await this.contract["eraseMemberships(uint256[],bool)"]([idCommitmentBigInt], eraseFromMembershipSet, { gasLimit });
|
328
|
+
await tx.wait();
|
329
|
+
return tx;
|
308
330
|
}
|
309
|
-
async registerMembership(
|
331
|
+
async registerMembership(idCommitmentBigInt, rateLimit = DEFAULT_RATE_LIMIT) {
|
310
332
|
if (rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
311
333
|
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE) {
|
312
334
|
throw new Error(`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`);
|
313
335
|
}
|
314
|
-
return this.contract.register(
|
336
|
+
return this.contract.register(idCommitmentBigInt, rateLimit, []);
|
315
337
|
}
|
316
|
-
async withdraw(token,
|
338
|
+
async withdraw(token, walletAddress) {
|
317
339
|
try {
|
318
|
-
const tx = await this.contract.withdraw(token,
|
340
|
+
const tx = await this.contract.withdraw(token, walletAddress);
|
319
341
|
await tx.wait();
|
320
342
|
}
|
321
343
|
catch (error) {
|
@@ -326,7 +348,7 @@ class RLNBaseContract {
|
|
326
348
|
try {
|
327
349
|
log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
|
328
350
|
// Check if the ID commitment is already registered
|
329
|
-
const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt
|
351
|
+
const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt);
|
330
352
|
if (existingIndex) {
|
331
353
|
throw new Error(`ID commitment is already registered with index ${existingIndex}`);
|
332
354
|
}
|
@@ -432,13 +454,15 @@ class RLNBaseContract {
|
|
432
454
|
}
|
433
455
|
}
|
434
456
|
/**
|
435
|
-
* Validates that the rate limit is within the allowed range
|
457
|
+
* Validates that the rate limit is within the allowed range (sync)
|
436
458
|
* @throws Error if the rate limit is outside the allowed range
|
437
459
|
*/
|
438
460
|
validateRateLimit(rateLimit) {
|
439
|
-
if (
|
440
|
-
|
441
|
-
|
461
|
+
if (this.minRateLimit === undefined || this.maxRateLimit === undefined) {
|
462
|
+
throw new Error("Rate limits not initialized");
|
463
|
+
}
|
464
|
+
if (rateLimit < this.minRateLimit || rateLimit > this.maxRateLimit) {
|
465
|
+
throw new Error(`Rate limit must be between ${this.minRateLimit} and ${this.maxRateLimit} messages per epoch`);
|
442
466
|
}
|
443
467
|
}
|
444
468
|
get membersFilter() {
|
@@ -459,9 +483,9 @@ class RLNBaseContract {
|
|
459
483
|
}
|
460
484
|
return this._membersExpiredFilter;
|
461
485
|
}
|
462
|
-
async getMemberIndex(
|
486
|
+
async getMemberIndex(idCommitmentBigInt) {
|
463
487
|
try {
|
464
|
-
const events = await this.contract.queryFilter(this.contract.filters.MembershipRegistered(
|
488
|
+
const events = await this.contract.queryFilter(this.contract.filters.MembershipRegistered(idCommitmentBigInt));
|
465
489
|
if (events.length === 0)
|
466
490
|
return undefined;
|
467
491
|
// Get the most recent registration event
|
@@ -472,6 +496,45 @@ class RLNBaseContract {
|
|
472
496
|
return undefined;
|
473
497
|
}
|
474
498
|
}
|
499
|
+
async getMembershipStatus(idCommitment) {
|
500
|
+
const [isExpired, isInGrace] = await Promise.all([
|
501
|
+
this.contract.isExpired(idCommitment),
|
502
|
+
this.contract.isInGracePeriod(idCommitment)
|
503
|
+
]);
|
504
|
+
if (isExpired)
|
505
|
+
return "expired";
|
506
|
+
if (isInGrace)
|
507
|
+
return "grace";
|
508
|
+
return "active";
|
509
|
+
}
|
510
|
+
/**
|
511
|
+
* Checks if a membership is expired for the given idCommitment
|
512
|
+
* @param idCommitmentBigInt The idCommitment as bigint
|
513
|
+
* @returns Promise<boolean> True if expired, false otherwise
|
514
|
+
*/
|
515
|
+
async isExpired(idCommitmentBigInt) {
|
516
|
+
try {
|
517
|
+
return await this.contract.isExpired(idCommitmentBigInt);
|
518
|
+
}
|
519
|
+
catch (error) {
|
520
|
+
log.error("Error in isExpired:", error);
|
521
|
+
return false;
|
522
|
+
}
|
523
|
+
}
|
524
|
+
/**
|
525
|
+
* Checks if a membership is in grace period for the given idCommitment
|
526
|
+
* @param idCommitmentBigInt The idCommitment as bigint
|
527
|
+
* @returns Promise<boolean> True if in grace period, false otherwise
|
528
|
+
*/
|
529
|
+
async isInGracePeriod(idCommitmentBigInt) {
|
530
|
+
try {
|
531
|
+
return await this.contract.isInGracePeriod(idCommitmentBigInt);
|
532
|
+
}
|
533
|
+
catch (error) {
|
534
|
+
log.error("Error in isInGracePeriod:", error);
|
535
|
+
return false;
|
536
|
+
}
|
537
|
+
}
|
475
538
|
}
|
476
539
|
|
477
540
|
export { RLNBaseContract };
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import '../../../
|
2
|
-
import '../../../
|
3
|
-
import '../../../
|
1
|
+
import '../../../interfaces/dist/protocols.js';
|
2
|
+
import '../../../interfaces/dist/connection_manager.js';
|
3
|
+
import '../../../interfaces/dist/health_indicator.js';
|
4
4
|
import { hexToBytes } from '../../../utils/dist/bytes/index.js';
|
5
5
|
import { Logger } from '../../../utils/dist/logger/index.js';
|
6
6
|
import { MerkleRootTracker } from '../root_tracker.js';
|