{"version":3,"file":"web.js","names":[],"sources":["esm/platform/crypto/web.js"],"sourcesContent":["function subtle(verb) {\n  const found = globalThis.crypto?.subtle;\n  if (!found) {\n    throw new Error(`${verb} needs a browser with WebCrypto or a native build that includes one`);\n  }\n  return found;\n}\nconst webDigestSource = async (algorithm, buffer, offset, length) => {\n  if (algorithm === \"MD5\") {\n    throw new Error(\"Crypto.digest: MD5 needs an iOS or Android build\");\n  }\n  return subtle(\"Crypto.digest\").digest(algorithm, new Uint8Array(buffer, offset, length));\n};\nasync function importKey(raw) {\n  return subtle(\"Crypto.aesEncrypt\").importKey(\"raw\", raw, \"AES-GCM\", false, [\n    \"encrypt\",\n    \"decrypt\"\n  ]);\n}\nconst webAesEngine = {\n  async seal(key, iv, plaintext, additionalData, tagLength) {\n    const sealed = await subtle(\"Crypto.aesEncrypt\").encrypt(\n      {\n        name: \"AES-GCM\",\n        iv,\n        tagLength: tagLength * 8,\n        ...additionalData ? { additionalData } : {}\n      },\n      await importKey(key),\n      plaintext\n    );\n    return new Uint8Array(sealed);\n  },\n  async open(key, iv, ciphertextWithTag, additionalData, tagLength) {\n    try {\n      const opened = await subtle(\"Crypto.aesDecrypt\").decrypt(\n        {\n          name: \"AES-GCM\",\n          iv,\n          tagLength: tagLength * 8,\n          ...additionalData ? { additionalData } : {}\n        },\n        await importKey(key),\n        ciphertextWithTag\n      );\n      return new Uint8Array(opened);\n    } catch {\n      throw new Error(\"Crypto.aesDecrypt: authentication failed\");\n    }\n  },\n  random(bytes) {\n    const getRandomValues = globalThis.crypto?.getRandomValues;\n    if (typeof getRandomValues !== \"function\") {\n      throw new Error(\"secure random: web crypto is unavailable in this browser.\");\n    }\n    getRandomValues.call(globalThis.crypto, bytes);\n  }\n};\nexport {\n  webAesEngine,\n  webDigestSource\n};\n//# sourceMappingURL=web.js.map\n"],"mappings":";AAAA,SAAS,OAAO,MAAM;CACpB,MAAM,QAAQ,WAAW,QAAQ;CACjC,IAAI,CAAC,OAAO;EACV,MAAM,IAA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