Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #17 from dappnode/v0.1.5
Browse files Browse the repository at this point in the history
Decode IPFS contenthash using CID and multihash libraries
  • Loading branch information
eduadiez committed Feb 6, 2019
2 parents 20c008b + 694a835 commit 03255a9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
39 changes: 37 additions & 2 deletions build/src/package-lock.json

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

1 change: 1 addition & 0 deletions build/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"license": "GPL-3.0",
"dependencies": {
"bs58": "^4.0.1",
"cids": "^0.5.7",
"dotenv": "^5.0.1",
"http-proxy": "^1.17.0",
"multicodec": "^0.4.0",
Expand Down
9 changes: 7 additions & 2 deletions build/src/src/ens.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Web3 = require('web3');
const CID = require('cids');
const multihash = require('multihashes');
const multicodec = require('multicodec');

Expand Down Expand Up @@ -77,8 +78,12 @@ exports.getContent = async (name) => {
if(contenthash !== '0x'){
const contentHashEncoded = Buffer.from(contenthash.slice(2),'hex');
console.log('content codec: ' + multicodec.getCodec(contentHashEncoded))
content = multicodec.getCodec(contentHashEncoded).startsWith('ipfs') ? '/ipfs/' + multicodec.rmPrefix(contentHashEncoded) : null
console.log('content decoded: ' + content)
let value = multicodec.getCodec(contentHashEncoded).startsWith('ipfs') ? multicodec.rmPrefix(contentHashEncoded) : null
if(value){
let cid = new CID(value);
content = '/ipfs/' + multihash.toB58String(cid.multihash)
console.log('content decoded: ' + content)
}
break
}
/* this part is deprecated, it is maintained to preserve compatibility */
Expand Down
6 changes: 3 additions & 3 deletions build/src/test/ens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe('ens', () => {
assert.equal(content, '/ipfs/QmSpuwejUGjREmgsvm8eq3ZdsS7mVTHCRPZmLiUq84S9x8');
}).timeout(timeout);

it('should return the IPFS hash of eduadiez.eth', async () => {
const content = await ens.getContent('eduadiez.eth');
assert.equal(content, '/ipfs/QmYCMDy9fCwbxQ1sHtUG318AMunHGcfUGeuAKYvHvGyEd4');
it('should return the IPFS hash of eth2dai.eduadiez.eth', async () => {
const content = await ens.getContent('eth2dai.eduadiez.eth');
assert.equal(content, '/ipfs/QmZoHo1wi4G9VHX6xLmMBRdFpdHMkHnsqVXqV6Vsng9m8j');
}).timeout(timeout);

})
Expand Down
2 changes: 1 addition & 1 deletion dappnode_package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethforward.dnp.dappnode.eth",
"version": "0.1.4",
"version": "0.1.5",
"description": "Dappnode package responsible for providing .eth address resolve through ENS",
"avatar": "/ipfs/QmX2VK8wUfUfXetnCbYqhR6hwLV8W6XLcxRBRFWZhNq1tN",
"type": "dncore",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ networks:
services:
ethforward.dnp.dappnode.eth:
build: ./build
image: 'ethforward.dnp.dappnode.eth:0.1.4'
image: 'ethforward.dnp.dappnode.eth:0.1.5'
container_name: DAppNodeCore-ethforward.dnp.dappnode.eth
restart: always
dns: 172.33.1.2
Expand Down

0 comments on commit 03255a9

Please sign in to comment.