show npub key by default.

This commit is contained in:
fiatjaf
2022-11-04 22:24:03 -03:00
parent 43f4ee2785
commit 62b16a24c6
4 changed files with 30 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "nos2x",
"description": "Nostr Signer Extension",
"version": "1.4.1",
"version": "1.5.0",
"homepage_url": "https://github.com/fiatjaf/nos2x",
"manifest_version": 3,
"icons": {

View File

@@ -1,15 +1,26 @@
import browser from 'webextension-polyfill'
import {render} from 'react-dom'
import {getPublicKey} from 'nostr-tools'
import React, {useState, useEffect} from 'react'
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) {
setKey(getPublicKey(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)
}
@@ -25,7 +36,9 @@ function Popup() {
</p>
) : (
<>
<p>your public key:</p>
<p>
<a onClick={toggleKeyType}>↩️</a> your public key:
</p>
<pre
style={{
whiteSpace: 'pre-wrap',
@@ -39,6 +52,13 @@ function Popup() {
)}
</>
)
function toggleKeyType(e) {
e.preventDefault()
let nextKeyType =
keys.current[(keys.current.indexOf(key) + 1) % keys.current.length]
setKey(nextKeyType)
}
}
render(<Popup />, document.getElementById('main'))

View File

@@ -2,6 +2,7 @@
"dependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"async-mutex": "^0.3.2",
"bech32": "^2.0.0",
"esbuild": "^0.14.11",
"esbuild-plugin-alias": "^0.2.1",
"eslint": "^8.6.0",

View File

@@ -130,6 +130,11 @@ base64-js@^1.3.1:
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
bech32@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/bech32/-/bech32-2.0.0.tgz#078d3686535075c8c79709f054b1b226a133b355"
integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==
brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"