forked from Koniverse/SubWallet-Extension
-
Notifications
You must be signed in to change notification settings - Fork 1
BTC Provider
1% edited this page Jul 4, 2024
·
1 revision
To determine if OpenBit has been loaded, check window.OpenBitProvider
, window.OpenBitProvider helps you make requests from Dapps to OpenBit.
Simply provide the method name and any necessary parameters. For example, use getAddress
to connect with OpenBit.
const accounts = await window.OpenBitProvider.request("getAddresses");
Your application can use the getAddresses method to request a connection to the OpenBit wallet, prompting users to share their Bitcoin addresses.`
[
{
address: string, // The user’s connected wallet address
publicKey: string, // A hex string representing the bytes of the public key of the account. You can use this to construct partially signed
// Bitcoin transactions (PSBT).
isTestnet: boolean, // The network type of the connected account: mainnet or testnet
derivationPath: string,
tweakedPublicKey: string,
type: "p2tr" | "p2wpkh" | "unknow" // The address’s format,
// if the address type returned is 'unknown,' it means the address type is not yet supported by
// OpenBit.
},
]
const accounts = await window.OpenBitProvider.request("getAddresses");
{
result: {
addresses: [
{
"address": "tb1qw5k...zewats8j3",
"type": "p2sh",
"isTestnet": true,
"derivationPath": "m/84'/1'/0'/0/0",
"publicKey": "022d8f380dc8b4b29fa...6bf08c12f400a5e5dda15",
"tweakedPublicKey": "2d8f380dc8b4b29fad8e471aa...26bf08c12f400a5e5dda15"
},
{
"address": "tb1psnaergv47c8a2xt4hr...3k4fqt7rff3",
"type": "p2tr",
"isTestnet": true,
"derivationPath": "m/86'/1'/0'/0/0",
"publicKey": "02dbd9f32c6631786803215b97...30c35a642c533ba",
"tweakedPublicKey": "dbd9f32c6631786803215b97a2b2b8622a12cdf339b861b2230c35a642c533ba"
}
]
}
}
You can request your user to sign a message with their OpenBit's Bitcoin addresses, by invoking the signMessage method.
{
address: string, //a string representing the address to use to sign the message
message: string //a string representing the message to be signed by the wallet
}
{
signature: string, // a string representing the signed message.
address: string, // a string representing the address used for signing
message: string //a string representing the message to be signed by the wallet
}
const result = await window.OpenBitProvider.request("signMessage", {
message: "Hello world",
address: "tb1qpm2duck....efgj39g6wvw6m48"
});
{
signature: "GylRLzywQkyg0j5L/xPtW...gDZNBMnvYwOkGUSmXMHUxrZ9xCmDT5uQ1fJQ=",
address: "tb1qpm2duck....efgj39g6wvw6m48" ,
message: "Hello world"
}
Request the signature and broadcast of a Partially Signed Bitcoin Transaction (PSBT).
{
psbt: string, //Hex of PSBT payload for signing
allowedSighash ?: SignatureHash[], //Sighash types allowed for signing and finalizing inputs (defaults to type ALL)
signAtIndex ?: number | number[], // Input index(es) that should be signed (defaults to sign all inputs)
network : string, // Network for signing: mainnet, testnet,
account: string, //A string representing the address to use to sign the message
broadcast ?: boolean // Whether to broadcast upon signing (default false)
}
{
psbt : string, //The hex encoded signed PSBT
txid ?: string // The transaction id as a hex-encoded string.
// This is only returned if the transaction was broadcasted.
}
const result = await window.OpenBitProvider.request("signPsbt", {
psbt: "7073627...12a34e000000",
signAtIndex: [0],
account: "tb1qpm2duck3g53gj7lm...fgj39g6wvw6m48",
network: "testnet",
broadcast: false
});
{
psbt: "70736274ff010071020000000...555d7cc9000000",
txid: "0201acfcffe78dcf2...3e6006f675284beb0"
}
{
account: string, // Address of account to send
network: string, // Network for send: mainnet or testnet
recipients: RecipientsParam[] // Array of amounts to transfer by recipient address
}
interface RecipientParams {
address: string, // A string representing the recipient's address
amount: string // string representing the amount of Bitcoin to send, denominated in satoshis (Bitcoin base unit)
}
//The request will return a string that is the transaction ID as a hex-encoded string.
const result = await window.OpenBitProvider.request("sendTransfer", {
account: "tb1qpm2duck3g....fgj39g6wvw6m48",
recipients: [
{
address: "tb1qw5k3jylesv....wyw0hzewats8j3,
amount: "10000",
},
],
network: "testnet",
});
console.log(result)
//"0201acfcffe78dcf2...3e6006f675284beb0"