changes for: 1.1.5

This commit is contained in:
Andrei O 2022-11-02 17:11:16 +02:00
parent a0a198c8e4
commit 5539c2a4c1
No known key found for this signature in database
GPG Key ID: B961E5B68389457E
10 changed files with 71 additions and 474 deletions

1
.gitignore vendored
View File

@ -33,3 +33,4 @@ npm-debug.log*
/src/extension/content.js /src/extension/content.js
/src/extension/webInject.js /src/extension/webInject.js
releases releases
rules.json

View File

@ -1,6 +1,18 @@
# Changelog: # Changelog
### Manifest Version: 1.1.4: ## Manifest Version 1.1.5
- Added multiple new multiple implementations of MetamaskAPI including request to add a network by a website
- Injecting in sync mode stub wallet to increese compatibility with websites that expect a walled defined at the lowest point of page load
- Modifing CSP requests to allow sync injecting of stub
- Added Web3 Shim for compatibility with older websites
- Tested new websites and TX's
- Refactoring the 10 maximum conqurent messages limit
- Added support for most of listners and improve emiting them
- Added a post buil script
- Switch the content script to load initialy without a wrapper module
## Manifest Version: 1.1.4
- Added max 10 allowed concurrent messages to the wallet to prevent abusive websites from sending too many messages. - Added max 10 allowed concurrent messages to the wallet to prevent abusive websites from sending too many messages.
- Added explorer-button to main wallet page for easier viewing of the selected address on the blockchain explorer. - Added explorer-button to main wallet page for easier viewing of the selected address on the blockchain explorer.

View File

@ -1,14 +1,13 @@
{ {
"name": "clear-wallet", "name": "clear-wallet",
"version": "1.1.5", "version": "1.1.4",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"webInject": "tsc --out src/extension/webInject.js src/extension/webInject.ts",
"inject": "tsc --out src/extension/inject.js src/extension/inject.ts", "inject": "tsc --out src/extension/inject.js src/extension/inject.ts",
"content": "tsc --out src/extension/content.js src/extension/content.ts", "content": "tsc --out src/extension/content.js src/extension/content.ts",
"manifestContent" : "ts-node ./release-scripts/replace-content-manifest.ts", "post-build" : "ts-node ./release-scripts/post-build.ts",
"build": "yarn inject && yarn webInject && yarn content && vue-tsc --noEmit && vite build && yarn manifestContent", "build": "yarn inject && yarn content && vue-tsc --noEmit && vite build && yarn post-build",
"preview": "vite preview", "preview": "vite preview",
"release": "yarn config set version-tag-prefix clear-wallet@v && yarn config set version-git-message 'clear-wallet@v%s' && yarn version --patch && yarn postversion", "release": "yarn config set version-tag-prefix clear-wallet@v && yarn config set version-git-message 'clear-wallet@v%s' && yarn version --patch && yarn postversion",
"postversion": "git push", "postversion": "git push",

View File

@ -1,10 +1,10 @@
{ {
"appName": { "appName": {
"message": "Clear EVM Wallet (CLW)", "message": "Clear EVM Wallet (CLW)",
"description": "This is an open-source EVM wallet based on ethers, ionic, vue, that implements the metamask API." "description": "Clear EVM Wallet (CLW)"
}, },
"appDesc": { "appDesc": {
"message": "Clear EVM Wallet (CLW)", "message": "An open-source EVM wallet based on ethers, ionic, vue, that implements the metamask API, that works as drop in replacement.",
"description": "This is an open-source EVM wallet based on ethers, ionic, vue, that implements the metamask API." "description": "An open-source EVM wallet based on ethers, ionic, vue, that implements the metamask API, that works as drop in replacement."
} }
} }

View File

@ -0,0 +1,10 @@
(async () => {
const CONTENT_BUILD_PATH = 'src/extension/content.js'
const fs = (await import('fs')).default
const pkg = JSON.parse(fs.readFileSync('dist/manifest.json').toString());
pkg.content_scripts[0].js[0] = CONTENT_BUILD_PATH
fs.writeFileSync('dist/manifest.json', JSON.stringify(pkg, null, 2))
// fs.writeFileSync('dist/rules.js', fs.readFileSync('rules.json').toString())
fs.writeFileSync('dist/'+ CONTENT_BUILD_PATH, fs.readFileSync('src/extension/content.js').toString())
})();

View File

@ -1,7 +0,0 @@
(async () => {
const fs = (await import('fs')).default
const pkg = JSON.parse(fs.readFileSync('dist/manifest.json').toString());
pkg.content_scripts[0].js[0] = 'src/extension/content.js'
fs.writeFileSync('dist/manifest.json', JSON.stringify(pkg, null, 2))
})();

View File

@ -1,21 +1,23 @@
(() =>{ (() =>{
try { try {
const metamaskStub = ` // sha256-QANFAnmGYlNymbZUT9oHee/3HE1z/X5Qcngml3GzhVY=
// Add MetamaskAPI STUB for wallets lib to detect wallet exists const metamaskStub = `
window.ethereum = { // Add MetamaskAPI STUB for wallets lib to detect wallet exists
isMetaMask: true, window.ethereum = {
isConnected: () => false isMetaMask: true,
}`; isConnected: () => false
document.documentElement.setAttribute('onreset', metamaskStub); }`;
document.documentElement.dispatchEvent(new CustomEvent('reset')); document.documentElement.setAttribute('onreset', metamaskStub);
document.documentElement.removeAttribute('onreset'); document.documentElement.dispatchEvent(new CustomEvent('reset'));
document.documentElement.removeAttribute('onreset');
const container = document.documentElement; const container = document.documentElement;
const script = document.createElement('script'); const script = document.createElement('script');
script.setAttribute('async', "false") script.setAttribute('async', "false")
script.setAttribute('fetchpriority', "high") script.setAttribute('fetchpriority', "high")
script.src = chrome.runtime.getURL('src/extension/webInject.js') script.src = chrome.runtime.getURL('src/extension/inject.js')
container.prepend(script) container.prepend(script)
script.addEventListener('load', () => { container.removeChild(script) } )
} catch (error) { } catch (error) {
console.error('MetaMask: Provider injection failed.', error); console.error('MetaMask: Provider injection failed.', error);
} }
@ -60,7 +62,7 @@ const allowedMethods = {
window.addEventListener("message", (event) => { window.addEventListener("message", (event) => {
if (event.source != window) if (event.source != window)
return; return;
console.log(event) // console.log(event)
if (event.data.type && (event.data.type === "CLWALLET_CONTENT")) { if (event.data.type && (event.data.type === "CLWALLET_CONTENT")) {
event.data.data.resId = event.data.resId event.data.data.resId = event.data.resId
event.data.data.type = "CLWALLET_CONTENT_MSG" event.data.data.type = "CLWALLET_CONTENT_MSG"
@ -68,7 +70,7 @@ window.addEventListener("message", (event) => {
if((event?.data?.data?.method ?? 'x') in allowedMethods) { if((event?.data?.data?.method ?? 'x') in allowedMethods) {
chrome.runtime.sendMessage(event.data.data, (res) => { chrome.runtime.sendMessage(event.data.data, (res) => {
const data = { type: "CLWALLET_PAGE", data: res, resId: event.data.resId }; const data = { type: "CLWALLET_PAGE", data: res, resId: event.data.resId };
console.log('data back', data) // console.log('data back', data)
window.postMessage(data, "*"); window.postMessage(data, "*");
}) })
} }

View File

@ -278,7 +278,7 @@ const listner = function(event: any) {
} }
promResolvers.delete(event.data.resId) promResolvers.delete(event.data.resId)
} catch (e) { } catch (e) {
console.log('Failed to connect resolve msg', e) // console.log('Failed to connect resolve msg', e)
} }
} else if( event.data.type && (event.data.type === "CLWALLET_PAGE_LISTENER")) { } else if( event.data.type && (event.data.type === "CLWALLET_PAGE_LISTENER")) {
if((event?.data?.data?.listner ?? 'x') in listners ) { if((event?.data?.data?.listner ?? 'x') in listners ) {
@ -290,7 +290,7 @@ const listner = function(event: any) {
(<any>eth).selectedAddress = event?.data?.data?.address ?? null; (<any>eth).selectedAddress = event?.data?.data?.address ?? null;
(<any>eth).isConnected = () => true; (<any>eth).isConnected = () => true;
} else if( listnerName === 'chainChanged' ) { } else if( listnerName === 'chainChanged' ) {
console.log(event?.data?.data?.data); // console.log(event?.data?.data?.data);
(<any>eth).networkVersion = event?.data?.data?.data.toString(10) ?? '137'; (<any>eth).networkVersion = event?.data?.data?.data.toString(10) ?? '137';
(<any>eth).chainId = event?.data?.data?.data ?? '0x89'; (<any>eth).chainId = event?.data?.data?.data ?? '0x89';
} else if ( listnerName === 'accountsChanged' ) { } else if ( listnerName === 'accountsChanged' ) {
@ -302,7 +302,7 @@ const listner = function(event: any) {
listners.once[listnerName].delete(listner) listners.once[listnerName].delete(listner)
}); });
} catch (e) { } catch (e) {
console.error(e) // console.error(e)
// ignore // ignore
} }
} }
@ -311,41 +311,23 @@ const listner = function(event: any) {
window.addEventListener("message",listner) window.addEventListener("message",listner)
const proxy1 = new Proxy({ // const proxy1 = new Proxy({
// on: (event: any, callback:any) => { if (event === 'message') { // // on: (event: any, callback:any) => { if (event === 'message') {
// debugger; // // debugger;
// callback(true, true) // // callback(true, true)
// } } // // } }
}, { // }, {
get: function(target, name, receiver) { // get: function(target, name, receiver) {
if (typeof (<any>target)[name] == 'function') { // if (typeof (<any>target)[name] == 'function') {
return function (...args: any) { // return function (...args: any) {
console.dir({ call: [name, ...args] }); // console.dir({ call: [name, ...args] });
} // }
} // }
console.log('ETH', name.toString() , target, receiver); // console.log('ETH', name.toString() , target, receiver);
return undefined // return undefined
} // }
}) // })
const proxy2 = new Proxy({
// on: (event: any, callback:any) => { if (event === 'message') {
// debugger;
// callback(true, true)
// } }
}, {
get: function(target, name, receiver) {
if (typeof (<any>target)[name] == 'function') {
return function (...args: any) {
console.dir({ call: [name, ...args] });
}
}
console.log('web3', name.toString() , target, receiver);
return undefined
}
})
const web3Shim = { const web3Shim = {
currentProvider: eth, currentProvider: eth,
@ -362,7 +344,7 @@ Object.defineProperty(win, 'web3', {
sendMessage({ sendMessage({
method: 'wallet_ready' method: 'wallet_ready'
}, true) }, true)
console.log('Clear wallet injected', (window as any).ethereum, win) // console.log('Clear wallet injected', (window as any).ethereum, win)
} }
injectWallet(this); injectWallet(this);

View File

@ -3,8 +3,8 @@
"name": "__MSG_appName__", "name": "__MSG_appName__",
"description": "__MSG_appDesc__", "description": "__MSG_appDesc__",
"default_locale": "en", "default_locale": "en",
"version": "1.1.4", "version": "1.1.5",
"version_name": "1.1.4", "version_name": "1.1.5",
"icons": { "icons": {
"16": "assets/extension-icon/wallet_16.png", "16": "assets/extension-icon/wallet_16.png",
"32": "assets/extension-icon/wallet_32.png", "32": "assets/extension-icon/wallet_32.png",
@ -20,9 +20,8 @@
"128": "assets/extension-icon/wallet_128.png" "128": "assets/extension-icon/wallet_128.png"
} }
}, },
"minimum_chrome_version": "93", "minimum_chrome_version": "94",
"permissions": [ "permissions": [
"tabs",
"notifications", "notifications",
"storage", "storage",
"alarms", "alarms",
@ -31,8 +30,7 @@
"clipboardWrite" "clipboardWrite"
], ],
"host_permissions": [ "host_permissions": [
"http://*/", "*://*/*"
"https://*/"
], ],
"background": { "background": {
"service_worker": "/src/extension/serviceWorker.ts", "service_worker": "/src/extension/serviceWorker.ts",
@ -49,9 +47,8 @@
"js": ["/src/extension/content.ts"] "js": ["/src/extension/content.ts"]
} }
], ],
"web_accessible_resources": [{ "web_accessible_resources": [{
"resources": ["src/extension/inject.js", "src/extension/webInject.js", "src/extension/content.js"], "resources": ["src/extension/inject.js"],
"matches": ["<all_urls>"] "matches": ["<all_urls>"]
}] }]
} }

View File

@ -1,399 +0,0 @@
const container = document.head
const script = document.createElement('script');
script.setAttribute('async', "false")
script.textContent = `
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var listners = {
accountsChanged: new Set(),
connect: new Set(),
disconnect: new Set(),
chainChanged: new Set(),
once: {
accountsChanged: new Set(),
connect: new Set(),
disconnect: new Set(),
chainChanged: new Set()
}
};
var promResolvers = new Map();
var getListnersCount = function () {
var _a;
var count = 0;
for (var _i = 0, _b = Object.keys(listners); _i < _b.length; _i++) {
var key = _b[_i];
if (key === 'once') {
for (var _c = 0, _d = Object.keys(listners[key]); _c < _d.length; _c++) {
var onceKey = _d[_c];
count += (_a = listners[key][onceKey]) === null || _a === void 0 ? void 0 : _a.length;
}
}
else {
count += listners[key].length;
}
}
return count;
};
var sendMessage = function (args, ping) {
if (ping === void 0) { ping = false; }
if (Object.values(promResolvers).filter(function (r) { return r; }).length < 10) {
return new Promise(function (resolve, reject) {
var resId = crypto.randomUUID();
promResolvers.set(resId, { resolve: resolve, reject: reject });
var data = { type: "CLWALLET_CONTENT", data: args, resId: resId };
if (ping) {
data.type = 'CLWALLET_PING';
}
// console.log('data in', data)
window.postMessage(data, "*");
});
}
else {
return new Promise(function (resolve, reject) {
reject(new Error("You have reached the maximum number of concurent wallet messeges."));
});
}
};
var MetaMaskAPI = /** @class */ (function () {
function MetaMaskAPI() {
this.isMetaMask = true;
this._state = { accounts: Array(1), isConnected: true, isUnlocked: true, initialized: true, isPermanentlyDisconnected: false };
this._sentWarnings = { enable: false, experimentalMethods: false, send: false, events: {} };
// Deprecated - hardcoded for now, websites should not access this directly since is deprecated for a long time
this.chainId = "0x89";
// Deprecated - hardcoded for now, websites should not access this directly since is deprecated for a long time
this.networkVersion = "137";
this.selectedAddress = null;
this.autoRefreshOnNetworkChange = false;
// Internal Simulate Metamask
this._events = {};
this._eventsCount = 2;
this._jsonRpcConnection = {};
this._log = {};
this._maxListeners = 100;
this._metamask = new Proxy({
isUnlocked: function () {
return Promise.resolve(true);
},
requestBatch: function () {
// empty
}
}, {});
this._rpcEngine = {
_events: {}, _eventsCount: 0, _maxListeners: undefined, _middleware: Array(4)
};
}
MetaMaskAPI.prototype.isConnected = function () {
return false;
};
// for maximum compatibility since is cloning the same API
MetaMaskAPI.prototype.enable = function () {
return sendMessage({ method: 'eth_requestAccounts', params: Array(0) });
};
MetaMaskAPI.prototype.request = function (args) {
return sendMessage(args);
};
// Deprecated
MetaMaskAPI.prototype.sendAsync = function (arg1, arg2) {
return this.send(arg1, arg2);
};
// Deprecated
MetaMaskAPI.prototype.send = function (arg1, arg2) {
if (typeof arg1 === 'string') {
return sendMessage({
method: arg1,
params: arg2
});
}
else if (arg2 === undefined) {
console.error('Clear Wallet: Sync calling is deprecated and not supported');
}
else {
sendMessage(arg1).then(function (result) {
if (typeof arg2 === 'function') {
arg2(undefined, {
id: arg1 === null || arg1 === void 0 ? void 0 : arg1.id,
jsonrpc: '2.0',
method: arg1.method,
result: result
});
}
})["catch"](function (e) {
arg2(new Error(e), {
id: arg1 === null || arg1 === void 0 ? void 0 : arg1.id,
jsonrpc: '2.0',
method: arg1.method,
error: new Error(e)
});
});
}
};
MetaMaskAPI.prototype.on = function (eventName, callback) {
this.addListener(eventName, callback);
return this;
};
MetaMaskAPI.prototype.addListener = function (eventName, callback) {
switch (eventName) {
case 'accountsChanged':
listners.accountsChanged.add(callback);
break;
case 'connect':
listners.connect.add(callback);
sendMessage({
method: 'wallet_ready'
}, true);
break;
case 'disconnect':
case 'close':
listners.disconnect.add(callback);
break;
// Deprecated - chainIdChanged -networkChanged
case 'chainChanged':
case 'chainIdChanged':
case 'networkChanged':
listners.chainChanged.add(callback);
break;
}
return this;
};
MetaMaskAPI.prototype.once = function (eventName, callback) {
switch (eventName) {
case 'accountsChanged':
listners.once.accountsChanged.add(callback);
break;
case 'connect':
listners.once.connect.add(callback);
sendMessage({
method: 'wallet_ready'
}, true);
break;
case 'disconnect':
case 'close':
listners.once.disconnect.add(callback);
break;
// Deprecated - chainIdChanged -networkChanged
case 'chainChanged':
case 'chainIdChanged':
case 'networkChanged':
listners.once.chainChanged.add(callback);
break;
}
return this;
};
MetaMaskAPI.prototype.off = function (eventName, callback) {
(this).removeListener(eventName, callback);
return this;
};
MetaMaskAPI.prototype.removeListener = function (eventName, callback) {
switch (eventName) {
case 'accountsChanged':
listners.accountsChanged["delete"](callback);
break;
case 'connect':
listners.connect["delete"](callback);
break;
case 'disconnect':
case 'close':
listners.disconnect["delete"](callback);
break;
// Deprecated - chainIdChanged -networkChanged
case 'chainChanged':
case 'chainIdChanged':
case 'networkChanged':
listners.chainChanged["delete"](callback);
break;
default:
return;
}
return this;
};
MetaMaskAPI.prototype.removeAllListeners = function () {
listners.accountsChanged.clear();
listners.chainChanged.clear();
listners.disconnect.clear();
listners.connect.clear();
return this;
};
MetaMaskAPI.prototype.getMaxListeners = function () {
return 100;
};
MetaMaskAPI.prototype._getExperimentalApi = function () {
return this._metamask;
};
MetaMaskAPI.prototype.eventNames = function () {
return [];
};
MetaMaskAPI.prototype.listenerCount = function () {
return getListnersCount();
};
MetaMaskAPI.prototype.listners = function () { return []; };
MetaMaskAPI.prototype.rawListners = function () { return []; };
// Internal Simulate Metamask
MetaMaskAPI.prototype._warnOfDeprecation = function () { return true; };
MetaMaskAPI.prototype._rpcRequest = function () { return true; };
MetaMaskAPI.prototype._handleAccountsChanged = function () { return true; };
MetaMaskAPI.prototype._handleChainChanged = function () { return true; };
MetaMaskAPI.prototype._handleConnect = function () { return true; };
MetaMaskAPI.prototype._handleDisconnect = function () { return true; };
MetaMaskAPI.prototype._handleStreamDisconnect = function () { return true; };
MetaMaskAPI.prototype._handleUnlockStateChanged = function () { return true; };
MetaMaskAPI.prototype._sendSync = function () {
console.error('Clear Wallet: Sync calling is deprecated and not supported');
};
return MetaMaskAPI;
}());
var eth = new Proxy(new MetaMaskAPI(), {
// set: () => { return true },
// get: function(target, name, receiver) {
// if (typeof (<any>target)[name] == 'function') {
// return function (...args: any) {
// console.dir({ call: [name, ...args] });
// return undefined;
// }
// }
// let check = true
// setTimeout(() => check = false, 400)
// while(check){
// // igmore
// }
// },
deleteProperty: function () { return false; }
});
var listner = function (event) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
if (event.source != window)
return;
if (event.data.type && (event.data.type === "CLWALLET_PAGE")) {
try {
if ((_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) {
(_c = promResolvers.get(event.data.resId)) === null || _c === void 0 ? void 0 : _c.reject(event.data.data);
console.error((_d = event === null || event === void 0 ? void 0 : event.data) === null || _d === void 0 ? void 0 : _d.data);
}
else {
(_e = promResolvers.get(event.data.resId)) === null || _e === void 0 ? void 0 : _e.resolve(event.data.data);
}
promResolvers["delete"](event.data.resId);
}
catch (e) {
console.log('Failed to connect resolve msg', e);
}
}
else if (event.data.type && (event.data.type === "CLWALLET_PAGE_LISTENER")) {
if (((_h = (_g = (_f = event === null || event === void 0 ? void 0 : event.data) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.listner) !== null && _h !== void 0 ? _h : 'x') in listners) {
try {
var listnerName_1 = (_k = (_j = event === null || event === void 0 ? void 0 : event.data) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.listner;
if (listnerName_1 === 'connect' && ((_m = (_l = event === null || event === void 0 ? void 0 : event.data) === null || _l === void 0 ? void 0 : _l.data) === null || _m === void 0 ? void 0 : _m.data)) {
eth.networkVersion = (_s = (_r = (_q = (_p = (_o = event === null || event === void 0 ? void 0 : event.data) === null || _o === void 0 ? void 0 : _o.data) === null || _p === void 0 ? void 0 : _p.data) === null || _q === void 0 ? void 0 : _q.chainId) === null || _r === void 0 ? void 0 : _r.toString(10)) !== null && _s !== void 0 ? _s : '137';
eth.chainId = (_w = (_v = (_u = (_t = event === null || event === void 0 ? void 0 : event.data) === null || _t === void 0 ? void 0 : _t.data) === null || _u === void 0 ? void 0 : _u.data) === null || _v === void 0 ? void 0 : _v.chainId) !== null && _w !== void 0 ? _w : '0x89';
eth.selectedAddress = (_z = (_y = (_x = event === null || event === void 0 ? void 0 : event.data) === null || _x === void 0 ? void 0 : _x.data) === null || _y === void 0 ? void 0 : _y.address) !== null && _z !== void 0 ? _z : null;
eth.isConnected = function () { return true; };
}
else if (listnerName_1 === 'chainChanged') {
console.log((_1 = (_0 = event === null || event === void 0 ? void 0 : event.data) === null || _0 === void 0 ? void 0 : _0.data) === null || _1 === void 0 ? void 0 : _1.data);
eth.networkVersion = (_4 = (_3 = (_2 = event === null || event === void 0 ? void 0 : event.data) === null || _2 === void 0 ? void 0 : _2.data) === null || _3 === void 0 ? void 0 : _3.data.toString(10)) !== null && _4 !== void 0 ? _4 : '137';
eth.chainId = (_7 = (_6 = (_5 = event === null || event === void 0 ? void 0 : event.data) === null || _5 === void 0 ? void 0 : _5.data) === null || _6 === void 0 ? void 0 : _6.data) !== null && _7 !== void 0 ? _7 : '0x89';
}
else if (listnerName_1 === 'accountsChanged') {
eth.selectedAddress = (_11 = (_10 = (_9 = (_8 = event === null || event === void 0 ? void 0 : event.data) === null || _8 === void 0 ? void 0 : _8.data) === null || _9 === void 0 ? void 0 : _9.data) === null || _10 === void 0 ? void 0 : _10.address) !== null && _11 !== void 0 ? _11 : 'dummy-string';
}
listners[listnerName_1].forEach(function (listner) { var _a, _b; return listner((_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.data); });
listners.once[listnerName_1].forEach(function (listner) {
var _a, _b;
listner((_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.data);
listners.once[listnerName_1]["delete"](listner);
});
}
catch (e) {
console.error(e);
// ignore
}
}
}
};
window.addEventListener("message", listner);
var proxy1 = new Proxy({
// on: (event: any, callback:any) => { if (event === 'message') {
// debugger;
// callback(true, true)
// } }
}, {
get: function (target, name, receiver) {
if (typeof target[name] == 'function') {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
console.dir({ call: __spreadArray([name], args, true) });
};
}
console.log('ETH', name.toString(), target, receiver);
return undefined;
}
});
var proxy2 = new Proxy({
// on: (event: any, callback:any) => { if (event === 'message') {
// debugger;
// callback(true, true)
// } }
}, {
get: function (target, name, receiver) {
if (typeof target[name] == 'function') {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
console.dir({ call: __spreadArray([name], args, true) });
};
}
console.log('web3', name.toString(), target, receiver);
return undefined;
}
});
var web3Shim = {
currentProvider: eth,
__isMetaMaskShim__: true
};
var injectWallet = function (win) {
Object.defineProperty(win, 'ethereum', {
value: eth
});
Object.defineProperty(win, 'web3', {
value: web3Shim
});
sendMessage({
method: 'wallet_ready'
}, true);
console.log('Clear wallet injected', window.ethereum, win);
};
injectWallet(this);
// setTimeout(() => {
// // console.log('Metamask clone test');
// // (<any>window).ethereum.request({method: 'eth_requestAccounts', params: Array(0)}).then((res: any) => { console.log(res, '111111111')});
// // (<any>window).ethereum.request({method: 'eth_accounts', params: Array(0)}).then((res: any) => { console.log(res, '111111111')});
// // (<any>window).ethereum.request({method: 'eth_chainId', params: Array(0)}).then((res: any) => { console.log(res, '111111111')});
// // (<any>window).ethereum.request({method: 'wallet_requestPermissions', params: [{eth_accounts: {}}]}).then((res: any) => { console.log(res, '111111111')});
// // (<any>window).ethereum.request({method: 'net_version', params: []}).then((res: any) => { console.log(res, '111111111')});
// // (<any>window).ethereum.request({method: 'wallet_switchEthereumChain', params: [{chainId: "0x89"}]}).then((res: any) => { console.log(res, '111111111')});
// // (<any>window).ethereum2.request({method: 'wallet_switchEthereumChain', params: [{chainId: "0x89"}]}).then((res: any) => { console.log(res, '111111111')});
// // (<any>window).ethereum.on('connect', ((a: any, b: any) => console.log('connect', a, b)));
// // (<any>window).ethereum.on('accountsChanged', ((a: any, b: any) => console.log('accountsChanged', a, b)));
// // (<any>window).ethereum.on('chainChanged', ((a: any) => console.log('chainChanged', a, typeof a)));
// // console.log((<any>window).ethereum.on('message', (a: any, b:any) => console.log(a,b)))
// console.log((<any>window).ethereum.toString())
// console.log((<any>window).ethereum2.toString())
// console.log((<any>window).ethereum.Symbold)
// }, 3500)
// console.log( (window as any).ethereum.request({method: 'eth_chainId'}))
`
container.prepend(script);
script.parentElement?.removeChild(script)