Skip to content

Commit 6f9076c

Browse files
committed
fix: handle dnslink pointing to cid peer id
fixes #721
1 parent c7024de commit 6f9076c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/ipns/src/dnslink.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { } from '@libp2p/interface'
2-
import { peerIdFromString } from '@libp2p/peer-id'
2+
import { peerIdFromCID, peerIdFromString } from '@libp2p/peer-id'
33
import { RecordType } from '@multiformats/dns'
44
import { CID } from 'multiformats/cid'
55
import { DNSLinkNotFoundError } from './errors.js'
66
import type { ResolveDNSLinkOptions } from './index.js'
7-
import type { Logger } from '@libp2p/interface'
7+
import type { Logger, PeerId } from '@libp2p/interface'
88
import type { Answer, DNS } from '@multiformats/dns'
99

1010
const MAX_RECURSIVE_DEPTH = 32
@@ -66,7 +66,15 @@ async function recursiveResolveDnslink (domain: string, depth: number, dns: DNS,
6666
} catch {}
6767
} else if (protocol === 'ipns') {
6868
try {
69-
const peerId = peerIdFromString(domainOrCID)
69+
let peerId: PeerId
70+
71+
// eslint-disable-next-line max-depth
72+
if (domainOrCID.charAt(0) === '1' || domainOrCID.charAt(0) === 'Q') {
73+
peerId = peerIdFromString(domainOrCID)
74+
} else {
75+
// try parsing as a CID
76+
peerId = peerIdFromCID(CID.parse(domainOrCID))
77+
}
7078

7179
// if the result is a PeerId, we've reached the end of the recursion
7280
return {

0 commit comments

Comments
 (0)