From 9952afecc260454c95f118a148198bc3fce53dc3 Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Mon, 9 Sep 2024 18:58:08 +0900 Subject: [PATCH] change return type of `createIntegrityMetadata()` to `Promise` --- src/index.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 449f02d..7aea101 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,20 +81,19 @@ export async function createIntegrityMetadata( hashAlgorithm: HashAlgorithm, data: ArrayBuffer, opt: string[] = [], -): Promise { +): Promise { const alg = hashAlgorithm.toLowerCase() as HashAlgorithm; - if (!(alg in supportedHashAlgorithms)) return ""; + if (!(alg in supportedHashAlgorithms)) { + return new IntegrityMetadata(""); + } const hashAlgorithmIdentifier = supportedHashAlgorithms[alg]; const arrayBuffer = await crypto.subtle.digest(hashAlgorithmIdentifier, data); const val = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer))); + const integrity = IntegrityMetadata.stringify({ alg, val, opt }); - return IntegrityMetadata.stringify({ - alg, - val, - opt, - }); + return new IntegrityMetadata(integrity); } /** Integrity Metadata Set Options */