@waku/rln 0.1.7-7a9850d.0 → 0.1.7-987c6cd.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.
Files changed (95) hide show
  1. package/bundle/index.js +2 -2
  2. package/bundle/packages/core/dist/lib/connection_manager/connection_limiter.js +17 -0
  3. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +9 -5
  4. package/bundle/packages/core/dist/lib/connection_manager/dialer.js +17 -0
  5. package/bundle/packages/core/dist/lib/connection_manager/discovery_dialer.js +17 -0
  6. package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +1 -1
  7. package/bundle/packages/core/dist/lib/connection_manager/shard_reader.js +17 -0
  8. package/bundle/packages/core/dist/lib/filter/filter.js +2 -2
  9. package/bundle/packages/core/dist/lib/light_push/light_push.js +1 -1
  10. package/bundle/packages/core/dist/lib/message/version_0.js +1 -1
  11. package/bundle/packages/core/dist/lib/metadata/metadata.js +1 -1
  12. package/bundle/packages/core/dist/lib/store/store.js +1 -1
  13. package/bundle/packages/interfaces/dist/connection_manager.js +1 -12
  14. package/bundle/packages/rln/dist/codec.js +1 -1
  15. package/bundle/packages/rln/dist/contract/abi/price_calculator.js +95 -0
  16. package/bundle/packages/rln/dist/contract/constants.js +15 -3
  17. package/bundle/packages/rln/dist/contract/rln_base_contract.js +17 -5
  18. package/bundle/packages/rln/dist/contract/rln_contract.js +3 -3
  19. package/bundle/packages/rln/dist/credentials_manager.js +24 -20
  20. package/bundle/packages/rln/dist/identity.js +8 -6
  21. package/bundle/packages/rln/dist/keystore/keystore.js +39 -12
  22. package/bundle/packages/rln/dist/proof.js +2 -2
  23. package/bundle/packages/rln/dist/rln.js +1 -1
  24. package/bundle/packages/rln/dist/utils/bytes.js +103 -58
  25. package/bundle/packages/rln/dist/utils/epoch.js +1 -1
  26. package/bundle/packages/rln/dist/utils/hash.js +3 -3
  27. package/bundle/packages/rln/dist/zerokit.js +17 -17
  28. package/bundle/packages/utils/dist/{logger/index.js → logger.js} +3 -3
  29. package/dist/.tsbuildinfo +1 -1
  30. package/dist/contract/abi/price_calculator.d.ts +46 -0
  31. package/dist/contract/abi/price_calculator.js +94 -0
  32. package/dist/contract/abi/price_calculator.js.map +1 -0
  33. package/dist/contract/{abi.js → abi/rln.js} +1 -1
  34. package/dist/contract/abi/rln.js.map +1 -0
  35. package/dist/contract/constants.d.ts +57 -1
  36. package/dist/contract/constants.js +14 -2
  37. package/dist/contract/constants.js.map +1 -1
  38. package/dist/contract/price_calculator.test.d.ts +1 -0
  39. package/dist/contract/price_calculator.test.js +28 -0
  40. package/dist/contract/price_calculator.test.js.map +1 -0
  41. package/dist/contract/rln_base_contract.d.ts +7 -0
  42. package/dist/contract/rln_base_contract.js +16 -4
  43. package/dist/contract/rln_base_contract.js.map +1 -1
  44. package/dist/contract/rln_contract.js +2 -2
  45. package/dist/contract/rln_contract.js.map +1 -1
  46. package/dist/contract/{test-setup.d.ts → test_setup.d.ts} +4 -4
  47. package/dist/contract/{test-setup.js → test_setup.js} +4 -4
  48. package/dist/contract/{test-setup.js.map → test_setup.js.map} +1 -1
  49. package/dist/contract/{test-utils.js → test_utils.js} +10 -10
  50. package/dist/contract/{test-utils.js.map → test_utils.js.map} +1 -1
  51. package/dist/credentials_manager.d.ts +4 -0
  52. package/dist/credentials_manager.js +24 -19
  53. package/dist/credentials_manager.js.map +1 -1
  54. package/dist/identity.d.ts +5 -2
  55. package/dist/identity.js +8 -5
  56. package/dist/identity.js.map +1 -1
  57. package/dist/index.d.ts +3 -3
  58. package/dist/index.js +3 -3
  59. package/dist/index.js.map +1 -1
  60. package/dist/keystore/keystore.js +38 -11
  61. package/dist/keystore/keystore.js.map +1 -1
  62. package/dist/proof.js +2 -2
  63. package/dist/proof.js.map +1 -1
  64. package/dist/utils/bytes.d.ts +42 -20
  65. package/dist/utils/bytes.js +102 -57
  66. package/dist/utils/bytes.js.map +1 -1
  67. package/dist/utils/hash.js +5 -5
  68. package/dist/utils/hash.js.map +1 -1
  69. package/dist/utils/index.d.ts +1 -1
  70. package/dist/utils/index.js +1 -1
  71. package/dist/utils/index.js.map +1 -1
  72. package/dist/zerokit.js +17 -17
  73. package/dist/zerokit.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/contract/abi/price_calculator.ts +93 -0
  76. package/src/contract/constants.ts +18 -2
  77. package/src/contract/price_calculator.test.ts +36 -0
  78. package/src/contract/rln_base_contract.ts +27 -5
  79. package/src/contract/rln_contract.ts +5 -2
  80. package/src/contract/{test-setup.ts → test_setup.ts} +4 -4
  81. package/src/contract/{test-utils.ts → test_utils.ts} +9 -9
  82. package/src/credentials_manager.ts +41 -27
  83. package/src/identity.ts +11 -7
  84. package/src/index.ts +3 -3
  85. package/src/keystore/keystore.ts +52 -23
  86. package/src/proof.ts +2 -2
  87. package/src/utils/bytes.ts +118 -72
  88. package/src/utils/hash.ts +15 -5
  89. package/src/utils/index.ts +1 -6
  90. package/src/zerokit.ts +30 -22
  91. package/dist/contract/abi.js.map +0 -1
  92. /package/bundle/packages/rln/dist/contract/{abi.js → abi/rln.js} +0 -0
  93. /package/dist/contract/{abi.d.ts → abi/rln.d.ts} +0 -0
  94. /package/dist/contract/{test-utils.d.ts → test_utils.d.ts} +0 -0
  95. /package/src/contract/{abi.ts → abi/rln.ts} +0 -0
package/bundle/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { RLNDecoder, RLNEncoder } from './packages/rln/dist/codec.js';
2
- export { RLN_ABI } from './packages/rln/dist/contract/abi.js';
2
+ export { RLN_ABI } from './packages/rln/dist/contract/abi/rln.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_RATE_LIMIT, PRICE_CALCULATOR_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS, RLN_CONTRACT, RLN_Q } 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';
@@ -0,0 +1,17 @@
1
+ import '../../../../interfaces/dist/protocols.js';
2
+ import '../../../../interfaces/dist/connection_manager.js';
3
+ import '../../../../interfaces/dist/health_indicator.js';
4
+ import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
5
+ import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
6
+ import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
7
+ import '../../../../../node_modules/multiformats/dist/src/bases/base256emoji.js';
8
+ import '../../../../../node_modules/multiformats/dist/src/bases/base32.js';
9
+ import '../../../../../node_modules/multiformats/dist/src/bases/base36.js';
10
+ import '../../../../../node_modules/multiformats/dist/src/bases/base58.js';
11
+ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
12
+ import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
13
+ import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
14
+ import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
15
+ import { Logger } from '../../../../utils/dist/logger.js';
16
+
17
+ new Logger("connection-limiter");
@@ -1,3 +1,6 @@
1
+ import '../../../../interfaces/dist/protocols.js';
2
+ import '../../../../interfaces/dist/connection_manager.js';
3
+ import '../../../../interfaces/dist/health_indicator.js';
1
4
  import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
2
5
  import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
3
6
  import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
@@ -9,11 +12,12 @@ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
9
12
  import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
10
13
  import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
11
14
  import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
12
- import '../../../../../node_modules/@multiformats/multiaddr/dist/src/registry.js';
13
- import '../../../../interfaces/dist/protocols.js';
14
- import '../../../../interfaces/dist/connection_manager.js';
15
- import '../../../../interfaces/dist/health_indicator.js';
16
- import { Logger } from '../../../../utils/dist/logger/index.js';
15
+ import { Logger } from '../../../../utils/dist/logger.js';
16
+ import './connection_limiter.js';
17
+ import './dialer.js';
18
+ import './discovery_dialer.js';
17
19
  import './keep_alive_manager.js';
20
+ import './shard_reader.js';
21
+ import '../../../../../node_modules/@multiformats/multiaddr/dist/src/registry.js';
18
22
 
19
23
  new Logger("connection-manager");
@@ -0,0 +1,17 @@
1
+ import '../../../../interfaces/dist/protocols.js';
2
+ import '../../../../interfaces/dist/connection_manager.js';
3
+ import '../../../../interfaces/dist/health_indicator.js';
4
+ import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
5
+ import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
6
+ import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
7
+ import '../../../../../node_modules/multiformats/dist/src/bases/base256emoji.js';
8
+ import '../../../../../node_modules/multiformats/dist/src/bases/base32.js';
9
+ import '../../../../../node_modules/multiformats/dist/src/bases/base36.js';
10
+ import '../../../../../node_modules/multiformats/dist/src/bases/base58.js';
11
+ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
12
+ import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
13
+ import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
14
+ import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
15
+ import { Logger } from '../../../../utils/dist/logger.js';
16
+
17
+ new Logger("dialer");
@@ -0,0 +1,17 @@
1
+ import '../../../../interfaces/dist/protocols.js';
2
+ import '../../../../interfaces/dist/connection_manager.js';
3
+ import '../../../../interfaces/dist/health_indicator.js';
4
+ import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
5
+ import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
6
+ import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
7
+ import '../../../../../node_modules/multiformats/dist/src/bases/base256emoji.js';
8
+ import '../../../../../node_modules/multiformats/dist/src/bases/base32.js';
9
+ import '../../../../../node_modules/multiformats/dist/src/bases/base36.js';
10
+ import '../../../../../node_modules/multiformats/dist/src/bases/base58.js';
11
+ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
12
+ import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
13
+ import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
14
+ import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
15
+ import { Logger } from '../../../../utils/dist/logger.js';
16
+
17
+ new Logger("discovery-dialer");
@@ -12,7 +12,7 @@ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
12
12
  import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
13
13
  import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
14
14
  import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
15
- import { Logger } from '../../../../utils/dist/logger/index.js';
15
+ import { Logger } from '../../../../utils/dist/logger.js';
16
16
  import '../message/version_0.js';
17
17
 
18
18
  new Logger("keep-alive");
@@ -0,0 +1,17 @@
1
+ import '../../../../interfaces/dist/protocols.js';
2
+ import '../../../../interfaces/dist/connection_manager.js';
3
+ import '../../../../interfaces/dist/health_indicator.js';
4
+ import '../../../../../node_modules/multiformats/dist/src/bases/base10.js';
5
+ import '../../../../../node_modules/multiformats/dist/src/bases/base16.js';
6
+ import '../../../../../node_modules/multiformats/dist/src/bases/base2.js';
7
+ import '../../../../../node_modules/multiformats/dist/src/bases/base256emoji.js';
8
+ import '../../../../../node_modules/multiformats/dist/src/bases/base32.js';
9
+ import '../../../../../node_modules/multiformats/dist/src/bases/base36.js';
10
+ import '../../../../../node_modules/multiformats/dist/src/bases/base58.js';
11
+ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
12
+ import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
13
+ import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
14
+ import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
15
+ import { Logger } from '../../../../utils/dist/logger.js';
16
+
17
+ new Logger("shard-reader");
@@ -12,7 +12,7 @@ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
12
12
  import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
13
13
  import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
14
14
  import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
15
- import { Logger } from '../../../../utils/dist/logger/index.js';
15
+ import { Logger } from '../../../../utils/dist/logger.js';
16
16
  import '../../../../../node_modules/it-length-prefixed/dist/src/decode.js';
17
17
  import '../../../../proto/dist/generated/message.js';
18
18
  import '../../../../proto/dist/generated/filter.js';
@@ -24,4 +24,4 @@ import '../../../../proto/dist/generated/peer_exchange.js';
24
24
  import '../../../../proto/dist/generated/metadata.js';
25
25
  import '../../../../proto/dist/generated/sds_message.js';
26
26
 
27
- new Logger("filter:v2");
27
+ new Logger("filter-core");
@@ -21,7 +21,7 @@ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
21
21
  import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
22
22
  import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
23
23
  import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
24
- import { Logger } from '../../../../utils/dist/logger/index.js';
24
+ import { Logger } from '../../../../utils/dist/logger.js';
25
25
  import '../../../../../node_modules/it-length-prefixed/dist/src/decode.js';
26
26
 
27
27
  new Logger("light-push");
@@ -8,7 +8,7 @@ import '../../../../proto/dist/generated/peer_exchange.js';
8
8
  import '../../../../proto/dist/generated/metadata.js';
9
9
  import '../../../../proto/dist/generated/sds_message.js';
10
10
  import { determinePubsubTopic } from '../../../../utils/dist/common/sharding/index.js';
11
- import { Logger } from '../../../../utils/dist/logger/index.js';
11
+ import { Logger } from '../../../../utils/dist/logger.js';
12
12
 
13
13
  const log = new Logger("message:version-0");
14
14
  const OneMillion = BigInt(1_000_000);
@@ -21,7 +21,7 @@ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
21
21
  import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
22
22
  import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
23
23
  import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
24
- import { Logger } from '../../../../utils/dist/logger/index.js';
24
+ import { Logger } from '../../../../utils/dist/logger.js';
25
25
  import '../../../../../node_modules/it-length-prefixed/dist/src/decode.js';
26
26
 
27
27
  new Logger("metadata");
@@ -12,7 +12,7 @@ import '../../../../../node_modules/multiformats/dist/src/bases/base64.js';
12
12
  import '../../../../../node_modules/multiformats/dist/src/bases/base8.js';
13
13
  import '../../../../../node_modules/multiformats/dist/src/bases/identity.js';
14
14
  import '../../../../../node_modules/multiformats/dist/src/codecs/json.js';
15
- import { Logger } from '../../../../utils/dist/logger/index.js';
15
+ import { Logger } from '../../../../utils/dist/logger.js';
16
16
  import '../../../../../node_modules/it-length-prefixed/dist/src/decode.js';
17
17
  import '../../../../proto/dist/generated/message.js';
18
18
  import '../../../../proto/dist/generated/filter.js';
@@ -4,16 +4,5 @@ var Tags;
4
4
  Tags["PEER_EXCHANGE"] = "peer-exchange";
5
5
  Tags["LOCAL"] = "local-peer-cache";
6
6
  })(Tags || (Tags = {}));
7
- var EPeersByDiscoveryEvents;
8
- (function (EPeersByDiscoveryEvents) {
9
- EPeersByDiscoveryEvents["PEER_DISCOVERY_BOOTSTRAP"] = "peer:discovery:bootstrap";
10
- EPeersByDiscoveryEvents["PEER_DISCOVERY_PEER_EXCHANGE"] = "peer:discovery:peer-exchange";
11
- EPeersByDiscoveryEvents["PEER_CONNECT_BOOTSTRAP"] = "peer:connected:bootstrap";
12
- EPeersByDiscoveryEvents["PEER_CONNECT_PEER_EXCHANGE"] = "peer:connected:peer-exchange";
13
- })(EPeersByDiscoveryEvents || (EPeersByDiscoveryEvents = {}));
14
- var EConnectionStateEvents;
15
- (function (EConnectionStateEvents) {
16
- EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
17
- })(EConnectionStateEvents || (EConnectionStateEvents = {}));
18
7
 
19
- export { EConnectionStateEvents, EPeersByDiscoveryEvents, Tags };
8
+ export { Tags };
@@ -12,7 +12,7 @@ import '../../../node_modules/multiformats/dist/src/bases/base64.js';
12
12
  import '../../../node_modules/multiformats/dist/src/bases/base8.js';
13
13
  import '../../../node_modules/multiformats/dist/src/bases/identity.js';
14
14
  import '../../../node_modules/multiformats/dist/src/codecs/json.js';
15
- import { Logger } from '../../utils/dist/logger/index.js';
15
+ import { Logger } from '../../utils/dist/logger.js';
16
16
  import { toRLNSignal, RlnMessage } from './message.js';
17
17
 
18
18
  const log = new Logger("waku:rln:encoder");
@@ -0,0 +1,95 @@
1
+ const PRICE_CALCULATOR_ABI = [
2
+ {
3
+ inputs: [
4
+ { internalType: "address", name: "_token", type: "address" },
5
+ {
6
+ internalType: "uint256",
7
+ name: "_pricePerMessagePerEpoch",
8
+ type: "uint256"
9
+ }
10
+ ],
11
+ stateMutability: "nonpayable",
12
+ type: "constructor"
13
+ },
14
+ { inputs: [], name: "OnlyTokensAllowed", type: "error" },
15
+ {
16
+ anonymous: false,
17
+ inputs: [
18
+ {
19
+ indexed: true,
20
+ internalType: "address",
21
+ name: "previousOwner",
22
+ type: "address"
23
+ },
24
+ {
25
+ indexed: true,
26
+ internalType: "address",
27
+ name: "newOwner",
28
+ type: "address"
29
+ }
30
+ ],
31
+ name: "OwnershipTransferred",
32
+ type: "event"
33
+ },
34
+ {
35
+ inputs: [{ internalType: "uint32", name: "_rateLimit", type: "uint32" }],
36
+ name: "calculate",
37
+ outputs: [
38
+ { internalType: "address", name: "", type: "address" },
39
+ { internalType: "uint256", name: "", type: "uint256" }
40
+ ],
41
+ stateMutability: "view",
42
+ type: "function"
43
+ },
44
+ {
45
+ inputs: [],
46
+ name: "owner",
47
+ outputs: [{ internalType: "address", name: "", type: "address" }],
48
+ stateMutability: "view",
49
+ type: "function"
50
+ },
51
+ {
52
+ inputs: [],
53
+ name: "pricePerMessagePerEpoch",
54
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
55
+ stateMutability: "view",
56
+ type: "function"
57
+ },
58
+ {
59
+ inputs: [],
60
+ name: "renounceOwnership",
61
+ outputs: [],
62
+ stateMutability: "nonpayable",
63
+ type: "function"
64
+ },
65
+ {
66
+ inputs: [
67
+ { internalType: "address", name: "_token", type: "address" },
68
+ {
69
+ internalType: "uint256",
70
+ name: "_pricePerMessagePerEpoch",
71
+ type: "uint256"
72
+ }
73
+ ],
74
+ name: "setTokenAndPrice",
75
+ outputs: [],
76
+ stateMutability: "nonpayable",
77
+ type: "function"
78
+ },
79
+ {
80
+ inputs: [],
81
+ name: "token",
82
+ outputs: [{ internalType: "address", name: "", type: "address" }],
83
+ stateMutability: "view",
84
+ type: "function"
85
+ },
86
+ {
87
+ inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
88
+ name: "transferOwnership",
89
+ outputs: [],
90
+ stateMutability: "nonpayable",
91
+ type: "function"
92
+ }
93
+ ];
94
+
95
+ export { PRICE_CALCULATOR_ABI };
@@ -1,10 +1,16 @@
1
- import { RLN_ABI } from './abi.js';
1
+ import { PRICE_CALCULATOR_ABI } from './abi/price_calculator.js';
2
+ import { RLN_ABI } from './abi/rln.js';
2
3
 
3
- const LINEA_CONTRACT = {
4
+ const RLN_CONTRACT = {
4
5
  chainId: 59141,
5
6
  address: "0xb9cd878c90e49f797b4431fbf4fb333108cb90e6",
6
7
  abi: RLN_ABI
7
8
  };
9
+ const PRICE_CALCULATOR_CONTRACT = {
10
+ chainId: 59141,
11
+ address: "0xBcfC0660Df69f53ab409F32bb18A3fb625fcE644",
12
+ abi: PRICE_CALCULATOR_ABI
13
+ };
8
14
  /**
9
15
  * Rate limit tiers (messages per epoch)
10
16
  * Each membership can specify a rate limit within these bounds.
@@ -22,6 +28,12 @@ const RATE_LIMIT_PARAMS = {
22
28
  MAX_TOTAL_RATE: 160_000, // Maximum total rate limit across all memberships
23
29
  EPOCH_LENGTH: 600 // Epoch length in seconds (10 minutes)
24
30
  };
31
+ /**
32
+ * Default Q value for the RLN contract
33
+ * This is the upper bound for the ID commitment
34
+ * @see https://github.com/waku-org/specs/blob/master/standards/core/rln-contract.md#implementation-suggestions
35
+ */
36
+ const RLN_Q = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
25
37
  const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
26
38
 
27
- export { DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS };
39
+ export { DEFAULT_RATE_LIMIT, PRICE_CALCULATOR_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS, RLN_CONTRACT, RLN_Q };
@@ -12,9 +12,10 @@ import '../../../../node_modules/multiformats/dist/src/bases/base64.js';
12
12
  import '../../../../node_modules/multiformats/dist/src/bases/base8.js';
13
13
  import '../../../../node_modules/multiformats/dist/src/bases/identity.js';
14
14
  import '../../../../node_modules/multiformats/dist/src/codecs/json.js';
15
- import { Logger } from '../../../utils/dist/logger/index.js';
16
- import { RLN_ABI } from './abi.js';
17
- import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './constants.js';
15
+ import { Logger } from '../../../utils/dist/logger.js';
16
+ import { BytesUtils } from '../utils/bytes.js';
17
+ import { RLN_ABI } from './abi/rln.js';
18
+ import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS, PRICE_CALCULATOR_CONTRACT } from './constants.js';
18
19
  import { MembershipState } from './types.js';
19
20
  import { Contract } from '../../../../node_modules/@ethersproject/contracts/lib.esm/index.js';
20
21
  import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
@@ -352,7 +353,9 @@ class RLNBaseContract {
352
353
  }
353
354
  const estimatedGas = await this.contract.estimateGas.register(identity.IDCommitmentBigInt, this.rateLimit, []);
354
355
  const gasLimit = estimatedGas.add(10000);
355
- const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit });
356
+ const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], {
357
+ gasLimit
358
+ });
356
359
  const txRegisterReceipt = await txRegisterResponse.wait();
357
360
  if (txRegisterReceipt.status === 0) {
358
361
  throw new Error("Transaction failed on-chain");
@@ -414,7 +417,7 @@ class RLNBaseContract {
414
417
  async registerWithPermitAndErase(identity, permit, idCommitmentsToErase) {
415
418
  try {
416
419
  log.info(`Registering identity with permit and rate limit: ${this.rateLimit} messages/epoch`);
417
- const txRegisterResponse = await this.contract.registerWithPermit(permit.owner, permit.deadline, permit.v, permit.r, permit.s, identity.IDCommitmentBigInt, this.rateLimit, idCommitmentsToErase.map((id) => BigNumber.from(id)));
420
+ const txRegisterResponse = await this.contract.registerWithPermit(permit.owner, permit.deadline, permit.v, permit.r, permit.s, BytesUtils.buildBigIntFromUint8ArrayBE(identity.IDCommitment), this.rateLimit, idCommitmentsToErase.map((id) => BigNumber.from(id)));
418
421
  const txRegisterReceipt = await txRegisterResponse.wait();
419
422
  const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
420
423
  if (!memberRegistered || !memberRegistered.args) {
@@ -528,6 +531,15 @@ class RLNBaseContract {
528
531
  return false;
529
532
  }
530
533
  }
534
+ /**
535
+ * Calculates the price for a given rate limit using the PriceCalculator contract
536
+ */
537
+ async getPriceForRateLimit(rateLimit) {
538
+ const provider = this.contract.provider;
539
+ const priceCalculator = new Contract(PRICE_CALCULATOR_CONTRACT.address, PRICE_CALCULATOR_CONTRACT.abi, provider);
540
+ const [token, price] = await priceCalculator.calculate(rateLimit);
541
+ return { token, price };
542
+ }
531
543
  }
532
544
 
533
545
  export { RLNBaseContract };
@@ -2,9 +2,9 @@ import '../../../interfaces/dist/protocols.js';
2
2
  import '../../../interfaces/dist/connection_manager.js';
3
3
  import '../../../interfaces/dist/health_indicator.js';
4
4
  import { hexToBytes } from '../../../utils/dist/bytes/index.js';
5
- import { Logger } from '../../../utils/dist/logger/index.js';
5
+ import { Logger } from '../../../utils/dist/logger.js';
6
6
  import { MerkleRootTracker } from '../root_tracker.js';
7
- import { zeroPadLE } from '../utils/bytes.js';
7
+ import { BytesUtils } from '../utils/bytes.js';
8
8
  import { RLNBaseContract } from './rln_base_contract.js';
9
9
  import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
10
10
 
@@ -83,7 +83,7 @@ class RLNContract extends RLNBaseContract {
83
83
  if (typeof index === "number" || typeof index === "string") {
84
84
  index = BigNumber.from(index);
85
85
  }
86
- const idCommitment = zeroPadLE(hexToBytes(_idCommitment), 32);
86
+ const idCommitment = BytesUtils.zeroPadLE(hexToBytes(_idCommitment), 32);
87
87
  rlnInstance.zerokit.insertMember(idCommitment);
88
88
  const numericIndex = index.toNumber();
89
89
  this._members.set(numericIndex, {
@@ -1,5 +1,5 @@
1
1
  import { hmac } from '../../../node_modules/@noble/hashes/esm/hmac.js';
2
- import { sha256 } from '../../../node_modules/@noble/hashes/esm/sha256.js';
2
+ import { sha256 } from '../../../node_modules/@noble/hashes/esm/sha2.js';
3
3
  import '../../interfaces/dist/protocols.js';
4
4
  import '../../interfaces/dist/connection_manager.js';
5
5
  import '../../interfaces/dist/health_indicator.js';
@@ -14,13 +14,13 @@ import '../../../node_modules/multiformats/dist/src/bases/base64.js';
14
14
  import '../../../node_modules/multiformats/dist/src/bases/base8.js';
15
15
  import '../../../node_modules/multiformats/dist/src/bases/identity.js';
16
16
  import '../../../node_modules/multiformats/dist/src/codecs/json.js';
17
- import { Logger } from '../../utils/dist/logger/index.js';
18
- import { LINEA_CONTRACT } from './contract/constants.js';
17
+ import { Logger } from '../../utils/dist/logger.js';
18
+ import { RLN_CONTRACT, RLN_Q } from './contract/constants.js';
19
19
  import { RLNBaseContract } from './contract/rln_base_contract.js';
20
20
  import { IdentityCredential } from './identity.js';
21
21
  import { Keystore } from './keystore/keystore.js';
22
+ import { BytesUtils } from './utils/bytes.js';
22
23
  import { extractMetaMaskSigner } from './utils/metamask.js';
23
- import { buildBigIntFromUint8Array } from './utils/bytes.js';
24
24
  import './utils/epoch.js';
25
25
 
26
26
  const log = new Logger("waku:credentials");
@@ -95,7 +95,7 @@ class RLNCredentialsManager {
95
95
  }
96
96
  else {
97
97
  log.info("Using local implementation to generate identity");
98
- identity = this.generateSeededIdentityCredential(options.signature);
98
+ identity = await this.generateSeededIdentityCredential(options.signature);
99
99
  }
100
100
  }
101
101
  if (!identity) {
@@ -124,9 +124,9 @@ class RLNCredentialsManager {
124
124
  let chainId = credentials?.membership.chainId;
125
125
  const address = credentials?.membership.address ||
126
126
  options.address ||
127
- LINEA_CONTRACT.address;
128
- if (address === LINEA_CONTRACT.address) {
129
- chainId = LINEA_CONTRACT.chainId.toString();
127
+ RLN_CONTRACT.address;
128
+ if (address === RLN_CONTRACT.address) {
129
+ chainId = RLN_CONTRACT.chainId.toString();
130
130
  log.info(`Using Linea contract with chainId: ${chainId}`);
131
131
  }
132
132
  const signer = options.signer || (await extractMetaMaskSigner());
@@ -191,24 +191,28 @@ class RLNCredentialsManager {
191
191
  * @param seed A string seed to generate the identity from
192
192
  * @returns IdentityCredential
193
193
  */
194
- generateSeededIdentityCredential(seed) {
194
+ async generateSeededIdentityCredential(seed) {
195
195
  log.info("Generating seeded identity credential");
196
196
  // Convert the seed to bytes
197
197
  const encoder = new TextEncoder();
198
198
  const seedBytes = encoder.encode(seed);
199
199
  // Generate deterministic values using HMAC-SHA256
200
200
  // We use different context strings for each component to ensure they're different
201
- const idTrapdoor = hmac(sha256, seedBytes, encoder.encode("IDTrapdoor"));
202
- const idNullifier = hmac(sha256, seedBytes, encoder.encode("IDNullifier"));
203
- // Generate IDSecretHash as a hash of IDTrapdoor and IDNullifier
204
- const combinedBytes = new Uint8Array([...idTrapdoor, ...idNullifier]);
205
- const idSecretHash = sha256(combinedBytes);
206
- // Generate IDCommitment as a hash of IDSecretHash
207
- const idCommitment = sha256(idSecretHash);
208
- // Convert IDCommitment to BigInt
209
- const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
210
- log.info("Successfully generated identity credential");
211
- return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
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 idCommitmentRawBE = sha256(idSecretHashBE);
206
+ const idCommitmentBE = this.reduceIdCommitment(idCommitmentRawBE);
207
+ log.info("Successfully generated identity credential, storing in Big Endian format");
208
+ return new IdentityCredential(idTrapdoorBE, idNullifierBE, idSecretHashBE, idCommitmentBE);
209
+ }
210
+ /**
211
+ * Helper: take 32-byte BE, reduce mod Q, return 32-byte BE
212
+ */
213
+ reduceIdCommitment(bytesBE, limit = RLN_Q) {
214
+ const nBE = BytesUtils.buildBigIntFromUint8ArrayBE(bytesBE);
215
+ return BytesUtils.bigIntToUint8Array32BE(nBE % limit);
212
216
  }
213
217
  }
214
218
 
@@ -1,5 +1,4 @@
1
- import { buildBigIntFromUint8Array } from './utils/bytes.js';
2
- import './utils/epoch.js';
1
+ import { BytesUtils } from './utils/bytes.js';
3
2
 
4
3
  class IdentityCredential {
5
4
  IDTrapdoor;
@@ -7,12 +6,16 @@ class IdentityCredential {
7
6
  IDSecretHash;
8
7
  IDCommitment;
9
8
  IDCommitmentBigInt;
10
- constructor(IDTrapdoor, IDNullifier, IDSecretHash, IDCommitment, IDCommitmentBigInt) {
9
+ /**
10
+ * All variables are in little-endian format
11
+ */
12
+ constructor(IDTrapdoor, IDNullifier, IDSecretHash, IDCommitment) {
11
13
  this.IDTrapdoor = IDTrapdoor;
12
14
  this.IDNullifier = IDNullifier;
13
15
  this.IDSecretHash = IDSecretHash;
14
16
  this.IDCommitment = IDCommitment;
15
- this.IDCommitmentBigInt = IDCommitmentBigInt;
17
+ this.IDCommitmentBigInt =
18
+ BytesUtils.buildBigIntFromUint8ArrayBE(IDCommitment);
16
19
  }
17
20
  static fromBytes(memKeys) {
18
21
  if (memKeys.length < 128) {
@@ -22,8 +25,7 @@ class IdentityCredential {
22
25
  const idNullifier = memKeys.subarray(32, 64);
23
26
  const idSecretHash = memKeys.subarray(64, 96);
24
27
  const idCommitment = memKeys.subarray(96, 128);
25
- const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
26
- return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
28
+ return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment);
27
29
  }
28
30
  }
29
31
 
@@ -13,11 +13,11 @@ import '../../../../node_modules/multiformats/dist/src/bases/base64.js';
13
13
  import '../../../../node_modules/multiformats/dist/src/bases/base8.js';
14
14
  import '../../../../node_modules/multiformats/dist/src/bases/identity.js';
15
15
  import '../../../../node_modules/multiformats/dist/src/codecs/json.js';
16
- import { Logger } from '../../../utils/dist/logger/index.js';
16
+ import { Logger } from '../../../utils/dist/logger.js';
17
17
  import { sha256 } from '../../../../node_modules/ethereum-cryptography/esm/sha256.js';
18
18
  import { bytesToUtf8 } from '../../../../node_modules/ethereum-cryptography/esm/utils.js';
19
19
  import _ from '../../../../node_modules/lodash/lodash.js';
20
- import { buildBigIntFromUint8Array } from '../utils/bytes.js';
20
+ import { BytesUtils } from '../utils/bytes.js';
21
21
  import { keccak256Checksum, decryptEipKeystore } from './cipher.js';
22
22
  import { isKeystoreValid, isCredentialValid } from './schema_validator.js';
23
23
  import { __exports as lib } from '../../../../_virtual/index.js';
@@ -164,14 +164,24 @@ class Keystore {
164
164
  try {
165
165
  const str = bytesToUtf8(bytes);
166
166
  const obj = JSON.parse(str);
167
- // TODO: add runtime validation of nwaku credentials
167
+ // Little Endian
168
+ const idCommitmentLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", []));
169
+ const idTrapdoorLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", []));
170
+ const idNullifierLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", []));
171
+ const idSecretHashLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []));
172
+ // Big Endian
173
+ const idCommitmentBE = BytesUtils.switchEndianness(idCommitmentLE);
174
+ const idTrapdoorBE = BytesUtils.switchEndianness(idTrapdoorLE);
175
+ const idNullifierBE = BytesUtils.switchEndianness(idNullifierLE);
176
+ const idSecretHashBE = BytesUtils.switchEndianness(idSecretHashLE);
177
+ const idCommitmentBigInt = BytesUtils.buildBigIntFromUint8ArrayBE(idCommitmentBE);
168
178
  return {
169
179
  identity: {
170
- IDCommitment: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", [])),
171
- IDTrapdoor: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", [])),
172
- IDNullifier: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", [])),
173
- IDCommitmentBigInt: buildBigIntFromUint8Array(Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", []))),
174
- IDSecretHash: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []))
180
+ IDCommitment: idCommitmentBE,
181
+ IDTrapdoor: idTrapdoorBE,
182
+ IDNullifier: idNullifierBE,
183
+ IDSecretHash: idSecretHashBE,
184
+ IDCommitmentBigInt: idCommitmentBigInt
175
185
  },
176
186
  membership: {
177
187
  treeIndex: _.get(obj, "treeIndex"),
@@ -207,14 +217,31 @@ class Keystore {
207
217
  }
208
218
  // follows nwaku implementation
209
219
  // https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L98
220
+ // IdentityCredential is stored in Big Endian format => switch to Little Endian
210
221
  static fromIdentityToBytes(options) {
222
+ const { IDCommitment, IDNullifier, IDSecretHash, IDTrapdoor } = options.identity;
223
+ const idCommitmentLE = BytesUtils.switchEndianness(IDCommitment);
224
+ const idNullifierLE = BytesUtils.switchEndianness(IDNullifier);
225
+ const idSecretHashLE = BytesUtils.switchEndianness(IDSecretHash);
226
+ const idTrapdoorLE = BytesUtils.switchEndianness(IDTrapdoor);
227
+ // eslint-disable-next-line no-console
228
+ console.log({
229
+ idCommitmentBE: IDCommitment,
230
+ idCommitmentLE,
231
+ idNullifierBE: IDNullifier,
232
+ idNullifierLE,
233
+ idSecretHashBE: IDSecretHash,
234
+ idSecretHashLE,
235
+ idTrapdoorBE: IDTrapdoor,
236
+ idTrapdoorLE
237
+ });
211
238
  return utf8ToBytes(JSON.stringify({
212
239
  treeIndex: options.membership.treeIndex,
213
240
  identityCredential: {
214
- idCommitment: Array.from(options.identity.IDCommitment),
215
- idNullifier: Array.from(options.identity.IDNullifier),
216
- idSecretHash: Array.from(options.identity.IDSecretHash),
217
- idTrapdoor: Array.from(options.identity.IDTrapdoor)
241
+ idCommitment: Array.from(idCommitmentLE),
242
+ idNullifier: Array.from(idNullifierLE),
243
+ idSecretHash: Array.from(idSecretHashLE),
244
+ idTrapdoor: Array.from(idTrapdoorLE)
218
245
  },
219
246
  membershipContract: {
220
247
  chainId: options.membership.chainId,