Support IPNS address translations (#8502)

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

Co-authored-by: Whymarrh Whitby <whymarrh.whitby@gmail.com>
feature/default_network_editable
Henrique Dias 5 years ago committed by GitHub
parent 095eeab881
commit 890bc25e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      app/scripts/controllers/preferences.js
  3. 2
      app/scripts/lib/ens-ipfs/resolver.js
  4. 4
      app/scripts/lib/ens-ipfs/setup.js
  5. 28
      app/scripts/migrations/045.js
  6. 1
      app/scripts/migrations/index.js
  7. 92
      test/unit/migrations/045-test.js

@ -3,6 +3,7 @@
## Current Develop Branch
- [#7912](https://github.com/MetaMask/metamask-extension/pull/7912): Disable import button for empty string/file
- [#8246](https://github.com/MetaMask/metamask-extension/pull/8246): Make seed phrase import case-insensitive
- [#8502](https://github.com/MetaMask/metamask-extension/pull/8502): Add support for IPFS address resolution
## 7.7.0 Thu Nov 28 2019
- [#7004](https://github.com/MetaMask/metamask-extension/pull/7004): Connect distinct accounts per site

@ -61,7 +61,7 @@ export default class PreferencesController {
metaMetricsSendCount: 0,
// ENS decentralized website resolution
ipfsGateway: 'ipfs.dweb.link',
ipfsGateway: 'dweb.link',
}, opts.initState)
this.diagnostics = opts.diagnostics

@ -32,7 +32,7 @@ export default async function resolveEnsToIpfsContentId ({ provider, name }) {
let decodedContentHash = contentHash.decode(rawContentHash)
const type = contentHash.getCodec(rawContentHash)
if (type === 'ipfs-ns') {
if (type === 'ipfs-ns' || type === 'ipns-ns') {
decodedContentHash = contentHash.helpers.cidV0ToV1Base32(decodedContentHash)
}

@ -44,8 +44,8 @@ export default function setupEnsIpfsResolver ({ provider, getCurrentNetwork, get
let url = `https://app.ens.domains/name/${name}`
try {
const { type, hash } = await resolveEnsToIpfsContentId({ provider, name })
if (type === 'ipfs-ns') {
const resolvedUrl = `https://${hash}.${ipfsGateway}${path}${search || ''}${fragment || ''}`
if (type === 'ipfs-ns' || type === 'ipns-ns') {
const resolvedUrl = `https://${hash}.${type.slice(0, 4)}.${ipfsGateway}${path}${search || ''}${fragment || ''}`
try {
// check if ipfs gateway has result
const response = await window.fetch(resolvedUrl, { method: 'HEAD' })

@ -0,0 +1,28 @@
const version = 45
import { cloneDeep } from 'lodash'
/**
* Replaces {@code PreferencesController.ipfsGateway} with 'dweb.link' if set
*/
export default {
version,
migrate: async function (originalVersionedData) {
const versionedData = cloneDeep(originalVersionedData)
versionedData.meta.version = version
const state = versionedData.data
versionedData.data = transformState(state)
return versionedData
},
}
const outdatedGateways = [
'ipfs.io',
'ipfs.dweb.link',
]
function transformState (state) {
if (outdatedGateways.includes(state?.PreferencesController?.ipfsGateway)) {
state.PreferencesController.ipfsGateway = 'dweb.link'
}
return state
}

@ -55,6 +55,7 @@ const migrations = [
require('./042').default,
require('./043').default,
require('./044').default,
require('./045').default,
]
export default migrations

@ -0,0 +1,92 @@
import assert from 'assert'
import migration45 from '../../../app/scripts/migrations/045'
describe('migration #45', function () {
it('should update the version metadata', function (done) {
const oldStorage = {
'meta': {
'version': 44,
},
'data': {},
}
migration45.migrate(oldStorage)
.then((newStorage) => {
assert.deepEqual(newStorage.meta, {
'version': 45,
})
done()
})
.catch(done)
})
it('should update ipfsGateway value if outdated', function (done) {
const oldStorage = {
meta: {},
data: {
PreferencesController: {
ipfsGateway: 'ipfs.dweb.link',
bar: 'baz',
},
foo: 'bar',
},
}
migration45.migrate(oldStorage)
.then((newStorage) => {
assert.deepEqual(newStorage.data, {
PreferencesController: {
ipfsGateway: 'dweb.link',
bar: 'baz',
},
foo: 'bar',
})
done()
})
.catch(done)
})
it('should not update ipfsGateway value if custom set', function (done) {
const oldStorage = {
meta: {},
data: {
PreferencesController: {
ipfsGateway: 'blah',
bar: 'baz',
},
foo: 'bar',
},
}
migration45.migrate(oldStorage)
.then((newStorage) => {
assert.deepEqual(newStorage.data, {
PreferencesController: {
ipfsGateway: 'blah',
bar: 'baz',
},
foo: 'bar',
})
done()
})
.catch(done)
})
it('should do nothing if no PreferencesController key', function (done) {
const oldStorage = {
meta: {},
data: {
foo: 'bar',
},
}
migration45.migrate(oldStorage)
.then((newStorage) => {
assert.deepEqual(newStorage.data, {
foo: 'bar',
})
done()
})
.catch(done)
})
})
Loading…
Cancel
Save