@sundaeswap/sprinkles 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/README.md +178 -181
  2. package/dist/cjs/Sprinkle/__tests__/action-integration.test.js +590 -0
  3. package/dist/cjs/Sprinkle/__tests__/action-integration.test.js.map +1 -0
  4. package/dist/cjs/Sprinkle/__tests__/action-registry.test.js +193 -0
  5. package/dist/cjs/Sprinkle/__tests__/action-registry.test.js.map +1 -0
  6. package/dist/cjs/Sprinkle/__tests__/action-runner.test.js +304 -0
  7. package/dist/cjs/Sprinkle/__tests__/action-runner.test.js.map +1 -0
  8. package/dist/cjs/Sprinkle/__tests__/builtin-actions.test.js +1110 -0
  9. package/dist/cjs/Sprinkle/__tests__/builtin-actions.test.js.map +1 -0
  10. package/dist/cjs/Sprinkle/__tests__/cli-adapter.test.js +744 -0
  11. package/dist/cjs/Sprinkle/__tests__/cli-adapter.test.js.map +1 -0
  12. package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js +15 -1
  13. package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
  14. package/dist/cjs/Sprinkle/__tests__/mcp-adapter.test.js +711 -0
  15. package/dist/cjs/Sprinkle/__tests__/mcp-adapter.test.js.map +1 -0
  16. package/dist/cjs/Sprinkle/__tests__/native-script.test.js +390 -0
  17. package/dist/cjs/Sprinkle/__tests__/native-script.test.js.map +1 -0
  18. package/dist/cjs/Sprinkle/__tests__/tui-helpers.test.js +334 -0
  19. package/dist/cjs/Sprinkle/__tests__/tui-helpers.test.js.map +1 -0
  20. package/dist/cjs/Sprinkle/__tests__/utility-actions.test.js +367 -0
  21. package/dist/cjs/Sprinkle/__tests__/utility-actions.test.js.map +1 -0
  22. package/dist/cjs/Sprinkle/__tests__/wallet-transaction-actions.test.js +749 -0
  23. package/dist/cjs/Sprinkle/__tests__/wallet-transaction-actions.test.js.map +1 -0
  24. package/dist/cjs/Sprinkle/actions/builtin/addressbook-actions.js +164 -0
  25. package/dist/cjs/Sprinkle/actions/builtin/addressbook-actions.js.map +1 -0
  26. package/dist/cjs/Sprinkle/actions/builtin/blaze-helper.js +61 -0
  27. package/dist/cjs/Sprinkle/actions/builtin/blaze-helper.js.map +1 -0
  28. package/dist/cjs/Sprinkle/actions/builtin/index.js +174 -0
  29. package/dist/cjs/Sprinkle/actions/builtin/index.js.map +1 -0
  30. package/dist/cjs/Sprinkle/actions/builtin/native-script.js +139 -0
  31. package/dist/cjs/Sprinkle/actions/builtin/native-script.js.map +1 -0
  32. package/dist/cjs/Sprinkle/actions/builtin/profile-actions.js +202 -0
  33. package/dist/cjs/Sprinkle/actions/builtin/profile-actions.js.map +1 -0
  34. package/dist/cjs/Sprinkle/actions/builtin/settings-actions.js +87 -0
  35. package/dist/cjs/Sprinkle/actions/builtin/settings-actions.js.map +1 -0
  36. package/dist/cjs/Sprinkle/actions/builtin/transaction-actions.js +345 -0
  37. package/dist/cjs/Sprinkle/actions/builtin/transaction-actions.js.map +1 -0
  38. package/dist/cjs/Sprinkle/actions/builtin/utility-actions.js +218 -0
  39. package/dist/cjs/Sprinkle/actions/builtin/utility-actions.js.map +1 -0
  40. package/dist/cjs/Sprinkle/actions/builtin/wallet-actions.js +212 -0
  41. package/dist/cjs/Sprinkle/actions/builtin/wallet-actions.js.map +1 -0
  42. package/dist/cjs/Sprinkle/actions/cli-adapter.js +390 -0
  43. package/dist/cjs/Sprinkle/actions/cli-adapter.js.map +1 -0
  44. package/dist/cjs/Sprinkle/actions/index.js +139 -0
  45. package/dist/cjs/Sprinkle/actions/index.js.map +1 -0
  46. package/dist/cjs/Sprinkle/actions/mcp-adapter.js +557 -0
  47. package/dist/cjs/Sprinkle/actions/mcp-adapter.js.map +1 -0
  48. package/dist/cjs/Sprinkle/actions/registry.js +92 -0
  49. package/dist/cjs/Sprinkle/actions/registry.js.map +1 -0
  50. package/dist/cjs/Sprinkle/actions/runner.js +190 -0
  51. package/dist/cjs/Sprinkle/actions/runner.js.map +1 -0
  52. package/dist/cjs/Sprinkle/actions/tui-helpers.js +96 -0
  53. package/dist/cjs/Sprinkle/actions/tui-helpers.js.map +1 -0
  54. package/dist/cjs/Sprinkle/actions/types.js +68 -0
  55. package/dist/cjs/Sprinkle/actions/types.js.map +1 -0
  56. package/dist/cjs/Sprinkle/index.js +678 -5
  57. package/dist/cjs/Sprinkle/index.js.map +1 -1
  58. package/dist/cjs/Sprinkle/prompts.js +12 -7
  59. package/dist/cjs/Sprinkle/prompts.js.map +1 -1
  60. package/dist/cjs/Sprinkle/schemas.js +17 -1
  61. package/dist/cjs/Sprinkle/schemas.js.map +1 -1
  62. package/dist/cjs/Sprinkle/type-guards.js +7 -1
  63. package/dist/cjs/Sprinkle/type-guards.js.map +1 -1
  64. package/dist/esm/Sprinkle/__tests__/action-integration.test.js +588 -0
  65. package/dist/esm/Sprinkle/__tests__/action-integration.test.js.map +1 -0
  66. package/dist/esm/Sprinkle/__tests__/action-registry.test.js +192 -0
  67. package/dist/esm/Sprinkle/__tests__/action-registry.test.js.map +1 -0
  68. package/dist/esm/Sprinkle/__tests__/action-runner.test.js +302 -0
  69. package/dist/esm/Sprinkle/__tests__/action-runner.test.js.map +1 -0
  70. package/dist/esm/Sprinkle/__tests__/builtin-actions.test.js +1107 -0
  71. package/dist/esm/Sprinkle/__tests__/builtin-actions.test.js.map +1 -0
  72. package/dist/esm/Sprinkle/__tests__/cli-adapter.test.js +742 -0
  73. package/dist/esm/Sprinkle/__tests__/cli-adapter.test.js.map +1 -0
  74. package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js +15 -1
  75. package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
  76. package/dist/esm/Sprinkle/__tests__/mcp-adapter.test.js +710 -0
  77. package/dist/esm/Sprinkle/__tests__/mcp-adapter.test.js.map +1 -0
  78. package/dist/esm/Sprinkle/__tests__/native-script.test.js +388 -0
  79. package/dist/esm/Sprinkle/__tests__/native-script.test.js.map +1 -0
  80. package/dist/esm/Sprinkle/__tests__/tui-helpers.test.js +332 -0
  81. package/dist/esm/Sprinkle/__tests__/tui-helpers.test.js.map +1 -0
  82. package/dist/esm/Sprinkle/__tests__/utility-actions.test.js +365 -0
  83. package/dist/esm/Sprinkle/__tests__/utility-actions.test.js.map +1 -0
  84. package/dist/esm/Sprinkle/__tests__/wallet-transaction-actions.test.js +747 -0
  85. package/dist/esm/Sprinkle/__tests__/wallet-transaction-actions.test.js.map +1 -0
  86. package/dist/esm/Sprinkle/actions/builtin/addressbook-actions.js +159 -0
  87. package/dist/esm/Sprinkle/actions/builtin/addressbook-actions.js.map +1 -0
  88. package/dist/esm/Sprinkle/actions/builtin/blaze-helper.js +55 -0
  89. package/dist/esm/Sprinkle/actions/builtin/blaze-helper.js.map +1 -0
  90. package/dist/esm/Sprinkle/actions/builtin/index.js +37 -0
  91. package/dist/esm/Sprinkle/actions/builtin/index.js.map +1 -0
  92. package/dist/esm/Sprinkle/actions/builtin/native-script.js +133 -0
  93. package/dist/esm/Sprinkle/actions/builtin/native-script.js.map +1 -0
  94. package/dist/esm/Sprinkle/actions/builtin/profile-actions.js +197 -0
  95. package/dist/esm/Sprinkle/actions/builtin/profile-actions.js.map +1 -0
  96. package/dist/esm/Sprinkle/actions/builtin/settings-actions.js +81 -0
  97. package/dist/esm/Sprinkle/actions/builtin/settings-actions.js.map +1 -0
  98. package/dist/esm/Sprinkle/actions/builtin/transaction-actions.js +340 -0
  99. package/dist/esm/Sprinkle/actions/builtin/transaction-actions.js.map +1 -0
  100. package/dist/esm/Sprinkle/actions/builtin/utility-actions.js +213 -0
  101. package/dist/esm/Sprinkle/actions/builtin/utility-actions.js.map +1 -0
  102. package/dist/esm/Sprinkle/actions/builtin/wallet-actions.js +207 -0
  103. package/dist/esm/Sprinkle/actions/builtin/wallet-actions.js.map +1 -0
  104. package/dist/esm/Sprinkle/actions/cli-adapter.js +379 -0
  105. package/dist/esm/Sprinkle/actions/cli-adapter.js.map +1 -0
  106. package/dist/esm/Sprinkle/actions/index.js +12 -0
  107. package/dist/esm/Sprinkle/actions/index.js.map +1 -0
  108. package/dist/esm/Sprinkle/actions/mcp-adapter.js +547 -0
  109. package/dist/esm/Sprinkle/actions/mcp-adapter.js.map +1 -0
  110. package/dist/esm/Sprinkle/actions/registry.js +85 -0
  111. package/dist/esm/Sprinkle/actions/registry.js.map +1 -0
  112. package/dist/esm/Sprinkle/actions/runner.js +182 -0
  113. package/dist/esm/Sprinkle/actions/runner.js.map +1 -0
  114. package/dist/esm/Sprinkle/actions/tui-helpers.js +91 -0
  115. package/dist/esm/Sprinkle/actions/tui-helpers.js.map +1 -0
  116. package/dist/esm/Sprinkle/actions/types.js +61 -0
  117. package/dist/esm/Sprinkle/actions/types.js.map +1 -0
  118. package/dist/esm/Sprinkle/index.js +517 -7
  119. package/dist/esm/Sprinkle/index.js.map +1 -1
  120. package/dist/esm/Sprinkle/prompts.js +12 -7
  121. package/dist/esm/Sprinkle/prompts.js.map +1 -1
  122. package/dist/esm/Sprinkle/schemas.js +16 -0
  123. package/dist/esm/Sprinkle/schemas.js.map +1 -1
  124. package/dist/esm/Sprinkle/type-guards.js +3 -0
  125. package/dist/esm/Sprinkle/type-guards.js.map +1 -1
  126. package/dist/types/Sprinkle/actions/builtin/addressbook-actions.d.ts +50 -0
  127. package/dist/types/Sprinkle/actions/builtin/addressbook-actions.d.ts.map +1 -0
  128. package/dist/types/Sprinkle/actions/builtin/blaze-helper.d.ts +39 -0
  129. package/dist/types/Sprinkle/actions/builtin/blaze-helper.d.ts.map +1 -0
  130. package/dist/types/Sprinkle/actions/builtin/index.d.ts +30 -0
  131. package/dist/types/Sprinkle/actions/builtin/index.d.ts.map +1 -0
  132. package/dist/types/Sprinkle/actions/builtin/native-script.d.ts +27 -0
  133. package/dist/types/Sprinkle/actions/builtin/native-script.d.ts.map +1 -0
  134. package/dist/types/Sprinkle/actions/builtin/profile-actions.d.ts +55 -0
  135. package/dist/types/Sprinkle/actions/builtin/profile-actions.d.ts.map +1 -0
  136. package/dist/types/Sprinkle/actions/builtin/settings-actions.d.ts +32 -0
  137. package/dist/types/Sprinkle/actions/builtin/settings-actions.d.ts.map +1 -0
  138. package/dist/types/Sprinkle/actions/builtin/transaction-actions.d.ts +70 -0
  139. package/dist/types/Sprinkle/actions/builtin/transaction-actions.d.ts.map +1 -0
  140. package/dist/types/Sprinkle/actions/builtin/utility-actions.d.ts +48 -0
  141. package/dist/types/Sprinkle/actions/builtin/utility-actions.d.ts.map +1 -0
  142. package/dist/types/Sprinkle/actions/builtin/wallet-actions.d.ts +50 -0
  143. package/dist/types/Sprinkle/actions/builtin/wallet-actions.d.ts.map +1 -0
  144. package/dist/types/Sprinkle/actions/cli-adapter.d.ts +104 -0
  145. package/dist/types/Sprinkle/actions/cli-adapter.d.ts.map +1 -0
  146. package/dist/types/Sprinkle/actions/index.d.ts +13 -0
  147. package/dist/types/Sprinkle/actions/index.d.ts.map +1 -0
  148. package/dist/types/Sprinkle/actions/mcp-adapter.d.ts +116 -0
  149. package/dist/types/Sprinkle/actions/mcp-adapter.d.ts.map +1 -0
  150. package/dist/types/Sprinkle/actions/registry.d.ts +42 -0
  151. package/dist/types/Sprinkle/actions/registry.d.ts.map +1 -0
  152. package/dist/types/Sprinkle/actions/runner.d.ts +45 -0
  153. package/dist/types/Sprinkle/actions/runner.d.ts.map +1 -0
  154. package/dist/types/Sprinkle/actions/tui-helpers.d.ts +53 -0
  155. package/dist/types/Sprinkle/actions/tui-helpers.d.ts.map +1 -0
  156. package/dist/types/Sprinkle/actions/types.d.ts +76 -0
  157. package/dist/types/Sprinkle/actions/types.d.ts.map +1 -0
  158. package/dist/types/Sprinkle/index.d.ts +84 -2
  159. package/dist/types/Sprinkle/index.d.ts.map +1 -1
  160. package/dist/types/Sprinkle/prompts.d.ts.map +1 -1
  161. package/dist/types/Sprinkle/schemas.d.ts +72 -0
  162. package/dist/types/Sprinkle/schemas.d.ts.map +1 -1
  163. package/dist/types/Sprinkle/type-guards.d.ts +4 -1
  164. package/dist/types/Sprinkle/type-guards.d.ts.map +1 -1
  165. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  166. package/package.json +9 -2
  167. package/src/Sprinkle/__tests__/action-integration.test.ts +558 -0
  168. package/src/Sprinkle/__tests__/action-registry.test.ts +187 -0
  169. package/src/Sprinkle/__tests__/action-runner.test.ts +324 -0
  170. package/src/Sprinkle/__tests__/builtin-actions.test.ts +1022 -0
  171. package/src/Sprinkle/__tests__/cli-adapter.test.ts +736 -0
  172. package/src/Sprinkle/__tests__/fill-in-struct.test.ts +23 -1
  173. package/src/Sprinkle/__tests__/mcp-adapter.test.ts +720 -0
  174. package/src/Sprinkle/__tests__/native-script.test.ts +341 -0
  175. package/src/Sprinkle/__tests__/tui-helpers.test.ts +325 -0
  176. package/src/Sprinkle/__tests__/utility-actions.test.ts +348 -0
  177. package/src/Sprinkle/__tests__/wallet-transaction-actions.test.ts +695 -0
  178. package/src/Sprinkle/actions/builtin/addressbook-actions.ts +168 -0
  179. package/src/Sprinkle/actions/builtin/blaze-helper.ts +89 -0
  180. package/src/Sprinkle/actions/builtin/index.ts +125 -0
  181. package/src/Sprinkle/actions/builtin/native-script.ts +165 -0
  182. package/src/Sprinkle/actions/builtin/profile-actions.ts +229 -0
  183. package/src/Sprinkle/actions/builtin/settings-actions.ts +99 -0
  184. package/src/Sprinkle/actions/builtin/transaction-actions.ts +381 -0
  185. package/src/Sprinkle/actions/builtin/utility-actions.ts +285 -0
  186. package/src/Sprinkle/actions/builtin/wallet-actions.ts +233 -0
  187. package/src/Sprinkle/actions/cli-adapter.ts +446 -0
  188. package/src/Sprinkle/actions/index.ts +33 -0
  189. package/src/Sprinkle/actions/mcp-adapter.ts +638 -0
  190. package/src/Sprinkle/actions/registry.ts +97 -0
  191. package/src/Sprinkle/actions/runner.ts +200 -0
  192. package/src/Sprinkle/actions/tui-helpers.ts +114 -0
  193. package/src/Sprinkle/actions/types.ts +91 -0
  194. package/src/Sprinkle/index.ts +612 -3
  195. package/src/Sprinkle/prompts.ts +118 -72
  196. package/src/Sprinkle/schemas.ts +20 -0
  197. package/src/Sprinkle/type-guards.ts +9 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-actions.js","names":["Type","Core","ActionError","getBlazeFromContext","isHotWallet","countSignatures","getRequiredSigners","TokenEntrySchema","Object","policyId","String","description","assetName","quantity","parseTxCbor","txCbor","Transaction","fromCbor","TxCBOR","err","Error","message","error","signTransaction","name","category","inputSchema","outputSchema","signedTxCbor","txHash","signatureCount","Number","execute","input","context","blaze","tx","signedTx","toCbor","body","hash","toString","submitTransaction","submitted","Boolean","signAndSubmit","waitForConfirmation","Optional","default","confirmationTimeout","confirmed","txHashStr","timeoutSeconds","deadline","Date","now","pollIntervalMs","Promise","resolve","setTimeout","utxos","provider","getUnspentOutputs","wallet","getChangeAddress","anyMatch","some","u","transactionId","decodeTransaction","inputs","Array","outputIndex","outputs","address","lovelace","tokens","fee","requiredSigners","_context","inputSet","from","values","map","txInput","index","txOutput","value","amount","multiasset","assetId","entries","push","AssetId","getPolicyId","getAssetName","toBech32","toBytes","coin"],"sources":["../../../../../src/Sprinkle/actions/builtin/transaction-actions.ts"],"sourcesContent":["/**\n * Built-in transaction actions for the Sprinkle action system.\n * These actions expose transaction signing, submission, and decoding\n * as non-interactive actions available in CLI and MCP modes.\n *\n * Sign/submit actions use category \"wallet\".\n * The decode action uses category \"transaction\" (no wallet required).\n */\n\nimport { Type } from \"@sinclair/typebox\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { Core } from \"@blaze-cardano/sdk\";\nimport { ActionError } from \"../types.js\";\nimport type { IAction } from \"../types.js\";\nimport { getBlazeFromContext, isHotWallet } from \"./blaze-helper.js\";\nimport { countSignatures, getRequiredSigners } from \"../../tx-dialog.js\";\n\n/** Shared token entry schema (also used in wallet-actions) */\nconst TokenEntrySchema = Type.Object({\n policyId: Type.String({ description: \"Policy ID of the token\" }),\n assetName: Type.String({ description: \"Asset name of the token (hex)\" }),\n quantity: Type.String({ description: \"Token quantity as string (BigInt-safe)\" }),\n});\n\n/**\n * Parses a hex CBOR string into a `Core.Transaction`.\n * Throws `ActionError(\"INVALID_CBOR\")` if the string is not valid transaction CBOR.\n */\nfunction parseTxCbor(txCbor: string): Core.Transaction {\n try {\n return Core.Transaction.fromCbor(Core.TxCBOR(txCbor));\n } catch (err) {\n throw new ActionError(\n `Invalid transaction CBOR: ${err instanceof Error ? err.message : String(err)}`,\n \"INVALID_CBOR\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n}\n\n/**\n * `sign-transaction` -- Signs a transaction with the configured hot wallet.\n * Cold wallets cannot sign; use an external signing tool and submit the result.\n */\nexport const signTransaction: IAction<\n { txCbor: string },\n { signedTxCbor: string; txHash: string; signatureCount: number },\n TSchema\n> = {\n name: \"sign-transaction\",\n description:\n \"Sign a transaction with the configured hot wallet. Requires a hot wallet; cold wallets cannot sign.\",\n category: \"wallet\",\n inputSchema: Type.Object({\n txCbor: Type.String({ description: \"Transaction CBOR hex string to sign\" }),\n }),\n outputSchema: Type.Object({\n signedTxCbor: Type.String({ description: \"Signed transaction CBOR hex\" }),\n txHash: Type.String({ description: \"Transaction hash\" }),\n signatureCount: Type.Number({ description: \"Number of VKey witnesses after signing\" }),\n }),\n execute: async (input, context) => {\n const blaze = await getBlazeFromContext(context);\n\n if (!isHotWallet(blaze)) {\n throw new ActionError(\n \"Cold wallets cannot sign transactions. Export the CBOR and sign externally, then use submit-transaction.\",\n \"COLD_WALLET\",\n );\n }\n\n const tx = parseTxCbor(input.txCbor);\n\n let signedTx: Core.Transaction;\n try {\n signedTx = await blaze.signTransaction(tx);\n } catch (err) {\n throw new ActionError(\n `Failed to sign transaction: ${err instanceof Error ? err.message : String(err)}`,\n \"SIGN_ERROR\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n return {\n signedTxCbor: signedTx.toCbor(),\n txHash: signedTx.body().hash().toString(),\n signatureCount: countSignatures(signedTx),\n };\n },\n};\n\n/**\n * `submit-transaction` -- Submits a signed transaction to the blockchain.\n */\nexport const submitTransaction: IAction<\n { txCbor: string },\n { txHash: string; submitted: boolean },\n TSchema\n> = {\n name: \"submit-transaction\",\n description: \"Submit a signed transaction to the blockchain.\",\n category: \"wallet\",\n inputSchema: Type.Object({\n txCbor: Type.String({ description: \"Signed transaction CBOR hex string to submit\" }),\n }),\n outputSchema: Type.Object({\n txHash: Type.String({ description: \"Submitted transaction hash\" }),\n submitted: Type.Boolean(),\n }),\n execute: async (input, context) => {\n const blaze = await getBlazeFromContext(context);\n const tx = parseTxCbor(input.txCbor);\n\n let txHash: Core.TransactionId;\n try {\n txHash = await blaze.submitTransaction(tx);\n } catch (err) {\n throw new ActionError(\n `Transaction submission failed: ${err instanceof Error ? err.message : String(err)}`,\n \"SUBMISSION_ERROR\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n return {\n txHash: txHash.toString(),\n submitted: true,\n };\n },\n};\n\n/**\n * `sign-and-submit` -- Signs a transaction and immediately submits it.\n * Optionally waits for on-chain confirmation with a configurable timeout.\n */\nexport const signAndSubmit: IAction<\n {\n txCbor: string;\n waitForConfirmation?: boolean;\n confirmationTimeout?: number;\n },\n {\n txHash: string;\n submitted: boolean;\n confirmed?: boolean;\n signedTxCbor: string;\n },\n TSchema\n> = {\n name: \"sign-and-submit\",\n description:\n \"Sign and submit a transaction. Optionally wait for on-chain confirmation.\",\n category: \"wallet\",\n inputSchema: Type.Object({\n txCbor: Type.String({ description: \"Transaction CBOR hex string to sign and submit\" }),\n waitForConfirmation: Type.Optional(\n Type.Boolean({\n default: false,\n description: \"Whether to wait for on-chain confirmation before returning\",\n }),\n ),\n confirmationTimeout: Type.Optional(\n Type.Number({\n default: 60,\n description: \"Timeout in seconds to wait for confirmation\",\n }),\n ),\n }),\n outputSchema: Type.Object({\n txHash: Type.String({ description: \"Transaction hash\" }),\n submitted: Type.Boolean(),\n confirmed: Type.Optional(Type.Boolean({ description: \"Whether tx was confirmed on-chain\" })),\n signedTxCbor: Type.String({ description: \"Signed transaction CBOR hex\" }),\n }),\n execute: async (input, context) => {\n const blaze = await getBlazeFromContext(context);\n\n if (!isHotWallet(blaze)) {\n throw new ActionError(\n \"Cold wallets cannot sign transactions. Export the CBOR and sign externally, then use submit-transaction.\",\n \"COLD_WALLET\",\n );\n }\n\n const tx = parseTxCbor(input.txCbor);\n\n // Sign\n let signedTx: Core.Transaction;\n try {\n signedTx = await blaze.signTransaction(tx);\n } catch (err) {\n throw new ActionError(\n `Failed to sign transaction: ${err instanceof Error ? err.message : String(err)}`,\n \"SIGN_ERROR\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n const signedTxCbor = signedTx.toCbor();\n\n // Submit\n let txHash: Core.TransactionId;\n try {\n txHash = await blaze.submitTransaction(signedTx);\n } catch (err) {\n throw new ActionError(\n `Transaction submission failed: ${err instanceof Error ? err.message : String(err)}`,\n \"SUBMISSION_ERROR\",\n { error: err instanceof Error ? err.message : String(err), signedTxCbor },\n );\n }\n\n const txHashStr = txHash.toString();\n\n // If confirmation not requested, return immediately\n if (!input.waitForConfirmation) {\n return {\n txHash: txHashStr,\n submitted: true,\n signedTxCbor,\n };\n }\n\n // Poll for confirmation\n const timeoutSeconds = input.confirmationTimeout ?? 60;\n const deadline = Date.now() + timeoutSeconds * 1000;\n const pollIntervalMs = 5000; // 5 seconds between polls\n\n let confirmed = false;\n while (Date.now() < deadline) {\n await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));\n try {\n // Query UTxOs and check if any reference this tx hash\n // This is a lightweight confirmation check using the provider\n const utxos = await blaze.provider.getUnspentOutputs(\n await blaze.wallet.getChangeAddress(),\n );\n // If provider returns without error and tx hash appears in a UTxO input or\n // the query succeeds after submission, assume confirmed.\n // A more precise check would be to look up the tx directly.\n // Use resolveUnspentOutputs if available, otherwise accept the provider response.\n const anyMatch = utxos.some(\n (u) => u.input().transactionId().toString() === txHashStr,\n );\n // If we get a fresh UTxO referencing our tx, confirmed\n if (anyMatch) {\n confirmed = true;\n break;\n }\n // Check if we got back any UTxOs at all - for a send transaction the\n // change output should be visible once confirmed\n // Fall through and keep polling\n } catch {\n // Provider error during poll -- keep trying until timeout\n }\n }\n\n if (!confirmed && input.waitForConfirmation) {\n // Return partial success rather than throwing -- tx was submitted successfully\n // but we couldn't confirm within the timeout\n return {\n txHash: txHashStr,\n submitted: true,\n confirmed: false,\n signedTxCbor,\n };\n }\n\n return {\n txHash: txHashStr,\n submitted: true,\n confirmed,\n signedTxCbor,\n };\n },\n};\n\n/**\n * `decode-transaction` -- Decodes a transaction CBOR hex without requiring a wallet.\n * Extracts inputs, outputs, fee, witness count, and required signers from the tx body.\n */\nexport const decodeTransaction: IAction<\n { txCbor: string },\n {\n txHash: string;\n inputs: Array<{ txHash: string; outputIndex: number }>;\n outputs: Array<{\n address: string;\n lovelace: string;\n tokens: Array<{ policyId: string; assetName: string; quantity: string }>;\n }>;\n fee: string;\n signatureCount: number;\n requiredSigners: string[];\n },\n TSchema\n> = {\n name: \"decode-transaction\",\n description:\n \"Decode a transaction CBOR hex and return its inputs, outputs, fee, and signers. Does not require a wallet.\",\n category: \"transaction\",\n inputSchema: Type.Object({\n txCbor: Type.String({ description: \"Transaction CBOR hex string to decode\" }),\n }),\n outputSchema: Type.Object({\n txHash: Type.String({ description: \"Transaction body hash\" }),\n inputs: Type.Array(\n Type.Object({\n txHash: Type.String({ description: \"Input transaction hash\" }),\n outputIndex: Type.Number({ description: \"Input output index\" }),\n }),\n ),\n outputs: Type.Array(\n Type.Object({\n address: Type.String({ description: \"Output address (bech32 or hex)\" }),\n lovelace: Type.String({ description: \"Output lovelace amount as string\" }),\n tokens: Type.Array(TokenEntrySchema),\n }),\n ),\n fee: Type.String({ description: \"Transaction fee in lovelace as string\" }),\n signatureCount: Type.Number({ description: \"Number of VKey witnesses\" }),\n requiredSigners: Type.Array(\n Type.String({ description: \"Required signer key hashes\" }),\n ),\n }),\n execute: async (input, _context) => {\n // No Blaze instance needed -- pure CBOR parsing\n const tx = parseTxCbor(input.txCbor);\n\n const body = tx.body();\n const txHash = body.hash().toString();\n\n // Extract inputs\n const inputSet = body.inputs();\n const inputs = Array.from(inputSet.values()).map((txInput) => ({\n txHash: txInput.transactionId().toString(),\n outputIndex: Number(txInput.index()),\n }));\n\n // Extract outputs\n const outputs = body.outputs().map((txOutput) => {\n const value = txOutput.amount();\n const tokens: Array<{ policyId: string; assetName: string; quantity: string }> = [];\n\n const multiasset = value.multiasset();\n if (multiasset) {\n for (const [assetId, quantity] of multiasset.entries()) {\n tokens.push({\n policyId: Core.AssetId.getPolicyId(assetId),\n assetName: Core.AssetId.getAssetName(assetId),\n quantity: quantity.toString(),\n });\n }\n }\n\n // Attempt bech32 address, fall back to hex if conversion fails\n let address: string;\n try {\n address = txOutput.address().toBech32();\n } catch {\n address = txOutput.address().toBytes();\n }\n\n return {\n address,\n lovelace: value.coin().toString(),\n tokens,\n };\n });\n\n return {\n txHash,\n inputs,\n outputs,\n fee: body.fee().toString(),\n signatureCount: countSignatures(tx),\n requiredSigners: getRequiredSigners(tx),\n };\n },\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,QAAQ,mBAAmB;AAExC,SAASC,IAAI,QAAQ,oBAAoB;AACzC,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,mBAAmB,EAAEC,WAAW,QAAQ,mBAAmB;AACpE,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,oBAAoB;;AAExE;AACA,MAAMC,gBAAgB,GAAGP,IAAI,CAACQ,MAAM,CAAC;EACnCC,QAAQ,EAAET,IAAI,CAACU,MAAM,CAAC;IAAEC,WAAW,EAAE;EAAyB,CAAC,CAAC;EAChEC,SAAS,EAAEZ,IAAI,CAACU,MAAM,CAAC;IAAEC,WAAW,EAAE;EAAgC,CAAC,CAAC;EACxEE,QAAQ,EAAEb,IAAI,CAACU,MAAM,CAAC;IAAEC,WA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ExE,kBAAkB,CAAC8B,EAAE;IACxC,CAAC;EACH;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Built-in utility actions for the Sprinkle action system.
3
+ * These actions provide common Cardano operations: minting tokens,
4
+ * sending ADA/tokens, and registering stake scripts.
5
+ */
6
+
7
+ import { Type } from "@sinclair/typebox";
8
+ import { Core, makeValue } from "@blaze-cardano/sdk";
9
+ import { ActionError } from "../types.js";
10
+ import { getBlazeFromContext, isHotWallet } from "./blaze-helper.js";
11
+ import { NativeScriptsParam } from "../../schemas.js";
12
+ import { completeWithScripts } from "./native-script.js";
13
+
14
+ /**
15
+ * `mint-token` -- Mint native tokens using a native script derived from the wallet's payment key.
16
+ * The policy is a simple ScriptPubkey requiring the wallet's payment credential to sign.
17
+ * Requires a hot wallet.
18
+ */
19
+ export const mintToken = {
20
+ name: "mint-token",
21
+ description: "Mint native tokens using a native script policy derived from the wallet's payment key.",
22
+ category: "utility",
23
+ inputSchema: Type.Object({
24
+ tokenName: Type.String({
25
+ description: "Name of the token to mint"
26
+ }),
27
+ amount: Type.String({
28
+ description: "Amount of tokens to mint (as string for BigInt safety)"
29
+ }),
30
+ nativeScripts: NativeScriptsParam
31
+ }),
32
+ outputSchema: Type.Object({
33
+ policyId: Type.String({
34
+ description: "Policy ID of the minted token"
35
+ }),
36
+ tokenName: Type.String({
37
+ description: "Token name"
38
+ }),
39
+ amount: Type.String({
40
+ description: "Amount minted"
41
+ }),
42
+ txCbor: Type.String({
43
+ description: "Unsigned transaction CBOR hex ready for signing"
44
+ })
45
+ }),
46
+ execute: async (input, context) => {
47
+ const blaze = await getBlazeFromContext(context);
48
+ if (!isHotWallet(blaze)) {
49
+ throw new ActionError("Mint token requires a hot wallet to derive the native script policy.", "COLD_WALLET");
50
+ }
51
+
52
+ // Get the wallet's payment credential hash for the native script
53
+ let address;
54
+ try {
55
+ address = await blaze.wallet.getChangeAddress();
56
+ } catch (err) {
57
+ throw new ActionError(`Failed to get wallet address: ${err instanceof Error ? err.message : String(err)}`, "NO_ADDRESS", {
58
+ error: err instanceof Error ? err.message : String(err)
59
+ });
60
+ }
61
+ const baseAddress = address.asBase();
62
+ if (!baseAddress) {
63
+ throw new ActionError("Could not derive base address from wallet. Ensure the wallet has a payment credential.", "INVALID_ADDRESS");
64
+ }
65
+ const paymentCredential = baseAddress.getPaymentCredential();
66
+ if (!paymentCredential?.hash) {
67
+ throw new ActionError("Could not extract payment credential hash from wallet address.", "NO_PAYMENT_CREDENTIAL");
68
+ }
69
+ const hash = Core.Ed25519KeyHashHex(paymentCredential.hash.toString());
70
+ const tokenPolicy = new Core.ScriptPubkey(hash);
71
+ const policy = Core.Script.newNativeScript(Core.NativeScript.newScriptPubkey(tokenPolicy));
72
+ const policyId = policy.hash();
73
+ const assetName = Core.AssetName(Core.toHex(Buffer.from(input.tokenName)));
74
+ const mintAmount = BigInt(input.amount);
75
+ const mints = new Map();
76
+ mints.set(assetName, mintAmount);
77
+ let tx;
78
+ try {
79
+ const txBuilder = blaze.newTransaction().addMint(Core.PolicyId(policyId), mints).provideScript(policy);
80
+ tx = await completeWithScripts(txBuilder, input.nativeScripts, context);
81
+ } catch (err) {
82
+ if (err instanceof ActionError) throw err;
83
+ throw new ActionError(`Failed to build mint transaction: ${err instanceof Error ? err.message : String(err)}`, "BUILD_ERROR", {
84
+ error: err instanceof Error ? err.message : String(err)
85
+ });
86
+ }
87
+ return {
88
+ policyId: policyId.toString(),
89
+ tokenName: input.tokenName,
90
+ amount: input.amount,
91
+ txCbor: tx.toCbor()
92
+ };
93
+ }
94
+ };
95
+
96
+ /**
97
+ * `simple-send` -- Send ADA or a native token to a recipient address.
98
+ * Builds an unsigned transaction that can be signed via TxDialog or sign-transaction.
99
+ */
100
+ export const simpleSend = {
101
+ name: "simple-send",
102
+ description: "Send ADA or a native token to a recipient address.",
103
+ category: "wallet",
104
+ inputSchema: Type.Object({
105
+ recipientAddress: Type.String({
106
+ description: "Bech32 recipient address"
107
+ }),
108
+ lovelace: Type.Optional(Type.String({
109
+ description: "Amount of lovelace to send (as string for BigInt safety). Required if not sending a token."
110
+ })),
111
+ policyId: Type.Optional(Type.String({
112
+ description: "Policy ID of the token to send"
113
+ })),
114
+ assetName: Type.Optional(Type.String({
115
+ description: "Asset name of the token to send (hex-encoded)"
116
+ })),
117
+ tokenAmount: Type.Optional(Type.String({
118
+ description: "Amount of tokens to send (as string for BigInt safety)"
119
+ })),
120
+ nativeScripts: NativeScriptsParam
121
+ }),
122
+ outputSchema: Type.Object({
123
+ txCbor: Type.String({
124
+ description: "Unsigned transaction CBOR hex ready for signing"
125
+ })
126
+ }),
127
+ execute: async (input, context) => {
128
+ const blaze = await getBlazeFromContext(context);
129
+
130
+ // Validate: must provide lovelace or token details
131
+ const hasToken = input.policyId && input.assetName && input.tokenAmount;
132
+ if (!input.lovelace && !hasToken) {
133
+ throw new ActionError("Must provide either lovelace amount or token details (policyId, assetName, tokenAmount).", "INVALID_INPUT");
134
+ }
135
+ let recipient;
136
+ try {
137
+ recipient = Core.Address.fromBech32(input.recipientAddress);
138
+ } catch (err) {
139
+ throw new ActionError(`Invalid recipient address: ${err instanceof Error ? err.message : String(err)}`, "INVALID_ADDRESS", {
140
+ error: err instanceof Error ? err.message : String(err)
141
+ });
142
+ }
143
+ let value;
144
+ if (hasToken) {
145
+ const assetId = `${input.policyId}${input.assetName}`;
146
+ value = makeValue(BigInt(input.lovelace ?? "0"), [assetId, BigInt(input.tokenAmount)]);
147
+ } else {
148
+ value = makeValue(BigInt(input.lovelace));
149
+ }
150
+ let tx;
151
+ try {
152
+ const txBuilder = blaze.newTransaction().payAssets(recipient, value);
153
+ tx = await completeWithScripts(txBuilder, input.nativeScripts, context);
154
+ } catch (err) {
155
+ if (err instanceof ActionError) throw err;
156
+ throw new ActionError(`Failed to build send transaction: ${err instanceof Error ? err.message : String(err)}`, "BUILD_ERROR", {
157
+ error: err instanceof Error ? err.message : String(err)
158
+ });
159
+ }
160
+ return {
161
+ txCbor: tx.toCbor()
162
+ };
163
+ }
164
+ };
165
+
166
+ /**
167
+ * `register-stake-script` -- Register a stake script credential on-chain.
168
+ * Takes a script hash and builds a stake registration transaction.
169
+ */
170
+ export const registerStakeScript = {
171
+ name: "register-stake-script",
172
+ description: "Register a stake script credential on-chain. Takes a script hash (hex) and builds the registration transaction.",
173
+ category: "utility",
174
+ inputSchema: Type.Object({
175
+ scriptHash: Type.String({
176
+ description: "Stake script hash in hex (28 bytes / 56 hex characters)"
177
+ }),
178
+ nativeScripts: NativeScriptsParam
179
+ }),
180
+ outputSchema: Type.Object({
181
+ txCbor: Type.String({
182
+ description: "Unsigned transaction CBOR hex ready for signing"
183
+ })
184
+ }),
185
+ execute: async (input, context) => {
186
+ const blaze = await getBlazeFromContext(context);
187
+
188
+ // Validate hex format
189
+ if (!/^[0-9a-fA-F]{56}$/.test(input.scriptHash)) {
190
+ throw new ActionError("Script hash must be exactly 56 hex characters (28 bytes).", "INVALID_SCRIPT_HASH", {
191
+ provided: input.scriptHash
192
+ });
193
+ }
194
+ const credential = Core.Credential.fromCore({
195
+ hash: Core.Hash28ByteBase16(input.scriptHash),
196
+ type: Core.CredentialType.ScriptHash
197
+ });
198
+ let tx;
199
+ try {
200
+ const txBuilder = blaze.newTransaction().addRegisterStake(credential);
201
+ tx = await completeWithScripts(txBuilder, input.nativeScripts, context);
202
+ } catch (err) {
203
+ if (err instanceof ActionError) throw err;
204
+ throw new ActionError(`Failed to build stake registration transaction: ${err instanceof Error ? err.message : String(err)}`, "BUILD_ERROR", {
205
+ error: err instanceof Error ? err.message : String(err)
206
+ });
207
+ }
208
+ return {
209
+ txCbor: tx.toCbor()
210
+ };
211
+ }
212
+ };
213
+ //# sourceMappingURL=utility-actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utility-actions.js","names":["Type","Core","makeValue","ActionError","getBlazeFromContext","isHotWallet","NativeScriptsParam","completeWithScripts","mintToken","name","description","category","inputSchema","Object","tokenName","String","amount","nativeScripts","outputSchema","policyId","txCbor","execute","input","context","blaze","address","wallet","getChangeAddress","err","Error","message","error","baseAddress","asBase","paymentCredential","getPaymentCredential","hash","Ed25519KeyHashHex","toString","tokenPolicy","ScriptPubkey","policy","Script","newNativeScript","NativeScript","newScriptPubkey","assetName","AssetName","toHex","Buffer","from","mintAmount","BigInt","mints","Map","set","tx","txBuilder","newTransaction","addMint","PolicyId","provideScript","toCbor","simpleSend","recipientAddress","lovelace","Optional","tokenAmount","hasToken","recipient","Address","fromBech32","value","assetId","payAssets","registerStakeScript","scriptHash","test","provided","credential","Credential","fromCore","Hash28ByteBase16","type","CredentialType","ScriptHash","addRegisterStake"],"sources":["../../../../../src/Sprinkle/actions/builtin/utility-actions.ts"],"sourcesContent":["/**\n * Built-in utility actions for the Sprinkle action system.\n * These actions provide common Cardano operations: minting tokens,\n * sending ADA/tokens, and registering stake scripts.\n */\n\nimport { Type } from \"@sinclair/typebox\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { Core, makeValue } from \"@blaze-cardano/sdk\";\nimport { ActionError } from \"../types.js\";\nimport type { IAction } from \"../types.js\";\nimport { getBlazeFromContext, isHotWallet } from \"./blaze-helper.js\";\nimport { NativeScriptsParam } from \"../../schemas.js\";\nimport type { NativeScriptInput } from \"./native-script.js\";\nimport { completeWithScripts } from \"./native-script.js\";\n\n/**\n * `mint-token` -- Mint native tokens using a native script derived from the wallet's payment key.\n * The policy is a simple ScriptPubkey requiring the wallet's payment credential to sign.\n * Requires a hot wallet.\n */\nexport const mintToken: IAction<\n { tokenName: string; amount: string; nativeScripts?: NativeScriptInput[] },\n { policyId: string; tokenName: string; amount: string; txCbor: string },\n TSchema\n> = {\n name: \"mint-token\",\n description:\n \"Mint native tokens using a native script policy derived from the wallet's payment key.\",\n category: \"utility\",\n inputSchema: Type.Object({\n tokenName: Type.String({ description: \"Name of the token to mint\" }),\n amount: Type.String({\n description: \"Amount of tokens to mint (as string for BigInt safety)\",\n }),\n nativeScripts: NativeScriptsParam,\n }),\n outputSchema: Type.Object({\n policyId: Type.String({ description: \"Policy ID of the minted token\" }),\n tokenName: Type.String({ description: \"Token name\" }),\n amount: Type.String({ description: \"Amount minted\" }),\n txCbor: Type.String({\n description: \"Unsigned transaction CBOR hex ready for signing\",\n }),\n }),\n execute: async (input, context) => {\n const blaze = await getBlazeFromContext(context);\n\n if (!isHotWallet(blaze)) {\n throw new ActionError(\n \"Mint token requires a hot wallet to derive the native script policy.\",\n \"COLD_WALLET\",\n );\n }\n\n // Get the wallet's payment credential hash for the native script\n let address: Core.Address;\n try {\n address = await blaze.wallet.getChangeAddress();\n } catch (err) {\n throw new ActionError(\n `Failed to get wallet address: ${err instanceof Error ? err.message : String(err)}`,\n \"NO_ADDRESS\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n const baseAddress = address.asBase();\n if (!baseAddress) {\n throw new ActionError(\n \"Could not derive base address from wallet. Ensure the wallet has a payment credential.\",\n \"INVALID_ADDRESS\",\n );\n }\n\n const paymentCredential = baseAddress.getPaymentCredential();\n if (!paymentCredential?.hash) {\n throw new ActionError(\n \"Could not extract payment credential hash from wallet address.\",\n \"NO_PAYMENT_CREDENTIAL\",\n );\n }\n\n const hash = Core.Ed25519KeyHashHex(paymentCredential.hash.toString());\n const tokenPolicy = new Core.ScriptPubkey(hash);\n const policy = Core.Script.newNativeScript(\n Core.NativeScript.newScriptPubkey(tokenPolicy),\n );\n\n const policyId = policy.hash();\n const assetName = Core.AssetName(\n Core.toHex(Buffer.from(input.tokenName)),\n );\n const mintAmount = BigInt(input.amount);\n\n const mints = new Map<Core.AssetName, bigint>();\n mints.set(assetName, mintAmount);\n\n let tx: Core.Transaction;\n try {\n const txBuilder = blaze\n .newTransaction()\n .addMint(Core.PolicyId(policyId), mints)\n .provideScript(policy);\n tx = await completeWithScripts(txBuilder, input.nativeScripts, context);\n } catch (err) {\n if (err instanceof ActionError) throw err;\n throw new ActionError(\n `Failed to build mint transaction: ${err instanceof Error ? err.message : String(err)}`,\n \"BUILD_ERROR\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n return {\n policyId: policyId.toString(),\n tokenName: input.tokenName,\n amount: input.amount,\n txCbor: tx.toCbor(),\n };\n },\n};\n\n/**\n * `simple-send` -- Send ADA or a native token to a recipient address.\n * Builds an unsigned transaction that can be signed via TxDialog or sign-transaction.\n */\nexport const simpleSend: IAction<\n {\n recipientAddress: string;\n lovelace?: string;\n policyId?: string;\n assetName?: string;\n tokenAmount?: string;\n nativeScripts?: NativeScriptInput[];\n },\n { txCbor: string },\n TSchema\n> = {\n name: \"simple-send\",\n description: \"Send ADA or a native token to a recipient address.\",\n category: \"wallet\",\n inputSchema: Type.Object({\n recipientAddress: Type.String({\n description: \"Bech32 recipient address\",\n }),\n lovelace: Type.Optional(\n Type.String({\n description:\n \"Amount of lovelace to send (as string for BigInt safety). Required if not sending a token.\",\n }),\n ),\n policyId: Type.Optional(\n Type.String({ description: \"Policy ID of the token to send\" }),\n ),\n assetName: Type.Optional(\n Type.String({\n description: \"Asset name of the token to send (hex-encoded)\",\n }),\n ),\n tokenAmount: Type.Optional(\n Type.String({\n description: \"Amount of tokens to send (as string for BigInt safety)\",\n }),\n ),\n nativeScripts: NativeScriptsParam,\n }),\n outputSchema: Type.Object({\n txCbor: Type.String({\n description: \"Unsigned transaction CBOR hex ready for signing\",\n }),\n }),\n execute: async (input, context) => {\n const blaze = await getBlazeFromContext(context);\n\n // Validate: must provide lovelace or token details\n const hasToken = input.policyId && input.assetName && input.tokenAmount;\n if (!input.lovelace && !hasToken) {\n throw new ActionError(\n \"Must provide either lovelace amount or token details (policyId, assetName, tokenAmount).\",\n \"INVALID_INPUT\",\n );\n }\n\n let recipient: Core.Address;\n try {\n recipient = Core.Address.fromBech32(input.recipientAddress);\n } catch (err) {\n throw new ActionError(\n `Invalid recipient address: ${err instanceof Error ? err.message : String(err)}`,\n \"INVALID_ADDRESS\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n let value: Core.Value;\n if (hasToken) {\n const assetId =\n `${input.policyId}${input.assetName}` as Core.AssetId;\n value = makeValue(\n BigInt(input.lovelace ?? \"0\"),\n [assetId, BigInt(input.tokenAmount!)],\n );\n } else {\n value = makeValue(BigInt(input.lovelace!));\n }\n\n let tx: Core.Transaction;\n try {\n const txBuilder = blaze.newTransaction().payAssets(recipient, value);\n tx = await completeWithScripts(txBuilder, input.nativeScripts, context);\n } catch (err) {\n if (err instanceof ActionError) throw err;\n throw new ActionError(\n `Failed to build send transaction: ${err instanceof Error ? err.message : String(err)}`,\n \"BUILD_ERROR\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n return {\n txCbor: tx.toCbor(),\n };\n },\n};\n\n/**\n * `register-stake-script` -- Register a stake script credential on-chain.\n * Takes a script hash and builds a stake registration transaction.\n */\nexport const registerStakeScript: IAction<\n { scriptHash: string; nativeScripts?: NativeScriptInput[] },\n { txCbor: string },\n TSchema\n> = {\n name: \"register-stake-script\",\n description:\n \"Register a stake script credential on-chain. Takes a script hash (hex) and builds the registration transaction.\",\n category: \"utility\",\n inputSchema: Type.Object({\n scriptHash: Type.String({\n description: \"Stake script hash in hex (28 bytes / 56 hex characters)\",\n }),\n nativeScripts: NativeScriptsParam,\n }),\n outputSchema: Type.Object({\n txCbor: Type.String({\n description: \"Unsigned transaction CBOR hex ready for signing\",\n }),\n }),\n execute: async (input, context) => {\n const blaze = await getBlazeFromContext(context);\n\n // Validate hex format\n if (!/^[0-9a-fA-F]{56}$/.test(input.scriptHash)) {\n throw new ActionError(\n \"Script hash must be exactly 56 hex characters (28 bytes).\",\n \"INVALID_SCRIPT_HASH\",\n { provided: input.scriptHash },\n );\n }\n\n const credential = Core.Credential.fromCore({\n hash: Core.Hash28ByteBase16(input.scriptHash),\n type: Core.CredentialType.ScriptHash,\n });\n\n let tx: Core.Transaction;\n try {\n const txBuilder = blaze.newTransaction().addRegisterStake(credential);\n tx = await completeWithScripts(txBuilder, input.nativeScripts, context);\n } catch (err) {\n if (err instanceof ActionError) throw err;\n throw new ActionError(\n `Failed to build stake registration transaction: ${err instanceof Error ? err.message : String(err)}`,\n \"BUILD_ERROR\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n return {\n txCbor: tx.toCbor(),\n };\n },\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,QAAQ,mBAAmB;AAExC,SAASC,IAAI,EAAEC,SAAS,QAAQ,oBAAoB;AACpD,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,mBAAmB,EAAEC,WAAW,QAAQ,mBAAmB;AACpE,SAASC,kBAAkB,QAAQ,kBAAkB;AAErD,SAASC,mBAAmB,QAAQ,oBAAoB;;AAExD;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAIZ,GAAG;EACFC,IAAI,EAAE,YAAY;EAClBC,WAAW,EACT,wFAAwF;EAC1FC,QAAQ,EAAE,SAAS;EACnBC,WAAW,EAAEZ,IAAI,CAACa,MAAM,CAAC;IACvBC,SAAS,EAAEd,IAAI,CAACe,MAAM,CAAC;MAAEL,WAAW,EAAE;IAA4B,CAAC,CAAC;IACpEM,MAAM,EAAEhB,IAAI,CAACe,MAAM,CAAC;MAClBL,WAAW,EAAE;IACf,CAAC,CAAC;IACFO,aAAa,EAAEX;EACjB,CAAC,CAAC;EACFY,YAAY,EAAElB,IAAI,CAACa,MAAM,CAAC;IACxBM,QAAQ,EAAEnB,IAAI,CAACe,MAAM,CAAC;MAAEL,WAAW,EAAE;IAAgC,CAAC,CAAC;IACvEI,SAAS,EAAEd,IAAI,CAACe,MAAM,CAAC;MAAEL,WAAW,EAAE;IAAa,CAAC,CAAC;IACrDM,MAAM,EAAEhB,IAAI,CAACe,MAAM,CAAC;MAAEL,WAAW,EAAE;IAAgB,CAAC,CAAC;IACrDU,MAAM,EAAEpB,IAAI,CAACe,MAAM,CAAC;MAClBL,WAAW,EAAE;IACf,CAAC;EACH,CAAC,CAAC;EACFW,OAAO,EAAE,MAAAA,CAAOC,KAA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AC;MAC7CO,IAAI,EAAElF,IAAI,CAACmF,cAAc,CAACC;IAC5B,CAAC,CAAC;IAEF,IAAI7B,EAAoB;IACxB,IAAI;MACF,MAAMC,SAAS,GAAGjC,KAAK,CAACkC,cAAc,CAAC,CAAC,CAAC4B,gBAAgB,CAACP,UAAU,CAAC;MACrEvB,EAAE,GAAG,MAAMjD,mBAAmB,CAACkD,SAAS,EAAEnC,KAAK,CAACL,aAAa,EAAEM,OAAO,CAAC;IACzE,CAAC,CAAC,OAAOK,GAAG,EAAE;MACZ,IAAIA,GAAG,YAAYzB,WAAW,EAAE,MAAMyB,GAAG;MACzC,MAAM,IAAIzB,WAAW,CACnB,mDAAmDyB,GAAG,YAAYC,KAAK,GAAGD,GAAG,CAACE,OAAO,GAAGf,MAAM,CAACa,GAAG,CAAC,EAAE,EACrG,aAAa,EACb;QAAEG,KAAK,EAAEH,GAAG,YAAYC,KAAK,GAAGD,GAAG,CAACE,OAAO,GAAGf,MAAM,CAACa,GAAG;MAAE,CAC5D,CAAC;IACH;IAEA,OAAO;MACLR,MAAM,EAAEoC,EAAE,CAACM,MAAM,CAAC;IACpB,CAAC;EACH;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Built-in wallet query actions for the Sprinkle action system.
3
+ * These actions expose wallet address, balance, and UTxO queries as
4
+ * non-interactive actions available in CLI and MCP modes.
5
+ *
6
+ * All actions use category "wallet".
7
+ */
8
+
9
+ import { Type } from "@sinclair/typebox";
10
+ import { Core } from "@blaze-cardano/sdk";
11
+ import { ActionError } from "../types.js";
12
+ import { getBlazeFromContext } from "./blaze-helper.js";
13
+
14
+ /** Shared token entry shape for balance and UTxO output */
15
+ const TokenEntrySchema = Type.Object({
16
+ policyId: Type.String({
17
+ description: "Policy ID of the token"
18
+ }),
19
+ assetName: Type.String({
20
+ description: "Asset name of the token (hex)"
21
+ }),
22
+ quantity: Type.String({
23
+ description: "Token quantity as string (BigInt-safe)"
24
+ })
25
+ });
26
+
27
+ /**
28
+ * `get-wallet-address` -- Returns the primary change address of the configured wallet.
29
+ */
30
+ export const getWalletAddress = {
31
+ name: "get-wallet-address",
32
+ description: "Get the primary address of the configured wallet.",
33
+ category: "wallet",
34
+ inputSchema: Type.Object({}),
35
+ outputSchema: Type.Object({
36
+ address: Type.String({
37
+ description: "Bech32-encoded payment/change address"
38
+ }),
39
+ network: Type.String({
40
+ description: "Network name (mainnet, preview, preprod)"
41
+ })
42
+ }),
43
+ execute: async (_input, context) => {
44
+ const blaze = await getBlazeFromContext(context);
45
+ let address;
46
+ try {
47
+ address = await blaze.wallet.getChangeAddress();
48
+ } catch (err) {
49
+ throw new ActionError(`Failed to get wallet address: ${err instanceof Error ? err.message : String(err)}`, "NO_ADDRESS", {
50
+ error: err instanceof Error ? err.message : String(err)
51
+ });
52
+ }
53
+ if (!address) {
54
+ throw new ActionError("The wallet returned no address. Ensure the wallet is properly configured.", "NO_ADDRESS");
55
+ }
56
+ const settings = context.settings;
57
+ const network = settings.network ?? "unknown";
58
+ return {
59
+ address: address.toBech32(),
60
+ network
61
+ };
62
+ }
63
+ };
64
+
65
+ /**
66
+ * `get-wallet-balance` -- Returns the ADA and token balance of the configured wallet.
67
+ * Aggregates lovelace and multi-asset amounts from all UTxOs.
68
+ * All quantities are returned as strings for BigInt-safe JSON serialization.
69
+ */
70
+ export const getWalletBalance = {
71
+ name: "get-wallet-balance",
72
+ description: "Get the ADA and token balance of the configured wallet. Quantities returned as strings.",
73
+ category: "wallet",
74
+ inputSchema: Type.Object({}),
75
+ outputSchema: Type.Object({
76
+ lovelace: Type.String({
77
+ description: "Total ADA balance in lovelace (as string for BigInt safety)"
78
+ }),
79
+ ada: Type.String({
80
+ description: "Total ADA balance as decimal string"
81
+ }),
82
+ tokens: Type.Array(TokenEntrySchema)
83
+ }),
84
+ execute: async (_input, context) => {
85
+ const blaze = await getBlazeFromContext(context);
86
+ let utxos;
87
+ try {
88
+ utxos = await blaze.wallet.getUnspentOutputs();
89
+ } catch (err) {
90
+ throw new ActionError(`Provider error while fetching UTxOs: ${err instanceof Error ? err.message : String(err)}`, "PROVIDER_ERROR", {
91
+ error: err instanceof Error ? err.message : String(err)
92
+ });
93
+ }
94
+
95
+ // Aggregate lovelace and token amounts
96
+ let totalLovelace = 0n;
97
+ const tokenMap = new Map(); // key: `${policyId}.${assetName}`
98
+
99
+ for (const utxo of utxos) {
100
+ const value = utxo.output().amount();
101
+ totalLovelace += value.coin();
102
+ const multiasset = value.multiasset();
103
+ if (multiasset) {
104
+ for (const [assetId, quantity] of multiasset.entries()) {
105
+ const policyId = Core.AssetId.getPolicyId(assetId);
106
+ const assetName = Core.AssetId.getAssetName(assetId);
107
+ const key = `${policyId}.${assetName}`;
108
+ tokenMap.set(key, (tokenMap.get(key) ?? 0n) + quantity);
109
+ }
110
+ }
111
+ }
112
+
113
+ // Convert tokens map to array, serializing BigInt quantities as strings
114
+ const tokens = Array.from(tokenMap.entries()).map(([key, quantity]) => {
115
+ const [policyId, assetName] = key.split(".");
116
+ return {
117
+ policyId: policyId ?? "",
118
+ assetName: assetName ?? "",
119
+ quantity: quantity.toString()
120
+ };
121
+ });
122
+
123
+ // ADA = lovelace / 1_000_000, with 6 decimal places
124
+ const adaWhole = totalLovelace / 1_000_000n;
125
+ const adaFraction = totalLovelace % 1_000_000n;
126
+ const ada = `${adaWhole}.${adaFraction.toString().padStart(6, "0")}`;
127
+ return {
128
+ lovelace: totalLovelace.toString(),
129
+ ada,
130
+ tokens
131
+ };
132
+ }
133
+ };
134
+
135
+ /**
136
+ * `get-wallet-utxos` -- Returns raw UTxO set for the configured wallet.
137
+ * Accepts an optional limit (default 100). Returns UTxOs and the total count.
138
+ */
139
+ export const getWalletUtxos = {
140
+ name: "get-wallet-utxos",
141
+ description: "Get the UTxO set for the configured wallet.",
142
+ category: "wallet",
143
+ inputSchema: Type.Object({
144
+ limit: Type.Optional(Type.Number({
145
+ default: 100,
146
+ description: "Maximum number of UTxOs to return"
147
+ }))
148
+ }),
149
+ outputSchema: Type.Object({
150
+ utxos: Type.Array(Type.Object({
151
+ txHash: Type.String({
152
+ description: "Transaction hash of the UTxO"
153
+ }),
154
+ outputIndex: Type.Number({
155
+ description: "Output index within the transaction"
156
+ }),
157
+ lovelace: Type.String({
158
+ description: "Lovelace amount as string (BigInt-safe)"
159
+ }),
160
+ tokens: Type.Array(TokenEntrySchema)
161
+ })),
162
+ total: Type.Number({
163
+ description: "Total number of UTxOs (before limit)"
164
+ })
165
+ }),
166
+ execute: async (input, context) => {
167
+ const blaze = await getBlazeFromContext(context);
168
+ const limit = input.limit ?? 100;
169
+ let allUtxos;
170
+ try {
171
+ allUtxos = await blaze.wallet.getUnspentOutputs();
172
+ } catch (err) {
173
+ throw new ActionError(`Provider error while fetching UTxOs: ${err instanceof Error ? err.message : String(err)}`, "PROVIDER_ERROR", {
174
+ error: err instanceof Error ? err.message : String(err)
175
+ });
176
+ }
177
+ const total = allUtxos.length;
178
+ const limited = allUtxos.slice(0, limit);
179
+ const utxos = limited.map(utxo => {
180
+ const input = utxo.input();
181
+ const output = utxo.output();
182
+ const value = output.amount();
183
+ const tokens = [];
184
+ const multiasset = value.multiasset();
185
+ if (multiasset) {
186
+ for (const [assetId, quantity] of multiasset.entries()) {
187
+ tokens.push({
188
+ policyId: Core.AssetId.getPolicyId(assetId),
189
+ assetName: Core.AssetId.getAssetName(assetId),
190
+ quantity: quantity.toString()
191
+ });
192
+ }
193
+ }
194
+ return {
195
+ txHash: input.transactionId().toString(),
196
+ outputIndex: Number(input.index()),
197
+ lovelace: value.coin().toString(),
198
+ tokens
199
+ };
200
+ });
201
+ return {
202
+ utxos,
203
+ total
204
+ };
205
+ }
206
+ };
207
+ //# sourceMappingURL=wallet-actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-actions.js","names":["Type","Core","ActionError","getBlazeFromContext","TokenEntrySchema","Object","policyId","String","description","assetName","quantity","getWalletAddress","name","category","inputSchema","outputSchema","address","network","execute","_input","context","blaze","wallet","getChangeAddress","err","Error","message","error","settings","toBech32","getWalletBalance","lovelace","ada","tokens","Array","utxos","getUnspentOutputs","totalLovelace","tokenMap","Map","utxo","value","output","amount","coin","multiasset","assetId","entries","AssetId","getPolicyId","getAssetName","key","set","get","from","map","split","toString","adaWhole","adaFraction","padStart","getWalletUtxos","limit","Optional","Number","default","txHash","outputIndex","total","input","allUtxos","length","limited","slice","push","transactionId","index"],"sources":["../../../../../src/Sprinkle/actions/builtin/wallet-actions.ts"],"sourcesContent":["/**\n * Built-in wallet query actions for the Sprinkle action system.\n * These actions expose wallet address, balance, and UTxO queries as\n * non-interactive actions available in CLI and MCP modes.\n *\n * All actions use category \"wallet\".\n */\n\nimport { Type } from \"@sinclair/typebox\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { Core } from \"@blaze-cardano/sdk\";\nimport { ActionError } from \"../types.js\";\nimport type { IAction } from \"../types.js\";\nimport { getBlazeFromContext } from \"./blaze-helper.js\";\n\n/** Shared token entry shape for balance and UTxO output */\nconst TokenEntrySchema = Type.Object({\n policyId: Type.String({ description: \"Policy ID of the token\" }),\n assetName: Type.String({ description: \"Asset name of the token (hex)\" }),\n quantity: Type.String({ description: \"Token quantity as string (BigInt-safe)\" }),\n});\n\n/**\n * `get-wallet-address` -- Returns the primary change address of the configured wallet.\n */\nexport const getWalletAddress: IAction<\n Record<string, never>,\n { address: string; network: string },\n TSchema\n> = {\n name: \"get-wallet-address\",\n description: \"Get the primary address of the configured wallet.\",\n category: \"wallet\",\n inputSchema: Type.Object({}),\n outputSchema: Type.Object({\n address: Type.String({ description: \"Bech32-encoded payment/change address\" }),\n network: Type.String({ description: \"Network name (mainnet, preview, preprod)\" }),\n }),\n execute: async (_input, context) => {\n const blaze = await getBlazeFromContext(context);\n\n let address: Core.Address;\n try {\n address = await blaze.wallet.getChangeAddress();\n } catch (err) {\n throw new ActionError(\n `Failed to get wallet address: ${err instanceof Error ? err.message : String(err)}`,\n \"NO_ADDRESS\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n if (!address) {\n throw new ActionError(\n \"The wallet returned no address. Ensure the wallet is properly configured.\",\n \"NO_ADDRESS\",\n );\n }\n\n const settings = context.settings as unknown as { network?: string };\n const network = settings.network ?? \"unknown\";\n\n return {\n address: address.toBech32(),\n network,\n };\n },\n};\n\n/**\n * `get-wallet-balance` -- Returns the ADA and token balance of the configured wallet.\n * Aggregates lovelace and multi-asset amounts from all UTxOs.\n * All quantities are returned as strings for BigInt-safe JSON serialization.\n */\nexport const getWalletBalance: IAction<\n Record<string, never>,\n {\n lovelace: string;\n ada: string;\n tokens: Array<{ policyId: string; assetName: string; quantity: string }>;\n },\n TSchema\n> = {\n name: \"get-wallet-balance\",\n description:\n \"Get the ADA and token balance of the configured wallet. Quantities returned as strings.\",\n category: \"wallet\",\n inputSchema: Type.Object({}),\n outputSchema: Type.Object({\n lovelace: Type.String({\n description: \"Total ADA balance in lovelace (as string for BigInt safety)\",\n }),\n ada: Type.String({ description: \"Total ADA balance as decimal string\" }),\n tokens: Type.Array(TokenEntrySchema),\n }),\n execute: async (_input, context) => {\n const blaze = await getBlazeFromContext(context);\n\n let utxos: Awaited<ReturnType<typeof blaze.wallet.getUnspentOutputs>>;\n try {\n utxos = await blaze.wallet.getUnspentOutputs();\n } catch (err) {\n throw new ActionError(\n `Provider error while fetching UTxOs: ${err instanceof Error ? err.message : String(err)}`,\n \"PROVIDER_ERROR\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n // Aggregate lovelace and token amounts\n let totalLovelace = 0n;\n const tokenMap = new Map<string, bigint>(); // key: `${policyId}.${assetName}`\n\n for (const utxo of utxos) {\n const value = utxo.output().amount();\n totalLovelace += value.coin();\n\n const multiasset = value.multiasset();\n if (multiasset) {\n for (const [assetId, quantity] of multiasset.entries()) {\n const policyId = Core.AssetId.getPolicyId(assetId);\n const assetName = Core.AssetId.getAssetName(assetId);\n const key = `${policyId}.${assetName}`;\n tokenMap.set(key, (tokenMap.get(key) ?? 0n) + quantity);\n }\n }\n }\n\n // Convert tokens map to array, serializing BigInt quantities as strings\n const tokens = Array.from(tokenMap.entries()).map(([key, quantity]) => {\n const [policyId, assetName] = key.split(\".\");\n return {\n policyId: policyId ?? \"\",\n assetName: assetName ?? \"\",\n quantity: quantity.toString(),\n };\n });\n\n // ADA = lovelace / 1_000_000, with 6 decimal places\n const adaWhole = totalLovelace / 1_000_000n;\n const adaFraction = totalLovelace % 1_000_000n;\n const ada = `${adaWhole}.${adaFraction.toString().padStart(6, \"0\")}`;\n\n return {\n lovelace: totalLovelace.toString(),\n ada,\n tokens,\n };\n },\n};\n\n/**\n * `get-wallet-utxos` -- Returns raw UTxO set for the configured wallet.\n * Accepts an optional limit (default 100). Returns UTxOs and the total count.\n */\nexport const getWalletUtxos: IAction<\n { limit?: number },\n {\n utxos: Array<{\n txHash: string;\n outputIndex: number;\n lovelace: string;\n tokens: Array<{ policyId: string; assetName: string; quantity: string }>;\n }>;\n total: number;\n },\n TSchema\n> = {\n name: \"get-wallet-utxos\",\n description: \"Get the UTxO set for the configured wallet.\",\n category: \"wallet\",\n inputSchema: Type.Object({\n limit: Type.Optional(\n Type.Number({ default: 100, description: \"Maximum number of UTxOs to return\" }),\n ),\n }),\n outputSchema: Type.Object({\n utxos: Type.Array(\n Type.Object({\n txHash: Type.String({ description: \"Transaction hash of the UTxO\" }),\n outputIndex: Type.Number({ description: \"Output index within the transaction\" }),\n lovelace: Type.String({ description: \"Lovelace amount as string (BigInt-safe)\" }),\n tokens: Type.Array(TokenEntrySchema),\n }),\n ),\n total: Type.Number({ description: \"Total number of UTxOs (before limit)\" }),\n }),\n execute: async (input, context) => {\n const blaze = await getBlazeFromContext(context);\n const limit = input.limit ?? 100;\n\n let allUtxos: Awaited<ReturnType<typeof blaze.wallet.getUnspentOutputs>>;\n try {\n allUtxos = await blaze.wallet.getUnspentOutputs();\n } catch (err) {\n throw new ActionError(\n `Provider error while fetching UTxOs: ${err instanceof Error ? err.message : String(err)}`,\n \"PROVIDER_ERROR\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n\n const total = allUtxos.length;\n const limited = allUtxos.slice(0, limit);\n\n const utxos = limited.map((utxo) => {\n const input = utxo.input();\n const output = utxo.output();\n const value = output.amount();\n\n const tokens: Array<{ policyId: string; assetName: string; quantity: string }> = [];\n const multiasset = value.multiasset();\n if (multiasset) {\n for (const [assetId, quantity] of multiasset.entries()) {\n tokens.push({\n policyId: Core.AssetId.getPolicyId(assetId),\n assetName: Core.AssetId.getAssetName(assetId),\n quantity: quantity.toString(),\n });\n }\n }\n\n return {\n txHash: input.transactionId().toString(),\n outputIndex: Number(input.index()),\n lovelace: value.coin().toString(),\n tokens,\n };\n });\n\n return { utxos, total };\n },\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,QAAQ,mBAAmB;AAExC,SAASC,IAAI,QAAQ,oBAAoB;AACzC,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,mBAAmB,QAAQ,mBAAmB;;AAEvD;AACA,MAAMC,gBAAgB,GAAGJ,IAAI,CAACK,MAAM,CAAC;EACnCC,QAAQ,EAAEN,IAAI,CAACO,MAAM,CAAC;IAAEC,WAAW,EAAE;EAAyB,CAAC,CAAC;EAChEC,SAAS,EAAET,IAAI,CAACO,MAAM,CAAC;IAAEC,WAAW,EAAE;EAAgC,CAAC,CAAC;EACxEE,QAAQ,EAAEV,IAAI,CAACO,MAAM,CAAC;IAAEC,WAAW,EAAE;EAAyC,CAAC;AACjF,CAAC,CAAC;;AAEF;AACA;AACA;AACA,OAAO,MAAMG,gBAIZ,GAAG;EACFC,IAAI,EAAE,oBAAoB;EAC1BJ,WAAW,EAAE,mDAAmD;EAChEK,QAAQ,EAAE,QAAQ;EAClBC,WAAW,EAAEd,IAAI,CAACK,MAAM,CAAC,CAAC,CAAC,CAAC;EAC5BU,YAAY,EAAEf,IAAI,CAACK,MAAM,CAAC;IACxBW,OAAO,EAAEhB,IAAI,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