@libp2p/webrtc 4.1.1 → 4.1.2-4a994c5ef
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 +14 -28
- package/dist/src/constants.d.ts +4 -1
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +5 -7
- package/dist/src/constants.js.map +1 -1
- package/dist/src/error.d.ts +2 -2
- package/dist/src/error.d.ts.map +1 -1
- package/dist/src/error.js +3 -3
- package/dist/src/error.js.map +1 -1
- package/dist/src/private-to-private/transport.d.ts +3 -3
- package/dist/src/private-to-private/transport.d.ts.map +1 -1
- package/dist/src/private-to-private/transport.js.map +1 -1
- package/dist/src/private-to-public/options.d.ts +2 -2
- package/dist/src/private-to-public/options.d.ts.map +1 -1
- package/dist/src/private-to-public/sdp.d.ts +4 -10
- package/dist/src/private-to-public/sdp.d.ts.map +1 -1
- package/dist/src/private-to-public/sdp.js +15 -16
- package/dist/src/private-to-public/sdp.js.map +1 -1
- package/dist/src/private-to-public/transport.js +4 -4
- package/dist/src/private-to-public/transport.js.map +1 -1
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +1 -1
- package/dist/src/stream.js.map +1 -1
- package/package.json +12 -13
- package/src/constants.ts +5 -7
- package/src/error.ts +4 -4
- package/src/private-to-private/transport.ts +3 -3
- package/src/private-to-public/options.ts +2 -2
- package/src/private-to-public/sdp.ts +17 -19
- package/src/private-to-public/transport.ts +5 -5
- package/src/stream.ts +1 -1
- package/dist/typedoc-urls.json +0 -8
@@ -1,10 +1,9 @@
|
|
1
|
-
import {
|
2
|
-
import
|
3
|
-
import { inappropriateMultiaddr, invalidArgument, invalidFingerprint,
|
1
|
+
import { type Multiaddr } from '@multiformats/multiaddr'
|
2
|
+
import { bases, digest } from 'multiformats/basics'
|
3
|
+
import { inappropriateMultiaddr, invalidArgument, invalidFingerprint, unsupportedHashAlgorithmCode } from '../error.js'
|
4
4
|
import { CERTHASH_CODE } from './transport.js'
|
5
5
|
import type { LoggerOptions } from '@libp2p/interface'
|
6
|
-
import type {
|
7
|
-
import type { HashCode, HashName } from 'multihashes'
|
6
|
+
import type { MultihashDigest } from 'multiformats/hashes/interface'
|
8
7
|
|
9
8
|
/**
|
10
9
|
* Get base2 | identity decoders
|
@@ -71,9 +70,8 @@ export function certhash (ma: Multiaddr): string {
|
|
71
70
|
/**
|
72
71
|
* Convert a certhash into a multihash
|
73
72
|
*/
|
74
|
-
export function decodeCerthash (certhash: string):
|
75
|
-
|
76
|
-
return multihashes.decode(mbdecoded)
|
73
|
+
export function decodeCerthash (certhash: string): MultihashDigest {
|
74
|
+
return digest.decode(mbdecoder.decode(certhash))
|
77
75
|
}
|
78
76
|
|
79
77
|
/**
|
@@ -81,7 +79,7 @@ export function decodeCerthash (certhash: string): { code: HashCode, name: HashN
|
|
81
79
|
*/
|
82
80
|
export function ma2Fingerprint (ma: Multiaddr): string[] {
|
83
81
|
const mhdecoded = decodeCerthash(certhash(ma))
|
84
|
-
const prefix = toSupportedHashFunction(mhdecoded.
|
82
|
+
const prefix = toSupportedHashFunction(mhdecoded.code)
|
85
83
|
const fingerprint = mhdecoded.digest.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '')
|
86
84
|
const sdp = fingerprint.match(/.{1,2}/g)
|
87
85
|
|
@@ -89,22 +87,22 @@ export function ma2Fingerprint (ma: Multiaddr): string[] {
|
|
89
87
|
throw invalidFingerprint(fingerprint, ma.toString())
|
90
88
|
}
|
91
89
|
|
92
|
-
return [`${prefix
|
90
|
+
return [`${prefix} ${sdp.join(':').toUpperCase()}`, fingerprint]
|
93
91
|
}
|
94
92
|
|
95
93
|
/**
|
96
94
|
* Normalize the hash name from a given multihash has name
|
97
95
|
*/
|
98
|
-
export function toSupportedHashFunction (
|
99
|
-
switch (
|
100
|
-
case
|
101
|
-
return '
|
102
|
-
case
|
103
|
-
return '
|
104
|
-
case
|
105
|
-
return '
|
96
|
+
export function toSupportedHashFunction (code: number): 'SHA-1' | 'SHA-256' | 'SHA-512' {
|
97
|
+
switch (code) {
|
98
|
+
case 0x11:
|
99
|
+
return 'SHA-1'
|
100
|
+
case 0x12:
|
101
|
+
return 'SHA-256'
|
102
|
+
case 0x13:
|
103
|
+
return 'SHA-512'
|
106
104
|
default:
|
107
|
-
throw
|
105
|
+
throw unsupportedHashAlgorithmCode(code)
|
108
106
|
}
|
109
107
|
}
|
110
108
|
|
@@ -3,7 +3,7 @@ import { transportSymbol, serviceCapabilities } from '@libp2p/interface'
|
|
3
3
|
import * as p from '@libp2p/peer-id'
|
4
4
|
import { protocols } from '@multiformats/multiaddr'
|
5
5
|
import { WebRTCDirect } from '@multiformats/multiaddr-matcher'
|
6
|
-
import * as
|
6
|
+
import * as Digest from 'multiformats/hashes/digest'
|
7
7
|
import { concat } from 'uint8arrays/concat'
|
8
8
|
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
|
9
9
|
import { dataChannelError, inappropriateMultiaddr, unimplemented, invalidArgument } from '../error.js'
|
@@ -135,7 +135,7 @@ export class WebRTCDirectTransport implements Transport {
|
|
135
135
|
const certificate = await RTCPeerConnection.generateCertificate({
|
136
136
|
name: 'ECDSA',
|
137
137
|
namedCurve: 'P-256',
|
138
|
-
hash: sdp.toSupportedHashFunction(remoteCerthash.
|
138
|
+
hash: sdp.toSupportedHashFunction(remoteCerthash.code)
|
139
139
|
} as any)
|
140
140
|
|
141
141
|
const peerConnection = new RTCPeerConnection({
|
@@ -273,7 +273,7 @@ export class WebRTCDirectTransport implements Transport {
|
|
273
273
|
* Generate a noise prologue from the peer connection's certificate.
|
274
274
|
* noise prologue = bytes('libp2p-webrtc-noise:') + noise-responder fingerprint + noise-initiator fingerprint
|
275
275
|
*/
|
276
|
-
private generateNoisePrologue (pc: RTCPeerConnection, hashCode:
|
276
|
+
private generateNoisePrologue (pc: RTCPeerConnection, hashCode: number, ma: Multiaddr): Uint8Array {
|
277
277
|
if (pc.getConfiguration().certificates?.length === 0) {
|
278
278
|
throw invalidArgument('no local certificate')
|
279
279
|
}
|
@@ -287,10 +287,10 @@ export class WebRTCDirectTransport implements Transport {
|
|
287
287
|
|
288
288
|
const localFpString = localFingerprint.trim().toLowerCase().replaceAll(':', '')
|
289
289
|
const localFpArray = uint8arrayFromString(localFpString, 'hex')
|
290
|
-
const local =
|
290
|
+
const local = Digest.create(hashCode, localFpArray)
|
291
291
|
const remote: Uint8Array = sdp.mbdecoder.decode(sdp.certhash(ma))
|
292
292
|
const prefix = uint8arrayFromString('libp2p-webrtc-noise:')
|
293
293
|
|
294
|
-
return concat([prefix, local, remote])
|
294
|
+
return concat([prefix, local.bytes, remote])
|
295
295
|
}
|
296
296
|
}
|
package/src/stream.ts
CHANGED
@@ -27,7 +27,7 @@ export interface WebRTCStreamInit extends AbstractStreamInit, DataChannelOptions
|
|
27
27
|
/**
|
28
28
|
* How much can be buffered to the DataChannel at once
|
29
29
|
*/
|
30
|
-
export const MAX_BUFFERED_AMOUNT =
|
30
|
+
export const MAX_BUFFERED_AMOUNT = 2 * 1024 * 1024
|
31
31
|
|
32
32
|
/**
|
33
33
|
* How long time we wait for the 'bufferedamountlow' event to be emitted
|
package/dist/typedoc-urls.json
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"DataChannelOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.DataChannelOptions.html",
|
3
|
-
".:DataChannelOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.DataChannelOptions.html",
|
4
|
-
"webRTC": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTC.html",
|
5
|
-
".:webRTC": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTC.html",
|
6
|
-
"webRTCDirect": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTCDirect.html",
|
7
|
-
".:webRTCDirect": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTCDirect.html"
|
8
|
-
}
|