Skip to content

Commit 3f9a285

Browse files
authored
Disable dials to multiaddrs without certhashes (libp2p#32)
1 parent e76b7ae commit 3f9a285

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ class WebTransport implements Transport {
294294

295295
const { url, certhashes, remotePeer } = parseMultiaddr(ma)
296296

297+
if (certhashes.length === 0) {
298+
throw new Error('Expected multiaddr to contain certhashes')
299+
}
300+
297301
const wt = new window.WebTransport(`${url}/.well-known/libp2p-webtransport?type=noise`, {
298302
serverCertificateHashes: certhashes.map(certhash => ({
299303
algorithm: 'sha-256',

test/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('libp2p-webtransport', () => {
8484
await node.start()
8585

8686
const err = await expect(node.dial(ma)).to.eventually.be.rejected()
87-
expect(err.errors[0].toString()).to.contain('WebTransportError: Opening handshake failed.')
87+
expect(err.errors[0].toString()).to.contain('Expected multiaddr to contain certhashes')
8888

8989
await node.stop()
9090
})

0 commit comments

Comments
 (0)