INNER CODE UNIT · JavaScript

digestSha256

mozilla/firefox-translations · extension/controller/backgroundScript.js:839

const digestSha256 = async buffer => {
  // hash the message
  if (!crypto.subtle) return null;
  const hashBuffer = await crypto.subtle.digest("SHA-256", buffer);
  // convert buffer to byte array
  const hashArray = Array.from(new Uint8Array(hashBuffer));
  // convert bytes to hex string
  return hashArray.map(b => b.toString(16).padStart(2, "0")).join("");
};

// eslint-disable-next-line max-lines-per-function
const getItemFromWeb = async (tabId, itemURL, fileSize, fileChecksum) => {
  let fetchResponse = null;
  try {
      fetchResponse = await fetch(itemURL);
  } catch (error) {
      console.log(`Error downloading ${itemURL} (error: ${error})`);
      // inform mediator

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…