@waku/rln 0.1.6-2ce706d.0 → 0.1.6-34d4730.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/rln/dist/contract/constants.js +1 -7
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +5 -10
- package/bundle/packages/rln/dist/credentials_manager.js +14 -16
- package/bundle/packages/rln/dist/identity.js +7 -37
- package/bundle/packages/rln/dist/keystore/keystore.js +11 -15
- package/bundle/packages/rln/dist/utils/bytes.js +16 -14
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/constants.d.ts +0 -6
- package/dist/contract/constants.js +0 -6
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_base_contract.js +5 -10
- package/dist/contract/rln_base_contract.js.map +1 -1
- 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/credentials_manager.js +14 -16
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.d.ts +2 -11
- package/dist/identity.js +6 -23
- package/dist/identity.js.map +1 -1
- package/dist/keystore/keystore.js +11 -15
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/utils/bytes.d.ts +6 -2
- package/dist/utils/bytes.js +15 -13
- package/dist/utils/bytes.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/package.json +1 -1
- package/src/contract/constants.ts +0 -9
- package/src/contract/rln_base_contract.ts +13 -12
- package/src/contract/test-utils.ts +179 -0
- package/src/credentials_manager.ts +21 -27
- package/src/identity.ts +6 -32
- package/src/keystore/keystore.ts +24 -28
- package/src/utils/bytes.ts +25 -21
- package/src/utils/index.ts +1 -1
package/bundle/_virtual/utils.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {
|
1
|
+
var utils = {};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __exports };
|
@@ -1,3 +1,3 @@
|
|
1
|
-
var utils = {};
|
1
|
+
var utils = {exports: {}};
|
2
2
|
|
3
|
-
export { utils as
|
3
|
+
export { utils as __module };
|
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 {
|
4
|
+
export { 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/utils.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/utils.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/utils.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/utils.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/utils.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/utils.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/utils.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/utils.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/utils2.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/utils.js';
|
8
8
|
|
9
9
|
utils.exports;
|
10
10
|
|
@@ -22,12 +22,6 @@ 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");
|
31
25
|
const DEFAULT_RATE_LIMIT = RATE_LIMIT_PARAMS.MAX_RATE;
|
32
26
|
|
33
|
-
export {
|
27
|
+
export { DEFAULT_RATE_LIMIT, LINEA_CONTRACT, RATE_LIMIT_PARAMS, RATE_LIMIT_TIERS };
|
@@ -13,7 +13,6 @@ 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
15
|
import { Logger } from '../../../utils/dist/logger/index.js';
|
16
|
-
import { IdentityCredential } from '../identity.js';
|
17
16
|
import { RLN_ABI } from './abi.js';
|
18
17
|
import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './constants.js';
|
19
18
|
import { MembershipState } from './types.js';
|
@@ -67,8 +66,7 @@ class RLNBaseContract {
|
|
67
66
|
const instance = new RLNBaseContract(options);
|
68
67
|
const [min, max] = await Promise.all([
|
69
68
|
instance.contract.minMembershipRateLimit(),
|
70
|
-
instance.contract.maxMembershipRateLimit()
|
71
|
-
instance.contract.Q()
|
69
|
+
instance.contract.maxMembershipRateLimit()
|
72
70
|
]);
|
73
71
|
instance.minRateLimit = BigNumber.from(min).toNumber();
|
74
72
|
instance.maxRateLimit = BigNumber.from(max).toNumber();
|
@@ -342,9 +340,8 @@ class RLNBaseContract {
|
|
342
340
|
async registerWithIdentity(identity) {
|
343
341
|
try {
|
344
342
|
log.info(`Registering identity with rate limit: ${this.rateLimit} messages/epoch`);
|
345
|
-
const idCommitmentBigInt = IdentityCredential.getIdCommitmentBigInt(identity.IDCommitment);
|
346
343
|
// Check if the ID commitment is already registered
|
347
|
-
const existingIndex = await this.getMemberIndex(
|
344
|
+
const existingIndex = await this.getMemberIndex(identity.IDCommitmentBigInt);
|
348
345
|
if (existingIndex) {
|
349
346
|
throw new Error(`ID commitment is already registered with index ${existingIndex}`);
|
350
347
|
}
|
@@ -353,11 +350,9 @@ class RLNBaseContract {
|
|
353
350
|
if (remainingRateLimit < this.rateLimit) {
|
354
351
|
throw new Error(`Not enough remaining rate limit. Requested: ${this.rateLimit}, Available: ${remainingRateLimit}`);
|
355
352
|
}
|
356
|
-
const estimatedGas = await this.contract.estimateGas.register(
|
353
|
+
const estimatedGas = await this.contract.estimateGas.register(identity.IDCommitmentBigInt, this.rateLimit, []);
|
357
354
|
const gasLimit = estimatedGas.add(10000);
|
358
|
-
const txRegisterResponse = await this.contract.register(
|
359
|
-
gasLimit
|
360
|
-
});
|
355
|
+
const txRegisterResponse = await this.contract.register(identity.IDCommitmentBigInt, this.rateLimit, [], { gasLimit });
|
361
356
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
362
357
|
if (txRegisterReceipt.status === 0) {
|
363
358
|
throw new Error("Transaction failed on-chain");
|
@@ -419,7 +414,7 @@ class RLNBaseContract {
|
|
419
414
|
async registerWithPermitAndErase(identity, permit, idCommitmentsToErase) {
|
420
415
|
try {
|
421
416
|
log.info(`Registering identity with permit and rate limit: ${this.rateLimit} messages/epoch`);
|
422
|
-
const txRegisterResponse = await this.contract.registerWithPermit(permit.owner, permit.deadline, permit.v, permit.r, permit.s,
|
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)));
|
423
418
|
const txRegisterReceipt = await txRegisterResponse.wait();
|
424
419
|
const memberRegistered = txRegisterReceipt.events?.find((event) => event.event === "MembershipRegistered");
|
425
420
|
if (!memberRegistered || !memberRegistered.args) {
|
@@ -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/
|
2
|
+
import { sha256 } from '../../../node_modules/@noble/hashes/esm/sha256.js';
|
3
3
|
import '../../interfaces/dist/protocols.js';
|
4
4
|
import '../../interfaces/dist/connection_manager.js';
|
5
5
|
import '../../interfaces/dist/health_indicator.js';
|
@@ -20,7 +20,7 @@ import { RLNBaseContract } from './contract/rln_base_contract.js';
|
|
20
20
|
import { IdentityCredential } from './identity.js';
|
21
21
|
import { Keystore } from './keystore/keystore.js';
|
22
22
|
import { extractMetaMaskSigner } from './utils/metamask.js';
|
23
|
-
import {
|
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 =
|
98
|
+
identity = this.generateSeededIdentityCredential(options.signature);
|
99
99
|
}
|
100
100
|
}
|
101
101
|
if (!identity) {
|
@@ -191,26 +191,24 @@ class RLNCredentialsManager {
|
|
191
191
|
* @param seed A string seed to generate the identity from
|
192
192
|
* @returns IdentityCredential
|
193
193
|
*/
|
194
|
-
|
194
|
+
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
|
202
|
-
const
|
203
|
-
|
204
|
-
const
|
205
|
-
const
|
206
|
-
//
|
207
|
-
|
208
|
-
|
209
|
-
const
|
210
|
-
const idSecretHashLE = switchEndianness(idSecretHashBE);
|
211
|
-
const idCommitmentLE = switchEndianness(idCommitmentBE);
|
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);
|
212
210
|
log.info("Successfully generated identity credential");
|
213
|
-
return new IdentityCredential(
|
211
|
+
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
214
212
|
}
|
215
213
|
}
|
216
214
|
|
@@ -1,35 +1,18 @@
|
|
1
|
-
import '
|
2
|
-
import '
|
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/index.js';
|
16
|
-
import { DEFAULT_Q } from './contract/constants.js';
|
17
|
-
import { buildBigIntFromUint8ArrayBE } from './utils/bytes.js';
|
1
|
+
import { buildBigIntFromUint8Array } from './utils/bytes.js';
|
2
|
+
import './utils/epoch.js';
|
18
3
|
|
19
|
-
const log = new Logger("waku:rln:identity");
|
20
4
|
class IdentityCredential {
|
21
5
|
IDTrapdoor;
|
22
6
|
IDNullifier;
|
23
7
|
IDSecretHash;
|
24
8
|
IDCommitment;
|
25
|
-
|
26
|
-
|
27
|
-
*/
|
28
|
-
constructor(IDTrapdoor, IDNullifier, IDSecretHash, IDCommitment) {
|
9
|
+
IDCommitmentBigInt;
|
10
|
+
constructor(IDTrapdoor, IDNullifier, IDSecretHash, IDCommitment, IDCommitmentBigInt) {
|
29
11
|
this.IDTrapdoor = IDTrapdoor;
|
30
12
|
this.IDNullifier = IDNullifier;
|
31
13
|
this.IDSecretHash = IDSecretHash;
|
32
14
|
this.IDCommitment = IDCommitment;
|
15
|
+
this.IDCommitmentBigInt = IDCommitmentBigInt;
|
33
16
|
}
|
34
17
|
static fromBytes(memKeys) {
|
35
18
|
if (memKeys.length < 128) {
|
@@ -39,21 +22,8 @@ class IdentityCredential {
|
|
39
22
|
const idNullifier = memKeys.subarray(32, 64);
|
40
23
|
const idSecretHash = memKeys.subarray(64, 96);
|
41
24
|
const idCommitment = memKeys.subarray(96, 128);
|
42
|
-
|
43
|
-
|
44
|
-
/**
|
45
|
-
* Converts an ID commitment from bytes to a BigInt, normalizing it against a limit if needed
|
46
|
-
* @param bytes The ID commitment bytes to convert
|
47
|
-
* @param limit Optional limit to normalize against (Q value)
|
48
|
-
* @returns The ID commitment as a BigInt
|
49
|
-
*/
|
50
|
-
static getIdCommitmentBigInt(bytes, limit = DEFAULT_Q) {
|
51
|
-
let idCommitmentBigIntBE = buildBigIntFromUint8ArrayBE(bytes);
|
52
|
-
if (limit && idCommitmentBigIntBE >= limit) {
|
53
|
-
log.warn(`ID commitment is greater than Q, reducing it by Q: ${idCommitmentBigIntBE} % ${limit}`);
|
54
|
-
idCommitmentBigIntBE = idCommitmentBigIntBE % limit;
|
55
|
-
}
|
56
|
-
return idCommitmentBigIntBE;
|
25
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
26
|
+
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
57
27
|
}
|
58
28
|
}
|
59
29
|
|
@@ -17,6 +17,7 @@ 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 { buildBigIntFromUint8Array } from '../utils/bytes.js';
|
20
21
|
import { keccak256Checksum, decryptEipKeystore } from './cipher.js';
|
21
22
|
import { isKeystoreValid, isCredentialValid } from './schema_validator.js';
|
22
23
|
import { __exports as lib } from '../../../../_virtual/index.js';
|
@@ -163,16 +164,14 @@ class Keystore {
|
|
163
164
|
try {
|
164
165
|
const str = bytesToUtf8(bytes);
|
165
166
|
const obj = JSON.parse(str);
|
166
|
-
|
167
|
-
const idTrapdoorLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", []));
|
168
|
-
const idNullifierLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", []));
|
169
|
-
const idSecretHashLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []));
|
167
|
+
// TODO: add runtime validation of nwaku credentials
|
170
168
|
return {
|
171
169
|
identity: {
|
172
|
-
IDCommitment:
|
173
|
-
IDTrapdoor:
|
174
|
-
IDNullifier:
|
175
|
-
|
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", []))
|
176
175
|
},
|
177
176
|
membership: {
|
178
177
|
treeIndex: _.get(obj, "treeIndex"),
|
@@ -209,16 +208,13 @@ class Keystore {
|
|
209
208
|
// follows nwaku implementation
|
210
209
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L98
|
211
210
|
static fromIdentityToBytes(options) {
|
212
|
-
function toLittleEndian(bytes) {
|
213
|
-
return new Uint8Array(bytes).reverse();
|
214
|
-
}
|
215
211
|
return utf8ToBytes(JSON.stringify({
|
216
212
|
treeIndex: options.membership.treeIndex,
|
217
213
|
identityCredential: {
|
218
|
-
idCommitment: Array.from(
|
219
|
-
idNullifier: Array.from(
|
220
|
-
idSecretHash: Array.from(
|
221
|
-
idTrapdoor: Array.from(
|
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)
|
222
218
|
},
|
223
219
|
membershipContract: {
|
224
220
|
chainId: options.membership.chainId,
|
@@ -16,12 +16,12 @@ function concatenate(...input) {
|
|
16
16
|
}
|
17
17
|
return result;
|
18
18
|
}
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
// Adapted from https://github.com/feross/buffer
|
20
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
21
|
+
if (value > max || value < min)
|
22
|
+
throw new RangeError('"value" argument is out of bounds');
|
23
|
+
if (offset + ext > buf.length)
|
24
|
+
throw new RangeError("Index out of range");
|
25
25
|
}
|
26
26
|
function writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
27
27
|
value = +value;
|
@@ -39,6 +39,15 @@ function writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
|
39
39
|
}
|
40
40
|
return buf;
|
41
41
|
}
|
42
|
+
/**
|
43
|
+
* Transforms Uint8Array into BigInt
|
44
|
+
* @param array: Uint8Array
|
45
|
+
* @returns BigInt
|
46
|
+
*/
|
47
|
+
function buildBigIntFromUint8Array(array, byteOffset = 0) {
|
48
|
+
const dataView = new DataView(array.buffer);
|
49
|
+
return dataView.getBigUint64(byteOffset, true);
|
50
|
+
}
|
42
51
|
/**
|
43
52
|
* Fills with zeros to set length
|
44
53
|
* @param array little endian Uint8Array
|
@@ -52,12 +61,5 @@ function zeroPadLE(array, length) {
|
|
52
61
|
}
|
53
62
|
return result;
|
54
63
|
}
|
55
|
-
// Adapted from https://github.com/feross/buffer
|
56
|
-
function checkInt(buf, value, offset, ext, max, min) {
|
57
|
-
if (value > max || value < min)
|
58
|
-
throw new RangeError('"value" argument is out of bounds');
|
59
|
-
if (offset + ext > buf.length)
|
60
|
-
throw new RangeError("Index out of range");
|
61
|
-
}
|
62
64
|
|
63
|
-
export {
|
65
|
+
export { buildBigIntFromUint8Array, concatenate, writeUIntLE, zeroPadLE };
|