@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 • 18.8 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":"AAmCaA,IAAAA,CAAAA,CAAN,cAAgD,KAAM,CAS3D,KAUA,KAUA,CAAA,QAAA,CAUA,OAUA,MAUA,CAAA,SAAA,CASA,UAYA,MAAS,EAAA,CACP,OAAO,CACL,IAAA,CAAM,KAAK,IACX,CAAA,KAAA,CAAO,IAAK,CAAA,KAAA,CACZ,QAAU,CAAA,IAAA,CAAK,SACf,MAAQ,CAAA,IAAA,CAAK,OACb,MAAQ,CAAA,IAAA,CAAK,OACb,SAAW,CAAA,IAAA,CAAK,SAChB,CAAA,SAAA,CAAW,IAAK,CAAA,SAClB,CACF,CAsBA,WAAA,CAAY,CACV,IAAAC,CAAAA,CAAAA,CACA,MAAAC,CACA,CAAA,QAAA,CAAAC,CACA,CAAA,SAAA,CAAAC,CACA,CAAA,MAAA,CAAAC,EACA,MAAAC,CAAAA,CACF,EAOG,CACD,KAAA,CAAMD,GAAUH,CAASD,EAAAA,CAAI,CAE7B,CAAA,IAAA,CAAK,IAAOA,CAAAA,CAAAA,CACZ,KAAK,KAAQC,CAAAA,CAAAA,EAASD,EACtB,IAAK,CAAA,QAAA,CAAWE,EAChB,IAAK,CAAA,MAAA,CAASE,CACd,CAAA,IAAA,CAAK,MAASC,CAAAA,CAAAA,CACd,KAAK,SAAY,CAAA,IAAI,MAAO,CAAA,WAAA,GAC5B,IAAK,CAAA,S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AAAA,SAAiBpB,CAA+B,CAI3D,OAAO,KAAQkB,CAAAA,CAAAA,CAaf,WAAYjB,CAAAA,CAAAA,CAAqBE,EAAkBC,CAAmB,CAAA,CACpE,MAAM,CACJ,IAAA,CAAAH,EACA,QAAAE,CAAAA,CAAAA,CACA,SAAAC,CAAAA,CAAAA,CACA,KAAOgB,CAAAA,CAAAA,CAASV,GAAUT,CAAI,CAChC,CAAC,EACH,CAQA,MAAOS,EAAUC,CAAAA,CAAAA,CAAkC,CACjD,OAAQA,CAAW,EACjB,KAAK,uBACH,CAAA,OAAO,gDAET,KAAK,gBAAA,CACH,OAAO,oBAET,CAAA,KAAK,eACH,CAAA,OAAO,iCAET,CAAA,KAAK,iBACH,OAAO,0CAAA,CAET,KAAK,kBACH,CAAA,OAAO,+DAET,KAAK,8BAAA,CACH,OAAO,4DAAA,CAET,KAAK,sBAAA,CACH,OAAO,uBAET,CAAA,KAAK,oBACH,OAAO,gDAAA,CAET,KAAK,oBACH,CAAA,OAAO,kEAET,CAAA,KAAK,aACH,CAAA,OAAO,gEAET,KAAK,sBAAA,CACH,OAAO,4DAET,CAAA,QACE,OAAO,CAAuBA,oBAAAA,EAAAA,CAAS,CAC3C,CAAA,CACF,CACF","file":"chunk-7K44U4PL.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 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(type: SdkErrorTypes, instance: string, rootError?: Error) {\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.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"]}