{"version":3,"sources":["../../src/api/transactionSubmission/helpers.ts"],"sourcesContent":["import { AccountAuthenticator, AnyRawTransaction, InputTransactionPluginData } from \"../../transactions\";\nimport { AptosConfig } from \"../aptosConfig\";\n\n/**\n * Validates the fee payer data when submitting a transaction to ensure that the fee\n * payer authenticator is provided if a fee payer address is specified. This helps\n * prevent errors in transaction submission related to fee payer authentication.\n *\n * The validation is skipped if a custom transaction submitter is defined.\n *\n * @param config - The Aptos configuration that may contain a transaction submitter.\n * @param args - The method arguments containing transaction data and optional transaction submitter.\n *\n * @example\n * ```typescript\n * import { Aptos, AptosConfig, Network } from \"@aptos-labs/ts-sdk\";\n *\n * const config = new AptosConfig({ network: Network.TESTNET });\n * const aptos = new Aptos(config);\n *\n * class TransactionHandler {\n *   async submitTransaction(methodArgs: { transaction: { feePayerAddress: string }, feePayerAuthenticator?: string }) {\n *     validateFeePayerDataOnSubmission(this.config, methodArgs);\n *     // Logic to submit the transaction\n *   }\n * }\n *\n * async function runExample() {\n *   const handler = new TransactionHandler();\n *\n *   // Attempt to submit a transaction without a fee payer authenticator\n *   try {\n *     await handler.submitTransaction({\n *       transaction: { feePayerAddress: \"0x1\" }, // replace with a real fee payer address\n *     });\n *   } catch (error) {\n *     console.error(error.message); // Should log the error message\n *   }\n *\n *   // Submit a transaction with a fee payer authenticator\n *   await handler.submitTransaction({\n *     transaction: { feePayerAddress: \"0x1\" }, // replace with a real fee payer address\n *     feePayerAuthenticator: \"authenticatorValue\", // replace with a real authenticator\n *   });\n *\n *   console.log(\"Transaction submitted successfully.\");\n * }\n * runExample().catch(console.error);\n * ```\n * @group Implementation\n */\nexport function validateFeePayerDataOnSubmission(\n  config: AptosConfig,\n  args: {\n    transaction: AnyRawTransaction;\n    senderAuthenticator: AccountAuthenticator;\n    feePayerAuthenticator?: AccountAuthenticator;\n  } & InputTransactionPluginData,\n): void {\n  // Skip validation if a transaction submitter is defined.\n  if (config.getTransactionSubmitter() !== undefined || args.transactionSubmitter !== undefined) {\n    return;\n  }\n\n  if (args.transaction.feePayerAddress && !args.feePayerAuthenticator) {\n    throw new Error(\"You are submitting a Fee Payer transaction but missing the feePayerAuthenticator\");\n  }\n}\n\n/**\n * Validates that the fee payer public key is provided when simulating a Fee Payer transaction.\n * This ensures that all necessary data is present for the simulation to proceed correctly.\n *\n * @param target - The target object where the method is defined.\n * @param propertyKey - The name of the method being decorated.\n * @param descriptor - The property descriptor for the method.\n *\n * @example\n * ```typescript\n * import { Aptos, AptosConfig, Network } from \"@aptos-labs/ts-sdk\";\n *\n * const config = new AptosConfig({ network: Network.TESTNET });\n * const aptos = new Aptos(config);\n *\n * async function runExample() {\n *   const methodArgs = {\n *     transaction: {\n *       feePayerAddress: \"0x1\", // replace with a real fee payer address\n *     },\n *     feePayerPublicKey: undefined, // missing fee payer public key\n *   };\n *\n *   try {\n *     // This will throw an error due to missing feePayerPublicKey\n *     await aptos.someMethod(methodArgs);\n *   } catch (error) {\n *     console.error(error.message); // Output the error message\n *   }\n * }\n * runExample().catch(console.error);\n * ```\n * @group Implementation\n */\nexport function ValidateFeePayerDataOnSimulation(target: unknown, propertyKey: string, descriptor: PropertyDescriptor) {\n  const originalMethod = descriptor.value;\n  descriptor.value = async function (...args: any[]) {\n    return originalMethod.apply(this, args);\n  };\n\n  return descriptor;\n}\n"],"mappings":"AAmDO,SAASA,EACdC,EACAC,EAKM,CAEN,GAAI,EAAAD,EAAO,wBAAwB,IAAM,QAAaC,EAAK,uBAAyB,SAIhFA,EAAK,YAAY,iBAAmB,CAACA,EAAK,sBAC5C,MAAM,IAAI,MAAM,kFAAkF,CAEtG,CAoCO,SAASC,EAAiCC,EAAiBC,EAAqBC,EAAgC,CACrH,IAAMC,EAAiBD,EAAW,MAClC,OAAAA,EAAW,MAAQ,kBAAmBJ,EAAa,CACjD,OAAOK,EAAe,MAAM,KAAML,CAAI,CACxC,EAEOI,CACT","names":["validateFeePayerDataOnSubmission","config","args","ValidateFeePayerDataOnSimulation","target","propertyKey","descriptor","originalMethod"]}