mirror of
https://github.com/pezkuwichain/pezkuwi-extension.git
synced 2026-11-25 07:19:54 +00:00
Make the PR checks able to fail, and fix what they had been hiding
pr-any.yml ran lint, test and build with continue-on-error: true, so every PR showed success while main had 41 lint errors and 19 of 61 tests failing. The flag is removed and the failures are fixed: - TypeScript 5.5.4 -> 5.9. @pezkuwi/util and friends ship declarations with Uint8Array<ArrayBufferLike>, which 5.5 cannot read, so every such value was typed `any` here (the 16 wrapBytes errors). The pin dates from a styled-components declaration problem that went away with the move back to styled-components 5; build and lint pass on 5.9. - State.ts: the stored security log is parsed through a function that returns an empty log for anything that is not a JSON array, instead of letting `any` flow on; fire-and-forget logging uses .catch(console.error) like the rest of the codebase; object keys sorted. - buildHierarchy.spec.ts: a rename had replaced the genesis hashes with 0x..01 / 0x..02, which resolve to no network name, so sorting by network had nothing to sort on. The test now takes two real entries from chains.ts by name. - scripts/*.cjs is in the lint project (it failed to parse); header and key order fixed in postbuild-cleanup.cjs. - temp_ff_validate/ (43 build files) and pezkuwi-chrome-0.62.22.zip were committed by accident in f5495f7; removed and ignored. 16 of the 19 failing tests are not fixed here: they fail because @pezkuwi/wasm-crypto 7.5.18 stubs ed25519, secp256k1 and sr25519 derivation. With the 7.5.19 build from pezkuwi-wasm#2 installed locally, lint is clean and all 61 tests pass. Until 7.5.19 is published and picked up here, those 16 stay red on this PR, which is the point.
This commit is contained in:
1 parent
23bd90e7a3
commit
865bce54ae
53 files changed
+70
-3692
No files matched your search
@@ -95,6 +95,23 @@ interface SecurityLogEntry {
|
||||
details?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the stored security log. Anything that is not a JSON array (a missing key,
|
||||
* or a value written by something else) reads as an empty log rather than as an
|
||||
* untyped value flowing on.
|
||||
*/
|
||||
function parseSecurityLog (stored: unknown): SecurityLogEntry[] {
|
||||
if (typeof stored !== 'string') {
|
||||
return [];
|
||||
}
|
||||
|
||||
const parsed: unknown = JSON.parse(stored);
|
||||
|
||||
return Array.isArray(parsed)
|
||||
? parsed as SecurityLogEntry[]
|
||||
: [];
|
||||
}
|
||||
|
||||
async function extractMetadata (store: MetadataStore): Promise<void> {
|
||||
await store.allMap(async (map): Promise<void> => {
|
||||
const knownEntries = Object.entries(knownGenesis);
|
||||
@@ -208,13 +225,13 @@ export default class State {
|
||||
private async logSecurityEvent (event: SecurityLogEntry['event'], origin: string, details?: string): Promise<void> {
|
||||
try {
|
||||
const storageData = await chrome.storage.local.get(SECURITY_LOG_KEY);
|
||||
const logs: SecurityLogEntry[] = JSON.parse(storageData[SECURITY_LOG_KEY] || '[]');
|
||||
const logs = parseSecurityLog(storageData[SECURITY_LOG_KEY]);
|
||||
|
||||
logs.push({
|
||||
timestamp: Date.now(),
|
||||
details,
|
||||
event,
|
||||
origin,
|
||||
details
|
||||
timestamp: Date.now()
|
||||
});
|
||||
|
||||
// Keep only the last MAX_SECURITY_LOG_ENTRIES entries
|
||||
@@ -232,7 +249,7 @@ export default class State {
|
||||
try {
|
||||
const storageData = await chrome.storage.local.get(SECURITY_LOG_KEY);
|
||||
|
||||
return JSON.parse(storageData[SECURITY_LOG_KEY] || '[]');
|
||||
return parseSecurityLog(storageData[SECURITY_LOG_KEY]);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
@@ -449,13 +466,13 @@ export default class State {
|
||||
reject: (error: Error): void => {
|
||||
complete();
|
||||
// Fire-and-forget logging (don't block user)
|
||||
void this.logSecurityEvent('sign_rejected', url || 'unknown', error.message);
|
||||
this.logSecurityEvent('sign_rejected', url || 'unknown', error.message).catch(console.error);
|
||||
reject(error);
|
||||
},
|
||||
resolve: (result: ResponseSigning): void => {
|
||||
complete();
|
||||
// Fire-and-forget logging (don't block user)
|
||||
void this.logSecurityEvent('sign_approved', url || 'unknown');
|
||||
this.logSecurityEvent('sign_approved', url || 'unknown').catch(console.error);
|
||||
resolve(result);
|
||||
}
|
||||
};
|
||||
@@ -738,7 +755,7 @@ export default class State {
|
||||
|
||||
if (now - lastTime < this.#rateLimitInterval) {
|
||||
// Log rate limit hit (fire-and-forget)
|
||||
void this.logSecurityEvent('rate_limit_hit', origin, 'Signing request rate limited');
|
||||
this.logSecurityEvent('rate_limit_hit', origin, 'Signing request rate limited').catch(console.error);
|
||||
throw new Error('Rate limit exceeded. Try again later.');
|
||||
}
|
||||
|
||||
@@ -759,7 +776,7 @@ export default class State {
|
||||
|
||||
if (now - lastTime < this.#authRateLimitInterval) {
|
||||
// Log rate limit hit (fire-and-forget)
|
||||
void this.logSecurityEvent('rate_limit_hit', origin, 'Authorization request rate limited');
|
||||
this.logSecurityEvent('rate_limit_hit', origin, 'Authorization request rate limited').catch(console.error);
|
||||
throw new Error('Too many authorization requests. Please wait a few seconds.');
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user