@waku/core 0.0.26 → 0.0.28-434be7b.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/CHANGELOG.md +26 -0
- package/bundle/{base_protocol-pDODy0G6.js → base_protocol-BCwLeb-A.js} +134 -89
- package/bundle/{browser-mTOOnVZp.js → browser-DoQRY-an.js} +518 -712
- package/bundle/{index-cmONXM-V.js → index-vlQahmUj.js} +98 -41
- package/bundle/index.js +3081 -21642
- package/bundle/lib/base_protocol.js +3 -3
- package/bundle/lib/message/version_0.js +3 -3
- package/bundle/lib/predefined_bootstrap_nodes.js +1 -1
- package/bundle/{version_0-LQTFNC7k.js → version_0-DiakMc1A.js} +1246 -2444
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +15 -13
- package/dist/lib/base_protocol.js +35 -22
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.d.ts +2 -2
- package/dist/lib/connection_manager.js +16 -6
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/index.d.ts +1 -1
- package/dist/lib/filter/index.js +144 -82
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/filterPeers.d.ts +8 -5
- package/dist/lib/filterPeers.js +12 -5
- package/dist/lib/filterPeers.js.map +1 -1
- package/dist/lib/keep_alive_manager.d.ts +2 -3
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +12 -2
- package/dist/lib/light_push/index.js +80 -80
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +2 -2
- package/dist/lib/metadata/index.js +58 -16
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/store/index.js +1 -3
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager.d.ts +2 -2
- package/dist/lib/stream_manager.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.d.ts +1 -1
- package/dist/lib/wait_for_remote_peer.js +42 -10
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/package.json +1 -127
- package/src/index.ts +1 -6
- package/src/lib/base_protocol.ts +57 -37
- package/src/lib/connection_manager.ts +17 -10
- package/src/lib/filter/index.ts +234 -136
- package/src/lib/filterPeers.ts +15 -7
- package/src/lib/keep_alive_manager.ts +2 -3
- package/src/lib/light_push/index.ts +104 -124
- package/src/lib/metadata/index.ts +92 -30
- package/src/lib/store/index.ts +3 -6
- package/src/lib/stream_manager.ts +2 -3
- package/src/lib/wait_for_remote_peer.ts +68 -12
- package/dist/lib/waku.d.ts +0 -57
- package/dist/lib/waku.js +0 -130
- package/dist/lib/waku.js.map +0 -1
- package/src/lib/waku.ts +0 -214
@@ -1,9 +1,4 @@
|
|
1
|
-
import { i as identityBase,
|
2
|
-
|
3
|
-
// @ts-check
|
4
|
-
|
5
|
-
|
6
|
-
const bases = { ...identityBase, ...base2, ...base8, ...base10, ...base16, ...base32, ...base36, ...base58, ...base64, ...base256emoji };
|
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';
|
7
2
|
|
8
3
|
/**
|
9
4
|
* To guarantee Uint8Array semantics, convert nodejs Buffers
|
@@ -38,6 +33,8 @@ function allocUnsafe(size = 0) {
|
|
38
33
|
return new Uint8Array(size);
|
39
34
|
}
|
40
35
|
|
36
|
+
const bases = { ...identityBase, ...base2, ...base8, ...base10, ...base16, ...base32, ...base36, ...base58, ...base64, ...base256emoji };
|
37
|
+
|
41
38
|
function createCodec(name, prefix, encode, decode) {
|
42
39
|
return {
|
43
40
|
name,
|
@@ -83,25 +80,6 @@ const BASES = {
|
|
83
80
|
...bases
|
84
81
|
};
|
85
82
|
|
86
|
-
/**
|
87
|
-
* Turns a `Uint8Array` into a string.
|
88
|
-
*
|
89
|
-
* Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
|
90
|
-
*
|
91
|
-
* Also `ascii` which is similar to node's 'binary' encoding.
|
92
|
-
*/
|
93
|
-
function toString(array, encoding = 'utf8') {
|
94
|
-
const base = BASES[encoding];
|
95
|
-
if (base == null) {
|
96
|
-
throw new Error(`Unsupported encoding "${encoding}"`);
|
97
|
-
}
|
98
|
-
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
|
99
|
-
return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString('utf8');
|
100
|
-
}
|
101
|
-
// strip multibase prefix
|
102
|
-
return base.encoder.encode(array).substring(1);
|
103
|
-
}
|
104
|
-
|
105
83
|
/**
|
106
84
|
* Create a `Uint8Array` from the passed string
|
107
85
|
*
|
@@ -121,13 +99,13 @@ function fromString(string, encoding = 'utf8') {
|
|
121
99
|
return base.decoder.decode(`${base.prefix}${string}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
|
122
100
|
}
|
123
101
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
102
|
+
// copied from utils
|
103
|
+
function isBytes$1(a) {
|
104
|
+
return (a instanceof Uint8Array ||
|
105
|
+
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
|
106
|
+
}
|
129
107
|
function bytes(b, ...lengths) {
|
130
|
-
if (!(b
|
108
|
+
if (!isBytes$1(b))
|
131
109
|
throw new Error('Expected Uint8Array');
|
132
110
|
if (lengths.length > 0 && !lengths.includes(b.length))
|
133
111
|
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
|
@@ -152,14 +130,19 @@ function output(out, instance) {
|
|
152
130
|
// For node.js, package.json#exports field mapping rewrites import
|
153
131
|
// from `crypto` to `cryptoNode`, which imports native module.
|
154
132
|
// Makes the utils un-importable in browsers without a bundler.
|
155
|
-
// Once node.js 18 is deprecated, we can just drop the import.
|
156
|
-
|
133
|
+
// 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
|
+
}
|
157
138
|
// Cast array to view
|
158
139
|
const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
159
140
|
// The rotate right (circular right shift) operation for uint32
|
160
141
|
const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
|
161
142
|
// big-endian hardware is rare. Just in case someone still decides to run hashes:
|
162
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.
|
163
146
|
const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
164
147
|
if (!isLE)
|
165
148
|
throw new Error('Non little-endian hardware is not supported');
|
@@ -179,7 +162,7 @@ function utf8ToBytes$1(str) {
|
|
179
162
|
function toBytes(data) {
|
180
163
|
if (typeof data === 'string')
|
181
164
|
data = utf8ToBytes$1(data);
|
182
|
-
if (!
|
165
|
+
if (!isBytes(data))
|
183
166
|
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
184
167
|
return data;
|
185
168
|
}
|
@@ -419,6 +402,34 @@ class SHA256 extends SHA2 {
|
|
419
402
|
*/
|
420
403
|
const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
421
404
|
|
405
|
+
/**
|
406
|
+
* DefaultPubsubTopic is the default gossipsub topic to use for Waku.
|
407
|
+
*/
|
408
|
+
const DefaultPubsubTopic = "/waku/2/default-waku/proto";
|
409
|
+
/**
|
410
|
+
* The default cluster ID for The Waku Network
|
411
|
+
*/
|
412
|
+
const DEFAULT_CLUSTER_ID = 1;
|
413
|
+
|
414
|
+
/**
|
415
|
+
* Turns a `Uint8Array` into a string.
|
416
|
+
*
|
417
|
+
* Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
|
418
|
+
*
|
419
|
+
* Also `ascii` which is similar to node's 'binary' encoding.
|
420
|
+
*/
|
421
|
+
function toString(array, encoding = 'utf8') {
|
422
|
+
const base = BASES[encoding];
|
423
|
+
if (base == null) {
|
424
|
+
throw new Error(`Unsupported encoding "${encoding}"`);
|
425
|
+
}
|
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
|
+
// strip multibase prefix
|
430
|
+
return base.encoder.encode(array).substring(1);
|
431
|
+
}
|
432
|
+
|
422
433
|
/**
|
423
434
|
* Decode byte array to utf-8 string.
|
424
435
|
*/
|
@@ -447,9 +458,7 @@ const singleShardInfoToPubsubTopic = (shardInfo) => {
|
|
447
458
|
return `/waku/2/rs/${shardInfo.clusterId}/${shardInfo.shard}`;
|
448
459
|
};
|
449
460
|
const shardInfoToPubsubTopics = (shardInfo) => {
|
450
|
-
if (shardInfo
|
451
|
-
throw new Error("Cluster ID must be specified");
|
452
|
-
if ("contentTopics" in shardInfo) {
|
461
|
+
if ("contentTopics" in shardInfo && shardInfo.contentTopics) {
|
453
462
|
// Autosharding: explicitly defined content topics
|
454
463
|
return Array.from(new Set(shardInfo.contentTopics.map((contentTopic) => contentTopicToPubsubTopic(contentTopic, shardInfo.clusterId))));
|
455
464
|
}
|
@@ -457,14 +466,17 @@ const shardInfoToPubsubTopics = (shardInfo) => {
|
|
457
466
|
// Static sharding
|
458
467
|
if (shardInfo.shards === undefined)
|
459
468
|
throw new Error("Invalid shard");
|
460
|
-
return Array.from(new Set(shardInfo.shards.map((index) => `/waku/2/rs/${shardInfo.clusterId}/${index}`)));
|
469
|
+
return Array.from(new Set(shardInfo.shards.map((index) => `/waku/2/rs/${shardInfo.clusterId ?? DEFAULT_CLUSTER_ID}/${index}`)));
|
461
470
|
}
|
462
|
-
else {
|
471
|
+
else if ("application" in shardInfo && "version" in shardInfo) {
|
463
472
|
// Autosharding: single shard from application and version
|
464
473
|
return [
|
465
474
|
contentTopicToPubsubTopic(`/${shardInfo.application}/${shardInfo.version}/default/default`)
|
466
475
|
];
|
467
476
|
}
|
477
|
+
else {
|
478
|
+
throw new Error("Missing required configuration in shard parameters");
|
479
|
+
}
|
468
480
|
};
|
469
481
|
const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
|
470
482
|
const parts = pubsubTopics.split("/");
|
@@ -482,6 +494,8 @@ const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
|
|
482
494
|
shard
|
483
495
|
};
|
484
496
|
};
|
497
|
+
//TODO: move part of BaseProtocol instead of utils
|
498
|
+
// return `ProtocolError.TOPIC_NOT_CONFIGURED` instead of throwing
|
485
499
|
function ensurePubsubTopicIsConfigured(pubsubTopic, configuredTopics) {
|
486
500
|
if (!configuredTopics.includes(pubsubTopic)) {
|
487
501
|
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.`);
|
@@ -544,7 +558,7 @@ function contentTopicToShardIndex(contentTopic, networkShards = 8) {
|
|
544
558
|
const dataview = new DataView(digest.buffer.slice(-8));
|
545
559
|
return Number(dataview.getBigUint64(0, false) % BigInt(networkShards));
|
546
560
|
}
|
547
|
-
function contentTopicToPubsubTopic(contentTopic, clusterId =
|
561
|
+
function contentTopicToPubsubTopic(contentTopic, clusterId = DEFAULT_CLUSTER_ID, networkShards = 8) {
|
548
562
|
const shardIndex = contentTopicToShardIndex(contentTopic, networkShards);
|
549
563
|
return `/waku/2/rs/${clusterId}/${shardIndex}`;
|
550
564
|
}
|
@@ -563,6 +577,49 @@ function determinePubsubTopic(contentTopic, pubsubTopicShardInfo = DefaultPubsub
|
|
563
577
|
: DefaultPubsubTopic;
|
564
578
|
}
|
565
579
|
}
|
580
|
+
/**
|
581
|
+
* Validates sharding configuration and sets defaults where possible.
|
582
|
+
* @returns Validated sharding parameters, with any missing values set to defaults
|
583
|
+
*/
|
584
|
+
const ensureShardingConfigured = (shardInfo) => {
|
585
|
+
const clusterId = shardInfo.clusterId ?? DEFAULT_CLUSTER_ID;
|
586
|
+
const shards = "shards" in shardInfo ? shardInfo.shards : [];
|
587
|
+
const contentTopics = "contentTopics" in shardInfo ? shardInfo.contentTopics : [];
|
588
|
+
const [application, version] = "application" in shardInfo && "version" in shardInfo
|
589
|
+
? [shardInfo.application, shardInfo.version]
|
590
|
+
: [undefined, undefined];
|
591
|
+
const isShardsConfigured = shards && shards.length > 0;
|
592
|
+
const isContentTopicsConfigured = contentTopics && contentTopics.length > 0;
|
593
|
+
const isApplicationVersionConfigured = application && version;
|
594
|
+
if (isShardsConfigured) {
|
595
|
+
return {
|
596
|
+
shardingParams: { clusterId, shards },
|
597
|
+
shardInfo: { clusterId, shards },
|
598
|
+
pubsubTopics: shardInfoToPubsubTopics({ clusterId, shards })
|
599
|
+
};
|
600
|
+
}
|
601
|
+
if (isContentTopicsConfigured) {
|
602
|
+
const pubsubTopics = Array.from(new Set(contentTopics.map((topic) => contentTopicToPubsubTopic(topic, clusterId))));
|
603
|
+
const shards = Array.from(new Set(contentTopics.map((topic) => contentTopicToShardIndex(topic))));
|
604
|
+
return {
|
605
|
+
shardingParams: { clusterId, contentTopics },
|
606
|
+
shardInfo: { clusterId, shards },
|
607
|
+
pubsubTopics
|
608
|
+
};
|
609
|
+
}
|
610
|
+
if (isApplicationVersionConfigured) {
|
611
|
+
const pubsubTopic = contentTopicToPubsubTopic(`/${application}/${version}/default/default`);
|
612
|
+
return {
|
613
|
+
shardingParams: { clusterId, application, version },
|
614
|
+
shardInfo: {
|
615
|
+
clusterId,
|
616
|
+
shards: [pubsubTopicToSingleShardInfo(pubsubTopic).shard]
|
617
|
+
},
|
618
|
+
pubsubTopics: [pubsubTopic]
|
619
|
+
};
|
620
|
+
}
|
621
|
+
throw new Error("Missing minimum required configuration options for static sharding or autosharding.");
|
622
|
+
};
|
566
623
|
|
567
624
|
const APP_NAME = "waku";
|
568
625
|
class Logger {
|
@@ -592,4 +649,4 @@ class Logger {
|
|
592
649
|
}
|
593
650
|
}
|
594
651
|
|
595
|
-
export { DefaultPubsubTopic as D, Logger as L,
|
652
|
+
export { DefaultPubsubTopic as D, Logger as L, asUint8Array as a, bytesToUtf8 as b, concat as c, allocUnsafe as d, alloc as e, singleShardInfoToPubsubTopic as f, ensurePubsubTopicIsConfigured as g, shardInfoToPubsubTopics as h, fromString as i, determinePubsubTopic as j, ensureShardingConfigured as k, pubsubTopicToSingleShardInfo as p, sha256 as s, utf8ToBytes as u };
|