# encodeBytesKey

> **encodeBytesKey**(`value`): `Uint8Array`

Defined in: [packages/key-encoding/src/scalars.ts:186](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/key-encoding/src/scalars.ts#L186)

Encode a byte string so that `compareBytes` orders the keys as the byte strings themselves, and so the key is self-delimiting: it can be followed by more key bytes without changing the order.

Writes each `0x00` as `0x00 0xff` and ends with `0x00 0x00`. A byte string that is a prefix of another therefore sorts first, exactly as under [compareBytes](/reference/knotkit/key-encoding/functions/comparebytes/). Costs `value.byteLength + 2` bytes plus one per `0x00`.

## Parameters

### value

`Uint8Array`

## Returns

`Uint8Array`

## Throws

`INVALID_KEY_VALUE` when `value` is not a `Uint8Array`.
