Skip to Content
硬件接入
本页目录

btcGetPublicKey

Bitcoin:获取公钥

返回指定路径派生的公钥。可通过 showOnOneKey 请求用户在设备上确认。

const result = await HardwareSDK.btcGetPublicKey(connectId, deviceId, params);

参数

可选通用参数

导出单个公钥

  • path - 必需 string | Array<number> SDK 校验的最小长度为 1。 路径格式
  • showOnOneKey - 可选 boolean。是否在设备上显示公钥,默认为 true。
  • coin - 可选 string 决定 coins.json 文件中指定的网络定义。可以使用币种的 shortcut、name 或 label。如果未设置 coin,API 将尝试从 path 获取网络定义。
  • scriptType - 可选 InputScriptType,地址脚本类型

导出批量公钥

  • bundle - 对象数组,每个对象包含 path、coin 字段。

示例

返回第五个 Bitcoin 账户的公钥:

HardwareSDK.btcGetPublicKey(connectId, deviceId, { path: "m/49'/0'/4'", coin: "btc" });

批量返回多个 Bitcoin 账户的公钥:

HardwareSDK.btcGetPublicKey(connectId, deviceId, { bundle: [ { path: "m/49'/0'/0'" }, // account 1 { path: "m/49'/0'/1'" }, // account 2 { path: "m/49'/0'/2'" } // account 3 ] });

返回结果

单个公钥响应

{ success: true, payload: { path: string, // serialized BIP32 path xpub: string, // xpub in legacy format xpubSegwit?: string, // optional for segwit accounts: xpub in segwit format root_fingerprint?: number, node: { depth: number, fingerprint: number, child_num: number, chain_code: string, public_key: string, }, } }

了解更多关于 BIP32 序列化格式 

批量公钥响应

{ success: true, payload: [ { path, xpub, xpubSegwit, root_fingerprint, node }, // account 1 { path, xpub, xpubSegwit, root_fingerprint, node }, // account 2 { path, xpub, xpubSegwit, root_fingerprint, node } // account 3 ] }

错误

{ success: false, payload: { error: string, // error message code?: string | number // error code } }
最后更新于