Turn on promise-function-async and init-declarations and satisfy them with async functions and null-initialized lets
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user