@waku/rln 0.1.5-ea6daae.0 → 0.1.5-ff0222a.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/README.md +5 -0
- package/bundle/_virtual/index2.js +1 -1
- package/bundle/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/index.js +3 -1
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +1 -1
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
- package/bundle/node_modules/{js-sha3 → @ethersproject/keccak256/node_modules/js-sha3}/src/sha3.js +2 -2
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +1 -19
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +10 -58
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +1 -1
- package/bundle/packages/rln/dist/contract/abi.js +502 -248
- package/bundle/packages/rln/dist/contract/constants.js +4 -4
- package/bundle/packages/rln/dist/contract/rln_contract.js +124 -40
- package/bundle/packages/rln/dist/contract/rln_light_contract.js +477 -0
- package/bundle/packages/rln/dist/identity.js +9 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
- package/bundle/packages/rln/dist/keystore/keystore.js +16 -25
- package/bundle/packages/rln/dist/rln.js +8 -8
- package/bundle/packages/rln/dist/rln_light.js +149 -0
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/checksum.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/cipher.js +4 -4
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/class.js +7 -7
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/functional.js +7 -7
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/index.js +6 -6
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/kdf.js +5 -5
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/password.js +1 -1
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/schema-validation.js +2 -2
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/types.js +1 -1
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +7 -7
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +7 -7
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_assert.js +1 -1
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_sha2.js +3 -3
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_u64.js +1 -1
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +43 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +116 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +79 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +126 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +43 -0
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/hmac.js +3 -3
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/pbkdf2.js +4 -4
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/scrypt.js +5 -5
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/sha256.js +3 -3
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/sha512.js +4 -4
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/utils.js +2 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.test-utils.d.ts +36 -0
- package/dist/codec.test-utils.js +56 -0
- package/dist/codec.test-utils.js.map +1 -0
- package/dist/contract/abi.d.ts +21 -17
- package/dist/contract/abi.js +502 -248
- package/dist/contract/abi.js.map +1 -1
- package/dist/contract/constants.d.ts +23 -19
- package/dist/contract/constants.js +3 -3
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +10 -3
- package/dist/contract/rln_contract.js +124 -40
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/contract/rln_light_contract.d.ts +124 -0
- package/dist/contract/rln_light_contract.js +460 -0
- package/dist/contract/rln_light_contract.js.map +1 -0
- package/dist/contract/test-setup.d.ts +26 -0
- package/dist/contract/test-setup.js +56 -0
- package/dist/contract/test-setup.js.map +1 -0
- package/dist/contract/test-utils.d.ts +39 -0
- package/dist/contract/test-utils.js +118 -0
- package/dist/contract/test-utils.js.map +1 -0
- package/dist/identity.d.ts +1 -0
- package/dist/identity.js +9 -0
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.d.ts +0 -1
- package/dist/keystore/keystore.js +15 -24
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +2 -1
- package/dist/rln.d.ts +1 -1
- package/dist/rln.js +8 -8
- package/dist/rln.js.map +1 -1
- package/dist/rln_light.d.ts +64 -0
- package/dist/rln_light.js +144 -0
- package/dist/rln_light.js.map +1 -0
- package/package.json +1 -1
- package/src/codec.test-utils.ts +80 -0
- package/src/contract/abi.ts +502 -248
- package/src/contract/constants.ts +3 -3
- package/src/contract/rln_contract.ts +162 -50
- package/src/contract/rln_light_contract.ts +725 -0
- package/src/contract/test-setup.ts +86 -0
- package/src/contract/test-utils.ts +179 -0
- package/src/identity.ts +10 -0
- package/src/index.ts +17 -2
- package/src/keystore/keystore.ts +27 -42
- package/src/keystore/types.ts +2 -1
- package/src/rln.ts +9 -9
- package/src/rln_light.ts +235 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +0 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
import { hmac } from "@noble/hashes/hmac";
|
2
|
+
import { sha256 } from "@noble/hashes/sha256";
|
3
|
+
import { Logger } from "@waku/utils";
|
4
|
+
import { LINEA_CONTRACT } from "./contract/constants.js";
|
5
|
+
import { RLNLightContract } from "./contract/rln_light_contract.js";
|
6
|
+
import { IdentityCredential } from "./identity.js";
|
7
|
+
import { Keystore } from "./keystore/index.js";
|
8
|
+
import { buildBigIntFromUint8Array, extractMetaMaskSigner } from "./utils/index.js";
|
9
|
+
const log = new Logger("waku:rln");
|
10
|
+
/**
|
11
|
+
* Create an instance of RLN
|
12
|
+
* @returns RLNInstance
|
13
|
+
*/
|
14
|
+
export async function create() {
|
15
|
+
try {
|
16
|
+
return new RLNLightInstance();
|
17
|
+
}
|
18
|
+
catch (error) {
|
19
|
+
log.error("Failed to initialize RLN:", error);
|
20
|
+
throw error;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
export class RLNLightInstance {
|
24
|
+
started = false;
|
25
|
+
starting = false;
|
26
|
+
_contract;
|
27
|
+
_signer;
|
28
|
+
keystore = Keystore.create();
|
29
|
+
_credentials;
|
30
|
+
constructor() { }
|
31
|
+
get contract() {
|
32
|
+
return this._contract;
|
33
|
+
}
|
34
|
+
get signer() {
|
35
|
+
return this._signer;
|
36
|
+
}
|
37
|
+
async start(options = {}) {
|
38
|
+
if (this.started || this.starting) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
this.starting = true;
|
42
|
+
try {
|
43
|
+
const { credentials, keystore } = await RLNLightInstance.decryptCredentialsIfNeeded(options.credentials);
|
44
|
+
const { signer, address, rateLimit } = await this.determineStartOptions(options, credentials);
|
45
|
+
if (keystore) {
|
46
|
+
this.keystore = keystore;
|
47
|
+
}
|
48
|
+
this._credentials = credentials;
|
49
|
+
this._signer = signer;
|
50
|
+
this._contract = await RLNLightContract.init({
|
51
|
+
address: address,
|
52
|
+
signer: signer,
|
53
|
+
rateLimit: rateLimit
|
54
|
+
});
|
55
|
+
this.started = true;
|
56
|
+
}
|
57
|
+
finally {
|
58
|
+
this.starting = false;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
get credentials() {
|
62
|
+
return this._credentials;
|
63
|
+
}
|
64
|
+
async determineStartOptions(options, credentials) {
|
65
|
+
let chainId = credentials?.membership.chainId;
|
66
|
+
const address = credentials?.membership.address ||
|
67
|
+
options.address ||
|
68
|
+
LINEA_CONTRACT.address;
|
69
|
+
if (address === LINEA_CONTRACT.address) {
|
70
|
+
chainId = LINEA_CONTRACT.chainId;
|
71
|
+
}
|
72
|
+
const signer = options.signer || (await extractMetaMaskSigner());
|
73
|
+
const currentChainId = (await signer.getChainId()).toString();
|
74
|
+
if (chainId && chainId !== currentChainId) {
|
75
|
+
throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
|
76
|
+
}
|
77
|
+
return {
|
78
|
+
signer,
|
79
|
+
address
|
80
|
+
};
|
81
|
+
}
|
82
|
+
static async decryptCredentialsIfNeeded(credentials) {
|
83
|
+
if (!credentials) {
|
84
|
+
return {};
|
85
|
+
}
|
86
|
+
if ("identity" in credentials) {
|
87
|
+
return { credentials };
|
88
|
+
}
|
89
|
+
const keystore = Keystore.fromString(credentials.keystore);
|
90
|
+
if (!keystore) {
|
91
|
+
return {};
|
92
|
+
}
|
93
|
+
const decryptedCredentials = await keystore.readCredential(credentials.id, credentials.password);
|
94
|
+
return {
|
95
|
+
keystore,
|
96
|
+
credentials: decryptedCredentials
|
97
|
+
};
|
98
|
+
}
|
99
|
+
/**
|
100
|
+
* Generates an identity credential from a seed string
|
101
|
+
* This is a pure implementation that doesn't rely on Zerokit
|
102
|
+
* @param seed A string seed to generate the identity from
|
103
|
+
* @returns IdentityCredential
|
104
|
+
*/
|
105
|
+
generateSeededIdentityCredential(seed) {
|
106
|
+
// Convert the seed to bytes
|
107
|
+
const encoder = new TextEncoder();
|
108
|
+
const seedBytes = encoder.encode(seed);
|
109
|
+
// Generate deterministic values using HMAC-SHA256
|
110
|
+
// We use different context strings for each component to ensure they're different
|
111
|
+
const idTrapdoor = hmac(sha256, seedBytes, encoder.encode("IDTrapdoor"));
|
112
|
+
const idNullifier = hmac(sha256, seedBytes, encoder.encode("IDNullifier"));
|
113
|
+
// Generate IDSecretHash as a hash of IDTrapdoor and IDNullifier
|
114
|
+
const combinedBytes = new Uint8Array([...idTrapdoor, ...idNullifier]);
|
115
|
+
const idSecretHash = sha256(combinedBytes);
|
116
|
+
// Generate IDCommitment as a hash of IDSecretHash
|
117
|
+
const idCommitment = sha256(idSecretHash);
|
118
|
+
// Convert IDCommitment to BigInt
|
119
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
|
120
|
+
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
121
|
+
}
|
122
|
+
async registerMembership(options) {
|
123
|
+
if (!this.contract) {
|
124
|
+
throw Error("RLN Contract is not initialized.");
|
125
|
+
}
|
126
|
+
let identity = "identity" in options && options.identity;
|
127
|
+
if ("signature" in options) {
|
128
|
+
identity = this.generateSeededIdentityCredential(options.signature);
|
129
|
+
}
|
130
|
+
if (!identity) {
|
131
|
+
throw Error("Missing signature or identity to register membership.");
|
132
|
+
}
|
133
|
+
return this.contract.registerWithIdentity(identity);
|
134
|
+
}
|
135
|
+
/**
|
136
|
+
* Changes credentials in use by relying on provided Keystore earlier in rln.start
|
137
|
+
* @param id: string, hash of credentials to select from Keystore
|
138
|
+
* @param password: string or bytes to use to decrypt credentials from Keystore
|
139
|
+
*/
|
140
|
+
async useCredentials(id, password) {
|
141
|
+
this._credentials = await this.keystore?.readCredential(id, password);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
//# sourceMappingURL=rln_light.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rln_light.js","sourceRoot":"","sources":["../src/rln_light.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO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AY,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;QAE3C,kDAAkD;QAClD,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;QAE1C,iCAAiC;QACjC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAC;QAEnE,OAAO,IAAI,kBAAkB,CAC3B,UAAU,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,CACnB,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAC7B,OAAkC;QAElC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,QAAQ,GAAG,UAAU,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;QAEzD,IAAI,WAAW,IAAI,OAAO,EAAE,CAAC;YAC3B,QAAQ,GAAG,IAAI,CAAC,gCAAgC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,KAAK,CAAC,uDAAuD,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,cAAc,CAAC,EAAU,EAAE,QAAkB;QACxD,IAAI,CAAC,YAAY,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IACxE,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"name":"@waku/rln","version":"0.1.5-
|
1
|
+
{"name":"@waku/rln","version":"0.1.5-ff0222a.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":">=20"},"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","@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.33-ff0222a.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.35-ff0222a.0","@waku/utils":"0.0.23-ff0222a.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,80 @@
|
|
1
|
+
import type { IProtoMessage } from "@waku/interfaces";
|
2
|
+
import { expect } from "chai";
|
3
|
+
|
4
|
+
import { createRLN } from "./create.js";
|
5
|
+
import type { IdentityCredential } from "./identity.js";
|
6
|
+
|
7
|
+
export interface TestRLNCodecSetup {
|
8
|
+
rlnInstance: any;
|
9
|
+
credential: IdentityCredential;
|
10
|
+
index: number;
|
11
|
+
payload: Uint8Array;
|
12
|
+
}
|
13
|
+
|
14
|
+
export const TEST_CONSTANTS = {
|
15
|
+
contentTopic: "/test/1/waku-message/utf8",
|
16
|
+
emptyPubsubTopic: "",
|
17
|
+
defaultIndex: 0,
|
18
|
+
defaultPayload: new Uint8Array([1, 2, 3, 4, 5])
|
19
|
+
} as const;
|
20
|
+
|
21
|
+
export const EMPTY_PROTO_MESSAGE = {
|
22
|
+
timestamp: undefined,
|
23
|
+
contentTopic: "",
|
24
|
+
ephemeral: undefined,
|
25
|
+
meta: undefined,
|
26
|
+
rateLimitProof: undefined,
|
27
|
+
version: undefined
|
28
|
+
} as const;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Creates a basic RLN setup for codec tests
|
32
|
+
*/
|
33
|
+
export async function createTestRLNCodecSetup(): Promise<TestRLNCodecSetup> {
|
34
|
+
const rlnInstance = await createRLN();
|
35
|
+
const credential = rlnInstance.zerokit.generateIdentityCredentials();
|
36
|
+
rlnInstance.zerokit.insertMember(credential.IDCommitment);
|
37
|
+
|
38
|
+
return {
|
39
|
+
rlnInstance,
|
40
|
+
credential,
|
41
|
+
index: TEST_CONSTANTS.defaultIndex,
|
42
|
+
payload: TEST_CONSTANTS.defaultPayload
|
43
|
+
};
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Creates a meta setter function for testing
|
48
|
+
*/
|
49
|
+
export function createTestMetaSetter(): (
|
50
|
+
msg: IProtoMessage & { meta: undefined }
|
51
|
+
) => Uint8Array {
|
52
|
+
return (msg: IProtoMessage & { meta: undefined }): Uint8Array => {
|
53
|
+
const buffer = new ArrayBuffer(4);
|
54
|
+
const view = new DataView(buffer);
|
55
|
+
view.setUint32(0, msg.payload.length, false);
|
56
|
+
return new Uint8Array(buffer);
|
57
|
+
};
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Verifies common RLN message properties
|
62
|
+
*/
|
63
|
+
export function verifyRLNMessage(
|
64
|
+
msg: any,
|
65
|
+
payload: Uint8Array,
|
66
|
+
contentTopic: string,
|
67
|
+
version: number,
|
68
|
+
rlnInstance: any
|
69
|
+
): void {
|
70
|
+
expect(msg.rateLimitProof).to.not.be.undefined;
|
71
|
+
expect(msg.verify([rlnInstance.zerokit.getMerkleRoot()])).to.be.true;
|
72
|
+
expect(msg.verifyNoRoot()).to.be.true;
|
73
|
+
expect(msg.epoch).to.not.be.undefined;
|
74
|
+
expect(msg.epoch).to.be.gt(0);
|
75
|
+
|
76
|
+
expect(msg.contentTopic).to.eq(contentTopic);
|
77
|
+
expect(msg.msg.version).to.eq(version);
|
78
|
+
expect(msg.payload).to.deep.eq(payload);
|
79
|
+
expect(msg.timestamp).to.not.be.undefined;
|
80
|
+
}
|