libp2p 0.36.2-64bfcee → 0.36.2-c64a586
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/dist/src/circuit/circuit/hop.d.ts +3 -3
- package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/hop.js +1 -1
- package/dist/src/circuit/circuit/hop.js.map +1 -1
- package/dist/src/circuit/circuit/stop.d.ts +3 -3
- package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stop.js.map +1 -1
- package/dist/src/circuit/circuit/stream-handler.d.ts +4 -4
- package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stream-handler.js +2 -3
- package/dist/src/circuit/circuit/stream-handler.js.map +1 -1
- package/dist/src/circuit/circuit/utils.d.ts +2 -2
- package/dist/src/circuit/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/circuit/utils.js.map +1 -1
- package/dist/src/circuit/pb/index.d.ts +42 -164
- package/dist/src/circuit/pb/index.d.ts.map +1 -0
- package/dist/src/circuit/pb/index.js +67 -523
- package/dist/src/circuit/pb/index.js.map +1 -0
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +5 -6
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/fetch/pb/proto.d.ts +20 -128
- package/dist/src/fetch/pb/proto.d.ts.map +1 -0
- package/dist/src/fetch/pb/proto.js +44 -331
- package/dist/src/fetch/pb/proto.js.map +1 -0
- package/dist/src/identify/index.d.ts +4 -2
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +8 -8
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/identify/pb/message.d.ts +13 -108
- package/dist/src/identify/pb/message.d.ts.map +1 -0
- package/dist/src/identify/pb/message.js +21 -366
- package/dist/src/identify/pb/message.js.map +1 -0
- package/dist/src/insecure/index.d.ts.map +1 -1
- package/dist/src/insecure/index.js +5 -2
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/insecure/pb/proto.d.ts +24 -130
- package/dist/src/insecure/pb/proto.d.ts.map +1 -0
- package/dist/src/insecure/pb/proto.js +46 -388
- package/dist/src/insecure/pb/proto.js.map +1 -0
- package/dist/src/keychain/index.d.ts +2 -2
- package/dist/src/keychain/index.js +2 -2
- package/dist/src/keychain/util.d.ts +1 -1
- package/dist/src/keychain/util.d.ts.map +1 -1
- package/package.json +24 -22
- package/src/circuit/circuit/hop.ts +4 -4
- package/src/circuit/circuit/stop.ts +3 -3
- package/src/circuit/circuit/stream-handler.ts +5 -6
- package/src/circuit/circuit/utils.ts +2 -2
- package/src/circuit/pb/index.proto +1 -1
- package/src/circuit/pb/index.ts +88 -0
- package/src/fetch/index.ts +6 -7
- package/src/fetch/pb/proto.ts +58 -0
- package/src/identify/index.ts +10 -10
- package/src/identify/pb/message.ts +36 -0
- package/src/insecure/index.ts +8 -4
- package/src/insecure/pb/proto.ts +61 -0
- package/src/keychain/index.ts +2 -2
- package/src/circuit/pb/index.d.ts +0 -173
- package/src/circuit/pb/index.js +0 -528
- package/src/fetch/pb/proto.d.ts +0 -134
- package/src/fetch/pb/proto.js +0 -331
- package/src/identify/pb/message.d.ts +0 -110
- package/src/identify/pb/message.js +0 -369
- package/src/insecure/pb/proto.d.ts +0 -134
- package/src/insecure/pb/proto.js +0 -388
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "0.36.2-
|
|
3
|
+
"version": "0.36.2-c64a586",
|
|
4
4
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p#readme",
|
|
@@ -76,36 +76,34 @@
|
|
|
76
76
|
]
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
|
+
"clean": "aegir clean",
|
|
79
80
|
"lint": "aegir lint",
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"generate": "run-s generate:proto:*
|
|
83
|
-
"generate:proto:circuit": "
|
|
84
|
-
"generate:proto:fetch": "
|
|
85
|
-
"generate:proto:identify": "
|
|
86
|
-
"generate:proto:plaintext": "
|
|
87
|
-
"generate:proto-types:circuit": "pbts -o src/circuit/protocol/index.d.ts src/circuit/protocol/index.js",
|
|
88
|
-
"generate:proto-types:fetch": "pbts -o src/fetch/proto.d.ts src/fetch/proto.js",
|
|
89
|
-
"generate:proto-types:identify": "pbts -o src/identify/message.d.ts src/identify/message.js",
|
|
90
|
-
"generate:proto-types:plaintext": "pbts -o src/insecure/proto.d.ts src/insecure/proto.js",
|
|
91
|
-
"pretest": "npm run build",
|
|
81
|
+
"dep-check": "aegir dep-check",
|
|
82
|
+
"build": "aegir build",
|
|
83
|
+
"generate": "run-s generate:proto:*",
|
|
84
|
+
"generate:proto:circuit": "protons ./src/circuit/pb/index.proto",
|
|
85
|
+
"generate:proto:fetch": "protons ./src/fetch/pb/proto.proto",
|
|
86
|
+
"generate:proto:identify": "protons ./src/identify/pb/message.proto",
|
|
87
|
+
"generate:proto:plaintext": "protons ./src/insecure/pb/proto.proto",
|
|
92
88
|
"test": "aegir test",
|
|
93
|
-
"test:node": "
|
|
94
|
-
"test:chrome": "
|
|
95
|
-
"test:chrome-webworker": "
|
|
96
|
-
"test:firefox": "
|
|
97
|
-
"test:firefox-webworker": "
|
|
89
|
+
"test:node": "aegir test -t node -f \"./dist/test/**/*.{node,spec}.js\" --cov",
|
|
90
|
+
"test:chrome": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" --cov",
|
|
91
|
+
"test:chrome-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\"",
|
|
92
|
+
"test:firefox": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
|
|
93
|
+
"test:firefox-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
|
|
98
94
|
"test:examples": "cd examples && npm run test:all",
|
|
99
|
-
"test:interop": "
|
|
95
|
+
"test:interop": "aegir test -t node -f dist/test/interop.js"
|
|
100
96
|
},
|
|
101
97
|
"dependencies": {
|
|
102
98
|
"@achingbrain/nat-port-mapper": "^1.0.0",
|
|
103
99
|
"@libp2p/connection": "^1.1.4",
|
|
104
100
|
"@libp2p/crypto": "^0.22.9",
|
|
105
101
|
"@libp2p/interfaces": "^1.3.17",
|
|
102
|
+
"@libp2p/logger": "^1.1.3",
|
|
106
103
|
"@libp2p/multistream-select": "^1.0.3",
|
|
107
104
|
"@libp2p/peer-id": "^1.1.8",
|
|
108
105
|
"@libp2p/peer-id-factory": "^1.0.8",
|
|
106
|
+
"@libp2p/peer-record": "^1.0.8",
|
|
109
107
|
"@libp2p/peer-store": "^1.0.6",
|
|
110
108
|
"@libp2p/utils": "^1.0.9",
|
|
111
109
|
"@multiformats/mafmt": "^11.0.2",
|
|
@@ -144,7 +142,7 @@
|
|
|
144
142
|
"p-retry": "^5.0.0",
|
|
145
143
|
"p-settle": "^5.0.0",
|
|
146
144
|
"private-ip": "^2.3.3",
|
|
147
|
-
"
|
|
145
|
+
"protons-runtime": "^1.0.2",
|
|
148
146
|
"retimer": "^3.0.0",
|
|
149
147
|
"sanitize-filename": "^1.6.3",
|
|
150
148
|
"set-delayed-interval": "^1.0.0",
|
|
@@ -165,11 +163,13 @@
|
|
|
165
163
|
"@libp2p/delegated-peer-routing": "^1.0.2",
|
|
166
164
|
"@libp2p/floodsub": "^1.0.2",
|
|
167
165
|
"@libp2p/interface-compliance-tests": "^1.1.20",
|
|
168
|
-
"@libp2p/interop": "^1.0.
|
|
166
|
+
"@libp2p/interop": "^1.0.3",
|
|
169
167
|
"@libp2p/kad-dht": "^1.0.3",
|
|
170
168
|
"@libp2p/mdns": "^1.0.3",
|
|
171
169
|
"@libp2p/mplex": "^1.0.1",
|
|
170
|
+
"@libp2p/pubsub": "^1.2.14",
|
|
172
171
|
"@libp2p/tcp": "^1.0.6",
|
|
172
|
+
"@libp2p/topology": "^1.1.7",
|
|
173
173
|
"@libp2p/tracked-map": "^1.0.4",
|
|
174
174
|
"@libp2p/webrtc-star": "^1.0.3",
|
|
175
175
|
"@libp2p/websockets": "^1.0.3",
|
|
@@ -179,10 +179,11 @@
|
|
|
179
179
|
"@types/p-fifo": "^1.0.0",
|
|
180
180
|
"@types/varint": "^6.0.0",
|
|
181
181
|
"@types/xsalsa20": "^1.1.0",
|
|
182
|
-
"aegir": "^
|
|
182
|
+
"aegir": "^37.0.9",
|
|
183
183
|
"buffer": "^6.0.3",
|
|
184
184
|
"cborg": "^1.8.1",
|
|
185
185
|
"delay": "^5.0.0",
|
|
186
|
+
"execa": "^6.1.0",
|
|
186
187
|
"go-libp2p": "^0.0.6",
|
|
187
188
|
"into-stream": "^7.0.0",
|
|
188
189
|
"ipfs-http-client": "^56.0.1",
|
|
@@ -194,6 +195,7 @@
|
|
|
194
195
|
"p-event": "^5.0.1",
|
|
195
196
|
"p-times": "^4.0.0",
|
|
196
197
|
"p-wait-for": "^4.1.0",
|
|
198
|
+
"protons": "^3.0.2",
|
|
197
199
|
"rimraf": "^3.0.2",
|
|
198
200
|
"sinon": "^13.0.1",
|
|
199
201
|
"ts-sinon": "^2.0.2"
|
|
@@ -2,7 +2,7 @@ import { logger } from '@libp2p/logger'
|
|
|
2
2
|
import errCode from 'err-code'
|
|
3
3
|
import { validateAddrs } from './utils.js'
|
|
4
4
|
import { StreamHandler } from './stream-handler.js'
|
|
5
|
-
import { CircuitRelay as CircuitPB
|
|
5
|
+
import { CircuitRelay as CircuitPB } from '../pb/index.js'
|
|
6
6
|
import { pipe } from 'it-pipe'
|
|
7
7
|
import { codes as Errors } from '../../errors.js'
|
|
8
8
|
import { stop } from './stop.js'
|
|
@@ -17,7 +17,7 @@ const log = logger('libp2p:circuit:hop')
|
|
|
17
17
|
|
|
18
18
|
export interface HopRequest {
|
|
19
19
|
connection: Connection
|
|
20
|
-
request:
|
|
20
|
+
request: CircuitPB
|
|
21
21
|
streamHandler: StreamHandler
|
|
22
22
|
circuit: Circuit
|
|
23
23
|
connectionManager: ConnectionManager
|
|
@@ -120,7 +120,7 @@ export async function handleHop (hopRequest: HopRequest) {
|
|
|
120
120
|
|
|
121
121
|
export interface HopConfig {
|
|
122
122
|
connection: Connection
|
|
123
|
-
request:
|
|
123
|
+
request: CircuitPB
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
@@ -153,7 +153,7 @@ export async function hop (options: HopConfig): Promise<Duplex<Uint8Array>> {
|
|
|
153
153
|
log('hop request failed with code %d, closing stream', response.code)
|
|
154
154
|
streamHandler.close()
|
|
155
155
|
|
|
156
|
-
throw errCode(new Error(`HOP request failed with code ${response.code}`), Errors.ERR_HOP_REQUEST_FAILED)
|
|
156
|
+
throw errCode(new Error(`HOP request failed with code "${response.code ?? 'unknown'}"`), Errors.ERR_HOP_REQUEST_FAILED)
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
export interface CanHopOptions {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import { CircuitRelay as CircuitPB
|
|
2
|
+
import { CircuitRelay as CircuitPB } from '../pb/index.js'
|
|
3
3
|
import { RELAY_CODEC } from '../multicodec.js'
|
|
4
4
|
import { StreamHandler } from './stream-handler.js'
|
|
5
5
|
import { validateAddrs } from './utils.js'
|
|
@@ -10,7 +10,7 @@ const log = logger('libp2p:circuit:stop')
|
|
|
10
10
|
|
|
11
11
|
export interface HandleStopOptions {
|
|
12
12
|
connection: Connection
|
|
13
|
-
request:
|
|
13
|
+
request: CircuitPB
|
|
14
14
|
streamHandler: StreamHandler
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -44,7 +44,7 @@ export function handleStop (options: HandleStopOptions): Duplex<Uint8Array> | un
|
|
|
44
44
|
|
|
45
45
|
export interface StopOptions {
|
|
46
46
|
connection: Connection
|
|
47
|
-
request:
|
|
47
|
+
request: CircuitPB
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import * as lp from 'it-length-prefixed'
|
|
3
3
|
import { Handshake, handshake } from 'it-handshake'
|
|
4
|
-
import { CircuitRelay
|
|
4
|
+
import { CircuitRelay } from '../pb/index.js'
|
|
5
5
|
import type { Stream } from '@libp2p/interfaces/connection'
|
|
6
6
|
import type { Source } from 'it-stream-types'
|
|
7
7
|
|
|
@@ -53,10 +53,9 @@ export class StreamHandler {
|
|
|
53
53
|
/**
|
|
54
54
|
* Encode and write array of buffers
|
|
55
55
|
*/
|
|
56
|
-
write (msg:
|
|
56
|
+
write (msg: CircuitRelay) {
|
|
57
57
|
log('write message type %s', msg.type)
|
|
58
|
-
|
|
59
|
-
this.shake.write(lp.encode.single(CircuitRelay.encode(msg).finish()))
|
|
58
|
+
this.shake.write(lp.encode.single(CircuitRelay.encode(msg)).slice())
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
/**
|
|
@@ -68,9 +67,9 @@ export class StreamHandler {
|
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
/**
|
|
71
|
-
* @param {
|
|
70
|
+
* @param {CircuitRelay} msg - An unencoded CircuitRelay protobuf message
|
|
72
71
|
*/
|
|
73
|
-
end (msg:
|
|
72
|
+
end (msg: CircuitRelay) {
|
|
74
73
|
this.write(msg)
|
|
75
74
|
this.close()
|
|
76
75
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Multiaddr } from '@multiformats/multiaddr'
|
|
2
|
-
import { CircuitRelay
|
|
2
|
+
import { CircuitRelay } from '../pb/index.js'
|
|
3
3
|
import type { StreamHandler } from './stream-handler.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -15,7 +15,7 @@ function writeResponse (streamHandler: StreamHandler, status: CircuitRelay.Statu
|
|
|
15
15
|
/**
|
|
16
16
|
* Validate incomming HOP/STOP message
|
|
17
17
|
*/
|
|
18
|
-
export function validateAddrs (msg:
|
|
18
|
+
export function validateAddrs (msg: CircuitRelay, streamHandler: StreamHandler) {
|
|
19
19
|
try {
|
|
20
20
|
if (msg.dstPeer?.addrs != null) {
|
|
21
21
|
msg.dstPeer.addrs.forEach((addr) => {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
|
|
4
|
+
import { enumeration, encodeMessage, decodeMessage, message, bytes } from 'protons-runtime'
|
|
5
|
+
|
|
6
|
+
export interface CircuitRelay {
|
|
7
|
+
type?: CircuitRelay.Type
|
|
8
|
+
srcPeer?: CircuitRelay.Peer
|
|
9
|
+
dstPeer?: CircuitRelay.Peer
|
|
10
|
+
code?: CircuitRelay.Status
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export namespace CircuitRelay {
|
|
14
|
+
export enum Status {
|
|
15
|
+
SUCCESS = 'SUCCESS',
|
|
16
|
+
HOP_SRC_ADDR_TOO_LONG = 'HOP_SRC_ADDR_TOO_LONG',
|
|
17
|
+
HOP_DST_ADDR_TOO_LONG = 'HOP_DST_ADDR_TOO_LONG',
|
|
18
|
+
HOP_SRC_MULTIADDR_INVALID = 'HOP_SRC_MULTIADDR_INVALID',
|
|
19
|
+
HOP_DST_MULTIADDR_INVALID = 'HOP_DST_MULTIADDR_INVALID',
|
|
20
|
+
HOP_NO_CONN_TO_DST = 'HOP_NO_CONN_TO_DST',
|
|
21
|
+
HOP_CANT_DIAL_DST = 'HOP_CANT_DIAL_DST',
|
|
22
|
+
HOP_CANT_OPEN_DST_STREAM = 'HOP_CANT_OPEN_DST_STREAM',
|
|
23
|
+
HOP_CANT_SPEAK_RELAY = 'HOP_CANT_SPEAK_RELAY',
|
|
24
|
+
HOP_CANT_RELAY_TO_SELF = 'HOP_CANT_RELAY_TO_SELF',
|
|
25
|
+
STOP_SRC_ADDR_TOO_LONG = 'STOP_SRC_ADDR_TOO_LONG',
|
|
26
|
+
STOP_DST_ADDR_TOO_LONG = 'STOP_DST_ADDR_TOO_LONG',
|
|
27
|
+
STOP_SRC_MULTIADDR_INVALID = 'STOP_SRC_MULTIADDR_INVALID',
|
|
28
|
+
STOP_DST_MULTIADDR_INVALID = 'STOP_DST_MULTIADDR_INVALID',
|
|
29
|
+
STOP_RELAY_REFUSED = 'STOP_RELAY_REFUSED',
|
|
30
|
+
MALFORMED_MESSAGE = 'MALFORMED_MESSAGE'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export namespace Status {
|
|
34
|
+
export const codec = () => {
|
|
35
|
+
return enumeration<typeof Status>(Status)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export enum Type {
|
|
39
|
+
HOP = 'HOP',
|
|
40
|
+
STOP = 'STOP',
|
|
41
|
+
STATUS = 'STATUS',
|
|
42
|
+
CAN_HOP = 'CAN_HOP'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export namespace Type {
|
|
46
|
+
export const codec = () => {
|
|
47
|
+
return enumeration<typeof Type>(Type)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export interface Peer {
|
|
51
|
+
id: Uint8Array
|
|
52
|
+
addrs: Uint8Array[]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export namespace Peer {
|
|
56
|
+
export const codec = () => {
|
|
57
|
+
return message<Peer>({
|
|
58
|
+
1: { name: 'id', codec: bytes },
|
|
59
|
+
2: { name: 'addrs', codec: bytes, repeats: true }
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const encode = (obj: Peer): Uint8Array => {
|
|
64
|
+
return encodeMessage(obj, Peer.codec())
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const decode = (buf: Uint8Array): Peer => {
|
|
68
|
+
return decodeMessage(buf, Peer.codec())
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const codec = () => {
|
|
73
|
+
return message<CircuitRelay>({
|
|
74
|
+
1: { name: 'type', codec: CircuitRelay.Type.codec(), optional: true },
|
|
75
|
+
2: { name: 'srcPeer', codec: CircuitRelay.Peer.codec(), optional: true },
|
|
76
|
+
3: { name: 'dstPeer', codec: CircuitRelay.Peer.codec(), optional: true },
|
|
77
|
+
4: { name: 'code', codec: CircuitRelay.Status.codec(), optional: true }
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const encode = (obj: CircuitRelay): Uint8Array => {
|
|
82
|
+
return encodeMessage(obj, CircuitRelay.codec())
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const decode = (buf: Uint8Array): CircuitRelay => {
|
|
86
|
+
return decodeMessage(buf, CircuitRelay.codec())
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/fetch/index.ts
CHANGED
|
@@ -75,8 +75,7 @@ export class FetchService implements Startable {
|
|
|
75
75
|
const shake = handshake(stream)
|
|
76
76
|
|
|
77
77
|
// send message
|
|
78
|
-
|
|
79
|
-
shake.write(lp.encode.single(FetchRequest.encode(request).finish()).slice())
|
|
78
|
+
shake.write(lp.encode.single(FetchRequest.encode({ identifier: key })).slice())
|
|
80
79
|
|
|
81
80
|
// read response
|
|
82
81
|
// @ts-expect-error fromReader returns a Source which has no .next method
|
|
@@ -109,21 +108,21 @@ export class FetchService implements Startable {
|
|
|
109
108
|
// @ts-expect-error fromReader returns a Source which has no .next method
|
|
110
109
|
const request = FetchRequest.decode((await lp.decode.fromReader(shake.reader).next()).value.slice())
|
|
111
110
|
|
|
112
|
-
let response
|
|
111
|
+
let response: FetchResponse
|
|
113
112
|
const lookup = this._getLookupFunction(request.identifier)
|
|
114
113
|
if (lookup != null) {
|
|
115
114
|
const data = await lookup(request.identifier)
|
|
116
115
|
if (data != null) {
|
|
117
|
-
response =
|
|
116
|
+
response = { status: FetchResponse.StatusCode.OK, data }
|
|
118
117
|
} else {
|
|
119
|
-
response =
|
|
118
|
+
response = { status: FetchResponse.StatusCode.NOT_FOUND, data: new Uint8Array(0) }
|
|
120
119
|
}
|
|
121
120
|
} else {
|
|
122
121
|
const errmsg = (new TextEncoder()).encode('No lookup function registered for key: ' + request.identifier)
|
|
123
|
-
response =
|
|
122
|
+
response = { status: FetchResponse.StatusCode.ERROR, data: errmsg }
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
shake.write(lp.encode.single(FetchResponse.encode(response)
|
|
125
|
+
shake.write(lp.encode.single(FetchResponse.encode(response)).slice())
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
/**
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
|
|
4
|
+
import { encodeMessage, decodeMessage, message, string, enumeration, bytes } from 'protons-runtime'
|
|
5
|
+
|
|
6
|
+
export interface FetchRequest {
|
|
7
|
+
identifier: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export namespace FetchRequest {
|
|
11
|
+
export const codec = () => {
|
|
12
|
+
return message<FetchRequest>({
|
|
13
|
+
1: { name: 'identifier', codec: string }
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const encode = (obj: FetchRequest): Uint8Array => {
|
|
18
|
+
return encodeMessage(obj, FetchRequest.codec())
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const decode = (buf: Uint8Array): FetchRequest => {
|
|
22
|
+
return decodeMessage(buf, FetchRequest.codec())
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface FetchResponse {
|
|
27
|
+
status: FetchResponse.StatusCode
|
|
28
|
+
data: Uint8Array
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export namespace FetchResponse {
|
|
32
|
+
export enum StatusCode {
|
|
33
|
+
OK = 'OK',
|
|
34
|
+
NOT_FOUND = 'NOT_FOUND',
|
|
35
|
+
ERROR = 'ERROR'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export namespace StatusCode {
|
|
39
|
+
export const codec = () => {
|
|
40
|
+
return enumeration<typeof StatusCode>(StatusCode)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const codec = () => {
|
|
45
|
+
return message<FetchResponse>({
|
|
46
|
+
1: { name: 'status', codec: FetchResponse.StatusCode.codec() },
|
|
47
|
+
2: { name: 'data', codec: bytes }
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const encode = (obj: FetchResponse): Uint8Array => {
|
|
52
|
+
return encodeMessage(obj, FetchResponse.codec())
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const decode = (buf: Uint8Array): FetchResponse => {
|
|
56
|
+
return decodeMessage(buf, FetchResponse.codec())
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/identify/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import drain from 'it-drain'
|
|
|
8
8
|
import first from 'it-first'
|
|
9
9
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
10
|
import { Multiaddr, protocols } from '@multiformats/multiaddr'
|
|
11
|
-
import
|
|
11
|
+
import { Identify } from './pb/message.js'
|
|
12
12
|
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
|
|
13
13
|
import {
|
|
14
14
|
MULTICODEC_IDENTIFY,
|
|
@@ -132,11 +132,11 @@ export class IdentifyService implements Startable {
|
|
|
132
132
|
const { stream } = await connection.newStream([this.identifyPushProtocolStr])
|
|
133
133
|
|
|
134
134
|
await pipe(
|
|
135
|
-
[
|
|
135
|
+
[Identify.encode({
|
|
136
136
|
listenAddrs,
|
|
137
137
|
signedPeerRecord,
|
|
138
138
|
protocols
|
|
139
|
-
})
|
|
139
|
+
})],
|
|
140
140
|
lp.encode(),
|
|
141
141
|
stream,
|
|
142
142
|
drain
|
|
@@ -194,9 +194,9 @@ export class IdentifyService implements Startable {
|
|
|
194
194
|
throw errCode(new Error('No data could be retrieved'), codes.ERR_CONNECTION_ENDED)
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
let message
|
|
197
|
+
let message: Identify
|
|
198
198
|
try {
|
|
199
|
-
message =
|
|
199
|
+
message = Identify.decode(data)
|
|
200
200
|
} catch (err: any) {
|
|
201
201
|
throw errCode(err, codes.ERR_INVALID_MESSAGE)
|
|
202
202
|
}
|
|
@@ -325,7 +325,7 @@ export class IdentifyService implements Startable {
|
|
|
325
325
|
signedPeerRecord = envelope.marshal()
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
-
const message =
|
|
328
|
+
const message = Identify.encode({
|
|
329
329
|
protocolVersion: this.host.protocolVersion,
|
|
330
330
|
agentVersion: this.host.agentVersion,
|
|
331
331
|
publicKey,
|
|
@@ -333,7 +333,7 @@ export class IdentifyService implements Startable {
|
|
|
333
333
|
signedPeerRecord,
|
|
334
334
|
observedAddr: connection.remoteAddr.bytes,
|
|
335
335
|
protocols: peerData.protocols
|
|
336
|
-
})
|
|
336
|
+
})
|
|
337
337
|
|
|
338
338
|
await pipe(
|
|
339
339
|
[message],
|
|
@@ -352,7 +352,7 @@ export class IdentifyService implements Startable {
|
|
|
352
352
|
async _handlePush (data: IncomingStreamData) {
|
|
353
353
|
const { connection, stream } = data
|
|
354
354
|
|
|
355
|
-
let message
|
|
355
|
+
let message: Identify | undefined
|
|
356
356
|
try {
|
|
357
357
|
const data = await pipe(
|
|
358
358
|
[],
|
|
@@ -362,7 +362,7 @@ export class IdentifyService implements Startable {
|
|
|
362
362
|
)
|
|
363
363
|
|
|
364
364
|
if (data != null) {
|
|
365
|
-
message =
|
|
365
|
+
message = Identify.decode(data)
|
|
366
366
|
}
|
|
367
367
|
} catch (err: any) {
|
|
368
368
|
return log.error('received invalid message', err)
|
|
@@ -442,4 +442,4 @@ export const multicodecs = {
|
|
|
442
442
|
IDENTIFY_PUSH: MULTICODEC_IDENTIFY_PUSH
|
|
443
443
|
}
|
|
444
444
|
|
|
445
|
-
export
|
|
445
|
+
export const Message = { Identify }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
|
|
4
|
+
import { encodeMessage, decodeMessage, message, string, bytes } from 'protons-runtime'
|
|
5
|
+
|
|
6
|
+
export interface Identify {
|
|
7
|
+
protocolVersion?: string
|
|
8
|
+
agentVersion?: string
|
|
9
|
+
publicKey?: Uint8Array
|
|
10
|
+
listenAddrs: Uint8Array[]
|
|
11
|
+
observedAddr?: Uint8Array
|
|
12
|
+
protocols: string[]
|
|
13
|
+
signedPeerRecord?: Uint8Array
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export namespace Identify {
|
|
17
|
+
export const codec = () => {
|
|
18
|
+
return message<Identify>({
|
|
19
|
+
5: { name: 'protocolVersion', codec: string, optional: true },
|
|
20
|
+
6: { name: 'agentVersion', codec: string, optional: true },
|
|
21
|
+
1: { name: 'publicKey', codec: bytes, optional: true },
|
|
22
|
+
2: { name: 'listenAddrs', codec: bytes, repeats: true },
|
|
23
|
+
4: { name: 'observedAddr', codec: bytes, optional: true },
|
|
24
|
+
3: { name: 'protocols', codec: string, repeats: true },
|
|
25
|
+
8: { name: 'signedPeerRecord', codec: bytes, optional: true }
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const encode = (obj: Identify): Uint8Array => {
|
|
30
|
+
return encodeMessage(obj, Identify.codec())
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const decode = (buf: Uint8Array): Identify => {
|
|
34
|
+
return decodeMessage(buf, Identify.codec())
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/insecure/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { logger } from '@libp2p/logger'
|
|
|
2
2
|
import { handshake } from 'it-handshake'
|
|
3
3
|
import * as lp from 'it-length-prefixed'
|
|
4
4
|
import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interfaces/connection-encrypter/errors'
|
|
5
|
-
import { Exchange,
|
|
5
|
+
import { Exchange, KeyType } from './pb/proto.js'
|
|
6
6
|
import type { PeerId } from '@libp2p/interfaces/peer-id'
|
|
7
7
|
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
|
|
8
8
|
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interfaces/connection-encrypter'
|
|
@@ -11,8 +11,8 @@ import type { Duplex } from 'it-stream-types'
|
|
|
11
11
|
const log = logger('libp2p:plaintext')
|
|
12
12
|
const PROTOCOL = '/plaintext/2.0.0'
|
|
13
13
|
|
|
14
|
-
function lpEncodeExchange (exchange:
|
|
15
|
-
const pb = Exchange.encode(exchange)
|
|
14
|
+
function lpEncodeExchange (exchange: Exchange) {
|
|
15
|
+
const pb = Exchange.encode(exchange)
|
|
16
16
|
|
|
17
17
|
return lp.encode.single(pb)
|
|
18
18
|
}
|
|
@@ -37,7 +37,7 @@ async function encrypt (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: Pe
|
|
|
37
37
|
id: localId.toBytes(),
|
|
38
38
|
pubkey: {
|
|
39
39
|
Type: type,
|
|
40
|
-
Data: localId.publicKey
|
|
40
|
+
Data: localId.publicKey ?? new Uint8Array(0)
|
|
41
41
|
}
|
|
42
42
|
}).slice()
|
|
43
43
|
)
|
|
@@ -52,6 +52,10 @@ async function encrypt (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: Pe
|
|
|
52
52
|
|
|
53
53
|
let peerId
|
|
54
54
|
try {
|
|
55
|
+
if (id.pubkey == null) {
|
|
56
|
+
throw new Error('Public key missing')
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
if (id.pubkey.Data.length === 0) {
|
|
56
60
|
throw new Error('Public key data too short')
|
|
57
61
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
|
|
4
|
+
import { encodeMessage, decodeMessage, message, bytes, enumeration } from 'protons-runtime'
|
|
5
|
+
|
|
6
|
+
export interface Exchange {
|
|
7
|
+
id?: Uint8Array
|
|
8
|
+
pubkey?: PublicKey
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export namespace Exchange {
|
|
12
|
+
export const codec = () => {
|
|
13
|
+
return message<Exchange>({
|
|
14
|
+
1: { name: 'id', codec: bytes, optional: true },
|
|
15
|
+
2: { name: 'pubkey', codec: PublicKey.codec(), optional: true }
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const encode = (obj: Exchange): Uint8Array => {
|
|
20
|
+
return encodeMessage(obj, Exchange.codec())
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const decode = (buf: Uint8Array): Exchange => {
|
|
24
|
+
return decodeMessage(buf, Exchange.codec())
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export enum KeyType {
|
|
29
|
+
RSA = 'RSA',
|
|
30
|
+
Ed25519 = 'Ed25519',
|
|
31
|
+
Secp256k1 = 'Secp256k1',
|
|
32
|
+
ECDSA = 'ECDSA'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export namespace KeyType {
|
|
36
|
+
export const codec = () => {
|
|
37
|
+
return enumeration<typeof KeyType>(KeyType)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PublicKey {
|
|
42
|
+
Type: KeyType
|
|
43
|
+
Data: Uint8Array
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export namespace PublicKey {
|
|
47
|
+
export const codec = () => {
|
|
48
|
+
return message<PublicKey>({
|
|
49
|
+
1: { name: 'Type', codec: KeyType.codec() },
|
|
50
|
+
2: { name: 'Data', codec: bytes }
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const encode = (obj: PublicKey): Uint8Array => {
|
|
55
|
+
return encodeMessage(obj, PublicKey.codec())
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const decode = (buf: Uint8Array): PublicKey => {
|
|
59
|
+
return decodeMessage(buf, PublicKey.codec())
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/keychain/index.ts
CHANGED
|
@@ -171,7 +171,7 @@ export class KeyChain {
|
|
|
171
171
|
/**
|
|
172
172
|
* Generates the options for a keychain. A random salt is produced.
|
|
173
173
|
*
|
|
174
|
-
* @returns {
|
|
174
|
+
* @returns {object}
|
|
175
175
|
*/
|
|
176
176
|
static generateOptions (): KeyChainInit {
|
|
177
177
|
const options = Object.assign({}, defaultOptions)
|
|
@@ -184,7 +184,7 @@ export class KeyChain {
|
|
|
184
184
|
* Gets an object that can encrypt/decrypt protected data.
|
|
185
185
|
* The default options for a keychain.
|
|
186
186
|
*
|
|
187
|
-
* @returns {
|
|
187
|
+
* @returns {object}
|
|
188
188
|
*/
|
|
189
189
|
static get options () {
|
|
190
190
|
return defaultOptions
|