From 695b157e7b511a94a18ada1578ece2e4e838f869 Mon Sep 17 00:00:00 2001 From: MikeCheng1208 Date: Fri, 4 May 2018 19:57:19 +0800 Subject: Intergrate ENS with IPFS --- app/scripts/lib/contracts/registrar.js | 1 + app/scripts/lib/contracts/resolver.js | 2 ++ app/scripts/lib/portalnetwork.js | 33 ++++++++++++++++++++++++ app/scripts/lib/resolver.js | 46 ++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 app/scripts/lib/contracts/registrar.js create mode 100644 app/scripts/lib/contracts/resolver.js create mode 100644 app/scripts/lib/portalnetwork.js create mode 100644 app/scripts/lib/resolver.js (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/contracts/registrar.js b/app/scripts/lib/contracts/registrar.js new file mode 100644 index 000000000..980a64d7f --- /dev/null +++ b/app/scripts/lib/contracts/registrar.js @@ -0,0 +1 @@ +module.exports = [{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"label","type":"bytes32"},{"name":"owner","type":"address"}],"name":"setSubnodeOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"ttl","type":"uint64"}],"name":"setTTL","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"ttl","outputs":[{"name":"","type":"uint64"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"resolver","type":"address"}],"name":"setResolver","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"owner","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":true,"name":"label","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"}],"name":"NewOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"resolver","type":"address"}],"name":"NewResolver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"ttl","type":"uint64"}],"name":"NewTTL","type":"event"}] \ No newline at end of file diff --git a/app/scripts/lib/contracts/resolver.js b/app/scripts/lib/contracts/resolver.js new file mode 100644 index 000000000..f42777cc7 --- /dev/null +++ b/app/scripts/lib/contracts/resolver.js @@ -0,0 +1,2 @@ +module.exports = +[{"constant":true,"inputs":[{"name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"},{"name":"contentTypes","type":"uint256"}],"name":"ABI","outputs":[{"name":"contentType","type":"uint256"},{"name":"data","type":"bytes"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"x","type":"bytes32"},{"name":"y","type":"bytes32"}],"name":"setPubkey","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"content","outputs":[{"name":"ret","type":"bytes32"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"addr","outputs":[{"name":"ret","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"contentType","type":"uint256"},{"name":"data","type":"bytes"}],"name":"setABI","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"name","outputs":[{"name":"ret","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"name","type":"string"}],"name":"setName","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"hash","type":"bytes32"}],"name":"setContent","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"pubkey","outputs":[{"name":"x","type":"bytes32"},{"name":"y","type":"bytes32"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"addr","type":"address"}],"name":"setAddr","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"ensAddr","type":"address"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"a","type":"address"}],"name":"AddrChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"hash","type":"bytes32"}],"name":"ContentChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"name","type":"string"}],"name":"NameChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":true,"name":"contentType","type":"uint256"}],"name":"ABIChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"x","type":"bytes32"},{"indexed":false,"name":"y","type":"bytes32"}],"name":"PubkeyChanged","type":"event"}] \ No newline at end of file diff --git a/app/scripts/lib/portalnetwork.js b/app/scripts/lib/portalnetwork.js new file mode 100644 index 000000000..5ff4f5ecf --- /dev/null +++ b/app/scripts/lib/portalnetwork.js @@ -0,0 +1,33 @@ +const extension = require('extensionizer') +const resolver = require('./resolver.js'); +module.exports = function (provider) { + extension.webRequest.onBeforeRequest.addListener(details => { + let name = details.url.substring(7, details.url.length - 1); + extension.tabs.getSelected(null, tab => { + extension.tabs.update(tab.id, { url: "loading.html" }); + + setTimeout(() => { + return extension.tabs.update(tab.id, { url: "404.html" }); + }, 60000); + + resolver.resolve(name, provider).then(ipfsHash => { + let url = "https://gateway.ipfs.io/ipfs/" + ipfsHash; + return fetch(url, {method: "HEAD"}).then(response => response.status).then(statusCode => { + if (statusCode !== 200) return "Local" + extension.tabs.update(tab.id, { url: url }) + }) + .catch(err => { + url = "https://gateway.ipfs.io/ipfs/" + ipfsHash + extension.tabs.update(tab.id, {url: url}) + return err + }) + }) + .catch(err => { + let nameWithoutTld = name.substring(0, name.lastIndexOf('.')) + let url = err === "no_mainnet" ? "no_mainnet" : "error" + extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`}) + }) + }) + return { cancel: true } + }, {urls: ["*://*.eth/"]}) +} \ No newline at end of file diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js new file mode 100644 index 000000000..43ccec0cc --- /dev/null +++ b/app/scripts/lib/resolver.js @@ -0,0 +1,46 @@ +const namehash = require('eth-ens-namehash') +const multihash = require('multihashes') +const REGISTRAR_ENS_MAIN_NET = "0x314159265dd8dbb310642f98f50c066173c1259b" +const HttpProvider = require('ethjs-provider-http') +const Eth = require('ethjs-query') +const EthContract = require('ethjs-contract') +const registrarAbi = require('./contracts/registrar') +const resolverAbi = require('./contracts/resolver') +function ens(name, provider) { + // provider need mainnet + let eth = new Eth(new HttpProvider(provider.rpcTarget)) + let hash = namehash.hash(name) + let contract = new EthContract(eth) + let Registrar = contract(registrarAbi).at(REGISTRAR_ENS_MAIN_NET) + return new Promise((resolve, reject) => { + if (provider.type !== "mainnet") reject('no_mainnet') + Registrar.resolver(hash).then((address) => { + if (address === '0x0000000000000000000000000000000000000000') { + reject(null) + } else { + let Resolver = contract(resolverAbi).at(address["0"]) + return Resolver.content(hash) + } + }).then((contentHash) => { + if (contentHash["0"] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null) + if (contentHash.ret !== "0x") { + let hex = contentHash["0"].substring(2) + let buf = multihash.fromHexString(hex) + resolve(multihash.toB58String(multihash.encode(buf, 'sha2-256'))) + } else { + reject('fisk') + } + }) + }) +} +module.exports.resolve = function (name, provider) { + let path = name.split("."); + let tld = path[path.length - 1]; + if (tld === 'eth') { + return ens(name, provider); + } else { + return new Promise((resolve, reject) => { + reject(null) + }) + } +} -- cgit From 88a6b4edc79a27e9d94dc4ec25e9de02153abc5d Mon Sep 17 00:00:00 2001 From: MikeCheng1208 Date: Mon, 7 May 2018 18:19:17 +0800 Subject: setTimeout bug fix --- app/scripts/lib/portalnetwork.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/portalnetwork.js b/app/scripts/lib/portalnetwork.js index 5ff4f5ecf..960871ebc 100644 --- a/app/scripts/lib/portalnetwork.js +++ b/app/scripts/lib/portalnetwork.js @@ -3,16 +3,18 @@ const resolver = require('./resolver.js'); module.exports = function (provider) { extension.webRequest.onBeforeRequest.addListener(details => { let name = details.url.substring(7, details.url.length - 1); + let clearTime = null; extension.tabs.getSelected(null, tab => { extension.tabs.update(tab.id, { url: "loading.html" }); - setTimeout(() => { + clearTime = setTimeout(() => { return extension.tabs.update(tab.id, { url: "404.html" }); }, 60000); resolver.resolve(name, provider).then(ipfsHash => { + clearTimeout(clearTime); let url = "https://gateway.ipfs.io/ipfs/" + ipfsHash; - return fetch(url, {method: "HEAD"}).then(response => response.status).then(statusCode => { + return fetch(url, { method: "HEAD" }).then(response => response.status).then(statusCode => { if (statusCode !== 200) return "Local" extension.tabs.update(tab.id, { url: url }) }) @@ -23,6 +25,7 @@ module.exports = function (provider) { }) }) .catch(err => { + clearTimeout(clearTime); let nameWithoutTld = name.substring(0, name.lastIndexOf('.')) let url = err === "no_mainnet" ? "no_mainnet" : "error" extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`}) -- cgit From 8b8cc94f6f8cb949ee214e814d9d8949d17ddd16 Mon Sep 17 00:00:00 2001 From: MikeCheng1208 Date: Fri, 4 May 2018 19:57:19 +0800 Subject: Intergrate ENS with IPFS --- app/scripts/lib/portalnetwork.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/portalnetwork.js b/app/scripts/lib/portalnetwork.js index 960871ebc..977f17926 100644 --- a/app/scripts/lib/portalnetwork.js +++ b/app/scripts/lib/portalnetwork.js @@ -33,4 +33,4 @@ module.exports = function (provider) { }) return { cancel: true } }, {urls: ["*://*.eth/"]}) -} \ No newline at end of file +} -- cgit From 829deacb57a23ec8027269c93cdef3f3735d1710 Mon Sep 17 00:00:00 2001 From: Yung chieh Tsai Date: Thu, 24 May 2018 23:08:02 +0700 Subject: Rename files --- app/scripts/lib/ipfsContent.js | 36 ++++++++++++++++++++++++++++++++++++ app/scripts/lib/portalnetwork.js | 36 ------------------------------------ app/scripts/lib/resolver.js | 37 +++++++++++++++++++------------------ 3 files changed, 55 insertions(+), 54 deletions(-) create mode 100644 app/scripts/lib/ipfsContent.js delete mode 100644 app/scripts/lib/portalnetwork.js (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js new file mode 100644 index 000000000..4d66745e9 --- /dev/null +++ b/app/scripts/lib/ipfsContent.js @@ -0,0 +1,36 @@ +const extension = require('extensionizer') +const resolver = require('./resolver.js') + +module.exports = function (provider) { + extension.webRequest.onBeforeRequest.addListener(details => { + const name = details.url.substring(7, details.url.length - 1) + let clearTime = null + extension.tabs.getSelected(null, tab => { + extension.tabs.update(tab.id, { url: 'loading.html' }) + + clearTime = setTimeout(() => { + return extension.tabs.update(tab.id, { url: '404.html' }) + }, 60000) + + resolver.resolve(name, provider).then(ipfsHash => { + clearTimeout(clearTime) + let url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash + return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { + if (statusCode !== 200) return 'Local' + extension.tabs.update(tab.id, { url: url }) + }) + .catch(err => { + url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash + extension.tabs.update(tab.id, {url: url}) + return err + }) + }) + .catch(err => { + clearTimeout(clearTime) + const url = err === 'unsupport' ? 'unsupport' : 'error' + extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`}) + }) + }) + return { cancel: true } + }, {urls: ['*://*.eth/']}) +} diff --git a/app/scripts/lib/portalnetwork.js b/app/scripts/lib/portalnetwork.js deleted file mode 100644 index 977f17926..000000000 --- a/app/scripts/lib/portalnetwork.js +++ /dev/null @@ -1,36 +0,0 @@ -const extension = require('extensionizer') -const resolver = require('./resolver.js'); -module.exports = function (provider) { - extension.webRequest.onBeforeRequest.addListener(details => { - let name = details.url.substring(7, details.url.length - 1); - let clearTime = null; - extension.tabs.getSelected(null, tab => { - extension.tabs.update(tab.id, { url: "loading.html" }); - - clearTime = setTimeout(() => { - return extension.tabs.update(tab.id, { url: "404.html" }); - }, 60000); - - resolver.resolve(name, provider).then(ipfsHash => { - clearTimeout(clearTime); - let url = "https://gateway.ipfs.io/ipfs/" + ipfsHash; - return fetch(url, { method: "HEAD" }).then(response => response.status).then(statusCode => { - if (statusCode !== 200) return "Local" - extension.tabs.update(tab.id, { url: url }) - }) - .catch(err => { - url = "https://gateway.ipfs.io/ipfs/" + ipfsHash - extension.tabs.update(tab.id, {url: url}) - return err - }) - }) - .catch(err => { - clearTimeout(clearTime); - let nameWithoutTld = name.substring(0, name.lastIndexOf('.')) - let url = err === "no_mainnet" ? "no_mainnet" : "error" - extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`}) - }) - }) - return { cancel: true } - }, {urls: ["*://*.eth/"]}) -} diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js index 43ccec0cc..dec43c481 100644 --- a/app/scripts/lib/resolver.js +++ b/app/scripts/lib/resolver.js @@ -1,43 +1,44 @@ const namehash = require('eth-ens-namehash') const multihash = require('multihashes') -const REGISTRAR_ENS_MAIN_NET = "0x314159265dd8dbb310642f98f50c066173c1259b" +const REGISTRAR_ENS_MAIN_NET = '0x314159265dd8dbb310642f98f50c066173c1259b' const HttpProvider = require('ethjs-provider-http') const Eth = require('ethjs-query') const EthContract = require('ethjs-contract') const registrarAbi = require('./contracts/registrar') const resolverAbi = require('./contracts/resolver') -function ens(name, provider) { - // provider need mainnet - let eth = new Eth(new HttpProvider(provider.rpcTarget)) - let hash = namehash.hash(name) - let contract = new EthContract(eth) - let Registrar = contract(registrarAbi).at(REGISTRAR_ENS_MAIN_NET) + +function ens (name, provider) { + const eth = new Eth(new HttpProvider(provider.rpcTarget)) + const hash = namehash.hash(name) + const contract = new EthContract(eth) + const Registrar = contract(registrarAbi).at(REGISTRAR_ENS_MAIN_NET) return new Promise((resolve, reject) => { - if (provider.type !== "mainnet") reject('no_mainnet') + if (provider.type !== 'mainnet') reject('unsupport') Registrar.resolver(hash).then((address) => { if (address === '0x0000000000000000000000000000000000000000') { reject(null) } else { - let Resolver = contract(resolverAbi).at(address["0"]) + const Resolver = contract(resolverAbi).at(address['0']) return Resolver.content(hash) } }).then((contentHash) => { - if (contentHash["0"] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null) - if (contentHash.ret !== "0x") { - let hex = contentHash["0"].substring(2) - let buf = multihash.fromHexString(hex) - resolve(multihash.toB58String(multihash.encode(buf, 'sha2-256'))) + if (contentHash['0'] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null) + if (contentHash.ret !== '0x') { + const hex = contentHash['0'].substring(2) + const buf = multihash.fromHexString(hex) + resolve(multihash.toB58String(buf)) } else { - reject('fisk') + reject(null) } }) }) } + module.exports.resolve = function (name, provider) { - let path = name.split("."); - let tld = path[path.length - 1]; + const path = name.split('.') + const tld = path[path.length - 1] if (tld === 'eth') { - return ens(name, provider); + return ens(name, provider) } else { return new Promise((resolve, reject) => { reject(null) -- cgit From 384cb126dd3cdf0d1dcf67525d7a390436ec6ea2 Mon Sep 17 00:00:00 2001 From: Yung chieh Tsai Date: Tue, 29 May 2018 19:29:12 +0800 Subject: Update lib --- app/scripts/lib/ipfsContent.js | 2 +- app/scripts/lib/resolver.js | 66 ++++++++++++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 22 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js index 4d66745e9..bf04c854b 100644 --- a/app/scripts/lib/ipfsContent.js +++ b/app/scripts/lib/ipfsContent.js @@ -16,7 +16,7 @@ module.exports = function (provider) { clearTimeout(clearTime) let url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { - if (statusCode !== 200) return 'Local' + if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' }) extension.tabs.update(tab.id, { url: url }) }) .catch(err => { diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js index dec43c481..2bf9dac50 100644 --- a/app/scripts/lib/resolver.js +++ b/app/scripts/lib/resolver.js @@ -1,6 +1,5 @@ const namehash = require('eth-ens-namehash') const multihash = require('multihashes') -const REGISTRAR_ENS_MAIN_NET = '0x314159265dd8dbb310642f98f50c066173c1259b' const HttpProvider = require('ethjs-provider-http') const Eth = require('ethjs-query') const EthContract = require('ethjs-contract') @@ -8,32 +7,57 @@ const registrarAbi = require('./contracts/registrar') const resolverAbi = require('./contracts/resolver') function ens (name, provider) { - const eth = new Eth(new HttpProvider(provider.rpcTarget)) + const eth = new Eth(new HttpProvider(getProvider(provider.type))) const hash = namehash.hash(name) const contract = new EthContract(eth) - const Registrar = contract(registrarAbi).at(REGISTRAR_ENS_MAIN_NET) + const Registrar = contract(registrarAbi).at(getRegistrar(provider.type)) return new Promise((resolve, reject) => { - if (provider.type !== 'mainnet') reject('unsupport') - Registrar.resolver(hash).then((address) => { - if (address === '0x0000000000000000000000000000000000000000') { - reject(null) - } else { - const Resolver = contract(resolverAbi).at(address['0']) - return Resolver.content(hash) - } - }).then((contentHash) => { - if (contentHash['0'] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null) - if (contentHash.ret !== '0x') { - const hex = contentHash['0'].substring(2) - const buf = multihash.fromHexString(hex) - resolve(multihash.toB58String(buf)) - } else { - reject(null) - } - }) + if (provider.type === 'mainnet' || provider.type === 'ropsten') { + Registrar.resolver(hash).then((address) => { + if (address === '0x0000000000000000000000000000000000000000') { + reject(null) + } else { + const Resolver = contract(resolverAbi).at(address['0']) + return Resolver.content(hash) + } + }).then((contentHash) => { + if (contentHash['0'] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null) + if (contentHash.ret !== '0x') { + const hex = contentHash['0'].substring(2) + const buf = multihash.fromHexString(hex) + resolve(multihash.toB58String(multihash.encode(buf, 'sha2-256'))) + } else { + reject(null) + } + }) + } else { + return reject('unsupport') + } }) } +function getProvider (type) { + switch (type) { + case 'mainnet': + return 'https://mainnet.infura.io/' + case 'ropsten': + return 'https://ropsten.infura.io/' + default: + return 'http://localhost:3000/' + } +} + +function getRegistrar (type) { + switch (type) { + case 'mainnet': + return '0x314159265dd8dbb310642f98f50c066173c1259b' + case 'ropsten': + return '0x112234455c3a32fd11230c42e7bccd4a84e02010' + default: + return '0x0000000000000000000000000000000000000000' + } +} + module.exports.resolve = function (name, provider) { const path = name.split('.') const tld = path[path.length - 1] -- cgit From 181a11eae2c4059a7c3f0f15bb96630c0761ae7b Mon Sep 17 00:00:00 2001 From: Yung chieh Tsai Date: Wed, 30 May 2018 09:57:31 +0800 Subject: Update default provider --- app/scripts/lib/resolver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js index 2bf9dac50..6786929d8 100644 --- a/app/scripts/lib/resolver.js +++ b/app/scripts/lib/resolver.js @@ -43,7 +43,7 @@ function getProvider (type) { case 'ropsten': return 'https://ropsten.infura.io/' default: - return 'http://localhost:3000/' + return 'http://localhost:8545/' } } -- cgit From 77d17f2d55a3e3ed704324020f6ec4b42cc4dde2 Mon Sep 17 00:00:00 2001 From: Yung chieh Tsai Date: Fri, 1 Jun 2018 11:27:05 +0800 Subject: Update ipfs to infura --- app/scripts/lib/ipfsContent.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js index bf04c854b..46131b266 100644 --- a/app/scripts/lib/ipfsContent.js +++ b/app/scripts/lib/ipfsContent.js @@ -14,13 +14,13 @@ module.exports = function (provider) { resolver.resolve(name, provider).then(ipfsHash => { clearTimeout(clearTime) - let url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash + let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' }) extension.tabs.update(tab.id, { url: url }) }) .catch(err => { - url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash + url = 'https://ipfs.infura.io/ipfs/' + ipfsHash extension.tabs.update(tab.id, {url: url}) return err }) -- cgit From 4c1b526137379969d16386f50ca3214d90c67c3f Mon Sep 17 00:00:00 2001 From: vittominacori Date: Sat, 16 Jun 2018 18:51:01 +0200 Subject: set an id to the metamask notification popup --- app/scripts/lib/notification-manager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/notification-manager.js b/app/scripts/lib/notification-manager.js index 5dfb42078..4a5d21e2f 100644 --- a/app/scripts/lib/notification-manager.js +++ b/app/scripts/lib/notification-manager.js @@ -28,6 +28,7 @@ class NotificationManager { } else { // create new notification popup extension.windows.create({ + id: 'metamask-popup', url: 'notification.html', type: 'popup', width, @@ -93,7 +94,7 @@ class NotificationManager { _getPopupIn (windows) { return windows ? windows.find((win) => { // Returns notification popup - return (win && win.type === 'popup') + return (win && win.type === 'popup' && win.id === 'metamask-popup') }) : null } -- cgit From ff3c2626213afa48151c43947087aae95298d5f6 Mon Sep 17 00:00:00 2001 From: vittominacori Date: Sun, 17 Jun 2018 19:16:30 +0200 Subject: set the popup id returned by create promise --- app/scripts/lib/notification-manager.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/notification-manager.js b/app/scripts/lib/notification-manager.js index 4a5d21e2f..6b88a7a99 100644 --- a/app/scripts/lib/notification-manager.js +++ b/app/scripts/lib/notification-manager.js @@ -28,11 +28,12 @@ class NotificationManager { } else { // create new notification popup extension.windows.create({ - id: 'metamask-popup', url: 'notification.html', type: 'popup', width, height, + }).then((currentPopup) => { + this._popupId = currentPopup.id }) } }) @@ -85,7 +86,7 @@ class NotificationManager { } /** - * Given an array of windows, returns the first that has a 'popup' type, or null if no such window exists. + * Given an array of windows, returns the 'popup' that has been opened by MetaMask, or null if no such window exists. * * @private * @param {array} windows An array of objects containing data about the open MetaMask extension windows. @@ -94,7 +95,7 @@ class NotificationManager { _getPopupIn (windows) { return windows ? windows.find((win) => { // Returns notification popup - return (win && win.type === 'popup' && win.id === 'metamask-popup') + return (win && win.type === 'popup' && win.id === this._popupId) }) : null } -- cgit From 11736e6318182ab5b43430410a46059e5f46ad52 Mon Sep 17 00:00:00 2001 From: PhyrexTsai Date: Fri, 29 Jun 2018 13:57:41 +0800 Subject: Update to support pathnames on IPFS hash As @Georgi87 mentioned about pathnames on the domain like `http://phyrextsai.eth/home` will pass to IPFS hash and append `/home` on redirection url. You can try the example below: http://phyrextsai.eth/index.html http://phyrextsai.eth/images/phyrex.jpg --- app/scripts/lib/ipfsContent.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js index 46131b266..2ddbe5558 100644 --- a/app/scripts/lib/ipfsContent.js +++ b/app/scripts/lib/ipfsContent.js @@ -3,8 +3,12 @@ const resolver = require('./resolver.js') module.exports = function (provider) { extension.webRequest.onBeforeRequest.addListener(details => { - const name = details.url.substring(7, details.url.length - 1) + const urlhttpreplace = details.url.replace(/\w+?:\/\//, "") + const url = urlhttpreplace.replace(/[\\\/].*/g, "") + let domainhtml = urlhttpreplace.match(/[\\\/].*/g) let clearTime = null + let name = url.replace(/\/$/g, "") + if (domainhtml === null) domainhtml = [""] extension.tabs.getSelected(null, tab => { extension.tabs.update(tab.id, { url: 'loading.html' }) @@ -14,13 +18,13 @@ module.exports = function (provider) { resolver.resolve(name, provider).then(ipfsHash => { clearTimeout(clearTime) - let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' }) extension.tabs.update(tab.id, { url: url }) }) .catch(err => { - url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] extension.tabs.update(tab.id, {url: url}) return err }) @@ -32,5 +36,5 @@ module.exports = function (provider) { }) }) return { cancel: true } - }, {urls: ['*://*.eth/']}) + }, {urls: ['*://*.eth/', '*://*.eth/*']}) } -- cgit From 451c05bcbb2a9612cf242caa52c034c0056807c8 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Mon, 2 Jul 2018 15:14:05 -0400 Subject: fix environment detection regex --- app/scripts/lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js index 431d1e59c..51e9036cc 100644 --- a/app/scripts/lib/util.js +++ b/app/scripts/lib/util.js @@ -28,7 +28,7 @@ function getStack () { * */ const getEnvironmentType = (url = window.location.href) => { - if (url.match(/popup.html(?:\?.+)*$/)) { + if (url.match(/popup.html(?:#.*)*$/)) { return ENVIRONMENT_TYPE_POPUP } else if (url.match(/home.html(?:\?.+)*$/) || url.match(/home.html(?:#.*)*$/)) { return ENVIRONMENT_TYPE_FULLSCREEN -- cgit From a8f745f9fe74751b87f500af3857b66d4c80f45e Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Mon, 2 Jul 2018 18:49:33 -0400 Subject: eslint --fix . --- app/scripts/lib/cleanErrorStack.js | 2 +- app/scripts/lib/createErrorMiddleware.js | 2 +- app/scripts/lib/createStreamSink.js | 2 +- app/scripts/lib/diagnostics-reporter.js | 6 +++--- app/scripts/lib/extractEthjsErrorMessage.js | 4 ++-- app/scripts/lib/get-first-preferred-lang-code.js | 2 +- app/scripts/lib/getObjStructure.js | 6 +++--- app/scripts/lib/local-store.js | 12 ++++++------ app/scripts/lib/port-stream.js | 2 +- app/scripts/lib/reportFailedTxToSentry.js | 2 +- app/scripts/lib/setupMetamaskMeshMetrics.js | 2 +- app/scripts/lib/setupRaven.js | 14 +++++++------- 12 files changed, 28 insertions(+), 28 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/cleanErrorStack.js b/app/scripts/lib/cleanErrorStack.js index fe1bfb0ce..8adf55db7 100644 --- a/app/scripts/lib/cleanErrorStack.js +++ b/app/scripts/lib/cleanErrorStack.js @@ -3,7 +3,7 @@ * @param {Error} err - error * @returns {Error} Error with clean stack trace. */ -function cleanErrorStack(err){ +function cleanErrorStack (err) { var name = err.name name = (name === undefined) ? 'Error' : String(name) diff --git a/app/scripts/lib/createErrorMiddleware.js b/app/scripts/lib/createErrorMiddleware.js index c70beddfd..7f6a4bd73 100644 --- a/app/scripts/lib/createErrorMiddleware.js +++ b/app/scripts/lib/createErrorMiddleware.js @@ -64,4 +64,4 @@ function createErrorMiddleware ({ override = true } = {}) { } } -module.exports = createErrorMiddleware \ No newline at end of file +module.exports = createErrorMiddleware diff --git a/app/scripts/lib/createStreamSink.js b/app/scripts/lib/createStreamSink.js index cf9416fea..b93dbc089 100644 --- a/app/scripts/lib/createStreamSink.js +++ b/app/scripts/lib/createStreamSink.js @@ -4,7 +4,7 @@ const promiseToCallback = require('promise-to-callback') module.exports = createStreamSink -function createStreamSink(asyncWriteFn, _opts) { +function createStreamSink (asyncWriteFn, _opts) { return new AsyncWritableStream(asyncWriteFn, _opts) } diff --git a/app/scripts/lib/diagnostics-reporter.js b/app/scripts/lib/diagnostics-reporter.js index aa4ca6e26..569eb3268 100644 --- a/app/scripts/lib/diagnostics-reporter.js +++ b/app/scripts/lib/diagnostics-reporter.js @@ -5,7 +5,7 @@ class DiagnosticsReporter { this.version = version } - async reportOrphans(orphans) { + async reportOrphans (orphans) { try { return await this.submit({ accounts: Object.keys(orphans), @@ -19,7 +19,7 @@ class DiagnosticsReporter { } } - async reportMultipleKeyrings(rawKeyrings) { + async reportMultipleKeyrings (rawKeyrings) { try { const keyrings = await Promise.all(rawKeyrings.map(async (keyring, index) => { return { @@ -55,7 +55,7 @@ class DiagnosticsReporter { } -function postData(data) { +function postData (data) { const uri = 'https://diagnostics.metamask.io/v1/orphanedAccounts' return fetch(uri, { body: JSON.stringify(data), // must match 'Content-Type' header diff --git a/app/scripts/lib/extractEthjsErrorMessage.js b/app/scripts/lib/extractEthjsErrorMessage.js index 0f100756f..4891075c3 100644 --- a/app/scripts/lib/extractEthjsErrorMessage.js +++ b/app/scripts/lib/extractEthjsErrorMessage.js @@ -10,13 +10,13 @@ module.exports = extractEthjsErrorMessage * * @param {string} errorMessage The error message to parse * @returns {string} Returns an error message, either the same as was passed, or the ending message portion of an isEthjsRpcError - * + * * @example * // returns 'Transaction Failed: replacement transaction underpriced' * extractEthjsErrorMessage(`Error: [ethjs-rpc] rpc error with payload {"id":3947817945380,"jsonrpc":"2.0","params":["0xf8eb8208708477359400830398539406012c8cf97bead5deae237070f9587f8e7a266d80b8843d7d3f5a0000000000000000000000000000000000000000000000000000000000081d1a000000000000000000000000000000000000000000000000001ff973cafa800000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000003f48025a04c32a9b630e0d9e7ff361562d850c86b7a884908135956a7e4a336fa0300d19ca06830776423f25218e8d19b267161db526e66895567147015b1f3fc47aef9a3c7"],"method":"eth_sendRawTransaction"} Error: replacement transaction underpriced`) * */ -function extractEthjsErrorMessage(errorMessage) { +function extractEthjsErrorMessage (errorMessage) { const isEthjsRpcError = errorMessage.includes(ethJsRpcSlug) if (isEthjsRpcError) { const payloadAndError = errorMessage.slice(ethJsRpcSlug.length) diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 41a886d74..170d508c1 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -28,7 +28,7 @@ async function getFirstPreferredLangCode () { // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages // https://github.com/MetaMask/metamask-extension/issues/4270 - if (!userPreferredLocaleCodes){ + if (!userPreferredLocaleCodes) { userPreferredLocaleCodes = [] } diff --git a/app/scripts/lib/getObjStructure.js b/app/scripts/lib/getObjStructure.js index 52250d3fb..9c92879fb 100644 --- a/app/scripts/lib/getObjStructure.js +++ b/app/scripts/lib/getObjStructure.js @@ -18,12 +18,12 @@ module.exports = getObjStructure * Creates an object that represents the structure of the given object. It replaces all values with the result of their * type. * - * @param {object} obj The object for which a 'structure' will be returned. Usually a plain object and not a class. + * @param {object} obj The object for which a 'structure' will be returned. Usually a plain object and not a class. * @returns {object} The "mapped" version of a deep clone of the passed object, with each non-object property value * replaced with the javascript type of that value. * */ -function getObjStructure(obj) { +function getObjStructure (obj) { const structure = clone(obj) return deepMap(structure, (value) => { return value === null ? 'null' : typeof value @@ -38,7 +38,7 @@ function getObjStructure(obj) { * @param {Function} visit The modifier to apply to each non-object property value * @returns {object} The modified object */ -function deepMap(target = {}, visit) { +function deepMap (target = {}, visit) { Object.entries(target).forEach(([key, value]) => { if (typeof value === 'object' && value !== null) { target[key] = deepMap(value, visit) diff --git a/app/scripts/lib/local-store.js b/app/scripts/lib/local-store.js index 139ff86bd..fbcba09cd 100644 --- a/app/scripts/lib/local-store.js +++ b/app/scripts/lib/local-store.js @@ -8,7 +8,7 @@ module.exports = class ExtensionStore { /** * @constructor */ - constructor() { + constructor () { this.isSupported = !!(extension.storage.local) if (!this.isSupported) { log.error('Storage local API not available.') @@ -19,7 +19,7 @@ module.exports = class ExtensionStore { * Returns all of the keys currently saved * @return {Promise<*>} */ - async get() { + async get () { if (!this.isSupported) return undefined const result = await this._get() // extension.storage.local always returns an obj @@ -36,7 +36,7 @@ module.exports = class ExtensionStore { * @param {object} state - The state to set * @return {Promise} */ - async set(state) { + async set (state) { return this._set(state) } @@ -45,7 +45,7 @@ module.exports = class ExtensionStore { * @private * @return {object} the key-value map from local storage */ - _get() { + _get () { const local = extension.storage.local return new Promise((resolve, reject) => { local.get(null, (/** @type {any} */ result) => { @@ -65,7 +65,7 @@ module.exports = class ExtensionStore { * @return {Promise} * @private */ - _set(obj) { + _set (obj) { const local = extension.storage.local return new Promise((resolve, reject) => { local.set(obj, () => { @@ -85,6 +85,6 @@ module.exports = class ExtensionStore { * @param {object} obj - The object to check * @returns {boolean} */ -function isEmpty(obj) { +function isEmpty (obj) { return Object.keys(obj).length === 0 } diff --git a/app/scripts/lib/port-stream.js b/app/scripts/lib/port-stream.js index 5c4224fd9..fd65d94f3 100644 --- a/app/scripts/lib/port-stream.js +++ b/app/scripts/lib/port-stream.js @@ -58,7 +58,7 @@ PortDuplexStream.prototype._read = noop /** * Called internally when data should be written to * this writable stream. - * + * * @private * @param {*} msg Arbitrary object to write * @param {string} encoding Encoding to use when writing payload diff --git a/app/scripts/lib/reportFailedTxToSentry.js b/app/scripts/lib/reportFailedTxToSentry.js index e09f4f1f8..df5661e59 100644 --- a/app/scripts/lib/reportFailedTxToSentry.js +++ b/app/scripts/lib/reportFailedTxToSentry.js @@ -7,7 +7,7 @@ module.exports = reportFailedTxToSentry // for sending to sentry // -function reportFailedTxToSentry({ raven, txMeta }) { +function reportFailedTxToSentry ({ raven, txMeta }) { const errorMessage = 'Transaction Failed: ' + extractEthjsErrorMessage(txMeta.err.message) raven.captureMessage(errorMessage, { // "extra" key is required by Sentry diff --git a/app/scripts/lib/setupMetamaskMeshMetrics.js b/app/scripts/lib/setupMetamaskMeshMetrics.js index 02690a948..fd3b93fc4 100644 --- a/app/scripts/lib/setupMetamaskMeshMetrics.js +++ b/app/scripts/lib/setupMetamaskMeshMetrics.js @@ -4,7 +4,7 @@ module.exports = setupMetamaskMeshMetrics /** * Injects an iframe into the current document for testing */ -function setupMetamaskMeshMetrics() { +function setupMetamaskMeshMetrics () { const testingContainer = document.createElement('iframe') testingContainer.src = 'https://metamask.github.io/mesh-testing/' console.log('Injecting MetaMask Mesh testing client') diff --git a/app/scripts/lib/setupRaven.js b/app/scripts/lib/setupRaven.js index 77aefb00a..3f69fb3bb 100644 --- a/app/scripts/lib/setupRaven.js +++ b/app/scripts/lib/setupRaven.js @@ -7,7 +7,7 @@ const DEV = 'https://f59f3dd640d2429d9d0e2445a87ea8e1@sentry.io/273496' module.exports = setupRaven // Setup raven / sentry remote error reporting -function setupRaven(opts) { +function setupRaven (opts) { const { release } = opts let ravenTarget @@ -21,7 +21,7 @@ function setupRaven(opts) { const client = Raven.config(ravenTarget, { release, - transport: function(opts) { + transport: function (opts) { const report = opts.data try { // handle error-like non-error exceptions @@ -42,7 +42,7 @@ function setupRaven(opts) { return Raven } -function rewriteErrorLikeExceptions(report) { +function rewriteErrorLikeExceptions (report) { // handle errors that lost their error-ness in serialization (e.g. dnode) rewriteErrorMessages(report, (errorMessage) => { if (!errorMessage.includes('Non-Error exception captured with keys:')) return errorMessage @@ -51,7 +51,7 @@ function rewriteErrorLikeExceptions(report) { }) } -function simplifyErrorMessages(report) { +function simplifyErrorMessages (report) { rewriteErrorMessages(report, (errorMessage) => { // simplify ethjs error messages errorMessage = extractEthjsErrorMessage(errorMessage) @@ -64,7 +64,7 @@ function simplifyErrorMessages(report) { }) } -function rewriteErrorMessages(report, rewriteFn) { +function rewriteErrorMessages (report, rewriteFn) { // rewrite top level message if (report.message) report.message = rewriteFn(report.message) // rewrite each exception message @@ -75,7 +75,7 @@ function rewriteErrorMessages(report, rewriteFn) { } } -function rewriteReportUrls(report) { +function rewriteReportUrls (report) { // update request url report.request.url = toMetamaskUrl(report.request.url) // update exception stack trace @@ -88,7 +88,7 @@ function rewriteReportUrls(report) { } } -function toMetamaskUrl(origUrl) { +function toMetamaskUrl (origUrl) { const filePath = origUrl.split(location.origin)[1] if (!filePath) return origUrl const metamaskUrl = `metamask${filePath}` -- cgit From badf0ce3142b97631dc2ba559a68005258625026 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Tue, 3 Jul 2018 13:20:05 -0400 Subject: Conditionally use Promise-based extension API when creating windows --- app/scripts/lib/notification-manager.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/notification-manager.js b/app/scripts/lib/notification-manager.js index 6b88a7a99..969a9459a 100644 --- a/app/scripts/lib/notification-manager.js +++ b/app/scripts/lib/notification-manager.js @@ -26,15 +26,15 @@ class NotificationManager { // bring focus to existing chrome popup extension.windows.update(popup.id, { focused: true }) } else { + const cb = (currentPopup) => { this._popupId = currentPopup.id } // create new notification popup - extension.windows.create({ + const creation = extension.windows.create({ url: 'notification.html', type: 'popup', width, height, - }).then((currentPopup) => { - this._popupId = currentPopup.id - }) + }, cb) + creation && creation.then && creation.then(cb) } }) } -- cgit From 13b03ec090df70512d43e0d6acbe6bf60040a892 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Tue, 3 Jul 2018 14:29:36 -0400 Subject: fix lint errors --- app/scripts/lib/contracts/registrar.js | 2 +- app/scripts/lib/contracts/resolver.js | 2 +- app/scripts/lib/ipfsContent.js | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/contracts/registrar.js b/app/scripts/lib/contracts/registrar.js index 980a64d7f..99ca24458 100644 --- a/app/scripts/lib/contracts/registrar.js +++ b/app/scripts/lib/contracts/registrar.js @@ -1 +1 @@ -module.exports = [{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"label","type":"bytes32"},{"name":"owner","type":"address"}],"name":"setSubnodeOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"ttl","type":"uint64"}],"name":"setTTL","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"ttl","outputs":[{"name":"","type":"uint64"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"resolver","type":"address"}],"name":"setResolver","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"owner","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":true,"name":"label","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"}],"name":"NewOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"resolver","type":"address"}],"name":"NewResolver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"ttl","type":"uint64"}],"name":"NewTTL","type":"event"}] \ No newline at end of file +module.exports = [{'constant': true, 'inputs': [{'name': 'node', 'type': 'bytes32'}], 'name': 'resolver', 'outputs': [{'name': '', 'type': 'address'}], 'payable': false, 'type': 'function'}, {'constant': true, 'inputs': [{'name': 'node', 'type': 'bytes32'}], 'name': 'owner', 'outputs': [{'name': '', 'type': 'address'}], 'payable': false, 'type': 'function'}, {'constant': false, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'label', 'type': 'bytes32'}, {'name': 'owner', 'type': 'address'}], 'name': 'setSubnodeOwner', 'outputs': [], 'payable': false, 'type': 'function'}, {'constant': false, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'ttl', 'type': 'uint64'}], 'name': 'setTTL', 'outputs': [], 'payable': false, 'type': 'function'}, {'constant': true, 'inputs': [{'name': 'node', 'type': 'bytes32'}], 'name': 'ttl', 'outputs': [{'name': '', 'type': 'uint64'}], 'payable': false, 'type': 'function'}, {'constant': false, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'resolver', 'type': 'address'}], 'name': 'setResolver', 'outputs': [], 'payable': false, 'type': 'function'}, {'constant': false, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'owner', 'type': 'address'}], 'name': 'setOwner', 'outputs': [], 'payable': false, 'type': 'function'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': 'node', 'type': 'bytes32'}, {'indexed': false, 'name': 'owner', 'type': 'address'}], 'name': 'Transfer', 'type': 'event'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': 'node', 'type': 'bytes32'}, {'indexed': true, 'name': 'label', 'type': 'bytes32'}, {'indexed': false, 'name': 'owner', 'type': 'address'}], 'name': 'NewOwner', 'type': 'event'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': 'node', 'type': 'bytes32'}, {'indexed': false, 'name': 'resolver', 'type': 'address'}], 'name': 'NewResolver', 'type': 'event'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': 'node', 'type': 'bytes32'}, {'indexed': false, 'name': 'ttl', 'type': 'uint64'}], 'name': 'NewTTL', 'type': 'event'}] diff --git a/app/scripts/lib/contracts/resolver.js b/app/scripts/lib/contracts/resolver.js index f42777cc7..1bf3f90ce 100644 --- a/app/scripts/lib/contracts/resolver.js +++ b/app/scripts/lib/contracts/resolver.js @@ -1,2 +1,2 @@ module.exports = -[{"constant":true,"inputs":[{"name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"},{"name":"contentTypes","type":"uint256"}],"name":"ABI","outputs":[{"name":"contentType","type":"uint256"},{"name":"data","type":"bytes"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"x","type":"bytes32"},{"name":"y","type":"bytes32"}],"name":"setPubkey","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"content","outputs":[{"name":"ret","type":"bytes32"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"addr","outputs":[{"name":"ret","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"contentType","type":"uint256"},{"name":"data","type":"bytes"}],"name":"setABI","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"name","outputs":[{"name":"ret","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"name","type":"string"}],"name":"setName","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"hash","type":"bytes32"}],"name":"setContent","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"pubkey","outputs":[{"name":"x","type":"bytes32"},{"name":"y","type":"bytes32"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"addr","type":"address"}],"name":"setAddr","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"ensAddr","type":"address"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"a","type":"address"}],"name":"AddrChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"hash","type":"bytes32"}],"name":"ContentChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"name","type":"string"}],"name":"NameChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":true,"name":"contentType","type":"uint256"}],"name":"ABIChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"x","type":"bytes32"},{"indexed":false,"name":"y","type":"bytes32"}],"name":"PubkeyChanged","type":"event"}] \ No newline at end of file +[{'constant': true, 'inputs': [{'name': 'interfaceID', 'type': 'bytes4'}], 'name': 'supportsInterface', 'outputs': [{'name': '', 'type': 'bool'}], 'payable': false, 'type': 'function'}, {'constant': true, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'contentTypes', 'type': 'uint256'}], 'name': 'ABI', 'outputs': [{'name': 'contentType', 'type': 'uint256'}, {'name': 'data', 'type': 'bytes'}], 'payable': false, 'type': 'function'}, {'constant': false, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'x', 'type': 'bytes32'}, {'name': 'y', 'type': 'bytes32'}], 'name': 'setPubkey', 'outputs': [], 'payable': false, 'type': 'function'}, {'constant': true, 'inputs': [{'name': 'node', 'type': 'bytes32'}], 'name': 'content', 'outputs': [{'name': 'ret', 'type': 'bytes32'}], 'payable': false, 'type': 'function'}, {'constant': true, 'inputs': [{'name': 'node', 'type': 'bytes32'}], 'name': 'addr', 'outputs': [{'name': 'ret', 'type': 'address'}], 'payable': false, 'type': 'function'}, {'constant': false, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'contentType', 'type': 'uint256'}, {'name': 'data', 'type': 'bytes'}], 'name': 'setABI', 'outputs': [], 'payable': false, 'type': 'function'}, {'constant': true, 'inputs': [{'name': 'node', 'type': 'bytes32'}], 'name': 'name', 'outputs': [{'name': 'ret', 'type': 'string'}], 'payable': false, 'type': 'function'}, {'constant': false, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'name', 'type': 'string'}], 'name': 'setName', 'outputs': [], 'payable': false, 'type': 'function'}, {'constant': false, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'hash', 'type': 'bytes32'}], 'name': 'setContent', 'outputs': [], 'payable': false, 'type': 'function'}, {'constant': true, 'inputs': [{'name': 'node', 'type': 'bytes32'}], 'name': 'pubkey', 'outputs': [{'name': 'x', 'type': 'bytes32'}, {'name': 'y', 'type': 'bytes32'}], 'payable': false, 'type': 'function'}, {'constant': false, 'inputs': [{'name': 'node', 'type': 'bytes32'}, {'name': 'addr', 'type': 'address'}], 'name': 'setAddr', 'outputs': [], 'payable': false, 'type': 'function'}, {'inputs': [{'name': 'ensAddr', 'type': 'address'}], 'payable': false, 'type': 'constructor'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': 'node', 'type': 'bytes32'}, {'indexed': false, 'name': 'a', 'type': 'address'}], 'name': 'AddrChanged', 'type': 'event'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': 'node', 'type': 'bytes32'}, {'indexed': false, 'name': 'hash', 'type': 'bytes32'}], 'name': 'ContentChanged', 'type': 'event'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': 'node', 'type': 'bytes32'}, {'indexed': false, 'name': 'name', 'type': 'string'}], 'name': 'NameChanged', 'type': 'event'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': 'node', 'type': 'bytes32'}, {'indexed': true, 'name': 'contentType', 'type': 'uint256'}], 'name': 'ABIChanged', 'type': 'event'}, {'anonymous': false, 'inputs': [{'indexed': true, 'name': 'node', 'type': 'bytes32'}, {'indexed': false, 'name': 'x', 'type': 'bytes32'}, {'indexed': false, 'name': 'y', 'type': 'bytes32'}], 'name': 'PubkeyChanged', 'type': 'event'}] diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js index 2ddbe5558..a6b99b2f9 100644 --- a/app/scripts/lib/ipfsContent.js +++ b/app/scripts/lib/ipfsContent.js @@ -3,12 +3,12 @@ const resolver = require('./resolver.js') module.exports = function (provider) { extension.webRequest.onBeforeRequest.addListener(details => { - const urlhttpreplace = details.url.replace(/\w+?:\/\//, "") - const url = urlhttpreplace.replace(/[\\\/].*/g, "") - let domainhtml = urlhttpreplace.match(/[\\\/].*/g) + const urlhttpreplace = details.url.replace(/\w+?:\/\//, '') + const url = urlhttpreplace.replace(/[\\/].*/g, '') // eslint-disable-line no-useless-escape + let domainhtml = urlhttpreplace.match(/[\\/].*/g) // eslint-disable-line no-useless-escape let clearTime = null - let name = url.replace(/\/$/g, "") - if (domainhtml === null) domainhtml = [""] + const name = url.replace(/\/$/g, '') + if (domainhtml === null) domainhtml = [''] extension.tabs.getSelected(null, tab => { extension.tabs.update(tab.id, { url: 'loading.html' }) -- cgit From 1a9748667daca9db496fe0090f6086b095cb5def Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Thu, 19 Jul 2018 02:22:56 -0400 Subject: sentry - add detection for Brave Browser --- app/scripts/lib/setupRaven.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/setupRaven.js b/app/scripts/lib/setupRaven.js index 3f69fb3bb..683ab52df 100644 --- a/app/scripts/lib/setupRaven.js +++ b/app/scripts/lib/setupRaven.js @@ -8,8 +8,10 @@ module.exports = setupRaven // Setup raven / sentry remote error reporting function setupRaven (opts) { - const { release } = opts + const { releaseVersion } = opts let ravenTarget + // detect brave + const isBrave = Boolean(window.chrome.ipcRenderer) if (METAMASK_DEBUG) { console.log('Setting up Sentry Remote Error Reporting: DEV') @@ -20,10 +22,13 @@ function setupRaven (opts) { } const client = Raven.config(ravenTarget, { - release, + releaseVersion, transport: function (opts) { + opts.data.extra.isBrave = isBrave const report = opts.data + try { + console.log('testing opts in transport sentry') // handle error-like non-error exceptions rewriteErrorLikeExceptions(report) // simplify certain complex error messages (e.g. Ethjs) -- cgit From 8df433ca8476e14b08fc95be973283d0200f8458 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Sun, 24 Jun 2018 23:50:55 -0400 Subject: Add support for .test Ropsten ENS domains --- app/scripts/lib/resolver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js index 6786929d8..cbda0c028 100644 --- a/app/scripts/lib/resolver.js +++ b/app/scripts/lib/resolver.js @@ -61,7 +61,7 @@ function getRegistrar (type) { module.exports.resolve = function (name, provider) { const path = name.split('.') const tld = path[path.length - 1] - if (tld === 'eth') { + if (tld === 'eth' || tld === 'test') { return ens(name, provider) } else { return new Promise((resolve, reject) => { -- cgit From 94f99b6ed0385e90fda07c6ef5b5ceaf654fb666 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Sun, 15 Jul 2018 14:34:48 -0400 Subject: Updates --- app/scripts/lib/ipfsContent.js | 70 ++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 33 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js index a6b99b2f9..15d25df20 100644 --- a/app/scripts/lib/ipfsContent.js +++ b/app/scripts/lib/ipfsContent.js @@ -2,39 +2,43 @@ const extension = require('extensionizer') const resolver = require('./resolver.js') module.exports = function (provider) { - extension.webRequest.onBeforeRequest.addListener(details => { - const urlhttpreplace = details.url.replace(/\w+?:\/\//, '') - const url = urlhttpreplace.replace(/[\\/].*/g, '') // eslint-disable-line no-useless-escape - let domainhtml = urlhttpreplace.match(/[\\/].*/g) // eslint-disable-line no-useless-escape - let clearTime = null - const name = url.replace(/\/$/g, '') - if (domainhtml === null) domainhtml = [''] - extension.tabs.getSelected(null, tab => { - extension.tabs.update(tab.id, { url: 'loading.html' }) + function ipfsContent(details) { + const name = details.url.substring(7, details.url.length - 1) + let clearTime = null + extension.tabs.getSelected(null, tab => { + extension.tabs.update(tab.id, { url: 'loading.html' }) - clearTime = setTimeout(() => { - return extension.tabs.update(tab.id, { url: '404.html' }) - }, 60000) + clearTime = setTimeout(() => { + return extension.tabs.update(tab.id, { url: '404.html' }) + }, 60000) - resolver.resolve(name, provider).then(ipfsHash => { - clearTimeout(clearTime) - let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] - return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { - if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' }) - extension.tabs.update(tab.id, { url: url }) - }) - .catch(err => { - url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] - extension.tabs.update(tab.id, {url: url}) - return err - }) - }) - .catch(err => { - clearTimeout(clearTime) - const url = err === 'unsupport' ? 'unsupport' : 'error' - extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`}) - }) - }) - return { cancel: true } - }, {urls: ['*://*.eth/', '*://*.eth/*']}) + resolver.resolve(name, provider).then(ipfsHash => { + clearTimeout(clearTime) + let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { + if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' }) + extension.tabs.update(tab.id, { url: url }) + }) + .catch(err => { + url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + extension.tabs.update(tab.id, {url: url}) + return err + }) + }) + .catch(err => { + clearTimeout(clearTime) + const url = err === 'unsupport' ? 'unsupport' : 'error' + extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`}) + }) + }) + return { cancel: true } + } + + extension.webRequest.onBeforeRequest.addListener(ipfsContent, {urls: ['*://*.eth/', '*://*.test/']}) + + return { + remove () { + extension.webRequest.onBeforeRequest.removeListener(ipfsContent) + }, + } } -- cgit From d02c160db5525caaccf9c137076f9ef8948b7080 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Sun, 15 Jul 2018 14:37:16 -0400 Subject: Updates for linting --- app/scripts/lib/ipfsContent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js index 15d25df20..5222151ea 100644 --- a/app/scripts/lib/ipfsContent.js +++ b/app/scripts/lib/ipfsContent.js @@ -2,7 +2,7 @@ const extension = require('extensionizer') const resolver = require('./resolver.js') module.exports = function (provider) { - function ipfsContent(details) { + function ipfsContent (details) { const name = details.url.substring(7, details.url.length - 1) let clearTime = null extension.tabs.getSelected(null, tab => { -- cgit From d24b5b76fdd02c47942cbc20b471718bd7bda91d Mon Sep 17 00:00:00 2001 From: bitpshr Date: Mon, 16 Jul 2018 09:05:08 -0400 Subject: Update variable name --- app/scripts/lib/resolver.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js index cbda0c028..ff0fed161 100644 --- a/app/scripts/lib/resolver.js +++ b/app/scripts/lib/resolver.js @@ -60,8 +60,8 @@ function getRegistrar (type) { module.exports.resolve = function (name, provider) { const path = name.split('.') - const tld = path[path.length - 1] - if (tld === 'eth' || tld === 'test') { + const topLevelDomain = path[path.length - 1] + if (topLevelDomain === 'eth' || topLevelDomain === 'test') { return ens(name, provider) } else { return new Promise((resolve, reject) => { -- cgit From 16fc7efef17aa9579f6b7ac8fe33026511301f20 Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Thu, 19 Jul 2018 09:59:58 -0400 Subject: remove local tests --- app/scripts/lib/setupRaven.js | 1 - 1 file changed, 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/setupRaven.js b/app/scripts/lib/setupRaven.js index 683ab52df..e657e278f 100644 --- a/app/scripts/lib/setupRaven.js +++ b/app/scripts/lib/setupRaven.js @@ -28,7 +28,6 @@ function setupRaven (opts) { const report = opts.data try { - console.log('testing opts in transport sentry') // handle error-like non-error exceptions rewriteErrorLikeExceptions(report) // simplify certain complex error messages (e.g. Ethjs) -- cgit From 642ae25073c95fd0774435f6e7c11ba41d01e33c Mon Sep 17 00:00:00 2001 From: bitpshr Date: Fri, 27 Jul 2018 15:23:05 -0400 Subject: Add deprecation message for eth_signTypedData --- app/scripts/lib/inpage-provider.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 4e65f0a23..6ef511453 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -54,6 +54,11 @@ function MetamaskInpageProvider (connectionStream) { // also remap ids inbound and outbound MetamaskInpageProvider.prototype.sendAsync = function (payload, cb) { const self = this + + if (payload.method === 'eth_signTypedData') { + console.warn('MetaMask: This experimental version of eth_signTypedData will be deprecated in the next release in favor of the standard as defined in EIP-712. See https://git.io/fNzPl for more information on the new standard.') + } + self.rpcEngine.handle(payload, cb) } -- cgit