mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex-taker-v2.git
synced 2026-09-21 16:52:01 -07:00
Merge pull request #12 from Permissionless-Software-Foundation/dh-nostr-keys
fix(nostr): Display Nostr keys as npub and nsec
This commit is contained in:
@@ -165,28 +165,28 @@ function WalletSummary (props) {
|
||||
</Row>
|
||||
<Row style={{ padding: '25px', backgroundColor: '#eee' }}>
|
||||
<Col xs={10} sm={10} lg={8} style={{ padding: '10px' }}>
|
||||
<b>Nostr Priv Key:</b> <span className={blurredNostrPrivKey ? 'blurred' : null}>{nostrKeyPair.privHex}</span>
|
||||
<b>Nostr Priv Key:</b> <span className={blurredNostrPrivKey ? 'blurred' : null}>{nostrKeyPair.nsec}</span>
|
||||
</Col>
|
||||
<Col xs={6} sm={1} lg={2} style={{ textAlign: 'center' }}>
|
||||
<FontAwesomeIcon
|
||||
style={{ cursor: 'pointer' }}
|
||||
icon={eyeIcon.privateKey}
|
||||
size='lg'
|
||||
onClick={() => toggleNostrPrivateKeyBlur(nostrKeyPair.privHex)}
|
||||
onClick={() => toggleNostrPrivateKeyBlur(nostrKeyPair.nsec)}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={6} sm={1} lg={2} style={{ textAlign: 'center' }}>
|
||||
<CopyOnClick appData={appData} value={nostrKeyPair.privHex} />
|
||||
<CopyOnClick appData={appData} value={nostrKeyPair.nsec} />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row style={{ padding: '25px', backgroundColor: '#eee' }}>
|
||||
<Col xs={10} sm={10} lg={8} style={{ padding: '10px' }}>
|
||||
<b>Nostr Pub Key:</b> {nostrKeyPair.pubHex}
|
||||
<b>Nostr Pub Key:</b> {nostrKeyPair.npub}
|
||||
</Col>
|
||||
<Col xs={6} sm={1} lg={2} style={{ textAlign: 'center' }} />
|
||||
|
||||
<Col xs={6} sm={1} lg={2} style={{ textAlign: 'center' }}>
|
||||
<CopyOnClick appData={appData} value={nostrKeyPair.pubHex} />
|
||||
<CopyOnClick appData={appData} value={nostrKeyPair.npub} />
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
|
||||
@@ -13,6 +13,7 @@ import P2WDB from 'p2wdb'
|
||||
import { base58_to_binary as base58ToBinary } from 'base58-js'
|
||||
import { bytesToHex } from '@noble/hashes/utils' // already an installed dependency
|
||||
import { getPublicKey } from 'nostr-tools/pure'
|
||||
import * as nip19 from 'nostr-tools/nip19'
|
||||
|
||||
class AsyncLoad {
|
||||
constructor () {
|
||||
@@ -65,7 +66,7 @@ class AsyncLoad {
|
||||
|
||||
// Get Nostr key pair from WIF
|
||||
const nostrKeyPair = this.nostrKeyPairFromWIF(wallet.walletInfo.privateKey)
|
||||
|
||||
console.log('nostrKeyPair: ', nostrKeyPair)
|
||||
const walletInfo = wallet.walletInfo
|
||||
walletInfo.nostrKeyPair = nostrKeyPair
|
||||
// Update the state of the wallet.
|
||||
@@ -265,15 +266,21 @@ class AsyncLoad {
|
||||
const wifBuf = base58ToBinary(WIF)
|
||||
const privBuf = wifBuf.slice(1, 33)
|
||||
// console.log('privBuf: ', privBuf)
|
||||
|
||||
// Convert the private key to a hex string
|
||||
const privHex = bytesToHex(privBuf)
|
||||
console.log('BCH & Nostr private key (HEX format): ', privHex)
|
||||
// Convert the private key to a Nostr NSEC key
|
||||
const nsec = nip19.nsecEncode(privBuf)
|
||||
|
||||
// Get the public key hex string from the private key
|
||||
const pubHex = getPublicKey(privBuf)
|
||||
// Convert the public key to a Nostr NPUB key
|
||||
const npub = nip19.npubEncode(pubHex)
|
||||
|
||||
return {
|
||||
privHex,
|
||||
pubHex
|
||||
pubHex,
|
||||
nsec,
|
||||
npub
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user