diff --git a/package.json b/package.json index 8004501..460e2a0 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "core-js": "^3.6.5", "identicon.js": "^2.3.3", "markdown-it": "^12.3.0", - "nostr-tools": "^0.18.0", + "nostr-tools": "^0.19.0", "pouchdb-adapter-idb": "6", "pouchdb-core": "6", "pouchdb-mapreduce": "6", diff --git a/src/components/Publish.vue b/src/components/Publish.vue index b31a974..5de5442 100644 --- a/src/components/Publish.vue +++ b/src/components/Publish.vue @@ -28,7 +28,6 @@ unelevated type="submit" color="primary" - :disable="!$store.state.keys.priv" /> @@ -48,9 +47,9 @@ export default { } }, methods: { - sendPost() { - this.$store.dispatch('sendPost', {message: this.text}) - this.text = '' + async sendPost() { + let ok = await this.$store.dispatch('sendPost', {message: this.text}) + if (ok) this.text = '' } } } diff --git a/src/components/Reply.vue b/src/components/Reply.vue index bb7ea4a..271110a 100644 --- a/src/components/Reply.vue +++ b/src/components/Reply.vue @@ -10,14 +10,7 @@
- +
@@ -39,7 +32,7 @@ export default { }, methods: { - sendReply() { + async sendReply() { // build tags let tags = [] @@ -69,11 +62,12 @@ export default { // remove ourselves tags = tags.filter(([_, v]) => v !== this.$store.state.keys.pub) - this.$store.dispatch('sendPost', { + let ok = await this.$store.dispatch('sendPost', { message: this.text, tags }) - this.text = '' + + if (ok) this.text = '' } } } diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index 2e0a17d..769f7ef 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -221,22 +221,21 @@
Initial Key Setup
-

- Type your mnemonic seed from a previous Nostr account or generate a +

+ Type your private key from a previous Nostr account or generate a new one. -

-

- You can also type a raw private key or just a public key for a - watch-only setup. -

- - +
+
+ You can also type just a public key and later sign events manually + or using a Nostr-capable browser extension. +
+ Your keys -

- Make sure you back up your private key!
- Posts are published using your private key. Others can see your - posts or follow you using only your public key. +

+ Make sure you back up your private key!

+

Your private key is not here!

+
+ Posts are published using your private key. Others can see your + posts or follow you using only your public key. +
-

Seed Words:

-

Private Key:

{ + Dialog.create({ + class: 'px-6 py-1 overflow-hidden', + title: 'Sign this event manually', + message: `
${JSON.stringify(
+          event,
+          null,
+          2
+        )}
`, + html: true, + prompt: { + model: '', + type: 'text', + isValid: val => !!val.toLowerCase().match(/^[a-z0-9]{128}$/), + attrs: {autocomplete: 'off'}, + label: 'Paste the signature here (as hex)' + } + }) + .onOk(resolve) + .onCancel(() => reject('Canceled.')) + .onDismiss(() => reject('Canceled.')) + }) + } +} diff --git a/src/store/actions.js b/src/store/actions.js index ce175a8..9e1b89e 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -1,7 +1,7 @@ import {encrypt} from 'nostr-tools/nip04' import {Notify, LocalStorage} from 'quasar' -import {pool} from '../pool' +import {pool, signAsynchronously} from '../pool' import {dbSave, dbGetProfile, dbGetContactList} from '../db' export function initKeys(store, keys) { @@ -19,9 +19,11 @@ export async function launch(store) { store.commit('haveReadNotifications') } - // now we already have a key + // if we have already have a private key if (store.state.keys.priv) { pool.setPrivateKey(store.state.keys.priv) + } else { + pool.registerSigningFunction(signAsynchronously) } // translate localStorage into a kind3 event -- or load relays and following from event @@ -138,15 +140,31 @@ export function restartMainSubscription(store) { export async function sendPost(store, {message, tags = [], kind = 1}) { if (message.length === 0) return - let event = await pool.publish({ - pubkey: store.state.keys.pub, - created_at: Math.floor(Date.now() / 1000), - kind, - tags, - content: message - }) + let event + try { + event = await pool.publish({ + pubkey: store.state.keys.pub, + created_at: Math.floor(Date.now() / 1000), + kind, + tags, + content: message + }) + } catch (err) { + Notify.create({ + message: `Did not publish: ${err}`, + color: 'red' + }) + return + } + + if (!event) { + // aborted + return + } store.dispatch('addEvent', {event}) + + return true } export async function setMetadata(store, metadata) { diff --git a/src/store/mutations.js b/src/store/mutations.js index 4bbea54..717560a 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -20,7 +20,7 @@ export function setKeys(state, {mnemonic, priv, pub} = {}) { pub = getPublicKey(priv) } - state.keys = {mnemonic, priv, pub} + state.keys = {priv, pub} } export function setRelays(state, relays) { diff --git a/src/store/state.js b/src/store/state.js index efe3331..1a747ce 100644 --- a/src/store/state.js +++ b/src/store/state.js @@ -3,6 +3,7 @@ import {LocalStorage} from 'quasar' export default function () { return { keys: LocalStorage.getItem('keys') || {pub: '00'}, // { mnemonic, priv, pub } + relays: { // 'wss://nostr.rocks': {read: true, write: true}, 'wss://relayer.fiatjaf.com': {read: true, write: true}, diff --git a/yarn.lock b/yarn.lock index 34c7919..7642f2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4769,10 +4769,10 @@ normalize-url@^6.0.1: resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-6.1.0.tgz#40d0885b535deffe3f3147bec877d05fe4c5668a" integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A== -nostr-tools@^0.18.0: - version "0.18.0" - resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-0.18.0.tgz#d5c76ecd2ea6728a772de5daa5ab5d8110f3425c" - integrity sha512-NOAC7JhNrAtFnEsr4vEG3PzSzhAcChzXr0SCcfrlFbXcwIFKHcrBGZ4K6qmhJPGpVvhuXwquixG3KlfMIoqc5g== +nostr-tools@^0.19.0: + version "0.19.0" + resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-0.19.0.tgz#3e086f4a1715607d8917912f56a16866a115efec" + integrity sha512-kn7+gy+Ncrf7WkIN/OTuNu/EZtfK2hVLQZw9CQOVcngeF5nlqMRVrgMQBo2CkrkFFV5G5tS71lH4imtiklh13g== dependencies: "@noble/hashes" "^0.5.7" "@noble/secp256k1" "^1.3.0"