fix: always encode as naddr for PRE

This commit is contained in:
2023-10-18 15:06:22 +01:00
parent ce09b92518
commit 4be93c8f51

View File

@ -21,11 +21,13 @@ export class NostrLink {
readonly relays?: Array<string>, readonly relays?: Array<string>,
) {} ) {}
encode(type: NostrPrefix = this.type): string { encode(type?: NostrPrefix): string {
if (type === NostrPrefix.Note || type === NostrPrefix.PrivateKey || type === NostrPrefix.PublicKey) { // cant encode 'naddr' to 'note'/'nevent' because 'id' is not hex
return hexToBech32(type, this.id); let newType = this.type === NostrPrefix.Address ? this.type : type ?? this.type;
if (newType === NostrPrefix.Note || newType === NostrPrefix.PrivateKey || newType === NostrPrefix.PublicKey) {
return hexToBech32(newType, this.id);
} else { } else {
return encodeTLV(type, this.id, this.relays, this.kind, this.author); return encodeTLV(newType, this.id, this.relays, this.kind, this.author);
} }
} }