Skip to content

Commit bf0c4d4

Browse files
committed
nip10: improve, support quotes, author hints, change the way legacy refs are discovered.
1 parent 50fe7c2 commit bf0c4d4

File tree

4 files changed

+186
-98
lines changed

4 files changed

+186
-98
lines changed

jsr.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nostr/tools",
3-
"version": "2.10.1",
3+
"version": "2.10.2",
44
"exports": {
55
".": "./index.ts",
66
"./core": "./core.ts",

nip10.test.ts

+86-51
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ describe('parse NIP10-referenced events', () => {
55
test('legacy + a lot of events', () => {
66
let event = {
77
tags: [
8-
['e', 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c'],
9-
['e', 'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631'],
10-
['e', '5e081ebb19153357d7c31e8a10b9ceeef29313f58dc8d701f66727fab02aef64'],
11-
['e', '49aff7ae6daeaaa2777931b90f9bb29f6cb01c5a3d7d88c8ba82d890f264afb4'],
12-
['e', '567b7c11f0fe582361e3cea6fcc7609a8942dfe196ee1b98d5604c93fbeea976'],
13-
['e', '090c037b2e399ee74d9f134758928948dd9154413ca1a1acb37155046e03a051'],
14-
['e', '89f220b63465c93542b1a78caa3a952cf4f196e91a50596493c8093c533ebc4d'],
15-
['p', '77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7'],
16-
['p', '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec'],
178
['p', '4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0'],
9+
['p', '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec'],
10+
['p', '77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7'],
11+
['e', '89f220b63465c93542b1a78caa3a952cf4f196e91a50596493c8093c533ebc4d'],
12+
['e', '090c037b2e399ee74d9f134758928948dd9154413ca1a1acb37155046e03a051'],
13+
['e', '567b7c11f0fe582361e3cea6fcc7609a8942dfe196ee1b98d5604c93fbeea976'],
14+
['e', '49aff7ae6daeaaa2777931b90f9bb29f6cb01c5a3d7d88c8ba82d890f264afb4'],
15+
['e', '5e081ebb19153357d7c31e8a10b9ceeef29313f58dc8d701f66727fab02aef64'],
16+
['e', 'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631'],
17+
['e', 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c'],
1818
],
1919
}
2020

2121
expect(parse(event)).toEqual({
22+
quotes: [],
2223
mentions: [
2324
{
2425
id: 'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631',
@@ -55,41 +56,37 @@ describe('parse NIP10-referenced events', () => {
5556
relays: [],
5657
},
5758
],
58-
reply: {
59+
root: {
5960
id: '89f220b63465c93542b1a78caa3a952cf4f196e91a50596493c8093c533ebc4d',
6061
relays: [],
6162
},
62-
root: {
63+
reply: {
6364
id: 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c',
6465
relays: [],
6566
},
6667
})
6768
})
6869

69-
test('legacy + 3 events', () => {
70+
test('modern', () => {
7071
let event = {
7172
tags: [
72-
['e', 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c'],
73-
['e', 'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631'],
74-
['e', '5e081ebb19153357d7c31e8a10b9ceeef29313f58dc8d701f66727fab02aef64'],
75-
['p', '77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7'],
76-
['p', '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec'],
7773
['p', '4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0'],
74+
['p', '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec'],
75+
['e', '77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7'],
76+
['e', 'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631', '', 'root'],
77+
['e', 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c', '', 'reply'],
7878
],
7979
}
8080

8181
expect(parse(event)).toEqual({
82+
quotes: [],
8283
mentions: [
8384
{
84-
id: 'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631',
85+
id: '77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7',
8586
relays: [],
8687
},
8788
],
8889
profiles: [
89-
{
90-
pubkey: '77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7',
91-
relays: [],
92-
},
9390
{
9491
pubkey: '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec',
9592
relays: [],
@@ -99,30 +96,43 @@ describe('parse NIP10-referenced events', () => {
9996
relays: [],
10097
},
10198
],
102-
reply: {
103-
id: '5e081ebb19153357d7c31e8a10b9ceeef29313f58dc8d701f66727fab02aef64',
99+
root: {
100+
id: 'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631',
104101
relays: [],
105102
},
106-
root: {
103+
reply: {
107104
id: 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c',
108105
relays: [],
109106
},
110107
})
111108
})
112109

113-
test('legacy + 2 events', () => {
110+
test('modern, inverted, author hint', () => {
114111
let event = {
115112
tags: [
116-
['e', 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c'],
117-
['e', 'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631'],
118-
['p', '77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7'],
113+
['p', '4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0', 'wss://goiaba.com'],
119114
['p', '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec'],
120-
['p', '4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0'],
115+
['p', '77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7'],
116+
['e', '5e081ebb19153357d7c31e8a10b9ceeef29313f58dc8d701f66727fab02aef64', '', 'reply'],
117+
[
118+
'e',
119+
'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631',
120+
'wss://banana.com',
121+
'root',
122+
'4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0',
123+
],
124+
['e', 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c'],
121125
],
122126
}
123127

124128
expect(parse(event)).toEqual({
125-
mentions: [],
129+
quotes: [],
130+
mentions: [
131+
{
132+
id: 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c',
133+
relays: [],
134+
},
135+
],
126136
profiles: [
127137
{
128138
pubkey: '77ce56f89d1228f7ff3743ce1ad1b254857b9008564727ebd5a1f317362f6ca7',
@@ -134,60 +144,80 @@ describe('parse NIP10-referenced events', () => {
134144
},
135145
{
136146
pubkey: '4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0',
137-
relays: [],
147+
relays: ['wss://banana.com', 'wss://goiaba.com'],
138148
},
139149
],
140-
reply: {
150+
root: {
141151
id: 'bbd72f0ae14374aa8fb166b483cfcf99b57d7f4cf1600ccbf17c350040834631',
142-
relays: [],
152+
relays: ['wss://banana.com', 'wss://goiaba.com'],
153+
author: '4ca4f5533e40da5e0508796d409e6bb35a50b26fc304345617ab017183d83ac0',
143154
},
144-
root: {
145-
id: 'b857504288c18a15950dd05b9e8772c62ca6289d5aac373c0a8ee5b132e94e7c',
155+
reply: {
156+
id: '5e081ebb19153357d7c31e8a10b9ceeef29313f58dc8d701f66727fab02aef64',
146157
relays: [],
147158
},
148159
})
149160
})
150161

151-
test('legacy + 1 event', () => {
162+
test('1 event, relay hint from author', () => {
152163
let event = {
153164
tags: [
154-
['e', '9abbfd9b9ac5ecdab45d14b8bf8d746139ea039e931a1b376d19a239f1946590'],
155-
['p', '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec'],
165+
['p', '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec', 'wss://banana.com'],
166+
[
167+
'e',
168+
'9abbfd9b9ac5ecdab45d14b8bf8d746139ea039e931a1b376d19a239f1946590',
169+
'',
170+
'root',
171+
'534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec',
172+
],
156173
],
157174
}
158175

159176
expect(parse(event)).toEqual({
177+
quotes: [],
160178
mentions: [],
161179
profiles: [
162180
{
163181
pubkey: '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec',
164-
relays: [],
182+
relays: ['wss://banana.com'],
165183
},
166184
],
167-
reply: undefined,
185+
reply: {
186+
author: '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec',
187+
id: '9abbfd9b9ac5ecdab45d14b8bf8d746139ea039e931a1b376d19a239f1946590',
188+
relays: ['wss://banana.com'],
189+
},
168190
root: {
191+
author: '534780e44da7b494485e85cd4cca6af4f6caa1627472432b6f2a4ece0e9e54ec',
169192
id: '9abbfd9b9ac5ecdab45d14b8bf8d746139ea039e931a1b376d19a239f1946590',
170-
relays: [],
193+
relays: ['wss://banana.com'],
171194
},
172195
})
173196
})
174197

175-
test('recommended + 1 event', () => {
198+
test('many p 1 reply', () => {
176199
let event = {
177200
tags: [
178-
['p', 'a8c21fcd8aa1f4befba14d72fc7a012397732d30d8b3131af912642f3c726f52', 'wss://relay.mostr.pub'],
179-
['p', '003d7fd21fd09ff7f6f63a75daf194dd99feefbe6919cc376b7359d5090aa9a6', 'wss://relay.mostr.pub'],
180-
['p', '2f6fbe452edd3987d3c67f3b034c03ec5bcf4d054c521c3a954686f89f03212e', 'wss://relay.mostr.pub'],
181-
['p', '44c7c74668ff222b0e0b30579c49fc6e22dafcdeaad091036c947f9856590f1e', 'wss://relay.mostr.pub'],
182-
['p', 'c5cf39149caebda4cdd61771c51f6ba91ef5645919004e5c4998a4ea69f00512', 'wss://relay.mostr.pub'],
183-
['p', '094d44bb1e812696c57f57ad1c0c707812dedbe72c07e538b80639032c236a9e', 'wss://relay.mostr.pub'],
184201
['p', 'a1ba0ac9b6ec098f726a3c11ec654df4a32cbb84b5377e8788395e9c27d9ecda', 'wss://relay.mostr.pub'],
185-
['e', 'f9472913904ab7e9da008dcb2d85fd4af2d2993ada483d00c646d0c4481d031d', 'wss://relay.mostr.pub', 'reply'],
202+
['p', '094d44bb1e812696c57f57ad1c0c707812dedbe72c07e538b80639032c236a9e', 'wss://relay.mostr.pub'],
203+
['p', 'c5cf39149caebda4cdd61771c51f6ba91ef5645919004e5c4998a4ea69f00512', 'wss://relay.mostr.pub'],
204+
['p', '44c7c74668ff222b0e0b30579c49fc6e22dafcdeaad091036c947f9856590f1e', 'wss://relay.mostr.pub'],
205+
['p', '2f6fbe452edd3987d3c67f3b034c03ec5bcf4d054c521c3a954686f89f03212e', 'wss://relay.mostr.pub'],
206+
['p', '003d7fd21fd09ff7f6f63a75daf194dd99feefbe6919cc376b7359d5090aa9a6', 'wss://relay.mostr.pub'],
207+
['p', 'a8c21fcd8aa1f4befba14d72fc7a012397732d30d8b3131af912642f3c726f52', 'wss://relay.mostr.pub'],
208+
[
209+
'e',
210+
'f9472913904ab7e9da008dcb2d85fd4af2d2993ada483d00c646d0c4481d031d',
211+
'wss://relay.mostr.pub',
212+
'reply',
213+
'c5cf39149caebda4cdd61771c51f6ba91ef5645919004e5c4998a4ea69f00512',
214+
],
186215
['mostr', 'https://poa.st/objects/dc50684b-6364-4264-ab16-49f4622f05ea'],
187216
],
188217
}
189218

190219
expect(parse(event)).toEqual({
220+
quotes: [],
191221
mentions: [],
192222
profiles: [
193223
{
@@ -222,8 +252,13 @@ describe('parse NIP10-referenced events', () => {
222252
reply: {
223253
id: 'f9472913904ab7e9da008dcb2d85fd4af2d2993ada483d00c646d0c4481d031d',
224254
relays: ['wss://relay.mostr.pub'],
255+
author: 'c5cf39149caebda4cdd61771c51f6ba91ef5645919004e5c4998a4ea69f00512',
256+
},
257+
root: {
258+
id: 'f9472913904ab7e9da008dcb2d85fd4af2d2993ada483d00c646d0c4481d031d',
259+
relays: ['wss://relay.mostr.pub'],
260+
author: 'c5cf39149caebda4cdd61771c51f6ba91ef5645919004e5c4998a4ea69f00512',
225261
},
226-
root: undefined,
227262
})
228263
})
229264
})

0 commit comments

Comments
 (0)