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