# @endo/hex

> Transcodes hexadecimal

Latest version **1.1.1** (published 2026-06-12) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @endo/hex
pnpm add @endo/hex
yarn add @endo/hex
bun add @endo/hex
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2026-06-12 |
| First published | 2026-05-27 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1053 |
| Author | Endo contributors |
| Maintainers | kriskowal, michaelfig, erights, warner, mhofman, boneskull, naugtur, turadga, kriscendobot |
| Keywords | hex, hexadecimal, endo, ses |

## Links

- npm: https://www.npmjs.com/package/@endo/hex
- Repository: https://github.com/endojs/endo
- Homepage: https://github.com/endojs/endo/blob/master/packages/hex/README.md
- Issues: https://github.com/endojs/endo/issues
- npm.io page: https://npm.io/package/@endo/hex

## Dependencies (1)

- [@endo/harden](https://npm.io/package/@endo/harden.md) ^1.1.0

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@oxyhq/services](https://npm.io/package/@oxyhq/services.md) — 2.3K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2026-06-12
- 1.1.0 — 2026-05-27

## README

# `@endo/hex`

`@endo/hex` encodes and decodes between `Uint8Array` and hexadecimal
strings.
It is a ponyfill for the TC39 `Uint8Array.prototype.toHex` and
`Uint8Array.fromHex` intrinsics (proposal-arraybuffer-base64, Stage 4),
but for errors provides a consistent diagnostic optionally including a name to
identify the file the source material came from, which can be instrumental for
debugging.

On engines that ship the native intrinsics, `encodeHex` and `decodeHex`
dispatch to them at module load time.
On older engines, and in SES-locked-down compartments where a realm
has removed the intrinsics, the package falls through to a portable
pure-JavaScript implementation.

## Install

```sh
npm install @endo/hex
```

## Usage

```js
import { encodeHex } from '@endo/hex/encode.js';
import { decodeHex } from '@endo/hex/decode.js';

// Or, if you genuinely need to entrain both implementations:
// import { encodeHex, decodeHex } from '@endo/hex';

encodeHex(new Uint8Array([0xb0, 0xb5, 0xc4, 0xfe])); // 'b0b5c4fe'
decodeHex('b0b5c4fe'); // Uint8Array(4) [0xb0, 0xb5, 0xc4, 0xfe]
```

## API

### `encodeHex(bytes) -> string`

Encodes a `Uint8Array` as a lowercase hex string.
Callers that need uppercase can call `.toUpperCase()` on the result.

### `decodeHex(string, name?) -> Uint8Array`

Decodes a hex string to a `Uint8Array`.
Accepts both upper- and lowercase input.
Throws on odd-length strings and on characters outside `[0-9a-fA-F]`.
The optional `name` parameter is included in error messages for
diagnostic context.

## Hardened JavaScript

The native intrinsic reference is captured once at module load, before
any caller can reach the exported functions and before SES lockdown
freezes `Uint8Array`.
Post-lockdown mutation of `Uint8Array` cannot redirect the dispatched
bindings.

In a post-lockdown environment, this module hardens its interfaces to reduce
supply chain attack exposure.

---
_Source: https://npm.io/package/@endo/hex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
