nip19: support empty "d" in naddr.

This commit is contained in:
fiatjaf
2025-11-13 11:45:39 -03:00
parent dcb9378f09
commit e6dd124042

View File

@@ -104,12 +104,13 @@ func Decode(bech32string string) (prefix string, value any, err error) {
} }
case "naddr": case "naddr":
var result nostr.EntityPointer var result nostr.EntityPointer
var hasIdentifier bool
curr := 0 curr := 0
for { for {
t, v := readTLVEntry(data[curr:]) t, v := readTLVEntry(data[curr:])
if v == nil { if v == nil {
// end here // end here
if result.Kind == 0 || result.Identifier == "" || result.PublicKey == nostr.ZeroPK { if result.Kind == 0 || !hasIdentifier || result.PublicKey == nostr.ZeroPK {
return prefix, result, fmt.Errorf("incomplete naddr") return prefix, result, fmt.Errorf("incomplete naddr")
} }
@@ -119,6 +120,7 @@ func Decode(bech32string string) (prefix string, value any, err error) {
switch t { switch t {
case TLVDefault: case TLVDefault:
result.Identifier = string(v) result.Identifier = string(v)
hasIdentifier = true
case TLVRelay: case TLVRelay:
result.Relays = append(result.Relays, string(v)) result.Relays = append(result.Relays, string(v))
case TLVAuthor: case TLVAuthor: