@libp2p/webtransport 4.1.9 → 5.0.0-d101aac4b
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/README.md +1 -1
- package/dist/index.min.js +2 -3
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +11 -14
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/parse-multiaddr.js +2 -2
- package/dist/src/utils/parse-multiaddr.js.map +1 -1
- package/package.json +10 -10
- package/src/index.ts +13 -16
- package/src/utils/parse-multiaddr.ts +2 -2
- package/dist/typedoc-urls.json +0 -14
package/dist/src/index.d.ts
CHANGED
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
* transports: [
|
|
23
23
|
* webTransport()
|
|
24
24
|
* ],
|
|
25
|
-
*
|
|
25
|
+
* connectionEncrypters: [
|
|
26
26
|
* noise()
|
|
27
27
|
* ]
|
|
28
28
|
* })
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
import type { Transport, ComponentLogger, CounterGroup, Metrics, PeerId, OutboundConnectionUpgradeEvents } from '@libp2p/interface';
|
|
31
|
+
import type { Transport, ComponentLogger, CounterGroup, Metrics, PeerId, OutboundConnectionUpgradeEvents, PrivateKey } from '@libp2p/interface';
|
|
32
32
|
import type { MultihashDigest } from 'multiformats/hashes/interface';
|
|
33
33
|
import type { ProgressEvent } from 'progress-events';
|
|
34
34
|
/**
|
|
@@ -46,6 +46,7 @@ export interface WebTransportInit {
|
|
|
46
46
|
}
|
|
47
47
|
export interface WebTransportComponents {
|
|
48
48
|
peerId: PeerId;
|
|
49
|
+
privateKey: PrivateKey;
|
|
49
50
|
metrics?: Metrics;
|
|
50
51
|
logger: ComponentLogger;
|
|
51
52
|
}
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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AA;AA0Q3D,wBAAgB,YAAY,CAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,UAAU,EAAE,sBAAsB,KAAK,SAAS,CAE5G"}
|
package/dist/src/index.js
CHANGED
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
* transports: [
|
|
23
23
|
* webTransport()
|
|
24
24
|
* ],
|
|
25
|
-
*
|
|
25
|
+
* connectionEncrypters: [
|
|
26
26
|
* noise()
|
|
27
27
|
* ]
|
|
28
28
|
* })
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
32
|
-
import {
|
|
32
|
+
import { InvalidCryptoExchangeError, InvalidParametersError, serviceCapabilities, transportSymbol } from '@libp2p/interface';
|
|
33
33
|
import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher';
|
|
34
34
|
import { CustomProgressEvent } from 'progress-events';
|
|
35
35
|
import { raceSignal } from 'race-signal';
|
|
@@ -67,14 +67,8 @@ class WebTransportTransport {
|
|
|
67
67
|
'@libp2p/transport'
|
|
68
68
|
];
|
|
69
69
|
async dial(ma, options) {
|
|
70
|
-
|
|
71
|
-
throw new AbortError();
|
|
72
|
-
}
|
|
70
|
+
options?.signal?.throwIfAborted();
|
|
73
71
|
this.log('dialing %s', ma);
|
|
74
|
-
const localPeer = this.components.peerId;
|
|
75
|
-
if (localPeer === undefined) {
|
|
76
|
-
throw new CodeError('Need a local peerid', 'ERR_INVALID_PARAMETERS');
|
|
77
|
-
}
|
|
78
72
|
options = options ?? {};
|
|
79
73
|
const { url, certhashes, remotePeer } = parseMultiaddr(ma);
|
|
80
74
|
let abortListener;
|
|
@@ -139,9 +133,9 @@ class WebTransportTransport {
|
|
|
139
133
|
.finally(() => {
|
|
140
134
|
cleanUpWTSession('remote_close');
|
|
141
135
|
});
|
|
142
|
-
authenticated = await raceSignal(this.authenticateWebTransport({ wt,
|
|
136
|
+
authenticated = await raceSignal(this.authenticateWebTransport({ wt, remotePeer, certhashes, ...options }), options.signal);
|
|
143
137
|
if (!authenticated) {
|
|
144
|
-
throw new
|
|
138
|
+
throw new InvalidCryptoExchangeError('Failed to authenticate webtransport');
|
|
145
139
|
}
|
|
146
140
|
this.metrics?.dialerEvents.increment({ open: true });
|
|
147
141
|
maConn = {
|
|
@@ -187,7 +181,7 @@ class WebTransportTransport {
|
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
183
|
}
|
|
190
|
-
async authenticateWebTransport({ wt,
|
|
184
|
+
async authenticateWebTransport({ wt, remotePeer, certhashes, onProgress, signal }) {
|
|
191
185
|
signal?.throwIfAborted();
|
|
192
186
|
onProgress?.(new CustomProgressEvent('webtransport:open-authentication-stream'));
|
|
193
187
|
const stream = await wt.createBidirectionalStream();
|
|
@@ -217,7 +211,10 @@ class WebTransportTransport {
|
|
|
217
211
|
};
|
|
218
212
|
const n = noise()(this.components);
|
|
219
213
|
onProgress?.(new CustomProgressEvent('webtransport:secure-outbound-connection'));
|
|
220
|
-
const { remoteExtensions } = await n.secureOutbound(
|
|
214
|
+
const { remoteExtensions } = await n.secureOutbound(duplex, {
|
|
215
|
+
signal,
|
|
216
|
+
remotePeer
|
|
217
|
+
});
|
|
221
218
|
onProgress?.(new CustomProgressEvent('webtransport:close-authentication-stream'));
|
|
222
219
|
// We're done with this authentication stream
|
|
223
220
|
writer.close().catch((err) => {
|
|
@@ -228,7 +225,7 @@ class WebTransportTransport {
|
|
|
228
225
|
});
|
|
229
226
|
// Verify the certhashes we used when dialing are a subset of the certhashes relayed by the remote peer
|
|
230
227
|
if (!isSubset(remoteExtensions?.webtransportCerthashes ?? [], certhashes.map(ch => ch.bytes))) {
|
|
231
|
-
throw new
|
|
228
|
+
throw new InvalidParametersError("Our certhashes are not a subset of the remote's reported certhashes");
|
|
232
229
|
}
|
|
233
230
|
return true;
|
|
234
231
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":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C,YAAY,IAAI,IAAI,EAAE,CAAC;YACpC,OAAO,EAAE,CAAA;QACX,CAAC;QAED,OAAO,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;YAC5B,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;gBACxC,OAAO,KAAK,CAAA;YACd,CAAC;YAED,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,cAAc,CAAC,EAAE,CAAC,CAAA;YAE9C,OAAO,GAAG,IAAI,IAAI,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAE,OAAyB,EAAE;IACvD,OAAO,CAAC,UAAkC,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC5F,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InvalidMultiaddrError } from '@libp2p/interface';
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
3
3
|
import { protocols } from '@multiformats/multiaddr';
|
|
4
4
|
import { WebTransport } from '@multiformats/multiaddr-matcher';
|
|
@@ -10,7 +10,7 @@ function decodeCerthashStr(s) {
|
|
|
10
10
|
}
|
|
11
11
|
export function parseMultiaddr(ma) {
|
|
12
12
|
if (!WebTransport.matches(ma)) {
|
|
13
|
-
throw new
|
|
13
|
+
throw new InvalidMultiaddrError('Invalid multiaddr, was not a WebTransport address');
|
|
14
14
|
}
|
|
15
15
|
const parts = ma.stringTuples();
|
|
16
16
|
const certhashes = parts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-multiaddr.js","sourceRoot":"","sources":["../../../src/utils/parse-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"parse-multiaddr.js","sourceRoot":"","sources":["../../../src/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KAAK;SACrB,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;SACrD,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAExD,MAAM,IAAI,GAAG,EAAE,CAAC,SAAS,EAAE,CAAA;IAC3B,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;IAEpB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7C;;;;;;;WAOG;QACH,IAAI,GAAG,IAAI,IAAI,GAAG,CAAA;IACpB,CAAC;IAED,OAAO;QACL,kCAAkC;QAClC,GAAG,EAAE,WAAW,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;QACnC,UAAU;QACV,UAAU;KACX,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/webtransport",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-d101aac4b",
|
|
4
4
|
"description": "JavaScript implementation of the WebTransport module that libp2p uses and that implements the interface-transport spec",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webtransport#readme",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"test:chrome-webworker": "aegir test -t webworker"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@chainsafe/libp2p-noise": "^
|
|
54
|
-
"@libp2p/interface": "
|
|
55
|
-
"@libp2p/peer-id": "
|
|
56
|
-
"@libp2p/utils": "
|
|
53
|
+
"@chainsafe/libp2p-noise": "^16.0.0",
|
|
54
|
+
"@libp2p/interface": "2.0.0-d101aac4b",
|
|
55
|
+
"@libp2p/peer-id": "5.0.0-d101aac4b",
|
|
56
|
+
"@libp2p/utils": "6.0.0-d101aac4b",
|
|
57
57
|
"@multiformats/multiaddr": "^12.2.3",
|
|
58
58
|
"@multiformats/multiaddr-matcher": "^1.2.1",
|
|
59
59
|
"it-stream-types": "^2.0.1",
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"uint8arrays": "^5.1.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@libp2p/
|
|
68
|
-
"@libp2p/
|
|
69
|
-
"@libp2p/
|
|
70
|
-
"@libp2p/ping": "
|
|
67
|
+
"@libp2p/crypto": "5.0.0-d101aac4b",
|
|
68
|
+
"@libp2p/daemon-client": "^9.0.1",
|
|
69
|
+
"@libp2p/logger": "5.0.0-d101aac4b",
|
|
70
|
+
"@libp2p/ping": "2.0.0-d101aac4b",
|
|
71
71
|
"@noble/hashes": "^1.4.0",
|
|
72
72
|
"aegir": "^44.0.1",
|
|
73
73
|
"execa": "^9.1.0",
|
|
74
74
|
"go-libp2p": "^1.2.0",
|
|
75
75
|
"it-map": "^3.1.0",
|
|
76
76
|
"it-to-buffer": "^4.0.7",
|
|
77
|
-
"libp2p": "
|
|
77
|
+
"libp2p": "2.0.0-d101aac4b",
|
|
78
78
|
"p-defer": "^4.0.1",
|
|
79
79
|
"p-wait-for": "^5.0.2"
|
|
80
80
|
},
|
package/src/index.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* transports: [
|
|
23
23
|
* webTransport()
|
|
24
24
|
* ],
|
|
25
|
-
*
|
|
25
|
+
* connectionEncrypters: [
|
|
26
26
|
* noise()
|
|
27
27
|
* ]
|
|
28
28
|
* })
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
import { noise } from '@chainsafe/libp2p-noise'
|
|
33
|
-
import {
|
|
33
|
+
import { InvalidCryptoExchangeError, InvalidParametersError, serviceCapabilities, transportSymbol } from '@libp2p/interface'
|
|
34
34
|
import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher'
|
|
35
35
|
import { CustomProgressEvent } from 'progress-events'
|
|
36
36
|
import { raceSignal } from 'race-signal'
|
|
@@ -40,7 +40,7 @@ import { inertDuplex } from './utils/inert-duplex.js'
|
|
|
40
40
|
import { isSubset } from './utils/is-subset.js'
|
|
41
41
|
import { parseMultiaddr } from './utils/parse-multiaddr.js'
|
|
42
42
|
import WebTransport from './webtransport.js'
|
|
43
|
-
import type { Transport, CreateListenerOptions, DialTransportOptions, Listener, ComponentLogger, Logger, Connection, MultiaddrConnection, CounterGroup, Metrics, PeerId, OutboundConnectionUpgradeEvents } from '@libp2p/interface'
|
|
43
|
+
import type { Transport, CreateListenerOptions, DialTransportOptions, Listener, ComponentLogger, Logger, Connection, MultiaddrConnection, CounterGroup, Metrics, PeerId, OutboundConnectionUpgradeEvents, PrivateKey } from '@libp2p/interface'
|
|
44
44
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
45
45
|
import type { Source } from 'it-stream-types'
|
|
46
46
|
import type { MultihashDigest } from 'multiformats/hashes/interface'
|
|
@@ -68,6 +68,7 @@ export interface WebTransportInit {
|
|
|
68
68
|
|
|
69
69
|
export interface WebTransportComponents {
|
|
70
70
|
peerId: PeerId
|
|
71
|
+
privateKey: PrivateKey
|
|
71
72
|
metrics?: Metrics
|
|
72
73
|
logger: ComponentLogger
|
|
73
74
|
}
|
|
@@ -85,7 +86,6 @@ export type WebTransportDialEvents =
|
|
|
85
86
|
|
|
86
87
|
interface AuthenticateWebTransportOptions extends DialTransportOptions<WebTransportDialEvents> {
|
|
87
88
|
wt: WebTransport
|
|
88
|
-
localPeer: PeerId
|
|
89
89
|
remotePeer?: PeerId
|
|
90
90
|
certhashes: Array<MultihashDigest<number>>
|
|
91
91
|
}
|
|
@@ -124,15 +124,9 @@ class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
|
124
124
|
]
|
|
125
125
|
|
|
126
126
|
async dial (ma: Multiaddr, options: DialTransportOptions<WebTransportDialEvents>): Promise<Connection> {
|
|
127
|
-
|
|
128
|
-
throw new AbortError()
|
|
129
|
-
}
|
|
127
|
+
options?.signal?.throwIfAborted()
|
|
130
128
|
|
|
131
129
|
this.log('dialing %s', ma)
|
|
132
|
-
const localPeer = this.components.peerId
|
|
133
|
-
if (localPeer === undefined) {
|
|
134
|
-
throw new CodeError('Need a local peerid', 'ERR_INVALID_PARAMETERS')
|
|
135
|
-
}
|
|
136
130
|
|
|
137
131
|
options = options ?? {}
|
|
138
132
|
|
|
@@ -206,10 +200,10 @@ class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
|
206
200
|
cleanUpWTSession('remote_close')
|
|
207
201
|
})
|
|
208
202
|
|
|
209
|
-
authenticated = await raceSignal(this.authenticateWebTransport({ wt,
|
|
203
|
+
authenticated = await raceSignal(this.authenticateWebTransport({ wt, remotePeer, certhashes, ...options }), options.signal)
|
|
210
204
|
|
|
211
205
|
if (!authenticated) {
|
|
212
|
-
throw new
|
|
206
|
+
throw new InvalidCryptoExchangeError('Failed to authenticate webtransport')
|
|
213
207
|
}
|
|
214
208
|
|
|
215
209
|
this.metrics?.dialerEvents.increment({ open: true })
|
|
@@ -257,7 +251,7 @@ class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
|
257
251
|
}
|
|
258
252
|
}
|
|
259
253
|
|
|
260
|
-
async authenticateWebTransport ({ wt,
|
|
254
|
+
async authenticateWebTransport ({ wt, remotePeer, certhashes, onProgress, signal }: AuthenticateWebTransportOptions): Promise<boolean> {
|
|
261
255
|
signal?.throwIfAborted()
|
|
262
256
|
|
|
263
257
|
onProgress?.(new CustomProgressEvent('webtransport:open-authentication-stream'))
|
|
@@ -295,7 +289,10 @@ class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
|
295
289
|
const n = noise()(this.components)
|
|
296
290
|
|
|
297
291
|
onProgress?.(new CustomProgressEvent('webtransport:secure-outbound-connection'))
|
|
298
|
-
const { remoteExtensions } = await n.secureOutbound(
|
|
292
|
+
const { remoteExtensions } = await n.secureOutbound(duplex, {
|
|
293
|
+
signal,
|
|
294
|
+
remotePeer
|
|
295
|
+
})
|
|
299
296
|
|
|
300
297
|
onProgress?.(new CustomProgressEvent('webtransport:close-authentication-stream'))
|
|
301
298
|
// We're done with this authentication stream
|
|
@@ -309,7 +306,7 @@ class WebTransportTransport implements Transport<WebTransportDialEvents> {
|
|
|
309
306
|
|
|
310
307
|
// Verify the certhashes we used when dialing are a subset of the certhashes relayed by the remote peer
|
|
311
308
|
if (!isSubset(remoteExtensions?.webtransportCerthashes ?? [], certhashes.map(ch => ch.bytes))) {
|
|
312
|
-
throw new
|
|
309
|
+
throw new InvalidParametersError("Our certhashes are not a subset of the remote's reported certhashes")
|
|
313
310
|
}
|
|
314
311
|
|
|
315
312
|
return true
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InvalidMultiaddrError } from '@libp2p/interface'
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
3
3
|
import { type Multiaddr, protocols } from '@multiformats/multiaddr'
|
|
4
4
|
import { WebTransport } from '@multiformats/multiaddr-matcher'
|
|
@@ -21,7 +21,7 @@ export interface ParsedMultiaddr {
|
|
|
21
21
|
|
|
22
22
|
export function parseMultiaddr (ma: Multiaddr): ParsedMultiaddr {
|
|
23
23
|
if (!WebTransport.matches(ma)) {
|
|
24
|
-
throw new
|
|
24
|
+
throw new InvalidMultiaddrError('Invalid multiaddr, was not a WebTransport address')
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const parts = ma.stringTuples()
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"WebTransportCertificate": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportCertificate.html",
|
|
3
|
-
".:WebTransportCertificate": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportCertificate.html",
|
|
4
|
-
"WebTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportComponents.html",
|
|
5
|
-
".:WebTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportComponents.html",
|
|
6
|
-
"WebTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportInit.html",
|
|
7
|
-
".:WebTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportInit.html",
|
|
8
|
-
"WebTransportMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportMetrics.html",
|
|
9
|
-
".:WebTransportMetrics": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportMetrics.html",
|
|
10
|
-
"WebTransportDialEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_webtransport.WebTransportDialEvents.html",
|
|
11
|
-
".:WebTransportDialEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_webtransport.WebTransportDialEvents.html",
|
|
12
|
-
"webTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webtransport.webTransport.html",
|
|
13
|
-
".:webTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webtransport.webTransport.html"
|
|
14
|
-
}
|