Turn on promise-function-async and init-declarations and satisfy them with async functions and null-initialized lets

This commit is contained in:
Danny Kim
2026-10-19 19:44:35 +09:00
parent a65bf353ab
commit d879b04e46
14 changed files with 147 additions and 99 deletions
+10 -3
View File
@@ -33,12 +33,16 @@ function encodeBase64Url(value: Uint8Array): string {
const buffer = (value: Uint8Array): ArrayBuffer => Uint8Array.from(value).buffer;
function importMasterKey(encoded: string, usage: webcrypto.KeyUsage): Promise<webcrypto.CryptoKey> {
async function importMasterKey(
encoded: string,
usage: webcrypto.KeyUsage,
): Promise<webcrypto.CryptoKey> {
const bytes = decodeBase64Url(encoded);
if (bytes.length !== 32) {
throw new Error("master-key must be 32 bytes encoded as base64url");
}
return webcrypto.subtle.importKey("raw", buffer(bytes), "AES-GCM", false, [usage]);
const key = await webcrypto.subtle.importKey("raw", buffer(bytes), "AES-GCM", false, [usage]);
return key;
}
export async function decryptCredential(encrypted: string, masterKey: string): Promise<string> {
@@ -127,7 +131,10 @@ export async function parseCredentials(text: string, masterKey: string): Promise
throw new Error("profiles must contain at least one profile");
}
const parsed = await Promise.all(
profiles.map((entry: unknown, index) => parseProfile(entry, index, masterKey)),
profiles.map(async (entry: unknown, index) => {
const profile = await parseProfile(entry, index, masterKey);
return profile;
}),
);
return { reviewerToken: await decryptCredential(reviewerToken, masterKey), profiles: parsed };
}