fix: always encode as naddr for PRE
This commit is contained in:
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user