@waku/rln 0.1.6-b53ba62.0 → 0.1.6-b58de3a.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 +13 -8
- package/bundle/packages/rln/dist/identity.js +2 -2
- package/bundle/packages/rln/dist/keystore/keystore.js +16 -10
- package/bundle/packages/rln/dist/message.js +11 -0
- package/bundle/packages/rln/dist/utils/bytes.js +3 -12
- 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 +13 -8
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.js +2 -2
- package/dist/identity.js.map +1 -1
- package/dist/keystore/keystore.js +16 -10
- package/dist/keystore/keystore.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 -6
- package/dist/utils/bytes.js +2 -11
- 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 +9 -0
- package/src/contract/rln_base_contract.ts +19 -5
- package/src/credentials_manager.ts +21 -8
- package/src/identity.ts +2 -2
- package/src/keystore/keystore.ts +36 -16
- package/src/message.ts +7 -4
- package/src/utils/bytes.ts +5 -11
- package/src/utils/index.ts +1 -1
package/src/identity.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { buildBigIntFromUint8ArrayLE } from "./utils/index.js";
|
2
2
|
|
3
3
|
export class IdentityCredential {
|
4
4
|
public constructor(
|
@@ -18,7 +18,7 @@ export class IdentityCredential {
|
|
18
18
|
const idNullifier = memKeys.subarray(32, 64);
|
19
19
|
const idSecretHash = memKeys.subarray(64, 96);
|
20
20
|
const idCommitment = memKeys.subarray(96, 128);
|
21
|
-
const idCommitmentBigInt =
|
21
|
+
const idCommitmentBigInt = buildBigIntFromUint8ArrayLE(idCommitment);
|
22
22
|
|
23
23
|
return new IdentityCredential(
|
24
24
|
idTrapdoor,
|
package/src/keystore/keystore.ts
CHANGED
@@ -14,7 +14,7 @@ import {
|
|
14
14
|
import _ from "lodash";
|
15
15
|
import { v4 as uuidV4 } from "uuid";
|
16
16
|
|
17
|
-
import {
|
17
|
+
import { buildBigIntFromUint8ArrayLE } from "../utils/bytes.js";
|
18
18
|
|
19
19
|
import { decryptEipKeystore, keccak256Checksum } from "./cipher.js";
|
20
20
|
import { isCredentialValid, isKeystoreValid } from "./schema_validator.js";
|
@@ -246,6 +246,9 @@ export class Keystore {
|
|
246
246
|
private static fromBytesToIdentity(
|
247
247
|
bytes: Uint8Array
|
248
248
|
): undefined | KeystoreEntity {
|
249
|
+
function fromLittleEndian(bytes: Uint8Array): Uint8Array {
|
250
|
+
return new Uint8Array(bytes).reverse();
|
251
|
+
}
|
249
252
|
try {
|
250
253
|
const str = bytesToUtf8(bytes);
|
251
254
|
const obj = JSON.parse(str);
|
@@ -253,22 +256,32 @@ export class Keystore {
|
|
253
256
|
// TODO: add runtime validation of nwaku credentials
|
254
257
|
return {
|
255
258
|
identity: {
|
256
|
-
IDCommitment:
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
_.get(obj, "identityCredential.idTrapdoor", [])
|
259
|
+
IDCommitment: fromLittleEndian(
|
260
|
+
Keystore.fromArraylikeToBytes(
|
261
|
+
_.get(obj, "identityCredential.idCommitment", [])
|
262
|
+
)
|
261
263
|
),
|
262
|
-
|
263
|
-
|
264
|
+
IDTrapdoor: fromLittleEndian(
|
265
|
+
Keystore.fromArraylikeToBytes(
|
266
|
+
_.get(obj, "identityCredential.idTrapdoor", [])
|
267
|
+
)
|
264
268
|
),
|
265
|
-
|
269
|
+
IDNullifier: fromLittleEndian(
|
266
270
|
Keystore.fromArraylikeToBytes(
|
267
|
-
_.get(obj, "identityCredential.
|
271
|
+
_.get(obj, "identityCredential.idNullifier", [])
|
268
272
|
)
|
269
273
|
),
|
270
|
-
|
271
|
-
|
274
|
+
IDCommitmentBigInt: buildBigIntFromUint8ArrayLE(
|
275
|
+
fromLittleEndian(
|
276
|
+
Keystore.fromArraylikeToBytes(
|
277
|
+
_.get(obj, "identityCredential.idCommitment", [])
|
278
|
+
)
|
279
|
+
)
|
280
|
+
),
|
281
|
+
IDSecretHash: fromLittleEndian(
|
282
|
+
Keystore.fromArraylikeToBytes(
|
283
|
+
_.get(obj, "identityCredential.idSecretHash", [])
|
284
|
+
)
|
272
285
|
)
|
273
286
|
},
|
274
287
|
membership: {
|
@@ -321,14 +334,21 @@ export class Keystore {
|
|
321
334
|
// follows nwaku implementation
|
322
335
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L98
|
323
336
|
private static fromIdentityToBytes(options: KeystoreEntity): Uint8Array {
|
337
|
+
function toLittleEndian(bytes: Uint8Array): Uint8Array {
|
338
|
+
return new Uint8Array(bytes).reverse();
|
339
|
+
}
|
324
340
|
return utf8ToBytes(
|
325
341
|
JSON.stringify({
|
326
342
|
treeIndex: options.membership.treeIndex,
|
327
343
|
identityCredential: {
|
328
|
-
idCommitment: Array.from(
|
329
|
-
|
330
|
-
|
331
|
-
|
344
|
+
idCommitment: Array.from(
|
345
|
+
toLittleEndian(options.identity.IDCommitment)
|
346
|
+
),
|
347
|
+
idNullifier: Array.from(toLittleEndian(options.identity.IDNullifier)),
|
348
|
+
idSecretHash: Array.from(
|
349
|
+
toLittleEndian(options.identity.IDSecretHash)
|
350
|
+
),
|
351
|
+
idTrapdoor: Array.from(toLittleEndian(options.identity.IDTrapdoor))
|
332
352
|
},
|
333
353
|
membershipContract: {
|
334
354
|
chainId: options.membership.chainId,
|
package/src/message.ts
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
import { message } from "@waku/core";
|
1
2
|
import type {
|
2
3
|
IDecodedMessage,
|
3
4
|
IMessage,
|
4
|
-
IRateLimitProof
|
5
|
+
IRateLimitProof,
|
6
|
+
IRlnMessage
|
5
7
|
} from "@waku/interfaces";
|
6
8
|
import * as utils from "@waku/utils/bytes";
|
7
9
|
|
@@ -13,12 +15,13 @@ export function toRLNSignal(contentTopic: string, msg: IMessage): Uint8Array {
|
|
13
15
|
return new Uint8Array([...(msg.payload ?? []), ...contentTopicBytes]);
|
14
16
|
}
|
15
17
|
|
16
|
-
export class RlnMessage<T extends IDecodedMessage> implements
|
18
|
+
export class RlnMessage<T extends IDecodedMessage> implements IRlnMessage {
|
17
19
|
public pubsubTopic = "";
|
20
|
+
public version = message.version_0.Version;
|
18
21
|
|
19
22
|
public constructor(
|
20
|
-
|
21
|
-
|
23
|
+
private rlnInstance: RLNInstance,
|
24
|
+
private msg: T,
|
22
25
|
public rateLimitProof: IRateLimitProof | undefined
|
23
26
|
) {}
|
24
27
|
|
package/src/utils/bytes.ts
CHANGED
@@ -56,17 +56,11 @@ export function writeUIntLE(
|
|
56
56
|
return buf;
|
57
57
|
}
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
*
|
62
|
-
|
63
|
-
|
64
|
-
export function buildBigIntFromUint8Array(array: Uint8Array): bigint {
|
65
|
-
let hex = "";
|
66
|
-
for (let i = array.length - 1; i >= 0; i--) {
|
67
|
-
hex += array[i].toString(16).padStart(2, "0");
|
68
|
-
}
|
69
|
-
return BigInt("0x" + hex);
|
59
|
+
export function buildBigIntFromUint8ArrayLE(bytes: Uint8Array): bigint {
|
60
|
+
return bytes.reduce(
|
61
|
+
(acc, byte, i) => acc + BigInt(byte) * (1n << (8n * BigInt(i))),
|
62
|
+
0n
|
63
|
+
);
|
70
64
|
}
|
71
65
|
|
72
66
|
/**
|
package/src/utils/index.ts
CHANGED