@keyban/sdk-base
Version:
Keyban Javascript SDK provides core functionalities for the MPC wallet solution, supporting web and Node.js apps with TypeScript, custom storage, and Ethereum blockchain integration.
1 lines • 48.6 kB
Source Map (JSON)
{"version":3,"sources":["../src/account.ts","../src/apollo.ts","../src/client.ts","../src/clientShareProvider.ts","../src/network.ts","../src/utils/formatBalance.ts"],"names":["KeybanAccount","rpcClient","dppId","createApolloClient","apiUrl","accessTokenProvider","authLink","setContext","_","headers","token","httpLink","createHttpLink","wsUrl","wsLink","GraphQLWsLink","createClient","transportLink","split","query","definition","getMainDefinition","ApolloClient","InMemoryCache","relayStylePagination","date","ApolloLink","KeybanClientBase","config","metadataConfig","KeybanClientShareProvider","indexerPrefix","metadataUrl","res","RpcClient","err","input","connection","loginUrl","width","height","left","top","popup","authenticatedPromise","resolve","handler","event","interval","logoutUrl","KeybanClient","#client","#pendingAccounts","KeybanEvmClient","StarknetClient","StellarClient","key","pending","promise","client","#rpcClient","clientShare","KeybanNetwork","formatBalance","balance","decimals","symbol","fmt","formatUnits"],"mappings":"2aA8EO,IAAeA,CAAAA,CAAf,KAA6B,CAWxB,SAAA,CAOV,YAAYC,CAAAA,CAAsB,CAChC,IAAA,CAAK,SAAA,CAAYA,EACnB,CAuKA,MAAM,QAAA,CAASC,EAAe,CAC5B,OAAO,IAAA,CAAK,SAAA,CAAU,IAAA,CAAK,KAAA,CAAO,OAAA,CAASA,CAAAA,CAAO,KAAK,OAAO,CAChE,CASA,MAAM,YAAA,EAA8B,CAGlC,OAAO,OAAA,CAAQ,SACjB,CAOA,MAAM,cAAA,EAAgC,CAGpC,OAAO,OAAA,CAAQ,OAAA,EACjB,CACF,EC9QO,SAASC,CAAAA,CACdC,EACAC,CAAAA,CACA,CACA,IAAMC,CAAAA,CAAWC,UAAAA,CAAW,MAAOC,CAAAA,CAAG,CAAE,QAAAC,CAAQ,CAAA,GAAM,CACpD,IAAMC,CAAAA,CAAQ,MAAML,CAAAA,IAAsB,CAE1C,OAAO,CACL,OAAA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A,iBAAA,CAAoB,oBAKpBA,CAAAA,CAAA,cAAA,CAAiB,gBAAA,CAKjBA,CAAAA,CAAA,eAAiB,gBAAA,CA3CPA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,EC8CL,SAASC,EACdJ,CAAAA,CACAK,CAAAA,CACAtD,CAAAA,CACQ,CACR,IAAIuD,CAAAA,CAAWD,CAAAA,CAAQ,QAAA,CACnBE,EAASF,CAAAA,CAAQ,MAAA,CACjBA,CAAAA,CAAQ,MAAA,EACVC,CAAAA,CAAWN,CAAAA,CAAO,QAAA,CAAS,QAAA,CAC3BO,EAASP,CAAAA,CAAO,QAAA,CAAS,MAAA,EAChBK,CAAAA,CAAQ,UACjBC,CAAAA,CAAWN,CAAAA,CAAO,cAAA,CAAe,QAAA,CACjCO,EAASP,CAAAA,CAAO,cAAA,CAAe,MAAA,EACtBjD,CAAAA,GACTuD,CAAAA,CAAWvD,CAAAA,CAAM,QAAA,EAAY,MAAA,CAC7BwD,EAASxD,CAAAA,CAAM,MAAA,EAAU,MAAA,CAAA,CAE3BuD,CAAAA,CAAWA,CAAAA,EAAY,CAAA,CAEvB,IAAME,CAAAA,CAAMC,YACV,OAAOJ,CAAAA,CAAQ,GAAA,EAAQ,QAAA,CAAWA,CAAAA,CAAQ,GAAA,CAAM,MAAA,CAAOA,CAAAA,CAAQ,GAAG,CAAA,CAClEC,CACF,CAAA,CACA,OAAOC,EAAS,CAAA,EAAGC,CAAG,CAAA,CAAA,EAAID,CAAM,GAAKC,CACvC","file":"chunk-UGMWAWZZ.mjs","sourcesContent":["/**\n * @module Account\n */\n\nimport type { Address, Hash, Hex } from \"~/index\";\nimport { RpcClient } from \"~/rpc\";\n\nimport { EvmFeeDetails } from \"./evm/account\";\nimport { StellarFeeDetails } from \"./stellar/account\";\n\nexport type FeeDetails = EvmFeeDetails | StellarFeeDetails;\n/**\n * Represents the estimation of fees for a transaction.\n * @see {@link KeybanAccount#estimateTransfer}\n */\nexport type FeesEstimation = {\n /**\n * The total maximum fees for the transaction.\n */\n maxFees: bigint;\n\n details: FeeDetails;\n};\n\n/**\n * Represents the parameters for transferring ERC20 tokens.\n * @property {Address} contractAddress - The address of the ERC20 token contract\n * @property {Address} to - The recipient's address\n * @property {bigint} value - The transfer amount in the smallest token unit\n * @property {FeeDetails} fees - The transaction fees details\n * @see {@link KeybanAccount#transferERC20}\n */\nexport type TransferERC20Params<TFeeDetails = FeeDetails> = {\n contractAddress: Address;\n to: Address;\n value: bigint;\n fees?: TFeeDetails;\n};\n\n/**\n * Represents the parameters for transferring ERC721 and ERC1155 tokens.\n * @property {Address} contractAddress - The address of the NFT contract\n * @property {bigint} tokenId - The ID of the token\n * @property {Address} to - The recipient's address\n * @property {bigint} value - The transfer amount (for ERC1155 tokens)\n * @property {FeeDetails} fees - The transaction fees details\n * @property {string} standard - The token standard (ERC721 or ERC1155)\n * @see {@link KeybanAccount#transferNft}\n */\nexport type TransferNftParams<TFeeDetails = FeeDetails> = {\n contractAddress: Address;\n tokenId: bigint;\n to: Address;\n value?: bigint;\n standard: \"ERC721\" | \"ERC1155\";\n fees?: TFeeDetails;\n};\n\n/**\n * Represents the parameters required to estimate an ERC20 token transfer,\n * excluding the fee details.\n *\n * This type is derived from `TransferERC20Params` by omitting the `fees` property.\n */\nexport type EstimateERC20TransferParams = Omit<TransferERC20Params, \"fees\">;\n/**\n * Parameters required to estimate the transfer of an NFT, excluding the fee details.\n *\n * This type is derived from `TransferNftParams` by omitting the `fees` property.\n * @see {@link TransferNftParams}\n */\nexport type EstimateNftTransferParams = Omit<TransferNftParams, \"fees\">;\n\n/**\n * A `KeybanAccount` represents a user's account in the Keyban system.\n * It provides methods to interact with the blockchain, including signing messages,\n * fetching balances, transferring tokens, and estimating transaction costs.\n */\nexport abstract class KeybanAccount {\n /**\n * The blockchain address associated with the account.\n */\n abstract address: Address;\n\n /**\n * The public key associated with the account.\n */\n abstract publicKey: string;\n\n protected rpcClient: RpcClient;\n\n /**\n * KeybanAccount constructor\n * @param rpcClient - the keyban rpc client\n * @private\n */\n constructor(rpcClient: RpcClient) {\n this.rpcClient = rpcClient;\n }\n\n /**\n * Signs an Ethereum message.\n * @param message - The message to be signed.\n * @returns - The signed message as a hex string.\n * @throws {Error} If the message is empty or there is an issue during signing.\n */\n abstract signMessage(message: string): Promise<Hex | string | string[]>;\n\n /**\n * Signs a transaction hash.\n * @param txHash - The transaction hash to be signed in hex string format.\n * @returns - The signed transaction as a hex string or an array of hex strings.\n * @throws {Error} If the transaction hash is invalid or there is an issue during signing.\n * @internal\n */\n abstract signTransaction(txHash: string): Promise<Hex | string | string[]>;\n\n /**\n * Transfers native tokens to another address.\n * @param to - The recipient's address.\n * @param value - The transfer amount in wei (must be greater than 0).\n * @param fees - Optional transaction fees.\n * @returns - A promise that resolves to the transaction hash.\n * @throws {SdkError} If the recipient's address is invalid or the transfer amount is invalid.\n * @example\n * ```ts\n * const handleTransfer = async () => {\n * // amount, account, recipient, setTransactionHash are state variables\n * try {\n * const valueInWei = BigInt(Number(amount) * 1e18);\n * const txHash = await account.transfer(recipient as Address, valueInWei);\n * setTransactionHash(txHash);\n * } catch (err) {\n * console.log(err);\n * }\n * };\n * ```\n */\n abstract transfer(\n to: Address,\n value: bigint,\n fees?: FeeDetails,\n ): Promise<Hash | string>;\n\n /**\n * Estimates the cost of transferring native tokens to another address.\n * @param to - The recipient's address.\n * @returns - A promise that resolves to a `FeesEstimation` object containing the fee details.\n * @throws {Error} If there is an issue with estimating the gas or fees.\n */\n abstract estimateTransfer(to: Address): Promise<FeesEstimation>;\n\n /**\n * Transfers ERC20 tokens to another address.\n * @param params - The parameters for the ERC20 transfer.\n * @returns - A promise that resolves to the transaction hash.\n * @throws {SdkError} If the recipient's address is invalid, the contract address is invalid, or the transfer amount is invalid.\n * @example\n * ```ts\n * const handleTransfer = async () => {\n * // amount, account, recipient, contractAddress, setTransactionHash are state variables\n * try {\n * const valueInWei = BigInt(Number(amount) * 1e18);\n * const txHash = await account.transferERC20({\n * contractAddress: contractAddress as Address,\n * to: recipient as Address,\n * value: valueInWei,\n * });\n * setTransactionHash(txHash);\n * } catch (err) {\n * console.log(err);\n * }\n * };\n * ```\n */\n abstract transferERC20(params: TransferERC20Params): Promise<Hash | string>;\n\n /**\n * Estimates the cost of transferring ERC20 tokens to another address.\n * @param params - The parameters for estimating the ERC20 transfer.\n * @returns - A promise that resolves to a `FeesEstimation` object containing the fee details.\n * @throws {Error} If there is an issue with estimating the gas or fees.\n * @example\n * ```ts\n * const handleEstimate = async () => {\n * // account, recipient, contractAddress, amount, setTransferCost are state variables\n * try {\n * const valueInWei = BigInt(Number(amount) * 1e18);\n * const estimation = await account.estimateTransferERC20({\n * contractAddress: contractAddress as Address,\n * to: recipient as Address,\n * value: valueInWei,\n * });\n * setTransferCost(estimation.maxFees.toString());\n * } catch (err) {\n * console.log(err);\n * }\n * };\n * ```\n */\n abstract estimateERC20Transfer(\n params: EstimateERC20TransferParams,\n ): Promise<FeesEstimation>;\n\n /**\n * Transfers ERC721 and ERC1155 tokens to another address.\n * @param params - The parameters for the NFT transfer.\n * @returns - A promise that resolves to the transaction hash.\n * @throws {SdkError} If the recipient's address is invalid, the contract address is invalid, the transfer amount is invalid, or the token standard is invalid.\n * @example\n * ```ts\n * const handleTransfer = async () => {\n * // account, recipient, contractAddress, tokenId, amount, standard, setTransactionHash are state variables\n * try {\n * const value = BigInt(amount);\n * const txHash = await account.transferNft({\n * contractAddress: contractAddress as Address,\n * tokenId: tokenId as bigint,\n * to: recipient as Address,\n * value: value,\n * standard: standard as 'ERC721' | 'ERC1155',\n * });\n * setTransactionHash(txHash);\n * } catch (err) {\n * console.log(err);\n * }\n * };\n * ```\n */\n abstract transferNft(params: TransferNftParams): Promise<Hash>;\n\n /**\n * Estimates the cost of transferring ERC721 and ERC1155 tokens to another address.\n * @param params - The parameters for estimating the NFT transfer.\n * @returns - A promise that resolves to a `FeesEstimation` object containing the fee details.\n * @throws {Error} If there is an issue with estimating the gas or fees.\n * @example\n * ```ts\n * const handleEstimate = async () => {\n * // account, recipient, contractAddress, tokenId, amount, standard, setTransferCost are state variables\n * try {\n * const value = BigInt(amount);\n * const estimation = await account.estimateNftTransfer({\n * contractAddress: contractAddress as Address,\n * tokenId: tokenId as bigint,\n * to: recipient as Address,\n * value: value,\n * standard: standard as 'ERC721' | 'ERC1155',\n * });\n * setTransferCost(estimation.maxFees.toString());\n * } catch (err) {\n * console.log(err);\n * }\n * };\n * ```\n */\n abstract estimateNftTransfer(\n params: EstimateNftTransferParams,\n ): Promise<FeesEstimation>;\n\n /**\n * Claims a DPP for a given recipient.\n * @param dppId - The identifier of the Tokenized Product Passport (DPP) to claim.\n * @returns A promise that resolves with the result of the RPC call.\n */\n async dppClaim(dppId: string) {\n return this.rpcClient.call(\"dpp\", \"claim\", dppId, this.address);\n }\n\n /**\n * Sets up the account for the loyalty application.\n * This method signs a setup transaction and submits it to the network.\n * It makes the account ready to be used with the loyalty application.\n * It depends on the blockchain network.\n * @returns A promise that resolves when the setup is complete.\n */\n async loyaltySetup(): Promise<void> {\n // By default, this method does nothing.\n // Subclasses can override this method to provide specific implementation.\n return Promise.resolve();\n }\n\n /**\n * Destroys the loyalty setup for the account.\n * @internal\n * @returns A promise that resolves when the loyalty setup is destroyed.\n */\n async loyaltyDestroy(): Promise<void> {\n // By default, this method does nothing.\n // Subclasses can override this method to provide specific implementation.\n return Promise.resolve();\n }\n}\n","import { InMemoryCache } from \"@apollo/client/cache\";\nimport {\n ApolloClient,\n ApolloLink,\n createHttpLink,\n split,\n} from \"@apollo/client/core\";\nimport { setContext } from \"@apollo/client/link/context\";\nimport { GraphQLWsLink } from \"@apollo/client/link/subscriptions\";\nimport {\n getMainDefinition,\n relayStylePagination,\n} from \"@apollo/client/utilities\";\nimport { createClient } from \"graphql-ws\";\n\n/**\n * Creates an Apollo Client instance.\n * @param apiUrl - The API URL.\n * @param accessTokenProvider - Optional function to provide access token.\n * @returns - The Apollo Client instance.\n * @private\n */\nexport function createApolloClient(\n apiUrl: URL,\n accessTokenProvider?: () => string | Promise<string>,\n) {\n const authLink = setContext(async (_, { headers }) => {\n const token = await accessTokenProvider?.();\n\n return {\n headers: {\n ...headers,\n authorization: token ? `Bearer ${token}` : \"\",\n },\n };\n });\n\n const httpLink = createHttpLink({ uri: apiUrl.toString() });\n\n const wsUrl = new URL(apiUrl);\n wsUrl.protocol = \"wss\";\n const wsLink = new GraphQLWsLink(createClient({ url: wsUrl.toString() }));\n\n const transportLink = split(\n ({ query }) => {\n const definition = getMainDefinition(query);\n return (\n definition.kind === \"OperationDefinition\" &&\n definition.operation === \"subscription\"\n );\n },\n wsLink,\n httpLink,\n );\n\n return new ApolloClient({\n connectToDevTools: true,\n defaultOptions: {\n query: { fetchPolicy: \"network-only\" },\n watchQuery: { fetchPolicy: \"cache-and-network\" },\n },\n cache: new InMemoryCache({\n typePolicies: {\n Query: {\n fields: {\n tokenBalances: relayStylePagination([\"filter\"]),\n nftBalances: relayStylePagination([\"filter\"]),\n assetTransfers: relayStylePagination([\"filter\"]),\n orders: relayStylePagination([\"filter\"]),\n },\n },\n Transaction: {\n fields: {\n date: {\n read(date) {\n return date ? date + \"Z\" : date;\n },\n },\n },\n },\n },\n }),\n link: ApolloLink.from([authLink, transportLink]),\n });\n}\n","/**\n * @module Client\n */\nimport type { NormalizedCacheObject } from \"@apollo/client/cache\";\nimport type { ApolloClient } from \"@apollo/client/core\";\n\nimport { KeybanAccount } from \"~/account\";\nimport type { KeybanApiStatus } from \"~/api\";\nimport { createApolloClient } from \"~/apollo\";\nimport {\n AuthConnection,\n KeybanClientShareProvider,\n KeybanNetwork,\n} from \"~/index\";\nimport { type FeesUnit, NativeCurrency } from \"~/network\";\nimport {\n PasswordlessLoginInput,\n PasswordlessStartInput,\n PasswordLoginInput,\n RpcClient,\n} from \"~/rpc\";\n\n/**\n * Represents a storage provider for the client share.\n *\n * The purpose of `ClientShareProvider` is to provide an interface that allows integrators\n * to save and restore the client share of their customers. The integrator has the\n * responsibility to securely store the client share.\n * @remarks\n * The client share is not considered sensitive data because only the client\n * can use it, and its usage is secured by strong authentication between the client\n * and the Keyban services.\n *\n * ### Example Implementation\n *\n * Below is a basic implementation of a `CustomClientShareProvider` using a fetch-based provider:\n *\n * ```typescript\n * class CustomClientShareProvider implements ClientShareProvider {\n * // Retrieves the client share data.\n * // @returns - A promise resolving to the client share string or `null` if unavailable.\n * async get(): Promise<string | null> {\n * try {\n * const response = await fetch(\"/api/clientShare\", {\n * method: \"GET\",\n * headers: { \"Content-Type\": \"application/json\" },\n * });\n *\n * if (!response.ok) {\n * console.error(\"Failed to fetch client share:\", response.statusText);\n * return null;\n * }\n *\n * return response.text();\n * } catch (error) {\n * console.error(\"Error retrieving client share:\", error);\n * return null;\n * }\n * }\n *\n *\n * // Saves the client share data.\n * // @param clientShare - The client share string to store.\n * // @returns - A promise that resolves when the operation is complete.\n * async set(clientShare: string): Promise<void> {\n * try {\n * const response = await fetch(\"/api/clientShare\", {\n * method: \"POST\",\n * headers: { \"Content-Type\": \"application/json\" },\n * body: JSON.stringify({ clientShare }),\n * });\n *\n * if (!response.ok) {\n * throw new Error(`Failed to save client share: ${response.statusText}`);\n * }\n * } catch (error) {\n * console.error(\"Error saving client share:\", error);\n * throw error;\n * }\n * }\n * }\n * ```\n *\n * This implementation assumes the existence of an API endpoint `/api/clientShare`\n * to manage the client share on the server side. The integrator should ensure that\n * the endpoint is appropriately secured.\n */\nexport interface ClientShareProvider {\n /**\n * Retrieves the client share information.\n * @param key - The key associated with the client share.\n * @returns - A promise that resolves to a string containing the client share, or null if not available.\n */\n get(key: string): Promise<string | null>;\n /**\n * Sets the client share information.\n * @param key - The key associated with the client share.\n * @param clientShare - The client share string to set.\n * @returns - A promise that resolves when the client share has been set.\n */\n set(key: string, clientShare: string): Promise<unknown>;\n}\n\n/**\n * Configuration options for initializing the Keyban client.\n */\nexport type KeybanClientConfig = {\n /**\n * The base URL of the API. Optional. Defaults to \"https://api.prod.keyban.io\" if not provided.\n */\n apiUrl?: URL | string;\n\n /**\n * The application ID.\n */\n appId: string;\n\n /**\n * The blockchain configuration for Keyban.\n */\n network: KeybanNetwork;\n\n /**\n * The client share provider.\n */\n clientShareProvider: ClientShareProvider;\n};\n\nexport type MetadataConfig = {\n network: { rpcUrl: string; indexerUrl: string; horizonUrl?: string };\n auth: { domain: string; clientId: string };\n};\n\nexport abstract class KeybanClientBase {\n /**\n * The Keyban API URL, defaulting to \"https://api.prod.keyban.io\".\n */\n apiUrl: URL;\n\n /**\n * The application ID used for authentication with the Keyban API.\n */\n appId: string;\n\n /**\n * The blockchain used by Keyban.\n */\n network: KeybanNetwork;\n\n /**\n * The Apollo GraphQL client used for making API requests.\n */\n apolloClient: ApolloClient<NormalizedCacheObject>;\n\n protected clientShareProvider: ClientShareProvider;\n protected metadataConfig: Promise<MetadataConfig>;\n\n constructor(\n config: KeybanClientConfig,\n metadataConfig?: Promise<MetadataConfig>,\n ) {\n this.apiUrl = new URL(config.apiUrl ?? \"https://api.prod.keyban.io\");\n this.appId = config.appId;\n this.network = config.network;\n\n this.clientShareProvider = config.clientShareProvider;\n if (this.clientShareProvider instanceof KeybanClientShareProvider)\n this.clientShareProvider.registerClient(this);\n\n const indexerPrefix = {\n [KeybanNetwork.EthereumAnvil]: \"subql-ethereum-anvil.\",\n [KeybanNetwork.PolygonAmoy]: \"subql-polygon-amoy.\",\n [KeybanNetwork.StarknetDevnet]: \"subql-starknet-devnet.\",\n [KeybanNetwork.StarknetSepolia]: \"subql-starknet-sepolia.\",\n [KeybanNetwork.StarknetMainnet]: \"subql-starknet-mainnet.\",\n [KeybanNetwork.StellarQuickstart]: \"subql-stellar-quickstart.\",\n [KeybanNetwork.StellarTestnet]: \"subql-stellar-testnet.\",\n [KeybanNetwork.StellarMainnet]: \"subql-stellar-mainnet.\",\n }[this.network];\n this.apolloClient = createApolloClient(\n new URL(this.apiUrl.origin.replace(\"api.\", indexerPrefix)),\n );\n\n const metadataUrl = new URL(`/v1/metadata`, this.apiUrl);\n metadataUrl.searchParams.set(\"network\", this.network);\n this.metadataConfig =\n metadataConfig ?? fetch(metadataUrl).then((res) => res.json());\n }\n\n protected get rpcClient() {\n return RpcClient.getInstance(this);\n }\n\n /**\n * Retrieves the native currency details associated with the current chain.\n *\n * This getter returns an object that includes the native currency's name, symbol, and decimal precision for the respective blockchain\n * as defined by the `this.chain` property. Each blockchain in the supported list (e.g., EthereumAnvil, PolygonAmoy, StarknetDevnet, etc.)\n * has its unique configuration, which is used to construct the returned object.\n * @returns The native currency information for the current chain.\n */\n get nativeCurrency(): NativeCurrency {\n return {\n [KeybanNetwork.EthereumAnvil]: {\n decimals: 18,\n name: \"Ether\",\n symbol: \"ETH\",\n },\n [KeybanNetwork.PolygonAmoy]: {\n name: \"POL\",\n symbol: \"POL\",\n decimals: 18,\n },\n [KeybanNetwork.StarknetDevnet]: {\n name: \"Starknet Token\",\n symbol: \"STRK\",\n decimals: 18,\n },\n [KeybanNetwork.StarknetSepolia]: {\n name: \"StarkNet Token\",\n symbol: \"STRK\",\n decimals: 18,\n },\n [KeybanNetwork.StarknetMainnet]: {\n name: \"StarkNet Token\",\n symbol: \"STRK\",\n decimals: 18,\n },\n [KeybanNetwork.StellarQuickstart]: {\n name: \"Lumen\",\n symbol: \"XLM\",\n decimals: 7,\n },\n [KeybanNetwork.StellarTestnet]: {\n name: \"Lumen\",\n symbol: \"XLM\",\n decimals: 7,\n },\n [KeybanNetwork.StellarMainnet]: {\n name: \"Lumen\",\n symbol: \"XLM\",\n decimals: 7,\n },\n }[this.network];\n }\n\n /**\n * Retrieves the fee unit configuration based on the current blockchain chain.\n *\n * This getter returns an object that maps supported blockchain chains to their respective\n * fee unit details, including the currency symbol and the number of decimal places.\n * The fee unit is selected according to the chain specified in `this.chain`.\n * @remarks\n * Supported configurations include:\n * - EthereumAnvil & PolygonAmoy with unit \"gwei\" and 9 decimals.\n * - StarknetDevnet, StarknetSepolia, & StarknetMainnet with unit \"FRI\" and 18 decimals.\n * - StellarTestnet with unit \"stroop\" and 6 decimals.\n * @returns An object containing the fee unit configuration for the active chain.\n */\n get feesUnit(): FeesUnit {\n return {\n [KeybanNetwork.EthereumAnvil]: {\n symbol: \"gwei\",\n decimals: 9,\n },\n [KeybanNetwork.PolygonAmoy]: {\n symbol: \"gwei\",\n decimals: 9,\n },\n [KeybanNetwork.StarknetDevnet]: {\n symbol: \"FRI\",\n decimals: 18,\n },\n [KeybanNetwork.StarknetSepolia]: {\n symbol: \"FRI\",\n decimals: 18,\n },\n [KeybanNetwork.StarknetMainnet]: {\n symbol: \"FRI\",\n decimals: 18,\n },\n [KeybanNetwork.StellarQuickstart]: {\n symbol: \"stroop\",\n decimals: 7,\n },\n [KeybanNetwork.StellarTestnet]: {\n symbol: \"stroop\",\n decimals: 7,\n },\n [KeybanNetwork.StellarMainnet]: {\n symbol: \"stroop\",\n decimals: 7,\n },\n }[this.network];\n }\n\n /**\n * Performs a health check on the Keyban API to determine its operational status.\n * @returns - A promise resolving to the API status, either `\"operational\"` or `\"down\"`.\n * @example\n * ```typescript\n * const status = await client.apiStatus();\n * console.log(`API Status: ${status}`);\n * ```\n * @throws {Error} Throws an error if the health check request fails.\n * @see {@link KeybanApiStatus}\n */\n async apiStatus(): Promise<KeybanApiStatus> {\n return fetch(new URL(\"/health/ready\", this.apiUrl))\n .then((res) => (res.ok ? \"operational\" : \"down\"))\n .catch((err) => {\n console.error(\"Failed to perform health check\", err);\n return \"down\";\n });\n }\n\n /**\n * Checks whether the client is authenticated.\n * @returns A Promise that resolves to the result of the authentication check.\n */\n async isAuthenticated() {\n return this.rpcClient.call(\"auth\", \"isAuthenticated\");\n }\n\n /**\n * Retrieves the current user information.\n * @returns A Promise resolving with the user data retrieved from the server.\n */\n async getUser() {\n return this.rpcClient.call(\"auth\", \"getUser\");\n }\n\n async passwordLogin(input: PasswordLoginInput) {\n return this.rpcClient.call(\"auth\", \"passwordLogin\", input);\n }\n\n async passwordlessStart(input: PasswordlessStartInput) {\n return this.rpcClient.call(\"auth\", \"passwordlessStart\", input);\n }\n\n async passwordlessLogin(input: PasswordlessLoginInput) {\n return this.rpcClient.call(\"auth\", \"passwordlessLogin\", input);\n }\n\n /**\n * Initiates the login process by opening a popup window for user authentication.\n * @param [connection] - Optional authentication connection details.\n * @returns - A promise that resolves when the user is authenticated or the popup is closed.\n */\n async login(connection?: AuthConnection) {\n const loginUrl = await this.rpcClient.call(\n \"auth\",\n \"getLoginUrl\",\n connection,\n );\n\n const width = 500;\n const height = 685;\n const left = window.screenX + (window.innerWidth - width) / 2;\n const top = window.screenY + (window.innerHeight - height) / 2;\n\n const popup = window.open(\n loginUrl,\n `keyban:auth:${this.appId}`,\n `left=${left},top=${top},width=${width},height=${height},popup,resizable,scrollbars`,\n );\n\n // Setup our handler for when user is fully authenticated\n const authenticatedPromise = new Promise<void>((resolve) => {\n const handler = (event: MessageEvent) => {\n if (event.origin !== this.apiUrl.origin) return;\n if (event.data !== \"keyban:auth:isAuthenticated\") return;\n\n window.removeEventListener(\"message\", handler);\n\n resolve();\n };\n\n window.addEventListener(\"message\", handler);\n });\n\n // Wait for popup to be closed\n await new Promise<void>((resolve) => {\n const interval = setInterval(() => {\n if (!popup?.closed) return;\n\n clearInterval(interval);\n resolve();\n }, 100);\n });\n\n // Wait for user to be authenticated or timeout\n await Promise.race([\n authenticatedPromise,\n new Promise((resolve) => setTimeout(resolve, 2000)),\n ]);\n }\n\n async logout() {\n const logoutUrl = await this.rpcClient.call(\n \"auth\",\n \"getLogoutUrl\",\n window.location.href,\n );\n\n const width = 500;\n const height = 685;\n const left = window.screenX + (window.innerWidth - width) / 2;\n const top = window.screenY + (window.innerHeight - height) / 2;\n\n const popup = window.open(\n logoutUrl,\n `keyban:auth:${this.appId}`,\n `left=${left},top=${top},width=${width},height=${height},popup,resizable,scrollbars`,\n );\n\n // Wait for popup to be closed\n await new Promise<void>((resolve) => {\n const interval = setInterval(() => {\n if (!popup?.closed) return;\n\n clearInterval(interval);\n resolve();\n }, 100);\n });\n }\n\n /**\n * Initializes a `KeybanAccount` associated with the current client.\n * This method sets up the account by retrieving or generating the client share,\n * and prepares the account for transactions and other operations.\n * @returns - A promise that resolves to an instance of `KeybanAccount`.\n * @throws {SdkError} If initialization fails due to signing errors.\n * @example\n * ```typescript\n * const account = await client.initialize();\n * console.log(`Account address: ${account.address}`);\n * ```\n * @see {@link KeybanAccount}\n */\n abstract initialize(): Promise<KeybanAccount>;\n}\n\n/**\n * Main client for interacting with the Keyban API and associated services.\n * This class provides methods to initialize accounts, retrieve balances, query NFTs,\n * and interact with the Keyban blockchain.\n * @remarks\n * The `KeybanClient` serves as the primary interface for developers to interact with\n * the Keyban ecosystem. It handles authentication, communication with the Keyban API,\n * and provides utility methods for common tasks.\n * @example\n * ```typescript\n * // Initialize the client\n * const client = new KeybanClient({\n * apiUrl: \"https://api.prod.keyban.io\",\n * appId: \"your-app-id\",\n * network: KeybanNetwork.EthereumAnvil,\n * });\n *\n * // Initialize an account\n * const account = await client.initialize();\n * ```\n * @see {@link KeybanAccount}\n */\nexport class KeybanClient extends KeybanClientBase {\n #client: Promise<KeybanClientBase>;\n\n #pendingAccounts: Map<string, Promise<KeybanAccount>> = new Map();\n\n /**\n * Creates a new instance of `KeybanClient`.\n * @param config - The configuration object to initialize the client.\n * @throws {SdkError} If the configuration is invalid.\n * @example\n * ```typescript\n * const client = new KeybanClient({\n * apiUrl: \"https://api.prod.keyban.io\",\n * appId: \"your-app-id\",\n * network: KeybanNetwork.EthereumAnvil,\n * });\n * ```\n */\n constructor(config: KeybanClientConfig) {\n super(config);\n\n this.#client = {\n [KeybanNetwork.EthereumAnvil]: () =>\n import(\"~/evm\").then(\n ({ KeybanEvmClient }) =>\n new KeybanEvmClient(config, this.metadataConfig),\n ),\n [KeybanNetwork.PolygonAmoy]: () =>\n import(\"~/evm\").then(\n ({ KeybanEvmClient }) =>\n new KeybanEvmClient(config, this.metadataConfig),\n ),\n [KeybanNetwork.StarknetDevnet]: () =>\n import(\"~/starknet\").then(\n ({ StarknetClient }) =>\n new StarknetClient(config, this.metadataConfig),\n ),\n [KeybanNetwork.StarknetSepolia]: () =>\n import(\"~/starknet\").then(\n ({ StarknetClient }) =>\n new StarknetClient(config, this.metadataConfig),\n ),\n [KeybanNetwork.StarknetMainnet]: () =>\n import(\"~/starknet\").then(\n ({ StarknetClient }) =>\n new StarknetClient(config, this.metadataConfig),\n ),\n [KeybanNetwork.StellarQuickstart]: () =>\n import(\"~/stellar\").then(\n ({ StellarClient }) => new StellarClient(config, this.metadataConfig),\n ),\n [KeybanNetwork.StellarTestnet]: () =>\n import(\"~/stellar\").then(\n ({ StellarClient }) => new StellarClient(config, this.metadataConfig),\n ),\n [KeybanNetwork.StellarMainnet]: () =>\n import(\"~/stellar\").then(\n ({ StellarClient }) => new StellarClient(config, this.metadataConfig),\n ),\n }[this.network]();\n }\n\n async initialize() {\n const key = \"WHATEVER\";\n\n const pending = this.#pendingAccounts.get(key);\n if (pending) return pending;\n\n const promise = this.#client.then((client) => client.initialize());\n\n this.#pendingAccounts.set(key, promise);\n promise.catch(() => {}).finally(() => this.#pendingAccounts.delete(key));\n\n return promise;\n }\n}\n","import { ClientShareProvider, KeybanClientBase } from \"~/client\";\nimport { RpcClient } from \"~/rpc\";\n\n/**\n * A client share provider implementation for the Keyban client.\n *\n * The `KeybanClientShareProvider` class provides methods to get and set the client share.\n * This class is used to interact with the client share storage on the server side.\n * @remarks\n * The client share is saved in a service provided by Keyban, ensuring secure storage\n * and retrieval of the client share information.\n */\nexport class KeybanClientShareProvider implements ClientShareProvider {\n #client!: KeybanClientBase;\n\n /**\n * Internal use only.\n * @param client - A keyban client\n * @private\n */\n registerClient(client: KeybanClientBase) {\n this.#client = client;\n }\n\n get #rpcClient() {\n return RpcClient.getInstance(this.#client);\n }\n\n /**\n * Retrieves the client share information.\n * @param key - The key associated with the client share.\n * @returns - A promise that resolves to a string containing the client share, or null if not available.\n */\n async get(key: string): Promise<string | null> {\n return this.#rpcClient.call(\"clientShareStorage\", \"get\", key);\n }\n\n /**\n * Sets the client share information.\n * @param key - The key associated with the client share.\n * @param clientShare - The client share string to set.\n * @returns - A promise that resolves when the client share has been set.\n */\n async set(key: string, clientShare: string): Promise<unknown> {\n return this.#rpcClient.call(\"clientShareStorage\", \"set\", key, clientShare);\n }\n}\n","/**\n * @module Chains\n */\n\n/**\n * @enum {string}\n * The `KeybanNetwork` enumeration defines the various blockchain networks supported by the Keyban SDK.\n * Each member of the enumeration represents a specific blockchain network identified by its unique name.\n * @remarks\n * Use this enumeration to specify the blockchain network you wish to interact with when utilizing\n * the different functionalities of the Keyban SDK, such as account management, transactions, and NFTs.\n * @example\n * ```typescript\n * import { KeybanClient, KeybanNetwork } from '@keyban/sdk';\n *\n * const client = new KeybanClient({\n * apiUrl: \"https://api.prod.keyban.io\",\n * appId: \"your-app-id\",\n * network: KeybanNetwork.EthereumAnvil,\n * });\n * ```\n */\nexport enum KeybanNetwork {\n /**\n * Ethereum Anvil Chain.\n * Primarily used for development and testing purposes. This chain allows simulation of\n * transactions and interactions without affecting the main chain.\n */\n EthereumAnvil = \"EthereumAnvil\",\n\n /**\n * Polygon Amoy Chain.\n * Represents the Polygon Amoy mainnet, offering fast transactions and reduced fees.\n * Ideal for production applications requiring high performance.\n */\n PolygonAmoy = \"PolygonAmoy\",\n\n /**\n * Starknet Devnet Chain.\n */\n StarknetDevnet = \"StarknetDevnet\",\n\n /**\n * Starknet Sepolia Chain.\n */\n StarknetSepolia = \"StarknetSepolia\",\n\n /**\n * Starknet Mainnet Chain.\n */\n StarknetMainnet = \"StarknetMainnet\",\n\n /**\n * Stellar Quickstart Chain.\n */\n StellarQuickstart = \"StellarQuickstart\",\n\n /**\n * Stellar Testnet Chain.\n */\n StellarTestnet = \"StellarTestnet\",\n\n /**\n * Stellar Mainnet Chain.\n */\n StellarMainnet = \"StellarMainnet\",\n}\n\n/**\n * Represents the unit of fees in a specific blockchain.\n * @property {string} symbol - The symbol of the fee unit (e.g., \"gwei\").\n * @property {number} decimals - The number of decimal places for the fee unit.\n */\nexport type FeesUnit = {\n symbol: string;\n decimals: number;\n};\n\n/**\n * Represents the native currency of a blockchain network.\n * @property {string} name - The name of the native currency (e.g., \"Ether\").\n * @property {string} symbol - The symbol of the native currency (e.g., \"ETH\").\n * @property {number} decimals - The number of decimal places the currency can be divided into.\n * @example\n * const nativeCurrency = {\n * name: \"Ether\",\n * symbol: \"ETH\",\n * decimals: 18\n * };\n * @example\n * const nativeCurrency = {\n * name: \"Bitcoin\",\n * symbol: \"BTC\",\n * decimals: 8\n * };\n */\nexport type NativeCurrency = {\n name: string;\n symbol: string;\n decimals: number;\n};\n","/**\n * @module Format Balances\n */\nimport { formatUnits } from \"viem\";\n\nimport type { KeybanClient, KeybanToken } from \"~/index\";\n\n/**\n * Represents a balance with optional metadata.\n * @example\n * // Example of a balance in native currency with fees\n * const balance: Balance = {\n * raw: '1000000000000000000',\n * decimals: 18,\n * symbol: 'ETH',\n * isNative: true,\n * isFees: true\n * };\n * @example\n * // Example of a balance in a token\n * const tokenBalance: Balance = {\n * raw: BigInt('500000000000000000'),\n * decimals: 18,\n * symbol: 'DAI'\n * };\n */\nexport type Balance = {\n /** The raw balance value. */\n raw: string | bigint;\n /** The number of decimal places for the balance. */\n decimals?: number;\n /** The symbol of the currency. */\n symbol?: string;\n /** Indicates if the balance is in the native currency. */\n isNative?: boolean;\n /** Indicates if the balance is used for fees. */\n isFees?: boolean;\n};\n\n/**\n * Formats the balance into a human-readable string with the appropriate decimals and symbol.\n * @param client - The KeybanClient instance which provides information about fees and native currency.\n * @param balance - The balance object containing raw balance, decimals, symbol, and flags indicating if it's fees or native currency.\n * @param [token] - (Optional) The KeybanToken object which provides token-specific decimals and symbol.\n * @returns - A formatted string representing the balance with the appropriate decimals and symbol.\n *\n * test\n * @example\n * ```typescript\n * const client = new KeybanClient(...);\n * const balance = { raw: 1000000000000000000n, decimals: 18, isNative: true };\n * console.log(formatBalance(client, balance)); // \"1 ETH\"\n *\n * const balanceWithToken = { raw: 1000000n };\n * const token = {\n * id: '1',\n * type: 'ERC20',\n * name: 'Tether',\n * symbol: 'USDT',\n * decimals: 6,\n * iconUrl: 'https://example.com/usdt-icon.png'\n * };\n * console.log(formatBalance(client, balanceWithToken, token)); // \"1 USDT\"\n *\n * const feeBalance = { raw: 1000n, isFees: true };\n * console.log(formatBalance(client, feeBalance)); // \"0.000001 gwei\"\n * ```\n */\nexport function formatBalance(\n client: KeybanClient,\n balance: Balance,\n token?: KeybanToken,\n): string {\n let decimals = balance.decimals;\n let symbol = balance.symbol;\n if (balance.isFees) {\n decimals = client.feesUnit.decimals;\n symbol = client.feesUnit.symbol;\n } else if (balance.isNative) {\n decimals = client.nativeCurrency.decimals;\n symbol = client.nativeCurrency.symbol;\n } else if (token) {\n decimals = token.decimals ?? undefined;\n symbol = token.symbol ?? undefined;\n }\n decimals = decimals ?? 0;\n\n const fmt = formatUnits(\n typeof balance.raw === \"bigint\" ? balance.raw : BigInt(balance.raw),\n decimals,\n );\n return symbol ? `${fmt} ${symbol}` : fmt;\n}\n"]}