diff --git a/ROADMAP.md b/ROADMAP.md index 13a4daeb..b9fa1410 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,7 +1,7 @@ # Current - [ ] Strip zero width spaces from compose -- [ ] Fix iOS +- [ ] Fix iOS/safari/firefox - [ ] Make the note relays button modal make sense, one relay with no explanation is not good # Image uploads @@ -28,6 +28,7 @@ # More +- [ ] Mute threads http://localhost:5173/nevent1qqsyz8x6r0cu7l6vwlcjhf8qhxyjtdykvuervkc3t3mfggse4qtwt0gpyfmhxue69uhkummnw3ezumrfvfjhyarpwdc8y6tddaexg6t4d5hxxmmdnhxvea - [ ] Add webtorrent support - https://coracle.social/nevent1qqsxgxcsq5vevy4wdty5z5v88nhwp2fc5qgl0ws5rmamn6z72hwv3qcpyfmhxue69uhkummnw3ez6an9wf5kv6t9vsh8wetvd3hhyer9wghxuet5qk6c9q - [ ] Add coracle relay diff --git a/src/agent/keys.ts b/src/agent/keys.ts index fbbb474e..5af1c16f 100644 --- a/src/agent/keys.ts +++ b/src/agent/keys.ts @@ -3,72 +3,106 @@ import {get} from 'svelte/store' import {error} from 'src/util/logger' import {synced} from 'src/util/misc' +const method = synced('agent/keys/method') const pubkey = synced('agent/keys/pubkey') const privkey = synced('agent/keys/privkey') const getExtension = () => (window as {nostr?: any}).nostr -const canSign = () => Boolean(getExtension() || get(privkey)) +const canSign = () => ['privkey', 'extension'].includes(get(method)) -const setPrivateKey = _privkey => { - privkey.set(_privkey) - pubkey.set(getPublicKey(_privkey)) -} +// For backwards compatibility, if method isn't set but we're logged in, set it +setTimeout(() => { + method.update($method => { + if ($method) { + return $method + } -const setPublicKey = _pubkey => { - pubkey.set(_pubkey) + if (get(privkey)) { + return 'privkey' + } + + if (get(pubkey)) { + return getExtension() ? 'extension' : 'pubkey' + } + + return null + }) +}, 100) + +const login = ($method, key) => { + method.set($method) + + if ($method === 'privkey') { + privkey.set(key) + pubkey.set(getPublicKey(key)) + } else { + privkey.set(null) + pubkey.set(key) + } } const clear = () => { + method.set(null) pubkey.set(null) privkey.set(null) } -const sign = async event => { - const ext = getExtension() - const key = get(privkey) +const sign = event => { + const $method = get(method) event.pubkey = get(pubkey) event.id = getEventHash(event) - if (key) { + if ($method === 'privkey') { return Object.assign(event, { sig: signEvent(event, get(privkey)), }) - } else if (ext) { - return await ext.signEvent(event) - } else { - throw new Error('Unable to sign event') } + + if ($method === 'extension') { + return getExtension().signEvent(event) + } + + throw new Error(`Unable to sign event, method is ${$method}`) } const getCrypt = () => { - const $privkey = get(privkey) - const nostr = getExtension() + const $method = get(method) - if (!$privkey && !nostr) { - throw new Error('No encryption method available.') + if ($method === 'privkey') { + const $privkey = get(privkey) + + return { + encrypt: (pubkey, message) => nip04.encrypt($privkey, pubkey, message), + decrypt: async (pubkey, message) => { + try { + return nip04.decrypt($privkey, pubkey, message) + } catch (e) { + error(e) + + return `` + } + }, + } } - return { - encrypt: (pubkey, message) => { - return $privkey - ? nip04.encrypt($privkey, pubkey, message) - : nostr.nip04.encrypt(pubkey, message) - }, - decrypt: async (pubkey, message) => { - try { - return $privkey - ? nip04.decrypt($privkey, pubkey, message) - : await nostr.nip04.decrypt(pubkey, message) - } catch (e) { - error(e) + if ($method === 'extension') { + return { + encrypt: (pubkey, message) => getExtension().nip04.encrypt(pubkey, message), + decrypt: async (pubkey, message) => { + try { + return await getExtension().nip04.decrypt(pubkey, message) + } catch (e) { + error(e) - return `` - } - }, + return `` + } + }, + } } + + throw new Error('No encryption method available.') } export default { - pubkey, privkey, canSign, setPrivateKey, setPublicKey, clear, - sign, getCrypt, + pubkey, privkey, canSign, login, clear, sign, getCrypt, } diff --git a/src/app/index.ts b/src/app/index.ts index 8ceb8be8..0ddca6fb 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -21,18 +21,14 @@ export const loadAppData = async pubkey => { } } -export const login = ({privkey, pubkey}: {privkey?: string, pubkey?: string}) => { - if (privkey) { - keys.setPrivateKey(privkey) - } else { - keys.setPublicKey(pubkey) - } +export const login = (method, key) => { + keys.login(method, key) modal.set({type: 'login/connect', noEscape: true}) } export const signup = privkey => { - keys.setPrivateKey(privkey) + keys.login('privkey', privkey) navigate('/notes/follows') } diff --git a/src/partials/Content.svelte b/src/partials/Content.svelte index 8afb4480..16cc8cbd 100644 --- a/src/partials/Content.svelte +++ b/src/partials/Content.svelte @@ -24,7 +24,7 @@ {/if} {#if size === '2xl'} -
+
{/if} diff --git a/src/partials/ImageInput.svelte b/src/partials/ImageInput.svelte index 0785ab2a..24b0e42d 100644 --- a/src/partials/ImageInput.svelte +++ b/src/partials/ImageInput.svelte @@ -12,6 +12,7 @@ export let icon export let maxWidth = null export let maxHeight = null + export let hideInput = false let input, file, listener, quote let loading = false @@ -55,9 +56,11 @@
+ {#if !hideInput} + {/if} { isOpen = true }}> diff --git a/src/views/TopNav.svelte b/src/views/TopNav.svelte index 8c29258a..254d3b4e 100644 --- a/src/views/TopNav.svelte +++ b/src/views/TopNav.svelte @@ -17,7 +17,7 @@
- +
+ + +
{ showSettings = true }}> diff --git a/src/views/notes/NotesList.svelte b/src/views/notes/NotesList.svelte index 562063f8..4a6101fd 100644 --- a/src/views/notes/NotesList.svelte +++ b/src/views/notes/NotesList.svelte @@ -29,4 +29,5 @@ {/if}
+ diff --git a/src/views/person/PersonDetail.svelte b/src/views/person/PersonDetail.svelte index a0d9f313..6315e6e2 100644 --- a/src/views/person/PersonDetail.svelte +++ b/src/views/person/PersonDetail.svelte @@ -57,7 +57,7 @@ actions.push({onClick: openAdvanced, label: 'Advanced', icon: 'sliders'}) } - if (user.getPubkey() === pubkey) { + if (user.getPubkey() === pubkey && $canPublish) { actions.push({onClick: () => navigate('/profile'), label: 'Edit', icon: 'edit'}) } } diff --git a/src/views/person/PersonSummary.svelte b/src/views/person/PersonSummary.svelte index da97f8dc..b6156068 100644 --- a/src/views/person/PersonSummary.svelte +++ b/src/views/person/PersonSummary.svelte @@ -7,11 +7,11 @@ import user from "src/agent/user" import {sampleRelays, getPubkeyWriteRelays} from "src/agent/relays" import database from "src/agent/database" - import {routes, modal} from "src/app/ui" + import {routes} from "src/app/ui" export let pubkey - const {petnamePubkeys} = user + const {petnamePubkeys, canPublish} = user const getRelays = () => sampleRelays(getPubkeyWriteRelays(pubkey)) let following = false @@ -28,10 +28,6 @@ const unfollow = async () => { user.removePetname(pubkey) } - - const share = () => { - modal.set({type: 'person/share', person}) - }
@@ -54,9 +50,7 @@ {/if}
- - - + {#if $canPublish} {#if following} @@ -66,6 +60,7 @@ {/if} + {/if}

{@html renderContent(person?.kind0?.about || '')}