Browser Wallets
Browser Wallets supports the following wallets:
Connecting to Browser Wallets
You may interface with the wallets above by importing the API as follows:
- Unisat
- Xverse
import {
isInstalled,
getAddresses,
signPsbt,
signMessage,
} from "@ordzaar/ordit-sdk/unisat";
import {
isInstalled,
getAddresses,
signPsbt,
signMessage,
} from "@ordzaar/ordit-sdk/xverse";
Importing the functions individually ensures that tree-shaking is applied when bundling your application.
Example
The following snippet checks if the browser wallet is installed and returns a list of addresses, if authorized by the wallet.
async function connectToWallet() {
if (!isInstalled()) {
throw new Error("Wallet is not installed");
}
const addresses = await getAddresses("mainnet"); // mainnet or testnet
console.log(addresses);
// Example output of addresses:
//
// [{
// publicKey:
// "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
// address: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
// format: "segwit",
// }]
//
// or an error is thrown by the wallet provider.
}
connectToWallet();
API Reference
isInstalled
isInstalled()
Indicates whether the browser wallet extension is installed.
Returns: boolean
Output Example: true | false
Throws:
OrditSDKError
Function is called outside a browser withoutwindow
object
getAddresses
getAddresses([network, readOnly])
Gets a list of addresses for the browser wallet if authorized.
Parameters:
network
:"mainnet" | "testnet"
(defaults tomainnet
) - NetworkreadOnly
: boolean (defaults tofalse
) - Read only (when set to true, the wallet modal appears)
Returns: Promise<WalletAddress[]>
Output Example:
[
{
publicKey:
"0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
address: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
format: "segwit",
},
];
Throws:
BrowserWalletNotInstalledError
Wallet is not installedBrowserWalletRequestCancelledByUserError
if user cancels the request on wallet popupOrditSDKError
Internal error
signPsbt
signPsbt(psbt[, options])
Signs a Partially Signed Bitcoin Transaction (PSBT) and returns a signature.
Parameters:
psbt
:string
- hex or base64 formatoptions
:object
(optional for Unisat)extractTx
: Extract transaction (defaults totrue
)finalize
: Finalize signing (defaults totrue
)network
(for Xverse only) :"mainnet" | "testnet"
(defaults tomainnet
)inputsToSign
(for Xverse only) : List of inputs and signing indexes to sign
Note: Extracting a transaction is only possible when all transactions on the PSBT are finalized. Hence, when extractTx
is true
, finalize
must also be true
and all other inputs must have been finalized.
Sample input (for Xverse):
{
extractTx: true,
finalize: true
network: "mainnet",
inputsToSign: [
{
address: "bc1pr09enf3yc43cz8qh7xwaasuv3xzlgfttdr3wn0q2dy9frkhrpdtsk05jqq",
signingIndexes: [0, 1],
},
],
}
Returns: Promise<BrowserWalletSignResponse>
Output Example:
{
base64: "cHNidP8BAAoCAAAAAAAAAAAAAAAA",
hex: "70736274ff01000a02000000000000000000000000",
}
Throws:
BrowserWalletNotInstalledError
Wallet is not installedBrowserWalletSigningError
Signing failedBrowserWalletExtractTxFromNonFinalizedPsbtError
ifextractTx
istrue
but there are non-finalized transactions in the PSBTBrowserWalletRequestCancelledByUserError
if user cancels the request on wallet popupOrditSDKError
if invalid options are provided
signMessage
signMessage(message[, type])
Signs a message and returns a signature.
Parameters:
message
:string
address
(for Xverse only) :string
- Wallet address to sign messagenetwork
(for Xverse only) :"mainnet" | "testnet"
(defaults tomainnet
) - Networktype
(for Unisat only) :"bip322-simple" | "ecdsa"
(defaults toecdsa
)
Returns: Promise<BrowserWalletSignResponse>
Output Example:
{
base64: "cHNidP8BAAoCAAAAAAAAAAAAAAAA",
hex: "70736274ff01000a02000000000000000000000000",
}
Throws:
BrowserWalletNotInstalledError
Wallet is not installedBrowserWalletSigningError
Signing failedBrowserWalletRequestCancelledByUserError
if user cancels the request on wallet popupOrditSDKError
if invalid options are provided