> For the complete documentation index, see [llms.txt](https://docs.stacks.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stacks.co/reference/stacks.js/stacks-bitcoin-staking/script/validateearlyunlockbytes.md).

# validateEarlyUnlockBytes

Checks a bond's `early-unlock-bytes` subscript before it is spliced into a lockup script, and returns it as bytes. Pure computation: no network call.

***

### Usage

```ts
import { fetchBond, validateEarlyUnlockBytes } from '@stacks/bitcoin-staking';

const bond = await fetchBond({ bondIndex: 2, network: 'mainnet' });
if (!bond) throw new Error('bond 2 is not set up');

const earlyUnlockBytes = validateEarlyUnlockBytes(bond.earlyUnlockBytes);
```

#### Notes

* The structural check always runs. It throws if the bytes are empty, since the early-exit branch would then carry no spend condition, or if they do not decode as Bitcoin script, since a truncated push corrupts the assembled lockup script.
* The shape check runs unless `opts.shape` is `false`. It throws unless the subscript has exactly one 33-byte public-key push, ends in `OP_CHECKSIG`, and contains no `OP_IF`, `OP_NOTIF`, `OP_ELSE` or `OP_ENDIF`.
* pox-5 treats these bytes as opaque, so an M-of-N template is valid on chain but fails the shape check. Pass `{ shape: false }` for such a bond. [finalizeReclaim](/reference/stacks.js/stacks-bitcoin-staking/reclaim/finalizereclaim.md) still cannot assemble an early-exit witness for more than one cosigner key.
* The bytes come from the bond's `early-unlock-bytes` field in the `protocol-bonds` map, up to 683 bytes ([L110-L128](https://github.com/stacks-network/stacks-core/blob/10474cdec9f9c0bdf05841b58cffc89cdad87a9b/stackslib/src/chainstate/stacks/boot/pox-5.clar#L110-L128)). Read them with [fetchBond](/reference/stacks.js/stacks-bitcoin-staking/fetch/fetchbond.md).
* [buildLockScript](/reference/stacks.js/stacks-bitcoin-staking/script/buildlockscript.md) runs this check on its `earlyUnlockBytes`.

[**Reference Link**](https://github.com/stx-labs/stacks.js/blob/6101c99efe5a9616ce7e16cef68e28fd10676e7e/packages/bitcoin-staking/src/script.ts#L197-L240)

***

### Signature

```ts
function validateEarlyUnlockBytes(
  earlyUnlockBytes: Uint8Array | string,
  opts?: { shape?: boolean }
): Uint8Array;
```

***

### Returns

`Uint8Array`

The subscript as bytes, unchanged.

***

### Parameters

#### earlyUnlockBytes (required)

* **Type**: `Uint8Array | string`

The bond's early-unlock subscript, as bytes or hex.

#### opts.shape (optional)

* **Type**: `boolean`

Whether to run the shape check. Defaults to `true`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stacks.co/reference/stacks.js/stacks-bitcoin-staking/script/validateearlyunlockbytes.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
