btc.signTransaction
Sign a single BTC raw transaction via the btc object. Supports three signature types: legacy, segwit_v0, and taproot.
For the taproot type, leafHashesHex distinguishes between key path and script path: undefined for key path, a value for script path.
Usage
Legacy (P2PKH) Signing
ts
const result = await Turing.btc.signTransaction({
txHex: "0200000001...",
type: "legacy",
prevOutScriptsHex: ["76a914...88ac"],
});
if (result.sigs) {
console.log("Signatures:", result.sigs);
}SegWit V0 (P2WPKH) Signing
ts
const result = await Turing.btc.signTransaction({
txHex: "0200000001...",
type: "segwit_v0",
prevOutScriptsHex: ["76a914...88ac"],
values: [100000],
});
if (result.sigs) {
console.log("Signatures:", result.sigs);
}Taproot Key Path Signing
ts
const result = await Turing.btc.signTransaction({
txHex: "0200000001...",
type: "taproot",
prevOutScriptsHex: ["5120..."],
values: [100000],
});
if (result.sigs) {
console.log("Signatures:", result.sigs);
}Taproot Script Path Signing
ts
const result = await Turing.btc.signTransaction({
txHex: "0200000001...",
type: "taproot",
prevOutScriptsHex: ["5120..."],
values: [100000],
leafHashesHex: ["ab12cd34..."],
});
if (result.sigs) {
console.log("Signatures:", result.sigs);
}Parameters
ts
type BtcSigHashType = "legacy" | "segwit_v0" | "taproot";
interface BtcSignTransaction {
txHex: string; // Raw transaction hex
type: BtcSigHashType; // Signature hash type
prevOutScriptsHex: string[]; // Previous output script hex for each input
values?: number[]; // Amount (satoshis) for each input, required for segwit_v0/taproot
leafHashesHex?: (string | undefined)[]; // Leaf hash for each input, taproot only. undefined = key path, value = script path
}| Field | Type | Description |
|---|---|---|
txHex | string | Raw transaction hex to sign |
type | BtcSigHashType | Signature type — "legacy", "segwit_v0", or "taproot" |
prevOutScriptsHex | string[] | Previous output script hex for each input |
values | number[] | (Optional) Amount in satoshis for each input. Required for segwit_v0 and taproot |
leafHashesHex | (string | undefined)[] | (Optional) Leaf hash for each input. Taproot only — undefined for key path, a hex string for script path |
Returns
ts
interface BtcSignTransactionResponse {
sigs?: string[]; // Signature hex for each input
error?: string; // Error message
}| Field | Type | Description |
|---|---|---|
sigs | string[] | Array of signature hex strings, one per input |
error | string | Error message if signing fails |
Error Handling
ts
const result = await Turing.btc.signTransaction({
txHex: "0200000001...",
type: "legacy",
prevOutScriptsHex: ["76a914...88ac"],
});
if (result.error) {
console.error("Signing failed:", result.error);
return;
}
console.log("Signatures:", result.sigs);