@waku/core 0.0.26 → 0.0.28-070b625.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 (66) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/bundle/{base_protocol-pDODy0G6.js → base_protocol-D0Zdzb-v.js} +134 -89
  3. package/bundle/{browser-mTOOnVZp.js → browser-DoQRY-an.js} +518 -712
  4. package/bundle/{index-cmONXM-V.js → index-BJwgMx4y.js} +116 -88
  5. package/bundle/index.js +2967 -21667
  6. package/bundle/lib/base_protocol.js +3 -3
  7. package/bundle/lib/message/version_0.js +3 -3
  8. package/bundle/lib/predefined_bootstrap_nodes.js +17 -17
  9. package/bundle/version_0-C6o0DvNW.js +4055 -0
  10. package/dist/.tsbuildinfo +1 -1
  11. package/dist/index.d.ts +3 -6
  12. package/dist/index.js +3 -6
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/base_protocol.d.ts +15 -13
  15. package/dist/lib/base_protocol.js +35 -22
  16. package/dist/lib/base_protocol.js.map +1 -1
  17. package/dist/lib/connection_manager.d.ts +2 -2
  18. package/dist/lib/connection_manager.js +16 -6
  19. package/dist/lib/connection_manager.js.map +1 -1
  20. package/dist/lib/filter/index.d.ts +1 -1
  21. package/dist/lib/filter/index.js +144 -82
  22. package/dist/lib/filter/index.js.map +1 -1
  23. package/dist/lib/filterPeers.d.ts +8 -5
  24. package/dist/lib/filterPeers.js +12 -5
  25. package/dist/lib/filterPeers.js.map +1 -1
  26. package/dist/lib/keep_alive_manager.d.ts +2 -3
  27. package/dist/lib/keep_alive_manager.js.map +1 -1
  28. package/dist/lib/light_push/index.d.ts +12 -2
  29. package/dist/lib/light_push/index.js +80 -80
  30. package/dist/lib/light_push/index.js.map +1 -1
  31. package/dist/lib/message/version_0.js +1 -1
  32. package/dist/lib/message/version_0.js.map +1 -1
  33. package/dist/lib/metadata/index.d.ts +2 -2
  34. package/dist/lib/metadata/index.js +58 -16
  35. package/dist/lib/metadata/index.js.map +1 -1
  36. package/dist/lib/predefined_bootstrap_nodes.d.ts +11 -11
  37. package/dist/lib/predefined_bootstrap_nodes.js +16 -16
  38. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
  39. package/dist/lib/store/history_rpc.js +1 -1
  40. package/dist/lib/store/history_rpc.js.map +1 -1
  41. package/dist/lib/store/index.d.ts +14 -6
  42. package/dist/lib/store/index.js +51 -235
  43. package/dist/lib/store/index.js.map +1 -1
  44. package/dist/lib/stream_manager.d.ts +2 -2
  45. package/dist/lib/stream_manager.js.map +1 -1
  46. package/dist/lib/wait_for_remote_peer.d.ts +1 -1
  47. package/dist/lib/wait_for_remote_peer.js +42 -10
  48. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  49. package/package.json +1 -127
  50. package/src/index.ts +3 -7
  51. package/src/lib/base_protocol.ts +57 -37
  52. package/src/lib/connection_manager.ts +17 -10
  53. package/src/lib/filter/index.ts +234 -136
  54. package/src/lib/filterPeers.ts +15 -7
  55. package/src/lib/keep_alive_manager.ts +2 -3
  56. package/src/lib/light_push/index.ts +104 -124
  57. package/src/lib/metadata/index.ts +92 -30
  58. package/src/lib/predefined_bootstrap_nodes.ts +22 -22
  59. package/src/lib/store/index.ts +79 -344
  60. package/src/lib/stream_manager.ts +2 -3
  61. package/src/lib/wait_for_remote_peer.ts +68 -12
  62. package/bundle/version_0-LQTFNC7k.js +0 -5008
  63. package/dist/lib/waku.d.ts +0 -57
  64. package/dist/lib/waku.js +0 -130
  65. package/dist/lib/waku.js.map +0 -1
  66. package/src/lib/waku.ts +0 -214
@@ -1,795 +1,622 @@
1
+ function coerce(o) {
2
+ if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array')
3
+ return o;
4
+ if (o instanceof ArrayBuffer)
5
+ return new Uint8Array(o);
6
+ if (ArrayBuffer.isView(o)) {
7
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
8
+ }
9
+ throw new Error('Unknown type, must be binary type');
10
+ }
11
+ function fromString(str) {
12
+ return new TextEncoder().encode(str);
13
+ }
14
+ function toString(b) {
15
+ return new TextDecoder().decode(b);
16
+ }
17
+
18
+ /* eslint-disable */
1
19
  // base-x encoding / decoding
2
20
  // Copyright (c) 2018 base-x contributors
3
21
  // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
4
22
  // Distributed under the MIT software license, see the accompanying
5
23
  // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
6
- function base (ALPHABET, name) {
7
- if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
8
- var BASE_MAP = new Uint8Array(256);
9
- for (var j = 0; j < BASE_MAP.length; j++) {
10
- BASE_MAP[j] = 255;
11
- }
12
- for (var i = 0; i < ALPHABET.length; i++) {
13
- var x = ALPHABET.charAt(i);
14
- var xc = x.charCodeAt(0);
15
- if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
16
- BASE_MAP[xc] = i;
17
- }
18
- var BASE = ALPHABET.length;
19
- var LEADER = ALPHABET.charAt(0);
20
- var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
21
- var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
22
- function encode (source) {
23
- if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
24
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
25
- } else if (Array.isArray(source)) {
26
- source = Uint8Array.from(source);
24
+ /**
25
+ * @param {string} ALPHABET
26
+ * @param {any} name
27
+ */
28
+ function base(ALPHABET, name) {
29
+ if (ALPHABET.length >= 255) {
30
+ throw new TypeError('Alphabet too long');
27
31
  }
28
- if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
29
- if (source.length === 0) { return '' }
30
- // Skip & count leading zeroes.
31
- var zeroes = 0;
32
- var length = 0;
33
- var pbegin = 0;
34
- var pend = source.length;
35
- while (pbegin !== pend && source[pbegin] === 0) {
36
- pbegin++;
37
- zeroes++;
32
+ var BASE_MAP = new Uint8Array(256);
33
+ for (var j = 0; j < BASE_MAP.length; j++) {
34
+ BASE_MAP[j] = 255;
35
+ }
36
+ for (var i = 0; i < ALPHABET.length; i++) {
37
+ var x = ALPHABET.charAt(i);
38
+ var xc = x.charCodeAt(0);
39
+ if (BASE_MAP[xc] !== 255) {
40
+ throw new TypeError(x + ' is ambiguous');
41
+ }
42
+ BASE_MAP[xc] = i;
38
43
  }
44
+ var BASE = ALPHABET.length;
45
+ var LEADER = ALPHABET.charAt(0);
46
+ var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
47
+ var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
48
+ /**
49
+ * @param {any[] | Iterable<number>} source
50
+ */
51
+ function encode(source) {
52
+ // @ts-ignore
53
+ if (source instanceof Uint8Array)
54
+ ;
55
+ else if (ArrayBuffer.isView(source)) {
56
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
57
+ }
58
+ else if (Array.isArray(source)) {
59
+ source = Uint8Array.from(source);
60
+ }
61
+ if (!(source instanceof Uint8Array)) {
62
+ throw new TypeError('Expected Uint8Array');
63
+ }
64
+ if (source.length === 0) {
65
+ return '';
66
+ }
67
+ // Skip & count leading zeroes.
68
+ var zeroes = 0;
69
+ var length = 0;
70
+ var pbegin = 0;
71
+ var pend = source.length;
72
+ while (pbegin !== pend && source[pbegin] === 0) {
73
+ pbegin++;
74
+ zeroes++;
75
+ }
39
76
  // Allocate enough space in big-endian base58 representation.
40
- var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
41
- var b58 = new Uint8Array(size);
77
+ var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
78
+ var b58 = new Uint8Array(size);
42
79
  // Process the bytes.
43
- while (pbegin !== pend) {
44
- var carry = source[pbegin];
80
+ while (pbegin !== pend) {
81
+ var carry = source[pbegin];
45
82
  // Apply "b58 = b58 * 256 + ch".
46
- var i = 0;
47
- for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
48
- carry += (256 * b58[it1]) >>> 0;
49
- b58[it1] = (carry % BASE) >>> 0;
50
- carry = (carry / BASE) >>> 0;
51
- }
52
- if (carry !== 0) { throw new Error('Non-zero carry') }
53
- length = i;
54
- pbegin++;
55
- }
83
+ var i = 0;
84
+ for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
85
+ carry += (256 * b58[it1]) >>> 0;
86
+ b58[it1] = (carry % BASE) >>> 0;
87
+ carry = (carry / BASE) >>> 0;
88
+ }
89
+ if (carry !== 0) {
90
+ throw new Error('Non-zero carry');
91
+ }
92
+ length = i;
93
+ pbegin++;
94
+ }
56
95
  // Skip leading zeroes in base58 result.
57
- var it2 = size - length;
58
- while (it2 !== size && b58[it2] === 0) {
59
- it2++;
60
- }
96
+ var it2 = size - length;
97
+ while (it2 !== size && b58[it2] === 0) {
98
+ it2++;
99
+ }
61
100
  // Translate the result into a string.
62
- var str = LEADER.repeat(zeroes);
63
- for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
64
- return str
65
- }
66
- function decodeUnsafe (source) {
67
- if (typeof source !== 'string') { throw new TypeError('Expected String') }
68
- if (source.length === 0) { return new Uint8Array() }
69
- var psz = 0;
101
+ var str = LEADER.repeat(zeroes);
102
+ for (; it2 < size; ++it2) {
103
+ str += ALPHABET.charAt(b58[it2]);
104
+ }
105
+ return str;
106
+ }
107
+ /**
108
+ * @param {string | string[]} source
109
+ */
110
+ function decodeUnsafe(source) {
111
+ if (typeof source !== 'string') {
112
+ throw new TypeError('Expected String');
113
+ }
114
+ if (source.length === 0) {
115
+ return new Uint8Array();
116
+ }
117
+ var psz = 0;
70
118
  // Skip leading spaces.
71
- if (source[psz] === ' ') { return }
119
+ if (source[psz] === ' ') {
120
+ return;
121
+ }
72
122
  // Skip and count leading '1's.
73
- var zeroes = 0;
74
- var length = 0;
75
- while (source[psz] === LEADER) {
76
- zeroes++;
77
- psz++;
78
- }
123
+ var zeroes = 0;
124
+ var length = 0;
125
+ while (source[psz] === LEADER) {
126
+ zeroes++;
127
+ psz++;
128
+ }
79
129
  // Allocate enough space in big-endian base256 representation.
80
- var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
81
- var b256 = new Uint8Array(size);
130
+ var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
131
+ var b256 = new Uint8Array(size);
82
132
  // Process the characters.
83
- while (source[psz]) {
133
+ while (source[psz]) {
84
134
  // Decode character
85
- var carry = BASE_MAP[source.charCodeAt(psz)];
135
+ var carry = BASE_MAP[source.charCodeAt(psz)];
86
136
  // Invalid character
87
- if (carry === 255) { return }
88
- var i = 0;
89
- for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
90
- carry += (BASE * b256[it3]) >>> 0;
91
- b256[it3] = (carry % 256) >>> 0;
92
- carry = (carry / 256) >>> 0;
93
- }
94
- if (carry !== 0) { throw new Error('Non-zero carry') }
95
- length = i;
96
- psz++;
97
- }
137
+ if (carry === 255) {
138
+ return;
139
+ }
140
+ var i = 0;
141
+ for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
142
+ carry += (BASE * b256[it3]) >>> 0;
143
+ b256[it3] = (carry % 256) >>> 0;
144
+ carry = (carry / 256) >>> 0;
145
+ }
146
+ if (carry !== 0) {
147
+ throw new Error('Non-zero carry');
148
+ }
149
+ length = i;
150
+ psz++;
151
+ }
98
152
  // Skip trailing spaces.
99
- if (source[psz] === ' ') { return }
153
+ if (source[psz] === ' ') {
154
+ return;
155
+ }
100
156
  // Skip leading zeroes in b256.
101
- var it4 = size - length;
102
- while (it4 !== size && b256[it4] === 0) {
103
- it4++;
157
+ var it4 = size - length;
158
+ while (it4 !== size && b256[it4] === 0) {
159
+ it4++;
160
+ }
161
+ var vch = new Uint8Array(zeroes + (size - it4));
162
+ var j = zeroes;
163
+ while (it4 !== size) {
164
+ vch[j++] = b256[it4++];
165
+ }
166
+ return vch;
104
167
  }
105
- var vch = new Uint8Array(zeroes + (size - it4));
106
- var j = zeroes;
107
- while (it4 !== size) {
108
- vch[j++] = b256[it4++];
168
+ /**
169
+ * @param {string | string[]} string
170
+ */
171
+ function decode(string) {
172
+ var buffer = decodeUnsafe(string);
173
+ if (buffer) {
174
+ return buffer;
175
+ }
176
+ throw new Error(`Non-${name} character`);
109
177
  }
110
- return vch
111
- }
112
- function decode (string) {
113
- var buffer = decodeUnsafe(string);
114
- if (buffer) { return buffer }
115
- throw new Error(`Non-${name} character`)
116
- }
117
- return {
118
- encode: encode,
119
- decodeUnsafe: decodeUnsafe,
120
- decode: decode
121
- }
178
+ return {
179
+ encode: encode,
180
+ decodeUnsafe: decodeUnsafe,
181
+ decode: decode
182
+ };
122
183
  }
123
184
  var src = base;
124
-
125
185
  var _brrp__multiformats_scope_baseX = src;
126
186
 
127
- /**
128
- * @param {Uint8Array} aa
129
- * @param {Uint8Array} bb
130
- */
131
- const equals = (aa, bb) => {
132
- if (aa === bb) return true
133
- if (aa.byteLength !== bb.byteLength) {
134
- return false
135
- }
136
-
137
- for (let ii = 0; ii < aa.byteLength; ii++) {
138
- if (aa[ii] !== bb[ii]) {
139
- return false
140
- }
141
- }
142
-
143
- return true
144
- };
145
-
146
- /**
147
- * @param {ArrayBufferView|ArrayBuffer|Uint8Array} o
148
- * @returns {Uint8Array}
149
- */
150
- const coerce = o => {
151
- if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array') return o
152
- if (o instanceof ArrayBuffer) return new Uint8Array(o)
153
- if (ArrayBuffer.isView(o)) {
154
- return new Uint8Array(o.buffer, o.byteOffset, o.byteLength)
155
- }
156
- throw new Error('Unknown type, must be binary type')
157
- };
158
-
159
- /**
160
- * @param {string} str
161
- * @returns {Uint8Array}
162
- */
163
- const fromString = str => (new TextEncoder()).encode(str);
164
-
165
- /**
166
- * @param {Uint8Array} b
167
- * @returns {string}
168
- */
169
- const toString = b => (new TextDecoder()).decode(b);
170
-
171
187
  /**
172
188
  * Class represents both BaseEncoder and MultibaseEncoder meaning it
173
189
  * can be used to encode to multibase or base encode without multibase
174
190
  * prefix.
175
- *
176
- * @class
177
- * @template {string} Base
178
- * @template {string} Prefix
179
- * @implements {API.MultibaseEncoder<Prefix>}
180
- * @implements {API.BaseEncoder}
181
191
  */
182
192
  class Encoder {
183
- /**
184
- * @param {Base} name
185
- * @param {Prefix} prefix
186
- * @param {(bytes:Uint8Array) => string} baseEncode
187
- */
188
- constructor (name, prefix, baseEncode) {
189
- this.name = name;
190
- this.prefix = prefix;
191
- this.baseEncode = baseEncode;
192
- }
193
-
194
- /**
195
- * @param {Uint8Array} bytes
196
- * @returns {API.Multibase<Prefix>}
197
- */
198
- encode (bytes) {
199
- if (bytes instanceof Uint8Array) {
200
- return `${this.prefix}${this.baseEncode(bytes)}`
201
- } else {
202
- throw Error('Unknown type, must be binary type')
193
+ name;
194
+ prefix;
195
+ baseEncode;
196
+ constructor(name, prefix, baseEncode) {
197
+ this.name = name;
198
+ this.prefix = prefix;
199
+ this.baseEncode = baseEncode;
200
+ }
201
+ encode(bytes) {
202
+ if (bytes instanceof Uint8Array) {
203
+ return `${this.prefix}${this.baseEncode(bytes)}`;
204
+ }
205
+ else {
206
+ throw Error('Unknown type, must be binary type');
207
+ }
203
208
  }
204
- }
205
209
  }
206
-
207
- /**
208
- * @template {string} Prefix
209
- */
210
210
  /**
211
211
  * Class represents both BaseDecoder and MultibaseDecoder so it could be used
212
212
  * to decode multibases (with matching prefix) or just base decode strings
213
213
  * with corresponding base encoding.
214
- *
215
- * @class
216
- * @template {string} Base
217
- * @template {string} Prefix
218
- * @implements {API.MultibaseDecoder<Prefix>}
219
- * @implements {API.UnibaseDecoder<Prefix>}
220
- * @implements {API.BaseDecoder}
221
214
  */
222
215
  class Decoder {
223
- /**
224
- * @param {Base} name
225
- * @param {Prefix} prefix
226
- * @param {(text:string) => Uint8Array} baseDecode
227
- */
228
- constructor (name, prefix, baseDecode) {
229
- this.name = name;
230
- this.prefix = prefix;
231
- /* c8 ignore next 3 */
232
- if (prefix.codePointAt(0) === undefined) {
233
- throw new Error('Invalid prefix character')
216
+ name;
217
+ prefix;
218
+ baseDecode;
219
+ prefixCodePoint;
220
+ constructor(name, prefix, baseDecode) {
221
+ this.name = name;
222
+ this.prefix = prefix;
223
+ /* c8 ignore next 3 */
224
+ if (prefix.codePointAt(0) === undefined) {
225
+ throw new Error('Invalid prefix character');
226
+ }
227
+ this.prefixCodePoint = prefix.codePointAt(0);
228
+ this.baseDecode = baseDecode;
234
229
  }
235
- /** @private */
236
- this.prefixCodePoint = /** @type {number} */ (prefix.codePointAt(0));
237
- this.baseDecode = baseDecode;
238
- }
239
-
240
- /**
241
- * @param {string} text
242
- */
243
- decode (text) {
244
- if (typeof text === 'string') {
245
- if (text.codePointAt(0) !== this.prefixCodePoint) {
246
- throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`)
247
- }
248
- return this.baseDecode(text.slice(this.prefix.length))
249
- } else {
250
- throw Error('Can only multibase decode strings')
230
+ decode(text) {
231
+ if (typeof text === 'string') {
232
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
233
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
234
+ }
235
+ return this.baseDecode(text.slice(this.prefix.length));
236
+ }
237
+ else {
238
+ throw Error('Can only multibase decode strings');
239
+ }
240
+ }
241
+ or(decoder) {
242
+ return or(this, decoder);
251
243
  }
252
- }
253
-
254
- /**
255
- * @template {string} OtherPrefix
256
- * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
257
- * @returns {ComposedDecoder<Prefix|OtherPrefix>}
258
- */
259
- or (decoder) {
260
- return or(this, decoder)
261
- }
262
244
  }
263
-
264
- /**
265
- * @template {string} Prefix
266
- * @typedef {Record<Prefix, API.UnibaseDecoder<Prefix>>} Decoders
267
- */
268
-
269
- /**
270
- * @template {string} Prefix
271
- * @implements {API.MultibaseDecoder<Prefix>}
272
- * @implements {API.CombobaseDecoder<Prefix>}
273
- */
274
245
  class ComposedDecoder {
275
- /**
276
- * @param {Decoders<Prefix>} decoders
277
- */
278
- constructor (decoders) {
279
- this.decoders = decoders;
280
- }
281
-
282
- /**
283
- * @template {string} OtherPrefix
284
- * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
285
- * @returns {ComposedDecoder<Prefix|OtherPrefix>}
286
- */
287
- or (decoder) {
288
- return or(this, decoder)
289
- }
290
-
291
- /**
292
- * @param {string} input
293
- * @returns {Uint8Array}
294
- */
295
- decode (input) {
296
- const prefix = /** @type {Prefix} */ (input[0]);
297
- const decoder = this.decoders[prefix];
298
- if (decoder) {
299
- return decoder.decode(input)
300
- } else {
301
- throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)
246
+ decoders;
247
+ constructor(decoders) {
248
+ this.decoders = decoders;
249
+ }
250
+ or(decoder) {
251
+ return or(this, decoder);
252
+ }
253
+ decode(input) {
254
+ const prefix = input[0];
255
+ const decoder = this.decoders[prefix];
256
+ if (decoder != null) {
257
+ return decoder.decode(input);
258
+ }
259
+ else {
260
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
261
+ }
302
262
  }
303
- }
304
263
  }
305
-
306
- /**
307
- * @template {string} L
308
- * @template {string} R
309
- * @param {API.UnibaseDecoder<L>|API.CombobaseDecoder<L>} left
310
- * @param {API.UnibaseDecoder<R>|API.CombobaseDecoder<R>} right
311
- * @returns {ComposedDecoder<L|R>}
312
- */
313
- const or = (left, right) => new ComposedDecoder(/** @type {Decoders<L|R>} */({
314
- ...(left.decoders || { [/** @type API.UnibaseDecoder<L> */(left).prefix]: left }),
315
- ...(right.decoders || { [/** @type API.UnibaseDecoder<R> */(right).prefix]: right })
316
- }));
317
-
318
- /**
319
- * @class
320
- * @template {string} Base
321
- * @template {string} Prefix
322
- * @implements {API.MultibaseCodec<Prefix>}
323
- * @implements {API.MultibaseEncoder<Prefix>}
324
- * @implements {API.MultibaseDecoder<Prefix>}
325
- * @implements {API.BaseCodec}
326
- * @implements {API.BaseEncoder}
327
- * @implements {API.BaseDecoder}
328
- */
264
+ function or(left, right) {
265
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
266
+ return new ComposedDecoder({
267
+ ...(left.decoders ?? { [left.prefix]: left }),
268
+ ...(right.decoders ?? { [right.prefix]: right })
269
+ });
270
+ }
329
271
  class Codec {
330
- /**
331
- * @param {Base} name
332
- * @param {Prefix} prefix
333
- * @param {(bytes:Uint8Array) => string} baseEncode
334
- * @param {(text:string) => Uint8Array} baseDecode
335
- */
336
- constructor (name, prefix, baseEncode, baseDecode) {
337
- this.name = name;
338
- this.prefix = prefix;
339
- this.baseEncode = baseEncode;
340
- this.baseDecode = baseDecode;
341
- this.encoder = new Encoder(name, prefix, baseEncode);
342
- this.decoder = new Decoder(name, prefix, baseDecode);
343
- }
344
-
345
- /**
346
- * @param {Uint8Array} input
347
- */
348
- encode (input) {
349
- return this.encoder.encode(input)
350
- }
351
-
352
- /**
353
- * @param {string} input
354
- */
355
- decode (input) {
356
- return this.decoder.decode(input)
357
- }
272
+ name;
273
+ prefix;
274
+ baseEncode;
275
+ baseDecode;
276
+ encoder;
277
+ decoder;
278
+ constructor(name, prefix, baseEncode, baseDecode) {
279
+ this.name = name;
280
+ this.prefix = prefix;
281
+ this.baseEncode = baseEncode;
282
+ this.baseDecode = baseDecode;
283
+ this.encoder = new Encoder(name, prefix, baseEncode);
284
+ this.decoder = new Decoder(name, prefix, baseDecode);
285
+ }
286
+ encode(input) {
287
+ return this.encoder.encode(input);
288
+ }
289
+ decode(input) {
290
+ return this.decoder.decode(input);
291
+ }
358
292
  }
359
-
360
- /**
361
- * @template {string} Base
362
- * @template {string} Prefix
363
- * @param {object} options
364
- * @param {Base} options.name
365
- * @param {Prefix} options.prefix
366
- * @param {(bytes:Uint8Array) => string} options.encode
367
- * @param {(input:string) => Uint8Array} options.decode
368
- * @returns {Codec<Base, Prefix>}
369
- */
370
- const from = ({ name, prefix, encode, decode }) =>
371
- new Codec(name, prefix, encode, decode);
372
-
373
- /**
374
- * @template {string} Base
375
- * @template {string} Prefix
376
- * @param {object} options
377
- * @param {Base} options.name
378
- * @param {Prefix} options.prefix
379
- * @param {string} options.alphabet
380
- * @returns {Codec<Base, Prefix>}
381
- */
382
- const baseX = ({ prefix, name, alphabet }) => {
383
- const { encode, decode } = _brrp__multiformats_scope_baseX(alphabet, name);
384
- return from({
385
- prefix,
386
- name,
387
- encode,
388
- /**
389
- * @param {string} text
390
- */
391
- decode: text => coerce(decode(text))
392
- })
393
- };
394
-
395
- /**
396
- * @param {string} string
397
- * @param {string} alphabet
398
- * @param {number} bitsPerChar
399
- * @param {string} name
400
- * @returns {Uint8Array}
401
- */
402
- const decode$1 = (string, alphabet, bitsPerChar, name) => {
403
- // Build the character lookup table:
404
- /** @type {Record<string, number>} */
405
- const codes = {};
406
- for (let i = 0; i < alphabet.length; ++i) {
407
- codes[alphabet[i]] = i;
408
- }
409
-
410
- // Count the padding bytes:
411
- let end = string.length;
412
- while (string[end - 1] === '=') {
413
- --end;
414
- }
415
-
416
- // Allocate the output:
417
- const out = new Uint8Array((end * bitsPerChar / 8) | 0);
418
-
419
- // Parse the data:
420
- let bits = 0; // Number of bits currently in the buffer
421
- let buffer = 0; // Bits waiting to be written out, MSB first
422
- let written = 0; // Next byte to write
423
- for (let i = 0; i < end; ++i) {
424
- // Read one character from the string:
425
- const value = codes[string[i]];
426
- if (value === undefined) {
427
- throw new SyntaxError(`Non-${name} character`)
293
+ function from({ name, prefix, encode, decode }) {
294
+ return new Codec(name, prefix, encode, decode);
295
+ }
296
+ function baseX({ name, prefix, alphabet }) {
297
+ const { encode, decode } = _brrp__multiformats_scope_baseX(alphabet, name);
298
+ return from({
299
+ prefix,
300
+ name,
301
+ encode,
302
+ decode: (text) => coerce(decode(text))
303
+ });
304
+ }
305
+ function decode$1(string, alphabet, bitsPerChar, name) {
306
+ // Build the character lookup table:
307
+ const codes = {};
308
+ for (let i = 0; i < alphabet.length; ++i) {
309
+ codes[alphabet[i]] = i;
428
310
  }
429
-
430
- // Append the bits to the buffer:
431
- buffer = (buffer << bitsPerChar) | value;
432
- bits += bitsPerChar;
433
-
434
- // Write out some bits if the buffer has a byte's worth:
435
- if (bits >= 8) {
436
- bits -= 8;
437
- out[written++] = 0xff & (buffer >> bits);
311
+ // Count the padding bytes:
312
+ let end = string.length;
313
+ while (string[end - 1] === '=') {
314
+ --end;
438
315
  }
439
- }
440
-
441
- // Verify that we have received just enough bits:
442
- if (bits >= bitsPerChar || 0xff & (buffer << (8 - bits))) {
443
- throw new SyntaxError('Unexpected end of data')
444
- }
445
-
446
- return out
447
- };
448
-
449
- /**
450
- * @param {Uint8Array} data
451
- * @param {string} alphabet
452
- * @param {number} bitsPerChar
453
- * @returns {string}
454
- */
455
- const encode$1 = (data, alphabet, bitsPerChar) => {
456
- const pad = alphabet[alphabet.length - 1] === '=';
457
- const mask = (1 << bitsPerChar) - 1;
458
- let out = '';
459
-
460
- let bits = 0; // Number of bits currently in the buffer
461
- let buffer = 0; // Bits waiting to be written out, MSB first
462
- for (let i = 0; i < data.length; ++i) {
463
- // Slurp data into the buffer:
464
- buffer = (buffer << 8) | data[i];
465
- bits += 8;
466
-
467
- // Write out as much as we can:
468
- while (bits > bitsPerChar) {
469
- bits -= bitsPerChar;
470
- out += alphabet[mask & (buffer >> bits)];
316
+ // Allocate the output:
317
+ const out = new Uint8Array((end * bitsPerChar / 8) | 0);
318
+ // Parse the data:
319
+ let bits = 0; // Number of bits currently in the buffer
320
+ let buffer = 0; // Bits waiting to be written out, MSB first
321
+ let written = 0; // Next byte to write
322
+ for (let i = 0; i < end; ++i) {
323
+ // Read one character from the string:
324
+ const value = codes[string[i]];
325
+ if (value === undefined) {
326
+ throw new SyntaxError(`Non-${name} character`);
327
+ }
328
+ // Append the bits to the buffer:
329
+ buffer = (buffer << bitsPerChar) | value;
330
+ bits += bitsPerChar;
331
+ // Write out some bits if the buffer has a byte's worth:
332
+ if (bits >= 8) {
333
+ bits -= 8;
334
+ out[written++] = 0xff & (buffer >> bits);
335
+ }
471
336
  }
472
- }
473
-
474
- // Partial character:
475
- if (bits) {
476
- out += alphabet[mask & (buffer << (bitsPerChar - bits))];
477
- }
478
-
479
- // Add padding characters until we hit a byte boundary:
480
- if (pad) {
481
- while ((out.length * bitsPerChar) & 7) {
482
- out += '=';
337
+ // Verify that we have received just enough bits:
338
+ if (bits >= bitsPerChar || (0xff & (buffer << (8 - bits))) !== 0) {
339
+ throw new SyntaxError('Unexpected end of data');
483
340
  }
484
- }
485
-
486
- return out
487
- };
488
-
341
+ return out;
342
+ }
343
+ function encode$1(data, alphabet, bitsPerChar) {
344
+ const pad = alphabet[alphabet.length - 1] === '=';
345
+ const mask = (1 << bitsPerChar) - 1;
346
+ let out = '';
347
+ let bits = 0; // Number of bits currently in the buffer
348
+ let buffer = 0; // Bits waiting to be written out, MSB first
349
+ for (let i = 0; i < data.length; ++i) {
350
+ // Slurp data into the buffer:
351
+ buffer = (buffer << 8) | data[i];
352
+ bits += 8;
353
+ // Write out as much as we can:
354
+ while (bits > bitsPerChar) {
355
+ bits -= bitsPerChar;
356
+ out += alphabet[mask & (buffer >> bits)];
357
+ }
358
+ }
359
+ // Partial character:
360
+ if (bits !== 0) {
361
+ out += alphabet[mask & (buffer << (bitsPerChar - bits))];
362
+ }
363
+ // Add padding characters until we hit a byte boundary:
364
+ if (pad) {
365
+ while (((out.length * bitsPerChar) & 7) !== 0) {
366
+ out += '=';
367
+ }
368
+ }
369
+ return out;
370
+ }
489
371
  /**
490
372
  * RFC4648 Factory
491
- *
492
- * @template {string} Base
493
- * @template {string} Prefix
494
- * @param {object} options
495
- * @param {Base} options.name
496
- * @param {Prefix} options.prefix
497
- * @param {string} options.alphabet
498
- * @param {number} options.bitsPerChar
499
373
  */
500
- const rfc4648 = ({ name, prefix, bitsPerChar, alphabet }) => {
501
- return from({
502
- prefix,
503
- name,
504
- encode (input) {
505
- return encode$1(input, alphabet, bitsPerChar)
506
- },
507
- decode (input) {
508
- return decode$1(input, alphabet, bitsPerChar, name)
509
- }
510
- })
511
- };
512
-
513
- const base58btc = baseX({
514
- name: 'base58btc',
515
- prefix: 'z',
516
- alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
517
- });
518
-
519
- const base58flickr = baseX({
520
- name: 'base58flickr',
521
- prefix: 'Z',
522
- alphabet: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
523
- });
524
-
525
- var base58 = /*#__PURE__*/Object.freeze({
526
- __proto__: null,
527
- base58btc: base58btc,
528
- base58flickr: base58flickr
529
- });
530
-
531
- const base32 = rfc4648({
532
- prefix: 'b',
533
- name: 'base32',
534
- alphabet: 'abcdefghijklmnopqrstuvwxyz234567',
535
- bitsPerChar: 5
536
- });
537
-
538
- const base32upper = rfc4648({
539
- prefix: 'B',
540
- name: 'base32upper',
541
- alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
542
- bitsPerChar: 5
543
- });
544
-
545
- const base32pad = rfc4648({
546
- prefix: 'c',
547
- name: 'base32pad',
548
- alphabet: 'abcdefghijklmnopqrstuvwxyz234567=',
549
- bitsPerChar: 5
550
- });
551
-
552
- const base32padupper = rfc4648({
553
- prefix: 'C',
554
- name: 'base32padupper',
555
- alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=',
556
- bitsPerChar: 5
557
- });
558
-
559
- const base32hex = rfc4648({
560
- prefix: 'v',
561
- name: 'base32hex',
562
- alphabet: '0123456789abcdefghijklmnopqrstuv',
563
- bitsPerChar: 5
564
- });
565
-
566
- const base32hexupper = rfc4648({
567
- prefix: 'V',
568
- name: 'base32hexupper',
569
- alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
570
- bitsPerChar: 5
571
- });
572
-
573
- const base32hexpad = rfc4648({
574
- prefix: 't',
575
- name: 'base32hexpad',
576
- alphabet: '0123456789abcdefghijklmnopqrstuv=',
577
- bitsPerChar: 5
578
- });
579
-
580
- const base32hexpadupper = rfc4648({
581
- prefix: 'T',
582
- name: 'base32hexpadupper',
583
- alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV=',
584
- bitsPerChar: 5
585
- });
586
-
587
- const base32z = rfc4648({
588
- prefix: 'h',
589
- name: 'base32z',
590
- alphabet: 'ybndrfg8ejkmcpqxot1uwisza345h769',
591
- bitsPerChar: 5
592
- });
593
-
594
- var base32$1 = /*#__PURE__*/Object.freeze({
595
- __proto__: null,
596
- base32: base32,
597
- base32hex: base32hex,
598
- base32hexpad: base32hexpad,
599
- base32hexpadupper: base32hexpadupper,
600
- base32hexupper: base32hexupper,
601
- base32pad: base32pad,
602
- base32padupper: base32padupper,
603
- base32upper: base32upper,
604
- base32z: base32z
605
- });
374
+ function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
375
+ return from({
376
+ prefix,
377
+ name,
378
+ encode(input) {
379
+ return encode$1(input, alphabet, bitsPerChar);
380
+ },
381
+ decode(input) {
382
+ return decode$1(input, alphabet, bitsPerChar, name);
383
+ }
384
+ });
385
+ }
606
386
 
607
387
  const base10 = baseX({
608
- prefix: '9',
609
- name: 'base10',
610
- alphabet: '0123456789'
388
+ prefix: '9',
389
+ name: 'base10',
390
+ alphabet: '0123456789'
611
391
  });
612
392
 
613
393
  var base10$1 = /*#__PURE__*/Object.freeze({
614
- __proto__: null,
615
- base10: base10
394
+ __proto__: null,
395
+ base10: base10
616
396
  });
617
397
 
618
- // @ts-check
619
-
620
-
621
398
  const base16 = rfc4648({
622
- prefix: 'f',
623
- name: 'base16',
624
- alphabet: '0123456789abcdef',
625
- bitsPerChar: 4
399
+ prefix: 'f',
400
+ name: 'base16',
401
+ alphabet: '0123456789abcdef',
402
+ bitsPerChar: 4
626
403
  });
627
-
628
404
  const base16upper = rfc4648({
629
- prefix: 'F',
630
- name: 'base16upper',
631
- alphabet: '0123456789ABCDEF',
632
- bitsPerChar: 4
405
+ prefix: 'F',
406
+ name: 'base16upper',
407
+ alphabet: '0123456789ABCDEF',
408
+ bitsPerChar: 4
633
409
  });
634
410
 
635
411
  var base16$1 = /*#__PURE__*/Object.freeze({
636
- __proto__: null,
637
- base16: base16,
638
- base16upper: base16upper
412
+ __proto__: null,
413
+ base16: base16,
414
+ base16upper: base16upper
639
415
  });
640
416
 
641
- // @ts-check
642
-
643
-
644
417
  const base2 = rfc4648({
645
- prefix: '0',
646
- name: 'base2',
647
- alphabet: '01',
648
- bitsPerChar: 1
418
+ prefix: '0',
419
+ name: 'base2',
420
+ alphabet: '01',
421
+ bitsPerChar: 1
649
422
  });
650
423
 
651
424
  var base2$1 = /*#__PURE__*/Object.freeze({
652
- __proto__: null,
653
- base2: base2
425
+ __proto__: null,
426
+ base2: base2
654
427
  });
655
428
 
656
429
  const alphabet = Array.from('🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂');
657
- const alphabetBytesToChars = /** @type {string[]} */ (alphabet.reduce((p, c, i) => { p[i] = c; return p }, /** @type {string[]} */([])));
658
- const alphabetCharsToBytes = /** @type {number[]} */ (alphabet.reduce((p, c, i) => { p[/** @type {number} */ (c.codePointAt(0))] = i; return p }, /** @type {number[]} */([])));
659
-
660
- /**
661
- * @param {Uint8Array} data
662
- * @returns {string}
663
- */
664
- function encode (data) {
665
- return data.reduce((p, c) => {
666
- p += alphabetBytesToChars[c];
667
- return p
668
- }, '')
430
+ const alphabetBytesToChars = (alphabet.reduce((p, c, i) => { p[i] = c; return p; }, ([])));
431
+ const alphabetCharsToBytes = (alphabet.reduce((p, c, i) => { p[c.codePointAt(0)] = i; return p; }, ([])));
432
+ function encode(data) {
433
+ return data.reduce((p, c) => {
434
+ p += alphabetBytesToChars[c];
435
+ return p;
436
+ }, '');
669
437
  }
670
-
671
- /**
672
- * @param {string} str
673
- * @returns {Uint8Array}
674
- */
675
- function decode (str) {
676
- const byts = [];
677
- for (const char of str) {
678
- const byt = alphabetCharsToBytes[/** @type {number} */ (char.codePointAt(0))];
679
- if (byt === undefined) {
680
- throw new Error(`Non-base256emoji character: ${char}`)
438
+ function decode(str) {
439
+ const byts = [];
440
+ for (const char of str) {
441
+ const byt = alphabetCharsToBytes[char.codePointAt(0)];
442
+ if (byt === undefined) {
443
+ throw new Error(`Non-base256emoji character: ${char}`);
444
+ }
445
+ byts.push(byt);
681
446
  }
682
- byts.push(byt);
683
- }
684
- return new Uint8Array(byts)
447
+ return new Uint8Array(byts);
685
448
  }
686
-
687
449
  const base256emoji = from({
688
- prefix: '🚀',
689
- name: 'base256emoji',
690
- encode,
691
- decode
450
+ prefix: '🚀',
451
+ name: 'base256emoji',
452
+ encode,
453
+ decode
692
454
  });
693
455
 
694
456
  var base256emoji$1 = /*#__PURE__*/Object.freeze({
695
- __proto__: null,
696
- base256emoji: base256emoji
457
+ __proto__: null,
458
+ base256emoji: base256emoji
697
459
  });
698
460
 
699
- const base36 = baseX({
700
- prefix: 'k',
701
- name: 'base36',
702
- alphabet: '0123456789abcdefghijklmnopqrstuvwxyz'
461
+ const base32 = rfc4648({
462
+ prefix: 'b',
463
+ name: 'base32',
464
+ alphabet: 'abcdefghijklmnopqrstuvwxyz234567',
465
+ bitsPerChar: 5
466
+ });
467
+ const base32upper = rfc4648({
468
+ prefix: 'B',
469
+ name: 'base32upper',
470
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
471
+ bitsPerChar: 5
472
+ });
473
+ const base32pad = rfc4648({
474
+ prefix: 'c',
475
+ name: 'base32pad',
476
+ alphabet: 'abcdefghijklmnopqrstuvwxyz234567=',
477
+ bitsPerChar: 5
478
+ });
479
+ const base32padupper = rfc4648({
480
+ prefix: 'C',
481
+ name: 'base32padupper',
482
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=',
483
+ bitsPerChar: 5
484
+ });
485
+ const base32hex = rfc4648({
486
+ prefix: 'v',
487
+ name: 'base32hex',
488
+ alphabet: '0123456789abcdefghijklmnopqrstuv',
489
+ bitsPerChar: 5
490
+ });
491
+ const base32hexupper = rfc4648({
492
+ prefix: 'V',
493
+ name: 'base32hexupper',
494
+ alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
495
+ bitsPerChar: 5
496
+ });
497
+ const base32hexpad = rfc4648({
498
+ prefix: 't',
499
+ name: 'base32hexpad',
500
+ alphabet: '0123456789abcdefghijklmnopqrstuv=',
501
+ bitsPerChar: 5
502
+ });
503
+ const base32hexpadupper = rfc4648({
504
+ prefix: 'T',
505
+ name: 'base32hexpadupper',
506
+ alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV=',
507
+ bitsPerChar: 5
508
+ });
509
+ const base32z = rfc4648({
510
+ prefix: 'h',
511
+ name: 'base32z',
512
+ alphabet: 'ybndrfg8ejkmcpqxot1uwisza345h769',
513
+ bitsPerChar: 5
514
+ });
515
+
516
+ var base32$1 = /*#__PURE__*/Object.freeze({
517
+ __proto__: null,
518
+ base32: base32,
519
+ base32hex: base32hex,
520
+ base32hexpad: base32hexpad,
521
+ base32hexpadupper: base32hexpadupper,
522
+ base32hexupper: base32hexupper,
523
+ base32pad: base32pad,
524
+ base32padupper: base32padupper,
525
+ base32upper: base32upper,
526
+ base32z: base32z
703
527
  });
704
528
 
529
+ const base36 = baseX({
530
+ prefix: 'k',
531
+ name: 'base36',
532
+ alphabet: '0123456789abcdefghijklmnopqrstuvwxyz'
533
+ });
705
534
  const base36upper = baseX({
706
- prefix: 'K',
707
- name: 'base36upper',
708
- alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
535
+ prefix: 'K',
536
+ name: 'base36upper',
537
+ alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
709
538
  });
710
539
 
711
540
  var base36$1 = /*#__PURE__*/Object.freeze({
712
- __proto__: null,
713
- base36: base36,
714
- base36upper: base36upper
541
+ __proto__: null,
542
+ base36: base36,
543
+ base36upper: base36upper
715
544
  });
716
545
 
717
- // @ts-check
546
+ const base58btc = baseX({
547
+ name: 'base58btc',
548
+ prefix: 'z',
549
+ alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
550
+ });
551
+ const base58flickr = baseX({
552
+ name: 'base58flickr',
553
+ prefix: 'Z',
554
+ alphabet: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
555
+ });
718
556
 
557
+ var base58 = /*#__PURE__*/Object.freeze({
558
+ __proto__: null,
559
+ base58btc: base58btc,
560
+ base58flickr: base58flickr
561
+ });
719
562
 
720
563
  const base64 = rfc4648({
721
- prefix: 'm',
722
- name: 'base64',
723
- alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
724
- bitsPerChar: 6
564
+ prefix: 'm',
565
+ name: 'base64',
566
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
567
+ bitsPerChar: 6
725
568
  });
726
-
727
569
  const base64pad = rfc4648({
728
- prefix: 'M',
729
- name: 'base64pad',
730
- alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
731
- bitsPerChar: 6
570
+ prefix: 'M',
571
+ name: 'base64pad',
572
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
573
+ bitsPerChar: 6
732
574
  });
733
-
734
575
  const base64url = rfc4648({
735
- prefix: 'u',
736
- name: 'base64url',
737
- alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
738
- bitsPerChar: 6
576
+ prefix: 'u',
577
+ name: 'base64url',
578
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
579
+ bitsPerChar: 6
739
580
  });
740
-
741
581
  const base64urlpad = rfc4648({
742
- prefix: 'U',
743
- name: 'base64urlpad',
744
- alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=',
745
- bitsPerChar: 6
582
+ prefix: 'U',
583
+ name: 'base64urlpad',
584
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=',
585
+ bitsPerChar: 6
746
586
  });
747
587
 
748
588
  var base64$1 = /*#__PURE__*/Object.freeze({
749
- __proto__: null,
750
- base64: base64,
751
- base64pad: base64pad,
752
- base64url: base64url,
753
- base64urlpad: base64urlpad
589
+ __proto__: null,
590
+ base64: base64,
591
+ base64pad: base64pad,
592
+ base64url: base64url,
593
+ base64urlpad: base64urlpad
754
594
  });
755
595
 
756
- // @ts-check
757
-
758
-
759
596
  const base8 = rfc4648({
760
- prefix: '7',
761
- name: 'base8',
762
- alphabet: '01234567',
763
- bitsPerChar: 3
597
+ prefix: '7',
598
+ name: 'base8',
599
+ alphabet: '01234567',
600
+ bitsPerChar: 3
764
601
  });
765
602
 
766
603
  var base8$1 = /*#__PURE__*/Object.freeze({
767
- __proto__: null,
768
- base8: base8
604
+ __proto__: null,
605
+ base8: base8
769
606
  });
770
607
 
771
- // @ts-check
772
-
773
-
774
608
  const identity = from({
775
- prefix: '\x00',
776
- name: 'identity',
777
- encode: (buf) => toString(buf),
778
- decode: (str) => fromString(str)
609
+ prefix: '\x00',
610
+ name: 'identity',
611
+ encode: (buf) => toString(buf),
612
+ decode: (str) => fromString(str)
779
613
  });
780
614
 
781
615
  var identityBase = /*#__PURE__*/Object.freeze({
782
- __proto__: null,
783
- identity: identity
616
+ __proto__: null,
617
+ identity: identity
784
618
  });
785
619
 
786
- // @ts-check
787
-
788
- /**
789
- * @template T
790
- * @typedef {import('./interface.js').ByteView<T>} ByteView
791
- */
792
-
793
620
  new TextEncoder();
794
621
  new TextDecoder();
795
622
 
@@ -800,54 +627,59 @@ var Protocols;
800
627
  Protocols["LightPush"] = "lightpush";
801
628
  Protocols["Filter"] = "filter";
802
629
  })(Protocols || (Protocols = {}));
803
- var SendError;
804
- (function (SendError) {
630
+ var ProtocolError;
631
+ (function (ProtocolError) {
805
632
  /** Could not determine the origin of the fault. Best to check connectivity and try again */
806
- SendError["GENERIC_FAIL"] = "Generic error";
633
+ ProtocolError["GENERIC_FAIL"] = "Generic error";
807
634
  /**
808
635
  * Failure to protobuf encode the message. This is not recoverable and needs
809
636
  * further investigation.
810
637
  */
811
- SendError["ENCODE_FAILED"] = "Failed to encode";
638
+ ProtocolError["ENCODE_FAILED"] = "Failed to encode";
812
639
  /**
813
640
  * Failure to protobuf decode the message. May be due to a remote peer issue,
814
641
  * ensuring that messages are sent via several peer enable mitigation of this error.
815
642
  */
816
- SendError["DECODE_FAILED"] = "Failed to decode";
643
+ ProtocolError["DECODE_FAILED"] = "Failed to decode";
817
644
  /**
818
645
  * The message payload is empty, making the message invalid. Ensure that a non-empty
819
646
  * payload is set on the outgoing message.
820
647
  */
821
- SendError["EMPTY_PAYLOAD"] = "Payload is empty";
648
+ ProtocolError["EMPTY_PAYLOAD"] = "Payload is empty";
822
649
  /**
823
650
  * The message size is above the maximum message size allowed on the Waku Network.
824
651
  * Compressing the message or using an alternative strategy for large messages is recommended.
825
652
  */
826
- SendError["SIZE_TOO_BIG"] = "Size is too big";
653
+ ProtocolError["SIZE_TOO_BIG"] = "Size is too big";
827
654
  /**
828
655
  * The PubsubTopic passed to the send function is not configured on the Waku node.
829
656
  * Please ensure that the PubsubTopic is used when initializing the Waku node.
830
657
  */
831
- SendError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
658
+ ProtocolError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
832
659
  /**
833
660
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
834
661
  * Mitigation can be: retrying after a given time period, display connectivity issue
835
662
  * to user or listening for `peer:connected:bootstrap` or `peer:connected:peer-exchange`
836
663
  * on the connection manager before retrying.
837
664
  */
838
- SendError["NO_PEER_AVAILABLE"] = "No peer available";
665
+ ProtocolError["NO_PEER_AVAILABLE"] = "No peer available";
839
666
  /**
840
667
  * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
841
668
  * or `DECODE_FAILED` can be used.
842
669
  */
843
- SendError["REMOTE_PEER_FAULT"] = "Remote peer fault";
670
+ ProtocolError["REMOTE_PEER_FAULT"] = "Remote peer fault";
844
671
  /**
845
672
  * The remote peer rejected the message. Information provided by the remote peer
846
673
  * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
847
674
  * or `DECODE_FAILED` can be used.
848
675
  */
849
- SendError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
850
- })(SendError || (SendError = {}));
676
+ ProtocolError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
677
+ /**
678
+ * The protocol request timed out without a response. This may be due to a connection issue.
679
+ * Mitigation can be: retrying after a given time period
680
+ */
681
+ ProtocolError["REQUEST_TIMEOUT"] = "Request timeout";
682
+ })(ProtocolError || (ProtocolError = {}));
851
683
 
852
684
  var PageDirection;
853
685
  (function (PageDirection) {
@@ -859,6 +691,7 @@ var Tags;
859
691
  (function (Tags) {
860
692
  Tags["BOOTSTRAP"] = "bootstrap";
861
693
  Tags["PEER_EXCHANGE"] = "peer-exchange";
694
+ Tags["LOCAL"] = "local-peer-cache";
862
695
  })(Tags || (Tags = {}));
863
696
  var EPeersByDiscoveryEvents;
864
697
  (function (EPeersByDiscoveryEvents) {
@@ -872,37 +705,10 @@ var EConnectionStateEvents;
872
705
  EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
873
706
  })(EConnectionStateEvents || (EConnectionStateEvents = {}));
874
707
 
875
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
876
-
877
708
  function getDefaultExportFromCjs (x) {
878
709
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
879
710
  }
880
711
 
881
- function getAugmentedNamespace(n) {
882
- if (n.__esModule) return n;
883
- var f = n.default;
884
- if (typeof f == "function") {
885
- var a = function a () {
886
- if (this instanceof a) {
887
- return Reflect.construct(f, arguments, this.constructor);
888
- }
889
- return f.apply(this, arguments);
890
- };
891
- a.prototype = f.prototype;
892
- } else a = {};
893
- Object.defineProperty(a, '__esModule', {value: true});
894
- Object.keys(n).forEach(function (k) {
895
- var d = Object.getOwnPropertyDescriptor(n, k);
896
- Object.defineProperty(a, k, d.get ? d : {
897
- enumerable: true,
898
- get: function () {
899
- return n[k];
900
- }
901
- });
902
- });
903
- return a;
904
- }
905
-
906
712
  var browser = {exports: {}};
907
713
 
908
714
  /**
@@ -1625,4 +1431,4 @@ var common = setup;
1625
1431
  var browserExports = browser.exports;
1626
1432
  var debug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
1627
1433
 
1628
- export { EConnectionStateEvents as E, Protocols as P, SendError as S, Tags as T, base58btc as a, base32 as b, coerce as c, commonjsGlobal as d, equals as e, EPeersByDiscoveryEvents as f, getAugmentedNamespace as g, getDefaultExportFromCjs as h, identityBase as i, base2$1 as j, base8$1 as k, base10$1 as l, base16$1 as m, base32$1 as n, base36$1 as o, base58 as p, base64$1 as q, base256emoji$1 as r, debug as s };
1434
+ export { EConnectionStateEvents as E, ProtocolError as P, Tags as T, Protocols as a, EPeersByDiscoveryEvents as b, base2$1 as c, base8$1 as d, base10$1 as e, base16$1 as f, getDefaultExportFromCjs as g, base32$1 as h, identityBase as i, base36$1 as j, base58 as k, base64$1 as l, base256emoji$1 as m, debug as n };