# hypercore-id-encoding

> Convert Hypercore keys to/from z-base32 or hex

Latest version **1.3.0** (published 2024-03-26) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install hypercore-id-encoding
pnpm add hypercore-id-encoding
yarn add hypercore-id-encoding
bun add hypercore-id-encoding
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2024-03-26 |
| First published | 2022-06-18 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Maintainers | mafintosh, andrewosh |

## Links

- npm: https://www.npmjs.com/package/hypercore-id-encoding
- Repository: https://github.com/holepunchto/hypercore-id-encoding
- Homepage: https://github.com/holepunchto/hypercore-id-encoding#readme
- Issues: https://github.com/holepunchto/hypercore-id-encoding/issues
- npm.io page: https://npm.io/package/hypercore-id-encoding

## Dependencies (2)

- [b4a](https://npm.io/package/b4a.md) ^1.5.3
- [z32](https://npm.io/package/z32.md) ^1.0.0

## Recent versions

- 1.3.0 (latest) — 2024-03-26
- 1.2.0 — 2023-07-25
- 1.1.0 — 2023-06-07
- 1.0.2 — 2022-11-07
- 1.0.1 — 2022-11-02
- 1.0.0 — 2022-06-18

## README

# hypercore-id-encoding

Encodes Hypercore keys into z-base32 ids, and decodes both hex/z-base32 strings.

```
npm install hypercore-id-encoding
```

## Usage

```js
const { encode, decode, normalize } = require('hypercore-id-encoding')

const id = encode(core.key) // (z-base32 String)
const hexEncoded = core.key.toString('hex')

const core = new Hypercore(ram, decode(id)) 
const core2 = new Hypercore(ram, decode(hexEncoded)) // Will also work with hex

const id2 = normalize(id)
const id3 = normalize(hexEncoded)
```

## API

#### `const id = encode(hypercoreKey)`

Encodes a 32-byte Hypercore key into a z-base32 id.

`hypercoreKey` must be a Buffer or an ArrayBuffer.

#### `const buf = decode(hypercoreId)`

Decodes an id or pear link into a Hypercore key.

If `hypercoreId` is a 52-character String, it will be decoded as z-base32.

If `hypercoreId` is a 64-character String, it will be decoded as hex.

If `hypercoreId` is already a Buffer and is a valid id, it will be returned as-is.

#### `const id = normalize(any)`

Decodes and encodes the input `any` to always return a z-base32 id.

#### `isValid(any)`

Returns a boolean indicating whether the key is a valid hypercore key (meaning that it can be decoded/normalised).

## License

Apache-2.0

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