blue-js-sdk 2.0.1 → 2.0.3
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/ai-path/index.js +13 -4
- package/chain/client.js +54 -6
- package/cosmjs-setup.js +52 -7
- package/package.json +1 -1
package/ai-path/index.js
CHANGED
|
@@ -58,8 +58,17 @@ export {
|
|
|
58
58
|
rpcQueryBalance,
|
|
59
59
|
rpcQueryNode,
|
|
60
60
|
// v1.5.2: Session recovery (referenced in docs but was missing from exports)
|
|
61
|
-
recoverOrphans,
|
|
61
|
+
recoverOrphans as recoverSession,
|
|
62
|
+
// v2.0.2: Plan operations for AI agents using subscription-based access
|
|
63
|
+
connectViaSubscription,
|
|
64
|
+
connectViaPlan,
|
|
65
|
+
subscribeToPlan,
|
|
66
|
+
hasActiveSubscription,
|
|
67
|
+
querySubscriptions,
|
|
68
|
+
queryPlanNodes,
|
|
69
|
+
queryFeeGrants,
|
|
70
|
+
buildFeeGrantMsg,
|
|
71
|
+
broadcastWithFeeGrant,
|
|
72
|
+
rpcQueryNodesForPlan,
|
|
73
|
+
rpcQuerySubscriptionsForAccount,
|
|
62
74
|
} from '../index.js';
|
|
63
|
-
|
|
64
|
-
// Re-export recoverOrphans as recoverSession (the name used in ai-path docs)
|
|
65
|
-
export { recoverOrphans as recoverSession };
|
package/chain/client.js
CHANGED
|
@@ -43,7 +43,8 @@ import {
|
|
|
43
43
|
encodeMsgEndLease,
|
|
44
44
|
} from '../plan-operations.js';
|
|
45
45
|
|
|
46
|
-
import { GAS_PRICE } from '../defaults.js';
|
|
46
|
+
import { GAS_PRICE, RPC_ENDPOINTS } from '../defaults.js';
|
|
47
|
+
import { ValidationError, ChainError, ErrorCodes } from '../errors.js';
|
|
47
48
|
|
|
48
49
|
// ─── CosmJS Registry ─────────────────────────────────────────────────────────
|
|
49
50
|
|
|
@@ -107,12 +108,59 @@ export function buildRegistry() {
|
|
|
107
108
|
/**
|
|
108
109
|
* Create a SigningStargateClient connected to Sentinel RPC.
|
|
109
110
|
* Gas price: from defaults.js GAS_PRICE (chain minimum).
|
|
111
|
+
*
|
|
112
|
+
* Signatures:
|
|
113
|
+
* createClient(rpcUrl, wallet) — classic: connect to specific RPC with existing wallet
|
|
114
|
+
* createClient(mnemonic) — convenience: create wallet from mnemonic, try RPC endpoints with failover
|
|
115
|
+
*
|
|
116
|
+
* @param {string} rpcUrlOrMnemonic - Either an RPC URL (https://...) or a BIP39 mnemonic
|
|
117
|
+
* @param {DirectSecp256k1HdWallet} [wallet] - Wallet object (required when first arg is RPC URL)
|
|
118
|
+
* @returns {Promise<SigningStargateClient>} Connected signing client with full Sentinel registry
|
|
110
119
|
*/
|
|
111
|
-
export async function createClient(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
export async function createClient(rpcUrlOrMnemonic, wallet) {
|
|
121
|
+
// Classic call: createClient(rpcUrl, wallet)
|
|
122
|
+
if (wallet) {
|
|
123
|
+
return SigningStargateClient.connectWithSigner(rpcUrlOrMnemonic, wallet, {
|
|
124
|
+
gasPrice: GasPrice.fromString(GAS_PRICE),
|
|
125
|
+
registry: buildRegistry(),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// If first arg looks like a URL, it's a missing wallet — throw helpful error
|
|
130
|
+
if (typeof rpcUrlOrMnemonic === 'string' && /^(https?|wss?):\/\//i.test(rpcUrlOrMnemonic)) {
|
|
131
|
+
throw new ValidationError(ErrorCodes.INVALID_MNEMONIC,
|
|
132
|
+
'createClient(rpcUrl, wallet): wallet parameter is required when passing an RPC URL. ' +
|
|
133
|
+
'Use createClient(mnemonic) for convenience, or createClient(rpcUrl, wallet) with an existing wallet.',
|
|
134
|
+
{ value: rpcUrlOrMnemonic });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Convenience call: createClient(mnemonic) — create wallet + try RPC endpoints
|
|
138
|
+
// Lazy import to avoid circular dependency
|
|
139
|
+
const { createWallet, validateMnemonic } = await import('./wallet.js');
|
|
140
|
+
validateMnemonic(rpcUrlOrMnemonic, 'createClient');
|
|
141
|
+
const { wallet: derivedWallet } = await createWallet(rpcUrlOrMnemonic);
|
|
142
|
+
const registry = buildRegistry();
|
|
143
|
+
const gasPrice = GasPrice.fromString(GAS_PRICE);
|
|
144
|
+
|
|
145
|
+
// Try each RPC endpoint until one connects
|
|
146
|
+
const errors = [];
|
|
147
|
+
for (const ep of RPC_ENDPOINTS) {
|
|
148
|
+
try {
|
|
149
|
+
const client = await SigningStargateClient.connectWithSigner(ep.url, derivedWallet, {
|
|
150
|
+
gasPrice,
|
|
151
|
+
registry,
|
|
152
|
+
});
|
|
153
|
+
return client;
|
|
154
|
+
} catch (err) {
|
|
155
|
+
errors.push({ endpoint: ep.url, name: ep.name, error: err.message });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// All endpoints failed
|
|
160
|
+
const tried = errors.map(e => ` ${e.name} (${e.endpoint}): ${e.error}`).join('\n');
|
|
161
|
+
throw new ChainError('ALL_ENDPOINTS_FAILED',
|
|
162
|
+
`createClient(mnemonic): failed to connect to all ${RPC_ENDPOINTS.length} RPC endpoints:\n${tried}`,
|
|
163
|
+
{ endpoints: errors });
|
|
116
164
|
}
|
|
117
165
|
|
|
118
166
|
// ─── All Type URL Constants ──────────────────────────────────────────────────
|
package/cosmjs-setup.js
CHANGED
|
@@ -50,7 +50,7 @@ import {
|
|
|
50
50
|
encodeMsgStartLease,
|
|
51
51
|
encodeMsgEndLease,
|
|
52
52
|
} from './plan-operations.js';
|
|
53
|
-
import { GAS_PRICE, LCD_ENDPOINTS, tryWithFallback } from './defaults.js';
|
|
53
|
+
import { GAS_PRICE, RPC_ENDPOINTS, LCD_ENDPOINTS, tryWithFallback } from './defaults.js';
|
|
54
54
|
import { ValidationError, NodeError, ChainError, ErrorCodes } from './errors.js';
|
|
55
55
|
import path from 'path';
|
|
56
56
|
import os from 'os';
|
|
@@ -216,12 +216,57 @@ export function buildRegistry() {
|
|
|
216
216
|
/**
|
|
217
217
|
* Create a SigningStargateClient connected to Sentinel RPC.
|
|
218
218
|
* Gas price: from defaults.js GAS_PRICE (chain minimum).
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
*
|
|
220
|
+
* Signatures:
|
|
221
|
+
* createClient(rpcUrl, wallet) — classic: connect to specific RPC with existing wallet
|
|
222
|
+
* createClient(mnemonic) — convenience: create wallet from mnemonic, try RPC endpoints with failover
|
|
223
|
+
*
|
|
224
|
+
* @param {string} rpcUrlOrMnemonic - Either an RPC URL (https://...) or a BIP39 mnemonic
|
|
225
|
+
* @param {DirectSecp256k1HdWallet} [wallet] - Wallet object (required when first arg is RPC URL)
|
|
226
|
+
* @returns {Promise<SigningStargateClient>} Connected signing client with full Sentinel registry
|
|
227
|
+
*/
|
|
228
|
+
export async function createClient(rpcUrlOrMnemonic, wallet) {
|
|
229
|
+
// Classic call: createClient(rpcUrl, wallet)
|
|
230
|
+
if (wallet) {
|
|
231
|
+
return SigningStargateClient.connectWithSigner(rpcUrlOrMnemonic, wallet, {
|
|
232
|
+
gasPrice: GasPrice.fromString(GAS_PRICE),
|
|
233
|
+
registry: buildRegistry(),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// If first arg looks like a URL, it's a missing wallet — throw helpful error
|
|
238
|
+
if (typeof rpcUrlOrMnemonic === 'string' && /^(https?|wss?):\/\//i.test(rpcUrlOrMnemonic)) {
|
|
239
|
+
throw new ValidationError(ErrorCodes.INVALID_MNEMONIC,
|
|
240
|
+
'createClient(rpcUrl, wallet): wallet parameter is required when passing an RPC URL. ' +
|
|
241
|
+
'Use createClient(mnemonic) for convenience, or createClient(rpcUrl, wallet) with an existing wallet.',
|
|
242
|
+
{ value: rpcUrlOrMnemonic });
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Convenience call: createClient(mnemonic) — create wallet + try RPC endpoints
|
|
246
|
+
validateMnemonic(rpcUrlOrMnemonic, 'createClient');
|
|
247
|
+
const { wallet: derivedWallet } = await createWallet(rpcUrlOrMnemonic);
|
|
248
|
+
const registry = buildRegistry();
|
|
249
|
+
const gasPrice = GasPrice.fromString(GAS_PRICE);
|
|
250
|
+
|
|
251
|
+
// Try each RPC endpoint until one connects
|
|
252
|
+
const errors = [];
|
|
253
|
+
for (const ep of RPC_ENDPOINTS) {
|
|
254
|
+
try {
|
|
255
|
+
const client = await SigningStargateClient.connectWithSigner(ep.url, derivedWallet, {
|
|
256
|
+
gasPrice,
|
|
257
|
+
registry,
|
|
258
|
+
});
|
|
259
|
+
return client;
|
|
260
|
+
} catch (err) {
|
|
261
|
+
errors.push({ endpoint: ep.url, name: ep.name, error: err.message });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// All endpoints failed
|
|
266
|
+
const tried = errors.map(e => ` ${e.name} (${e.endpoint}): ${e.error}`).join('\n');
|
|
267
|
+
throw new ChainError('ALL_ENDPOINTS_FAILED',
|
|
268
|
+
`createClient(mnemonic): failed to connect to all ${RPC_ENDPOINTS.length} RPC endpoints:\n${tried}`,
|
|
269
|
+
{ endpoints: errors });
|
|
225
270
|
}
|
|
226
271
|
|
|
227
272
|
// ─── TX Helpers ──────────────────────────────────────────────────────────────
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blue-js-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Decentralized VPN SDK for the Sentinel P2P bandwidth network. WireGuard + V2Ray tunnels, Cosmos blockchain, 900+ nodes. Tested on Windows. macOS/Linux support included but untested.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|