aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/ens-ipfs/resolver.js
diff options
context:
space:
mode:
authorpldespaigne <pldespaigne@cascade8.com>2019-04-04 23:15:57 +0800
committerpldespaigne <pldespaigne@cascade8.com>2019-04-04 23:15:57 +0800
commitdc4c40414e6fb76d3c56aa771752dd6ade61c280 (patch)
treee98da4985ed226b05103a66def82fff7f38167e0 /app/scripts/lib/ens-ipfs/resolver.js
parentb26a59dbbe2666640529f7ae0a86bd5a2da3f607 (diff)
downloadtangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.tar
tangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.tar.gz
tangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.tar.bz2
tangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.tar.lz
tangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.tar.xz
tangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.tar.zst
tangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.zip
issue#5742
Diffstat (limited to 'app/scripts/lib/ens-ipfs/resolver.js')
-rw-r--r--app/scripts/lib/ens-ipfs/resolver.js30
1 files changed, 20 insertions, 10 deletions
diff --git a/app/scripts/lib/ens-ipfs/resolver.js b/app/scripts/lib/ens-ipfs/resolver.js
index 18f7704c3..3f0fb00a2 100644
--- a/app/scripts/lib/ens-ipfs/resolver.js
+++ b/app/scripts/lib/ens-ipfs/resolver.js
@@ -1,9 +1,9 @@
const namehash = require('eth-ens-namehash')
-const multihash = require('multihashes')
const Eth = require('ethjs-query')
const EthContract = require('ethjs-contract')
const registryAbi = require('./contracts/registry')
const resolverAbi = require('./contracts/resolver')
+const contentHash = require('content-hash')
module.exports = resolveEnsToIpfsContentId
@@ -26,16 +26,26 @@ async function resolveEnsToIpfsContentId ({ provider, name }) {
throw new Error(`EnsIpfsResolver - no resolver found for name "${name}"`)
}
const Resolver = contract(resolverAbi).at(resolverAddress)
- // lookup content id
- const contentLookupResult = await Resolver.content(hash)
- const contentHash = contentLookupResult[0]
- if (hexValueIsEmpty(contentHash)) {
- throw new Error(`EnsIpfsResolver - no content ID found for name "${name}"`)
+
+ const isEIP1577Compliant = await Resolver.supportsInterface('0xbc1c58d1')
+ const isLegacyResolver = await Resolver.supportsInterface('0xd8389dc5')
+ if (isEIP1577Compliant[0]) {
+ const contentLookupResult = await Resolver.contenthash(hash)
+ const rawContentHash = contentLookupResult[0]
+ const decodedContentHash = contentHash.decode(rawContentHash)
+ const type = contentHash.getCodec(rawContentHash)
+ return {type: type, hash: decodedContentHash}
+ }
+ if (isLegacyResolver[0]) {
+ // lookup content id
+ const contentLookupResult = await Resolver.content(hash)
+ const content = contentLookupResult[0]
+ if (hexValueIsEmpty(content)) {
+ throw new Error(`EnsIpfsResolver - no content ID found for name "${name}"`)
+ }
+ return {type: 'swarm-ns', hash: content.slice(2)}
}
- const nonPrefixedHex = contentHash.slice(2)
- const buffer = multihash.fromHexString(nonPrefixedHex)
- const contentId = multihash.toB58String(multihash.encode(buffer, 'sha2-256'))
- return contentId
+ throw new Error(`EnsIpfsResolver - the resolver for name "${name}" is not standard, it should either supports contenthash() or content()`)
}
function hexValueIsEmpty (value) {