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 */