diff --git a/.changeset/tender-birds-worry.md b/.changeset/tender-birds-worry.md new file mode 100644 index 0000000..5f6674b --- /dev/null +++ b/.changeset/tender-birds-worry.md @@ -0,0 +1,5 @@ +--- +"@babylonlabs-io/bbn-wallet-connect": patch +--- + +Minimize BTC interface diff --git a/src/core/types.ts b/src/core/types.ts index 495a393..2601334 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -174,14 +174,19 @@ export interface IBTCProvider extends IProvider { getNetwork(): Promise; /** - * Signs a message using BIP-322 simple. + * Signs a message using the specified signing method. * @param message - The message to sign. + * @param type - The signing method to use. * @returns A promise that resolves to the signed message. */ - signMessageBIP322(message: string): Promise; - signMessage(message: string, type: "ecdsa" | "bip322-simple"): Promise; + /** + * Retrieves the inscriptions for the connected wallet. + * @returns A promise that resolves to an array of inscriptions. + */ + getInscriptions(): Promise; + /** * Registers an event listener for the specified event. * At the moment, only the "accountChanged" event is supported. @@ -190,51 +195,24 @@ export interface IBTCProvider extends IProvider { */ on(eventName: string, callBack: () => void): void; - off(eventName: string, callBack: () => void): void; - - /** - * Gets the balance for the connected wallet address. - * By default, this method will return the mempool balance if not implemented by the child class. - * @returns A promise that resolves to the balance of the wallet. - */ - getBalance(): Promise; - - /** - * Retrieves the network fees. - * @returns A promise that resolves to the network fees. - */ - getNetworkFees(): Promise; - - /** - * Pushes a transaction to the network. - * @param txHex - The hexadecimal representation of the transaction. - * @returns A promise that resolves to a string representing the transaction ID. - */ - pushTx(txHex: string): Promise; - /** - * Retrieves the unspent transaction outputs (UTXOs) for a given address and amount. - * - * If the amount is provided, it will return UTXOs that cover the specified amount. - * If the amount is not provided, it will return all available UTXOs for the address. - * - * @param address - The address to retrieve UTXOs for. - * @param amount - Optional amount of funds required. - * @returns A promise that resolves to an array of UTXOs. + * Unregisters an event listener for the specified event. + * @param eventName - The name of the event to listen for. + * @param callBack - The callback function to be executed when the event occurs. */ - getUtxos(address: string, amount?: number): Promise; + off(eventName: string, callBack: () => void): void; /** - * Retrieves the tip height of the BTC chain. - * @returns A promise that resolves to the block height. + * Gets the name of the wallet provider. + * @returns A promise that resolves to the name of the wallet provider. */ - getBTCTipHeight(): Promise; + getWalletProviderName(): Promise; /** - * Retrieves the inscriptions for the connected wallet. - * @returns A promise that resolves to an array of inscriptions. + * Gets the icon URL of the wallet provider. + * @returns A promise that resolves to the icon URL of the wallet provider. */ - getInscriptions(): Promise; + getWalletProviderIcon(): Promise; } export interface IBBNProvider extends IProvider { diff --git a/src/core/wallets/btc/BTCProvider.ts b/src/core/wallets/btc/BTCProvider.ts index 4807fbe..08facaf 100644 --- a/src/core/wallets/btc/BTCProvider.ts +++ b/src/core/wallets/btc/BTCProvider.ts @@ -1,16 +1,12 @@ -import type { BTCConfig, Fees, IBTCProvider, InscriptionIdentifier, Network, UTXO } from "../../types"; -import { createMempoolAPI, MempoolApi } from "../../utils/mempool"; +import type { BTCConfig, IBTCProvider, InscriptionIdentifier, Network } from "../../types"; /** * Abstract class representing a wallet provider. * Provides methods for connecting to a wallet, retrieving wallet information, signing transactions, and more. */ export abstract class BTCProvider implements IBTCProvider { - protected mempool: MempoolApi; + constructor(protected config: BTCConfig) {} - constructor(protected config: BTCConfig) { - this.mempool = createMempoolAPI(this.config.mempoolApiUrl); - } /** * Connects to the wallet and returns the instance of the wallet provider. * Currently only supports "native segwit" and "taproot" address types. @@ -52,14 +48,19 @@ export abstract class BTCProvider implements IBTCProvider { abstract getNetwork(): Promise; /** - * Signs a message using BIP-322 simple. + * Signs a message using the specified signing method. * @param message - The message to sign. + * @param type - The signing method to use. * @returns A promise that resolves to the signed message. */ - abstract signMessageBIP322(message: string): Promise; - abstract signMessage(message: string, type: "ecdsa" | "bip322-simple"): Promise; + /** + * Retrieves the inscriptions for the connected wallet. + * @returns A promise that resolves to an array of inscriptions. + */ + abstract getInscriptions(): Promise; + /** * Registers an event listener for the specified event. * At the moment, only the "accountChanged" event is supported. @@ -68,49 +69,22 @@ export abstract class BTCProvider implements IBTCProvider { */ abstract on(eventName: string, callBack: () => void): void; - abstract off(eventName: string, callBack: () => void): void; - - /** - * Gets the balance for the connected wallet address. - * By default, this method will return the mempool balance if not implemented by the child class. - * @returns A promise that resolves to the balance of the wallet. - */ - abstract getBalance(): Promise; - /** - * Retrieves the network fees. - * @returns A promise that resolves to the network fees. - */ - abstract getNetworkFees(): Promise; - - /** - * Pushes a transaction to the network. - * @param txHex - The hexadecimal representation of the transaction. - * @returns A promise that resolves to a string representing the transaction ID. - */ - abstract pushTx(txHex: string): Promise; - - /** - * Retrieves the unspent transaction outputs (UTXOs) for a given address and amount. - * - * If the amount is provided, it will return UTXOs that cover the specified amount. - * If the amount is not provided, it will return all available UTXOs for the address. - * - * @param address - The address to retrieve UTXOs for. - * @param amount - Optional amount of funds required. - * @returns A promise that resolves to an array of UTXOs. + * Unregisters an event listener for the specified event. + * @param eventName - The name of the event to listen for. + * @param callBack - The callback function to be executed when the event occurs. */ - abstract getUtxos(address: string, amount?: number): Promise; + abstract off(eventName: string, callBack: () => void): void; /** - * Retrieves the tip height of the BTC chain. - * @returns A promise that resolves to the block height. + * Gets the name of the wallet provider. + * @returns A promise that resolves to the name of the wallet provider. */ - abstract getBTCTipHeight(): Promise; + abstract getWalletProviderName(): Promise; /** - * Retrieves the inscriptions for the connected wallet. - * @returns A promise that resolves to an array of inscriptions. + * Gets the icon URL of the wallet provider. + * @returns A promise that resolves to the icon URL of the wallet provider. */ - abstract getInscriptions(): Promise; + abstract getWalletProviderIcon(): Promise; } diff --git a/src/core/wallets/btc/bitget/provider.ts b/src/core/wallets/btc/bitget/provider.ts index 76637c7..400e317 100644 --- a/src/core/wallets/btc/bitget/provider.ts +++ b/src/core/wallets/btc/bitget/provider.ts @@ -1,10 +1,12 @@ import { Psbt } from "bitcoinjs-lib"; -import type { BTCConfig, Fees, InscriptionIdentifier, UTXO, WalletInfo } from "@/core/types"; +import type { BTCConfig, InscriptionIdentifier, WalletInfo } from "@/core/types"; import { Network } from "@/core/types"; import { validateAddress } from "@/core/utils/wallet"; import { BTCProvider } from "@/core/wallets/btc/BTCProvider"; +import logo from "./logo.svg"; + const INTERNAL_NETWORK_NAMES = { [Network.MAINNET]: "livenet", [Network.TESTNET]: "testnet", @@ -55,10 +57,6 @@ export class BitgetProvider extends BTCProvider { } }; - getWalletProviderName = async (): Promise => { - return "Bitget"; - }; - getAddress = async (): Promise => { const accounts = (await this.provider.getAccounts()) || []; if (!accounts?.[0]) { @@ -140,16 +138,6 @@ export class BitgetProvider extends BTCProvider { } }; - signMessageBIP322 = async (message: string): Promise => { - if (!this.walletInfo) throw new Error("Bitget Wallet not connected"); - return await this.provider.signMessage(message, "bip322-simple"); - }; - - signMessage = async (message: string, type: "ecdsa" | "bip322-simple" = "ecdsa"): Promise => { - if (!this.walletInfo) throw new Error("Bitget Wallet not connected"); - return await this.provider.signMessage(message, type); - }; - getNetwork = async (): Promise => { const internalNetwork = await this.provider.getNetwork(); @@ -162,6 +150,16 @@ export class BitgetProvider extends BTCProvider { throw new Error("Unsupported network"); }; + signMessage = async (message: string, type: "ecdsa" | "bip322-simple" = "ecdsa"): Promise => { + if (!this.walletInfo) throw new Error("Bitget Wallet not connected"); + + return await this.provider.signMessage(message, type); + }; + + getInscriptions = async (): Promise => { + throw new Error("Method not implemented."); + }; + on = (eventName: string, callBack: () => void) => { if (!this.walletInfo) throw new Error("Bitget Wallet not connected"); @@ -182,28 +180,11 @@ export class BitgetProvider extends BTCProvider { return this.provider.off(eventName, callBack); }; - // Mempool calls - getBalance = async (): Promise => { - return await this.mempool.getAddressBalance(await this.getAddress()); - }; - - getNetworkFees = async (): Promise => { - return await this.mempool.getNetworkFees(); - }; - - pushTx = async (txHex: string): Promise => { - return await this.mempool.pushTx(txHex); - }; - - getUtxos = async (address: string, amount: number): Promise => { - return await this.mempool.getFundingUTXOs(address, amount); - }; - - getBTCTipHeight = async (): Promise => { - return await this.mempool.getTipHeight(); + getWalletProviderName = async (): Promise => { + return "Bitget"; }; - getInscriptions = async (): Promise => { - throw new Error("Method not implemented."); + getWalletProviderIcon = async (): Promise => { + return logo; }; } diff --git a/src/core/wallets/btc/cactus/provider.ts b/src/core/wallets/btc/cactus/provider.ts index ef2d495..90f3020 100644 --- a/src/core/wallets/btc/cactus/provider.ts +++ b/src/core/wallets/btc/cactus/provider.ts @@ -1,8 +1,10 @@ -import type { BTCConfig, Fees, InscriptionIdentifier, UTXO, WalletInfo } from "@/core/types"; +import type { BTCConfig, InscriptionIdentifier, WalletInfo } from "@/core/types"; import { Network } from "@/core/types"; import { validateAddress } from "@/core/utils/wallet"; import { BTCProvider } from "@/core/wallets/btc/BTCProvider"; +import logo from "./logo.svg"; + const INTERNAL_NETWORK_NAMES = { [Network.MAINNET]: "mainnet", [Network.TESTNET]: "testnet", @@ -55,17 +57,13 @@ export class CactusLinkProvider extends BTCProvider { } }; - getWalletProviderName = async (): Promise => { - return "Cactus Link"; - }; - - async getAddress(): Promise { + getAddress = async (): Promise => { const accounts = (await this.provider.getAccounts()) || []; if (!accounts?.[0]) { throw new Error("Cactus Link Wallet not connected"); } return accounts[0]; - } + }; getPublicKeyHex = async (): Promise => { const publicKey = await this.provider.getPublicKey(); @@ -97,16 +95,6 @@ export class CactusLinkProvider extends BTCProvider { return await this.provider.signPsbts(psbtsHexes, options); }; - signMessageBIP322 = async (message: string): Promise => { - if (!this.walletInfo) throw new Error("Cactus Link Wallet not connected"); - return await this.provider.signMessage(message, "bip322-simple"); - }; - - signMessage = async (message: string, type: "ecdsa" | "bip322-simple" = "ecdsa"): Promise => { - if (!this.walletInfo) throw new Error("Cactus Link Wallet not connected"); - return await this.provider.signMessage(message, type); - }; - getNetwork = async (): Promise => { const internalNetwork = await this.provider.getNetwork(); @@ -119,6 +107,17 @@ export class CactusLinkProvider extends BTCProvider { throw new Error("Unsupported network"); }; + signMessage = async (message: string, type: "ecdsa" | "bip322-simple" = "ecdsa"): Promise => { + if (!this.walletInfo) throw new Error("Cactus Link Wallet not connected"); + + return await this.provider.signMessage(message, type); + }; + + getInscriptions = async (): Promise => { + // Temporary solution to ignore inscriptions filtering for Cactus Link Wallet + return Promise.resolve([]); + }; + on = (eventName: string, callBack: () => void) => { if (!this.walletInfo) throw new Error("Cactus Link Wallet not connected"); @@ -139,29 +138,11 @@ export class CactusLinkProvider extends BTCProvider { return this.provider.off(eventName, callBack); }; - // Mempool calls - getBalance = async (): Promise => { - return await this.mempool.getAddressBalance(await this.getAddress()); - }; - - getNetworkFees = async (): Promise => { - return await this.mempool.getNetworkFees(); - }; - - pushTx = async (txHex: string): Promise => { - return await this.mempool.pushTx(txHex); - }; - - getUtxos = async (address: string, amount: number): Promise => { - return await this.mempool.getFundingUTXOs(address, amount); - }; - - getBTCTipHeight = async (): Promise => { - return await this.mempool.getTipHeight(); + getWalletProviderName = async (): Promise => { + return "Cactus Link"; }; - getInscriptions = async (): Promise => { - // Temporary solution to ignore inscriptions filtering for Cactus Link Wallet - return Promise.resolve([]); + getWalletProviderIcon = async (): Promise => { + return logo; }; } diff --git a/src/core/wallets/btc/keystone/provider.ts b/src/core/wallets/btc/keystone/provider.ts index 14078c1..b62993b 100644 --- a/src/core/wallets/btc/keystone/provider.ts +++ b/src/core/wallets/btc/keystone/provider.ts @@ -8,12 +8,14 @@ import { tapleafHash } from "bitcoinjs-lib/src/payments/bip341"; import { toXOnly } from "bitcoinjs-lib/src/psbt/bip371"; import { pubkeyInScript } from "bitcoinjs-lib/src/psbt/psbtutils"; -import type { BTCConfig, Fees, InscriptionIdentifier, UTXO } from "@/core/types"; +import type { BTCConfig, InscriptionIdentifier } from "@/core/types"; import { Network } from "@/core/types"; import BIP322 from "@/core/utils/bip322"; import { toNetwork } from "@/core/utils/wallet"; import { BTCProvider } from "@/core/wallets/btc/BTCProvider"; +import logo from "./logo.svg"; + initEccLib(ecc); type KeystoneWalletInfo = { @@ -107,10 +109,6 @@ export class KeystoneProvider extends BTCProvider { this.keystoneWaleltInfo.scriptPubKeyHex = scriptPubKeyHex; }; - getWalletProviderName = async (): Promise => { - return "Keystone"; - }; - getAddress = async (): Promise => { if (!this.keystoneWaleltInfo?.address) throw new Error("Could not retrieve the address"); @@ -196,6 +194,22 @@ export class KeystoneProvider extends BTCProvider { return ""; }; + getInscriptions = async (): Promise => { + throw new Error("Method not implemented."); + }; + + // Not implemented because of the Airgapped HW nature + on = (): void => {}; + off = (): void => {}; + + getWalletProviderName = async (): Promise => { + return "Keystone"; + }; + + getWalletProviderIcon = async (): Promise => { + return logo; + }; + /** * Sign the PSBT with the Keystone device. * @@ -255,35 +269,6 @@ export class KeystoneProvider extends BTCProvider { }); return psbt; }; - - // Not implemented because of the Airgapped HW nature - on = (): void => {}; - off = (): void => {}; - - // Mempool calls - getBalance = async (): Promise => { - return await this.mempool.getAddressBalance(await this.getAddress()); - }; - - getNetworkFees = async (): Promise => { - return await this.mempool.getNetworkFees(); - }; - - pushTx = async (txHex: string): Promise => { - return await this.mempool.pushTx(txHex); - }; - - getUtxos = async (address: string, amount: number): Promise => { - return await this.mempool.getFundingUTXOs(address, amount); - }; - - getBTCTipHeight = async (): Promise => { - return await this.mempool.getTipHeight(); - }; - - getInscriptions(): Promise { - throw new Error("Method not implemented."); - } } /** diff --git a/src/core/wallets/btc/okx/provider.ts b/src/core/wallets/btc/okx/provider.ts index 0b9e356..b07e3cb 100644 --- a/src/core/wallets/btc/okx/provider.ts +++ b/src/core/wallets/btc/okx/provider.ts @@ -1,8 +1,10 @@ -import type { BTCConfig, Fees, InscriptionIdentifier, UTXO, WalletInfo } from "@/core/types"; +import type { BTCConfig, InscriptionIdentifier, WalletInfo } from "@/core/types"; import { Network } from "@/core/types"; import { validateAddress } from "@/core/utils/wallet"; import { BTCProvider } from "@/core/wallets/btc/BTCProvider"; +import logo from "./logo.svg"; + const PROVIDER_NAMES = { [Network.MAINNET]: "bitcoin", [Network.TESTNET]: "bitcoinTestnet", @@ -65,113 +67,51 @@ export class OKXProvider extends BTCProvider { } }; - getWalletProviderName = async (): Promise => { - return "OKX"; - }; - getAddress = async (): Promise => { - if (!this.walletInfo) { - throw new Error("OKX Wallet not connected"); - } + if (!this.walletInfo) throw new Error("OKX Wallet not connected"); + return this.walletInfo.address; }; getPublicKeyHex = async (): Promise => { - if (!this.walletInfo) { - throw new Error("OKX Wallet not connected"); - } + if (!this.walletInfo) throw new Error("OKX Wallet not connected"); + return this.walletInfo.publicKeyHex; }; signPsbt = async (psbtHex: string): Promise => { - if (!this.walletInfo) { - throw new Error("OKX Wallet not connected"); - } - // Use signPsbt since it shows the fees + if (!this.walletInfo) throw new Error("OKX Wallet not connected"); + return await this.provider.signPsbt(psbtHex); }; signPsbts = async (psbtsHexes: string[]): Promise => { - if (!this.walletInfo) { - throw new Error("OKX Wallet not connected"); - } - // sign the PSBTs - return await this.provider.signPsbts(psbtsHexes); - }; + if (!this.walletInfo) throw new Error("OKX Wallet not connected"); - signMessageBIP322 = async (message: string): Promise => { - if (!this.walletInfo) { - throw new Error("OKX Wallet not connected"); - } - return await this.provider.signMessage(message, "bip322-simple"); + return await this.provider.signPsbts(psbtsHexes); }; - async signMessage(message: string, type: "ecdsa" | "bip322-simple" = "ecdsa"): Promise { - if (!this.walletInfo) { - throw new Error("OKX Wallet not connected"); - } - return await this.provider.signMessage(message, type); - } - getNetwork = async (): Promise => { // OKX does not provide a way to get the network for Signet and Testnet // So we pass the check on connection and return the environment network - if (!this.config.network) { - throw new Error("Network not set"); - } - return this.config.network; - }; - - on = (eventName: string, callBack: () => void) => { - if (!this.walletInfo) { - throw new Error("OKX Wallet not connected"); - } - // subscribe to account change event - if (eventName === "accountChanged") { - return this.provider.on(eventName, callBack); - } - }; - - off = (eventName: string, callBack: () => void) => { - if (!this.walletInfo) { - throw new Error("OKX Wallet not connected"); - } - // subscribe to account change event - if (eventName === "accountChanged") { - return this.provider.off(eventName, callBack); - } - }; + if (!this.config.network) throw new Error("Network not set"); - // Mempool calls - getBalance = async (): Promise => { - return await this.mempool.getAddressBalance(await this.getAddress()); - }; - - getNetworkFees = async (): Promise => { - return await this.mempool.getNetworkFees(); - }; - - pushTx = async (txHex: string): Promise => { - return await this.mempool.pushTx(txHex); + return this.config.network; }; - getUtxos = async (address: string, amount: number): Promise => { - // mempool call - return await this.mempool.getFundingUTXOs(address, amount); - }; + signMessage = async (message: string, type: "ecdsa" | "bip322-simple" = "ecdsa"): Promise => { + if (!this.walletInfo) throw new Error("OKX Wallet not connected"); - getBTCTipHeight = async (): Promise => { - return await this.mempool.getTipHeight(); + return await this.provider.signMessage(message, type); }; // Inscriptions are only available on OKX Wallet BTC mainnet (i.e okxWallet.bitcoin) getInscriptions = async (): Promise => { - if (!this.walletInfo) { - throw new Error("OKX Wallet not connected"); - } + if (!this.walletInfo) throw new Error("OKX Wallet not connected"); if (this.config.network !== Network.MAINNET) { throw new Error("Inscriptions are only available on OKX Wallet BTC mainnet"); } + // max num of iterations to prevent infinite loop const MAX_ITERATIONS = 100; // Fetch inscriptions in batches of 100 @@ -205,4 +145,30 @@ export class OKXProvider extends BTCProvider { return inscriptionIdentifiers; }; + + on = (eventName: string, callBack: () => void) => { + if (!this.walletInfo) throw new Error("OKX Wallet not connected"); + + // subscribe to account change event + if (eventName === "accountChanged") { + return this.provider.on(eventName, callBack); + } + }; + + off = (eventName: string, callBack: () => void) => { + if (!this.walletInfo) throw new Error("OKX Wallet not connected"); + + // subscribe to account change event + if (eventName === "accountChanged") { + return this.provider.off(eventName, callBack); + } + }; + + getWalletProviderName = async (): Promise => { + return "OKX"; + }; + + getWalletProviderIcon = async (): Promise => { + return logo; + }; } diff --git a/src/core/wallets/btc/onekey/provider.ts b/src/core/wallets/btc/onekey/provider.ts index c07f1c2..88452c2 100644 --- a/src/core/wallets/btc/onekey/provider.ts +++ b/src/core/wallets/btc/onekey/provider.ts @@ -1,8 +1,10 @@ -import type { BTCConfig, Fees, InscriptionIdentifier, UTXO, WalletInfo } from "@/core/types"; +import type { BTCConfig, InscriptionIdentifier, WalletInfo } from "@/core/types"; import { Network } from "@/core/types"; import { validateAddress } from "@/core/utils/wallet"; import { BTCProvider } from "@/core/wallets/btc/BTCProvider"; +import logo from "./logo.svg"; + const INTERNAL_NETWORK_NAMES = { [Network.MAINNET]: "livenet", [Network.TESTNET]: "testnet", @@ -50,10 +52,6 @@ export class OneKeyProvider extends BTCProvider { } }; - getWalletProviderName = async (): Promise => { - return "OneKey"; - }; - getAddress = async (): Promise => { if (!this.walletInfo) throw new Error("OneKey Wallet not connected"); @@ -96,59 +94,12 @@ export class OneKeyProvider extends BTCProvider { throw new Error("Unsupported network"); }; - signMessageBIP322 = async (message: string): Promise => { - if (!this.walletInfo) throw new Error("OneKey Wallet not connected"); - - return await this.provider.signMessageBIP322(message); - }; - signMessage = async (message: string, type: "ecdsa" | "bip322-simple" = "ecdsa"): Promise => { if (!this.walletInfo) throw new Error("OneKey Wallet not connected"); return await this.provider.signMessage(message, type); }; - on = (eventName: string, callBack: () => void) => { - if (!this.walletInfo) throw new Error("OneKey Wallet not connected"); - - // subscribe to account change event: `accountChanged` -> `accountsChanged` - if (eventName === "accountChanged") { - return this.provider.on("accountsChanged", callBack); - } - return this.provider.on(eventName, callBack); - }; - - off = (eventName: string, callBack: () => void) => { - if (!this.walletInfo) throw new Error("OneKey Wallet not connected"); - - // unsubscribe to account change event - if (eventName === "accountChanged") { - return this.provider.off("accountsChanged", callBack); - } - return this.provider.off(eventName, callBack); - }; - - // Mempool calls - getBalance = async (): Promise => { - return await this.mempool.getAddressBalance(await this.getAddress()); - }; - - getNetworkFees = async (): Promise => { - return await this.mempool.getNetworkFees(); - }; - - pushTx = async (txHex: string): Promise => { - return await this.mempool.pushTx(txHex); - }; - - getUtxos = async (address: string, amount: number): Promise => { - return await this.mempool.getFundingUTXOs(address, amount); - }; - - getBTCTipHeight = async (): Promise => { - return await this.mempool.getTipHeight(); - }; - // Inscriptions are only available on OneKey Wallet BTC mainnet getInscriptions = async (): Promise => { if (!this.walletInfo) throw new Error("OneKey Wallet not connected"); @@ -189,4 +140,32 @@ export class OneKeyProvider extends BTCProvider { return inscriptionIdentifiers; }; + + on = (eventName: string, callBack: () => void) => { + if (!this.walletInfo) throw new Error("OneKey Wallet not connected"); + + // subscribe to account change event: `accountChanged` -> `accountsChanged` + if (eventName === "accountChanged") { + return this.provider.on("accountsChanged", callBack); + } + return this.provider.on(eventName, callBack); + }; + + off = (eventName: string, callBack: () => void) => { + if (!this.walletInfo) throw new Error("OneKey Wallet not connected"); + + // unsubscribe to account change event + if (eventName === "accountChanged") { + return this.provider.off("accountsChanged", callBack); + } + return this.provider.off(eventName, callBack); + }; + + getWalletProviderName = async (): Promise => { + return "OneKey"; + }; + + getWalletProviderIcon = async (): Promise => { + return logo; + }; }