buildSignerGrantMessage
Builds the SIP-018 message and domain that a signer key signs to authorize a signer-manager. Pure computation that mirrors what pox-5 get-signer-grant-message-hash hashes.
Usage
import { buildSignerGrantMessage } from '@stacks/bitcoin-staking';
import { STACKS_MAINNET } from '@stacks/network';
import { signStructuredData } from '@stacks/transactions';
const { message, domain } = buildSignerGrantMessage({
signerManager: 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.my-signer-manager',
authId: 1n,
chainId: STACKS_MAINNET.chainId,
});
// The same signature signSignerGrant returns for these inputs.
const signature = signStructuredData({ message, domain, privateKey: process.env.SIGNER_KEY! });Notes
messageis the tuple{ topic: "grant-authorization", signer-manager, auth-id }anddomainis{ name: "pox-5-signer", version: "1.0.0", chain-id }, the values pox-5 hashes (pox-5.clar L2862-L2877, L90-L95).pox-5 fills
chain-idfrom the chain it runs on, sochainIdmust be that network's chain ID:1on mainnet,0x80000000on testnet.Use it with a signer that takes SIP-018 structured data. With the private key at hand, signSignerGrant signs in one call, and computeSignerGrantHash returns the 32-byte hash.
Signature
opts is a SignerKeyGrantOptions.
Returns
{ message: ClarityValue; domain: ClarityValue }
Parameters
opts.signerManager (required)
Type:
string
Stacks principal of the signer-manager being authorized.
opts.authId (required)
Type:
IntegerType
Replay nonce. pox-5 accepts each signer key, signer-manager and authId combination once.
opts.chainId (required)
Type:
number
Chain ID of the network the grant is for, for example STACKS_MAINNET.chainId.
Was this helpful?