-
Notifications
You must be signed in to change notification settings - Fork 110
Upgrade guide from Helia 4.0.0 to Helia 5.0.0
Please see the release notes for the full run-down of all the new features and bug fixes in helia@5.x.x
.
The main feature of helia@5.x.x
is the upgrade to libp2p@2.x.x
. There may be nothing for you to do here, it depends on which parts of the libp2p API your application uses.
Please see the libp2p@2.x.x migration guide for any changes that will be necessary.
You should upgrade all @libp2p/*
modules along with libp2p
to the latest releases and not upgrading them piecemeal.
The @helia/ipns
module is used to publish and resolve IPNS names.
Each IPNS record is signed by a private key that should be stored somewhere secure in order to later publish updates to that record.
The @libp2p/keychain module is one such location, it will store your keys encrypted at rest.
The keychain module used to use @libp2p/peer-id instances as a convenient way to export private keys from the keychain, as they had an optional .privateKey
property that could be used to store the private key.
As of libp2p@2.x.x
the keychain module returns PrivateKey
instances from the @libp2p/crypto
module instead and no longer works with PeerId
instances.
Consequently the @helia/ipns
interface has also changed to accept PrivateKey
instances instead of PeerId
s which removes a layer of indirection and makes it clearer what is actually being used.
Before
import { createHelia } from 'helia'
import { ipns } from '@helia/ipns'
import { unixfs } from '@helia/unixfs'
const helia = await createHelia()
const name = ipns(helia)
// create a public key to publish as an IPNS name
const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
// store some data to publish
const fs = unixfs(helia)
const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
// publish the name
await name.publish(peerId, cid)
// resolve the name
const result = name.resolve(peerId)
console.info(result.cid, result.path)
After
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)