@waku/core 0.0.6 → 0.0.8
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 +42 -4
- package/bundle/index.js +10870 -3756
- package/bundle/lib/message/topic_only_message.js +33 -0
- package/bundle/lib/message/version_0.js +133 -0
- package/bundle/{message-70dbb19b.js → peer_exchange-df95c3a7.js} +1899 -16
- package/dist/index.d.ts +14 -14
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/lib/{waku_filter → filter}/filter_rpc.d.ts +1 -1
- package/dist/lib/{waku_filter → filter}/filter_rpc.js +1 -1
- package/dist/lib/filter/filter_rpc.js.map +1 -0
- package/dist/lib/{waku_filter → filter}/index.d.ts +3 -3
- package/dist/lib/{waku_filter → filter}/index.js +3 -4
- package/dist/lib/filter/index.js.map +1 -0
- package/dist/lib/{waku_light_push → light_push}/index.d.ts +3 -3
- package/dist/lib/{waku_light_push → light_push}/index.js +4 -5
- package/dist/lib/light_push/index.js.map +1 -0
- package/dist/lib/{waku_light_push → light_push}/push_rpc.d.ts +1 -1
- package/dist/lib/{waku_light_push → light_push}/push_rpc.js +1 -1
- package/dist/lib/light_push/push_rpc.js.map +1 -0
- package/dist/lib/message/topic_only_message.d.ts +16 -0
- package/dist/lib/{waku_message → message}/topic_only_message.js +1 -1
- package/dist/lib/message/topic_only_message.js.map +1 -0
- package/dist/lib/message/version_0.d.ts +54 -0
- package/dist/lib/{waku_message → message}/version_0.js +35 -7
- package/dist/lib/message/version_0.js.map +1 -0
- package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
- package/dist/lib/{waku_relay → relay}/constants.d.ts +0 -0
- package/dist/lib/{waku_relay → relay}/constants.js +0 -0
- package/dist/lib/relay/constants.js.map +1 -0
- package/dist/lib/{waku_relay → relay}/index.d.ts +5 -5
- package/dist/lib/{waku_relay → relay}/index.js +5 -5
- package/dist/lib/relay/index.js.map +1 -0
- package/dist/lib/{waku_store → store}/history_rpc.d.ts +1 -1
- package/dist/lib/{waku_store → store}/history_rpc.js +1 -1
- package/dist/lib/store/history_rpc.js.map +1 -0
- package/dist/lib/{waku_store → store}/index.d.ts +7 -5
- package/dist/lib/{waku_store → store}/index.js +9 -8
- package/dist/lib/store/index.js.map +1 -0
- package/dist/lib/to_proto_message.d.ts +3 -3
- package/dist/lib/to_proto_message.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js +12 -3
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.d.ts +10 -9
- package/dist/lib/waku.js +19 -9
- package/dist/lib/waku.js.map +1 -1
- package/package.json +21 -19
- package/src/index.ts +19 -18
- package/src/lib/{waku_filter → filter}/filter_rpc.ts +1 -2
- package/src/lib/{waku_filter → filter}/index.ts +26 -26
- package/src/lib/{waku_light_push → light_push}/index.ts +17 -18
- package/src/lib/{waku_light_push → light_push}/push_rpc.ts +1 -2
- package/src/lib/{waku_message → message}/topic_only_message.ts +10 -7
- package/src/lib/{waku_message → message}/version_0.ts +53 -18
- package/src/lib/predefined_bootstrap_nodes.ts +1 -1
- package/src/lib/{waku_relay → relay}/constants.ts +0 -0
- package/src/lib/{waku_relay → relay}/index.ts +20 -26
- package/src/lib/{waku_store → store}/history_rpc.ts +1 -2
- package/src/lib/{waku_store → store}/index.ts +38 -24
- package/src/lib/to_proto_message.ts +4 -5
- package/src/lib/wait_for_remote_peer.ts +17 -5
- package/src/lib/waku.ts +40 -17
- package/bundle/index-925587a4.js +0 -5642
- package/bundle/lib/wait_for_remote_peer.js +0 -324
- package/bundle/lib/waku_message/topic_only_message.js +0 -2
- package/bundle/lib/waku_message/version_0.js +0 -330
- package/bundle/topic_only_message-a80fe8b2.js +0 -82
- package/dist/lib/multiaddr_to_peer_info.d.ts +0 -3
- package/dist/lib/multiaddr_to_peer_info.js +0 -15
- package/dist/lib/multiaddr_to_peer_info.js.map +0 -1
- package/dist/lib/select_connection.d.ts +0 -2
- package/dist/lib/select_connection.js +0 -19
- package/dist/lib/select_connection.js.map +0 -1
- package/dist/lib/select_peer.d.ts +0 -15
- package/dist/lib/select_peer.js +0 -59
- package/dist/lib/select_peer.js.map +0 -1
- package/dist/lib/waku_filter/filter_rpc.js.map +0 -1
- package/dist/lib/waku_filter/index.js.map +0 -1
- package/dist/lib/waku_light_push/index.js.map +0 -1
- package/dist/lib/waku_light_push/push_rpc.js.map +0 -1
- package/dist/lib/waku_message/topic_only_message.d.ts +0 -16
- package/dist/lib/waku_message/topic_only_message.js.map +0 -1
- package/dist/lib/waku_message/version_0.d.ts +0 -30
- package/dist/lib/waku_message/version_0.js.map +0 -1
- package/dist/lib/waku_relay/constants.js.map +0 -1
- package/dist/lib/waku_relay/index.js.map +0 -1
- package/dist/lib/waku_store/history_rpc.js.map +0 -1
- package/dist/lib/waku_store/index.js.map +0 -1
- package/dist/proto/filter.d.ts +0 -66
- package/dist/proto/filter.js +0 -432
- package/dist/proto/filter.js.map +0 -1
- package/dist/proto/light_push.d.ts +0 -58
- package/dist/proto/light_push.js +0 -376
- package/dist/proto/light_push.js.map +0 -1
- package/dist/proto/message.d.ts +0 -30
- package/dist/proto/message.js +0 -222
- package/dist/proto/message.js.map +0 -1
- package/dist/proto/store.d.ts +0 -105
- package/dist/proto/store.js +0 -609
- package/dist/proto/store.js.map +0 -1
- package/dist/proto/topic_only_message.d.ts +0 -10
- package/dist/proto/topic_only_message.js +0 -46
- package/dist/proto/topic_only_message.js.map +0 -1
- package/src/lib/multiaddr_to_peer_info.ts +0 -17
- package/src/lib/select_connection.ts +0 -24
- package/src/lib/select_peer.ts +0 -77
- package/src/proto/filter.ts +0 -611
- package/src/proto/light_push.ts +0 -535
- package/src/proto/message.ts +0 -313
- package/src/proto/store.ts +0 -853
- package/src/proto/topic_only_message.ts +0 -67
@@ -1,324 +0,0 @@
|
|
1
|
-
import { P as Protocols, S as StoreCodec, L as LightPushCodec, F as FilterCodec } from '../index-925587a4.js';
|
2
|
-
import { d as debug } from '../message-70dbb19b.js';
|
3
|
-
|
4
|
-
class TimeoutError extends Error {
|
5
|
-
constructor(message) {
|
6
|
-
super(message);
|
7
|
-
this.name = 'TimeoutError';
|
8
|
-
}
|
9
|
-
}
|
10
|
-
|
11
|
-
/**
|
12
|
-
An error to be thrown when the request is aborted by AbortController.
|
13
|
-
DOMException is thrown instead of this Error when DOMException is available.
|
14
|
-
*/
|
15
|
-
class AbortError extends Error {
|
16
|
-
constructor(message) {
|
17
|
-
super();
|
18
|
-
this.name = 'AbortError';
|
19
|
-
this.message = message;
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
/**
|
24
|
-
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
|
25
|
-
*/
|
26
|
-
const getDOMException = errorMessage => globalThis.DOMException === undefined ?
|
27
|
-
new AbortError(errorMessage) :
|
28
|
-
new DOMException(errorMessage);
|
29
|
-
|
30
|
-
/**
|
31
|
-
TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
|
32
|
-
*/
|
33
|
-
const getAbortedReason = signal => {
|
34
|
-
const reason = signal.reason === undefined ?
|
35
|
-
getDOMException('This operation was aborted.') :
|
36
|
-
signal.reason;
|
37
|
-
|
38
|
-
return reason instanceof Error ? reason : getDOMException(reason);
|
39
|
-
};
|
40
|
-
|
41
|
-
function pTimeout(promise, milliseconds, fallback, options) {
|
42
|
-
let timer;
|
43
|
-
|
44
|
-
const cancelablePromise = new Promise((resolve, reject) => {
|
45
|
-
if (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) {
|
46
|
-
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
47
|
-
}
|
48
|
-
|
49
|
-
if (milliseconds === Number.POSITIVE_INFINITY) {
|
50
|
-
resolve(promise);
|
51
|
-
return;
|
52
|
-
}
|
53
|
-
|
54
|
-
options = {
|
55
|
-
customTimers: {setTimeout, clearTimeout},
|
56
|
-
...options
|
57
|
-
};
|
58
|
-
|
59
|
-
if (options.signal) {
|
60
|
-
const {signal} = options;
|
61
|
-
if (signal.aborted) {
|
62
|
-
reject(getAbortedReason(signal));
|
63
|
-
}
|
64
|
-
|
65
|
-
signal.addEventListener('abort', () => {
|
66
|
-
reject(getAbortedReason(signal));
|
67
|
-
});
|
68
|
-
}
|
69
|
-
|
70
|
-
timer = options.customTimers.setTimeout.call(undefined, () => {
|
71
|
-
if (typeof fallback === 'function') {
|
72
|
-
try {
|
73
|
-
resolve(fallback());
|
74
|
-
} catch (error) {
|
75
|
-
reject(error);
|
76
|
-
}
|
77
|
-
|
78
|
-
return;
|
79
|
-
}
|
80
|
-
|
81
|
-
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
|
82
|
-
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
|
83
|
-
|
84
|
-
if (typeof promise.cancel === 'function') {
|
85
|
-
promise.cancel();
|
86
|
-
}
|
87
|
-
|
88
|
-
reject(timeoutError);
|
89
|
-
}, milliseconds);
|
90
|
-
|
91
|
-
(async () => {
|
92
|
-
try {
|
93
|
-
resolve(await promise);
|
94
|
-
} catch (error) {
|
95
|
-
reject(error);
|
96
|
-
} finally {
|
97
|
-
options.customTimers.clearTimeout.call(undefined, timer);
|
98
|
-
}
|
99
|
-
})();
|
100
|
-
});
|
101
|
-
|
102
|
-
cancelablePromise.clear = () => {
|
103
|
-
clearTimeout(timer);
|
104
|
-
timer = undefined;
|
105
|
-
};
|
106
|
-
|
107
|
-
return cancelablePromise;
|
108
|
-
}
|
109
|
-
|
110
|
-
const normalizeEmitter = emitter => {
|
111
|
-
const addListener = emitter.on || emitter.addListener || emitter.addEventListener;
|
112
|
-
const removeListener = emitter.off || emitter.removeListener || emitter.removeEventListener;
|
113
|
-
|
114
|
-
if (!addListener || !removeListener) {
|
115
|
-
throw new TypeError('Emitter is not compatible');
|
116
|
-
}
|
117
|
-
|
118
|
-
return {
|
119
|
-
addListener: addListener.bind(emitter),
|
120
|
-
removeListener: removeListener.bind(emitter),
|
121
|
-
};
|
122
|
-
};
|
123
|
-
|
124
|
-
function pEventMultiple(emitter, event, options) {
|
125
|
-
let cancel;
|
126
|
-
const returnValue = new Promise((resolve, reject) => {
|
127
|
-
options = {
|
128
|
-
rejectionEvents: ['error'],
|
129
|
-
multiArgs: false,
|
130
|
-
resolveImmediately: false,
|
131
|
-
...options,
|
132
|
-
};
|
133
|
-
|
134
|
-
if (!(options.count >= 0 && (options.count === Number.POSITIVE_INFINITY || Number.isInteger(options.count)))) {
|
135
|
-
throw new TypeError('The `count` option should be at least 0 or more');
|
136
|
-
}
|
137
|
-
|
138
|
-
// Allow multiple events
|
139
|
-
const events = [event].flat();
|
140
|
-
|
141
|
-
const items = [];
|
142
|
-
const {addListener, removeListener} = normalizeEmitter(emitter);
|
143
|
-
|
144
|
-
const onItem = (...arguments_) => {
|
145
|
-
const value = options.multiArgs ? arguments_ : arguments_[0];
|
146
|
-
|
147
|
-
// eslint-disable-next-line unicorn/no-array-callback-reference
|
148
|
-
if (options.filter && !options.filter(value)) {
|
149
|
-
return;
|
150
|
-
}
|
151
|
-
|
152
|
-
items.push(value);
|
153
|
-
|
154
|
-
if (options.count === items.length) {
|
155
|
-
cancel();
|
156
|
-
resolve(items);
|
157
|
-
}
|
158
|
-
};
|
159
|
-
|
160
|
-
const rejectHandler = error => {
|
161
|
-
cancel();
|
162
|
-
reject(error);
|
163
|
-
};
|
164
|
-
|
165
|
-
cancel = () => {
|
166
|
-
for (const event of events) {
|
167
|
-
removeListener(event, onItem);
|
168
|
-
}
|
169
|
-
|
170
|
-
for (const rejectionEvent of options.rejectionEvents) {
|
171
|
-
removeListener(rejectionEvent, rejectHandler);
|
172
|
-
}
|
173
|
-
};
|
174
|
-
|
175
|
-
for (const event of events) {
|
176
|
-
addListener(event, onItem);
|
177
|
-
}
|
178
|
-
|
179
|
-
for (const rejectionEvent of options.rejectionEvents) {
|
180
|
-
addListener(rejectionEvent, rejectHandler);
|
181
|
-
}
|
182
|
-
|
183
|
-
if (options.resolveImmediately) {
|
184
|
-
resolve(items);
|
185
|
-
}
|
186
|
-
});
|
187
|
-
|
188
|
-
returnValue.cancel = cancel;
|
189
|
-
|
190
|
-
if (typeof options.timeout === 'number') {
|
191
|
-
const timeout = pTimeout(returnValue, options.timeout);
|
192
|
-
timeout.cancel = cancel;
|
193
|
-
return timeout;
|
194
|
-
}
|
195
|
-
|
196
|
-
return returnValue;
|
197
|
-
}
|
198
|
-
|
199
|
-
function pEvent(emitter, event, options) {
|
200
|
-
if (typeof options === 'function') {
|
201
|
-
options = {filter: options};
|
202
|
-
}
|
203
|
-
|
204
|
-
options = {
|
205
|
-
...options,
|
206
|
-
count: 1,
|
207
|
-
resolveImmediately: false,
|
208
|
-
};
|
209
|
-
|
210
|
-
const arrayPromise = pEventMultiple(emitter, event, options);
|
211
|
-
const promise = arrayPromise.then(array => array[0]); // eslint-disable-line promise/prefer-await-to-then
|
212
|
-
promise.cancel = arrayPromise.cancel;
|
213
|
-
|
214
|
-
return promise;
|
215
|
-
}
|
216
|
-
|
217
|
-
const log = debug("waku:wait-for-remote-peer");
|
218
|
-
/**
|
219
|
-
* Wait for a remote peer to be ready given the passed protocols.
|
220
|
-
* Must be used after attempting to connect to nodes, using
|
221
|
-
* {@link index.waku.WakuNode.dial} or a bootstrap method with
|
222
|
-
* {@link lib/create_waku.createLightNode}.
|
223
|
-
*
|
224
|
-
* If the passed protocols is a GossipSub protocol, then it resolves only once
|
225
|
-
* a peer is in a mesh, to help ensure that other peers will send and receive
|
226
|
-
* message to us.
|
227
|
-
*
|
228
|
-
* @param waku The Waku Node
|
229
|
-
* @param protocols The protocols that need to be enabled by remote peers.
|
230
|
-
* @param timeoutMs A timeout value in milliseconds..
|
231
|
-
*
|
232
|
-
* @returns A promise that **resolves** if all desired protocols are fulfilled by
|
233
|
-
* remote nodes, **rejects** if the timeoutMs is reached.
|
234
|
-
* @throws If passing a protocol that is not mounted
|
235
|
-
* @default Wait for remote peers with protocols enabled locally and no time out is applied.
|
236
|
-
*/
|
237
|
-
async function waitForRemotePeer(waku, protocols, timeoutMs) {
|
238
|
-
protocols = protocols ?? getEnabledProtocols(waku);
|
239
|
-
if (!waku.isStarted())
|
240
|
-
return Promise.reject("Waku node is not started");
|
241
|
-
const promises = [];
|
242
|
-
if (protocols.includes(Protocols.Relay)) {
|
243
|
-
if (!waku.relay)
|
244
|
-
throw new Error("Cannot wait for Relay peer: protocol not mounted");
|
245
|
-
promises.push(waitForGossipSubPeerInMesh(waku.relay));
|
246
|
-
}
|
247
|
-
if (protocols.includes(Protocols.Store)) {
|
248
|
-
if (!waku.store)
|
249
|
-
throw new Error("Cannot wait for Store peer: protocol not mounted");
|
250
|
-
promises.push(waitForConnectedPeer(waku.store, [StoreCodec]));
|
251
|
-
}
|
252
|
-
if (protocols.includes(Protocols.LightPush)) {
|
253
|
-
if (!waku.lightPush)
|
254
|
-
throw new Error("Cannot wait for LightPush peer: protocol not mounted");
|
255
|
-
promises.push(waitForConnectedPeer(waku.lightPush, [LightPushCodec]));
|
256
|
-
}
|
257
|
-
if (protocols.includes(Protocols.Filter)) {
|
258
|
-
if (!waku.filter)
|
259
|
-
throw new Error("Cannot wait for Filter peer: protocol not mounted");
|
260
|
-
promises.push(waitForConnectedPeer(waku.filter, [FilterCodec]));
|
261
|
-
}
|
262
|
-
if (timeoutMs) {
|
263
|
-
await rejectOnTimeout(Promise.all(promises), timeoutMs, "Timed out waiting for a remote peer.");
|
264
|
-
}
|
265
|
-
else {
|
266
|
-
await Promise.all(promises);
|
267
|
-
}
|
268
|
-
}
|
269
|
-
/**
|
270
|
-
* Wait for a peer with the given protocol to be connected.
|
271
|
-
*/
|
272
|
-
async function waitForConnectedPeer(waku, codecs) {
|
273
|
-
const peers = await waku.peers();
|
274
|
-
if (peers.length) {
|
275
|
-
log(`${codecs} peer found: `, peers[0].id.toString());
|
276
|
-
return;
|
277
|
-
}
|
278
|
-
await new Promise((resolve) => {
|
279
|
-
const cb = (evt) => {
|
280
|
-
for (const codec of codecs) {
|
281
|
-
if (evt.detail.protocols.includes(codec)) {
|
282
|
-
log("Resolving for", codec, evt.detail.protocols);
|
283
|
-
waku.peerStore.removeEventListener("change:protocols", cb);
|
284
|
-
resolve();
|
285
|
-
break;
|
286
|
-
}
|
287
|
-
}
|
288
|
-
};
|
289
|
-
waku.peerStore.addEventListener("change:protocols", cb);
|
290
|
-
});
|
291
|
-
}
|
292
|
-
/**
|
293
|
-
* Wait for a peer with the given protocol to be connected and in the gossipsub
|
294
|
-
* mesh.
|
295
|
-
*/
|
296
|
-
async function waitForGossipSubPeerInMesh(waku) {
|
297
|
-
let peers = waku.getMeshPeers();
|
298
|
-
while (peers.length == 0) {
|
299
|
-
await pEvent(waku, "gossipsub:heartbeat");
|
300
|
-
peers = waku.getMeshPeers();
|
301
|
-
}
|
302
|
-
}
|
303
|
-
const awaitTimeout = (ms, rejectReason) => new Promise((_resolve, reject) => setTimeout(() => reject(rejectReason), ms));
|
304
|
-
async function rejectOnTimeout(promise, timeoutMs, rejectReason) {
|
305
|
-
await Promise.race([promise, awaitTimeout(timeoutMs, rejectReason)]);
|
306
|
-
}
|
307
|
-
function getEnabledProtocols(waku) {
|
308
|
-
const protocols = [];
|
309
|
-
if (waku.relay) {
|
310
|
-
protocols.push(Protocols.Relay);
|
311
|
-
}
|
312
|
-
if (waku.filter) {
|
313
|
-
protocols.push(Protocols.Filter);
|
314
|
-
}
|
315
|
-
if (waku.store) {
|
316
|
-
protocols.push(Protocols.Store);
|
317
|
-
}
|
318
|
-
if (waku.lightPush) {
|
319
|
-
protocols.push(Protocols.LightPush);
|
320
|
-
}
|
321
|
-
return protocols;
|
322
|
-
}
|
323
|
-
|
324
|
-
export { waitForRemotePeer };
|
@@ -1,330 +0,0 @@
|
|
1
|
-
import { m as message$1, k as encodeMessage, l as decodeMessage, d as debug } from '../../message-70dbb19b.js';
|
2
|
-
|
3
|
-
/* eslint-disable import/export */
|
4
|
-
var RateLimitProof;
|
5
|
-
(function (RateLimitProof) {
|
6
|
-
let _codec;
|
7
|
-
RateLimitProof.codec = () => {
|
8
|
-
if (_codec == null) {
|
9
|
-
_codec = message$1((obj, writer, opts = {}) => {
|
10
|
-
if (opts.lengthDelimited !== false) {
|
11
|
-
writer.fork();
|
12
|
-
}
|
13
|
-
if (obj.proof != null) {
|
14
|
-
writer.uint32(10);
|
15
|
-
writer.bytes(obj.proof);
|
16
|
-
}
|
17
|
-
else {
|
18
|
-
throw new Error('Protocol error: required field "proof" was not found in object');
|
19
|
-
}
|
20
|
-
if (obj.merkleRoot != null) {
|
21
|
-
writer.uint32(18);
|
22
|
-
writer.bytes(obj.merkleRoot);
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
throw new Error('Protocol error: required field "merkleRoot" was not found in object');
|
26
|
-
}
|
27
|
-
if (obj.epoch != null) {
|
28
|
-
writer.uint32(26);
|
29
|
-
writer.bytes(obj.epoch);
|
30
|
-
}
|
31
|
-
else {
|
32
|
-
throw new Error('Protocol error: required field "epoch" was not found in object');
|
33
|
-
}
|
34
|
-
if (obj.shareX != null) {
|
35
|
-
writer.uint32(34);
|
36
|
-
writer.bytes(obj.shareX);
|
37
|
-
}
|
38
|
-
else {
|
39
|
-
throw new Error('Protocol error: required field "shareX" was not found in object');
|
40
|
-
}
|
41
|
-
if (obj.shareY != null) {
|
42
|
-
writer.uint32(42);
|
43
|
-
writer.bytes(obj.shareY);
|
44
|
-
}
|
45
|
-
else {
|
46
|
-
throw new Error('Protocol error: required field "shareY" was not found in object');
|
47
|
-
}
|
48
|
-
if (obj.nullifier != null) {
|
49
|
-
writer.uint32(50);
|
50
|
-
writer.bytes(obj.nullifier);
|
51
|
-
}
|
52
|
-
else {
|
53
|
-
throw new Error('Protocol error: required field "nullifier" was not found in object');
|
54
|
-
}
|
55
|
-
if (obj.rlnIdentifier != null) {
|
56
|
-
writer.uint32(58);
|
57
|
-
writer.bytes(obj.rlnIdentifier);
|
58
|
-
}
|
59
|
-
else {
|
60
|
-
throw new Error('Protocol error: required field "rlnIdentifier" was not found in object');
|
61
|
-
}
|
62
|
-
if (opts.lengthDelimited !== false) {
|
63
|
-
writer.ldelim();
|
64
|
-
}
|
65
|
-
}, (reader, length) => {
|
66
|
-
const obj = {
|
67
|
-
proof: new Uint8Array(0),
|
68
|
-
merkleRoot: new Uint8Array(0),
|
69
|
-
epoch: new Uint8Array(0),
|
70
|
-
shareX: new Uint8Array(0),
|
71
|
-
shareY: new Uint8Array(0),
|
72
|
-
nullifier: new Uint8Array(0),
|
73
|
-
rlnIdentifier: new Uint8Array(0),
|
74
|
-
};
|
75
|
-
const end = length == null ? reader.len : reader.pos + length;
|
76
|
-
while (reader.pos < end) {
|
77
|
-
const tag = reader.uint32();
|
78
|
-
switch (tag >>> 3) {
|
79
|
-
case 1:
|
80
|
-
obj.proof = reader.bytes();
|
81
|
-
break;
|
82
|
-
case 2:
|
83
|
-
obj.merkleRoot = reader.bytes();
|
84
|
-
break;
|
85
|
-
case 3:
|
86
|
-
obj.epoch = reader.bytes();
|
87
|
-
break;
|
88
|
-
case 4:
|
89
|
-
obj.shareX = reader.bytes();
|
90
|
-
break;
|
91
|
-
case 5:
|
92
|
-
obj.shareY = reader.bytes();
|
93
|
-
break;
|
94
|
-
case 6:
|
95
|
-
obj.nullifier = reader.bytes();
|
96
|
-
break;
|
97
|
-
case 7:
|
98
|
-
obj.rlnIdentifier = reader.bytes();
|
99
|
-
break;
|
100
|
-
default:
|
101
|
-
reader.skipType(tag & 7);
|
102
|
-
break;
|
103
|
-
}
|
104
|
-
}
|
105
|
-
if (obj.proof == null) {
|
106
|
-
throw new Error('Protocol error: value for required field "proof" was not found in protobuf');
|
107
|
-
}
|
108
|
-
if (obj.merkleRoot == null) {
|
109
|
-
throw new Error('Protocol error: value for required field "merkleRoot" was not found in protobuf');
|
110
|
-
}
|
111
|
-
if (obj.epoch == null) {
|
112
|
-
throw new Error('Protocol error: value for required field "epoch" was not found in protobuf');
|
113
|
-
}
|
114
|
-
if (obj.shareX == null) {
|
115
|
-
throw new Error('Protocol error: value for required field "shareX" was not found in protobuf');
|
116
|
-
}
|
117
|
-
if (obj.shareY == null) {
|
118
|
-
throw new Error('Protocol error: value for required field "shareY" was not found in protobuf');
|
119
|
-
}
|
120
|
-
if (obj.nullifier == null) {
|
121
|
-
throw new Error('Protocol error: value for required field "nullifier" was not found in protobuf');
|
122
|
-
}
|
123
|
-
if (obj.rlnIdentifier == null) {
|
124
|
-
throw new Error('Protocol error: value for required field "rlnIdentifier" was not found in protobuf');
|
125
|
-
}
|
126
|
-
return obj;
|
127
|
-
});
|
128
|
-
}
|
129
|
-
return _codec;
|
130
|
-
};
|
131
|
-
RateLimitProof.encode = (obj) => {
|
132
|
-
return encodeMessage(obj, RateLimitProof.codec());
|
133
|
-
};
|
134
|
-
RateLimitProof.decode = (buf) => {
|
135
|
-
return decodeMessage(buf, RateLimitProof.codec());
|
136
|
-
};
|
137
|
-
})(RateLimitProof || (RateLimitProof = {}));
|
138
|
-
var WakuMessage;
|
139
|
-
(function (WakuMessage) {
|
140
|
-
let _codec;
|
141
|
-
WakuMessage.codec = () => {
|
142
|
-
if (_codec == null) {
|
143
|
-
_codec = message$1((obj, writer, opts = {}) => {
|
144
|
-
if (opts.lengthDelimited !== false) {
|
145
|
-
writer.fork();
|
146
|
-
}
|
147
|
-
if (obj.payload != null) {
|
148
|
-
writer.uint32(10);
|
149
|
-
writer.bytes(obj.payload);
|
150
|
-
}
|
151
|
-
if (obj.contentTopic != null) {
|
152
|
-
writer.uint32(18);
|
153
|
-
writer.string(obj.contentTopic);
|
154
|
-
}
|
155
|
-
if (obj.version != null) {
|
156
|
-
writer.uint32(24);
|
157
|
-
writer.uint32(obj.version);
|
158
|
-
}
|
159
|
-
if (obj.timestampDeprecated != null) {
|
160
|
-
writer.uint32(33);
|
161
|
-
writer.double(obj.timestampDeprecated);
|
162
|
-
}
|
163
|
-
if (obj.timestamp != null) {
|
164
|
-
writer.uint32(80);
|
165
|
-
writer.sint64(obj.timestamp);
|
166
|
-
}
|
167
|
-
if (obj.rateLimitProof != null) {
|
168
|
-
writer.uint32(170);
|
169
|
-
RateLimitProof.codec().encode(obj.rateLimitProof, writer);
|
170
|
-
}
|
171
|
-
if (obj.ephemeral != null) {
|
172
|
-
writer.uint32(248);
|
173
|
-
writer.bool(obj.ephemeral);
|
174
|
-
}
|
175
|
-
if (opts.lengthDelimited !== false) {
|
176
|
-
writer.ldelim();
|
177
|
-
}
|
178
|
-
}, (reader, length) => {
|
179
|
-
const obj = {};
|
180
|
-
const end = length == null ? reader.len : reader.pos + length;
|
181
|
-
while (reader.pos < end) {
|
182
|
-
const tag = reader.uint32();
|
183
|
-
switch (tag >>> 3) {
|
184
|
-
case 1:
|
185
|
-
obj.payload = reader.bytes();
|
186
|
-
break;
|
187
|
-
case 2:
|
188
|
-
obj.contentTopic = reader.string();
|
189
|
-
break;
|
190
|
-
case 3:
|
191
|
-
obj.version = reader.uint32();
|
192
|
-
break;
|
193
|
-
case 4:
|
194
|
-
obj.timestampDeprecated = reader.double();
|
195
|
-
break;
|
196
|
-
case 10:
|
197
|
-
obj.timestamp = reader.sint64();
|
198
|
-
break;
|
199
|
-
case 21:
|
200
|
-
obj.rateLimitProof = RateLimitProof.codec().decode(reader, reader.uint32());
|
201
|
-
break;
|
202
|
-
case 31:
|
203
|
-
obj.ephemeral = reader.bool();
|
204
|
-
break;
|
205
|
-
default:
|
206
|
-
reader.skipType(tag & 7);
|
207
|
-
break;
|
208
|
-
}
|
209
|
-
}
|
210
|
-
return obj;
|
211
|
-
});
|
212
|
-
}
|
213
|
-
return _codec;
|
214
|
-
};
|
215
|
-
WakuMessage.encode = (obj) => {
|
216
|
-
return encodeMessage(obj, WakuMessage.codec());
|
217
|
-
};
|
218
|
-
WakuMessage.decode = (buf) => {
|
219
|
-
return decodeMessage(buf, WakuMessage.codec());
|
220
|
-
};
|
221
|
-
})(WakuMessage || (WakuMessage = {}));
|
222
|
-
|
223
|
-
var message = /*#__PURE__*/Object.freeze({
|
224
|
-
__proto__: null,
|
225
|
-
get RateLimitProof () { return RateLimitProof; },
|
226
|
-
get WakuMessage () { return WakuMessage; }
|
227
|
-
});
|
228
|
-
|
229
|
-
const log = debug("waku:message:version-0");
|
230
|
-
const OneMillion = BigInt(1000000);
|
231
|
-
const Version = 0;
|
232
|
-
class MessageV0 {
|
233
|
-
constructor(proto) {
|
234
|
-
this.proto = proto;
|
235
|
-
}
|
236
|
-
get _rawPayload() {
|
237
|
-
if (this.proto.payload) {
|
238
|
-
return new Uint8Array(this.proto.payload);
|
239
|
-
}
|
240
|
-
return;
|
241
|
-
}
|
242
|
-
get ephemeral() {
|
243
|
-
return Boolean(this.proto.ephemeral);
|
244
|
-
}
|
245
|
-
get payload() {
|
246
|
-
return this._rawPayload;
|
247
|
-
}
|
248
|
-
get contentTopic() {
|
249
|
-
return this.proto.contentTopic;
|
250
|
-
}
|
251
|
-
get _rawTimestamp() {
|
252
|
-
return this.proto.timestamp;
|
253
|
-
}
|
254
|
-
get timestamp() {
|
255
|
-
// In the case we receive a value that is bigger than JS's max number,
|
256
|
-
// we catch the error and return undefined.
|
257
|
-
try {
|
258
|
-
if (this.proto.timestamp) {
|
259
|
-
// nanoseconds 10^-9 to milliseconds 10^-3
|
260
|
-
const timestamp = this.proto.timestamp / OneMillion;
|
261
|
-
return new Date(Number(timestamp));
|
262
|
-
}
|
263
|
-
if (this.proto.timestampDeprecated) {
|
264
|
-
return new Date(this.proto.timestampDeprecated * 1000);
|
265
|
-
}
|
266
|
-
}
|
267
|
-
catch (e) {
|
268
|
-
return;
|
269
|
-
}
|
270
|
-
return;
|
271
|
-
}
|
272
|
-
get version() {
|
273
|
-
// https://github.com/status-im/js-waku/issues/921
|
274
|
-
return this.proto.version ?? 0;
|
275
|
-
}
|
276
|
-
get rateLimitProof() {
|
277
|
-
return this.proto.rateLimitProof;
|
278
|
-
}
|
279
|
-
}
|
280
|
-
class EncoderV0 {
|
281
|
-
constructor(contentTopic, ephemeral = false) {
|
282
|
-
this.contentTopic = contentTopic;
|
283
|
-
this.ephemeral = ephemeral;
|
284
|
-
}
|
285
|
-
async toWire(message$1) {
|
286
|
-
return WakuMessage.encode(await this.toProtoObj(message$1));
|
287
|
-
}
|
288
|
-
async toProtoObj(message) {
|
289
|
-
const timestamp = message.timestamp ?? new Date();
|
290
|
-
return {
|
291
|
-
payload: message.payload,
|
292
|
-
version: Version,
|
293
|
-
contentTopic: this.contentTopic,
|
294
|
-
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
|
295
|
-
rateLimitProof: message.rateLimitProof,
|
296
|
-
ephemeral: this.ephemeral,
|
297
|
-
};
|
298
|
-
}
|
299
|
-
}
|
300
|
-
class DecoderV0 {
|
301
|
-
constructor(contentTopic, ephemeral = false) {
|
302
|
-
this.contentTopic = contentTopic;
|
303
|
-
this.ephemeral = ephemeral;
|
304
|
-
}
|
305
|
-
fromWireToProtoObj(bytes) {
|
306
|
-
const protoMessage = WakuMessage.decode(bytes);
|
307
|
-
log("Message decoded", protoMessage);
|
308
|
-
return Promise.resolve({
|
309
|
-
payload: protoMessage.payload ?? undefined,
|
310
|
-
contentTopic: protoMessage.contentTopic ?? undefined,
|
311
|
-
version: protoMessage.version ?? undefined,
|
312
|
-
timestamp: protoMessage.timestamp ?? undefined,
|
313
|
-
rateLimitProof: protoMessage.rateLimitProof ?? undefined,
|
314
|
-
ephemeral: protoMessage.ephemeral ?? false,
|
315
|
-
});
|
316
|
-
}
|
317
|
-
async fromProtoObj(proto) {
|
318
|
-
// https://github.com/status-im/js-waku/issues/921
|
319
|
-
if (proto.version === undefined) {
|
320
|
-
proto.version = 0;
|
321
|
-
}
|
322
|
-
if (proto.version !== Version) {
|
323
|
-
log("Failed to decode due to incorrect version, expected:", Version, ", actual:", proto.version);
|
324
|
-
return Promise.resolve(undefined);
|
325
|
-
}
|
326
|
-
return new MessageV0(proto);
|
327
|
-
}
|
328
|
-
}
|
329
|
-
|
330
|
-
export { DecoderV0, EncoderV0, MessageV0, Version, message as proto };
|