@@ -13,8 +13,8 @@ export interface NostrEvent<K extends EventKind = EventKind> {
13
13
pubkey : PublicKey ;
14
14
created_at : Timestamp ;
15
15
kind : K ;
16
- tags : Tag [ ] ;
17
- content : Stringified < EventContent [ K ] > ;
16
+ tags : TagFor [ K ] [ ] ;
17
+ content : Stringified < EventContentFor [ K ] > ;
18
18
sig : Signature ;
19
19
}
20
20
@@ -26,31 +26,34 @@ export type Timestamp = Brand<number, "EventTimeStamp">;
26
26
// Tags
27
27
// ----------------------
28
28
29
- export type Tag < T extends TagName = TagName > = [ T , ...string [ ] ] ;
29
+ export interface TagFor {
30
+ 0 : AnyTag ;
31
+ 1 : AnyTag ;
32
+ 2 : AnyTag ;
33
+ }
34
+
35
+ export type AnyTag = string [ ] ;
30
36
31
- export type TagName = Brand < string , "TagName" > ;
32
37
export type IndexedEventTag = [ IndexedEventTagName , ...string [ ] ] ;
33
38
34
- export type EventTag = [ "e" , EventId , RecmRelayUrl ?] ;
35
- export type PubKeyTag = [ "p" , PublicKey , RecmRelayUrl ?] ;
39
+ export type EventTag = [ "e" , EventId , RelayUrl ?] ;
40
+ export type PubKeyTag = [ "p" , PublicKey , RelayUrl ?] ;
36
41
export type ParameterizedReplaceableEventTag = [
37
42
"a" ,
38
43
`${EventKind } :${PublicKey } :${TagValue < "d" > } `,
39
- RecmRelayUrl ?,
44
+ RelayUrl ?,
40
45
] ;
41
46
export type NonParameterizedReplaceableEventTag = [
42
47
"a" ,
43
48
`${EventKind } :${PublicKey } `,
44
- RecmRelayUrl ?,
49
+ RelayUrl ?,
45
50
] ;
46
51
47
52
// TODO: Use template literal
48
53
export type IndexedEventTagName = Brand < string , "IndexedEventTagName" > ;
49
54
// TODO: Use template literal
50
55
export type TagValue < T extends string = string > = Brand < string , `${T } TagValue`> ;
51
56
52
- export type RecmRelayUrl = RelayUrl ;
53
-
54
57
export type PrivateKey = Brand < string , "PrivateKey" > ;
55
58
export type Signature = Brand < string , "EventSignature" > ;
56
59
@@ -59,8 +62,8 @@ export type EventSerializePrecursor<K extends EventKind = EventKind> = [
59
62
pubkey : PublicKey ,
60
63
created_at : Timestamp ,
61
64
kind : K ,
62
- tags : Tag [ ] ,
63
- content : Stringified < EventContent [ K ] > ,
65
+ tags : TagFor [ K ] [ ] ,
66
+ content : Stringified < EventContentFor [ K ] > ,
64
67
] ;
65
68
66
69
// ----------------------
@@ -96,6 +99,7 @@ export type EventMessage<K extends EventKind = EventKind> = [
96
99
] ;
97
100
export type OkMessage < B extends boolean = boolean > = [
98
101
"OK" ,
102
+
99
103
EventId ,
100
104
B ,
101
105
OkMessageBody < B > ,
@@ -139,10 +143,17 @@ export type SubscriptionFilter<
139
143
// Basic event kinds
140
144
// ----------------------
141
145
142
- export type EventKind < T extends number = number > = Brand < T , "EventKind" > ;
146
+ export enum EventKind {
147
+ Metadata = 0 ,
148
+ TextNote = 1 ,
149
+ /**
150
+ * @deprecated
151
+ */
152
+ RecommendRelay = 2 ,
153
+ }
143
154
144
- export type MetadataEvent = NostrEvent < EventKind < 0 > > ;
145
- export type TextNoteEvent = NostrEvent < EventKind < 1 > > ;
155
+ export type MetadataEvent = NostrEvent < 0 > ;
156
+ export type TextNoteEvent = NostrEvent < 1 > ;
146
157
147
158
// TODO: Use template literal for T
148
159
@@ -168,44 +179,35 @@ export type ParameterizedReplaceableEventKind<T extends number = number> =
168
179
"ParameterizedReplaceable"
169
180
> ;
170
181
171
- export const EventKind = {
172
- 0 : 0 as EventKind < 0 > ,
173
- Metadata : 0 as EventKind < 0 > ,
174
-
175
- 1 : 1 as EventKind < 1 > ,
176
- TextNote : 1 as EventKind < 1 > ,
177
-
178
- $ < T extends number > ( kind : T ) : EventKind < T > {
179
- return kind as EventKind < T > ;
180
- } ,
181
-
182
- isRegularEventKind (
182
+ // deno-lint-ignore no-namespace
183
+ export namespace EventKind {
184
+ export function isRegularEventKind (
183
185
kind : EventKind ,
184
186
) : kind is RegularEventKind {
185
187
return 1000 <= kind && kind < 10000 ;
186
- } ,
187
- isReplaceableEventKind (
188
+ }
189
+ export function isReplaceableEventKind (
188
190
kind : EventKind ,
189
191
) : kind is ReplaceableEventKind {
190
- return ( 10000 <= kind && kind < 20000 ) || kind === 0 || kind === 3 ;
191
- } ,
192
- isEphemeralEventKind (
192
+ return ( 10000 <= kind && kind < 20000 ) || kind === 0 ;
193
+ }
194
+ export function isEphemeralEventKind (
193
195
kind : EventKind ,
194
196
) : kind is EphemeralEventKind {
195
197
return 20000 <= kind && kind < 30000 ;
196
- } ,
197
- isParameterizedReplaceableEventKind (
198
+ }
199
+ export function isParameterizedReplaceableEventKind (
198
200
kind : EventKind ,
199
201
) : kind is ParameterizedReplaceableEventKind {
200
202
return 30000 <= kind && kind < 40000 ;
201
- } ,
202
- } ;
203
+ }
204
+ }
203
205
204
- export type EventContent = [
205
- MetadataContent ,
206
- string ,
207
- RelayUrl ,
208
- ] ;
206
+ export interface EventContentFor extends Record < EventKind , unknown > {
207
+ 0 : MetadataContent ;
208
+ 1 : string ;
209
+ 2 : RelayUrl ;
210
+ }
209
211
210
212
export interface MetadataContent {
211
213
name : string ;
0 commit comments