@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.
@@ -1,10 +1,9 @@
1
- import { bases } from 'multiformats/basics'
2
- import * as multihashes from 'multihashes'
3
- import { inappropriateMultiaddr, invalidArgument, invalidFingerprint, unsupportedHashAlgorithm } from '../error.js'
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 { Multiaddr } from '@multiformats/multiaddr'
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): { code: HashCode, name: HashName, length: number, digest: Uint8Array } {
75
- const mbdecoded = mbdecoder.decode(certhash)
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.name)
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.toUpperCase()} ${sdp.join(':').toUpperCase()}`, fingerprint]
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 (name: multihashes.HashName): string {
99
- switch (name) {
100
- case 'sha1':
101
- return 'sha-1'
102
- case 'sha2-256':
103
- return 'sha-256'
104
- case 'sha2-512':
105
- return 'sha-512'
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 unsupportedHashAlgorithm(name)
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 multihashes from 'multihashes'
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.name)
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: multihashes.HashCode, ma: Multiaddr): Uint8Array {
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 = multihashes.encode(localFpArray, hashCode)
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 = 16 * 1024 * 1024
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
@@ -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
- }