> 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/signer/signsignergrant.md).

# signSignerGrant

Signs a signer-key grant with the signer's private key. Returns the signature that [buildGrantSignerKey](/reference/stacks.js/stacks-bitcoin-staking/build/buildgrantsignerkey.md) takes as `signerSignature`.

***

### Usage

```ts
import { signSignerGrant, verifySignerGrant } from '@stacks/bitcoin-staking';
import { STACKS_MAINNET } from '@stacks/network';
import { privateKeyToPublic, publicKeyToHex } from '@stacks/transactions';

const privateKey = process.env.SIGNER_KEY!;
const grant = {
  signerManager: 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.my-signer-manager',
  authId: 1n,
  chainId: STACKS_MAINNET.chainId,
};

const signature = signSignerGrant({ ...grant, privateKey });

const valid = verifySignerGrant({
  ...grant,
  publicKey: publicKeyToHex(privateKeyToPublic(privateKey)),
  signature,
});
```

#### Notes

* Returns a 65-byte recoverable signature in RSV order, hex-encoded (130 characters), over the hash from [computeSignerGrantHash](/reference/stacks.js/stacks-bitcoin-staking/signer/computesignergranthash.md).
* pox-5 recovers the public key from the signature and compares it with the 33-byte `signer-key` in `grant-signer-key` ([pox-5.clar L2766-L2778](https://github.com/stacks-network/stacks-core/blob/10474cdec9f9c0bdf05841b58cffc89cdad87a9b/stackslib/src/chainstate/stacks/boot/pox-5.clar#L2766-L2778)). Sign with the private key of that compressed public key.
* The hash includes the chain ID, so a grant signed for testnet fails on mainnet with `ERR_INVALID_SIGNATURE_PUBKEY (u14)`.
* Each signer key, signer-manager and `authId` combination can be granted once. Check an `authId` with [fetchSignerKeyGrantUsed](/reference/stacks.js/stacks-bitcoin-staking/fetch/fetchsignerkeygrantused.md).

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

***

### Signature

```ts
function signSignerGrant(opts: SignerKeyGrantOptions & { privateKey: PrivateKey }): string;
```

`opts` extends [SignerKeyGrantOptions](/reference/stacks.js/stacks-bitcoin-staking/types/signerkeygrantoptions.md) with `privateKey`.

***

### Returns

`string`

Hex-encoded 65-byte RSV signature.

***

### Parameters

#### opts.signerManager (required)

* **Type**: `string`

Stacks principal of the signer-manager being authorized.

#### opts.authId (required)

* **Type**: `IntegerType`

Replay nonce of the grant.

#### opts.chainId (required)

* **Type**: `number`

Chain ID of the network the grant is for: `1` on mainnet, `0x80000000` on testnet.

#### opts.privateKey (required)

* **Type**: `PrivateKey`

Private key of the signer key, as hex or bytes.


---

# 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/signer/signsignergrant.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.
