{"name":"@exodus/bytes","version":"1.7.0","author":{"name":"Exodus Movement, Inc."},"license":"MIT","_id":"@exodus/bytes@1.7.0","maintainers":[{"name":"joshuabot","email":"joshuabot@exodus.io"},{"name":"chalker","email":"chalkerx@gmail.com"}],"homepage":"https://github.com/ExodusOSS/bytes#readme","bugs":{"url":"https://github.com/ExodusOSS/bytes/issues"},"dist":{"shasum":"0bfe8baefb3843eb28b15eff7fd18edaefff6228","tarball":"http://registry-npm.ywwl.com/@exodus/bytes/download/@exodus/bytes-1.7.0.tgz","fileCount":46,"integrity":"sha512-5i+BtvujK/vM07YCGDyz4C4AyDzLmhxHMtM5HpUyPRtJPBdFPsj290ffXW+UXY21/G7GtXeHD2nRmq0T1ShyQQ==","signatures":[{"sig":"MEQCIBApnusWCc+ejYvXnOdmZVsGnhCWNaO59w+BW8pSben3AiBiHBvUY439XuXJlogkGyf7zWrQmAkqqTiLOi4f1W0MnA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":332281,"size":125766,"noattachment":false,"key":"/@exodus/bytes/-/@exodus/bytes-1.7.0.tgz"},"type":"module","engines":{"node":"^20.19.0 || ^22.12.0 || >=24.0.0"},"exports":{"./hex.js":{"node":"./hex.node.js","types":"./hex.d.ts","default":"./hex.js"},"./wif.js":"./wif.js","./utf8.js":{"node":"./utf8.node.js","types":"./utf8.d.ts","default":"./utf8.js"},"./array.js":{"types":"./array.d.ts","default":"./array.js"},"./utf16.js":{"node":"./utf16.node.js","default":"./utf16.js"},"./base32.js":"./base32.js","./base58.js":"./base58.js","./base64.js":{"types":"./base64.d.ts","default":"./base64.js"},"./bech32.js":"./bech32.js","./bigint.js":"./bigint.js","./encoding.js":"./encoding.js","./multi-byte.js":{"node":"./multi-byte.node.js","default":"./multi-byte.js"},"./base58check.js":{"node":"./base58check.node.js","default":"./base58check.js"},"./single-byte.js":{"node":"./single-byte.node.js","default":"./single-byte.js"},"./encoding-lite.js":"./encoding-lite.js"},"gitHead":"bfc362e581d7c6526e037862d1d61729c997b484","scripts":{"jsvu":"jsvu","lint":"eslint .","test":"exodus-test","test:v8":"exodus-test --engine=v8:bundle","test:xs":"exodus-test --engine=xs:bundle","coverage":"exodus-test --coverage","test:bun":"exodus-test --engine=bun:pure","test:jsc":"exodus-test --engine=jsc:bundle","benchmark":"exodus-test --concurrency=1 benchmarks/*.bench.js","test:deno":"exodus-test --engine=deno:pure","playwright":"exodus-test --playwright","test:hermes":"exodus-test --engine=hermes:bundle","test:quickjs":"exodus-test --engine=quickjs:bundle","test:engine262":"exodus-test --engine=engine262:bundle","test:servo:bundle":"exodus-test --engine=servo:bundle","test:spidermonkey":"exodus-test --engine=spidermonkey:bundle","test:javascriptcore":"npm run test:jsc --","test:electron:bundle":"exodus-test --engine=electron:bundle","test:chrome:puppeteer":"exodus-test --engine=chrome:puppeteer","test:electron:as-node":"exodus-test --engine=electron-as-node:test","test:firefox:puppeteer":"exodus-test --engine=firefox:puppeteer","test:webkit:playwright":"exodus-test --engine=webkit:playwright","test:firefox:playwright":"exodus-test --engine=firefox:playwright","test:chromium:playwright":"exodus-test --engine=chromium:playwright"},"_npmUser":{"name":"chalker","email":"chalkerx@gmail.com"},"prettier":"@exodus/prettier","repository":{"url":"git+https://github.com/ExodusOSS/bytes.git","type":"git"},"_npmVersion":"10.9.4","description":"Various operations on Uint8Array data","directories":{},"_nodeVersion":"22.21.1","_hasShrinkwrap":false,"packageManager":"pnpm@10.12.1+sha256.889bac470ec93ccc3764488a19d6ba8f9c648ad5e50a9a6e4be3768a5de387a3","devDependencies":{"wif":"^5.0.0","bs58":"^6.0.0","jsvu":"^3.0.3","utf8":"^3.0.0","base-x":"^5.0.1","bech32":"^2.0.0","buffer":"^6.0.3","eslint":"^8.44.0","bstring":"^0.3.9","electron":"36.5.0","hextreme":"^1.0.7","base32.js":"^0.1.0","base58-js":"^3.0.3","base64-js":"^1.5.1","bs58check":"^4.0.0","hi-base32":"^0.5.1","iconv-lite":"^0.7.0","typescript":"^5.9.3","@scure/base":"^1.2.6","@types/node":"^22.12.0","decode-utf8":"^1.0.1","encode-utf8":"^2.0.0","@exodus/test":"^1.0.0-rc.109","@noble/hashes":"^2.0.1","text-encoding":"^0.7.0","@exodus/crypto":"^1.0.0-rc.30","@stablelib/hex":"^2.0.1","whatwg-encoding":"^3.1.1","@exodus/prettier":"^1.0.0","uint8array-tools":"^0.0.9","@stablelib/base64":"^2.0.1","fast-base64-decode":"^2.0.0","fast-base64-encode":"^1.0.0","@petamoriken/float16":"^3.9.3","web-streams-polyfill":"^4.2.0","@exodus/eslint-config":"^5.24.0","@ethersproject/strings":"^5.8.0"},"peerDependencies":{"@exodus/crypto":"^1.0.0-rc.4"},"peerDependenciesMeta":{"@exodus/crypto":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/bytes_1.7.0_1766952783885_0.054149109111066185","host":"s3://npm-registry-packages-npm-production"},"readme":"# @exodus/bytes\n\n[![](https://img.shields.io/npm/v/@exodus/bytes?style=flat-square)](https://npmjs.org/package/@exodus/bytes)\n[![](https://img.shields.io/github/release/ExodusOSS/bytes?style=flat-square&logo=github)](https://github.com/ExodusOSS/bytes/releases)\n[![](https://img.shields.io/npm/dm/@exodus/bytes?style=flat-square)](https://www.npmcharts.com/compare/@exodus/bytes?minimal=true)\n[![](https://img.shields.io/npm/l/@exodus/bytes?style=flat-square&color=blue)](https://github.com/ExodusOSS/bytes/blob/HEAD/LICENSE)\n[![](https://img.shields.io/github/check-runs/ExodusOSS/bytes/main?style=flat-square&logo=github)](https://github.com/ExodusOSS/bytes/actions/workflows/test.yml?query=branch%3Amain)\n[![](https://img.shields.io/badge/Documentation-3178c6?style=flat-square&logo=TypeScript&logoColor=fff)](https://exodusoss.github.io/bytes/)\n\n`Uint8Array` conversion to and from `base64`, `base32`, `base58`, `hex`, `utf8`, `utf16`, `bech32` and `wif`\n\nAnd a [`TextEncoder` / `TextDecoder` polyfill](#textencoder--textdecoder-polyfill)\n\nSee [documentation](https://exodusoss.github.io/bytes/).\n\n## Strict\n\nPerforms proper input validation, ensures no garbage-in-garbage-out\n\nTested in CI with [@exodus/test](https://github.com/ExodusMovement/test#exodustest) on:\n\n[![Node.js](https://img.shields.io/badge/Node.js-338750?style=for-the-badge&logo=Node.js&logoColor=FFF)](https://nodejs.org/api/test.html)\n[![Deno](https://img.shields.io/badge/Deno-121417?style=for-the-badge&logo=Deno&logoColor=FFF)](https://deno.com/)\n[![Bun](https://img.shields.io/badge/Bun-F472B6?style=for-the-badge&logo=Bun&logoColor=FFF)](https://bun.sh/)\n[![Electron](https://img.shields.io/badge/Electron-2F3242?style=for-the-badge&logo=Electron&logoColor=A2ECFB)](http://electronjs.org/)\n[![workerd](https://img.shields.io/badge/workerd-F38020?style=for-the-badge&logo=cloudflareworkers&logoColor=FFF)](https://github.com/cloudflare/workerd)\\\n[![Chrome](https://img.shields.io/badge/Chrome-4285F4?style=for-the-badge&logo=GoogleChrome&logoColor=FFF)](https://www.chromium.org/Home/)\n[![WebKit](https://img.shields.io/badge/WebKit-006CFF?style=for-the-badge&logo=Safari&logoColor=FFF)](http://webkit.org/)\n[![Firefox](https://img.shields.io/badge/Firefox-FF7139?style=for-the-badge&logo=Firefox&logoColor=FFF)](https://github.com/mozilla-firefox)\n[![Servo](https://img.shields.io/badge/Servo-009D9A?style=for-the-badge)](https://servo.org/)\\\n[![Hermes](https://img.shields.io/badge/Hermes-282C34?style=for-the-badge&logo=React)](https://hermesengine.dev)\n[![V8](https://img.shields.io/badge/V8-4285F4?style=for-the-badge&logo=V8&logoColor=white)](https://v8.dev/docs/d8)\n[![JavaScriptCore](https://img.shields.io/badge/JavaScriptCore-006CFF?style=for-the-badge)](https://docs.webkit.org/Deep%20Dive/JSC/JavaScriptCore.html)\n[![SpiderMonkey](https://img.shields.io/badge/SpiderMonkey-FFD681?style=for-the-badge)](https://spidermonkey.dev/)\\\n[![QuickJS](https://img.shields.io/badge/QuickJS-E58200?style=for-the-badge)](https://github.com/quickjs-ng/quickjs)\n[![XS](https://img.shields.io/badge/XS-0B307A?style=for-the-badge)](https://github.com/Moddable-OpenSource/moddable)\n[![GraalJS](https://img.shields.io/badge/GraalJS-C74634?style=for-the-badge)](https://github.com/oracle/graaljs)\n\n## Fast\n\n* `10-20x` faster than `Buffer` polyfill\n* `2-10x` faster than `iconv-lite`\n\nThe above was for the js fallback\n\nIt's up to `100x` when native impl is available \\\ne.g. in `utf8fromString` on Hermes / React Native or `fromHex` in Chrome\n\nAlso:\n* `3-8x` faster than `bs58`\n* `10-30x` faster than `@scure/base` (or `>100x` on Node.js <25)\n* Faster in `utf8toString` / `utf8fromString` than `Buffer` or `TextDecoder` / `TextEncoder` on Node.js\n\nSee [Performance](./Performance.md) for more info\n\n## TextEncoder / TextDecoder polyfill\n\n```js\nimport { TextDecoder, TextEncoder } from '@exodus/bytes/encoding.js'\nimport { TextDecoderStream, TextEncoderStream } from '@exodus/bytes/encoding.js' // Requires Streams\n```\n\nLess than half the bundle size of [text-encoding](https://npmjs.com/text-encoding), [whatwg-encoding](https://npmjs.com/whatwg-encoding) or [iconv-lite](https://npmjs.com/iconv-lite) (gzipped or not).\\\nAlso [much faster](#fast) than all of those.\n\n> [!TIP]\n> See also the [lite version](#lite-version) to get this down to 8 KiB gzipped.\n\nSpec compliant, passing WPT and covered with extra tests.\\\nMoreover, tests for this library uncovered [bugs in all major implementations](https://docs.google.com/spreadsheets/d/1pdEefRG6r9fZy61WHGz0TKSt8cO4ISWqlpBN5KntIvQ/edit).\\\nIncluding all three major browser engines being wrong at UTF-8.\\\nSee [WPT pull request](https://github.com/web-platform-tests/wpt/pull/56892).\n\nIt works correctly even in environments that have native implementations broken (that's all of them currently).\\\nRuns (and passes WPT) on Node.js built without ICU.\n\n> [!NOTE]\n> [Faster than Node.js native implementation on Node.js](https://github.com/nodejs/node/issues/61041#issuecomment-3649242024).\n>\n> The JS multi-byte version is as fast as native impl in Node.js and browsers, but (unlike them) returns correct results.\n>\n> For encodings where native version is known to be fast and correct, it is automatically used.\\\n> Some single-byte encodings are faster than native in all three major browser engines.\n\nSee [analysis table](https://docs.google.com/spreadsheets/d/1pdEefRG6r9fZy61WHGz0TKSt8cO4ISWqlpBN5KntIvQ/edit) for more info.\n\n### Caveat: `TextDecoder` / `TextEncoder` APIs are lossy by default per spec\n\n_These are only provided as a compatibility layer, prefer hardened APIs instead in new code._\n\n * `TextDecoder` can (and should) be used with `{ fatal: true }` option for all purposes demanding correctness / lossless transforms\n\n * `TextEncoder` does not support a fatal mode per spec, it always performs replacement.\n\n   That is not suitable for hashing, cryptography or consensus applications.\\\n   Otherwise there would be non-equal strings with equal signatures and hashes — the collision is caused by the lossy transform of a JS string to bytes.\n   Those also survive e.g. `JSON.stringify`/`JSON.parse` or being sent over network.\n\n   Use strict APIs in new applications, see `utf8fromString` / `utf16fromString` below.\\\n   Those throw on non-well-formed strings by default.\n\n### Lite version\n\nAlternate exports exist that can help reduce bundle size, see comparison:\n\n| import | size |\n| - | - |\n| [@exodus/bytes/encoding-browser.js](#exodusbytesencoding-browserjs-) | <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/encoding-browser.js?style=flat-square)</sub> |\n| [@exodus/bytes/encoding-lite.js](#exodusbytesencoding-litejs-) | <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/encoding-lite.js?style=flat-square)</sub> |\n| [@exodus/bytes/encoding.js](#exodusbytesencodingjs-) | <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/encoding.js?style=flat-square)</sub> |\n| `text-encoding` | <sub>![](https://img.shields.io/bundlejs/size/text-encoding?style=flat-square)</sub> |\n| `iconv-lite` | <sub>![](https://img.shields.io/bundlejs/size/iconv-lite/lib/index.js?style=flat-square)</sub> |\n| `whatwg-encoding` | <sub>![](https://img.shields.io/bundlejs/size/whatwg-encoding?style=flat-square)</sub> |\n\nLibraries are advised to use single-purpose hardened `@exodus/bytes/utf8.js` / `@exodus/bytes/utf16.js` APIs for Unicode.\n\nApplications (including React Native apps) are advised to load either `@exodus/bytes/encoding-lite.js` or `@exodus/bytes/encoding.js`\n(depending on whether legacy multi-byte support is needed) and use that as a global polyfill.\n\n#### `@exodus/bytes/encoding-lite.js`\n\nIf you don't need support for legacy multi-byte encodings.\n\nReduces the bundle size ~12x, while still keeping `utf-8`, `utf-16le`, `utf-16be` and all single-byte encodings specified by the spec.\nThe only difference is support for legacy multi-byte encodings.\n\nSee [the list of encodings](https://encoding.spec.whatwg.org/#names-and-labels).\n\nThis can be useful for example in React Native global TextDecoder polyfill,\nif you are sure that you don't need legacy multi-byte encodings support.\n\n#### `@exodus/bytes/encoding-browser.js`\n\nResolves to a tiny import in browser bundles, preferring native `TextDecoder` / `TextEncoder`.\n\nFor non-browsers (Node.js, React Native), loads a full implementation.\n\n> [!NOTE]\n> This is not the default behavior for `@exodus/bytes/encoding.js` because all major browser implementations have bugs,\n> which `@exodus/bytes/encoding.js` fixes. Only use if you are ok with that.\n\n## API\n\n### @exodus/bytes/utf8.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/utf8.js?style=flat-square)</sub>\n\nUTF-8 encoding/decoding\n\n```js\nimport { utf8fromString, utf8toString } from '@exodus/bytes/utf8.js'\n\n// loose\nimport { utf8fromStringLoose, utf8toStringLoose } from '@exodus/bytes/utf8.js'\n```\n\n_These methods by design encode/decode BOM (codepoint `U+FEFF` Byte Order Mark) as-is._\\\n_If you need BOM handling or detection, use `@exodus/bytes/encoding.js`_\n\n#### `utf8fromString(string, format = 'uint8')`\n\nEncode a string to UTF-8 bytes (strict mode)\n\nThrows on invalid Unicode (unpaired surrogates)\n\nThis is similar to the following snippet (but works on all engines):\n```js\n// Strict encode, requiring Unicode codepoints to be valid\nif (typeof string !== 'string' || !string.isWellFormed()) throw new TypeError()\nreturn new TextEncoder().encode(string)\n```\n\n#### `utf8fromStringLoose(string, format = 'uint8')`\n\nEncode a string to UTF-8 bytes (loose mode)\n\nReplaces invalid Unicode (unpaired surrogates) with replacement codepoints `U+FFFD`\nper [WHATWG Encoding](https://encoding.spec.whatwg.org/) specification.\n\n_Such replacement is a non-injective function, is irreversable and causes collisions.\\\nPrefer using strict throwing methods for cryptography applications._\n\nThis is similar to the following snippet (but works on all engines):\n```js\n// Loose encode, replacing invalid Unicode codepoints with U+FFFD\nif (typeof string !== 'string') throw new TypeError()\nreturn new TextEncoder().encode(string)\n```\n\n#### `utf8toString(arr)`\n\nDecode UTF-8 bytes to a string (strict mode)\n\nThrows on invalid UTF-8 byte sequences\n\nThis is similar to `new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(arr)`,\nbut works on all engines.\n\n#### `utf8toStringLoose(arr)`\n\nDecode UTF-8 bytes to a string (loose mode)\n\nReplaces invalid UTF-8 byte sequences with replacement codepoints `U+FFFD`\nper [WHATWG Encoding](https://encoding.spec.whatwg.org/) specification.\n\n_Such replacement is a non-injective function, is irreversable and causes collisions.\\\nPrefer using strict throwing methods for cryptography applications._\n\nThis is similar to `new TextDecoder('utf-8', { ignoreBOM: true }).decode(arr)`,\nbut works on all engines.\n\n### @exodus/bytes/utf16.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/utf16.js?style=flat-square)</sub>\n\nUTF-16 encoding/decoding\n\n```js\nimport { utf16fromString, utf16toString } from '@exodus/bytes/utf16.js'\n\n// loose\nimport { utf16fromStringLoose, utf16toStringLoose } from '@exodus/bytes/utf16.js'\n```\n\n_These methods by design encode/decode BOM (codepoint `U+FEFF` Byte Order Mark) as-is._\\\n_If you need BOM handling or detection, use `@exodus/bytes/encoding.js`_\n\n#### `utf16fromString(string, format = 'uint16')`\n\nEncode a string to UTF-16 bytes (strict mode)\n\nThrows on invalid Unicode (unpaired surrogates)\n\n#### `utf16fromStringLoose(string, format = 'uint16')`\n\nEncode a string to UTF-16 bytes (loose mode)\n\nReplaces invalid Unicode (unpaired surrogates) with replacement codepoints `U+FFFD`\nper [WHATWG Encoding](https://encoding.spec.whatwg.org/) specification.\n\n_Such replacement is a non-injective function, is irreversible and causes collisions.\\\nPrefer using strict throwing methods for cryptography applications._\n\n#### `utf16toString(arr, format = 'uint16')`\n\nDecode UTF-16 bytes to a string (strict mode)\n\nThrows on invalid UTF-16 byte sequences\n\nThrows on non-even byte length.\n\n#### `utf16toStringLoose(arr, format = 'uint16')`\n\nDecode UTF-16 bytes to a string (loose mode)\n\nReplaces invalid UTF-16 byte sequences with replacement codepoints `U+FFFD`\nper [WHATWG Encoding](https://encoding.spec.whatwg.org/) specification.\n\n_Such replacement is a non-injective function, is irreversible and causes collisions.\\\nPrefer using strict throwing methods for cryptography applications._\n\nThrows on non-even byte length.\n\n### @exodus/bytes/bigint.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/bigint.js?style=flat-square)</sub>\n\nConvert between BigInt and Uint8Array\n\n```js\nimport { fromBigInt, toBigInt } from '@exodus/bytes/bigint.js'\n```\n\n#### `fromBigInt(bigint, { length, format = 'uint8' })`\n\nConvert a BigInt to a Uint8Array or Buffer\n\nThe output bytes are in big-endian format.\n\nThrows if the BigInt is negative or cannot fit into the specified length.\n\n#### `toBigInt(arr)`\n\nConvert a Uint8Array or Buffer to a BigInt\n\nThe bytes are interpreted as a big-endian unsigned integer.\n\n### @exodus/bytes/hex.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/hex.js?style=flat-square)</sub>\n\nImplements Base16 from [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648)\n(no differences from [RFC3548](https://datatracker.ietf.org/doc/html/rfc4648)).\n\n```js\nimport { fromHex, toHex } from '@exodus/bytes/hex.js'\n```\n\n#### `fromHex(string, format = 'uint8')`\n\nDecode a hex string to bytes\n\nUnlike `Buffer.from()`, throws on invalid input\n\n#### `toHex(arr)`\n\nEncode a `Uint8Array` to a lowercase hex string\n\n### @exodus/bytes/base64.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/base64.js?style=flat-square)</sub>\n\nImplements base64 and base64url from [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648)\n(no differences from [RFC3548](https://datatracker.ietf.org/doc/html/rfc4648)).\n\n```js\nimport { fromBase64, toBase64 } from '@exodus/bytes/base64.js'\nimport { fromBase64url, toBase64url } from '@exodus/bytes/base64.js'\nimport { fromBase64any } from '@exodus/bytes/base64.js'\n```\n\n#### `fromBase64(string, { format = 'uint8', padding = 'both' })`\n\nDecode a base64 string to bytes\n\nOperates in strict mode for last chunk, does not allow whitespace\n\n#### `fromBase64url(string, { format = 'uint8', padding = false })`\n\nDecode a base64url string to bytes\n\nOperates in strict mode for last chunk, does not allow whitespace\n\n#### `fromBase64any(string, { format = 'uint8', padding = 'both' })`\n\nDecode either base64 or base64url string to bytes\n\nAutomatically detects the variant based on characters present\n\n#### `toBase64(arr, { padding = true })`\n\nEncode a `Uint8Array` to a base64 string (RFC 4648)\n\n#### `toBase64url(arr, { padding = false })`\n\nEncode a `Uint8Array` to a base64url string (RFC 4648)\n\n### @exodus/bytes/base32.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/base32.js?style=flat-square)</sub>\n\nImplements base32 and base32hex from [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648)\n(no differences from [RFC3548](https://datatracker.ietf.org/doc/html/rfc4648)).\n\n```js\nimport { fromBase32, toBase32 } from '@exodus/bytes/base32.js'\nimport { fromBase32hex, toBase32hex } from '@exodus/bytes/base32.js'\n```\n\n#### `fromBase32(string, { format = 'uint8', padding = 'both' })`\n\nDecode a base32 string to bytes\n\nOperates in strict mode for last chunk, does not allow whitespace\n\n#### `fromBase32hex(string, { format = 'uint8', padding = 'both' })`\n\nDecode a base32hex string to bytes\n\nOperates in strict mode for last chunk, does not allow whitespace\n\n#### `fromBase32crockford(string, options)`\n\nDecode a Crockford base32 string to bytes\n\nOperates in strict mode for last chunk, does not allow whitespace\n\nCrockford base32 decoding follows extra mapping per spec: `LIli -> 1, Oo -> 0`\n\n#### `toBase32(arr, { padding = false })`\n\nEncode a `Uint8Array` to a base32 string (RFC 4648)\n\n#### `toBase32hex(arr, { padding = false })`\n\nEncode a `Uint8Array` to a base32hex string (RFC 4648)\n\n#### `toBase32crockford(arr, options)`\n\nEncode a `Uint8Array` to a Crockford base32 string\n\n### @exodus/bytes/bech32.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/bech32.js?style=flat-square)</sub>\n\nImplements bech32 and bech32m from\n[BIP-0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#specification)\nand [BIP-0350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki#specification).\n\n```js\nimport { fromBech32, toBech32 } from '@exodus/bytes/bech32.js'\nimport { fromBech32m, toBech32m } from '@exodus/bytes/bech32.js'\nimport { getPrefix } from '@exodus/bytes/bech32.js'\n```\n\n#### `getPrefix(string, limit = 90)`\n\nExtract the prefix from a bech32 or bech32m string without full validation\n\nThis is a quick check that skips most validation.\n\n#### `fromBech32(string, limit = 90)`\n\nDecode a bech32 string to bytes\n\n#### `toBech32(prefix, bytes, limit = 90)`\n\nEncode bytes to a bech32 string\n\n#### `fromBech32m(string, limit = 90)`\n\nDecode a bech32m string to bytes\n\n#### `toBech32m(prefix, bytes, limit = 90)`\n\nEncode bytes to a bech32m string\n\n### @exodus/bytes/base58.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/base58.js?style=flat-square)</sub>\n\nImplements [base58](https://www.ietf.org/archive/id/draft-msporny-base58-03.txt) encoding.\n\nSupports both standard base58 and XRP variant alphabets.\n\n```js\nimport { fromBase58, toBase58 } from '@exodus/bytes/base58.js'\nimport { fromBase58xrp, toBase58xrp } from '@exodus/bytes/base58.js'\n```\n\n#### `fromBase58(string, format = 'uint8')`\n\nDecode a base58 string to bytes\n\nUses the standard Bitcoin base58 alphabet\n\n#### `toBase58(arr)`\n\nEncode a `Uint8Array` to a base58 string\n\nUses the standard Bitcoin base58 alphabet\n\n#### `fromBase58xrp(string, format = 'uint8')`\n\nDecode a base58 string to bytes using XRP alphabet\n\nUses the XRP variant base58 alphabet\n\n#### `toBase58xrp(arr)`\n\nEncode a `Uint8Array` to a base58 string using XRP alphabet\n\nUses the XRP variant base58 alphabet\n\n### @exodus/bytes/base58check.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/base58check.js?style=flat-square)</sub>\n\nImplements [base58check](https://en.bitcoin.it/wiki/Base58Check_encoding) encoding.\n\n```js\nimport { fromBase58check, toBase58check } from '@exodus/bytes/base58check.js'\nimport { fromBase58checkSync, toBase58checkSync } from '@exodus/bytes/base58check.js'\nimport { makeBase58check } from '@exodus/bytes/base58check.js'\n```\n\nOn non-Node.js, requires peer dependency [@noble/hashes](https://www.npmjs.com/package/@noble/hashes) to be installed.\n\n#### `async fromBase58check(string, format = 'uint8')`\n\nDecode a base58check string to bytes asynchronously\n\nValidates the checksum using double SHA-256\n\n#### `async toBase58check(arr)`\n\nEncode bytes to base58check string asynchronously\n\nUses double SHA-256 for checksum calculation\n\n#### `fromBase58checkSync(string, format = 'uint8')`\n\nDecode a base58check string to bytes synchronously\n\nValidates the checksum using double SHA-256\n\n#### `toBase58checkSync(arr)`\n\nEncode bytes to base58check string synchronously\n\nUses double SHA-256 for checksum calculation\n\n#### `makeBase58check(hashAlgo, hashAlgoSync)`\n\nCreate a base58check encoder/decoder with custom hash functions\n\n### @exodus/bytes/wif.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/wif.js?style=flat-square)</sub>\n\nWallet Import Format (WIF) encoding and decoding.\n\n```js\nimport { fromWifString, toWifString } from '@exodus/bytes/wif.js'\nimport { fromWifStringSync, toWifStringSync } from '@exodus/bytes/wif.js'\n```\n\nOn non-Node.js, requires peer dependency [@noble/hashes](https://www.npmjs.com/package/@noble/hashes) to be installed.\n\n#### `async fromWifString(string[, version])`\n\nDecode a WIF string to WIF data\n\nReturns a promise that resolves to an object with `{ version, privateKey, compressed }`.\n\nThe optional `version` parameter validates the version byte.\n\nThrows if the WIF string is invalid or version doesn't match.\n\n#### `fromWifStringSync(string[, version])`\n\nDecode a WIF string to WIF data (synchronous)\n\nReturns an object with `{ version, privateKey, compressed }`.\n\nThe optional `version` parameter validates the version byte.\n\nThrows if the WIF string is invalid or version doesn't match.\n\n#### `async toWifString({ version, privateKey, compressed })`\n\nEncode WIF data to a WIF string\n\n#### `toWifStringSync({ version, privateKey, compressed })`\n\nEncode WIF data to a WIF string (synchronous)\n\n### @exodus/bytes/array.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/array.js?style=flat-square)</sub>\n\nTypedArray utils and conversions.\n\n```js\nimport { typedCopyBytes, typedView } from '@exodus/bytes/array.js'\n```\n\n#### `typedCopyBytes(arr, format = 'uint8')`\n\nCreate a copy of TypedArray underlying bytes in the specified format (`'uint8'`, `'buffer'`, or `'arraybuffer'`)\n\nThis does not copy _values_, but copies the underlying bytes.\nThe result is similar to that of `typedView()`, but this function provides a copy, not a view of the same memory.\n\n> [!WARNING]\n> Copying underlying bytes from `Uint16Array` (or other with `BYTES_PER_ELEMENT > 1`)\n> is platform endianness-dependent.\n\n> [!NOTE]\n> Buffer might be pooled.\n> Uint8Array return values are not pooled and match their underlying ArrayBuffer.\n\n#### `typedView(arr, format = 'uint8')`\n\nCreate a view of a TypedArray in the specified format (`'uint8'` or `'buffer'`)\n\n> [!IMPORTANT]\n> Does not copy data, returns a view on the same underlying buffer\n\n> [!WARNING]\n> Viewing `Uint16Array` (or other with `BYTES_PER_ELEMENT > 1`) as bytes\n> is platform endianness-dependent.\n\n### @exodus/bytes/encoding.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/encoding.js?style=flat-square)</sub>\n\nImplements the [Encoding standard](https://encoding.spec.whatwg.org/):\n[TextDecoder](https://encoding.spec.whatwg.org/#interface-textdecoder),\n[TextEncoder](https://encoding.spec.whatwg.org/#interface-textencoder),\n[TextDecoderStream](https://encoding.spec.whatwg.org/#interface-textdecoderstream),\n[TextEncoderStream](https://encoding.spec.whatwg.org/#interface-textencoderstream),\nsome [hooks](https://encoding.spec.whatwg.org/#specification-hooks).\n\n```js\nimport { TextDecoder, TextEncoder } from '@exodus/bytes/encoding.js'\nimport { TextDecoderStream, TextEncoderStream } from '@exodus/bytes/encoding.js' // Requires Streams\nimport { isomorphicDecode, isomorphicEncode } from '@exodus/bytes/encoding.js'\n\n// Hooks for standards\nimport { getBOMEncoding, legacyHookDecode, labelToName, normalizeEncoding } from '@exodus/bytes/encoding.js'\n```\n\n#### `new TextDecoder(label = 'utf-8', { fatal = false, ignoreBOM = false })`\n\n[TextDecoder](https://encoding.spec.whatwg.org/#interface-textdecoder) implementation/polyfill.\n\nDecode bytes to strings according to [WHATWG Encoding](https://encoding.spec.whatwg.org) specification.\n\n#### `new TextEncoder()`\n\n[TextEncoder](https://encoding.spec.whatwg.org/#interface-textencoder) implementation/polyfill.\n\nEncode strings to UTF-8 bytes according to [WHATWG Encoding](https://encoding.spec.whatwg.org) specification.\n\n#### `new TextDecoderStream(label = 'utf-8', { fatal = false, ignoreBOM = false })`\n\n[TextDecoderStream](https://encoding.spec.whatwg.org/#interface-textdecoderstream) implementation/polyfill.\n\nA [Streams](https://streams.spec.whatwg.org/) wrapper for `TextDecoder`.\n\nRequires [Streams](https://streams.spec.whatwg.org/) to be either supported by the platform or\n[polyfilled](https://npmjs.com/package/web-streams-polyfill).\n\n#### `new TextEncoderStream()`\n\n[TextEncoderStream](https://encoding.spec.whatwg.org/#interface-textencoderstream) implementation/polyfill.\n\nA [Streams](https://streams.spec.whatwg.org/) wrapper for `TextEncoder`.\n\nRequires [Streams](https://streams.spec.whatwg.org/) to be either supported by the platform or\n[polyfilled](https://npmjs.com/package/web-streams-polyfill).\n\n#### `isomorphicDecode(input)`\n\nImplements [isomorphic decode](https://infra.spec.whatwg.org/#isomorphic-decode).\n\nGiven a `TypedArray` or an `ArrayBuffer` instance `input`, creates a string of the same length\nas input byteLength, using bytes from input as codepoints.\n\nE.g. for `Uint8Array` input, this is similar to `String.fromCodePoint(...input)`.\n\nWider `TypedArray` inputs, e.g. `Uint16Array`, are interpreted as underlying _bytes_.\n\n#### `isomorphicEncode(str)`\n\nImplements [isomorphic encode](https://infra.spec.whatwg.org/#isomorphic-encode).\n\nGiven a string, creates an `Uint8Array` of the same length with the string codepoints as byte values.\n\nAccepts only [isomorphic string](https://infra.spec.whatwg.org/#isomorphic-string) input\nand asserts that, throwing on any strings containing codepoints higher than `U+00FF`.\n\n#### `labelToName(label)`\n\nImplements [get an encoding from a string `label`](https://encoding.spec.whatwg.org/#concept-encoding-get).\n\nConvert an encoding [label](https://encoding.spec.whatwg.org/#names-and-labels) to its name,\nas a case-sensitive string.\n\nIf an encoding with that label does not exist, returns `null`.\n\nAll encoding names are also valid labels for corresponding encodings.\n\n#### `normalizeEncoding(label)`\n\nConvert an encoding [label](https://encoding.spec.whatwg.org/#names-and-labels) to its name,\nas an ASCII-lowercased string.\n\nIf an encoding with that label does not exist, returns `null`.\n\nThis is the same as [`decoder.encoding` getter](https://encoding.spec.whatwg.org/#dom-textdecoder-encoding),\nexcept that it:\n 1. Supports [`replacement` encoding](https://encoding.spec.whatwg.org/#replacement) and its\n    [labels](https://encoding.spec.whatwg.org/#ref-for-replacement%E2%91%A1)\n 2. Does not throw for invalid labels and instead returns `null`\n\nIt is identical to:\n```js\nlabelToName(label)?.toLowerCase() ?? null\n```\n\nAll encoding names are also valid labels for corresponding encodings.\n\n#### `getBOMEncoding(input)`\n\nImplements [BOM sniff](https://encoding.spec.whatwg.org/#bom-sniff) legacy hook.\n\nGiven a `TypedArray` or an `ArrayBuffer` instance `input`, returns either of:\n- `'utf-8'`, if `input` starts with UTF-8 byte order mark.\n- `'utf-16le'`, if `input` starts with UTF-16LE byte order mark.\n- `'utf-16be'`, if `input` starts with UTF-16BE byte order mark.\n- `null` otherwise.\n\n#### `legacyHookDecode(input, fallbackEncoding = 'utf-8')`\n\nImplements [decode](https://encoding.spec.whatwg.org/#decode) legacy hook.\n\nGiven a `TypedArray` or an `ArrayBuffer` instance `input` and an optional `fallbackEncoding`\nencoding [label](https://encoding.spec.whatwg.org/#names-and-labels),\nsniffs encoding from BOM with `fallbackEncoding` fallback and then\ndecodes the `input` using that encoding, skipping BOM if it was present.\n\nNotes:\n\n- BOM-sniffed encoding takes precedence over `fallbackEncoding` option per spec.\n  Use with care.\n- Always operates in non-fatal [mode](https://encoding.spec.whatwg.org/#textdecoder-error-mode),\n  aka replacement. It can convert different byte sequences to equal strings.\n\nThis method is similar to the following code, except that it doesn't support encoding labels and\nonly expects lowercased encoding name:\n\n```js\nnew TextDecoder(getBOMEncoding(input) ?? fallbackEncoding).decode(input)\n```\n\n### @exodus/bytes/encoding-lite.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/encoding-lite.js?style=flat-square)</sub>\n\nThe exact same exports as `@exodus/bytes/encoding.js` are also exported as\n`@exodus/bytes/encoding-lite.js`, with the difference that the lite version does not load\nmulti-byte `TextDecoder` encodings by default to reduce bundle size ~12x.\n\n```js\nimport { TextDecoder, TextEncoder } from '@exodus/bytes/encoding-lite.js'\nimport { TextDecoderStream, TextEncoderStream } from '@exodus/bytes/encoding-lite.js' // Requires Streams\nimport { isomorphicDecode, isomorphicEncode } from '@exodus/bytes/encoding-lite.js'\n\n// Hooks for standards\nimport { getBOMEncoding, legacyHookDecode, labelToName, normalizeEncoding } from '@exodus/bytes/encoding-lite.js'\n```\n\nThe only affected encodings are: `gbk`, `gb18030`, `big5`, `euc-jp`, `iso-2022-jp`, `shift_jis`\nand their [labels](https://encoding.spec.whatwg.org/#names-and-labels) when used with `TextDecoder`.\n\nLegacy single-byte encodingds are loaded by default in both cases.\n\n`TextEncoder` and hooks for standards (including `labelToName` / `normalizeEncoding`) do not have any behavior\ndifferences in the lite version and support full range if inputs.\n\nTo avoid inconsistencies, the exported classes and methods are exactly the same objects.\n\n```console\n> lite = require('@exodus/bytes/encoding-lite.js')\n[Module: null prototype] {\n  TextDecoder: [class TextDecoder],\n  TextDecoderStream: [class TextDecoderStream],\n  TextEncoder: [class TextEncoder],\n  TextEncoderStream: [class TextEncoderStream],\n  getBOMEncoding: [Function: getBOMEncoding],\n  labelToName: [Function: labelToName],\n  legacyHookDecode: [Function: legacyHookDecode],\n  normalizeEncoding: [Function: normalizeEncoding]\n}\n> new lite.TextDecoder('big5').decode(Uint8Array.of(0x25))\nUncaught:\nError: Legacy multi-byte encodings are disabled in /encoding-lite.js, use /encoding.js for full encodings range support\n\n> full = require('@exodus/bytes/encoding.js')\n[Module: null prototype] {\n  TextDecoder: [class TextDecoder],\n  TextDecoderStream: [class TextDecoderStream],\n  TextEncoder: [class TextEncoder],\n  TextEncoderStream: [class TextEncoderStream],\n  getBOMEncoding: [Function: getBOMEncoding],\n  labelToName: [Function: labelToName],\n  legacyHookDecode: [Function: legacyHookDecode],\n  normalizeEncoding: [Function: normalizeEncoding]\n}\n> full.TextDecoder === lite.TextDecoder\ntrue\n> new full.TextDecoder('big5').decode(Uint8Array.of(0x25))\n'%'\n> new lite.TextDecoder('big5').decode(Uint8Array.of(0x25))\n'%'\n```\n\n### @exodus/bytes/encoding-browser.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/encoding-browser.js?style=flat-square)</sub>\n\nSame as `@exodus/bytes/encoding.js`, but in browsers instead of polyfilling just uses whatever the\nbrowser provides, drastically reducing the bundle size (to less than 2 KiB gzipped).\n\nDoes not provide `isomorphicDecode` and `isomorphicEncode` exports.\n\n```js\nimport { TextDecoder, TextEncoder } from '@exodus/bytes/encoding-browser.js'\nimport { TextDecoderStream, TextEncoderStream } from '@exodus/bytes/encoding-browser.js' // Requires Streams\n\n// Hooks for standards\nimport { getBOMEncoding, legacyHookDecode, labelToName, normalizeEncoding } from '@exodus/bytes/encoding-browser.js'\n```\n\nUnder non-browser engines (Node.js, React Native, etc.) a full polyfill is used as those platforms\ndo not provide sufficiently complete / non-buggy `TextDecoder` APIs.\n\n> [!NOTE]\n> Implementations in browsers [have bugs](https://docs.google.com/spreadsheets/d/1pdEefRG6r9fZy61WHGz0TKSt8cO4ISWqlpBN5KntIvQ/edit),\n> but they are fixing them and the expected update window is short.\\\n> If you want to circumvent browser bugs, use full `@exodus/bytes/encoding.js` import.\n\n### @exodus/bytes/whatwg.js <sub>![](https://img.shields.io/bundlejs/size/@exodus/bytes/whatwg.js?style=flat-square)</sub>\n\nWHATWG helpers\n\n```js\nimport '@exodus/bytes/encoding.js' // For full legacy multi-byte encodings support\nimport { percentEncodeAfterEncoding } from '@exodus/bytes/whatwg.js'\n```\n\n#### `percentEncodeAfterEncoding(encoding, input, percentEncodeSet, spaceAsPlus = false)`\n\nImplements [percent-encode after encoding](https://url.spec.whatwg.org/#string-percent-encode-after-encoding)\nper WHATWG URL specification.\n\n> [!IMPORTANT]\n> You must import `@exodus/bytes/encoding.js` for this API to accept legacy multi-byte encodings.\n\nEncodings `utf16-le`, `utf16-be`, and `replacement` are not accepted.\n\n[C0 control percent-encode set](https://url.spec.whatwg.org/#c0-control-percent-encode-set) is\nalways percent-encoded.\n\n`percentEncodeSet` is an addition to that, and must be a string of unique increasing codepoints\nin range 0x20 - 0x7e, e.g. `' \"#<>'`.\n\nThis method accepts [DOMStrings](https://webidl.spec.whatwg.org/#idl-DOMString) and converts them\nto [USVStrings](https://webidl.spec.whatwg.org/#idl-USVString).\nThis is different from e.g. `encodeURI` and `encodeURIComponent` which throw on surrogates:\n```js\n> percentEncodeAfterEncoding('utf8', '\\ud800', ' \"#$%&+,/:;<=>?@[\\\\]^`{|}') // component\n'%EF%BF%BD'\n> encodeURIComponent('\\ud800')\nUncaught URIError: URI malformed\n```\n\n## Changelog\n\nSee [GitHub Releases](https://github.com/ExodusOSS/bytes/releases) tab\n\n## License\n\n[MIT](./LICENSE)\n","publish_time":1766952784035,"_cnpm_publish_time":1766952784035,"dist-tags":{"latest":"1.16.0"}}