This package builds a wrapper around the messaging system used to interact with
the XDB Wallet wallet (a web browser extension). Client applications will be able to
install this package from npm and then integrate with XDB Wallet using dev-friendly
methods like getPublicKey
.
Both the XDB Wallet web extension and XDB Wallet API are built to support transactions on the XDB Chain blockchain network.
import xdbwalletApi from "@xdbchain/xdbwallet-api";
or import just the modules you require:
import {
isConnected,
getPublicKey,
signTransaction,
getNetwork,
} from "@xdbchain/xdbwallet-api";
Now let's dig into what functionality is available to you:
This function is useful for determining if a user in your application has XDB Wallet installed.
import { isConnected } from "@xdbchain/xdbwallet-api";
if (await isConnected()) {
alert("User has XDB Wallet!");
}
If the user has authorized your application previously and XDB Wallet is connected, XDB Wallet will simply return the public key. If either one of the above is not true, it will return an empty string.
import { getPublicKey } from "@xdbchain/xdbwallet-api";
const retrievePublicKey = async () => {
let publicKey = "";
let error = "";
try {
publicKey = await getPublicKey();
} catch (e) {
error = e;
}
if (error) {
return error;
}
return publicKey;
};
const result = retrievePublicKey();
This function is useful for determining what network the user has configured XDB Wallet to use.
import {
isConnected,
getNetwork,
} from "@xdbchain/xdbwallet-api";
if (await isConnected()) {
alert("User has XDB Wallet!");
}
const retrieveNetwork = async () => {
let network = "";
let error = "";
try {
network = await getNetwork();
} catch (e) {
error = e;
}
if (error) {
return error;
}
return network;
};
const result = retrieveNetwork();
This function accepts a transaction XDR string as the first parameter, which it will decode, sign as the user, and then return the signed transaction to your application.
The user will need to provide their password if the extension does not currently have their private key. Once the user has provided their password, the extension will have access to the user private key for 5 minutes. The user must then review the transaction details and accept within those 5 minutes for the transaction to be signed.
NOTE: The user must provide a valid transaction XDR string for the extension to properly sign.