mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
fix nip19: relays TLV items are optional.
This commit is contained in:
@@ -56,3 +56,15 @@ test('encode and decode naddr', () => {
|
|||||||
expect(data.kind).toEqual(30023)
|
expect(data.kind).toEqual(30023)
|
||||||
expect(data.identifier).toEqual('banana')
|
expect(data.identifier).toEqual('banana')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('encode and decode naddr from habla.news', () => {
|
||||||
|
let {type, data} = nip19.decode(
|
||||||
|
'naddr1qq98yetxv4ex2mnrv4esygrl54h466tz4v0re4pyuavvxqptsejl0vxcmnhfl60z3rth2xkpjspsgqqqw4rsf34vl5'
|
||||||
|
)
|
||||||
|
expect(type).toEqual('naddr')
|
||||||
|
expect(data.pubkey).toEqual(
|
||||||
|
'7fa56f5d6962ab1e3cd424e758c3002b8665f7b0d8dcee9fe9e288d7751ac194'
|
||||||
|
)
|
||||||
|
expect(data.kind).toEqual(30023)
|
||||||
|
expect(data.identifier).toEqual('references')
|
||||||
|
})
|
||||||
|
|||||||
6
nip19.ts
6
nip19.ts
@@ -39,7 +39,7 @@ export function decode(nip19: string): {
|
|||||||
type: 'nprofile',
|
type: 'nprofile',
|
||||||
data: {
|
data: {
|
||||||
pubkey: secp256k1.utils.bytesToHex(tlv[0][0]),
|
pubkey: secp256k1.utils.bytesToHex(tlv[0][0]),
|
||||||
relays: tlv[1].map(d => utf8Decoder.decode(d))
|
relays: tlv[1] ? tlv[1].map(d => utf8Decoder.decode(d)) : []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ export function decode(nip19: string): {
|
|||||||
type: 'nevent',
|
type: 'nevent',
|
||||||
data: {
|
data: {
|
||||||
id: secp256k1.utils.bytesToHex(tlv[0][0]),
|
id: secp256k1.utils.bytesToHex(tlv[0][0]),
|
||||||
relays: tlv[1].map(d => utf8Decoder.decode(d))
|
relays: tlv[1] ? tlv[1].map(d => utf8Decoder.decode(d)) : []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ export function decode(nip19: string): {
|
|||||||
identifier: utf8Decoder.decode(tlv[0][0]),
|
identifier: utf8Decoder.decode(tlv[0][0]),
|
||||||
pubkey: secp256k1.utils.bytesToHex(tlv[2][0]),
|
pubkey: secp256k1.utils.bytesToHex(tlv[2][0]),
|
||||||
kind: parseInt(secp256k1.utils.bytesToHex(tlv[3][0]), 16),
|
kind: parseInt(secp256k1.utils.bytesToHex(tlv[3][0]), 16),
|
||||||
relays: tlv[1].map(d => utf8Decoder.decode(d))
|
relays: tlv[1] ? tlv[1].map(d => utf8Decoder.decode(d)) : []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "1.6.0",
|
"version": "1.6.1",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user