@libp2p/webrtc 1.0.2 → 1.0.4
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/index.min.js +19 -19
- package/dist/src/error.d.ts +9 -10
- package/dist/src/error.d.ts.map +1 -1
- package/dist/src/maconn.d.ts.map +1 -1
- package/dist/src/maconn.js.map +1 -1
- package/dist/src/muxer.d.ts +1 -5
- package/dist/src/muxer.d.ts.map +1 -1
- package/dist/src/muxer.js +3 -6
- package/dist/src/muxer.js.map +1 -1
- package/dist/src/sdp.d.ts +3 -2
- package/dist/src/sdp.d.ts.map +1 -1
- package/dist/src/sdp.js +2 -7
- package/dist/src/sdp.js.map +1 -1
- package/dist/src/stream.d.ts +16 -10
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +75 -30
- package/dist/src/stream.js.map +1 -1
- package/dist/src/transport.d.ts.map +1 -1
- package/dist/src/transport.js +31 -31
- package/dist/src/transport.js.map +1 -1
- package/dist/src/util.d.ts.map +1 -1
- package/dist/src/util.js.map +1 -1
- package/package.json +8 -7
- package/src/error.ts +9 -9
- package/src/maconn.ts +4 -4
- package/src/muxer.ts +5 -8
- package/src/sdp.ts +4 -8
- package/src/stream.ts +288 -253
- package/src/transport.ts +34 -34
- package/src/util.ts +1 -1
package/dist/src/transport.js
CHANGED
|
@@ -3,7 +3,6 @@ import { symbol } from '@libp2p/interface-transport';
|
|
|
3
3
|
import { logger } from '@libp2p/logger';
|
|
4
4
|
import * as p from '@libp2p/peer-id';
|
|
5
5
|
import * as multihashes from 'multihashes';
|
|
6
|
-
import defer from 'p-defer';
|
|
7
6
|
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string';
|
|
8
7
|
import { concat } from 'uint8arrays/concat';
|
|
9
8
|
import { dataChannelError, inappropriateMultiaddr, unimplemented, invalidArgument } from './error.js';
|
|
@@ -69,10 +68,11 @@ export class WebRTCTransport {
|
|
|
69
68
|
* Connect to a peer using a multiaddr
|
|
70
69
|
*/
|
|
71
70
|
async _connect(ma, options) {
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
71
|
+
const remotePeerString = ma.getPeerId();
|
|
72
|
+
if (remotePeerString === null) {
|
|
74
73
|
throw inappropriateMultiaddr("we need to have the remote's PeerId");
|
|
75
74
|
}
|
|
75
|
+
const theirPeerId = p.peerIdFromString(remotePeerString);
|
|
76
76
|
const remoteCerthash = sdp.decodeCerthash(sdp.certhash(ma));
|
|
77
77
|
// ECDSA is preferred over RSA here. From our testing we find that P-256 elliptic
|
|
78
78
|
// curve is supported by Pion, webrtc-rs, as well as Chromium (P-228 and P-384
|
|
@@ -87,27 +87,28 @@ export class WebRTCTransport {
|
|
|
87
87
|
// create data channel for running the noise handshake. Once the data channel is opened,
|
|
88
88
|
// the remote will initiate the noise handshake. This is used to confirm the identity of
|
|
89
89
|
// the peer.
|
|
90
|
-
const dataChannelOpenPromise =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
90
|
+
const dataChannelOpenPromise = new Promise((resolve, reject) => {
|
|
91
|
+
const handshakeDataChannel = peerConnection.createDataChannel('', { negotiated: true, id: 0 });
|
|
92
|
+
const handshakeTimeout = setTimeout(() => {
|
|
93
|
+
const error = `Data channel was never opened: state: ${handshakeDataChannel.readyState}`;
|
|
94
|
+
log.error(error);
|
|
95
|
+
reject(dataChannelError('data', error));
|
|
96
|
+
}, HANDSHAKE_TIMEOUT_MS);
|
|
97
|
+
handshakeDataChannel.onopen = (_) => {
|
|
98
|
+
clearTimeout(handshakeTimeout);
|
|
99
|
+
resolve(handshakeDataChannel);
|
|
100
|
+
};
|
|
101
|
+
// ref: https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/error_event
|
|
102
|
+
handshakeDataChannel.onerror = (event) => {
|
|
103
|
+
clearTimeout(handshakeTimeout);
|
|
104
|
+
const errorTarget = event.target?.toString() ?? 'not specified';
|
|
105
|
+
const error = `Error opening a data channel for handshaking: ${errorTarget}`;
|
|
106
|
+
log.error(error);
|
|
107
|
+
reject(dataChannelError('data', error));
|
|
108
|
+
};
|
|
109
|
+
});
|
|
109
110
|
const ufrag = 'libp2p+webrtc+v1/' + genUfrag(32);
|
|
110
|
-
// Create offer and munge sdp with ufrag
|
|
111
|
+
// Create offer and munge sdp with ufrag == pwd. This allows the remote to
|
|
111
112
|
// respond to STUN messages without performing an actual SDP exchange.
|
|
112
113
|
// This is because it can infer the passwd field by reading the USERNAME
|
|
113
114
|
// attribute of the STUN message.
|
|
@@ -118,20 +119,19 @@ export class WebRTCTransport {
|
|
|
118
119
|
const answerSdp = sdp.fromMultiAddr(ma, ufrag);
|
|
119
120
|
await peerConnection.setRemoteDescription(answerSdp);
|
|
120
121
|
// wait for peerconnection.onopen to fire, or for the datachannel to open
|
|
121
|
-
await dataChannelOpenPromise
|
|
122
|
+
const handshakeDataChannel = await dataChannelOpenPromise;
|
|
122
123
|
const myPeerId = this.components.peerId;
|
|
123
|
-
const theirPeerId = p.peerIdFromString(rps);
|
|
124
124
|
// Do noise handshake.
|
|
125
125
|
// Set the Noise Prologue to libp2p-webrtc-noise:<FINGERPRINTS> before starting the actual Noise handshake.
|
|
126
126
|
// <FINGERPRINTS> is the concatenation of the of the two TLS fingerprints of A and B in their multihash byte representation, sorted in ascending order.
|
|
127
|
-
const fingerprintsPrologue = this.generateNoisePrologue(peerConnection, remoteCerthash.
|
|
127
|
+
const fingerprintsPrologue = this.generateNoisePrologue(peerConnection, remoteCerthash.code, ma);
|
|
128
128
|
// Since we use the default crypto interface and do not use a static key or early data,
|
|
129
129
|
// we pass in undefined for these parameters.
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
const wrappedChannel = new WebRTCStream({ channel: handshakeDataChannel, stat: { direction: 'outbound', timeline: { open: 1 } } });
|
|
130
|
+
const noise = Noise({ prologueBytes: fingerprintsPrologue })();
|
|
131
|
+
const wrappedChannel = new WebRTCStream({ channel: handshakeDataChannel, stat: { direction: 'inbound', timeline: { open: 1 } } });
|
|
133
132
|
const wrappedDuplex = {
|
|
134
133
|
...wrappedChannel,
|
|
134
|
+
sink: wrappedChannel.sink.bind(wrappedChannel),
|
|
135
135
|
source: {
|
|
136
136
|
[Symbol.asyncIterator]: async function* () {
|
|
137
137
|
for await (const list of wrappedChannel.source) {
|
|
@@ -159,7 +159,7 @@ export class WebRTCTransport {
|
|
|
159
159
|
* Generate a noise prologue from the peer connection's certificate.
|
|
160
160
|
* noise prologue = bytes('libp2p-webrtc-noise:') + noise-responder fingerprint + noise-initiator fingerprint
|
|
161
161
|
*/
|
|
162
|
-
generateNoisePrologue(pc,
|
|
162
|
+
generateNoisePrologue(pc, hashCode, ma) {
|
|
163
163
|
if (pc.getConfiguration().certificates?.length === 0) {
|
|
164
164
|
throw invalidArgument('no local certificate');
|
|
165
165
|
}
|
|
@@ -173,7 +173,7 @@ export class WebRTCTransport {
|
|
|
173
173
|
}
|
|
174
174
|
const localFpString = localFingerprint.value.replace(/:/g, '');
|
|
175
175
|
const localFpArray = uint8arrayFromString(localFpString, 'hex');
|
|
176
|
-
const local = multihashes.encode(localFpArray,
|
|
176
|
+
const local = multihashes.encode(localFpArray, hashCode);
|
|
177
177
|
const remote = sdp.mbdecoder.decode(sdp.certhash(ma));
|
|
178
178
|
const prefix = uint8arrayFromString('libp2p-webrtc-noise:');
|
|
179
179
|
return concat([prefix, local, remote]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,EAAmC,MAAM,EAAa,MAAM,6BAA6B,CAAA;A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AAA;QAEvD,IAAI,gBAAgB,CAAC,KAAK,KAAK,SAAS,EAAE;YACxC,MAAM,eAAe,CAAC,qCAAqC,CAAC,CAAA;SAC7D;QAED,MAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAC9D,MAAM,YAAY,GAAG,oBAAoB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA;QAC/D,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;QACxD,MAAM,MAAM,GAAe,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;QACjE,MAAM,MAAM,GAAG,oBAAoB,CAAC,sBAAsB,CAAC,CAAA;QAE3D,OAAO,MAAM,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;IACxC,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,OAAO,CAAE,EAAa;IAC7B,MAAM,KAAK,GAAG,EAAE,CAAC,UAAU,EAAE,CAAA;IAC7B,OAAO,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,IAAI,IAAI,CAAA;AAC/F,CAAC"}
|
package/dist/src/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;CAErB,CAAA;AAED,eAAO,MAAM,OAAO,MAAa,GAAG,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;CAErB,CAAA;AAED,eAAO,MAAM,OAAO,MAAa,GAAG,KAAG,QAAQ,IAAI,CAAO,CAAA;AAG1D,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,MAAoG,CAAA"}
|
package/dist/src/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,KAAK,CAAC,CAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC;CACrC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,CAAM,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,KAAK,CAAC,CAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC;CACrC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,CAAM,EAAiB,EAAE,GAAE,CAAC,CAAA;AAE1D,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAA;AAC9F,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/webrtc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A libp2p transport using WebRTC connections",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "Apache-2.0 OR MIT",
|
|
@@ -135,13 +135,13 @@
|
|
|
135
135
|
"release": "aegir release"
|
|
136
136
|
},
|
|
137
137
|
"dependencies": {
|
|
138
|
-
"@chainsafe/libp2p-noise": "^
|
|
138
|
+
"@chainsafe/libp2p-noise": "^11.0.0",
|
|
139
139
|
"@libp2p/interface-connection": "^3.0.2",
|
|
140
|
-
"@libp2p/interface-peer-id": "^
|
|
140
|
+
"@libp2p/interface-peer-id": "^2.0.0",
|
|
141
141
|
"@libp2p/interface-stream-muxer": "^3.0.0",
|
|
142
142
|
"@libp2p/interface-transport": "^2.0.0",
|
|
143
143
|
"@libp2p/logger": "^2.0.0",
|
|
144
|
-
"@libp2p/peer-id": "^
|
|
144
|
+
"@libp2p/peer-id": "^2.0.0",
|
|
145
145
|
"@multiformats/multiaddr": "^11.0.3",
|
|
146
146
|
"@protobuf-ts/runtime": "^2.8.0",
|
|
147
147
|
"err-code": "^3.0.1",
|
|
@@ -157,11 +157,12 @@
|
|
|
157
157
|
"uint8arrays": "^4.0.2"
|
|
158
158
|
},
|
|
159
159
|
"devDependencies": {
|
|
160
|
-
"@libp2p/interface-mocks": "^
|
|
161
|
-
"@libp2p/peer-id-factory": "^
|
|
160
|
+
"@libp2p/interface-mocks": "^9.0.0",
|
|
161
|
+
"@libp2p/peer-id-factory": "^2.0.0",
|
|
162
162
|
"@protobuf-ts/plugin": "^2.8.0",
|
|
163
163
|
"@protobuf-ts/protoc": "^2.8.0",
|
|
164
|
-
"aegir": "^
|
|
164
|
+
"aegir": "^38.1.6",
|
|
165
|
+
"eslint-plugin-etc": "^2.0.2",
|
|
165
166
|
"it-first": "^2.0.0",
|
|
166
167
|
"libp2p": "^0.41.0"
|
|
167
168
|
}
|
package/src/error.ts
CHANGED
|
@@ -28,7 +28,7 @@ export class ConnectionClosedError extends WebRTCTransportError {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export function connectionClosedError (state: RTCPeerConnectionState, msg: string) {
|
|
31
|
+
export function connectionClosedError (state: RTCPeerConnectionState, msg: string): Error {
|
|
32
32
|
return errCode(new ConnectionClosedError(state, msg), codes.ERR_CONNECTION_CLOSED)
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -39,7 +39,7 @@ export class DataChannelError extends WebRTCTransportError {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function dataChannelError (streamLabel: string, msg: string) {
|
|
42
|
+
export function dataChannelError (streamLabel: string, msg: string): Error {
|
|
43
43
|
return errCode(new DataChannelError(streamLabel, msg), codes.ERR_DATA_CHANNEL)
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -50,7 +50,7 @@ export class InappropriateMultiaddrError extends WebRTCTransportError {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export function inappropriateMultiaddr (msg: string) {
|
|
53
|
+
export function inappropriateMultiaddr (msg: string): Error {
|
|
54
54
|
return errCode(new InappropriateMultiaddrError(msg), codes.ERR_INVALID_MULTIADDR)
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -61,7 +61,7 @@ export class InvalidArgumentError extends WebRTCTransportError {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export function invalidArgument (msg: string) {
|
|
64
|
+
export function invalidArgument (msg: string): Error {
|
|
65
65
|
return errCode(new InvalidArgumentError(msg), codes.ERR_INVALID_PARAMETERS)
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -72,7 +72,7 @@ export class InvalidFingerprintError extends WebRTCTransportError {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export function invalidFingerprint (fingerprint: string, source: string) {
|
|
75
|
+
export function invalidFingerprint (fingerprint: string, source: string): Error {
|
|
76
76
|
return errCode(new InvalidFingerprintError(fingerprint, source), codes.ERR_INVALID_FINGERPRINT)
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -83,7 +83,7 @@ export class OperationAbortedError extends WebRTCTransportError {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
export function operationAborted (context: string, reason: string) {
|
|
86
|
+
export function operationAborted (context: string, reason: string): Error {
|
|
87
87
|
return errCode(new OperationAbortedError(context, reason), codes.ERR_ALREADY_ABORTED)
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -94,7 +94,7 @@ export class OverStreamLimitError extends WebRTCTransportError {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export function overStreamLimit (dir: Direction, proto: string) {
|
|
97
|
+
export function overStreamLimit (dir: Direction, proto: string): Error {
|
|
98
98
|
const code = dir === 'inbound' ? codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS : codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS
|
|
99
99
|
return errCode(new OverStreamLimitError(`${dir} stream limit reached for protocol - ${proto}`), code)
|
|
100
100
|
}
|
|
@@ -106,7 +106,7 @@ export class UnimplementedError extends WebRTCTransportError {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
export function unimplemented (methodName: string) {
|
|
109
|
+
export function unimplemented (methodName: string): Error {
|
|
110
110
|
return errCode(new UnimplementedError(methodName), codes.ERR_NOT_IMPLEMENTED)
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -118,6 +118,6 @@ export class UnsupportedHashAlgorithmError extends WebRTCTransportError {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export function unsupportedHashAlgorithm (algorithm: string) {
|
|
121
|
+
export function unsupportedHashAlgorithm (algorithm: string): Error {
|
|
122
122
|
return errCode(new UnsupportedHashAlgorithmError(algorithm), codes.ERR_HASH_NOT_SUPPORTED)
|
|
123
123
|
}
|
package/src/maconn.ts
CHANGED
|
@@ -28,17 +28,17 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
|
28
28
|
/**
|
|
29
29
|
* WebRTC Peer Connection
|
|
30
30
|
*/
|
|
31
|
-
readonly peerConnection: RTCPeerConnection
|
|
31
|
+
readonly peerConnection: RTCPeerConnection
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* The multiaddr address used to communicate with the remote peer
|
|
35
35
|
*/
|
|
36
|
-
remoteAddr: Multiaddr
|
|
36
|
+
remoteAddr: Multiaddr
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Holds the lifecycle times of the connection
|
|
40
40
|
*/
|
|
41
|
-
timeline: MultiaddrConnectionTimeline
|
|
41
|
+
timeline: MultiaddrConnectionTimeline
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* The stream source, a no-op as the transport natively supports multiplexing
|
|
@@ -48,7 +48,7 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
|
48
48
|
/**
|
|
49
49
|
* The stream destination, a no-op as the transport natively supports multiplexing
|
|
50
50
|
*/
|
|
51
|
-
sink: Sink<Uint8Array, Promise<void>> = nopSink
|
|
51
|
+
sink: Sink<Uint8Array, Promise<void>> = nopSink
|
|
52
52
|
|
|
53
53
|
constructor (init: WebRTCMultiaddrConnectionInit) {
|
|
54
54
|
this.remoteAddr = init.remoteAddr
|
package/src/muxer.ts
CHANGED
|
@@ -56,12 +56,12 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
56
56
|
/**
|
|
57
57
|
* The stream source, a no-op as the transport natively supports multiplexing
|
|
58
58
|
*/
|
|
59
|
-
source: Source<Uint8Array> = nopSource
|
|
59
|
+
source: Source<Uint8Array> = nopSource
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* The stream destination, a no-op as the transport natively supports multiplexing
|
|
63
63
|
*/
|
|
64
|
-
sink: Sink<Uint8Array, Promise<void>> = nopSink
|
|
64
|
+
sink: Sink<Uint8Array, Promise<void>> = nopSink
|
|
65
65
|
|
|
66
66
|
constructor (peerConnection: RTCPeerConnection, init?: StreamMuxerInit) {
|
|
67
67
|
/**
|
|
@@ -98,12 +98,9 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*/
|
|
105
|
-
newStream (name: string = ''): Stream {
|
|
106
|
-
const channel = this.peerConnection.createDataChannel(name)
|
|
101
|
+
newStream (): Stream {
|
|
102
|
+
// The spec says the label SHOULD be an empty string: https://github.com/libp2p/specs/blob/master/webrtc/README.md#rtcdatachannel-label
|
|
103
|
+
const channel = this.peerConnection.createDataChannel('')
|
|
107
104
|
const stream = new WebRTCStream({
|
|
108
105
|
channel,
|
|
109
106
|
stat: {
|
package/src/sdp.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { logger } from '@libp2p/logger'
|
|
|
2
2
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
import { bases } from 'multiformats/basics'
|
|
4
4
|
import * as multihashes from 'multihashes'
|
|
5
|
+
import type { HashCode, HashName } from 'multihashes'
|
|
5
6
|
|
|
6
7
|
import { inappropriateMultiaddr, invalidArgument, invalidFingerprint, unsupportedHashAlgorithm } from './error.js'
|
|
7
8
|
import { CERTHASH_CODE } from './transport.js'
|
|
@@ -11,12 +12,8 @@ const log = logger('libp2p:webrtc:sdp')
|
|
|
11
12
|
/**
|
|
12
13
|
* Get base2 | identity decoders
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let acc = decoders[0].or(decoders[1])
|
|
17
|
-
decoders.slice(2).forEach((d) => (acc = acc.or(d)))
|
|
18
|
-
return acc
|
|
19
|
-
})()
|
|
15
|
+
// @ts-expect-error - Not easy to combine these types.
|
|
16
|
+
export const mbdecoder: any = Object.values(bases).map(b => b.decoder).reduce((d, b) => d.or(b))
|
|
20
17
|
|
|
21
18
|
/**
|
|
22
19
|
* Get base2 | identity decoders
|
|
@@ -48,7 +45,7 @@ export function certhash (ma: Multiaddr): string {
|
|
|
48
45
|
/**
|
|
49
46
|
* Convert a certhash into a multihash
|
|
50
47
|
*/
|
|
51
|
-
export function decodeCerthash (certhash: string) {
|
|
48
|
+
export function decodeCerthash (certhash: string): { code: HashCode, name: HashName, length: number, digest: Uint8Array } {
|
|
52
49
|
const mbdecoded = mbdecoder.decode(certhash)
|
|
53
50
|
return multihashes.decode(mbdecoded)
|
|
54
51
|
}
|
|
@@ -57,7 +54,6 @@ export function decodeCerthash (certhash: string) {
|
|
|
57
54
|
* Extract the fingerprint from a multiaddr
|
|
58
55
|
*/
|
|
59
56
|
export function ma2Fingerprint (ma: Multiaddr): string[] {
|
|
60
|
-
// certhash_value is a multibase encoded multihash encoded string
|
|
61
57
|
const mhdecoded = decodeCerthash(certhash(ma))
|
|
62
58
|
const prefix = toSupportedHashFunction(mhdecoded.name)
|
|
63
59
|
const fingerprint = mhdecoded.digest.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '')
|