@manifest-network/manifest-mcp-browser 0.1.6 → 0.1.8

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 +5 -2
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/config.js +0 -10
  4. package/dist/config.js.map +1 -1
  5. package/dist/index.d.ts +0 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3 -7
  8. package/dist/index.js.map +1 -1
  9. package/dist/modules.d.ts.map +1 -1
  10. package/dist/modules.js +42 -0
  11. package/dist/modules.js.map +1 -1
  12. package/dist/queries/group.d.ts +12 -0
  13. package/dist/queries/group.d.ts.map +1 -0
  14. package/dist/queries/group.js +107 -0
  15. package/dist/queries/group.js.map +1 -0
  16. package/dist/queries/index.d.ts +2 -0
  17. package/dist/queries/index.d.ts.map +1 -1
  18. package/dist/queries/index.js +2 -0
  19. package/dist/queries/index.js.map +1 -1
  20. package/dist/queries/utils.d.ts +3 -18
  21. package/dist/queries/utils.d.ts.map +1 -1
  22. package/dist/queries/utils.js +2 -17
  23. package/dist/queries/utils.js.map +1 -1
  24. package/dist/transactions/bank.d.ts.map +1 -1
  25. package/dist/transactions/bank.js +7 -5
  26. package/dist/transactions/bank.js.map +1 -1
  27. package/dist/transactions/gov.d.ts.map +1 -1
  28. package/dist/transactions/gov.js +9 -30
  29. package/dist/transactions/gov.js.map +1 -1
  30. package/dist/transactions/group.d.ts +7 -0
  31. package/dist/transactions/group.d.ts.map +1 -0
  32. package/dist/transactions/group.js +339 -0
  33. package/dist/transactions/group.js.map +1 -0
  34. package/dist/transactions/index.d.ts +2 -0
  35. package/dist/transactions/index.d.ts.map +1 -1
  36. package/dist/transactions/index.js +2 -0
  37. package/dist/transactions/index.js.map +1 -1
  38. package/dist/transactions/utils.d.ts +37 -0
  39. package/dist/transactions/utils.d.ts.map +1 -1
  40. package/dist/transactions/utils.js +43 -0
  41. package/dist/transactions/utils.js.map +1 -1
  42. package/dist/types.d.ts +31 -3
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/types.js.map +1 -1
  45. package/package.json +5 -2
  46. package/.github/workflows/ci.yml +0 -37
  47. package/.github/workflows/publish.yml +0 -53
  48. package/CLAUDE.md +0 -111
  49. package/dist/config.test.d.ts +0 -2
  50. package/dist/config.test.d.ts.map +0 -1
  51. package/dist/config.test.js +0 -251
  52. package/dist/config.test.js.map +0 -1
  53. package/dist/modules.test.d.ts +0 -2
  54. package/dist/modules.test.d.ts.map +0 -1
  55. package/dist/modules.test.js +0 -159
  56. package/dist/modules.test.js.map +0 -1
  57. package/dist/queries/utils.test.d.ts +0 -2
  58. package/dist/queries/utils.test.d.ts.map +0 -1
  59. package/dist/queries/utils.test.js +0 -117
  60. package/dist/queries/utils.test.js.map +0 -1
  61. package/dist/transactions/utils.test.d.ts +0 -2
  62. package/dist/transactions/utils.test.d.ts.map +0 -1
  63. package/dist/transactions/utils.test.js +0 -471
  64. package/dist/transactions/utils.test.js.map +0 -1
  65. package/src/client.ts +0 -288
  66. package/src/config.test.ts +0 -299
  67. package/src/config.ts +0 -174
  68. package/src/cosmos.ts +0 -106
  69. package/src/index.ts +0 -478
  70. package/src/modules.test.ts +0 -189
  71. package/src/modules.ts +0 -428
  72. package/src/queries/auth.ts +0 -97
  73. package/src/queries/bank.ts +0 -99
  74. package/src/queries/billing.ts +0 -124
  75. package/src/queries/distribution.ts +0 -114
  76. package/src/queries/gov.ts +0 -104
  77. package/src/queries/index.ts +0 -16
  78. package/src/queries/sku.ts +0 -85
  79. package/src/queries/staking.ts +0 -154
  80. package/src/queries/utils.test.ts +0 -156
  81. package/src/queries/utils.ts +0 -145
  82. package/src/transactions/bank.ts +0 -86
  83. package/src/transactions/billing.ts +0 -286
  84. package/src/transactions/distribution.ts +0 -76
  85. package/src/transactions/gov.ts +0 -191
  86. package/src/transactions/index.ts +0 -7
  87. package/src/transactions/manifest.ts +0 -67
  88. package/src/transactions/sku.ts +0 -232
  89. package/src/transactions/staking.ts +0 -85
  90. package/src/transactions/utils.test.ts +0 -518
  91. package/src/transactions/utils.ts +0 -348
  92. package/src/types.ts +0 -497
  93. package/src/wallet/index.ts +0 -2
  94. package/src/wallet/mnemonic.ts +0 -146
  95. package/tsconfig.json +0 -23
@@ -1,348 +0,0 @@
1
- import { SigningStargateClient } from '@cosmjs/stargate';
2
- import { fromBech32, fromHex, toHex } from '@cosmjs/encoding';
3
- import { ManifestMCPError, ManifestMCPErrorCode, CosmosTxResult } from '../types.js';
4
-
5
- /** Maximum number of arguments allowed */
6
- export const MAX_ARGS = 100;
7
-
8
- /** Maximum meta hash length in bytes (64 bytes for SHA-512) */
9
- export const MAX_META_HASH_BYTES = 64;
10
-
11
- /**
12
- * Result from extracting a flag from args
13
- */
14
- export interface ExtractedFlag {
15
- /** The flag value, or undefined if flag not present */
16
- value: string | undefined;
17
- /** Indices consumed by the flag and its value (for filtering) */
18
- consumedIndices: number[];
19
- }
20
-
21
- /**
22
- * Extract a flag value from args array.
23
- * Returns { value, consumedIndices } or { value: undefined, consumedIndices: [] } if flag not present.
24
- * Throws if flag is present but value is missing or looks like another flag.
25
- *
26
- * @param args - The arguments array to search
27
- * @param flagName - The flag to look for (e.g., '--memo')
28
- * @param context - Description for error messages (e.g., 'bank send')
29
- */
30
- export function extractFlag(
31
- args: string[],
32
- flagName: string,
33
- context: string
34
- ): ExtractedFlag {
35
- const flagIndex = args.indexOf(flagName);
36
- if (flagIndex === -1) {
37
- return { value: undefined, consumedIndices: [] };
38
- }
39
-
40
- const value = args[flagIndex + 1];
41
- if (!value || value.startsWith('--')) {
42
- throw new ManifestMCPError(
43
- ManifestMCPErrorCode.TX_FAILED,
44
- `${flagName} flag requires a value in ${context}`
45
- );
46
- }
47
-
48
- return { value, consumedIndices: [flagIndex, flagIndex + 1] };
49
- }
50
-
51
- /**
52
- * Filter args to remove consumed flag indices
53
- */
54
- export function filterConsumedArgs(args: string[], consumedIndices: number[]): string[] {
55
- if (consumedIndices.length === 0) {
56
- return args;
57
- }
58
- const consumedSet = new Set(consumedIndices);
59
- return args.filter((_, index) => !consumedSet.has(index));
60
- }
61
-
62
- /** Maximum memo length (Cosmos SDK default) */
63
- export const MAX_MEMO_LENGTH = 256;
64
-
65
- /**
66
- * Parse a colon-separated pair (e.g., "address:amount", "sku:quantity").
67
- * Throws with helpful error if format is invalid.
68
- *
69
- * @param input - The string to parse (e.g., "manifest1abc:1000umfx")
70
- * @param leftName - Name of the left value for error messages (e.g., "address")
71
- * @param rightName - Name of the right value for error messages (e.g., "amount")
72
- * @param context - Context for error messages (e.g., "multi-send pair")
73
- * @returns Tuple of [left, right] values
74
- */
75
- export function parseColonPair(
76
- input: string,
77
- leftName: string,
78
- rightName: string,
79
- context: string
80
- ): [string, string] {
81
- const colonIndex = input.indexOf(':');
82
- if (colonIndex === -1) {
83
- throw new ManifestMCPError(
84
- ManifestMCPErrorCode.TX_FAILED,
85
- `Invalid ${context} format: "${input}". Missing colon separator. Expected format: ${leftName}:${rightName}`
86
- );
87
- }
88
- if (colonIndex === 0) {
89
- throw new ManifestMCPError(
90
- ManifestMCPErrorCode.TX_FAILED,
91
- `Invalid ${context} format: "${input}". Missing ${leftName}. Expected format: ${leftName}:${rightName}`
92
- );
93
- }
94
- if (colonIndex === input.length - 1) {
95
- throw new ManifestMCPError(
96
- ManifestMCPErrorCode.TX_FAILED,
97
- `Invalid ${context} format: "${input}". Missing ${rightName}. Expected format: ${leftName}:${rightName}`
98
- );
99
- }
100
- return [input.slice(0, colonIndex), input.slice(colonIndex + 1)];
101
- }
102
-
103
- /**
104
- * Validate args array length (max limit)
105
- */
106
- export function validateArgsLength(args: string[], context: string): void {
107
- if (args.length > MAX_ARGS) {
108
- throw new ManifestMCPError(
109
- ManifestMCPErrorCode.TX_FAILED,
110
- `Too many arguments for ${context}: ${args.length}. Maximum allowed: ${MAX_ARGS}`
111
- );
112
- }
113
- }
114
-
115
- /**
116
- * Validate that required arguments are present.
117
- * Provides helpful error messages with received vs expected args.
118
- *
119
- * @param args - The arguments array to validate
120
- * @param minCount - Minimum number of required arguments
121
- * @param expectedNames - Names of expected arguments for error messages
122
- * @param context - Context for error messages (e.g., 'bank send', 'staking delegate')
123
- * @param errorCode - Error code to use (defaults to TX_FAILED)
124
- * @throws ManifestMCPError if args.length < minCount
125
- */
126
- export function requireArgs(
127
- args: string[],
128
- minCount: number,
129
- expectedNames: string[],
130
- context: string,
131
- errorCode: ManifestMCPErrorCode = ManifestMCPErrorCode.TX_FAILED
132
- ): void {
133
- if (args.length >= minCount) {
134
- return;
135
- }
136
-
137
- const expectedList = expectedNames.slice(0, minCount).join(', ');
138
- const receivedList = args.length === 0
139
- ? 'none'
140
- : args.map(a => `"${a}"`).join(', ');
141
-
142
- throw new ManifestMCPError(
143
- errorCode,
144
- `${context} requires ${minCount} argument(s): ${expectedList}. Received ${args.length}: ${receivedList}`,
145
- {
146
- expectedArgs: expectedNames.slice(0, minCount),
147
- receivedArgs: args,
148
- receivedCount: args.length,
149
- requiredCount: minCount,
150
- }
151
- );
152
- }
153
-
154
- /**
155
- * Validate a bech32 address using @cosmjs/encoding
156
- */
157
- export function validateAddress(address: string, fieldName: string, expectedPrefix?: string): void {
158
- if (!address || address.trim() === '') {
159
- throw new ManifestMCPError(
160
- ManifestMCPErrorCode.INVALID_ADDRESS,
161
- `${fieldName} is required`
162
- );
163
- }
164
-
165
- try {
166
- const { prefix } = fromBech32(address);
167
- if (expectedPrefix && prefix !== expectedPrefix) {
168
- throw new ManifestMCPError(
169
- ManifestMCPErrorCode.INVALID_ADDRESS,
170
- `Invalid ${fieldName}: "${address}". Expected prefix "${expectedPrefix}", got "${prefix}"`
171
- );
172
- }
173
- } catch (error) {
174
- if (error instanceof ManifestMCPError) {
175
- throw error;
176
- }
177
- throw new ManifestMCPError(
178
- ManifestMCPErrorCode.INVALID_ADDRESS,
179
- `Invalid ${fieldName}: "${address}". Not a valid bech32 address.`
180
- );
181
- }
182
- }
183
-
184
- /**
185
- * Validate memo length
186
- */
187
- export function validateMemo(memo: string): void {
188
- if (memo.length > MAX_MEMO_LENGTH) {
189
- throw new ManifestMCPError(
190
- ManifestMCPErrorCode.TX_FAILED,
191
- `Memo too long: ${memo.length} characters. Maximum allowed: ${MAX_MEMO_LENGTH}`
192
- );
193
- }
194
- }
195
-
196
- /**
197
- * Parse and validate a hex string into Uint8Array.
198
- * Uses @cosmjs/encoding for browser compatibility.
199
- *
200
- * @param hexString - The hex string to parse
201
- * @param fieldName - Name of the field for error messages
202
- * @param maxBytes - Maximum allowed byte length
203
- * @param errorCode - Error code to use (defaults to TX_FAILED)
204
- * @returns Uint8Array of the parsed bytes
205
- */
206
- export function parseHexBytes(
207
- hexString: string,
208
- fieldName: string,
209
- maxBytes: number,
210
- errorCode: ManifestMCPErrorCode = ManifestMCPErrorCode.TX_FAILED
211
- ): Uint8Array {
212
- // Check for empty string
213
- if (!hexString || hexString.trim() === '') {
214
- throw new ManifestMCPError(
215
- errorCode,
216
- `Invalid ${fieldName}: empty value. Expected a hex string.`
217
- );
218
- }
219
-
220
- // Check even length (each byte is 2 hex chars)
221
- if (hexString.length % 2 !== 0) {
222
- throw new ManifestMCPError(
223
- errorCode,
224
- `Invalid ${fieldName}: hex string must have even length. Got ${hexString.length} characters.`
225
- );
226
- }
227
-
228
- // Check max length
229
- const byteLength = hexString.length / 2;
230
- if (byteLength > maxBytes) {
231
- throw new ManifestMCPError(
232
- errorCode,
233
- `Invalid ${fieldName}: exceeds maximum ${maxBytes} bytes. Got ${byteLength} bytes (${hexString.length} hex chars).`
234
- );
235
- }
236
-
237
- // Use @cosmjs/encoding for browser-compatible hex parsing
238
- try {
239
- return fromHex(hexString);
240
- } catch (error) {
241
- throw new ManifestMCPError(
242
- errorCode,
243
- `Invalid ${fieldName}: "${hexString}". Must contain only hexadecimal characters (0-9, a-f, A-F).`
244
- );
245
- }
246
- }
247
-
248
- /**
249
- * Convert Uint8Array to hex string.
250
- * Uses @cosmjs/encoding for browser compatibility.
251
- */
252
- export function bytesToHex(bytes: Uint8Array): string {
253
- return toHex(bytes);
254
- }
255
-
256
- /**
257
- * Safely parse a string to BigInt with proper error handling and configurable error code.
258
- * This is the base implementation used by both transaction and query utilities.
259
- */
260
- export function parseBigIntWithCode(
261
- value: string,
262
- fieldName: string,
263
- errorCode: ManifestMCPErrorCode
264
- ): bigint {
265
- // Check for empty string explicitly (BigInt('') returns 0n, not an error)
266
- if (!value || value.trim() === '') {
267
- throw new ManifestMCPError(
268
- errorCode,
269
- `Invalid ${fieldName}: empty value. Expected a valid integer.`
270
- );
271
- }
272
-
273
- try {
274
- return BigInt(value);
275
- } catch {
276
- throw new ManifestMCPError(
277
- errorCode,
278
- `Invalid ${fieldName}: "${value}". Expected a valid integer.`
279
- );
280
- }
281
- }
282
-
283
- /**
284
- * Safely parse a string to BigInt with proper error handling (for transactions)
285
- */
286
- export function parseBigInt(value: string, fieldName: string): bigint {
287
- return parseBigIntWithCode(value, fieldName, ManifestMCPErrorCode.TX_FAILED);
288
- }
289
-
290
- /**
291
- * Parse amount string into coin (e.g., "1000umfx" -> { amount: "1000", denom: "umfx" })
292
- * Supports simple denoms (umfx), IBC denoms (ibc/...), and factory denoms (factory/creator/subdenom)
293
- */
294
- export function parseAmount(amountStr: string): { amount: string; denom: string } {
295
- // Regex supports alphanumeric denoms with slashes and underscores for IBC/factory denoms
296
- const match = amountStr.match(/^(\d+)([a-zA-Z][a-zA-Z0-9/_]*)$/);
297
- if (!match) {
298
- // Provide specific hints based on common mistakes
299
- let hint = '';
300
- if (!amountStr || amountStr.trim() === '') {
301
- hint = ' Received empty string.';
302
- } else if (amountStr.includes(' ')) {
303
- hint = ' Remove the space between number and denom.';
304
- } else if (amountStr.includes(',')) {
305
- hint = ' Do not use commas in the number.';
306
- } else if (/^\d+$/.test(amountStr)) {
307
- hint = ' Missing denomination (e.g., add "umfx" after the number).';
308
- } else if (/^[a-zA-Z]/.test(amountStr)) {
309
- hint = ' Amount must start with a number, not the denomination.';
310
- }
311
-
312
- throw new ManifestMCPError(
313
- ManifestMCPErrorCode.TX_FAILED,
314
- `Invalid amount format: "${amountStr}".${hint} Expected format: <number><denom> (e.g., "1000000umfx" or "1000000factory/address/subdenom")`,
315
- { receivedValue: amountStr, expectedFormat: '<number><denom>', example: '1000000umfx' }
316
- );
317
- }
318
- return { amount: match[1], denom: match[2] };
319
- }
320
-
321
- /**
322
- * Build transaction result from DeliverTxResponse
323
- */
324
- export function buildTxResult(
325
- module: string,
326
- subcommand: string,
327
- result: Awaited<ReturnType<SigningStargateClient['signAndBroadcast']>>,
328
- waitForConfirmation: boolean
329
- ): CosmosTxResult {
330
- const txResult: CosmosTxResult = {
331
- module,
332
- subcommand,
333
- transactionHash: result.transactionHash,
334
- code: result.code,
335
- height: String(result.height),
336
- rawLog: result.rawLog || undefined,
337
- gasUsed: String(result.gasUsed),
338
- gasWanted: String(result.gasWanted),
339
- events: result.events,
340
- };
341
-
342
- if (waitForConfirmation) {
343
- txResult.confirmed = result.code === 0;
344
- txResult.confirmationHeight = String(result.height);
345
- }
346
-
347
- return txResult;
348
- }