@waku/rln 0.1.6-b53ba62.0 → 0.1.6-f7778a9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/_sha2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/hmac.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/pbkdf2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/scrypt.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha256.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha512.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/utils.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
- package/bundle/packages/core/dist/lib/message/version_0.js +1 -4
- package/bundle/packages/rln/dist/contract/constants.js +7 -1
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +12 -5
- package/bundle/packages/rln/dist/credentials_manager.js +11 -6
- package/bundle/packages/rln/dist/identity.js +1 -1
- package/bundle/packages/rln/dist/message.js +11 -0
- package/bundle/packages/rln/dist/utils/bytes.js +3 -6
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/constants.d.ts +6 -0
- package/dist/contract/constants.js +6 -0
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_base_contract.d.ts +6 -1
- package/dist/contract/rln_base_contract.js +12 -5
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/credentials_manager.js +11 -6
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/identity.js.map +1 -1
- package/dist/message.d.ts +5 -4
- package/dist/message.js +2 -0
- package/dist/message.js.map +1 -1
- package/dist/utils/bytes.d.ts +1 -1
- package/dist/utils/bytes.js +3 -6
- package/dist/utils/bytes.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +9 -0
- package/src/contract/rln_base_contract.ts +19 -5
- package/src/credentials_manager.ts +19 -6
- package/src/identity.ts +1 -1
- package/src/message.ts +7 -4
- package/src/utils/bytes.ts +6 -6
package/bundle/_virtual/utils.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {};
|
1
|
+
var utils = {exports: {}};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __module };
|
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {
|
1
|
+
var utils = {};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __exports };
|
package/bundle/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export { RLNDecoder, RLNEncoder } from './packages/rln/dist/codec.js';
|
2
2
|
export { RLN_ABI } from './packages/rln/dist/contract/abi.js';
|
3
3
|
export { RLNContract } from './packages/rln/dist/contract/rln_contract.js';
|
4
|
-
export { DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS } from './packages/rln/dist/contract/constants.js';
|
4
|
+
export { DEFAULT_Q, DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS } from './packages/rln/dist/contract/constants.js';
|
5
5
|
export { MembershipState } from './packages/rln/dist/contract/types.js';
|
6
6
|
export { RLNBaseContract } from './packages/rln/dist/contract/rln_base_contract.js';
|
7
7
|
export { createRLN } from './packages/rln/dist/create.js';
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { __exports as _sha2 } from '../../../../../../_virtual/_sha2.js';
|
2
2
|
import './_assert.js';
|
3
3
|
import './utils.js';
|
4
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
4
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
5
5
|
import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
|
6
6
|
|
7
7
|
Object.defineProperty(_sha2, "__esModule", { value: true });
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { __exports as hmac } from '../../../../../../_virtual/hmac.js';
|
2
2
|
import './_assert.js';
|
3
3
|
import './utils.js';
|
4
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
4
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
5
5
|
import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
|
6
6
|
|
7
7
|
(function (exports) {
|
@@ -2,7 +2,7 @@ import { __exports as pbkdf2$1 } from '../../../../../../_virtual/pbkdf22.js';
|
|
2
2
|
import './_assert.js';
|
3
3
|
import './hmac.js';
|
4
4
|
import './utils.js';
|
5
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
5
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
6
6
|
import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
|
7
7
|
import { __exports as hmac } from '../../../../../../_virtual/hmac.js';
|
8
8
|
|
@@ -3,7 +3,7 @@ import './_assert.js';
|
|
3
3
|
import './sha256.js';
|
4
4
|
import './pbkdf2.js';
|
5
5
|
import './utils.js';
|
6
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
6
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
7
7
|
import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
|
8
8
|
import { __exports as pbkdf2 } from '../../../../../../_virtual/pbkdf22.js';
|
9
9
|
import { __exports as sha256 } from '../../../../../../_virtual/sha2562.js';
|
@@ -2,7 +2,7 @@ import { __exports as sha256 } from '../../../../../../_virtual/sha2562.js';
|
|
2
2
|
import './_sha2.js';
|
3
3
|
import './utils.js';
|
4
4
|
import { __exports as _sha2 } from '../../../../../../_virtual/_sha2.js';
|
5
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
5
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
6
6
|
|
7
7
|
Object.defineProperty(sha256, "__esModule", { value: true });
|
8
8
|
sha256.sha224 = sha256.sha256 = void 0;
|
@@ -4,7 +4,7 @@ import './_u64.js';
|
|
4
4
|
import './utils.js';
|
5
5
|
import { __exports as _u64 } from '../../../../../../_virtual/_u64.js';
|
6
6
|
import { __exports as _sha2 } from '../../../../../../_virtual/_sha2.js';
|
7
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
7
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
8
8
|
|
9
9
|
Object.defineProperty(sha512, "__esModule", { value: true });
|
10
10
|
sha512.sha384 = sha512.sha512_256 = sha512.sha512_224 = sha512.sha512 = sha512.SHA512 = void 0;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { __exports as utils } from '../../../../../../_virtual/
|
1
|
+
import { __exports as utils } from '../../../../../../_virtual/utils2.js';
|
2
2
|
import './cryptoBrowser.js';
|
3
3
|
import { __exports as cryptoBrowser } from '../../../../../../_virtual/cryptoBrowser.js';
|
4
4
|
|
package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { __exports as random } from '../../../../../_virtual/random.js';
|
2
2
|
import '../@noble/hashes/utils.js';
|
3
|
-
import { __exports as utils } from '../../../../../_virtual/
|
3
|
+
import { __exports as utils } from '../../../../../_virtual/utils2.js';
|
4
4
|
|
5
5
|
Object.defineProperty(random, "__esModule", { value: true });
|
6
6
|
random.getRandomBytes = random.getRandomBytesSync = void 0;
|
package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import { commonjsGlobal } from '../../../../../_virtual/_commonjsHelpers.js';
|
2
2
|
import { commonjsRequire } from '../../../../../_virtual/_commonjs-dynamic-modules.js';
|
3
|
-
import { __module as utils } from '../../../../../_virtual/
|
3
|
+
import { __module as utils } from '../../../../../_virtual/utils.js';
|
4
4
|
import '../@noble/hashes/_assert.js';
|
5
5
|
import '../@noble/hashes/utils.js';
|
6
6
|
import { __exports as _assert } from '../../../../../_virtual/_assert.js';
|
7
|
-
import { __exports as utils$1 } from '../../../../../_virtual/
|
7
|
+
import { __exports as utils$1 } from '../../../../../_virtual/utils2.js';
|
8
8
|
|
9
9
|
utils.exports;
|
10
10
|
|
@@ -29,9 +29,6 @@ class DecodedMessage {
|
|
29
29
|
get contentTopic() {
|
30
30
|
return this.proto.contentTopic;
|
31
31
|
}
|
32
|
-
get _rawTimestamp() {
|
33
|
-
return this.proto.timestamp;
|
34
|
-
}
|
35
32
|
get timestamp() {
|
36
33
|
// In the case we receive a value that is bigger than JS's max number,
|
37
34
|
// we catch the error and return undefined.
|
@@ -53,7 +50,7 @@ class DecodedMessage {
|
|
53
50
|
get version() {
|
54
51
|
// https://rfc.vac.dev/spec/14/
|
55
52
|
// > If omitted, the value SHOULD be interpreted as version 0.
|
56
|
-
return this.proto.version ??
|
53
|
+
return this.proto.version ?? Version;
|
57
54
|
}
|
58
55
|
get rateLimitProof() {
|
59
56
|
return this.proto.rateLimitProof;
|
@@ -22,6 +22,12 @@ const RATE_LIMIT_PARAMS = {
|
|
22
22
|
MAX_TOTAL_RATE: 160_000, // Maximum total rate limit across all memberships
|
23
23
|
EPOCH_LENGTH: 600 // Epoch length in seconds (10 minutes)
|
24
24
|
};
|
25
|
+
/**
|
26
|
+
* Default Q value for the RLN contract
|
27
|
+
* This is the upper bound for the ID commitment
|
28
|
+
* @see https://github.com/waku-org/specs/blob/master/standards/core/rln-contract.md#implementation-suggestions
|
29
|
+
*/
|
30
|
+
const DEFAULT_Q = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
25
31
|
const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
|
26
32
|
|
27
|
-
export { DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS };
|
33
|
+
export { DEFAULT_Q, DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS };
|
@@ -14,7 +14,7 @@ import '../../../../node_modules/multiformats/dist/src/bases/identity.js';
|
|
14
14
|
import '../../../../node_modules/multiformats/dist/src/codecs/json.js';
|
15
15
|
import { Logger } from '../../../utils/dist/logger/index.js';
|
16
16
|
import { RLN_ABI } from './abi.js';
|
17
|
-
import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './constants.js';
|
17
|
+
import { DEFAULT_Q, DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './constants.js';
|
18
18
|
import { MembershipState } from './types.js';
|
19
19
|
import { Contract } from '../../../../node_modules/@ethersproject/contracts/lib.esm/index.js';
|
20
20
|
import { BigNumber } from '../../../../node_modules/@ethersproject/bignumber/lib.esm/bignumber.js';
|
@@ -26,6 +26,11 @@ class RLNBaseContract {
|
|
26
26
|
rateLimit;
|
27
27
|
minRateLimit;
|
28
28
|
maxRateLimit;
|
29
|
+
/**
|
30
|
+
* Default Q value for the RLN contract.
|
31
|
+
* @see https://github.com/waku-org/waku-rlnv2-contract/blob/b7e9a9b1bc69256a2a3076c1f099b50ce84e7eff/src/WakuRlnV2.sol#L25
|
32
|
+
*/
|
33
|
+
idCommitmentBigIntLimit = DEFAULT_Q;
|
29
34
|
_members = new Map();
|
30
35
|
_membersFilter;
|
31
36
|
_membershipErasedFilter;
|
@@ -64,12 +69,14 @@ class RLNBaseContract {
|
|
64
69
|
*/
|
65
70
|
static async create(options) {
|
66
71
|
const instance = new RLNBaseContract(options);
|
67
|
-
const [min, max] = await Promise.all([
|
72
|
+
const [min, max, idCommitmentBigIntLimit] = await Promise.all([
|
68
73
|
instance.contract.minMembershipRateLimit(),
|
69
|
-
instance.contract.maxMembershipRateLimit()
|
74
|
+
instance.contract.maxMembershipRateLimit(),
|
75
|
+
instance.contract.Q()
|
70
76
|
]);
|
71
77
|
instance.minRateLimit = BigNumber.from(min).toNumber();
|
72
78
|
instance.maxRateLimit = BigNumber.from(max).toNumber();
|
79
|
+
instance.idCommitmentBigIntLimit = BigInt(idCommitmentBigIntLimit.toString());
|
73
80
|
instance.validateRateLimit(instance.rateLimit);
|
74
81
|
return instance;
|
75
82
|
}
|
@@ -328,9 +335,9 @@ class RLNBaseContract {
|
|
328
335
|
}
|
329
336
|
return this.contract.register(idCommitmentBigInt, rateLimit, []);
|
330
337
|
}
|
331
|
-
async withdraw(token,
|
338
|
+
async withdraw(token, walletAddress) {
|
332
339
|
try {
|
333
|
-
const tx = await this.contract.withdraw(token,
|
340
|
+
const tx = await this.contract.withdraw(token, walletAddress);
|
334
341
|
await tx.wait();
|
335
342
|
}
|
336
343
|
catch (error) {
|
@@ -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) {
|
@@ -191,7 +191,7 @@ 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();
|
@@ -200,13 +200,18 @@ class RLNCredentialsManager {
|
|
200
200
|
// We use different context strings for each component to ensure they're different
|
201
201
|
const idTrapdoor = hmac(sha256, seedBytes, encoder.encode("IDTrapdoor"));
|
202
202
|
const idNullifier = hmac(sha256, seedBytes, encoder.encode("IDNullifier"));
|
203
|
-
// Generate IDSecretHash as a hash of IDTrapdoor and IDNullifier
|
204
203
|
const combinedBytes = new Uint8Array([...idTrapdoor, ...idNullifier]);
|
205
204
|
const idSecretHash = sha256(combinedBytes);
|
206
|
-
// Generate IDCommitment as a hash of IDSecretHash
|
207
205
|
const idCommitment = sha256(idSecretHash);
|
208
|
-
|
209
|
-
|
206
|
+
let idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
|
207
|
+
if (!this.contract) {
|
208
|
+
throw Error("RLN contract is not initialized");
|
209
|
+
}
|
210
|
+
const idCommitmentBigIntLimit = this.contract.idCommitmentBigIntLimit;
|
211
|
+
if (idCommitmentBigInt >= idCommitmentBigIntLimit) {
|
212
|
+
log.warn(`ID commitment is greater than Q, reducing it by Q(idCommitmentBigIntLimit): ${idCommitmentBigInt} % ${idCommitmentBigIntLimit}`);
|
213
|
+
idCommitmentBigInt = idCommitmentBigInt % idCommitmentBigIntLimit;
|
214
|
+
}
|
210
215
|
log.info("Successfully generated identity credential");
|
211
216
|
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
212
217
|
}
|
@@ -22,7 +22,7 @@ class IdentityCredential {
|
|
22
22
|
const idNullifier = memKeys.subarray(32, 64);
|
23
23
|
const idSecretHash = memKeys.subarray(64, 96);
|
24
24
|
const idCommitment = memKeys.subarray(96, 128);
|
25
|
-
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
|
25
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
26
26
|
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
27
27
|
}
|
28
28
|
}
|
@@ -1,4 +1,14 @@
|
|
1
|
+
import { Version } from '../../core/dist/lib/message/version_0.js';
|
2
|
+
import '../../core/dist/lib/filter/filter.js';
|
3
|
+
import '../../core/dist/lib/light_push/light_push.js';
|
4
|
+
import '../../core/dist/lib/store/store.js';
|
5
|
+
import '../../core/dist/lib/connection_manager/connection_manager.js';
|
6
|
+
import '../../interfaces/dist/protocols.js';
|
7
|
+
import '../../interfaces/dist/connection_manager.js';
|
8
|
+
import '../../interfaces/dist/health_indicator.js';
|
1
9
|
import { utf8ToBytes } from '../../utils/dist/bytes/index.js';
|
10
|
+
import '../../../node_modules/debug/src/browser.js';
|
11
|
+
import '../../core/dist/lib/metadata/metadata.js';
|
2
12
|
import { epochBytesToInt } from './utils/epoch.js';
|
3
13
|
|
4
14
|
function toRLNSignal(contentTopic, msg) {
|
@@ -10,6 +20,7 @@ class RlnMessage {
|
|
10
20
|
msg;
|
11
21
|
rateLimitProof;
|
12
22
|
pubsubTopic = "";
|
23
|
+
version = Version;
|
13
24
|
constructor(rlnInstance, msg, rateLimitProof) {
|
14
25
|
this.rlnInstance = rlnInstance;
|
15
26
|
this.msg = msg;
|
@@ -44,12 +44,9 @@ function writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
|
44
44
|
* @param array: Uint8Array
|
45
45
|
* @returns BigInt
|
46
46
|
*/
|
47
|
-
function buildBigIntFromUint8Array(array) {
|
48
|
-
|
49
|
-
|
50
|
-
hex += array[i].toString(16).padStart(2, "0");
|
51
|
-
}
|
52
|
-
return BigInt("0x" + hex);
|
47
|
+
function buildBigIntFromUint8Array(array, byteOffset = 0) {
|
48
|
+
const dataView = new DataView(array.buffer);
|
49
|
+
return dataView.getBigUint64(byteOffset, true);
|
53
50
|
}
|
54
51
|
/**
|
55
52
|
* Fills with zeros to set length
|