@sundaeswap/sprinkles 0.4.0 → 0.6.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 (140) hide show
  1. package/dist/cjs/Sprinkle/__tests__/encryption.test.js +22 -8
  2. package/dist/cjs/Sprinkle/__tests__/encryption.test.js.map +1 -1
  3. package/dist/cjs/Sprinkle/__tests__/enhancements.test.js +37 -46
  4. package/dist/cjs/Sprinkle/__tests__/enhancements.test.js.map +1 -1
  5. package/dist/cjs/Sprinkle/__tests__/field-utils.test.js +170 -0
  6. package/dist/cjs/Sprinkle/__tests__/field-utils.test.js.map +1 -0
  7. package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js +283 -81
  8. package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
  9. package/dist/cjs/Sprinkle/__tests__/formatting.test.js +97 -0
  10. package/dist/cjs/Sprinkle/__tests__/formatting.test.js.map +1 -0
  11. package/dist/cjs/Sprinkle/__tests__/show-menu.test.js +97 -7
  12. package/dist/cjs/Sprinkle/__tests__/show-menu.test.js.map +1 -1
  13. package/dist/cjs/Sprinkle/__tests__/tx-dialog.test.js +30 -0
  14. package/dist/cjs/Sprinkle/__tests__/tx-dialog.test.js.map +1 -1
  15. package/dist/cjs/Sprinkle/encryption.js +131 -0
  16. package/dist/cjs/Sprinkle/encryption.js.map +1 -0
  17. package/dist/cjs/Sprinkle/index.js +427 -438
  18. package/dist/cjs/Sprinkle/index.js.map +1 -1
  19. package/dist/cjs/Sprinkle/menus/array-menu.js +195 -0
  20. package/dist/cjs/Sprinkle/menus/array-menu.js.map +1 -0
  21. package/dist/cjs/Sprinkle/menus/field-menu.js +161 -0
  22. package/dist/cjs/Sprinkle/menus/field-menu.js.map +1 -0
  23. package/dist/cjs/Sprinkle/menus/index.js +33 -0
  24. package/dist/cjs/Sprinkle/menus/index.js.map +1 -0
  25. package/dist/cjs/Sprinkle/menus/object-menu.js +324 -0
  26. package/dist/cjs/Sprinkle/menus/object-menu.js.map +1 -0
  27. package/dist/cjs/Sprinkle/prompts.js +459 -0
  28. package/dist/cjs/Sprinkle/prompts.js.map +1 -0
  29. package/dist/cjs/Sprinkle/schemas.js +97 -0
  30. package/dist/cjs/Sprinkle/schemas.js.map +1 -0
  31. package/dist/cjs/Sprinkle/tx-dialog.js +101 -0
  32. package/dist/cjs/Sprinkle/tx-dialog.js.map +1 -0
  33. package/dist/cjs/Sprinkle/type-guards.js +89 -0
  34. package/dist/cjs/Sprinkle/type-guards.js.map +1 -0
  35. package/dist/cjs/Sprinkle/types.js +73 -0
  36. package/dist/cjs/Sprinkle/types.js.map +1 -0
  37. package/dist/cjs/Sprinkle/utils/field-utils.js +154 -0
  38. package/dist/cjs/Sprinkle/utils/field-utils.js.map +1 -0
  39. package/dist/cjs/Sprinkle/utils/formatting.js +126 -0
  40. package/dist/cjs/Sprinkle/utils/formatting.js.map +1 -0
  41. package/dist/cjs/Sprinkle/utils/index.js +56 -0
  42. package/dist/cjs/Sprinkle/utils/index.js.map +1 -0
  43. package/dist/cjs/Sprinkle/wallet.js +98 -0
  44. package/dist/cjs/Sprinkle/wallet.js.map +1 -0
  45. package/dist/esm/Sprinkle/__tests__/encryption.test.js +22 -8
  46. package/dist/esm/Sprinkle/__tests__/encryption.test.js.map +1 -1
  47. package/dist/esm/Sprinkle/__tests__/enhancements.test.js +37 -46
  48. package/dist/esm/Sprinkle/__tests__/enhancements.test.js.map +1 -1
  49. package/dist/esm/Sprinkle/__tests__/field-utils.test.js +168 -0
  50. package/dist/esm/Sprinkle/__tests__/field-utils.test.js.map +1 -0
  51. package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js +284 -82
  52. package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
  53. package/dist/esm/Sprinkle/__tests__/formatting.test.js +95 -0
  54. package/dist/esm/Sprinkle/__tests__/formatting.test.js.map +1 -0
  55. package/dist/esm/Sprinkle/__tests__/show-menu.test.js +98 -8
  56. package/dist/esm/Sprinkle/__tests__/show-menu.test.js.map +1 -1
  57. package/dist/esm/Sprinkle/__tests__/tx-dialog.test.js +30 -0
  58. package/dist/esm/Sprinkle/__tests__/tx-dialog.test.js.map +1 -1
  59. package/dist/esm/Sprinkle/encryption.js +117 -0
  60. package/dist/esm/Sprinkle/encryption.js.map +1 -0
  61. package/dist/esm/Sprinkle/index.js +248 -425
  62. package/dist/esm/Sprinkle/index.js.map +1 -1
  63. package/dist/esm/Sprinkle/menus/array-menu.js +190 -0
  64. package/dist/esm/Sprinkle/menus/array-menu.js.map +1 -0
  65. package/dist/esm/Sprinkle/menus/field-menu.js +155 -0
  66. package/dist/esm/Sprinkle/menus/field-menu.js.map +1 -0
  67. package/dist/esm/Sprinkle/menus/index.js +8 -0
  68. package/dist/esm/Sprinkle/menus/index.js.map +1 -0
  69. package/dist/esm/Sprinkle/menus/object-menu.js +318 -0
  70. package/dist/esm/Sprinkle/menus/object-menu.js.map +1 -0
  71. package/dist/esm/Sprinkle/prompts.js +443 -0
  72. package/dist/esm/Sprinkle/prompts.js.map +1 -0
  73. package/dist/esm/Sprinkle/schemas.js +91 -0
  74. package/dist/esm/Sprinkle/schemas.js.map +1 -0
  75. package/dist/esm/Sprinkle/tx-dialog.js +90 -0
  76. package/dist/esm/Sprinkle/tx-dialog.js.map +1 -0
  77. package/dist/esm/Sprinkle/type-guards.js +66 -0
  78. package/dist/esm/Sprinkle/type-guards.js.map +1 -0
  79. package/dist/esm/Sprinkle/types.js +66 -0
  80. package/dist/esm/Sprinkle/types.js.map +1 -0
  81. package/dist/esm/Sprinkle/utils/field-utils.js +145 -0
  82. package/dist/esm/Sprinkle/utils/field-utils.js.map +1 -0
  83. package/dist/esm/Sprinkle/utils/formatting.js +118 -0
  84. package/dist/esm/Sprinkle/utils/formatting.js.map +1 -0
  85. package/dist/esm/Sprinkle/utils/index.js +7 -0
  86. package/dist/esm/Sprinkle/utils/index.js.map +1 -0
  87. package/dist/esm/Sprinkle/wallet.js +90 -0
  88. package/dist/esm/Sprinkle/wallet.js.map +1 -0
  89. package/dist/types/Sprinkle/encryption.d.ts +43 -0
  90. package/dist/types/Sprinkle/encryption.d.ts.map +1 -0
  91. package/dist/types/Sprinkle/index.d.ts +17 -177
  92. package/dist/types/Sprinkle/index.d.ts.map +1 -1
  93. package/dist/types/Sprinkle/menus/array-menu.d.ts +31 -0
  94. package/dist/types/Sprinkle/menus/array-menu.d.ts.map +1 -0
  95. package/dist/types/Sprinkle/menus/field-menu.d.ts +34 -0
  96. package/dist/types/Sprinkle/menus/field-menu.d.ts.map +1 -0
  97. package/dist/types/Sprinkle/menus/index.d.ts +10 -0
  98. package/dist/types/Sprinkle/menus/index.d.ts.map +1 -0
  99. package/dist/types/Sprinkle/menus/object-menu.d.ts +34 -0
  100. package/dist/types/Sprinkle/menus/object-menu.d.ts.map +1 -0
  101. package/dist/types/Sprinkle/prompts.d.ts +119 -0
  102. package/dist/types/Sprinkle/prompts.d.ts.map +1 -0
  103. package/dist/types/Sprinkle/schemas.d.ts +125 -0
  104. package/dist/types/Sprinkle/schemas.d.ts.map +1 -0
  105. package/dist/types/Sprinkle/tx-dialog.d.ts +37 -0
  106. package/dist/types/Sprinkle/tx-dialog.d.ts.map +1 -0
  107. package/dist/types/Sprinkle/type-guards.d.ts +45 -0
  108. package/dist/types/Sprinkle/type-guards.d.ts.map +1 -0
  109. package/dist/types/Sprinkle/types.d.ts +115 -0
  110. package/dist/types/Sprinkle/types.d.ts.map +1 -0
  111. package/dist/types/Sprinkle/utils/field-utils.d.ts +47 -0
  112. package/dist/types/Sprinkle/utils/field-utils.d.ts.map +1 -0
  113. package/dist/types/Sprinkle/utils/formatting.d.ts +30 -0
  114. package/dist/types/Sprinkle/utils/formatting.d.ts.map +1 -0
  115. package/dist/types/Sprinkle/wallet.d.ts +27 -0
  116. package/dist/types/Sprinkle/wallet.d.ts.map +1 -0
  117. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  118. package/package.json +1 -1
  119. package/src/Sprinkle/__tests__/encryption.test.ts +23 -8
  120. package/src/Sprinkle/__tests__/enhancements.test.ts +34 -47
  121. package/src/Sprinkle/__tests__/field-utils.test.ts +191 -0
  122. package/src/Sprinkle/__tests__/fill-in-struct.test.ts +301 -86
  123. package/src/Sprinkle/__tests__/formatting.test.ts +115 -0
  124. package/src/Sprinkle/__tests__/show-menu.test.ts +102 -8
  125. package/src/Sprinkle/__tests__/tx-dialog.test.ts +30 -0
  126. package/src/Sprinkle/encryption.ts +130 -0
  127. package/src/Sprinkle/index.ts +368 -598
  128. package/src/Sprinkle/menus/array-menu.ts +191 -0
  129. package/src/Sprinkle/menus/field-menu.ts +145 -0
  130. package/src/Sprinkle/menus/index.ts +12 -0
  131. package/src/Sprinkle/menus/object-menu.ts +336 -0
  132. package/src/Sprinkle/prompts.ts +551 -0
  133. package/src/Sprinkle/schemas.ts +111 -0
  134. package/src/Sprinkle/tx-dialog.ts +100 -0
  135. package/src/Sprinkle/type-guards.ts +93 -0
  136. package/src/Sprinkle/types.ts +116 -0
  137. package/src/Sprinkle/utils/field-utils.ts +158 -0
  138. package/src/Sprinkle/utils/formatting.ts +127 -0
  139. package/src/Sprinkle/utils/index.ts +17 -0
  140. package/src/Sprinkle/wallet.ts +133 -0
@@ -4,18 +4,195 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
+ Sprinkle: true,
8
+ UserCancelledError: true,
7
9
  NetworkSchema: true,
8
10
  MultisigScriptModule: true,
9
11
  MultisigScript: true,
10
12
  ProviderSettingsSchema: true,
11
13
  WalletSettingsSchema: true,
12
- Sprinkle: true
14
+ isOptional: true,
15
+ isImport: true,
16
+ isArray: true,
17
+ isBigInt: true,
18
+ isLiteral: true,
19
+ isObject: true,
20
+ isRef: true,
21
+ isString: true,
22
+ isThis: true,
23
+ isTuple: true,
24
+ isUnion: true,
25
+ isSensitive: true,
26
+ isNull: true,
27
+ isNullable: true,
28
+ unwrapNullable: true,
29
+ hasDefault: true,
30
+ getDefault: true,
31
+ GetProvider: true,
32
+ GetWallet: true,
33
+ GetBlaze: true
13
34
  };
14
- exports.WalletSettingsSchema = exports.Sprinkle = exports.ProviderSettingsSchema = exports.NetworkSchema = exports.MultisigScriptModule = exports.MultisigScript = void 0;
15
- var _query = require("@blaze-cardano/query");
35
+ Object.defineProperty(exports, "GetBlaze", {
36
+ enumerable: true,
37
+ get: function () {
38
+ return _wallet.GetBlaze;
39
+ }
40
+ });
41
+ Object.defineProperty(exports, "GetProvider", {
42
+ enumerable: true,
43
+ get: function () {
44
+ return _wallet.GetProvider;
45
+ }
46
+ });
47
+ Object.defineProperty(exports, "GetWallet", {
48
+ enumerable: true,
49
+ get: function () {
50
+ return _wallet.GetWallet;
51
+ }
52
+ });
53
+ Object.defineProperty(exports, "MultisigScript", {
54
+ enumerable: true,
55
+ get: function () {
56
+ return _schemas.MultisigScript;
57
+ }
58
+ });
59
+ Object.defineProperty(exports, "MultisigScriptModule", {
60
+ enumerable: true,
61
+ get: function () {
62
+ return _schemas.MultisigScriptModule;
63
+ }
64
+ });
65
+ Object.defineProperty(exports, "NetworkSchema", {
66
+ enumerable: true,
67
+ get: function () {
68
+ return _schemas.NetworkSchema;
69
+ }
70
+ });
71
+ Object.defineProperty(exports, "ProviderSettingsSchema", {
72
+ enumerable: true,
73
+ get: function () {
74
+ return _schemas.ProviderSettingsSchema;
75
+ }
76
+ });
77
+ exports.Sprinkle = void 0;
78
+ Object.defineProperty(exports, "UserCancelledError", {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _types.UserCancelledError;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "WalletSettingsSchema", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _schemas.WalletSettingsSchema;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "getDefault", {
91
+ enumerable: true,
92
+ get: function () {
93
+ return _typeGuards.getDefault;
94
+ }
95
+ });
96
+ Object.defineProperty(exports, "hasDefault", {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _typeGuards.hasDefault;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, "isArray", {
103
+ enumerable: true,
104
+ get: function () {
105
+ return _typeGuards.isArray;
106
+ }
107
+ });
108
+ Object.defineProperty(exports, "isBigInt", {
109
+ enumerable: true,
110
+ get: function () {
111
+ return _typeGuards.isBigInt;
112
+ }
113
+ });
114
+ Object.defineProperty(exports, "isImport", {
115
+ enumerable: true,
116
+ get: function () {
117
+ return _typeGuards.isImport;
118
+ }
119
+ });
120
+ Object.defineProperty(exports, "isLiteral", {
121
+ enumerable: true,
122
+ get: function () {
123
+ return _typeGuards.isLiteral;
124
+ }
125
+ });
126
+ Object.defineProperty(exports, "isNull", {
127
+ enumerable: true,
128
+ get: function () {
129
+ return _typeGuards.isNull;
130
+ }
131
+ });
132
+ Object.defineProperty(exports, "isNullable", {
133
+ enumerable: true,
134
+ get: function () {
135
+ return _typeGuards.isNullable;
136
+ }
137
+ });
138
+ Object.defineProperty(exports, "isObject", {
139
+ enumerable: true,
140
+ get: function () {
141
+ return _typeGuards.isObject;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, "isOptional", {
145
+ enumerable: true,
146
+ get: function () {
147
+ return _typeGuards.isOptional;
148
+ }
149
+ });
150
+ Object.defineProperty(exports, "isRef", {
151
+ enumerable: true,
152
+ get: function () {
153
+ return _typeGuards.isRef;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, "isSensitive", {
157
+ enumerable: true,
158
+ get: function () {
159
+ return _typeGuards.isSensitive;
160
+ }
161
+ });
162
+ Object.defineProperty(exports, "isString", {
163
+ enumerable: true,
164
+ get: function () {
165
+ return _typeGuards.isString;
166
+ }
167
+ });
168
+ Object.defineProperty(exports, "isThis", {
169
+ enumerable: true,
170
+ get: function () {
171
+ return _typeGuards.isThis;
172
+ }
173
+ });
174
+ Object.defineProperty(exports, "isTuple", {
175
+ enumerable: true,
176
+ get: function () {
177
+ return _typeGuards.isTuple;
178
+ }
179
+ });
180
+ Object.defineProperty(exports, "isUnion", {
181
+ enumerable: true,
182
+ get: function () {
183
+ return _typeGuards.isUnion;
184
+ }
185
+ });
186
+ Object.defineProperty(exports, "unwrapNullable", {
187
+ enumerable: true,
188
+ get: function () {
189
+ return _typeGuards.unwrapNullable;
190
+ }
191
+ });
16
192
  var _sdk = require("@blaze-cardano/sdk");
17
193
  var _core = require("@blaze-cardano/core");
18
- var _prompts = require("@inquirer/prompts");
194
+ var _prompts = require("./prompts.js");
195
+ var _yoctocolorsCjs = _interopRequireDefault(require("yoctocolors-cjs"));
19
196
  var _typebox = require("@sinclair/typebox");
20
197
  Object.keys(_typebox).forEach(function (key) {
21
198
  if (key === "default" || key === "__esModule") return;
@@ -30,102 +207,26 @@ Object.keys(_typebox).forEach(function (key) {
30
207
  });
31
208
  var fs = _interopRequireWildcard(require("fs"));
32
209
  var path = _interopRequireWildcard(require("path"));
210
+ var _types = require("./types.js");
211
+ var _schemas = require("./schemas.js");
212
+ var _typeGuards = require("./type-guards.js");
213
+ var _wallet = require("./wallet.js");
214
+ var _encryption = require("./encryption.js");
215
+ var _txDialog = require("./tx-dialog.js");
216
+ var _index = require("./menus/index.js");
217
+ var _formatting = require("./utils/formatting.js");
218
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
33
219
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
34
220
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
35
221
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
36
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
37
- const isOptional = t => t[_typebox.OptionalKind] === "Optional";
38
- const isImport = t => t[_typebox.Kind] === "Import";
39
- const isArray = t => t[_typebox.Kind] === "Array";
40
- const isBigInt = t => t[_typebox.Kind] === "BigInt";
41
- // const isBoolean = (t: TSchema): t is TBoolean => t[Kind] === "Boolean";
42
- const isLiteral = t => t[_typebox.Kind] === "Literal";
43
- // const isNumber = (t: TSchema): t is TNumber => t[Kind] === "Number";
44
- const isObject = t => t[_typebox.Kind] === "Object";
45
- // const isRecord = (t: TSchema): t is TRecord => t[Kind] === "Record";
46
- const isRef = t => t[_typebox.Kind] === "Ref";
47
- const isString = t => t[_typebox.Kind] === "String";
48
- const isThis = t => t[_typebox.Kind] === "This";
49
- const isTuple = t => t[_typebox.Kind] === "Tuple";
50
- const isUnion = t => t[_typebox.Kind] === "Union";
51
- // const isAny = (t: TSchema): t is TAny => t[Kind] === "Any";
52
-
53
- const isSensitive = t => isString(t) && t.sensitive === true;
54
- const NetworkSchema = exports.NetworkSchema = _typebox.Type.Union([_typebox.Type.Literal("mainnet"), _typebox.Type.Literal("preview"), _typebox.Type.Literal("preprod")]);
55
- const MultisigScriptModule = exports.MultisigScriptModule = _typebox.Type.Module({
56
- MultisigScript: _typebox.Type.Union([_typebox.Type.Object({
57
- Signature: _typebox.Type.Object({
58
- key_hash: _typebox.Type.String()
59
- }, {
60
- ctor: 0n
61
- })
62
- }), _typebox.Type.Object({
63
- AllOf: _typebox.Type.Object({
64
- scripts: _typebox.Type.Array(_typebox.Type.Ref("MultisigScript"))
65
- }, {
66
- ctor: 1n
67
- })
68
- }), _typebox.Type.Object({
69
- AnyOf: _typebox.Type.Object({
70
- scripts: _typebox.Type.Array(_typebox.Type.Ref("MultisigScript"))
71
- }, {
72
- ctor: 2n
73
- })
74
- }), _typebox.Type.Object({
75
- AtLeast: _typebox.Type.Object({
76
- required: _typebox.Type.BigInt(),
77
- scripts: _typebox.Type.Array(_typebox.Type.Ref("MultisigScript"))
78
- }, {
79
- ctor: 3n
80
- })
81
- }), _typebox.Type.Object({
82
- Before: _typebox.Type.Object({
83
- time: _typebox.Type.BigInt()
84
- }, {
85
- ctor: 4n
86
- })
87
- }), _typebox.Type.Object({
88
- After: _typebox.Type.Object({
89
- time: _typebox.Type.BigInt()
90
- }, {
91
- ctor: 5n
92
- })
93
- }), _typebox.Type.Object({
94
- Script: _typebox.Type.Object({
95
- script_hash: _typebox.Type.String()
96
- }, {
97
- ctor: 6n
98
- })
99
- })])
100
- });
101
- const MultisigScript = exports.MultisigScript = MultisigScriptModule.Import("MultisigScript");
102
- const ProviderSettingsSchema = exports.ProviderSettingsSchema = _typebox.Type.Union([_typebox.Type.Object({
103
- type: _typebox.Type.Literal("blockfrost"),
104
- projectId: _typebox.Type.String({
105
- minLength: 1,
106
- title: "Blockfrost Project ID"
107
- })
108
- }), _typebox.Type.Object({
109
- type: _typebox.Type.Literal("maestro"),
110
- apiKey: _typebox.Type.String({
111
- minLength: 1,
112
- title: "Maestro API Key"
113
- })
114
- })]);
115
- const WalletSettingsSchema = exports.WalletSettingsSchema = _typebox.Type.Union([_typebox.Type.Object({
116
- type: _typebox.Type.Literal("hot"),
117
- privateKey: _typebox.Type.String({
118
- minLength: 1,
119
- title: "Hot Wallet Private Key",
120
- sensitive: true
121
- })
122
- }), _typebox.Type.Object({
123
- type: _typebox.Type.Literal("cold"),
124
- address: _typebox.Type.String({
125
- minLength: 1,
126
- title: "Cold Wallet Address"
127
- })
128
- })]);
222
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // Re-export types from types.ts
223
+ // Re-export schemas from schemas.ts
224
+ // Import and re-export type guards
225
+ // Import schemas for use in this file
226
+ // Import and re-export wallet utilities
227
+ // Import encryption utilities
228
+ // Import tx-dialog utilities
229
+ // Import menu modules
129
230
  class Sprinkle {
130
231
  constructor(type, storagePath, options) {
131
232
  _defineProperty(this, "storagePath", void 0);
@@ -232,32 +333,42 @@ class Sprinkle {
232
333
  meta: this.profileMeta,
233
334
  settings: settingsToSave,
234
335
  defaults: this.defaults
235
- }, Sprinkle.bigIntReplacer, 2);
336
+ }, _encryption.bigIntReplacer, 2);
236
337
  fs.writeFileSync(filePath, jsonContent, "utf-8");
237
338
  }
238
339
  async promptProfileMeta(defaultName, defaultDescription) {
239
- const name = await (0, _prompts.input)({
340
+ const name = await (0, _prompts.inputCancellable)({
240
341
  message: "Profile name:",
241
342
  default: defaultName,
242
343
  validate: v => v.trim().length > 0 ? true : "Name cannot be empty"
243
344
  });
244
- const description = await (0, _prompts.input)({
345
+ if (name === null) return null; // User cancelled
346
+ const description = await (0, _prompts.inputCancellable)({
245
347
  message: "Profile description (optional):",
246
348
  default: defaultDescription ?? ""
247
349
  });
350
+ if (description === null) return null; // User cancelled
248
351
  return {
249
352
  name,
250
353
  description: description || undefined
251
354
  };
252
355
  }
253
356
  async createProfile() {
357
+ const result = await this.promptProfileMeta();
358
+ if (result === null) return; // User cancelled
254
359
  const {
255
360
  name,
256
361
  description
257
- } = await this.promptProfileMeta();
362
+ } = result;
258
363
  const profilesDir = Sprinkle.profilesDir(this.storagePath);
259
364
  const id = Sprinkle.findAvailableId(profilesDir, Sprinkle.sanitizeProfileId(name));
260
365
  const now = new Date().toISOString();
366
+
367
+ // Snapshot current state in case we need to restore on cancellation
368
+ const prevProfileId = this.profileId;
369
+ const prevProfileMeta = this.profileMeta;
370
+ const prevDefaults = this.defaults;
371
+ const prevSettings = this.settings;
261
372
  this.profileId = id;
262
373
  this.profileMeta = {
263
374
  name,
@@ -266,7 +377,19 @@ class Sprinkle {
266
377
  updatedAt: now
267
378
  };
268
379
  this.defaults = {};
269
- this.settings = await this.FillInStruct(this.type);
380
+ try {
381
+ this.settings = await this.FillInStruct(this.type);
382
+ } catch (e) {
383
+ // Restore previous state on cancellation
384
+ if (e instanceof _types.UserCancelledError) {
385
+ this.profileId = prevProfileId;
386
+ this.profileMeta = prevProfileMeta;
387
+ this.defaults = prevDefaults;
388
+ this.settings = prevSettings;
389
+ return;
390
+ }
391
+ throw e;
392
+ }
270
393
  this.saveProfile();
271
394
  fs.writeFileSync(Sprinkle.activeProfilePath(this.storagePath), id, "utf-8");
272
395
  }
@@ -291,7 +414,7 @@ class Sprinkle {
291
414
  fs.mkdirSync(profilesDir, {
292
415
  recursive: true
293
416
  });
294
- fs.writeFileSync(Sprinkle.profilePath(this.storagePath, "default"), JSON.stringify(profileData, Sprinkle.bigIntReplacer, 2), "utf-8");
417
+ fs.writeFileSync(Sprinkle.profilePath(this.storagePath, "default"), JSON.stringify(profileData, _encryption.bigIntReplacer, 2), "utf-8");
295
418
  fs.writeFileSync(Sprinkle.activeProfilePath(this.storagePath), "default", "utf-8");
296
419
  // Backup legacy file
297
420
  fs.renameSync(legacyPath, `${legacyPath}.bak`);
@@ -328,23 +451,26 @@ class Sprinkle {
328
451
  }
329
452
  async selectProfile(profiles) {
330
453
  const available = profiles ?? this.scanProfiles();
331
- const selection = await (0, _prompts.select)({
454
+ const selection = await (0, _prompts.selectCancellable)({
332
455
  message: "Select a profile:",
333
456
  choices: available.map(p => ({
334
457
  name: p.meta.description ? `${p.meta.name} - ${p.meta.description}` : p.meta.name,
335
458
  value: p.id
336
459
  }))
337
460
  });
461
+ if (selection === null) return; // User cancelled
338
462
  await this.loadProfile(selection);
339
463
  }
340
464
 
341
465
  // --- Profile management (CRUD) ---
342
466
 
343
467
  async duplicateProfile() {
468
+ const result = await this.promptProfileMeta(`${this.profileMeta.name} (copy)`, this.profileMeta.description);
469
+ if (result === null) return; // User cancelled
344
470
  const {
345
471
  name,
346
472
  description
347
- } = await this.promptProfileMeta(`${this.profileMeta.name} (copy)`, this.profileMeta.description);
473
+ } = result;
348
474
  const profilesDir = Sprinkle.profilesDir(this.storagePath);
349
475
  const id = Sprinkle.findAvailableId(profilesDir, Sprinkle.sanitizeProfileId(name));
350
476
  const now = new Date().toISOString();
@@ -359,15 +485,17 @@ class Sprinkle {
359
485
  },
360
486
  settings: settingsToSave,
361
487
  defaults: this.defaults
362
- }, Sprinkle.bigIntReplacer, 2);
488
+ }, _encryption.bigIntReplacer, 2);
363
489
  fs.writeFileSync(path.join(profilesDir, `${id}.json`), jsonContent, "utf-8");
364
490
  console.log(`Profile "${name}" created as a copy.`);
365
491
  }
366
492
  async renameProfile() {
493
+ const result = await this.promptProfileMeta(this.profileMeta.name, this.profileMeta.description);
494
+ if (result === null) return; // User cancelled
367
495
  const {
368
496
  name,
369
497
  description
370
- } = await this.promptProfileMeta(this.profileMeta.name, this.profileMeta.description);
498
+ } = result;
371
499
  const newId = Sprinkle.sanitizeProfileId(name);
372
500
  const oldId = this.profileId;
373
501
  this.profileMeta.name = name;
@@ -395,34 +523,39 @@ class Sprinkle {
395
523
  console.log("Cannot delete the only profile.");
396
524
  return;
397
525
  }
398
- const toDelete = await (0, _prompts.select)({
526
+ const toDelete = await (0, _prompts.selectCancellable)({
399
527
  message: "Select a profile to delete:",
400
- choices: [...others.map(p => ({
528
+ choices: others.map(p => ({
401
529
  name: p.meta.description ? `${p.meta.name} - ${p.meta.description}` : p.meta.name,
402
530
  value: p.id
403
- })), {
404
- name: "Cancel",
405
- value: "__cancel__"
406
- }]
531
+ }))
407
532
  });
408
- if (toDelete === "__cancel__") return;
409
- const profileToDelete = others.find(p => p.id === toDelete);
410
- const confirmed = await (0, _prompts.confirm)({
411
- message: `Delete profile "${profileToDelete?.meta.name ?? toDelete}"? This cannot be undone.`,
533
+ if (toDelete === null) return; // User cancelled
534
+
535
+ const profileId = toDelete;
536
+ const profileToDelete = others.find(p => p.id === profileId);
537
+ const confirmed = await (0, _prompts.confirmCancellable)({
538
+ message: `Delete profile "${profileToDelete?.meta.name ?? profileId}"? This cannot be undone.`,
412
539
  default: false
413
540
  });
541
+ if (confirmed === null) return; // User cancelled
542
+
414
543
  if (confirmed) {
415
- fs.unlinkSync(Sprinkle.profilePath(this.storagePath, toDelete));
416
- console.log(`Profile "${profileToDelete?.meta.name ?? toDelete}" deleted.`);
544
+ fs.unlinkSync(Sprinkle.profilePath(this.storagePath, profileId));
545
+ console.log(`Profile "${profileToDelete?.meta.name ?? profileId}" deleted.`);
417
546
  }
418
547
  }
419
548
 
420
549
  // --- Menu ---
421
550
 
422
551
  async showMenu(menu) {
423
- return this._showMenu(menu, true);
552
+ return this._showMenu(menu, true, [menu.title]);
424
553
  }
425
- async _showMenu(menu, main) {
554
+ async _showMenu(menu, main, path, clearPrevious = false) {
555
+ // Clear previous breadcrumb if coming back from action/submenu
556
+ if (clearPrevious) {
557
+ process.stdout.write("\x1b[1A\x1b[2K\x1b[G");
558
+ }
426
559
  if (menu.beforeShow) {
427
560
  await menu.beforeShow(this);
428
561
  }
@@ -454,14 +587,43 @@ class Sprinkle {
454
587
  value: -1
455
588
  });
456
589
  }
457
- const selection = await (0, _prompts.select)({
590
+
591
+ // Show breadcrumb
592
+ const breadcrumb = path.join(" > ");
593
+ console.log(_yoctocolorsCjs.default.dim("🍞 " + breadcrumb));
594
+ const selectionResult = await (0, _prompts.selectWithClear)({
458
595
  message: "Select an option:",
459
596
  choices: choices
460
597
  });
598
+ // Handle escape (null) as Back
599
+ // Don't clear here - let the caller's clearPrevious handle it
600
+ if (selectionResult === null) {
601
+ return;
602
+ }
603
+ const selection = selectionResult;
461
604
  if (selection === -5) {
462
605
  const settingsMenu = {
463
606
  title: "Settings & Profiles",
464
607
  items: [{
608
+ title: "View settings",
609
+ action: async () => {
610
+ const jsonStr = JSON.stringify(this.getDisplaySettings(), _encryption.bigIntReplacer, 2);
611
+ const jsonLines = jsonStr.split("\n").length;
612
+ console.log(jsonStr);
613
+
614
+ // Wait for user to press Enter
615
+ await (0, _prompts.selectWithClear)({
616
+ message: "Press Enter to continue...",
617
+ choices: [{
618
+ name: "Continue",
619
+ value: "continue"
620
+ }]
621
+ });
622
+
623
+ // Clear the JSON output
624
+ process.stdout.write("\x1b[1A\x1b[2K".repeat(jsonLines) + "\x1b[G");
625
+ }
626
+ }, {
465
627
  title: "Edit settings",
466
628
  action: async () => {
467
629
  this.settings = await this.EditStruct(this.type, this.settings);
@@ -500,24 +662,28 @@ class Sprinkle {
500
662
  }
501
663
  }]
502
664
  };
503
- await this._showMenu(settingsMenu, false);
504
- await this._showMenu(menu, main);
665
+ await this._showMenu(settingsMenu, false, [...path, "Settings & Profiles"], true);
666
+ await this._showMenu(menu, main, path, true);
505
667
  return;
506
668
  }
507
669
  if (selection === -1) {
670
+ // Don't clear here - let the caller's clearPrevious handle it
508
671
  return;
509
672
  }
510
673
  const selectedItem = menu.items[selection];
511
674
  if ("action" in selectedItem) {
675
+ // Update breadcrumb to show current action
676
+ process.stdout.write("\x1b[1A\x1b[2K\x1b[G");
677
+ console.log(_yoctocolorsCjs.default.dim("🍞 " + [...path, selectedItem.title].join(" > ")));
512
678
  const result = await selectedItem.action(this);
513
679
  if (result instanceof Sprinkle) {
514
680
  this.settings = result.settings;
515
681
  this.saveSettings();
516
682
  }
517
- await this._showMenu(menu, main);
683
+ await this._showMenu(menu, main, path, true);
518
684
  } else {
519
- await this._showMenu(selectedItem, false);
520
- await this._showMenu(menu, main);
685
+ await this._showMenu(selectedItem, false, [...path, selectedItem.title], true);
686
+ await this._showMenu(menu, main, path, true);
521
687
  }
522
688
  return;
523
689
  }
@@ -529,40 +695,13 @@ class Sprinkle {
529
695
  return sprinkle;
530
696
  }
531
697
  static async GetProvider(network, settings) {
532
- switch (settings.type) {
533
- case "blockfrost":
534
- return new _query.Blockfrost({
535
- network: `cardano-${network}`,
536
- projectId: settings.projectId
537
- });
538
- case "maestro":
539
- // Dynamic import - Maestro may or may not be exported depending on @blaze-cardano/query version
540
- const queryModule = await Promise.resolve().then(() => _interopRequireWildcard(require("@blaze-cardano/query")));
541
- if (!queryModule.Maestro) {
542
- throw new Error("Maestro is not available in the installed version of @blaze-cardano/query. Please install a version that includes Maestro support.");
543
- }
544
- return new queryModule.Maestro({
545
- network: network,
546
- apiKey: settings.apiKey
547
- });
548
- default:
549
- throw new Error("Invalid provider type");
550
- }
698
+ return (0, _wallet.GetProvider)(network, settings);
551
699
  }
552
700
  static async GetWallet(settings, provider) {
553
- switch (settings.type) {
554
- case "hot":
555
- return _sdk.HotWallet.fromMasterkey(_sdk.Core.Bip32PrivateKeyHex(settings.privateKey), provider, provider.network);
556
- case "cold":
557
- return new _sdk.ColdWallet(_sdk.Core.Address.fromBech32(settings.address), provider.network, provider);
558
- default:
559
- throw new Error("Invalid wallet type");
560
- }
701
+ return (0, _wallet.GetWallet)(settings, provider);
561
702
  }
562
703
  static async GetBlaze(network, providerSettings, walletSettings) {
563
- const provider = await Sprinkle.GetProvider(network, providerSettings);
564
- const wallet = await Sprinkle.GetWallet(walletSettings, provider);
565
- return _sdk.Blaze.from(provider, wallet);
704
+ return (0, _wallet.GetBlaze)(network, providerSettings, walletSettings);
566
705
  }
567
706
 
568
707
  /**
@@ -571,30 +710,10 @@ class Sprinkle {
571
710
  * @returns The Bip32PrivateKey hex string for storage
572
711
  */
573
712
  static async generateWalletFromMnemonic() {
574
- const mnemonic = _sdk.Core.generateMnemonic(_core.wordlist, 256); // 24 words
575
- const words = mnemonic.split(" ");
576
- console.log("\n=== NEW WALLET GENERATED ===\n");
577
- console.log("IMPORTANT: Save these 24 words in a secure location.");
578
- console.log("This is the ONLY way to recover your wallet.\n");
579
-
580
- // Display in 4 columns
581
- for (let i = 0; i < 6; i++) {
582
- console.log(`${(i + 1).toString().padStart(2)}. ${words[i].padEnd(12)} ` + `${(i + 7).toString().padStart(2)}. ${words[i + 6].padEnd(12)} ` + `${(i + 13).toString().padStart(2)}. ${words[i + 12].padEnd(12)} ` + `${(i + 19).toString().padStart(2)}. ${words[i + 18]}`);
583
- }
584
- console.log("");
585
- const confirmed = await (0, _prompts.confirm)({
586
- message: "Have you saved your recovery phrase?",
587
- default: false
588
- });
589
- if (!confirmed) {
590
- throw new Error("Wallet generation cancelled - recovery phrase not saved");
591
- }
592
- const entropy = _sdk.Core.mnemonicToEntropy(mnemonic, _core.wordlist);
593
- const masterKey = _sdk.Core.Bip32PrivateKey.fromBip39Entropy(Buffer.from(entropy), "");
594
- return masterKey.hex();
713
+ return (0, _wallet.generateWalletFromMnemonic)();
595
714
  }
596
715
  static async SearchSelect(opts) {
597
- return (0, _prompts.search)(opts);
716
+ return (0, _prompts.searchCancellable)(opts);
598
717
  }
599
718
  static SettingsPath(storagePath) {
600
719
  return `${storagePath}${path.sep}settings.json`;
@@ -618,166 +737,21 @@ class Sprinkle {
618
737
  }
619
738
  }
620
739
  static bigIntReviver(key, value) {
621
- if (typeof value === "string" && /^\d+n$/.test(value)) {
622
- return BigInt(value.slice(0, -1));
623
- }
624
- return value;
625
- }
626
- static bigIntReplacer(_key, value) {
627
- return typeof value === "bigint" ? `${value.toString()}n` : value;
628
- }
629
- static collectSensitivePaths(type, prefix = "") {
630
- const paths = [];
631
- if (isObject(type)) {
632
- const fields = type["properties"];
633
- for (const [field, fieldType] of Object.entries(fields)) {
634
- const fieldPath = prefix ? `${prefix}.${field}` : field;
635
- if (isSensitive(fieldType)) {
636
- paths.push(fieldPath);
637
- }
638
- paths.push(...Sprinkle.collectSensitivePaths(fieldType, fieldPath));
639
- }
640
- }
641
- if (isUnion(type)) {
642
- for (const variant of type.anyOf) {
643
- paths.push(...Sprinkle.collectSensitivePaths(variant, prefix));
644
- }
645
- }
646
- return paths;
647
- }
648
- static getNestedValue(obj, path) {
649
- return path.split(".").reduce((o, k) => o?.[k], obj);
650
- }
651
- static setNestedValue(obj, path, value) {
652
- const keys = path.split(".");
653
- const last = keys.pop();
654
- const parent = keys.reduce((o, k) => o?.[k], obj);
655
- if (parent && typeof parent === "object") {
656
- parent[last] = value;
657
- }
740
+ return (0, _encryption.bigIntReviver)(key, value);
658
741
  }
659
742
  encryptSettings(settings) {
660
743
  if (!this.options.encryption) return settings;
661
- const clone = JSON.parse(JSON.stringify(settings, Sprinkle.bigIntReplacer), Sprinkle.bigIntReviver);
662
- const sensitivePaths = Sprinkle.collectSensitivePaths(this.type);
663
- for (const p of sensitivePaths) {
664
- const value = Sprinkle.getNestedValue(clone, p);
665
- if (typeof value === "string" && value.length > 0) {
666
- Sprinkle.setNestedValue(clone, p, this.options.encryption.encrypt(value));
667
- }
668
- }
669
- return clone;
744
+ return (0, _encryption.encryptSensitiveFields)(settings, this.type, this.options.encryption);
670
745
  }
671
746
  async decryptSettings(settings) {
672
747
  if (!this.options.encryption) return settings;
673
- const clone = JSON.parse(JSON.stringify(settings, Sprinkle.bigIntReplacer), Sprinkle.bigIntReviver);
674
- const sensitivePaths = Sprinkle.collectSensitivePaths(this.type);
675
- for (const p of sensitivePaths) {
676
- const value = Sprinkle.getNestedValue(clone, p);
677
- if (typeof value === "string" && value.length > 0) {
678
- Sprinkle.setNestedValue(clone, p, await this.options.encryption.decrypt(value));
679
- }
680
- }
681
- return clone;
748
+ return (0, _encryption.decryptSensitiveFields)(settings, this.type, this.options.encryption);
682
749
  }
683
750
  saveSettings() {
684
751
  this.saveProfile();
685
752
  }
686
753
  getDisplaySettings() {
687
- const clone = JSON.parse(JSON.stringify(this.settings, Sprinkle.bigIntReplacer), Sprinkle.bigIntReviver);
688
- const sensitivePaths = Sprinkle.collectSensitivePaths(this.type);
689
- for (const p of sensitivePaths) {
690
- const value = Sprinkle.getNestedValue(clone, p);
691
- if (typeof value === "string" && value.length > 0) {
692
- Sprinkle.setNestedValue(clone, p, "********");
693
- }
694
- }
695
- return clone;
696
- }
697
-
698
- // --- TxDialog Helpers ---
699
-
700
- /**
701
- * Get the payment key hash from a HotWallet's first address
702
- */
703
- async getWalletPaymentKeyHash(wallet) {
704
- try {
705
- const addresses = await wallet.getUsedAddresses();
706
- const address = addresses[0];
707
- if (!address) return null;
708
- const paymentCredential = address.asBase()?.getPaymentCredential();
709
- return paymentCredential?.hash?.toString() ?? null;
710
- } catch {
711
- return null;
712
- }
713
- }
714
-
715
- /**
716
- * Count the number of vkey signatures in a transaction's witness set
717
- */
718
- countSignatures(tx) {
719
- const vkeys = tx.witnessSet().vkeys();
720
- return vkeys ? vkeys.size() : 0;
721
- }
722
-
723
- /**
724
- * Check if a specific public key has already signed the transaction
725
- * Compares by vkey (public key bytes)
726
- */
727
- hasVkeySigned(tx, vkeyHex) {
728
- const vkeys = tx.witnessSet().vkeys();
729
- if (!vkeys) return false;
730
- const vkeyArray = vkeys.toCore();
731
- return vkeyArray.some(([vkey]) => vkey === vkeyHex);
732
- }
733
-
734
- /**
735
- * Get the list of required signer key hashes from the transaction body
736
- */
737
- getRequiredSigners(tx) {
738
- const requiredSigners = tx.body().requiredSigners();
739
- if (!requiredSigners) return [];
740
- return Array.from(requiredSigners.values()).map(s => s.toString());
741
- }
742
-
743
- /**
744
- * Compute the transaction body hash for display
745
- */
746
- getTxBodyHash(tx) {
747
- const bodyCbor = tx.body().toCbor();
748
- return (0, _core.blake2b_256)(bodyCbor);
749
- }
750
-
751
- /**
752
- * Format a hash for display: first 8 chars + ... + last 8 chars
753
- */
754
- formatHash(hash) {
755
- if (hash.length <= 20) return hash;
756
- return `${hash.slice(0, 8)}...${hash.slice(-8)}`;
757
- }
758
-
759
- /**
760
- * Merge signatures from source transaction into target transaction.
761
- * Prevents duplicate signatures by comparing vkey (public key).
762
- * Returns the count of newly added signatures.
763
- */
764
- mergeSignatures(target, source) {
765
- const targetWs = target.witnessSet();
766
- const sourceWs = source.witnessSet();
767
- const targetVkeys = targetWs.vkeys()?.toCore() ?? [];
768
- const sourceVkeys = sourceWs.vkeys()?.toCore() ?? [];
769
-
770
- // Find vkeys in source that aren't in target (by comparing public key)
771
- const existingPubKeys = new Set(targetVkeys.map(([vkey]) => vkey));
772
- const newVkeys = sourceVkeys.filter(([vkey]) => !existingPubKeys.has(vkey));
773
- if (newVkeys.length === 0) {
774
- return 0;
775
- }
776
-
777
- // Merge the new vkeys into target
778
- targetWs.setVkeys(_core.CborSet.fromCore([...targetVkeys, ...newVkeys], _core.VkeyWitness.fromCore));
779
- target.setWitnessSet(targetWs);
780
- return newVkeys.length;
754
+ return (0, _encryption.maskSensitiveFields)(this.settings, this.type);
781
755
  }
782
756
  async TxDialog(blaze, tx, opts) {
783
757
  let currentTx = tx;
@@ -805,16 +779,16 @@ class Sprinkle {
805
779
  }
806
780
  while (true) {
807
781
  // Display transaction status
808
- const txHash = this.getTxBodyHash(currentTx);
809
- const sigCount = this.countSignatures(currentTx);
810
- const requiredSigners = this.getRequiredSigners(currentTx);
782
+ const txHash = (0, _txDialog.getTxBodyHash)(currentTx);
783
+ const sigCount = (0, _txDialog.countSignatures)(currentTx);
784
+ const requiredSigners = (0, _txDialog.getRequiredSigners)(currentTx);
811
785
  console.log("");
812
- console.log(`Transaction: ${this.formatHash(txHash)}`);
786
+ console.log(`Transaction: ${(0, _txDialog.formatHash)(txHash)}`);
813
787
  if (requiredSigners.length > 0) {
814
788
  console.log(`Signatures: ${sigCount} of ${requiredSigners.length} required`);
815
789
  console.log("Required signers:");
816
790
  for (const signer of requiredSigners) {
817
- console.log(` - ${this.formatHash(signer)}`);
791
+ console.log(` - ${(0, _txDialog.formatHash)(signer)}`);
818
792
  }
819
793
  } else {
820
794
  console.log(`Signatures: ${sigCount}`);
@@ -864,11 +838,25 @@ class Sprinkle {
864
838
  name: "Cancel",
865
839
  value: "cancel"
866
840
  });
867
- const selection = await (0, _prompts.select)({
841
+ const selection = await (0, _prompts.selectWithClear)({
868
842
  message: "Select an option:",
869
843
  choices
870
844
  });
871
845
 
846
+ // Handle escape/cancel as cancel action
847
+ if (selection === null) {
848
+ if (hasSignedThisSession) {
849
+ return {
850
+ action: "signed",
851
+ tx: currentTx
852
+ };
853
+ }
854
+ return {
855
+ action: "cancelled",
856
+ tx: currentTx
857
+ };
858
+ }
859
+
872
860
  // Handle selection
873
861
  if (selection === "sign") {
874
862
  if (opts?.beforeSign) {
@@ -934,7 +922,7 @@ class Sprinkle {
934
922
  } else {
935
923
  const signedTx = await blaze.signTransaction(currentTx);
936
924
  // Merge signatures from signed tx into current tx
937
- const added = this.mergeSignatures(currentTx, signedTx);
925
+ const added = (0, _txDialog.mergeSignatures)(currentTx, signedTx);
938
926
  if (added > 0) {
939
927
  console.log(`Added ${added} signature(s).`);
940
928
  hasSignedThisSession = true;
@@ -966,10 +954,10 @@ class Sprinkle {
966
954
  continue;
967
955
  }
968
956
  if (selection === "import") {
969
- const cborInput = await (0, _prompts.input)({
957
+ const cborInput = await (0, _prompts.inputCancellable)({
970
958
  message: "Paste transaction CBOR (hex):"
971
959
  });
972
- if (!cborInput || cborInput.trim() === "") {
960
+ if (cborInput === null || cborInput.trim() === "") {
973
961
  console.log("No CBOR provided.");
974
962
  continue;
975
963
  }
@@ -977,21 +965,21 @@ class Sprinkle {
977
965
  const importedTx = _sdk.Core.Transaction.fromCbor((0, _core.TxCBOR)(cborInput.trim()));
978
966
 
979
967
  // Validate body hash matches
980
- const currentHash = this.getTxBodyHash(currentTx);
981
- const importedHash = this.getTxBodyHash(importedTx);
968
+ const currentHash = (0, _txDialog.getTxBodyHash)(currentTx);
969
+ const importedHash = (0, _txDialog.getTxBodyHash)(importedTx);
982
970
  if (currentHash !== importedHash) {
983
- const proceed = await (0, _prompts.confirm)({
984
- message: `Warning: Imported transaction has different body hash.\nCurrent: ${this.formatHash(currentHash)}\nImported: ${this.formatHash(importedHash)}\nProceed anyway?`,
971
+ const proceed = await (0, _prompts.confirmCancellable)({
972
+ message: `Warning: Imported transaction has different body hash.\nCurrent: ${(0, _txDialog.formatHash)(currentHash)}\nImported: ${(0, _txDialog.formatHash)(importedHash)}\nProceed anyway?`,
985
973
  default: false
986
974
  });
987
- if (!proceed) {
975
+ if (proceed === null || !proceed) {
988
976
  console.log("Import cancelled.");
989
977
  continue;
990
978
  }
991
979
  }
992
980
 
993
981
  // Merge signatures
994
- const added = this.mergeSignatures(currentTx, importedTx);
982
+ const added = (0, _txDialog.mergeSignatures)(currentTx, importedTx);
995
983
  const sourceVkeys = importedTx.witnessSet().vkeys();
996
984
  const sourceCount = sourceVkeys ? sourceVkeys.size() : 0;
997
985
  const skipped = sourceCount - added;
@@ -1010,13 +998,13 @@ class Sprinkle {
1010
998
  continue;
1011
999
  }
1012
1000
  if (selection === "submit") {
1013
- const sigCount = this.countSignatures(currentTx);
1001
+ const sigCount = (0, _txDialog.countSignatures)(currentTx);
1014
1002
  if (sigCount === 0) {
1015
- const proceed = await (0, _prompts.confirm)({
1003
+ const proceed = await (0, _prompts.confirmCancellable)({
1016
1004
  message: "Warning: Transaction has no signatures. Submit anyway?",
1017
1005
  default: false
1018
1006
  });
1019
- if (!proceed) {
1007
+ if (proceed === null || !proceed) {
1020
1008
  continue;
1021
1009
  }
1022
1010
  }
@@ -1048,46 +1036,18 @@ class Sprinkle {
1048
1036
  }
1049
1037
  }
1050
1038
  }
1039
+
1040
+ /**
1041
+ * Edit an existing struct value using a menu-based interface.
1042
+ * This is now unified with FillInStruct - both use the same menu system.
1043
+ * @param type - The TypeBox schema
1044
+ * @param current - The current value to edit
1045
+ * @returns The edited value
1046
+ */
1051
1047
  async EditStruct(type, current) {
1052
- return this._editStruct(type, ["root"], current);
1053
- }
1054
- async _editStruct(type, path, current) {
1055
- if (isObject(type)) {
1056
- const obj = {};
1057
- const fields = type["properties"];
1058
- const menuItems = [];
1059
- const currentRecord = current;
1060
- for (const [field, fieldType] of Object.entries(fields)) {
1061
- if (current && field in currentRecord) {
1062
- obj[field] = currentRecord[field];
1063
- }
1064
- const menuTitle = Sprinkle.ExtractMessage(fieldType, `Edit ${field} at ${path.join(".")}`);
1065
- if (isOptional(fieldType) && current && currentRecord[field] !== undefined) {
1066
- menuItems.push({
1067
- title: `Clear ${field}`,
1068
- action: async sprinkle => {
1069
- obj[field] = undefined;
1070
- return sprinkle;
1071
- }
1072
- });
1073
- }
1074
- menuItems.push({
1075
- title: menuTitle,
1076
- action: async sprinkle => {
1077
- const fieldValue = await sprinkle._editStruct(fieldType, path.concat([field]), current && field in currentRecord ? currentRecord[field] : undefined);
1078
- obj[field] = fieldValue;
1079
- return sprinkle;
1080
- }
1081
- });
1082
- }
1083
- const editMenu = {
1084
- title: "Test",
1085
- items: menuItems
1086
- };
1087
- await this._showMenu(editMenu, false);
1088
- return obj;
1089
- }
1090
- return this._fillInStruct(type, path, {}, current);
1048
+ // Use FillInStruct with current values as defaults
1049
+ // The menu system will show existing values and allow editing
1050
+ return this.FillInStruct(type, current);
1091
1051
  }
1092
1052
  async FillInStruct(type, def) {
1093
1053
  return this._fillInStruct(type, ["root"], {}, def);
@@ -1104,9 +1064,10 @@ class Sprinkle {
1104
1064
  }
1105
1065
  return this._fillInStruct(resolvedType, path, defs, def);
1106
1066
  }
1107
- if (isOptional(type)) {
1108
- const shouldSet = await (0, _prompts.select)({
1109
- message: Sprinkle.ExtractMessage(type, `Set value for ${path.join(".")}?`),
1067
+ if ((0, _typeGuards.isOptional)(type)) {
1068
+ const pathDisplay = (0, _formatting.formatPath)(path) || "value";
1069
+ const shouldSet = await (0, _prompts.selectWithClear)({
1070
+ message: Sprinkle.ExtractMessage(type, `Set value for ${pathDisplay}?`),
1110
1071
  choices: [{
1111
1072
  name: "Yes",
1112
1073
  value: true
@@ -1116,6 +1077,9 @@ class Sprinkle {
1116
1077
  }],
1117
1078
  default: def !== undefined
1118
1079
  });
1080
+ if (shouldSet === null) {
1081
+ throw new _types.UserCancelledError();
1082
+ }
1119
1083
  if (!shouldSet) {
1120
1084
  return undefined;
1121
1085
  }
@@ -1126,7 +1090,8 @@ class Sprinkle {
1126
1090
  delete innerType[_typebox.OptionalKind];
1127
1091
  return this._fillInStruct(innerType, path, defs, def);
1128
1092
  }
1129
- if (isUnion(type)) {
1093
+ if ((0, _typeGuards.isUnion)(type)) {
1094
+ const pathDisplay = (0, _formatting.formatPath)(path) || "value";
1130
1095
  const choices = [];
1131
1096
  const resolved = this.resolveType(type, path, defs);
1132
1097
  for (const variant of resolved.anyOf) {
@@ -1135,17 +1100,20 @@ class Sprinkle {
1135
1100
  value: variant
1136
1101
  });
1137
1102
  }
1138
- const selection = await (0, _prompts.select)({
1139
- message: Sprinkle.ExtractMessage(resolved, `Enter a choice for ${path.join(".")}`),
1140
- choices: choices,
1141
- default: def ? `${def}` : undefined
1103
+ const selectionResult = await (0, _prompts.selectWithClear)({
1104
+ message: Sprinkle.ExtractMessage(resolved, `Enter a choice for ${pathDisplay}`),
1105
+ choices: choices
1142
1106
  });
1107
+ if (selectionResult === null) {
1108
+ throw new _types.UserCancelledError();
1109
+ }
1110
+ const selection = selectionResult;
1143
1111
  return this._fillInStruct(selection, path, defs);
1144
1112
  }
1145
- if (isString(type)) {
1113
+ if ((0, _typeGuards.isString)(type)) {
1146
1114
  // Special handling for hot wallet private key - offer generation option
1147
1115
  if (type.title === "Hot Wallet Private Key") {
1148
- const choice = await (0, _prompts.select)({
1116
+ const choice = await (0, _prompts.selectWithClear)({
1149
1117
  message: "Hot wallet setup:",
1150
1118
  choices: [{
1151
1119
  name: "Enter existing private key",
@@ -1155,34 +1123,47 @@ class Sprinkle {
1155
1123
  value: "generate"
1156
1124
  }]
1157
1125
  });
1126
+ if (choice === null) {
1127
+ throw new _types.UserCancelledError();
1128
+ }
1158
1129
  if (choice === "generate") {
1159
1130
  return Sprinkle.generateWalletFromMnemonic();
1160
1131
  }
1161
1132
  // Fall through to password prompt for "existing" choice
1162
- const answer = await (0, _prompts.password)({
1133
+ const answer = await (0, _prompts.passwordWithClear)({
1163
1134
  message: "Enter your private key:"
1164
1135
  });
1136
+ if (answer === null) {
1137
+ throw new _types.UserCancelledError();
1138
+ }
1165
1139
  return answer;
1166
1140
  }
1141
+ const pathDisplay = (0, _formatting.formatPath)(path) || "value";
1167
1142
  const defaultString = def ? def : this.defaults["string"];
1168
- const message = Sprinkle.ExtractMessage(type, `Enter a string for ${path.join(".")}`);
1143
+ const message = Sprinkle.ExtractMessage(type, `Enter a string for ${pathDisplay}`);
1169
1144
  let answer;
1170
- if (isSensitive(type)) {
1171
- answer = await (0, _prompts.password)({
1145
+ if ((0, _typeGuards.isSensitive)(type)) {
1146
+ answer = await (0, _prompts.passwordWithClear)({
1172
1147
  message
1173
1148
  });
1174
1149
  } else {
1175
- answer = await (0, _prompts.input)({
1150
+ answer = await (0, _prompts.inputWithClear)({
1176
1151
  message,
1177
1152
  default: defaultString
1178
1153
  });
1179
- this.defaults["string"] = answer;
1154
+ if (answer !== null) {
1155
+ this.defaults["string"] = answer;
1156
+ }
1157
+ }
1158
+ if (answer === null) {
1159
+ throw new _types.UserCancelledError();
1180
1160
  }
1181
1161
  return answer;
1182
1162
  }
1183
- if (isBigInt(type)) {
1184
- const answer = await (0, _prompts.input)({
1185
- message: Sprinkle.ExtractMessage(type, `Enter a bigint for ${path.join(".")}`),
1163
+ if ((0, _typeGuards.isBigInt)(type)) {
1164
+ const pathDisplay = (0, _formatting.formatPath)(path) || "value";
1165
+ const answer = await (0, _prompts.inputWithClear)({
1166
+ message: Sprinkle.ExtractMessage(type, `Enter a bigint for ${pathDisplay}`),
1186
1167
  default: def ? def.toString() : undefined,
1187
1168
  validate: s => {
1188
1169
  try {
@@ -1193,44 +1174,51 @@ class Sprinkle {
1193
1174
  }
1194
1175
  }
1195
1176
  });
1177
+ if (answer === null) {
1178
+ throw new _types.UserCancelledError();
1179
+ }
1196
1180
  return BigInt(answer);
1197
1181
  }
1198
- if (isLiteral(type)) {
1182
+ if ((0, _typeGuards.isLiteral)(type)) {
1199
1183
  return type.const;
1200
1184
  }
1201
- if (isObject(type)) {
1202
- const obj = {};
1203
- const fields = type["properties"];
1204
- for (const [field, fieldType] of Object.entries(fields)) {
1205
- const fieldValue = await this._fillInStruct(fieldType, path.concat([field]), defs, def ? def[field] : undefined);
1206
- obj[field] = fieldValue;
1185
+ if ((0, _typeGuards.isObject)(type)) {
1186
+ // Use menu-based editing for objects
1187
+ const defaults = def;
1188
+ const sprinkle = this;
1189
+ const result = await (0, _index.promptObject)({
1190
+ type,
1191
+ path,
1192
+ defs,
1193
+ defaults,
1194
+ fillField: async (fieldType, fieldPath, fieldDefs, fieldDef) => {
1195
+ return sprinkle._fillInStruct(fieldType, fieldPath, fieldDefs, fieldDef);
1196
+ }
1197
+ });
1198
+ if (result.action === "cancel") {
1199
+ throw new _types.UserCancelledError();
1207
1200
  }
1208
- return obj;
1201
+ return result.value;
1209
1202
  }
1210
-
1211
- //TODO: support starting with default values for arrays and allow removal of items
1212
- if (isArray(type)) {
1213
- const arr = [];
1214
- const itemType = type.items;
1215
- let addMore = true;
1216
- while (addMore) {
1217
- const itemValue = await this._fillInStruct(itemType, path.concat([`[${arr.length}]`]), defs);
1218
- arr.push(itemValue);
1219
- const continueAnswer = await (0, _prompts.select)({
1220
- message: `Add another item to ${path.join(".")}?`,
1221
- choices: [{
1222
- name: "Yes",
1223
- value: true
1224
- }, {
1225
- name: "No",
1226
- value: false
1227
- }]
1228
- });
1229
- addMore = continueAnswer;
1203
+ if ((0, _typeGuards.isArray)(type)) {
1204
+ // Use menu-based editing for arrays
1205
+ const defaults = def;
1206
+ const sprinkle = this;
1207
+ const result = await (0, _index.promptArray)({
1208
+ type,
1209
+ path,
1210
+ defs,
1211
+ defaults,
1212
+ fillField: async (itemType, itemPath, itemDefs, itemDef) => {
1213
+ return sprinkle._fillInStruct(itemType, itemPath, itemDefs, itemDef);
1214
+ }
1215
+ });
1216
+ if (result.action === "back") {
1217
+ throw new _types.UserCancelledError();
1230
1218
  }
1231
- return arr;
1219
+ return result.value;
1232
1220
  }
1233
- if (isTuple(type)) {
1221
+ if ((0, _typeGuards.isTuple)(type)) {
1234
1222
  const items = type.items ?? [];
1235
1223
  const result = [];
1236
1224
  for (let i = 0; i < items.length; i++) {
@@ -1240,10 +1228,11 @@ class Sprinkle {
1240
1228
  }
1241
1229
  return result;
1242
1230
  }
1243
- throw new Error(`Unable to fill in struct for type at path ${path.join(".")}`);
1231
+ const pathDisplay = (0, _formatting.formatPath)(path) || "root";
1232
+ throw new Error(`Unable to fill in struct for type at path ${pathDisplay}`);
1244
1233
  }
1245
1234
  resolveType(type, path, defs) {
1246
- if (isRef(type) || isThis(type) || isImport(type)) {
1235
+ if ((0, _typeGuards.isRef)(type) || (0, _typeGuards.isThis)(type) || (0, _typeGuards.isImport)(type)) {
1247
1236
  defs = {
1248
1237
  ...defs,
1249
1238
  ...type.$defs
@@ -1263,10 +1252,10 @@ class Sprinkle {
1263
1252
  if ("description" in type) {
1264
1253
  return type.description;
1265
1254
  }
1266
- if (isLiteral(type)) {
1255
+ if ((0, _typeGuards.isLiteral)(type)) {
1267
1256
  return `${type.const}`;
1268
1257
  }
1269
- if (isObject(type)) {
1258
+ if ((0, _typeGuards.isObject)(type)) {
1270
1259
  const fields = type["properties"];
1271
1260
  if ("type" in fields) {
1272
1261
  return Sprinkle.ExtractMessage(fields["type"], def);