Chrome: nos2x is undefined when trying to signEvent
Opened this issue · 1 comments
mirzabusatlic commented
I'm able to fetch the public key from the extension, and when I call window.nostr.signEvent
, it does ask me to give permissions to post the event. When I choose "Allow for 5 minutes", I get the error nos2x is undefined
.
Not sure if I'm doing something wrong but I couldn't find any resources on how to fix this...
Note that 'pubkey' is not set on the event. Setting it before validateEvent
causes that method to return false
. Setting event.pubkey = pubkey
after validateEvent
still produces the error...
signEvent(event)
{
return new Promise((resolve, reject) => {
if (window.nostr) {
return window.nostr.getPublicKey().then(pubkey => {
let validEvent = validateEvent(event); // `validateEvent` from nostr-tools
console.log('Event is valid:', validEvent); // True
return window.nostr.signEvent(event).then(response => {
// Does not enter here...
//resolve(event);
}).catch(error => {
reject(error); // Error occurs here 'nos2x: undefined'
});
}).catch(error => { // Did not get public key
reject(error);
});
} else { // window.nostr undefined
reject('window.nostr undefined');
}
});
},
monlovesmango commented
hmm i could not replicate your error. this code runs for me.
signEvent will automatically add id and pubkey if they are missing. can you just try:
signEvent(event)
{
return new Promise((resolve, reject) => {
if (window.nostr) {
return window.nostr.signEvent(event).then(response => {
// Does not enter here...
//resolve(event);
}).catch(error => {
reject(error); // Error occurs here 'nos2x: undefined'
});
} else { // window.nostr undefined
reject('window.nostr undefined');
}
});
},