{"version":3,"file":"auxiliary-files.mjs","sourceRoot":"","sources":["../src/auxiliary-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,4BAA4B;AAC5D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,wBAAwB;AAEpE,OAAO,EAAE,YAAY,EAAE,qBAAiB;AACxC,OAAO,EAAE,aAAa,EAAE,wBAAoB;AAG5C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,KAAa,EACb,QAA+B;IAE/B,oDAAoD;IACpD,IAAI,QAAQ,KAAK,qBAAqB,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,qCAAqC;IACrC,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;IAC1C,IAAI,QAAQ,KAAK,qBAAqB,CAAC,IAAI,EAAE,CAAC;QAC5C,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAoB;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CACJ,IAAI,CAAC,IAAI,GAAG,aAAa,EACzB,+DAA+D,CAChE,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport { assert, bytesToHex, bytesToString } from '@metamask/utils';\n\nimport { decodeBase64 } from './base64';\nimport { MAX_FILE_SIZE } from './constants';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Re-encodes an auxiliary file if needed depending on the requested file encoding.\n *\n * @param value - The base64 value stored for the auxiliary file.\n * @param encoding - The chosen encoding.\n * @returns The file encoded in the requested encoding.\n */\nexport async function encodeAuxiliaryFile(\n  value: string,\n  encoding: AuxiliaryFileEncoding,\n) {\n  // Input is assumed to be the stored file in base64.\n  if (encoding === AuxiliaryFileEncoding.Base64) {\n    return value;\n  }\n\n  // TODO: Use @metamask/utils for this\n  const decoded = await decodeBase64(value);\n  if (encoding === AuxiliaryFileEncoding.Utf8) {\n    return bytesToString(decoded);\n  }\n\n  return bytesToHex(decoded);\n}\n\n/**\n * Validate that auxiliary files used by the Snap are within size limits.\n *\n * @param files - A list of auxiliary files.\n */\nexport function validateAuxiliaryFiles(files: VirtualFile[]) {\n  for (const file of files) {\n    assert(\n      file.size < MAX_FILE_SIZE,\n      'Static files required by the Snap must be smaller than 64 MB.',\n    );\n  }\n}\n"]}