OKX Injected Providers API (Testnet) 基于 JavaScript 模型,由 OKX 嵌入用户访问网站中。DApp 项目可以通过调用此 API 请求用户账户信息,从用户所连接的区块链中读取数据,并协助用户进行消息和交易的签署。
okxwallet.bitcoinTestnet.connect()
描述
连接钱包
参数
无
返回值
示例
const result = await okxwallet.bitcoinTestnet.connect()
// example
{
address: 'bc1pwqye6x35g2n6xpwalywhpsvsu39k3l6086cvdgqazlw9mz2meansz9knaq',
publicKey: '4a627f388196639041ce226c0229560127ef9a5a39d4885123cd82dc82d8b497'
}
okxwallet.bitcoinTestnet.signMessage(signStr[, type])
描述
签名消息
参数
返回值
示例
const signStr = 'need sign string';
const result = await window.okxwallet.bitcoinTestnet.signMessage(signStr, 'ecdsa')
// example
INg2ZeG8b6GsiYLiWeQQpvmfFHqCt3zC6ocdlN9ZRQLhSFZdGhgYWF8ipar1wqJtYufxzSYiZm5kdlAcnxgZWQU=
okxwallet.bitcoinTestnet.signPsbt(psbtHex[, options])
描述
签名 psbt,该方法将遍历所有与当前地址匹配的输入进行签名
参数
构建交易生成 psbt (string 类型),如果遇到 input 地址是 Taproot 类型,需要提供公钥。
示例:可参考下面的 txInput 和 publicKey。
const txInputs: utxoInput[] = [];
txInputs.push({
txId: "1e0f92720ef34ab75eefc5d691b551fb2f783eac61503a69cdf63eb7305d2306",
vOut: 2,
amount: 341474,
address: "tb1q8h8....mjxzny",
privateKey: "0s79......ldjejke",
publicKey: "tb1q8h8....mjxzny",
bip32Derivation: [
{
"masterFingerprint": "a22e8e32",
"pubkey": "tb1q8h8....mjxzny",
"path": "m/49'/0'/0'/0/0",
},
],
});
返回值
示例
try {
let res = await okxwallet.bitcoinTestnet.signPsbt('70736274ff01007d....', {
autoFinalized: false,
toSignInputs: [
{
index: 0,
address: 'tb1q8h8....mjxzny',
},
{
index: 1,
publicKey: 'tb1q8h8....mjxzny',
sighashTypes: [1],
},
{
index: 2,
publicKey: '02062...8779693f',
},
],
});
console.log(res);
} catch (e) {
console.log(e);
}
okxwallet.bitcoinTestnet.signPsbt('xxxxxxxx', {
toSignInputs: [{ index: 0, publicKey: 'xxxxxx', disableTweakSigner: true }],
autoFinalized: false,
});
okxwallet.bitcoinTestnet.signPsbts(psbtHexs[, options])
描述
签署多个 psbt,该方法将遍历所有与当前地址匹配的输入进行签名
参数
构建交易生成 psbt (string 类型),如果遇到 input 地址是 Taproot 类型,需要提供公钥。
示例:可参考下面的 txInput 和 publicKey。
const txInputs: utxoInput[] = [];
txInputs.push({
txId: "1e0f92720ef34ab75eefc5d691b551fb2f783eac61503a69cdf63eb7305d2306",
vOut: 2,
amount: 341474,
address: "tb1q8h8....mjxzny",
privateKey: "0s79......ldjejke",
publicKey: "tb1q8h8....mjxzny",
bip32Derivation: [
{
"masterFingerprint": "a22e8e32",
"pubkey": "tb1q8h8....mjxzny",
"path": "m/49'/0'/0'/0/0",
},
],
});
返回值
示例
try {
let res = await okxwallet.bitcoinTestnet.signPsbts([
'70736274ff01007d...',
'70736274ff01007d...',
]);
console.log(res);
} catch (e) {
console.log(e);
}