import { Env, JsonRpcMethod, Network, unsupportedChainError } from '@haechi-labs/face-types'; import { isSupportedNetwork } from '@haechi-labs/shared'; import { Auth } from './Auth'; import { Bora } from './blockchain/Bora'; import { Internal } from './Internal'; import { Provider } from './Provider'; import { getValidNetwork } from './utils/network'; import { Wallet } from './Wallet'; export { Network }; export interface FaceConfig { apiKey: string; network: Network | number; scheme: string; } /** * Face SDK * * @category API * * @class * @name Face * @param {object} config - Config. * @param {string} config.apiKey - Api key. * @param {string} config.network - Blockchain Network such as Sepolia, Mumbai, Ethereum etc. */ export class Face { private config: any; private readonly internal: Internal; public auth: Auth; public wallet: Wallet; public bora: Bora; // public wc: WalletConnect; // public solana: Solana; // public near: Near; constructor(config: FaceConfig) { this.config = config; const { apiKey, network, scheme, ...rest } = config; const _network = getValidNetwork(network); if (!isSupportedNetwork(_network, ['react-native'])) { throw unsupportedChainError(); } this.internal = new Internal({ apiKey, network: _network, scheme, env: (rest as { env?: Env }).env, iframeUrl: (rest as { iframeUrl?: string }).iframeUrl, face: this, }); /** @member {Auth} */ this.auth = new Auth(this.internal); /** @member {Wallet} */ this.wallet = new Wallet(this.internal); this.bora = new Bora(this.internal, this.auth); // this.wc = new WalletConnect(this.internal); // this.near = new Near(this.internal); // this.solana = new Solana(this.internal); } /** * Return provider for the EVM blockchain provider * * @method */ getEthLikeProvider(): Provider { return new Provider(this.internal); } /** * Return the wallet address array * * @method * @returns {Promise} */ getAddresses = async (): Promise => { return await this.internal.getAddresses(); }; /** * Return the set network * * @method * @returns {Network} */ getNetwork = (): Network => { return this.internal.getNetwork(); }; /** * Return the chain id of current network * * @method * @returns {Promise} */ getChainId = async (): Promise => { return Number(await this.internal.sendRpc({ method: JsonRpcMethod.eth_chainId, params: [] })); }; /** * Switch network * * @method * @returns {Promise} */ async switchNetwork(network: Network | number | string) { return await this.internal.switchNetwork(network); } }