Add debug logging to getAmberPublicKeyViaPlugin to trace exact return value
Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
parent
a6c220c911
commit
1c577f7392
1 changed files with 20 additions and 6 deletions
|
|
@ -52,19 +52,33 @@ export async function getAmberPublicKeyViaPlugin(): Promise<string> {
|
||||||
// Pass null as packageName to skip the Content Resolver silent path
|
// Pass null as packageName to skip the Content Resolver silent path
|
||||||
// and always open the Amber UI so the user explicitly selects their key.
|
// and always open the Amber UI so the user explicitly selects their key.
|
||||||
// This prevents returning a stale/wrong cached key.
|
// This prevents returning a stale/wrong cached key.
|
||||||
const { npub } = await plugin.getPublicKey(null);
|
const result = await plugin.getPublicKey(null);
|
||||||
|
|
||||||
|
// Log everything we got back for debugging
|
||||||
|
console.log('[CapacitorAmber] getPublicKey raw result:', JSON.stringify(result));
|
||||||
|
|
||||||
|
const npub = result?.npub ?? result?.pubkey ?? result;
|
||||||
|
console.log('[CapacitorAmber] npub field value:', npub, 'type:', typeof npub, 'length:', String(npub).length);
|
||||||
|
|
||||||
|
if (!npub) throw new Error('Amber returned empty key');
|
||||||
|
|
||||||
// The "npub" field is actually hex (Java calls npubToHex before returning)
|
// The "npub" field is actually hex (Java calls npubToHex before returning)
|
||||||
if (/^[0-9a-f]{64}$/i.test(npub)) {
|
if (/^[0-9a-f]{64}$/i.test(String(npub))) {
|
||||||
return npub.toLowerCase();
|
console.log('[CapacitorAmber] Returning hex pubkey:', String(npub).slice(0, 16) + '...');
|
||||||
|
return String(npub).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: handle real npub just in case
|
// Fallback: handle real npub just in case
|
||||||
const decoded = nip19.decode(npub);
|
if (String(npub).startsWith('npub1')) {
|
||||||
|
const decoded = nip19.decode(String(npub));
|
||||||
if (decoded.type !== 'npub') throw new Error('Unexpected key format from Amber');
|
if (decoded.type !== 'npub') throw new Error('Unexpected key format from Amber');
|
||||||
|
console.log('[CapacitorAmber] Decoded npub to hex');
|
||||||
return decoded.data as string;
|
return decoded.data as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new Error(`Unexpected key format from Amber: "${String(npub).slice(0, 20)}" (length: ${String(npub).length})`);
|
||||||
|
}
|
||||||
|
|
||||||
export class CapacitorAmberSigner implements NostrSigner {
|
export class CapacitorAmberSigner implements NostrSigner {
|
||||||
readonly pubkey: string;
|
readonly pubkey: string;
|
||||||
// Store the npub for use in signing calls
|
// Store the npub for use in signing calls
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue