@waku/core 0.0.36-2ce706d.0 → 0.0.36-34d4730.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.
@@ -1,5 +1,3 @@
1
- import { g as base256emoji, h as base64, i as base58, j as base36, k as base32, l as base16, m as base10, n as base8, o as base2, p as identityBase, L as Logger } from './index-CTo1my9M.js';
2
-
3
1
  /**
4
2
  * Returns a `Uint8Array` of the requested size. Referenced memory will
5
3
  * be initialized to 0.
@@ -221,7 +219,7 @@ function decodeUint8ArrayList(buf, offset) {
221
219
  }
222
220
  throw new RangeError('Could not decode varint');
223
221
  }
224
- function encode(value, buf, offset = 0) {
222
+ function encode$2(value, buf, offset = 0) {
225
223
  if (buf == null) {
226
224
  buf = allocUnsafe(encodingLength(value));
227
225
  }
@@ -232,7 +230,7 @@ function encode(value, buf, offset = 0) {
232
230
  return encodeUint8ArrayList(value, buf, offset);
233
231
  }
234
232
  }
235
- function decode(buf, offset = 0) {
233
+ function decode$2(buf, offset = 0) {
236
234
  if (buf instanceof Uint8Array) {
237
235
  return decodeUint8Array(buf, offset);
238
236
  }
@@ -932,7 +930,654 @@ function decodeMessage(buf, codec, opts) {
932
930
  return codec.decode(reader, undefined, opts);
933
931
  }
934
932
 
935
- const bases = { ...identityBase, ...base2, ...base8, ...base10, ...base16, ...base32, ...base36, ...base58, ...base64, ...base256emoji };
933
+ function equals(aa, bb) {
934
+ if (aa === bb)
935
+ return true;
936
+ if (aa.byteLength !== bb.byteLength) {
937
+ return false;
938
+ }
939
+ for (let ii = 0; ii < aa.byteLength; ii++) {
940
+ if (aa[ii] !== bb[ii]) {
941
+ return false;
942
+ }
943
+ }
944
+ return true;
945
+ }
946
+ function coerce(o) {
947
+ if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array')
948
+ return o;
949
+ if (o instanceof ArrayBuffer)
950
+ return new Uint8Array(o);
951
+ if (ArrayBuffer.isView(o)) {
952
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
953
+ }
954
+ throw new Error('Unknown type, must be binary type');
955
+ }
956
+ function fromString$1(str) {
957
+ return new TextEncoder().encode(str);
958
+ }
959
+ function toString$1(b) {
960
+ return new TextDecoder().decode(b);
961
+ }
962
+
963
+ /* eslint-disable */
964
+ // base-x encoding / decoding
965
+ // Copyright (c) 2018 base-x contributors
966
+ // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
967
+ // Distributed under the MIT software license, see the accompanying
968
+ // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
969
+ /**
970
+ * @param {string} ALPHABET
971
+ * @param {any} name
972
+ */
973
+ function base(ALPHABET, name) {
974
+ if (ALPHABET.length >= 255) {
975
+ throw new TypeError('Alphabet too long');
976
+ }
977
+ var BASE_MAP = new Uint8Array(256);
978
+ for (var j = 0; j < BASE_MAP.length; j++) {
979
+ BASE_MAP[j] = 255;
980
+ }
981
+ for (var i = 0; i < ALPHABET.length; i++) {
982
+ var x = ALPHABET.charAt(i);
983
+ var xc = x.charCodeAt(0);
984
+ if (BASE_MAP[xc] !== 255) {
985
+ throw new TypeError(x + ' is ambiguous');
986
+ }
987
+ BASE_MAP[xc] = i;
988
+ }
989
+ var BASE = ALPHABET.length;
990
+ var LEADER = ALPHABET.charAt(0);
991
+ var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
992
+ var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
993
+ /**
994
+ * @param {any[] | Iterable<number>} source
995
+ */
996
+ function encode(source) {
997
+ // @ts-ignore
998
+ if (source instanceof Uint8Array)
999
+ ;
1000
+ else if (ArrayBuffer.isView(source)) {
1001
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
1002
+ }
1003
+ else if (Array.isArray(source)) {
1004
+ source = Uint8Array.from(source);
1005
+ }
1006
+ if (!(source instanceof Uint8Array)) {
1007
+ throw new TypeError('Expected Uint8Array');
1008
+ }
1009
+ if (source.length === 0) {
1010
+ return '';
1011
+ }
1012
+ // Skip & count leading zeroes.
1013
+ var zeroes = 0;
1014
+ var length = 0;
1015
+ var pbegin = 0;
1016
+ var pend = source.length;
1017
+ while (pbegin !== pend && source[pbegin] === 0) {
1018
+ pbegin++;
1019
+ zeroes++;
1020
+ }
1021
+ // Allocate enough space in big-endian base58 representation.
1022
+ var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
1023
+ var b58 = new Uint8Array(size);
1024
+ // Process the bytes.
1025
+ while (pbegin !== pend) {
1026
+ var carry = source[pbegin];
1027
+ // Apply "b58 = b58 * 256 + ch".
1028
+ var i = 0;
1029
+ for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
1030
+ carry += (256 * b58[it1]) >>> 0;
1031
+ b58[it1] = (carry % BASE) >>> 0;
1032
+ carry = (carry / BASE) >>> 0;
1033
+ }
1034
+ if (carry !== 0) {
1035
+ throw new Error('Non-zero carry');
1036
+ }
1037
+ length = i;
1038
+ pbegin++;
1039
+ }
1040
+ // Skip leading zeroes in base58 result.
1041
+ var it2 = size - length;
1042
+ while (it2 !== size && b58[it2] === 0) {
1043
+ it2++;
1044
+ }
1045
+ // Translate the result into a string.
1046
+ var str = LEADER.repeat(zeroes);
1047
+ for (; it2 < size; ++it2) {
1048
+ str += ALPHABET.charAt(b58[it2]);
1049
+ }
1050
+ return str;
1051
+ }
1052
+ /**
1053
+ * @param {string | string[]} source
1054
+ */
1055
+ function decodeUnsafe(source) {
1056
+ if (typeof source !== 'string') {
1057
+ throw new TypeError('Expected String');
1058
+ }
1059
+ if (source.length === 0) {
1060
+ return new Uint8Array();
1061
+ }
1062
+ var psz = 0;
1063
+ // Skip leading spaces.
1064
+ if (source[psz] === ' ') {
1065
+ return;
1066
+ }
1067
+ // Skip and count leading '1's.
1068
+ var zeroes = 0;
1069
+ var length = 0;
1070
+ while (source[psz] === LEADER) {
1071
+ zeroes++;
1072
+ psz++;
1073
+ }
1074
+ // Allocate enough space in big-endian base256 representation.
1075
+ var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
1076
+ var b256 = new Uint8Array(size);
1077
+ // Process the characters.
1078
+ while (source[psz]) {
1079
+ // Decode character
1080
+ var carry = BASE_MAP[source.charCodeAt(psz)];
1081
+ // Invalid character
1082
+ if (carry === 255) {
1083
+ return;
1084
+ }
1085
+ var i = 0;
1086
+ for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
1087
+ carry += (BASE * b256[it3]) >>> 0;
1088
+ b256[it3] = (carry % 256) >>> 0;
1089
+ carry = (carry / 256) >>> 0;
1090
+ }
1091
+ if (carry !== 0) {
1092
+ throw new Error('Non-zero carry');
1093
+ }
1094
+ length = i;
1095
+ psz++;
1096
+ }
1097
+ // Skip trailing spaces.
1098
+ if (source[psz] === ' ') {
1099
+ return;
1100
+ }
1101
+ // Skip leading zeroes in b256.
1102
+ var it4 = size - length;
1103
+ while (it4 !== size && b256[it4] === 0) {
1104
+ it4++;
1105
+ }
1106
+ var vch = new Uint8Array(zeroes + (size - it4));
1107
+ var j = zeroes;
1108
+ while (it4 !== size) {
1109
+ vch[j++] = b256[it4++];
1110
+ }
1111
+ return vch;
1112
+ }
1113
+ /**
1114
+ * @param {string | string[]} string
1115
+ */
1116
+ function decode(string) {
1117
+ var buffer = decodeUnsafe(string);
1118
+ if (buffer) {
1119
+ return buffer;
1120
+ }
1121
+ throw new Error(`Non-${name} character`);
1122
+ }
1123
+ return {
1124
+ encode: encode,
1125
+ decodeUnsafe: decodeUnsafe,
1126
+ decode: decode
1127
+ };
1128
+ }
1129
+ var src = base;
1130
+ var _brrp__multiformats_scope_baseX = src;
1131
+
1132
+ /**
1133
+ * Class represents both BaseEncoder and MultibaseEncoder meaning it
1134
+ * can be used to encode to multibase or base encode without multibase
1135
+ * prefix.
1136
+ */
1137
+ let Encoder$1 = class Encoder {
1138
+ name;
1139
+ prefix;
1140
+ baseEncode;
1141
+ constructor(name, prefix, baseEncode) {
1142
+ this.name = name;
1143
+ this.prefix = prefix;
1144
+ this.baseEncode = baseEncode;
1145
+ }
1146
+ encode(bytes) {
1147
+ if (bytes instanceof Uint8Array) {
1148
+ return `${this.prefix}${this.baseEncode(bytes)}`;
1149
+ }
1150
+ else {
1151
+ throw Error('Unknown type, must be binary type');
1152
+ }
1153
+ }
1154
+ };
1155
+ /**
1156
+ * Class represents both BaseDecoder and MultibaseDecoder so it could be used
1157
+ * to decode multibases (with matching prefix) or just base decode strings
1158
+ * with corresponding base encoding.
1159
+ */
1160
+ let Decoder$1 = class Decoder {
1161
+ name;
1162
+ prefix;
1163
+ baseDecode;
1164
+ prefixCodePoint;
1165
+ constructor(name, prefix, baseDecode) {
1166
+ this.name = name;
1167
+ this.prefix = prefix;
1168
+ const prefixCodePoint = prefix.codePointAt(0);
1169
+ /* c8 ignore next 3 */
1170
+ if (prefixCodePoint === undefined) {
1171
+ throw new Error('Invalid prefix character');
1172
+ }
1173
+ this.prefixCodePoint = prefixCodePoint;
1174
+ this.baseDecode = baseDecode;
1175
+ }
1176
+ decode(text) {
1177
+ if (typeof text === 'string') {
1178
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
1179
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
1180
+ }
1181
+ return this.baseDecode(text.slice(this.prefix.length));
1182
+ }
1183
+ else {
1184
+ throw Error('Can only multibase decode strings');
1185
+ }
1186
+ }
1187
+ or(decoder) {
1188
+ return or(this, decoder);
1189
+ }
1190
+ };
1191
+ class ComposedDecoder {
1192
+ decoders;
1193
+ constructor(decoders) {
1194
+ this.decoders = decoders;
1195
+ }
1196
+ or(decoder) {
1197
+ return or(this, decoder);
1198
+ }
1199
+ decode(input) {
1200
+ const prefix = input[0];
1201
+ const decoder = this.decoders[prefix];
1202
+ if (decoder != null) {
1203
+ return decoder.decode(input);
1204
+ }
1205
+ else {
1206
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
1207
+ }
1208
+ }
1209
+ }
1210
+ function or(left, right) {
1211
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1212
+ return new ComposedDecoder({
1213
+ ...(left.decoders ?? { [left.prefix]: left }),
1214
+ ...(right.decoders ?? { [right.prefix]: right })
1215
+ });
1216
+ }
1217
+ class Codec {
1218
+ name;
1219
+ prefix;
1220
+ baseEncode;
1221
+ baseDecode;
1222
+ encoder;
1223
+ decoder;
1224
+ constructor(name, prefix, baseEncode, baseDecode) {
1225
+ this.name = name;
1226
+ this.prefix = prefix;
1227
+ this.baseEncode = baseEncode;
1228
+ this.baseDecode = baseDecode;
1229
+ this.encoder = new Encoder$1(name, prefix, baseEncode);
1230
+ this.decoder = new Decoder$1(name, prefix, baseDecode);
1231
+ }
1232
+ encode(input) {
1233
+ return this.encoder.encode(input);
1234
+ }
1235
+ decode(input) {
1236
+ return this.decoder.decode(input);
1237
+ }
1238
+ }
1239
+ function from({ name, prefix, encode, decode }) {
1240
+ return new Codec(name, prefix, encode, decode);
1241
+ }
1242
+ function baseX({ name, prefix, alphabet }) {
1243
+ const { encode, decode } = _brrp__multiformats_scope_baseX(alphabet, name);
1244
+ return from({
1245
+ prefix,
1246
+ name,
1247
+ encode,
1248
+ decode: (text) => coerce(decode(text))
1249
+ });
1250
+ }
1251
+ function decode$1(string, alphabet, bitsPerChar, name) {
1252
+ // Build the character lookup table:
1253
+ const codes = {};
1254
+ for (let i = 0; i < alphabet.length; ++i) {
1255
+ codes[alphabet[i]] = i;
1256
+ }
1257
+ // Count the padding bytes:
1258
+ let end = string.length;
1259
+ while (string[end - 1] === '=') {
1260
+ --end;
1261
+ }
1262
+ // Allocate the output:
1263
+ const out = new Uint8Array((end * bitsPerChar / 8) | 0);
1264
+ // Parse the data:
1265
+ let bits = 0; // Number of bits currently in the buffer
1266
+ let buffer = 0; // Bits waiting to be written out, MSB first
1267
+ let written = 0; // Next byte to write
1268
+ for (let i = 0; i < end; ++i) {
1269
+ // Read one character from the string:
1270
+ const value = codes[string[i]];
1271
+ if (value === undefined) {
1272
+ throw new SyntaxError(`Non-${name} character`);
1273
+ }
1274
+ // Append the bits to the buffer:
1275
+ buffer = (buffer << bitsPerChar) | value;
1276
+ bits += bitsPerChar;
1277
+ // Write out some bits if the buffer has a byte's worth:
1278
+ if (bits >= 8) {
1279
+ bits -= 8;
1280
+ out[written++] = 0xff & (buffer >> bits);
1281
+ }
1282
+ }
1283
+ // Verify that we have received just enough bits:
1284
+ if (bits >= bitsPerChar || (0xff & (buffer << (8 - bits))) !== 0) {
1285
+ throw new SyntaxError('Unexpected end of data');
1286
+ }
1287
+ return out;
1288
+ }
1289
+ function encode$1(data, alphabet, bitsPerChar) {
1290
+ const pad = alphabet[alphabet.length - 1] === '=';
1291
+ const mask = (1 << bitsPerChar) - 1;
1292
+ let out = '';
1293
+ let bits = 0; // Number of bits currently in the buffer
1294
+ let buffer = 0; // Bits waiting to be written out, MSB first
1295
+ for (let i = 0; i < data.length; ++i) {
1296
+ // Slurp data into the buffer:
1297
+ buffer = (buffer << 8) | data[i];
1298
+ bits += 8;
1299
+ // Write out as much as we can:
1300
+ while (bits > bitsPerChar) {
1301
+ bits -= bitsPerChar;
1302
+ out += alphabet[mask & (buffer >> bits)];
1303
+ }
1304
+ }
1305
+ // Partial character:
1306
+ if (bits !== 0) {
1307
+ out += alphabet[mask & (buffer << (bitsPerChar - bits))];
1308
+ }
1309
+ // Add padding characters until we hit a byte boundary:
1310
+ if (pad) {
1311
+ while (((out.length * bitsPerChar) & 7) !== 0) {
1312
+ out += '=';
1313
+ }
1314
+ }
1315
+ return out;
1316
+ }
1317
+ /**
1318
+ * RFC4648 Factory
1319
+ */
1320
+ function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
1321
+ return from({
1322
+ prefix,
1323
+ name,
1324
+ encode(input) {
1325
+ return encode$1(input, alphabet, bitsPerChar);
1326
+ },
1327
+ decode(input) {
1328
+ return decode$1(input, alphabet, bitsPerChar, name);
1329
+ }
1330
+ });
1331
+ }
1332
+
1333
+ const base10 = baseX({
1334
+ prefix: '9',
1335
+ name: 'base10',
1336
+ alphabet: '0123456789'
1337
+ });
1338
+
1339
+ var base10$1 = /*#__PURE__*/Object.freeze({
1340
+ __proto__: null,
1341
+ base10: base10
1342
+ });
1343
+
1344
+ const base16 = rfc4648({
1345
+ prefix: 'f',
1346
+ name: 'base16',
1347
+ alphabet: '0123456789abcdef',
1348
+ bitsPerChar: 4
1349
+ });
1350
+ const base16upper = rfc4648({
1351
+ prefix: 'F',
1352
+ name: 'base16upper',
1353
+ alphabet: '0123456789ABCDEF',
1354
+ bitsPerChar: 4
1355
+ });
1356
+
1357
+ var base16$1 = /*#__PURE__*/Object.freeze({
1358
+ __proto__: null,
1359
+ base16: base16,
1360
+ base16upper: base16upper
1361
+ });
1362
+
1363
+ const base2 = rfc4648({
1364
+ prefix: '0',
1365
+ name: 'base2',
1366
+ alphabet: '01',
1367
+ bitsPerChar: 1
1368
+ });
1369
+
1370
+ var base2$1 = /*#__PURE__*/Object.freeze({
1371
+ __proto__: null,
1372
+ base2: base2
1373
+ });
1374
+
1375
+ const alphabet = Array.from('🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂');
1376
+ const alphabetBytesToChars = (alphabet.reduce((p, c, i) => { p[i] = c; return p; }, ([])));
1377
+ const alphabetCharsToBytes = (alphabet.reduce((p, c, i) => {
1378
+ const codePoint = c.codePointAt(0);
1379
+ if (codePoint == null) {
1380
+ throw new Error(`Invalid character: ${c}`);
1381
+ }
1382
+ p[codePoint] = i;
1383
+ return p;
1384
+ }, ([])));
1385
+ function encode(data) {
1386
+ return data.reduce((p, c) => {
1387
+ p += alphabetBytesToChars[c];
1388
+ return p;
1389
+ }, '');
1390
+ }
1391
+ function decode(str) {
1392
+ const byts = [];
1393
+ for (const char of str) {
1394
+ const codePoint = char.codePointAt(0);
1395
+ if (codePoint == null) {
1396
+ throw new Error(`Invalid character: ${char}`);
1397
+ }
1398
+ const byt = alphabetCharsToBytes[codePoint];
1399
+ if (byt == null) {
1400
+ throw new Error(`Non-base256emoji character: ${char}`);
1401
+ }
1402
+ byts.push(byt);
1403
+ }
1404
+ return new Uint8Array(byts);
1405
+ }
1406
+ const base256emoji = from({
1407
+ prefix: '🚀',
1408
+ name: 'base256emoji',
1409
+ encode,
1410
+ decode
1411
+ });
1412
+
1413
+ var base256emoji$1 = /*#__PURE__*/Object.freeze({
1414
+ __proto__: null,
1415
+ base256emoji: base256emoji
1416
+ });
1417
+
1418
+ const base32 = rfc4648({
1419
+ prefix: 'b',
1420
+ name: 'base32',
1421
+ alphabet: 'abcdefghijklmnopqrstuvwxyz234567',
1422
+ bitsPerChar: 5
1423
+ });
1424
+ const base32upper = rfc4648({
1425
+ prefix: 'B',
1426
+ name: 'base32upper',
1427
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
1428
+ bitsPerChar: 5
1429
+ });
1430
+ const base32pad = rfc4648({
1431
+ prefix: 'c',
1432
+ name: 'base32pad',
1433
+ alphabet: 'abcdefghijklmnopqrstuvwxyz234567=',
1434
+ bitsPerChar: 5
1435
+ });
1436
+ const base32padupper = rfc4648({
1437
+ prefix: 'C',
1438
+ name: 'base32padupper',
1439
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=',
1440
+ bitsPerChar: 5
1441
+ });
1442
+ const base32hex = rfc4648({
1443
+ prefix: 'v',
1444
+ name: 'base32hex',
1445
+ alphabet: '0123456789abcdefghijklmnopqrstuv',
1446
+ bitsPerChar: 5
1447
+ });
1448
+ const base32hexupper = rfc4648({
1449
+ prefix: 'V',
1450
+ name: 'base32hexupper',
1451
+ alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
1452
+ bitsPerChar: 5
1453
+ });
1454
+ const base32hexpad = rfc4648({
1455
+ prefix: 't',
1456
+ name: 'base32hexpad',
1457
+ alphabet: '0123456789abcdefghijklmnopqrstuv=',
1458
+ bitsPerChar: 5
1459
+ });
1460
+ const base32hexpadupper = rfc4648({
1461
+ prefix: 'T',
1462
+ name: 'base32hexpadupper',
1463
+ alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV=',
1464
+ bitsPerChar: 5
1465
+ });
1466
+ const base32z = rfc4648({
1467
+ prefix: 'h',
1468
+ name: 'base32z',
1469
+ alphabet: 'ybndrfg8ejkmcpqxot1uwisza345h769',
1470
+ bitsPerChar: 5
1471
+ });
1472
+
1473
+ var base32$1 = /*#__PURE__*/Object.freeze({
1474
+ __proto__: null,
1475
+ base32: base32,
1476
+ base32hex: base32hex,
1477
+ base32hexpad: base32hexpad,
1478
+ base32hexpadupper: base32hexpadupper,
1479
+ base32hexupper: base32hexupper,
1480
+ base32pad: base32pad,
1481
+ base32padupper: base32padupper,
1482
+ base32upper: base32upper,
1483
+ base32z: base32z
1484
+ });
1485
+
1486
+ const base36 = baseX({
1487
+ prefix: 'k',
1488
+ name: 'base36',
1489
+ alphabet: '0123456789abcdefghijklmnopqrstuvwxyz'
1490
+ });
1491
+ const base36upper = baseX({
1492
+ prefix: 'K',
1493
+ name: 'base36upper',
1494
+ alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1495
+ });
1496
+
1497
+ var base36$1 = /*#__PURE__*/Object.freeze({
1498
+ __proto__: null,
1499
+ base36: base36,
1500
+ base36upper: base36upper
1501
+ });
1502
+
1503
+ const base58btc = baseX({
1504
+ name: 'base58btc',
1505
+ prefix: 'z',
1506
+ alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
1507
+ });
1508
+ const base58flickr = baseX({
1509
+ name: 'base58flickr',
1510
+ prefix: 'Z',
1511
+ alphabet: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
1512
+ });
1513
+
1514
+ var base58 = /*#__PURE__*/Object.freeze({
1515
+ __proto__: null,
1516
+ base58btc: base58btc,
1517
+ base58flickr: base58flickr
1518
+ });
1519
+
1520
+ const base64 = rfc4648({
1521
+ prefix: 'm',
1522
+ name: 'base64',
1523
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
1524
+ bitsPerChar: 6
1525
+ });
1526
+ const base64pad = rfc4648({
1527
+ prefix: 'M',
1528
+ name: 'base64pad',
1529
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
1530
+ bitsPerChar: 6
1531
+ });
1532
+ const base64url = rfc4648({
1533
+ prefix: 'u',
1534
+ name: 'base64url',
1535
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
1536
+ bitsPerChar: 6
1537
+ });
1538
+ const base64urlpad = rfc4648({
1539
+ prefix: 'U',
1540
+ name: 'base64urlpad',
1541
+ alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=',
1542
+ bitsPerChar: 6
1543
+ });
1544
+
1545
+ var base64$1 = /*#__PURE__*/Object.freeze({
1546
+ __proto__: null,
1547
+ base64: base64,
1548
+ base64pad: base64pad,
1549
+ base64url: base64url,
1550
+ base64urlpad: base64urlpad
1551
+ });
1552
+
1553
+ const base8 = rfc4648({
1554
+ prefix: '7',
1555
+ name: 'base8',
1556
+ alphabet: '01234567',
1557
+ bitsPerChar: 3
1558
+ });
1559
+
1560
+ var base8$1 = /*#__PURE__*/Object.freeze({
1561
+ __proto__: null,
1562
+ base8: base8
1563
+ });
1564
+
1565
+ const identity = from({
1566
+ prefix: '\x00',
1567
+ name: 'identity',
1568
+ encode: (buf) => toString$1(buf),
1569
+ decode: (str) => fromString$1(str)
1570
+ });
1571
+
1572
+ var identityBase = /*#__PURE__*/Object.freeze({
1573
+ __proto__: null,
1574
+ identity: identity
1575
+ });
1576
+
1577
+ new TextEncoder();
1578
+ new TextDecoder();
1579
+
1580
+ const bases = { ...identityBase, ...base2$1, ...base8$1, ...base10$1, ...base16$1, ...base32$1, ...base36$1, ...base58, ...base64$1, ...base256emoji$1 };
936
1581
 
937
1582
  function createCodec$1(name, prefix, encode, decode) {
938
1583
  return {
@@ -4329,11 +4974,131 @@ const sha256$1 = /* @__PURE__ */ createHasher(() => new SHA256());
4329
4974
  /** @deprecated Use import from `noble/hashes/sha2` module */
4330
4975
  const sha256 = sha256$1;
4331
4976
 
4977
+ var Protocols;
4978
+ (function (Protocols) {
4979
+ Protocols["Relay"] = "relay";
4980
+ Protocols["Store"] = "store";
4981
+ Protocols["LightPush"] = "lightpush";
4982
+ Protocols["Filter"] = "filter";
4983
+ })(Protocols || (Protocols = {}));
4984
+ var ProtocolError;
4985
+ (function (ProtocolError) {
4986
+ //
4987
+ // GENERAL ERRORS SECTION
4988
+ //
4989
+ /**
4990
+ * Could not determine the origin of the fault. Best to check connectivity and try again
4991
+ * */
4992
+ ProtocolError["GENERIC_FAIL"] = "Generic error";
4993
+ /**
4994
+ * The remote peer rejected the message. Information provided by the remote peer
4995
+ * is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
4996
+ * or `DECODE_FAILED` can be used.
4997
+ */
4998
+ ProtocolError["REMOTE_PEER_REJECTED"] = "Remote peer rejected";
4999
+ /**
5000
+ * Failure to protobuf decode the message. May be due to a remote peer issue,
5001
+ * ensuring that messages are sent via several peer enable mitigation of this error.
5002
+ */
5003
+ ProtocolError["DECODE_FAILED"] = "Failed to decode";
5004
+ /**
5005
+ * Failure to find a peer with suitable protocols. This may due to a connection issue.
5006
+ * Mitigation can be: retrying after a given time period, display connectivity issue
5007
+ * to user or listening for `peer:connected:bootstrap` or `peer:connected:peer-exchange`
5008
+ * on the connection manager before retrying.
5009
+ */
5010
+ ProtocolError["NO_PEER_AVAILABLE"] = "No peer available";
5011
+ /**
5012
+ * Failure to find a stream to the peer. This may be because the connection with the peer is not still alive.
5013
+ * Mitigation can be: retrying after a given time period, or mitigation for `NO_PEER_AVAILABLE` can be used.
5014
+ */
5015
+ ProtocolError["NO_STREAM_AVAILABLE"] = "No stream available";
5016
+ /**
5017
+ * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
5018
+ * or `DECODE_FAILED` can be used.
5019
+ */
5020
+ ProtocolError["NO_RESPONSE"] = "No response received";
5021
+ //
5022
+ // SEND ERRORS SECTION
5023
+ //
5024
+ /**
5025
+ * Failure to protobuf encode the message. This is not recoverable and needs
5026
+ * further investigation.
5027
+ */
5028
+ ProtocolError["ENCODE_FAILED"] = "Failed to encode";
5029
+ /**
5030
+ * The message payload is empty, making the message invalid. Ensure that a non-empty
5031
+ * payload is set on the outgoing message.
5032
+ */
5033
+ ProtocolError["EMPTY_PAYLOAD"] = "Payload is empty";
5034
+ /**
5035
+ * The message size is above the maximum message size allowed on the Waku Network.
5036
+ * Compressing the message or using an alternative strategy for large messages is recommended.
5037
+ */
5038
+ ProtocolError["SIZE_TOO_BIG"] = "Size is too big";
5039
+ /**
5040
+ * The PubsubTopic passed to the send function is not configured on the Waku node.
5041
+ * Please ensure that the PubsubTopic is used when initializing the Waku node.
5042
+ */
5043
+ ProtocolError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
5044
+ /**
5045
+ * Fails when
5046
+ */
5047
+ ProtocolError["STREAM_ABORTED"] = "Stream aborted";
5048
+ /**
5049
+ * General proof generation error message.
5050
+ * nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
5051
+ */
5052
+ ProtocolError["RLN_PROOF_GENERATION"] = "Proof generation failed";
5053
+ //
5054
+ // RECEIVE ERRORS SECTION
5055
+ //
5056
+ /**
5057
+ * The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
5058
+ * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
5059
+ */
5060
+ ProtocolError["TOPIC_DECODER_MISMATCH"] = "Topic decoder mismatch";
5061
+ /**
5062
+ * The topics passed in the decoders do not match each other, or don't exist at all.
5063
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
5064
+ */
5065
+ ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
5066
+ })(ProtocolError || (ProtocolError = {}));
5067
+
5068
+ var Tags;
5069
+ (function (Tags) {
5070
+ Tags["BOOTSTRAP"] = "bootstrap";
5071
+ Tags["PEER_EXCHANGE"] = "peer-exchange";
5072
+ Tags["LOCAL"] = "local-peer-cache";
5073
+ })(Tags || (Tags = {}));
5074
+ var EPeersByDiscoveryEvents;
5075
+ (function (EPeersByDiscoveryEvents) {
5076
+ EPeersByDiscoveryEvents["PEER_DISCOVERY_BOOTSTRAP"] = "peer:discovery:bootstrap";
5077
+ EPeersByDiscoveryEvents["PEER_DISCOVERY_PEER_EXCHANGE"] = "peer:discovery:peer-exchange";
5078
+ EPeersByDiscoveryEvents["PEER_CONNECT_BOOTSTRAP"] = "peer:connected:bootstrap";
5079
+ EPeersByDiscoveryEvents["PEER_CONNECT_PEER_EXCHANGE"] = "peer:connected:peer-exchange";
5080
+ })(EPeersByDiscoveryEvents || (EPeersByDiscoveryEvents = {}));
5081
+ var EConnectionStateEvents;
5082
+ (function (EConnectionStateEvents) {
5083
+ EConnectionStateEvents["CONNECTION_STATUS"] = "waku:connection";
5084
+ })(EConnectionStateEvents || (EConnectionStateEvents = {}));
5085
+
4332
5086
  /**
4333
5087
  * The default cluster ID for The Waku Network
4334
5088
  */
4335
5089
  const DEFAULT_CLUSTER_ID = 1;
4336
5090
 
5091
+ var HealthStatusChangeEvents;
5092
+ (function (HealthStatusChangeEvents) {
5093
+ HealthStatusChangeEvents["StatusChange"] = "health:change";
5094
+ })(HealthStatusChangeEvents || (HealthStatusChangeEvents = {}));
5095
+ var HealthStatus;
5096
+ (function (HealthStatus) {
5097
+ HealthStatus["Unhealthy"] = "Unhealthy";
5098
+ HealthStatus["MinimallyHealthy"] = "MinimallyHealthy";
5099
+ HealthStatus["SufficientlyHealthy"] = "SufficientlyHealthy";
5100
+ })(HealthStatus || (HealthStatus = {}));
5101
+
4337
5102
  /**
4338
5103
  * Turns a `Uint8Array` into a string.
4339
5104
  *
@@ -4528,6 +5293,781 @@ pubsubTopicShardInfo) {
4528
5293
  : contentTopicToPubsubTopic(contentTopic, pubsubTopicShardInfo?.clusterId ?? DEFAULT_CLUSTER_ID);
4529
5294
  }
4530
5295
 
5296
+ function getDefaultExportFromCjs (x) {
5297
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5298
+ }
5299
+
5300
+ var browser = {exports: {}};
5301
+
5302
+ /**
5303
+ * Helpers.
5304
+ */
5305
+
5306
+ var ms;
5307
+ var hasRequiredMs;
5308
+
5309
+ function requireMs () {
5310
+ if (hasRequiredMs) return ms;
5311
+ hasRequiredMs = 1;
5312
+ var s = 1000;
5313
+ var m = s * 60;
5314
+ var h = m * 60;
5315
+ var d = h * 24;
5316
+ var w = d * 7;
5317
+ var y = d * 365.25;
5318
+
5319
+ /**
5320
+ * Parse or format the given `val`.
5321
+ *
5322
+ * Options:
5323
+ *
5324
+ * - `long` verbose formatting [false]
5325
+ *
5326
+ * @param {String|Number} val
5327
+ * @param {Object} [options]
5328
+ * @throws {Error} throw an error if val is not a non-empty string or a number
5329
+ * @return {String|Number}
5330
+ * @api public
5331
+ */
5332
+
5333
+ ms = function (val, options) {
5334
+ options = options || {};
5335
+ var type = typeof val;
5336
+ if (type === 'string' && val.length > 0) {
5337
+ return parse(val);
5338
+ } else if (type === 'number' && isFinite(val)) {
5339
+ return options.long ? fmtLong(val) : fmtShort(val);
5340
+ }
5341
+ throw new Error(
5342
+ 'val is not a non-empty string or a valid number. val=' +
5343
+ JSON.stringify(val)
5344
+ );
5345
+ };
5346
+
5347
+ /**
5348
+ * Parse the given `str` and return milliseconds.
5349
+ *
5350
+ * @param {String} str
5351
+ * @return {Number}
5352
+ * @api private
5353
+ */
5354
+
5355
+ function parse(str) {
5356
+ str = String(str);
5357
+ if (str.length > 100) {
5358
+ return;
5359
+ }
5360
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
5361
+ str
5362
+ );
5363
+ if (!match) {
5364
+ return;
5365
+ }
5366
+ var n = parseFloat(match[1]);
5367
+ var type = (match[2] || 'ms').toLowerCase();
5368
+ switch (type) {
5369
+ case 'years':
5370
+ case 'year':
5371
+ case 'yrs':
5372
+ case 'yr':
5373
+ case 'y':
5374
+ return n * y;
5375
+ case 'weeks':
5376
+ case 'week':
5377
+ case 'w':
5378
+ return n * w;
5379
+ case 'days':
5380
+ case 'day':
5381
+ case 'd':
5382
+ return n * d;
5383
+ case 'hours':
5384
+ case 'hour':
5385
+ case 'hrs':
5386
+ case 'hr':
5387
+ case 'h':
5388
+ return n * h;
5389
+ case 'minutes':
5390
+ case 'minute':
5391
+ case 'mins':
5392
+ case 'min':
5393
+ case 'm':
5394
+ return n * m;
5395
+ case 'seconds':
5396
+ case 'second':
5397
+ case 'secs':
5398
+ case 'sec':
5399
+ case 's':
5400
+ return n * s;
5401
+ case 'milliseconds':
5402
+ case 'millisecond':
5403
+ case 'msecs':
5404
+ case 'msec':
5405
+ case 'ms':
5406
+ return n;
5407
+ default:
5408
+ return undefined;
5409
+ }
5410
+ }
5411
+
5412
+ /**
5413
+ * Short format for `ms`.
5414
+ *
5415
+ * @param {Number} ms
5416
+ * @return {String}
5417
+ * @api private
5418
+ */
5419
+
5420
+ function fmtShort(ms) {
5421
+ var msAbs = Math.abs(ms);
5422
+ if (msAbs >= d) {
5423
+ return Math.round(ms / d) + 'd';
5424
+ }
5425
+ if (msAbs >= h) {
5426
+ return Math.round(ms / h) + 'h';
5427
+ }
5428
+ if (msAbs >= m) {
5429
+ return Math.round(ms / m) + 'm';
5430
+ }
5431
+ if (msAbs >= s) {
5432
+ return Math.round(ms / s) + 's';
5433
+ }
5434
+ return ms + 'ms';
5435
+ }
5436
+
5437
+ /**
5438
+ * Long format for `ms`.
5439
+ *
5440
+ * @param {Number} ms
5441
+ * @return {String}
5442
+ * @api private
5443
+ */
5444
+
5445
+ function fmtLong(ms) {
5446
+ var msAbs = Math.abs(ms);
5447
+ if (msAbs >= d) {
5448
+ return plural(ms, msAbs, d, 'day');
5449
+ }
5450
+ if (msAbs >= h) {
5451
+ return plural(ms, msAbs, h, 'hour');
5452
+ }
5453
+ if (msAbs >= m) {
5454
+ return plural(ms, msAbs, m, 'minute');
5455
+ }
5456
+ if (msAbs >= s) {
5457
+ return plural(ms, msAbs, s, 'second');
5458
+ }
5459
+ return ms + ' ms';
5460
+ }
5461
+
5462
+ /**
5463
+ * Pluralization helper.
5464
+ */
5465
+
5466
+ function plural(ms, msAbs, n, name) {
5467
+ var isPlural = msAbs >= n * 1.5;
5468
+ return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
5469
+ }
5470
+ return ms;
5471
+ }
5472
+
5473
+ /**
5474
+ * This is the common logic for both the Node.js and web browser
5475
+ * implementations of `debug()`.
5476
+ */
5477
+
5478
+ function setup(env) {
5479
+ createDebug.debug = createDebug;
5480
+ createDebug.default = createDebug;
5481
+ createDebug.coerce = coerce;
5482
+ createDebug.disable = disable;
5483
+ createDebug.enable = enable;
5484
+ createDebug.enabled = enabled;
5485
+ createDebug.humanize = requireMs();
5486
+ createDebug.destroy = destroy;
5487
+
5488
+ Object.keys(env).forEach(key => {
5489
+ createDebug[key] = env[key];
5490
+ });
5491
+
5492
+ /**
5493
+ * The currently active debug mode names, and names to skip.
5494
+ */
5495
+
5496
+ createDebug.names = [];
5497
+ createDebug.skips = [];
5498
+
5499
+ /**
5500
+ * Map of special "%n" handling functions, for the debug "format" argument.
5501
+ *
5502
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
5503
+ */
5504
+ createDebug.formatters = {};
5505
+
5506
+ /**
5507
+ * Selects a color for a debug namespace
5508
+ * @param {String} namespace The namespace string for the debug instance to be colored
5509
+ * @return {Number|String} An ANSI color code for the given namespace
5510
+ * @api private
5511
+ */
5512
+ function selectColor(namespace) {
5513
+ let hash = 0;
5514
+
5515
+ for (let i = 0; i < namespace.length; i++) {
5516
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
5517
+ hash |= 0; // Convert to 32bit integer
5518
+ }
5519
+
5520
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
5521
+ }
5522
+ createDebug.selectColor = selectColor;
5523
+
5524
+ /**
5525
+ * Create a debugger with the given `namespace`.
5526
+ *
5527
+ * @param {String} namespace
5528
+ * @return {Function}
5529
+ * @api public
5530
+ */
5531
+ function createDebug(namespace) {
5532
+ let prevTime;
5533
+ let enableOverride = null;
5534
+ let namespacesCache;
5535
+ let enabledCache;
5536
+
5537
+ function debug(...args) {
5538
+ // Disabled?
5539
+ if (!debug.enabled) {
5540
+ return;
5541
+ }
5542
+
5543
+ const self = debug;
5544
+
5545
+ // Set `diff` timestamp
5546
+ const curr = Number(new Date());
5547
+ const ms = curr - (prevTime || curr);
5548
+ self.diff = ms;
5549
+ self.prev = prevTime;
5550
+ self.curr = curr;
5551
+ prevTime = curr;
5552
+
5553
+ args[0] = createDebug.coerce(args[0]);
5554
+
5555
+ if (typeof args[0] !== 'string') {
5556
+ // Anything else let's inspect with %O
5557
+ args.unshift('%O');
5558
+ }
5559
+
5560
+ // Apply any `formatters` transformations
5561
+ let index = 0;
5562
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
5563
+ // If we encounter an escaped % then don't increase the array index
5564
+ if (match === '%%') {
5565
+ return '%';
5566
+ }
5567
+ index++;
5568
+ const formatter = createDebug.formatters[format];
5569
+ if (typeof formatter === 'function') {
5570
+ const val = args[index];
5571
+ match = formatter.call(self, val);
5572
+
5573
+ // Now we need to remove `args[index]` since it's inlined in the `format`
5574
+ args.splice(index, 1);
5575
+ index--;
5576
+ }
5577
+ return match;
5578
+ });
5579
+
5580
+ // Apply env-specific formatting (colors, etc.)
5581
+ createDebug.formatArgs.call(self, args);
5582
+
5583
+ const logFn = self.log || createDebug.log;
5584
+ logFn.apply(self, args);
5585
+ }
5586
+
5587
+ debug.namespace = namespace;
5588
+ debug.useColors = createDebug.useColors();
5589
+ debug.color = createDebug.selectColor(namespace);
5590
+ debug.extend = extend;
5591
+ debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
5592
+
5593
+ Object.defineProperty(debug, 'enabled', {
5594
+ enumerable: true,
5595
+ configurable: false,
5596
+ get: () => {
5597
+ if (enableOverride !== null) {
5598
+ return enableOverride;
5599
+ }
5600
+ if (namespacesCache !== createDebug.namespaces) {
5601
+ namespacesCache = createDebug.namespaces;
5602
+ enabledCache = createDebug.enabled(namespace);
5603
+ }
5604
+
5605
+ return enabledCache;
5606
+ },
5607
+ set: v => {
5608
+ enableOverride = v;
5609
+ }
5610
+ });
5611
+
5612
+ // Env-specific initialization logic for debug instances
5613
+ if (typeof createDebug.init === 'function') {
5614
+ createDebug.init(debug);
5615
+ }
5616
+
5617
+ return debug;
5618
+ }
5619
+
5620
+ function extend(namespace, delimiter) {
5621
+ const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
5622
+ newDebug.log = this.log;
5623
+ return newDebug;
5624
+ }
5625
+
5626
+ /**
5627
+ * Enables a debug mode by namespaces. This can include modes
5628
+ * separated by a colon and wildcards.
5629
+ *
5630
+ * @param {String} namespaces
5631
+ * @api public
5632
+ */
5633
+ function enable(namespaces) {
5634
+ createDebug.save(namespaces);
5635
+ createDebug.namespaces = namespaces;
5636
+
5637
+ createDebug.names = [];
5638
+ createDebug.skips = [];
5639
+
5640
+ const split = (typeof namespaces === 'string' ? namespaces : '')
5641
+ .trim()
5642
+ .replace(' ', ',')
5643
+ .split(',')
5644
+ .filter(Boolean);
5645
+
5646
+ for (const ns of split) {
5647
+ if (ns[0] === '-') {
5648
+ createDebug.skips.push(ns.slice(1));
5649
+ } else {
5650
+ createDebug.names.push(ns);
5651
+ }
5652
+ }
5653
+ }
5654
+
5655
+ /**
5656
+ * Checks if the given string matches a namespace template, honoring
5657
+ * asterisks as wildcards.
5658
+ *
5659
+ * @param {String} search
5660
+ * @param {String} template
5661
+ * @return {Boolean}
5662
+ */
5663
+ function matchesTemplate(search, template) {
5664
+ let searchIndex = 0;
5665
+ let templateIndex = 0;
5666
+ let starIndex = -1;
5667
+ let matchIndex = 0;
5668
+
5669
+ while (searchIndex < search.length) {
5670
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
5671
+ // Match character or proceed with wildcard
5672
+ if (template[templateIndex] === '*') {
5673
+ starIndex = templateIndex;
5674
+ matchIndex = searchIndex;
5675
+ templateIndex++; // Skip the '*'
5676
+ } else {
5677
+ searchIndex++;
5678
+ templateIndex++;
5679
+ }
5680
+ } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
5681
+ // Backtrack to the last '*' and try to match more characters
5682
+ templateIndex = starIndex + 1;
5683
+ matchIndex++;
5684
+ searchIndex = matchIndex;
5685
+ } else {
5686
+ return false; // No match
5687
+ }
5688
+ }
5689
+
5690
+ // Handle trailing '*' in template
5691
+ while (templateIndex < template.length && template[templateIndex] === '*') {
5692
+ templateIndex++;
5693
+ }
5694
+
5695
+ return templateIndex === template.length;
5696
+ }
5697
+
5698
+ /**
5699
+ * Disable debug output.
5700
+ *
5701
+ * @return {String} namespaces
5702
+ * @api public
5703
+ */
5704
+ function disable() {
5705
+ const namespaces = [
5706
+ ...createDebug.names,
5707
+ ...createDebug.skips.map(namespace => '-' + namespace)
5708
+ ].join(',');
5709
+ createDebug.enable('');
5710
+ return namespaces;
5711
+ }
5712
+
5713
+ /**
5714
+ * Returns true if the given mode name is enabled, false otherwise.
5715
+ *
5716
+ * @param {String} name
5717
+ * @return {Boolean}
5718
+ * @api public
5719
+ */
5720
+ function enabled(name) {
5721
+ for (const skip of createDebug.skips) {
5722
+ if (matchesTemplate(name, skip)) {
5723
+ return false;
5724
+ }
5725
+ }
5726
+
5727
+ for (const ns of createDebug.names) {
5728
+ if (matchesTemplate(name, ns)) {
5729
+ return true;
5730
+ }
5731
+ }
5732
+
5733
+ return false;
5734
+ }
5735
+
5736
+ /**
5737
+ * Coerce `val`.
5738
+ *
5739
+ * @param {Mixed} val
5740
+ * @return {Mixed}
5741
+ * @api private
5742
+ */
5743
+ function coerce(val) {
5744
+ if (val instanceof Error) {
5745
+ return val.stack || val.message;
5746
+ }
5747
+ return val;
5748
+ }
5749
+
5750
+ /**
5751
+ * XXX DO NOT USE. This is a temporary stub function.
5752
+ * XXX It WILL be removed in the next major release.
5753
+ */
5754
+ function destroy() {
5755
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
5756
+ }
5757
+
5758
+ createDebug.enable(createDebug.load());
5759
+
5760
+ return createDebug;
5761
+ }
5762
+
5763
+ var common = setup;
5764
+
5765
+ /* eslint-env browser */
5766
+
5767
+ (function (module, exports) {
5768
+ /**
5769
+ * This is the web browser implementation of `debug()`.
5770
+ */
5771
+
5772
+ exports.formatArgs = formatArgs;
5773
+ exports.save = save;
5774
+ exports.load = load;
5775
+ exports.useColors = useColors;
5776
+ exports.storage = localstorage();
5777
+ exports.destroy = (() => {
5778
+ let warned = false;
5779
+
5780
+ return () => {
5781
+ if (!warned) {
5782
+ warned = true;
5783
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
5784
+ }
5785
+ };
5786
+ })();
5787
+
5788
+ /**
5789
+ * Colors.
5790
+ */
5791
+
5792
+ exports.colors = [
5793
+ '#0000CC',
5794
+ '#0000FF',
5795
+ '#0033CC',
5796
+ '#0033FF',
5797
+ '#0066CC',
5798
+ '#0066FF',
5799
+ '#0099CC',
5800
+ '#0099FF',
5801
+ '#00CC00',
5802
+ '#00CC33',
5803
+ '#00CC66',
5804
+ '#00CC99',
5805
+ '#00CCCC',
5806
+ '#00CCFF',
5807
+ '#3300CC',
5808
+ '#3300FF',
5809
+ '#3333CC',
5810
+ '#3333FF',
5811
+ '#3366CC',
5812
+ '#3366FF',
5813
+ '#3399CC',
5814
+ '#3399FF',
5815
+ '#33CC00',
5816
+ '#33CC33',
5817
+ '#33CC66',
5818
+ '#33CC99',
5819
+ '#33CCCC',
5820
+ '#33CCFF',
5821
+ '#6600CC',
5822
+ '#6600FF',
5823
+ '#6633CC',
5824
+ '#6633FF',
5825
+ '#66CC00',
5826
+ '#66CC33',
5827
+ '#9900CC',
5828
+ '#9900FF',
5829
+ '#9933CC',
5830
+ '#9933FF',
5831
+ '#99CC00',
5832
+ '#99CC33',
5833
+ '#CC0000',
5834
+ '#CC0033',
5835
+ '#CC0066',
5836
+ '#CC0099',
5837
+ '#CC00CC',
5838
+ '#CC00FF',
5839
+ '#CC3300',
5840
+ '#CC3333',
5841
+ '#CC3366',
5842
+ '#CC3399',
5843
+ '#CC33CC',
5844
+ '#CC33FF',
5845
+ '#CC6600',
5846
+ '#CC6633',
5847
+ '#CC9900',
5848
+ '#CC9933',
5849
+ '#CCCC00',
5850
+ '#CCCC33',
5851
+ '#FF0000',
5852
+ '#FF0033',
5853
+ '#FF0066',
5854
+ '#FF0099',
5855
+ '#FF00CC',
5856
+ '#FF00FF',
5857
+ '#FF3300',
5858
+ '#FF3333',
5859
+ '#FF3366',
5860
+ '#FF3399',
5861
+ '#FF33CC',
5862
+ '#FF33FF',
5863
+ '#FF6600',
5864
+ '#FF6633',
5865
+ '#FF9900',
5866
+ '#FF9933',
5867
+ '#FFCC00',
5868
+ '#FFCC33'
5869
+ ];
5870
+
5871
+ /**
5872
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
5873
+ * and the Firebug extension (any Firefox version) are known
5874
+ * to support "%c" CSS customizations.
5875
+ *
5876
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
5877
+ */
5878
+
5879
+ // eslint-disable-next-line complexity
5880
+ function useColors() {
5881
+ // NB: In an Electron preload script, document will be defined but not fully
5882
+ // initialized. Since we know we're in Chrome, we'll just detect this case
5883
+ // explicitly
5884
+ if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
5885
+ return true;
5886
+ }
5887
+
5888
+ // Internet Explorer and Edge do not support colors.
5889
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
5890
+ return false;
5891
+ }
5892
+
5893
+ let m;
5894
+
5895
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
5896
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
5897
+ // eslint-disable-next-line no-return-assign
5898
+ return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
5899
+ // Is firebug? http://stackoverflow.com/a/398120/376773
5900
+ (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
5901
+ // Is firefox >= v31?
5902
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
5903
+ (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
5904
+ // Double check webkit in userAgent just in case we are in a worker
5905
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
5906
+ }
5907
+
5908
+ /**
5909
+ * Colorize log arguments if enabled.
5910
+ *
5911
+ * @api public
5912
+ */
5913
+
5914
+ function formatArgs(args) {
5915
+ args[0] = (this.useColors ? '%c' : '') +
5916
+ this.namespace +
5917
+ (this.useColors ? ' %c' : ' ') +
5918
+ args[0] +
5919
+ (this.useColors ? '%c ' : ' ') +
5920
+ '+' + module.exports.humanize(this.diff);
5921
+
5922
+ if (!this.useColors) {
5923
+ return;
5924
+ }
5925
+
5926
+ const c = 'color: ' + this.color;
5927
+ args.splice(1, 0, c, 'color: inherit');
5928
+
5929
+ // The final "%c" is somewhat tricky, because there could be other
5930
+ // arguments passed either before or after the %c, so we need to
5931
+ // figure out the correct index to insert the CSS into
5932
+ let index = 0;
5933
+ let lastC = 0;
5934
+ args[0].replace(/%[a-zA-Z%]/g, match => {
5935
+ if (match === '%%') {
5936
+ return;
5937
+ }
5938
+ index++;
5939
+ if (match === '%c') {
5940
+ // We only are interested in the *last* %c
5941
+ // (the user may have provided their own)
5942
+ lastC = index;
5943
+ }
5944
+ });
5945
+
5946
+ args.splice(lastC, 0, c);
5947
+ }
5948
+
5949
+ /**
5950
+ * Invokes `console.debug()` when available.
5951
+ * No-op when `console.debug` is not a "function".
5952
+ * If `console.debug` is not available, falls back
5953
+ * to `console.log`.
5954
+ *
5955
+ * @api public
5956
+ */
5957
+ exports.log = console.debug || console.log || (() => {});
5958
+
5959
+ /**
5960
+ * Save `namespaces`.
5961
+ *
5962
+ * @param {String} namespaces
5963
+ * @api private
5964
+ */
5965
+ function save(namespaces) {
5966
+ try {
5967
+ if (namespaces) {
5968
+ exports.storage.setItem('debug', namespaces);
5969
+ } else {
5970
+ exports.storage.removeItem('debug');
5971
+ }
5972
+ } catch (error) {
5973
+ // Swallow
5974
+ // XXX (@Qix-) should we be logging these?
5975
+ }
5976
+ }
5977
+
5978
+ /**
5979
+ * Load `namespaces`.
5980
+ *
5981
+ * @return {String} returns the previously persisted debug modes
5982
+ * @api private
5983
+ */
5984
+ function load() {
5985
+ let r;
5986
+ try {
5987
+ r = exports.storage.getItem('debug');
5988
+ } catch (error) {
5989
+ // Swallow
5990
+ // XXX (@Qix-) should we be logging these?
5991
+ }
5992
+
5993
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
5994
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
5995
+ r = process.env.DEBUG;
5996
+ }
5997
+
5998
+ return r;
5999
+ }
6000
+
6001
+ /**
6002
+ * Localstorage attempts to return the localstorage.
6003
+ *
6004
+ * This is necessary because safari throws
6005
+ * when a user disables cookies/localstorage
6006
+ * and you attempt to access it.
6007
+ *
6008
+ * @return {LocalStorage}
6009
+ * @api private
6010
+ */
6011
+
6012
+ function localstorage() {
6013
+ try {
6014
+ // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
6015
+ // The Browser also has localStorage in the global context.
6016
+ return localStorage;
6017
+ } catch (error) {
6018
+ // Swallow
6019
+ // XXX (@Qix-) should we be logging these?
6020
+ }
6021
+ }
6022
+
6023
+ module.exports = common(exports);
6024
+
6025
+ const {formatters} = module.exports;
6026
+
6027
+ /**
6028
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
6029
+ */
6030
+
6031
+ formatters.j = function (v) {
6032
+ try {
6033
+ return JSON.stringify(v);
6034
+ } catch (error) {
6035
+ return '[UnexpectedJSONParseError]: ' + error.message;
6036
+ }
6037
+ };
6038
+ } (browser, browser.exports));
6039
+
6040
+ var browserExports = browser.exports;
6041
+ var debug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
6042
+
6043
+ const APP_NAME = "waku";
6044
+ class Logger {
6045
+ _info;
6046
+ _warn;
6047
+ _error;
6048
+ static createDebugNamespace(level, prefix) {
6049
+ return prefix ? `${APP_NAME}:${level}:${prefix}` : `${APP_NAME}:${level}`;
6050
+ }
6051
+ constructor(prefix) {
6052
+ this._info = debug(Logger.createDebugNamespace("info", prefix));
6053
+ this._warn = debug(Logger.createDebugNamespace("warn", prefix));
6054
+ this._error = debug(Logger.createDebugNamespace("error", prefix));
6055
+ }
6056
+ get info() {
6057
+ return this._info;
6058
+ }
6059
+ get warn() {
6060
+ return this._warn;
6061
+ }
6062
+ get error() {
6063
+ return this._error;
6064
+ }
6065
+ log(level, ...args) {
6066
+ const logger = this[level];
6067
+ logger(...args);
6068
+ }
6069
+ }
6070
+
4531
6071
  const log = new Logger("message:version-0");
4532
6072
  const OneMillion = BigInt(1_000_000);
4533
6073
  const Version = 0;
@@ -4677,4 +6217,4 @@ var version_0 = /*#__PURE__*/Object.freeze({
4677
6217
  proto: message
4678
6218
  });
4679
6219
 
4680
- export { DecodedMessage as D, Encoder as E, FilterSubscribeRequest as F, MessagePush as M, PushRpc$1 as P, StoreQueryRequest$1 as S, Version as V, WakuMetadataRequest as W, allocUnsafe as a, alloc$1 as b, encode as c, decode as d, encodingLength as e, FilterSubscribeResponse$1 as f, PushResponse as g, StoreQueryResponse$1 as h, bases as i, fromString as j, createEncoder as k, bytesToUtf8 as l, pubsubTopicsToShardInfo as m, WakuMetadataResponse as n, concat as o, pubsubTopicToSingleShardInfo as p, sha256 as q, bytesToHex as r, shardInfoToPubsubTopics as s, toString as t, utf8ToBytes as u, version_0 as v, numberToBytes as w, createDecoder as x, message as y, Decoder as z };
6220
+ export { concat as A, sha256 as B, bytesToHex as C, numberToBytes as D, EPeersByDiscoveryEvents as E, FilterSubscribeRequest as F, createDecoder as G, message as H, DecodedMessage as I, Encoder as J, Decoder as K, Logger as L, MessagePush as M, ProtocolError as P, StoreQueryRequest$1 as S, Tags as T, Version as V, WakuMetadataRequest as W, base58btc as a, base32 as b, coerce as c, base36 as d, equals as e, allocUnsafe as f, alloc$1 as g, encodingLength as h, encode$2 as i, decode$2 as j, FilterSubscribeResponse$1 as k, PushRpc$1 as l, PushResponse as m, StoreQueryResponse$1 as n, bases as o, fromString as p, createEncoder as q, pubsubTopicToSingleShardInfo as r, bytesToUtf8 as s, toString as t, utf8ToBytes as u, version_0 as v, shardInfoToPubsubTopics as w, EConnectionStateEvents as x, pubsubTopicsToShardInfo as y, WakuMetadataResponse as z };