mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
feat: implement direct decryption for unrecognized event kinds
- Add manual decryption using signer's nip04 capabilities directly - Parse decrypted content as JSON array of bookmark tags - Cache decrypted content properly for getHiddenBookmarks to find - Enable decryption of legacy bookmark events (kind 30001) with encrypted content
This commit is contained in:
@@ -2,6 +2,8 @@ import { RelayPool, completeOnEose } from 'applesauce-relay'
|
||||
import { getParsedContent } from 'applesauce-content/text'
|
||||
import { Helpers } from 'applesauce-core'
|
||||
import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
||||
// Import the bookmark hidden symbol for caching
|
||||
const BookmarkHiddenSymbol = Symbol.for("bookmark-hidden")
|
||||
import { Bookmark, IndividualBookmark, ParsedContent, ActiveAccount } from '../types/bookmarks'
|
||||
|
||||
interface BookmarkData {
|
||||
@@ -246,17 +248,23 @@ export const fetchBookmarks = async (
|
||||
else if (evt.content && evt.content.length > 0 && signerCandidate) {
|
||||
try {
|
||||
console.log('🔓 Attempting manual decryption for event with unrecognized kind...')
|
||||
// Try to manually decrypt using applesauce's unlockHiddenContent function
|
||||
// We'll temporarily mark the event as supporting hidden content
|
||||
const originalKind = evt.kind
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(evt as any).kind = 10003 // Temporarily change to recognized kind
|
||||
console.log('📄 Content to decrypt:', evt.content.slice(0, 100) + '...')
|
||||
|
||||
// Try direct decryption using the signer's nip04 capabilities
|
||||
const decryptedContent = await (signerCandidate as any).nip04?.decrypt(evt.pubkey, evt.content)
|
||||
console.log('✅ Successfully decrypted content manually')
|
||||
|
||||
// Parse the decrypted content as JSON (should be array of tags)
|
||||
try {
|
||||
await Helpers.unlockHiddenContent(evt, signerCandidate as any)
|
||||
console.log('✅ Successfully decrypted unrecognized event')
|
||||
} finally {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(evt as any).kind = originalKind // Restore original kind
|
||||
const hiddenTags = JSON.parse(decryptedContent)
|
||||
console.log('📋 Decrypted hidden tags:', hiddenTags.length, 'tags')
|
||||
|
||||
// Set the cached value on the event so getHiddenBookmarks can find it
|
||||
Reflect.set(evt, BookmarkHiddenSymbol, hiddenTags)
|
||||
Reflect.set(evt, 'EncryptedContentSymbol', decryptedContent)
|
||||
|
||||
} catch (parseError) {
|
||||
console.warn('❌ Failed to parse decrypted content as JSON:', parseError)
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('❌ Failed manual decryption:', error)
|
||||
|
||||
Reference in New Issue
Block a user