@waku/core 0.0.27 → 0.0.28-17a8640.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/{base_protocol-LhsIWF3-.js → base_protocol-D0Zdzb-v.js} +2 -5
- package/bundle/{browser-BQyFvtq6.js → browser-DoQRY-an.js} +18 -13
- package/bundle/{index-8YyfzF9R.js → index-BJwgMx4y.js} +35 -62
- package/bundle/index.js +258 -342
- package/bundle/lib/base_protocol.js +3 -3
- package/bundle/lib/message/version_0.js +3 -3
- package/bundle/lib/predefined_bootstrap_nodes.js +17 -17
- package/bundle/{version_0-FXfzO8Km.js → version_0-C6o0DvNW.js} +566 -321
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +4 -5
- package/dist/lib/base_protocol.js +0 -3
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/filter/index.js +4 -0
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +12 -2
- package/dist/lib/light_push/index.js +79 -76
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/message/version_0.js +1 -1
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +1 -1
- package/dist/lib/metadata/index.js +42 -14
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/predefined_bootstrap_nodes.d.ts +11 -11
- package/dist/lib/predefined_bootstrap_nodes.js +16 -16
- package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
- package/dist/lib/store/history_rpc.js +1 -1
- package/dist/lib/store/history_rpc.js.map +1 -1
- package/dist/lib/store/index.d.ts +14 -6
- package/dist/lib/store/index.js +50 -232
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js +4 -2
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/package.json +1 -129
- package/src/index.ts +3 -2
- package/src/lib/base_protocol.ts +4 -9
- package/src/lib/filter/index.ts +7 -0
- package/src/lib/light_push/index.ts +97 -118
- package/src/lib/metadata/index.ts +56 -26
- package/src/lib/predefined_bootstrap_nodes.ts +22 -22
- package/src/lib/store/index.ts +77 -339
- package/src/lib/wait_for_remote_peer.ts +14 -4
@@ -1,5 +1,5 @@
|
|
1
|
-
import { b as bytesToUtf8, L as Logger,
|
2
|
-
import { T as Tags } from './browser-
|
1
|
+
import { b as bytesToUtf8, L as Logger, j as ensureShardingConfigured } from './index-BJwgMx4y.js';
|
2
|
+
import { T as Tags } from './browser-DoQRY-an.js';
|
3
3
|
|
4
4
|
const decodeRelayShard = (bytes) => {
|
5
5
|
// explicitly converting to Uint8Array to avoid Buffer
|
@@ -229,7 +229,6 @@ class StreamManager {
|
|
229
229
|
};
|
230
230
|
}
|
231
231
|
|
232
|
-
const DEFAULT_NUM_PEERS_TO_USE = 3;
|
233
232
|
/**
|
234
233
|
* A class with predefined helpers, to be used as a base to implement Waku
|
235
234
|
* Protocols.
|
@@ -242,7 +241,6 @@ class BaseProtocol {
|
|
242
241
|
options;
|
243
242
|
addLibp2pEventListener;
|
244
243
|
removeLibp2pEventListener;
|
245
|
-
numPeersToUse;
|
246
244
|
streamManager;
|
247
245
|
constructor(multicodec, components, log, pubsubTopics, options) {
|
248
246
|
this.multicodec = multicodec;
|
@@ -250,7 +248,6 @@ class BaseProtocol {
|
|
250
248
|
this.log = log;
|
251
249
|
this.pubsubTopics = pubsubTopics;
|
252
250
|
this.options = options;
|
253
|
-
this.numPeersToUse = options?.numPeersToUse ?? DEFAULT_NUM_PEERS_TO_USE;
|
254
251
|
this.addLibp2pEventListener = components.events.addEventListener.bind(components.events);
|
255
252
|
this.removeLibp2pEventListener = components.events.removeEventListener.bind(components.events);
|
256
253
|
this.streamManager = new StreamManager(multicodec, components.connectionManager.getConnections.bind(components.connectionManager), this.addLibp2pEventListener);
|
@@ -627,54 +627,59 @@ var Protocols;
|
|
627
627
|
Protocols["LightPush"] = "lightpush";
|
628
628
|
Protocols["Filter"] = "filter";
|
629
629
|
})(Protocols || (Protocols = {}));
|
630
|
-
var
|
631
|
-
(function (
|
630
|
+
var ProtocolError;
|
631
|
+
(function (ProtocolError) {
|
632
632
|
/** Could not determine the origin of the fault. Best to check connectivity and try again */
|
633
|
-
|
633
|
+
ProtocolError["GENERIC_FAIL"] = "Generic error";
|
634
634
|
/**
|
635
635
|
* Failure to protobuf encode the message. This is not recoverable and needs
|
636
636
|
* further investigation.
|
637
637
|
*/
|
638
|
-
|
638
|
+
ProtocolError["ENCODE_FAILED"] = "Failed to encode";
|
639
639
|
/**
|
640
640
|
* Failure to protobuf decode the message. May be due to a remote peer issue,
|
641
641
|
* ensuring that messages are sent via several peer enable mitigation of this error.
|
642
642
|
*/
|
643
|
-
|
643
|
+
ProtocolError["DECODE_FAILED"] = "Failed to decode";
|
644
644
|
/**
|
645
645
|
* The message payload is empty, making the message invalid. Ensure that a non-empty
|
646
646
|
* payload is set on the outgoing message.
|
647
647
|
*/
|
648
|
-
|
648
|
+
ProtocolError["EMPTY_PAYLOAD"] = "Payload is empty";
|
649
649
|
/**
|
650
650
|
* The message size is above the maximum message size allowed on the Waku Network.
|
651
651
|
* Compressing the message or using an alternative strategy for large messages is recommended.
|
652
652
|
*/
|
653
|
-
|
653
|
+
ProtocolError["SIZE_TOO_BIG"] = "Size is too big";
|
654
654
|
/**
|
655
655
|
* The PubsubTopic passed to the send function is not configured on the Waku node.
|
656
656
|
* Please ensure that the PubsubTopic is used when initializing the Waku node.
|
657
657
|
*/
|
658
|
-
|
658
|
+
ProtocolError["TOPIC_NOT_CONFIGURED"] = "Topic not configured";
|
659
659
|
/**
|
660
660
|
* Failure to find a peer with suitable protocols. This may due to a connection issue.
|
661
661
|
* Mitigation can be: retrying after a given time period, display connectivity issue
|
662
662
|
* to user or listening for `peer:connected:bootstrap` or `peer:connected:peer-exchange`
|
663
663
|
* on the connection manager before retrying.
|
664
664
|
*/
|
665
|
-
|
665
|
+
ProtocolError["NO_PEER_AVAILABLE"] = "No peer available";
|
666
666
|
/**
|
667
667
|
* The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
|
668
668
|
* or `DECODE_FAILED` can be used.
|
669
669
|
*/
|
670
|
-
|
670
|
+
ProtocolError["REMOTE_PEER_FAULT"] = "Remote peer fault";
|
671
671
|
/**
|
672
672
|
* The remote peer rejected the message. Information provided by the remote peer
|
673
673
|
* is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
|
674
674
|
* or `DECODE_FAILED` can be used.
|
675
675
|
*/
|
676
|
-
|
677
|
-
|
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 = {}));
|
678
683
|
|
679
684
|
var PageDirection;
|
680
685
|
(function (PageDirection) {
|
@@ -1426,4 +1431,4 @@ var common = setup;
|
|
1426
1431
|
var browserExports = browser.exports;
|
1427
1432
|
var debug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
1428
1433
|
|
1429
|
-
export { EConnectionStateEvents as E,
|
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 };
|
@@ -1,24 +1,10 @@
|
|
1
|
-
import { i as identityBase,
|
2
|
-
|
3
|
-
/**
|
4
|
-
* To guarantee Uint8Array semantics, convert nodejs Buffers
|
5
|
-
* into vanilla Uint8Arrays
|
6
|
-
*/
|
7
|
-
function asUint8Array(buf) {
|
8
|
-
if (globalThis.Buffer != null) {
|
9
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
10
|
-
}
|
11
|
-
return buf;
|
12
|
-
}
|
1
|
+
import { i as identityBase, c as base2, d as base8, e as base10, f as base16, h as base32, j as base36, k as base58, l as base64, m as base256emoji, n as debug } from './browser-DoQRY-an.js';
|
13
2
|
|
14
3
|
/**
|
15
4
|
* Returns a `Uint8Array` of the requested size. Referenced memory will
|
16
5
|
* be initialized to 0.
|
17
6
|
*/
|
18
7
|
function alloc(size = 0) {
|
19
|
-
if (globalThis.Buffer?.alloc != null) {
|
20
|
-
return asUint8Array(globalThis.Buffer.alloc(size));
|
21
|
-
}
|
22
8
|
return new Uint8Array(size);
|
23
9
|
}
|
24
10
|
/**
|
@@ -27,9 +13,6 @@ function alloc(size = 0) {
|
|
27
13
|
* overwrite every value in the returned `Uint8Array`.
|
28
14
|
*/
|
29
15
|
function allocUnsafe(size = 0) {
|
30
|
-
if (globalThis.Buffer?.allocUnsafe != null) {
|
31
|
-
return asUint8Array(globalThis.Buffer.allocUnsafe(size));
|
32
|
-
}
|
33
16
|
return new Uint8Array(size);
|
34
17
|
}
|
35
18
|
|
@@ -92,23 +75,20 @@ function fromString(string, encoding = 'utf8') {
|
|
92
75
|
if (base == null) {
|
93
76
|
throw new Error(`Unsupported encoding "${encoding}"`);
|
94
77
|
}
|
95
|
-
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
|
96
|
-
return asUint8Array(globalThis.Buffer.from(string, 'utf-8'));
|
97
|
-
}
|
98
78
|
// add multibase prefix
|
99
79
|
return base.decoder.decode(`${base.prefix}${string}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
|
100
80
|
}
|
101
81
|
|
102
82
|
// copied from utils
|
103
|
-
function isBytes
|
83
|
+
function isBytes(a) {
|
104
84
|
return (a instanceof Uint8Array ||
|
105
85
|
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
|
106
86
|
}
|
107
87
|
function bytes(b, ...lengths) {
|
108
|
-
if (!isBytes
|
109
|
-
throw new Error('
|
88
|
+
if (!isBytes(b))
|
89
|
+
throw new Error('Uint8Array expected');
|
110
90
|
if (lengths.length > 0 && !lengths.includes(b.length))
|
111
|
-
throw new Error(`
|
91
|
+
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
|
112
92
|
}
|
113
93
|
function exists(instance, checkFinished = true) {
|
114
94
|
if (instance.destroyed)
|
@@ -131,21 +111,11 @@ function output(out, instance) {
|
|
131
111
|
// from `crypto` to `cryptoNode`, which imports native module.
|
132
112
|
// Makes the utils un-importable in browsers without a bundler.
|
133
113
|
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
134
|
-
function isBytes(a) {
|
135
|
-
return (a instanceof Uint8Array ||
|
136
|
-
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
|
137
|
-
}
|
138
114
|
// Cast array to view
|
139
115
|
const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
140
116
|
// The rotate right (circular right shift) operation for uint32
|
141
117
|
const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
|
142
|
-
|
143
|
-
// early-throw an error because we don't support BE yet.
|
144
|
-
// Other libraries would silently corrupt the data instead of throwing an error,
|
145
|
-
// when they don't support it.
|
146
|
-
const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
147
|
-
if (!isLE)
|
148
|
-
throw new Error('Non little-endian hardware is not supported');
|
118
|
+
new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
149
119
|
/**
|
150
120
|
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
151
121
|
*/
|
@@ -162,8 +132,7 @@ function utf8ToBytes$1(str) {
|
|
162
132
|
function toBytes(data) {
|
163
133
|
if (typeof data === 'string')
|
164
134
|
data = utf8ToBytes$1(data);
|
165
|
-
|
166
|
-
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
135
|
+
bytes(data);
|
167
136
|
return data;
|
168
137
|
}
|
169
138
|
// For runtime check if class implements interface
|
@@ -195,8 +164,15 @@ function setBigUint64(view, byteOffset, value, isLE) {
|
|
195
164
|
view.setUint32(byteOffset + h, wh, isLE);
|
196
165
|
view.setUint32(byteOffset + l, wl, isLE);
|
197
166
|
}
|
198
|
-
//
|
199
|
-
|
167
|
+
// Choice: a ? b : c
|
168
|
+
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
169
|
+
// Majority function, true if any two inpust is true
|
170
|
+
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
171
|
+
/**
|
172
|
+
* Merkle-Damgard hash construction base class.
|
173
|
+
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
174
|
+
*/
|
175
|
+
class HashMD extends Hash {
|
200
176
|
constructor(blockLen, outputLen, padOffset, isLE) {
|
201
177
|
super();
|
202
178
|
this.blockLen = blockLen;
|
@@ -248,7 +224,8 @@ class SHA2 extends Hash {
|
|
248
224
|
// append the bit '1' to the message
|
249
225
|
buffer[pos++] = 0b10000000;
|
250
226
|
this.buffer.subarray(pos).fill(0);
|
251
|
-
// we have less than padOffset left in buffer, so we cannot put length in
|
227
|
+
// we have less than padOffset left in buffer, so we cannot put length in
|
228
|
+
// current block, need process it and pad again
|
252
229
|
if (this.padOffset > blockLen - pos) {
|
253
230
|
this.process(view, 0);
|
254
231
|
pos = 0;
|
@@ -296,10 +273,6 @@ class SHA2 extends Hash {
|
|
296
273
|
|
297
274
|
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
|
298
275
|
// BTC network is doing 2^67 hashes/sec as per early 2023.
|
299
|
-
// Choice: a ? b : c
|
300
|
-
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
301
|
-
// Majority function, true if any two inpust is true
|
302
|
-
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
303
276
|
// Round constants:
|
304
277
|
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
305
278
|
// prettier-ignore
|
@@ -313,27 +286,28 @@ const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
313
286
|
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
314
287
|
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
315
288
|
]);
|
316
|
-
// Initial state
|
289
|
+
// Initial state:
|
290
|
+
// first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19
|
317
291
|
// prettier-ignore
|
318
|
-
const
|
292
|
+
const SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
319
293
|
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
320
294
|
]);
|
321
295
|
// Temporary buffer, not used to store anything between runs
|
322
296
|
// Named this way because it matches specification.
|
323
297
|
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
324
|
-
class SHA256 extends
|
298
|
+
class SHA256 extends HashMD {
|
325
299
|
constructor() {
|
326
300
|
super(64, 32, 8, false);
|
327
301
|
// We cannot use array here since array allows indexing by variable
|
328
302
|
// which means optimizer/compiler cannot use registers.
|
329
|
-
this.A =
|
330
|
-
this.B =
|
331
|
-
this.C =
|
332
|
-
this.D =
|
333
|
-
this.E =
|
334
|
-
this.F =
|
335
|
-
this.G =
|
336
|
-
this.H =
|
303
|
+
this.A = SHA256_IV[0] | 0;
|
304
|
+
this.B = SHA256_IV[1] | 0;
|
305
|
+
this.C = SHA256_IV[2] | 0;
|
306
|
+
this.D = SHA256_IV[3] | 0;
|
307
|
+
this.E = SHA256_IV[4] | 0;
|
308
|
+
this.F = SHA256_IV[5] | 0;
|
309
|
+
this.G = SHA256_IV[6] | 0;
|
310
|
+
this.H = SHA256_IV[7] | 0;
|
337
311
|
}
|
338
312
|
get() {
|
339
313
|
const { A, B, C, D, E, F, G, H } = this;
|
@@ -423,9 +397,6 @@ function toString(array, encoding = 'utf8') {
|
|
423
397
|
if (base == null) {
|
424
398
|
throw new Error(`Unsupported encoding "${encoding}"`);
|
425
399
|
}
|
426
|
-
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
|
427
|
-
return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString('utf8');
|
428
|
-
}
|
429
400
|
// strip multibase prefix
|
430
401
|
return base.encoder.encode(array).substring(1);
|
431
402
|
}
|
@@ -471,7 +442,7 @@ const shardInfoToPubsubTopics = (shardInfo) => {
|
|
471
442
|
else if ("application" in shardInfo && "version" in shardInfo) {
|
472
443
|
// Autosharding: single shard from application and version
|
473
444
|
return [
|
474
|
-
contentTopicToPubsubTopic(`/${shardInfo.application}/${shardInfo.version}/default/default
|
445
|
+
contentTopicToPubsubTopic(`/${shardInfo.application}/${shardInfo.version}/default/default`, shardInfo.clusterId)
|
475
446
|
];
|
476
447
|
}
|
477
448
|
else {
|
@@ -494,6 +465,8 @@ const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
|
|
494
465
|
shard
|
495
466
|
};
|
496
467
|
};
|
468
|
+
//TODO: move part of BaseProtocol instead of utils
|
469
|
+
// return `ProtocolError.TOPIC_NOT_CONFIGURED` instead of throwing
|
497
470
|
function ensurePubsubTopicIsConfigured(pubsubTopic, configuredTopics) {
|
498
471
|
if (!configuredTopics.includes(pubsubTopic)) {
|
499
472
|
throw new Error(`Pubsub topic ${pubsubTopic} has not been configured on this instance. Configured topics are: ${configuredTopics}. Please update your configuration by passing in the topic during Waku node instantiation.`);
|
@@ -606,7 +579,7 @@ const ensureShardingConfigured = (shardInfo) => {
|
|
606
579
|
};
|
607
580
|
}
|
608
581
|
if (isApplicationVersionConfigured) {
|
609
|
-
const pubsubTopic = contentTopicToPubsubTopic(`/${application}/${version}/default/default
|
582
|
+
const pubsubTopic = contentTopicToPubsubTopic(`/${application}/${version}/default/default`, clusterId);
|
610
583
|
return {
|
611
584
|
shardingParams: { clusterId, application, version },
|
612
585
|
shardInfo: {
|
@@ -647,4 +620,4 @@ class Logger {
|
|
647
620
|
}
|
648
621
|
}
|
649
622
|
|
650
|
-
export { DefaultPubsubTopic as D, Logger as L,
|
623
|
+
export { DefaultPubsubTopic as D, Logger as L, allocUnsafe as a, bytesToUtf8 as b, concat as c, alloc as d, singleShardInfoToPubsubTopic as e, ensurePubsubTopicIsConfigured as f, shardInfoToPubsubTopics as g, fromString as h, determinePubsubTopic as i, ensureShardingConfigured as j, pubsubTopicToSingleShardInfo as p, sha256 as s, utf8ToBytes as u };
|