-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
757 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
dist/ | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# while testing npm5 | ||
package-lock.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
# IPNS | ||
|
||
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai) | ||
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) | ||
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) | ||
[![standard-readme](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) | ||
|
||
> ipns record definitions | ||
This module contains all the necessary code for creating, understanding and validating IPNS records. | ||
|
||
## Lead Maintainer | ||
|
||
[Vasco Santos](https://github.com/vasco-santos). | ||
|
||
## Table of Contents | ||
|
||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [Create Record](#create-record) | ||
- [Validate Record](#validate-record) | ||
- [Embed public key to record](#embed-public-key-to-record) | ||
- [Extract public key from record](#extract-public-key-from-record) | ||
- [Datastore key](#datastore-key) | ||
- [API](#api) | ||
- [Contribute](#contribute) | ||
- [License](#license) | ||
|
||
### Install | ||
|
||
> npm install ipns | ||
## Usage | ||
|
||
#### Create record | ||
|
||
```js | ||
const ipns = require('ipns') | ||
|
||
ipns.create(privateKey, value, sequenceNumber, lifetime, (err, entryData) => { | ||
// your code goes here | ||
}); | ||
``` | ||
|
||
#### Validate record | ||
|
||
```js | ||
const ipns = require('ipns') | ||
|
||
ipns.validate(publicKey, ipnsEntry, (err) => { | ||
// your code goes here | ||
// if no error, the record is valid | ||
}); | ||
``` | ||
|
||
#### Embed public key to record | ||
|
||
> Not available yet | ||
#### Extract public key from record | ||
|
||
> Not available yet | ||
#### Datastore key | ||
|
||
```js | ||
const ipns = require('ipns') | ||
|
||
ipns.getLocalKey(peerId); | ||
``` | ||
|
||
Returns a key to be used for storing the ipns entry locally, that is: | ||
|
||
``` | ||
/ipns/${base32(<HASH>)} | ||
``` | ||
|
||
#### Marshal data with proto buffer | ||
|
||
```js | ||
const ipns = require('ipns') | ||
|
||
ipns.create(privateKey, value, sequenceNumber, lifetime, (err, entryData) => { | ||
// ... | ||
const marshalledData = ipns.marshal(entryData) | ||
// ... | ||
}); | ||
``` | ||
|
||
Returns the entry data serialized. | ||
|
||
#### Unmarshal data from proto buffer | ||
|
||
```js | ||
const ipns = require('ipns') | ||
|
||
const data = ipns.unmarshal(storedData) | ||
``` | ||
|
||
Returns the entry data structure after being serialized. | ||
|
||
## API | ||
|
||
#### Create record | ||
|
||
```js | ||
|
||
ipns.create(privateKey, value, sequenceNumber, lifetime, [callback]); | ||
``` | ||
|
||
Create an IPNS record for being stored in a protocol buffer. | ||
|
||
- `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. | ||
- `value` (string): ipfs path of the object to be published. | ||
- `sequenceNumber` (Number): number representing the current version of the record. | ||
- `lifetime` (string): lifetime of the record (in milliseconds). | ||
- `callback` (function): operation result. | ||
|
||
`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: | ||
|
||
```js | ||
{ | ||
value: '/ipfs/QmWEekX7EZLUd9VXRNMRXW3LXe4F6x7mB8oPxY5XLptrBq', | ||
signature: Buffer, | ||
validityType: 0, | ||
validity: '2018-06-27T14:49:14.074000000Z', | ||
sequence: 2 | ||
} | ||
``` | ||
|
||
#### Validate record | ||
|
||
```js | ||
|
||
ipns.validate(publicKey, ipnsEntry, [callback]); | ||
``` | ||
|
||
Validate an IPNS record previously stored in a protocol buffer. | ||
|
||
- `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. | ||
- `ipnsEntry` (Object): ipns entry record (obtained using the create function). | ||
- `callback` (function): operation result. | ||
|
||
`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. | ||
|
||
#### Datastore key | ||
|
||
```js | ||
ipns.getDatastoreKey(peerId); | ||
``` | ||
|
||
Get a key for storing the ipns entry in the datastore. | ||
|
||
- `peerId` (`Uint8Array`): peer identifier. | ||
|
||
#### Marshal data with proto buffer | ||
|
||
```js | ||
const marshalledData = ipns.marshal(entryData) | ||
}); | ||
``` | ||
|
||
Returns the entry data serialized. | ||
|
||
- `entryData` (Object): ipns entry record (obtained using the create function). | ||
|
||
#### Unmarshal data from proto buffer | ||
|
||
```js | ||
const data = ipns.unmarshal(storedData) | ||
``` | ||
|
||
Returns the entry data structure after being serialized. | ||
|
||
- `storedData` (Buffer): ipns entry record serialized. | ||
|
||
## Contribute | ||
|
||
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipns/issues)! | ||
|
||
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). | ||
|
||
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md) | ||
|
||
## License | ||
|
||
Copyright (c) Protocol Labs, Inc. under the **MIT**. See [MIT](./LICENSE) for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. | ||
javascript() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "ipns", | ||
"version": "0.1.0", | ||
"description": "ipns record definitions", | ||
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"build": "aegir build", | ||
"lint": "aegir lint", | ||
"release": "aegir release", | ||
"release-minor": "aegir release --type minor", | ||
"release-major": "aegir release --type major", | ||
"test": "aegir test", | ||
"test:browser": "aegir test -t browser -t webworker", | ||
"test:node": "aegir test -t node" | ||
}, | ||
"pre-push": [ | ||
"lint", | ||
"test" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ipfs/js-ipns.git" | ||
}, | ||
"keywords": [ | ||
"ipfs", | ||
"ipns" | ||
], | ||
"author": "Vasco Santos <vasco.santos@moxy.studio>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ipfs/js-ipns/issues" | ||
}, | ||
"homepage": "https://github.com/ipfs/js-ipns#readme", | ||
"dependencies": { | ||
"base32-encode": "^1.1.0", | ||
"big.js": "^5.1.2", | ||
"debug": "^3.1.0", | ||
"left-pad": "^1.3.0", | ||
"nano-date": "^2.1.0", | ||
"protons": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^13.1.0", | ||
"chai": "^4.1.2", | ||
"chai-bytes": "^0.1.1", | ||
"chai-string": "^1.4.0", | ||
"dirty-chai": "^2.0.1", | ||
"ipfs": "^0.29.3", | ||
"ipfsd-ctl": "^0.36.0", | ||
"libp2p-crypto": "^0.13.0", | ||
"multihashes": "^0.4.13" | ||
}, | ||
"contributors": [ | ||
"Vasco Santos <vasco.santos@moxy.studio>" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
exports.ERR_IPNS_EXPIRED_RECORD = 'ERR_IPNS_EXPIRED_RECORD' | ||
exports.ERR_UNRECOGNIZED_VALIDITY = 'ERR_UNRECOGNIZED_VALIDITY' | ||
exports.ERR_SIGNATURE_CREATION = 'ERR_SIGNATURE_CREATION' | ||
exports.ERR_SIGNATURE_VERIFICATION = 'ERR_SIGNATURE_VERIFICATION' | ||
exports.ERR_UNRECOGNIZED_FORMAT = 'ERR_UNRECOGNIZED_FORMAT' |
Oops, something went wrong.