Skip to content

Commit 27749d9

Browse files
committed
fix nip19: relays TLV items are optional.
1 parent 9530849 commit 27749d9

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

nip19.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,15 @@ test('encode and decode naddr', () => {
5656
expect(data.kind).toEqual(30023)
5757
expect(data.identifier).toEqual('banana')
5858
})
59+
60+
test('encode and decode naddr from habla.news', () => {
61+
let {type, data} = nip19.decode(
62+
'naddr1qq98yetxv4ex2mnrv4esygrl54h466tz4v0re4pyuavvxqptsejl0vxcmnhfl60z3rth2xkpjspsgqqqw4rsf34vl5'
63+
)
64+
expect(type).toEqual('naddr')
65+
expect(data.pubkey).toEqual(
66+
'7fa56f5d6962ab1e3cd424e758c3002b8665f7b0d8dcee9fe9e288d7751ac194'
67+
)
68+
expect(data.kind).toEqual(30023)
69+
expect(data.identifier).toEqual('references')
70+
})

nip19.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function decode(nip19: string): {
3939
type: 'nprofile',
4040
data: {
4141
pubkey: secp256k1.utils.bytesToHex(tlv[0][0]),
42-
relays: tlv[1].map(d => utf8Decoder.decode(d))
42+
relays: tlv[1] ? tlv[1].map(d => utf8Decoder.decode(d)) : []
4343
}
4444
}
4545
}
@@ -52,7 +52,7 @@ export function decode(nip19: string): {
5252
type: 'nevent',
5353
data: {
5454
id: secp256k1.utils.bytesToHex(tlv[0][0]),
55-
relays: tlv[1].map(d => utf8Decoder.decode(d))
55+
relays: tlv[1] ? tlv[1].map(d => utf8Decoder.decode(d)) : []
5656
}
5757
}
5858
}
@@ -71,7 +71,7 @@ export function decode(nip19: string): {
7171
identifier: utf8Decoder.decode(tlv[0][0]),
7272
pubkey: secp256k1.utils.bytesToHex(tlv[2][0]),
7373
kind: parseInt(secp256k1.utils.bytesToHex(tlv[3][0]), 16),
74-
relays: tlv[1].map(d => utf8Decoder.decode(d))
74+
relays: tlv[1] ? tlv[1].map(d => utf8Decoder.decode(d)) : []
7575
}
7676
}
7777
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nostr-tools",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"description": "Tools for making a Nostr client.",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)