From 4803fce66fa549b6c908faa8cd136a1cc783f5bd Mon Sep 17 00:00:00 2001 From: Muffin Date: Wed, 1 May 2024 15:35:56 -0500 Subject: [PATCH] Fix prepublish script in Node 18 which is the version shipped by debian 12 --- scripts/prepublish.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/prepublish.mjs b/scripts/prepublish.mjs index 1f38f331a..6d005b7f0 100644 --- a/scripts/prepublish.mjs +++ b/scripts/prepublish.mjs @@ -6,6 +6,7 @@ import fs from 'fs'; import path from 'path'; +import nodeCrypto from 'crypto'; import crossFetch from 'cross-fetch'; import yauzl from 'yauzl'; @@ -82,10 +83,9 @@ const downloadMicrobitHex = async () => { console.info(`Downloading ${url}`); const response = await crossFetch(url); const zipBuffer = Buffer.from(await response.arrayBuffer()); - const sha256Digest = new Uint8Array(await crypto.subtle.digest('SHA-256', zipBuffer)); - const sha256Hex = Array.from(sha256Digest).map(i => i.toString(16).padStart(2, '0')).join(''); - if (sha256Hex !== expectedSHA256) { - throw new Error(`microbit hex has SHA-256 ${sha256Hex} but expected ${expectedSHA256}`); + const sha256 = nodeCrypto.createHash('sha-256').update(zipBuffer).digest('hex'); + if (sha256 !== expectedSHA256) { + throw new Error(`microbit hex has SHA-256 ${sha256} but expected ${expectedSHA256}`); } const relativeHexDir = path.join('static', 'microbit'); const hexFileName = await extractFirstMatchingFile(