Skip to content

Commit 982a4e5

Browse files
authored
fix: allow peer id on webrtc address (#43)
Adds exact webrtc address tests
1 parent 10f731f commit 982a4e5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ export const Circuit = fmt(_Circuit)
402402
const _WebRTC = or(
403403
and(_P2P, literal('p2p-circuit'), literal('webrtc'), optional(peerId())),
404404
and(_P2P, literal('webrtc'), optional(peerId())),
405-
literal('webrtc')
405+
and(literal('webrtc'), optional(peerId()))
406406
)
407407

408408
/**

test/index.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,20 @@ describe('multiaddr matcher', () => {
223223
'/ip4/0.0.0.0/tcp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
224224
]
225225

226-
const goodWebRTC = [
226+
const exactWebRTC = [
227227
'/ip4/195.201.24.91/udp/4001/quic-v1/webtransport/certhash/uEiCsrVjg8IHCNqD-5x91Rv6CiOQmvCZBGdjxZQBoFYVo9g/certhash/uEiBdh-sKr7lCAwlJRWkmOM-LwW5jGhqq5J4jM-EEvNLucg/p2p/12D3KooWLBjadARix9eMbThfGjCYTdB3Jq6LZVzkReEYqBCaZPiA/p2p-circuit/webrtc/p2p/12D3KooWHHdY2cWY7HKsTuQeBgDydapRVxy1XGUSzeZXv52vsdav',
228228
'/ip4/195.201.24.91/udp/4001/quic-v1/webtransport/certhash/uEiCsrVjg8IHCNqD-5x91Rv6CiOQmvCZBGdjxZQBoFYVo9g/certhash/uEiBdh-sKr7lCAwlJRWkmOM-LwW5jGhqq5J4jM-EEvNLucg/p2p/12D3KooWLBjadARix9eMbThfGjCYTdB3Jq6LZVzkReEYqBCaZPiA/p2p-circuit/webrtc',
229229
'/dnsaddr/example.org/wss/p2p/12D3KooWAzabxK2xhwGQuTUYjbcFT9SZcNvPS1cvj7bPMe2Rh9qF/p2p-circuit/webrtc/p2p/12D3KooWA6L4J1yRwqLwdXPZBxz3UL4E8pEE6AEhFkqDH5LTQyfq',
230230
'/ip4/127.0.0.1/tcp/59119/ws/p2p/12D3KooWAzabxK2xhwGQuTUYjbcFT9SZcNvPS1cvj7bPMe2Rh9qF/p2p-circuit/webrtc/p2p/12D3KooWA6L4J1yRwqLwdXPZBxz3UL4E8pEE6AEhFkqDH5LTQyfq',
231231
'/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/webrtc',
232+
'/webrtc/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v',
232233
'/webrtc'
233234
]
234235

236+
const goodWebRTC = [
237+
...exactWebRTC
238+
]
239+
235240
const badWebRTC = [
236241
'/ip4/0.0.0.0/udp/webrtc',
237242
'/ip4/0.0.0.0/tcp/12345/udp/2222/wss/webrtc'
@@ -405,6 +410,7 @@ describe('multiaddr matcher', () => {
405410

406411
it('WebRTC addresses', () => {
407412
assertMatches(mafmt.WebRTC, goodWebRTC)
413+
assertExactMatches(mafmt.WebRTC, exactWebRTC)
408414
assertMismatches(mafmt.WebRTC, badWebRTC)
409415
})
410416

0 commit comments

Comments
 (0)