From d740f57970e38a88127361ddaab8ddec7fd14d66 Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Wed, 2 Oct 2024 18:01:14 +0900 Subject: [PATCH] updated createIntegrityMetadataSet to accept more flexible input types --- src/index.ts | 8 ++++---- test/create-integrity-metadata-set.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4413704..202cfa7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -211,15 +211,15 @@ export class IntegrityMetadataSet { } export async function createIntegrityMetadataSet( - hashAlgorithms: HashAlgorithm[], + hashAlgorithms: ReadonlyArray | HashAlgorithm, data: ArrayBuffer, options: IntegrityMetadataSetOptions = { getPrioritizedHashAlgorithm, }, ): Promise { - const integrityMetadata = await Promise.all( - hashAlgorithms.map((alg) => createIntegrityMetadata(alg, data)), + const set = await Promise.all( + [hashAlgorithms].flat().map((alg) => createIntegrityMetadata(alg, data)), ); - return new IntegrityMetadataSet(integrityMetadata.join(" "), options); + return new IntegrityMetadataSet(set, options); } diff --git a/test/create-integrity-metadata-set.js b/test/create-integrity-metadata-set.js index 442e686..faffe1a 100644 --- a/test/create-integrity-metadata-set.js +++ b/test/create-integrity-metadata-set.js @@ -9,7 +9,7 @@ import { test("instantiate a new IntegrityMetadataSet", async function () { const res = new Response("Hello, world!"); const data = await res.arrayBuffer(); - const set = await createIntegrityMetadataSet(["sha256"], data); + const set = await createIntegrityMetadataSet("sha256", data); assert(set instanceof IntegrityMetadataSet); });