@libp2p/webtransport 3.0.3 → 3.0.4-6abcd22f
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 +2 -0
- package/dist/index.min.js +17 -14
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +106 -311
- package/dist/src/index.js.map +1 -1
- package/dist/src/stream.d.ts +3 -0
- package/dist/src/stream.d.ts.map +1 -0
- package/dist/src/stream.js +158 -0
- package/dist/src/stream.js.map +1 -0
- package/dist/src/utils/inert-duplex.d.ts +3 -0
- package/dist/src/utils/inert-duplex.d.ts.map +1 -0
- package/dist/src/utils/inert-duplex.js +20 -0
- package/dist/src/utils/inert-duplex.js.map +1 -0
- package/dist/src/utils/is-subset.d.ts +6 -0
- package/dist/src/utils/is-subset.d.ts.map +1 -0
- package/dist/src/utils/is-subset.js +12 -0
- package/dist/src/utils/is-subset.js.map +1 -0
- package/dist/src/utils/parse-multiaddr.d.ts +9 -0
- package/dist/src/utils/parse-multiaddr.d.ts.map +1 -0
- package/dist/src/utils/parse-multiaddr.js +77 -0
- package/dist/src/utils/parse-multiaddr.js.map +1 -0
- package/package.json +9 -8
- package/src/index.ts +127 -343
- package/src/stream.ts +183 -0
- package/src/utils/inert-duplex.ts +21 -0
- package/src/utils/is-subset.ts +12 -0
- package/src/utils/parse-multiaddr.ts +83 -0
- package/dist/typedoc-urls.json +0 -6
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { logger } from '@libp2p/logger';
|
|
2
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
3
|
+
const log = logger('libp2p:webtransport:stream');
|
|
4
|
+
export async function webtransportBiDiStreamToStream(bidiStream, streamId, direction, activeStreams, onStreamEnd) {
|
|
5
|
+
const writer = bidiStream.writable.getWriter();
|
|
6
|
+
const reader = bidiStream.readable.getReader();
|
|
7
|
+
await writer.ready;
|
|
8
|
+
function cleanupStreamFromActiveStreams() {
|
|
9
|
+
const index = activeStreams.findIndex(s => s === stream);
|
|
10
|
+
if (index !== -1) {
|
|
11
|
+
activeStreams.splice(index, 1);
|
|
12
|
+
stream.timeline.close = Date.now();
|
|
13
|
+
onStreamEnd?.(stream);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
let writerClosed = false;
|
|
17
|
+
let readerClosed = false;
|
|
18
|
+
(async function () {
|
|
19
|
+
const err = await writer.closed.catch((err) => err);
|
|
20
|
+
if (err != null) {
|
|
21
|
+
const msg = err.message;
|
|
22
|
+
if (!(msg.includes('aborted by the remote server') || msg.includes('STOP_SENDING'))) {
|
|
23
|
+
log.error(`WebTransport writer closed unexpectedly: streamId=${streamId} err=${err.message}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
writerClosed = true;
|
|
27
|
+
if (writerClosed && readerClosed) {
|
|
28
|
+
cleanupStreamFromActiveStreams();
|
|
29
|
+
}
|
|
30
|
+
})().catch(() => {
|
|
31
|
+
log.error('WebTransport failed to cleanup closed stream');
|
|
32
|
+
});
|
|
33
|
+
(async function () {
|
|
34
|
+
const err = await reader.closed.catch((err) => err);
|
|
35
|
+
if (err != null) {
|
|
36
|
+
log.error(`WebTransport reader closed unexpectedly: streamId=${streamId} err=${err.message}`);
|
|
37
|
+
}
|
|
38
|
+
readerClosed = true;
|
|
39
|
+
if (writerClosed && readerClosed) {
|
|
40
|
+
cleanupStreamFromActiveStreams();
|
|
41
|
+
}
|
|
42
|
+
})().catch(() => {
|
|
43
|
+
log.error('WebTransport failed to cleanup closed stream');
|
|
44
|
+
});
|
|
45
|
+
let sinkSunk = false;
|
|
46
|
+
const stream = {
|
|
47
|
+
id: streamId,
|
|
48
|
+
status: 'open',
|
|
49
|
+
writeStatus: 'ready',
|
|
50
|
+
readStatus: 'ready',
|
|
51
|
+
abort(err) {
|
|
52
|
+
if (!writerClosed) {
|
|
53
|
+
writer.abort(err);
|
|
54
|
+
writerClosed = true;
|
|
55
|
+
}
|
|
56
|
+
readerClosed = true;
|
|
57
|
+
this.status = 'aborted';
|
|
58
|
+
this.writeStatus = 'closed';
|
|
59
|
+
this.readStatus = 'closed';
|
|
60
|
+
this.timeline.reset =
|
|
61
|
+
this.timeline.close =
|
|
62
|
+
this.timeline.closeRead =
|
|
63
|
+
this.timeline.closeWrite = Date.now();
|
|
64
|
+
cleanupStreamFromActiveStreams();
|
|
65
|
+
},
|
|
66
|
+
async close(options) {
|
|
67
|
+
this.status = 'closing';
|
|
68
|
+
await Promise.all([
|
|
69
|
+
stream.closeRead(options),
|
|
70
|
+
stream.closeWrite(options)
|
|
71
|
+
]);
|
|
72
|
+
cleanupStreamFromActiveStreams();
|
|
73
|
+
this.status = 'closed';
|
|
74
|
+
this.timeline.close = Date.now();
|
|
75
|
+
},
|
|
76
|
+
async closeRead(options) {
|
|
77
|
+
if (!readerClosed) {
|
|
78
|
+
this.readStatus = 'closing';
|
|
79
|
+
try {
|
|
80
|
+
await reader.cancel();
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
if (err.toString().includes('RESET_STREAM') === true) {
|
|
84
|
+
writerClosed = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
this.timeline.closeRead = Date.now();
|
|
88
|
+
this.readStatus = 'closed';
|
|
89
|
+
readerClosed = true;
|
|
90
|
+
}
|
|
91
|
+
if (writerClosed) {
|
|
92
|
+
cleanupStreamFromActiveStreams();
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async closeWrite(options) {
|
|
96
|
+
if (!writerClosed) {
|
|
97
|
+
writerClosed = true;
|
|
98
|
+
this.writeStatus = 'closing';
|
|
99
|
+
try {
|
|
100
|
+
await writer.close();
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (err.toString().includes('RESET_STREAM') === true) {
|
|
104
|
+
readerClosed = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
this.timeline.closeWrite = Date.now();
|
|
108
|
+
this.writeStatus = 'closed';
|
|
109
|
+
}
|
|
110
|
+
if (readerClosed) {
|
|
111
|
+
cleanupStreamFromActiveStreams();
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
direction,
|
|
115
|
+
timeline: { open: Date.now() },
|
|
116
|
+
metadata: {},
|
|
117
|
+
source: (async function* () {
|
|
118
|
+
while (true) {
|
|
119
|
+
const val = await reader.read();
|
|
120
|
+
if (val.done === true) {
|
|
121
|
+
readerClosed = true;
|
|
122
|
+
if (writerClosed) {
|
|
123
|
+
cleanupStreamFromActiveStreams();
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
yield new Uint8ArrayList(val.value);
|
|
128
|
+
}
|
|
129
|
+
})(),
|
|
130
|
+
sink: async function (source) {
|
|
131
|
+
if (sinkSunk) {
|
|
132
|
+
throw new Error('sink already called on stream');
|
|
133
|
+
}
|
|
134
|
+
sinkSunk = true;
|
|
135
|
+
try {
|
|
136
|
+
this.writeStatus = 'writing';
|
|
137
|
+
for await (const chunks of source) {
|
|
138
|
+
if (chunks instanceof Uint8Array) {
|
|
139
|
+
await writer.write(chunks);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
for (const buf of chunks) {
|
|
143
|
+
await writer.write(buf);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
this.writeStatus = 'done';
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
this.timeline.closeWrite = Date.now();
|
|
151
|
+
this.writeStatus = 'closed';
|
|
152
|
+
await stream.closeWrite();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return stream;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,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AAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;qBAC3B;yBAAM;wBACL,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;4BACxB,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;yBACxB;qBACF;iBACF;gBAED,IAAI,CAAC,WAAW,GAAG,MAAM,CAAA;aAC1B;oBAAS;gBACR,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;gBACrC,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAA;gBAE3B,MAAM,MAAM,CAAC,UAAU,EAAE,CAAA;aAC1B;QACH,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inert-duplex.d.ts","sourceRoot":"","sources":["../../../src/utils/inert-duplex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAU,MAAM,iBAAiB,CAAA;AAGrD,wBAAgB,WAAW,IAAK,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAiBpD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Duplex that does nothing. Needed to fulfill the interface
|
|
2
|
+
export function inertDuplex() {
|
|
3
|
+
return {
|
|
4
|
+
source: {
|
|
5
|
+
[Symbol.asyncIterator]() {
|
|
6
|
+
return {
|
|
7
|
+
async next() {
|
|
8
|
+
// This will never resolve
|
|
9
|
+
return new Promise(() => { });
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
sink: async (source) => {
|
|
15
|
+
// This will never resolve
|
|
16
|
+
return new Promise(() => { });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=inert-duplex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inert-duplex.js","sourceRoot":"","sources":["../../../src/utils/inert-duplex.ts"],"names":[],"mappings":"AAEA,4DAA4D;AAC5D,MAAM,UAAU,WAAW;IACzB,OAAO;QACL,MAAM,EAAE;YACN,CAAC,MAAM,CAAC,aAAa,CAAC;gBACpB,OAAO;oBACL,KAAK,CAAC,IAAI;wBACR,0BAA0B;wBAC1B,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;oBAC/B,CAAC;iBACF,CAAA;YACH,CAAC;SACF;QACD,IAAI,EAAE,KAAK,EAAE,MAAmB,EAAE,EAAE;YAClC,0BAA0B;YAC1B,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;QAC/B,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if `maybeSubset` is a subset of `set`. This means that all byte
|
|
3
|
+
* arrays in `maybeSubset` are present in `set`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isSubset(set: Uint8Array[], maybeSubset: Uint8Array[]): boolean;
|
|
6
|
+
//# sourceMappingURL=is-subset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-subset.d.ts","sourceRoot":"","sources":["../../../src/utils/is-subset.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,QAAQ,CAAE,GAAG,EAAE,UAAU,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,OAAO,CAK/E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if `maybeSubset` is a subset of `set`. This means that all byte
|
|
4
|
+
* arrays in `maybeSubset` are present in `set`.
|
|
5
|
+
*/
|
|
6
|
+
export function isSubset(set, maybeSubset) {
|
|
7
|
+
const intersection = maybeSubset.filter(byteArray => {
|
|
8
|
+
return Boolean(set.find((otherByteArray) => uint8ArrayEquals(byteArray, otherByteArray)));
|
|
9
|
+
});
|
|
10
|
+
return (intersection.length === maybeSubset.length);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=is-subset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-subset.js","sourceRoot":"","sources":["../../../src/utils/is-subset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE/D;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAE,GAAiB,EAAE,WAAyB;IACpE,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;QAClD,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,cAA0B,EAAE,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,CAAA;IACvG,CAAC,CAAC,CAAA;IACF,OAAO,CAAC,YAAY,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,CAAA;AACrD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
import type { PeerId } from '@libp2p/interface/peer-id';
|
|
3
|
+
import type { MultihashDigest } from 'multiformats/hashes/interface';
|
|
4
|
+
export declare function parseMultiaddr(ma: Multiaddr): {
|
|
5
|
+
url: string;
|
|
6
|
+
certhashes: MultihashDigest[];
|
|
7
|
+
remotePeer?: PeerId;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=parse-multiaddr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-multiaddr.d.ts","sourceRoot":"","sources":["../../../src/utils/parse-multiaddr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,yBAAyB,CAAA;AAEnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AASpE,wBAAgB,cAAc,CAAE,EAAE,EAAE,SAAS,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,eAAe,EAAE,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAqElH"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { peerIdFromString } from '@libp2p/peer-id';
|
|
2
|
+
import { protocols } from '@multiformats/multiaddr';
|
|
3
|
+
import { bases, digest } from 'multiformats/basics';
|
|
4
|
+
// @ts-expect-error - Not easy to combine these types.
|
|
5
|
+
const multibaseDecoder = Object.values(bases).map(b => b.decoder).reduce((d, b) => d.or(b));
|
|
6
|
+
function decodeCerthashStr(s) {
|
|
7
|
+
return digest.decode(multibaseDecoder.decode(s));
|
|
8
|
+
}
|
|
9
|
+
export function parseMultiaddr(ma) {
|
|
10
|
+
const parts = ma.stringTuples();
|
|
11
|
+
// This is simpler to have inline than extract into a separate function
|
|
12
|
+
// eslint-disable-next-line complexity
|
|
13
|
+
const { url, certhashes, remotePeer } = parts.reduce((state, [proto, value]) => {
|
|
14
|
+
switch (proto) {
|
|
15
|
+
case protocols('ip6').code:
|
|
16
|
+
// @ts-expect-error - ts error on switch fallthrough
|
|
17
|
+
case protocols('dns6').code:
|
|
18
|
+
if (value?.includes(':') === true) {
|
|
19
|
+
/**
|
|
20
|
+
* This resolves cases where `new globalThis.WebTransport` fails to construct because of an invalid URL being passed.
|
|
21
|
+
*
|
|
22
|
+
* `new URL('https://::1:4001/blah')` will throw a `TypeError: Failed to construct 'URL': Invalid URL`
|
|
23
|
+
* `new URL('https://[::1]:4001/blah')` is valid and will not.
|
|
24
|
+
*
|
|
25
|
+
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
|
|
26
|
+
*/
|
|
27
|
+
value = `[${value}]`;
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line no-fallthrough
|
|
30
|
+
case protocols('ip4').code:
|
|
31
|
+
case protocols('dns4').code:
|
|
32
|
+
if (state.seenHost || state.seenPort) {
|
|
33
|
+
throw new Error('Invalid multiaddr, saw host and already saw the host or port');
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...state,
|
|
37
|
+
url: `${state.url}${value ?? ''}`,
|
|
38
|
+
seenHost: true
|
|
39
|
+
};
|
|
40
|
+
case protocols('quic').code:
|
|
41
|
+
case protocols('quic-v1').code:
|
|
42
|
+
case protocols('webtransport').code:
|
|
43
|
+
if (!state.seenHost || !state.seenPort) {
|
|
44
|
+
throw new Error("Invalid multiaddr, Didn't see host and port, but saw quic/webtransport");
|
|
45
|
+
}
|
|
46
|
+
return state;
|
|
47
|
+
case protocols('udp').code:
|
|
48
|
+
if (state.seenPort) {
|
|
49
|
+
throw new Error('Invalid multiaddr, saw port but already saw the port');
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
...state,
|
|
53
|
+
url: `${state.url}:${value ?? ''}`,
|
|
54
|
+
seenPort: true
|
|
55
|
+
};
|
|
56
|
+
case protocols('certhash').code:
|
|
57
|
+
if (!state.seenHost || !state.seenPort) {
|
|
58
|
+
throw new Error('Invalid multiaddr, saw the certhash before seeing the host and port');
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
...state,
|
|
62
|
+
certhashes: state.certhashes.concat([decodeCerthashStr(value ?? '')])
|
|
63
|
+
};
|
|
64
|
+
case protocols('p2p').code:
|
|
65
|
+
return {
|
|
66
|
+
...state,
|
|
67
|
+
remotePeer: peerIdFromString(value ?? '')
|
|
68
|
+
};
|
|
69
|
+
default:
|
|
70
|
+
throw new Error(`unexpected component in multiaddr: ${proto} ${protocols(proto).name} ${value ?? ''} `);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
// All webtransport urls are https
|
|
74
|
+
{ url: 'https://', seenHost: false, seenPort: false, certhashes: [] });
|
|
75
|
+
return { url, certhashes, remotePeer };
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=parse-multiaddr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-multiaddr.js","sourceRoot":"","sources":["../../../src/utils/parse-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAkB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAInD,sDAAsD;AACtD,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAE3F,SAAS,iBAAiB,CAAE,CAAS;IACnC,OAAO,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAClD,CAAC;AAED,MAAM,UAAU,cAAc,CAAE,EAAa;IAC3C,MAAM,KAAK,GAAG,EAAE,CAAC,YAAY,EAAE,CAAA;IAE/B,uEAAuE;IACvE,sCAAsC;IACtC,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,KAAgH,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE;QACxL,QAAQ,KAAK,EAAE;YACb,KAAK,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;YAC3B,oDAAoD;YACpD,KAAK,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI;gBACzB,IAAI,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;oBACjC;;;;;;;u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O;oBACL,GAAG,KAAK;oBACR,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;iBACtE,CAAA;YACH,KAAK,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI;gBACxB,OAAO;oBACL,GAAG,KAAK;oBACR,UAAU,EAAE,gBAAgB,CAAC,KAAK,IAAI,EAAE,CAAC;iBAC1C,CAAA;YACH;gBACE,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,KAAK,IAAI,EAAE,GAAG,CAAC,CAAA;SAC1G;IACH,CAAC;IACD,kCAAkC;IAClC,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAA;IAEtE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,CAAA;AACxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/webtransport",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4-6abcd22f",
|
|
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/master/packages/transport-webtransport#readme",
|
|
@@ -65,17 +65,18 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@chainsafe/libp2p-noise": "^13.0.0",
|
|
68
|
-
"@libp2p/interface": "
|
|
69
|
-
"@libp2p/logger": "
|
|
70
|
-
"@libp2p/peer-id": "
|
|
71
|
-
"@multiformats/multiaddr": "^12.1.
|
|
68
|
+
"@libp2p/interface": "0.1.2-6abcd22f",
|
|
69
|
+
"@libp2p/logger": "3.0.2-6abcd22f",
|
|
70
|
+
"@libp2p/peer-id": "3.0.2-6abcd22f",
|
|
71
|
+
"@multiformats/multiaddr": "^12.1.5",
|
|
72
72
|
"it-stream-types": "^2.0.1",
|
|
73
73
|
"multiformats": "^12.0.1",
|
|
74
|
-
"uint8arraylist": "^2.4.3"
|
|
74
|
+
"uint8arraylist": "^2.4.3",
|
|
75
|
+
"uint8arrays": "^4.0.6"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
|
-
"aegir": "^40.0.
|
|
78
|
-
"libp2p": "
|
|
78
|
+
"aegir": "^40.0.8",
|
|
79
|
+
"libp2p": "0.46.4-6abcd22f",
|
|
79
80
|
"p-defer": "^4.0.0"
|
|
80
81
|
},
|
|
81
82
|
"browser": {
|