fix slow types so we can publish to jsr.io
This commit is contained in:
parent
d3fc4734b4
commit
29ecdfc5ec
|
@ -23,7 +23,7 @@ export type SubscribeManyParams = Omit<SubscriptionParams, 'onclose' | 'id'> & {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AbstractSimplePool {
|
export class AbstractSimplePool {
|
||||||
protected relays = new Map<string, AbstractRelay>()
|
protected relays: Map<string, AbstractRelay> = new Map()
|
||||||
public seenOn: Map<string, Set<AbstractRelay>> = new Map()
|
public seenOn: Map<string, Set<AbstractRelay>> = new Map()
|
||||||
public trackRelays: boolean = false
|
public trackRelays: boolean = false
|
||||||
|
|
||||||
|
|
2
jsr.json
2
jsr.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@nostr/tools",
|
"name": "@nostr/tools",
|
||||||
"version": "2.3.2",
|
"version": "2.9.4",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./core": "./core.ts",
|
"./core": "./core.ts",
|
||||||
|
|
19
nip17.ts
19
nip17.ts
|
@ -1,5 +1,5 @@
|
||||||
import { PrivateDirectMessage } from './kinds.ts'
|
import { PrivateDirectMessage } from './kinds.ts'
|
||||||
import { EventTemplate, getPublicKey } from './pure.ts'
|
import { EventTemplate, NostrEvent, getPublicKey } from './pure.ts'
|
||||||
import * as nip59 from './nip59.ts'
|
import * as nip59 from './nip59.ts'
|
||||||
|
|
||||||
type Recipient = {
|
type Recipient = {
|
||||||
|
@ -48,7 +48,7 @@ export function wrapEvent(
|
||||||
message: string,
|
message: string,
|
||||||
conversationTitle?: string,
|
conversationTitle?: string,
|
||||||
replyTo?: ReplyTo,
|
replyTo?: ReplyTo,
|
||||||
) {
|
): NostrEvent {
|
||||||
const event = createEvent(recipient, message, conversationTitle, replyTo)
|
const event = createEvent(recipient, message, conversationTitle, replyTo)
|
||||||
return nip59.wrapEvent(event, senderPrivateKey, recipient.publicKey)
|
return nip59.wrapEvent(event, senderPrivateKey, recipient.publicKey)
|
||||||
}
|
}
|
||||||
|
@ -59,22 +59,17 @@ export function wrapManyEvents(
|
||||||
message: string,
|
message: string,
|
||||||
conversationTitle?: string,
|
conversationTitle?: string,
|
||||||
replyTo?: ReplyTo,
|
replyTo?: ReplyTo,
|
||||||
) {
|
): NostrEvent[] {
|
||||||
if (!recipients || recipients.length === 0) {
|
if (!recipients || recipients.length === 0) {
|
||||||
throw new Error('At least one recipient is required.')
|
throw new Error('At least one recipient is required.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const senderPublicKey = getPublicKey(senderPrivateKey)
|
const senderPublicKey = getPublicKey(senderPrivateKey)
|
||||||
|
|
||||||
// Initialize the wrappeds array with the sender's own wrapped event
|
// wrap the event for the sender and then for each recipient
|
||||||
const wrappeds = [wrapEvent(senderPrivateKey, { publicKey: senderPublicKey }, message, conversationTitle, replyTo)]
|
return [{ publicKey: senderPublicKey }, ...recipients].map(recipient =>
|
||||||
|
wrapEvent(senderPrivateKey, recipient, message, conversationTitle, replyTo),
|
||||||
// Wrap the event for each recipient
|
)
|
||||||
recipients.forEach(recipient => {
|
|
||||||
wrappeds.push(wrapEvent(senderPrivateKey, recipient, message, conversationTitle, replyTo))
|
|
||||||
})
|
|
||||||
|
|
||||||
return wrappeds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const unwrapEvent = nip59.unwrapEvent
|
export const unwrapEvent = nip59.unwrapEvent
|
||||||
|
|
26
nip59.ts
26
nip59.ts
|
@ -1,4 +1,4 @@
|
||||||
import { EventTemplate, UnsignedEvent, Event } from './core.ts'
|
import { EventTemplate, UnsignedEvent, NostrEvent } from './core.ts'
|
||||||
import { getConversationKey, decrypt, encrypt } from './nip44.ts'
|
import { getConversationKey, decrypt, encrypt } from './nip44.ts'
|
||||||
import { getEventHash, generateSecretKey, finalizeEvent, getPublicKey } from './pure.ts'
|
import { getEventHash, generateSecretKey, finalizeEvent, getPublicKey } from './pure.ts'
|
||||||
import { Seal, GiftWrap } from './kinds.ts'
|
import { Seal, GiftWrap } from './kinds.ts'
|
||||||
|
@ -15,10 +15,10 @@ const nip44ConversationKey = (privateKey: Uint8Array, publicKey: string) => getC
|
||||||
const nip44Encrypt = (data: EventTemplate, privateKey: Uint8Array, publicKey: string) =>
|
const nip44Encrypt = (data: EventTemplate, privateKey: Uint8Array, publicKey: string) =>
|
||||||
encrypt(JSON.stringify(data), nip44ConversationKey(privateKey, publicKey))
|
encrypt(JSON.stringify(data), nip44ConversationKey(privateKey, publicKey))
|
||||||
|
|
||||||
const nip44Decrypt = (data: Event, privateKey: Uint8Array) =>
|
const nip44Decrypt = (data: NostrEvent, privateKey: Uint8Array) =>
|
||||||
JSON.parse(decrypt(data.content, nip44ConversationKey(privateKey, data.pubkey)))
|
JSON.parse(decrypt(data.content, nip44ConversationKey(privateKey, data.pubkey)))
|
||||||
|
|
||||||
export function createRumor(event: Partial<UnsignedEvent>, privateKey: Uint8Array) {
|
export function createRumor(event: Partial<UnsignedEvent>, privateKey: Uint8Array): Rumor {
|
||||||
const rumor = {
|
const rumor = {
|
||||||
created_at: now(),
|
created_at: now(),
|
||||||
content: '',
|
content: '',
|
||||||
|
@ -32,7 +32,7 @@ export function createRumor(event: Partial<UnsignedEvent>, privateKey: Uint8Arra
|
||||||
return rumor as Rumor
|
return rumor as Rumor
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createSeal(rumor: Rumor, privateKey: Uint8Array, recipientPublicKey: string) {
|
export function createSeal(rumor: Rumor, privateKey: Uint8Array, recipientPublicKey: string): NostrEvent {
|
||||||
return finalizeEvent(
|
return finalizeEvent(
|
||||||
{
|
{
|
||||||
kind: Seal,
|
kind: Seal,
|
||||||
|
@ -41,10 +41,10 @@ export function createSeal(rumor: Rumor, privateKey: Uint8Array, recipientPublic
|
||||||
tags: [],
|
tags: [],
|
||||||
},
|
},
|
||||||
privateKey,
|
privateKey,
|
||||||
) as Event
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createWrap(seal: Event, recipientPublicKey: string) {
|
export function createWrap(seal: NostrEvent, recipientPublicKey: string): NostrEvent {
|
||||||
const randomKey = generateSecretKey()
|
const randomKey = generateSecretKey()
|
||||||
|
|
||||||
return finalizeEvent(
|
return finalizeEvent(
|
||||||
|
@ -55,10 +55,14 @@ export function createWrap(seal: Event, recipientPublicKey: string) {
|
||||||
tags: [['p', recipientPublicKey]],
|
tags: [['p', recipientPublicKey]],
|
||||||
},
|
},
|
||||||
randomKey,
|
randomKey,
|
||||||
) as Event
|
) as NostrEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
export function wrapEvent(event: Partial<UnsignedEvent>, senderPrivateKey: Uint8Array, recipientPublicKey: string) {
|
export function wrapEvent(
|
||||||
|
event: Partial<UnsignedEvent>,
|
||||||
|
senderPrivateKey: Uint8Array,
|
||||||
|
recipientPublicKey: string,
|
||||||
|
): NostrEvent {
|
||||||
const rumor = createRumor(event, senderPrivateKey)
|
const rumor = createRumor(event, senderPrivateKey)
|
||||||
|
|
||||||
const seal = createSeal(rumor, senderPrivateKey, recipientPublicKey)
|
const seal = createSeal(rumor, senderPrivateKey, recipientPublicKey)
|
||||||
|
@ -69,7 +73,7 @@ export function wrapManyEvents(
|
||||||
event: Partial<UnsignedEvent>,
|
event: Partial<UnsignedEvent>,
|
||||||
senderPrivateKey: Uint8Array,
|
senderPrivateKey: Uint8Array,
|
||||||
recipientsPublicKeys: string[],
|
recipientsPublicKeys: string[],
|
||||||
) {
|
): NostrEvent[] {
|
||||||
if (!recipientsPublicKeys || recipientsPublicKeys.length === 0) {
|
if (!recipientsPublicKeys || recipientsPublicKeys.length === 0) {
|
||||||
throw new Error('At least one recipient is required.')
|
throw new Error('At least one recipient is required.')
|
||||||
}
|
}
|
||||||
|
@ -85,12 +89,12 @@ export function wrapManyEvents(
|
||||||
return wrappeds
|
return wrappeds
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unwrapEvent(wrap: Event, recipientPrivateKey: Uint8Array): Rumor {
|
export function unwrapEvent(wrap: NostrEvent, recipientPrivateKey: Uint8Array): Rumor {
|
||||||
const unwrappedSeal = nip44Decrypt(wrap, recipientPrivateKey)
|
const unwrappedSeal = nip44Decrypt(wrap, recipientPrivateKey)
|
||||||
return nip44Decrypt(unwrappedSeal, recipientPrivateKey)
|
return nip44Decrypt(unwrappedSeal, recipientPrivateKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unwrapManyEvents(wrappedEvents: Event[], recipientPrivateKey: Uint8Array): Rumor[] {
|
export function unwrapManyEvents(wrappedEvents: NostrEvent[], recipientPrivateKey: Uint8Array): Rumor[] {
|
||||||
let unwrappedEvents: Rumor[] = []
|
let unwrappedEvents: Rumor[] = []
|
||||||
|
|
||||||
wrappedEvents.forEach(e => {
|
wrappedEvents.forEach(e => {
|
||||||
|
|
Loading…
Reference in New Issue