8.2.3 • Published 5 months ago

@helia/ipns v8.2.3

Weekly downloads
-
License
Apache-2.0 OR MIT
Repository
github
Last release
5 months ago

@helia/ipns

ipfs.tech Discuss codecov CI

An implementation of IPNS for Helia

About

IPNS operations using a Helia node

Example - Getting started

With IPNSRouting routers:

import { createHelia } from 'helia'
import { ipns } from '@helia/ipns'
import { unixfs } from '@helia/unixfs'
import { generateKeyPair } from '@libp2p/crypto/keys'

const helia = await createHelia()
const name = ipns(helia)

// create a keypair to publish an IPNS name
const privateKey = await generateKeyPair('Ed25519')

// store some data to publish
const fs = unixfs(helia)
const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))

// publish the name
await name.publish(privateKey, cid)

// resolve the name
const result = await name.resolve(privateKey.publicKey)

console.info(result.cid, result.path)

Example - Publishing a recursive record

A recursive record is a one that points to another record rather than to a value.

import { createHelia } from 'helia'
import { ipns } from '@helia/ipns'
import { unixfs } from '@helia/unixfs'
import { generateKeyPair } from '@libp2p/crypto/keys'

const helia = await createHelia()
const name = ipns(helia)

// create a keypair to publish an IPNS name
const privateKey = await generateKeyPair('Ed25519')

// store some data to publish
const fs = unixfs(helia)
const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))

// publish the name
await name.publish(privateKey, cid)

// create another keypair to re-publish the original record
const recursivePrivateKey = await generateKeyPair('Ed25519')

// publish the recursive name
await name.publish(recursivePrivateKey, privateKey.publicKey)

// resolve the name recursively - it resolves until a CID is found
const result = await name.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.

import { createHelia } from 'helia'
import { ipns } from '@helia/ipns'
import { unixfs } from '@helia/unixfs'
import { generateKeyPair } from '@libp2p/crypto/keys'

const helia = await createHelia()
const name = ipns(helia)

// create a keypair to publish an IPNS name
const privateKey = await generateKeyPair('Ed25519')

// store some data to publish
const fs = unixfs(helia)
const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))

// store the file in a directory
const dirCid = await fs.addDirectory()
const finalDirCid = await fs.cp(fileCid, dirCid, '/foo.txt')

// publish the name
await name.publish(privateKey, `/ipfs/${finalDirCid}/foo.txt`)

// resolve the name
const result = await name.resolve(privateKey.publicKey)

console.info(result.cid, result.path) // QmFoo.. 'foo.txt'

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.

import { createHelia, libp2pDefaults } from 'helia'
import { ipns } from '@helia/ipns'
import { pubsub } from '@helia/ipns/routing'
import { unixfs } from '@helia/unixfs'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { generateKeyPair } from '@libp2p/crypto/keys'
import type { Libp2p, PubSub } from '@libp2p/interface'
import type { DefaultLibp2pServices } from 'helia'

const libp2pOptions = libp2pDefaults()
libp2pOptions.services.pubsub = gossipsub()

const helia = await createHelia<Libp2p<DefaultLibp2pServices & { pubsub: PubSub }>>({
  libp2p: libp2pOptions
})
const name = ipns(helia, {
 routers: [
   pubsub(helia)
 ]
})

// create a keypair to publish an IPNS name
const privateKey = await generateKeyPair('Ed25519')

// store some data to publish
const fs = unixfs(helia)
const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))

// publish the name
await name.publish(privateKey, cid)

// resolve the name
const result = await name.resolve(privateKey.publicKey)

Example - Using custom DNS over HTTPS resolvers

To use custom resolvers, configure Helia's dns option:

import { createHelia } from 'helia'
import { ipns } from '@helia/ipns'
import { dns } from '@multiformats/dns'
import { dnsOverHttps } from '@multiformats/dns/resolvers'
import { helia } from '@helia/ipns/routing'

const node = await createHelia({
  dns: dns({
    resolvers: {
      '.': dnsOverHttps('https://private-dns-server.me/dns-query')
    }
  })
})
const name = ipns(node, {
 routers: [
   helia(node.routing)
 ]
})

const result = name.resolveDNSLink('some-domain-with-dnslink-entry.com')

Example - Resolving a domain with a dnslink entry

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"

import { createHelia } from 'helia'
import { ipns } from '@helia/ipns'

const node = await createHelia()
const name = ipns(node)

const { answer } = await name.resolveDNSLink('ipfs.io')

console.info(answer)
// { data: '/ipfs/QmWebsite' }

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.

import { createHelia } from 'helia'
import { ipns } from '@helia/ipns'
import { dns } from '@multiformats/dns'
import { dnsOverHttps } from '@multiformats/dns/resolvers'

const node = await createHelia({
  dns: dns({
    resolvers: {
      '.': dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
    }
  })
})
const name = ipns(node)

const result = await name.resolveDNSLink('ipfs.io')

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.

import { createHelia } from 'helia'
import { ipns } from '@helia/ipns'
import { dns } from '@multiformats/dns'
import { dnsJsonOverHttps } from '@multiformats/dns/resolvers'

const node = await createHelia({
  dns: dns({
    resolvers: {
      '.': dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
    }
  })
})
const name = ipns(node)

const result = await name.resolveDNSLink('ipfs.io')

Install

$ npm i @helia/ipns

Browser <script> tag

Loading this module through a script tag will make its exports available as HeliaIpns in the global namespace.

<script src="https://unpkg.com/@helia/ipns/dist/index.min.js"></script>

API Docs

License

Licensed under either of

Contribute

Contributions welcome! Please check out the issues.

Also see our contributing document for more information on how we work, and about contributing in general.

Please be aware that all interactions related to this repo are subject to the IPFS Code of Conduct.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

npm.io

8.1.0-375796a

8 months ago

8.0.0-c09fef2

12 months ago

8.0.1-73121c2

11 months ago

8.2.3

6 months ago

8.2.2

6 months ago

8.2.2-60fbbc2

6 months ago

8.2.0-c0bf36e

8 months ago

8.1.0

10 months ago

8.2.0-9591175

6 months ago

8.2.3-7a52e951

5 months ago

8.0.0-1aa6c8d

12 months ago

8.2.3-50a97662

5 months ago

8.1.0-99bb059

9 months ago

8.2.0-ae67092

6 months ago

8.0.1-87aa9b4

10 months ago

8.2.1

6 months ago

8.2.0

8 months ago

8.0.1-1c8583c

10 months ago

8.2.2-e3522f5

6 months ago

8.2.0-cd1eb58

6 months ago

8.2.0-bb2ab74

7 months ago

8.2.2-a4dfe0b

6 months ago

8.1.0-91880b0

8 months ago

8.1.0-e6339ed

8 months ago

8.2.3-28a70912

5 months ago

8.2.0-325b36f

8 months ago

8.1.0-73cb631

8 months ago

8.2.2-88cc129

6 months ago

8.1.0-70b8fa9

8 months ago

8.0.2-12df657

10 months ago

8.0.1-4710c65

11 months ago

8.0.2-c7024de

10 months ago

8.2.3-41bcc88d

5 months ago

8.1.0-d602bb2

8 months ago

8.0.1-e45e1de

10 months ago

8.0.1-3d1ce0b

11 months ago

8.0.1-22c1beb

10 months ago

8.2.2-d5e8799

6 months ago

8.1.0-45ca6bc

8 months ago

8.2.2-33dbeed

6 months ago

8.0.1-5784ceb

10 months ago

8.0.2-2666d64

10 months ago

8.1.0-f7155d8

9 months ago

8.1.0-2c7185c

9 months ago

8.0.1-6a9fd94

11 months ago

8.2.2-d78f91b

6 months ago

8.0.0-e58e49c

1 year ago

8.0.0-aecac3d

1 year ago

8.0.0-f7b5d3f

12 months ago

8.1.0-c015793

9 months ago

8.0.2-6542cf2

10 months ago

8.0.1-07e0bc0

11 months ago

8.0.1-075b6ca

11 months ago

8.1.0-15de32f

8 months ago

8.1.0-ac7185a

9 months ago

8.1.0-ad081b2

8 months ago

8.2.3-99025383

6 months ago

8.1.0-eaf789a

9 months ago

8.2.0-daaa511

7 months ago

8.0.1-a7aebd5

10 months ago

8.1.0-deb9165

9 months ago

8.2.0-313e2c1

7 months ago

8.2.0-3d77369

6 months ago

8.2.1-d43efc7

6 months ago

8.0.1

12 months ago

8.0.2

10 months ago

8.1.0-afa9a1a

8 months ago

8.2.0-d883eaf

7 months ago

8.0.0-dff82ec

1 year ago

8.0.0-0238ed4

1 year ago

8.0.0-23ebae1

1 year ago

8.0.0-efc47fa

1 year ago

8.0.0-693c82d

1 year ago

8.0.0-8364296

1 year ago

8.0.0-460853f

1 year ago

8.0.0-1b2934b

1 year ago

7.2.3-bc64f47

1 year ago

7.2.3-efdefc1

1 year ago

7.2.3-60d8c8a

1 year ago

7.2.3-2f88fc8

1 year ago

8.0.0

1 year ago

7.2.3-c04dbf5

1 year ago

7.2.3-ec8bf66

1 year ago

7.2.2-5fab3a3

1 year ago

7.2.2-117198f

1 year ago

7.2.3-f5a03fc

1 year ago

7.2.3-4f14996

1 year ago

7.2.3-acd876b

1 year ago

7.2.3-8805202

1 year ago

7.2.3-ac4bdb8

1 year ago

7.2.2-74ccc92

1 year ago

7.2.2-62f77df

1 year ago

7.2.2-461d219

1 year ago

7.2.3-3bf5ab0

1 year ago

7.2.2-e6bca0b

1 year ago

7.2.2-5643b1d

1 year ago

7.2.3-5ff6998

1 year ago

7.2.3

1 year ago

7.2.2-011fa92

1 year ago

7.2.3-e567717

1 year ago

7.2.2-3577d3d

1 year ago

7.2.3-c9c644c

1 year ago

7.2.2-f16c9ea

1 year ago

7.2.2-b4877b5

1 year ago

7.2.3-9de08ef

1 year ago

7.2.2-155e24d

1 year ago

7.2.3-23e62e1

1 year ago

7.2.2-6952f05

1 year ago

7.2.2-21ef20c

1 year ago

7.2.2-f46700f

1 year ago

7.2.2-e6b976a

1 year ago

7.2.2-9fa2427

2 years ago

7.2.2-a8fdfc2

2 years ago

7.2.2-55b9650

2 years ago

7.2.1-b0d50e9

2 years ago

7.2.2

2 years ago

7.2.1-7419dfc

2 years ago

7.2.1-fa9bd4b

2 years ago

7.2.1-6a62d1c

2 years ago

7.2.1-36081e0

2 years ago

7.2.1-2d070b9

2 years ago

7.2.1-e4e67d0

2 years ago

7.2.1-361fbd3

2 years ago

7.2.1-0a528bb

2 years ago

7.2.1-f6bcbd4

2 years ago

7.2.1-52dbcf2

2 years ago

7.2.1-f7f71bb

2 years ago

7.2.1-5e98950

2 years ago

7.2.1-0ecb529

2 years ago

7.2.1-5d62dfb

2 years ago

7.2.1-338885f

2 years ago

7.2.1-59de059

2 years ago

7.2.0-9ea934e

2 years ago

7.2.0-9c8a2c0

2 years ago

7.2.0-5323724

2 years ago

7.2.1

2 years ago

7.2.0-ba4b7ba

2 years ago

7.2.0-b67ac5f

2 years ago

7.2.0-b1c761d

2 years ago

7.2.0-395cd9e

2 years ago

7.2.0-532d6c4

2 years ago

7.2.0-7cd012a

2 years ago

7.2.0-e582c63

2 years ago

7.2.0-329652a

2 years ago

7.1.0-1561e4a

2 years ago

7.2.0-6ddefb0

2 years ago

7.2.0

2 years ago

7.2.0-5cf216b

2 years ago

7.1.0-9ac5909

2 years ago

7.1.0-d1c497b

2 years ago

7.1.0

2 years ago

7.0.0-b6765fe

2 years ago

7.0.0

2 years ago

7.0.0-ecf5394

2 years ago

6.0.1-adc5589

2 years ago

6.0.1-a0d651c

2 years ago

6.0.1-2c71b6e

2 years ago

6.0.1-8c9bb7d

2 years ago

6.0.1-a64e5de

2 years ago

6.0.1-c69913c

2 years ago

6.0.1-90c6feb

2 years ago

6.0.0-c3f2ed1

2 years ago

6.0.0-6f8c15b

2 years ago

6.0.0-77e34fc

2 years ago

6.0.1

2 years ago

6.0.0-1319c61

2 years ago

6.0.0-917a1bc

2 years ago

6.0.0-1ee6a4a

2 years ago

6.0.0-2d965be

2 years ago

6.0.0-7c3ce21

2 years ago

6.0.0-dc2e7a6

2 years ago

6.0.0-28d62f7

2 years ago

6.0.0-7c07e11

2 years ago

6.0.0-a04e041

2 years ago

6.0.0-754c7af

2 years ago

6.0.0-8db7792

2 years ago

6.0.0-31cdfa8

2 years ago

6.0.0-75d0a5b

2 years ago

6.0.0-9b1ddf8

2 years ago

6.0.0-7a7c0c1

2 years ago

6.0.0-3283a5c

2 years ago

6.0.0-f58d467

2 years ago

6.0.0-3851fe2

2 years ago

6.0.0-5c0c39c

2 years ago

6.0.0-6c88ee1

2 years ago

6.0.0-f243de2

2 years ago

6.0.0-8a5bc6f

2 years ago

6.0.0

2 years ago

5.0.0-ca8d5eb

2 years ago

5.0.0-e554493

2 years ago

5.0.0-94b0cd1

2 years ago

5.0.0-44f4e88

2 years ago

5.0.0

2 years ago

4.0.0-99c94f4

2 years ago

4.0.0-4836d52

2 years ago

4.0.0-db7d091

2 years ago

4.0.0-19bf9ce

2 years ago

4.0.0-031519c

2 years ago

4.0.0-4943c5b

2 years ago

4.0.0-f2853f8

2 years ago

4.0.0-163df38

2 years ago

4.0.0-a2229bd

2 years ago

4.0.0-3477b27

2 years ago

4.0.0-a966706

2 years ago

4.0.0-843fba4

2 years ago

4.0.0-ce74026

2 years ago

4.0.0-76220cd

2 years ago

4.0.0-5a87bbd

2 years ago

4.0.0-ece384a

2 years ago

4.0.0-5c6a066

2 years ago

4.0.0-5c4fd54

2 years ago

4.0.0-3f4c6bf

2 years ago

4.0.0-10272b4

2 years ago

4.0.0

2 years ago

4.0.0-a0692f9

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.1

3 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.0

3 years ago