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 @@
- Type your mnemonic seed from a previous Nostr account or generate a +
- You can also type a raw private key or just a public key for a - watch-only setup. -
- -
- 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!
+Seed Words:
-Private Key:
${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"