import browser from 'webextension-polyfill' import {render} from 'react-dom' import {getPublicKey} from 'nostr-tools' import {bech32} from 'bech32' import React, {useState, useRef, useEffect} from 'react' function Popup() { let [key, setKey] = useState('') let keys = useRef([]) useEffect(() => { browser.storage.local.get('private_key').then(results => { if (results.private_key) { let hexKey = getPublicKey(results.private_key) let npubKey = bech32.encode( 'npub', bech32.toWords(Buffer.from(hexKey, 'hex')) ) setKey(npubKey) keys.current.push(hexKey) keys.current.push(npubKey) } else { setKey(null) } }) }, []) return ( <>

nos2x

{key === null ? (

you don't have a private key set. use the options page to set one.

) : ( <>

↩️ your public key:

            {key}
          
)} ) function toggleKeyType(e) { e.preventDefault() let nextKeyType = keys.current[(keys.current.indexOf(key) + 1) % keys.current.length] setKey(nextKeyType) } } render(, document.getElementById('main'))