@waku/core 0.0.3 → 0.0.5
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
CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## @waku/core [0.0.4](https://github.com/waku-org/js-waku/compare/@waku/core@0.0.3...@waku/core@0.0.4) (2022-11-09)
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
- Bumped `libp2p` to 0.39.2.
|
15
|
+
|
10
16
|
## @waku/core [0.0.2](https://github.com/waku-org/js-waku/compare/@waku/core@0.0.1...@waku/core@0.0.2) (2022-11-04)
|
11
17
|
|
12
18
|
### Changed
|
@@ -1,8 +1,6 @@
|
|
1
1
|
import { e as errCode } from './index-64ce43f0.js';
|
2
2
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
4
|
-
// We don't care about how the IP is invalid. Save time in the error case by using a single error
|
5
|
-
const err = new Error("Invalid IP");
|
6
4
|
class Parser {
|
7
5
|
index = 0;
|
8
6
|
input = "";
|
@@ -14,33 +12,31 @@ class Parser {
|
|
14
12
|
/** Run a parser, and restore the pre-parse state if it fails. */
|
15
13
|
readAtomically(fn) {
|
16
14
|
const index = this.index;
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
catch (e) {
|
15
|
+
const result = fn();
|
16
|
+
if (result === undefined) {
|
21
17
|
this.index = index;
|
22
|
-
throw e;
|
23
18
|
}
|
19
|
+
return result;
|
24
20
|
}
|
25
21
|
/** Run a parser, but fail if the entire input wasn't consumed. Doesn't run atomically. */
|
26
22
|
parseWith(fn) {
|
27
23
|
const result = fn();
|
28
24
|
if (this.index !== this.input.length) {
|
29
|
-
|
25
|
+
return undefined;
|
30
26
|
}
|
31
27
|
return result;
|
32
28
|
}
|
33
29
|
/** Peek the next character from the input */
|
34
30
|
peekChar() {
|
35
31
|
if (this.index >= this.input.length) {
|
36
|
-
|
32
|
+
return undefined;
|
37
33
|
}
|
38
34
|
return this.input[this.index];
|
39
35
|
}
|
40
36
|
/** Read the next character from the input */
|
41
37
|
readChar() {
|
42
38
|
if (this.index >= this.input.length) {
|
43
|
-
|
39
|
+
return undefined;
|
44
40
|
}
|
45
41
|
return this.input[this.index++];
|
46
42
|
}
|
@@ -49,8 +45,9 @@ class Parser {
|
|
49
45
|
return this.readAtomically(() => {
|
50
46
|
const char = this.readChar();
|
51
47
|
if (char !== target) {
|
52
|
-
|
48
|
+
return undefined;
|
53
49
|
}
|
50
|
+
return char;
|
54
51
|
});
|
55
52
|
}
|
56
53
|
/**
|
@@ -62,7 +59,9 @@ class Parser {
|
|
62
59
|
readSeparator(sep, index, inner) {
|
63
60
|
return this.readAtomically(() => {
|
64
61
|
if (index > 0) {
|
65
|
-
this.readGivenChar(sep)
|
62
|
+
if (this.readGivenChar(sep) === undefined) {
|
63
|
+
return undefined;
|
64
|
+
}
|
66
65
|
}
|
67
66
|
return inner();
|
68
67
|
});
|
@@ -76,40 +75,45 @@ class Parser {
|
|
76
75
|
return this.readAtomically(() => {
|
77
76
|
let result = 0;
|
78
77
|
let digitCount = 0;
|
79
|
-
const
|
78
|
+
const leadingChar = this.peekChar();
|
79
|
+
if (leadingChar === undefined) {
|
80
|
+
return undefined;
|
81
|
+
}
|
82
|
+
const hasLeadingZero = leadingChar === "0";
|
80
83
|
const maxValue = 2 ** (8 * maxBytes) - 1;
|
81
84
|
// eslint-disable-next-line no-constant-condition
|
82
85
|
while (true) {
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
return
|
91
|
-
}
|
92
|
-
|
93
|
-
|
86
|
+
const digit = this.readAtomically(() => {
|
87
|
+
const char = this.readChar();
|
88
|
+
if (char === undefined) {
|
89
|
+
return undefined;
|
90
|
+
}
|
91
|
+
const num = Number.parseInt(char, radix);
|
92
|
+
if (Number.isNaN(num)) {
|
93
|
+
return undefined;
|
94
|
+
}
|
95
|
+
return num;
|
96
|
+
});
|
97
|
+
if (digit === undefined) {
|
94
98
|
break;
|
95
99
|
}
|
96
100
|
result *= radix;
|
97
101
|
result += digit;
|
98
102
|
if (result > maxValue) {
|
99
|
-
|
103
|
+
return undefined;
|
100
104
|
}
|
101
105
|
digitCount += 1;
|
102
106
|
if (maxDigits !== undefined) {
|
103
107
|
if (digitCount > maxDigits) {
|
104
|
-
|
108
|
+
return undefined;
|
105
109
|
}
|
106
110
|
}
|
107
111
|
}
|
108
112
|
if (digitCount === 0) {
|
109
|
-
|
113
|
+
return undefined;
|
110
114
|
}
|
111
115
|
else if (!allowZeroPrefix && hasLeadingZero && digitCount > 1) {
|
112
|
-
|
116
|
+
return undefined;
|
113
117
|
}
|
114
118
|
else {
|
115
119
|
return result;
|
@@ -121,7 +125,11 @@ class Parser {
|
|
121
125
|
return this.readAtomically(() => {
|
122
126
|
const out = new Uint8Array(4);
|
123
127
|
for (let i = 0; i < out.length; i++) {
|
124
|
-
|
128
|
+
const ix = this.readSeparator(".", i, () => this.readNumber(10, 3, false, 1));
|
129
|
+
if (ix === undefined) {
|
130
|
+
return undefined;
|
131
|
+
}
|
132
|
+
out[i] = ix;
|
125
133
|
}
|
126
134
|
return out;
|
127
135
|
});
|
@@ -140,25 +148,21 @@ class Parser {
|
|
140
148
|
const ix = i * 2;
|
141
149
|
// Try to read a trailing embedded IPv4 address. There must be at least 4 groups left.
|
142
150
|
if (i < groups.length - 3) {
|
143
|
-
|
144
|
-
|
151
|
+
const ipv4 = this.readSeparator(":", i, () => this.readIPv4Addr());
|
152
|
+
if (ipv4 !== undefined) {
|
145
153
|
groups[ix] = ipv4[0];
|
146
154
|
groups[ix + 1] = ipv4[1];
|
147
155
|
groups[ix + 2] = ipv4[2];
|
148
156
|
groups[ix + 3] = ipv4[3];
|
149
157
|
return [ix + 4, true];
|
150
|
-
// eslint-disable-next-line no-empty
|
151
158
|
}
|
152
|
-
catch (e) { }
|
153
|
-
}
|
154
|
-
try {
|
155
|
-
const group = this.readSeparator(":", i, () => this.readNumber(16, 4, true, 2));
|
156
|
-
groups[ix] = group >> 8;
|
157
|
-
groups[ix + 1] = group & 255;
|
158
159
|
}
|
159
|
-
|
160
|
+
const group = this.readSeparator(":", i, () => this.readNumber(16, 4, true, 2));
|
161
|
+
if (group === undefined) {
|
160
162
|
return [ix, false];
|
161
163
|
}
|
164
|
+
groups[ix] = group >> 8;
|
165
|
+
groups[ix + 1] = group & 255;
|
162
166
|
}
|
163
167
|
return [groups.length, false];
|
164
168
|
};
|
@@ -171,12 +175,16 @@ class Parser {
|
|
171
175
|
}
|
172
176
|
// IPv4 part is not allowed before `::`
|
173
177
|
if (headIp4) {
|
174
|
-
|
178
|
+
return undefined;
|
175
179
|
}
|
176
180
|
// Read `::` if previous code parsed less than 8 groups.
|
177
181
|
// `::` indicates one or more groups of 16 bits of zeros.
|
178
|
-
this.readGivenChar(":")
|
179
|
-
|
182
|
+
if (this.readGivenChar(":") === undefined) {
|
183
|
+
return undefined;
|
184
|
+
}
|
185
|
+
if (this.readGivenChar(":") === undefined) {
|
186
|
+
return undefined;
|
187
|
+
}
|
180
188
|
// Read the back part of the address. The :: must contain at least one
|
181
189
|
// set of zeroes, so our max length is 7.
|
182
190
|
const tail = new Uint8Array(14);
|
@@ -189,12 +197,7 @@ class Parser {
|
|
189
197
|
}
|
190
198
|
/** Read an IP Address, either IPv4 or IPv6. */
|
191
199
|
readIPAddr() {
|
192
|
-
|
193
|
-
return this.readIPv4Addr();
|
194
|
-
}
|
195
|
-
catch (e) {
|
196
|
-
return this.readIPv6Addr();
|
197
|
-
}
|
200
|
+
return this.readIPv4Addr() ?? this.readIPv6Addr();
|
198
201
|
}
|
199
202
|
}
|
200
203
|
|
@@ -205,53 +208,36 @@ const parser = new Parser();
|
|
205
208
|
/** Parse `input` into IPv4 bytes. */
|
206
209
|
function parseIPv4(input) {
|
207
210
|
if (input.length > MAX_IPV4_LENGTH) {
|
208
|
-
|
211
|
+
return undefined;
|
209
212
|
}
|
210
213
|
return parser.new(input).parseWith(() => parser.readIPv4Addr());
|
211
214
|
}
|
212
215
|
/** Parse `input` into IPv6 bytes. */
|
213
216
|
function parseIPv6(input) {
|
214
217
|
if (input.length > MAX_IPV6_LENGTH) {
|
215
|
-
|
218
|
+
return undefined;
|
216
219
|
}
|
217
220
|
return parser.new(input).parseWith(() => parser.readIPv6Addr());
|
218
221
|
}
|
219
222
|
/** Parse `input` into IPv4 or IPv6 bytes. */
|
220
223
|
function parseIP(input) {
|
221
224
|
if (input.length > MAX_IPV6_LENGTH) {
|
222
|
-
|
225
|
+
return undefined;
|
223
226
|
}
|
224
227
|
return parser.new(input).parseWith(() => parser.readIPAddr());
|
225
228
|
}
|
229
|
+
|
226
230
|
/** Check if `input` is IPv4. */
|
227
231
|
function isIPv4(input) {
|
228
|
-
|
229
|
-
parseIPv4(input);
|
230
|
-
return true;
|
231
|
-
}
|
232
|
-
catch (e) {
|
233
|
-
return false;
|
234
|
-
}
|
232
|
+
return Boolean(parseIPv4(input));
|
235
233
|
}
|
236
234
|
/** Check if `input` is IPv6. */
|
237
235
|
function isIPv6(input) {
|
238
|
-
|
239
|
-
parseIPv6(input);
|
240
|
-
return true;
|
241
|
-
}
|
242
|
-
catch (e) {
|
243
|
-
return false;
|
244
|
-
}
|
236
|
+
return Boolean(parseIPv6(input));
|
245
237
|
}
|
246
238
|
/** Check if `input` is IPv4 or IPv6. */
|
247
239
|
function isIP(input) {
|
248
|
-
|
249
|
-
parseIP(input);
|
250
|
-
return true;
|
251
|
-
}
|
252
|
-
catch (e) {
|
253
|
-
return false;
|
254
|
-
}
|
240
|
+
return Boolean(parseIP(input));
|
255
241
|
}
|
256
242
|
|
257
243
|
// base-x encoding / decoding
|
package/bundle/index.js
CHANGED
@@ -5,7 +5,7 @@ export { proto as proto_message } from './lib/waku_message/version_0.js';
|
|
5
5
|
import { T as TopicOnlyDecoder } from './topic_only_message-5ad3a869.js';
|
6
6
|
export { t as proto_topic_only_message } from './topic_only_message-5ad3a869.js';
|
7
7
|
import { p as peerIdFromString, a as peerIdFromKeys, b as peerIdFromBytes, E as EventEmitter, C as CustomEvent } from './events-158407bb.js';
|
8
|
-
import { m as multiaddr } from './index-
|
8
|
+
import { m as multiaddr } from './index-8710041d.js';
|
9
9
|
import { d as debug } from './browser-1e1a2f27.js';
|
10
10
|
import { e as errCode } from './index-64ce43f0.js';
|
11
11
|
import { r as requireAspromise, a as requireBase64, b as requireEventemitter, c as requireFloat, d as requireInquire, e as requireUtf8, f as requirePool, g as commonjsGlobal, h as getAugmentedNamespace } from './message-049c8b67.js';
|
@@ -21875,7 +21875,7 @@ async function unmarshalPrivateKey(buf) {
|
|
21875
21875
|
}
|
21876
21876
|
}
|
21877
21877
|
|
21878
|
-
const codes
|
21878
|
+
const codes = {
|
21879
21879
|
ERR_SIGNATURE_NOT_VALID: 'ERR_SIGNATURE_NOT_VALID'
|
21880
21880
|
};
|
21881
21881
|
|
@@ -23788,7 +23788,7 @@ RecordEnvelope.openAndCertify = async (data, domain) => {
|
|
23788
23788
|
const envelope = await RecordEnvelope.createFromProtobuf(data);
|
23789
23789
|
const valid = await envelope.validate(domain);
|
23790
23790
|
if (!valid) {
|
23791
|
-
throw errCode(new Error('envelope signature is not valid for the given domain'), codes
|
23791
|
+
throw errCode(new Error('envelope signature is not valid for the given domain'), codes.ERR_SIGNATURE_NOT_VALID);
|
23792
23792
|
}
|
23793
23793
|
return envelope;
|
23794
23794
|
};
|
@@ -23810,108 +23810,6 @@ const formatSignaturePayload = (domain, payloadType, payload) => {
|
|
23810
23810
|
return new Uint8ArrayList(domainLength, domainUint8Array, payloadTypeLength, payloadType, payloadLength, payload);
|
23811
23811
|
};
|
23812
23812
|
|
23813
|
-
const V = -1;
|
23814
|
-
const names = {};
|
23815
|
-
const codes = {};
|
23816
|
-
const table = [
|
23817
|
-
[4, 32, 'ip4'],
|
23818
|
-
[6, 16, 'tcp'],
|
23819
|
-
[33, 16, 'dccp'],
|
23820
|
-
[41, 128, 'ip6'],
|
23821
|
-
[42, V, 'ip6zone'],
|
23822
|
-
[53, V, 'dns', true],
|
23823
|
-
[54, V, 'dns4', true],
|
23824
|
-
[55, V, 'dns6', true],
|
23825
|
-
[56, V, 'dnsaddr', true],
|
23826
|
-
[132, 16, 'sctp'],
|
23827
|
-
[273, 16, 'udp'],
|
23828
|
-
[275, 0, 'p2p-webrtc-star'],
|
23829
|
-
[276, 0, 'p2p-webrtc-direct'],
|
23830
|
-
[277, 0, 'p2p-stardust'],
|
23831
|
-
[280, 0, 'webrtc'],
|
23832
|
-
[290, 0, 'p2p-circuit'],
|
23833
|
-
[301, 0, 'udt'],
|
23834
|
-
[302, 0, 'utp'],
|
23835
|
-
[400, V, 'unix', false, true],
|
23836
|
-
// `ipfs` is added before `p2p` for legacy support.
|
23837
|
-
// All text representations will default to `p2p`, but `ipfs` will
|
23838
|
-
// still be supported
|
23839
|
-
[421, V, 'ipfs'],
|
23840
|
-
// `p2p` is the preferred name for 421, and is now the default
|
23841
|
-
[421, V, 'p2p'],
|
23842
|
-
[443, 0, 'https'],
|
23843
|
-
[444, 96, 'onion'],
|
23844
|
-
[445, 296, 'onion3'],
|
23845
|
-
[446, V, 'garlic64'],
|
23846
|
-
[460, 0, 'quic'],
|
23847
|
-
[465, 0, 'webtransport'],
|
23848
|
-
[466, V, 'certhash'],
|
23849
|
-
[477, 0, 'ws'],
|
23850
|
-
[478, 0, 'wss'],
|
23851
|
-
[479, 0, 'p2p-websocket-star'],
|
23852
|
-
[480, 0, 'http'],
|
23853
|
-
[777, V, 'memory']
|
23854
|
-
];
|
23855
|
-
// populate tables
|
23856
|
-
table.forEach(row => {
|
23857
|
-
const proto = createProtocol(...row);
|
23858
|
-
codes[proto.code] = proto;
|
23859
|
-
names[proto.name] = proto;
|
23860
|
-
});
|
23861
|
-
function createProtocol(code, size, name, resolvable, path) {
|
23862
|
-
return {
|
23863
|
-
code,
|
23864
|
-
size,
|
23865
|
-
name,
|
23866
|
-
resolvable: Boolean(resolvable),
|
23867
|
-
path: Boolean(path)
|
23868
|
-
};
|
23869
|
-
}
|
23870
|
-
function getProtocol(proto) {
|
23871
|
-
if (typeof proto === 'number') {
|
23872
|
-
if (codes[proto] != null) {
|
23873
|
-
return codes[proto];
|
23874
|
-
}
|
23875
|
-
throw new Error(`no protocol with code: ${proto}`);
|
23876
|
-
}
|
23877
|
-
else if (typeof proto === 'string') {
|
23878
|
-
if (names[proto] != null) {
|
23879
|
-
return names[proto];
|
23880
|
-
}
|
23881
|
-
throw new Error(`no protocol with name: ${proto}`);
|
23882
|
-
}
|
23883
|
-
throw new Error(`invalid protocol id type: ${typeof proto}`);
|
23884
|
-
}
|
23885
|
-
|
23886
|
-
const decoders = Object.values(bases$2).map((c) => c.decoder);
|
23887
|
-
((function () {
|
23888
|
-
let acc = decoders[0].or(decoders[1]);
|
23889
|
-
decoders.slice(2).forEach((d) => (acc = acc.or(d)));
|
23890
|
-
return acc;
|
23891
|
-
}))();
|
23892
|
-
|
23893
|
-
(undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
23894
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
23895
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
23896
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
23897
|
-
};
|
23898
|
-
(undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
23899
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
23900
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
23901
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
23902
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
23903
|
-
};
|
23904
|
-
[
|
23905
|
-
getProtocol('dns').code,
|
23906
|
-
getProtocol('dns4').code,
|
23907
|
-
getProtocol('dns6').code,
|
23908
|
-
getProtocol('dnsaddr').code
|
23909
|
-
];
|
23910
|
-
[
|
23911
|
-
getProtocol('p2p').code,
|
23912
|
-
getProtocol('ipfs').code
|
23913
|
-
];
|
23914
|
-
|
23915
23813
|
/* eslint-disable import/export */
|
23916
23814
|
var PeerRecord;
|
23917
23815
|
(function (PeerRecord) {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { p as peerIdFromString, E as EventEmitter, C as CustomEvent } from '../events-158407bb.js';
|
2
|
-
import { m as multiaddr } from '../index-
|
2
|
+
import { m as multiaddr } from '../index-8710041d.js';
|
3
3
|
import { d as debug } from '../browser-1e1a2f27.js';
|
4
4
|
import { g as getPseudoRandomSubset } from '../random_subset-75d1c511.js';
|
5
5
|
import '../index-64ce43f0.js';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@waku/core",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.5",
|
4
4
|
"description": "TypeScript implementation of the Waku v2 protocol",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"module": "./dist/index.js",
|
@@ -88,7 +88,7 @@
|
|
88
88
|
"dependencies": {
|
89
89
|
"@waku/byte-utils": "*",
|
90
90
|
"@chainsafe/libp2p-gossipsub": "^4.1.1",
|
91
|
-
"@libp2p/interface-connection": "3.0.
|
91
|
+
"@libp2p/interface-connection": "^3.0.3",
|
92
92
|
"@libp2p/interface-peer-discovery": "^1.0.0",
|
93
93
|
"@libp2p/interface-peer-id": "^1.0.2",
|
94
94
|
"@libp2p/interface-peer-info": "^1.0.1",
|
@@ -102,7 +102,7 @@
|
|
102
102
|
"it-all": "^1.0.6",
|
103
103
|
"it-length-prefixed": "^8.0.2",
|
104
104
|
"it-pipe": "^2.0.4",
|
105
|
-
"libp2p": "0.
|
105
|
+
"libp2p": "0.39.5",
|
106
106
|
"p-event": "^5.0.1",
|
107
107
|
"protons-runtime": "^3.1.0",
|
108
108
|
"uint8arraylist": "^2.3.2",
|