{"version":3,"file":"intent.mjs","names":["operationType"],"sources":["../../src/auto-approvals/intent.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction, TransactionResult } from '@mysten/sui/transactions';\nimport type { TransactionDataBuilder } from '@mysten/sui/transactions';\nimport { TransactionCommands } from '@mysten/sui/transactions';\n\nexport const OPERATION_INTENT = '@mysten/wallet-kit/AutoApprovalOperation';\n\nexport function operationType(operationType: string) {\n\treturn (tx: Transaction): TransactionResult => {\n\t\ttx.addIntentResolver(OPERATION_INTENT, (transactionData, _options, next) => {\n\t\t\treplaceOperationTypeIntent(transactionData);\n\t\t\treturn next();\n\t\t});\n\n\t\tconst result = tx.add(\n\t\t\tTransactionCommands.Intent({\n\t\t\t\tname: OPERATION_INTENT,\n\t\t\t\tinputs: {},\n\t\t\t\tdata: { operationType },\n\t\t\t}),\n\t\t);\n\n\t\treturn result;\n\t};\n}\n\nexport function extractOperationType(cb: (operationType: string) => void) {\n\treturn (\n\t\ttransactionData: TransactionDataBuilder,\n\t\t_options: unknown,\n\t\tnext: () => Promise<void>,\n\t) => {\n\t\treplaceOperationTypeIntent(transactionData, cb);\n\t\treturn next();\n\t};\n}\n\nfunction replaceOperationTypeIntent(\n\ttransactionData: TransactionDataBuilder,\n\tcb?: (operationType: string) => void,\n) {\n\tlet intentFound = false;\n\tfor (let index = 0; index < transactionData.commands.length; index++) {\n\t\tconst command = transactionData.commands[index];\n\t\tif (command.$kind === '$Intent' && command.$Intent.name === OPERATION_INTENT) {\n\t\t\tif (intentFound) {\n\t\t\t\tthrow new Error('Multiple operation type intents found in transaction');\n\t\t\t}\n\t\t\tintentFound = true;\n\t\t\tconst operationType = command.$Intent.data.operationType as string;\n\t\t\ttransactionData.replaceCommand(index, []);\n\t\t\tcb?.(operationType);\n\t\t}\n\t}\n}\n"],"mappings":";;;AAOA,MAAa,mBAAmB;AAEhC,SAAgB,cAAc,iBAAuB;AACpD,SAAQ,OAAuC;AAC9C,KAAG,kBAAkB,mBAAmB,iBAAiB,UAAU,SAAS;AAC3E,8BAA2B,gBAAgB;AAC3C,UAAO,MAAM;IACZ;AAUF,SARe,GAAG,IACjB,oBAAoB,OAAO;GAC1B,MAAM;GACN,QAAQ,EAAE;GACV,MAAM,EAAE,gCAAe;GACvB,CAAC,CACF;;;AAMH,SAAgB,qBAAqB,IAAqC;AACzE,SACC,iBACA,UACA,SACI;AACJ,6BAA2B,iBAAiB,GAAG;AAC/C,SAAO,MAAM;;;AAIf,SAAS,2BACR,iBACA,IACC;CACD,IAAI,cAAc;AAClB,MAAK,IAAI,QAAQ,GAAG,QAAQ,gBAAgB,SAAS,QAAQ,SAAS;EACrE,MAAM,UAAU,gBAAgB,SAAS;AACzC,MAAI,QAAQ,UAAU,aAAa,QAAQ,QAAQ,SAAS,kBAAkB;AAC7E,OAAI,YACH,OAAM,IAAI,MAAM,uDAAuD;AAExE,iBAAc;GACd,MAAMA,kBAAgB,QAAQ,QAAQ,KAAK;AAC3C,mBAAgB,eAAe,OAAO,EAAE,CAAC;AACzC,QAAKA,gBAAc"}