@sundaeswap/sprinkles 0.7.0 → 0.8.1

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 (95) hide show
  1. package/README.md +178 -181
  2. package/dist/cjs/Sprinkle/__tests__/builtin-actions.test.js +4 -4
  3. package/dist/cjs/Sprinkle/__tests__/builtin-actions.test.js.map +1 -1
  4. package/dist/cjs/Sprinkle/__tests__/cli-adapter.test.js +25 -3
  5. package/dist/cjs/Sprinkle/__tests__/cli-adapter.test.js.map +1 -1
  6. package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js +15 -1
  7. package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
  8. package/dist/cjs/Sprinkle/__tests__/mcp-adapter.test.js +7 -9
  9. package/dist/cjs/Sprinkle/__tests__/mcp-adapter.test.js.map +1 -1
  10. package/dist/cjs/Sprinkle/__tests__/native-script.test.js +390 -0
  11. package/dist/cjs/Sprinkle/__tests__/native-script.test.js.map +1 -0
  12. package/dist/cjs/Sprinkle/__tests__/utility-actions.test.js +367 -0
  13. package/dist/cjs/Sprinkle/__tests__/utility-actions.test.js.map +1 -0
  14. package/dist/cjs/Sprinkle/actions/builtin/addressbook-actions.js +164 -0
  15. package/dist/cjs/Sprinkle/actions/builtin/addressbook-actions.js.map +1 -0
  16. package/dist/cjs/Sprinkle/actions/builtin/index.js +60 -3
  17. package/dist/cjs/Sprinkle/actions/builtin/index.js.map +1 -1
  18. package/dist/cjs/Sprinkle/actions/builtin/native-script.js +139 -0
  19. package/dist/cjs/Sprinkle/actions/builtin/native-script.js.map +1 -0
  20. package/dist/cjs/Sprinkle/actions/builtin/utility-actions.js +218 -0
  21. package/dist/cjs/Sprinkle/actions/builtin/utility-actions.js.map +1 -0
  22. package/dist/cjs/Sprinkle/actions/cli-adapter.js +20 -2
  23. package/dist/cjs/Sprinkle/actions/cli-adapter.js.map +1 -1
  24. package/dist/cjs/Sprinkle/actions/index.js +12 -0
  25. package/dist/cjs/Sprinkle/actions/index.js.map +1 -1
  26. package/dist/cjs/Sprinkle/actions/mcp-adapter.js +146 -4
  27. package/dist/cjs/Sprinkle/actions/mcp-adapter.js.map +1 -1
  28. package/dist/cjs/Sprinkle/index.js +282 -6
  29. package/dist/cjs/Sprinkle/index.js.map +1 -1
  30. package/dist/cjs/Sprinkle/schemas.js +17 -1
  31. package/dist/cjs/Sprinkle/schemas.js.map +1 -1
  32. package/dist/esm/Sprinkle/__tests__/builtin-actions.test.js +4 -4
  33. package/dist/esm/Sprinkle/__tests__/builtin-actions.test.js.map +1 -1
  34. package/dist/esm/Sprinkle/__tests__/cli-adapter.test.js +25 -3
  35. package/dist/esm/Sprinkle/__tests__/cli-adapter.test.js.map +1 -1
  36. package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js +15 -1
  37. package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
  38. package/dist/esm/Sprinkle/__tests__/mcp-adapter.test.js +7 -9
  39. package/dist/esm/Sprinkle/__tests__/mcp-adapter.test.js.map +1 -1
  40. package/dist/esm/Sprinkle/__tests__/native-script.test.js +388 -0
  41. package/dist/esm/Sprinkle/__tests__/native-script.test.js.map +1 -0
  42. package/dist/esm/Sprinkle/__tests__/utility-actions.test.js +365 -0
  43. package/dist/esm/Sprinkle/__tests__/utility-actions.test.js.map +1 -0
  44. package/dist/esm/Sprinkle/actions/builtin/addressbook-actions.js +159 -0
  45. package/dist/esm/Sprinkle/actions/builtin/addressbook-actions.js.map +1 -0
  46. package/dist/esm/Sprinkle/actions/builtin/index.js +8 -3
  47. package/dist/esm/Sprinkle/actions/builtin/index.js.map +1 -1
  48. package/dist/esm/Sprinkle/actions/builtin/native-script.js +133 -0
  49. package/dist/esm/Sprinkle/actions/builtin/native-script.js.map +1 -0
  50. package/dist/esm/Sprinkle/actions/builtin/utility-actions.js +213 -0
  51. package/dist/esm/Sprinkle/actions/builtin/utility-actions.js.map +1 -0
  52. package/dist/esm/Sprinkle/actions/cli-adapter.js +20 -2
  53. package/dist/esm/Sprinkle/actions/cli-adapter.js.map +1 -1
  54. package/dist/esm/Sprinkle/actions/index.js +1 -1
  55. package/dist/esm/Sprinkle/actions/index.js.map +1 -1
  56. package/dist/esm/Sprinkle/actions/mcp-adapter.js +145 -5
  57. package/dist/esm/Sprinkle/actions/mcp-adapter.js.map +1 -1
  58. package/dist/esm/Sprinkle/index.js +260 -9
  59. package/dist/esm/Sprinkle/index.js.map +1 -1
  60. package/dist/esm/Sprinkle/schemas.js +16 -0
  61. package/dist/esm/Sprinkle/schemas.js.map +1 -1
  62. package/dist/types/Sprinkle/actions/builtin/addressbook-actions.d.ts +50 -0
  63. package/dist/types/Sprinkle/actions/builtin/addressbook-actions.d.ts.map +1 -0
  64. package/dist/types/Sprinkle/actions/builtin/index.d.ts +6 -2
  65. package/dist/types/Sprinkle/actions/builtin/index.d.ts.map +1 -1
  66. package/dist/types/Sprinkle/actions/builtin/native-script.d.ts +27 -0
  67. package/dist/types/Sprinkle/actions/builtin/native-script.d.ts.map +1 -0
  68. package/dist/types/Sprinkle/actions/builtin/utility-actions.d.ts +48 -0
  69. package/dist/types/Sprinkle/actions/builtin/utility-actions.d.ts.map +1 -0
  70. package/dist/types/Sprinkle/actions/cli-adapter.d.ts.map +1 -1
  71. package/dist/types/Sprinkle/actions/index.d.ts +2 -1
  72. package/dist/types/Sprinkle/actions/index.d.ts.map +1 -1
  73. package/dist/types/Sprinkle/actions/mcp-adapter.d.ts +24 -0
  74. package/dist/types/Sprinkle/actions/mcp-adapter.d.ts.map +1 -1
  75. package/dist/types/Sprinkle/index.d.ts +5 -2
  76. package/dist/types/Sprinkle/index.d.ts.map +1 -1
  77. package/dist/types/Sprinkle/schemas.d.ts +72 -0
  78. package/dist/types/Sprinkle/schemas.d.ts.map +1 -1
  79. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  80. package/package.json +1 -1
  81. package/src/Sprinkle/__tests__/builtin-actions.test.ts +4 -4
  82. package/src/Sprinkle/__tests__/cli-adapter.test.ts +24 -3
  83. package/src/Sprinkle/__tests__/fill-in-struct.test.ts +23 -1
  84. package/src/Sprinkle/__tests__/mcp-adapter.test.ts +7 -5
  85. package/src/Sprinkle/__tests__/native-script.test.ts +341 -0
  86. package/src/Sprinkle/__tests__/utility-actions.test.ts +348 -0
  87. package/src/Sprinkle/actions/builtin/addressbook-actions.ts +168 -0
  88. package/src/Sprinkle/actions/builtin/index.ts +41 -2
  89. package/src/Sprinkle/actions/builtin/native-script.ts +165 -0
  90. package/src/Sprinkle/actions/builtin/utility-actions.ts +285 -0
  91. package/src/Sprinkle/actions/cli-adapter.ts +18 -2
  92. package/src/Sprinkle/actions/index.ts +2 -1
  93. package/src/Sprinkle/actions/mcp-adapter.ts +179 -4
  94. package/src/Sprinkle/index.ts +264 -3
  95. package/src/Sprinkle/schemas.ts +20 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addressbook-actions.js","names":["_typebox","require","_schemas","_types","_nativeScript","listAddressbook","exports","name","description","category","inputSchema","Type","Object","outputSchema","entries","Array","String","scriptHash","script","MultisigScript","execute","_input","context","addressbook","sprinkle","ms","toNativeScript","push","hash","setAddressbookEntry","minLength","input","blazeScript","saveSettings","deleteAddressbookEntry","deleted","Boolean","ActionError","getAddressbookEntry"],"sources":["../../../../../src/Sprinkle/actions/builtin/addressbook-actions.ts"],"sourcesContent":["/**\n * Built-in addressbook actions for managing named native scripts.\n *\n * The addressbook stores MultisigScript entries by name in the profile,\n * allowing them to be reused across actions and automatically resolved\n * by script hash during transaction building.\n */\n\nimport { Type } from \"@sinclair/typebox\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { MultisigScript } from \"../../schemas.js\";\nimport type { TMultisigScript } from \"../../schemas.js\";\nimport { ActionError } from \"../types.js\";\nimport type { IAction } from \"../types.js\";\nimport { toNativeScript } from \"./native-script.js\";\n\n/**\n * `list-addressbook` -- List all entries in the addressbook.\n */\nexport const listAddressbook: IAction<\n Record<string, never>,\n { entries: Array<{ name: string; scriptHash: string; script: TMultisigScript }> },\n TSchema\n> = {\n name: \"list-addressbook\",\n description: \"List all named native scripts in the addressbook.\",\n category: \"addressbook\",\n inputSchema: Type.Object({}),\n outputSchema: Type.Object({\n entries: Type.Array(\n Type.Object({\n name: Type.String(),\n scriptHash: Type.String(),\n script: MultisigScript,\n }),\n ),\n }),\n execute: async (_input, context) => {\n const addressbook = context.sprinkle.addressbook ?? {};\n const entries = [];\n for (const [name, ms] of Object.entries(addressbook)) {\n try {\n const script = toNativeScript(ms);\n entries.push({ name, scriptHash: script.hash(), script: ms });\n } catch {\n // Include entries even if hash computation fails\n entries.push({ name, scriptHash: \"unknown\", script: ms });\n }\n }\n return { entries };\n },\n};\n\n/**\n * `set-addressbook-entry` -- Add or update a named native script in the addressbook.\n */\nexport const setAddressbookEntry: IAction<\n { name: string; script: TMultisigScript },\n { name: string; scriptHash: string },\n TSchema\n> = {\n name: \"set-addressbook-entry\",\n description:\n \"Add or update a named native script in the addressbook. Accepts a MultisigScript JSON structure.\",\n category: \"addressbook\",\n inputSchema: Type.Object({\n name: Type.String({\n minLength: 1,\n description: \"Name for this addressbook entry\",\n }),\n script: MultisigScript,\n }),\n outputSchema: Type.Object({\n name: Type.String(),\n scriptHash: Type.String({ description: \"Computed script hash\" }),\n }),\n execute: async (input, context) => {\n // Validate the script can be converted\n const blazeScript = toNativeScript(input.script);\n const scriptHash = blazeScript.hash();\n\n context.sprinkle.addressbook[input.name] = input.script;\n context.sprinkle.saveSettings();\n\n return { name: input.name, scriptHash };\n },\n};\n\n/**\n * `delete-addressbook-entry` -- Remove a named native script from the addressbook.\n */\nexport const deleteAddressbookEntry: IAction<\n { name: string },\n { deleted: boolean; name: string },\n TSchema\n> = {\n name: \"delete-addressbook-entry\",\n description: \"Remove a named native script from the addressbook.\",\n category: \"addressbook\",\n inputSchema: Type.Object({\n name: Type.String({\n minLength: 1,\n description: \"Name of the addressbook entry to delete\",\n }),\n }),\n outputSchema: Type.Object({\n deleted: Type.Boolean(),\n name: Type.String(),\n }),\n execute: async (input, context) => {\n if (!(input.name in context.sprinkle.addressbook)) {\n throw new ActionError(\n `Addressbook entry \"${input.name}\" not found.`,\n \"NOT_FOUND\",\n { name: input.name },\n );\n }\n\n delete context.sprinkle.addressbook[input.name];\n context.sprinkle.saveSettings();\n\n return { deleted: true, name: input.name };\n },\n};\n\n/**\n * `get-addressbook-entry` -- Get a specific named native script from the addressbook.\n */\nexport const getAddressbookEntry: IAction<\n { name: string },\n { name: string; scriptHash: string; script: TMultisigScript },\n TSchema\n> = {\n name: \"get-addressbook-entry\",\n description: \"Get a specific named native script from the addressbook.\",\n category: \"addressbook\",\n inputSchema: Type.Object({\n name: Type.String({\n minLength: 1,\n description: \"Name of the addressbook entry to retrieve\",\n }),\n }),\n outputSchema: Type.Object({\n name: Type.String(),\n scriptHash: Type.String(),\n script: MultisigScript,\n }),\n execute: async (input, context) => {\n const ms = context.sprinkle.addressbook[input.name];\n if (!ms) {\n throw new ActionError(\n `Addressbook entry \"${input.name}\" not found.`,\n \"NOT_FOUND\",\n { name: input.name },\n );\n }\n\n let scriptHash = \"unknown\";\n try {\n const blazeScript = toNativeScript(ms);\n scriptHash = blazeScript.hash();\n } catch {\n // Return entry even if hash computation fails\n }\n\n return { name: input.name, scriptHash, script: ms };\n },\n};\n"],"mappings":";;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACO,MAAMI,eAIZ,GAAAC,OAAA,CAAAD,eAAA,GAAG;EACFE,IAAI,EAAE,kBAAkB;EACxBC,WAAW,EAAE,mDAAmD;EAChEC,QAAQ,EAAE,aAAa;EACvBC,WAAW,EAAEC,aAAI,CAACC,MAAM,CAAC,CAAC,CAAC,CAAC;EAC5BC,YAAY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;IAEA,IAAIU,UAAU,GAAG,SAAS;IAC1B,IAAI;MACF,MAAMe,WAAW,GAAG,IAAAN,4BAAc,EAACD,EAAE,CAAC;MACtCR,UAAU,GAAGe,WAAW,CAACJ,IAAI,CAAC,CAAC;IACjC,CAAC,CAAC,MAAM;MACN;IAAA;IAGF,OAAO;MAAErB,IAAI,EAAEwB,KAAK,CAACxB,IAAI;MAAEU,UAAU;MAAEC,MAAM,EAAEO;IAAG,CAAC;EACrD;AACF,CAAC","ignoreList":[]}
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "completeWithScripts", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _nativeScript.completeWithScripts;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "createProfile", {
7
13
  enumerable: true,
8
14
  get: function () {
@@ -15,12 +21,24 @@ Object.defineProperty(exports, "decodeTransaction", {
15
21
  return _transactionActions.decodeTransaction;
16
22
  }
17
23
  });
24
+ Object.defineProperty(exports, "deleteAddressbookEntry", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _addressbookActions.deleteAddressbookEntry;
28
+ }
29
+ });
18
30
  Object.defineProperty(exports, "deleteProfile", {
19
31
  enumerable: true,
20
32
  get: function () {
21
33
  return _profileActions.deleteProfile;
22
34
  }
23
35
  });
36
+ Object.defineProperty(exports, "getAddressbookEntry", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _addressbookActions.getAddressbookEntry;
40
+ }
41
+ });
24
42
  exports.getBuiltinActions = getBuiltinActions;
25
43
  Object.defineProperty(exports, "getProfile", {
26
44
  enumerable: true,
@@ -52,12 +70,36 @@ Object.defineProperty(exports, "getWalletUtxos", {
52
70
  return _walletActions.getWalletUtxos;
53
71
  }
54
72
  });
73
+ Object.defineProperty(exports, "listAddressbook", {
74
+ enumerable: true,
75
+ get: function () {
76
+ return _addressbookActions.listAddressbook;
77
+ }
78
+ });
55
79
  Object.defineProperty(exports, "listProfiles", {
56
80
  enumerable: true,
57
81
  get: function () {
58
82
  return _profileActions.listProfiles;
59
83
  }
60
84
  });
85
+ Object.defineProperty(exports, "mintToken", {
86
+ enumerable: true,
87
+ get: function () {
88
+ return _utilityActions.mintToken;
89
+ }
90
+ });
91
+ Object.defineProperty(exports, "registerStakeScript", {
92
+ enumerable: true,
93
+ get: function () {
94
+ return _utilityActions.registerStakeScript;
95
+ }
96
+ });
97
+ Object.defineProperty(exports, "setAddressbookEntry", {
98
+ enumerable: true,
99
+ get: function () {
100
+ return _addressbookActions.setAddressbookEntry;
101
+ }
102
+ });
61
103
  Object.defineProperty(exports, "setProfile", {
62
104
  enumerable: true,
63
105
  get: function () {
@@ -76,12 +118,24 @@ Object.defineProperty(exports, "signTransaction", {
76
118
  return _transactionActions.signTransaction;
77
119
  }
78
120
  });
121
+ Object.defineProperty(exports, "simpleSend", {
122
+ enumerable: true,
123
+ get: function () {
124
+ return _utilityActions.simpleSend;
125
+ }
126
+ });
79
127
  Object.defineProperty(exports, "submitTransaction", {
80
128
  enumerable: true,
81
129
  get: function () {
82
130
  return _transactionActions.submitTransaction;
83
131
  }
84
132
  });
133
+ Object.defineProperty(exports, "toNativeScript", {
134
+ enumerable: true,
135
+ get: function () {
136
+ return _nativeScript.toNativeScript;
137
+ }
138
+ });
85
139
  Object.defineProperty(exports, "updateSettings", {
86
140
  enumerable: true,
87
141
  get: function () {
@@ -92,15 +146,18 @@ var _profileActions = require("./profile-actions.js");
92
146
  var _settingsActions = require("./settings-actions.js");
93
147
  var _walletActions = require("./wallet-actions.js");
94
148
  var _transactionActions = require("./transaction-actions.js");
149
+ var _utilityActions = require("./utility-actions.js");
150
+ var _nativeScript = require("./native-script.js");
151
+ var _addressbookActions = require("./addressbook-actions.js");
95
152
  /**
96
153
  * Barrel export for built-in Sprinkle actions.
97
154
  *
98
- * Provides a `getBuiltinActions()` factory that returns all 14 built-in actions
155
+ * Provides a `getBuiltinActions()` factory that returns all 17 built-in actions
99
156
  * ready for registration on an ActionRegistry.
100
157
  */
101
158
 
102
159
  /**
103
- * Returns an array of all 14 built-in Sprinkle actions.
160
+ * Returns all built-in Sprinkle actions.
104
161
  * Register them on your ActionRegistry or pass them to `Sprinkle.run()`.
105
162
  *
106
163
  * @example
@@ -112,6 +169,6 @@ var _transactionActions = require("./transaction-actions.js");
112
169
  * ```
113
170
  */
114
171
  function getBuiltinActions() {
115
- return [_profileActions.listProfiles, _profileActions.getProfile, _profileActions.setProfile, _profileActions.createProfile, _profileActions.deleteProfile, _settingsActions.getSettings, _settingsActions.updateSettings, _walletActions.getWalletAddress, _walletActions.getWalletBalance, _walletActions.getWalletUtxos, _transactionActions.signTransaction, _transactionActions.submitTransaction, _transactionActions.signAndSubmit, _transactionActions.decodeTransaction];
172
+ return [_profileActions.listProfiles, _profileActions.getProfile, _profileActions.setProfile, _profileActions.createProfile, _profileActions.deleteProfile, _settingsActions.getSettings, _settingsActions.updateSettings, _walletActions.getWalletAddress, _walletActions.getWalletBalance, _walletActions.getWalletUtxos, _transactionActions.signTransaction, _transactionActions.submitTransaction, _transactionActions.signAndSubmit, _transactionActions.decodeTransaction, _utilityActions.mintToken, _utilityActions.simpleSend, _utilityActions.registerStakeScript, _addressbookActions.listAddressbook, _addressbookActions.getAddressbookEntry, _addressbookActions.setAddressbookEntry, _addressbookActions.deleteAddressbookEntry];
116
173
  }
117
174
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_profileActions","require","_settingsActions","_walletActions","_transactionActions","getBuiltinActions","listProfiles","getProfile","setProfile","createProfile","deleteProfile","getSettings","updateSettings","getWalletAddress","getWalletBalance","getWalletUtxos","signTransaction","submitTransaction","signAndSubmit","decodeTransaction"],"sources":["../../../../../src/Sprinkle/actions/builtin/index.ts"],"sourcesContent":["/**\n * Barrel export for built-in Sprinkle actions.\n *\n * Provides a `getBuiltinActions()` factory that returns all 14 built-in actions\n * ready for registration on an ActionRegistry.\n */\n\nimport type { TSchema } from \"@sinclair/typebox\";\nimport type { AnyAction } from \"../types.js\";\n\nexport {\n listProfiles,\n getProfile,\n setProfile,\n createProfile,\n deleteProfile,\n} from \"./profile-actions.js\";\n\nexport { getSettings, updateSettings } from \"./settings-actions.js\";\n\nexport {\n getWalletAddress,\n getWalletBalance,\n getWalletUtxos,\n} from \"./wallet-actions.js\";\n\nexport {\n signTransaction,\n submitTransaction,\n signAndSubmit,\n decodeTransaction,\n} from \"./transaction-actions.js\";\n\nimport {\n listProfiles,\n getProfile,\n setProfile,\n createProfile,\n deleteProfile,\n} from \"./profile-actions.js\";\n\nimport { getSettings, updateSettings } from \"./settings-actions.js\";\n\nimport {\n getWalletAddress,\n getWalletBalance,\n getWalletUtxos,\n} from \"./wallet-actions.js\";\n\nimport {\n signTransaction,\n submitTransaction,\n signAndSubmit,\n decodeTransaction,\n} from \"./transaction-actions.js\";\n\n/**\n * Returns an array of all 14 built-in Sprinkle actions.\n * Register them on your ActionRegistry or pass them to `Sprinkle.run()`.\n *\n * @example\n * ```ts\n * const sprinkle = new Sprinkle(MySchema, storagePath);\n * for (const action of getBuiltinActions()) {\n * sprinkle.registerAction(action);\n * }\n * ```\n */\nexport function getBuiltinActions<S extends TSchema>(): AnyAction<S>[] {\n return [\n listProfiles,\n getProfile,\n setProfile,\n createProfile,\n deleteProfile,\n getSettings,\n updateSettings,\n getWalletAddress,\n getWalletBalance,\n getWalletUtxos,\n signTransaction,\n submitTransaction,\n signAndSubmit,\n decodeTransaction,\n ] as unknown as AnyAction<S>[];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,IAAAA,eAAA,GAAAC,OAAA;AAQA,IAAAC,gBAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAF,OAAA;AAMA,IAAAG,mBAAA,GAAAH,OAAA;AA1BA;AACA;AACA;AACA;AACA;AACA;;AAmDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,iBAAiBA,CAAA,EAAsC;EACrE,OAAO,CACLC,4BAAY,EACZC,0BAAU,EACVC,0BAAU,EACVC,6BAAa,EACbC,6BAAa,EACbC,4BAAW,EACXC,+BAAc,EACdC,+BAAgB,EAChBC,+BAAgB,EAChBC,6BAAc,EACdC,mCAAe,EACfC,qCAAiB,EACjBC,iCAAa,EACbC,qCAAiB,CAClB;AACH","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_profileActions","require","_settingsActions","_walletActions","_transactionActions","_utilityActions","_nativeScript","_addressbookActions","getBuiltinActions","listProfiles","getProfile","setProfile","createProfile","deleteProfile","getSettings","updateSettings","getWalletAddress","getWalletBalance","getWalletUtxos","signTransaction","submitTransaction","signAndSubmit","decodeTransaction","mintToken","simpleSend","registerStakeScript","listAddressbook","getAddressbookEntry","setAddressbookEntry","deleteAddressbookEntry"],"sources":["../../../../../src/Sprinkle/actions/builtin/index.ts"],"sourcesContent":["/**\n * Barrel export for built-in Sprinkle actions.\n *\n * Provides a `getBuiltinActions()` factory that returns all 17 built-in actions\n * ready for registration on an ActionRegistry.\n */\n\nimport type { TSchema } from \"@sinclair/typebox\";\nimport type { AnyAction } from \"../types.js\";\n\nexport {\n listProfiles,\n getProfile,\n setProfile,\n createProfile,\n deleteProfile,\n} from \"./profile-actions.js\";\n\nexport { getSettings, updateSettings } from \"./settings-actions.js\";\n\nexport {\n getWalletAddress,\n getWalletBalance,\n getWalletUtxos,\n} from \"./wallet-actions.js\";\n\nexport {\n signTransaction,\n submitTransaction,\n signAndSubmit,\n decodeTransaction,\n} from \"./transaction-actions.js\";\n\nexport {\n mintToken,\n simpleSend,\n registerStakeScript,\n} from \"./utility-actions.js\";\n\nexport {\n toNativeScript,\n completeWithScripts,\n} from \"./native-script.js\";\nexport type { NativeScriptInput } from \"./native-script.js\";\n\nexport {\n listAddressbook,\n getAddressbookEntry,\n setAddressbookEntry,\n deleteAddressbookEntry,\n} from \"./addressbook-actions.js\";\n\nimport {\n listProfiles,\n getProfile,\n setProfile,\n createProfile,\n deleteProfile,\n} from \"./profile-actions.js\";\n\nimport { getSettings, updateSettings } from \"./settings-actions.js\";\n\nimport {\n getWalletAddress,\n getWalletBalance,\n getWalletUtxos,\n} from \"./wallet-actions.js\";\n\nimport {\n signTransaction,\n submitTransaction,\n signAndSubmit,\n decodeTransaction,\n} from \"./transaction-actions.js\";\n\nimport {\n mintToken,\n simpleSend,\n registerStakeScript,\n} from \"./utility-actions.js\";\n\nimport {\n listAddressbook,\n getAddressbookEntry,\n setAddressbookEntry,\n deleteAddressbookEntry,\n} from \"./addressbook-actions.js\";\n\n/**\n * Returns all built-in Sprinkle actions.\n * Register them on your ActionRegistry or pass them to `Sprinkle.run()`.\n *\n * @example\n * ```ts\n * const sprinkle = new Sprinkle(MySchema, storagePath);\n * for (const action of getBuiltinActions()) {\n * sprinkle.registerAction(action);\n * }\n * ```\n */\nexport function getBuiltinActions<S extends TSchema>(): AnyAction<S>[] {\n return [\n listProfiles,\n getProfile,\n setProfile,\n createProfile,\n deleteProfile,\n getSettings,\n updateSettings,\n getWalletAddress,\n getWalletBalance,\n getWalletUtxos,\n signTransaction,\n submitTransaction,\n signAndSubmit,\n decodeTransaction,\n mintToken,\n simpleSend,\n registerStakeScript,\n listAddressbook,\n getAddressbookEntry,\n setAddressbookEntry,\n deleteAddressbookEntry,\n ] as unknown as AnyAction<S>[];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,IAAAA,eAAA,GAAAC,OAAA;AAQA,IAAAC,gBAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAF,OAAA;AAMA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,eAAA,GAAAJ,OAAA;AAMA,IAAAK,aAAA,GAAAL,OAAA;AAMA,IAAAM,mBAAA,GAAAN,OAAA;AA7CA;AACA;AACA;AACA;AACA;AACA;;AAmFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASO,iBAAiBA,CAAA,EAAsC;EACrE,OAAO,CACLC,4BAAY,EACZC,0BAAU,EACVC,0BAAU,EACVC,6BAAa,EACbC,6BAAa,EACbC,4BAAW,EACXC,+BAAc,EACdC,+BAAgB,EAChBC,+BAAgB,EAChBC,6BAAc,EACdC,mCAAe,EACfC,qCAAiB,EACjBC,iCAAa,EACbC,qCAAiB,EACjBC,yBAAS,EACTC,0BAAU,EACVC,mCAAmB,EACnBC,mCAAe,EACfC,uCAAmB,EACnBC,uCAAmB,EACnBC,0CAAsB,CACvB;AACH","ignoreList":[]}
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.completeWithScripts = completeWithScripts;
7
+ exports.toNativeScript = toNativeScript;
8
+ var _sdk = require("@blaze-cardano/sdk");
9
+ var _types = require("../types.js");
10
+ /**
11
+ * Native script utilities for Sprinkle actions.
12
+ *
13
+ * Provides conversion from user-friendly input formats (CBOR hex or structured JSON)
14
+ * to Blaze NativeScript objects, and a helper to attach scripts during tx completion.
15
+ */
16
+
17
+ /** Input type: either a CBOR hex string or a MultisigScript JSON structure */
18
+
19
+ /**
20
+ * Converts a MultisigScript JSON structure to a Blaze NativeScript.
21
+ * Handles the recursive structure (AllOf, AnyOf, AtLeast contain nested scripts).
22
+ */
23
+ function multisigToNativeScript(ms) {
24
+ if ("Signature" in ms) {
25
+ const hash = _sdk.Core.Ed25519KeyHashHex(ms.Signature.key_hash);
26
+ return _sdk.Core.NativeScript.newScriptPubkey(new _sdk.Core.ScriptPubkey(hash));
27
+ }
28
+ if ("AllOf" in ms) {
29
+ const scripts = ms.AllOf.scripts.map(multisigToNativeScript);
30
+ return _sdk.Core.NativeScript.newScriptAll(new _sdk.Core.ScriptAll(scripts));
31
+ }
32
+ if ("AnyOf" in ms) {
33
+ const scripts = ms.AnyOf.scripts.map(multisigToNativeScript);
34
+ return _sdk.Core.NativeScript.newScriptAny(new _sdk.Core.ScriptAny(scripts));
35
+ }
36
+ if ("AtLeast" in ms) {
37
+ const scripts = ms.AtLeast.scripts.map(multisigToNativeScript);
38
+ return _sdk.Core.NativeScript.newScriptNOfK(new _sdk.Core.ScriptNOfK(scripts, Number(ms.AtLeast.required)));
39
+ }
40
+ if ("Before" in ms) {
41
+ return _sdk.Core.NativeScript.newTimelockExpiry(new _sdk.Core.TimelockExpiry(_sdk.Core.Slot(Number(ms.Before.time))));
42
+ }
43
+ if ("After" in ms) {
44
+ return _sdk.Core.NativeScript.newTimelockStart(new _sdk.Core.TimelockStart(_sdk.Core.Slot(Number(ms.After.time))));
45
+ }
46
+ if ("Script" in ms) {
47
+ // Script variant references a script by hash — this is a ScriptPubkey
48
+ // but using the script hash directly as a key hash reference
49
+ const hash = _sdk.Core.Ed25519KeyHashHex(ms.Script.script_hash);
50
+ return _sdk.Core.NativeScript.newScriptPubkey(new _sdk.Core.ScriptPubkey(hash));
51
+ }
52
+ throw new _types.ActionError("Unrecognized MultisigScript variant", "INVALID_NATIVE_SCRIPT", {
53
+ input: ms
54
+ });
55
+ }
56
+
57
+ /**
58
+ * Converts a native script input (CBOR hex string or MultisigScript JSON)
59
+ * to a Blaze Script object suitable for `provideScript()`.
60
+ */
61
+ function toNativeScript(input) {
62
+ if (typeof input === "string") {
63
+ try {
64
+ const nativeScript = _sdk.Core.NativeScript.fromCbor(_sdk.Core.HexBlob(input));
65
+ return _sdk.Core.Script.newNativeScript(nativeScript);
66
+ } catch (err) {
67
+ throw new _types.ActionError(`Invalid native script CBOR: ${err instanceof Error ? err.message : String(err)}`, "INVALID_NATIVE_SCRIPT", {
68
+ error: err instanceof Error ? err.message : String(err)
69
+ });
70
+ }
71
+ }
72
+ try {
73
+ const nativeScript = multisigToNativeScript(input);
74
+ return _sdk.Core.Script.newNativeScript(nativeScript);
75
+ } catch (err) {
76
+ if (err instanceof _types.ActionError) throw err;
77
+ throw new _types.ActionError(`Failed to convert MultisigScript to native script: ${err instanceof Error ? err.message : String(err)}`, "INVALID_NATIVE_SCRIPT", {
78
+ error: err instanceof Error ? err.message : String(err)
79
+ });
80
+ }
81
+ }
82
+
83
+ /** Regex to extract a script hash from Blaze's "Could not resolve script hash" error */
84
+ const MISSING_SCRIPT_HASH_RE = /complete: Could not resolve script hash[: ]*([0-9a-fA-F]+)/;
85
+
86
+ /**
87
+ * Builds a hash → Script lookup from the addressbook in the sprinkle context.
88
+ * Returns an empty map if there's no addressbook.
89
+ */
90
+ function buildAddressbookIndex(addressbook) {
91
+ const index = new Map();
92
+ if (!addressbook) return index;
93
+ for (const [, ms] of Object.entries(addressbook)) {
94
+ try {
95
+ const script = toNativeScript(ms);
96
+ index.set(script.hash(), script);
97
+ } catch {
98
+ // Skip invalid addressbook entries
99
+ }
100
+ }
101
+ return index;
102
+ }
103
+
104
+ /**
105
+ * Attaches optional native scripts to a transaction builder and completes it.
106
+ *
107
+ * If completion fails because Blaze cannot resolve a required native script hash,
108
+ * and a context with an addressbook is provided, it will look up the missing script
109
+ * by hash in the addressbook and retry once.
110
+ */
111
+ async function completeWithScripts(txBuilder, nativeScripts, context) {
112
+ if (nativeScripts?.length) {
113
+ for (const input of nativeScripts) {
114
+ txBuilder.provideScript(toNativeScript(input));
115
+ }
116
+ }
117
+ try {
118
+ return await txBuilder.complete();
119
+ } catch (err) {
120
+ const message = err instanceof Error ? err.message : String(err);
121
+ const match = message.match(MISSING_SCRIPT_HASH_RE);
122
+ if (!match || !context?.sprinkle?.addressbook) {
123
+ throw err;
124
+ }
125
+
126
+ // Build hash index from addressbook and try to resolve the missing script
127
+ const addressbookIndex = buildAddressbookIndex(context.sprinkle.addressbook);
128
+ const missingHash = match[1];
129
+ const script = addressbookIndex.get(missingHash);
130
+ if (!script) {
131
+ throw err;
132
+ }
133
+
134
+ // Attach the found script and retry
135
+ txBuilder.provideScript(script);
136
+ return txBuilder.complete();
137
+ }
138
+ }
139
+ //# sourceMappingURL=native-script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-script.js","names":["_sdk","require","_types","multisigToNativeScript","ms","hash","Core","Ed25519KeyHashHex","Signature","key_hash","NativeScript","newScriptPubkey","ScriptPubkey","scripts","AllOf","map","newScriptAll","ScriptAll","AnyOf","newScriptAny","ScriptAny","AtLeast","newScriptNOfK","ScriptNOfK","Number","required","newTimelockExpiry","TimelockExpiry","Slot","Before","time","newTimelockStart","TimelockStart","After","Script","script_hash","ActionError","input","toNativeScript","nativeScript","fromCbor","HexBlob","newNativeScript","err","Error","message","String","error","MISSING_SCRIPT_HASH_RE","buildAddressbookIndex","addressbook","index","Map","Object","entries","script","set","completeWithScripts","txBuilder","nativeScripts","context","length","provideScript","complete","match","sprinkle","addressbookIndex","missingHash","get"],"sources":["../../../../../src/Sprinkle/actions/builtin/native-script.ts"],"sourcesContent":["/**\n * Native script utilities for Sprinkle actions.\n *\n * Provides conversion from user-friendly input formats (CBOR hex or structured JSON)\n * to Blaze NativeScript objects, and a helper to attach scripts during tx completion.\n */\n\nimport { Core } from \"@blaze-cardano/sdk\";\nimport type { TxBuilder } from \"@blaze-cardano/tx\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport type { TMultisigScript } from \"../../schemas.js\";\nimport { ActionError } from \"../types.js\";\nimport type { IActionContext } from \"../types.js\";\n\n/** Input type: either a CBOR hex string or a MultisigScript JSON structure */\nexport type NativeScriptInput = string | TMultisigScript;\n\n/**\n * Converts a MultisigScript JSON structure to a Blaze NativeScript.\n * Handles the recursive structure (AllOf, AnyOf, AtLeast contain nested scripts).\n */\nfunction multisigToNativeScript(ms: TMultisigScript): Core.NativeScript {\n if (\"Signature\" in ms) {\n const hash = Core.Ed25519KeyHashHex(ms.Signature.key_hash);\n return Core.NativeScript.newScriptPubkey(new Core.ScriptPubkey(hash));\n }\n if (\"AllOf\" in ms) {\n const scripts = ms.AllOf.scripts.map(multisigToNativeScript);\n return Core.NativeScript.newScriptAll(new Core.ScriptAll(scripts));\n }\n if (\"AnyOf\" in ms) {\n const scripts = ms.AnyOf.scripts.map(multisigToNativeScript);\n return Core.NativeScript.newScriptAny(new Core.ScriptAny(scripts));\n }\n if (\"AtLeast\" in ms) {\n const scripts = ms.AtLeast.scripts.map(multisigToNativeScript);\n return Core.NativeScript.newScriptNOfK(\n new Core.ScriptNOfK(scripts, Number(ms.AtLeast.required)),\n );\n }\n if (\"Before\" in ms) {\n return Core.NativeScript.newTimelockExpiry(\n new Core.TimelockExpiry(Core.Slot(Number(ms.Before.time))),\n );\n }\n if (\"After\" in ms) {\n return Core.NativeScript.newTimelockStart(\n new Core.TimelockStart(Core.Slot(Number(ms.After.time))),\n );\n }\n if (\"Script\" in ms) {\n // Script variant references a script by hash — this is a ScriptPubkey\n // but using the script hash directly as a key hash reference\n const hash = Core.Ed25519KeyHashHex(ms.Script.script_hash);\n return Core.NativeScript.newScriptPubkey(new Core.ScriptPubkey(hash));\n }\n\n throw new ActionError(\n \"Unrecognized MultisigScript variant\",\n \"INVALID_NATIVE_SCRIPT\",\n { input: ms },\n );\n}\n\n/**\n * Converts a native script input (CBOR hex string or MultisigScript JSON)\n * to a Blaze Script object suitable for `provideScript()`.\n */\nexport function toNativeScript(input: NativeScriptInput): Core.Script {\n if (typeof input === \"string\") {\n try {\n const nativeScript = Core.NativeScript.fromCbor(\n Core.HexBlob(input),\n );\n return Core.Script.newNativeScript(nativeScript);\n } catch (err) {\n throw new ActionError(\n `Invalid native script CBOR: ${err instanceof Error ? err.message : String(err)}`,\n \"INVALID_NATIVE_SCRIPT\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n }\n\n try {\n const nativeScript = multisigToNativeScript(input);\n return Core.Script.newNativeScript(nativeScript);\n } catch (err) {\n if (err instanceof ActionError) throw err;\n throw new ActionError(\n `Failed to convert MultisigScript to native script: ${err instanceof Error ? err.message : String(err)}`,\n \"INVALID_NATIVE_SCRIPT\",\n { error: err instanceof Error ? err.message : String(err) },\n );\n }\n}\n\n/** Regex to extract a script hash from Blaze's \"Could not resolve script hash\" error */\nconst MISSING_SCRIPT_HASH_RE =\n /complete: Could not resolve script hash[: ]*([0-9a-fA-F]+)/;\n\n/**\n * Builds a hash → Script lookup from the addressbook in the sprinkle context.\n * Returns an empty map if there's no addressbook.\n */\nfunction buildAddressbookIndex(\n addressbook: Record<string, TMultisigScript> | undefined,\n): Map<string, Core.Script> {\n const index = new Map<string, Core.Script>();\n if (!addressbook) return index;\n for (const [, ms] of Object.entries(addressbook)) {\n try {\n const script = toNativeScript(ms);\n index.set(script.hash(), script);\n } catch {\n // Skip invalid addressbook entries\n }\n }\n return index;\n}\n\n/**\n * Attaches optional native scripts to a transaction builder and completes it.\n *\n * If completion fails because Blaze cannot resolve a required native script hash,\n * and a context with an addressbook is provided, it will look up the missing script\n * by hash in the addressbook and retry once.\n */\nexport async function completeWithScripts<S extends TSchema>(\n txBuilder: TxBuilder,\n nativeScripts?: NativeScriptInput[],\n context?: IActionContext<S>,\n): Promise<Core.Transaction> {\n if (nativeScripts?.length) {\n for (const input of nativeScripts) {\n txBuilder.provideScript(toNativeScript(input));\n }\n }\n\n try {\n return await txBuilder.complete();\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n const match = message.match(MISSING_SCRIPT_HASH_RE);\n\n if (!match || !context?.sprinkle?.addressbook) {\n throw err;\n }\n\n // Build hash index from addressbook and try to resolve the missing script\n const addressbookIndex = buildAddressbookIndex(\n context.sprinkle.addressbook,\n );\n const missingHash = match[1];\n const script = addressbookIndex.get(missingHash);\n\n if (!script) {\n throw err;\n }\n\n // Attach the found script and retry\n txBuilder.provideScript(script);\n return txBuilder.complete();\n }\n}\n"],"mappings":";;;;;;;AAOA,IAAAA,IAAA,GAAAC,OAAA;AA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AK,IAAIsB,aAAa,EAAE;MACjCD,SAAS,CAACI,aAAa,CAACxB,cAAc,CAACD,KAAK,CAAC,CAAC;IAChD;EACF;EAEA,IAAI;IACF,OAAO,MAAMqB,SAAS,CAACK,QAAQ,CAAC,CAAC;EACnC,CAAC,CAAC,OAAOpB,GAAG,EAAE;IACZ,MAAME,OAAO,GAAGF,GAAG,YAAYC,KAAK,GAAGD,GAAG,CAACE,OAAO,GAAGC,MAAM,CAACH,GAAG,CAAC;IAChE,MAAMqB,KAAK,GAAGnB,OAAO,CAACmB,KAAK,CAAChB,sBAAsB,CAAC;IAEnD,IAAI,CAACgB,KAAK,IAAI,CAACJ,OAAO,EAAEK,QAAQ,EAAEf,WAAW,EAAE;MAC7C,MAAMP,GAAG;IACX;;IAEA;IACA,MAAMuB,gBAAgB,GAAGjB,qBAAqB,CAC5CW,OAAO,CAACK,QAAQ,CAACf,WACnB,CAAC;IACD,MAAMiB,WAAW,GAAGH,KAAK,CAAC,CAAC,CAAC;IAC5B,MAAMT,MAAM,GAAGW,gBAAgB,CAACE,GAAG,CAACD,WAAW,CAAC;IAEhD,IAAI,CAACZ,MAAM,EAAE;MACX,MAAMZ,GAAG;IACX;;IAEA;IACAe,SAAS,CAACI,aAAa,CAACP,MAAM,CAAC;IAC/B,OAAOG,SAAS,CAACK,QAAQ,CAAC,CAAC;EAC7B;AACF","ignoreList":[]}
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.simpleSend = exports.registerStakeScript = exports.mintToken = void 0;
7
+ var _typebox = require("@sinclair/typebox");
8
+ var _sdk = require("@blaze-cardano/sdk");
9
+ var _types = require("../types.js");
10
+ var _blazeHelper = require("./blaze-helper.js");
11
+ var _schemas = require("../../schemas.js");
12
+ var _nativeScript = require("./native-script.js");
13
+ /**
14
+ * Built-in utility actions for the Sprinkle action system.
15
+ * These actions provide common Cardano operations: minting tokens,
16
+ * sending ADA/tokens, and registering stake scripts.
17
+ */
18
+
19
+ /**
20
+ * `mint-token` -- Mint native tokens using a native script derived from the wallet's payment key.
21
+ * The policy is a simple ScriptPubkey requiring the wallet's payment credential to sign.
22
+ * Requires a hot wallet.
23
+ */
24
+ const mintToken = exports.mintToken = {
25
+ name: "mint-token",
26
+ description: "Mint native tokens using a native script policy derived from the wallet's payment key.",
27
+ category: "utility",
28
+ inputSchema: _typebox.Type.Object({
29
+ tokenName: _typebox.Type.String({
30
+ description: "Name of the token to mint"
31
+ }),
32
+ amount: _typebox.Type.String({
33
+ description: "Amount of tokens to mint (as string for BigInt safety)"
34
+ }),
35
+ nativeScripts: _schemas.NativeScriptsParam
36
+ }),
37
+ outputSchema: _typebox.Type.Object({
38
+ policyId: _typebox.Type.String({
39
+ description: "Policy ID of the minted token"
40
+ }),
41
+ tokenName: _typebox.Type.String({
42
+ description: "Token name"
43
+ }),
44
+ amount: _typebox.Type.String({
45
+ description: "Amount minted"
46
+ }),
47
+ txCbor: _typebox.Type.String({
48
+ description: "Unsigned transaction CBOR hex ready for signing"
49
+ })
50
+ }),
51
+ execute: async (input, context) => {
52
+ const blaze = await (0, _blazeHelper.getBlazeFromContext)(context);
53
+ if (!(0, _blazeHelper.isHotWallet)(blaze)) {
54
+ throw new _types.ActionError("Mint token requires a hot wallet to derive the native script policy.", "COLD_WALLET");
55
+ }
56
+
57
+ // Get the wallet's payment credential hash for the native script
58
+ let address;
59
+ try {
60
+ address = await blaze.wallet.getChangeAddress();
61
+ } catch (err) {
62
+ throw new _types.ActionError(`Failed to get wallet address: ${err instanceof Error ? err.message : String(err)}`, "NO_ADDRESS", {
63
+ error: err instanceof Error ? err.message : String(err)
64
+ });
65
+ }
66
+ const baseAddress = address.asBase();
67
+ if (!baseAddress) {
68
+ throw new _types.ActionError("Could not derive base address from wallet. Ensure the wallet has a payment credential.", "INVALID_ADDRESS");
69
+ }
70
+ const paymentCredential = baseAddress.getPaymentCredential();
71
+ if (!paymentCredential?.hash) {
72
+ throw new _types.ActionError("Could not extract payment credential hash from wallet address.", "NO_PAYMENT_CREDENTIAL");
73
+ }
74
+ const hash = _sdk.Core.Ed25519KeyHashHex(paymentCredential.hash.toString());
75
+ const tokenPolicy = new _sdk.Core.ScriptPubkey(hash);
76
+ const policy = _sdk.Core.Script.newNativeScript(_sdk.Core.NativeScript.newScriptPubkey(tokenPolicy));
77
+ const policyId = policy.hash();
78
+ const assetName = _sdk.Core.AssetName(_sdk.Core.toHex(Buffer.from(input.tokenName)));
79
+ const mintAmount = BigInt(input.amount);
80
+ const mints = new Map();
81
+ mints.set(assetName, mintAmount);
82
+ let tx;
83
+ try {
84
+ const txBuilder = blaze.newTransaction().addMint(_sdk.Core.PolicyId(policyId), mints).provideScript(policy);
85
+ tx = await (0, _nativeScript.completeWithScripts)(txBuilder, input.nativeScripts, context);
86
+ } catch (err) {
87
+ if (err instanceof _types.ActionError) throw err;
88
+ throw new _types.ActionError(`Failed to build mint transaction: ${err instanceof Error ? err.message : String(err)}`, "BUILD_ERROR", {
89
+ error: err instanceof Error ? err.message : String(err)
90
+ });
91
+ }
92
+ return {
93
+ policyId: policyId.toString(),
94
+ tokenName: input.tokenName,
95
+ amount: input.amount,
96
+ txCbor: tx.toCbor()
97
+ };
98
+ }
99
+ };
100
+
101
+ /**
102
+ * `simple-send` -- Send ADA or a native token to a recipient address.
103
+ * Builds an unsigned transaction that can be signed via TxDialog or sign-transaction.
104
+ */
105
+ const simpleSend = exports.simpleSend = {
106
+ name: "simple-send",
107
+ description: "Send ADA or a native token to a recipient address.",
108
+ category: "wallet",
109
+ inputSchema: _typebox.Type.Object({
110
+ recipientAddress: _typebox.Type.String({
111
+ description: "Bech32 recipient address"
112
+ }),
113
+ lovelace: _typebox.Type.Optional(_typebox.Type.String({
114
+ description: "Amount of lovelace to send (as string for BigInt safety). Required if not sending a token."
115
+ })),
116
+ policyId: _typebox.Type.Optional(_typebox.Type.String({
117
+ description: "Policy ID of the token to send"
118
+ })),
119
+ assetName: _typebox.Type.Optional(_typebox.Type.String({
120
+ description: "Asset name of the token to send (hex-encoded)"
121
+ })),
122
+ tokenAmount: _typebox.Type.Optional(_typebox.Type.String({
123
+ description: "Amount of tokens to send (as string for BigInt safety)"
124
+ })),
125
+ nativeScripts: _schemas.NativeScriptsParam
126
+ }),
127
+ outputSchema: _typebox.Type.Object({
128
+ txCbor: _typebox.Type.String({
129
+ description: "Unsigned transaction CBOR hex ready for signing"
130
+ })
131
+ }),
132
+ execute: async (input, context) => {
133
+ const blaze = await (0, _blazeHelper.getBlazeFromContext)(context);
134
+
135
+ // Validate: must provide lovelace or token details
136
+ const hasToken = input.policyId && input.assetName && input.tokenAmount;
137
+ if (!input.lovelace && !hasToken) {
138
+ throw new _types.ActionError("Must provide either lovelace amount or token details (policyId, assetName, tokenAmount).", "INVALID_INPUT");
139
+ }
140
+ let recipient;
141
+ try {
142
+ recipient = _sdk.Core.Address.fromBech32(input.recipientAddress);
143
+ } catch (err) {
144
+ throw new _types.ActionError(`Invalid recipient address: ${err instanceof Error ? err.message : String(err)}`, "INVALID_ADDRESS", {
145
+ error: err instanceof Error ? err.message : String(err)
146
+ });
147
+ }
148
+ let value;
149
+ if (hasToken) {
150
+ const assetId = `${input.policyId}${input.assetName}`;
151
+ value = (0, _sdk.makeValue)(BigInt(input.lovelace ?? "0"), [assetId, BigInt(input.tokenAmount)]);
152
+ } else {
153
+ value = (0, _sdk.makeValue)(BigInt(input.lovelace));
154
+ }
155
+ let tx;
156
+ try {
157
+ const txBuilder = blaze.newTransaction().payAssets(recipient, value);
158
+ tx = await (0, _nativeScript.completeWithScripts)(txBuilder, input.nativeScripts, context);
159
+ } catch (err) {
160
+ if (err instanceof _types.ActionError) throw err;
161
+ throw new _types.ActionError(`Failed to build send transaction: ${err instanceof Error ? err.message : String(err)}`, "BUILD_ERROR", {
162
+ error: err instanceof Error ? err.message : String(err)
163
+ });
164
+ }
165
+ return {
166
+ txCbor: tx.toCbor()
167
+ };
168
+ }
169
+ };
170
+
171
+ /**
172
+ * `register-stake-script` -- Register a stake script credential on-chain.
173
+ * Takes a script hash and builds a stake registration transaction.
174
+ */
175
+ const registerStakeScript = exports.registerStakeScript = {
176
+ name: "register-stake-script",
177
+ description: "Register a stake script credential on-chain. Takes a script hash (hex) and builds the registration transaction.",
178
+ category: "utility",
179
+ inputSchema: _typebox.Type.Object({
180
+ scriptHash: _typebox.Type.String({
181
+ description: "Stake script hash in hex (28 bytes / 56 hex characters)"
182
+ }),
183
+ nativeScripts: _schemas.NativeScriptsParam
184
+ }),
185
+ outputSchema: _typebox.Type.Object({
186
+ txCbor: _typebox.Type.String({
187
+ description: "Unsigned transaction CBOR hex ready for signing"
188
+ })
189
+ }),
190
+ execute: async (input, context) => {
191
+ const blaze = await (0, _blazeHelper.getBlazeFromContext)(context);
192
+
193
+ // Validate hex format
194
+ if (!/^[0-9a-fA-F]{56}$/.test(input.scriptHash)) {
195
+ throw new _types.ActionError("Script hash must be exactly 56 hex characters (28 bytes).", "INVALID_SCRIPT_HASH", {
196
+ provided: input.scriptHash
197
+ });
198
+ }
199
+ const credential = _sdk.Core.Credential.fromCore({
200
+ hash: _sdk.Core.Hash28ByteBase16(input.scriptHash),
201
+ type: _sdk.Core.CredentialType.ScriptHash
202
+ });
203
+ let tx;
204
+ try {
205
+ const txBuilder = blaze.newTransaction().addRegisterStake(credential);
206
+ tx = await (0, _nativeScript.completeWithScripts)(txBuilder, input.nativeScripts, context);
207
+ } catch (err) {
208
+ if (err instanceof _types.ActionError) throw err;
209
+ throw new _types.ActionError(`Failed to build stake registration transaction: ${err instanceof Error ? err.message : String(err)}`, "BUILD_ERROR", {
210
+ error: err instanceof Error ? err.message : String(err)
211
+ });
212
+ }
213
+ return {
214
+ txCbor: tx.toCbor()
215
+ };
216
+ }
217
+ };
218
+ //# sourceMappingURL=utility-actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utility-actions.js","names":["_typebox","require","_sdk","_types","_blazeHelper","_schemas","_nativeScript","mintToken","exports","name","description","category","inputSchema","Type","Object","tokenName","String","amount","nativeScripts","NativeScriptsParam","outputSchema","policyId","txCbor","execute","input","context","blaze","getBlazeFromContext","isHotWallet","ActionError","address","wallet","getChangeAddress","err","Error","message","error","baseAddress","asBase","paymentCredential","getPaymentCredential","hash","Core","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","completeWithScripts","toCbor","simpleSend","recipientAddress","lovelace","Optional","tokenAmount","hasToken","recipient","Address","fromBech32","value","assetId","makeValue","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":";;;;;;AAMA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AAdA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACO,MAAMM,SAIZ,GAAAC,OAAA,CAAAD,SAAA,GAAG;EACFE,IAAI,EAAE,YAAY;EAClBC,WAAW,EACT,wFAAwF;EAC1FC,QAAQ,EAAE,SAAS;EACnBC,WAAW,EAAEC,aAAI,CAACC,MAAM,CAAC;IACvBC,SAAS,EAAEF,aAAI,CAACG,MAAM,CAAC;MAAEN,WAAW,EAAE;IAA4B,CAAC,CAAC;IACpEO,MAAM,EAAEJ,aAAI,CAACG,MAAM,CAAC;MAClBN,WAAW,EAAE;IACf,CAAC,CAAC;IACFQ,aAAa,EAAEC;EACjB,CAAC,CAAC;EACFC,YAAY,EAAEP,aAAI,CAACC,MAAM,CAAC;IACxBO,QAAQ,EAAER,aAAI,CAACG,MAAM,CAAC;MAAEN,WAAW,EAAE;IAAgC,CAAC,CAAC;IACvEK,SAAS,EAAEF,aAAI,CAACG,MAAM,CAAC;MAAEN,WAAW,EAAE;IAAa,CAAC,CAAC;IACrDO,MAAM,EAAEJ,aAAI,CAACG,MAAM,CAAC;MAAEN,WAAW,EAAE;IAAgB,CAAC,CAAC;IACrDY,MAAM,EAAET,aAAI,CAACG,MAAM,CAAC;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W,CAC/B,CAAC;IACH;IAEA,MAAMG,UAAU,GAAG7C,SAAI,CAAC8C,UAAU,CAACC,QAAQ,CAAC;MAC1ChD,IAAI,EAAEC,SAAI,CAACgD,gBAAgB,CAAClE,KAAK,CAAC4D,UAAU,CAAC;MAC7CO,IAAI,EAAEjD,SAAI,CAACkD,cAAc,CAACC;IAC5B,CAAC,CAAC;IAEF,IAAI/B,EAAoB;IACxB,IAAI;MACF,MAAMC,SAAS,GAAGrC,KAAK,CAACsC,cAAc,CAAC,CAAC,CAAC8B,gBAAgB,CAACP,UAAU,CAAC;MACrEzB,EAAE,GAAG,MAAM,IAAAM,iCAAmB,EAACL,SAAS,EAAEvC,KAAK,CAACN,aAAa,EAAEO,OAAO,CAAC;IACzE,CAAC,CAAC,OAAOQ,GAAG,EAAE;MACZ,IAAIA,GAAG,YAAYJ,kBAAW,EAAE,MAAMI,GAAG;MACzC,MAAM,IAAIJ,kBAAW,CACnB,mDAAmDI,GAAG,YAAYC,KAAK,GAAGD,GAAG,CAACE,OAAO,GAAGnB,MAAM,CAACiB,GAAG,CAAC,EAAE,EACrG,aAAa,EACb;QAAEG,KAAK,EAAEH,GAAG,YAAYC,KAAK,GAAGD,GAAG,CAACE,OAAO,GAAGnB,MAAM,CAACiB,GAAG;MAAE,CAC5D,CAAC;IACH;IAEA,OAAO;MACLX,MAAM,EAAEwC,EAAE,CAACO,MAAM,CAAC;IACpB,CAAC;EACH;AACF,CAAC","ignoreList":[]}
@@ -121,18 +121,36 @@ function coerceValue(raw, schema) {
121
121
  return [singleValue];
122
122
  }
123
123
  if ((0, _typeGuards.isObject)(schema)) {
124
+ let obj = raw;
124
125
  // If it's a JSON string, parse it
125
126
  if (typeof raw === "string") {
126
127
  const trimmed = raw.trim();
127
128
  if (trimmed.startsWith("{")) {
128
129
  try {
129
- return JSON.parse(trimmed);
130
+ obj = JSON.parse(trimmed);
130
131
  } catch {
131
132
  return raw;
132
133
  }
134
+ } else {
135
+ return raw;
133
136
  }
134
137
  }
135
- return raw;
138
+ // Recurse into properties to coerce nested values
139
+ if (typeof obj === "object" && obj !== null && !Array.isArray(obj)) {
140
+ const props = schema.properties;
141
+ if (props) {
142
+ const result = {
143
+ ...obj
144
+ };
145
+ for (const [key, propSchema] of Object.entries(props)) {
146
+ if (key in result) {
147
+ result[key] = coerceValue(result[key], propSchema);
148
+ }
149
+ }
150
+ return result;
151
+ }
152
+ }
153
+ return obj;
136
154
  }
137
155
  if ((0, _typeGuards.isString)(schema)) {
138
156
  if (typeof raw === "string") return raw;