Kontor Wallet Client
The wallet client is an interface to the necessary cryptographic operations that mediate transacting on the Kontor network via Kontor Wallet Actions such as signCommit and signReveal.
Import
import { createKontorWalletClient } from "@kontor/kontor-sdk";JSON-RPC Accounts
A JSON-RPC Account delegates cryptographic operations to browser extension wallets ( e.g. Horizon, XVerse, and Leather ).
Usage
Unfortunately, there is not a uniform standard for a Bitcoin Wallet extensions which means that it is necessary to shim browser extension APIs to provide a consistent interface which can be used internally by the SDK. Accordingly, createKontorWallet client expects a custom transport that is configured with a request method that conforms to the WBIP001 specification.
Below is an example of configuring a wallet client to work with the Leather browser extension.
const client = createKontorWalletClient({
chain: signet,
transport: custom({
request: async ({ method, params }) => {
if (method === "signPsbt") {
const res = await window.LeatherProvider!.request("signPsbt", {
hex: params.psbt,
broadcast: params.broadcast,
signAtIndex: params.signInputs,
network: "signet",
});
return { result: { psbt: res.result.hex } };
}
return window.LeatherProvider!.request(method, params);
},
}),
});
const addresses = await client.getAddresses();Local Accounts
It is also possible to instantiate a wallet client that has access to a local private key.
mnemonicToAccount
import { createKontorWalletClient, signet, custom, mnemonicToAccount } from "@kontor/kontor-sdk";
const account = mnemonicToAccount("mnemomic phrase", {
networkConfig: signet.networkConfig,
coinType: 1,
});
const client = createKontorWalletClient({
account,
chain: signet,
// TODO: shouldn't need dummy transport
transport: custom({
request: async (args: any) => {},
}),
});
const addresses = await client.getAddresses();hdKeyToAccount
import { HDKey } from "@scure/bip32";
import {
createKontorWalletClient,
signet,
custom,
hdKeyToAccount,
} from "@kontor/kontor-sdk";
const seed = new Uint8Array([112, 111, 108, 121, 99, 114, 105, 115, 105, 115]);
const key = HDKey.fromMasterSeed(seed);
const account = hdKeyToAccount(key);
const client = createKontorWalletClient({
account,
chain: signet,
// TODO: shouldn't need dummy transport
transport: custom({
request: async (args: any) => {},
}),
});
const addresses = await client.getAddresses();privateKeyToAccount
import {
createKontorWalletClient,
signet,
custom,
privateKeyToAccount,
} from "@kontor/kontor-sdk";
const account = privateKeyToAccount("0xdabdad");
const client = createKontorWalletClient({
account,
chain: signet,
// TODO: shouldn't need dummy transport
transport: custom({
request: async (args: any) => {},
}),
});
const addresses = await client.getAddresses();