Fix getPublicKey: Java returns hex not npub despite field name

NostrSigner.npubToHex() is called before putting result in "npub" field,
so the value is already a 64-char hex pubkey. Skip nip19.decode() and
use it directly. This was causing the "data must be at least 8 chars" error.

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy 2026-07-09 12:50:37 +07:00
parent 9eda3d5c86
commit da1d208579

View file

@ -44,6 +44,13 @@ export async function getAmberPublicKeyViaPlugin(): Promise<string> {
const { npub } = await plugin.getPublicKey(AMBER_PACKAGE);
// Despite the field being called "npub", the Java bridge calls npubToHex()
// before returning — so this is actually a hex pubkey already.
if (/^[0-9a-f]{64}$/i.test(npub)) {
return npub.toLowerCase();
}
// Fallback: if it somehow comes back as a real npub, decode it
const decoded = nip19.decode(npub);
if (decoded.type !== 'npub') throw new Error('Unexpected key format from Amber');
return decoded.data as string;