fiatjaf / nos2x

nostr signer extension
278 stars 55 forks source link

Problem with webextension-polyfill #58

Closed Anderson-Juhasc closed 5 months ago

Anderson-Juhasc commented 5 months ago

I had to add the script webextension-polyfill to run, but now I have this problem when I try to save private key in Uint8Array format:

Uncaught (in promise) Error: Cannot serialize value to JSON at browser-polyfill.js:772:26

@fiatjaf how did you solve this?

Thanks.

Anderson-Juhasc commented 5 months ago

Well, I'm not sure if it's a right way but worked, I tried this code to encode and decode the private key saved in local storage:

Encode: const myUint8Array = new Uint8Array([10, 20, 30]); const encodedString = btoa(String.fromCharCode.apply(null, myUint8Array)); localStorage.setItem('myDataKey', encodedString);

Decode: const encodedString = localStorage.getItem('myDataKey'); const decodedString = atob(encodedString); const uint8Array = Uint8Array.from(decodedString.split('').map(c => c.charCodeAt(0)));

fiatjaf commented 5 months ago

Recent nostr-tools versions are return private keys in Uint8Array:

https://github.com/nbd-wtf/nostr-tools/pull/389/files