From da1d2085790b8c64452c91b04635b4112ea8211b Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Thu, 9 Jul 2026 12:50:37 +0700 Subject: [PATCH] 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 --- src/lib/capacitorAmberSigner.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/capacitorAmberSigner.ts b/src/lib/capacitorAmberSigner.ts index 67e69e6..072dacb 100644 --- a/src/lib/capacitorAmberSigner.ts +++ b/src/lib/capacitorAmberSigner.ts @@ -44,6 +44,13 @@ export async function getAmberPublicKeyViaPlugin(): Promise { 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;