@waku/rln 0.1.6-f911bf8.0 → 0.1.7-7a9850d.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/bundle/node_modules/@chainsafe/is-ip/lib/is-ip.js +12 -0
  3. package/bundle/node_modules/@chainsafe/is-ip/lib/parse.js +26 -0
  4. package/bundle/node_modules/@chainsafe/is-ip/lib/parser.js +202 -0
  5. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +1 -1
  6. package/bundle/node_modules/@multiformats/multiaddr/dist/src/constants.js +43 -0
  7. package/bundle/node_modules/@multiformats/multiaddr/dist/src/errors.js +17 -0
  8. package/bundle/node_modules/@multiformats/multiaddr/dist/src/registry.js +245 -0
  9. package/bundle/node_modules/@multiformats/multiaddr/dist/src/utils.js +191 -0
  10. package/bundle/node_modules/@multiformats/multiaddr/dist/src/validation.js +30 -0
  11. package/bundle/node_modules/debug/src/browser.js +1 -1
  12. package/bundle/node_modules/debug/src/common.js +1 -1
  13. package/bundle/node_modules/lodash/lodash.js +5 -5
  14. package/bundle/node_modules/multiformats/dist/src/bases/base.js +12 -9
  15. package/bundle/node_modules/multiformats/dist/src/bytes.js +19 -3
  16. package/bundle/node_modules/multiformats/dist/src/cid.js +371 -0
  17. package/bundle/node_modules/multiformats/dist/src/hashes/digest.js +62 -0
  18. package/bundle/node_modules/multiformats/dist/src/varint.js +15 -0
  19. package/bundle/node_modules/multiformats/dist/src/vendor/varint.js +78 -0
  20. package/bundle/node_modules/uint8arrays/dist/src/concat.js +20 -0
  21. package/bundle/node_modules/uint8arrays/dist/src/to-string.js +19 -0
  22. package/bundle/node_modules/uint8arrays/dist/src/util/as-uint8array.js +9 -0
  23. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +1 -3
  24. package/bundle/packages/core/dist/lib/message/version_0.js +1 -4
  25. package/bundle/packages/proto/dist/generated/filter.js +2 -0
  26. package/bundle/packages/proto/dist/generated/filter_v2.js +2 -0
  27. package/bundle/packages/proto/dist/generated/light_push.js +2 -0
  28. package/bundle/packages/proto/dist/generated/message.js +2 -0
  29. package/bundle/packages/proto/dist/generated/metadata.js +2 -0
  30. package/bundle/packages/proto/dist/generated/peer_exchange.js +2 -0
  31. package/bundle/packages/proto/dist/generated/sds_message.js +2 -0
  32. package/bundle/packages/proto/dist/generated/store_v3.js +2 -0
  33. package/bundle/packages/proto/dist/generated/topic_only_message.js +2 -0
  34. package/bundle/packages/rln/dist/contract/rln_base_contract.js +2 -2
  35. package/bundle/packages/rln/dist/identity.js +1 -1
  36. package/bundle/packages/rln/dist/message.js +11 -0
  37. package/bundle/packages/rln/dist/utils/bytes.js +2 -6
  38. package/dist/.tsbuildinfo +1 -1
  39. package/dist/codec.test-utils.d.ts +1 -1
  40. package/dist/contract/rln_base_contract.d.ts +1 -1
  41. package/dist/contract/rln_base_contract.js +2 -2
  42. package/dist/contract/rln_base_contract.js.map +1 -1
  43. package/dist/contract/test-setup.d.ts +1 -1
  44. package/dist/identity.js +1 -1
  45. package/dist/identity.js.map +1 -1
  46. package/dist/keystore/credential_validation_generated.d.ts +0 -2
  47. package/dist/keystore/keystore_validation_generated.d.ts +0 -2
  48. package/dist/message.d.ts +5 -4
  49. package/dist/message.js +2 -0
  50. package/dist/message.js.map +1 -1
  51. package/dist/utils/bytes.js +2 -6
  52. package/dist/utils/bytes.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/contract/rln_base_contract.ts +2 -2
  55. package/src/identity.ts +1 -1
  56. package/src/message.ts +7 -4
  57. package/src/utils/bytes.ts +2 -6
  58. package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +0 -15
  59. package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +0 -21
  60. package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +0 -92
@@ -0,0 +1,191 @@
1
+ import { isIPv4 } from '../../../../@chainsafe/is-ip/lib/is-ip.js';
2
+ import { base32 } from '../../../../multiformats/dist/src/bases/base32.js';
3
+ import { bases } from '../../../../multiformats/dist/src/basics.js';
4
+ import { concat } from '../../../../uint8arrays/dist/src/concat.js';
5
+ import { fromString } from '../../../../uint8arrays/dist/src/from-string.js';
6
+ import { toString } from '../../../../uint8arrays/dist/src/to-string.js';
7
+ import { InvalidMultiaddrError } from './errors.js';
8
+
9
+ function bytesToString(base) {
10
+ return (buf) => {
11
+ return toString(buf, base);
12
+ };
13
+ }
14
+ function stringToBytes(base) {
15
+ return (buf) => {
16
+ return fromString(buf, base);
17
+ };
18
+ }
19
+ function bytes2port(buf) {
20
+ const view = new DataView(buf.buffer);
21
+ return view.getUint16(buf.byteOffset).toString();
22
+ }
23
+ function port2bytes(port) {
24
+ const buf = new ArrayBuffer(2);
25
+ const view = new DataView(buf);
26
+ view.setUint16(0, typeof port === 'string' ? parseInt(port) : port);
27
+ return new Uint8Array(buf);
28
+ }
29
+ function onion2bytes(str) {
30
+ const addr = str.split(':');
31
+ if (addr.length !== 2) {
32
+ throw new Error(`failed to parse onion addr: ["'${addr.join('", "')}'"]' does not contain a port number`);
33
+ }
34
+ if (addr[0].length !== 16) {
35
+ throw new Error(`failed to parse onion addr: ${addr[0]} not a Tor onion address.`);
36
+ }
37
+ // onion addresses do not include the multibase prefix, add it before decoding
38
+ const buf = fromString(addr[0], 'base32');
39
+ // onion port number
40
+ const port = parseInt(addr[1], 10);
41
+ if (port < 1 || port > 65536) {
42
+ throw new Error('Port number is not in range(1, 65536)');
43
+ }
44
+ const portBuf = port2bytes(port);
45
+ return concat([buf, portBuf], buf.length + portBuf.length);
46
+ }
47
+ function onion32bytes(str) {
48
+ const addr = str.split(':');
49
+ if (addr.length !== 2) {
50
+ throw new Error(`failed to parse onion addr: ["'${addr.join('", "')}'"]' does not contain a port number`);
51
+ }
52
+ if (addr[0].length !== 56) {
53
+ throw new Error(`failed to parse onion addr: ${addr[0]} not a Tor onion3 address.`);
54
+ }
55
+ // onion addresses do not include the multibase prefix, add it before decoding
56
+ const buf = base32.decode(`b${addr[0]}`);
57
+ // onion port number
58
+ const port = parseInt(addr[1], 10);
59
+ if (port < 1 || port > 65536) {
60
+ throw new Error('Port number is not in range(1, 65536)');
61
+ }
62
+ const portBuf = port2bytes(port);
63
+ return concat([buf, portBuf], buf.length + portBuf.length);
64
+ }
65
+ function bytes2onion(buf) {
66
+ const addrBytes = buf.subarray(0, buf.length - 2);
67
+ const portBytes = buf.subarray(buf.length - 2);
68
+ const addr = toString(addrBytes, 'base32');
69
+ const port = bytes2port(portBytes);
70
+ return `${addr}:${port}`;
71
+ }
72
+ // Copied from https://github.com/indutny/node-ip/blob/master/lib/ip.js#L7
73
+ // but with buf/offset args removed because we don't use them
74
+ const ip4ToBytes = function (ip) {
75
+ ip = ip.toString().trim();
76
+ const bytes = new Uint8Array(4);
77
+ ip.split(/\./g).forEach((byte, index) => {
78
+ const value = parseInt(byte, 10);
79
+ if (isNaN(value) || value < 0 || value > 0xff) {
80
+ throw new InvalidMultiaddrError('Invalid byte value in IP address');
81
+ }
82
+ bytes[index] = value;
83
+ });
84
+ return bytes;
85
+ };
86
+ // Copied from https://github.com/indutny/node-ip/blob/master/lib/ip.js#L7
87
+ // but with buf/offset args removed because we don't use them
88
+ const ip6ToBytes = function (ip) {
89
+ let offset = 0;
90
+ ip = ip.toString().trim();
91
+ const sections = ip.split(':', 8);
92
+ let i;
93
+ for (i = 0; i < sections.length; i++) {
94
+ const isv4 = isIPv4(sections[i]);
95
+ let v4Buffer;
96
+ if (isv4) {
97
+ v4Buffer = ip4ToBytes(sections[i]);
98
+ sections[i] = toString(v4Buffer.subarray(0, 2), 'base16');
99
+ }
100
+ if (v4Buffer != null && ++i < 8) {
101
+ sections.splice(i, 0, toString(v4Buffer.subarray(2, 4), 'base16'));
102
+ }
103
+ }
104
+ if (sections[0] === '') {
105
+ while (sections.length < 8) {
106
+ sections.unshift('0');
107
+ }
108
+ }
109
+ else if (sections[sections.length - 1] === '') {
110
+ while (sections.length < 8) {
111
+ sections.push('0');
112
+ }
113
+ }
114
+ else if (sections.length < 8) {
115
+ for (i = 0; i < sections.length && sections[i] !== ''; i++) { }
116
+ const argv = [i, 1];
117
+ for (i = 9 - sections.length; i > 0; i--) {
118
+ argv.push('0');
119
+ }
120
+ sections.splice.apply(sections, argv);
121
+ }
122
+ const bytes = new Uint8Array(offset + 16);
123
+ for (i = 0; i < sections.length; i++) {
124
+ if (sections[i] === '') {
125
+ sections[i] = '0';
126
+ }
127
+ const word = parseInt(sections[i], 16);
128
+ if (isNaN(word) || word < 0 || word > 0xffff) {
129
+ throw new InvalidMultiaddrError('Invalid byte value in IP address');
130
+ }
131
+ bytes[offset++] = (word >> 8) & 0xff;
132
+ bytes[offset++] = word & 0xff;
133
+ }
134
+ return bytes;
135
+ };
136
+ // Copied from https://github.com/indutny/node-ip/blob/master/lib/ip.js#L63
137
+ const ip4ToString = function (buf) {
138
+ if (buf.byteLength !== 4) {
139
+ throw new InvalidMultiaddrError('IPv4 address was incorrect length');
140
+ }
141
+ const result = [];
142
+ for (let i = 0; i < buf.byteLength; i++) {
143
+ result.push(buf[i]);
144
+ }
145
+ return result.join('.');
146
+ };
147
+ const ip6ToString = function (buf) {
148
+ if (buf.byteLength !== 16) {
149
+ throw new InvalidMultiaddrError('IPv6 address was incorrect length');
150
+ }
151
+ const result = [];
152
+ for (let i = 0; i < buf.byteLength; i += 2) {
153
+ const byte1 = buf[i];
154
+ const byte2 = buf[i + 1];
155
+ const tuple = `${byte1.toString(16).padStart(2, '0')}${byte2.toString(16).padStart(2, '0')}`;
156
+ result.push(tuple);
157
+ }
158
+ const ip = result.join(':');
159
+ try {
160
+ const url = new URL(`http://[${ip}]`);
161
+ return url.hostname.substring(1, url.hostname.length - 1);
162
+ }
163
+ catch {
164
+ throw new InvalidMultiaddrError(`Invalid IPv6 address "${ip}"`);
165
+ }
166
+ };
167
+ function ip6StringToValue(str) {
168
+ try {
169
+ const url = new URL(`http://[${str}]`);
170
+ return url.hostname.substring(1, url.hostname.length - 1);
171
+ }
172
+ catch {
173
+ throw new InvalidMultiaddrError(`Invalid IPv6 address "${str}"`);
174
+ }
175
+ }
176
+ const decoders = Object.values(bases).map((c) => c.decoder);
177
+ const anybaseDecoder = (function () {
178
+ let acc = decoders[0].or(decoders[1]);
179
+ decoders.slice(2).forEach((d) => (acc = acc.or(d)));
180
+ return acc;
181
+ })();
182
+ function mb2bytes(mbstr) {
183
+ return anybaseDecoder.decode(mbstr);
184
+ }
185
+ function bytes2mb(base) {
186
+ return (buf) => {
187
+ return base.encoder.encode(buf);
188
+ };
189
+ }
190
+
191
+ export { bytes2mb, bytes2onion, bytes2port, bytesToString, ip4ToBytes, ip4ToString, ip6StringToValue, ip6ToBytes, ip6ToString, mb2bytes, onion2bytes, onion32bytes, port2bytes, stringToBytes };
@@ -0,0 +1,30 @@
1
+ import { ValidationError } from './errors.js';
2
+
3
+ function integer(value) {
4
+ const int = parseInt(value);
5
+ if (int.toString() !== value) {
6
+ throw new ValidationError('Value must be an integer');
7
+ }
8
+ }
9
+ function positive(value) {
10
+ if (value < 0) {
11
+ throw new ValidationError('Value must be a positive integer, or zero');
12
+ }
13
+ }
14
+ function maxValue(max) {
15
+ return (value) => {
16
+ if (value > max) {
17
+ throw new ValidationError(`Value must be smaller than or equal to ${max}`);
18
+ }
19
+ };
20
+ }
21
+ function validate(...funcs) {
22
+ return (value) => {
23
+ for (const fn of funcs) {
24
+ fn(value);
25
+ }
26
+ };
27
+ }
28
+ const validatePort = validate(integer, positive, maxValue(65_535));
29
+
30
+ export { integer, maxValue, positive, validate, validatePort };
@@ -224,7 +224,7 @@ import { c as common } from './common.js';
224
224
  function load() {
225
225
  let r;
226
226
  try {
227
- r = exports.storage.getItem('debug');
227
+ r = exports.storage.getItem('debug') || exports.storage.getItem('DEBUG') ;
228
228
  } catch (error) {
229
229
  // Swallow
230
230
  // XXX (@Qix-) should we be logging these?
@@ -169,7 +169,7 @@ function setup(env) {
169
169
 
170
170
  const split = (typeof namespaces === 'string' ? namespaces : '')
171
171
  .trim()
172
- .replace(' ', ',')
172
+ .replace(/\s+/g, ',')
173
173
  .split(',')
174
174
  .filter(Boolean);
175
175
 
@@ -4302,7 +4302,7 @@ lodash.exports;
4302
4302
  return symbolToString ? symbolToString.call(value) : '';
4303
4303
  }
4304
4304
  var result = (value + '');
4305
- return (result == '0' && (1 / value) == -Infinity) ? '-0' : result;
4305
+ return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
4306
4306
  }
4307
4307
 
4308
4308
  /**
@@ -6825,7 +6825,7 @@ lodash.exports;
6825
6825
  return value;
6826
6826
  }
6827
6827
  var result = (value + '');
6828
- return (result == '0' && (1 / value) == -Infinity) ? '-0' : result;
6828
+ return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
6829
6829
  }
6830
6830
 
6831
6831
  /**
@@ -12167,7 +12167,7 @@ lodash.exports;
12167
12167
  * // => false
12168
12168
  */
12169
12169
  function isSafeInteger(value) {
12170
- return isInteger(value) && value >= -9007199254740991 && value <= MAX_SAFE_INTEGER;
12170
+ return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
12171
12171
  }
12172
12172
 
12173
12173
  /**
@@ -12434,7 +12434,7 @@ lodash.exports;
12434
12434
  return value === 0 ? value : 0;
12435
12435
  }
12436
12436
  value = toNumber(value);
12437
- if (value === INFINITY || value === -Infinity) {
12437
+ if (value === INFINITY || value === -INFINITY) {
12438
12438
  var sign = (value < 0 ? -1 : 1);
12439
12439
  return sign * MAX_INTEGER;
12440
12440
  }
@@ -12603,7 +12603,7 @@ lodash.exports;
12603
12603
  */
12604
12604
  function toSafeInteger(value) {
12605
12605
  return value
12606
- ? baseClamp(toInteger(value), -9007199254740991, MAX_SAFE_INTEGER)
12606
+ ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
12607
12607
  : (value === 0 ? value : 0);
12608
12608
  }
12609
12609
 
@@ -80,7 +80,6 @@ class ComposedDecoder {
80
80
  }
81
81
  }
82
82
  function or(left, right) {
83
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
84
83
  return new ComposedDecoder({
85
84
  ...(left.decoders ?? { [left.prefix]: left }),
86
85
  ...(right.decoders ?? { [right.prefix]: right })
@@ -120,12 +119,7 @@ function baseX({ name, prefix, alphabet }) {
120
119
  decode: (text) => coerce(decode(text))
121
120
  });
122
121
  }
123
- function decode(string, alphabet, bitsPerChar, name) {
124
- // Build the character lookup table:
125
- const codes = {};
126
- for (let i = 0; i < alphabet.length; ++i) {
127
- codes[alphabet[i]] = i;
128
- }
122
+ function decode(string, alphabetIdx, bitsPerChar, name) {
129
123
  // Count the padding bytes:
130
124
  let end = string.length;
131
125
  while (string[end - 1] === '=') {
@@ -139,7 +133,7 @@ function decode(string, alphabet, bitsPerChar, name) {
139
133
  let written = 0; // Next byte to write
140
134
  for (let i = 0; i < end; ++i) {
141
135
  // Read one character from the string:
142
- const value = codes[string[i]];
136
+ const value = alphabetIdx[string[i]];
143
137
  if (value === undefined) {
144
138
  throw new SyntaxError(`Non-${name} character`);
145
139
  }
@@ -186,10 +180,19 @@ function encode(data, alphabet, bitsPerChar) {
186
180
  }
187
181
  return out;
188
182
  }
183
+ function createAlphabetIdx(alphabet) {
184
+ // Build the character lookup table:
185
+ const alphabetIdx = {};
186
+ for (let i = 0; i < alphabet.length; ++i) {
187
+ alphabetIdx[alphabet[i]] = i;
188
+ }
189
+ return alphabetIdx;
190
+ }
189
191
  /**
190
192
  * RFC4648 Factory
191
193
  */
192
194
  function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
195
+ const alphabetIdx = createAlphabetIdx(alphabet);
193
196
  return from({
194
197
  prefix,
195
198
  name,
@@ -197,7 +200,7 @@ function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
197
200
  return encode(input, alphabet, bitsPerChar);
198
201
  },
199
202
  decode(input) {
200
- return decode(input, alphabet, bitsPerChar, name);
203
+ return decode(input, alphabetIdx, bitsPerChar, name);
201
204
  }
202
205
  });
203
206
  }
@@ -1,8 +1,24 @@
1
+ function equals(aa, bb) {
2
+ if (aa === bb) {
3
+ return true;
4
+ }
5
+ if (aa.byteLength !== bb.byteLength) {
6
+ return false;
7
+ }
8
+ for (let ii = 0; ii < aa.byteLength; ii++) {
9
+ if (aa[ii] !== bb[ii]) {
10
+ return false;
11
+ }
12
+ }
13
+ return true;
14
+ }
1
15
  function coerce(o) {
2
- if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array')
16
+ if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array') {
3
17
  return o;
4
- if (o instanceof ArrayBuffer)
18
+ }
19
+ if (o instanceof ArrayBuffer) {
5
20
  return new Uint8Array(o);
21
+ }
6
22
  if (ArrayBuffer.isView(o)) {
7
23
  return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
8
24
  }
@@ -15,4 +31,4 @@ function toString(b) {
15
31
  return new TextDecoder().decode(b);
16
32
  }
17
33
 
18
- export { coerce, fromString, toString };
34
+ export { coerce, equals, fromString, toString };