Skip to Content
硬件接入

btcGetPublicKey

Bitcoin:获取公钥

获取指定 BIP32 路径派生的扩展公钥。用户需要确认导出。

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

参数

可选通用参数

导出单个公钥

  • path - 必需 string | Array<number> 最小长度为 1更多信息
  • showOnOneKey - 可选 boolean 决定是否在设备上显示地址。默认设置为 true
  • coin - 可选 string 决定 coins.json 文件中指定的网络定义。可以使用币种的 shortcutnamelabel。如果未设置 coin,API 将尝试从 path 获取网络定义。
  • scriptType - 可选 InputScriptType,地址脚本类型

导出批量公钥

  • bundle - 包含 pathcoin 字段的对象 Array

示例

返回第五个比特币账户的公钥:

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

返回多个比特币账户的批量公钥:

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

返回结果

只有一个公钥的结果

{ success: true, payload: { path: Array<number>, // 强化路径 xpub: string, // 传统格式的 xpub xpubSegwit?: string, // segwit 账户可选:segwit 格式的 xpub chainCode: string, // BIP32 序列化格式 childNum: number, // BIP32 序列化格式 publicKey: string, // BIP32 序列化格式 fingerprint: number, // BIP32 序列化格式 depth: number, // BIP32 序列化格式 } }

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

批量公钥的结果

{ success: true, payload: [ { path, serializedPath, xpub, xpubSegwit?, chainCode, childNum, publicKey, fingerprint, depth }, // 账户 1 { path, serializedPath, xpub, xpubSegwit?, chainCode, childNum, publicKey, fingerprint, depth }, // 账户 2 { path, serializedPath, xpub, xpubSegwit?, chainCode, childNum, publicKey, fingerprint, depth } // 账户 3 ] }

错误

{ success: false, payload: { error: string, // 错误信息 code: number // 错误码 } }
Last updated on