Skip to content

Commit 361ef89

Browse files
publishing somehow working
1 parent 74aa3d4 commit 361ef89

1 file changed

Lines changed: 82 additions & 37 deletions

File tree

src/views/Export/Nostr.vue

Lines changed: 82 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<div class="modal-body">
1515
<!-- Key Management Section -->
1616
<div v-if="step === 'initial'" class="key-management mb-4">
17-
<h6>Nostr Key</h6>
17+
<h6>Nostr Keys</h6>
18+
19+
<!-- Public Key -->
1820
<div class="form-group mb-3">
1921
<label for="nostrPublicKey" class="form-label">Your Public Key (npub):</label>
2022
<div class="input-group">
@@ -38,32 +40,18 @@
3840
</div>
3941
</div>
4042

41-
<div class="form-check mb-3" v-if="publicKey">
42-
<input
43-
class="form-check-input"
44-
type="checkbox"
45-
id="rememberKey"
46-
v-model="rememberKey"
47-
/>
48-
<label class="form-check-label" for="rememberKey">
49-
Remember my public key for future posts
50-
</label>
51-
</div>
52-
53-
<div v-if="privateKey" class="alert alert-warning">
54-
<div class="d-flex align-items-center mb-2">
55-
<i class="bi bi-exclamation-triangle-fill me-2"></i>
56-
<strong>Important: Save your private key</strong>
57-
</div>
58-
<p class="mb-2">
59-
This private key gives access to your Nostr identity. Save it securely.
60-
</p>
43+
<!-- Private Key (always visible) -->
44+
<div class="form-group mb-3">
45+
<label for="nostrPrivateKey" class="form-label"
46+
>Your Private Key (nsec):</label
47+
>
6148
<div class="input-group">
6249
<input
50+
id="nostrPrivateKey"
6351
:type="privateKeyVisible ? 'text' : 'password'"
6452
class="form-control"
6553
v-model="privateKey"
66-
readonly
54+
placeholder="Enter your Nostr private key (nsec...)"
6755
/>
6856
<button
6957
class="btn btn-outline-secondary"
@@ -75,10 +63,42 @@
7563
class="btn btn-outline-secondary"
7664
@click="copyToClipboard(privateKey)"
7765
title="Copy to clipboard"
66+
:disabled="!privateKey"
7867
>
7968
<i class="bi bi-clipboard"></i>
8069
</button>
8170
</div>
71+
<div class="form-text text-muted">
72+
Your private key is needed to sign and publish posts. Keep it secure.
73+
</div>
74+
</div>
75+
76+
<!-- Store credentials checkbox -->
77+
<div class="form-check mb-3" v-if="publicKey || privateKey">
78+
<input
79+
class="form-check-input"
80+
type="checkbox"
81+
id="storeCredentials"
82+
v-model="storeCredentials"
83+
/>
84+
<label class="form-check-label" for="storeCredentials">
85+
Store credentials in this browser
86+
</label>
87+
<div class="form-text text-warning">
88+
<i class="bi bi-exclamation-triangle-fill me-1"></i>
89+
Storing your private key in the browser is convenient but less secure.
90+
</div>
91+
</div>
92+
93+
<!-- Warning box when keys are generated -->
94+
<div v-if="isNewlyGenerated" class="alert alert-warning">
95+
<div class="d-flex align-items-center mb-2">
96+
<i class="bi bi-exclamation-triangle-fill me-2"></i>
97+
<strong>Important: Save your private key</strong>
98+
</div>
99+
<p class="mb-2">
100+
This private key gives access to your Nostr identity. Save it securely.
101+
</p>
82102
</div>
83103
</div>
84104

@@ -115,7 +135,7 @@
115135
<button
116136
class="btn btn-primary"
117137
@click="publishToNostr"
118-
:disabled="!publicKey"
138+
:disabled="!publicKey || !privateKey"
119139
>
120140
<i class="bi bi-lightning-charge me-1"></i> Publish Now
121141
</button>
@@ -196,6 +216,7 @@ import {
196216
nip19,
197217
SimplePool,
198218
getEventHash,
219+
finalizeEvent,
199220
} from "nostr-tools";
200221
import Dexie from "../../ts/indexDB";
201222
import * as Y from "yjs";
@@ -231,17 +252,24 @@ export default {
231252
// Nostr key management
232253
publicKey: "",
233254
privateKey: "",
234-
rememberKey: true,
255+
storeCredentials: true,
235256
privateKeyVisible: false,
257+
isNewlyGenerated: false,
236258
};
237259
},
238260
239261
created() {
240-
// Try to load saved public key from localStorage
262+
// Try to load saved credentials from localStorage
241263
const savedPublicKey = localStorage.getItem("nostrPublicKey");
264+
const savedPrivateKey = localStorage.getItem("nostrPrivateKey");
265+
242266
if (savedPublicKey) {
243267
this.publicKey = savedPublicKey;
244268
}
269+
270+
if (savedPrivateKey) {
271+
this.privateKey = savedPrivateKey;
272+
}
245273
},
246274
247275
computed: {
@@ -252,15 +280,21 @@ export default {
252280
253281
methods: {
254282
close() {
255-
// Clear generated private key when closing the modal for security
256-
this.privateKey = "";
283+
// Save credentials if requested
284+
this.saveCredentials();
285+
286+
// Reset newly generated flag
287+
this.isNewlyGenerated = false;
288+
289+
// Hide private key when closing
257290
this.privateKeyVisible = false;
291+
258292
this.$emit("close");
259293
},
260294
261295
generateKeyPair() {
262296
try {
263-
// Generate a new private key (using the correct function name)
297+
// Generate a new private key
264298
const privateKey = generateSecretKey();
265299
266300
// Derive the public key from it
@@ -273,6 +307,7 @@ export default {
273307
this.privateKey = nsec;
274308
this.publicKey = npub;
275309
this.privateKeyVisible = true;
310+
this.isNewlyGenerated = true;
276311
} catch (error) {
277312
console.error("Error generating key pair:", error);
278313
alert("Failed to generate key pair. Please try again.");
@@ -289,6 +324,20 @@ export default {
289324
});
290325
},
291326
327+
saveCredentials() {
328+
if (this.storeCredentials) {
329+
if (this.publicKey) {
330+
localStorage.setItem("nostrPublicKey", this.publicKey);
331+
}
332+
if (this.privateKey) {
333+
localStorage.setItem("nostrPrivateKey", this.privateKey);
334+
}
335+
} else {
336+
localStorage.removeItem("nostrPublicKey");
337+
localStorage.removeItem("nostrPrivateKey");
338+
}
339+
},
340+
292341
addTag() {
293342
if (this.newTag.trim() && !this.tags.includes(this.newTag.trim())) {
294343
this.tags.push(this.newTag.trim());
@@ -301,17 +350,13 @@ export default {
301350
},
302351
303352
publishToNostr() {
304-
if (!this.publicKey) {
305-
alert("Please enter your public key or generate a new one before publishing.");
353+
if (!this.publicKey || !this.privateKey) {
354+
alert("Please enter both your public and private keys before publishing.");
306355
return;
307356
}
308357
309-
// Store public key if requested
310-
if (this.rememberKey) {
311-
localStorage.setItem("nostrPublicKey", this.publicKey);
312-
} else {
313-
localStorage.removeItem("nostrPublicKey");
314-
}
358+
// Save credentials if requested
359+
this.saveCredentials();
315360
316361
// Loading indicator could be added here
317362
this.publishStatus = "loading";
@@ -379,7 +424,7 @@ export default {
379424
380425
// Sign the event - updated approach for newer nostr-tools
381426
event.id = getEventHash(event);
382-
const signedEvent = signEvent(event, privkey);
427+
const signedEvent = finalizeEvent(event, privkey);
383428
384429
// Publish to relays
385430
console.log("Publishing event:", signedEvent);

0 commit comments

Comments
 (0)