aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/ens-ipfs/resolver.js
diff options
context:
space:
mode:
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) {