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

Commit 03255a9

Browse files
authored
Merge pull request #17 from dappnode/v0.1.5
Decode IPFS contenthash using CID and multihash libraries
2 parents 20c008b + 694a835 commit 03255a9

6 files changed

Lines changed: 50 additions & 9 deletions

File tree

build/src/package-lock.json

Lines changed: 37 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/src/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"license": "GPL-3.0",
1515
"dependencies": {
1616
"bs58": "^4.0.1",
17+
"cids": "^0.5.7",
1718
"dotenv": "^5.0.1",
1819
"http-proxy": "^1.17.0",
1920
"multicodec": "^0.4.0",

build/src/src/ens.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Web3 = require('web3');
2+
const CID = require('cids');
23
const multihash = require('multihashes');
34
const multicodec = require('multicodec');
45

@@ -77,8 +78,12 @@ exports.getContent = async (name) => {
7778
if(contenthash !== '0x'){
7879
const contentHashEncoded = Buffer.from(contenthash.slice(2),'hex');
7980
console.log('content codec: ' + multicodec.getCodec(contentHashEncoded))
80-
content = multicodec.getCodec(contentHashEncoded).startsWith('ipfs') ? '/ipfs/' + multicodec.rmPrefix(contentHashEncoded) : null
81-
console.log('content decoded: ' + content)
81+
let value = multicodec.getCodec(contentHashEncoded).startsWith('ipfs') ? multicodec.rmPrefix(contentHashEncoded) : null
82+
if(value){
83+
let cid = new CID(value);
84+
content = '/ipfs/' + multihash.toB58String(cid.multihash)
85+
console.log('content decoded: ' + content)
86+
}
8287
break
8388
}
8489
/* this part is deprecated, it is maintained to preserve compatibility */

build/src/test/ens.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ describe('ens', () => {
3030
assert.equal(content, '/ipfs/QmSpuwejUGjREmgsvm8eq3ZdsS7mVTHCRPZmLiUq84S9x8');
3131
}).timeout(timeout);
3232

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

3838
})

dappnode_package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethforward.dnp.dappnode.eth",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "Dappnode package responsible for providing .eth address resolve through ENS",
55
"avatar": "/ipfs/QmX2VK8wUfUfXetnCbYqhR6hwLV8W6XLcxRBRFWZhNq1tN",
66
"type": "dncore",

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ networks:
99
services:
1010
ethforward.dnp.dappnode.eth:
1111
build: ./build
12-
image: 'ethforward.dnp.dappnode.eth:0.1.4'
12+
image: 'ethforward.dnp.dappnode.eth:0.1.5'
1313
container_name: DAppNodeCore-ethforward.dnp.dappnode.eth
1414
restart: always
1515
dns: 172.33.1.2

0 commit comments

Comments
 (0)