1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
<script>
import { browser } from "$app/environment";
import { getNsec } from "$lib/nostr";
import { page } from "$app/stores";
import { tick } from "svelte";
import { t } from "$lib/translations";
import { copy, fail } from "$lib/utils";
import {
PUBLIC_COINOS_PUBKEY as pk,
PUBLIC_COINOS_RELAY as relay,
} from "$env/static/public";
import { signer, save } from "$lib/store";
let { data } = $props();
let { challenge, user } = $derived(data);
let { npub } = $state(user);
let extensionAvailable = $derived(browser && window.nostr);
let newNsec = $state(),
nsec = $state(),
pin = $state(""),
revealNsec = $state(),
revealNwc = $state();
let toggleNsec = async () => {
try {
nsec = await getNsec(user);
revealNsec = !revealNsec;
} catch (e) {
fail("Failed to decrypt nsec");
}
};
let lud16 = $derived(`${user.username}@${$page.url.host}`);
let nwc = $derived(
`nostr+walletconnect://${pk}?relay=${encodeURIComponent(
relay,
)}&secret=${user.nwc}&lud16=${lud16}`,
);
let toggleNwc = () => (revealNwc = !revealNwc);
let extension = $state();
let getPubkey = async () => {
$signer = { method: "extension", ready: true };
extension = true;
npub = await window.nostr.getPublicKey();
await tick();
$save.click();
};
</script>
<div>
<input type="hidden" name="challenge" value={challenge} />
<input type="hidden" name="extension" value={extension} />
<label for="nwc" class="font-bold">{$t("user.settings.nwc")}</label>
<p class="text-secondary mb-1">
{$t("user.settings.nwcDescription")}
</p>
<div class="flex flex-wrap justify-center gap-2">
<a href={nwc} class="btn grow">
<img src="/images/nostr.png" class="w-8" />
<div class="my-auto">{$t("user.settings.connectNostr")}</div>
</a>
{#if !revealNwc}
<button onclick={toggleNwc} type="button" class="btn grow">
<iconify-icon noobserver icon="ph:warning-bold" width="32"
></iconify-icon>
<div class="my-auto">{$t("accounts.revealNwc")}</div></button
>
{/if}
</div>
</div>
{#if revealNwc}
<div class="break-all grow">
{nwc}
</div>
<div class="flex flex-wrap gap-2">
<button onclick={() => copy(nwc)} type="button" class="btn grow">
<iconify-icon noobserver icon="ph:copy-bold" width="32"></iconify-icon>
<div class="my-auto">{$t("accounts.copy")}</div></button
>
<a href={`/qr/${encodeURIComponent(nwc)}`} class="btn grow">
<iconify-icon noobserver icon="ph:qr-code-bold" width="32"></iconify-icon>
<div class="my-auto">{$t("user.receive.showQR")}</div>
</a>
</div>
{/if}
<div class="space-y-2">
<div class="font-bold">{$t("user.nostrPubkey")}</div>
<div class="flex gap-4">
<textarea name="pubkey" bind:value={npub}> </textarea>
<div class="flex my-auto gap-1">
<button type="button" class="my-auto" onclick={() => copy(npub)}
><iconify-icon noobserver icon="ph:copy-bold" width="32"
></iconify-icon></button
>
<a href={`/qr/${encodeURIComponent(npub)}`} class="my-auto">
<iconify-icon noobserver icon="ph:qr-code-bold" width="32"
></iconify-icon>
</a>
</div>
</div>
{#if extensionAvailable}
<button class="btn" type="button" onclick={getPubkey}>
<iconify-icon icon="lucide-lab:bee" width="32" class="text-yellow-400"
></iconify-icon>
{$t("user.settings.syncWithExtension")}</button
>
{/if}
</div>
{#if user.nsec}
<div class="space-y-2">
<label for="seedphrase" class="font-bold"
>{$t("user.settings.nostrKeys")}</label
>
<p class="text-secondary mb-1">
{$t("user.settings.nostrDescription")}
</p>
<div class="flex flex-wrap sm:flex-nowrap gap-2">
<button type="button" class="btn !w-auto flex-grow" onclick={toggleNsec}>
{#if revealNsec}
<iconify-icon noobserver icon="ph:eye-slash-bold" width="32"
></iconify-icon>
{$t("user.settings.hideNsec")}
{:else}
<iconify-icon noobserver icon="ph:warning-bold" width="32"
></iconify-icon>
{$t("user.settings.revealNsec")}
{/if}
</button>
</div>
{#if revealNsec}
<button
type="button"
class="btn break-all !h-auto font-normal leading-normal flex-nowrap"
onclick={() => copy(nsec)}
>
<div>{nsec}</div>
<iconify-icon noobserver icon="ph:copy-bold" width="32"></iconify-icon>
</button>
{/if}
</div>
{/if}
|