CompactSize
Utility functions for Bitcoin's CompactSize variable-length integer encoding.
Examples
Below are some examples demonstrating common usages of the CompactSize module:
Encoding
import { CompactSize } from 'ox'
const bytes = CompactSize.toBytes(65535)Decoding
import { CompactSize } from 'ox'
const { value, size } = CompactSize.fromBytes(new Uint8Array([0xfd, 0xff, 0xff]))Functions
| Name | Description |
|---|---|
CompactSize.fromBytes | Decodes a CompactSize-encoded value from Bytes.Bytes. |
CompactSize.fromHex | Decodes a CompactSize-encoded value from Hex.Hex. |
CompactSize.toBytes | Encodes an integer using Bitcoin's CompactSize variable-length encoding. |
CompactSize.toHex | Encodes an integer using Bitcoin's CompactSize variable-length encoding and returns it as Hex.Hex. |
Errors
| Name | Description |
|---|---|
CompactSize.InsufficientBytesError | Thrown when there are insufficient bytes to decode a CompactSize value. |
CompactSize.NegativeValueError | Thrown when a CompactSize value is negative. |

