1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Support IPNS address translations (#8502)

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

Co-authored-by: Whymarrh Whitby <whymarrh.whitby@gmail.com>
This commit is contained in:
Henrique Dias 2020-05-14 11:26:27 +01:00 committed by GitHub
parent 095eeab881
commit 890bc25e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 126 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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' })

View File

@ -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
}

View File

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

View File

@ -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)
})
})