mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 00:28:51 +00:00
fix types, imports and other stuff on nip17 and nip59.
This commit is contained in:
21
nip59.ts
21
nip59.ts
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user