debug: show field lengths and try multiple field name patterns

This commit is contained in:
2026-03-04 04:23:30 +03:00
parent 12618885a0
commit 3ba1ac31b8
2 changed files with 24 additions and 18 deletions
+2 -5
View File
@@ -205,12 +205,9 @@ export function useMessaging() {
);
return { sender: msg.sender, blockNumber: msg.blockNumber, plaintext, raw: msg };
} catch (err) {
console.error('[PEZMessage] decrypt failed:', err,
'ephPubKey len:', msg.ephemeralPublicKey?.length,
'nonce len:', msg.nonce?.length,
'ct len:', msg.ciphertext?.length);
const errText = err instanceof Error ? err.message : String(err);
return { sender: msg.sender, blockNumber: msg.blockNumber, plaintext: `[ERR: ${errText}]`, raw: msg };
const dbg = `eph:${msg.ephemeralPublicKey?.length} n:${msg.nonce?.length} ct:${msg.ciphertext?.length}`;
return { sender: msg.sender, blockNumber: msg.blockNumber, plaintext: `[${errText}] ${dbg}`, raw: msg };
}
});
} else {
+22 -13
View File
@@ -58,19 +58,28 @@ export async function getInbox(
if (result.isEmpty || result.length === 0) return [];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return result.map((msg: any) => {
console.log('[PEZMessage] msg keys:', Object.keys(msg.toJSON?.() ?? msg));
return msg;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}).map((msg: Record<string, any>) => ({
sender: msg.sender.toString(),
blockNumber: msg.blockNumber?.toNumber?.() ?? msg.block_number?.toNumber?.() ?? 0,
ephemeralPublicKey: hexToBytes(
msg.ephemeralPublicKey?.toHex?.() ?? msg.ephemeral_public_key?.toHex?.() ?? '0x'
),
nonce: hexToBytes(msg.nonce.toHex()),
ciphertext: hexToBytes(msg.ciphertext.toHex()),
}));
const first = result[0];
if (first) {
const keys = Object.getOwnPropertyNames(first).filter(k => !k.startsWith('_'));
const json = first.toJSON?.() ?? {};
const jsonKeys = Object.keys(json);
console.log('[PEZMessage] field names:', keys, 'json keys:', jsonKeys, 'json:', JSON.stringify(json));
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return result.map((msg: Record<string, any>) => {
// Try multiple field name patterns
const eph = msg.ephemeralPublicKey ?? msg.ephemeral_public_key ?? msg.ephemeralPubKey ?? msg.ephemeral_pub_key;
const blk = msg.blockNumber ?? msg.block_number ?? msg.blockNum;
const ct = msg.ciphertext ?? msg.cipher_text;
return {
sender: msg.sender.toString(),
blockNumber: blk?.toNumber?.() ?? 0,
ephemeralPublicKey: hexToBytes(eph?.toHex?.() ?? '0x'),
nonce: hexToBytes(msg.nonce?.toHex?.() ?? '0x'),
ciphertext: hexToBytes(ct?.toHex?.() ?? '0x'),
};
});
}
export async function getSendCount(