@waku/core 0.0.28-b5e8b17.0 → 0.0.28
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 +30 -0
- package/bundle/{base_protocol-BCwLeb-A.js → base_protocol-D0Zdzb-v.js} +1 -1
- package/bundle/{index-vlQahmUj.js → index-BJwgMx4y.js} +32 -61
- package/bundle/index.js +111 -250
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/lib/predefined_bootstrap_nodes.js +16 -16
- package/bundle/{version_0-DiakMc1A.js → version_0-C6o0DvNW.js} +566 -321
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/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/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 +1 -1
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/package.json +136 -1
- package/src/index.ts +2 -1
- 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 +1 -1
package/CHANGELOG.md
CHANGED
@@ -5,6 +5,36 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The file is maintained by [Release Please](https://github.com/googleapis/release-please) based on [Conventional Commits](https://www.conventionalcommits.org) specification,
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.0.28](https://github.com/waku-org/js-waku/compare/core-v0.0.27...core-v0.0.28) (2024-04-09)
|
9
|
+
|
10
|
+
|
11
|
+
### ⚠ BREAKING CHANGES
|
12
|
+
|
13
|
+
* **store:** move protocol implementation opinions to `@waku/sdk` ([#1913](https://github.com/waku-org/js-waku/issues/1913))
|
14
|
+
* **lightpush:** move protocol implementation opinions to `@waku/sdk` ([#1887](https://github.com/waku-org/js-waku/issues/1887))
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* Add cross peer dependency for [@waku](https://github.com/waku) packages ([#1889](https://github.com/waku-org/js-waku/issues/1889)) ([8f86740](https://github.com/waku-org/js-waku/commit/8f867404e3e950b6e491c8831068962c6968ed4e))
|
19
|
+
* **metadata:** Use error codes ([#1904](https://github.com/waku-org/js-waku/issues/1904)) ([1882023](https://github.com/waku-org/js-waku/commit/1882023c58c830fc31921fe786bce734536ac1da))
|
20
|
+
* Peer-exchange uses error codes ([#1907](https://github.com/waku-org/js-waku/issues/1907)) ([877fe1d](https://github.com/waku-org/js-waku/commit/877fe1dc1daf6826b60ac5011af2915c47864d90))
|
21
|
+
|
22
|
+
|
23
|
+
### Miscellaneous Chores
|
24
|
+
|
25
|
+
* **lightpush:** Move protocol implementation opinions to `@waku/sdk` ([#1887](https://github.com/waku-org/js-waku/issues/1887)) ([8deab11](https://github.com/waku-org/js-waku/commit/8deab11890160b40a22e7d11926a2307afb93af4))
|
26
|
+
* **store:** Move protocol implementation opinions to `@waku/sdk` ([#1913](https://github.com/waku-org/js-waku/issues/1913)) ([bf42c8f](https://github.com/waku-org/js-waku/commit/bf42c8f53a291172d6af64cbf72c4092146899df))
|
27
|
+
|
28
|
+
|
29
|
+
### Dependencies
|
30
|
+
|
31
|
+
* The following workspace dependencies were updated
|
32
|
+
* dependencies
|
33
|
+
* @waku/enr bumped from ^0.0.21 to ^0.0.22
|
34
|
+
* @waku/interfaces bumped from 0.0.22 to 0.0.23
|
35
|
+
* @waku/message-hash bumped from ^0.1.11 to ^0.1.12
|
36
|
+
* @waku/utils bumped from 0.0.15 to 0.0.16
|
37
|
+
|
8
38
|
## [0.0.27](https://github.com/waku-org/js-waku/compare/core-v0.0.26...core-v0.0.27) (2024-03-04)
|
9
39
|
|
10
40
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { b as bytesToUtf8, L as Logger,
|
1
|
+
import { b as bytesToUtf8, L as Logger, j as ensureShardingConfigured } from './index-BJwgMx4y.js';
|
2
2
|
import { T as Tags } from './browser-DoQRY-an.js';
|
3
3
|
|
4
4
|
const decodeRelayShard = (bytes) => {
|
@@ -1,24 +1,10 @@
|
|
1
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';
|
2
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
|
-
}
|
13
|
-
|
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 {
|
@@ -608,7 +579,7 @@ const ensureShardingConfigured = (shardInfo) => {
|
|
608
579
|
};
|
609
580
|
}
|
610
581
|
if (isApplicationVersionConfigured) {
|
611
|
-
const pubsubTopic = contentTopicToPubsubTopic(`/${application}/${version}/default/default
|
582
|
+
const pubsubTopic = contentTopicToPubsubTopic(`/${application}/${version}/default/default`, clusterId);
|
612
583
|
return {
|
613
584
|
shardingParams: { clusterId, application, version },
|
614
585
|
shardInfo: {
|
@@ -649,4 +620,4 @@ class Logger {
|
|
649
620
|
}
|
650
621
|
}
|
651
622
|
|
652
|
-
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 };
|