@waku/rln 0.1.6 → 0.1.7-36f6884.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/index.js +2 -2
- package/bundle/packages/core/dist/lib/connection_manager/connection_limiter.js +17 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +9 -5
- package/bundle/packages/core/dist/lib/connection_manager/dialer.js +17 -0
- package/bundle/packages/core/dist/lib/connection_manager/discovery_dialer.js +17 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +2 -2
- package/bundle/packages/core/dist/lib/connection_manager/shard_reader.js +17 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +3 -3
- package/bundle/packages/core/dist/lib/light_push/light_push.js +2 -2
- package/bundle/packages/core/dist/lib/message/version_0.js +1 -1
- package/bundle/packages/core/dist/lib/metadata/metadata.js +2 -2
- package/bundle/packages/core/dist/lib/store/store.js +2 -2
- package/bundle/packages/interfaces/dist/connection_manager.js +2 -12
- package/bundle/packages/interfaces/dist/{health_indicator.js → health_status.js} +10 -5
- package/bundle/packages/proto/dist/generated/light_push.js +160 -1
- package/bundle/packages/rln/dist/codec.js +2 -2
- package/bundle/packages/rln/dist/contract/abi/price_calculator.js +95 -0
- package/bundle/packages/rln/dist/contract/constants.js +15 -3
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +25 -6
- package/bundle/packages/rln/dist/contract/rln_contract.js +4 -4
- package/bundle/packages/rln/dist/credentials_manager.js +25 -21
- package/bundle/packages/rln/dist/identity.js +8 -6
- package/bundle/packages/rln/dist/keystore/keystore.js +40 -13
- package/bundle/packages/rln/dist/message.js +1 -1
- package/bundle/packages/rln/dist/proof.js +2 -2
- package/bundle/packages/rln/dist/rln.js +2 -2
- package/bundle/packages/rln/dist/utils/bytes.js +103 -58
- package/bundle/packages/rln/dist/utils/epoch.js +2 -2
- package/bundle/packages/rln/dist/utils/hash.js +3 -3
- package/bundle/packages/rln/dist/zerokit.js +17 -17
- package/bundle/packages/utils/dist/common/sharding/index.js +1 -1
- package/bundle/packages/utils/dist/{logger/index.js → logger.js} +3 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/abi/price_calculator.d.ts +46 -0
- package/dist/contract/abi/price_calculator.js +94 -0
- package/dist/contract/abi/price_calculator.js.map +1 -0
- package/dist/contract/{abi.js → abi/rln.js} +1 -1
- package/dist/contract/abi/rln.js.map +1 -0
- package/dist/contract/constants.d.ts +57 -1
- package/dist/contract/constants.js +14 -2
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_base_contract.d.ts +9 -0
- package/dist/contract/rln_base_contract.js +23 -4
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/rln_contract.js +2 -2
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/contract/{test-setup.d.ts → test_setup.d.ts} +4 -4
- package/dist/contract/{test-setup.js → test_setup.js} +4 -4
- package/dist/contract/{test-setup.js.map → test_setup.js.map} +1 -1
- package/dist/contract/{test-utils.js → test_utils.js} +10 -10
- package/dist/contract/{test-utils.js.map → test_utils.js.map} +1 -1
- package/dist/credentials_manager.d.ts +4 -0
- package/dist/credentials_manager.js +24 -19
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.d.ts +5 -2
- package/dist/identity.js +8 -5
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.js +38 -11
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/proof.js +2 -2
- package/dist/proof.js.map +1 -1
- package/dist/utils/bytes.d.ts +42 -20
- package/dist/utils/bytes.js +102 -57
- package/dist/utils/bytes.js.map +1 -1
- package/dist/utils/hash.js +5 -5
- package/dist/utils/hash.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/dist/zerokit.js +17 -17
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -93
- package/src/contract/abi/price_calculator.ts +93 -0
- package/src/contract/constants.ts +18 -2
- package/src/contract/rln_base_contract.ts +38 -5
- package/src/contract/rln_contract.ts +5 -2
- package/src/contract/{test-setup.ts → test_setup.ts} +4 -4
- package/src/contract/{test-utils.ts → test_utils.ts} +9 -9
- package/src/credentials_manager.ts +41 -27
- package/src/identity.ts +11 -7
- package/src/index.ts +3 -3
- package/src/keystore/keystore.ts +52 -23
- package/src/proof.ts +2 -2
- package/src/utils/bytes.ts +118 -72
- package/src/utils/hash.ts +15 -5
- package/src/utils/index.ts +1 -6
- package/src/zerokit.ts +30 -22
- package/dist/contract/abi.js.map +0 -1
- /package/bundle/packages/rln/dist/contract/{abi.js → abi/rln.js} +0 -0
- /package/dist/contract/{abi.d.ts → abi/rln.d.ts} +0 -0
- /package/dist/contract/{test-utils.d.ts → test_utils.d.ts} +0 -0
- /package/src/contract/{abi.ts → abi/rln.ts} +0 -0
package/dist/utils/hash.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
2
|
-
import {
|
2
|
+
import { BytesUtils } from "./bytes.js";
|
3
3
|
export function poseidonHash(...input) {
|
4
|
-
const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
|
5
|
-
const lenPrefixedData = concatenate(inputLen, ...input);
|
4
|
+
const inputLen = BytesUtils.writeUIntLE(new Uint8Array(8), input.length, 0, 8);
|
5
|
+
const lenPrefixedData = BytesUtils.concatenate(inputLen, ...input);
|
6
6
|
return zerokitRLN.poseidonHash(lenPrefixedData);
|
7
7
|
}
|
8
8
|
export function sha256(input) {
|
9
|
-
const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
|
10
|
-
const lenPrefixedData = concatenate(inputLen, input);
|
9
|
+
const inputLen = BytesUtils.writeUIntLE(new Uint8Array(8), input.length, 0, 8);
|
10
|
+
const lenPrefixedData = BytesUtils.concatenate(inputLen, input);
|
11
11
|
return zerokitRLN.hash(lenPrefixedData);
|
12
12
|
}
|
13
13
|
//# sourceMappingURL=hash.js.map
|
package/dist/utils/hash.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,UAAU,YAAY,CAAC,GAAG,KAAwB;IACtD,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CACrC,IAAI,UAAU,CAAC,CAAC,CAAC,EACjB,KAAK,CAAC,MAAM,EACZ,CAAC,EACD,CAAC,CACF,CAAC;IACF,MAAM,eAAe,GAAG,UAAU,CAAC,WAAW,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC;IACnE,OAAO,UAAU,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAiB;IACtC,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CACrC,IAAI,UAAU,CAAC,CAAC,CAAC,EACjB,KAAK,CAAC,MAAM,EACZ,CAAC,EACD,CAAC,CACF,CAAC;IACF,MAAM,eAAe,GAAG,UAAU,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChE,OAAO,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAC1C,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
export { extractMetaMaskSigner } from "./metamask.js";
|
2
|
-
export {
|
2
|
+
export { BytesUtils } from "./bytes.js";
|
3
3
|
export { sha256, poseidonHash } from "./hash.js";
|
4
4
|
export { dateToEpoch, epochIntToBytes, epochBytesToInt } from "./epoch.js";
|
package/dist/utils/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
export { extractMetaMaskSigner } from "./metamask.js";
|
2
|
-
export {
|
2
|
+
export { BytesUtils } from "./bytes.js";
|
3
3
|
export { sha256, poseidonHash } from "./hash.js";
|
4
4
|
export { dateToEpoch, epochIntToBytes, epochBytesToInt } from "./epoch.js";
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/zerokit.js
CHANGED
@@ -2,7 +2,7 @@ import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
|
2
2
|
import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from "./contract/constants.js";
|
3
3
|
import { IdentityCredential } from "./identity.js";
|
4
4
|
import { Proof, proofToBytes } from "./proof.js";
|
5
|
-
import {
|
5
|
+
import { BytesUtils, dateToEpoch, epochIntToBytes } from "./utils/index.js";
|
6
6
|
export class Zerokit {
|
7
7
|
zkRLN;
|
8
8
|
witnessCalculator;
|
@@ -38,8 +38,8 @@ export class Zerokit {
|
|
38
38
|
insertMembers(index, ...idCommitments) {
|
39
39
|
// serializes a seq of IDCommitments to a byte seq
|
40
40
|
// the order of serialization is |id_commitment_len<8>|id_commitment<var>|
|
41
|
-
const idCommitmentLen = writeUIntLE(new Uint8Array(8), idCommitments.length, 0, 8);
|
42
|
-
const idCommitmentBytes = concatenate(idCommitmentLen, ...idCommitments);
|
41
|
+
const idCommitmentLen = BytesUtils.writeUIntLE(new Uint8Array(8), idCommitments.length, 0, 8);
|
42
|
+
const idCommitmentBytes = BytesUtils.concatenate(idCommitmentLen, ...idCommitments);
|
43
43
|
zerokitRLN.setLeavesFrom(this.zkRLN, index, idCommitmentBytes);
|
44
44
|
}
|
45
45
|
deleteMember(index) {
|
@@ -50,11 +50,11 @@ export class Zerokit {
|
|
50
50
|
}
|
51
51
|
serializeMessage(uint8Msg, memIndex, epoch, idKey, rateLimit) {
|
52
52
|
// calculate message length
|
53
|
-
const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
|
54
|
-
const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
|
55
|
-
const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
53
|
+
const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
|
54
|
+
const memIndexBytes = BytesUtils.writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
|
55
|
+
const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
56
56
|
// [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> | rate_limit<8> ]
|
57
|
-
return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg, rateLimitBytes);
|
57
|
+
return BytesUtils.concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg, rateLimitBytes);
|
58
58
|
}
|
59
59
|
async generateRLNProof(msg, index, epoch, idSecretHash, rateLimit) {
|
60
60
|
if (epoch === undefined) {
|
@@ -90,9 +90,9 @@ export class Zerokit {
|
|
90
90
|
pBytes = proofToBytes(proof);
|
91
91
|
}
|
92
92
|
// calculate message length
|
93
|
-
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
94
|
-
const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
95
|
-
return zerokitRLN.verifyRLNProof(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes));
|
93
|
+
const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
94
|
+
const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
95
|
+
return zerokitRLN.verifyRLNProof(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes));
|
96
96
|
}
|
97
97
|
verifyWithRoots(proof, msg, roots, rateLimit) {
|
98
98
|
let pBytes;
|
@@ -103,10 +103,10 @@ export class Zerokit {
|
|
103
103
|
pBytes = proofToBytes(proof);
|
104
104
|
}
|
105
105
|
// calculate message length
|
106
|
-
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
107
|
-
const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
108
|
-
const rootsBytes = concatenate(...roots);
|
109
|
-
return zerokitRLN.verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes), rootsBytes);
|
106
|
+
const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
107
|
+
const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
108
|
+
const rootsBytes = BytesUtils.concatenate(...roots);
|
109
|
+
return zerokitRLN.verifyWithRoots(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes), rootsBytes);
|
110
110
|
}
|
111
111
|
verifyWithNoRoot(proof, msg, rateLimit) {
|
112
112
|
let pBytes;
|
@@ -117,9 +117,9 @@ export class Zerokit {
|
|
117
117
|
pBytes = proofToBytes(proof);
|
118
118
|
}
|
119
119
|
// calculate message length
|
120
|
-
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
121
|
-
const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
122
|
-
return zerokitRLN.verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes), new Uint8Array());
|
120
|
+
const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
121
|
+
const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
122
|
+
return zerokitRLN.verifyWithRoots(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes), new Uint8Array());
|
123
123
|
}
|
124
124
|
}
|
125
125
|
//# sourceMappingURL=zerokit.js.map
|
package/dist/zerokit.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"zerokit.js","sourceRoot":"","sources":["../src/zerokit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,
|
1
|
+
{"version":3,"file":"zerokit.js","sourceRoot":"","sources":["../src/zerokit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjD,OA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,CAAC,CAAC,CAAC,EACjB,SAAS,IAAI,IAAI,CAAC,SAAS,EAC3B,CAAC,EACD,CAAC,CACF,CAAC;QAEF,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC,CAAC;QAEpD,OAAO,UAAU,CAAC,eAAe,CAC/B,IAAI,CAAC,KAAK,EACV,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,EAC3D,UAAU,CACX,CAAC;IACJ,CAAC;IAEM,gBAAgB,CACrB,KAAmC,EACnC,GAAe,EACf,SAAkB;QAElB,IAAI,MAAkB,CAAC;QACvB,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;YAChC,MAAM,GAAG,KAAK,CAAC;QACjB,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QAED,2BAA2B;QAC3B,MAAM,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3E,MAAM,cAAc,GAAG,UAAU,CAAC,WAAW,CAC3C,IAAI,UAAU,CAAC,CAAC,CAAC,EACjB,SAAS,IAAI,IAAI,CAAC,SAAS,EAC3B,CAAC,EACD,CAAC,CACF,CAAC;QAEF,OAAO,UAAU,CAAC,eAAe,CAC/B,IAAI,CAAC,KAAK,EACV,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,EAC3D,IAAI,UAAU,EAAE,CACjB,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1,93 +1 @@
|
|
1
|
-
{
|
2
|
-
"name": "@waku/rln",
|
3
|
-
"version": "0.1.6",
|
4
|
-
"description": "RLN (Rate Limiting Nullifier) implementation for Waku",
|
5
|
-
"types": "./dist/index.d.ts",
|
6
|
-
"module": "./dist/index.js",
|
7
|
-
"exports": {
|
8
|
-
".": {
|
9
|
-
"types": "./dist/index.d.ts",
|
10
|
-
"import": "./dist/index.js"
|
11
|
-
}
|
12
|
-
},
|
13
|
-
"type": "module",
|
14
|
-
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/rln#readme",
|
15
|
-
"repository": {
|
16
|
-
"type": "git",
|
17
|
-
"url": "https://github.com/waku-org/js-waku.git"
|
18
|
-
},
|
19
|
-
"bugs": {
|
20
|
-
"url": "https://github.com/waku-org/js-waku/issues"
|
21
|
-
},
|
22
|
-
"license": "MIT OR Apache-2.0",
|
23
|
-
"keywords": [
|
24
|
-
"waku",
|
25
|
-
"rln",
|
26
|
-
"rate-limiting",
|
27
|
-
"privacy",
|
28
|
-
"web3"
|
29
|
-
],
|
30
|
-
"scripts": {
|
31
|
-
"build": "run-s build:**",
|
32
|
-
"build:copy": "mkdir -p dist/resources && cp -r src/resources/* dist/resources/",
|
33
|
-
"build:esm": "tsc",
|
34
|
-
"build:bundle": "rollup --config rollup.config.js",
|
35
|
-
"fix": "run-s fix:*",
|
36
|
-
"fix:lint": "eslint src *.js --fix",
|
37
|
-
"check": "run-s check:*",
|
38
|
-
"check:tsc": "tsc -p tsconfig.dev.json",
|
39
|
-
"check:lint": "eslint \"src/!(resources)/**/*.{ts,js}\" *.js",
|
40
|
-
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
41
|
-
"test": "NODE_ENV=test run-s test:*",
|
42
|
-
"test:browser": "karma start karma.conf.cjs",
|
43
|
-
"watch:build": "tsc -p tsconfig.json -w",
|
44
|
-
"watch:test": "mocha --watch",
|
45
|
-
"prepublish": "npm run build",
|
46
|
-
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
47
|
-
},
|
48
|
-
"engines": {
|
49
|
-
"node": ">=22"
|
50
|
-
},
|
51
|
-
"devDependencies": {
|
52
|
-
"@rollup/plugin-commonjs": "^25.0.7",
|
53
|
-
"@rollup/plugin-json": "^6.0.0",
|
54
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
55
|
-
"@types/chai": "^5.0.1",
|
56
|
-
"@types/chai-spies": "^1.0.6",
|
57
|
-
"@waku/interfaces": "0.0.31",
|
58
|
-
"@types/deep-equal-in-any-order": "^1.0.4",
|
59
|
-
"@types/lodash": "^4.17.15",
|
60
|
-
"@types/sinon": "^17.0.3",
|
61
|
-
"@waku/build-utils": "^1.0.0",
|
62
|
-
"@waku/message-encryption": "^0.0.34",
|
63
|
-
"deep-equal-in-any-order": "^2.0.6",
|
64
|
-
"fast-check": "^3.23.2",
|
65
|
-
"rollup-plugin-copy": "^3.5.0"
|
66
|
-
},
|
67
|
-
"files": [
|
68
|
-
"dist",
|
69
|
-
"bundle",
|
70
|
-
"src/**/*.ts",
|
71
|
-
"!**/*.spec.*",
|
72
|
-
"!**/*.json",
|
73
|
-
"CHANGELOG.md",
|
74
|
-
"LICENSE",
|
75
|
-
"README.md"
|
76
|
-
],
|
77
|
-
"dependencies": {
|
78
|
-
"@chainsafe/bls-keystore": "3.0.0",
|
79
|
-
"@waku/core": "^0.0.36",
|
80
|
-
"@waku/utils": "^0.0.24",
|
81
|
-
"@noble/hashes": "^1.2.0",
|
82
|
-
"@waku/zerokit-rln-wasm": "^0.0.13",
|
83
|
-
"ethereum-cryptography": "^3.1.0",
|
84
|
-
"ethers": "^5.7.2",
|
85
|
-
"lodash": "^4.17.21",
|
86
|
-
"uuid": "^11.0.5",
|
87
|
-
"chai": "^5.1.2",
|
88
|
-
"chai-as-promised": "^8.0.1",
|
89
|
-
"chai-spies": "^1.1.0",
|
90
|
-
"chai-subset": "^1.6.0",
|
91
|
-
"sinon": "^19.0.2"
|
92
|
-
}
|
93
|
-
}
|
1
|
+
{"name":"@waku/rln","version":"0.1.7-36f6884.0","description":"RLN (Rate Limiting Nullifier) implementation for Waku","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/rln#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","rln","rate-limiting","privacy","web3"],"scripts":{"build":"run-s build:**","build:copy":"mkdir -p dist/resources && cp -r src/resources/* dist/resources/","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:tsc":"tsc -p tsconfig.dev.json","check:lint":"eslint \"src/!(resources)/**/*.{ts,js}\" *.js","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","test":"NODE_ENV=test run-s test:*","test:browser":"karma start karma.conf.cjs","watch:build":"tsc -p tsconfig.json -w","watch:test":"mocha --watch","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=22"},"devDependencies":{"@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^5.0.1","@types/chai-spies":"^1.0.6","@waku/interfaces":"0.0.32-36f6884.0","@types/deep-equal-in-any-order":"^1.0.4","@types/lodash":"^4.17.15","@types/sinon":"^17.0.3","@waku/build-utils":"^1.0.0","@waku/message-encryption":"0.0.35-36f6884.0","deep-equal-in-any-order":"^2.0.6","fast-check":"^3.23.2","rollup-plugin-copy":"^3.5.0"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@chainsafe/bls-keystore":"3.0.0","@waku/core":"0.0.37-36f6884.0","@waku/utils":"0.0.25-36f6884.0","@noble/hashes":"^1.2.0","@waku/zerokit-rln-wasm":"^0.0.13","ethereum-cryptography":"^3.1.0","ethers":"^5.7.2","lodash":"^4.17.21","uuid":"^11.0.5","chai":"^5.1.2","chai-as-promised":"^8.0.1","chai-spies":"^1.1.0","chai-subset":"^1.6.0","sinon":"^19.0.2"}}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
export 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
|
+
];
|
@@ -1,11 +1,18 @@
|
|
1
|
-
import {
|
1
|
+
import { PRICE_CALCULATOR_ABI } from "./abi/price_calculator.js";
|
2
|
+
import { RLN_ABI } from "./abi/rln.js";
|
2
3
|
|
3
|
-
export const
|
4
|
+
export const RLN_CONTRACT = {
|
4
5
|
chainId: 59141,
|
5
6
|
address: "0xb9cd878c90e49f797b4431fbf4fb333108cb90e6",
|
6
7
|
abi: RLN_ABI
|
7
8
|
};
|
8
9
|
|
10
|
+
export const PRICE_CALCULATOR_CONTRACT = {
|
11
|
+
chainId: 59141,
|
12
|
+
address: "0xBcfC0660Df69f53ab409F32bb18A3fb625fcE644",
|
13
|
+
abi: PRICE_CALCULATOR_ABI
|
14
|
+
};
|
15
|
+
|
9
16
|
/**
|
10
17
|
* Rate limit tiers (messages per epoch)
|
11
18
|
* Each membership can specify a rate limit within these bounds.
|
@@ -25,4 +32,13 @@ export const RATE_LIMIT_PARAMS = {
|
|
25
32
|
EPOCH_LENGTH: 600 // Epoch length in seconds (10 minutes)
|
26
33
|
} as const;
|
27
34
|
|
35
|
+
/**
|
36
|
+
* Default Q value for the RLN contract
|
37
|
+
* This is the upper bound for the ID commitment
|
38
|
+
* @see https://github.com/waku-org/specs/blob/master/standards/core/rln-contract.md#implementation-suggestions
|
39
|
+
*/
|
40
|
+
export const RLN_Q = BigInt(
|
41
|
+
"21888242871839275222246405745257275088548364400416034343698204186575808495617"
|
42
|
+
);
|
43
|
+
|
28
44
|
export const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
|
@@ -3,9 +3,14 @@ import { ethers } from "ethers";
|
|
3
3
|
|
4
4
|
import { IdentityCredential } from "../identity.js";
|
5
5
|
import { DecryptedCredentials } from "../keystore/types.js";
|
6
|
+
import { BytesUtils } from "../utils/bytes.js";
|
6
7
|
|
7
|
-
import { RLN_ABI } from "./abi.js";
|
8
|
-
import {
|
8
|
+
import { RLN_ABI } from "./abi/rln.js";
|
9
|
+
import {
|
10
|
+
DEFAULT_RATE_LIMIT,
|
11
|
+
PRICE_CALCULATOR_CONTRACT,
|
12
|
+
RATE_LIMIT_PARAMS
|
13
|
+
} from "./constants.js";
|
9
14
|
import {
|
10
15
|
CustomQueryOptions,
|
11
16
|
FetchMembersOptions,
|
@@ -490,7 +495,6 @@ export class RLNBaseContract {
|
|
490
495
|
log.error(`Error in withdraw: ${(error as Error).message}`);
|
491
496
|
}
|
492
497
|
}
|
493
|
-
|
494
498
|
public async registerWithIdentity(
|
495
499
|
identity: IdentityCredential
|
496
500
|
): Promise<DecryptedCredentials | undefined> {
|
@@ -529,7 +533,9 @@ export class RLNBaseContract {
|
|
529
533
|
identity.IDCommitmentBigInt,
|
530
534
|
this.rateLimit,
|
531
535
|
[],
|
532
|
-
{
|
536
|
+
{
|
537
|
+
gasLimit
|
538
|
+
}
|
533
539
|
);
|
534
540
|
|
535
541
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
@@ -626,7 +632,7 @@ export class RLNBaseContract {
|
|
626
632
|
permit.v,
|
627
633
|
permit.r,
|
628
634
|
permit.s,
|
629
|
-
identity.
|
635
|
+
BytesUtils.buildBigIntFromUint8ArrayBE(identity.IDCommitment),
|
630
636
|
this.rateLimit,
|
631
637
|
idCommitmentsToErase.map((id) => ethers.BigNumber.from(id))
|
632
638
|
);
|
@@ -768,4 +774,31 @@ export class RLNBaseContract {
|
|
768
774
|
return false;
|
769
775
|
}
|
770
776
|
}
|
777
|
+
|
778
|
+
/**
|
779
|
+
* Calculates the price for a given rate limit using the PriceCalculator contract
|
780
|
+
* @param rateLimit The rate limit to calculate the price for
|
781
|
+
* @param contractFactory Optional factory for creating the contract (for testing)
|
782
|
+
*/
|
783
|
+
public async getPriceForRateLimit(
|
784
|
+
rateLimit: number,
|
785
|
+
contractFactory?: typeof import("ethers").Contract
|
786
|
+
): Promise<{
|
787
|
+
token: string | null;
|
788
|
+
price: import("ethers").BigNumber | null;
|
789
|
+
}> {
|
790
|
+
const provider = this.contract.provider;
|
791
|
+
const ContractCtor = contractFactory || ethers.Contract;
|
792
|
+
const priceCalculator = new ContractCtor(
|
793
|
+
PRICE_CALCULATOR_CONTRACT.address,
|
794
|
+
PRICE_CALCULATOR_CONTRACT.abi,
|
795
|
+
provider
|
796
|
+
);
|
797
|
+
const [token, price] = await priceCalculator.calculate(rateLimit);
|
798
|
+
// Defensive: if token or price is null/undefined, return nulls
|
799
|
+
if (!token || !price) {
|
800
|
+
return { token: null, price: null };
|
801
|
+
}
|
802
|
+
return { token, price };
|
803
|
+
}
|
771
804
|
}
|
@@ -4,7 +4,7 @@ import { ethers } from "ethers";
|
|
4
4
|
|
5
5
|
import type { RLNInstance } from "../rln.js";
|
6
6
|
import { MerkleRootTracker } from "../root_tracker.js";
|
7
|
-
import {
|
7
|
+
import { BytesUtils } from "../utils/bytes.js";
|
8
8
|
|
9
9
|
import { RLNBaseContract } from "./rln_base_contract.js";
|
10
10
|
import { RLNContractInitOptions } from "./types.js";
|
@@ -110,7 +110,10 @@ export class RLNContract extends RLNBaseContract {
|
|
110
110
|
index = ethers.BigNumber.from(index);
|
111
111
|
}
|
112
112
|
|
113
|
-
const idCommitment = zeroPadLE(
|
113
|
+
const idCommitment = BytesUtils.zeroPadLE(
|
114
|
+
hexToBytes(_idCommitment),
|
115
|
+
32
|
116
|
+
);
|
114
117
|
rlnInstance.zerokit.insertMember(idCommitment);
|
115
118
|
|
116
119
|
const numericIndex = index.toNumber();
|
@@ -5,7 +5,7 @@ import sinon from "sinon";
|
|
5
5
|
import { createRLN } from "../create.js";
|
6
6
|
import type { IdentityCredential } from "../identity.js";
|
7
7
|
|
8
|
-
import { DEFAULT_RATE_LIMIT,
|
8
|
+
import { DEFAULT_RATE_LIMIT, RLN_CONTRACT } from "./constants.js";
|
9
9
|
import { RLNContract } from "./rln_contract.js";
|
10
10
|
|
11
11
|
export interface TestRLNInstance {
|
@@ -42,7 +42,7 @@ export async function initializeRLNContract(
|
|
42
42
|
mockedRegistryContract: ethers.Contract
|
43
43
|
): Promise<RLNContract> {
|
44
44
|
const provider = new ethers.providers.JsonRpcProvider();
|
45
|
-
const voidSigner = new ethers.VoidSigner(
|
45
|
+
const voidSigner = new ethers.VoidSigner(RLN_CONTRACT.address, provider);
|
46
46
|
|
47
47
|
const originalRegister = mockedRegistryContract.register;
|
48
48
|
(mockedRegistryContract as any).register = function (...args: any[]) {
|
@@ -63,7 +63,7 @@ export async function initializeRLNContract(
|
|
63
63
|
};
|
64
64
|
|
65
65
|
const contract = await RLNContract.init(rlnInstance, {
|
66
|
-
address:
|
66
|
+
address: RLN_CONTRACT.address,
|
67
67
|
signer: voidSigner,
|
68
68
|
rateLimit: DEFAULT_RATE_LIMIT,
|
69
69
|
contract: mockedRegistryContract
|
@@ -83,4 +83,4 @@ export const TEST_DATA = {
|
|
83
83
|
),
|
84
84
|
mockSignature:
|
85
85
|
"0xdeb8a6b00a8e404deb1f52d3aa72ed7f60a2ff4484c737eedaef18a0aacb2dfb4d5d74ac39bb71fa358cf2eb390565a35b026cc6272f2010d4351e17670311c21c"
|
86
|
-
}
|
86
|
+
};
|
@@ -5,7 +5,7 @@ import sinon from "sinon";
|
|
5
5
|
|
6
6
|
import type { IdentityCredential } from "../identity.js";
|
7
7
|
|
8
|
-
import { DEFAULT_RATE_LIMIT,
|
8
|
+
import { DEFAULT_RATE_LIMIT, RLN_CONTRACT } from "./constants.js";
|
9
9
|
|
10
10
|
export const mockRateLimits = {
|
11
11
|
minRate: 20,
|
@@ -36,9 +36,9 @@ export function createMockProvider(): MockProvider {
|
|
36
36
|
|
37
37
|
export function createMockFilters(): MockFilters {
|
38
38
|
return {
|
39
|
-
MembershipRegistered: () => ({ address:
|
40
|
-
MembershipErased: () => ({ address:
|
41
|
-
MembershipExpired: () => ({ address:
|
39
|
+
MembershipRegistered: () => ({ address: RLN_CONTRACT.address }),
|
40
|
+
MembershipErased: () => ({ address: RLN_CONTRACT.address }),
|
41
|
+
MembershipExpired: () => ({ address: RLN_CONTRACT.address })
|
42
42
|
};
|
43
43
|
}
|
44
44
|
|
@@ -51,9 +51,9 @@ export function createMockRegistryContract(
|
|
51
51
|
overrides: ContractOverrides = {}
|
52
52
|
): ethers.Contract {
|
53
53
|
const filters = {
|
54
|
-
MembershipRegistered: () => ({ address:
|
55
|
-
MembershipErased: () => ({ address:
|
56
|
-
MembershipExpired: () => ({ address:
|
54
|
+
MembershipRegistered: () => ({ address: RLN_CONTRACT.address }),
|
55
|
+
MembershipErased: () => ({ address: RLN_CONTRACT.address }),
|
56
|
+
MembershipExpired: () => ({ address: RLN_CONTRACT.address })
|
57
57
|
};
|
58
58
|
|
59
59
|
const baseContract = {
|
@@ -89,7 +89,7 @@ export function createMockRegistryContract(
|
|
89
89
|
format: () => {}
|
90
90
|
})
|
91
91
|
},
|
92
|
-
address:
|
92
|
+
address: RLN_CONTRACT.address
|
93
93
|
};
|
94
94
|
|
95
95
|
// Merge overrides while preserving filters
|
@@ -163,7 +163,7 @@ export function verifyRegistration(
|
|
163
163
|
expect(decryptedCredentials).to.have.property("identity");
|
164
164
|
expect(decryptedCredentials).to.have.property("membership");
|
165
165
|
expect(decryptedCredentials.membership).to.include({
|
166
|
-
address:
|
166
|
+
address: RLN_CONTRACT.address,
|
167
167
|
treeIndex: 1
|
168
168
|
});
|
169
169
|
|