Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

AEX-2 Compatibility #98

Open
wants to merge 11 commits into
base: aex-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 49 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
"dependencies": {
"@aeternity/aepp-components": "git+https://github.com/aeternity/aepp-components.git#develop",
"@aeternity/aepp-components-3": "3.0.0-alpha.9",
"@aeternity/aepp-sdk": "6.0.0",
"@aeternity/aepp-sdk": "github:aeternity/aepp-sdk-js#develop",
"@aeternity/bip39": "^0.1.0",
"@aeternity/hd-wallet": "^0.2.0",
"@aeternity/ledger-app-api": "^0.1.0",
"@ledgerhq/hw-transport-u2f": "^4.72.1",
"@vue/cli-plugin-e2e-cypress": "^3.12.0",
"@vue/cli-service": "^3.12.0",
"@zxing/library": "^0.15.2",
"argon2-browser": "^1.11.1",
"argon2-browser": "^1.5.2",
"axios": "^0.19.0",
"bignumber.js": "^8.1.1",
"bip38": "^2.0.3",
"bip38-network": "^3.0.0",
"bitcoinjs-lib": "^4.0.3",
"bluebird": "^3.7.1",
"bootstrap": "^4.3.1",
"bootstrap-vue": "^2.0.4",
"bs58check": "^2.1.2",
Expand Down
67 changes: 49 additions & 18 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { phishingCheckUrl, getPhishingUrls, setPhishingUrl } from './popup/utils/phishing-detect';
import { checkAeppConnected, initializeSDK, removeTxFromStorage, detectBrowser } from './popup/utils/helper';
import {
phishingCheckUrl,
getPhishingUrls,
setPhishingUrl
} from './popup/utils/phishing-detect';
import {
checkAeppConnected,
removeTxFromStorage,
detectBrowser
} from './popup/utils/helper';
import WalletContorller from './wallet-controller'
import Notification from './notifications';
import {
HDWALLET_METHODS
} from './popup/utils/constants'



import initRpcwallet from './lib/initRpcWallet'


global.browser = require('webextension-polyfill');
Expand All @@ -17,9 +32,8 @@ chrome.browserAction.onClicked.addListener(function (tab) {
setInterval(() => {
browser.windows.getAll({}).then((wins) => {
if(wins.length == 0) {
console.log("remove")
sessionStorage.removeItem("phishing_urls");
browser.storage.sync.remove('isLogged')
// browser.storage.sync.remove('isLogged')
browser.storage.sync.remove('activeAccount')
}
});
Expand Down Expand Up @@ -251,22 +265,39 @@ const postToContent = (data, tabId) => {
}

const controller = new WalletContorller()
const notification = new Notification();

browser.runtime.onConnect.addListener( ( port ) => {
let extensionUrl = 'chrome-extension'
if(detectBrowser() == 'Firefox') {
extensionUrl = 'moz-extension'
}
if((port.name == 'popup' && port.sender.id == browser.runtime.id && port.sender.url == `${extensionUrl}://${browser.runtime.id}/popup/popup.html` && detectBrowser() != 'Firefox') || ( detectBrowser() == 'Firefox' && port.name == 'popup' && port.sender.id == browser.runtime.id ) ) {
port.onMessage.addListener(({ type, payload, uuid}) => {
console.log(type)
controller[type](payload).then((res) => {
port.postMessage({ uuid, res })
})
})

const connectToExtPopup = (onMessage) => {
browser.runtime.onConnect.addListener( ( port ) => {
let extensionUrl = 'chrome-extension'
if(detectBrowser() == 'Firefox') {
extensionUrl = 'moz-extension'
}
if((port.name == 'popup' && port.sender.id == browser.runtime.id && port.sender.url == `${extensionUrl}://${browser.runtime.id}/popup/popup.html` && detectBrowser() != 'Firefox') || ( detectBrowser() == 'Firefox' && port.name == 'popup' && port.sender.id == browser.runtime.id ) ) {
port.onMessage.addListener(({ type, payload, uuid}) => {
let hdwallet = false
if(HDWALLET_METHODS.includes(type)) {
hdwallet = true

}
onMessage({ hdwallet, port, type, payload, uuid })
})
}
})
}

connectToExtPopup(({ hdwallet, port, type, payload, uuid }) => {
if(hdwallet) {
controller[type](payload).then((res) => {
port.postMessage({ uuid, res })
})
}
})
})


/**
* AEX-2
*/

const notification = new Notification();
initRpcwallet(connectToExtPopup, controller)
51 changes: 21 additions & 30 deletions src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { extractHostName, detectBrowser } from './popup/utils/helper';
global.browser = require('webextension-polyfill');

if(typeof navigator.clipboard == 'undefined') {
redirectToWarning(extractHostName(window.location.href),window.location.href)
// redirectToWarning(extractHostName(window.location.href),window.location.href)
} else {
sendToBackground('phishingCheck',{ hostname:extractHostName(window.location.href), href:window.location.href })
}
let aepp = browser.runtime.getURL("aepp.js")
fetch(aepp)
fetch(aepp)
.then(res => res.text())
.then(res => {
injectScript(res)
// injectScript(res)
})
// Subscribe from postMessages from page
window.addEventListener("message", ({data}) => {

window.addEventListener("message", (data) => {
// browser.runtime.sendMessage(data)
let method = "pageMessage";
if(typeof data.method != "undefined") {
method = data.method
Expand All @@ -28,18 +29,24 @@ window.addEventListener("message", ({data}) => {
}
})
}


}, false)

// Handle message from background and redirect to page
browser.runtime.onMessage.addListener(({ data, method }, sender, sendResponse) => {
if(data.method == 'phishingCheck') {
if(data.blocked) {
redirectToWarning(data.params.hostname,data.params.href,data.extUrl)
}
const readyStateCheckInterval = setInterval(function () {
if (document.readyState === "complete") {
clearInterval(readyStateCheckInterval)
// Handle message from background and redirect to page
chrome.runtime.onMessage.addListener(({ data }, sender) => {
if(data.hasOwnProperty("method") && data.method == 'phishingCheck') {
if(data.blocked) {
redirectToWarning(data.params.hostname,data.params.href,data.extUrl)
}
} else {
window.postMessage(data, '*')
}
})
}
})
}, 10)


const redirectToWarning = (hostname,href,extUrl = '') => {
window.stop()
Expand Down Expand Up @@ -81,19 +88,3 @@ function sendToBackground(method, params) {
})
})
}

// Render
function render(data) {
// @TODO create list with sdks and his transaction with ability to accept/decline signing
}

function clickSign({target, value}) {
const [sdkId, tx] = target.id.split['-'];
signResponse({value, sdkId, tx})
}

function signResponse({value, sdkId, tx}) {
sendToBackground('txSign', {value, sdkId, tx})
}


5 changes: 5 additions & 0 deletions src/lib/initEnv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Object.assign(process.env, {
...process.env.RUNNING_IN_POPUP === undefined && {
RUNNING_IN_POPUP: !!window.opener && window.name.includes('popup'),
},
});
Loading