@libp2p/daemon-protocol 1.0.1 → 1.0.2

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/src/index.ts ADDED
@@ -0,0 +1,502 @@
1
+ /* eslint-disable import/export */
2
+ /* eslint-disable @typescript-eslint/no-namespace */
3
+
4
+ import { enumeration, encodeMessage, decodeMessage, message, bytes, int64, string, int32 } from 'protons-runtime'
5
+
6
+ export interface IdentifyResponse {
7
+ id: Uint8Array
8
+ addrs: Uint8Array[]
9
+ }
10
+
11
+ export namespace IdentifyResponse {
12
+ export const codec = message<IdentifyResponse>({
13
+ 1: { name: 'id', codec: bytes },
14
+ 2: { name: 'addrs', codec: bytes, repeats: true }
15
+ })
16
+
17
+ export const encode = (obj: IdentifyResponse): Uint8Array => {
18
+ return encodeMessage(obj, IdentifyResponse.codec)
19
+ }
20
+
21
+ export const decode = (buf: Uint8Array): IdentifyResponse => {
22
+ return decodeMessage(buf, IdentifyResponse.codec)
23
+ }
24
+ }
25
+
26
+ export interface ConnectRequest {
27
+ peer: Uint8Array
28
+ addrs: Uint8Array[]
29
+ timeout?: bigint
30
+ }
31
+
32
+ export namespace ConnectRequest {
33
+ export const codec = message<ConnectRequest>({
34
+ 1: { name: 'peer', codec: bytes },
35
+ 2: { name: 'addrs', codec: bytes, repeats: true },
36
+ 3: { name: 'timeout', codec: int64, optional: true }
37
+ })
38
+
39
+ export const encode = (obj: ConnectRequest): Uint8Array => {
40
+ return encodeMessage(obj, ConnectRequest.codec)
41
+ }
42
+
43
+ export const decode = (buf: Uint8Array): ConnectRequest => {
44
+ return decodeMessage(buf, ConnectRequest.codec)
45
+ }
46
+ }
47
+
48
+ export interface StreamOpenRequest {
49
+ peer: Uint8Array
50
+ proto: string[]
51
+ timeout?: bigint
52
+ }
53
+
54
+ export namespace StreamOpenRequest {
55
+ export const codec = message<StreamOpenRequest>({
56
+ 1: { name: 'peer', codec: bytes },
57
+ 2: { name: 'proto', codec: string, repeats: true },
58
+ 3: { name: 'timeout', codec: int64, optional: true }
59
+ })
60
+
61
+ export const encode = (obj: StreamOpenRequest): Uint8Array => {
62
+ return encodeMessage(obj, StreamOpenRequest.codec)
63
+ }
64
+
65
+ export const decode = (buf: Uint8Array): StreamOpenRequest => {
66
+ return decodeMessage(buf, StreamOpenRequest.codec)
67
+ }
68
+ }
69
+
70
+ export interface StreamHandlerRequest {
71
+ addr: Uint8Array
72
+ proto: string[]
73
+ }
74
+
75
+ export namespace StreamHandlerRequest {
76
+ export const codec = message<StreamHandlerRequest>({
77
+ 1: { name: 'addr', codec: bytes },
78
+ 2: { name: 'proto', codec: string, repeats: true }
79
+ })
80
+
81
+ export const encode = (obj: StreamHandlerRequest): Uint8Array => {
82
+ return encodeMessage(obj, StreamHandlerRequest.codec)
83
+ }
84
+
85
+ export const decode = (buf: Uint8Array): StreamHandlerRequest => {
86
+ return decodeMessage(buf, StreamHandlerRequest.codec)
87
+ }
88
+ }
89
+
90
+ export interface ErrorResponse {
91
+ msg: string
92
+ }
93
+
94
+ export namespace ErrorResponse {
95
+ export const codec = message<ErrorResponse>({
96
+ 1: { name: 'msg', codec: string }
97
+ })
98
+
99
+ export const encode = (obj: ErrorResponse): Uint8Array => {
100
+ return encodeMessage(obj, ErrorResponse.codec)
101
+ }
102
+
103
+ export const decode = (buf: Uint8Array): ErrorResponse => {
104
+ return decodeMessage(buf, ErrorResponse.codec)
105
+ }
106
+ }
107
+
108
+ export interface StreamInfo {
109
+ peer: Uint8Array
110
+ addr: Uint8Array
111
+ proto: string
112
+ }
113
+
114
+ export namespace StreamInfo {
115
+ export const codec = message<StreamInfo>({
116
+ 1: { name: 'peer', codec: bytes },
117
+ 2: { name: 'addr', codec: bytes },
118
+ 3: { name: 'proto', codec: string }
119
+ })
120
+
121
+ export const encode = (obj: StreamInfo): Uint8Array => {
122
+ return encodeMessage(obj, StreamInfo.codec)
123
+ }
124
+
125
+ export const decode = (buf: Uint8Array): StreamInfo => {
126
+ return decodeMessage(buf, StreamInfo.codec)
127
+ }
128
+ }
129
+
130
+ export interface DHTRequest {
131
+ type: DHTRequest.Type
132
+ peer?: Uint8Array
133
+ cid?: Uint8Array
134
+ key?: Uint8Array
135
+ value?: Uint8Array
136
+ count?: number
137
+ timeout?: bigint
138
+ }
139
+
140
+ export namespace DHTRequest {
141
+ export enum Type {
142
+ FIND_PEER = 'FIND_PEER',
143
+ FIND_PEERS_CONNECTED_TO_PEER = 'FIND_PEERS_CONNECTED_TO_PEER',
144
+ FIND_PROVIDERS = 'FIND_PROVIDERS',
145
+ GET_CLOSEST_PEERS = 'GET_CLOSEST_PEERS',
146
+ GET_PUBLIC_KEY = 'GET_PUBLIC_KEY',
147
+ GET_VALUE = 'GET_VALUE',
148
+ SEARCH_VALUE = 'SEARCH_VALUE',
149
+ PUT_VALUE = 'PUT_VALUE',
150
+ PROVIDE = 'PROVIDE'
151
+ }
152
+
153
+ export namespace Type {
154
+ export const codec = enumeration<typeof Type>(Type)
155
+ }
156
+
157
+ export const codec = message<DHTRequest>({
158
+ 1: { name: 'type', codec: DHTRequest.Type.codec },
159
+ 2: { name: 'peer', codec: bytes, optional: true },
160
+ 3: { name: 'cid', codec: bytes, optional: true },
161
+ 4: { name: 'key', codec: bytes, optional: true },
162
+ 5: { name: 'value', codec: bytes, optional: true },
163
+ 6: { name: 'count', codec: int32, optional: true },
164
+ 7: { name: 'timeout', codec: int64, optional: true }
165
+ })
166
+
167
+ export const encode = (obj: DHTRequest): Uint8Array => {
168
+ return encodeMessage(obj, DHTRequest.codec)
169
+ }
170
+
171
+ export const decode = (buf: Uint8Array): DHTRequest => {
172
+ return decodeMessage(buf, DHTRequest.codec)
173
+ }
174
+ }
175
+
176
+ export interface PeerInfo {
177
+ id: Uint8Array
178
+ addrs: Uint8Array[]
179
+ }
180
+
181
+ export namespace PeerInfo {
182
+ export const codec = message<PeerInfo>({
183
+ 1: { name: 'id', codec: bytes },
184
+ 2: { name: 'addrs', codec: bytes, repeats: true }
185
+ })
186
+
187
+ export const encode = (obj: PeerInfo): Uint8Array => {
188
+ return encodeMessage(obj, PeerInfo.codec)
189
+ }
190
+
191
+ export const decode = (buf: Uint8Array): PeerInfo => {
192
+ return decodeMessage(buf, PeerInfo.codec)
193
+ }
194
+ }
195
+
196
+ export interface DHTResponse {
197
+ type: DHTResponse.Type
198
+ peer?: PeerInfo
199
+ value?: Uint8Array
200
+ }
201
+
202
+ export namespace DHTResponse {
203
+ export enum Type {
204
+ BEGIN = 'BEGIN',
205
+ VALUE = 'VALUE',
206
+ END = 'END'
207
+ }
208
+
209
+ export namespace Type {
210
+ export const codec = enumeration<typeof Type>(Type)
211
+ }
212
+
213
+ export const codec = message<DHTResponse>({
214
+ 1: { name: 'type', codec: DHTResponse.Type.codec },
215
+ 2: { name: 'peer', codec: PeerInfo.codec, optional: true },
216
+ 3: { name: 'value', codec: bytes, optional: true }
217
+ })
218
+
219
+ export const encode = (obj: DHTResponse): Uint8Array => {
220
+ return encodeMessage(obj, DHTResponse.codec)
221
+ }
222
+
223
+ export const decode = (buf: Uint8Array): DHTResponse => {
224
+ return decodeMessage(buf, DHTResponse.codec)
225
+ }
226
+ }
227
+
228
+ export interface ConnManagerRequest {
229
+ type: ConnManagerRequest.Type
230
+ peer?: Uint8Array
231
+ tag?: string
232
+ weight?: bigint
233
+ }
234
+
235
+ export namespace ConnManagerRequest {
236
+ export enum Type {
237
+ TAG_PEER = 'TAG_PEER',
238
+ UNTAG_PEER = 'UNTAG_PEER',
239
+ TRIM = 'TRIM'
240
+ }
241
+
242
+ export namespace Type {
243
+ export const codec = enumeration<typeof Type>(Type)
244
+ }
245
+
246
+ export const codec = message<ConnManagerRequest>({
247
+ 1: { name: 'type', codec: ConnManagerRequest.Type.codec },
248
+ 2: { name: 'peer', codec: bytes, optional: true },
249
+ 3: { name: 'tag', codec: string, optional: true },
250
+ 4: { name: 'weight', codec: int64, optional: true }
251
+ })
252
+
253
+ export const encode = (obj: ConnManagerRequest): Uint8Array => {
254
+ return encodeMessage(obj, ConnManagerRequest.codec)
255
+ }
256
+
257
+ export const decode = (buf: Uint8Array): ConnManagerRequest => {
258
+ return decodeMessage(buf, ConnManagerRequest.codec)
259
+ }
260
+ }
261
+
262
+ export interface DisconnectRequest {
263
+ peer: Uint8Array
264
+ }
265
+
266
+ export namespace DisconnectRequest {
267
+ export const codec = message<DisconnectRequest>({
268
+ 1: { name: 'peer', codec: bytes }
269
+ })
270
+
271
+ export const encode = (obj: DisconnectRequest): Uint8Array => {
272
+ return encodeMessage(obj, DisconnectRequest.codec)
273
+ }
274
+
275
+ export const decode = (buf: Uint8Array): DisconnectRequest => {
276
+ return decodeMessage(buf, DisconnectRequest.codec)
277
+ }
278
+ }
279
+
280
+ export interface PSRequest {
281
+ type: PSRequest.Type
282
+ topic?: string
283
+ data?: Uint8Array
284
+ }
285
+
286
+ export namespace PSRequest {
287
+ export enum Type {
288
+ GET_TOPICS = 'GET_TOPICS',
289
+ LIST_PEERS = 'LIST_PEERS',
290
+ PUBLISH = 'PUBLISH',
291
+ SUBSCRIBE = 'SUBSCRIBE'
292
+ }
293
+
294
+ export namespace Type {
295
+ export const codec = enumeration<typeof Type>(Type)
296
+ }
297
+
298
+ export const codec = message<PSRequest>({
299
+ 1: { name: 'type', codec: PSRequest.Type.codec },
300
+ 2: { name: 'topic', codec: string, optional: true },
301
+ 3: { name: 'data', codec: bytes, optional: true }
302
+ })
303
+
304
+ export const encode = (obj: PSRequest): Uint8Array => {
305
+ return encodeMessage(obj, PSRequest.codec)
306
+ }
307
+
308
+ export const decode = (buf: Uint8Array): PSRequest => {
309
+ return decodeMessage(buf, PSRequest.codec)
310
+ }
311
+ }
312
+
313
+ export interface PSMessage {
314
+ from?: Uint8Array
315
+ data?: Uint8Array
316
+ seqno?: Uint8Array
317
+ topicIDs: string[]
318
+ signature?: Uint8Array
319
+ key?: Uint8Array
320
+ }
321
+
322
+ export namespace PSMessage {
323
+ export const codec = message<PSMessage>({
324
+ 1: { name: 'from', codec: bytes, optional: true },
325
+ 2: { name: 'data', codec: bytes, optional: true },
326
+ 3: { name: 'seqno', codec: bytes, optional: true },
327
+ 4: { name: 'topicIDs', codec: string, repeats: true },
328
+ 5: { name: 'signature', codec: bytes, optional: true },
329
+ 6: { name: 'key', codec: bytes, optional: true }
330
+ })
331
+
332
+ export const encode = (obj: PSMessage): Uint8Array => {
333
+ return encodeMessage(obj, PSMessage.codec)
334
+ }
335
+
336
+ export const decode = (buf: Uint8Array): PSMessage => {
337
+ return decodeMessage(buf, PSMessage.codec)
338
+ }
339
+ }
340
+
341
+ export interface PSResponse {
342
+ topics: string[]
343
+ peerIDs: Uint8Array[]
344
+ }
345
+
346
+ export namespace PSResponse {
347
+ export const codec = message<PSResponse>({
348
+ 1: { name: 'topics', codec: string, repeats: true },
349
+ 2: { name: 'peerIDs', codec: bytes, repeats: true }
350
+ })
351
+
352
+ export const encode = (obj: PSResponse): Uint8Array => {
353
+ return encodeMessage(obj, PSResponse.codec)
354
+ }
355
+
356
+ export const decode = (buf: Uint8Array): PSResponse => {
357
+ return decodeMessage(buf, PSResponse.codec)
358
+ }
359
+ }
360
+
361
+ export interface PeerstoreRequest {
362
+ type: PeerstoreRequest.Type
363
+ id?: Uint8Array
364
+ protos: string[]
365
+ }
366
+
367
+ export namespace PeerstoreRequest {
368
+ export enum Type {
369
+ GET_PROTOCOLS = 'GET_PROTOCOLS',
370
+ GET_PEER_INFO = 'GET_PEER_INFO'
371
+ }
372
+
373
+ export namespace Type {
374
+ export const codec = enumeration<typeof Type>(Type)
375
+ }
376
+
377
+ export const codec = message<PeerstoreRequest>({
378
+ 1: { name: 'type', codec: PeerstoreRequest.Type.codec },
379
+ 2: { name: 'id', codec: bytes, optional: true },
380
+ 3: { name: 'protos', codec: string, repeats: true }
381
+ })
382
+
383
+ export const encode = (obj: PeerstoreRequest): Uint8Array => {
384
+ return encodeMessage(obj, PeerstoreRequest.codec)
385
+ }
386
+
387
+ export const decode = (buf: Uint8Array): PeerstoreRequest => {
388
+ return decodeMessage(buf, PeerstoreRequest.codec)
389
+ }
390
+ }
391
+
392
+ export interface PeerstoreResponse {
393
+ peer?: PeerInfo
394
+ protos: string[]
395
+ }
396
+
397
+ export namespace PeerstoreResponse {
398
+ export const codec = message<PeerstoreResponse>({
399
+ 1: { name: 'peer', codec: PeerInfo.codec, optional: true },
400
+ 2: { name: 'protos', codec: string, repeats: true }
401
+ })
402
+
403
+ export const encode = (obj: PeerstoreResponse): Uint8Array => {
404
+ return encodeMessage(obj, PeerstoreResponse.codec)
405
+ }
406
+
407
+ export const decode = (buf: Uint8Array): PeerstoreResponse => {
408
+ return decodeMessage(buf, PeerstoreResponse.codec)
409
+ }
410
+ }
411
+
412
+ export interface Request {
413
+ type: Request.Type
414
+ connect?: ConnectRequest
415
+ streamOpen?: StreamOpenRequest
416
+ streamHandler?: StreamHandlerRequest
417
+ dht?: DHTRequest
418
+ connManager?: ConnManagerRequest
419
+ disconnect?: DisconnectRequest
420
+ pubsub?: PSRequest
421
+ peerStore?: PeerstoreRequest
422
+ }
423
+
424
+ export namespace Request {
425
+ export enum Type {
426
+ IDENTIFY = 'IDENTIFY',
427
+ CONNECT = 'CONNECT',
428
+ STREAM_OPEN = 'STREAM_OPEN',
429
+ STREAM_HANDLER = 'STREAM_HANDLER',
430
+ DHT = 'DHT',
431
+ LIST_PEERS = 'LIST_PEERS',
432
+ CONNMANAGER = 'CONNMANAGER',
433
+ DISCONNECT = 'DISCONNECT',
434
+ PUBSUB = 'PUBSUB',
435
+ PEERSTORE = 'PEERSTORE'
436
+ }
437
+
438
+ export namespace Type {
439
+ export const codec = enumeration<typeof Type>(Type)
440
+ }
441
+
442
+ export const codec = message<Request>({
443
+ 1: { name: 'type', codec: Request.Type.codec },
444
+ 2: { name: 'connect', codec: ConnectRequest.codec, optional: true },
445
+ 3: { name: 'streamOpen', codec: StreamOpenRequest.codec, optional: true },
446
+ 4: { name: 'streamHandler', codec: StreamHandlerRequest.codec, optional: true },
447
+ 5: { name: 'dht', codec: DHTRequest.codec, optional: true },
448
+ 6: { name: 'connManager', codec: ConnManagerRequest.codec, optional: true },
449
+ 7: { name: 'disconnect', codec: DisconnectRequest.codec, optional: true },
450
+ 8: { name: 'pubsub', codec: PSRequest.codec, optional: true },
451
+ 9: { name: 'peerStore', codec: PeerstoreRequest.codec, optional: true }
452
+ })
453
+
454
+ export const encode = (obj: Request): Uint8Array => {
455
+ return encodeMessage(obj, Request.codec)
456
+ }
457
+
458
+ export const decode = (buf: Uint8Array): Request => {
459
+ return decodeMessage(buf, Request.codec)
460
+ }
461
+ }
462
+
463
+ export interface Response {
464
+ type: Response.Type
465
+ error?: ErrorResponse
466
+ streamInfo?: StreamInfo
467
+ identify?: IdentifyResponse
468
+ dht?: DHTResponse
469
+ peers: PeerInfo[]
470
+ pubsub?: PSResponse
471
+ peerStore?: PeerstoreResponse
472
+ }
473
+
474
+ export namespace Response {
475
+ export enum Type {
476
+ OK = 'OK',
477
+ ERROR = 'ERROR'
478
+ }
479
+
480
+ export namespace Type {
481
+ export const codec = enumeration<typeof Type>(Type)
482
+ }
483
+
484
+ export const codec = message<Response>({
485
+ 1: { name: 'type', codec: Response.Type.codec },
486
+ 2: { name: 'error', codec: ErrorResponse.codec, optional: true },
487
+ 3: { name: 'streamInfo', codec: StreamInfo.codec, optional: true },
488
+ 4: { name: 'identify', codec: IdentifyResponse.codec, optional: true },
489
+ 5: { name: 'dht', codec: DHTResponse.codec, optional: true },
490
+ 6: { name: 'peers', codec: PeerInfo.codec, repeats: true },
491
+ 7: { name: 'pubsub', codec: PSResponse.codec, optional: true },
492
+ 8: { name: 'peerStore', codec: PeerstoreResponse.codec, optional: true }
493
+ })
494
+
495
+ export const encode = (obj: Response): Uint8Array => {
496
+ return encodeMessage(obj, Response.codec)
497
+ }
498
+
499
+ export const decode = (buf: Uint8Array): Response => {
500
+ return decodeMessage(buf, Response.codec)
501
+ }
502
+ }