[wip] getting keypair stuff to work
This commit is contained in:
+73
-14
@@ -17,20 +17,11 @@ function post_detect_msg() {
|
||||
window.postMessage(detect_awcp_msg, '*');
|
||||
}
|
||||
|
||||
function post_connect_msg(msg_ident) {
|
||||
// : EventData_W2A_connection_open
|
||||
// http://localhost:6969/local-awcp-0.2.1/types/EventData_W2A_connection_open.html
|
||||
let connect_response =
|
||||
{type: "to_aepp",
|
||||
data: {jsonrpc: "2.0",
|
||||
id: msg_ident,
|
||||
method: "connection.open",
|
||||
result: detect_msg}};
|
||||
window.postMessage(connect_response, '*');
|
||||
}
|
||||
|
||||
async function mk_detectable() {
|
||||
while (true) {
|
||||
//while (true) {
|
||||
// 3 seconds times 40 is 2 minutes
|
||||
for (let i=1; i<=40; i++) {
|
||||
console.error('pee');
|
||||
post_detect_msg();
|
||||
await sleep(3000);
|
||||
@@ -42,6 +33,9 @@ function sleep(ms) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This handles messages from *other parts of the extension*
|
||||
*/
|
||||
function handler(msg) {
|
||||
console.error('message: ', msg);
|
||||
switch(msg) {
|
||||
@@ -53,6 +47,9 @@ function handler(msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This handles messages from page scripts
|
||||
*/
|
||||
function window_message_handler(msg) {
|
||||
console.error('the science is coming', msg);
|
||||
// example science:
|
||||
@@ -80,6 +77,15 @@ function window_message_handler(msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* window_message_handler handles all messages sent into the event bus,
|
||||
* including messages that we sent (yay js). window_message_handler branches on
|
||||
* whether the message is for us or not (is the science good or bad?). If the
|
||||
* message is for us (the science is good), then this function is triggered.
|
||||
*
|
||||
* The bottom line is this is the function that *actually* handles messages
|
||||
* from the window
|
||||
*/
|
||||
function the_science_is_good(awcp_rcp_data) {
|
||||
// example science data:
|
||||
// // layer 3: json rpc
|
||||
@@ -92,19 +98,72 @@ function the_science_is_good(awcp_rcp_data) {
|
||||
// can assume it is a call
|
||||
let msg_ident = awcp_rcp_data.id;
|
||||
let msg_method = awcp_rcp_data.method;
|
||||
// branch here on the "method" field
|
||||
switch (msg_method) {
|
||||
case "connection.open":
|
||||
post_connect_msg(msg_ident);
|
||||
return;
|
||||
break;
|
||||
case "address.subscribe":
|
||||
bg_address_subscribe(msg_ident);
|
||||
break;
|
||||
case "transaction.sign":
|
||||
bg_tx_sign(msg_ident, awcp_rcp_data.params);
|
||||
break;
|
||||
case "message.sign":
|
||||
bg_msg_sign(msg_ident, awcp_rcp_data.params);
|
||||
break;
|
||||
default:
|
||||
console.error('the science is worse than i initially thought');
|
||||
console.error("we're going to have to put the science to sleep");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in response to "connection.open" requests from page scripts
|
||||
*
|
||||
* FIXME: this should query the user to see if he wants to connect
|
||||
*/
|
||||
function post_connect_msg(msg_ident) {
|
||||
// : EventData_W2A_connection_open
|
||||
// http://localhost:6969/local-awcp-0.2.1/types/EventData_W2A_connection_open.html
|
||||
let connect_response =
|
||||
{type: "to_aepp",
|
||||
data: {jsonrpc: "2.0",
|
||||
id: msg_ident,
|
||||
method: "connection.open",
|
||||
result: detect_msg}};
|
||||
window.postMessage(connect_response, '*');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called in response to "address.subscribe" requests from page scripts
|
||||
*
|
||||
* this is to get the wallet's address
|
||||
*/
|
||||
function bg_address_subscribe(msg_ident) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called in response to "transaction.sign" requests from page scripts
|
||||
*
|
||||
* user wants us to sign a transaction
|
||||
*/
|
||||
function bg_tx_sign(msg_ident, params) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in response to "message.sign" requests from page scripts
|
||||
*
|
||||
* user wants us to sign a message
|
||||
*/
|
||||
function bg_msg_sign(msg_ident, params) {
|
||||
}
|
||||
|
||||
browser.runtime.onMessage.addListener(handler);
|
||||
window.addEventListener('message', window_message_handler);
|
||||
//window.addEventListener('message', function(evt) { console.error('BYYYYYYYYYYYYYYY', evt) });
|
||||
window.addEventListener('click', function() { console.error('HERRRO'); });
|
||||
//window.addEventListener('click', function() { console.error('HERRRO'); });
|
||||
|
||||
console.error('poop');
|
||||
|
||||
Reference in New Issue
Block a user