a thousand fixes and now signEvent and getPublic are fully working.

This commit is contained in:
fiatjaf
2022-01-10 21:18:55 -03:00
parent 233aaa0f8f
commit 0d38bc7eb3
7 changed files with 66 additions and 34 deletions

View File

@@ -8,22 +8,27 @@ script.setAttribute('src', browser.runtime.getURL('nostr-provider.js'))
document.head.appendChild(script)
// listen for messages from that script
window.addEventListener('message', async ev => {
if (ev.source !== window) return
if (!ev.data || ev.data.ext !== 'nos2x') {
// pass on to background
var response
try {
response = browser.runtime.sendMessage({
type: ev.data.type,
params: ev.data.params,
host: window.location.host
})
} catch (error) {
response = {error}
}
window.addEventListener('message', async message => {
if (message.source !== window) return
if (!message.data) return
if (!message.data.params) return
if (message.data.ext !== 'nos2x') return
// return response
window.postMessage({id: ev.data.id, ext: 'nos2x', response})
// pass on to background
var response
try {
response = await browser.runtime.sendMessage({
type: message.data.type,
params: message.data.params,
host: window.location.host
})
} catch (error) {
response = {error}
}
// return response
window.postMessage(
{id: message.data.id, ext: 'nos2x', response},
message.origin
)
})