Skip to content

Commit

Permalink
fix private key format in localStorage.
Browse files Browse the repository at this point in the history
  • Loading branch information
AsaiToshiya authored and fiatjaf committed Sep 25, 2024
1 parent c399275 commit 0f21202
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"license": "MIT",
"repository": "https://github.com/fiatjaf/nocomment",
"dependencies": {
"@noble/hashes": "^1.5.0",
"dayjs": "^1.11.6",
"esbuild": "^0.17.0",
"nostr-tools": "^2.7.2",
Expand Down
5 changes: 4 additions & 1 deletion src/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getPublicKey,
finalizeEvent
} from 'nostr-tools/pure'
import {bytesToHex, hexToBytes} from '@noble/hashes/utils'

export function Editor({
publicKey,
Expand Down Expand Up @@ -98,7 +99,9 @@ export function Editor({
let privateKey = localStorage.getItem('nostrkey')
if (!privateKey || privateKey.match(/^[a-f0-9]{64}$/)) {
privateKey = generateSecretKey()
localStorage.setItem('nostrkey', privateKey)
localStorage.setItem('nostrkey', bytesToHex(privateKey))
} else {
privateKey = hexToBytes(privateKey)
}
setPrivateKey(privateKey)
setPublicKey(getPublicKey(privateKey))
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==

"@noble/hashes@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.5.0.tgz#abadc5ca20332db2b1b2aa3e496e9af1213570b0"
integrity sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==

"@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699"
Expand Down

0 comments on commit 0f21202

Please sign in to comment.