@t402/cosmos 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +175 -0
  2. package/dist/cjs/exact-direct/client/index.d.ts +50 -0
  3. package/dist/cjs/exact-direct/client/index.js +122 -0
  4. package/dist/cjs/exact-direct/client/index.js.map +1 -0
  5. package/dist/cjs/exact-direct/facilitator/index.d.ts +70 -0
  6. package/dist/cjs/exact-direct/facilitator/index.js +300 -0
  7. package/dist/cjs/exact-direct/facilitator/index.js.map +1 -0
  8. package/dist/cjs/exact-direct/server/index.d.ts +87 -0
  9. package/dist/cjs/exact-direct/server/index.js +241 -0
  10. package/dist/cjs/exact-direct/server/index.js.map +1 -0
  11. package/dist/cjs/index.d.ts +178 -0
  12. package/dist/cjs/index.js +619 -0
  13. package/dist/cjs/index.js.map +1 -0
  14. package/dist/cjs/types-CgseoctH.d.ts +155 -0
  15. package/dist/esm/chunk-2UTEGIZ2.mjs +101 -0
  16. package/dist/esm/chunk-2UTEGIZ2.mjs.map +1 -0
  17. package/dist/esm/chunk-57DBLYIR.mjs +58 -0
  18. package/dist/esm/chunk-57DBLYIR.mjs.map +1 -0
  19. package/dist/esm/chunk-JV6LXL2U.mjs +158 -0
  20. package/dist/esm/chunk-JV6LXL2U.mjs.map +1 -0
  21. package/dist/esm/chunk-QP5VO3IO.mjs +68 -0
  22. package/dist/esm/chunk-QP5VO3IO.mjs.map +1 -0
  23. package/dist/esm/chunk-XUMAS5DJ.mjs +223 -0
  24. package/dist/esm/chunk-XUMAS5DJ.mjs.map +1 -0
  25. package/dist/esm/exact-direct/client/index.d.mts +50 -0
  26. package/dist/esm/exact-direct/client/index.mjs +8 -0
  27. package/dist/esm/exact-direct/client/index.mjs.map +1 -0
  28. package/dist/esm/exact-direct/facilitator/index.d.mts +70 -0
  29. package/dist/esm/exact-direct/facilitator/index.mjs +9 -0
  30. package/dist/esm/exact-direct/facilitator/index.mjs.map +1 -0
  31. package/dist/esm/exact-direct/server/index.d.mts +87 -0
  32. package/dist/esm/exact-direct/server/index.mjs +9 -0
  33. package/dist/esm/exact-direct/server/index.mjs.map +1 -0
  34. package/dist/esm/index.d.mts +178 -0
  35. package/dist/esm/index.mjs +83 -0
  36. package/dist/esm/index.mjs.map +1 -0
  37. package/dist/esm/types-CgseoctH.d.mts +155 -0
  38. package/package.json +96 -0
@@ -0,0 +1,178 @@
1
+ import { T as TokenConfig } from './types-CgseoctH.mjs';
2
+ export { d as ClientCosmosSigner, C as Coin, E as ExactDirectCosmosPayload, F as FacilitatorCosmosSigner, M as MsgSend, N as NetworkConfig, a as TransactionResult, c as TxBody, b as TxWrapper } from './types-CgseoctH.mjs';
3
+ export { ExactDirectCosmosClient, ExactDirectCosmosClientConfig } from './exact-direct/client/index.mjs';
4
+ export { ExactDirectCosmosServer, ExactDirectCosmosServerConfig } from './exact-direct/server/index.mjs';
5
+ export { ExactDirectCosmosFacilitator, ExactDirectCosmosFacilitatorConfig } from './exact-direct/facilitator/index.mjs';
6
+ import '@t402/core/types';
7
+
8
+ /**
9
+ * Cosmos Network Constants
10
+ *
11
+ * This module provides constants for Cosmos blockchain integration including:
12
+ * - CAIP-2 network identifiers (Noble chain)
13
+ * - RPC and REST endpoints
14
+ * - Bech32 prefix configuration
15
+ * - USDC denomination and gas parameters
16
+ */
17
+ /**
18
+ * CAIP-2 Network Identifiers for Cosmos (Noble)
19
+ */
20
+ declare const NOBLE_MAINNET_CAIP2 = "cosmos:noble-1";
21
+ declare const NOBLE_TESTNET_CAIP2 = "cosmos:grand-1";
22
+ /**
23
+ * Supported Cosmos networks
24
+ */
25
+ declare const COSMOS_NETWORKS: readonly ["cosmos:noble-1", "cosmos:grand-1"];
26
+ type CosmosNetwork = (typeof COSMOS_NETWORKS)[number];
27
+ /**
28
+ * Default RPC endpoints
29
+ */
30
+ declare const NOBLE_MAINNET_RPC = "https://noble-rpc.polkachu.com";
31
+ declare const NOBLE_TESTNET_RPC = "https://rpc.testnet.noble.strange.love";
32
+ /**
33
+ * Default REST endpoints
34
+ */
35
+ declare const NOBLE_MAINNET_REST = "https://noble-api.polkachu.com";
36
+ declare const NOBLE_TESTNET_REST = "https://api.testnet.noble.strange.love";
37
+ /**
38
+ * Network RPC endpoint mapping
39
+ */
40
+ declare const NETWORK_RPC_ENDPOINTS: Record<string, string>;
41
+ /**
42
+ * Network REST endpoint mapping
43
+ */
44
+ declare const NETWORK_REST_ENDPOINTS: Record<string, string>;
45
+ /**
46
+ * Bech32 prefix for Noble addresses
47
+ */
48
+ declare const NOBLE_BECH32_PREFIX = "noble";
49
+ /**
50
+ * USDC denomination on Noble
51
+ * uusdc = micro-USDC (1 USDC = 1,000,000 uusdc)
52
+ */
53
+ declare const USDC_DENOM = "uusdc";
54
+ /**
55
+ * Default gas parameters
56
+ */
57
+ declare const DEFAULT_GAS_LIMIT = 200000;
58
+ declare const DEFAULT_GAS_PRICE = "0.025uusdc";
59
+ declare const DEFAULT_FEE_AMOUNT = "5000";
60
+ /**
61
+ * Cosmos message type for bank send
62
+ */
63
+ declare const MSG_TYPE_SEND = "/cosmos.bank.v1beta1.MsgSend";
64
+ /**
65
+ * Scheme identifier for exact-direct payments
66
+ */
67
+ declare const SCHEME_EXACT_DIRECT = "exact-direct";
68
+ /**
69
+ * Maximum transaction age to accept (in milliseconds)
70
+ */
71
+ declare const MAX_TRANSACTION_AGE: number;
72
+ /**
73
+ * CAIP-2 namespace for Cosmos
74
+ */
75
+ declare const COSMOS_CAIP2_NAMESPACE = "cosmos";
76
+
77
+ /**
78
+ * Cosmos Token Registry
79
+ *
80
+ * Defines supported tokens for each Cosmos network (currently Noble USDC).
81
+ */
82
+
83
+ /**
84
+ * Token registry by network
85
+ */
86
+ declare const TOKEN_REGISTRY: Record<string, TokenConfig[]>;
87
+ /**
88
+ * Get token configuration by symbol
89
+ * @param network - CAIP-2 network identifier
90
+ * @param symbol - Token symbol (e.g., "USDC")
91
+ * @returns Token configuration or undefined
92
+ */
93
+ declare function getTokenConfig(network: string, symbol: string): TokenConfig | undefined;
94
+ /**
95
+ * Get token configuration by denomination
96
+ * @param network - CAIP-2 network identifier
97
+ * @param denom - Token denomination (e.g., "uusdc")
98
+ * @returns Token configuration or undefined
99
+ */
100
+ declare function getTokenByDenom(network: string, denom: string): TokenConfig | undefined;
101
+ /**
102
+ * Get the default token for a network
103
+ * Returns the token with highest priority (lowest priority number)
104
+ * @param network - CAIP-2 network identifier
105
+ * @returns Default token configuration or undefined
106
+ */
107
+ declare function getDefaultToken(network: string): TokenConfig | undefined;
108
+ /**
109
+ * Get all tokens for a network
110
+ * @param network - CAIP-2 network identifier
111
+ * @returns Array of token configurations
112
+ */
113
+ declare function getNetworkTokens(network: string): TokenConfig[];
114
+ /**
115
+ * Check if a network is supported
116
+ * @param network - CAIP-2 network identifier
117
+ */
118
+ declare function isNetworkSupported(network: string): boolean;
119
+
120
+ /**
121
+ * Cosmos Utility Functions
122
+ *
123
+ * Helper functions for Cosmos address validation, network normalization,
124
+ * and amount conversion.
125
+ */
126
+
127
+ /**
128
+ * Normalize a network identifier to CAIP-2 format
129
+ * @param network - Network identifier (e.g., "noble-1", "cosmos:noble-1")
130
+ * @returns CAIP-2 formatted network identifier
131
+ */
132
+ declare function normalizeNetwork(network: string): CosmosNetwork;
133
+ /**
134
+ * Extract network ID from CAIP-2 identifier
135
+ * @param network - CAIP-2 network identifier
136
+ * @returns Network ID (e.g., "noble-1")
137
+ */
138
+ declare function extractNetworkId(network: string): string;
139
+ /**
140
+ * Validate a Cosmos bech32 address with Noble prefix
141
+ * Checks that the address starts with the "noble" prefix followed by "1"
142
+ * @param address - Address to validate
143
+ * @returns Whether the address is valid
144
+ */
145
+ declare function isValidAddress(address: string): boolean;
146
+ /**
147
+ * Get RPC endpoint for a network
148
+ * @param network - CAIP-2 network identifier
149
+ * @returns RPC endpoint URL
150
+ */
151
+ declare function getRpcEndpoint(network: string): string;
152
+ /**
153
+ * Get REST endpoint for a network
154
+ * @param network - CAIP-2 network identifier
155
+ * @returns REST endpoint URL
156
+ */
157
+ declare function getRestEndpoint(network: string): string;
158
+ /**
159
+ * Convert decimal amount to token units (atomic units)
160
+ * @param decimalAmount - Amount with decimals (e.g., "1.50")
161
+ * @param decimals - Token decimals
162
+ * @returns Amount in smallest units
163
+ */
164
+ declare function toAtomicUnits(decimalAmount: string | number, decimals: number): bigint;
165
+ /**
166
+ * Format amount for display (with decimals)
167
+ * @param amount - Amount in smallest units
168
+ * @param decimals - Number of decimal places
169
+ * @returns Formatted amount string
170
+ */
171
+ declare function formatAmount(amount: bigint, decimals: number): string;
172
+ /**
173
+ * Get the list of supported networks
174
+ * @returns Array of CAIP-2 network identifiers
175
+ */
176
+ declare function getSupportedNetworks(): string[];
177
+
178
+ export { COSMOS_CAIP2_NAMESPACE, COSMOS_NETWORKS, type CosmosNetwork, DEFAULT_FEE_AMOUNT, DEFAULT_GAS_LIMIT, DEFAULT_GAS_PRICE, MAX_TRANSACTION_AGE, MSG_TYPE_SEND, NETWORK_REST_ENDPOINTS, NETWORK_RPC_ENDPOINTS, NOBLE_BECH32_PREFIX, NOBLE_MAINNET_CAIP2, NOBLE_MAINNET_REST, NOBLE_MAINNET_RPC, NOBLE_TESTNET_CAIP2, NOBLE_TESTNET_REST, NOBLE_TESTNET_RPC, SCHEME_EXACT_DIRECT, TOKEN_REGISTRY, TokenConfig, USDC_DENOM, extractNetworkId, formatAmount, getDefaultToken, getNetworkTokens, getRestEndpoint, getRpcEndpoint, getSupportedNetworks, getTokenByDenom, getTokenConfig, isNetworkSupported, isValidAddress, normalizeNetwork, toAtomicUnits };
@@ -0,0 +1,83 @@
1
+ import {
2
+ ExactDirectCosmosClient
3
+ } from "./chunk-QP5VO3IO.mjs";
4
+ import {
5
+ ExactDirectCosmosServer
6
+ } from "./chunk-JV6LXL2U.mjs";
7
+ import {
8
+ ExactDirectCosmosFacilitator
9
+ } from "./chunk-XUMAS5DJ.mjs";
10
+ import {
11
+ TOKEN_REGISTRY,
12
+ getDefaultToken,
13
+ getNetworkTokens,
14
+ getTokenByDenom,
15
+ getTokenConfig,
16
+ isNetworkSupported
17
+ } from "./chunk-57DBLYIR.mjs";
18
+ import {
19
+ COSMOS_CAIP2_NAMESPACE,
20
+ COSMOS_NETWORKS,
21
+ DEFAULT_FEE_AMOUNT,
22
+ DEFAULT_GAS_LIMIT,
23
+ DEFAULT_GAS_PRICE,
24
+ MAX_TRANSACTION_AGE,
25
+ MSG_TYPE_SEND,
26
+ NETWORK_REST_ENDPOINTS,
27
+ NETWORK_RPC_ENDPOINTS,
28
+ NOBLE_BECH32_PREFIX,
29
+ NOBLE_MAINNET_CAIP2,
30
+ NOBLE_MAINNET_REST,
31
+ NOBLE_MAINNET_RPC,
32
+ NOBLE_TESTNET_CAIP2,
33
+ NOBLE_TESTNET_REST,
34
+ NOBLE_TESTNET_RPC,
35
+ SCHEME_EXACT_DIRECT,
36
+ USDC_DENOM,
37
+ extractNetworkId,
38
+ formatAmount,
39
+ getRestEndpoint,
40
+ getRpcEndpoint,
41
+ getSupportedNetworks,
42
+ isValidAddress,
43
+ normalizeNetwork,
44
+ toAtomicUnits
45
+ } from "./chunk-2UTEGIZ2.mjs";
46
+ export {
47
+ COSMOS_CAIP2_NAMESPACE,
48
+ COSMOS_NETWORKS,
49
+ DEFAULT_FEE_AMOUNT,
50
+ DEFAULT_GAS_LIMIT,
51
+ DEFAULT_GAS_PRICE,
52
+ ExactDirectCosmosClient,
53
+ ExactDirectCosmosFacilitator,
54
+ ExactDirectCosmosServer,
55
+ MAX_TRANSACTION_AGE,
56
+ MSG_TYPE_SEND,
57
+ NETWORK_REST_ENDPOINTS,
58
+ NETWORK_RPC_ENDPOINTS,
59
+ NOBLE_BECH32_PREFIX,
60
+ NOBLE_MAINNET_CAIP2,
61
+ NOBLE_MAINNET_REST,
62
+ NOBLE_MAINNET_RPC,
63
+ NOBLE_TESTNET_CAIP2,
64
+ NOBLE_TESTNET_REST,
65
+ NOBLE_TESTNET_RPC,
66
+ SCHEME_EXACT_DIRECT,
67
+ TOKEN_REGISTRY,
68
+ USDC_DENOM,
69
+ extractNetworkId,
70
+ formatAmount,
71
+ getDefaultToken,
72
+ getNetworkTokens,
73
+ getRestEndpoint,
74
+ getRpcEndpoint,
75
+ getSupportedNetworks,
76
+ getTokenByDenom,
77
+ getTokenConfig,
78
+ isNetworkSupported,
79
+ isValidAddress,
80
+ normalizeNetwork,
81
+ toAtomicUnits
82
+ };
83
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Cosmos Payment Types
3
+ *
4
+ * Defines the payload structure for Cosmos (Noble USDC) payments using the exact-direct scheme.
5
+ * The exact-direct scheme has the client execute the transfer directly, then provide
6
+ * the transaction hash as proof of payment.
7
+ */
8
+ /**
9
+ * Cosmos payment payload for the exact-direct scheme
10
+ * Contains transaction hash and metadata for verification
11
+ */
12
+ type ExactDirectCosmosPayload = {
13
+ /**
14
+ * Transaction hash of the completed MsgSend
15
+ */
16
+ txHash: string;
17
+ /**
18
+ * Sender bech32 address (e.g., "noble1...")
19
+ */
20
+ from: string;
21
+ /**
22
+ * Recipient bech32 address (e.g., "noble1...")
23
+ */
24
+ to: string;
25
+ /**
26
+ * Transfer amount in smallest units (e.g., "1000000" for 1 USDC)
27
+ */
28
+ amount: string;
29
+ /**
30
+ * Token denomination (e.g., "uusdc")
31
+ */
32
+ denom?: string;
33
+ };
34
+ /**
35
+ * Token configuration
36
+ */
37
+ interface TokenConfig {
38
+ /** Token denomination */
39
+ denom: string;
40
+ /** Token symbol */
41
+ symbol: string;
42
+ /** Token name */
43
+ name: string;
44
+ /** Decimal places */
45
+ decimals: number;
46
+ /** Priority for selection (lower = higher priority) */
47
+ priority: number;
48
+ }
49
+ /**
50
+ * Network configuration
51
+ */
52
+ interface NetworkConfig {
53
+ /** CAIP-2 network identifier */
54
+ network: string;
55
+ /** Bech32 address prefix */
56
+ bech32Prefix: string;
57
+ /** RPC endpoint */
58
+ rpcEndpoint: string;
59
+ /** REST endpoint */
60
+ restEndpoint: string;
61
+ }
62
+ /**
63
+ * Cosmos transaction result
64
+ */
65
+ interface TransactionResult {
66
+ /** Transaction hash */
67
+ txHash: string;
68
+ /** Block height */
69
+ height: string;
70
+ /** Result code (0 = success) */
71
+ code: number;
72
+ /** Raw log */
73
+ rawLog: string;
74
+ /** Gas wanted */
75
+ gasWanted: string;
76
+ /** Gas used */
77
+ gasUsed: string;
78
+ /** Transaction timestamp */
79
+ timestamp: string;
80
+ /** Transaction body */
81
+ tx: TxWrapper;
82
+ }
83
+ /**
84
+ * Transaction wrapper
85
+ */
86
+ interface TxWrapper {
87
+ body: TxBody;
88
+ }
89
+ /**
90
+ * Transaction body
91
+ */
92
+ interface TxBody {
93
+ messages: MsgSend[];
94
+ memo: string;
95
+ }
96
+ /**
97
+ * Cosmos MsgSend
98
+ */
99
+ interface MsgSend {
100
+ "@type"?: string;
101
+ fromAddress: string;
102
+ toAddress: string;
103
+ amount: Coin[];
104
+ }
105
+ /**
106
+ * Cosmos Coin
107
+ */
108
+ interface Coin {
109
+ denom: string;
110
+ amount: string;
111
+ }
112
+ /**
113
+ * Cosmos signer interface for client operations
114
+ */
115
+ interface ClientCosmosSigner {
116
+ /**
117
+ * Get the bech32 address
118
+ */
119
+ readonly address: string;
120
+ /**
121
+ * Send tokens to a recipient
122
+ * @param network - CAIP-2 network identifier
123
+ * @param to - Recipient bech32 address
124
+ * @param amount - Amount in smallest units
125
+ * @param denom - Token denomination
126
+ * @returns Transaction hash
127
+ */
128
+ sendTokens(network: string, to: string, amount: string, denom: string): Promise<string>;
129
+ }
130
+ /**
131
+ * Cosmos signer interface for facilitator operations
132
+ */
133
+ interface FacilitatorCosmosSigner {
134
+ /**
135
+ * Get the facilitator's addresses for a network
136
+ * @param network - CAIP-2 network identifier
137
+ */
138
+ getAddresses(network: string): string[];
139
+ /**
140
+ * Query a transaction by hash
141
+ * @param network - CAIP-2 network identifier
142
+ * @param txHash - Transaction hash
143
+ * @returns Transaction result
144
+ */
145
+ queryTransaction(network: string, txHash: string): Promise<TransactionResult>;
146
+ /**
147
+ * Get token balance for an address
148
+ * @param network - CAIP-2 network identifier
149
+ * @param address - Bech32 address
150
+ * @param denom - Token denomination
151
+ */
152
+ getBalance(network: string, address: string, denom: string): Promise<bigint>;
153
+ }
154
+
155
+ export type { Coin as C, ExactDirectCosmosPayload as E, FacilitatorCosmosSigner as F, MsgSend as M, NetworkConfig as N, TokenConfig as T, TransactionResult as a, TxWrapper as b, TxBody as c, ClientCosmosSigner as d };
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@t402/cosmos",
3
+ "version": "2.4.0",
4
+ "main": "./dist/cjs/index.js",
5
+ "module": "./dist/esm/index.js",
6
+ "types": "./dist/cjs/index.d.ts",
7
+ "keywords": [
8
+ "t402",
9
+ "payment",
10
+ "protocol",
11
+ "cosmos",
12
+ "noble",
13
+ "usdc"
14
+ ],
15
+ "license": "Apache-2.0",
16
+ "author": "T402 Team",
17
+ "repository": "https://github.com/t402-io/t402",
18
+ "description": "t402 Payment Protocol Cosmos (Noble USDC) Implementation",
19
+ "devDependencies": {
20
+ "@eslint/js": "^9.24.0",
21
+ "@types/node": "^25.2.0",
22
+ "@typescript-eslint/eslint-plugin": "^8.29.1",
23
+ "@typescript-eslint/parser": "^8.29.1",
24
+ "eslint": "^9.24.0",
25
+ "eslint-plugin-import": "^2.31.0",
26
+ "eslint-plugin-jsdoc": "^62.5.0",
27
+ "eslint-plugin-prettier": "^5.2.6",
28
+ "glob": "^13.0.0",
29
+ "prettier": "3.5.2",
30
+ "tsup": "^8.4.0",
31
+ "tsx": "^4.21.0",
32
+ "typescript": "^5.7.3",
33
+ "vite": "^7.3.1",
34
+ "vite-tsconfig-paths": "^5.1.4",
35
+ "vitest": "^3.2.4"
36
+ },
37
+ "dependencies": {
38
+ "@t402/core": "2.4.0"
39
+ },
40
+ "exports": {
41
+ ".": {
42
+ "import": {
43
+ "types": "./dist/esm/index.d.mts",
44
+ "default": "./dist/esm/index.mjs"
45
+ },
46
+ "require": {
47
+ "types": "./dist/cjs/index.d.ts",
48
+ "default": "./dist/cjs/index.js"
49
+ }
50
+ },
51
+ "./exact-direct/client": {
52
+ "import": {
53
+ "types": "./dist/esm/exact-direct/client/index.d.mts",
54
+ "default": "./dist/esm/exact-direct/client/index.mjs"
55
+ },
56
+ "require": {
57
+ "types": "./dist/cjs/exact-direct/client/index.d.ts",
58
+ "default": "./dist/cjs/exact-direct/client/index.js"
59
+ }
60
+ },
61
+ "./exact-direct/server": {
62
+ "import": {
63
+ "types": "./dist/esm/exact-direct/server/index.d.mts",
64
+ "default": "./dist/esm/exact-direct/server/index.mjs"
65
+ },
66
+ "require": {
67
+ "types": "./dist/cjs/exact-direct/server/index.d.ts",
68
+ "default": "./dist/cjs/exact-direct/server/index.js"
69
+ }
70
+ },
71
+ "./exact-direct/facilitator": {
72
+ "import": {
73
+ "types": "./dist/esm/exact-direct/facilitator/index.d.mts",
74
+ "default": "./dist/esm/exact-direct/facilitator/index.mjs"
75
+ },
76
+ "require": {
77
+ "types": "./dist/cjs/exact-direct/facilitator/index.d.ts",
78
+ "default": "./dist/cjs/exact-direct/facilitator/index.js"
79
+ }
80
+ }
81
+ },
82
+ "files": [
83
+ "dist"
84
+ ],
85
+ "scripts": {
86
+ "start": "tsx --env-file=.env index.ts",
87
+ "build": "tsup",
88
+ "test": "vitest run",
89
+ "test:watch": "vitest",
90
+ "watch": "tsc --watch",
91
+ "format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
92
+ "format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
93
+ "lint": "eslint . --ext .ts --fix",
94
+ "lint:check": "eslint . --ext .ts"
95
+ }
96
+ }