From e677822f43a4217d929adef63cb9e0e1a9a77041 Mon Sep 17 00:00:00 2001 From: Peter Harpending Date: Sat, 7 Oct 2023 23:14:14 -0600 Subject: [PATCH] [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 --- jrx/manifest.json | 3 +- jrx/notes.txt | 7 ++ jrx/pages/gb.html | 19 +++ jrx/pages/msg_confirm.html | 20 --- jrx/pages/tx_confirm.html | 25 ---- .../tx_confirm.ts => scratch/gen_dialog.ts} | 2 +- jrx/src/b_lib.ts | 116 +++++++++++++++--- jrx/src/msg_confirm.ts | 106 ---------------- 8 files changed, 125 insertions(+), 173 deletions(-) create mode 100644 jrx/pages/gb.html delete mode 100644 jrx/pages/msg_confirm.html delete mode 100644 jrx/pages/tx_confirm.html rename jrx/{src/tx_confirm.ts => scratch/gen_dialog.ts} (98%) delete mode 100644 jrx/src/msg_confirm.ts diff --git a/jrx/manifest.json b/jrx/manifest.json index 4b86d56..8ffa813 100644 --- a/jrx/manifest.json +++ b/jrx/manifest.json @@ -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" : ["*://*/*"]} diff --git a/jrx/notes.txt b/jrx/notes.txt index 14f20a9..7a4ce0c 100644 --- a/jrx/notes.txt +++ b/jrx/notes.txt @@ -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 diff --git a/jrx/pages/gb.html b/jrx/pages/gb.html new file mode 100644 index 0000000..939e9e2 --- /dev/null +++ b/jrx/pages/gb.html @@ -0,0 +1,19 @@ + + + + + + + + +

+ +

+
+
+ +
+ + + + diff --git a/jrx/pages/msg_confirm.html b/jrx/pages/msg_confirm.html deleted file mode 100644 index 3a689c4..0000000 --- a/jrx/pages/msg_confirm.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - Is this message good or bad? - - -

Do you want to sign this message?

- -

-
-
- -
- - - - - - diff --git a/jrx/pages/tx_confirm.html b/jrx/pages/tx_confirm.html deleted file mode 100644 index 26f9ec5..0000000 --- a/jrx/pages/tx_confirm.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - Do you want to sign this transaction? - - -

Do you want to sign this transaction?

- -

Tx Base64

-

-
-
-

Tx Decomposed info

-

-
-
- -
- - - - - - diff --git a/jrx/src/tx_confirm.ts b/jrx/scratch/gen_dialog.ts similarity index 98% rename from jrx/src/tx_confirm.ts rename to jrx/scratch/gen_dialog.ts index 7f712a5..9170d2d 100644 --- a/jrx/src/tx_confirm.ts +++ b/jrx/scratch/gen_dialog.ts @@ -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' diff --git a/jrx/src/b_lib.ts b/jrx/src/b_lib.ts index 5f04aab..7b1bef3 100644 --- a/jrx/src/b_lib.ts +++ b/jrx/src/b_lib.ts @@ -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 +{ + 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 * diff --git a/jrx/src/msg_confirm.ts b/jrx/src/msg_confirm.ts deleted file mode 100644 index a517835..0000000 --- a/jrx/src/msg_confirm.ts +++ /dev/null @@ -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 -{ - 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 -{ - return new Promise(resolve => setTimeout(resolve, ms)); -}