
signPsbt
Request the signature and broadcast of a Partially Signed Bitcoin Transaction (PSBT)
Method name
signPsbt
Parameters
hex
Hex of PSBT payload for signing
string
allowedSighash
Sighash types allowed for signing and finalizing inputs (defaults to type ALL)
SignatureHash[]
signAtIndex
Input index(es) that should be signed (defaults to sign all inputs)
number | number[]
network
Network for signing: mainnet, testnet, signet, sbtcDevenv or devnet (defaults to the user's current network)
string
account
Index of account for signing (defaults to active account)
uint
broadcast
Whether to broadcast upon signing (default false). txid returned on successful broadcast.
boolean
descriptor
A wsh(...) output descriptor. Leather signs the inputs it locks with the active account's key. See Sign inputs locked by a wsh() descriptor. Leather browser extension 6.103.1 and later.
string
Example request
Sign PSBT
interface SignPsbtRequestParams {
hex: string;
allowedSighash?: SignatureHash[];
signAtIndex?: number | number[];
network?: NetworkModes; // default is user's current network
account?: number; // default is user's current account
broadcast?: boolean; // default is false - finalize/broadcast tx
descriptor?: string; // wsh(...) descriptor, extension 6.103.1 and later
}
const requestParams: SignPsbtRequestParams = { ...params };
const response = await window.LeatherProvider.request('signPsbt', requestParams);Broadcast PSBT
Our API returns a PSBT back to the app, with the newly applied signatures. If your use-case is to spend the transaction immediately, you'll first need to finalize it, then broadcast it to the network.
See this example below how to extract a signed transaction from the PSBT
Types and helper functions
Helper functions for Native SegWit PsbtRequestOptions
Helper functions for Taproot PsbtRequestOptions
Sign inputs locked by a wsh() descriptor
Pass a wsh(...) output descriptor as descriptor to sign PSBT inputs locked by a P2WSH miniscript policy, such as a multisig or a timelocked script, in which the active account holds one of the keys. Available in the Leather browser extension from 6.103.1.
The descriptor must include the active account's Native SegWit key in one of two forms:
The account's extended public key with a
/0/Nor/1/Nkey path. Every extended key in the descriptor must use the same key path, and Leather signs with the account key at that path.The raw public key of the account's first Native SegWit address (
m/84'/0'/0'/0/0for account 0 on mainnet), thepublicKeythatgetAddressesreturns for thep2wpkhentry.
With a descriptor, Leather compiles it to its witness script and output script, signs every PSBT input whose output script matches, and adds the witness script to those inputs. signAtIndex is not used in this mode. The matched inputs must use SIGHASH_DEFAULT or SIGHASH_ALL.
The response hex is the PSBT with the account's partial signature. With broadcast: true, Leather also tries to satisfy the whole policy from what the PSBT already carries: the other partial signatures, and hash preimages in the inputs' BIP-174 preimage fields. If that succeeds, it finalizes and broadcasts the transaction and returns txid. If not, it returns the partially signed PSBT without broadcasting, so your app can collect the remaining signatures.
On a Ledger account, the device signs. Each co-signer key given as a raw public key must resolve to an extended public key from the PSBT's PSBT_GLOBAL_XPUB or PSBT_IN_BIP32_DERIVATION fields, or the request fails.
-32602, Only wsh() descriptors are supported
descriptor does not start with wsh(
-32602, Request rejected: an input to sign uses a sighash type not covered by allowedSighash
A matched input uses a sighash type other than SIGHASH_DEFAULT or SIGHASH_ALL
-32600, Error signing transaction
The active account's key is not in the descriptor, no PSBT input is locked by it, or a matched input was left unsigned
Multisig accounts
A user can add a Bitcoin multisig vault created at leather.io/multisig to the Leather browser extension, from 6.112.0. Vaults are not yet available in the mobile app. When the active account is a Bitcoin vault, signPsbt does not sign. Leather proposes the PSBT to the vault's co-signers and returns the PSBT you sent, unsigned, with a proposal ID:
Check status before you treat hex as signed. With a vault active, Leather only accepts requests that spend from it with its bond-exit template:
descriptoris required and must be awsh(and_v(v:or_i(after(<unlock height>),and_v(v:sha256(<hash>),pk(<counterparty key>))),<vault multisig>))descriptor whose multisig part matches the connected vault.Every PSBT input must be locked by that descriptor and use
SIGHASH_DEFAULTorSIGHASH_ALL.
-32602, Proposing a transaction requires a descriptor and PSBT
No descriptor
-32602, Descriptor is not a supported bond template
The descriptor does not follow the bond-exit template
-32600, Connected multisig account does not match this bond descriptor
The descriptor's multisig keys are not the connected vault's
-32600, All PSBT inputs must be locked by the bond descriptor
An input is locked by something else
-32600, Bond proposals only support SIGHASH_DEFAULT or SIGHASH_ALL inputs
An input uses another sighash type
-32603, Failed to propose transaction
The proposal could not be submitted
Custom scripts
For more complex PSBTs, such as those using custom Bitcoin scripts, we recommend you read the supporting documentation of the @scure/btc-signer library.
Debugging
If you're running into issues signing a PSBT with Leather, the best way to debug the problem is to sign it without Leather.
Starting with a test-only mnemonic, drive a BTC address, and try sign the transaction. This helps ensure your PSBT is constructed correctly.
Here's a Codesandbox with a PSBT debugging environment set up for you to test. When asking for PSBT signing support, provide a test case forked from this.
Preview

Last updated
Was this helpful?