Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial implementation #1

Merged
merged 4 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .gitignore
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
129 changes: 129 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# ipns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be all uppercase, no?


[![](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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

const ipns = require('ipns')


ipns.create(privateKey, value, seqNumber, eol, (err, entryData) => {
// your code goes here
});
```

#### Validate record

```js
const ipns = require('./ipns')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as prev comment.


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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.


ipns.getDatastoreKey(peerId);
```

Returns a key to be used for storing the ipns entry in the datastore according to the specs, that is:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please link to specs you're referring to or reword...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have to reword by now! I still didn't create the PR with specs.


```
/ipns/${base32(<HASH>)}
```

## API

#### Create record

```js

ipns.create(privateKey, value, sequenceNumber, eol, callback);
```

Create an IPNS record for being stored in a protocol buffer.

- `privateKey` (`PrivKey` RSA Instance): key to be used for cryptographic operations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A link the module that would provide this instance would be useful here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! I agree that it is useful here. Will add it

- `value` (string): ipfs path of the object to be published.
- `sequenceNumber` (Number): sequence number of the record.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind expanding on this description please?

- `eol` (string): end of life datetime of the record (according to RFC3339).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a Date instance?...oh wait I think the docs are wrong here this needs to be a date as you're calling toISOString on it in create (https://github.com/ipfs/js-ipns/pull/1/files#diff-1fdf421c05c1140f6d71444ea2b27638R23).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add link to RFC?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it easier to pass a TTL? DNS records use TTL, so it'll be familiar to developers - and this is what seems to be stored in the protobuf...

Copy link
Member Author

@vasco-santos vasco-santos Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you understood, eol was standing for a date in the last origin commit. Currently, I have a new approach in here.

Basically, I think that this function should receive a lifetime of the record and it should be responsible for calculating the appropriate validity of the record (RFC3339 with nanoseconds precision). And I consider this to be the best approach, as a consequence of the ipns entry requirement of the RFC, which does not allow the usage of the native date.

I didn't go with the ttl parameter instead of lifetime/ validity because the ttl parameter will also be used in the IPNS for caching purposes, as you can see here

EDIT: I will try to update this PR today with this new approach

- `callback` (function): operation result.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs documentation about the shape or class of the object that is returned, it's methods and properties.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, still says (string) here, should it be a number now?


#### Create record
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This title should read #### Validate record


```js

ipns.validate(publicKey, ipnsEntry, callback);
```

Create an IPNS record for being stored in a protocol buffer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong description


- `publicKey` (`PubKey` RSA Instance): key to be used for cryptographic operations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A link the module that would provide this instance would be useful here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as before 🙂

- `ipnsEntry` (Object): ipns entry record (obtained using the create function).
- `callback` (function): operation result (if no error, validation successful).

#### Datastore key

```js
ipns.getDatastoreKey(peerId);
```

Get a key for storing the ipns entry in the datastore.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't feel like it belongs here...shouldn't it be something that the datastore determines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, maybe the name was not the best one. For ipns there are two different ways of storing records (which can be used together), store locally, and store using routing.
In addition, the local store is being used with datastore now, but it should also be compatible with any other key-value store.

Therefore, I will change this name to getLocalKey, which I think that suits better here. What do you think?


- `peerId` (`Uint8Array`): peer identifier.

## 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

[MIT](LICENSE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind updating this to fit with the IPFS licensing policy? That should just be a slight tweak to this line in the README to add a little info and updating the LICENSE file to make sure copyright is assigned to “Protocol Labs, Inc.” instead of “IPFS” (which is not an entity copyright can be assigned to).

2 changes: 2 additions & 0 deletions ci/Jenkinsfile
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()
53 changes: 53 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "ipns",
"version": "0.1.0",
"description": "ipns record definitions",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there going to more than just record stuff in here? If not would it be better named ipns-record?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with you! It has been discussed here, but there is no agreement yet!

It is js-ipns for now to be coherent with go-ipns.

"leadMaintainer": "Vasco Santos <[email protected]>",
"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 <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ipfs/js-ipns/issues"
},
"homepage": "https://github.com/ipfs/js-ipns#readme",
"dependencies": {
"base32-encode": "^1.0.0",
"debug": "^3.1.0",
"protons": "^1.0.1"
},
"devDependencies": {
"aegir": "^13.1.0",
"chai": "^4.1.2",
"chai-string": "^1.4.0",
"dirty-chai": "^2.0.1",
"ipfs": "^0.28.2",
"ipfsd-ctl": "^0.36.0",
"libp2p-crypto": "^0.13.0",
"multihashes": "^0.4.13"
},
"contributors": [
"Vasco Santos <[email protected]>"
]
}
5 changes: 5 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

exports.ERR_IPNS_EXPIRED_RECORD = 'ERR_IPNS_EXPIRED_RECORD'
exports.ERR_UNRECOGNIZED_VALIDITY = 'ERR_UNRECOGNIZED_VALIDITY'
exports.ERR_SIGNATURE_VERIFICATION = 'ERR_SIGNATURE_VERIFICATION'
Loading