Skip to main content

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:

import {
isInstalled,
getAddresses,
signPsbt,
signMessage,
} from "@ordzaar/ordit-sdk/unisat";
tip

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, testnet or signet
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 without window object

getAddresses

getAddresses([network[, chain, options]])

Gets a list of addresses for the browser wallet if authorized.

Parameters:

  • network : "mainnet" | "testnet" | "signet" (defaults to mainnet) - Network
  • chain : "bitcoin" | "fractal-bitcoin" (defaults to bitcoin) - Chain
  • options : object (optional)
    • readOnly : boolean (defaults to false) - Read only. When set to true, the wallet modal appears for Unisat.

Returns: Promise<WalletAddress[]>

Output Example:

[
{
publicKey:
"0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
address: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
format: "segwit",
},
];

Throws:

  • BrowserWalletNotInstalledError Wallet is not installed
  • BrowserWalletRequestCancelledByUserError if user cancels the request on wallet popup
  • OrditSDKError Internal error

signPsbt

signPsbt(psbt[, options])

Signs a Partially Signed Bitcoin Transaction (PSBT) and returns a signature.

Parameters:

  • psbt : string - hex or base64 format
  • options : object (optional)
    • extractTx : Extract transaction (defaults to true)
    • finalize : Finalize signing (defaults to true)
    • network (for Xverse only) : "mainnet" | "testnet" | "signet" (defaults to mainnet)
    • 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 installed
  • BrowserWalletSigningError Signing failed
  • BrowserWalletExtractTxFromNonFinalizedPsbtError if extractTx is true but there are non-finalized transactions in the PSBT
  • BrowserWalletRequestCancelledByUserError if user cancels the request on wallet popup
  • OrditSDKError if invalid options are provided

signMessage

signMessage(message[, address, network, type])

Signs a message and returns a signature.

Parameters:

  • message : string
  • address (for Xverse only) : string - Wallet address to sign message
  • network (for Xverse only) : "mainnet" | "testnet" | "signet" (defaults to mainnet) - Network
  • type (for Unisat only) : "bip322-simple" | "ecdsa" (defaults to ecdsa)

Returns: Promise<BrowserWalletSignResponse>

Output Example:

{
base64: "cHNidP8BAAoCAAAAAAAAAAAAAAAA",
hex: "70736274ff01000a02000000000000000000000000",
}

Throws:

  • BrowserWalletNotInstalledError Wallet is not installed
  • BrowserWalletSigningError Signing failed
  • BrowserWalletRequestCancelledByUserError if user cancels the request on wallet popup
  • OrditSDKError if invalid options are provided