本页目录
signPsbt
此方法将遍历所有匹配当前地址的输入进行签名。
钱包和地址类型兼容性
| 钱包类型 | 型号 | 支持的地址类型 |
|---|---|---|
| 软件钱包 | - | p2wpkh (原生隔离见证), p2tr (Taproot) |
| 硬件钱包 | Pro, Classic1S | p2tr (Taproot) |
方法
declare function signPsbt(
psbtHex: string,
options?: {
autoFinalized?: boolean;
toSignInputs?: Array<{
index: number;
address?: string;
publicKey?: string;
sighashTypes?: number[];
disableTweakSigner?: boolean;
useTweakedSigner?: boolean;
}>;
}
): Promise<string>参数
psbtHex— 必填string要签名的 PSBT 十六进制字符串options— 可选objectautoFinalized— 可选boolean:签名后是否完成 PSBT,默认为truetoSignInputs— 可选Array:指定要签名的输入index— 必填number:要签名的输入索引address— 可选string:(指定 address 或 publicKey 之一)用于确定签名密钥的地址publicKey— 可选string:(指定 address 或 publicKey 之一)用于确定签名密钥的公钥sighashTypes— 可选number[]:输入的可选签名哈希类型disableTweakSigner— 可选boolean:默认为 false。设置为 true 以在签名 Taproot 输入时使用原始私钥useTweakedSigner— 可选boolean:强制是否使用 tweaked 签名器。优先级高于 disableTweakSigner
返回值
Promise<string> — 签名后的 PSBT 十六进制字符串
示例
const provider = (window.$onekey && window.$onekey.btc) || window.unisat;
try {
// Basic signing
const signedBasic = await provider.signPsbt("70736274ff01007d....");
// Advanced signing with options
const signedAdvanced = await provider.signPsbt(
"70736274ff01007d....",
{
autoFinalized: false,
toSignInputs: [
{
index: 0,
address: "bc1qxxx...xxx",
},
{
index: 1,
publicKey: "02xxx...xxx",
sighashTypes: [1]
},
{
index: 2,
publicKey: "02xxx...xxx",
disableTweakSigner: true
}
]
}
);
console.log('Signed PSBT:', signedAdvanced);
} catch (error) {
console.error('Failed to sign PSBT:', error);
// Handle signing errors appropriately
}演示
钱包和地址兼容性取决于钱包及固件版本。使用兼容性表前,请确认目标账户是否支持相应操作。
上方省略的 PSBT、地址和公钥均为占位值,请替换为完整数据。公开的 provider 接口声明了 autoFinalized;额外的 toSignInputs 选项由钱包实现决定,需要在目标版本上验证。签名不会广播交易。
最后更新于