diff options
Diffstat (limited to 'src/nostr.js')
| -rw-r--r-- | src/nostr.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/nostr.js b/src/nostr.js index 431bb1e..91005ec 100644 --- a/src/nostr.js +++ b/src/nostr.js @@ -186,6 +186,20 @@ export class NostrSync { } catch { return () => {}; } } + // Live subscription to our own (replaceable) state event, decrypted. + // Another device saving state delivers here within seconds. + subscribeStates(onState) { + if (!this.pk) return () => {}; + return this.subscribeEvents( + { kinds: [30078], authors: [this.pk], '#d': [this.dtag] }, + (ev) => { + try { + const v = JSON.parse(nip44.decrypt(ev.content, this.ck)); + if (v) onState(v); + } catch {} + }); + } + // Fetch the newest decrypted state across relays, or null. async fetch() { if (!this.sk) return null; |
