@metamask/snaps-utils
Version:
A collection of utilities for MetaMask Snaps
1 lines • 1.11 kB
Source Map (JSON)
{"version":3,"file":"bytes.cjs","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":";;;AAAA,2CAAgD;AAEhD,gEAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,KAAwC;IAC/D,6CAA6C;IAC7C,oDAAoD;IACpD,MAAM,SAAS,GAAG,KAAK,YAAY,yBAAW,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAErE,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,IAAA,qBAAa,EAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAVD,4BAUC","sourcesContent":["import { stringToBytes } from '@metamask/utils';\n\nimport { VirtualFile } from './virtual-file/VirtualFile';\n\n/**\n * Convert a bytes-like input value to a Uint8Array.\n *\n * @param bytes - A bytes-like value.\n * @returns The input value converted to a Uint8Array if necessary.\n */\nexport function getBytes(bytes: VirtualFile | Uint8Array | string): Uint8Array {\n // Unwrap VirtualFiles to extract the content\n // The content is then either a string or Uint8Array\n const unwrapped = bytes instanceof VirtualFile ? bytes.value : bytes;\n\n if (typeof unwrapped === 'string') {\n return stringToBytes(unwrapped);\n }\n\n return unwrapped;\n}\n"]}