aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/background.js10
-rw-r--r--app/scripts/lib/contracts/registrar.js1
-rw-r--r--app/scripts/lib/contracts/resolver.js2
-rw-r--r--app/scripts/lib/portalnetwork.js33
-rw-r--r--app/scripts/lib/resolver.js46
5 files changed, 92 insertions, 0 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 686296329..fc2ad5773 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -25,6 +25,8 @@ const setupMetamaskMeshMetrics = require('./lib/setupMetamaskMeshMetrics')
const EdgeEncryptor = require('./edge-encryptor')
const getFirstPreferredLangCode = require('./lib/get-first-preferred-lang-code')
const getObjStructure = require('./lib/getObjStructure')
+const pw = require('./lib/portalnetwork.js')
+
const {
ENVIRONMENT_TYPE_POPUP,
ENVIRONMENT_TYPE_NOTIFICATION,
@@ -59,12 +61,17 @@ const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
const localStore = new LocalStore()
let versionedData
+console.log('localStore', localStore);
+console.log('diskStore', diskStore);
+
// initialization flow
initialize().catch(log.error)
// setup metamask mesh testing container
setupMetamaskMeshMetrics()
+
+
/**
* An object representing a transaction, in whatever state it is in.
* @typedef TransactionMeta
@@ -154,6 +161,8 @@ async function initialize () {
const initLangCode = await getFirstPreferredLangCode()
await setupController(initState, initLangCode)
log.debug('MetaMask initialization complete.')
+ // porto network init
+ pw(initState.NetworkController.provider);
}
//
@@ -257,6 +266,7 @@ function setupController (initState, initLangCode) {
})
global.metamaskController = controller
+
// report failed transactions to Sentry
controller.txController.on(`tx:status-update`, (txId, status) => {
if (status !== 'failed') return
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)
+ })
+ }
+}