Skip to content

Commit e802b3d

Browse files
committed
feat: support subject tags in text notes and add NIP-14 support coverage
1 parent 1663b83 commit e802b3d

5 files changed

Lines changed: 40 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ NIPs with a relay-specific implementation are listed here.
5151
- [x] NIP-11: Relay information document
5252
- [x] NIP-12: Generic tag queries
5353
- [x] NIP-13: Proof of Work
54+
- [x] NIP-14: Subject tag in text events
5455
- [x] NIP-15: End of Stored Events Notice
5556
- [x] NIP-16: Event Treatment
5657
- [x] NIP-20: Command Results

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
9,
1212
11,
1313
12,
14+
14,
1415
15,
1516
16,
1617
17,

src/constants/base.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export enum EventTags {
4646
Event = 'e',
4747
Pubkey = 'p',
4848
Relay = 'r',
49+
// NIP-14: Subject for text notes
50+
Subject = 'subject',
4951
// Multicast = 'm',
5052
Deduplication = 'd',
5153
Expiration = 'expiration',

test/unit/repositories/event-repository.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,23 @@ describe('EventRepository', () => {
575575
'insert into "events" ("event_content", "event_created_at", "event_id", "event_kind", "event_pubkey", "event_signature", "event_tags", "expires_at", "remote_address") values (\'I\'\'ve set up mirroring between relays: https://i.imgur.com/HxCDipB.png\', 1648351380, X\'6b3cdd0302ded8068ad3f0269c74423ca4fee460f800f3d90103b63f14400407\', 1, X\'22e804d26ed16b68db5259e78449e96dab5d464c8f470bda3eb1a70467f2c793\', X\'b37adfed0e6398546d623536f9ddc92b95b7dc71927e1123266332659253ecd0ffa91ddf2c0a82a8426c5b363139d28534d6cac893b8a810149557a3f6d36768\', \'[["p","8355095016fddbe31fcf1453b26f613553e9758cf2263e190eac8fd96a3d3de9","wss://nostr-pub.wellorder.net"],["e","7377fa81fc6c7ae7f7f4ef8938d4a603f7bf98183b35ab128235cc92d4bebf96","wss://nostr-relay.untethr.me"]]\', NULL, \'::1\') on conflict do nothing',
576576
)
577577
})
578+
579+
it('preserves subject tag when serializing text note tags', () => {
580+
const event: Event = {
581+
id: '6b3cdd0302ded8068ad3f0269c74423ca4fee460f800f3d90103b63f14400407',
582+
pubkey: '22e804d26ed16b68db5259e78449e96dab5d464c8f470bda3eb1a70467f2c793',
583+
created_at: 1648351380,
584+
kind: 1,
585+
tags: [[EventTags.Subject, 'Weekly notes']],
586+
content: 'hello',
587+
sig: 'b37adfed0e6398546d623536f9ddc92b95b7dc71927e1123266332659253ecd0ffa91ddf2c0a82a8426c5b363139d28534d6cac893b8a810149557a3f6d36768',
588+
[ContextMetadataKey]: { remoteAddress: { address: '::1' } as any },
589+
}
590+
591+
const query = (repository as any).insert(event).toString()
592+
593+
expect(query).to.include('[["subject","Weekly notes"]]')
594+
})
578595
})
579596

580597
describe('deleteByPubkeyAndIds', () => {

test/unit/schemas/event-schema.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,22 @@ describe('NIP-01', () => {
108108
}
109109
})
110110
})
111+
112+
describe('NIP-14', () => {
113+
it('accepts subject tag on text note events', () => {
114+
const event: Event = {
115+
id: 'fa4dd948576fe182f5d0e3120b9df42c83dffa1c884754d5e4d3b0a2f98a01c5',
116+
pubkey: 'edfa27d49d2af37ee331e1225bb6ed1912c6d999281b36d8018ad99bc3573c29',
117+
created_at: 1660306803,
118+
kind: 1,
119+
tags: [[EventTags.Subject, 'SoB weekly update']],
120+
content: 'testing subject tag',
121+
sig: '313a9b8cd68267a51da84e292c0937d1f3686c6757c4584f50fcedad2b13fad755e6226924f79880fb5aa9de95c04231a4823981513ac9e7092bad7488282a96',
122+
}
123+
124+
const result = validateSchema(eventSchema)(event)
125+
126+
expect(result.error).to.be.undefined
127+
expect(result.value).to.deep.equal(event)
128+
})
129+
})

0 commit comments

Comments
 (0)