Skip to content

Commit

Permalink
add ipns and coresponding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pldespaigne committed Jul 16, 2019
1 parent 97caf9d commit 39c2628
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
11 changes: 9 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3362,6 +3362,7 @@ exports['path'] = Buffer.from('2f', 'hex')
exports['ipld-ns'] = Buffer.from('e2', 'hex')
exports['ipfs-ns'] = Buffer.from('e3', 'hex')
exports['swarm-ns'] = Buffer.from('e4', 'hex')
exports['ipns-ns'] = Buffer.from('e5', 'hex')

// key
exports['ed25519-pub'] = Buffer.from('ed', 'hex')
Expand Down Expand Up @@ -3808,6 +3809,7 @@ module.exports = Object.freeze({
IPLD_NS: 0xe2,
IPFS_NS: 0xe3,
SWARM_NS: 0xe4,
IPNS_NS: 0xe5,

// key
ED25519_PUB: 0xed,
Expand Down Expand Up @@ -4397,6 +4399,7 @@ module.exports = Object.freeze({
0xe2: 'ipld-ns',
0xe3: 'ipfs-ns',
0xe4: 'swarm-ns',
0xe5: 'ipns-ns',

// key
0xed: 'ed25519-pub',
Expand Down Expand Up @@ -5878,7 +5881,7 @@ module.exports = function (value) {
},{}],30:[function(require,module,exports){
module.exports={
"name": "content-hash",
"version": "2.4.0",
"version": "2.4.1",
"next-release": "patch",
"description": "simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers",
"main": "index.js",
Expand All @@ -5897,7 +5900,7 @@ module.exports={
"license": "ISC",
"dependencies": {
"cids": "^0.6.0",
"multicodec": "^0.5.3",
"multicodec": "^0.5.4",
"multihashes": "^0.4.15"
},
"devDependencies": {
Expand Down Expand Up @@ -6125,6 +6128,10 @@ const profiles = {
encode: encodes.ipfs,
decode: decodes.b58MultiHash,
},
'ipns-ns': {
encode: encodes.ipfs,
decode: decodes.b58MultiHash,
},
'onion': {
encode: encodes.utf8,
decode: decodes.utf8,
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "ISC",
"dependencies": {
"cids": "^0.6.0",
"multicodec": "^0.5.3",
"multicodec": "^0.5.4",
"multihashes": "^0.4.15"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions src/profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ const profiles = {
encode: encodes.ipfs,
decode: decodes.b58MultiHash,
},
'ipns-ns': {
encode: encodes.ipfs,
decode: decodes.b58MultiHash,
},
'onion': {
encode: encodes.utf8,
decode: decodes.utf8,
Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const contentHash = require('../src/index.js')

const ipfs = 'QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4'
const ipfs_contentHash = 'e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f'
const ipns_contentHash = 'e5010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f'
const swarm = 'd1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'
const swarm_contentHash = 'e40101fa011b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'
const onion = 'zqktlwi4fecvo6ri'
Expand Down Expand Up @@ -81,6 +82,20 @@ describe('content-hash', () => {
actual.should.be.equal(ipfs);
});
});
describe('ipns', () => {
it('should encode', () => {
const actual = contentHash.encode('ipns-ns', ipfs); // ipns & ipfs are the same hash and same encoding, only codec differ
actual.should.be.equal(ipns_contentHash);
});
it('should getCodec', () => {
const actual = contentHash.getCodec(ipns_contentHash);
actual.should.be.equal('ipns-ns');
});
it('should decode', () => {
const actual = contentHash.decode(ipns_contentHash);
actual.should.be.equal(ipfs); // ipns & ipfs are the same hash and same encoding, only codec differ
});
});
describe('onion', () => {
it('should encode', () => {
const actual = contentHash.encode('onion', onion);
Expand Down

0 comments on commit 39c2628

Please sign in to comment.