Skip to content

Commit b8eb65f

Browse files
authored
feat: initial implementation
* feat: initial implementation
1 parent 2b6a7fe commit b8eb65f

10 files changed

+757
-6
lines changed

.gitignore

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
dist/
2+
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
*.pid.lock
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# nyc test coverage
23+
.nyc_output
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# Bower dependency directory (https://bower.io/)
29+
bower_components
30+
31+
# node-waf configuration
32+
.lock-wscript
33+
34+
# Compiled binary addons (http://nodejs.org/api/addons.html)
35+
build/Release
36+
37+
# Dependency directories
38+
node_modules/
39+
jspm_packages/
40+
41+
# Typescript v1 declaration files
42+
typings/
43+
44+
# Optional npm cache directory
45+
.npm
46+
47+
# Optional eslint cache
48+
.eslintcache
49+
50+
# Optional REPL history
51+
.node_repl_history
52+
53+
# Output of 'npm pack'
54+
*.tgz
55+
56+
# Yarn Integrity file
57+
.yarn-integrity
58+
59+
# dotenv environment variables file
60+
.env
61+
62+
# while testing npm5
63+
package-lock.json
64+
yarn.lock

LICENSE

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2018 IPFS
3+
Copyright (c) 2018 Protocol Labs, Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# IPNS
2+
3+
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
4+
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
5+
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
6+
[![standard-readme](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
7+
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](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://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](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.

ci/Jenkinsfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// 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.
2+
javascript()

package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "ipns",
3+
"version": "0.1.0",
4+
"description": "ipns record definitions",
5+
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>",
6+
"main": "src/index.js",
7+
"scripts": {
8+
"build": "aegir build",
9+
"lint": "aegir lint",
10+
"release": "aegir release",
11+
"release-minor": "aegir release --type minor",
12+
"release-major": "aegir release --type major",
13+
"test": "aegir test",
14+
"test:browser": "aegir test -t browser -t webworker",
15+
"test:node": "aegir test -t node"
16+
},
17+
"pre-push": [
18+
"lint",
19+
"test"
20+
],
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/ipfs/js-ipns.git"
24+
},
25+
"keywords": [
26+
"ipfs",
27+
"ipns"
28+
],
29+
"author": "Vasco Santos <vasco.santos@moxy.studio>",
30+
"license": "MIT",
31+
"bugs": {
32+
"url": "https://github.com/ipfs/js-ipns/issues"
33+
},
34+
"homepage": "https://github.com/ipfs/js-ipns#readme",
35+
"dependencies": {
36+
"base32-encode": "^1.1.0",
37+
"big.js": "^5.1.2",
38+
"debug": "^3.1.0",
39+
"left-pad": "^1.3.0",
40+
"nano-date": "^2.1.0",
41+
"protons": "^1.0.1"
42+
},
43+
"devDependencies": {
44+
"aegir": "^13.1.0",
45+
"chai": "^4.1.2",
46+
"chai-bytes": "^0.1.1",
47+
"chai-string": "^1.4.0",
48+
"dirty-chai": "^2.0.1",
49+
"ipfs": "^0.29.3",
50+
"ipfsd-ctl": "^0.36.0",
51+
"libp2p-crypto": "^0.13.0",
52+
"multihashes": "^0.4.13"
53+
},
54+
"contributors": [
55+
"Vasco Santos <vasco.santos@moxy.studio>"
56+
]
57+
}

src/errors.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
exports.ERR_IPNS_EXPIRED_RECORD = 'ERR_IPNS_EXPIRED_RECORD'
4+
exports.ERR_UNRECOGNIZED_VALIDITY = 'ERR_UNRECOGNIZED_VALIDITY'
5+
exports.ERR_SIGNATURE_CREATION = 'ERR_SIGNATURE_CREATION'
6+
exports.ERR_SIGNATURE_VERIFICATION = 'ERR_SIGNATURE_VERIFICATION'
7+
exports.ERR_UNRECOGNIZED_FORMAT = 'ERR_UNRECOGNIZED_FORMAT'

0 commit comments

Comments
 (0)