ipfsjs-ipfs

What is the use of key API in IPFS Core APIs?


I am working on a project with JS implementation of IPFS. I want to upload multiple websites. While going through the official documentation of IPFS Core APIs, under example section of ipfs.name.publish I found a line which says "If you want to have multiple websites (for example) under the same IPFS module, you can always check the key API."

I went through the key API but did not understand the purpose of these APIs, what is there usage and how will it help in hosting multiple websites?


Solution

  • With ipfs.name.publish you use the IPNS feature, that maps an identifier (of the form /ipns/...) to a CID. The API allows to update the mapping, such that your IPNS name always points to the latest version of your content/website. As I've detailed here, the IPNS identifier of the form /ipns/... is an encoded version of your public key. Only you, who has the corresponding private key can update the mapping of IPNS to CID.

    If you want to manage multiple websites, each with a separate IPNS identifier, you need multiple private-public-key-pairs. With the key API, you can manage and create additional keys. When you call ipfs.name.publish() you can pass the name of a key as an optional argument. This choice which key you use will define the IPNS identifier and also which mapping/website will be updated.