{"version":3,"file":"relayer.cjs","names":[],"sources":["../../src/errors/base.ts","../../src/errors/relayer.ts"],"sourcesContent":["/**\n * Typed error codes thrown by the SDK.\n * Use `error.code` or `instanceof` to programmatically handle specific failure modes.\n *\n * @example\n * ```ts\n * try {\n *   await token.confidentialTransfer(\"0xTo\", 100n);\n * } catch (e) {\n *   if (e instanceof SigningRejectedError) {\n *     // User rejected the wallet signature\n *   }\n * }\n * ```\n */\nexport const ZamaErrorCode = {\n  /** User rejected the wallet signature prompt. */\n  SigningRejected: \"SIGNING_REJECTED\",\n  /** Wallet signature failed for a reason other than rejection. */\n  SigningFailed: \"SIGNING_FAILED\",\n  /** FHE encryption failed. */\n  EncryptionFailed: \"ENCRYPTION_FAILED\",\n  /** FHE decryption failed. */\n  DecryptionFailed: \"DECRYPTION_FAILED\",\n  /** On-chain transaction reverted. */\n  TransactionReverted: \"TRANSACTION_REVERTED\",\n  /** Transport key pair has expired and needs regeneration. */\n  TransportKeyPairExpired: \"KEYPAIR_EXPIRED\",\n  /** Relayer rejected transport key pair (stale, expired, or malformed). */\n  InvalidTransportKeyPair: \"INVALID_KEYPAIR\",\n  /** No FHE ciphertext exists for this account (never shielded). */\n  NoCiphertext: \"NO_CIPHERTEXT\",\n  /** Relayer HTTP request failed. */\n  RelayerRequestFailed: \"RELAYER_REQUEST_FAILED\",\n  /** SDK configuration is invalid (e.g. forbidden chain ID, unsupported type). */\n  Configuration: \"CONFIGURATION\",\n  /** Delegation cannot target self (delegate === msg.sender). */\n  DelegationSelfNotAllowed: \"DELEGATION_SELF_NOT_ALLOWED\",\n  /** Only one delegate/revoke per (delegator, delegate, contract) per block. */\n  DelegationCooldown: \"DELEGATION_COOLDOWN\",\n  /** No active delegation found for this (delegator, delegate, contract) tuple. */\n  DelegationNotFound: \"DELEGATION_NOT_FOUND\",\n  /** The delegation has expired. */\n  DelegationExpired: \"DELEGATION_EXPIRED\",\n  /** Confidential (cToken) balance is insufficient for the requested operation. */\n  InsufficientConfidentialBalance: \"INSUFFICIENT_CONFIDENTIAL_BALANCE\",\n  /** ERC-20 balance is insufficient for the requested shield amount. */\n  InsufficientERC20Balance: \"INSUFFICIENT_ERC20_BALANCE\",\n  /** Balance validation could not be performed (no cached credentials and decryption not possible). */\n  BalanceCheckUnavailable: \"BALANCE_CHECK_UNAVAILABLE\",\n  /** Public ERC-20 read (e.g. balanceOf) failed due to a network or contract error. */\n  ERC20ReadFailed: \"ERC20_READ_FAILED\",\n  /** The new expiration date equals the current one — no on-chain change needed. */\n  DelegationExpiryUnchanged: \"DELEGATION_EXPIRY_UNCHANGED\",\n  /** Delegate address cannot be the contract address. */\n  DelegationDelegateEqualsContract: \"DELEGATION_DELEGATE_EQUALS_CONTRACT\",\n  /** Contract address cannot be the sender address. */\n  DelegationContractIsSelf: \"DELEGATION_CONTRACT_IS_SELF\",\n  /** The ACL contract is paused. */\n  AclPaused: \"ACL_PAUSED\",\n  /** Expiration date is too soon (must be at least 1 hour in the future). */\n  DelegationExpirationTooSoon: \"DELEGATION_EXPIRATION_TOO_SOON\",\n  /** Delegation exists on-chain but hasn't propagated to the gateway yet. */\n  DelegationNotPropagated: \"DELEGATION_NOT_PROPAGATED\",\n  /** Signer and provider are connected to different chains. */\n  ChainMismatch: \"CHAIN_MISMATCH\",\n  /** Operation requires a signer but none is configured. */\n  SignerNotConfigured: \"SIGNER_NOT_CONFIGURED\",\n  /** Operation requires a connected wallet account. */\n  WalletNotConnected: \"WALLET_NOT_CONNECTED\",\n  /** Wallet account discovery is still resolving. */\n  WalletAccountNotReady: \"WALLET_ACCOUNT_NOT_READY\",\n} as const;\n\n/** Union of all {@link ZamaErrorCode} string values. */\nexport type ZamaErrorCode = (typeof ZamaErrorCode)[keyof typeof ZamaErrorCode];\n\n/**\n * Base error thrown by all SDK operations.\n * Carries a {@link ZamaErrorCode} for programmatic error handling.\n * Prefer catching specific subclasses (e.g. {@link EncryptionFailedError}).\n */\nexport class ZamaError extends Error {\n  /** Machine-readable error code. */\n  readonly code: ZamaErrorCode;\n\n  constructor(code: ZamaErrorCode, message: string, options?: ErrorOptions) {\n    super(message, options);\n    Object.setPrototypeOf(this, new.target.prototype);\n    this.name = \"ZamaError\";\n    this.code = code;\n  }\n}\n\n/**\n * Pattern-match on a {@link ZamaError} by its error code.\n * Falls through to the `_` wildcard handler if no specific handler matches.\n * Returns `undefined` if the error is not a `ZamaError` and no `_` handler is provided.\n *\n * @example\n * ```ts\n * matchZamaError(error, {\n *   SIGNING_REJECTED: () => toast(\"Please approve in wallet\"),\n *   TRANSACTION_REVERTED: (e) => toast(`Tx failed: ${e.message}`),\n *   _: () => toast(\"Unknown error\"),\n * });\n * ```\n */\nexport function matchZamaError<R>(\n  error: unknown,\n  handlers: Partial<Record<ZamaErrorCode, (error: ZamaError) => R>> & {\n    _?: (error: unknown) => R;\n  },\n): R | undefined {\n  if (error instanceof ZamaError) {\n    const handler = handlers[error.code];\n    if (handler) {\n      return handler(error);\n    }\n  }\n  return handlers._?.(error);\n}\n","import { ZamaError, ZamaErrorCode } from \"./base\";\n\n/** Relayer HTTP request failed. */\nexport class RelayerRequestFailedError extends ZamaError {\n  /** HTTP status code from the relayer, if available. */\n  readonly statusCode: number | undefined;\n\n  constructor(message: string, statusCode?: number, options?: ErrorOptions) {\n    super(ZamaErrorCode.RelayerRequestFailed, message, options);\n    this.name = \"RelayerRequestFailedError\";\n    this.statusCode = statusCode;\n  }\n}\n\n/** SDK configuration is invalid (e.g. forbidden chain ID, unsupported type). */\nexport class ConfigurationError extends ZamaError {\n  constructor(message: string, options?: ErrorOptions) {\n    super(ZamaErrorCode.Configuration, message, options);\n    this.name = \"ConfigurationError\";\n  }\n}\n"],"mappings":"AAeA,MAAa,EAAgB,CAE3B,gBAAiB,mBAEjB,cAAe,iBAEf,iBAAkB,oBAElB,iBAAkB,oBAElB,oBAAqB,uBAErB,wBAAyB,kBAEzB,wBAAyB,kBAEzB,aAAc,gBAEd,qBAAsB,yBAEtB,cAAe,gBAEf,yBAA0B,8BAE1B,mBAAoB,sBAEpB,mBAAoB,uBAEpB,kBAAmB,qBAEnB,gCAAiC,oCAEjC,yBAA0B,6BAE1B,wBAAyB,4BAEzB,gBAAiB,oBAEjB,0BAA2B,8BAE3B,iCAAkC,sCAElC,yBAA0B,8BAE1B,UAAW,aAEX,4BAA6B,iCAE7B,wBAAyB,4BAEzB,cAAe,iBAEf,oBAAqB,wBAErB,mBAAoB,uBAEpB,sBAAuB,0BACzB,EAUA,IAAa,EAAb,cAA+B,KAAM,CAEnC,KAEA,YAAY,EAAqB,EAAiB,EAAwB,CACxE,MAAM,EAAS,CAAO,EACtB,OAAO,eAAe,KAAM,IAAI,OAAO,SAAS,EAChD,KAAK,KAAO,YACZ,KAAK,KAAO,CACd,CACF,EAgBA,SAAgB,EACd,EACA,EAGe,CACf,GAAI,aAAiB,EAAW,CAC9B,IAAM,EAAU,EAAS,EAAM,MAC/B,GAAI,EACF,OAAO,EAAQ,CAAK,CAExB,CACA,OAAO,EAAS,IAAI,CAAK,CAC3B,CCtHA,IAAa,EAAb,cAA+C,CAAU,CAEvD,WAEA,YAAY,EAAiB,EAAqB,EAAwB,CACxE,MAAM,EAAc,qBAAsB,EAAS,CAAO,EAC1D,KAAK,KAAO,4BACZ,KAAK,WAAa,CACpB,CACF,EAGa,EAAb,cAAwC,CAAU,CAChD,YAAY,EAAiB,EAAwB,CACnD,MAAM,EAAc,cAAe,EAAS,CAAO,EACnD,KAAK,KAAO,oBACd,CACF"}