@waku/rln 0.1.6-b7e9b08.0 → 0.1.6-c8b7131.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 +2 -1
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
- package/bundle/node_modules/{@ethersproject/keccak256/node_modules/js-sha3 → js-sha3}/src/sha3.js +2 -2
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +0 -3
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +3 -3
- package/bundle/packages/core/dist/lib/filter/filter.js +0 -3
- package/bundle/packages/core/dist/lib/light_push/light_push.js +0 -3
- package/bundle/packages/core/dist/lib/message/version_0.js +1 -4
- package/bundle/packages/core/dist/lib/metadata/metadata.js +0 -3
- package/bundle/packages/core/dist/lib/store/store.js +3 -3
- package/bundle/packages/rln/dist/codec.js +3 -3
- package/bundle/packages/rln/dist/contract/constants.js +8 -1
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +138 -77
- package/bundle/packages/rln/dist/contract/rln_contract.js +5 -5
- package/bundle/packages/rln/dist/credentials_manager.js +28 -20
- package/bundle/packages/rln/dist/identity.js +8 -6
- package/bundle/packages/rln/dist/keystore/keystore.js +18 -14
- package/bundle/packages/rln/dist/message.js +11 -0
- package/bundle/packages/rln/dist/proof.js +2 -2
- package/bundle/packages/rln/dist/rln.js +3 -3
- package/bundle/packages/rln/dist/utils/bytes.js +103 -58
- package/bundle/packages/rln/dist/utils/epoch.js +3 -3
- package/bundle/packages/rln/dist/utils/hash.js +3 -3
- package/bundle/packages/rln/dist/zerokit.js +17 -17
- package/bundle/packages/utils/dist/common/sharding/index.js +4 -4
- 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/index.d.ts +1 -0
- package/dist/contract/index.js +1 -0
- package/dist/contract/index.js.map +1 -1
- package/dist/contract/rln_base_contract.d.ts +32 -22
- package/dist/contract/rln_base_contract.js +135 -74
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/rln_contract.js +2 -2
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/contract/types.d.ts +5 -0
- package/dist/contract/types.js.map +1 -1
- package/dist/credentials_manager.d.ts +4 -0
- package/dist/credentials_manager.js +26 -17
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.d.ts +5 -2
- package/dist/identity.js +8 -5
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.js +14 -10
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +2 -2
- package/dist/message.d.ts +5 -4
- package/dist/message.js +2 -0
- package/dist/message.js.map +1 -1
- package/dist/proof.js +2 -2
- package/dist/proof.js.map +1 -1
- package/dist/utils/bytes.d.ts +42 -20
- package/dist/utils/bytes.js +102 -57
- package/dist/utils/bytes.js.map +1 -1
- package/dist/utils/hash.js +5 -5
- package/dist/utils/hash.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/dist/zerokit.js +17 -17
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +9 -0
- package/src/contract/index.ts +1 -0
- package/src/contract/rln_base_contract.ts +177 -113
- package/src/contract/rln_contract.ts +5 -2
- package/src/contract/types.ts +5 -0
- package/src/credentials_manager.ts +47 -25
- package/src/identity.ts +11 -7
- package/src/index.ts +3 -1
- package/src/keystore/keystore.ts +34 -24
- package/src/keystore/types.ts +2 -2
- package/src/message.ts +7 -4
- package/src/proof.ts +2 -2
- package/src/utils/bytes.ts +118 -72
- package/src/utils/hash.ts +15 -5
- package/src/utils/index.ts +1 -6
- package/src/zerokit.ts +30 -22
- package/bundle/packages/utils/node_modules/@waku/interfaces/dist/connection_manager.js +0 -19
- package/bundle/packages/utils/node_modules/@waku/interfaces/dist/health_indicator.js +0 -12
- package/bundle/packages/utils/node_modules/@waku/interfaces/dist/protocols.js +0 -92
- package/dist/contract/test-utils.d.ts +0 -39
- package/dist/contract/test-utils.js +0 -118
- package/dist/contract/test-utils.js.map +0 -1
- package/src/contract/test-utils.ts +0 -179
- /package/bundle/packages/{utils/node_modules/@waku/interfaces → interfaces}/dist/constants.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/native.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/rng.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/stringify.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/uuid/dist/esm-browser/v4.js +0 -0
@@ -1,5 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import './utils/epoch.js';
|
1
|
+
import { BytesUtils } from './utils/bytes.js';
|
3
2
|
|
4
3
|
class IdentityCredential {
|
5
4
|
IDTrapdoor;
|
@@ -7,12 +6,16 @@ class IdentityCredential {
|
|
7
6
|
IDSecretHash;
|
8
7
|
IDCommitment;
|
9
8
|
IDCommitmentBigInt;
|
10
|
-
|
9
|
+
/**
|
10
|
+
* All variables are in little-endian format
|
11
|
+
*/
|
12
|
+
constructor(IDTrapdoor, IDNullifier, IDSecretHash, IDCommitment) {
|
11
13
|
this.IDTrapdoor = IDTrapdoor;
|
12
14
|
this.IDNullifier = IDNullifier;
|
13
15
|
this.IDSecretHash = IDSecretHash;
|
14
16
|
this.IDCommitment = IDCommitment;
|
15
|
-
this.IDCommitmentBigInt =
|
17
|
+
this.IDCommitmentBigInt =
|
18
|
+
BytesUtils.buildBigIntFromUint8ArrayBE(IDCommitment);
|
16
19
|
}
|
17
20
|
static fromBytes(memKeys) {
|
18
21
|
if (memKeys.length < 128) {
|
@@ -22,8 +25,7 @@ class IdentityCredential {
|
|
22
25
|
const idNullifier = memKeys.subarray(32, 64);
|
23
26
|
const idSecretHash = memKeys.subarray(64, 96);
|
24
27
|
const idCommitment = memKeys.subarray(96, 128);
|
25
|
-
|
26
|
-
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
28
|
+
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment);
|
27
29
|
}
|
28
30
|
}
|
29
31
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import '../../../../node_modules/@chainsafe/bls-keystore/lib/index.js';
|
2
|
-
import '../../../
|
3
|
-
import '../../../
|
4
|
-
import '../../../
|
2
|
+
import '../../../interfaces/dist/protocols.js';
|
3
|
+
import '../../../interfaces/dist/connection_manager.js';
|
4
|
+
import '../../../interfaces/dist/health_indicator.js';
|
5
5
|
import '../../../../node_modules/multiformats/dist/src/bases/base10.js';
|
6
6
|
import '../../../../node_modules/multiformats/dist/src/bases/base16.js';
|
7
7
|
import '../../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -17,11 +17,11 @@ 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 {
|
20
|
+
import { BytesUtils } from '../utils/bytes.js';
|
21
21
|
import { keccak256Checksum, decryptEipKeystore } from './cipher.js';
|
22
22
|
import { isKeystoreValid, isCredentialValid } from './schema_validator.js';
|
23
23
|
import { __exports as lib } from '../../../../_virtual/index.js';
|
24
|
-
import v4 from '
|
24
|
+
import v4 from '../../node_modules/uuid/dist/esm-browser/v4.js';
|
25
25
|
import { bytesToHex, utf8ToBytes } from '../../../../node_modules/@noble/hashes/esm/utils.js';
|
26
26
|
|
27
27
|
const log = new Logger("waku:rln:keystore");
|
@@ -164,14 +164,17 @@ class Keystore {
|
|
164
164
|
try {
|
165
165
|
const str = bytesToUtf8(bytes);
|
166
166
|
const obj = JSON.parse(str);
|
167
|
-
|
167
|
+
const idCommitmentLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", []));
|
168
|
+
const idTrapdoorLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", []));
|
169
|
+
const idNullifierLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", []));
|
170
|
+
const idSecretHashLE = Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []));
|
168
171
|
return {
|
169
172
|
identity: {
|
170
|
-
IDCommitment:
|
171
|
-
IDTrapdoor:
|
172
|
-
IDNullifier:
|
173
|
-
|
174
|
-
|
173
|
+
IDCommitment: idCommitmentLE,
|
174
|
+
IDTrapdoor: idTrapdoorLE,
|
175
|
+
IDNullifier: idNullifierLE,
|
176
|
+
IDSecretHash: idSecretHashLE,
|
177
|
+
IDCommitmentBigInt: BytesUtils.buildBigIntFromUint8ArrayBE(idCommitmentLE)
|
175
178
|
},
|
176
179
|
membership: {
|
177
180
|
treeIndex: _.get(obj, "treeIndex"),
|
@@ -207,13 +210,14 @@ class Keystore {
|
|
207
210
|
}
|
208
211
|
// follows nwaku implementation
|
209
212
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L98
|
213
|
+
// IdentityCredential is stored in Big Endian format => switch to Little Endian
|
210
214
|
static fromIdentityToBytes(options) {
|
211
215
|
return utf8ToBytes(JSON.stringify({
|
212
216
|
treeIndex: options.membership.treeIndex,
|
213
217
|
identityCredential: {
|
214
|
-
idCommitment: Array.from(options.identity.IDCommitment),
|
215
|
-
idNullifier: Array.from(options.identity.IDNullifier),
|
216
|
-
idSecretHash: Array.from(options.identity.IDSecretHash),
|
218
|
+
idCommitment: Array.from(BytesUtils.switchEndianness(options.identity.IDCommitment)),
|
219
|
+
idNullifier: Array.from(BytesUtils.switchEndianness(options.identity.IDNullifier)),
|
220
|
+
idSecretHash: Array.from(BytesUtils.switchEndianness(options.identity.IDSecretHash)),
|
217
221
|
idTrapdoor: Array.from(options.identity.IDTrapdoor)
|
218
222
|
},
|
219
223
|
membershipContract: {
|
@@ -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;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { BytesUtils } from './utils/bytes.js';
|
2
2
|
import { poseidonHash } from './utils/hash.js';
|
3
3
|
import './utils/epoch.js';
|
4
4
|
|
@@ -48,7 +48,7 @@ class Proof {
|
|
48
48
|
}
|
49
49
|
}
|
50
50
|
function proofToBytes(p) {
|
51
|
-
return concatenate(p.proof, p.merkleRoot, p.epoch, p.shareX, p.shareY, p.nullifier, p.rlnIdentifier);
|
51
|
+
return BytesUtils.concatenate(p.proof, p.merkleRoot, p.epoch, p.shareX, p.shareY, p.nullifier, p.rlnIdentifier);
|
52
52
|
}
|
53
53
|
|
54
54
|
export { Proof, proofToBytes };
|
@@ -3,9 +3,9 @@ import '../../core/dist/lib/filter/filter.js';
|
|
3
3
|
import '../../core/dist/lib/light_push/light_push.js';
|
4
4
|
import '../../core/dist/lib/store/store.js';
|
5
5
|
import '../../core/dist/lib/connection_manager/connection_manager.js';
|
6
|
-
import '../../
|
7
|
-
import '../../
|
8
|
-
import '../../
|
6
|
+
import '../../interfaces/dist/protocols.js';
|
7
|
+
import '../../interfaces/dist/connection_manager.js';
|
8
|
+
import '../../interfaces/dist/health_indicator.js';
|
9
9
|
import '../../../node_modules/multiformats/dist/src/bases/base10.js';
|
10
10
|
import '../../../node_modules/multiformats/dist/src/bases/base16.js';
|
11
11
|
import '../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -1,65 +1,110 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
let totalLength = 0;
|
8
|
-
for (const arr of input) {
|
9
|
-
totalLength += arr.length;
|
1
|
+
class BytesUtils {
|
2
|
+
/**
|
3
|
+
* Switches endianness of a byte array
|
4
|
+
*/
|
5
|
+
static switchEndianness(bytes) {
|
6
|
+
return new Uint8Array(bytes.reverse());
|
10
7
|
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
/**
|
9
|
+
* Builds a BigInt from a big-endian Uint8Array
|
10
|
+
* @param bytes The big-endian bytes to convert
|
11
|
+
* @returns The resulting BigInt in big-endian format
|
12
|
+
*/
|
13
|
+
static buildBigIntFromUint8ArrayBE(bytes) {
|
14
|
+
let result = 0n;
|
15
|
+
for (let i = 0; i < bytes.length; i++) {
|
16
|
+
result = (result << 8n) + BigInt(bytes[i]);
|
17
|
+
}
|
18
|
+
return result;
|
16
19
|
}
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
20
|
+
/**
|
21
|
+
* Switches endianness of a bigint value
|
22
|
+
* @param value The bigint value to switch endianness for
|
23
|
+
* @returns The bigint value with reversed endianness
|
24
|
+
*/
|
25
|
+
static switchEndiannessBigInt(value) {
|
26
|
+
// Convert bigint to byte array
|
27
|
+
const bytes = [];
|
28
|
+
let tempValue = value;
|
29
|
+
while (tempValue > 0n) {
|
30
|
+
bytes.push(Number(tempValue & 0xffn));
|
31
|
+
tempValue >>= 8n;
|
32
|
+
}
|
33
|
+
// Reverse bytes and convert back to bigint
|
34
|
+
return bytes
|
35
|
+
.reverse()
|
36
|
+
.reduce((acc, byte) => (acc << 8n) + BigInt(byte), 0n);
|
33
37
|
}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
/**
|
39
|
+
* Converts a big-endian bigint to a 32-byte big-endian Uint8Array
|
40
|
+
* @param value The big-endian bigint to convert
|
41
|
+
* @returns A 32-byte big-endian Uint8Array
|
42
|
+
*/
|
43
|
+
static bigIntToUint8Array32BE(value) {
|
44
|
+
const bytes = new Uint8Array(32);
|
45
|
+
for (let i = 31; i >= 0; i--) {
|
46
|
+
bytes[i] = Number(value & 0xffn);
|
47
|
+
value >>= 8n;
|
48
|
+
}
|
49
|
+
return bytes;
|
39
50
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
}
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
/**
|
52
|
+
* Writes an unsigned integer to a buffer in little-endian format
|
53
|
+
*/
|
54
|
+
static writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
55
|
+
value = +value;
|
56
|
+
offset = offset >>> 0;
|
57
|
+
byteLength = byteLength >>> 0;
|
58
|
+
if (!noAssert) {
|
59
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
60
|
+
BytesUtils.checkInt(buf, value, offset, byteLength, maxBytes, 0);
|
61
|
+
}
|
62
|
+
let mul = 1;
|
63
|
+
let i = 0;
|
64
|
+
buf[offset] = value & 0xff;
|
65
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
66
|
+
buf[offset + i] = (value / mul) & 0xff;
|
67
|
+
}
|
68
|
+
return buf;
|
69
|
+
}
|
70
|
+
/**
|
71
|
+
* Fills with zeros to set length
|
72
|
+
* @param array little endian Uint8Array
|
73
|
+
* @param length amount to pad
|
74
|
+
* @returns little endian Uint8Array padded with zeros to set length
|
75
|
+
*/
|
76
|
+
static zeroPadLE(array, length) {
|
77
|
+
const result = new Uint8Array(length);
|
78
|
+
for (let i = 0; i < length; i++) {
|
79
|
+
result[i] = array[i] || 0;
|
80
|
+
}
|
81
|
+
return result;
|
82
|
+
}
|
83
|
+
// Adapted from https://github.com/feross/buffer
|
84
|
+
static checkInt(buf, value, offset, ext, max, min) {
|
85
|
+
if (value > max || value < min)
|
86
|
+
throw new RangeError('"value" argument is out of bounds');
|
87
|
+
if (offset + ext > buf.length)
|
88
|
+
throw new RangeError("Index out of range");
|
89
|
+
}
|
90
|
+
/**
|
91
|
+
* Concatenate Uint8Arrays
|
92
|
+
* @param input
|
93
|
+
* @returns concatenation of all Uint8Array received as input
|
94
|
+
*/
|
95
|
+
static concatenate(...input) {
|
96
|
+
let totalLength = 0;
|
97
|
+
for (const arr of input) {
|
98
|
+
totalLength += arr.length;
|
99
|
+
}
|
100
|
+
const result = new Uint8Array(totalLength);
|
101
|
+
let offset = 0;
|
102
|
+
for (const arr of input) {
|
103
|
+
result.set(arr, offset);
|
104
|
+
offset += arr.length;
|
105
|
+
}
|
106
|
+
return result;
|
61
107
|
}
|
62
|
-
return result;
|
63
108
|
}
|
64
109
|
|
65
|
-
export {
|
110
|
+
export { BytesUtils };
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import '../../../
|
2
|
-
import '../../../
|
3
|
-
import '../../../
|
1
|
+
import '../../../interfaces/dist/protocols.js';
|
2
|
+
import '../../../interfaces/dist/connection_manager.js';
|
3
|
+
import '../../../interfaces/dist/health_indicator.js';
|
4
4
|
import '../../../../node_modules/multiformats/dist/src/bases/base10.js';
|
5
5
|
import '../../../../node_modules/multiformats/dist/src/bases/base16.js';
|
6
6
|
import '../../../../node_modules/multiformats/dist/src/bases/base2.js';
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { poseidonHash as poseidonHash$1 } from '../../../../node_modules/@waku/zerokit-rln-wasm/rln_wasm.js';
|
2
|
-
import {
|
2
|
+
import { BytesUtils } from './bytes.js';
|
3
3
|
|
4
4
|
function poseidonHash(...input) {
|
5
|
-
const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
|
6
|
-
const lenPrefixedData = concatenate(inputLen, ...input);
|
5
|
+
const inputLen = BytesUtils.writeUIntLE(new Uint8Array(8), input.length, 0, 8);
|
6
|
+
const lenPrefixedData = BytesUtils.concatenate(inputLen, ...input);
|
7
7
|
return poseidonHash$1(lenPrefixedData);
|
8
8
|
}
|
9
9
|
|
@@ -2,7 +2,7 @@ import { generateExtendedMembershipKey, generateSeededExtendedMembershipKey, ins
|
|
2
2
|
import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from './contract/constants.js';
|
3
3
|
import { IdentityCredential } from './identity.js';
|
4
4
|
import { Proof, proofToBytes } from './proof.js';
|
5
|
-
import {
|
5
|
+
import { BytesUtils } from './utils/bytes.js';
|
6
6
|
import { epochIntToBytes, dateToEpoch } from './utils/epoch.js';
|
7
7
|
|
8
8
|
class Zerokit {
|
@@ -40,8 +40,8 @@ class Zerokit {
|
|
40
40
|
insertMembers(index, ...idCommitments) {
|
41
41
|
// serializes a seq of IDCommitments to a byte seq
|
42
42
|
// the order of serialization is |id_commitment_len<8>|id_commitment<var>|
|
43
|
-
const idCommitmentLen = writeUIntLE(new Uint8Array(8), idCommitments.length, 0, 8);
|
44
|
-
const idCommitmentBytes = concatenate(idCommitmentLen, ...idCommitments);
|
43
|
+
const idCommitmentLen = BytesUtils.writeUIntLE(new Uint8Array(8), idCommitments.length, 0, 8);
|
44
|
+
const idCommitmentBytes = BytesUtils.concatenate(idCommitmentLen, ...idCommitments);
|
45
45
|
setLeavesFrom(this.zkRLN, index, idCommitmentBytes);
|
46
46
|
}
|
47
47
|
deleteMember(index) {
|
@@ -52,11 +52,11 @@ class Zerokit {
|
|
52
52
|
}
|
53
53
|
serializeMessage(uint8Msg, memIndex, epoch, idKey, rateLimit) {
|
54
54
|
// calculate message length
|
55
|
-
const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
|
56
|
-
const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
|
57
|
-
const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
55
|
+
const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
|
56
|
+
const memIndexBytes = BytesUtils.writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
|
57
|
+
const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
58
58
|
// [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> | rate_limit<8> ]
|
59
|
-
return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg, rateLimitBytes);
|
59
|
+
return BytesUtils.concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg, rateLimitBytes);
|
60
60
|
}
|
61
61
|
async generateRLNProof(msg, index, epoch, idSecretHash, rateLimit) {
|
62
62
|
if (epoch === undefined) {
|
@@ -92,9 +92,9 @@ class Zerokit {
|
|
92
92
|
pBytes = proofToBytes(proof);
|
93
93
|
}
|
94
94
|
// calculate message length
|
95
|
-
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
96
|
-
const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
97
|
-
return verifyRLNProof(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes));
|
95
|
+
const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
96
|
+
const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
97
|
+
return verifyRLNProof(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes));
|
98
98
|
}
|
99
99
|
verifyWithRoots(proof, msg, roots, rateLimit) {
|
100
100
|
let pBytes;
|
@@ -105,10 +105,10 @@ class Zerokit {
|
|
105
105
|
pBytes = proofToBytes(proof);
|
106
106
|
}
|
107
107
|
// calculate message length
|
108
|
-
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
109
|
-
const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
110
|
-
const rootsBytes = concatenate(...roots);
|
111
|
-
return verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes), rootsBytes);
|
108
|
+
const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
109
|
+
const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
110
|
+
const rootsBytes = BytesUtils.concatenate(...roots);
|
111
|
+
return verifyWithRoots(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes), rootsBytes);
|
112
112
|
}
|
113
113
|
verifyWithNoRoot(proof, msg, rateLimit) {
|
114
114
|
let pBytes;
|
@@ -119,9 +119,9 @@ class Zerokit {
|
|
119
119
|
pBytes = proofToBytes(proof);
|
120
120
|
}
|
121
121
|
// calculate message length
|
122
|
-
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
123
|
-
const rateLimitBytes = writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
124
|
-
return verifyWithRoots(this.zkRLN, concatenate(pBytes, msgLen, msg, rateLimitBytes), new Uint8Array());
|
122
|
+
const msgLen = BytesUtils.writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
123
|
+
const rateLimitBytes = BytesUtils.writeUIntLE(new Uint8Array(8), rateLimit ?? this.rateLimit, 0, 8);
|
124
|
+
return verifyWithRoots(this.zkRLN, BytesUtils.concatenate(pBytes, msgLen, msg, rateLimitBytes), new Uint8Array());
|
125
125
|
}
|
126
126
|
}
|
127
127
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { sha256 } from '../../../../../node_modules/@noble/hashes/esm/sha256.js';
|
2
|
-
import '
|
3
|
-
import '
|
4
|
-
import { DEFAULT_CLUSTER_ID } from '
|
5
|
-
import '
|
2
|
+
import '../../../../interfaces/dist/protocols.js';
|
3
|
+
import '../../../../interfaces/dist/connection_manager.js';
|
4
|
+
import { DEFAULT_CLUSTER_ID } from '../../../../interfaces/dist/constants.js';
|
5
|
+
import '../../../../interfaces/dist/health_indicator.js';
|
6
6
|
import { concat, utf8ToBytes } from '../../bytes/index.js';
|
7
7
|
|
8
8
|
const singleShardInfoToPubsubTopic = (shardInfo) => {
|