// create a keypair to publish an IPNS name constprivateKey = awaitgenerateKeyPair('Ed25519')
// store some data to publish constfs = unixfs(helia) constcid = awaitfs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
// publish the name awaitname.publish(privateKey, cid)
// create another keypair to re-publish the original record constrecursivePrivateKey = awaitgenerateKeyPair('Ed25519')
// publish the recursive name awaitname.publish(recursivePrivateKey, privateKey.publicKey)
// resolve the name recursively - it resolves until a CID is found constresult = awaitname.resolve(recursivePrivateKey.publicKey) console.info(result.cid.toString() === cid.toString()) // true
Example: Publishing a record with a path
It is possible to publish CIDs with an associated path.
Additional IPNS routers can be configured - these enable alternative means to
publish and resolve IPNS names.
One example is the PubSub router - this requires an instance of Helia with
libp2p PubSub configured.
It works by subscribing to a pubsub topic for each IPNS name that we try to
resolve. Updated IPNS records are shared on these topics so an update must
occur before the name is resolvable.
This router is only suitable for networks where IPNS updates are frequent
and multiple peers are listening on the topic(s), otherwise update messages
may fail to be published with "Insufficient peers" errors.
Calling resolveDNSLink with the @helia/ipns instance:
// resolve a CID from a TXT record in a DNS zone file, using the default // resolver for the current platform eg: // > dig _dnslink.ipfs.io TXT // ;; ANSWER SECTION: // _dnslink.ipfs.io. 60 IN TXT "dnslink=/ipns/website.ipfs.io" // > dig _dnslink.website.ipfs.io TXT // ;; ANSWER SECTION: // _dnslink.website.ipfs.io. 60 IN TXT "dnslink=/ipfs/QmWebsite"
This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This
uses binary DNS records so requires extra dependencies to process the
response which can increase browser bundle sizes.
If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
IPNS operations using a Helia node
Example: Getting started
With IPNSRouting routers:
Example: Publishing a recursive record
A recursive record is a one that points to another record rather than to a value.
Example: Publishing a record with a path
It is possible to publish CIDs with an associated path.
Example: Using custom PubSub router
Additional IPNS routers can be configured - these enable alternative means to publish and resolve IPNS names.
One example is the PubSub router - this requires an instance of Helia with libp2p PubSub configured.
It works by subscribing to a pubsub topic for each IPNS name that we try to resolve. Updated IPNS records are shared on these topics so an update must occur before the name is resolvable.
This router is only suitable for networks where IPNS updates are frequent and multiple peers are listening on the topic(s), otherwise update messages may fail to be published with "Insufficient peers" errors.
Example: Using custom DNS over HTTPS resolvers
To use custom resolvers, configure Helia's
dns
option:Example: Resolving a domain with a dnslink entry
Calling
resolveDNSLink
with the@helia/ipns
instance:Example: Using DNS-Over-HTTPS
This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This uses binary DNS records so requires extra dependencies to process the response which can increase browser bundle sizes.
If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
Example: Using DNS-JSON-Over-HTTPS
DNS-JSON-Over-HTTPS resolvers use the RFC 8427
application/dns-json
and can result in a smaller browser bundle due to the response being plain JSON.