fix types, imports and other stuff on nip17 and nip59.

This commit is contained in:
fiatjaf
2024-10-25 22:10:05 -03:00
parent a72e47135a
commit e2ec7a4b55
4 changed files with 21 additions and 29 deletions

View File

@@ -2,7 +2,6 @@ import { EventTemplate, UnsignedEvent, Event } from './core.ts'
import { getConversationKey, decrypt, encrypt } from './nip44.ts'
import { getEventHash, generateSecretKey, finalizeEvent, getPublicKey } from './pure.ts'
import { Seal, GiftWrap } from './kinds.ts'
import { SimplePool } from './pool'
type Rumor = UnsignedEvent & { id: string }
@@ -86,13 +85,13 @@ export function wrapManyEvents(
return wrappeds
}
export function unwrapEvent(wrap: Event, recipientPrivateKey: Uint8Array) {
export function unwrapEvent(wrap: Event, recipientPrivateKey: Uint8Array): Rumor {
const unwrappedSeal = nip44Decrypt(wrap, recipientPrivateKey)
return nip44Decrypt(unwrappedSeal, recipientPrivateKey)
}
export function unwrapManyEvents(wrappedEvents: Event[], recipientPrivateKey: Uint8Array) {
let unwrappedEvents = []
export function unwrapManyEvents(wrappedEvents: Event[], recipientPrivateKey: Uint8Array): Rumor[] {
let unwrappedEvents: Rumor[] = []
wrappedEvents.forEach(e => {
unwrappedEvents.push(unwrapEvent(e, recipientPrivateKey))
@@ -102,17 +101,3 @@ export function unwrapManyEvents(wrappedEvents: Event[], recipientPrivateKey: Ui
return unwrappedEvents
}
export async function getWrappedEvents(pubKey: string, relays: string[] = []): Promise<Event[] | undefined> {
const pool = new SimplePool()
try {
const events: Event[] = await pool.querySync(relays, { kinds: [GiftWrap], '#p': [pubKey] })
pool.close(relays)
return events
} catch (error) {
console.error('Failed to:', error)
return undefined
}
}