show npub key by default.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nos2x",
|
"name": "nos2x",
|
||||||
"description": "Nostr Signer Extension",
|
"description": "Nostr Signer Extension",
|
||||||
"version": "1.4.1",
|
"version": "1.5.0",
|
||||||
"homepage_url": "https://github.com/fiatjaf/nos2x",
|
"homepage_url": "https://github.com/fiatjaf/nos2x",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"icons": {
|
"icons": {
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
import browser from 'webextension-polyfill'
|
import browser from 'webextension-polyfill'
|
||||||
import {render} from 'react-dom'
|
import {render} from 'react-dom'
|
||||||
import {getPublicKey} from 'nostr-tools'
|
import {getPublicKey} from 'nostr-tools'
|
||||||
import React, {useState, useEffect} from 'react'
|
import {bech32} from 'bech32'
|
||||||
|
import React, {useState, useRef, useEffect} from 'react'
|
||||||
|
|
||||||
function Popup() {
|
function Popup() {
|
||||||
let [key, setKey] = useState('')
|
let [key, setKey] = useState('')
|
||||||
|
let keys = useRef([])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
browser.storage.local.get('private_key').then(results => {
|
browser.storage.local.get('private_key').then(results => {
|
||||||
if (results.private_key) {
|
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 {
|
} else {
|
||||||
setKey(null)
|
setKey(null)
|
||||||
}
|
}
|
||||||
@@ -25,7 +36,9 @@ function Popup() {
|
|||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<p>your public key:</p>
|
<p>
|
||||||
|
<a onClick={toggleKeyType}>↩️</a> your public key:
|
||||||
|
</p>
|
||||||
<pre
|
<pre
|
||||||
style={{
|
style={{
|
||||||
whiteSpace: 'pre-wrap',
|
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'))
|
render(<Popup />, document.getElementById('main'))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
||||||
"async-mutex": "^0.3.2",
|
"async-mutex": "^0.3.2",
|
||||||
|
"bech32": "^2.0.0",
|
||||||
"esbuild": "^0.14.11",
|
"esbuild": "^0.14.11",
|
||||||
"esbuild-plugin-alias": "^0.2.1",
|
"esbuild-plugin-alias": "^0.2.1",
|
||||||
"eslint": "^8.6.0",
|
"eslint": "^8.6.0",
|
||||||
|
|||||||
@@ -130,6 +130,11 @@ base64-js@^1.3.1:
|
|||||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
|
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
|
||||||
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
|
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:
|
brace-expansion@^1.1.7:
|
||||||
version "1.1.11"
|
version "1.1.11"
|
||||||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
||||||
|
|||||||
Reference in New Issue
Block a user