Skip to Content
dApp 接入
本页目录

signPsbts

一次签名多个 PSBT。此方法将遍历所有匹配当前地址的输入进行签名。

钱包和地址类型兼容性

钱包类型型号支持的地址类型
软件钱包全部p2wpkh (原生隔离见证), p2tr (Taproot)
硬件钱包Pro, Classic1Sp2tr (Taproot)

方法

declare function signPsbts( psbtHexs: string[], options?: { autoFinalized?: boolean; toSignInputs?: Array<{ index: number; address?: string; publicKey?: string; sighashTypes?: number[]; disableTweakSigner?: boolean; useTweakedSigner?: boolean; }>; }, ): Promise<string[]>

参数

  • psbtHexs — 必填 string[] 要签名的 PSBT 十六进制字符串数组
  • options — 可选 object
    • autoFinalized — 可选 boolean 签名后是否完成 PSBT,默认为 true
    • toSignInputs — 可选 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 { const psbtHexs = [ "70736274ff01007d...", "70736274ff01007d..." ]; const signeds = await provider.signPsbts(psbtHexs, { autoFinalized: true, toSignInputs: [ { index: 0, publicKey: "02abc...", useTweakedSigner: true }, { index: 1, address: "bc1p...", disableTweakSigner: true } ] }); console.log(signeds); } catch (e) { console.log(e); }

演示

省略的数据均为占位值,请替换为完整的 PSBT、地址和公钥。公开的 provider 接口声明了 autoFinalized;高级输入选项由钱包实现决定,需要在目标版本上验证。签名不会广播交易。

最后更新于