@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 • 19.2 kB
Source Map (JSON)
{"version":3,"sources":["../src/errors/KeybanBaseError.ts","../src/errors/CryptoError.ts","../src/errors/IFrameRpcError.ts","../src/errors/JwtError.ts","../src/errors/SdkError.ts"],"names":["KeybanBaseError","type","title","instance","rootError","detail","status","CryptoErrorType","CryptoError","_CryptoError","#getTitle","errorType","IFrameRpcErrorType","IFrameRpcError","_IFrameRpcError","JwtErrorType","JwtError","_JwtError","SdkErrorTypes","SdkError","_SdkError"],"mappings":"AAmCO,IAAMA,CAAAA,CAAN,cAAgD,KAAM,CAS3D,KAUA,KAAA,CAUA,QAAA,CAUA,MAAA,CAUA,MAAA,CAUA,SAAA,CASA,SAAA,CAYA,QAAS,CACP,OAAO,CACL,IAAA,CAAM,IAAA,CAAK,KACX,KAAA,CAAO,IAAA,CAAK,KAAA,CACZ,QAAA,CAAU,IAAA,CAAK,QAAA,CACf,OAAQ,IAAA,CAAK,MAAA,CACb,OAAQ,IAAA,CAAK,MAAA,CACb,UAAW,IAAA,CAAK,SAAA,CAChB,SAAA,CAAW,IAAA,CAAK,SAClB,CACF,CAsBA,WAAA,CAAY,CACV,KAAAC,CAAAA,CACA,KAAA,CAAAC,EACA,QAAA,CAAAC,CAAAA,CACA,SAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,OAAAC,CACF,CAAA,CAOG,CACD,KAAA,CAAMD,CAAAA,EAAUH,GAASD,CAAI,CAAA,CAE7B,IAAA,CAAK,IAAA,CAAOA,CAAAA,CACZ,IAAA,CAAK,MAAQC,CAAAA,EAASD,CAAAA,CACtB,KAAK,QAAA,CAAWE,CAAAA,CAChB,KAAK,MAAA,CAASE,CAAAA,CACd,IAAA,CAAK,MAAA,CAASC,CAAAA,CACd,IAAA,CAAK,UAAY,IAAI,IAAA,GAAO,WAAA,EAAY,CACxC,KA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,CAAc,aAAA,CAQdA,CAAAA,CAAA,oBAAA,CAAuB,sBAAA,CAzFbA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,IAoGCC,CAAAA,CAAN,MAAMC,UAAiBpB,CAA+B,CAI3D,OAAO,KAAA,CAAQkB,CAAAA,CAaf,WAAA,CACEjB,CAAAA,CACAE,CAAAA,CACAC,CAAAA,CACA,CACA,KAAA,CAAM,CACJ,KAAAH,CAAAA,CACA,QAAA,CAAAE,EACA,SAAA,CAAAC,CAAAA,CACA,KAAA,CAAOgB,CAAAA,CAASV,EAAAA,CAAUT,CAAI,CAChC,CAAC,EACH,CAQA,MAAOS,EAAAA,CAAUC,CAAAA,CAAkC,CACjD,OAAQA,CAAAA,EACN,KAAK,yBAAA,CACH,OAAO,iDAET,KAAK,uBAAA,CACH,OAAO,+CAAA,CAET,KAAK,iBACH,OAAO,oBAAA,CAET,KAAK,eAAA,CACH,OAAO,iCAAA,CAET,KAAK,gBAAA,CACH,OAAO,2CAET,KAAK,kBAAA,CACH,OAAO,8DAAA,CAET,KAAK,8BAAA,CACH,OAAO,4DAAA,CAET,KAAK,uBACH,OAAO,uBAAA,CAET,KAAK,mBAAA,CACH,OAAO,iDAET,KAAK,oBAAA,CACH,OAAO,kEAAA,CAET,KAAK,aAAA,CACH,OAAO,+DAAA,CAET,KAAK,sBAAA,CACH,OAAO,4DAAA,CAET,QACE,OAAO,CAAA,oBAAA,EAAuBA,CAAS,CAAA,CAC3C,CACF,CACF","file":"chunk-VGFAFYVC.mjs","sourcesContent":["/**\n * @module Errors\n */\n/**\n * The `KeybanBaseError` class serves as the foundational structure for all custom errors within the Keyban SDK.\n * It extends the native JavaScript `Error` class, providing additional properties to enrich error handling\n * with more context and information.\n * @template T - The enum type representing the specific error category.\n * @remarks\n * This class is intended to be extended by more specific error classes that define particular error types.\n * It standardizes error information, making it easier to handle and debug errors across the SDK.\n * @example\n * ```typescript\n * import { KeybanBaseError, SdkErrorTypes } from '@keyban/sdk';\n *\n * class AddressInvalidError extends KeybanBaseError<SdkErrorTypes.AddressInvalid> {\n * constructor(instance: string, detail?: string) {\n * super({\n * type: SdkErrorTypes.AddressInvalid,\n * instance,\n * detail,\n * title: \"Invalid Ethereum Address\",\n * status: 400,\n * });\n * }\n * }\n *\n * // Usage in a function\n * function validateAddress(address: string) {\n * if (!isValidEthereumAddress(address)) {\n * throw new AddressInvalidError(\"validateAddress-001\", \"The provided Ethereum address is not valid.\");\n * }\n * }\n * ```\n */\nexport class KeybanBaseError<T extends string> extends Error {\n /**\n * A URI reference that identifies the problem type. This property is mandatory and provides a\n * machine-readable identifier for the error.\n * @example\n * ```typescript\n * error.type // \"https://api.prod.keyban.io/errors/address-invalid\"\n * ```\n */\n type: T;\n\n /**\n * A short, human-readable summary of the problem type. It should remain consistent across\n * occurrences of the problem except for localization purposes.\n * @example\n * ```typescript\n * error.title // \"Invalid Ethereum Address\"\n * ```\n */\n title: string;\n\n /**\n * A URI reference that identifies the specific occurrence of the problem. This provides a\n * unique identifier for the particular instance of the error.\n * @example\n * ```typescript\n * error.instance // \"validateAddress-001\"\n * ```\n */\n instance: string;\n\n /**\n * The HTTP status code generated by the origin server for this occurrence of the problem.\n * It is a numeric value and is included for the convenience of the client.\n * @example\n * ```typescript\n * error.status // 400\n * ```\n */\n status?: number;\n\n /**\n * A human-readable explanation specific to this occurrence of the problem. This field helps\n * the client understand and potentially correct the issue.\n * @example\n * ```typescript\n * error.detail // \"The provided Ethereum address is not valid.\"\n * ```\n */\n detail?: string;\n\n /**\n * A timestamp recording the exact date and time when the exception occurred, in ISO8601 format\n * (`YYYY-MM-DDTHH:mm:ss.sssZ`).\n * @example\n * ```typescript\n * error.timestamp // \"2024-04-27T12:34:56.789Z\"\n * ```\n */\n timestamp: string;\n\n /**\n * The original error instance, if any. This can be used to trace the root cause of the error.\n * @example\n * ```typescript\n * error.rootError // Original Error instance or additional error details\n * ```\n */\n rootError?: Error | Record<string, unknown>;\n\n /**\n * Serializes the error instance into a JSON object, including all relevant properties.\n * This is useful for logging, debugging, or transmitting error information.\n * @returns - A JSON representation of the error.\n * @example\n * ```typescript\n * const errorJson = error.toJSON();\n * console.log(errorJson);\n * ```\n */\n toJSON() {\n return {\n type: this.type,\n title: this.title,\n instance: this.instance,\n status: this.status,\n detail: this.detail,\n timestamp: this.timestamp,\n rootError: this.rootError,\n };\n }\n\n /**\n * Creates an instance of `KeybanBaseError`. It initializes the error with the provided properties,\n * sets the error message, and records the timestamp.\n * @param params - The parameters to initialize the error.\n * @param params.type - The specific error type identifier.\n * @param [params.title] - A short summary of the error. Defaults to the `type` if not provided.\n * @param params.instance - A unique identifier for this specific error occurrence.\n * @param [params.rootError] - The original error, if any.\n * @param [params.detail] - A detailed explanation of the error.\n * @param [params.status] - The HTTP status code associated with the error.\n * @example\n * ```typescript\n * const error = new KeybanBaseError({\n * type: SdkErrorTypes.AddressInvalid,\n * instance: \"validateAddress-001\",\n * detail: \"The provided Ethereum address is not valid.\",\n * status: 400,\n * });\n * ```\n */\n constructor({\n type,\n title,\n instance,\n rootError,\n detail,\n status,\n }: {\n type: KeybanBaseError<T>[\"type\"];\n title?: KeybanBaseError<T>[\"title\"];\n instance: KeybanBaseError<T>[\"instance\"];\n rootError?: KeybanBaseError<T>[\"rootError\"];\n detail?: KeybanBaseError<T>[\"detail\"];\n status?: KeybanBaseError<T>[\"status\"];\n }) {\n super(detail ?? title ?? type);\n\n this.type = type;\n this.title = title ?? type;\n this.instance = instance;\n this.detail = detail;\n this.status = status;\n this.timestamp = new Date().toISOString();\n this.rootError = rootError;\n }\n}\n","import { KeybanBaseError } from \"./KeybanBaseError\";\n\nexport enum CryptoErrorType {\n GenerateKey = \"GenerateKey\",\n ExportKey = \"ExportKey\",\n ImportKey = \"ImportKey\",\n Encrypt = \"Encrypt\",\n Decrypt = \"Decrypt\",\n}\n\nexport class CryptoError extends KeybanBaseError<CryptoErrorType> {\n static types = CryptoErrorType;\n\n constructor(type: CryptoErrorType, instance: string, rootError?: Error) {\n super({\n type,\n instance,\n rootError,\n title: CryptoError.#getTitle(type),\n });\n }\n\n static #getTitle(errorType: CryptoErrorType): string {\n switch (errorType) {\n case CryptoErrorType.GenerateKey:\n return \"Error generating a cryptographic key\";\n\n case CryptoErrorType.ExportKey:\n return \"Error exporting a cryptographic key\";\n\n case CryptoErrorType.ImportKey:\n return \"Error importing a cryptographic key\";\n\n case CryptoErrorType.Encrypt:\n return \"Error encrypting data\";\n\n case CryptoErrorType.Decrypt:\n return \"Error decrypting data\";\n\n default:\n return `Unknown error type: ${errorType}`;\n }\n }\n}\n","import { KeybanBaseError } from \"./KeybanBaseError\";\n\nexport enum IFrameRpcErrorType {\n InvalidOrigin = \"InvalidOrigin\",\n InvalidCall = \"InvalidCall\",\n}\n\nexport class IFrameRpcError extends KeybanBaseError<IFrameRpcErrorType> {\n static types = IFrameRpcErrorType;\n\n constructor(type: IFrameRpcErrorType, instance: string, rootError?: Error) {\n super({\n type,\n instance,\n rootError,\n title: IFrameRpcError.#getTitle(type),\n });\n }\n\n static #getTitle(errorType: IFrameRpcErrorType): string {\n switch (errorType) {\n case IFrameRpcErrorType.InvalidOrigin:\n return \"The current domain is not allowed for this appId\";\n\n case IFrameRpcErrorType.InvalidCall:\n return \"Invalid method call, either the method does not exists or is not allowed\";\n\n default:\n return `Unknown error type: ${errorType}`;\n }\n }\n}\n","import { KeybanBaseError } from \"./KeybanBaseError\";\n\nexport enum JwtErrorType {\n InvalidToken = \"InvalidToken\",\n}\n\nexport class JwtError extends KeybanBaseError<JwtErrorType> {\n static types = JwtErrorType;\n\n constructor(type: JwtErrorType, instance: string, rootError?: Error) {\n super({\n type,\n instance,\n rootError,\n title: JwtError.#getTitle(type),\n });\n }\n\n static #getTitle(errorType: JwtErrorType): string {\n switch (errorType) {\n case JwtErrorType.InvalidToken:\n return \"You provided an invalid access token\";\n\n default:\n return `Unknown error type: ${errorType}`;\n }\n }\n}\n","/**\n * @module SDK Errors\n */\nimport { KeybanBaseError } from \"./KeybanBaseError\";\n\n/**\n * Enum representing all possible SDK error types.\n *\n * This enumeration defines the various error conditions that can occur within the Keyban SDK.\n * Each error type is associated with a specific scenario, allowing developers to handle errors\n * gracefully and provide meaningful feedback to users.\n * @enum {string}\n */\nexport enum SdkErrorTypes {\n /**\n * An unknown transaction error.\n */\n UnknownTransactionError = \"UnknownTransactionError\",\n\n /**\n * An unknown error during iframe RPC call.\n */\n UnknownIframeRpcError = \"UnknownIframeRpcError\",\n\n /**\n * The provided address is invalid.\n *\n * **Description:** The Ethereum address does not conform to the expected format.\n * **Possible Cause:** Typographical errors in the address or incorrect formatting.\n */\n AddressInvalid = \"AddressInvalid\",\n\n /**\n * The provided amount is invalid.\n *\n * **Description:** The amount specified for a transaction is not acceptable.\n * **Possible Cause:** Amount is zero, negative, or exceeds allowed limits.\n */\n AmountInvalid = \"AmountInvalid\",\n\n /**\n * The amount is required for this operation.\n *\n * **Description:** An operation that requires a monetary amount did not receive one.\n * **Possible Cause:** Missing amount parameter in the function call.\n */\n AmountRequired = \"AmountRequired\",\n\n /**\n * The amount provided is irrelevant and should not be provided.\n *\n * **Description:** An operation does not require an amount, but one was supplied.\n * **Possible Cause:** Misuse of the API by providing unnecessary parameters.\n */\n AmountIrrelevant = \"AmountIrrelevant\",\n\n /**\n * The recipient address is the same as the sender address.\n *\n * **Description:** A transaction was attempted where the sender and recipient are identical.\n * **Possible Cause:** User error in specifying addresses or attempting redundant transactions.\n */\n RecipientAddressEqualsSender = \"RecipientAddressEqualsSender\",\n\n /**\n * Gas estimation failed during transaction processing.\n *\n * **Description:** The SDK was unable to estimate the gas required for a transaction.\n * **Possible Cause:** Network issues, incorrect transaction parameters, or contract errors.\n */\n EstimateGasExecution = \"EstimateGasExecution\",\n\n /**\n * The account has insufficient funds to perform the operation.\n *\n * **Description:** The user's account balance is too low to cover the transaction amount and associated fees.\n * **Possible Cause:** Attempting a transaction with an amount exceeding the available balance.\n */\n InsufficientFunds = \"InsufficientFunds\",\n\n /**\n * The NFT standard provided is invalid.\n *\n * **Description:** An unsupported NFT standard was specified.\n * **Possible Cause:** Using an NFT standard other than ERC721 or ERC1155.\n */\n InvalidNftStandard = \"InvalidNftStandard\",\n\n /**\n * The specified NFT was not found.\n *\n * **Description:** The NFT identified by the provided contract address and token ID does not exist.\n * **Possible Cause:** Incorrect token ID, wrong contract address, or the NFT has been burned.\n */\n NftNotFound = \"NftNotFound\",\n\n /**\n * The specified token balance was not found.\n *\n * **Description:** The token balance identified by the provided contract address does not exist.\n * **Possible Cause:** Incorrect wallet address, wrong contract address.\n */\n TokenBalanceNotFound = \"TokenBalanceNotFound\",\n}\n\n/**\n * Class representing an SDK-specific error.\n *\n * The `SdkError` class extends the `KeybanBaseError` to provide detailed error information\n * based on predefined `SdkErrorTypes`. It facilitates consistent error handling across\n * the Keyban SDK by categorizing errors and providing meaningful messages.\n * @augments KeybanBaseError\n */\nexport class SdkError extends KeybanBaseError<SdkErrorTypes> {\n /**\n * The available SDK error types.\n */\n static types = SdkErrorTypes;\n\n /**\n * Creates an instance of `SdkError`.\n * @param type - The specific type of SDK error.\n * @param instance - The identifier of the instance where the error occurred.\n * @param [rootError] - The original error that caused this SDK error, if any.\n * @throws {SdkError} Throws an error if an unknown `SdkErrorTypes` is provided.\n * @example\n * ```typescript\n * throw new SdkError(SdkErrorTypes.InsufficientFunds, \"transferFunction\");\n * ```\n */\n constructor(\n type: SdkErrorTypes,\n instance: string,\n rootError?: Error | Record<string, unknown>,\n ) {\n super({\n type,\n instance,\n rootError,\n title: SdkError.#getTitle(type),\n });\n }\n\n /**\n * Retrieves a human-readable title based on the error type.\n * @private\n * @param errorType - The type of SDK error.\n * @returns - A descriptive title for the error.\n */\n static #getTitle(errorType: SdkErrorTypes): string {\n switch (errorType) {\n case SdkErrorTypes.UnknownTransactionError:\n return \"An unknown error occurred with the transaction\";\n\n case SdkErrorTypes.UnknownIframeRpcError:\n return \"An unknown error occured with iframe rpc call\";\n\n case SdkErrorTypes.AddressInvalid:\n return \"Address is invalid\";\n\n case SdkErrorTypes.AmountInvalid:\n return \"The specified amount is invalid\";\n\n case SdkErrorTypes.AmountRequired:\n return \"An amount is required for this operation\";\n\n case SdkErrorTypes.AmountIrrelevant:\n return \"The amount provided is irrelevant and should not be included\";\n\n case SdkErrorTypes.RecipientAddressEqualsSender:\n return \"Recipient address cannot be the same as the sender address\";\n\n case SdkErrorTypes.EstimateGasExecution:\n return \"Gas estimation failed\";\n\n case SdkErrorTypes.InsufficientFunds:\n return \"Insufficient funds to complete the transaction\";\n\n case SdkErrorTypes.InvalidNftStandard:\n return \"Invalid NFT standard. Supported standards are ERC721 and ERC1155\";\n\n case SdkErrorTypes.NftNotFound:\n return \"NFT not found with the provided contract address and token ID\";\n\n case SdkErrorTypes.TokenBalanceNotFound:\n return \"Token balance not found with the provided contract address\";\n\n default:\n return `Unknown error type: ${errorType}`;\n }\n }\n}\n"]}