|
| 1 | +# IPNS |
| 2 | + |
| 3 | +[](http://protocol.ai) |
| 4 | +[](http://ipfs.io/) |
| 5 | +[](http://webchat.freenode.net/?channels=%23ipfs) |
| 6 | +[](https://github.com/RichardLitt/standard-readme) |
| 7 | +[](https://github.com/feross/standard) |
| 8 | + |
| 9 | +> ipns record definitions |
| 10 | +
|
| 11 | +This module contains all the necessary code for creating, understanding and validating IPNS records. |
| 12 | + |
| 13 | +## Lead Maintainer |
| 14 | + |
| 15 | +[Vasco Santos](https://github.com/vasco-santos). |
| 16 | + |
| 17 | +## Table of Contents |
| 18 | + |
| 19 | +- [Install](#install) |
| 20 | +- [Usage](#usage) |
| 21 | + - [Create Record](#create-record) |
| 22 | + - [Validate Record](#validate-record) |
| 23 | + - [Embed public key to record](#embed-public-key-to-record) |
| 24 | + - [Extract public key from record](#extract-public-key-from-record) |
| 25 | + - [Datastore key](#datastore-key) |
| 26 | +- [API](#api) |
| 27 | +- [Contribute](#contribute) |
| 28 | +- [License](#license) |
| 29 | + |
| 30 | +### Install |
| 31 | + |
| 32 | +> npm install ipns |
| 33 | +
|
| 34 | +## Usage |
| 35 | + |
| 36 | +#### Create record |
| 37 | + |
| 38 | +```js |
| 39 | +const ipns = require('ipns') |
| 40 | + |
| 41 | +ipns.create(privateKey, value, sequenceNumber, lifetime, (err, entryData) => { |
| 42 | + // your code goes here |
| 43 | +}); |
| 44 | +``` |
| 45 | + |
| 46 | +#### Validate record |
| 47 | + |
| 48 | +```js |
| 49 | +const ipns = require('ipns') |
| 50 | + |
| 51 | +ipns.validate(publicKey, ipnsEntry, (err) => { |
| 52 | + // your code goes here |
| 53 | + // if no error, the record is valid |
| 54 | +}); |
| 55 | +``` |
| 56 | + |
| 57 | +#### Embed public key to record |
| 58 | + |
| 59 | +> Not available yet |
| 60 | +
|
| 61 | +#### Extract public key from record |
| 62 | + |
| 63 | +> Not available yet |
| 64 | +
|
| 65 | +#### Datastore key |
| 66 | + |
| 67 | +```js |
| 68 | +const ipns = require('ipns') |
| 69 | + |
| 70 | +ipns.getLocalKey(peerId); |
| 71 | +``` |
| 72 | + |
| 73 | +Returns a key to be used for storing the ipns entry locally, that is: |
| 74 | + |
| 75 | +``` |
| 76 | +/ipns/${base32(<HASH>)} |
| 77 | +``` |
| 78 | + |
| 79 | +#### Marshal data with proto buffer |
| 80 | + |
| 81 | +```js |
| 82 | +const ipns = require('ipns') |
| 83 | + |
| 84 | +ipns.create(privateKey, value, sequenceNumber, lifetime, (err, entryData) => { |
| 85 | + // ... |
| 86 | + const marshalledData = ipns.marshal(entryData) |
| 87 | + // ... |
| 88 | +}); |
| 89 | +``` |
| 90 | + |
| 91 | +Returns the entry data serialized. |
| 92 | + |
| 93 | +#### Unmarshal data from proto buffer |
| 94 | + |
| 95 | +```js |
| 96 | +const ipns = require('ipns') |
| 97 | + |
| 98 | +const data = ipns.unmarshal(storedData) |
| 99 | +``` |
| 100 | + |
| 101 | +Returns the entry data structure after being serialized. |
| 102 | + |
| 103 | +## API |
| 104 | + |
| 105 | +#### Create record |
| 106 | + |
| 107 | +```js |
| 108 | + |
| 109 | +ipns.create(privateKey, value, sequenceNumber, lifetime, [callback]); |
| 110 | +``` |
| 111 | + |
| 112 | +Create an IPNS record for being stored in a protocol buffer. |
| 113 | + |
| 114 | +- `privateKey` (`PrivKey` [RSA Instance](https://github.com/libp2p/js-libp2p-crypto/blob/master/src/keys/rsa-class.js)): key to be used for cryptographic operations. |
| 115 | +- `value` (string): ipfs path of the object to be published. |
| 116 | +- `sequenceNumber` (Number): number representing the current version of the record. |
| 117 | +- `lifetime` (string): lifetime of the record (in milliseconds). |
| 118 | +- `callback` (function): operation result. |
| 119 | + |
| 120 | +`callback` must follow `function (err, ipnsEntry) {}` signature, where `err` is an error if the operation was not successful. `ipnsEntry` is an object that contains the entry's properties, such as: |
| 121 | + |
| 122 | +```js |
| 123 | +{ |
| 124 | + value: '/ipfs/QmWEekX7EZLUd9VXRNMRXW3LXe4F6x7mB8oPxY5XLptrBq', |
| 125 | + signature: Buffer, |
| 126 | + validityType: 0, |
| 127 | + validity: '2018-06-27T14:49:14.074000000Z', |
| 128 | + sequence: 2 |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +#### Validate record |
| 133 | + |
| 134 | +```js |
| 135 | + |
| 136 | +ipns.validate(publicKey, ipnsEntry, [callback]); |
| 137 | +``` |
| 138 | + |
| 139 | +Validate an IPNS record previously stored in a protocol buffer. |
| 140 | + |
| 141 | +- `publicKey` (`PubKey` [RSA Instance](https://github.com/libp2p/js-libp2p-crypto/blob/master/src/keys/rsa-class.js)): key to be used for cryptographic operations. |
| 142 | +- `ipnsEntry` (Object): ipns entry record (obtained using the create function). |
| 143 | +- `callback` (function): operation result. |
| 144 | + |
| 145 | +`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful. This way, if no error, the validation was successful. |
| 146 | + |
| 147 | +#### Datastore key |
| 148 | + |
| 149 | +```js |
| 150 | +ipns.getDatastoreKey(peerId); |
| 151 | +``` |
| 152 | + |
| 153 | +Get a key for storing the ipns entry in the datastore. |
| 154 | + |
| 155 | +- `peerId` (`Uint8Array`): peer identifier. |
| 156 | + |
| 157 | +#### Marshal data with proto buffer |
| 158 | + |
| 159 | +```js |
| 160 | +const marshalledData = ipns.marshal(entryData) |
| 161 | +}); |
| 162 | +``` |
| 163 | + |
| 164 | +Returns the entry data serialized. |
| 165 | + |
| 166 | +- `entryData` (Object): ipns entry record (obtained using the create function). |
| 167 | + |
| 168 | +#### Unmarshal data from proto buffer |
| 169 | + |
| 170 | +```js |
| 171 | +const data = ipns.unmarshal(storedData) |
| 172 | +``` |
| 173 | + |
| 174 | +Returns the entry data structure after being serialized. |
| 175 | + |
| 176 | +- `storedData` (Buffer): ipns entry record serialized. |
| 177 | + |
| 178 | +## Contribute |
| 179 | + |
| 180 | +Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipns/issues)! |
| 181 | + |
| 182 | +This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). |
| 183 | + |
| 184 | +[](https://github.com/ipfs/community/blob/master/contributing.md) |
| 185 | + |
| 186 | +## License |
| 187 | + |
| 188 | +Copyright (c) Protocol Labs, Inc. under the **MIT**. See [MIT](./LICENSE) for details. |
0 commit comments