@waku/rln 0.1.5-861a776.0 → 0.1.5-a8ff776.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 +0 -2
- package/bundle/packages/rln/dist/contract/constants.js +1 -1
- package/bundle/packages/rln/dist/contract/rln_contract.js +8 -8
- package/bundle/packages/rln/dist/identity.js +0 -9
- package/bundle/packages/rln/dist/keystore/keystore.js +25 -15
- package/bundle/packages/rln/dist/rln.js +4 -4
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/constants.d.ts +1 -1
- package/dist/contract/constants.js +1 -1
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.js +8 -8
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/identity.d.ts +0 -1
- package/dist/identity.js +0 -9
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.d.ts +1 -0
- package/dist/keystore/keystore.js +25 -15
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +1 -1
- package/dist/rln.js +4 -4
- package/dist/rln.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +1 -1
- package/src/contract/rln_contract.ts +8 -8
- package/src/identity.ts +0 -10
- package/src/index.ts +0 -4
- package/src/keystore/keystore.ts +43 -27
- package/src/keystore/types.ts +1 -1
- package/src/rln.ts +4 -4
- package/bundle/packages/rln/dist/contract/rln_light_contract.js +0 -477
- package/bundle/packages/rln/dist/rln_light.js +0 -149
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +0 -43
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +0 -116
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +0 -79
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +0 -126
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +0 -43
- package/dist/contract/rln_light_contract.d.ts +0 -124
- package/dist/contract/rln_light_contract.js +0 -460
- package/dist/contract/rln_light_contract.js.map +0 -1
- package/dist/rln_light.d.ts +0 -64
- package/dist/rln_light.js +0 -144
- package/dist/rln_light.js.map +0 -1
- package/src/contract/rln_light_contract.ts +0 -725
- package/src/rln_light.ts +0 -235
package/bundle/index.js
CHANGED
@@ -2,13 +2,11 @@ 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
4
|
export { LINEA_CONTRACT } from './packages/rln/dist/contract/constants.js';
|
5
|
-
export { RLNLightContract } from './packages/rln/dist/contract/rln_light_contract.js';
|
6
5
|
export { createRLN } from './packages/rln/dist/create.js';
|
7
6
|
export { IdentityCredential } from './packages/rln/dist/identity.js';
|
8
7
|
export { Keystore } from './packages/rln/dist/keystore/keystore.js';
|
9
8
|
export { Proof } from './packages/rln/dist/proof.js';
|
10
9
|
export { RLNInstance } from './packages/rln/dist/rln.js';
|
11
|
-
export { RLNLightInstance } from './packages/rln/dist/rln_light.js';
|
12
10
|
export { MerkleRootTracker } from './packages/rln/dist/root_tracker.js';
|
13
11
|
export { extractMetaMaskSigner } from './packages/rln/dist/utils/metamask.js';
|
14
12
|
import './packages/rln/dist/utils/epoch.js';
|
@@ -84,7 +84,7 @@ class RLNContract {
|
|
84
84
|
*/
|
85
85
|
async getMinRateLimit() {
|
86
86
|
const minRate = await this.contract.minMembershipRateLimit();
|
87
|
-
return
|
87
|
+
return minRate.toNumber();
|
88
88
|
}
|
89
89
|
/**
|
90
90
|
* Gets the maximum allowed rate limit from the contract
|
@@ -92,7 +92,7 @@ class RLNContract {
|
|
92
92
|
*/
|
93
93
|
async getMaxRateLimit() {
|
94
94
|
const maxRate = await this.contract.maxMembershipRateLimit();
|
95
|
-
return
|
95
|
+
return maxRate.toNumber();
|
96
96
|
}
|
97
97
|
/**
|
98
98
|
* Gets the maximum total rate limit across all memberships
|
@@ -300,13 +300,13 @@ class RLNContract {
|
|
300
300
|
`and rate limit ${decodedData.membershipRateLimit}`);
|
301
301
|
const network = await this.contract.provider.getNetwork();
|
302
302
|
const address = this.contract.address;
|
303
|
-
const membershipId = decodedData.index
|
303
|
+
const membershipId = Number(decodedData.index);
|
304
304
|
return {
|
305
305
|
identity,
|
306
306
|
membership: {
|
307
307
|
address,
|
308
|
-
treeIndex:
|
309
|
-
chainId: network.chainId
|
308
|
+
treeIndex: membershipId,
|
309
|
+
chainId: network.chainId,
|
310
310
|
rateLimit: decodedData.membershipRateLimit.toNumber()
|
311
311
|
}
|
312
312
|
};
|
@@ -380,13 +380,13 @@ class RLNContract {
|
|
380
380
|
`Rate limit: ${decodedData.membershipRateLimit}, Erased ${idCommitmentsToErase.length} commitments`);
|
381
381
|
const network = await this.contract.provider.getNetwork();
|
382
382
|
const address = this.contract.address;
|
383
|
-
const membershipId = decodedData.index.
|
383
|
+
const membershipId = BigNumber.from(decodedData.index).toNumber();
|
384
384
|
return {
|
385
385
|
identity,
|
386
386
|
membership: {
|
387
387
|
address,
|
388
|
-
treeIndex:
|
389
|
-
chainId: network.chainId
|
388
|
+
treeIndex: membershipId,
|
389
|
+
chainId: network.chainId,
|
390
390
|
rateLimit: decodedData.membershipRateLimit.toNumber()
|
391
391
|
}
|
392
392
|
};
|
@@ -25,15 +25,6 @@ class IdentityCredential {
|
|
25
25
|
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
26
26
|
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
27
27
|
}
|
28
|
-
toJSON() {
|
29
|
-
return [
|
30
|
-
Array.from(this.IDTrapdoor),
|
31
|
-
Array.from(this.IDNullifier),
|
32
|
-
Array.from(this.IDSecretHash),
|
33
|
-
Array.from(this.IDCommitment),
|
34
|
-
this.IDCommitmentBigInt.toString()
|
35
|
-
];
|
36
|
-
}
|
37
28
|
}
|
38
29
|
|
39
30
|
export { IdentityCredential };
|
@@ -17,7 +17,6 @@ import { Logger } from '../../../utils/dist/logger/index.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 { IdentityCredential } from '../identity.js';
|
21
20
|
import { buildBigIntFromUint8Array } from '../utils/bytes.js';
|
22
21
|
import { keccak256Checksum, decryptEipKeystore } from './cipher.js';
|
23
22
|
import { isKeystoreValid, isCredentialValid } from './schema_validator.js';
|
@@ -165,15 +164,15 @@ class Keystore {
|
|
165
164
|
try {
|
166
165
|
const str = bytesToUtf8(bytes);
|
167
166
|
const obj = JSON.parse(str);
|
168
|
-
//
|
169
|
-
const [idTrapdoor, idNullifier, idSecretHash, idCommitment] = _.get(obj, "identityCredential", []);
|
170
|
-
const idTrapdoorArray = new Uint8Array(idTrapdoor || []);
|
171
|
-
const idNullifierArray = new Uint8Array(idNullifier || []);
|
172
|
-
const idSecretHashArray = new Uint8Array(idSecretHash || []);
|
173
|
-
const idCommitmentArray = new Uint8Array(idCommitment || []);
|
174
|
-
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitmentArray);
|
167
|
+
// TODO: add runtime validation of nwaku credentials
|
175
168
|
return {
|
176
|
-
identity:
|
169
|
+
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", []))
|
175
|
+
},
|
177
176
|
membership: {
|
178
177
|
treeIndex: _.get(obj, "treeIndex"),
|
179
178
|
chainId: _.get(obj, "membershipContract.chainId"),
|
@@ -187,6 +186,17 @@ class Keystore {
|
|
187
186
|
return;
|
188
187
|
}
|
189
188
|
}
|
189
|
+
static fromArraylikeToBytes(obj) {
|
190
|
+
const bytes = [];
|
191
|
+
let index = 0;
|
192
|
+
let lastElement = obj[index];
|
193
|
+
while (lastElement !== undefined) {
|
194
|
+
bytes.push(lastElement);
|
195
|
+
index += 1;
|
196
|
+
lastElement = obj[index];
|
197
|
+
}
|
198
|
+
return new Uint8Array(bytes);
|
199
|
+
}
|
190
200
|
// follows nwaku implementation
|
191
201
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
192
202
|
static computeMembershipHash(info) {
|
@@ -197,12 +207,12 @@ class Keystore {
|
|
197
207
|
static fromIdentityToBytes(options) {
|
198
208
|
return utf8ToBytes(JSON.stringify({
|
199
209
|
treeIndex: options.membership.treeIndex,
|
200
|
-
identityCredential:
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
210
|
+
identityCredential: {
|
211
|
+
idCommitment: options.identity.IDCommitment,
|
212
|
+
idNullifier: options.identity.IDNullifier,
|
213
|
+
idSecretHash: options.identity.IDSecretHash,
|
214
|
+
idTrapdoor: options.identity.IDTrapdoor
|
215
|
+
},
|
206
216
|
membershipContract: {
|
207
217
|
chainId: options.membership.chainId,
|
208
218
|
address: options.membership.address
|
@@ -106,7 +106,7 @@ class RLNInstance {
|
|
106
106
|
this.starting = true;
|
107
107
|
try {
|
108
108
|
const { credentials, keystore } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
109
|
-
const { signer, address
|
109
|
+
const { signer, address } = await this.determineStartOptions(options, credentials);
|
110
110
|
if (keystore) {
|
111
111
|
this.keystore = keystore;
|
112
112
|
}
|
@@ -115,7 +115,7 @@ class RLNInstance {
|
|
115
115
|
this._contract = await RLNContract.init(this, {
|
116
116
|
address: address,
|
117
117
|
signer: signer,
|
118
|
-
rateLimit: rateLimit ?? this.zerokit.getRateLimit
|
118
|
+
rateLimit: options.rateLimit ?? this.zerokit.getRateLimit
|
119
119
|
});
|
120
120
|
this.started = true;
|
121
121
|
}
|
@@ -132,7 +132,7 @@ class RLNInstance {
|
|
132
132
|
chainId = LINEA_CONTRACT.chainId;
|
133
133
|
}
|
134
134
|
const signer = options.signer || (await extractMetaMaskSigner());
|
135
|
-
const currentChainId =
|
135
|
+
const currentChainId = await signer.getChainId();
|
136
136
|
if (chainId && chainId !== currentChainId) {
|
137
137
|
throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
|
138
138
|
}
|
@@ -204,7 +204,7 @@ class RLNInstance {
|
|
204
204
|
}
|
205
205
|
const chainId = credentials.membership.chainId;
|
206
206
|
const network = await this._contract.provider.getNetwork();
|
207
|
-
const currentChainId = network.chainId
|
207
|
+
const currentChainId = network.chainId;
|
208
208
|
if (chainId !== currentChainId) {
|
209
209
|
throw Error(`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`);
|
210
210
|
}
|