@waku/rln 0.1.6-f7c290d.0 → 0.1.6
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/CHANGELOG.md +29 -0
- 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/node_modules/@chainsafe/is-ip/lib/is-ip.js +12 -0
- package/bundle/node_modules/@chainsafe/is-ip/lib/parse.js +26 -0
- package/bundle/node_modules/@chainsafe/is-ip/lib/parser.js +202 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +1 -1
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/constants.js +43 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/errors.js +17 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/registry.js +245 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/utils.js +191 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/validation.js +30 -0
- package/bundle/node_modules/debug/src/browser.js +1 -1
- package/bundle/node_modules/debug/src/common.js +1 -1
- package/bundle/node_modules/lodash/lodash.js +5 -5
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +12 -9
- package/bundle/node_modules/multiformats/dist/src/bytes.js +19 -3
- package/bundle/node_modules/multiformats/dist/src/cid.js +371 -0
- package/bundle/node_modules/multiformats/dist/src/hashes/digest.js +62 -0
- package/bundle/node_modules/multiformats/dist/src/varint.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/varint.js +78 -0
- package/bundle/node_modules/uint8arrays/dist/src/concat.js +20 -0
- package/bundle/node_modules/uint8arrays/dist/src/to-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/as-uint8array.js +9 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +1 -3
- package/bundle/packages/proto/dist/generated/filter.js +2 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +2 -0
- package/bundle/packages/proto/dist/generated/light_push.js +2 -0
- package/bundle/packages/proto/dist/generated/message.js +2 -0
- package/bundle/packages/proto/dist/generated/metadata.js +2 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +2 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +2 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +2 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +2 -0
- package/bundle/packages/rln/dist/contract/constants.js +1 -7
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +2 -5
- package/bundle/packages/rln/dist/contract/rln_contract.js +2 -2
- package/bundle/packages/rln/dist/credentials_manager.js +16 -24
- package/bundle/packages/rln/dist/identity.js +6 -8
- package/bundle/packages/rln/dist/keystore/keystore.js +10 -21
- package/bundle/packages/rln/dist/proof.js +2 -2
- package/bundle/packages/rln/dist/utils/bytes.js +58 -103
- package/bundle/packages/rln/dist/utils/hash.js +3 -3
- package/bundle/packages/rln/dist/zerokit.js +17 -17
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.test-utils.d.ts +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 +2 -5
- 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/test-setup.d.ts +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.d.ts +0 -4
- package/dist/credentials_manager.js +16 -25
- package/dist/credentials_manager.js.map +1 -1
- package/dist/identity.d.ts +2 -5
- package/dist/identity.js +5 -8
- package/dist/identity.js.map +1 -1
- package/dist/keystore/credential_validation_generated.d.ts +0 -2
- package/dist/keystore/keystore.js +10 -21
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/keystore_validation_generated.d.ts +0 -2
- package/dist/proof.js +2 -2
- package/dist/proof.js.map +1 -1
- package/dist/utils/bytes.d.ts +20 -42
- package/dist/utils/bytes.js +57 -102
- 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 +93 -1
- package/src/contract/constants.ts +0 -9
- package/src/contract/rln_base_contract.ts +3 -5
- package/src/contract/rln_contract.ts +2 -5
- package/src/contract/test-utils.ts +179 -0
- package/src/credentials_manager.ts +24 -46
- package/src/identity.ts +7 -11
- package/src/keystore/keystore.ts +22 -38
- package/src/proof.ts +2 -2
- package/src/utils/bytes.ts +72 -118
- package/src/utils/hash.ts +5 -15
- package/src/utils/index.ts +6 -1
- package/src/zerokit.ts +22 -30
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +0 -15
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +0 -21
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +0 -92
package/src/zerokit.ts
CHANGED
@@ -5,7 +5,12 @@ import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from "./contract/constants.js";
|
|
5
5
|
import { IdentityCredential } from "./identity.js";
|
6
6
|
import { Proof, proofToBytes } from "./proof.js";
|
7
7
|
import { WitnessCalculator } from "./resources/witness_calculator";
|
8
|
-
import {
|
8
|
+
import {
|
9
|
+
concatenate,
|
10
|
+
dateToEpoch,
|
11
|
+
epochIntToBytes,
|
12
|
+
writeUIntLE
|
13
|
+
} from "./utils/index.js";
|
9
14
|
|
10
15
|
export class Zerokit {
|
11
16
|
public constructor(
|
@@ -52,16 +57,13 @@ export class Zerokit {
|
|
52
57
|
): void {
|
53
58
|
// serializes a seq of IDCommitments to a byte seq
|
54
59
|
// the order of serialization is |id_commitment_len<8>|id_commitment<var>|
|
55
|
-
const idCommitmentLen =
|
60
|
+
const idCommitmentLen = writeUIntLE(
|
56
61
|
new Uint8Array(8),
|
57
62
|
idCommitments.length,
|
58
63
|
0,
|
59
64
|
8
|
60
65
|
);
|
61
|
-
const idCommitmentBytes =
|
62
|
-
idCommitmentLen,
|
63
|
-
...idCommitments
|
64
|
-
);
|
66
|
+
const idCommitmentBytes = concatenate(idCommitmentLen, ...idCommitments);
|
65
67
|
zerokitRLN.setLeavesFrom(this.zkRLN, index, idCommitmentBytes);
|
66
68
|
}
|
67
69
|
|
@@ -81,19 +83,9 @@ export class Zerokit {
|
|
81
83
|
rateLimit?: number
|
82
84
|
): Uint8Array {
|
83
85
|
// calculate message length
|
84
|
-
const msgLen =
|
85
|
-
|
86
|
-
|
87
|
-
0,
|
88
|
-
8
|
89
|
-
);
|
90
|
-
const memIndexBytes = BytesUtils.writeUIntLE(
|
91
|
-
new Uint8Array(8),
|
92
|
-
memIndex,
|
93
|
-
0,
|
94
|
-
8
|
95
|
-
);
|
96
|
-
const rateLimitBytes = BytesUtils.writeUIntLE(
|
86
|
+
const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
|
87
|
+
const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
|
88
|
+
const rateLimitBytes = writeUIntLE(
|
97
89
|
new Uint8Array(8),
|
98
90
|
rateLimit ?? this.rateLimit,
|
99
91
|
0,
|
@@ -101,7 +93,7 @@ export class Zerokit {
|
|
101
93
|
);
|
102
94
|
|
103
95
|
// [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> | rate_limit<8> ]
|
104
|
-
return
|
96
|
+
return concatenate(
|
105
97
|
idKey,
|
106
98
|
memIndexBytes,
|
107
99
|
epoch,
|
@@ -177,8 +169,8 @@ export class Zerokit {
|
|
177
169
|
}
|
178
170
|
|
179
171
|
// calculate message length
|
180
|
-
const msgLen =
|
181
|
-
const rateLimitBytes =
|
172
|
+
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
173
|
+
const rateLimitBytes = writeUIntLE(
|
182
174
|
new Uint8Array(8),
|
183
175
|
rateLimit ?? this.rateLimit,
|
184
176
|
0,
|
@@ -187,7 +179,7 @@ export class Zerokit {
|
|
187
179
|
|
188
180
|
return zerokitRLN.verifyRLNProof(
|
189
181
|
this.zkRLN,
|
190
|
-
|
182
|
+
concatenate(pBytes, msgLen, msg, rateLimitBytes)
|
191
183
|
);
|
192
184
|
}
|
193
185
|
|
@@ -204,19 +196,19 @@ export class Zerokit {
|
|
204
196
|
pBytes = proofToBytes(proof);
|
205
197
|
}
|
206
198
|
// calculate message length
|
207
|
-
const msgLen =
|
208
|
-
const rateLimitBytes =
|
199
|
+
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
200
|
+
const rateLimitBytes = writeUIntLE(
|
209
201
|
new Uint8Array(8),
|
210
202
|
rateLimit ?? this.rateLimit,
|
211
203
|
0,
|
212
204
|
8
|
213
205
|
);
|
214
206
|
|
215
|
-
const rootsBytes =
|
207
|
+
const rootsBytes = concatenate(...roots);
|
216
208
|
|
217
209
|
return zerokitRLN.verifyWithRoots(
|
218
210
|
this.zkRLN,
|
219
|
-
|
211
|
+
concatenate(pBytes, msgLen, msg, rateLimitBytes),
|
220
212
|
rootsBytes
|
221
213
|
);
|
222
214
|
}
|
@@ -234,8 +226,8 @@ export class Zerokit {
|
|
234
226
|
}
|
235
227
|
|
236
228
|
// calculate message length
|
237
|
-
const msgLen =
|
238
|
-
const rateLimitBytes =
|
229
|
+
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
230
|
+
const rateLimitBytes = writeUIntLE(
|
239
231
|
new Uint8Array(8),
|
240
232
|
rateLimit ?? this.rateLimit,
|
241
233
|
0,
|
@@ -244,7 +236,7 @@ export class Zerokit {
|
|
244
236
|
|
245
237
|
return zerokitRLN.verifyWithRoots(
|
246
238
|
this.zkRLN,
|
247
|
-
|
239
|
+
concatenate(pBytes, msgLen, msg, rateLimitBytes),
|
248
240
|
new Uint8Array()
|
249
241
|
);
|
250
242
|
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
import '../../../../multiformats/dist/src/bases/base32.js';
|
2
|
-
import '../../../../multiformats/dist/src/bases/base58.js';
|
3
|
-
import { bases } from '../../../../multiformats/dist/src/basics.js';
|
4
|
-
import '../../../../multiformats/dist/src/bases/base36.js';
|
5
|
-
import { getProtocol } from './protocols-table.js';
|
6
|
-
|
7
|
-
getProtocol('ip4');
|
8
|
-
getProtocol('ip6');
|
9
|
-
getProtocol('ipcidr');
|
10
|
-
const decoders = Object.values(bases).map((c) => c.decoder);
|
11
|
-
((function () {
|
12
|
-
let acc = decoders[0].or(decoders[1]);
|
13
|
-
decoders.slice(2).forEach((d) => (acc = acc.or(d)));
|
14
|
-
return acc;
|
15
|
-
}))();
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import '../../../../multiformats/dist/src/bases/base58.js';
|
2
|
-
import '../../../../multiformats/dist/src/bases/base32.js';
|
3
|
-
import '../../../../multiformats/dist/src/bases/base36.js';
|
4
|
-
import '../../../../multiformats/dist/src/bases/base10.js';
|
5
|
-
import '../../../../multiformats/dist/src/bases/base16.js';
|
6
|
-
import '../../../../multiformats/dist/src/bases/base2.js';
|
7
|
-
import '../../../../multiformats/dist/src/bases/base256emoji.js';
|
8
|
-
import '../../../../multiformats/dist/src/bases/base64.js';
|
9
|
-
import '../../../../multiformats/dist/src/bases/base8.js';
|
10
|
-
import '../../../../multiformats/dist/src/bases/identity.js';
|
11
|
-
import '../../../../multiformats/dist/src/codecs/json.js';
|
12
|
-
import './convert.js';
|
13
|
-
import { getProtocol } from './protocols-table.js';
|
14
|
-
|
15
|
-
/* eslint-disable complexity */
|
16
|
-
[
|
17
|
-
getProtocol('dns').code,
|
18
|
-
getProtocol('dns4').code,
|
19
|
-
getProtocol('dns6').code,
|
20
|
-
getProtocol('dnsaddr').code
|
21
|
-
];
|
@@ -1,92 +0,0 @@
|
|
1
|
-
const V = -1;
|
2
|
-
const names = {};
|
3
|
-
const codes = {};
|
4
|
-
const table = [
|
5
|
-
[4, 32, 'ip4'],
|
6
|
-
[6, 16, 'tcp'],
|
7
|
-
[33, 16, 'dccp'],
|
8
|
-
[41, 128, 'ip6'],
|
9
|
-
[42, V, 'ip6zone'],
|
10
|
-
[43, 8, 'ipcidr'],
|
11
|
-
[53, V, 'dns', true],
|
12
|
-
[54, V, 'dns4', true],
|
13
|
-
[55, V, 'dns6', true],
|
14
|
-
[56, V, 'dnsaddr', true],
|
15
|
-
[132, 16, 'sctp'],
|
16
|
-
[273, 16, 'udp'],
|
17
|
-
[275, 0, 'p2p-webrtc-star'],
|
18
|
-
[276, 0, 'p2p-webrtc-direct'],
|
19
|
-
[277, 0, 'p2p-stardust'],
|
20
|
-
[280, 0, 'webrtc-direct'],
|
21
|
-
[281, 0, 'webrtc'],
|
22
|
-
[290, 0, 'p2p-circuit'],
|
23
|
-
[301, 0, 'udt'],
|
24
|
-
[302, 0, 'utp'],
|
25
|
-
[400, V, 'unix', false, true],
|
26
|
-
// `ipfs` is added before `p2p` for legacy support.
|
27
|
-
// All text representations will default to `p2p`, but `ipfs` will
|
28
|
-
// still be supported
|
29
|
-
[421, V, 'ipfs'],
|
30
|
-
// `p2p` is the preferred name for 421, and is now the default
|
31
|
-
[421, V, 'p2p'],
|
32
|
-
[443, 0, 'https'],
|
33
|
-
[444, 96, 'onion'],
|
34
|
-
[445, 296, 'onion3'],
|
35
|
-
[446, V, 'garlic64'],
|
36
|
-
[448, 0, 'tls'],
|
37
|
-
[449, V, 'sni'],
|
38
|
-
[460, 0, 'quic'],
|
39
|
-
[461, 0, 'quic-v1'],
|
40
|
-
[465, 0, 'webtransport'],
|
41
|
-
[466, V, 'certhash'],
|
42
|
-
[477, 0, 'ws'],
|
43
|
-
[478, 0, 'wss'],
|
44
|
-
[479, 0, 'p2p-websocket-star'],
|
45
|
-
[480, 0, 'http'],
|
46
|
-
[481, V, 'http-path'],
|
47
|
-
[777, V, 'memory']
|
48
|
-
];
|
49
|
-
// populate tables
|
50
|
-
table.forEach(row => {
|
51
|
-
const proto = createProtocol(...row);
|
52
|
-
codes[proto.code] = proto;
|
53
|
-
names[proto.name] = proto;
|
54
|
-
});
|
55
|
-
function createProtocol(code, size, name, resolvable, path) {
|
56
|
-
return {
|
57
|
-
code,
|
58
|
-
size,
|
59
|
-
name,
|
60
|
-
resolvable: Boolean(resolvable),
|
61
|
-
path: Boolean(path)
|
62
|
-
};
|
63
|
-
}
|
64
|
-
/**
|
65
|
-
* For the passed proto string or number, return a {@link Protocol}
|
66
|
-
*
|
67
|
-
* @example
|
68
|
-
*
|
69
|
-
* ```js
|
70
|
-
* import { protocol } from '@multiformats/multiaddr'
|
71
|
-
*
|
72
|
-
* console.info(protocol(4))
|
73
|
-
* // { code: 4, size: 32, name: 'ip4', resolvable: false, path: false }
|
74
|
-
* ```
|
75
|
-
*/
|
76
|
-
function getProtocol(proto) {
|
77
|
-
if (typeof proto === 'number') {
|
78
|
-
if (codes[proto] != null) {
|
79
|
-
return codes[proto];
|
80
|
-
}
|
81
|
-
throw new Error(`no protocol with code: ${proto}`);
|
82
|
-
}
|
83
|
-
else if (typeof proto === 'string') {
|
84
|
-
if (names[proto] != null) {
|
85
|
-
return names[proto];
|
86
|
-
}
|
87
|
-
throw new Error(`no protocol with name: ${proto}`);
|
88
|
-
}
|
89
|
-
throw new Error(`invalid protocol id type: ${typeof proto}`);
|
90
|
-
}
|
91
|
-
|
92
|
-
export { codes, createProtocol, getProtocol, names, table };
|