blue-js-sdk 2.0.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/CHANGELOG.md +446 -0
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/ai-path/ADMIN-ELEVATION.md +116 -0
- package/ai-path/AI-MANIFESTO.md +185 -0
- package/ai-path/BREAKING.md +74 -0
- package/ai-path/CHECKLIST.md +619 -0
- package/ai-path/CONNECTION-STEPS.md +724 -0
- package/ai-path/DECISION-TREE.md +378 -0
- package/ai-path/DEPENDENCIES.md +459 -0
- package/ai-path/E2E-FLOW.md +1555 -0
- package/ai-path/FAILURES.md +403 -0
- package/ai-path/GUIDE.md +1217 -0
- package/ai-path/README.md +558 -0
- package/ai-path/SPLIT-TUNNEL.md +266 -0
- package/ai-path/cli.js +535 -0
- package/ai-path/connect.js +884 -0
- package/ai-path/discover.js +178 -0
- package/ai-path/environment.js +266 -0
- package/ai-path/errors.js +86 -0
- package/ai-path/examples/autonomous-agent.mjs +220 -0
- package/ai-path/examples/multi-region.mjs +174 -0
- package/ai-path/examples/one-shot.mjs +31 -0
- package/ai-path/index.js +60 -0
- package/ai-path/pricing.js +136 -0
- package/ai-path/recommend.js +413 -0
- package/ai-path/run-admin.vbs +25 -0
- package/ai-path/setup.js +291 -0
- package/ai-path/wallet.js +137 -0
- package/app-helpers.js +363 -0
- package/app-settings.js +95 -0
- package/app-types.js +267 -0
- package/audit.js +847 -0
- package/batch.js +293 -0
- package/bin/setup.js +376 -0
- package/chain/authz.js +109 -0
- package/chain/broadcast.js +472 -0
- package/chain/client.js +160 -0
- package/chain/fee-grants.js +305 -0
- package/chain/index.js +891 -0
- package/chain/lcd.js +313 -0
- package/chain/queries.js +547 -0
- package/chain/rpc.js +408 -0
- package/chain/wallet.js +141 -0
- package/cli/config.js +143 -0
- package/cli/index.js +463 -0
- package/cli/output.js +182 -0
- package/cli.js +491 -0
- package/client/index.js +251 -0
- package/client.js +271 -0
- package/config/index.js +255 -0
- package/connection/connect.js +849 -0
- package/connection/disconnect.js +180 -0
- package/connection/discovery.js +321 -0
- package/connection/index.js +76 -0
- package/connection/proxy.js +148 -0
- package/connection/resilience.js +428 -0
- package/connection/security.js +232 -0
- package/connection/state.js +369 -0
- package/connection/tunnel.js +691 -0
- package/consumer.js +132 -0
- package/cosmjs-setup.js +1884 -0
- package/defaults.js +366 -0
- package/disk-cache.js +107 -0
- package/dist/client.d.ts +108 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +400 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/errors/index.js +112 -0
- package/errors.js +218 -0
- package/examples/README.md +64 -0
- package/examples/connect-direct.mjs +106 -0
- package/examples/connect-plan.mjs +125 -0
- package/examples/error-handling.mjs +109 -0
- package/examples/query-nodes.mjs +94 -0
- package/examples/wallet-basics.mjs +61 -0
- package/generated/amino/amino.ts +9 -0
- package/generated/cosmos/base/v1beta1/coin.ts +365 -0
- package/generated/cosmos_proto/cosmos.ts +323 -0
- package/generated/gogoproto/gogo.ts +9 -0
- package/generated/google/protobuf/descriptor.ts +7601 -0
- package/generated/google/protobuf/duration.ts +208 -0
- package/generated/google/protobuf/timestamp.ts +238 -0
- package/generated/sentinel/lease/v1/events.ts +924 -0
- package/generated/sentinel/lease/v1/lease.ts +292 -0
- package/generated/sentinel/lease/v1/msg.ts +949 -0
- package/generated/sentinel/lease/v1/params.ts +164 -0
- package/generated/sentinel/node/v3/events.ts +881 -0
- package/generated/sentinel/node/v3/msg.ts +1002 -0
- package/generated/sentinel/node/v3/node.ts +263 -0
- package/generated/sentinel/node/v3/params.ts +183 -0
- package/generated/sentinel/plan/v3/events.ts +675 -0
- package/generated/sentinel/plan/v3/msg.ts +1191 -0
- package/generated/sentinel/plan/v3/plan.ts +283 -0
- package/generated/sentinel/provider/v2/events.ts +171 -0
- package/generated/sentinel/provider/v2/msg.ts +480 -0
- package/generated/sentinel/provider/v2/params.ts +131 -0
- package/generated/sentinel/provider/v2/provider.ts +246 -0
- package/generated/sentinel/session/v3/events.ts +480 -0
- package/generated/sentinel/session/v3/msg.ts +616 -0
- package/generated/sentinel/session/v3/params.ts +260 -0
- package/generated/sentinel/session/v3/proof.ts +180 -0
- package/generated/sentinel/session/v3/session.ts +384 -0
- package/generated/sentinel/subscription/v3/events.ts +1181 -0
- package/generated/sentinel/subscription/v3/msg.ts +1305 -0
- package/generated/sentinel/subscription/v3/params.ts +167 -0
- package/generated/sentinel/subscription/v3/subscription.ts +315 -0
- package/generated/sentinel/types/v1/bandwidth.ts +124 -0
- package/generated/sentinel/types/v1/price.ts +149 -0
- package/generated/sentinel/types/v1/renewal.ts +87 -0
- package/generated/sentinel/types/v1/status.ts +54 -0
- package/generated/typeRegistry.ts +27 -0
- package/index.js +486 -0
- package/node-connect.js +3015 -0
- package/operator.js +134 -0
- package/package.json +113 -0
- package/plan-operations.js +199 -0
- package/preflight.js +352 -0
- package/pricing/index.js +262 -0
- package/proto/amino/amino.proto +84 -0
- package/proto/cosmos/base/v1beta1/coin.proto +61 -0
- package/proto/cosmos_proto/cosmos.proto +112 -0
- package/proto/gogoproto/gogo.proto +145 -0
- package/proto/google/api/annotations.proto +31 -0
- package/proto/google/api/http.proto +370 -0
- package/proto/google/protobuf/any.proto +106 -0
- package/proto/google/protobuf/duration.proto +115 -0
- package/proto/google/protobuf/timestamp.proto +145 -0
- package/proto/sentinel/lease/v1/events.proto +52 -0
- package/proto/sentinel/lease/v1/genesis.proto +15 -0
- package/proto/sentinel/lease/v1/lease.proto +25 -0
- package/proto/sentinel/lease/v1/msg.proto +62 -0
- package/proto/sentinel/lease/v1/params.proto +17 -0
- package/proto/sentinel/node/v3/events.proto +50 -0
- package/proto/sentinel/node/v3/genesis.proto +15 -0
- package/proto/sentinel/node/v3/msg.proto +63 -0
- package/proto/sentinel/node/v3/node.proto +27 -0
- package/proto/sentinel/node/v3/params.proto +21 -0
- package/proto/sentinel/node/v3/querier.proto +63 -0
- package/proto/sentinel/plan/v3/events.proto +41 -0
- package/proto/sentinel/plan/v3/genesis.proto +21 -0
- package/proto/sentinel/plan/v3/msg.proto +83 -0
- package/proto/sentinel/plan/v3/plan.proto +32 -0
- package/proto/sentinel/plan/v3/querier.proto +53 -0
- package/proto/sentinel/provider/v2/events.proto +16 -0
- package/proto/sentinel/provider/v2/genesis.proto +15 -0
- package/proto/sentinel/provider/v2/msg.proto +35 -0
- package/proto/sentinel/provider/v2/params.proto +17 -0
- package/proto/sentinel/provider/v2/provider.proto +24 -0
- package/proto/sentinel/provider/v3/genesis.proto +15 -0
- package/proto/sentinel/provider/v3/params.proto +13 -0
- package/proto/sentinel/session/v3/events.proto +30 -0
- package/proto/sentinel/session/v3/genesis.proto +15 -0
- package/proto/sentinel/session/v3/msg.proto +50 -0
- package/proto/sentinel/session/v3/params.proto +25 -0
- package/proto/sentinel/session/v3/proof.proto +25 -0
- package/proto/sentinel/session/v3/querier.proto +100 -0
- package/proto/sentinel/session/v3/session.proto +50 -0
- package/proto/sentinel/subscription/v2/allocation.proto +21 -0
- package/proto/sentinel/subscription/v2/payout.proto +22 -0
- package/proto/sentinel/subscription/v3/events.proto +65 -0
- package/proto/sentinel/subscription/v3/genesis.proto +17 -0
- package/proto/sentinel/subscription/v3/msg.proto +83 -0
- package/proto/sentinel/subscription/v3/params.proto +21 -0
- package/proto/sentinel/subscription/v3/subscription.proto +33 -0
- package/proto/sentinel/types/v1/bandwidth.proto +19 -0
- package/proto/sentinel/types/v1/price.proto +21 -0
- package/proto/sentinel/types/v1/renewal.proto +21 -0
- package/proto/sentinel/types/v1/status.proto +16 -0
- package/protocol/encoding.js +341 -0
- package/protocol/events.js +361 -0
- package/protocol/handshake.js +297 -0
- package/protocol/index.js +15 -0
- package/protocol/messages.js +346 -0
- package/protocol/plans.js +199 -0
- package/protocol/v2ray.js +268 -0
- package/protocol/v3.js +723 -0
- package/protocol/wireguard.js +125 -0
- package/security/index.js +132 -0
- package/session-manager.js +329 -0
- package/session-tracker.js +80 -0
- package/setup.js +376 -0
- package/speedtest/index.js +528 -0
- package/speedtest.js +567 -0
- package/src/client.ts +502 -0
- package/src/index.ts +20 -0
- package/state/index.js +347 -0
- package/state.js +516 -0
- package/test-all-chain-ops.js +493 -0
- package/test-all-logic.js +199 -0
- package/test-all-msg-types.js +292 -0
- package/test-every-connection.js +208 -0
- package/test-feegrant-connect.js +98 -0
- package/test-logic.js +148 -0
- package/test-mainnet.js +176 -0
- package/test-plan-lifecycle.js +335 -0
- package/tls-trust.js +132 -0
- package/tsconfig.build.json +20 -0
- package/tsconfig.json +34 -0
- package/types/chain.d.ts +746 -0
- package/types/connection.d.ts +425 -0
- package/types/errors.d.ts +174 -0
- package/types/index.d.ts +1380 -0
- package/types/nodes.d.ts +187 -0
- package/types/pricing.d.ts +156 -0
- package/types/protocol.d.ts +332 -0
- package/types/session.d.ts +236 -0
- package/types/settings.d.ts +192 -0
- package/v3protocol.js +1053 -0
- package/wallet/index.js +153 -0
- package/wireguard.js +307 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentinel SDK — Session Types
|
|
3
|
+
*
|
|
4
|
+
* Types for session management: state persistence, credential caching,
|
|
5
|
+
* session poisoning, payment mode tracking, and session allocation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ─── State Persistence ─────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Saved connection state for crash recovery.
|
|
12
|
+
* Written to ~/.sentinel-sdk/state.json after successful connection.
|
|
13
|
+
* Read on next startup by recoverOrphans() to clean up leaked resources.
|
|
14
|
+
*/
|
|
15
|
+
export interface SDKState {
|
|
16
|
+
/** Active session ID (numeric string) */
|
|
17
|
+
sessionId?: string;
|
|
18
|
+
/** Protocol in use */
|
|
19
|
+
serviceType?: 'wireguard' | 'v2ray';
|
|
20
|
+
/** WireGuard tunnel service name (e.g. 'sentinel0') */
|
|
21
|
+
wgTunnelName?: string;
|
|
22
|
+
/** V2Ray process PID */
|
|
23
|
+
v2rayPid?: number;
|
|
24
|
+
/** SOCKS5 proxy port */
|
|
25
|
+
socksPort?: number;
|
|
26
|
+
/** Whether system proxy was modified */
|
|
27
|
+
systemProxySet?: boolean;
|
|
28
|
+
/** Whether kill switch was enabled */
|
|
29
|
+
killSwitchEnabled?: boolean;
|
|
30
|
+
/** Connected node address (sentnode1...) */
|
|
31
|
+
nodeAddress?: string;
|
|
32
|
+
/** WireGuard config file path */
|
|
33
|
+
confPath?: string;
|
|
34
|
+
/** When state was saved (ISO timestamp) */
|
|
35
|
+
savedAt?: string;
|
|
36
|
+
/** Process ID that saved this state */
|
|
37
|
+
pid?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Result from recoverOrphans(). */
|
|
41
|
+
export interface RecoverResult {
|
|
42
|
+
/** Whether any orphaned state was found */
|
|
43
|
+
hadState: boolean;
|
|
44
|
+
/** List of resources that were cleaned up (e.g. 'wg:sentinel0', 'v2ray:12345') */
|
|
45
|
+
cleaned: string[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Result from checkPidFile(). */
|
|
49
|
+
export interface PidCheck {
|
|
50
|
+
/** Whether the process is still running */
|
|
51
|
+
running: boolean;
|
|
52
|
+
/** PID from the file */
|
|
53
|
+
pid?: number;
|
|
54
|
+
/** When the PID file was written (ISO timestamp) */
|
|
55
|
+
startedAt?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ─── Credential Cache ──────────────────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Saved handshake credentials for fast reconnect.
|
|
62
|
+
* Persisted to ~/.sentinel-sdk/ encrypted on disk.
|
|
63
|
+
* Enables reconnecting to a node without redoing the handshake.
|
|
64
|
+
*/
|
|
65
|
+
export interface SavedCredentials {
|
|
66
|
+
/** Session ID this credential belongs to */
|
|
67
|
+
sessionId: string;
|
|
68
|
+
/** Protocol type */
|
|
69
|
+
serviceType: 'wireguard' | 'v2ray';
|
|
70
|
+
/** WireGuard private key (base64, WG only) */
|
|
71
|
+
wgPrivateKey?: string;
|
|
72
|
+
/** Server's WG public key (base64, WG only) */
|
|
73
|
+
wgServerPubKey?: string;
|
|
74
|
+
/** Assigned IP addresses with CIDR (WG only) */
|
|
75
|
+
wgAssignedAddrs?: string[];
|
|
76
|
+
/** Server's WG endpoint (WG only) */
|
|
77
|
+
wgServerEndpoint?: string;
|
|
78
|
+
/** V2Ray UUID (V2Ray only) */
|
|
79
|
+
v2rayUuid?: string;
|
|
80
|
+
/** V2Ray metadata JSON (V2Ray only) */
|
|
81
|
+
v2rayConfig?: string;
|
|
82
|
+
/** When credentials were saved (ISO timestamp) */
|
|
83
|
+
savedAt: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ─── Session Manager ───────────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Options for SessionManager constructor.
|
|
90
|
+
*/
|
|
91
|
+
export interface SessionManagerOptions {
|
|
92
|
+
/** Session map cache TTL in ms (default: 300000 = 5 min) */
|
|
93
|
+
mapTtl?: number;
|
|
94
|
+
/** Custom path for credential cache file */
|
|
95
|
+
credentialPath?: string;
|
|
96
|
+
/** Logger function */
|
|
97
|
+
logger?: (msg: string) => void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Session map entry (from SessionManager.buildSessionMap).
|
|
102
|
+
* Maps node address to active session info.
|
|
103
|
+
*/
|
|
104
|
+
export interface SessionMapEntry {
|
|
105
|
+
/** Session ID */
|
|
106
|
+
sessionId: bigint;
|
|
107
|
+
/** Maximum bytes for this session */
|
|
108
|
+
maxBytes: number;
|
|
109
|
+
/** Bytes used so far */
|
|
110
|
+
usedBytes: number;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ─── Session Allocation ────────────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Session allocation stats from computeSessionAllocation() or querySessionAllocation().
|
|
117
|
+
* Shows how much bandwidth has been used and remains.
|
|
118
|
+
*/
|
|
119
|
+
export interface SessionAllocation {
|
|
120
|
+
/** Total bytes used (download + upload) */
|
|
121
|
+
usedBytes: number;
|
|
122
|
+
/** Maximum bytes allowed for this session */
|
|
123
|
+
maxBytes: number;
|
|
124
|
+
/** Remaining bytes before session expires */
|
|
125
|
+
remainingBytes: number;
|
|
126
|
+
/** Usage percentage (0-100, rounded to 1 decimal) */
|
|
127
|
+
usedPercent: number;
|
|
128
|
+
/** Human-readable used amount (e.g. "1.5 GB") */
|
|
129
|
+
usedDisplay: string;
|
|
130
|
+
/** Human-readable max amount (e.g. "5.0 GB") */
|
|
131
|
+
maxDisplay: string;
|
|
132
|
+
/** Human-readable remaining amount (e.g. "3.5 GB") */
|
|
133
|
+
remainingDisplay: string;
|
|
134
|
+
/** True if session is GB-based (maxDuration is "0s") */
|
|
135
|
+
isGbBased: boolean;
|
|
136
|
+
/** True if session is hourly (maxDuration > "0s") */
|
|
137
|
+
isHourlyBased: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Result from querySessionAllocation() (null if session not found). */
|
|
141
|
+
export interface QuerySessionAllocationResult {
|
|
142
|
+
/** Maximum bytes allowed */
|
|
143
|
+
maxBytes: number;
|
|
144
|
+
/** Bytes used (download + upload) */
|
|
145
|
+
usedBytes: number;
|
|
146
|
+
/** Remaining bytes */
|
|
147
|
+
remainingBytes: number;
|
|
148
|
+
/** Usage percentage (0-100) */
|
|
149
|
+
percentUsed: number;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ─── Session Payment Mode Tracking ─────────────────────────────────────────
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Session payment mode. The chain doesn't distinguish GB-based from hourly.
|
|
156
|
+
* This is tracked client-side so apps can show the correct pricing model.
|
|
157
|
+
*
|
|
158
|
+
* - 'gb': Paid per gigabyte (connectDirect with gigabytes param)
|
|
159
|
+
* - 'hour': Paid per hour (connectDirect with hours param)
|
|
160
|
+
* - 'plan': Started via plan subscription (connectViaPlan)
|
|
161
|
+
*/
|
|
162
|
+
export type SessionPaymentMode = 'gb' | 'hour' | 'plan';
|
|
163
|
+
|
|
164
|
+
// ─── Session History ───────────────────────────────────────────────────────
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Session history entry. Tracks both active and poisoned sessions.
|
|
168
|
+
* Stored in ~/.sentinel-sdk/sessions.json.
|
|
169
|
+
*/
|
|
170
|
+
export interface SessionHistoryEntry {
|
|
171
|
+
/** sentnode1... address */
|
|
172
|
+
nodeAddress: string;
|
|
173
|
+
/** Session status */
|
|
174
|
+
status: 'active' | 'poisoned';
|
|
175
|
+
/** Error message (poisoned sessions only) */
|
|
176
|
+
error?: string;
|
|
177
|
+
/** When the entry was created/updated */
|
|
178
|
+
timestamp: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ─── Batch Session Operations ──────────────────────────────────────────────
|
|
182
|
+
|
|
183
|
+
/** Options for batchStartSessions() (operator/testing tool). */
|
|
184
|
+
export interface BatchStartSessionsOptions {
|
|
185
|
+
/** BIP39 mnemonic phrase */
|
|
186
|
+
mnemonic: string;
|
|
187
|
+
/** RPC URL (default: cascading fallback) */
|
|
188
|
+
rpcUrl?: string;
|
|
189
|
+
/** LCD URL (default: cascading fallback) */
|
|
190
|
+
lcdUrl?: string;
|
|
191
|
+
/** Nodes to start sessions on */
|
|
192
|
+
nodes: Array<{
|
|
193
|
+
/** sentnode1... address */
|
|
194
|
+
nodeAddress: string;
|
|
195
|
+
/** GB to purchase (default: 1) */
|
|
196
|
+
gigabytes?: number;
|
|
197
|
+
/** Max acceptable price */
|
|
198
|
+
maxPrice?: { denom: string; base_value: string; quote_value: string };
|
|
199
|
+
}>;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Result from batchStartSessions(). */
|
|
203
|
+
export interface BatchStartResult {
|
|
204
|
+
/** Transaction hash */
|
|
205
|
+
txHash: string;
|
|
206
|
+
/** Session IDs created (one per node) */
|
|
207
|
+
sessionIds: bigint[];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Status of a batch session (from waitForBatchSessions). */
|
|
211
|
+
export interface BatchSessionStatus {
|
|
212
|
+
/** Session ID */
|
|
213
|
+
sessionId: bigint;
|
|
214
|
+
/** Whether the session appeared on LCD */
|
|
215
|
+
status: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Options for waitForBatchSessions(). */
|
|
219
|
+
export interface WaitForBatchOptions {
|
|
220
|
+
/** LCD URL */
|
|
221
|
+
lcdUrl?: string;
|
|
222
|
+
/** Max wait time in ms (default: 60000) */
|
|
223
|
+
timeoutMs?: number;
|
|
224
|
+
/** Polling interval in ms (default: 5000) */
|
|
225
|
+
pollIntervalMs?: number;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Options for waitForSessionActive(). */
|
|
229
|
+
export interface WaitForSessionActiveOptions {
|
|
230
|
+
/** LCD URL */
|
|
231
|
+
lcdUrl?: string;
|
|
232
|
+
/** Max wait time in ms (default: 30000) */
|
|
233
|
+
timeoutMs?: number;
|
|
234
|
+
/** Polling interval in ms (default: 3000) */
|
|
235
|
+
pollIntervalMs?: number;
|
|
236
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentinel SDK — Settings & App Configuration Types
|
|
3
|
+
*
|
|
4
|
+
* Types for app settings persistence, app type definitions,
|
|
5
|
+
* DNS presets, and app configuration validation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ─── App Settings ──────────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Persisted app settings. Stored at ~/.sentinel-sdk/app-settings.json.
|
|
12
|
+
* Every field has a sane default -- apps can use this out of the box.
|
|
13
|
+
* Mutate the object, then call saveAppSettings() to persist.
|
|
14
|
+
*/
|
|
15
|
+
export interface AppSettings {
|
|
16
|
+
// ── Network ──
|
|
17
|
+
/** DNS preset: 'handshake' | 'google' | 'cloudflare' | 'custom' */
|
|
18
|
+
dnsPreset: 'handshake' | 'google' | 'cloudflare' | 'custom';
|
|
19
|
+
/** Custom DNS IPs, comma-separated (only used when dnsPreset is 'custom') */
|
|
20
|
+
customDns: string;
|
|
21
|
+
|
|
22
|
+
// ── Tunnel ──
|
|
23
|
+
/** Route all traffic through VPN (default: true) */
|
|
24
|
+
fullTunnel: boolean;
|
|
25
|
+
/** Set OS SOCKS proxy for V2Ray (default: false) */
|
|
26
|
+
systemProxy: boolean;
|
|
27
|
+
/** Block all traffic if tunnel drops (default: false) */
|
|
28
|
+
killSwitch: boolean;
|
|
29
|
+
/** WireGuard MTU -- Sentinel nodes use 1280 (default: 1280) */
|
|
30
|
+
wgMtu: number;
|
|
31
|
+
/** WireGuard keepalive in seconds -- safe for all NAT routers (default: 15) */
|
|
32
|
+
wgKeepalive: number;
|
|
33
|
+
|
|
34
|
+
// ── Session ──
|
|
35
|
+
/** Default GB amount for per-GB sessions (default: 1) */
|
|
36
|
+
defaultGigabytes: number;
|
|
37
|
+
/** Default hour amount for hourly sessions (default: 1) */
|
|
38
|
+
defaultHours: number;
|
|
39
|
+
/** Prefer hourly pricing when available (default: false) */
|
|
40
|
+
preferHourly: boolean;
|
|
41
|
+
/** Protocol preference: 'auto' picks best, 'wireguard'/'v2ray' forces one */
|
|
42
|
+
protocolPreference: 'auto' | 'wireguard' | 'v2ray';
|
|
43
|
+
|
|
44
|
+
// ── Polling intervals (seconds) ──
|
|
45
|
+
/** Connection status check interval (default: 3) */
|
|
46
|
+
statusPollSec: number;
|
|
47
|
+
/** Public IP check interval (default: 60) */
|
|
48
|
+
ipCheckSec: number;
|
|
49
|
+
/** Wallet balance refresh interval (default: 300 = 5 min) */
|
|
50
|
+
balanceCheckSec: number;
|
|
51
|
+
/** Session allocation refresh interval (default: 120 = 2 min) */
|
|
52
|
+
allocationCheckSec: number;
|
|
53
|
+
|
|
54
|
+
// ── Plan ──
|
|
55
|
+
/** Max plan ID to probe in discoverPlans (default: 500) */
|
|
56
|
+
planProbeMax: number;
|
|
57
|
+
|
|
58
|
+
// ── Favorites ──
|
|
59
|
+
/** Array of sentnode1... addresses marked as favorite */
|
|
60
|
+
favoriteNodes: string[];
|
|
61
|
+
|
|
62
|
+
// ── Last connection ──
|
|
63
|
+
/** Last connected node address for quick reconnect (null if none) */
|
|
64
|
+
lastNodeAddress: string | null;
|
|
65
|
+
/** Last service type used */
|
|
66
|
+
lastServiceType: 'wireguard' | 'v2ray' | null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ─── DNS Presets ───────────────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
/** DNS server preset configuration. */
|
|
72
|
+
export interface DnsPreset {
|
|
73
|
+
/** Display name (e.g. 'Handshake') */
|
|
74
|
+
name: string;
|
|
75
|
+
/** DNS server IP addresses */
|
|
76
|
+
servers: string[];
|
|
77
|
+
/** Human-readable description */
|
|
78
|
+
description: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Available DNS preset names. */
|
|
82
|
+
export type DnsPresetName = 'handshake' | 'google' | 'cloudflare';
|
|
83
|
+
|
|
84
|
+
/** All DNS presets (frozen object). */
|
|
85
|
+
export type DnsPresets = Readonly<Record<DnsPresetName, DnsPreset>>;
|
|
86
|
+
|
|
87
|
+
// ─── App Types ─────────────────────────────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The three types of Sentinel dVPN applications.
|
|
91
|
+
* Choose based on how users pay for VPN access.
|
|
92
|
+
*/
|
|
93
|
+
export type AppType = 'white_label' | 'direct_p2p' | 'all_in_one';
|
|
94
|
+
|
|
95
|
+
/** App type string constants. */
|
|
96
|
+
export interface AppTypeConstants {
|
|
97
|
+
/** Branded app with pre-loaded plan. Users click "Connect", done. */
|
|
98
|
+
readonly WHITE_LABEL: 'white_label';
|
|
99
|
+
/** Users browse nodes, pick pricing, pay per session. */
|
|
100
|
+
readonly DIRECT_P2P: 'direct_p2p';
|
|
101
|
+
/** Plan subscriptions + direct P2P. Full flexibility. */
|
|
102
|
+
readonly ALL_IN_ONE: 'all_in_one';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** UI screens configuration for an app type. */
|
|
106
|
+
export interface AppTypeScreens {
|
|
107
|
+
/** Welcome/onboarding screen */
|
|
108
|
+
welcome: boolean;
|
|
109
|
+
/** Browse available plans */
|
|
110
|
+
planBrowser: boolean;
|
|
111
|
+
/** Browse individual nodes */
|
|
112
|
+
nodeBrowser: boolean;
|
|
113
|
+
/** Duration/amount picker (GB or hours) */
|
|
114
|
+
durationPicker: boolean;
|
|
115
|
+
/** Price display before connecting */
|
|
116
|
+
pricingDisplay: boolean;
|
|
117
|
+
/** Main connect button */
|
|
118
|
+
connect: boolean;
|
|
119
|
+
/** Settings screen */
|
|
120
|
+
settings: boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Complete configuration requirements and flow for an app type. */
|
|
124
|
+
export interface AppTypeConfig {
|
|
125
|
+
/** Human-readable description */
|
|
126
|
+
description: string;
|
|
127
|
+
/** Required configuration keys (must be non-null at startup) */
|
|
128
|
+
requiredConfig: string[];
|
|
129
|
+
/** Optional configuration keys */
|
|
130
|
+
optionalConfig: string[];
|
|
131
|
+
/** Recommended connect function name */
|
|
132
|
+
connectFunction: string;
|
|
133
|
+
/** Whether the user pays gas (false for white-label with fee grants) */
|
|
134
|
+
userPaysGas: boolean;
|
|
135
|
+
/** Whether the user picks a specific node */
|
|
136
|
+
userPicksNode: boolean;
|
|
137
|
+
/** Whether the user picks duration/amount */
|
|
138
|
+
userPicksDuration: boolean;
|
|
139
|
+
/** Whether pricing is shown to the user */
|
|
140
|
+
userSeesPricing: boolean;
|
|
141
|
+
/** Which UI screens to build */
|
|
142
|
+
screens: AppTypeScreens;
|
|
143
|
+
/** Step-by-step user flow description */
|
|
144
|
+
flow: string[];
|
|
145
|
+
/** SDK functions to use for this app type */
|
|
146
|
+
sdkFunctions: string[];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ─── App Config Validation ─────────────────────────────────────────────────
|
|
150
|
+
|
|
151
|
+
/** Result from validateAppConfig(). Run at app startup. */
|
|
152
|
+
export interface AppConfigValidation {
|
|
153
|
+
/** Whether the config is valid (no errors) */
|
|
154
|
+
valid: boolean;
|
|
155
|
+
/** Critical errors that must be fixed */
|
|
156
|
+
errors: string[];
|
|
157
|
+
/** Non-critical warnings */
|
|
158
|
+
warnings: string[];
|
|
159
|
+
/** The resolved app type config (null if type is invalid) */
|
|
160
|
+
type: AppTypeConfig | null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ─── VPN Settings (Legacy) ─────────────────────────────────────────────────
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Legacy VPN settings from loadVpnSettings() / saveVpnSettings().
|
|
167
|
+
* Stored at ~/.sentinel-sdk/settings.json.
|
|
168
|
+
* Use loadAppSettings() instead for new code.
|
|
169
|
+
*/
|
|
170
|
+
export type VpnSettings = Record<string, unknown>;
|
|
171
|
+
|
|
172
|
+
// ─── Disk Cache ────────────────────────────────────────────────────────────
|
|
173
|
+
|
|
174
|
+
/** Cache entry metadata from cacheInfo(). */
|
|
175
|
+
export interface CacheInfo {
|
|
176
|
+
/** Age of the cached data in ms */
|
|
177
|
+
ageMs: number;
|
|
178
|
+
/** Whether there is data in the cache */
|
|
179
|
+
hasData: boolean;
|
|
180
|
+
/** Whether a fetch is currently in flight */
|
|
181
|
+
inflight: boolean;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Disk cache load result from diskLoad(). */
|
|
185
|
+
export interface DiskCacheEntry<T = unknown> {
|
|
186
|
+
/** The cached data */
|
|
187
|
+
data: T;
|
|
188
|
+
/** When the data was saved (Date.now() timestamp) */
|
|
189
|
+
savedAt: number;
|
|
190
|
+
/** Whether the data exceeds maxAgeMs */
|
|
191
|
+
stale: boolean;
|
|
192
|
+
}
|