diff --git a/event.test.ts b/event.test.ts index ff91ac6..619efce 100644 --- a/event.test.ts +++ b/event.test.ts @@ -14,7 +14,7 @@ import { getPublicKey } from './keys.ts' describe('Event', () => { describe('getBlankEvent', () => { it('should return a blank event object', () => { - expect(getBlankEvent()).toEqual({ + expect(getBlankEvent(255)).toEqual({ kind: 255, content: '', tags: [], diff --git a/event.ts b/event.ts index d07c56e..d72f8ed 100644 --- a/event.ts +++ b/event.ts @@ -8,35 +8,33 @@ import { utf8Encoder } from './utils.ts' /** Designates a verified event signature. */ export const verifiedSymbol = Symbol('verified') -/** @deprecated Use numbers instead. */ -/* eslint-disable no-unused-vars */ -export enum Kind { - Metadata = 0, - Text = 1, - RecommendRelay = 2, - Contacts = 3, - EncryptedDirectMessage = 4, - EventDeletion = 5, - Repost = 6, - Reaction = 7, - BadgeAward = 8, - ChannelCreation = 40, - ChannelMetadata = 41, - ChannelMessage = 42, - ChannelHideMessage = 43, - ChannelMuteUser = 44, - Blank = 255, - Report = 1984, - ZapRequest = 9734, - Zap = 9735, - RelayList = 10002, - ClientAuth = 22242, - NwcRequest = 23194, - HttpAuth = 27235, - ProfileBadge = 30008, - BadgeDefinition = 30009, - Article = 30023, - FileMetadata = 1063, +export const Kind = { + Metadata: 0, + Text: 1, + RecommendRelay: 2, + Contacts: 3, + EncryptedDirectMessage: 4, + EventDeletion: 5, + Repost: 6, + Reaction: 7, + BadgeAward: 8, + ChannelCreation: 40, + ChannelMetadata: 41, + ChannelMessage: 42, + ChannelHideMessage: 43, + ChannelMuteUser: 44, + Blank: 255, + Report: 1984, + ZapRequest: 9734, + Zap: 9735, + RelayList: 10002, + ClientAuth: 22242, + NwcRequest: 23194, + HttpAuth: 27235, + ProfileBadge: 30008, + BadgeDefinition: 30009, + Article: 30023, + FileMetadata: 1063, } export interface Event { @@ -61,9 +59,7 @@ export interface VerifiedEvent extends Event { [verifiedSymbol]: true } -export function getBlankEvent(): EventTemplate -export function getBlankEvent(kind: K): EventTemplate -export function getBlankEvent(kind: K | Kind.Blank = Kind.Blank) { +export function getBlankEvent(kind: number = 255): EventTemplate { return { kind, content: '', diff --git a/nip13.test.ts b/nip13.test.ts index 9463f4f..2b9b491 100644 --- a/nip13.test.ts +++ b/nip13.test.ts @@ -1,4 +1,5 @@ import { getPow, minePow } from './nip13.ts' +import { Kind } from './event.ts' test('identifies proof-of-work difficulty', async () => { const id = '000006d8c378af1779d2feebc7603a125d99eca0ccf1085959b307f64e5dd358' @@ -11,7 +12,7 @@ test('mines POW for an event', async () => { const event = minePow( { - kind: 1, + kind: Kind.Text, tags: [], content: 'Hello, world!', created_at: 0, diff --git a/nip18.ts b/nip18.ts index 3a7e6da..f03d95c 100644 --- a/nip18.ts +++ b/nip18.ts @@ -23,7 +23,7 @@ export function finishRepostEvent( reposted: Event, relayUrl: string, privateKey: string, -): Event { +): Event { return finishEvent( { kind: Kind.Repost, diff --git a/nip25.ts b/nip25.ts index 5e10c47..2640d7f 100644 --- a/nip25.ts +++ b/nip25.ts @@ -16,11 +16,7 @@ export type ReactionEventTemplate = { created_at: number } -export function finishReactionEvent( - t: ReactionEventTemplate, - reacted: Event, - privateKey: string, -): Event { +export function finishReactionEvent(t: ReactionEventTemplate, reacted: Event, privateKey: string): Event { const inheritedTags = reacted.tags.filter(tag => tag.length >= 2 && (tag[0] === 'e' || tag[0] === 'p')) return finishEvent( diff --git a/nip28.ts b/nip28.ts index fba812f..a540586 100644 --- a/nip28.ts +++ b/nip28.ts @@ -44,10 +44,7 @@ export interface ChannelMuteUserEventTemplate { tags?: string[][] } -export const channelCreateEvent = ( - t: ChannelCreateEventTemplate, - privateKey: string, -): Event | undefined => { +export const channelCreateEvent = (t: ChannelCreateEventTemplate, privateKey: string): Event | undefined => { let content: string if (typeof t.content === 'object') { content = JSON.stringify(t.content) @@ -71,7 +68,7 @@ export const channelCreateEvent = ( export const channelMetadataEvent = ( t: ChannelMetadataEventTemplate, privateKey: string, -): Event | undefined => { +): Event | undefined => { let content: string if (typeof t.content === 'object') { content = JSON.stringify(t.content) @@ -92,7 +89,7 @@ export const channelMetadataEvent = ( ) } -export const channelMessageEvent = (t: ChannelMessageEventTemplate, privateKey: string): Event => { +export const channelMessageEvent = (t: ChannelMessageEventTemplate, privateKey: string): Event => { const tags = [['e', t.channel_create_event_id, t.relay_url, 'root']] if (t.reply_to_channel_message_event_id) { @@ -114,7 +111,7 @@ export const channelMessageEvent = (t: ChannelMessageEventTemplate, privateKey: export const channelHideMessageEvent = ( t: ChannelHideMessageEventTemplate, privateKey: string, -): Event | undefined => { +): Event | undefined => { let content: string if (typeof t.content === 'object') { content = JSON.stringify(t.content) @@ -138,7 +135,7 @@ export const channelHideMessageEvent = ( export const channelMuteUserEvent = ( t: ChannelMuteUserEventTemplate, privateKey: string, -): Event | undefined => { +): Event | undefined => { let content: string if (typeof t.content === 'object') { content = JSON.stringify(t.content) diff --git a/nip57.ts b/nip57.ts index 94fd488..0c523b4 100644 --- a/nip57.ts +++ b/nip57.ts @@ -13,7 +13,7 @@ export function useFetchImplementation(fetchImplementation: any) { _fetch = fetchImplementation } -export async function getZapEndpoint(metadata: Event): Promise { +export async function getZapEndpoint(metadata: Event): Promise { try { let lnurl: string = '' let { lud06, lud16 } = JSON.parse(metadata.content) @@ -53,12 +53,12 @@ export function makeZapRequest({ amount: number comment: string relays: string[] -}): EventTemplate { +}): EventTemplate { if (!amount) throw new Error('amount not given') if (!profile) throw new Error('profile not given') - let zr: EventTemplate = { - kind: 9734, + let zr: EventTemplate = { + kind: Kind.ZapRequest, created_at: Math.round(Date.now() / 1000), content: comment, tags: [ @@ -111,12 +111,12 @@ export function makeZapReceipt({ preimage?: string bolt11: string paidAt: Date -}): EventTemplate { - let zr: Event = JSON.parse(zapRequest) +}): EventTemplate { + let zr: Event = JSON.parse(zapRequest) let tagsFromZapRequest = zr.tags.filter(([t]) => t === 'e' || t === 'p' || t === 'a') - let zap: EventTemplate = { - kind: 9735, + let zap: EventTemplate = { + kind: Kind.Zap, created_at: Math.round(paidAt.getTime() / 1000), content: '', tags: [...tagsFromZapRequest, ['bolt11', bolt11], ['description', zapRequest]],