From 24e50ddf0d59ab843b4ab785f9c716892ad95378 Mon Sep 17 00:00:00 2001 From: SayMoon Date: Tue, 8 Apr 2025 09:41:10 +0200 Subject: [PATCH 1/2] Fix types --- hmac-sign/index.ts | 12 +++++++++--- hmac-verify/index.ts | 12 +++++++++--- multiple-resource-copy/index.ts | 4 ++-- resource-copy/index.ts | 4 ++-- rsa-sign/index.ts | 12 +++++++++--- rsa-verify/index.ts | 12 +++++++++--- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/hmac-sign/index.ts b/hmac-sign/index.ts index 136fb5e..0ac25b8 100644 --- a/hmac-sign/index.ts +++ b/hmac-sign/index.ts @@ -45,9 +45,15 @@ export async function execute(context: Context): Promise { } async function signContent(context: Context, contentBytes: SecureByteArray): Promise { - const algorithmParams = { name: "HMAC", hash: context.parameters.hmacHashAlgorithmName }; - const keyUse = ["sign"]; - const privateKey = await crypto.subtle.importKey("cryptosecret", context.parameters.cryptoSecretParameter, algorithmParams, false, keyUse); + const algorithmParams: HmacImportParams = { name: "HMAC", hash: context.parameters.hmacHashAlgorithmName }; + const keyUse: KeyUsage[] = ["sign"]; + const privateKey = await crypto.subtle.importKey( + "cryptosecret", + context.parameters.cryptoSecretParameter, + algorithmParams, + false, + keyUse + ); return await crypto.subtle.sign("HMAC", privateKey, contentBytes); } diff --git a/hmac-verify/index.ts b/hmac-verify/index.ts index 33ced8e..0cb165a 100644 --- a/hmac-verify/index.ts +++ b/hmac-verify/index.ts @@ -57,9 +57,15 @@ export async function execute(context: Context): Promise { } async function verifyContent(context: Context, signatureBytes: Uint8Array, contentBytes: SecureByteArray): Promise { - const algorithmParams = { name: "HMAC", hash: context.parameters.hmacHashAlgorithmName }; - const keyUse = ["verify"]; - const publicKey = await crypto.subtle.importKey("cryptosecret", context.parameters.cryptoSecretParameter, algorithmParams, false, keyUse); + const algorithmParams: HmacImportParams = { name: "HMAC", hash: context.parameters.hmacHashAlgorithmName }; + const keyUse: KeyUsage[] = ["verify"]; + const publicKey = await crypto.subtle.importKey( + "cryptosecret", + context.parameters.cryptoSecretParameter, + algorithmParams, + false, + keyUse + ); return await crypto.subtle.verify("HMAC", publicKey, signatureBytes, contentBytes); } diff --git a/multiple-resource-copy/index.ts b/multiple-resource-copy/index.ts index 1b54372..2f83470 100644 --- a/multiple-resource-copy/index.ts +++ b/multiple-resource-copy/index.ts @@ -1,4 +1,4 @@ -export function getDescription(): ScriptDescription { +export function getDescription() { return { displayName: "Multiple Resource Copy", description: "Copies multiple resources into a target directory. It has no size limit; the amount of transferred data is only limited by the step timeout.", @@ -80,7 +80,7 @@ export function getDescription(): ScriptDescription { description: "Number of files that failed to be copied.", }, ], - }; + } as const satisfies ScriptDescription; } export async function execute(context: Context): Promise { diff --git a/resource-copy/index.ts b/resource-copy/index.ts index 8276500..3c3ea74 100644 --- a/resource-copy/index.ts +++ b/resource-copy/index.ts @@ -1,4 +1,4 @@ -export function getDescription(): ScriptDescription { +export function getDescription() { return { displayName: "Resource Copy", description: "Copies an input resource into an output resource.", @@ -33,7 +33,7 @@ export function getDescription(): ScriptDescription { }, ], output: [], - }; + } as const satisfies ScriptDescription; } export async function execute(context: Context): Promise { diff --git a/rsa-sign/index.ts b/rsa-sign/index.ts index ae28460..0fe899d 100644 --- a/rsa-sign/index.ts +++ b/rsa-sign/index.ts @@ -51,9 +51,15 @@ export async function execute(context: Context): Promise { } async function signContent(context: Context, fileToSign: IFile): Promise { - const algorithmParams = { name: context.parameters.rsaAlgorithmName, hash: context.parameters.rsaHashAlgorithmName }; - const keyUse = ["sign"]; - const privateKey = await crypto.subtle.importKey("pkcs8fromparameterinput", context.parameters.privateCertificate, algorithmParams, false, keyUse); + const algorithmParams: RsaHashedImportParams = { name: context.parameters.rsaAlgorithmName, hash: context.parameters.rsaHashAlgorithmName }; + const keyUse: KeyUsage[] = ["sign"]; + const privateKey = await crypto.subtle.importKey( + "pkcs8fromparameterinput", + context.parameters.privateCertificate, + algorithmParams, + false, + keyUse + ); return await crypto.subtle.sign(context.parameters.rsaAlgorithmName, privateKey, fileToSign); } diff --git a/rsa-verify/index.ts b/rsa-verify/index.ts index 84f89e8..73f11b7 100644 --- a/rsa-verify/index.ts +++ b/rsa-verify/index.ts @@ -64,9 +64,15 @@ export async function execute(context: Context): Promise { } async function verifyContent(context: Context, signatureBytes: Uint8Array, fileToVerify: IFile): Promise { - const algorithmParams = { name: context.parameters.rsaAlgorithmName, hash: context.parameters.rsaHashAlgorithmName }; - const keyUse = ["verify"]; - const publicKey = await crypto.subtle.importKey("spkifromparameterinput", context.parameters.publicCertificate, algorithmParams, false, keyUse); + const algorithmParams: RsaHashedImportParams = { name: context.parameters.rsaAlgorithmName, hash: context.parameters.rsaHashAlgorithmName }; + const keyUse: KeyUsage[] = ["verify"]; + const publicKey = await crypto.subtle.importKey( + "spkifromparameterinput", + context.parameters.publicCertificate, + algorithmParams, + false, + keyUse + ); return await crypto.subtle.verify(context.parameters.rsaAlgorithmName, publicKey, signatureBytes, fileToVerify); } From 7df358732f98ef0ed423b39af55c6afe0885d2ec Mon Sep 17 00:00:00 2001 From: SayMoon Date: Tue, 8 Apr 2025 09:51:10 +0200 Subject: [PATCH 2/2] Fix formatting --- hmac-sign/index.ts | 8 +------- hmac-verify/index.ts | 8 +------- rsa-sign/index.ts | 8 +------- rsa-verify/index.ts | 8 +------- 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/hmac-sign/index.ts b/hmac-sign/index.ts index 0ac25b8..4616a77 100644 --- a/hmac-sign/index.ts +++ b/hmac-sign/index.ts @@ -47,13 +47,7 @@ export async function execute(context: Context): Promise { async function signContent(context: Context, contentBytes: SecureByteArray): Promise { const algorithmParams: HmacImportParams = { name: "HMAC", hash: context.parameters.hmacHashAlgorithmName }; const keyUse: KeyUsage[] = ["sign"]; - const privateKey = await crypto.subtle.importKey( - "cryptosecret", - context.parameters.cryptoSecretParameter, - algorithmParams, - false, - keyUse - ); + const privateKey = await crypto.subtle.importKey("cryptosecret", context.parameters.cryptoSecretParameter, algorithmParams, false, keyUse); return await crypto.subtle.sign("HMAC", privateKey, contentBytes); } diff --git a/hmac-verify/index.ts b/hmac-verify/index.ts index 0cb165a..bbd4f37 100644 --- a/hmac-verify/index.ts +++ b/hmac-verify/index.ts @@ -59,13 +59,7 @@ export async function execute(context: Context): Promise { async function verifyContent(context: Context, signatureBytes: Uint8Array, contentBytes: SecureByteArray): Promise { const algorithmParams: HmacImportParams = { name: "HMAC", hash: context.parameters.hmacHashAlgorithmName }; const keyUse: KeyUsage[] = ["verify"]; - const publicKey = await crypto.subtle.importKey( - "cryptosecret", - context.parameters.cryptoSecretParameter, - algorithmParams, - false, - keyUse - ); + const publicKey = await crypto.subtle.importKey("cryptosecret", context.parameters.cryptoSecretParameter, algorithmParams, false, keyUse); return await crypto.subtle.verify("HMAC", publicKey, signatureBytes, contentBytes); } diff --git a/rsa-sign/index.ts b/rsa-sign/index.ts index 0fe899d..3c5201c 100644 --- a/rsa-sign/index.ts +++ b/rsa-sign/index.ts @@ -53,13 +53,7 @@ export async function execute(context: Context): Promise { async function signContent(context: Context, fileToSign: IFile): Promise { const algorithmParams: RsaHashedImportParams = { name: context.parameters.rsaAlgorithmName, hash: context.parameters.rsaHashAlgorithmName }; const keyUse: KeyUsage[] = ["sign"]; - const privateKey = await crypto.subtle.importKey( - "pkcs8fromparameterinput", - context.parameters.privateCertificate, - algorithmParams, - false, - keyUse - ); + const privateKey = await crypto.subtle.importKey("pkcs8fromparameterinput", context.parameters.privateCertificate, algorithmParams, false, keyUse); return await crypto.subtle.sign(context.parameters.rsaAlgorithmName, privateKey, fileToSign); } diff --git a/rsa-verify/index.ts b/rsa-verify/index.ts index 73f11b7..26eb742 100644 --- a/rsa-verify/index.ts +++ b/rsa-verify/index.ts @@ -66,13 +66,7 @@ export async function execute(context: Context): Promise { async function verifyContent(context: Context, signatureBytes: Uint8Array, fileToVerify: IFile): Promise { const algorithmParams: RsaHashedImportParams = { name: context.parameters.rsaAlgorithmName, hash: context.parameters.rsaHashAlgorithmName }; const keyUse: KeyUsage[] = ["verify"]; - const publicKey = await crypto.subtle.importKey( - "spkifromparameterinput", - context.parameters.publicCertificate, - algorithmParams, - false, - keyUse - ); + const publicKey = await crypto.subtle.importKey("spkifromparameterinput", context.parameters.publicCertificate, algorithmParams, false, keyUse); return await crypto.subtle.verify(context.parameters.rsaAlgorithmName, publicKey, signatureBytes, fileToVerify); }