You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nostrweb/src/settings.ts

34 lines
758 B
TypeScript

import {generatePrivateKey, getPublicKey} from 'nostr-tools';
let pubkey = '';
const loadOrGeneraateKeys = () => {
const storedPubKey = localStorage.getItem('pub_key');
if (storedPubKey) {
return storedPubKey;
}
const privatekey = generatePrivateKey();
const pubkey = getPublicKey(privatekey);
localStorage.setItem('private_key', privatekey);
localStorage.setItem('pub_key', pubkey);
return pubkey;
};
/**
* global config object
* config.pubkey, if not set loaded from localStorage or generate a new key
*/
export const config = {
get pubkey() {
if (!pubkey) {
pubkey = loadOrGeneraateKeys();
}
return pubkey;
},
set pubkey(value) {
console.info(`pubkey was set to ${value}`)
pubkey = value;
}
};