Add missing files

This commit is contained in:
lash 2023-09-03 13:54:09 +01:00
parent f36f560edd
commit f345404416
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 354 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.pyc
__pycache__
build/*
dist/*
*.egg-info

20
js/booteth/eip1193.js Normal file
View File

@ -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);
};

9
js/booteth/package.json Normal file
View File

@ -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"
}
}

173
js/booteth/session.js Normal file
View File

@ -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;
}

117
js/booteth/wallet.js Normal file
View File

@ -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];
}

30
lets-encrypt-r3.pem Normal file
View File

@ -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
FHm0WeZ7tuXkAXOACIjIGlj26ZtuMDIGCCsGAQUFBwEBBCYwJD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