sign events working!

This commit is contained in:
Ryan Breen
2023-01-16 23:11:51 -05:00
parent 495cea8560
commit ffbf59ad17
3 changed files with 33 additions and 25 deletions

View File

@@ -3,13 +3,14 @@ script.setAttribute('src', browser.runtime.getURL('nostr.build.js'));
document.body.appendChild(script);
window.addEventListener('message', async (message) => {
let {kind, reqId} = message.data;
if (kind !== 'getPublicKey')
let {kind, reqId, payload} = message.data;
if (kind !== 'getPubKey' && kind !== 'signEvent')
return;
console.log(`Event ${reqId}: Content script received message kind ${kind}`);
let publicKey = await browser.runtime.sendMessage({kind: 'getPubKey'});
console.log(`Event ${reqId}: Public key retrieved; ${publicKey}`);
console.log(`Event ${reqId}: Content script received message kind ${kind}, payload: `, payload);
payload = await browser.runtime.sendMessage({kind, payload});
window.postMessage({kind: 'publicKey', reqId, payload: publicKey}, '*');
kind = `return_${kind}`;
window.postMessage({kind, reqId, payload}, '*');
});