@manifest-network/manifest-mcp-core 0.8.0 → 0.9.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.
- package/README.md +6 -2
- package/dist/__test-utils__/mocks.d.ts +8 -7
- package/dist/__test-utils__/mocks.d.ts.map +1 -1
- package/dist/__test-utils__/mocks.js +1 -1
- package/dist/config.d.ts +11 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/server-utils.d.ts +4 -2
- package/dist/server-utils.d.ts.map +1 -1
- package/dist/server-utils.js +9 -5
- package/dist/server-utils.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +9 -1
- package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +0 -78
- package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js.map +0 -1
- package/dist/node_modules/@vitest/expect/dist/index.d.ts +0 -802
- package/dist/node_modules/@vitest/expect/dist/index.d.ts.map +0 -1
- package/dist/node_modules/@vitest/expect/dist/index.js +0 -1457
- package/dist/node_modules/@vitest/expect/dist/index.js.map +0 -1
- package/dist/node_modules/@vitest/pretty-format/dist/index.d.ts +0 -95
- package/dist/node_modules/@vitest/pretty-format/dist/index.d.ts.map +0 -1
- package/dist/node_modules/@vitest/pretty-format/dist/index.js +0 -877
- package/dist/node_modules/@vitest/pretty-format/dist/index.js.map +0 -1
- package/dist/node_modules/@vitest/runner/dist/chunk-tasks.js +0 -91
- package/dist/node_modules/@vitest/runner/dist/chunk-tasks.js.map +0 -1
- package/dist/node_modules/@vitest/runner/dist/index.js +0 -1381
- package/dist/node_modules/@vitest/runner/dist/index.js.map +0 -1
- package/dist/node_modules/@vitest/runner/dist/tasks.d-D2GKpdwQ.d.ts +0 -540
- package/dist/node_modules/@vitest/runner/dist/tasks.d-D2GKpdwQ.d.ts.map +0 -1
- package/dist/node_modules/@vitest/runner/dist/utils.js +0 -1
- package/dist/node_modules/@vitest/snapshot/dist/environment.d-DOJxxZV9.d.ts +0 -16
- package/dist/node_modules/@vitest/snapshot/dist/environment.d-DOJxxZV9.d.ts.map +0 -1
- package/dist/node_modules/@vitest/snapshot/dist/index.d.ts +0 -89
- package/dist/node_modules/@vitest/snapshot/dist/index.d.ts.map +0 -1
- package/dist/node_modules/@vitest/snapshot/dist/index.js +0 -649
- package/dist/node_modules/@vitest/snapshot/dist/index.js.map +0 -1
- package/dist/node_modules/@vitest/snapshot/dist/rawSnapshot.d-U2kJUxDr.d.ts +0 -40
- package/dist/node_modules/@vitest/snapshot/dist/rawSnapshot.d-U2kJUxDr.d.ts.map +0 -1
- package/dist/node_modules/@vitest/spy/dist/index.d.ts +0 -343
- package/dist/node_modules/@vitest/spy/dist/index.d.ts.map +0 -1
- package/dist/node_modules/@vitest/spy/dist/index.js +0 -386
- package/dist/node_modules/@vitest/spy/dist/index.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +0 -82
- package/dist/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/diff.d.ts +0 -14
- package/dist/node_modules/@vitest/utils/dist/diff.d.ts.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/diff.js +0 -1297
- package/dist/node_modules/@vitest/utils/dist/diff.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/display.d.ts +0 -15
- package/dist/node_modules/@vitest/utils/dist/display.d.ts.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/display.js +0 -558
- package/dist/node_modules/@vitest/utils/dist/display.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/error.js +0 -30
- package/dist/node_modules/@vitest/utils/dist/error.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/helpers.js +0 -181
- package/dist/node_modules/@vitest/utils/dist/helpers.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/offset.js +0 -27
- package/dist/node_modules/@vitest/utils/dist/offset.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/serialize.js +0 -77
- package/dist/node_modules/@vitest/utils/dist/serialize.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/source-map.js +0 -367
- package/dist/node_modules/@vitest/utils/dist/source-map.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/timers.js +0 -37
- package/dist/node_modules/@vitest/utils/dist/timers.js.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/types.d-BCElaP-c.d.ts +0 -38
- package/dist/node_modules/@vitest/utils/dist/types.d-BCElaP-c.d.ts.map +0 -1
- package/dist/node_modules/@vitest/utils/dist/types.d.ts +0 -25
- package/dist/node_modules/@vitest/utils/dist/types.d.ts.map +0 -1
- package/dist/node_modules/chai/index.js +0 -2875
- package/dist/node_modules/chai/index.js.map +0 -1
- package/dist/node_modules/magic-string/dist/magic-string.es.js +0 -939
- package/dist/node_modules/magic-string/dist/magic-string.es.js.map +0 -1
- package/dist/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +0 -85
- package/dist/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js.map +0 -1
- package/dist/node_modules/tinybench/dist/index.d.ts +0 -91
- package/dist/node_modules/tinybench/dist/index.d.ts.map +0 -1
- package/dist/node_modules/tinyrainbow/dist/index.d.ts +0 -9
- package/dist/node_modules/tinyrainbow/dist/index.d.ts.map +0 -1
- package/dist/node_modules/tinyrainbow/dist/index.js +0 -86
- package/dist/node_modules/tinyrainbow/dist/index.js.map +0 -1
- package/dist/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -6
- package/dist/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js.map +0 -1
- package/dist/node_modules/vitest/dist/chunks/benchmark.D0SlKNbZ.js +0 -41
- package/dist/node_modules/vitest/dist/chunks/benchmark.D0SlKNbZ.js.map +0 -1
- package/dist/node_modules/vitest/dist/chunks/benchmark.d.DAaHLpsq.d.ts +0 -12
- package/dist/node_modules/vitest/dist/chunks/benchmark.d.DAaHLpsq.d.ts.map +0 -1
- package/dist/node_modules/vitest/dist/chunks/global.d.x-ILCfAE.d.ts +0 -100
- package/dist/node_modules/vitest/dist/chunks/global.d.x-ILCfAE.d.ts.map +0 -1
- package/dist/node_modules/vitest/dist/chunks/rpc.MzXet3jl.js +0 -57
- package/dist/node_modules/vitest/dist/chunks/rpc.MzXet3jl.js.map +0 -1
- package/dist/node_modules/vitest/dist/chunks/rpc.d.BFMWpdph.d.ts +0 -13
- package/dist/node_modules/vitest/dist/chunks/rpc.d.BFMWpdph.d.ts.map +0 -1
- package/dist/node_modules/vitest/dist/chunks/test.CTcmp4Su.js +0 -2791
- package/dist/node_modules/vitest/dist/chunks/test.CTcmp4Su.js.map +0 -1
- package/dist/node_modules/vitest/dist/chunks/utils.BX5Fg8C4.js +0 -44
- package/dist/node_modules/vitest/dist/chunks/utils.BX5Fg8C4.js.map +0 -1
- package/dist/node_modules/vitest/dist/index.d.ts +0 -9
package/README.md
CHANGED
|
@@ -14,8 +14,9 @@ npm install @manifest-network/manifest-mcp-core
|
|
|
14
14
|
- **LCD adapter** (`lcd-adapter.ts`) -- Converts LCD/REST responses to the RPC query client shape, making the codebase transport-agnostic
|
|
15
15
|
- **Module registry** (`modules.ts`) -- Static maps of Cosmos SDK modules with metadata and handler functions
|
|
16
16
|
- **Query/transaction routing** (`cosmos.ts`) -- Routes `(module, subcommand, args)` to per-module handlers
|
|
17
|
-
- **On-chain tool functions** (`tools/`) -- `getBalance`, `fundCredits`, `stopApp` (used by
|
|
18
|
-
- **Server utilities** (`server-utils.ts`) -- `withErrorHandling`, `jsonResponse`, `bigIntReplacer`, `sanitizeForLogging`
|
|
17
|
+
- **On-chain tool functions** (`tools/`) -- `getBalance`, `fundCredits`, `setItemCustomDomain`, `stopApp` (used by lease and fred packages)
|
|
18
|
+
- **Server utilities** (`server-utils.ts`) -- `withErrorHandling`, `jsonResponse`, `structuredResponse`, `bigIntReplacer`, `sanitizeForLogging`
|
|
19
|
+
- **Tool annotation helpers** (`tool-metadata.ts`) -- `readOnlyAnnotations`, `mutatingAnnotations`, `manifestMeta` (versioned `_meta.manifest` payload, `MANIFEST_TOOL_META_VERSION = 1`)
|
|
19
20
|
- **Wallet providers** (`wallet/`) -- `MnemonicWalletProvider` (BIP-39), `signArbitraryWithAmino` (ADR-036)
|
|
20
21
|
- **Logger** (`logger.ts`) -- Leveled logger (stderr output; defaults to `warn`, configurable via `logger.setLevel()`; the node package's bootstrap reads `LOG_LEVEL` and applies it)
|
|
21
22
|
- **Retry** (`retry.ts`) -- Exponential backoff with transient/permanent error classification
|
|
@@ -36,7 +37,10 @@ npm install @manifest-network/manifest-mcp-core
|
|
|
36
37
|
| poa | yes | yes |
|
|
37
38
|
| tokenfactory | yes | yes |
|
|
38
39
|
| ibc-transfer | yes | yes |
|
|
40
|
+
| authz | yes | yes |
|
|
41
|
+
| feegrant | yes | yes |
|
|
39
42
|
| auth | yes | -- |
|
|
43
|
+
| mint | yes | -- |
|
|
40
44
|
| manifest | -- | yes |
|
|
41
45
|
|
|
42
46
|
## Usage
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Mock, Procedure } from "../node_modules/@vitest/spy/dist/index.js";
|
|
2
1
|
import { ManifestMCPConfig, WalletProvider } from "../types.js";
|
|
3
2
|
import { ManifestQueryClient } from "../client.js";
|
|
4
3
|
import { LeaseState } from "@manifest-network/manifestjs/dist/codegen/liftedinit/billing/v1/types.js";
|
|
4
|
+
import * as vitest from "vitest";
|
|
5
|
+
import * as _vitest_spy0 from "@vitest/spy";
|
|
5
6
|
|
|
6
7
|
//#region src/__test-utils__/mocks.d.ts
|
|
7
8
|
/**
|
|
@@ -121,12 +122,12 @@ declare function makeMockClientManager(overrides?: {
|
|
|
121
122
|
address?: string;
|
|
122
123
|
config?: ManifestMCPConfig;
|
|
123
124
|
}): {
|
|
124
|
-
getQueryClient: Mock<Procedure>;
|
|
125
|
-
getSigningClient: Mock<Procedure>;
|
|
126
|
-
getAddress: Mock<Procedure>;
|
|
127
|
-
getConfig: Mock<Procedure>;
|
|
128
|
-
acquireRateLimit: Mock<Procedure>;
|
|
129
|
-
disconnect: Mock<Procedure>;
|
|
125
|
+
getQueryClient: vitest.Mock<_vitest_spy0.Procedure>;
|
|
126
|
+
getSigningClient: vitest.Mock<_vitest_spy0.Procedure>;
|
|
127
|
+
getAddress: vitest.Mock<_vitest_spy0.Procedure>;
|
|
128
|
+
getConfig: vitest.Mock<_vitest_spy0.Procedure>;
|
|
129
|
+
acquireRateLimit: vitest.Mock<_vitest_spy0.Procedure>;
|
|
130
|
+
disconnect: vitest.Mock<_vitest_spy0.Procedure>;
|
|
130
131
|
};
|
|
131
132
|
//#endregion
|
|
132
133
|
export { makeMockClientManager, makeMockConfig, makeMockQueryClient, makeMockWallet };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.d.ts","names":[],"sources":["../../src/__test-utils__/mocks.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"mocks.d.ts","names":[],"sources":["../../src/__test-utils__/mocks.ts"],"mappings":";;;;;;;;;;iBAYgB,cAAA,CACd,SAAA,GAAY,OAAA,CAAQ,iBAAA,IACnB,iBAAA;AAFH;;;;AAAA,iBAgBgB,cAAA,CAAe,IAAA;EAC7B,aAAA;AAAA,IACE,cAAA;;;;UAiBM,gBAAA;EACR,QAAA;IAAa,KAAA;IAAe,MAAA;EAAA;EAC5B,aAAA;IACE,gBAAA;IACA,iBAAA;IACA,eAAA;MAAmB,KAAA;MAAe,MAAA;IAAA;EAAA;EAEpC,qBAAA;IAA0B,KAAA;IAAe,MAAA;EAAA;EACzC,8BAAA;IAAmC,KAAA;IAAe,MAAA;EAAA;EAClD,cAAA;IACE,cAAA;MAAkB,KAAA;MAAe,MAAA;IAAA;IACjC,kBAAA;MAAsB,KAAA;MAAe,MAAA;IAAA;IACrC,wBAAA;IACA,gBAAA;EAAA;EAEF,KAAA;IACE,IAAA;IACA,KAAA,EAAO,UAAA;IACP,YAAA;IACA,SAAA,GAAY,IAAA;IACZ,QAAA,GAAW,IAAA;EAAA;EAEb,YAAA;IAAiB,IAAA;IAAc,YAAA;IAAsB,SAAA,GAAY,IAAA;EAAA;EACjE,aAAA;IAAkB,IAAA;IAAc,YAAA;IAAsB,SAAA,GAAY,IAAA;EAAA;EAClE,YAAA;IAAiB,IAAA;IAAc,YAAA;IAAsB,SAAA,GAAY,IAAA;EAAA;EACjE,cAAA;IAAmB,IAAA;IAAc,YAAA;IAAsB,SAAA,GAAY,IAAA;EAAA;EACnE,aAAA;IAAkB,IAAA;IAAc,YAAA;IAAsB,SAAA,GAAY,IAAA;EAAA;AAAA;AAAA,UAG1D,YAAA;EACR,SAAA;IACE,IAAA;IACA,OAAA;IACA,MAAA;IACA,MAAA;EAAA;EAEF,IAAA;IACE,IAAA;IACA,IAAA;IACA,YAAA;IACA,SAAA;MAAc,MAAA;MAAgB,KAAA;IAAA;EAAA;EAEhC,cAAA,GAAiB,MAAA;IAAiB,QAAA;MAAY,MAAA;IAAA;EAAA;AAAA;;;;iBAMhC,mBAAA,CAAoB,SAAA;EAClC,OAAA,GAAU,gBAAA;EACV,GAAA,GAAM,YAAA;AAAA,IA4KU,mBAAA;;;;iBAMF,qBAAA,CAAsB,SAAA;EACpC,WAAA,GAAc,mBAAA;EACd,OAAA;EACA,MAAA,GAAS,iBAAA;AAAA;8BAAiB,YAAA,CAAA,SAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { vi } from "../node_modules/vitest/dist/chunks/test.CTcmp4Su.js";
|
|
2
1
|
import { LeaseState } from "@manifest-network/manifestjs/dist/codegen/liftedinit/billing/v1/types.js";
|
|
2
|
+
import { vi } from "vitest";
|
|
3
3
|
//#region src/__test-utils__/mocks.ts
|
|
4
4
|
/**
|
|
5
5
|
* Create a mock ManifestMCPConfig with sensible defaults.
|
package/dist/config.d.ts
CHANGED
|
@@ -12,6 +12,16 @@ declare const DEFAULT_REQUESTS_PER_SECOND = 10;
|
|
|
12
12
|
* the --gas-adjustment value used in this project's E2E scripts (e2e/scripts/init_billing.sh).
|
|
13
13
|
*/
|
|
14
14
|
declare const DEFAULT_GAS_MULTIPLIER = 1.5;
|
|
15
|
+
/**
|
|
16
|
+
* Validate URL format and check if it uses HTTPS or is localhost (HTTP allowed for local dev)
|
|
17
|
+
* Returns validation result with error reason if invalid
|
|
18
|
+
*/
|
|
19
|
+
declare function validateEndpointUrl(url: string, label: string): {
|
|
20
|
+
valid: true;
|
|
21
|
+
} | {
|
|
22
|
+
valid: false;
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
15
25
|
/**
|
|
16
26
|
* Create a configuration object with defaults applied
|
|
17
27
|
*/
|
|
@@ -32,5 +42,5 @@ declare function validateConfig(config: Partial<ManifestMCPConfig>): ValidationR
|
|
|
32
42
|
*/
|
|
33
43
|
declare function createValidatedConfig(input: ManifestMCPConfig): ManifestMCPConfig;
|
|
34
44
|
//#endregion
|
|
35
|
-
export { DEFAULT_GAS_MULTIPLIER, DEFAULT_REQUESTS_PER_SECOND, DEFAULT_RETRY_CONFIG, ValidationResult, createConfig, createValidatedConfig, validateConfig };
|
|
45
|
+
export { DEFAULT_GAS_MULTIPLIER, DEFAULT_REQUESTS_PER_SECOND, DEFAULT_RETRY_CONFIG, ValidationResult, createConfig, createValidatedConfig, validateConfig, validateEndpointUrl };
|
|
36
46
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;AAeA;cAAa,2BAAA;;;;AAOb;;cAAa,sBAAA;;
|
|
1
|
+
{"version":3,"file":"config.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;AAeA;cAAa,2BAAA;;;;AAOb;;cAAa,sBAAA;;AAsBb;;;iBAAgB,mBAAA,CACd,GAAA,UACA,KAAA;EACG,KAAA;AAAA;EAAkB,KAAA;EAAc,MAAA;AAAA;;;AAqDrC;iBAAgB,YAAA,CAAa,KAAA,EAAO,iBAAA,GAAoB,iBAAA;;;;UAuBvC,gBAAA;EACf,KAAA;EACA,MAAA;AAAA;AAFF;;;AAAA,iBAQgB,cAAA,CACd,MAAA,EAAQ,OAAA,CAAQ,iBAAA,IACf,gBAAA;;AAFH;;iBAsIgB,qBAAA,CACd,KAAA,EAAO,iBAAA,GACN,iBAAA"}
|
package/dist/config.js
CHANGED
|
@@ -135,6 +135,6 @@ function createValidatedConfig(input) {
|
|
|
135
135
|
return createConfig(input);
|
|
136
136
|
}
|
|
137
137
|
//#endregion
|
|
138
|
-
export { DEFAULT_GAS_MULTIPLIER, DEFAULT_REQUESTS_PER_SECOND, DEFAULT_RETRY_CONFIG, createConfig, createValidatedConfig, validateConfig };
|
|
138
|
+
export { DEFAULT_GAS_MULTIPLIER, DEFAULT_REQUESTS_PER_SECOND, DEFAULT_RETRY_CONFIG, createConfig, createValidatedConfig, validateConfig, validateEndpointUrl };
|
|
139
139
|
|
|
140
140
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { DEFAULT_RETRY_CONFIG } from './retry.js';\nimport {\n type ManifestMCPConfig,\n ManifestMCPError,\n ManifestMCPErrorCode,\n} from './types.js';\n\n/**\n * Default address prefix for Manifest Network\n */\nconst DEFAULT_ADDRESS_PREFIX = 'manifest';\n\n/**\n * Default requests per second for rate limiting\n */\nexport const DEFAULT_REQUESTS_PER_SECOND = 10;\n\n/**\n * Default gas simulation multiplier. CosmJS defaults to 1.4 but billing module\n * transactions (close-lease in particular) can exceed that. 1.5 matches\n * the --gas-adjustment value used in this project's E2E scripts (e2e/scripts/init_billing.sh).\n */\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\n\n// Re-export for consumers\nexport { DEFAULT_RETRY_CONFIG };\n\n/**\n * Check if a hostname is localhost (IPv4, IPv6, or hostname)\n * Handles both bracketed and unbracketed IPv6 formats\n */\nfunction isLocalhostHostname(hostname: string): boolean {\n if (hostname === 'localhost' || hostname === '127.0.0.1') {\n return true;\n }\n // Handle IPv6 localhost - hostname may be '::1' or '[::1]' depending on environment\n const normalizedHostname = hostname.replace(/^\\[|\\]$/g, '');\n return normalizedHostname === '::1';\n}\n\n/**\n * Validate URL format and check if it uses HTTPS or is localhost (HTTP allowed for local dev)\n * Returns validation result with error reason if invalid\n */\nfunction validateEndpointUrl(\n url: string,\n label: string,\n): { valid: true } | { valid: false; reason: string } {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return { valid: false, reason: `${label} must be a valid URL` };\n }\n\n if (parsed.protocol === 'https:') {\n return { valid: true };\n }\n\n if (parsed.protocol === 'http:' && isLocalhostHostname(parsed.hostname)) {\n return { valid: true }; // HTTP allowed for localhost\n }\n\n return {\n valid: false,\n reason: `${label} must use HTTPS (got ${parsed.protocol}//). HTTP is only allowed for local development (localhost, 127.0.0.1, ::1).`,\n };\n}\n\n/**\n * Validate gas price format (e.g., \"1.0umfx\")\n */\nfunction isValidGasPrice(gasPrice: string): boolean {\n // Gas price should be a number followed by a denomination.\n // Denoms can be simple (umfx), IBC (ibc/ABC123...), or factory\n // (factory/manifest1.../utoken). Denoms are made of non-empty segments\n // separated by '/', with the first segment starting with a letter.\n // Each segment may contain letters, digits, dots, colons, underscores,\n // and hyphens. Denom length must be 3-128 chars per the Cosmos SDK spec.\n const match = gasPrice.match(\n /^(\\d+(?:\\.\\d+)?)([a-zA-Z][a-zA-Z0-9.:_-]*(?:\\/[a-zA-Z0-9.:_-]+)*)$/,\n );\n if (!match) {\n return false;\n }\n const denom = match[2];\n return denom.length >= 3 && denom.length <= 128;\n}\n\n/**\n * Validate chain ID format\n */\nfunction isValidChainId(chainId: string): boolean {\n // Chain ID should be alphanumeric with hyphens\n return /^[a-zA-Z0-9][\\w-]*$/.test(chainId);\n}\n\n/**\n * Create a configuration object with defaults applied\n */\nexport function createConfig(input: ManifestMCPConfig): ManifestMCPConfig {\n return {\n chainId: input.chainId,\n rpcUrl: input.rpcUrl,\n gasPrice: input.gasPrice,\n restUrl: input.restUrl,\n addressPrefix: input.addressPrefix ?? DEFAULT_ADDRESS_PREFIX,\n rateLimit: {\n requestsPerSecond:\n input.rateLimit?.requestsPerSecond ?? DEFAULT_REQUESTS_PER_SECOND,\n },\n retry: {\n maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,\n baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,\n maxDelayMs: input.retry?.maxDelayMs ?? DEFAULT_RETRY_CONFIG.maxDelayMs,\n },\n gasMultiplier: input.gasMultiplier ?? DEFAULT_GAS_MULTIPLIER,\n };\n}\n\n/**\n * Validation result\n */\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n}\n\n/**\n * Validate a configuration object\n */\nexport function validateConfig(\n config: Partial<ManifestMCPConfig>,\n): ValidationResult {\n const errors: string[] = [];\n\n // Required fields\n if (!config.chainId) {\n errors.push('chainId is required');\n } else if (!isValidChainId(config.chainId)) {\n errors.push(\n 'chainId must be alphanumeric with hyphens (e.g., \"manifest-ledger-testnet\")',\n );\n }\n\n // At least one of rpcUrl or restUrl must be provided\n if (!config.rpcUrl && !config.restUrl) {\n errors.push('At least one of rpcUrl or restUrl is required');\n }\n\n if (config.rpcUrl) {\n const urlCheck = validateEndpointUrl(config.rpcUrl, 'rpcUrl');\n if (!urlCheck.valid) {\n errors.push(urlCheck.reason);\n }\n }\n\n if (config.restUrl) {\n const urlCheck = validateEndpointUrl(config.restUrl, 'restUrl');\n if (!urlCheck.valid) {\n errors.push(urlCheck.reason);\n }\n }\n\n // gasPrice required when rpcUrl is provided (needed for signing)\n if (config.rpcUrl && !config.gasPrice) {\n errors.push('gasPrice is required when rpcUrl is provided');\n } else if (config.gasPrice && !isValidGasPrice(config.gasPrice)) {\n errors.push(\n 'gasPrice must be a number followed by denomination (e.g., \"1.0umfx\", \"0.5factory/addr/udenom\", or \"0.25ibc/ABC123\")',\n );\n }\n\n // Optional fields\n if (config.addressPrefix !== undefined) {\n if (!/^[a-z]+$/.test(config.addressPrefix)) {\n errors.push('addressPrefix must be lowercase letters only');\n }\n }\n\n if (config.rateLimit !== undefined) {\n if (\n typeof config.rateLimit !== 'object' ||\n config.rateLimit === null ||\n Array.isArray(config.rateLimit)\n ) {\n errors.push('rateLimit must be a plain object');\n } else if (config.rateLimit.requestsPerSecond !== undefined) {\n if (\n typeof config.rateLimit.requestsPerSecond !== 'number' ||\n config.rateLimit.requestsPerSecond <= 0 ||\n !Number.isInteger(config.rateLimit.requestsPerSecond)\n ) {\n errors.push('rateLimit.requestsPerSecond must be a positive integer');\n }\n }\n }\n\n if (config.retry !== undefined) {\n if (\n typeof config.retry !== 'object' ||\n config.retry === null ||\n Array.isArray(config.retry)\n ) {\n errors.push('retry must be a plain object');\n } else {\n if (config.retry.maxRetries !== undefined) {\n if (\n typeof config.retry.maxRetries !== 'number' ||\n config.retry.maxRetries < 0 ||\n !Number.isInteger(config.retry.maxRetries)\n ) {\n errors.push('retry.maxRetries must be a non-negative integer');\n }\n }\n if (config.retry.baseDelayMs !== undefined) {\n if (\n typeof config.retry.baseDelayMs !== 'number' ||\n config.retry.baseDelayMs <= 0 ||\n !Number.isInteger(config.retry.baseDelayMs)\n ) {\n errors.push('retry.baseDelayMs must be a positive integer');\n }\n }\n if (config.retry.maxDelayMs !== undefined) {\n if (\n typeof config.retry.maxDelayMs !== 'number' ||\n config.retry.maxDelayMs <= 0 ||\n !Number.isInteger(config.retry.maxDelayMs)\n ) {\n errors.push('retry.maxDelayMs must be a positive integer');\n }\n }\n // Validate maxDelayMs >= baseDelayMs if both are provided\n if (\n config.retry.baseDelayMs !== undefined &&\n config.retry.maxDelayMs !== undefined &&\n config.retry.maxDelayMs < config.retry.baseDelayMs\n ) {\n errors.push(\n 'retry.maxDelayMs must be greater than or equal to retry.baseDelayMs',\n );\n }\n }\n }\n\n if (config.gasMultiplier !== undefined) {\n if (\n typeof config.gasMultiplier !== 'number' ||\n !Number.isFinite(config.gasMultiplier) ||\n config.gasMultiplier < 1\n ) {\n errors.push('gasMultiplier must be a finite number >= 1');\n }\n }\n\n return {\n valid: errors.length === 0,\n errors,\n };\n}\n\n/**\n * Create and validate a configuration, throwing on invalid config\n */\nexport function createValidatedConfig(\n input: ManifestMCPConfig,\n): ManifestMCPConfig {\n const validation = validateConfig(input);\n\n if (!validation.valid) {\n throw new ManifestMCPError(\n ManifestMCPErrorCode.INVALID_CONFIG,\n `Invalid configuration: ${validation.errors.join(', ')}`,\n { errors: validation.errors },\n );\n }\n\n return createConfig(input);\n}\n"],"mappings":";;;;;;AAUA,MAAM,yBAAyB;;;;AAK/B,MAAa,8BAA8B;;;;;;AAO3C,MAAa,yBAAyB;;;;;AAStC,SAAS,oBAAoB,UAA2B;AACtD,KAAI,aAAa,eAAe,aAAa,YAC3C,QAAO;AAIT,QAD2B,SAAS,QAAQ,YAAY,GAAG,KAC7B;;;;;;AAOhC,SAAS,oBACP,KACA,OACoD;CACpD,IAAI;AACJ,KAAI;AACF,WAAS,IAAI,IAAI,IAAI;SACf;AACN,SAAO;GAAE,OAAO;GAAO,QAAQ,GAAG,MAAM;GAAuB;;AAGjE,KAAI,OAAO,aAAa,SACtB,QAAO,EAAE,OAAO,MAAM;AAGxB,KAAI,OAAO,aAAa,WAAW,oBAAoB,OAAO,SAAS,CACrE,QAAO,EAAE,OAAO,MAAM;AAGxB,QAAO;EACL,OAAO;EACP,QAAQ,GAAG,MAAM,uBAAuB,OAAO,SAAS;EACzD;;;;;AAMH,SAAS,gBAAgB,UAA2B;CAOlD,MAAM,QAAQ,SAAS,MACrB,qEACD;AACD,KAAI,CAAC,MACH,QAAO;CAET,MAAM,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SAAgB,sBACd,OACmB;CACnB,MAAM,aAAa,eAAe,MAAM;AAExC,KAAI,CAAC,WAAW,MACd,OAAM,IAAI,iBACR,qBAAqB,gBACrB,0BAA0B,WAAW,OAAO,KAAK,KAAK,IACtD,EAAE,QAAQ,WAAW,QAAQ,CAC9B;AAGH,QAAO,aAAa,MAAM"}
|
|
1
|
+
{"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { DEFAULT_RETRY_CONFIG } from './retry.js';\nimport {\n type ManifestMCPConfig,\n ManifestMCPError,\n ManifestMCPErrorCode,\n} from './types.js';\n\n/**\n * Default address prefix for Manifest Network\n */\nconst DEFAULT_ADDRESS_PREFIX = 'manifest';\n\n/**\n * Default requests per second for rate limiting\n */\nexport const DEFAULT_REQUESTS_PER_SECOND = 10;\n\n/**\n * Default gas simulation multiplier. CosmJS defaults to 1.4 but billing module\n * transactions (close-lease in particular) can exceed that. 1.5 matches\n * the --gas-adjustment value used in this project's E2E scripts (e2e/scripts/init_billing.sh).\n */\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\n\n// Re-export for consumers\nexport { DEFAULT_RETRY_CONFIG };\n\n/**\n * Check if a hostname is localhost (IPv4, IPv6, or hostname)\n * Handles both bracketed and unbracketed IPv6 formats\n */\nfunction isLocalhostHostname(hostname: string): boolean {\n if (hostname === 'localhost' || hostname === '127.0.0.1') {\n return true;\n }\n // Handle IPv6 localhost - hostname may be '::1' or '[::1]' depending on environment\n const normalizedHostname = hostname.replace(/^\\[|\\]$/g, '');\n return normalizedHostname === '::1';\n}\n\n/**\n * Validate URL format and check if it uses HTTPS or is localhost (HTTP allowed for local dev)\n * Returns validation result with error reason if invalid\n */\nexport function validateEndpointUrl(\n url: string,\n label: string,\n): { valid: true } | { valid: false; reason: string } {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return { valid: false, reason: `${label} must be a valid URL` };\n }\n\n if (parsed.protocol === 'https:') {\n return { valid: true };\n }\n\n if (parsed.protocol === 'http:' && isLocalhostHostname(parsed.hostname)) {\n return { valid: true }; // HTTP allowed for localhost\n }\n\n return {\n valid: false,\n reason: `${label} must use HTTPS (got ${parsed.protocol}//). HTTP is only allowed for local development (localhost, 127.0.0.1, ::1).`,\n };\n}\n\n/**\n * Validate gas price format (e.g., \"1.0umfx\")\n */\nfunction isValidGasPrice(gasPrice: string): boolean {\n // Gas price should be a number followed by a denomination.\n // Denoms can be simple (umfx), IBC (ibc/ABC123...), or factory\n // (factory/manifest1.../utoken). Denoms are made of non-empty segments\n // separated by '/', with the first segment starting with a letter.\n // Each segment may contain letters, digits, dots, colons, underscores,\n // and hyphens. Denom length must be 3-128 chars per the Cosmos SDK spec.\n const match = gasPrice.match(\n /^(\\d+(?:\\.\\d+)?)([a-zA-Z][a-zA-Z0-9.:_-]*(?:\\/[a-zA-Z0-9.:_-]+)*)$/,\n );\n if (!match) {\n return false;\n }\n const denom = match[2];\n return denom.length >= 3 && denom.length <= 128;\n}\n\n/**\n * Validate chain ID format\n */\nfunction isValidChainId(chainId: string): boolean {\n // Chain ID should be alphanumeric with hyphens\n return /^[a-zA-Z0-9][\\w-]*$/.test(chainId);\n}\n\n/**\n * Create a configuration object with defaults applied\n */\nexport function createConfig(input: ManifestMCPConfig): ManifestMCPConfig {\n return {\n chainId: input.chainId,\n rpcUrl: input.rpcUrl,\n gasPrice: input.gasPrice,\n restUrl: input.restUrl,\n addressPrefix: input.addressPrefix ?? DEFAULT_ADDRESS_PREFIX,\n rateLimit: {\n requestsPerSecond:\n input.rateLimit?.requestsPerSecond ?? DEFAULT_REQUESTS_PER_SECOND,\n },\n retry: {\n maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,\n baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,\n maxDelayMs: input.retry?.maxDelayMs ?? DEFAULT_RETRY_CONFIG.maxDelayMs,\n },\n gasMultiplier: input.gasMultiplier ?? DEFAULT_GAS_MULTIPLIER,\n };\n}\n\n/**\n * Validation result\n */\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n}\n\n/**\n * Validate a configuration object\n */\nexport function validateConfig(\n config: Partial<ManifestMCPConfig>,\n): ValidationResult {\n const errors: string[] = [];\n\n // Required fields\n if (!config.chainId) {\n errors.push('chainId is required');\n } else if (!isValidChainId(config.chainId)) {\n errors.push(\n 'chainId must be alphanumeric with hyphens (e.g., \"manifest-ledger-testnet\")',\n );\n }\n\n // At least one of rpcUrl or restUrl must be provided\n if (!config.rpcUrl && !config.restUrl) {\n errors.push('At least one of rpcUrl or restUrl is required');\n }\n\n if (config.rpcUrl) {\n const urlCheck = validateEndpointUrl(config.rpcUrl, 'rpcUrl');\n if (!urlCheck.valid) {\n errors.push(urlCheck.reason);\n }\n }\n\n if (config.restUrl) {\n const urlCheck = validateEndpointUrl(config.restUrl, 'restUrl');\n if (!urlCheck.valid) {\n errors.push(urlCheck.reason);\n }\n }\n\n // gasPrice required when rpcUrl is provided (needed for signing)\n if (config.rpcUrl && !config.gasPrice) {\n errors.push('gasPrice is required when rpcUrl is provided');\n } else if (config.gasPrice && !isValidGasPrice(config.gasPrice)) {\n errors.push(\n 'gasPrice must be a number followed by denomination (e.g., \"1.0umfx\", \"0.5factory/addr/udenom\", or \"0.25ibc/ABC123\")',\n );\n }\n\n // Optional fields\n if (config.addressPrefix !== undefined) {\n if (!/^[a-z]+$/.test(config.addressPrefix)) {\n errors.push('addressPrefix must be lowercase letters only');\n }\n }\n\n if (config.rateLimit !== undefined) {\n if (\n typeof config.rateLimit !== 'object' ||\n config.rateLimit === null ||\n Array.isArray(config.rateLimit)\n ) {\n errors.push('rateLimit must be a plain object');\n } else if (config.rateLimit.requestsPerSecond !== undefined) {\n if (\n typeof config.rateLimit.requestsPerSecond !== 'number' ||\n config.rateLimit.requestsPerSecond <= 0 ||\n !Number.isInteger(config.rateLimit.requestsPerSecond)\n ) {\n errors.push('rateLimit.requestsPerSecond must be a positive integer');\n }\n }\n }\n\n if (config.retry !== undefined) {\n if (\n typeof config.retry !== 'object' ||\n config.retry === null ||\n Array.isArray(config.retry)\n ) {\n errors.push('retry must be a plain object');\n } else {\n if (config.retry.maxRetries !== undefined) {\n if (\n typeof config.retry.maxRetries !== 'number' ||\n config.retry.maxRetries < 0 ||\n !Number.isInteger(config.retry.maxRetries)\n ) {\n errors.push('retry.maxRetries must be a non-negative integer');\n }\n }\n if (config.retry.baseDelayMs !== undefined) {\n if (\n typeof config.retry.baseDelayMs !== 'number' ||\n config.retry.baseDelayMs <= 0 ||\n !Number.isInteger(config.retry.baseDelayMs)\n ) {\n errors.push('retry.baseDelayMs must be a positive integer');\n }\n }\n if (config.retry.maxDelayMs !== undefined) {\n if (\n typeof config.retry.maxDelayMs !== 'number' ||\n config.retry.maxDelayMs <= 0 ||\n !Number.isInteger(config.retry.maxDelayMs)\n ) {\n errors.push('retry.maxDelayMs must be a positive integer');\n }\n }\n // Validate maxDelayMs >= baseDelayMs if both are provided\n if (\n config.retry.baseDelayMs !== undefined &&\n config.retry.maxDelayMs !== undefined &&\n config.retry.maxDelayMs < config.retry.baseDelayMs\n ) {\n errors.push(\n 'retry.maxDelayMs must be greater than or equal to retry.baseDelayMs',\n );\n }\n }\n }\n\n if (config.gasMultiplier !== undefined) {\n if (\n typeof config.gasMultiplier !== 'number' ||\n !Number.isFinite(config.gasMultiplier) ||\n config.gasMultiplier < 1\n ) {\n errors.push('gasMultiplier must be a finite number >= 1');\n }\n }\n\n return {\n valid: errors.length === 0,\n errors,\n };\n}\n\n/**\n * Create and validate a configuration, throwing on invalid config\n */\nexport function createValidatedConfig(\n input: ManifestMCPConfig,\n): ManifestMCPConfig {\n const validation = validateConfig(input);\n\n if (!validation.valid) {\n throw new ManifestMCPError(\n ManifestMCPErrorCode.INVALID_CONFIG,\n `Invalid configuration: ${validation.errors.join(', ')}`,\n { errors: validation.errors },\n );\n }\n\n return createConfig(input);\n}\n"],"mappings":";;;;;;AAUA,MAAM,yBAAyB;;;;A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AAgB,KAAA;OAE7B,OAAO,OAAO,MAAM,gBAAgB,YACpC,OAAO,MAAM,eAAe,KAC5B,CAAC,OAAO,UAAU,OAAO,MAAM,YAAY,CAE3C,QAAO,KAAK,+CAA+C;;AAG/D,MAAI,OAAO,MAAM,eAAe,KAAA;OAE5B,OAAO,OAAO,MAAM,eAAe,YACnC,OAAO,MAAM,cAAc,KAC3B,CAAC,OAAO,UAAU,OAAO,MAAM,WAAW,CAE1C,QAAO,KAAK,8CAA8C;;AAI9D,MACE,OAAO,MAAM,gBAAgB,KAAA,KAC7B,OAAO,MAAM,eAAe,KAAA,KAC5B,OAAO,MAAM,aAAa,OAAO,MAAM,YAEvC,QAAO,KACL,sEACD;;AAKP,KAAI,OAAO,kBAAkB,KAAA;MAEzB,OAAO,OAAO,kBAAkB,YAChC,CAAC,OAAO,SAAS,OAAO,cAAc,IACtC,OAAO,gBAAgB,EAEvB,QAAO,KAAK,6CAA6C;;AAI7D,QAAO;EACL,OAAO,OAAO,WAAW;EACzB;EACD;;;;;AAMH,SAAgB,sBACd,OACmB;CACnB,MAAM,aAAa,eAAe,MAAM;AAExC,KAAI,CAAC,WAAW,MACd,OAAM,IAAI,iBACR,qBAAqB,gBACrB,0BAA0B,WAAW,OAAO,KAAK,KAAK,IACtD,EAAE,QAAQ,WAAW,QAAQ,CAC9B;AAGH,QAAO,aAAa,MAAM"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AccountInfo, AccountInfoResult, AddressBytesToStringResult, AddressStringToBytesResult, Any, AuthAccountResult, AuthAccountsResult, AuthParams, AuthParamsResult, AuthzGrant, AuthzGrantAuthorization, AuthzGranteeGrantsResult, AuthzGranterGrantsResult, AuthzGrantsResult, AvailableModules, BalanceResult, BalancesResult, BankMetadata, BankParams, BankParamsResult, BaseAccount, Bech32PrefixResult, BillingParams, BillingParamsResult, BuiltMessages, CodeInfoResponse, Coin, CommissionResult, CommunityPoolResult, ContractCodeHistoryEntry, ContractInfo, CosmosQueryResult, CosmosTxResult, CreditAccount, CreditAccountResult, CreditAccountsResult, CreditAddressResult, CreditEstimateResult, DecCoin, DelegationDelegatorReward, DelegationResponse, DelegationResult, DelegationsResult, DelegatorValidatorsResult, DelegatorWithdrawAddressResult, DenomAuthorityMetadata, DenomAuthorityMetadataResult, DenomMetadataResult, DenomTrace, DenomsFromAdminResult, DenomsFromCreatorResult, DenomsMetadataResult, DepositParams, DepositResult, DepositsResult, DistributionParams, DistributionParamsResult, FeeEstimateResult, FeegrantAllowanceResult, FeegrantAllowancesResult, FeegrantGrant, GovDeposit, GovParams, GovParamsResult, GovProposal, GovTallyResult, GovVote, GroupInfo, GroupInfoResult, GroupMember, GroupMembersResult, GroupPoliciesResult, GroupPolicyInfo, GroupPolicyInfoResult, GroupProposal, GroupProposalResult, GroupProposalsResult, GroupTallyQueryResult, GroupTallyResult, GroupVote, GroupVoteResult, GroupVotesResult, GroupsResult, HistoricalInfo, HistoricalInfoResult, IbcDenomTraceResult, IbcDenomTracesResult, IbcTransferParams, IbcTransferParamsResult, Lease, LeaseByCustomDomainResult, LeaseItemInput, LeaseResult, LeasesResult, ManifestMCPConfig, ManifestMCPError, ManifestMCPErrorCode, MintAnnualProvisionsResult, MintInflationResult, MintParams, MintParamsResult, Model, ModuleAccount, ModuleAccountsResult, ModuleInfo, PaginatedResult, PaginationResponse, PoAAuthorityResult, PoAConsensusPowerResult, PoAPendingValidatorsResult, PoAStakingParams, PoAValidator, ProposalResult, ProposalsResult, Provider, ProviderResult, ProviderWithdrawableResult, ProvidersResult, QueryCreditEstimateResponse, QueryResult, RateLimitConfig, RedelegationResponse, RedelegationsResult, RetryConfig, RewardsResult, SKU, SendEnabled, SendEnabledResult, SignArbitraryResult, SkuParams, SkuParamsResult, SkuResult, SkusResult, SlashesResult, StakingParams, StakingParamsResult, StakingPool, StakingPoolResult, SupplyOfResult, TallyParams, TallyResult, TokenfactoryParams, TokenfactoryParamsResult, TotalSupplyResult, TxBuildContext, TxOptions, TxOverrides, UnbondingDelegation, UnbondingDelegationResult, UnbondingDelegationsResult, Validator, ValidatorAccumulatedCommission, ValidatorOutstandingRewards, ValidatorOutstandingRewardsResult, ValidatorResult, ValidatorSlashEvent, ValidatorsResult, VoteResult, VotesResult, VotingParams, WalletProvider, WasmAllContractStateResult, WasmBuildAddressResult, WasmCodeInfo, WasmCodeInfoResult, WasmCodeResult, WasmCodesResult, WasmContractHistoryResult, WasmContractInfoResult, WasmContractsByCodeResult, WasmContractsByCreatorResult, WasmLimitsConfigResult, WasmParams, WasmParamsResult, WasmPinnedCodesResult, WasmRawContractStateResult, WasmSmartContractStateResult, WithdrawableAmountResult } from "./types.js";
|
|
2
2
|
import { CosmosClientManager, ManifestQueryClient } from "./client.js";
|
|
3
3
|
import { DEFAULT_RETRY_CONFIG, RetryOptions, calculateBackoff, isRetryableError, withRetry } from "./retry.js";
|
|
4
|
-
import { ValidationResult, createConfig, createValidatedConfig, validateConfig } from "./config.js";
|
|
4
|
+
import { ValidationResult, createConfig, createValidatedConfig, validateConfig, validateEndpointUrl } from "./config.js";
|
|
5
5
|
import { cosmosEstimateFee, cosmosQuery, cosmosTx } from "./cosmos.js";
|
|
6
6
|
import { createLCDQueryClient } from "./lcd-adapter.js";
|
|
7
7
|
import { LogLevel, logger, parseLogLevel } from "./logger.js";
|
|
@@ -19,4 +19,4 @@ import { VERSION } from "./version.js";
|
|
|
19
19
|
import { MnemonicWalletProvider } from "./wallet/mnemonic.js";
|
|
20
20
|
import { signArbitraryWithAmino } from "./wallet/sign-arbitrary.js";
|
|
21
21
|
import { LeaseState, leaseStateFromJSON, leaseStateToJSON } from "@manifest-network/manifestjs/dist/codegen/liftedinit/billing/v1/types.js";
|
|
22
|
-
export { AccountInfo, AccountInfoResult, AddressBytesToStringResult, AddressStringToBytesResult, Any, AuthAccountResult, AuthAccountsResult, AuthParams, AuthParamsResult, AuthzGrant, AuthzGrantAuthorization, AuthzGranteeGrantsResult, AuthzGranterGrantsResult, AuthzGrantsResult, AvailableModules, BalanceResult, BalancesResult, BankMetadata, BankParams, BankParamsResult, BaseAccount, Bech32PrefixResult, BillingParams, BillingParamsResult, BuiltMessages, CodeInfoResponse, Coin, CommissionResult, CommunityPoolResult, ContractCodeHistoryEntry, ContractInfo, CosmosClientManager, CosmosQueryResult, CosmosTxResult, CreditAccount, CreditAccountResult, CreditAccountsResult, CreditAddressResult, CreditEstimateResult, DEFAULT_RETRY_CONFIG, DNS_LABEL_RE, DecCoin, DelegationDelegatorReward, DelegationResponse, DelegationResult, DelegationsResult, DelegatorValidatorsResult, DelegatorWithdrawAddressResult, DenomAuthorityMetadata, DenomAuthorityMetadataResult, DenomMetadataResult, DenomTrace, DenomsFromAdminResult, DenomsFromCreatorResult, DenomsMetadataResult, DepositParams, DepositResult, DepositsResult, DistributionParams, DistributionParamsResult, FeeEstimateResult, FeegrantAllowanceResult, FeegrantAllowancesResult, FeegrantGrant, type FundCreditsResult, GovDeposit, GovParams, GovParamsResult, GovProposal, GovTallyResult, GovVote, GroupInfo, GroupInfoResult, GroupMember, GroupMembersResult, GroupPoliciesResult, GroupPolicyInfo, GroupPolicyInfoResult, GroupProposal, GroupProposalResult, GroupProposalsResult, GroupTallyQueryResult, GroupTallyResult, GroupVote, GroupVoteResult, GroupVotesResult, GroupsResult, HistoricalInfo, HistoricalInfoResult, INFRASTRUCTURE_ERROR_CODES, IbcDenomTraceResult, IbcDenomTracesResult, IbcTransferParams, IbcTransferParamsResult, Lease, LeaseByCustomDomainResult, LeaseItemInput, LeaseResult, LeaseState, LeasesResult, type LogLevel, MANIFEST_TOOL_META_VERSION, MAX_PAGE_LIMIT, ManifestMCPConfig, ManifestMCPError, ManifestMCPErrorCode, type ManifestMCPServerOptions, type ManifestQueryClient, type ManifestToolMeta, type ManifestToolMetaContainer, type ManifestToolMetaVersion, MintAnnualProvisionsResult, MintInflationResult, MintParams, MintParamsResult, type MnemonicServerConfig, MnemonicWalletProvider, Model, ModuleAccount, ModuleAccountsResult, ModuleInfo, PaginatedResult, PaginationResponse, PoAAuthorityResult, PoAConsensusPowerResult, PoAPendingValidatorsResult, PoAStakingParams, PoAValidator, ProposalResult, ProposalsResult, Provider, ProviderResult, ProviderWithdrawableResult, ProvidersResult, QueryCreditEstimateResponse, QueryResult, RateLimitConfig, RedelegationResponse, RedelegationsResult, RetryConfig, type RetryOptions, RewardsResult, SENSITIVE_FIELDS, SKU, SendEnabled, SendEnabledResult, type SetItemCustomDomainOptions, type SetItemCustomDomainResult, SignArbitraryResult, SkuParams, SkuParamsResult, SkuResult, SkusResult, SlashesResult, StakingParams, StakingParamsResult, StakingPool, StakingPoolResult, type StopAppResult, SupplyOfResult, TallyParams, TallyResult, TokenfactoryParams, TokenfactoryParamsResult, TotalSupplyResult, TxBuildContext, TxOptions, TxOverrides, UnbondingDelegation, UnbondingDelegationResult, UnbondingDelegationsResult, VERSION, type ValidationResult, Validator, ValidatorAccumulatedCommission, ValidatorOutstandingRewards, ValidatorOutstandingRewardsResult, ValidatorResult, ValidatorSlashEvent, ValidatorsResult, VoteResult, VotesResult, VotingParams, WalletProvider, WasmAllContractStateResult, WasmBuildAddressResult, WasmCodeInfo, WasmCodeInfoResult, WasmCodeResult, WasmCodesResult, WasmContractHistoryResult, WasmContractInfoResult, WasmContractsByCodeResult, WasmContractsByCreatorResult, WasmLimitsConfigResult, WasmParams, WasmParamsResult, WasmPinnedCodesResult, WasmRawContractStateResult, WasmSmartContractStateResult, WithdrawableAmountResult, bigIntReplacer, calculateBackoff, cosmosEstimateFee, cosmosQuery, cosmosTx, createConfig, createLCDQueryClient, createMnemonicServer, createPagination, createValidatedConfig, fundCredits, getAvailableModules, getBalance, getModuleSubcommands, getSubcommandUsage, getSupportedModules, isRetryableError, isSubcommandSupported, jsonResponse, leaseStateFromJSON, leaseStateToJSON, logger, manifestMeta, mutatingAnnotations, optionalBoolean, parseArgs, parseLogLevel, readOnlyAnnotations, requireString, requireStringEnum, requireUuid, sanitizeForLogging, setItemCustomDomain, signArbitraryWithAmino, stopApp, structuredResponse, validateAddress, validateConfig, withErrorHandling, withRetry };
|
|
22
|
+
export { AccountInfo, AccountInfoResult, AddressBytesToStringResult, AddressStringToBytesResult, Any, AuthAccountResult, AuthAccountsResult, AuthParams, AuthParamsResult, AuthzGrant, AuthzGrantAuthorization, AuthzGranteeGrantsResult, AuthzGranterGrantsResult, AuthzGrantsResult, AvailableModules, BalanceResult, BalancesResult, BankMetadata, BankParams, BankParamsResult, BaseAccount, Bech32PrefixResult, BillingParams, BillingParamsResult, BuiltMessages, CodeInfoResponse, Coin, CommissionResult, CommunityPoolResult, ContractCodeHistoryEntry, ContractInfo, CosmosClientManager, CosmosQueryResult, CosmosTxResult, CreditAccount, CreditAccountResult, CreditAccountsResult, CreditAddressResult, CreditEstimateResult, DEFAULT_RETRY_CONFIG, DNS_LABEL_RE, DecCoin, DelegationDelegatorReward, DelegationResponse, DelegationResult, DelegationsResult, DelegatorValidatorsResult, DelegatorWithdrawAddressResult, DenomAuthorityMetadata, DenomAuthorityMetadataResult, DenomMetadataResult, DenomTrace, DenomsFromAdminResult, DenomsFromCreatorResult, DenomsMetadataResult, DepositParams, DepositResult, DepositsResult, DistributionParams, DistributionParamsResult, FeeEstimateResult, FeegrantAllowanceResult, FeegrantAllowancesResult, FeegrantGrant, type FundCreditsResult, GovDeposit, GovParams, GovParamsResult, GovProposal, GovTallyResult, GovVote, GroupInfo, GroupInfoResult, GroupMember, GroupMembersResult, GroupPoliciesResult, GroupPolicyInfo, GroupPolicyInfoResult, GroupProposal, GroupProposalResult, GroupProposalsResult, GroupTallyQueryResult, GroupTallyResult, GroupVote, GroupVoteResult, GroupVotesResult, GroupsResult, HistoricalInfo, HistoricalInfoResult, INFRASTRUCTURE_ERROR_CODES, IbcDenomTraceResult, IbcDenomTracesResult, IbcTransferParams, IbcTransferParamsResult, Lease, LeaseByCustomDomainResult, LeaseItemInput, LeaseResult, LeaseState, LeasesResult, type LogLevel, MANIFEST_TOOL_META_VERSION, MAX_PAGE_LIMIT, ManifestMCPConfig, ManifestMCPError, ManifestMCPErrorCode, type ManifestMCPServerOptions, type ManifestQueryClient, type ManifestToolMeta, type ManifestToolMetaContainer, type ManifestToolMetaVersion, MintAnnualProvisionsResult, MintInflationResult, MintParams, MintParamsResult, type MnemonicServerConfig, MnemonicWalletProvider, Model, ModuleAccount, ModuleAccountsResult, ModuleInfo, PaginatedResult, PaginationResponse, PoAAuthorityResult, PoAConsensusPowerResult, PoAPendingValidatorsResult, PoAStakingParams, PoAValidator, ProposalResult, ProposalsResult, Provider, ProviderResult, ProviderWithdrawableResult, ProvidersResult, QueryCreditEstimateResponse, QueryResult, RateLimitConfig, RedelegationResponse, RedelegationsResult, RetryConfig, type RetryOptions, RewardsResult, SENSITIVE_FIELDS, SKU, SendEnabled, SendEnabledResult, type SetItemCustomDomainOptions, type SetItemCustomDomainResult, SignArbitraryResult, SkuParams, SkuParamsResult, SkuResult, SkusResult, SlashesResult, StakingParams, StakingParamsResult, StakingPool, StakingPoolResult, type StopAppResult, SupplyOfResult, TallyParams, TallyResult, TokenfactoryParams, TokenfactoryParamsResult, TotalSupplyResult, TxBuildContext, TxOptions, TxOverrides, UnbondingDelegation, UnbondingDelegationResult, UnbondingDelegationsResult, VERSION, type ValidationResult, Validator, ValidatorAccumulatedCommission, ValidatorOutstandingRewards, ValidatorOutstandingRewardsResult, ValidatorResult, ValidatorSlashEvent, ValidatorsResult, VoteResult, VotesResult, VotingParams, WalletProvider, WasmAllContractStateResult, WasmBuildAddressResult, WasmCodeInfo, WasmCodeInfoResult, WasmCodeResult, WasmCodesResult, WasmContractHistoryResult, WasmContractInfoResult, WasmContractsByCodeResult, WasmContractsByCreatorResult, WasmLimitsConfigResult, WasmParams, WasmParamsResult, WasmPinnedCodesResult, WasmRawContractStateResult, WasmSmartContractStateResult, WithdrawableAmountResult, bigIntReplacer, calculateBackoff, cosmosEstimateFee, cosmosQuery, cosmosTx, createConfig, createLCDQueryClient, createMnemonicServer, createPagination, createValidatedConfig, fundCredits, getAvailableModules, getBalance, getModuleSubcommands, getSubcommandUsage, getSupportedModules, isRetryableError, isSubcommandSupported, jsonResponse, leaseStateFromJSON, leaseStateToJSON, logger, manifestMeta, mutatingAnnotations, optionalBoolean, parseArgs, parseLogLevel, readOnlyAnnotations, requireString, requireStringEnum, requireUuid, sanitizeForLogging, setItemCustomDomain, signArbitraryWithAmino, stopApp, structuredResponse, validateAddress, validateConfig, validateEndpointUrl, withErrorHandling, withRetry };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ManifestMCPError, ManifestMCPErrorCode } from "./types.js";
|
|
2
2
|
import { DEFAULT_RETRY_CONFIG, calculateBackoff, isRetryableError, withRetry } from "./retry.js";
|
|
3
|
-
import { createConfig, createValidatedConfig, validateConfig } from "./config.js";
|
|
3
|
+
import { createConfig, createValidatedConfig, validateConfig, validateEndpointUrl } from "./config.js";
|
|
4
4
|
import { logger, parseLogLevel } from "./logger.js";
|
|
5
5
|
import { createLCDQueryClient } from "./lcd-adapter.js";
|
|
6
6
|
import { CosmosClientManager } from "./client.js";
|
|
@@ -20,4 +20,4 @@ import { setItemCustomDomain } from "./tools/setItemCustomDomain.js";
|
|
|
20
20
|
import { stopApp } from "./tools/stopApp.js";
|
|
21
21
|
import { VERSION } from "./version.js";
|
|
22
22
|
import { LeaseState, leaseStateFromJSON, leaseStateToJSON } from "@manifest-network/manifestjs/dist/codegen/liftedinit/billing/v1/types.js";
|
|
23
|
-
export { CosmosClientManager, DEFAULT_RETRY_CONFIG, DNS_LABEL_RE, INFRASTRUCTURE_ERROR_CODES, LeaseState, MANIFEST_TOOL_META_VERSION, MAX_PAGE_LIMIT, ManifestMCPError, ManifestMCPErrorCode, MnemonicWalletProvider, SENSITIVE_FIELDS, VERSION, bigIntReplacer, calculateBackoff, cosmosEstimateFee, cosmosQuery, cosmosTx, createConfig, createLCDQueryClient, createMnemonicServer, createPagination, createValidatedConfig, fundCredits, getAvailableModules, getBalance, getModuleSubcommands, getSubcommandUsage, getSupportedModules, isRetryableError, isSubcommandSupported, jsonResponse, leaseStateFromJSON, leaseStateToJSON, logger, manifestMeta, mutatingAnnotations, optionalBoolean, parseArgs, parseLogLevel, readOnlyAnnotations, requireString, requireStringEnum, requireUuid, sanitizeForLogging, setItemCustomDomain, signArbitraryWithAmino, stopApp, structuredResponse, validateAddress, validateConfig, withErrorHandling, withRetry };
|
|
23
|
+
export { CosmosClientManager, DEFAULT_RETRY_CONFIG, DNS_LABEL_RE, INFRASTRUCTURE_ERROR_CODES, LeaseState, MANIFEST_TOOL_META_VERSION, MAX_PAGE_LIMIT, ManifestMCPError, ManifestMCPErrorCode, MnemonicWalletProvider, SENSITIVE_FIELDS, VERSION, bigIntReplacer, calculateBackoff, cosmosEstimateFee, cosmosQuery, cosmosTx, createConfig, createLCDQueryClient, createMnemonicServer, createPagination, createValidatedConfig, fundCredits, getAvailableModules, getBalance, getModuleSubcommands, getSubcommandUsage, getSupportedModules, isRetryableError, isSubcommandSupported, jsonResponse, leaseStateFromJSON, leaseStateToJSON, logger, manifestMeta, mutatingAnnotations, optionalBoolean, parseArgs, parseLogLevel, readOnlyAnnotations, requireString, requireStringEnum, requireUuid, sanitizeForLogging, setItemCustomDomain, signArbitraryWithAmino, stopApp, structuredResponse, validateAddress, validateConfig, validateEndpointUrl, withErrorHandling, withRetry };
|
package/dist/server-utils.d.ts
CHANGED
|
@@ -43,7 +43,9 @@ declare function jsonResponse(data: unknown, replacer?: (key: string, value: any
|
|
|
43
43
|
* (consumed by clients that validate against the tool's outputSchema) and
|
|
44
44
|
* `content` (text fallback for clients that don't). Use this for any tool
|
|
45
45
|
* registered with an `outputSchema`. Per MCP spec, `structuredContent` must
|
|
46
|
-
* be a JSON object — `data` is
|
|
46
|
+
* be a JSON object — `data` is typed as `unknown` so callers don't need to
|
|
47
|
+
* widen typed result interfaces with double-casts; the runtime contract
|
|
48
|
+
* (object-shaped after JSON round-trip) is enforced below.
|
|
47
49
|
*
|
|
48
50
|
* The optional `replacer` is applied to BOTH `structuredContent` and the
|
|
49
51
|
* text fallback by round-tripping through JSON. This keeps `structuredContent`
|
|
@@ -51,7 +53,7 @@ declare function jsonResponse(data: unknown, replacer?: (key: string, value: any
|
|
|
51
53
|
* `Date`, or anything else `JSON.stringify` knows how to convert via the
|
|
52
54
|
* replacer.
|
|
53
55
|
*/
|
|
54
|
-
declare function structuredResponse(data:
|
|
56
|
+
declare function structuredResponse(data: unknown, replacer?: (key: string, value: any) => any): CallToolResult;
|
|
55
57
|
/**
|
|
56
58
|
* Config shape accepted by createMnemonicServer.
|
|
57
59
|
* Derives from ManifestMCPConfig (minus rateLimit/retry) so new config fields propagate automatically.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-utils.d.ts","names":[],"sources":["../src/server-utils.ts"],"mappings":";;;;;;AAgBA;;;cAAa,0BAAA,EAA4B,WAAA,CAAY,oBAAA;;AAYrD;;cAAa,gBAAA,EAAkB,WAAA;;;AAwB/B;iBAAgB,cAAA,CAAe,IAAA,UAAc,KAAA;;;;iBAO7B,kBAAA,CAAmB,GAAA,WAAc,KAAA;;;;UAgDhC,wBAAA;EACf,MAAA,EAAQ,iBAAA;EACR,cAAA,EAAgB,cAAA;AAAA;;;;;;;iBAUF,iBAAA,eACA,IAAA,YAAgB,OAAA,CAAQ,cAAA,EAAA,CACtC,QAAA,UAAkB,EAAA,EAAI,CAAA,GAAI,CAAA;AAF5B;;;AAAA,
|
|
1
|
+
{"version":3,"file":"server-utils.d.ts","names":[],"sources":["../src/server-utils.ts"],"mappings":";;;;;;AAgBA;;;cAAa,0BAAA,EAA4B,WAAA,CAAY,oBAAA;;AAYrD;;cAAa,gBAAA,EAAkB,WAAA;;;AAwB/B;iBAAgB,cAAA,CAAe,IAAA,UAAc,KAAA;;;;iBAO7B,kBAAA,CAAmB,GAAA,WAAc,KAAA;;;;UAgDhC,wBAAA;EACf,MAAA,EAAQ,iBAAA;EACR,cAAA,EAAgB,cAAA;AAAA;;;;;;;iBAUF,iBAAA,eACA,IAAA,YAAgB,OAAA,CAAQ,cAAA,EAAA,CACtC,QAAA,UAAkB,EAAA,EAAI,CAAA,GAAI,CAAA;AAF5B;;;AAAA,iBAuFgB,YAAA,CACd,IAAA,WACA,QAAA,IAAY,GAAA,UAAa,KAAA,gBACxB,cAAA;;;;;;;;;;;;;;;;iBA0Ba,kBAAA,CACd,IAAA,WAEA,QAAA,IAAY,GAAA,UAAa,KAAA,gBACxB,cAAA;;;;;KAkBS,oBAAA,GAAuB,IAAA,CACjC,iBAAA;EAAA,SAGS,QAAA;AAAA;;;;AA1BX;;;iBAmCsB,oBAAA,GAAA,CACpB,MAAA,EAAQ,oBAAA,EACR,WAAA,OAAkB,IAAA,EAAM,wBAAA,KAA6B,CAAA,GACpD,OAAA,CAAQ,CAAA"}
|
package/dist/server-utils.js
CHANGED
|
@@ -82,12 +82,14 @@ function withErrorHandling(toolName, fn) {
|
|
|
82
82
|
} catch (error) {
|
|
83
83
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
84
84
|
const errorCode = error instanceof ManifestMCPError ? error.code : "UNKNOWN";
|
|
85
|
-
|
|
85
|
+
const safeMessage = sanitizeForLogging(errorMessage);
|
|
86
|
+
const messageWasRedacted = safeMessage !== errorMessage;
|
|
87
|
+
if (error instanceof ManifestMCPError) logger.error(`[${toolName}] Tool error [${errorCode}]: ${safeMessage}`);
|
|
86
88
|
else {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
let stackSuffix = "";
|
|
90
|
+
if (!messageWasRedacted && error instanceof Error && error.stack) stackSuffix = `\n${sanitizeForLogging(error.stack)}`;
|
|
91
|
+
logger.error(`[${toolName}] Tool error [${errorCode}]: ${safeMessage}${stackSuffix}`);
|
|
89
92
|
}
|
|
90
|
-
const safeMessage = sanitizeForLogging(errorMessage);
|
|
91
93
|
let errorResponse = {
|
|
92
94
|
error: true,
|
|
93
95
|
tool: toolName,
|
|
@@ -139,7 +141,9 @@ function jsonResponse(data, replacer) {
|
|
|
139
141
|
* (consumed by clients that validate against the tool's outputSchema) and
|
|
140
142
|
* `content` (text fallback for clients that don't). Use this for any tool
|
|
141
143
|
* registered with an `outputSchema`. Per MCP spec, `structuredContent` must
|
|
142
|
-
* be a JSON object — `data` is
|
|
144
|
+
* be a JSON object — `data` is typed as `unknown` so callers don't need to
|
|
145
|
+
* widen typed result interfaces with double-casts; the runtime contract
|
|
146
|
+
* (object-shaped after JSON round-trip) is enforced below.
|
|
143
147
|
*
|
|
144
148
|
* The optional `replacer` is applied to BOTH `structuredContent` and the
|
|
145
149
|
* text fallback by round-tripping through JSON. This keeps `structuredContent`
|
package/dist/server-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-utils.js","names":[],"sources":["../src/server-utils.ts"],"sourcesContent":["import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { createValidatedConfig } from './config.js';\nimport { logger } from './logger.js';\nimport {\n type ManifestMCPConfig,\n ManifestMCPError,\n ManifestMCPErrorCode,\n type WalletProvider,\n} from './types.js';\nimport { MnemonicWalletProvider } from './wallet/index.js';\n\n/**\n * Error codes that indicate infrastructure-level failures (wallet, RPC, config).\n * Used by tool implementations to distinguish infrastructure errors from\n * provider/application errors so that infrastructure errors are always re-thrown.\n */\nexport const INFRASTRUCTURE_ERROR_CODES: ReadonlySet<ManifestMCPErrorCode> =\n new Set([\n ManifestMCPErrorCode.WALLET_NOT_CONNECTED,\n ManifestMCPErrorCode.WALLET_CONNECTION_FAILED,\n ManifestMCPErrorCode.RPC_CONNECTION_FAILED,\n ManifestMCPErrorCode.INVALID_MNEMONIC,\n ManifestMCPErrorCode.INVALID_CONFIG,\n ]);\n\n/**\n * Sensitive field names that should be redacted from error responses\n */\nexport const SENSITIVE_FIELDS: ReadonlySet<string> = new Set([\n 'mnemonic',\n 'privatekey',\n 'private_key',\n 'secret',\n 'password',\n 'seed',\n 'secret_key',\n 'signing_key',\n 'apikey',\n 'api_key',\n 'auth_token',\n 'bearer_token',\n 'access_token',\n 'refresh_token',\n]);\n\n// Note: standalone \"key\" and \"token\" are intentionally excluded from SENSITIVE_FIELDS\n// because they are too generic — they would match pagination keys, map keys, and\n// non-sensitive token identifiers. Use compound names (api_key, auth_token, etc.) instead.\n\n/**\n * JSON replacer that converts BigInt values to strings\n */\nexport function bigIntReplacer(_key: string, value: unknown): unknown {\n return typeof value === 'bigint' ? value.toString() : value;\n}\n\n/**\n * Recursively sanitize an object by redacting sensitive fields\n */\nexport function sanitizeForLogging(obj: unknown, depth = 0): unknown {\n // Prevent infinite recursion\n if (depth > 10) {\n return '[max depth exceeded]';\n }\n\n if (obj === null || obj === undefined) {\n return obj;\n }\n\n if (typeof obj === 'string') {\n // Redact strings that look like BIP-39 mnemonics (12/15/18/21/24 words).\n // BIP-39 words are all lowercase alphabetic, so require that to avoid\n // false positives on error messages that happen to be 12/24 words.\n const words = obj.trim().split(/\\s+/);\n const wordCount = words.length;\n if (wordCount >= 12 && wordCount <= 24 && wordCount % 3 === 0) {\n const allLowercaseAlpha = words.every((w) => /^[a-z]+$/.test(w));\n if (allLowercaseAlpha) {\n return '[REDACTED - possible mnemonic]';\n }\n }\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sanitizeForLogging(item, depth + 1));\n }\n\n if (typeof obj === 'object') {\n const sanitized: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n const lowerKey = key.toLowerCase();\n if (SENSITIVE_FIELDS.has(lowerKey)) {\n sanitized[key] = '[REDACTED]';\n } else {\n sanitized[key] = sanitizeForLogging(value, depth + 1);\n }\n }\n return sanitized;\n }\n\n return obj;\n}\n\n/**\n * Options for creating a chain, lease, or fred MCP server\n */\nexport interface ManifestMCPServerOptions {\n config: ManifestMCPConfig;\n walletProvider: WalletProvider;\n}\n\n/**\n * Wrap a tool handler with error handling that preserves the existing error format.\n *\n * Generic over the callback type so that Zod-inferred argument types from\n * McpServer.registerTool flow through without requiring manual casts.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- preserves ToolCallback<Args> signature from McpServer\nexport function withErrorHandling<\n T extends (...args: any[]) => Promise<CallToolResult>,\n>(toolName: string, fn: T): T {\n // For tools with no inputSchema, McpServer calls cb(extra) with one arg.\n // For tools with inputSchema, McpServer calls cb(parsedArgs, extra).\n // We infer from cbArgs.length at call time (not fn.length) so default parameters are safe.\n const wrapped = async (...cbArgs: any[]) => {\n const hasArgs = cbArgs.length >= 2;\n const args = hasArgs ? (cbArgs[0] ?? {}) : {};\n try {\n return hasArgs ? await fn(args, cbArgs[1]) : await fn(cbArgs[0]);\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n const errorCode =\n error instanceof ManifestMCPError ? error.code : 'UNKNOWN';\n if (error instanceof ManifestMCPError) {\n logger.error(\n `[${toolName}] Tool error [${errorCode}]: ${errorMessage}`,\n );\n } else {\n const stack =\n error instanceof Error && error.stack ? `\\n${error.stack}` : '';\n logger.error(\n `[${toolName}] Tool error [${errorCode}]: ${errorMessage}${stack}`,\n );\n }\n\n // Sanitize error messages before including in the MCP response.\n // This catches mnemonic-like strings in error messages and redacts them.\n const safeMessage = sanitizeForLogging(errorMessage) as string;\n\n let errorResponse: Record<string, unknown> = {\n error: true,\n tool: toolName,\n input: sanitizeForLogging(args),\n };\n\n if (error instanceof ManifestMCPError) {\n errorResponse = {\n ...errorResponse,\n code: error.code,\n message: sanitizeForLogging(error.message) as string,\n details: sanitizeForLogging(error.details),\n };\n } else {\n errorResponse = {\n ...errorResponse,\n message: safeMessage,\n };\n }\n\n let responseText: string;\n try {\n responseText = JSON.stringify(errorResponse, bigIntReplacer, 2);\n } catch (stringifyError) {\n logger.error(\n `[${toolName}] Failed to serialize error response: ${stringifyError instanceof Error ? stringifyError.message : String(stringifyError)}`,\n );\n responseText = JSON.stringify({\n error: true,\n tool: toolName,\n message: safeMessage,\n });\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n isError: true,\n };\n }\n };\n return wrapped as T;\n}\n\n/**\n * Helper to build a successful JSON text response\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- matches JSON.stringify's replacer signature\nexport function jsonResponse(\n data: unknown,\n replacer?: (key: string, value: any) => any,\n): CallToolResult {\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(data, replacer, 2),\n },\n ],\n };\n}\n\n/**\n * Helper to build a successful CallToolResult with both `structuredContent`\n * (consumed by clients that validate against the tool's outputSchema) and\n * `content` (text fallback for clients that don't). Use this for any tool\n * registered with an `outputSchema`. Per MCP spec, `structuredContent` must\n * be a JSON object — `data` is therefore typed as a record.\n *\n * The optional `replacer` is applied to BOTH `structuredContent` and the\n * text fallback by round-tripping through JSON. This keeps `structuredContent`\n * JSON-serializable for the wire, even if the caller hands us a `BigInt`,\n * `Date`, or anything else `JSON.stringify` knows how to convert via the\n * replacer.\n */\nexport function structuredResponse(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- matches JSON.stringify's replacer signature\n data: Record<string, unknown>,\n replacer?: (key: string, value: any) => any,\n): CallToolResult {\n const serialized = JSON.stringify(data, replacer);\n const structuredContent = JSON.parse(serialized) as Record<string, unknown>;\n return {\n structuredContent,\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(structuredContent, undefined, 2),\n },\n ],\n };\n}\n\n/**\n * Config shape accepted by createMnemonicServer.\n * Derives from ManifestMCPConfig (minus rateLimit/retry) so new config fields propagate automatically.\n */\nexport type MnemonicServerConfig = Omit<\n ManifestMCPConfig,\n 'rateLimit' | 'retry'\n> & {\n readonly mnemonic: string;\n};\n\n/**\n * Generic factory that creates any MCP server class with a mnemonic wallet.\n *\n * Eliminates duplicated createMnemonic*Server patterns -- callers pass the\n * server constructor instead.\n */\nexport async function createMnemonicServer<T>(\n config: MnemonicServerConfig,\n ServerClass: new (opts: ManifestMCPServerOptions) => T,\n): Promise<T> {\n const { mnemonic, ...mcpConfig } = config;\n const validatedConfig = createValidatedConfig(mcpConfig);\n const walletProvider = new MnemonicWalletProvider(validatedConfig, mnemonic);\n await walletProvider.connect();\n\n return new ServerClass({\n config: validatedConfig,\n walletProvider,\n });\n}\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,6BACX,IAAI,IAAI;CACN,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACtB,CAAC;;;;AAKJ,MAAa,mBAAwC,IAAI,IAAI;CAC3D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AASF,SAAgB,eAAe,MAAc,OAAyB;AACpE,QAAO,OAAO,UAAU,WAAW,MAAM,UAAU,GAAG;;;;;AAMxD,SAAgB,mBAAmB,KAAc,QAAQ,GAAY;AAEnE,KAAI,QAAQ,GACV,QAAO;AAGT,KAAI,QAAQ,QAAQ,QAAQ,KAAA,EAC1B,QAAO;AAGT,KAAI,OAAO,QAAQ,UAAU;EAI3B,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,MAAM;EACrC,MAAM,YAAY,MAAM;AACxB,MAAI,aAAa,MAAM,aAAa,MAAM,YAAY,MAAM;OAChC,MAAM,OAAO,MAAM,WAAW,KAAK,EAAE,CAAC,CAE9D,QAAO;;AAGX,SAAO;;AAGT,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAK,SAAS,mBAAmB,MAAM,QAAQ,EAAE,CAAC;AAG/D,KAAI,OAAO,QAAQ,UAAU;EAC3B,MAAM,YAAqC,EAAE;AAC7C,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,EAAE;GAC9C,MAAM,WAAW,IAAI,aAAa;AAClC,OAAI,iBAAiB,IAAI,SAAS,CAChC,WAAU,OAAO;OAEjB,WAAU,OAAO,mBAAmB,OAAO,QAAQ,EAAE;;AAGzD,SAAO;;AAGT,QAAO;;;;;;;;AAkBT,SAAgB,kBAEd,UAAkB,IAA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N,MAAM,KAAK,UAAU,MAAM,UAAU,EAAE;EACxC,CACF,EACF;;;;;;;;;;;;;;;AAgBH,SAAgB,mBAEd,MACA,UACgB;CAChB,MAAM,aAAa,KAAK,UAAU,MAAM,SAAS;CACjD,MAAM,oBAAoB,KAAK,MAAM,WAAW;AAChD,QAAO;EACL;EACA,SAAS,CACP;GACE,MAAM;GACN,MAAM,KAAK,UAAU,mBAAmB,KAAA,GAAW,EAAE;GACtD,CACF;EACF;;;;;;;;AAoBH,eAAsB,qBACpB,QACA,aACY;CACZ,MAAM,EAAE,UAAU,GAAG,cAAc;CACnC,MAAM,kBAAkB,sBAAsB,UAAU;CACxD,MAAM,iBAAiB,IAAI,uBAAuB,iBAAiB,SAAS;AAC5E,OAAM,eAAe,SAAS;AAE9B,QAAO,IAAI,YAAY;EACrB,QAAQ;EACR;EACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"server-utils.js","names":[],"sources":["../src/server-utils.ts"],"sourcesContent":["import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { createValidatedConfig } from './config.js';\nimport { logger } from './logger.js';\nimport {\n type ManifestMCPConfig,\n ManifestMCPError,\n ManifestMCPErrorCode,\n type WalletProvider,\n} from './types.js';\nimport { MnemonicWalletProvider } from './wallet/index.js';\n\n/**\n * Error codes that indicate infrastructure-level failures (wallet, RPC, config).\n * Used by tool implementations to distinguish infrastructure errors from\n * provider/application errors so that infrastructure errors are always re-thrown.\n */\nexport const INFRASTRUCTURE_ERROR_CODES: ReadonlySet<ManifestMCPErrorCode> =\n new Set([\n ManifestMCPErrorCode.WALLET_NOT_CONNECTED,\n ManifestMCPErrorCode.WALLET_CONNECTION_FAILED,\n ManifestMCPErrorCode.RPC_CONNECTION_FAILED,\n ManifestMCPErrorCode.INVALID_MNEMONIC,\n ManifestMCPErrorCode.INVALID_CONFIG,\n ]);\n\n/**\n * Sensitive field names that should be redacted from error responses\n */\nexport const SENSITIVE_FIELDS: ReadonlySet<string> = new Set([\n 'mnemonic',\n 'privatekey',\n 'private_key',\n 'secret',\n 'password',\n 'seed',\n 'secret_key',\n 'signing_key',\n 'apikey',\n 'api_key',\n 'auth_token',\n 'bearer_token',\n 'access_token',\n 'refresh_token',\n]);\n\n// Note: standalone \"key\" and \"token\" are intentionally excluded from SENSITIVE_FIELDS\n// because they are too generic — they would match pagination keys, map keys, and\n// non-sensitive token identifiers. Use compound names (api_key, auth_token, etc.) instead.\n\n/**\n * JSON replacer that converts BigInt values to strings\n */\nexport function bigIntReplacer(_key: string, value: unknown): unknown {\n return typeof value === 'bigint' ? value.toString() : value;\n}\n\n/**\n * Recursively sanitize an object by redacting sensitive fields\n */\nexport function sanitizeForLogging(obj: unknown, depth = 0): unknown {\n // Prevent infinite recursion\n if (depth > 10) {\n return '[max depth exceeded]';\n }\n\n if (obj === null || obj === undefined) {\n return obj;\n }\n\n if (typeof obj === 'string') {\n // Redact strings that look like BIP-39 mnemonics (12/15/18/21/24 words).\n // BIP-39 words are all lowercase alphabetic, so require that to avoid\n // false positives on error messages that happen to be 12/24 words.\n const words = obj.trim().split(/\\s+/);\n const wordCount = words.length;\n if (wordCount >= 12 && wordCount <= 24 && wordCount % 3 === 0) {\n const allLowercaseAlpha = words.every((w) => /^[a-z]+$/.test(w));\n if (allLowercaseAlpha) {\n return '[REDACTED - possible mnemonic]';\n }\n }\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sanitizeForLogging(item, depth + 1));\n }\n\n if (typeof obj === 'object') {\n const sanitized: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n const lowerKey = key.toLowerCase();\n if (SENSITIVE_FIELDS.has(lowerKey)) {\n sanitized[key] = '[REDACTED]';\n } else {\n sanitized[key] = sanitizeForLogging(value, depth + 1);\n }\n }\n return sanitized;\n }\n\n return obj;\n}\n\n/**\n * Options for creating a chain, lease, or fred MCP server\n */\nexport interface ManifestMCPServerOptions {\n config: ManifestMCPConfig;\n walletProvider: WalletProvider;\n}\n\n/**\n * Wrap a tool handler with error handling that preserves the existing error format.\n *\n * Generic over the callback type so that Zod-inferred argument types from\n * McpServer.registerTool flow through without requiring manual casts.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- preserves ToolCallback<Args> signature from McpServer\nexport function withErrorHandling<\n T extends (...args: any[]) => Promise<CallToolResult>,\n>(toolName: string, fn: T): T {\n // For tools with no inputSchema, McpServer calls cb(extra) with one arg.\n // For tools with inputSchema, McpServer calls cb(parsedArgs, extra).\n // We infer from cbArgs.length at call time (not fn.length) so default parameters are safe.\n const wrapped = async (...cbArgs: any[]) => {\n const hasArgs = cbArgs.length >= 2;\n const args = hasArgs ? (cbArgs[0] ?? {}) : {};\n try {\n return hasArgs ? await fn(args, cbArgs[1]) : await fn(cbArgs[0]);\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n const errorCode =\n error instanceof ManifestMCPError ? error.code : 'UNKNOWN';\n // Sanitize error messages before including in the MCP response or logs.\n // This catches mnemonic-like strings in error messages and redacts them.\n const safeMessage = sanitizeForLogging(errorMessage) as string;\n const messageWasRedacted = safeMessage !== errorMessage;\n if (error instanceof ManifestMCPError) {\n logger.error(`[${toolName}] Tool error [${errorCode}]: ${safeMessage}`);\n } else {\n // Stack traces embed error.message verbatim. If the message was\n // redacted, the stack would re-leak the original — so suppress the\n // stack in that case rather than emit a half-sanitized trace.\n let stackSuffix = '';\n if (!messageWasRedacted && error instanceof Error && error.stack) {\n stackSuffix = `\\n${sanitizeForLogging(error.stack) as string}`;\n }\n logger.error(\n `[${toolName}] Tool error [${errorCode}]: ${safeMessage}${stackSuffix}`,\n );\n }\n\n let errorResponse: Record<string, unknown> = {\n error: true,\n tool: toolName,\n input: sanitizeForLogging(args),\n };\n\n if (error instanceof ManifestMCPError) {\n errorResponse = {\n ...errorResponse,\n code: error.code,\n message: sanitizeForLogging(error.message) as string,\n details: sanitizeForLogging(error.details),\n };\n } else {\n errorResponse = {\n ...errorResponse,\n message: safeMessage,\n };\n }\n\n let responseText: string;\n try {\n responseText = JSON.stringify(errorResponse, bigIntReplacer, 2);\n } catch (stringifyError) {\n logger.error(\n `[${toolName}] Failed to serialize error response: ${stringifyError instanceof Error ? stringifyError.message : String(stringifyError)}`,\n );\n responseText = JSON.stringify({\n error: true,\n tool: toolName,\n message: safeMessage,\n });\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n isError: true,\n };\n }\n };\n return wrapped as T;\n}\n\n/**\n * Helper to build a successful JSON text response\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- matches JSON.stringify's replacer signature\nexport function jsonResponse(\n data: unknown,\n replacer?: (key: string, value: any) => any,\n): CallToolResult {\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(data, replacer, 2),\n },\n ],\n };\n}\n\n/**\n * Helper to build a successful CallToolResult with both `structuredContent`\n * (consumed by clients that validate against the tool's outputSchema) and\n * `content` (text fallback for clients that don't). Use this for any tool\n * registered with an `outputSchema`. Per MCP spec, `structuredContent` must\n * be a JSON object — `data` is typed as `unknown` so callers don't need to\n * widen typed result interfaces with double-casts; the runtime contract\n * (object-shaped after JSON round-trip) is enforced below.\n *\n * The optional `replacer` is applied to BOTH `structuredContent` and the\n * text fallback by round-tripping through JSON. This keeps `structuredContent`\n * JSON-serializable for the wire, even if the caller hands us a `BigInt`,\n * `Date`, or anything else `JSON.stringify` knows how to convert via the\n * replacer.\n */\nexport function structuredResponse(\n data: unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- matches JSON.stringify's replacer signature\n replacer?: (key: string, value: any) => any,\n): CallToolResult {\n const serialized = JSON.stringify(data, replacer);\n const structuredContent = JSON.parse(serialized) as Record<string, unknown>;\n return {\n structuredContent,\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(structuredContent, undefined, 2),\n },\n ],\n };\n}\n\n/**\n * Config shape accepted by createMnemonicServer.\n * Derives from ManifestMCPConfig (minus rateLimit/retry) so new config fields propagate automatically.\n */\nexport type MnemonicServerConfig = Omit<\n ManifestMCPConfig,\n 'rateLimit' | 'retry'\n> & {\n readonly mnemonic: string;\n};\n\n/**\n * Generic factory that creates any MCP server class with a mnemonic wallet.\n *\n * Eliminates duplicated createMnemonic*Server patterns -- callers pass the\n * server constructor instead.\n */\nexport async function createMnemonicServer<T>(\n config: MnemonicServerConfig,\n ServerClass: new (opts: ManifestMCPServerOptions) => T,\n): Promise<T> {\n const { mnemonic, ...mcpConfig } = config;\n const validatedConfig = createValidatedConfig(mcpConfig);\n const walletProvider = new MnemonicWalletProvider(validatedConfig, mnemonic);\n await walletProvider.connect();\n\n return new ServerClass({\n config: validatedConfig,\n walletProvider,\n });\n}\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,6BACX,IAAI,IAAI;CACN,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACrB,qBAAqB;CACtB,CAAC;;;;AAKJ,MAAa,mBAAwC,IAAI,IAAI;CAC3D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AASF,SAAgB,eAAe,MAAc,OAAyB;AACpE,QAAO,OAAO,UAAU,WAAW,MAAM,UAAU,GAAG;;;;;AAMxD,SAAgB,mBAAmB,KAAc,QAAQ,GAAY;AAEnE,KAAI,QAAQ,GACV,QAAO;AAGT,KAAI,QAAQ,QAAQ,QAAQ,KAAA,EAC1B,QAAO;AAGT,KAAI,OAAO,QAAQ,UAAU;EAI3B,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,MAAM;EACrC,MAAM,YAAY,MAAM;AACxB,MAAI,aAAa,MAAM,aAAa,MAAM,YAAY,MAAM;OAChC,MAAM,OAAO,MAAM,WAAW,KAAK,EAAE,CAAC,CAE9D,QAAO;;AAGX,SAAO;;AAGT,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAK,SAAS,mBAAmB,MAAM,QAAQ,EAAE,CAAC;AAG/D,KAAI,OA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F,mBAAe,KAAK,UAAU,eAAe,gBAAgB,EAAE;YACxD,gBAAgB;AACvB,WAAO,MACL,IAAI,SAAS,wCAAwC,0BAA0B,QAAQ,eAAe,UAAU,OAAO,eAAe,GACvI;AACD,mBAAe,KAAK,UAAU;KAC5B,OAAO;KACP,MAAM;KACN,SAAS;KACV,CAAC;;AAGJ,UAAO;IACL,SAAS,CACP;KACE,MAAM;KACN,MAAM;KACP,CACF;IACD,SAAS;IACV;;;AAGL,QAAO;;;;;AAOT,SAAgB,aACd,MACA,UACgB;AAChB,QAAO,EACL,SAAS,CACP;EACE,MAAM;EACN,MAAM,KAAK,UAAU,MAAM,UAAU,EAAE;EACxC,CACF,EACF;;;;;;;;;;;;;;;;;AAkBH,SAAgB,mBACd,MAEA,UACgB;CAChB,MAAM,aAAa,KAAK,UAAU,MAAM,SAAS;CACjD,MAAM,oBAAoB,KAAK,MAAM,WAAW;AAChD,QAAO;EACL;EACA,SAAS,CACP;GACE,MAAM;GACN,MAAM,KAAK,UAAU,mBAAmB,KAAA,GAAW,EAAE;GACtD,CACF;EACF;;;;;;;;AAoBH,eAAsB,qBACpB,QACA,aACY;CACZ,MAAM,EAAE,UAAU,GAAG,cAAc;CACnC,MAAM,kBAAkB,sBAAsB,UAAU;CACxD,MAAM,iBAAiB,IAAI,uBAAuB,iBAAiB,SAAS;AAC5E,OAAM,eAAe,SAAS;AAE9B,QAAO,IAAI,YAAY;EACrB,QAAQ;EACR;EACD,CAAC"}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../src/version.ts"],"sourcesContent":["export const VERSION = '0.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../src/version.ts"],"sourcesContent":["export const VERSION = '0.9.0';\n"],"mappings":";AAAA,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manifest-network/manifest-mcp-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Shared library for Cosmos SDK blockchain logic, tool functions, and server utilities (Manifest Network)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -69,5 +69,13 @@
|
|
|
69
69
|
"@types/node": "22.15.29",
|
|
70
70
|
"typescript": "5.9.3",
|
|
71
71
|
"vitest": "4.1.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"vitest": "^4.1.0"
|
|
75
|
+
},
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"vitest": {
|
|
78
|
+
"optional": true
|
|
79
|
+
}
|
|
72
80
|
}
|
|
73
81
|
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
//#region ../../node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
2
|
-
var comma = ",".charCodeAt(0);
|
|
3
|
-
var semicolon = ";".charCodeAt(0);
|
|
4
|
-
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
5
|
-
var intToChar = new Uint8Array(64);
|
|
6
|
-
var charToInt = new Uint8Array(128);
|
|
7
|
-
for (let i = 0; i < chars.length; i++) {
|
|
8
|
-
const c = chars.charCodeAt(i);
|
|
9
|
-
intToChar[i] = c;
|
|
10
|
-
charToInt[c] = i;
|
|
11
|
-
}
|
|
12
|
-
function encodeInteger(builder, num, relative) {
|
|
13
|
-
let delta = num - relative;
|
|
14
|
-
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
15
|
-
do {
|
|
16
|
-
let clamped = delta & 31;
|
|
17
|
-
delta >>>= 5;
|
|
18
|
-
if (delta > 0) clamped |= 32;
|
|
19
|
-
builder.write(intToChar[clamped]);
|
|
20
|
-
} while (delta > 0);
|
|
21
|
-
return num;
|
|
22
|
-
}
|
|
23
|
-
var bufLength = 1024 * 16;
|
|
24
|
-
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
|
|
25
|
-
return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
|
|
26
|
-
} } : { decode(buf) {
|
|
27
|
-
let out = "";
|
|
28
|
-
for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
|
|
29
|
-
return out;
|
|
30
|
-
} };
|
|
31
|
-
var StringWriter = class {
|
|
32
|
-
constructor() {
|
|
33
|
-
this.pos = 0;
|
|
34
|
-
this.out = "";
|
|
35
|
-
this.buffer = new Uint8Array(bufLength);
|
|
36
|
-
}
|
|
37
|
-
write(v) {
|
|
38
|
-
const { buffer } = this;
|
|
39
|
-
buffer[this.pos++] = v;
|
|
40
|
-
if (this.pos === bufLength) {
|
|
41
|
-
this.out += td.decode(buffer);
|
|
42
|
-
this.pos = 0;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
flush() {
|
|
46
|
-
const { buffer, out, pos } = this;
|
|
47
|
-
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
function encode(decoded) {
|
|
51
|
-
const writer = new StringWriter();
|
|
52
|
-
let sourcesIndex = 0;
|
|
53
|
-
let sourceLine = 0;
|
|
54
|
-
let sourceColumn = 0;
|
|
55
|
-
let namesIndex = 0;
|
|
56
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
57
|
-
const line = decoded[i];
|
|
58
|
-
if (i > 0) writer.write(semicolon);
|
|
59
|
-
if (line.length === 0) continue;
|
|
60
|
-
let genColumn = 0;
|
|
61
|
-
for (let j = 0; j < line.length; j++) {
|
|
62
|
-
const segment = line[j];
|
|
63
|
-
if (j > 0) writer.write(comma);
|
|
64
|
-
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
65
|
-
if (segment.length === 1) continue;
|
|
66
|
-
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
67
|
-
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
68
|
-
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
69
|
-
if (segment.length === 4) continue;
|
|
70
|
-
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return writer.flush();
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
export { encode };
|
|
77
|
-
|
|
78
|
-
//# sourceMappingURL=sourcemap-codec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sourcemap-codec.js","names":[],"sources":["../../../../../../../node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs"],"sourcesContent":["// src/vlq.ts\nvar comma = \",\".charCodeAt(0);\nvar semicolon = \";\".charCodeAt(0);\nvar chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nvar intToChar = new Uint8Array(64);\nvar charToInt = new Uint8Array(128);\nfor (let i = 0; i < chars.length; i++) {\n const c = chars.charCodeAt(i);\n intToChar[i] = c;\n charToInt[c] = i;\n}\nfunction decodeInteger(reader, relative) {\n let value = 0;\n let shift = 0;\n let integer = 0;\n do {\n const c = reader.next();\n integer = charToInt[c];\n value |= (integer & 31) << shift;\n shift += 5;\n } while (integer & 32);\n const shouldNegate = value & 1;\n value >>>= 1;\n if (shouldNegate) {\n value = -2147483648 | -value;\n }\n return relative + value;\n}\nfunction encodeInteger(builder, num, relative) {\n let delta = num - relative;\n delta = delta < 0 ? -delta << 1 | 1 : delta << 1;\n do {\n let clamped = delta & 31;\n delta >>>= 5;\n if (delta > 0) clamped |= 32;\n builder.write(intToChar[clamped]);\n } while (delta > 0);\n return num;\n}\nfunction hasMoreVlq(reader, max) {\n if (reader.pos >= max) return false;\n return reader.peek() !== comma;\n}\n\n// src/strings.ts\nvar bufLength = 1024 * 16;\nvar td = typeof TextDecoder !== \"undefined\" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== \"undefined\" ? {\n decode(buf) {\n const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);\n return out.toString();\n }\n} : {\n decode(buf) {\n let out = \"\";\n for (let i = 0; i < buf.length; i++) {\n out += String.fromCharCode(buf[i]);\n }\n return out;\n }\n};\nvar StringWriter = class {\n constructor() {\n this.pos = 0;\n this.out = \"\";\n this.buffer = new Uint8Array(bufLength);\n }\n write(v) {\n const { buffer } = this;\n buffer[this.pos++] = v;\n if (this.pos === bufLength) {\n this.out += td.decode(buffer);\n this.pos = 0;\n }\n }\n flush() {\n const { buffer, out, pos } = this;\n return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;\n }\n};\nvar StringReader = class {\n constructor(buffer) {\n this.pos = 0;\n this.buffer = buffer;\n }\n next() {\n return this.buffer.charCodeAt(this.pos++);\n }\n peek() {\n return this.buffer.charCodeAt(this.pos);\n }\n indexOf(char) {\n const { buffer, pos } = this;\n const idx = buffer.indexOf(char, pos);\n return idx === -1 ? buffer.length : idx;\n }\n};\n\n// src/scopes.ts\nvar EMPTY = [];\nfunction decodeOriginalScopes(input) {\n const { length } = input;\n const reader = new StringReader(input);\n const scopes = [];\n const stack = [];\n let line = 0;\n for (; reader.pos < length; reader.pos++) {\n line = decodeInteger(reader, line);\n const column = decodeInteger(reader, 0);\n if (!hasMoreVlq(reader, length)) {\n const last = stack.pop();\n last[2] = line;\n last[3] = column;\n continue;\n }\n const kind = decodeInteger(reader, 0);\n const fields = decodeInteger(reader, 0);\n const hasName = fields & 1;\n const scope = hasName ? [line, column, 0, 0, kind, decodeInteger(reader, 0)] : [line, column, 0, 0, kind];\n let vars = EMPTY;\n if (hasMoreVlq(reader, length)) {\n vars = [];\n do {\n const varsIndex = decodeInteger(reader, 0);\n vars.push(varsIndex);\n } while (hasMoreVlq(reader, length));\n }\n scope.vars = vars;\n scopes.push(scope);\n stack.push(scope);\n }\n return scopes;\n}\nfunction encodeOriginalScopes(scopes) {\n const writer = new StringWriter();\n for (let i = 0; i < scopes.length; ) {\n i = _encodeOriginalScopes(scopes, i, writer, [0]);\n }\n return writer.flush();\n}\nfunction _encodeOriginalScopes(scopes, index, writer, state) {\n const scope = scopes[index];\n const { 0: startLine, 1: startColumn, 2: endLine, 3: endColumn, 4: kind, vars } = scope;\n if (index > 0) writer.write(comma);\n state[0] = encodeInteger(writer, startLine, state[0]);\n encodeInteger(writer, startColumn, 0);\n encodeInteger(writer, kind, 0);\n const fields = scope.length === 6 ? 1 : 0;\n encodeInteger(writer, fields, 0);\n if (scope.length === 6) encodeInteger(writer, scope[5], 0);\n for (const v of vars) {\n encodeInteger(writer, v, 0);\n }\n for (index++; index < scopes.length; ) {\n const next = scopes[index];\n const { 0: l, 1: c } = next;\n if (l > endLine || l === endLine && c >= endColumn) {\n break;\n }\n index = _encodeOriginalScopes(scopes, index, writer, state);\n }\n writer.write(comma);\n state[0] = encodeInteger(writer, endLine, state[0]);\n encodeInteger(writer, endColumn, 0);\n return index;\n}\nfunction decodeGeneratedRanges(input) {\n const { length } = input;\n const reader = new StringReader(input);\n const ranges = [];\n const stack = [];\n let genLine = 0;\n let definitionSourcesIndex = 0;\n let definitionScopeIndex = 0;\n let callsiteSourcesIndex = 0;\n let callsiteLine = 0;\n let callsiteColumn = 0;\n let bindingLine = 0;\n let bindingColumn = 0;\n do {\n const semi = reader.indexOf(\";\");\n let genColumn = 0;\n for (; reader.pos < semi; reader.pos++) {\n genColumn = decodeInteger(reader, genColumn);\n if (!hasMoreVlq(reader, semi)) {\n const last = stack.pop();\n last[2] = genLine;\n last[3] = genColumn;\n continue;\n }\n const fields = decodeInteger(reader, 0);\n const hasDefinition = fields & 1;\n const hasCallsite = fields & 2;\n const hasScope = fields & 4;\n let callsite = null;\n let bindings = EMPTY;\n let range;\n if (hasDefinition) {\n const defSourcesIndex = decodeInteger(reader, definitionSourcesIndex);\n definitionScopeIndex = decodeInteger(\n reader,\n definitionSourcesIndex === defSourcesIndex ? definitionScopeIndex : 0\n );\n definitionSourcesIndex = defSourcesIndex;\n range = [genLine, genColumn, 0, 0, defSourcesIndex, definitionScopeIndex];\n } else {\n range = [genLine, genColumn, 0, 0];\n }\n range.isScope = !!hasScope;\n if (hasCallsite) {\n const prevCsi = callsiteSourcesIndex;\n const prevLine = callsiteLine;\n callsiteSourcesIndex = decodeInteger(reader, callsiteSourcesIndex);\n const sameSource = prevCsi === callsiteSourcesIndex;\n callsiteLine = decodeInteger(reader, sameSource ? callsiteLine : 0);\n callsiteColumn = decodeInteger(\n reader,\n sameSource && prevLine === callsiteLine ? callsiteColumn : 0\n );\n callsite = [callsiteSourcesIndex, callsiteLine, callsiteColumn];\n }\n range.callsite = callsite;\n if (hasMoreVlq(reader, semi)) {\n bindings = [];\n do {\n bindingLine = genLine;\n bindingColumn = genColumn;\n const expressionsCount = decodeInteger(reader, 0);\n let expressionRanges;\n if (expressionsCount < -1) {\n expressionRanges = [[decodeInteger(reader, 0)]];\n for (let i = -1; i > expressionsCount; i--) {\n const prevBl = bindingLine;\n bindingLine = decodeInteger(reader, bindingLine);\n bindingColumn = decodeInteger(reader, bindingLine === prevBl ? bindingColumn : 0);\n const expression = decodeInteger(reader, 0);\n expressionRanges.push([expression, bindingLine, bindingColumn]);\n }\n } else {\n expressionRanges = [[expressionsCount]];\n }\n bindings.push(expressionRanges);\n } while (hasMoreVlq(reader, semi));\n }\n range.bindings = bindings;\n ranges.push(range);\n stack.push(range);\n }\n genLine++;\n reader.pos = semi + 1;\n } while (reader.pos < length);\n return ranges;\n}\nfunction encodeGeneratedRanges(ranges) {\n if (ranges.length === 0) return \"\";\n const writer = new StringWriter();\n for (let i = 0; i < ranges.length; ) {\n i = _encodeGeneratedRanges(ranges, i, writer, [0, 0, 0, 0, 0, 0, 0]);\n }\n return writer.flush();\n}\nfunction _encodeGeneratedRanges(ranges, index, writer, state) {\n const range = ranges[index];\n const {\n 0: startLine,\n 1: startColumn,\n 2: endLine,\n 3: endColumn,\n isScope,\n callsite,\n bindings\n } = range;\n if (state[0] < startLine) {\n catchupLine(writer, state[0], startLine);\n state[0] = startLine;\n state[1] = 0;\n } else if (index > 0) {\n writer.write(comma);\n }\n state[1] = encodeInteger(writer, range[1], state[1]);\n const fields = (range.length === 6 ? 1 : 0) | (callsite ? 2 : 0) | (isScope ? 4 : 0);\n encodeInteger(writer, fields, 0);\n if (range.length === 6) {\n const { 4: sourcesIndex, 5: scopesIndex } = range;\n if (sourcesIndex !== state[2]) {\n state[3] = 0;\n }\n state[2] = encodeInteger(writer, sourcesIndex, state[2]);\n state[3] = encodeInteger(writer, scopesIndex, state[3]);\n }\n if (callsite) {\n const { 0: sourcesIndex, 1: callLine, 2: callColumn } = range.callsite;\n if (sourcesIndex !== state[4]) {\n state[5] = 0;\n state[6] = 0;\n } else if (callLine !== state[5]) {\n state[6] = 0;\n }\n state[4] = encodeInteger(writer, sourcesIndex, state[4]);\n state[5] = encodeInteger(writer, callLine, state[5]);\n state[6] = encodeInteger(writer, callColumn, state[6]);\n }\n if (bindings) {\n for (const binding of bindings) {\n if (binding.length > 1) encodeInteger(writer, -binding.length, 0);\n const expression = binding[0][0];\n encodeInteger(writer, expression, 0);\n let bindingStartLine = startLine;\n let bindingStartColumn = startColumn;\n for (let i = 1; i < binding.length; i++) {\n const expRange = binding[i];\n bindingStartLine = encodeInteger(writer, expRange[1], bindingStartLine);\n bindingStartColumn = encodeInteger(writer, expRange[2], bindingStartColumn);\n encodeInteger(writer, expRange[0], 0);\n }\n }\n }\n for (index++; index < ranges.length; ) {\n const next = ranges[index];\n const { 0: l, 1: c } = next;\n if (l > endLine || l === endLine && c >= endColumn) {\n break;\n }\n index = _encodeGeneratedRanges(ranges, index, writer, state);\n }\n if (state[0] < endLine) {\n catchupLine(writer, state[0], endLine);\n state[0] = endLine;\n state[1] = 0;\n } else {\n writer.write(comma);\n }\n state[1] = encodeInteger(writer, endColumn, state[1]);\n return index;\n}\nfunction catchupLine(writer, lastLine, line) {\n do {\n writer.write(semicolon);\n } while (++lastLine < line);\n}\n\n// src/sourcemap-codec.ts\nfunction decode(mappings) {\n const { length } = mappings;\n const reader = new StringReader(mappings);\n const decoded = [];\n let genColumn = 0;\n let sourcesIndex = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let namesIndex = 0;\n do {\n const semi = reader.indexOf(\";\");\n const line = [];\n let sorted = true;\n let lastCol = 0;\n genColumn = 0;\n while (reader.pos < semi) {\n let seg;\n genColumn = decodeInteger(reader, genColumn);\n if (genColumn < lastCol) sorted = false;\n lastCol = genColumn;\n if (hasMoreVlq(reader, semi)) {\n sourcesIndex = decodeInteger(reader, sourcesIndex);\n sourceLine = decodeInteger(reader, sourceLine);\n sourceColumn = decodeInteger(reader, sourceColumn);\n if (hasMoreVlq(reader, semi)) {\n namesIndex = decodeInteger(reader, namesIndex);\n seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];\n } else {\n seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];\n }\n } else {\n seg = [genColumn];\n }\n line.push(seg);\n reader.pos++;\n }\n if (!sorted) sort(line);\n decoded.push(line);\n reader.pos = semi + 1;\n } while (reader.pos <= length);\n return decoded;\n}\nfunction sort(line) {\n line.sort(sortComparator);\n}\nfunction sortComparator(a, b) {\n return a[0] - b[0];\n}\nfunction encode(decoded) {\n const writer = new StringWriter();\n let sourcesIndex = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let namesIndex = 0;\n for (let i = 0; i < decoded.length; i++) {\n const line = decoded[i];\n if (i > 0) writer.write(semicolon);\n if (line.length === 0) continue;\n let genColumn = 0;\n for (let j = 0; j < line.length; j++) {\n const segment = line[j];\n if (j > 0) writer.write(comma);\n genColumn = encodeInteger(writer, segment[0], genColumn);\n if (segment.length === 1) continue;\n sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);\n sourceLine = encodeInteger(writer, segment[2], sourceLine);\n sourceColumn = encodeInteger(writer, segment[3], sourceColumn);\n if (segment.length === 4) continue;\n namesIndex = encodeInteger(writer, segment[4], namesIndex);\n }\n }\n return writer.flush();\n}\nexport {\n decode,\n decodeGeneratedRanges,\n decodeOriginalScopes,\n encode,\n encodeGeneratedRanges,\n encodeOriginalScopes\n};\n//# sourceMappingURL=sourcemap-codec.mjs.map\n"],"x_google_ignoreList":[0],"mappings":";AACA,IAAI,QAAQ,IAAI,WAAW,EAAE;AAC7B,IAAI,YAAY,IAAI,WAAW,EAAE;AACjC,IAAI,QAAQ;AACZ,IAAI,YAAY,IAAI,WAAW,GAAG;AAClC,IAAI,YAAY,IAAI,WAAW,IAAI;AACnC,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;CACrC,MAAM,IAAI,MAAM,WAAW,EAAE;AAC7B,WAAU,KAAK;AACf,WAAU,KAAK;;AAmBjB,SAAS,cAAc,SAAS,KAAK,UAAU;CAC7C,IAAI,QAAQ,MAAM;AAClB,SAAQ,QAAQ,IAAI,CAAC,SAAS,IAAI,IAAI,SAAS;AAC/C,IAAG;EACD,IAAI,UAAU,QAAQ;AACtB,aAAW;AACX,MAAI,QAAQ,EAAG,YAAW;AAC1B,UAAQ,MAAM,UAAU,SAAS;UAC1B,QAAQ;AACjB,QAAO;;AAQT,IAAI,YAAY,OAAO;AACvB,IAAI,KAAK,OAAO,gBAAgB,8BAA8B,IAAI,aAAa,GAAG,OAAO,WAAW,cAAc,EAChH,OAAO,KAAK;AAEV,QADY,OAAO,KAAK,IAAI,QAAQ,IAAI,YAAY,IAAI,WAAW,CACxD,UAAU;GAExB,GAAG,EACF,OAAO,KAAK;CACV,IAAI,MAAM;AACV,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,IAC9B,QAAO,OAAO,aAAa,IAAI,GAAG;AAEpC,QAAO;GAEV;AACD,IAAI,eAAe,MAAM;CACvB,cAAc;AACZ,OAAK,MAAM;AACX,OAAK,MAAM;AACX,OAAK,SAAS,IAAI,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