@waku/rln 0.1.6-b0a2e39.0 → 0.1.6-b4748fd.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 +1 -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/packages/core/dist/lib/connection_manager/connection_manager.js +0 -1
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +0 -1
- package/bundle/packages/core/dist/lib/filter/filter.js +0 -2
- package/bundle/packages/core/dist/lib/light_push/light_push.js +9 -12
- package/bundle/packages/core/dist/lib/message/version_0.js +0 -1
- package/bundle/packages/core/dist/lib/metadata/metadata.js +0 -2
- package/bundle/packages/core/dist/lib/store/store.js +0 -2
- package/bundle/packages/interfaces/dist/protocols.js +0 -10
- package/bundle/packages/proto/dist/generated/light_push.js +3 -3
- package/bundle/packages/rln/dist/codec.js +0 -1
- package/bundle/packages/rln/dist/contract/constants.js +7 -1
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +34 -8
- package/bundle/packages/rln/dist/contract/rln_contract.js +0 -1
- package/bundle/packages/rln/dist/credentials_manager.js +16 -15
- package/bundle/packages/rln/dist/identity.js +5 -8
- package/bundle/packages/rln/dist/keystore/keystore.js +15 -12
- package/bundle/packages/rln/dist/message.js +0 -2
- package/bundle/packages/rln/dist/rln.js +0 -2
- package/bundle/packages/rln/dist/utils/bytes.js +14 -16
- package/bundle/packages/rln/dist/utils/epoch.js +0 -1
- package/bundle/packages/utils/dist/common/sharding/index.js +0 -1
- 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/rln_base_contract.d.ts +6 -0
- package/dist/contract/rln_base_contract.js +34 -7
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/credentials_manager.js +16 -14
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.d.ts +4 -2
- package/dist/identity.js +5 -6
- package/dist/identity.js.map +1 -1
- package/dist/keystore/keystore.js +15 -11
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/utils/bytes.d.ts +2 -6
- package/dist/utils/bytes.js +13 -15
- package/dist/utils/bytes.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +9 -0
- package/src/contract/rln_base_contract.ts +54 -14
- package/src/credentials_manager.ts +27 -21
- package/src/identity.ts +5 -7
- package/src/keystore/keystore.ts +28 -24
- package/src/utils/bytes.ts +21 -25
- package/src/utils/index.ts +1 -1
- package/bundle/packages/core/dist/lib/light_push/light_push_v3.js +0 -30
- package/bundle/packages/core/dist/lib/light_push/utils.js +0 -18
- package/bundle/packages/interfaces/dist/light_push_v3.js +0 -29
- package/bundle/packages/proto/dist/generated/light_push_v3.js +0 -348
- package/dist/contract/test-utils.d.ts +0 -39
- package/dist/contract/test-utils.js +0 -118
- package/dist/contract/test-utils.js.map +0 -1
- package/src/contract/test-utils.ts +0 -179
package/bundle/_virtual/utils.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {
|
1
|
+
var utils = {};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __exports };
|
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {};
|
1
|
+
var utils = {exports: {}};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __module };
|
package/bundle/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
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 { DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS } 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
5
|
export { MembershipState } from './packages/rln/dist/contract/types.js';
|
6
6
|
export { RLNBaseContract } from './packages/rln/dist/contract/rln_base_contract.js';
|
7
7
|
export { createRLN } from './packages/rln/dist/create.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/utils.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/utils.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/utils.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/utils.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/utils.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/utils.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/utils.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/utils.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/utils2.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/utils.js';
|
8
8
|
|
9
9
|
utils.exports;
|
10
10
|
|
@@ -12,7 +12,6 @@ import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
|
|
12
12
|
import '../../../../../node_modules/@multiformats/multiaddr/dist/src/convert.js';
|
13
13
|
import '../../../../../node_modules/@multiformats/multiaddr/dist/src/protocols-table.js';
|
14
14
|
import '../../../../../node_modules/@multiformats/multiaddr/dist/src/multiaddr.js';
|
15
|
-
import '../../../../interfaces/dist/light_push_v3.js';
|
16
15
|
import '../../../../interfaces/dist/protocols.js';
|
17
16
|
import '../../../../interfaces/dist/connection_manager.js';
|
18
17
|
import '../../../../interfaces/dist/health_indicator.js';
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import '../../../../interfaces/dist/light_push_v3.js';
|
2
1
|
import '../../../../interfaces/dist/protocols.js';
|
3
2
|
import '../../../../interfaces/dist/connection_manager.js';
|
4
3
|
import '../../../../interfaces/dist/health_indicator.js';
|
@@ -20,7 +19,6 @@ import '../../../../proto/dist/generated/filter.js';
|
|
20
19
|
import '../../../../proto/dist/generated/topic_only_message.js';
|
21
20
|
import '../../../../proto/dist/generated/filter_v2.js';
|
22
21
|
import '../../../../proto/dist/generated/light_push.js';
|
23
|
-
import '../../../../proto/dist/generated/light_push_v3.js';
|
24
22
|
import '../../../../proto/dist/generated/store_v3.js';
|
25
23
|
import '../../../../proto/dist/generated/peer_exchange.js';
|
26
24
|
import '../../../../proto/dist/generated/metadata.js';
|
@@ -1,7 +1,15 @@
|
|
1
|
-
import '../../../../interfaces/dist/light_push_v3.js';
|
2
1
|
import '../../../../interfaces/dist/protocols.js';
|
3
2
|
import '../../../../interfaces/dist/connection_manager.js';
|
4
3
|
import '../../../../interfaces/dist/health_indicator.js';
|
4
|
+
import '../../../../proto/dist/generated/message.js';
|
5
|
+
import '../../../../proto/dist/generated/filter.js';
|
6
|
+
import '../../../../proto/dist/generated/topic_only_message.js';
|
7
|
+
import '../../../../proto/dist/generated/filter_v2.js';
|
8
|
+
export { PushResponse } from '../../../../proto/dist/generated/light_push.js';
|
9
|
+
import '../../../../proto/dist/generated/store_v3.js';
|
10
|
+
import '../../../../proto/dist/generated/peer_exchange.js';
|
11
|
+
import '../../../../proto/dist/generated/metadata.js';
|
12
|
+
import '../../../../proto/dist/generated/sds_message.js';
|
5
13
|
import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
|
6
14
|
import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
|
7
15
|
import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -15,16 +23,5 @@ import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
|
|
15
23
|
import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
|
16
24
|
import { Logger } from '../../../../utils/dist/logger/index.js';
|
17
25
|
import '../../../../../node_modules/it-length-prefixed/dist/src/decode.js';
|
18
|
-
import '../../../../proto/dist/generated/message.js';
|
19
|
-
import '../../../../proto/dist/generated/filter.js';
|
20
|
-
import '../../../../proto/dist/generated/topic_only_message.js';
|
21
|
-
import '../../../../proto/dist/generated/filter_v2.js';
|
22
|
-
import '../../../../proto/dist/generated/light_push.js';
|
23
|
-
import '../../../../proto/dist/generated/light_push_v3.js';
|
24
|
-
import '../../../../proto/dist/generated/store_v3.js';
|
25
|
-
import '../../../../proto/dist/generated/peer_exchange.js';
|
26
|
-
import '../../../../proto/dist/generated/metadata.js';
|
27
|
-
import '../../../../proto/dist/generated/sds_message.js';
|
28
|
-
import './utils.js';
|
29
26
|
|
30
27
|
new Logger("light-push");
|
@@ -3,7 +3,6 @@ import '../../../../proto/dist/generated/filter.js';
|
|
3
3
|
import '../../../../proto/dist/generated/topic_only_message.js';
|
4
4
|
import '../../../../proto/dist/generated/filter_v2.js';
|
5
5
|
import '../../../../proto/dist/generated/light_push.js';
|
6
|
-
import '../../../../proto/dist/generated/light_push_v3.js';
|
7
6
|
import '../../../../proto/dist/generated/store_v3.js';
|
8
7
|
import '../../../../proto/dist/generated/peer_exchange.js';
|
9
8
|
import '../../../../proto/dist/generated/metadata.js';
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import '../../../../interfaces/dist/light_push_v3.js';
|
2
1
|
import '../../../../interfaces/dist/protocols.js';
|
3
2
|
import '../../../../interfaces/dist/connection_manager.js';
|
4
3
|
import '../../../../interfaces/dist/health_indicator.js';
|
@@ -7,7 +6,6 @@ import '../../../../proto/dist/generated/filter.js';
|
|
7
6
|
import '../../../../proto/dist/generated/topic_only_message.js';
|
8
7
|
import '../../../../proto/dist/generated/filter_v2.js';
|
9
8
|
import '../../../../proto/dist/generated/light_push.js';
|
10
|
-
import '../../../../proto/dist/generated/light_push_v3.js';
|
11
9
|
import '../../../../proto/dist/generated/store_v3.js';
|
12
10
|
import '../../../../proto/dist/generated/peer_exchange.js';
|
13
11
|
import '../../../../proto/dist/generated/metadata.js';
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import '../../../../interfaces/dist/light_push_v3.js';
|
2
1
|
import '../../../../interfaces/dist/protocols.js';
|
3
2
|
import '../../../../interfaces/dist/connection_manager.js';
|
4
3
|
import '../../../../interfaces/dist/health_indicator.js';
|
@@ -20,7 +19,6 @@ import '../../../../proto/dist/generated/filter.js';
|
|
20
19
|
import '../../../../proto/dist/generated/topic_only_message.js';
|
21
20
|
import '../../../../proto/dist/generated/filter_v2.js';
|
22
21
|
import '../../../../proto/dist/generated/light_push.js';
|
23
|
-
import '../../../../proto/dist/generated/light_push_v3.js';
|
24
22
|
import '../../../../proto/dist/generated/store_v3.js';
|
25
23
|
import '../../../../proto/dist/generated/peer_exchange.js';
|
26
24
|
import '../../../../proto/dist/generated/metadata.js';
|
@@ -74,16 +74,6 @@ var ProtocolError;
|
|
74
74
|
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
|
75
75
|
*/
|
76
76
|
ProtocolError["RLN_PROOF_GENERATION"] = "Proof generation failed";
|
77
|
-
/**
|
78
|
-
* Message validation failed according to Light Push v3 specifications.
|
79
|
-
* This includes validation of message format, fields, or other protocol-specific requirements.
|
80
|
-
*/
|
81
|
-
ProtocolError["INVALID_MESSAGE"] = "Invalid message format";
|
82
|
-
/**
|
83
|
-
* Rate limiting error when too many requests are sent in a short period.
|
84
|
-
* Mitigation: Implement backoff strategy or reduce request frequency.
|
85
|
-
*/
|
86
|
-
ProtocolError["RATE_LIMIT_EXCEEDED"] = "Rate limit exceeded";
|
87
77
|
//
|
88
78
|
// RECEIVE ERRORS SECTION
|
89
79
|
//
|
@@ -122,7 +122,7 @@ var PushResponse;
|
|
122
122
|
return decodeMessage(buf, PushResponse.codec(), opts);
|
123
123
|
};
|
124
124
|
})(PushResponse || (PushResponse = {}));
|
125
|
-
var PushRpc;
|
125
|
+
var PushRpc$1;
|
126
126
|
(function (PushRpc) {
|
127
127
|
let _codec;
|
128
128
|
PushRpc.codec = () => {
|
@@ -187,7 +187,7 @@ var PushRpc;
|
|
187
187
|
PushRpc.decode = (buf, opts) => {
|
188
188
|
return decodeMessage(buf, PushRpc.codec(), opts);
|
189
189
|
};
|
190
|
-
})(PushRpc || (PushRpc = {}));
|
190
|
+
})(PushRpc$1 || (PushRpc$1 = {}));
|
191
191
|
var RateLimitProof;
|
192
192
|
(function (RateLimitProof) {
|
193
193
|
let _codec;
|
@@ -386,4 +386,4 @@ var WakuMessage;
|
|
386
386
|
};
|
387
387
|
})(WakuMessage || (WakuMessage = {}));
|
388
388
|
|
389
|
-
export { PushRequest, PushResponse, PushRpc, RateLimitProof, WakuMessage };
|
389
|
+
export { PushRequest, PushResponse, PushRpc$1 as PushRpc, RateLimitProof, WakuMessage };
|
@@ -22,6 +22,12 @@ const RATE_LIMIT_PARAMS = {
|
|
22
22
|
MAX_TOTAL_RATE: 160_000, // Maximum total rate limit across all memberships
|
23
23
|
EPOCH_LENGTH: 600 // Epoch length in seconds (10 minutes)
|
24
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");
|
25
31
|
const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
|
26
32
|
|
27
|
-
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,4 +1,3 @@
|
|
1
|
-
import '../../../interfaces/dist/light_push_v3.js';
|
2
1
|
import '../../../interfaces/dist/protocols.js';
|
3
2
|
import '../../../interfaces/dist/connection_manager.js';
|
4
3
|
import '../../../interfaces/dist/health_indicator.js';
|
@@ -14,8 +13,9 @@ import '../../../../node_modules/multiformats/dist/src/bases/base8.js';
|
|
14
13
|
import '../../../../node_modules/multiformats/dist/src/bases/identity.js';
|
15
14
|
import '../../../../node_modules/multiformats/dist/src/codecs/json.js';
|
16
15
|
import { Logger } from '../../../utils/dist/logger/index.js';
|
16
|
+
import { buildBigIntFromUint8ArrayBE } from '../utils/bytes.js';
|
17
17
|
import { RLN_ABI } from './abi.js';
|
18
|
-
import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './constants.js';
|
18
|
+
import { DEFAULT_Q, DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './constants.js';
|
19
19
|
import { MembershipState } from './types.js';
|
20
20
|
import { Contract } from '../../../../node_modules/@ethersproject/contracts/lib.esm/index.js';
|
21
21
|
import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
|
@@ -27,6 +27,11 @@ class RLNBaseContract {
|
|
27
27
|
rateLimit;
|
28
28
|
minRateLimit;
|
29
29
|
maxRateLimit;
|
30
|
+
/**
|
31
|
+
* Default Q value for the RLN contract.
|
32
|
+
* @see https://github.com/waku-org/waku-rlnv2-contract/blob/b7e9a9b1bc69256a2a3076c1f099b50ce84e7eff/src/WakuRlnV2.sol#L25
|
33
|
+
*/
|
34
|
+
idCommitmentBigIntLimit = DEFAULT_Q;
|
30
35
|
_members = new Map();
|
31
36
|
_membersFilter;
|
32
37
|
_membershipErasedFilter;
|
@@ -65,12 +70,14 @@ class RLNBaseContract {
|
|
65
70
|
*/
|
66
71
|
static async create(options) {
|
67
72
|
const instance = new RLNBaseContract(options);
|
68
|
-
const [min, max] = await Promise.all([
|
73
|
+
const [min, max, idCommitmentBigIntLimit] = await Promise.all([
|
69
74
|
instance.contract.minMembershipRateLimit(),
|
70
|
-
instance.contract.maxMembershipRateLimit()
|
75
|
+
instance.contract.maxMembershipRateLimit(),
|
76
|
+
instance.contract.Q()
|
71
77
|
]);
|
72
78
|
instance.minRateLimit = BigNumber.from(min).toNumber();
|
73
79
|
instance.maxRateLimit = BigNumber.from(max).toNumber();
|
80
|
+
instance.idCommitmentBigIntLimit = BigInt(idCommitmentBigIntLimit.toString());
|
74
81
|
instance.validateRateLimit(instance.rateLimit);
|
75
82
|
return instance;
|
76
83
|
}
|
@@ -338,11 +345,28 @@ class RLNBaseContract {
|
|
338
345
|
log.error(`Error in withdraw: ${error.message}`);
|
339
346
|
}
|
340
347
|
}
|
348
|
+
getIdCommitmentBigInt(bytes) {
|
349
|
+
let idCommitmentBigIntBE = buildBigIntFromUint8ArrayBE(bytes);
|
350
|
+
log.info("1");
|
351
|
+
if (!this.contract) {
|
352
|
+
throw Error("RLN contract is not initialized");
|
353
|
+
}
|
354
|
+
const idCommitmentBigIntLimit = this.contract.idCommitmentBigIntLimit;
|
355
|
+
log.info("idCommitmentBigIntBE: ", idCommitmentBigIntBE);
|
356
|
+
log.info("idCommitmentBigIntLimit: ", idCommitmentBigIntLimit);
|
357
|
+
log.info("idCommitmentBigIntBE >= idCommitmentBigIntLimit: ", idCommitmentBigIntBE >= idCommitmentBigIntLimit);
|
358
|
+
if (idCommitmentBigIntBE >= idCommitmentBigIntLimit) {
|
359
|
+
log.warn(`ID commitment is greater than Q, reducing it by Q(idCommitmentBigIntLimit): ${idCommitmentBigIntBE} % ${idCommitmentBigIntLimit}`);
|
360
|
+
idCommitmentBigIntBE = idCommitmentBigIntBE % idCommitmentBigIntLimit;
|
361
|
+
}
|
362
|
+
return idCommitmentBigIntBE;
|
363
|
+
}
|
341
364
|
async registerWithIdentity(identity) {
|
342
365
|
try {
|
343
366
|
log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
|
367
|
+
const idCommitmentBigInt = this.getIdCommitmentBigInt(identity.IDCommitment);
|
344
368
|
// Check if the ID commitment is already registered
|
345
|
-
const existingIndex = await this.getMemberIndex(
|
369
|
+
const existingIndex = await this.getMemberIndex(idCommitmentBigInt);
|
346
370
|
if (existingIndex) {
|
347
371
|
throw new Error(`ID commitment is already registered with index ${existingIndex}`);
|
348
372
|
}
|
@@ -351,9 +375,11 @@ class RLNBaseContract {
|
|
351
375
|
if (remainingRateLimit < this.rateLimit) {
|
352
376
|
throw new Error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
|
353
377
|
}
|
354
|
-
const estimatedGas = await this.contract.estimateGas.register(
|
378
|
+
const estimatedGas = await this.contract.estimateGas.register(idCommitmentBigInt, this.rateLimit, []);
|
355
379
|
const gasLimit = estimatedGas.add(10000);
|
356
|
-
const txRegisterResponse = await this.contract.register(
|
380
|
+
const txRegisterResponse = await this.contract.register(idCommitmentBigInt, this.rateLimit, [], {
|
381
|
+
gasLimit
|
382
|
+
});
|
357
383
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
358
384
|
if (txRegisterReceipt.status === 0) {
|
359
385
|
throw new Error("Transaction failed on-chain");
|
@@ -415,7 +441,7 @@ class RLNBaseContract {
|
|
415
441
|
async registerWithPermitAndErase(identity, permit, idCommitmentsToErase) {
|
416
442
|
try {
|
417
443
|
log.info(`Registering identity with permit and rate limit: ${this.rateLimit} messages/epoch`);
|
418
|
-
const txRegisterResponse = await this.contract.registerWithPermit(permit.owner, permit.deadline, permit.v, permit.r, permit.s, identity.
|
444
|
+
const txRegisterResponse = await this.contract.registerWithPermit(permit.owner, permit.deadline, permit.v, permit.r, permit.s, this.getIdCommitmentBigInt(identity.IDCommitment), this.rateLimit, idCommitmentsToErase.map((id) => BigNumber.from(id)));
|
419
445
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
420
446
|
const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
|
421
447
|
if (!memberRegistered || !memberRegistered.args) {
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { hmac } from '../../../node_modules/@noble/hashes/esm/hmac.js';
|
2
|
-
import { sha256 } from '../../../node_modules/@noble/hashes/esm/
|
3
|
-
import '../../interfaces/dist/light_push_v3.js';
|
2
|
+
import { sha256 } from '../../../node_modules/@noble/hashes/esm/sha2.js';
|
4
3
|
import '../../interfaces/dist/protocols.js';
|
5
4
|
import '../../interfaces/dist/connection_manager.js';
|
6
5
|
import '../../interfaces/dist/health_indicator.js';
|
@@ -21,7 +20,7 @@ import { RLNBaseContract } from './contract/rln_base_contract.js';
|
|
21
20
|
import { IdentityCredential } from './identity.js';
|
22
21
|
import { Keystore } from './keystore/keystore.js';
|
23
22
|
import { extractMetaMaskSigner } from './utils/metamask.js';
|
24
|
-
import {
|
23
|
+
import { switchEndianness } from './utils/bytes.js';
|
25
24
|
import './utils/epoch.js';
|
26
25
|
|
27
26
|
const log = new Logger("waku:credentials");
|
@@ -96,7 +95,7 @@ class RLNCredentialsManager {
|
|
96
95
|
}
|
97
96
|
else {
|
98
97
|
log.info("Using local implementation to generate identity");
|
99
|
-
identity = this.generateSeededIdentityCredential(options.signature);
|
98
|
+
identity = await this.generateSeededIdentityCredential(options.signature);
|
100
99
|
}
|
101
100
|
}
|
102
101
|
if (!identity) {
|
@@ -192,24 +191,26 @@ class RLNCredentialsManager {
|
|
192
191
|
* @param seed A string seed to generate the identity from
|
193
192
|
* @returns IdentityCredential
|
194
193
|
*/
|
195
|
-
generateSeededIdentityCredential(seed) {
|
194
|
+
async generateSeededIdentityCredential(seed) {
|
196
195
|
log.info("Generating seeded identity credential");
|
197
196
|
// Convert the seed to bytes
|
198
197
|
const encoder = new TextEncoder();
|
199
198
|
const seedBytes = encoder.encode(seed);
|
200
199
|
// Generate deterministic values using HMAC-SHA256
|
201
200
|
// We use different context strings for each component to ensure they're different
|
202
|
-
const
|
203
|
-
const
|
204
|
-
|
205
|
-
const
|
206
|
-
const
|
207
|
-
//
|
208
|
-
|
209
|
-
|
210
|
-
const
|
201
|
+
const idTrapdoorBE = hmac(sha256, seedBytes, encoder.encode("IDTrapdoor"));
|
202
|
+
const idNullifierBE = hmac(sha256, seedBytes, encoder.encode("IDNullifier"));
|
203
|
+
const combinedBytes = new Uint8Array([...idTrapdoorBE, ...idNullifierBE]);
|
204
|
+
const idSecretHashBE = sha256(combinedBytes);
|
205
|
+
const idCommitmentBE = sha256(idSecretHashBE);
|
206
|
+
// All hashing functions return big-endian bytes
|
207
|
+
// We need to switch to little-endian for the identity credential
|
208
|
+
const idTrapdoorLE = switchEndianness(idTrapdoorBE);
|
209
|
+
const idNullifierLE = switchEndianness(idNullifierBE);
|
210
|
+
const idSecretHashLE = switchEndianness(idSecretHashBE);
|
211
|
+
const idCommitmentLE = switchEndianness(idCommitmentBE);
|
211
212
|
log.info("Successfully generated identity credential");
|
212
|
-
return new IdentityCredential(
|
213
|
+
return new IdentityCredential(idTrapdoorLE, idNullifierLE, idSecretHashLE, idCommitmentLE);
|
213
214
|
}
|
214
215
|
}
|
215
216
|
|
@@ -1,18 +1,16 @@
|
|
1
|
-
import { buildBigIntFromUint8Array } from './utils/bytes.js';
|
2
|
-
import './utils/epoch.js';
|
3
|
-
|
4
1
|
class IdentityCredential {
|
5
2
|
IDTrapdoor;
|
6
3
|
IDNullifier;
|
7
4
|
IDSecretHash;
|
8
5
|
IDCommitment;
|
9
|
-
|
10
|
-
|
6
|
+
/**
|
7
|
+
* All variables are in little-endian format
|
8
|
+
*/
|
9
|
+
constructor(IDTrapdoor, IDNullifier, IDSecretHash, IDCommitment) {
|
11
10
|
this.IDTrapdoor = IDTrapdoor;
|
12
11
|
this.IDNullifier = IDNullifier;
|
13
12
|
this.IDSecretHash = IDSecretHash;
|
14
13
|
this.IDCommitment = IDCommitment;
|
15
|
-
this.IDCommitmentBigInt = IDCommitmentBigInt;
|
16
14
|
}
|
17
15
|
static fromBytes(memKeys) {
|
18
16
|
if (memKeys.length < 128) {
|
@@ -22,8 +20,7 @@ class IdentityCredential {
|
|
22
20
|
const idNullifier = memKeys.subarray(32, 64);
|
23
21
|
const idSecretHash = memKeys.subarray(64, 96);
|
24
22
|
const idCommitment = memKeys.subarray(96, 128);
|
25
|
-
|
26
|
-
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
23
|
+
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment);
|
27
24
|
}
|
28
25
|
}
|
29
26
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import '../../../../node_modules/@chainsafe/bls-keystore/lib/index.js';
|
2
|
-
import '../../../interfaces/dist/light_push_v3.js';
|
3
2
|
import '../../../interfaces/dist/protocols.js';
|
4
3
|
import '../../../interfaces/dist/connection_manager.js';
|
5
4
|
import '../../../interfaces/dist/health_indicator.js';
|
@@ -18,7 +17,6 @@ import { Logger } from '../../../utils/dist/logger/index.js';
|
|
18
17
|
import { sha256 } from '../../../../node_modules/ethereum-cryptography/esm/sha256.js';
|
19
18
|
import { bytesToUtf8 } from '../../../../node_modules/ethereum-cryptography/esm/utils.js';
|
20
19
|
import _ from '../../../../node_modules/lodash/lodash.js';
|
21
|
-
import { buildBigIntFromUint8Array } from '../utils/bytes.js';
|
22
20
|
import { keccak256Checksum, decryptEipKeystore } from './cipher.js';
|
23
21
|
import { isKeystoreValid, isCredentialValid } from './schema_validator.js';
|
24
22
|
import { __exports as lib } from '../../../../_virtual/index.js';
|
@@ -165,14 +163,16 @@ class Keystore {
|
|
165
163
|
try {
|
166
164
|
const str = bytesToUtf8(bytes);
|
167
165
|
const obj = JSON.parse(str);
|
168
|
-
|
166
|
+
const idCommitmentLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", []));
|
167
|
+
const idTrapdoorLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", []));
|
168
|
+
const idNullifierLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", []));
|
169
|
+
const idSecretHashLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []));
|
169
170
|
return {
|
170
171
|
identity: {
|
171
|
-
IDCommitment:
|
172
|
-
IDTrapdoor:
|
173
|
-
IDNullifier:
|
174
|
-
|
175
|
-
IDSecretHash: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []))
|
172
|
+
IDCommitment: idCommitmentLE,
|
173
|
+
IDTrapdoor: idTrapdoorLE,
|
174
|
+
IDNullifier: idNullifierLE,
|
175
|
+
IDSecretHash: idSecretHashLE
|
176
176
|
},
|
177
177
|
membership: {
|
178
178
|
treeIndex: _.get(obj, "treeIndex"),
|
@@ -209,13 +209,16 @@ class Keystore {
|
|
209
209
|
// follows nwaku implementation
|
210
210
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L98
|
211
211
|
static fromIdentityToBytes(options) {
|
212
|
+
function toLittleEndian(bytes) {
|
213
|
+
return new Uint8Array(bytes).reverse();
|
214
|
+
}
|
212
215
|
return utf8ToBytes(JSON.stringify({
|
213
216
|
treeIndex: options.membership.treeIndex,
|
214
217
|
identityCredential: {
|
215
|
-
idCommitment: Array.from(options.identity.IDCommitment),
|
216
|
-
idNullifier: Array.from(options.identity.IDNullifier),
|
217
|
-
idSecretHash: Array.from(options.identity.IDSecretHash),
|
218
|
-
idTrapdoor: Array.from(options.identity.IDTrapdoor)
|
218
|
+
idCommitment: Array.from(toLittleEndian(options.identity.IDCommitment)),
|
219
|
+
idNullifier: Array.from(toLittleEndian(options.identity.IDNullifier)),
|
220
|
+
idSecretHash: Array.from(toLittleEndian(options.identity.IDSecretHash)),
|
221
|
+
idTrapdoor: Array.from(toLittleEndian(options.identity.IDTrapdoor))
|
219
222
|
},
|
220
223
|
membershipContract: {
|
221
224
|
chainId: options.membership.chainId,
|
@@ -1,10 +1,8 @@
|
|
1
1
|
import { Version } from '../../core/dist/lib/message/version_0.js';
|
2
2
|
import '../../core/dist/lib/filter/filter.js';
|
3
3
|
import '../../core/dist/lib/light_push/light_push.js';
|
4
|
-
import '../../core/dist/lib/light_push/light_push_v3.js';
|
5
4
|
import '../../core/dist/lib/store/store.js';
|
6
5
|
import '../../core/dist/lib/connection_manager/connection_manager.js';
|
7
|
-
import '../../interfaces/dist/light_push_v3.js';
|
8
6
|
import '../../interfaces/dist/protocols.js';
|
9
7
|
import '../../interfaces/dist/connection_manager.js';
|
10
8
|
import '../../interfaces/dist/health_indicator.js';
|
@@ -1,10 +1,8 @@
|
|
1
1
|
import { createEncoder, createDecoder } from '../../core/dist/lib/message/version_0.js';
|
2
2
|
import '../../core/dist/lib/filter/filter.js';
|
3
3
|
import '../../core/dist/lib/light_push/light_push.js';
|
4
|
-
import '../../core/dist/lib/light_push/light_push_v3.js';
|
5
4
|
import '../../core/dist/lib/store/store.js';
|
6
5
|
import '../../core/dist/lib/connection_manager/connection_manager.js';
|
7
|
-
import '../../interfaces/dist/light_push_v3.js';
|
8
6
|
import '../../interfaces/dist/protocols.js';
|
9
7
|
import '../../interfaces/dist/connection_manager.js';
|
10
8
|
import '../../interfaces/dist/health_indicator.js';
|
@@ -16,12 +16,12 @@ function concatenate(...input) {
|
|
16
16
|
}
|
17
17
|
return result;
|
18
18
|
}
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
function switchEndianness(bytes) {
|
20
|
+
return new Uint8Array(bytes.reverse());
|
21
|
+
}
|
22
|
+
function buildBigIntFromUint8ArrayBE(bytes) {
|
23
|
+
// Interpret bytes as big-endian
|
24
|
+
return bytes.reduce((acc, byte) => (acc << 8n) + BigInt(byte), 0n);
|
25
25
|
}
|
26
26
|
function writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
27
27
|
value = +value;
|
@@ -39,15 +39,6 @@ function writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
|
39
39
|
}
|
40
40
|
return buf;
|
41
41
|
}
|
42
|
-
/**
|
43
|
-
* Transforms Uint8Array into BigInt
|
44
|
-
* @param array: Uint8Array
|
45
|
-
* @returns BigInt
|
46
|
-
*/
|
47
|
-
function buildBigIntFromUint8Array(array, byteOffset = 0) {
|
48
|
-
const dataView = new DataView(array.buffer);
|
49
|
-
return dataView.getBigUint64(byteOffset, true);
|
50
|
-
}
|
51
42
|
/**
|
52
43
|
* Fills with zeros to set length
|
53
44
|
* @param array little endian Uint8Array
|
@@ -61,5 +52,12 @@ function zeroPadLE(array, length) {
|
|
61
52
|
}
|
62
53
|
return result;
|
63
54
|
}
|
55
|
+
// Adapted from https://github.com/feross/buffer
|
56
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
57
|
+
if (value > max || value < min)
|
58
|
+
throw new RangeError('"value" argument is out of bounds');
|
59
|
+
if (offset + ext > buf.length)
|
60
|
+
throw new RangeError("Index out of range");
|
61
|
+
}
|
64
62
|
|
65
|
-
export {
|
63
|
+
export { buildBigIntFromUint8ArrayBE, concatenate, switchEndianness, writeUIntLE, zeroPadLE };
|