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 { getParsedContent } from 'applesauce-content/text'
|
||||||
import { Helpers } from 'applesauce-core'
|
import { Helpers } from 'applesauce-core'
|
||||||
import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
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'
|
import { Bookmark, IndividualBookmark, ParsedContent, ActiveAccount } from '../types/bookmarks'
|
||||||
|
|
||||||
interface BookmarkData {
|
interface BookmarkData {
|
||||||
@@ -246,17 +248,23 @@ export const fetchBookmarks = async (
|
|||||||
else if (evt.content && evt.content.length > 0 && signerCandidate) {
|
else if (evt.content && evt.content.length > 0 && signerCandidate) {
|
||||||
try {
|
try {
|
||||||
console.log('🔓 Attempting manual decryption for event with unrecognized kind...')
|
console.log('🔓 Attempting manual decryption for event with unrecognized kind...')
|
||||||
// Try to manually decrypt using applesauce's unlockHiddenContent function
|
console.log('📄 Content to decrypt:', evt.content.slice(0, 100) + '...')
|
||||||
// We'll temporarily mark the event as supporting hidden content
|
|
||||||
const originalKind = evt.kind
|
// Try direct decryption using the signer's nip04 capabilities
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
const decryptedContent = await (signerCandidate as any).nip04?.decrypt(evt.pubkey, evt.content)
|
||||||
;(evt as any).kind = 10003 // Temporarily change to recognized kind
|
console.log('✅ Successfully decrypted content manually')
|
||||||
|
|
||||||
|
// Parse the decrypted content as JSON (should be array of tags)
|
||||||
try {
|
try {
|
||||||
await Helpers.unlockHiddenContent(evt, signerCandidate as any)
|
const hiddenTags = JSON.parse(decryptedContent)
|
||||||
console.log('✅ Successfully decrypted unrecognized event')
|
console.log('📋 Decrypted hidden tags:', hiddenTags.length, 'tags')
|
||||||
} finally {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// Set the cached value on the event so getHiddenBookmarks can find it
|
||||||
;(evt as any).kind = originalKind // Restore original kind
|
Reflect.set(evt, BookmarkHiddenSymbol, hiddenTags)
|
||||||
|
Reflect.set(evt, 'EncryptedContentSymbol', decryptedContent)
|
||||||
|
|
||||||
|
} catch (parseError) {
|
||||||
|
console.warn('❌ Failed to parse decrypted content as JSON:', parseError)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('❌ Failed manual decryption:', error)
|
console.warn('❌ Failed manual decryption:', error)
|
||||||
|
|||||||
Reference in New Issue
Block a user