From 3f9a285e45e28cbbca9ed91e7560334f79a40695 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 1 Dec 2022 20:39:33 -0800 Subject: [PATCH] Disable dials to multiaddrs without certhashes (#32) --- src/index.ts | 4 ++++ test/browser.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 80dd679..58f5cf1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -294,6 +294,10 @@ class WebTransport implements Transport { const { url, certhashes, remotePeer } = parseMultiaddr(ma) + if (certhashes.length === 0) { + throw new Error('Expected multiaddr to contain certhashes') + } + const wt = new window.WebTransport(`${url}/.well-known/libp2p-webtransport?type=noise`, { serverCertificateHashes: certhashes.map(certhash => ({ algorithm: 'sha-256', diff --git a/test/browser.ts b/test/browser.ts index 296102d..ca691fd 100644 --- a/test/browser.ts +++ b/test/browser.ts @@ -84,7 +84,7 @@ describe('libp2p-webtransport', () => { await node.start() const err = await expect(node.dial(ma)).to.eventually.be.rejected() - expect(err.errors[0].toString()).to.contain('WebTransportError: Opening handshake failed.') + expect(err.errors[0].toString()).to.contain('Expected multiaddr to contain certhashes') await node.stop() })