Compare commits
2 Commits
07b680ed59
...
f345404416
Author | SHA1 | Date |
---|---|---|
lash | f345404416 | |
lash | f36f560edd |
|
@ -0,0 +1,5 @@
|
|||
*.pyc
|
||||
__pycache__
|
||||
build/*
|
||||
dist/*
|
||||
*.egg-info
|
|
@ -0,0 +1,20 @@
|
|||
// only pass it jsonrpcapiprovider or subclass
|
||||
function EIP1193DevWallet(baseProvider) {
|
||||
self.baseProvider = baseProvider;
|
||||
self.request = self._request_jsonrpc;
|
||||
}
|
||||
|
||||
EIP1193DevWallet.prototype.request_jsonrpc = async function(args) {
|
||||
let r = null;
|
||||
switch(args.method) {
|
||||
default:
|
||||
r = await self.baseProvider.send(args.method, args.params);
|
||||
}
|
||||
console.debug('provider result', r);
|
||||
return r;
|
||||
};
|
||||
|
||||
EIP1193DevWallet.prototype.request = async function(args) {
|
||||
console.debug('provider args', args);
|
||||
return this.request_jsonrpc(args);
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"devDependencies": {
|
||||
"ethers": "6.5.1",
|
||||
"jsqr": "^1.4.0",
|
||||
"openpgp": "^5.9.0",
|
||||
"qrcode": "1.5.3",
|
||||
"MimeJS": "git://git.defalsify.org/mime-js.git#lash/plain-part"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
openpgp.config.rejectCurves = new Set();
|
||||
|
||||
// pinched from https://stackoverflow.com/questions/16826200/javascript-silly-name-generator
|
||||
const name_parts = [
|
||||
["Runny", "Buttercup", "Dinky", "Stinky", "Crusty",
|
||||
"Greasy","Gidget", "Cheesypoof", "Lumpy", "Wacky", "Tiny", "Flunky",
|
||||
"Fluffy", "Zippy", "Doofus", "Gobsmacked", "Slimy", "Grimy", "Salamander",
|
||||
"Oily", "Burrito", "Bumpy", "Loopy", "Snotty", "Irving", "Egbert"],
|
||||
|
||||
["Waffer", "Lilly","Rugrat","Sand", "Fuzzy","Kitty",
|
||||
"Puppy", "Snuggles","Rubber", "Stinky", "Lulu", "Lala", "Sparkle", "Glitter",
|
||||
"Silver", "Golden", "Rainbow", "Cloud", "Rain", "Stormy", "Wink", "Sugar",
|
||||
"Twinkle", "Star", "Halo", "Angel"],
|
||||
["Snicker", "Buffalo", "Gross", "Bubble", "Sheep",
|
||||
"Corset", "Toilet", "Lizard", "Waffle", "Kumquat", "Burger", "Chimp", "Liver",
|
||||
"Gorilla", "Rhino", "Emu", "Pizza", "Toad", "Gerbil", "Pickle", "Tofu",
|
||||
"Chicken", "Potato", "Hamster", "Lemur", "Vermin"],
|
||||
["face", "dip", "nose", "brain", "head", "breath",
|
||||
"pants", "shorts", "lips", "mouth", "muffin", "butt", "bottom", "elbow",
|
||||
"honker", "toes", "buns", "spew", "kisser", "fanny", "squirt", "chunks",
|
||||
"brains", "wit", "juice", "shower"],
|
||||
];
|
||||
|
||||
function generateName() {
|
||||
name = '';
|
||||
for (let i = 0; i < name_parts.length; i++) {
|
||||
if (i > 0 && i < 3) {
|
||||
name += ' ';
|
||||
}
|
||||
const ii = Math.random() * name_parts[i].length;
|
||||
name += name_parts[i][Math.floor(ii)];
|
||||
}
|
||||
return name;
|
||||
}
|
||||
async function createSessionKey(passphrase) {
|
||||
const name = generateName();
|
||||
const k = await openpgp.generateKey({
|
||||
curve: 'secp256k1',
|
||||
userIDs: [{name: name, email: 'none@example.com'}],
|
||||
passphrase: passphrase,
|
||||
format: 'armored',
|
||||
});
|
||||
return k.privateKey;
|
||||
}
|
||||
|
||||
async function toKeyPair(pk, passphrase) {
|
||||
let o = await openpgp.readPrivateKey({
|
||||
armoredKey: pk,
|
||||
});
|
||||
if (!passphrase) {
|
||||
passphrase = undefined;
|
||||
}
|
||||
if (passphrase !== undefined) {
|
||||
o = await openpgp.decryptKey({
|
||||
privateKey: o,
|
||||
passphrase: passphrase,
|
||||
});
|
||||
}
|
||||
const r = o.toPacketList().findPacket(openpgp.enums.packet.secretKey);
|
||||
return {
|
||||
'publicKey': r.publicParams.Q,
|
||||
'privateKey': r.privateParams.d,
|
||||
};
|
||||
}
|
||||
|
||||
function SessionWallet() {
|
||||
this.provider = null;
|
||||
this.wallet_key = null;
|
||||
this.wallet = null;
|
||||
this.wallet_address = null;
|
||||
//self.wallet_address = "0xeb3907ecad74a0013c259d5874ae7f22dcbcc95c";
|
||||
}
|
||||
|
||||
async function ethKeyFromPGPKey(pk, passphrase) {
|
||||
const k = await toKeyPair(pk, passphrase);
|
||||
const signKey = new ethers.SigningKey(k.privateKey);
|
||||
return new ethers.Wallet(signKey);
|
||||
|
||||
}
|
||||
|
||||
SessionWallet.prototype.applyKey = async function(pk, passphrase) {
|
||||
this.wallet = await ethKeyFromPGPKey(pk, passphrase);
|
||||
this.wallet_key = pk;
|
||||
this.wallet_address = this.wallet.address;
|
||||
console.log('wallet key applied', this.wallet_address);
|
||||
}
|
||||
|
||||
SessionWallet.prototype.connect = async function(provider) {
|
||||
this.provider = provider;
|
||||
return this;
|
||||
}
|
||||
|
||||
SessionWallet.prototype.getAddress = function() {
|
||||
return this.wallet_address;
|
||||
}
|
||||
|
||||
SessionWallet.prototype.getNonce = async function() {
|
||||
return this.provider.send('eth_getTransactionCount', [this.wallet_address, 'latest']);
|
||||
}
|
||||
|
||||
async function sessionwallet_create(id, passphrase) {
|
||||
const w = new SessionWallet();
|
||||
if (window.localStorage.getItem('sessionKey_' + id) == null) {
|
||||
console.debug('creating new key');
|
||||
const newPk = await createSessionKey();
|
||||
const ethKey = await ethKeyFromPGPKey(newPk);
|
||||
const o = await openpgp.readKey({
|
||||
armoredKey: newPk,
|
||||
});
|
||||
let pl = o.toPacketList();
|
||||
let u = pl.findPacket(openpgp.enums.packet.userID);
|
||||
let a = ethKey.address;
|
||||
if (a.substring(0, 2) == '0x') {
|
||||
a = a.substring(2);
|
||||
}
|
||||
const uNew = openpgp.UserIDPacket.fromObject({
|
||||
name: u.name,
|
||||
email: a.toLowerCase() + '@defalsify.org',
|
||||
comment: "evm",
|
||||
});
|
||||
const r = await openpgp.reformatKey({
|
||||
privateKey: o,
|
||||
userIDs: [uNew],
|
||||
});
|
||||
let pku = await openpgp.readKey({
|
||||
armoredKey: r.privateKey,
|
||||
});
|
||||
if (passphrase !== undefined) {
|
||||
console.debug('encrypting');
|
||||
pku = await openpgp.encryptKey({
|
||||
privateKey: pku,
|
||||
passphrase: passphrase,
|
||||
|
||||
});
|
||||
}
|
||||
window.localStorage.setItem('sessionKey_' + id, pku.armor());
|
||||
pl = pku.toPacketList();
|
||||
u = pl.findPacket(openpgp.enums.packet.userID);
|
||||
console.debug('added key', u.name, u.email);
|
||||
}
|
||||
const pksrc = window.localStorage.getItem('sessionKey_' + id);
|
||||
console.debug('src', pksrc);
|
||||
let pk = await openpgp.readKey({
|
||||
armoredKey: pksrc,
|
||||
});
|
||||
if (passphrase !== undefined) {
|
||||
pk = await openpgp.decryptKey({
|
||||
privateKey: pk,
|
||||
passphrase: passphrase,
|
||||
});
|
||||
}
|
||||
await w.applyKey(pk.armor()); // the key is decrypted at this point
|
||||
return w;
|
||||
}
|
||||
|
||||
async function sessionwallet_importEth(id, passphrase) {
|
||||
const pk = window.localStorage.getItem('sessionKey_' + id);
|
||||
await ethers.Wallet.fromEncryptedJson(pk, passphrase);
|
||||
return pk;
|
||||
}
|
||||
|
||||
async function sessionwallet_exportEth(id, passphrase, progress) {
|
||||
const pk = window.localStorage.getItem('sessionKey_' + id);
|
||||
const w = await ethKeyFromPGPKey(pk, passphrase);
|
||||
const we = await w.encrypt(passphrase, progress);
|
||||
return we;
|
||||
}
|
||||
|
||||
async function sessionwallet_exportPgp(id, passphrase, progress) {
|
||||
const pk = window.localStorage.getItem('sessionKey_' + id);
|
||||
console.log(pk);
|
||||
return pk;
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
WALLETS = [
|
||||
'boot',
|
||||
'brave',
|
||||
'metamask',
|
||||
];
|
||||
|
||||
provider_rpc_url = 'http://localhost:8545';
|
||||
wallet_fallback = undefined;
|
||||
wallet_init = false;
|
||||
wallet_registered = {};
|
||||
provider_registered = {};
|
||||
var current_provider = null;
|
||||
var current_signer = null;
|
||||
ethers = undefined;
|
||||
|
||||
function register_ethers(m) {
|
||||
ethers = m;
|
||||
}
|
||||
|
||||
function wallet_register(wallet_key, wallet_constructor) {
|
||||
if (!wallet_key in WALLETS) {
|
||||
throw 'unknown wallet: ' + wallet;
|
||||
}
|
||||
if (wallet_registered[wallet_key] != undefined) {
|
||||
console.warn('wallet already registered', wallet_key);
|
||||
return;
|
||||
}
|
||||
console.log('registered wallet', wallet_key);
|
||||
wallet_registered[wallet_key] = wallet_constructor;
|
||||
}
|
||||
|
||||
function provider_register(provider_key, provider_constructor) {
|
||||
if (provider_registered[provider_key] != undefined) {
|
||||
console.warn('provider already registered', provider_key);
|
||||
return;
|
||||
}
|
||||
console.log('registered provider', provider_key);
|
||||
provider_registered[provider_key] = provider_constructor;
|
||||
}
|
||||
|
||||
async function wallet_connect(wallet_key, instanceId, passphrase) {
|
||||
if (!passphrase) {
|
||||
passphrase = undefined;
|
||||
}
|
||||
const fn = wallet_registered[wallet_key];
|
||||
let signer = await fn(instanceId, passphrase);
|
||||
let signed_connected;
|
||||
try {
|
||||
signer_connected = await signer.connect(current_provider);
|
||||
} catch(e) {
|
||||
console.debug('signer connect error', e);
|
||||
signer_connected = await current_provider.getSigner();
|
||||
}
|
||||
current_signer = signer_connected;
|
||||
console.log('connected to wallet', wallet_key, current_signer);
|
||||
return current_signer;
|
||||
}
|
||||
|
||||
async function provider_connect(provider_key) {
|
||||
const fn = provider_registered[provider_key];
|
||||
current_provider = await fn();
|
||||
console.log('registered provider', provider_key);
|
||||
return current_provider;
|
||||
}
|
||||
|
||||
function wallet_detect(ethers_instance) {
|
||||
if (wallet_init) {
|
||||
return;
|
||||
}
|
||||
ethers = ethers_instance;
|
||||
if (wallet_fallback !== undefined) {
|
||||
wallet_register('default', wallet_fallback);
|
||||
}
|
||||
if (window.ethereum != null) {
|
||||
if (window.ethereum.isBraveWallet) {
|
||||
wallet_register('brave', metamaskish_signer_connect);
|
||||
provider_register('brave', metamaskish_provider_connect);
|
||||
} else if (window.ethereum.isMetaMask) {
|
||||
wallet_register('metamask', metamaskish_signer_connect);
|
||||
provider_register('metamask', metamaskish_provider_connect);
|
||||
}
|
||||
}
|
||||
wallet_init = true;
|
||||
}
|
||||
|
||||
async function metamaskish_provider_connect() {
|
||||
let provider;
|
||||
return new ethers.BrowserProvider(window.ethereum)
|
||||
}
|
||||
|
||||
async function metamaskish_signer_connect() {
|
||||
let signer_provider;
|
||||
if (current_provider != null) {
|
||||
signer_provider = current_provider;
|
||||
} else {
|
||||
current_provider = new ethers.BrowserProvider(window.ethereum);
|
||||
signer_provider = current_provider;
|
||||
}
|
||||
return await signer_provider.getSigner();
|
||||
}
|
||||
|
||||
async function jsonrpc_provider_connect(url) {
|
||||
if (url === undefined) {
|
||||
url = provider_rpc_url;
|
||||
}
|
||||
return new ethers.JsonRpcProvider(url);
|
||||
}
|
||||
|
||||
function getWallet(id) {
|
||||
return wallet_registered[id];
|
||||
}
|
||||
|
||||
provider_register('default', jsonrpc_provider_connect);
|
||||
|
||||
function getProvider(id) {
|
||||
return provider_registered[id];
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>gas3</title>
|
||||
<script defer src="node_modules/alpinejs/dist/cdn.min.js"></script>
|
||||
<script src="node_modules/openpgp/dist/openpgp.min.js"></script>
|
||||
<script src="node_modules/MimeJS/src/base64.js"></script>
|
||||
<script src="node_modules/MimeJS/dist/mime-js.min.js"></script>
|
||||
<script src="run.js"></script>
|
||||
<script src="booteth/wallet.js"></script>
|
||||
<script src="booteth/session.js"></script>
|
||||
<script src="booteth/eip1193.js"></script>
|
||||
<script src="registry.js"></script>
|
||||
<script src="rpc.js"></script>
|
||||
<script type="module" src="main.js"></script>
|
||||
<script>
|
||||
wallet_fallback = sessionwallet_create;
|
||||
wallet_detect(ethers);
|
||||
</script>
|
||||
<link rel="stylesheet" type="text/css" href="style.css"></link>
|
||||
</head>
|
||||
|
||||
<body x-data='{
|
||||
needKey: false,
|
||||
error: "",
|
||||
lock: true,
|
||||
menuSelected: "main",
|
||||
}
|
||||
' >
|
||||
|
||||
<ul id="menu"
|
||||
x-data='{
|
||||
keyTitle: "unlock key",
|
||||
}'>
|
||||
<li><a id="menuKey" href="javascript:void(null);" x-text='keyTitle' @click='menuSelected="main"' ></a>
|
||||
<li><a href="javascript:void(null);" id="menuStatus" @click='menuSelected="state"'>status</a>
|
||||
<div id="main"
|
||||
x-show='needKey && menuSelected == "main"'
|
||||
@messagestatechange.window='
|
||||
if (checkState(STATE.LOCAL_KEY_PROBE, $event.detail.state)) {
|
||||
needKey = true;
|
||||
}
|
||||
if (checkState(STATE.LOCAL_KEY_REQUEST | STATE.LOCAL_KEY_UNLOCK, $event.detail.state)) {
|
||||
error = undefined;
|
||||
}
|
||||
if (checkState(STATE.LOCAL_KEY_REJECT, $event.detail.state)) {
|
||||
error = $event.detail.s;
|
||||
}
|
||||
if (checkState(STATE.LOCAL_KEY_UNLOCK, $event.detail.state)) {
|
||||
needKey = false;
|
||||
lock = false;
|
||||
}
|
||||
'
|
||||
>
|
||||
<form onSubmit='return false;'>
|
||||
<input type="password" name="passphrase" id="passphrase" /><br/>
|
||||
<button id="passphraseUnlock"
|
||||
x-data='{
|
||||
keyTitle: "enter new pin",
|
||||
}
|
||||
'
|
||||
x-text='keyTitle'
|
||||
@messagestatechange.window='
|
||||
if (checkState(STATE.LOCAL_KEY, $event.detail.state)) {
|
||||
keyTitle = "unlock key with pin";
|
||||
}
|
||||
'
|
||||
x-on:click='stateChange("unlock key request", STATE.LOCAL_KEY_REQUEST);'
|
||||
></button>
|
||||
<form>
|
||||
<br/><span id="keyError" class="error"
|
||||
x-text='error'
|
||||
></span>
|
||||
</div>
|
||||
|
||||
<div id="state"
|
||||
x-show='menuSelected == "state"'
|
||||
x-data='{
|
||||
stateKey: "locked",
|
||||
stateEvm: "disconnected",
|
||||
stateBalance: "0",
|
||||
stateAddress: "unknown",
|
||||
}
|
||||
'
|
||||
|
||||
@messagestatechange.window='
|
||||
if (checkState(STATE.LOCAL_KEY_UNLOCK, $event.detail.state)) {
|
||||
stateKey = "unlocked";
|
||||
}
|
||||
if (checkState(STATE.RPC_CONNECT, $event.detail.state)) {
|
||||
stateEvm = "connected";
|
||||
}
|
||||
console.debug("state", $event.detail.s);
|
||||
if (checkState(STATE.RPC_PING, $event.detail.state)) {
|
||||
stateBalance = $event.detail.s["balance"];
|
||||
stateAddress = $event.detail.s["address"];
|
||||
stateChange("reset ping", 0, STATE.RPC_PING);
|
||||
}
|
||||
'
|
||||
>
|
||||
<dl>
|
||||
<dt>Key</dt>
|
||||
<dd x-text='stateKey'>
|
||||
<dt>Address</dt>
|
||||
<dd x-text='stateAddress'>
|
||||
<dt>Balance</dt>
|
||||
<dd x-text='stateBalance'>
|
||||
</dl>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,67 @@
|
|||
import { ethers } from "./node_modules/ethers/dist/ethers.min.js";
|
||||
register_ethers(ethers);
|
||||
|
||||
var connect = connect_manual_session;
|
||||
|
||||
async function checkKey() {
|
||||
const r = localStorage.getItem(KEY_STORAGEKEY);
|
||||
if (r) {
|
||||
stateChange('found existing key', STATE.LOCAL_KEY, STATE.LOCAL_KEY_PROBE);
|
||||
}
|
||||
}
|
||||
|
||||
// router
|
||||
var initRouter = async (e) => {
|
||||
if (checkState(STATE.LOCAL_KEY_REQUEST, e.detail.state)) {
|
||||
stateChange('process key unlock request', 0, STATE.LOCAL_KEY_REQUEST | STATE.LOCAL_KEY_PROBE | STATE.LOCAL_KEY_REJECT);
|
||||
checkKey();
|
||||
const v = document.getElementById('passphrase').value;
|
||||
const r = await connect(v);
|
||||
if (r) {
|
||||
stateChange('key request finished', STATE.LOCAL_KEY_UNLOCK, );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
async function connect_manual_session(pw) {
|
||||
let provider = undefined;
|
||||
let wallet = undefined;
|
||||
try {
|
||||
provider = await provider_connect('default');
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
if (!provider) {
|
||||
stateChange('no provider', STATE.RPC_GONE, STATE.LOCAL_KEY_REQUEST);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
wallet = await wallet_connect('default', SESSION_ID, pw);
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
if (!wallet) {
|
||||
stateChange('wallet unlock fail', STATE.LOCAL_KEY_REJECT, STATE.LOCAL_KEY_REQUEST);
|
||||
return;
|
||||
}
|
||||
checkRpc();
|
||||
scanRegistry(g_registry);
|
||||
return wallet;
|
||||
}
|
||||
|
||||
function checkRpc() {
|
||||
pingRpc();
|
||||
setTimeout(checkRpc, 3000);
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
window.addEventListener('messagestatechange', initRouter);
|
||||
if (DEBUG) {
|
||||
window.addEventListener('messagestatechange', (e) => {
|
||||
console.debug('state change:', e.detail.s);
|
||||
});
|
||||
}
|
||||
stateChange('init key', STATE.LOCAL_KEY_PROBE);
|
||||
});
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "gas3",
|
||||
"version": "0.0.1-alpha.1",
|
||||
"dependencies": {
|
||||
"alpinejs": "3.10.3",
|
||||
"openpgp": "5.5.0",
|
||||
"jssha": "3.2.0",
|
||||
"MimeJS": "git://git.defalsify.org/mime-js.git#lash/plain-part",
|
||||
"jsqr": "^1.4.0",
|
||||
"qrcode": "1.5.3",
|
||||
"ethers": "6.5.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
const registryInterface = [{"inputs":[{"internalType":"bytes32[]","name":"_identifiers","type":"bytes32[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"_key","type":"bytes32"},{"indexed":false,"internalType":"address","name":"_address","type":"address"}],"name":"AddressKey","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"_newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"identifier","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"identifierCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"},{"internalType":"address","name":"_address","type":"address"}],"name":"set","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}];
|
||||
|
||||
async function scanRegistry(registry) {
|
||||
const o = new ethers.Contract(registry, registryInterface, current_provider);
|
||||
let i = 0;
|
||||
let r = {};
|
||||
while (true) {
|
||||
let identifier;
|
||||
try {
|
||||
identifier = await o.identifier(i);
|
||||
} catch(e) {
|
||||
break;
|
||||
}
|
||||
if (!identifier) {
|
||||
break;
|
||||
}
|
||||
const v = await o.addressOf(identifier);
|
||||
r[identifier] = v;
|
||||
console.debug('found ' + identifier + '=' + v + ' in registry ' + registry);
|
||||
i++;
|
||||
}
|
||||
return r;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
async function pingRpc() {
|
||||
const address = await current_signer.getAddress();
|
||||
const balance = await current_provider.getBalance(address);
|
||||
let set = STATE.RPC_PING;
|
||||
let rst = 0;
|
||||
let r = {
|
||||
balance: balance,
|
||||
address: address,
|
||||
}
|
||||
if (balance < g_minBalance) {
|
||||
set |= STATE.EVM_BALANCE_LOW;
|
||||
} else {
|
||||
rst = STATE.EVM_BALANCE_LOW;
|
||||
}
|
||||
stateChange(r, set, rst);
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
var STATE = {
|
||||
LOCAL_KEY: 1 << 0,
|
||||
LOCAL_KEY_PROBE: 1 << 1,
|
||||
LOCAL_KEY_REQUEST: 1 << 2,
|
||||
LOCAL_KEY_REJECT: 1 << 3,
|
||||
LOCAL_KEY_UNLOCK: 1 << 4,
|
||||
LOCAL_KEY_LOCK: 1 << 5,
|
||||
RPC_CONNECT: 1 << 6,
|
||||
RPC_CHANGE: 1 << 7,
|
||||
RPC_GONE: 1 << 8,
|
||||
RPC_PING: 1 << 9,
|
||||
EVM_BALANCE_LOW: 1 << 10,
|
||||
};
|
||||
const STATE_KEYS = Object.keys(STATE);
|
||||
var g_state = 0;
|
||||
var g_chainId = 1337;
|
||||
var g_balance = 0;
|
||||
var g_minBalance = 10000000;
|
||||
var g_registry = '0xb708175e3f6cd850643aaf7b32212afad50e2549';
|
||||
|
||||
const DEBUG = true;
|
||||
const SESSION_ID = 'gasgasgas';
|
||||
const KEY_STORAGEKEY = 'sessionKey_' + SESSION_ID;
|
||||
|
||||
const qp = new URLSearchParams(window.location.search);
|
||||
|
||||
// borrowed from forro
|
||||
async function stateChange(s, set_states, rst_states) {
|
||||
if (!set_states) {
|
||||
set_states = [];
|
||||
} else if (!Array.isArray(set_states)) {
|
||||
set_states = [set_states];
|
||||
}
|
||||
if (!rst_states) {
|
||||
rst_states = [];
|
||||
} else if (!Array.isArray(rst_states)) {
|
||||
rst_states = [rst_states];
|
||||
}
|
||||
let new_state = g_state;
|
||||
for (let i = 0; i < set_states.length; i++) {
|
||||
let state = parseInt(set_states[i]);
|
||||
new_state |= state;
|
||||
}
|
||||
for (let i = 0; i < rst_states.length; i++) {
|
||||
let state = parseInt(set_states[i]);
|
||||
new_state = new_state & (0xffffffff & ~rst_states[i]);
|
||||
}
|
||||
old_state = g_state;
|
||||
g_state = new_state;
|
||||
|
||||
const ev = new CustomEvent('messagestatechange', {
|
||||
bubbles: true,
|
||||
cancelable: false,
|
||||
composed: true,
|
||||
detail: {
|
||||
s: s,
|
||||
old_state: old_state,
|
||||
state: new_state,
|
||||
},
|
||||
});
|
||||
window.dispatchEvent(ev);
|
||||
}
|
||||
|
||||
function checkState(bit_check, bit_field) {
|
||||
if (bit_field != 0 && !bit_field) {
|
||||
bit_field = g_state;
|
||||
}
|
||||
return (bit_check & bit_field) > 0;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
body {}
|
||||
|
||||
.error {
|
||||
color: #ff0000;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw
|
||||
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMjAwOTA0MDAwMDAw
|
||||
WhcNMjUwOTE1MTYwMDAwWjAyMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg
|
||||
RW5jcnlwdDELMAkGA1UEAxMCUjMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
|
||||
AoIBAQC7AhUozPaglNMPEuyNVZLD+ILxmaZ6QoinXSaqtSu5xUyxr45r+XXIo9cP
|
||||
R5QUVTVXjJ6oojkZ9YI8QqlObvU7wy7bjcCwXPNZOOftz2nwWgsbvsCUJCWH+jdx
|
||||
sxPnHKzhm+/b5DtFUkWWqcFTzjTIUu61ru2P3mBw4qVUq7ZtDpelQDRrK9O8Zutm
|
||||
NHz6a4uPVymZ+DAXXbpyb/uBxa3Shlg9F8fnCbvxK/eG3MHacV3URuPMrSXBiLxg
|
||||
Z3Vms/EY96Jc5lP/Ooi2R6X/ExjqmAl3P51T+c8B5fWmcBcUr2Ok/5mzk53cU6cG
|
||||
/kiFHaFpriV1uxPMUgP17VGhi9sVAgMBAAGjggEIMIIBBDAOBgNVHQ8BAf8EBAMC
|
||||
AYYwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMBIGA1UdEwEB/wQIMAYB
|
||||
Af8CAQAwHQYDVR0OBBYEFBQusxe3WFbLrlAJQOYfr52LFMLGMB8GA1UdIwQYMBaA
|
||||
FHm0WeZ7tuXkAXOACIjIGlj26ZtuMDIGCCsGAQUFBwEBBCYwJDAiBggrBgEFBQcw
|
||||
AoYWaHR0cDovL3gxLmkubGVuY3Iub3JnLzAnBgNVHR8EIDAeMBygGqAYhhZodHRw
|
||||
Oi8veDEuYy5sZW5jci5vcmcvMCIGA1UdIAQbMBkwCAYGZ4EMAQIBMA0GCysGAQQB
|
||||
gt8TAQEBMA0GCSqGSIb3DQEBCwUAA4ICAQCFyk5HPqP3hUSFvNVneLKYY611TR6W
|
||||
PTNlclQtgaDqw+34IL9fzLdwALduO/ZelN7kIJ+m74uyA+eitRY8kc607TkC53wl
|
||||
ikfmZW4/RvTZ8M6UK+5UzhK8jCdLuMGYL6KvzXGRSgi3yLgjewQtCPkIVz6D2QQz
|
||||
CkcheAmCJ8MqyJu5zlzyZMjAvnnAT45tRAxekrsu94sQ4egdRCnbWSDtY7kh+BIm
|
||||
lJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML+Hbisq/yFOGwXD9RiX8F6sw6W4
|
||||
avAuvDszue5L3sz85K+EC4Y/wFVDNvZo4TYXao6Z0f+lQKc0t8DQYzk1OXVu8rp2
|
||||
yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1O
|
||||
yK5GhDDX8oVfGKF5u+decIsH4YaTw7mP3GFxJSqv3+0lUFJoi5Lc5da149p90Ids
|
||||
hCExroL1+7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0+L4WPlbuEjN/lxPFin+
|
||||
HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6Zv
|
||||
MldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqX
|
||||
nLRbwHOoq7hHwg==
|
||||
-----END CERTIFICATE-----
|
Loading…
Reference in New Issue