|
24 | 24 |
|
25 | 25 | let newRelay = 'wss://'; |
26 | 26 | let copiedPublicKey = false; |
| 27 | + let copiedPrivateKey = false; |
27 | 28 | let connectionName = 'Connect another Nostr app'; |
28 | 29 | let connections: Array<PomegranateProfile & { bunker: string }> = []; |
29 | 30 | let connectionError = ''; |
|
78 | 79 | setTimeout(() => (copiedPublicKey = false), 1400); |
79 | 80 | } |
80 | 81 |
|
| 82 | + async function copyPrivateKey() { |
| 83 | + if ($session?.mode !== 'private-key' || !$session.secret) return; |
| 84 | + const nsec = nsecFromHex($session.secret); |
| 85 | + if (!nsec) return; |
| 86 | + await navigator.clipboard.writeText(nsec); |
| 87 | + copiedPrivateKey = true; |
| 88 | + setTimeout(() => (copiedPrivateKey = false), 1400); |
| 89 | + } |
| 90 | +
|
| 91 | + function nsecFromHex(hex: string) { |
| 92 | + if (!/^[0-9a-f]{64}$/i.test(hex)) return ''; |
| 93 | + const bytes = new Uint8Array(hex.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []); |
| 94 | + return nip19.nsecEncode(bytes); |
| 95 | + } |
| 96 | +
|
81 | 97 | async function refreshConnections() { |
82 | 98 | connectionError = ''; |
83 | 99 | loadingConnections = true; |
|
182 | 198 | <div class="setting-grid"> |
183 | 199 | <div class="account-field"> |
184 | 200 | <span>Signed in with</span> |
185 | | - <strong>{sessionLabel($session.mode)}</strong> |
| 201 | + <span class="session-label-row"> |
| 202 | + <strong>{sessionLabel($session.mode)}</strong> |
| 203 | + {#if $session.mode === 'private-key' && $session.secret} |
| 204 | + <button class="icon-button small local-key-copy" on:click={copyPrivateKey} aria-label="Copy private key"> |
| 205 | + {#if copiedPrivateKey}<Check size={15} />{:else}<Copy size={15} />{/if} |
| 206 | + </button> |
| 207 | + {/if} |
| 208 | + </span> |
186 | 209 | </div> |
187 | 210 | <div class="account-field"> |
188 | 211 | <span>Public key</span> |
|
0 commit comments