bug: prefix hint breaks links

This commit is contained in:
Kieran 2023-04-28 19:26:46 +01:00
parent 48852f3099
commit 805ce1d96e
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
1 changed files with 9 additions and 1 deletions

View File

@ -523,7 +523,7 @@ export function parseNostrLink(link: string, prefixHint?: NostrPrefix): NostrLin
const entity = link.startsWith("web+nostr:") || link.startsWith("nostr:") ? link.split(":")[1] : link;
const isPrefix = (prefix: NostrPrefix) => {
return entity.startsWith(prefix) || prefix === prefixHint;
return entity.startsWith(prefix);
};
if (isPrefix(NostrPrefix.PublicKey)) {
@ -579,6 +579,14 @@ export function parseNostrLink(link: string, prefixHint?: NostrPrefix): NostrLin
encode,
};
}
} else if (prefixHint) {
return {
type: prefixHint,
id: link,
encode: () => hexToBech32(prefixHint, link),
};
} else {
throw new Error("Invalid nostr link");
}
}