Skip to content

Commit a8a805f

Browse files
AsaiToshiyafiatjaf
authored andcommitted
nip19: remove note1.
1 parent 5a55c67 commit a8a805f

6 files changed

+29
-57
lines changed

nip19.test.ts

+1-19
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,6 @@ describe('NostrTypeGuard', () => {
244244
expect(is).toBeFalse()
245245
})
246246

247-
test('isNote', () => {
248-
const is = NostrTypeGuard.isNote('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky')
249-
250-
expect(is).toBeTrue()
251-
})
252-
253-
test('isNote with invalid note', () => {
254-
const is = NostrTypeGuard.isNote('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sçlreky')
255-
256-
expect(is).toBeFalse()
257-
})
258-
259-
test('isNote with invalid note', () => {
260-
const is = NostrTypeGuard.isNote('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzasv8xeh5q92fv33sjgqy4pats')
261-
262-
expect(is).toBeFalse()
263-
})
264-
265247
test('isNcryptsec', () => {
266248
const is = NostrTypeGuard.isNcryptsec(
267249
'ncryptsec1qgg9947rlpvqu76pj5ecreduf9jxhselq2nae2kghhvd5g7dgjtcxfqtd67p9m0w57lspw8gsq6yphnm8623nsl8xn9j4jdzz84zm3frztj3z7s35vpzmqf6ksu8r89qk5z2zxfmu5gv8th8wclt0h4p',
@@ -279,7 +261,7 @@ describe('NostrTypeGuard', () => {
279261
})
280262

281263
test('isNcryptsec with invalid ncrytpsec', () => {
282-
const is = NostrTypeGuard.isNcryptsec('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sçlreky')
264+
const is = NostrTypeGuard.isNcryptsec('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzãsv8xeh5q92fv33sjgqy4pats')
283265

284266
expect(is).toBeFalse()
285267
})

nip19.ts

-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export type NEvent = `nevent1${string}`
88
export type NAddr = `naddr1${string}`
99
export type NSec = `nsec1${string}`
1010
export type NPub = `npub1${string}`
11-
export type Note = `note1${string}`
1211
export type Ncryptsec = `ncryptsec1${string}`
1312

1413
export const NostrTypeGuard = {
@@ -17,7 +16,6 @@ export const NostrTypeGuard = {
1716
isNAddr: (value?: string | null): value is NAddr => /^naddr1[a-z\d]+$/.test(value || ''),
1817
isNSec: (value?: string | null): value is NSec => /^nsec1[a-z\d]{58}$/.test(value || ''),
1918
isNPub: (value?: string | null): value is NPub => /^npub1[a-z\d]{58}$/.test(value || ''),
20-
isNote: (value?: string | null): value is Note => /^note1[a-z\d]+$/.test(value || ''),
2119
isNcryptsec: (value?: string | null): value is Ncryptsec => /^ncryptsec1[a-z\d]+$/.test(value || ''),
2220
}
2321

@@ -67,7 +65,6 @@ type Prefixes = {
6765
naddr: AddressPointer
6866
nsec: Uint8Array
6967
npub: string
70-
note: string
7168
}
7269

7370
type DecodeValue<Prefix extends keyof Prefixes> = {
@@ -140,7 +137,6 @@ export function decode(nip19: string): DecodeResult {
140137
return { type: prefix, data }
141138

142139
case 'npub':
143-
case 'note':
144140
return { type: prefix, data: bytesToHex(data) }
145141

146142
default:
@@ -173,10 +169,6 @@ export function npubEncode(hex: string): NPub {
173169
return encodeBytes('npub', hexToBytes(hex))
174170
}
175171

176-
export function noteEncode(hex: string): Note {
177-
return encodeBytes('note', hexToBytes(hex))
178-
}
179-
180172
function encodeBech32<Prefix extends string>(prefix: Prefix, data: Uint8Array): `${Prefix}1${string}` {
181173
let words = bech32.toWords(data)
182174
return bech32.encode(prefix, words, Bech32MaxSize) as `${Prefix}1${string}`

nip21.test.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ import { test as testRegex, parse } from './nip21.ts'
33

44
test('test()', () => {
55
expect(testRegex('nostr:npub108pv4cg5ag52nq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6')).toBe(true)
6-
expect(testRegex('nostr:note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky')).toBe(true)
76
expect(testRegex(' nostr:npub108pv4cg5ag52nq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6')).toBe(false)
87
expect(testRegex('nostr:')).toBe(false)
98
expect(testRegex('nostr:npub108pv4cg5ag52nQq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6')).toBe(false)
109
expect(testRegex('gggggg')).toBe(false)
1110
})
1211

1312
test('parse', () => {
14-
const result = parse('nostr:note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky')
13+
const result = parse('nostr:npub108pv4cg5ag52nq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6')
1514

1615
expect(result).toEqual({
17-
uri: 'nostr:note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky',
18-
value: 'note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky',
16+
uri: 'nostr:npub108pv4cg5ag52nq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6',
17+
value: 'npub108pv4cg5ag52nq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6',
1918
decoded: {
20-
type: 'note',
21-
data: '46d731680add2990efe1cc619dc9b8014feeb23261ab9dee50e9d11814de5a2b',
19+
type: 'npub',
20+
data: '79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6',
2221
},
2322
})
2423
})

nip27.test.ts

+20-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { matchAll, replaceAll } from './nip27.ts'
33

44
test('matchAll', () => {
55
const result = matchAll(
6-
'Hello nostr:npub108pv4cg5ag52nq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6!\n\nnostr:note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky',
6+
'Hello nostr:npub108pv4cg5ag52nq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6!\n\nnostr:nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9',
77
)
88

99
expect([...result]).toEqual([
@@ -18,46 +18,52 @@ test('matchAll', () => {
1818
end: 75,
1919
},
2020
{
21-
uri: 'nostr:note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky',
22-
value: 'note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky',
21+
uri: 'nostr:nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9',
22+
value: 'nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9',
2323
decoded: {
24-
type: 'note',
25-
data: '46d731680add2990efe1cc619dc9b8014feeb23261ab9dee50e9d11814de5a2b',
24+
type: 'nevent',
25+
data: {
26+
id: 'b3e392b11f5d4f28321cedd09303a748acfd0487aea5a7450b3481c60b6e4f87',
27+
relays: ['wss://relay.example.com'],
28+
},
2629
},
2730
start: 78,
28-
end: 147,
31+
end: 192,
2932
},
3033
])
3134
})
3235

3336
test('matchAll with an invalid nip19', () => {
3437
const result = matchAll(
35-
'Hello nostr:npub129tvj896hqqkljerxkccpj9flshwnw999v9uwn9lfmwlj8vnzwgq9y5llnpub1rujdpkd8mwezrvpqd2rx2zphfaztqrtsfg6w3vdnlj!\n\nnostr:note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky',
38+
'Hello nostr:npub129tvj896hqqkljerxkccpj9flshwnw999v9uwn9lfmwlj8vnzwgq9y5llnpub1rujdpkd8mwezrvpqd2rx2zphfaztqrtsfg6w3vdnlj!\n\nnostr:nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9',
3639
)
3740

3841
expect([...result]).toEqual([
3942
{
4043
decoded: {
41-
data: '46d731680add2990efe1cc619dc9b8014feeb23261ab9dee50e9d11814de5a2b',
42-
type: 'note',
44+
data: {
45+
id: 'b3e392b11f5d4f28321cedd09303a748acfd0487aea5a7450b3481c60b6e4f87',
46+
relays: ['wss://relay.example.com'],
47+
},
48+
type: 'nevent',
4349
},
44-
end: 193,
50+
end: 238,
4551
start: 124,
46-
uri: 'nostr:note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky',
47-
value: 'note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky',
52+
uri: 'nostr:nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9',
53+
value: 'nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9',
4854
},
4955
])
5056
})
5157

5258
test('replaceAll', () => {
5359
const content =
54-
'Hello nostr:npub108pv4cg5ag52nq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6!\n\nnostr:note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky'
60+
'Hello nostr:npub108pv4cg5ag52nq082kd5leu9ffrn2gdg6g4xdwatn73y36uzplmq9uyev6!\n\nnostr:nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9'
5561

5662
const result = replaceAll(content, ({ decoded, value }) => {
5763
switch (decoded.type) {
5864
case 'npub':
5965
return '@alex'
60-
case 'note':
66+
case 'nevent':
6167
return '!1234'
6268
default:
6369
return value

nip27.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export function* matchAll(content: string): Iterable<NostrURIMatch> {
4444
* switch(decoded.type) {
4545
* case 'npub':
4646
* return renderMention(decoded)
47-
* case 'note':
48-
* return renderNote(decoded)
47+
* case 'nevent':
48+
* return renderEvent(decoded)
4949
* default:
5050
* return value
5151
* }

references.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type Reference = {
99
address?: AddressPointer
1010
}
1111

12-
const mentionRegex = /\bnostr:((note|npub|naddr|nevent|nprofile)1\w+)\b|#\[(\d+)\]/g
12+
const mentionRegex = /\bnostr:((npub|naddr|nevent|nprofile)1\w+)\b|#\[(\d+)\]/g
1313

1414
export function parseReferences(evt: Event): Reference[] {
1515
let references: Reference[] = []
@@ -33,13 +33,6 @@ export function parseReferences(evt: Event): Reference[] {
3333
})
3434
break
3535
}
36-
case 'note': {
37-
references.push({
38-
text: ref[0],
39-
event: { id: data as string, relays: [] },
40-
})
41-
break
42-
}
4336
case 'nevent': {
4437
references.push({
4538
text: ref[0],

0 commit comments

Comments
 (0)