@libp2p/identify 0.0.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/LICENSE +4 -0
- package/README.md +53 -0
- package/dist/index.min.js +45 -0
- package/dist/src/consts.d.ts +9 -0
- package/dist/src/consts.d.ts.map +1 -0
- package/dist/src/consts.js +9 -0
- package/dist/src/consts.js.map +1 -0
- package/dist/src/identify.d.ts +54 -0
- package/dist/src/identify.d.ts.map +1 -0
- package/dist/src/identify.js +446 -0
- package/dist/src/identify.js.map +1 -0
- package/dist/src/index.d.ts +88 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +32 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/pb/message.d.ts +17 -0
- package/dist/src/pb/message.d.ts.map +1 -0
- package/dist/src/pb/message.js +98 -0
- package/dist/src/pb/message.js.map +1 -0
- package/dist/typedoc-urls.json +12 -0
- package/package.json +75 -0
- package/src/consts.ts +9 -0
- package/src/identify.ts +559 -0
- package/src/index.ts +108 -0
- package/src/pb/message.proto +30 -0
- package/src/pb/message.ts +126 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable complexity */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
6
|
+
|
|
7
|
+
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
|
|
8
|
+
import type { Codec } from 'protons-runtime'
|
|
9
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
10
|
+
|
|
11
|
+
export interface Identify {
|
|
12
|
+
protocolVersion?: string
|
|
13
|
+
agentVersion?: string
|
|
14
|
+
publicKey?: Uint8Array
|
|
15
|
+
listenAddrs: Uint8Array[]
|
|
16
|
+
observedAddr?: Uint8Array
|
|
17
|
+
protocols: string[]
|
|
18
|
+
signedPeerRecord?: Uint8Array
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export namespace Identify {
|
|
22
|
+
let _codec: Codec<Identify>
|
|
23
|
+
|
|
24
|
+
export const codec = (): Codec<Identify> => {
|
|
25
|
+
if (_codec == null) {
|
|
26
|
+
_codec = message<Identify>((obj, w, opts = {}) => {
|
|
27
|
+
if (opts.lengthDelimited !== false) {
|
|
28
|
+
w.fork()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (obj.protocolVersion != null) {
|
|
32
|
+
w.uint32(42)
|
|
33
|
+
w.string(obj.protocolVersion)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (obj.agentVersion != null) {
|
|
37
|
+
w.uint32(50)
|
|
38
|
+
w.string(obj.agentVersion)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (obj.publicKey != null) {
|
|
42
|
+
w.uint32(10)
|
|
43
|
+
w.bytes(obj.publicKey)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (obj.listenAddrs != null) {
|
|
47
|
+
for (const value of obj.listenAddrs) {
|
|
48
|
+
w.uint32(18)
|
|
49
|
+
w.bytes(value)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (obj.observedAddr != null) {
|
|
54
|
+
w.uint32(34)
|
|
55
|
+
w.bytes(obj.observedAddr)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (obj.protocols != null) {
|
|
59
|
+
for (const value of obj.protocols) {
|
|
60
|
+
w.uint32(26)
|
|
61
|
+
w.string(value)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (obj.signedPeerRecord != null) {
|
|
66
|
+
w.uint32(66)
|
|
67
|
+
w.bytes(obj.signedPeerRecord)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (opts.lengthDelimited !== false) {
|
|
71
|
+
w.ldelim()
|
|
72
|
+
}
|
|
73
|
+
}, (reader, length) => {
|
|
74
|
+
const obj: any = {
|
|
75
|
+
listenAddrs: [],
|
|
76
|
+
protocols: []
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const end = length == null ? reader.len : reader.pos + length
|
|
80
|
+
|
|
81
|
+
while (reader.pos < end) {
|
|
82
|
+
const tag = reader.uint32()
|
|
83
|
+
|
|
84
|
+
switch (tag >>> 3) {
|
|
85
|
+
case 5:
|
|
86
|
+
obj.protocolVersion = reader.string()
|
|
87
|
+
break
|
|
88
|
+
case 6:
|
|
89
|
+
obj.agentVersion = reader.string()
|
|
90
|
+
break
|
|
91
|
+
case 1:
|
|
92
|
+
obj.publicKey = reader.bytes()
|
|
93
|
+
break
|
|
94
|
+
case 2:
|
|
95
|
+
obj.listenAddrs.push(reader.bytes())
|
|
96
|
+
break
|
|
97
|
+
case 4:
|
|
98
|
+
obj.observedAddr = reader.bytes()
|
|
99
|
+
break
|
|
100
|
+
case 3:
|
|
101
|
+
obj.protocols.push(reader.string())
|
|
102
|
+
break
|
|
103
|
+
case 8:
|
|
104
|
+
obj.signedPeerRecord = reader.bytes()
|
|
105
|
+
break
|
|
106
|
+
default:
|
|
107
|
+
reader.skipType(tag & 7)
|
|
108
|
+
break
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return obj
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return _codec
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const encode = (obj: Partial<Identify>): Uint8Array => {
|
|
120
|
+
return encodeMessage(obj, Identify.codec())
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): Identify => {
|
|
124
|
+
return decodeMessage(buf, Identify.codec())
|
|
125
|
+
}
|
|
126
|
+
}
|