[wip] everything is stupid and i hate everyone and everything
the correct thing to do at this point is to factor out "show a yes/no popup window to user" the complexity in "open a window and then execute some code in the context of that window" is mind-boggling nothing works
This commit is contained in:
+2
-1
@@ -10,4 +10,5 @@
|
||||
"default_title" : "Jæck Russell",
|
||||
"default_popup" : "pages/popup.html"},
|
||||
"background" : {"page" : "pages/background.html"},
|
||||
"permissions" : ["storage", "history"]}
|
||||
"permissions" : ["storage", "scripting"],
|
||||
"host_permissions" : ["*://*/*"]}
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
TODO
|
||||
- manifest v3
|
||||
- mansplaining better
|
||||
- factor out "show a popup window"
|
||||
- show correct pubkey on popup
|
||||
- seed oil recovery
|
||||
|
||||
MODEL
|
||||
|
||||
popup.html/popup.js
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<!-- HTML page for a "generic dialog" -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="title-h1"></h1>
|
||||
|
||||
<pre id="miscinfo"></pre>
|
||||
|
||||
<br>
|
||||
<button id="good">Yes</button>
|
||||
<br>
|
||||
<button id="bad">No</button>
|
||||
|
||||
<body>
|
||||
</html>
|
||||
@@ -1,20 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Is this message good or bad?</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Do you want to sign this message?</h1>
|
||||
|
||||
<pre id="message"></pre>
|
||||
|
||||
<br>
|
||||
<button id="good">Yes</button>
|
||||
<br>
|
||||
<button id="bad">No</button>
|
||||
|
||||
<script type="module" src="../dist/msg_confirm.js"></script>
|
||||
|
||||
<body>
|
||||
</html>
|
||||
@@ -1,25 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Do you want to sign this transaction?</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Do you want to sign this transaction?</h1>
|
||||
|
||||
<h2>Tx Base64</h2>
|
||||
<pre id="tx-base64"></pre>
|
||||
|
||||
|
||||
<h2>Tx Decomposed info</h2>
|
||||
<pre id="tx-decomposed"></pre>
|
||||
|
||||
<br>
|
||||
<button id="good">Yes</button>
|
||||
<br>
|
||||
<button id="bad">No</button>
|
||||
|
||||
<script type="module" src="../dist/tx_confirm.js"></script>
|
||||
|
||||
<body>
|
||||
</html>
|
||||
@@ -52,7 +52,7 @@ main
|
||||
let MIN = 60*SEC;
|
||||
//let n_max = 10*MIN;
|
||||
let n = 1;
|
||||
let n_max = 30*SEC;
|
||||
let n_max = 30*MIN;
|
||||
|
||||
// result starts as neutral
|
||||
// if user clicks good, result will be updated to 'good'
|
||||
+96
-20
@@ -319,7 +319,7 @@ bi_msg_handler_content
|
||||
case "message.sign":
|
||||
console.log('jr bg content message handler message sign');
|
||||
let msg_str : string = msg.data.params.message;
|
||||
// TODO: need to break here on whether the msg signature was good
|
||||
// TODONE: need to break here on whether the msg signature was good
|
||||
// (signed) or bad (not)
|
||||
let resultt = await msg_sign(msg_str, secret_key);
|
||||
if (resultt.result === 'good') {
|
||||
@@ -356,6 +356,9 @@ bi_msg_handler_content
|
||||
}
|
||||
|
||||
|
||||
type gb = 'good' | 'bad';
|
||||
|
||||
|
||||
/**
|
||||
* Fornicating js block scope rules
|
||||
*
|
||||
@@ -364,6 +367,9 @@ bi_msg_handler_content
|
||||
*
|
||||
* wojak.jpg
|
||||
*
|
||||
* Good result = user said yes
|
||||
* Bad result = user said no
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
async function
|
||||
@@ -375,26 +381,10 @@ msg_sign
|
||||
| {result : 'bad'}
|
||||
>
|
||||
{
|
||||
// does the user want to sign the message
|
||||
let confirm_window = await browser.windows.create({url : '../pages/msg_confirm.html',
|
||||
type : 'popup'});
|
||||
//console.log(confirm_window.tabs);
|
||||
|
||||
// @ts-ignore shut the fuck up
|
||||
let tabid : number = confirm_window.tabs[0].id;
|
||||
//console.log('tabid', tabid);
|
||||
|
||||
// stupid hack because otherwise the message gets sent before the listener in the page script is created
|
||||
await sleep(200);
|
||||
console.log('slept');
|
||||
|
||||
let result: 'good' | 'bad'
|
||||
= await browser.tabs.sendMessage(tabid, {msg_str : msg_str});
|
||||
//
|
||||
console.log('result', result);
|
||||
|
||||
// close the popup
|
||||
browser.tabs.remove(tabid);
|
||||
= await gb('Do you want to sign this message?',
|
||||
msg_str,
|
||||
30*GB_MIN);
|
||||
|
||||
// if confirm
|
||||
if
|
||||
@@ -490,10 +480,96 @@ tx_sign
|
||||
else {
|
||||
return {result : 'bad'};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let GB_ITERS = 1;
|
||||
let GB_SEC = 200*GB_ITERS;
|
||||
let GB_MIN = 60*GB_SEC;
|
||||
|
||||
/**
|
||||
* This pops up a window for the luser and asks if the thing is good or bad.
|
||||
*
|
||||
* Returns good or bad
|
||||
*
|
||||
* Timeout should be a multiple of 5. Use `GB_SEC` or `GB_MIN` because you're
|
||||
* stupid and can't do math.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
async function
|
||||
gb
|
||||
(title : string,
|
||||
miscinfo : string,
|
||||
timeout_ms : number)
|
||||
: Promise<gb>
|
||||
{
|
||||
console.log('507');
|
||||
// does the user want to sign the message
|
||||
let confirm_window = await browser.windows.create({url : '../pages/gb.html',
|
||||
type : 'popup'});
|
||||
console.log('509');
|
||||
|
||||
// @ts-ignore shut the fuck up
|
||||
let tabid : number = confirm_window.tabs[0].id;
|
||||
console.log('515');
|
||||
|
||||
function
|
||||
the_function_that_runs_in_the_context_of_gb_dot_html
|
||||
(gb_title : string,
|
||||
gb_miscinfo : string,
|
||||
gb_timeout_ms : number)
|
||||
: string
|
||||
{
|
||||
// FIXME: not alerting user about bobs
|
||||
alert('bobs!');
|
||||
//// the last evaluated statement of this function is the "return value"
|
||||
//// as far as scripting.executeScript is concerned
|
||||
//console.log('gb_title', gb_title);
|
||||
//console.log('gb_miscinfo', gb_miscinfo);
|
||||
//console.log('gb_timeout_ms', gb_timeout_ms);
|
||||
|
||||
//document.getElementById('title-h1')!.innerHTML = gb_title;
|
||||
|
||||
return 'good';
|
||||
}
|
||||
|
||||
console.log('badness');
|
||||
// @ts-ignore i'm just assuming typescript is going to be stupid here i don't even know
|
||||
let dialog_result: Array<{result: gb} | {error: any}> =
|
||||
await browser.scripting.executeScript(
|
||||
// @ts-ignore i'm just assuming typescript is going to be stupid here i don't even know
|
||||
{func : the_function_that_runs_in_the_context_of_gb_dot_html,
|
||||
args : [title, miscinfo, timeout_ms],
|
||||
target : {tabId : tabid},
|
||||
// script just hangs forever without this line
|
||||
// in no case does it alert user about bobs
|
||||
// alright
|
||||
// need a break
|
||||
// when we get back, let's try a file
|
||||
// otherwise we're going to have to try a totally different idiom
|
||||
// maybe go back to some retarded message passing nonsense
|
||||
injectImmediately: true
|
||||
}
|
||||
);
|
||||
|
||||
console.log('dialog_result', dialog_result[0]);
|
||||
// @ts-ignore
|
||||
if (dialog_result[0].error) {
|
||||
// @ts-ignore
|
||||
throw dialog_result.error;
|
||||
}
|
||||
else {
|
||||
// @ts-ignore
|
||||
return dialog_result[0].result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Make the dumb address_subscribe thing
|
||||
*
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/**
|
||||
* Page script for "confirm sign message" popup window
|
||||
*
|
||||
* For some reason getting "duplicate function implementation" errors from TSC
|
||||
* if I give these functions normal names
|
||||
*
|
||||
* Getting this error on both this file and tx_confirm.ts
|
||||
*
|
||||
* For some reason changing the names only in this file gets rid of the errors
|
||||
* in both files.
|
||||
*
|
||||
* No idea what the fuck is going on and I can almost guarantee I don't want to
|
||||
* know.
|
||||
*
|
||||
* Everything about this language is painful. You know I think a lot. I wonder
|
||||
* why everything is stupid. In any individual case, you can understand the
|
||||
* chain of incentives for why thing X is stupid. But the majority of things
|
||||
* should not be stupid. The stupid should be the exception. Instead the world
|
||||
* runs on the short bus tech stack.
|
||||
*/
|
||||
|
||||
|
||||
maine();
|
||||
|
||||
|
||||
async function
|
||||
maine
|
||||
()
|
||||
: Promise<void>
|
||||
{
|
||||
console.log('msg_confirm maine');
|
||||
|
||||
let result : '' | 'good' | 'bad'
|
||||
= '';
|
||||
|
||||
document.getElementById('good')!.onclick
|
||||
= function() {
|
||||
console.log('click good');
|
||||
result = 'good';
|
||||
};
|
||||
document.getElementById('bad')!.onclick
|
||||
= function() {
|
||||
console.log('click bad');
|
||||
result = 'bad';
|
||||
};
|
||||
|
||||
|
||||
type bg_msg
|
||||
= {msg_str : string};
|
||||
|
||||
async function listener
|
||||
(msg : bg_msg,
|
||||
_sender : any,
|
||||
_sendResponse : any)
|
||||
: Promise<'good' | 'bad'>
|
||||
{
|
||||
console.log('listener triggered', msg);
|
||||
console.log('msg_str:', msg.msg_str);
|
||||
document.getElementById('message')!.innerHTML = msg.msg_str;
|
||||
|
||||
// every 5 ms check
|
||||
// timeout of 10 minutes = 10*60 secs * 20 iterations =
|
||||
// number of iters in a full second
|
||||
let ITERS = 1;
|
||||
let SEC = 200*ITERS;
|
||||
let MIN = 60*SEC;
|
||||
//let n_max = 10*MIN;
|
||||
let n = 1;
|
||||
let n_max = 30*SEC;
|
||||
|
||||
while
|
||||
(result === '') {
|
||||
// if haven't timed out yet
|
||||
if (n <= n_max) {
|
||||
await sleepy(5);
|
||||
n = n + 1;
|
||||
}
|
||||
// if timed out
|
||||
else {
|
||||
result = 'bad';
|
||||
// this break is implied but you're not smart enough to figure
|
||||
// that out yourself
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// send result back
|
||||
return result;
|
||||
}
|
||||
|
||||
// add listener
|
||||
browser.runtime.onMessage.addListener(listener);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Hack from stack overflow somewhere to sleep for the given number of ms
|
||||
*/
|
||||
async function
|
||||
sleepy
|
||||
(ms: number)
|
||||
: Promise<void>
|
||||
{
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
Reference in New Issue
Block a user