@layr-labs/ecloud-sdk 0.2.0-dev → 0.2.0-dev.1
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/VERSION +2 -2
- package/dist/billing.cjs +19 -0
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.d.cts +3 -2
- package/dist/billing.d.ts +3 -2
- package/dist/billing.js +2 -2
- package/dist/{chunk-34DXGQ35.js → chunk-FY7UU55U.js} +2 -2
- package/dist/chunk-FY7UU55U.js.map +1 -0
- package/dist/chunk-GB4GM4C2.js +434 -0
- package/dist/chunk-GB4GM4C2.js.map +1 -0
- package/dist/{chunk-HLH3AMQF.js → chunk-O7EU5JL7.js} +328 -123
- package/dist/chunk-O7EU5JL7.js.map +1 -0
- package/dist/{compute-B_ibIORD.d.cts → compute-CF2HOXed.d.ts} +101 -15
- package/dist/{compute-gpepEsn3.d.ts → compute-CbmjA8kJ.d.cts} +101 -15
- package/dist/compute.cjs +772 -62
- package/dist/compute.cjs.map +1 -1
- package/dist/compute.d.cts +2 -2
- package/dist/compute.d.ts +2 -2
- package/dist/compute.js +2 -2
- package/dist/{index-D-SUX3IG.d.ts → index-D2QufVB9.d.cts} +130 -6
- package/dist/{index-D-SUX3IG.d.cts → index-D2QufVB9.d.ts} +130 -6
- package/dist/index.cjs +646 -438
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -166
- package/dist/index.d.ts +52 -166
- package/dist/index.js +17 -243
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/chunk-34DXGQ35.js.map +0 -1
- package/dist/chunk-HLH3AMQF.js.map +0 -1
- package/dist/chunk-LINGJMAS.js +0 -180
- package/dist/chunk-LINGJMAS.js.map +0 -1
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addHexPrefix,
|
|
3
|
+
calculateBillingAuthSignature,
|
|
4
|
+
getBillingEnvironmentConfig,
|
|
5
|
+
getBuildType,
|
|
6
|
+
getLogger,
|
|
7
|
+
isSubscriptionActive,
|
|
8
|
+
withSDKTelemetry
|
|
9
|
+
} from "./chunk-FY7UU55U.js";
|
|
10
|
+
|
|
11
|
+
// src/client/common/auth/keyring.ts
|
|
12
|
+
import { AsyncEntry, findCredentials } from "@napi-rs/keyring";
|
|
13
|
+
import { privateKeyToAddress } from "viem/accounts";
|
|
14
|
+
var SERVICE_NAME = "ecloud";
|
|
15
|
+
var ACCOUNT_NAME = "key";
|
|
16
|
+
var EIGENX_SERVICE_NAME = "eigenx-cli";
|
|
17
|
+
var EIGENX_DEV_SERVICE_NAME = "eigenx-cli-dev";
|
|
18
|
+
var EIGENX_ACCOUNT_PREFIX = "eigenx-";
|
|
19
|
+
var GO_KEYRING_BASE64_PREFIX = "go-keyring-base64:";
|
|
20
|
+
var GO_KEYRING_ENCODED_PREFIX = "go-keyring-encoded:";
|
|
21
|
+
async function storePrivateKey(privateKey) {
|
|
22
|
+
const normalizedKey = normalizePrivateKey(privateKey);
|
|
23
|
+
const isValid = validatePrivateKey(normalizedKey);
|
|
24
|
+
if (!isValid) {
|
|
25
|
+
throw new Error("Invalid private key format");
|
|
26
|
+
}
|
|
27
|
+
const entry = new AsyncEntry(SERVICE_NAME, ACCOUNT_NAME);
|
|
28
|
+
try {
|
|
29
|
+
await entry.setPassword(normalizedKey);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Failed to store key in OS keyring: ${err?.message ?? err}. Ensure keyring service is available.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function getPrivateKey() {
|
|
37
|
+
const entry = new AsyncEntry(SERVICE_NAME, ACCOUNT_NAME);
|
|
38
|
+
try {
|
|
39
|
+
const key = await entry.getPassword();
|
|
40
|
+
if (key && validatePrivateKey(key)) {
|
|
41
|
+
return key;
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
async function deletePrivateKey() {
|
|
48
|
+
const entry = new AsyncEntry(SERVICE_NAME, ACCOUNT_NAME);
|
|
49
|
+
try {
|
|
50
|
+
await entry.deletePassword();
|
|
51
|
+
return true;
|
|
52
|
+
} catch {
|
|
53
|
+
console.warn("No key found in keyring");
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function listStoredKeys() {
|
|
58
|
+
const keys = [];
|
|
59
|
+
const creds = findCredentials(SERVICE_NAME);
|
|
60
|
+
for (const cred of creds) {
|
|
61
|
+
if (cred.account === ACCOUNT_NAME) {
|
|
62
|
+
try {
|
|
63
|
+
const address = getAddressFromPrivateKey(cred.password);
|
|
64
|
+
keys.push({ address });
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.warn(`Warning: Invalid key found, skipping: ${err}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return keys;
|
|
71
|
+
}
|
|
72
|
+
async function keyExists() {
|
|
73
|
+
const key = await getPrivateKey();
|
|
74
|
+
return key !== null;
|
|
75
|
+
}
|
|
76
|
+
async function getLegacyKeys() {
|
|
77
|
+
const keys = [];
|
|
78
|
+
try {
|
|
79
|
+
const eigenxCreds = findCredentials(EIGENX_SERVICE_NAME);
|
|
80
|
+
for (const cred of eigenxCreds) {
|
|
81
|
+
const accountName = cred.account;
|
|
82
|
+
if (!accountName.startsWith(EIGENX_ACCOUNT_PREFIX)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const environment = accountName.substring(EIGENX_ACCOUNT_PREFIX.length);
|
|
86
|
+
try {
|
|
87
|
+
const decodedKey = decodeGoKeyringValue(cred.password);
|
|
88
|
+
const address = getAddressFromPrivateKey(decodedKey);
|
|
89
|
+
keys.push({ environment, address, source: "eigenx" });
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.warn(
|
|
92
|
+
`Warning: Invalid key found for ${environment} (eigenx-cli), skipping: ${err}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const eigenxDevCreds = findCredentials(EIGENX_DEV_SERVICE_NAME);
|
|
100
|
+
for (const cred of eigenxDevCreds) {
|
|
101
|
+
const accountName = cred.account;
|
|
102
|
+
if (!accountName.startsWith(EIGENX_ACCOUNT_PREFIX)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const environment = accountName.substring(EIGENX_ACCOUNT_PREFIX.length);
|
|
106
|
+
try {
|
|
107
|
+
const decodedKey = decodeGoKeyringValue(cred.password);
|
|
108
|
+
const address = getAddressFromPrivateKey(decodedKey);
|
|
109
|
+
keys.push({ environment, address, source: "eigenx-dev" });
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.warn(
|
|
112
|
+
`Warning: Invalid key found for ${environment} (eigenx-dev), skipping: ${err}`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch {
|
|
117
|
+
}
|
|
118
|
+
return keys;
|
|
119
|
+
}
|
|
120
|
+
async function getLegacyPrivateKey(environment, source) {
|
|
121
|
+
const serviceName = source === "eigenx" ? EIGENX_SERVICE_NAME : EIGENX_DEV_SERVICE_NAME;
|
|
122
|
+
const accountName = EIGENX_ACCOUNT_PREFIX + environment;
|
|
123
|
+
const entry = new AsyncEntry(serviceName, accountName);
|
|
124
|
+
try {
|
|
125
|
+
const rawKey = await entry.getPassword();
|
|
126
|
+
if (rawKey) {
|
|
127
|
+
const decodedKey = decodeGoKeyringValue(rawKey);
|
|
128
|
+
if (validatePrivateKey(decodedKey)) {
|
|
129
|
+
return decodedKey;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
async function deleteLegacyPrivateKey(environment, source) {
|
|
137
|
+
const serviceName = source === "eigenx" ? EIGENX_SERVICE_NAME : EIGENX_DEV_SERVICE_NAME;
|
|
138
|
+
const accountName = EIGENX_ACCOUNT_PREFIX + environment;
|
|
139
|
+
const entry = new AsyncEntry(serviceName, accountName);
|
|
140
|
+
try {
|
|
141
|
+
await entry.deletePassword();
|
|
142
|
+
return true;
|
|
143
|
+
} catch {
|
|
144
|
+
console.warn(`No key found for ${environment} in ${source}`);
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function validatePrivateKey(privateKey) {
|
|
149
|
+
try {
|
|
150
|
+
getAddressFromPrivateKey(privateKey);
|
|
151
|
+
return true;
|
|
152
|
+
} catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function getAddressFromPrivateKey(privateKey) {
|
|
157
|
+
const normalized = normalizePrivateKey(privateKey);
|
|
158
|
+
return privateKeyToAddress(normalized);
|
|
159
|
+
}
|
|
160
|
+
function decodeGoKeyringValue(rawValue) {
|
|
161
|
+
if (rawValue.startsWith(GO_KEYRING_BASE64_PREFIX)) {
|
|
162
|
+
const encoded = rawValue.substring(GO_KEYRING_BASE64_PREFIX.length);
|
|
163
|
+
try {
|
|
164
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf8");
|
|
165
|
+
return decoded;
|
|
166
|
+
} catch (err) {
|
|
167
|
+
console.warn(`Warning: Failed to decode go-keyring base64 value: ${err}`);
|
|
168
|
+
return rawValue;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (rawValue.startsWith(GO_KEYRING_ENCODED_PREFIX)) {
|
|
172
|
+
const encoded = rawValue.substring(GO_KEYRING_ENCODED_PREFIX.length);
|
|
173
|
+
try {
|
|
174
|
+
const decoded = Buffer.from(encoded, "hex").toString("utf8");
|
|
175
|
+
return decoded;
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.warn(`Warning: Failed to decode go-keyring hex value: ${err}`);
|
|
178
|
+
return rawValue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return rawValue;
|
|
182
|
+
}
|
|
183
|
+
function normalizePrivateKey(privateKey) {
|
|
184
|
+
if (!privateKey.startsWith("0x")) {
|
|
185
|
+
return `0x${privateKey}`;
|
|
186
|
+
}
|
|
187
|
+
return privateKey;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/client/common/auth/resolver.ts
|
|
191
|
+
async function getPrivateKeyWithSource(options) {
|
|
192
|
+
if (options.privateKey) {
|
|
193
|
+
if (!validatePrivateKey(options.privateKey)) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
"Invalid private key format provided via command flag. Please check and try again."
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
key: options.privateKey,
|
|
200
|
+
source: "command flag"
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const envKey = process.env.ECLOUD_PRIVATE_KEY;
|
|
204
|
+
if (envKey) {
|
|
205
|
+
if (!validatePrivateKey(envKey)) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
"Invalid private key format provided via environment variable. Please check and try again."
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
key: envKey,
|
|
212
|
+
source: "environment variable (ECLOUD_PRIVATE_KEY)"
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const keyringKey = await getPrivateKey();
|
|
216
|
+
if (keyringKey) {
|
|
217
|
+
return {
|
|
218
|
+
key: keyringKey,
|
|
219
|
+
source: "stored credentials"
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
async function requirePrivateKey(options) {
|
|
225
|
+
const result = await getPrivateKeyWithSource({
|
|
226
|
+
privateKey: options.privateKey
|
|
227
|
+
});
|
|
228
|
+
if (!result) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`Private key required. Please provide it via:
|
|
231
|
+
\u2022 Keyring: ecloud auth login
|
|
232
|
+
\u2022 Flag: --private-key YOUR_KEY
|
|
233
|
+
\u2022 Environment: export ECLOUD_PRIVATE_KEY=YOUR_KEY`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/client/common/auth/generate.ts
|
|
240
|
+
import { generatePrivateKey, privateKeyToAddress as privateKeyToAddress2 } from "viem/accounts";
|
|
241
|
+
function generateNewPrivateKey() {
|
|
242
|
+
const privateKey = generatePrivateKey();
|
|
243
|
+
const address = privateKeyToAddress2(privateKey);
|
|
244
|
+
return {
|
|
245
|
+
privateKey,
|
|
246
|
+
address
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/client/common/utils/billingapi.ts
|
|
251
|
+
import axios from "axios";
|
|
252
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
253
|
+
var BillingApiClient = class {
|
|
254
|
+
constructor(config, privateKey) {
|
|
255
|
+
this.account = privateKeyToAccount(privateKey);
|
|
256
|
+
this.config = config;
|
|
257
|
+
}
|
|
258
|
+
async createSubscription(productId = "compute") {
|
|
259
|
+
const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
|
|
260
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "POST", productId);
|
|
261
|
+
return resp.json();
|
|
262
|
+
}
|
|
263
|
+
async getSubscription(productId = "compute") {
|
|
264
|
+
const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
|
|
265
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "GET", productId);
|
|
266
|
+
return resp.json();
|
|
267
|
+
}
|
|
268
|
+
async cancelSubscription(productId = "compute") {
|
|
269
|
+
const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
|
|
270
|
+
await this.makeAuthenticatedRequest(endpoint, "DELETE", productId);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Make an authenticated request to the billing API
|
|
274
|
+
*/
|
|
275
|
+
async makeAuthenticatedRequest(url, method, productId) {
|
|
276
|
+
const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
|
|
277
|
+
const { signature } = await calculateBillingAuthSignature({
|
|
278
|
+
account: this.account,
|
|
279
|
+
product: productId,
|
|
280
|
+
expiry
|
|
281
|
+
});
|
|
282
|
+
const headers = {
|
|
283
|
+
Authorization: `Bearer ${signature}`,
|
|
284
|
+
"X-Account": this.account.address,
|
|
285
|
+
"X-Expiry": expiry.toString()
|
|
286
|
+
};
|
|
287
|
+
try {
|
|
288
|
+
const response = await axios({
|
|
289
|
+
method,
|
|
290
|
+
url,
|
|
291
|
+
headers,
|
|
292
|
+
timeout: 3e4,
|
|
293
|
+
maxRedirects: 0,
|
|
294
|
+
validateStatus: () => true
|
|
295
|
+
// Don't throw on any status
|
|
296
|
+
});
|
|
297
|
+
const status = response.status;
|
|
298
|
+
const statusText = status >= 200 && status < 300 ? "OK" : "Error";
|
|
299
|
+
if (status < 200 || status >= 300) {
|
|
300
|
+
const body = typeof response.data === "string" ? response.data : JSON.stringify(response.data);
|
|
301
|
+
throw new Error(`BillingAPI request failed: ${status} ${statusText} - ${body}`);
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
json: async () => response.data,
|
|
305
|
+
text: async () => typeof response.data === "string" ? response.data : JSON.stringify(response.data)
|
|
306
|
+
};
|
|
307
|
+
} catch (error) {
|
|
308
|
+
if (error.message?.includes("fetch failed") || error.message?.includes("ECONNREFUSED") || error.message?.includes("ENOTFOUND") || error.cause) {
|
|
309
|
+
const cause = error.cause?.message || error.cause || error.message;
|
|
310
|
+
throw new Error(
|
|
311
|
+
`Failed to connect to BillingAPI at ${url}: ${cause}
|
|
312
|
+
Please check:
|
|
313
|
+
1. Your internet connection
|
|
314
|
+
2. The API server is accessible: ${this.config.billingApiServerURL}
|
|
315
|
+
3. Firewall/proxy settings`
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// src/client/modules/billing/index.ts
|
|
324
|
+
function createBillingModule(config) {
|
|
325
|
+
const { verbose = false, skipTelemetry = false } = config;
|
|
326
|
+
const privateKey = addHexPrefix(config.privateKey);
|
|
327
|
+
const address = getAddressFromPrivateKey(privateKey);
|
|
328
|
+
const logger = getLogger(verbose);
|
|
329
|
+
const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
|
|
330
|
+
const billingApi = new BillingApiClient(billingEnvConfig, privateKey);
|
|
331
|
+
return {
|
|
332
|
+
address,
|
|
333
|
+
async subscribe(opts) {
|
|
334
|
+
return withSDKTelemetry(
|
|
335
|
+
{
|
|
336
|
+
functionName: "subscribe",
|
|
337
|
+
skipTelemetry,
|
|
338
|
+
// Skip if called from CLI
|
|
339
|
+
properties: { productId: opts?.productId || "compute" }
|
|
340
|
+
},
|
|
341
|
+
async () => {
|
|
342
|
+
const productId = opts?.productId || "compute";
|
|
343
|
+
logger.debug(`Checking existing subscription for ${productId}...`);
|
|
344
|
+
const currentStatus = await billingApi.getSubscription(productId);
|
|
345
|
+
if (isSubscriptionActive(currentStatus.subscriptionStatus)) {
|
|
346
|
+
logger.debug(`Subscription already active: ${currentStatus.subscriptionStatus}`);
|
|
347
|
+
return {
|
|
348
|
+
type: "already_active",
|
|
349
|
+
status: currentStatus.subscriptionStatus
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
if (currentStatus.subscriptionStatus === "past_due" || currentStatus.subscriptionStatus === "unpaid") {
|
|
353
|
+
logger.debug(`Subscription has payment issue: ${currentStatus.subscriptionStatus}`);
|
|
354
|
+
return {
|
|
355
|
+
type: "payment_issue",
|
|
356
|
+
status: currentStatus.subscriptionStatus,
|
|
357
|
+
portalUrl: currentStatus.portalUrl
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
logger.debug(`Creating subscription for ${productId}...`);
|
|
361
|
+
const result = await billingApi.createSubscription(productId);
|
|
362
|
+
logger.debug(`Checkout URL: ${result.checkoutUrl}`);
|
|
363
|
+
return {
|
|
364
|
+
type: "checkout_created",
|
|
365
|
+
checkoutUrl: result.checkoutUrl
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
);
|
|
369
|
+
},
|
|
370
|
+
async getStatus(opts) {
|
|
371
|
+
return withSDKTelemetry(
|
|
372
|
+
{
|
|
373
|
+
functionName: "getStatus",
|
|
374
|
+
skipTelemetry,
|
|
375
|
+
// Skip if called from CLI
|
|
376
|
+
properties: { productId: opts?.productId || "compute" }
|
|
377
|
+
},
|
|
378
|
+
async () => {
|
|
379
|
+
const productId = opts?.productId || "compute";
|
|
380
|
+
logger.debug(`Fetching subscription status for ${productId}...`);
|
|
381
|
+
const result = await billingApi.getSubscription(productId);
|
|
382
|
+
logger.debug(`Subscription status: ${result.subscriptionStatus}`);
|
|
383
|
+
return result;
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
},
|
|
387
|
+
async cancel(opts) {
|
|
388
|
+
return withSDKTelemetry(
|
|
389
|
+
{
|
|
390
|
+
functionName: "cancel",
|
|
391
|
+
skipTelemetry,
|
|
392
|
+
// Skip if called from CLI
|
|
393
|
+
properties: { productId: opts?.productId || "compute" }
|
|
394
|
+
},
|
|
395
|
+
async () => {
|
|
396
|
+
const productId = opts?.productId || "compute";
|
|
397
|
+
logger.debug(`Checking subscription status for ${productId}...`);
|
|
398
|
+
const currentStatus = await billingApi.getSubscription(productId);
|
|
399
|
+
if (!isSubscriptionActive(currentStatus.subscriptionStatus)) {
|
|
400
|
+
logger.debug(`No active subscription to cancel: ${currentStatus.subscriptionStatus}`);
|
|
401
|
+
return {
|
|
402
|
+
type: "no_active_subscription",
|
|
403
|
+
status: currentStatus.subscriptionStatus
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
logger.debug(`Canceling subscription for ${productId}...`);
|
|
407
|
+
await billingApi.cancelSubscription(productId);
|
|
408
|
+
logger.debug(`Subscription canceled successfully`);
|
|
409
|
+
return {
|
|
410
|
+
type: "canceled"
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export {
|
|
419
|
+
storePrivateKey,
|
|
420
|
+
getPrivateKey,
|
|
421
|
+
deletePrivateKey,
|
|
422
|
+
listStoredKeys,
|
|
423
|
+
keyExists,
|
|
424
|
+
getLegacyKeys,
|
|
425
|
+
getLegacyPrivateKey,
|
|
426
|
+
deleteLegacyPrivateKey,
|
|
427
|
+
validatePrivateKey,
|
|
428
|
+
getAddressFromPrivateKey,
|
|
429
|
+
getPrivateKeyWithSource,
|
|
430
|
+
requirePrivateKey,
|
|
431
|
+
generateNewPrivateKey,
|
|
432
|
+
createBillingModule
|
|
433
|
+
};
|
|
434
|
+
//# sourceMappingURL=chunk-GB4GM4C2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/common/auth/keyring.ts","../src/client/common/auth/resolver.ts","../src/client/common/auth/generate.ts","../src/client/common/utils/billingapi.ts","../src/client/modules/billing/index.ts"],"sourcesContent":["/**\n * OS Keyring Integration\n *\n * Provides secure storage for private keys using native OS keychains:\n * - macOS: Keychain\n * - Linux: Secret Service API (libsecret/gnome-keyring)\n * - Windows: Credential Manager\n *\n * Uses a single key for all environments.\n */\n\nimport { AsyncEntry, findCredentials } from \"@napi-rs/keyring\";\nimport { Hex } from \"viem\";\nimport { privateKeyToAddress } from \"viem/accounts\";\n\n// ecloud keyring identifiers\nconst SERVICE_NAME = \"ecloud\";\nconst ACCOUNT_NAME = \"key\"; // Single key for all environments\n\n// eigenx-cli keyring identifiers (for legacy key detection)\nconst EIGENX_SERVICE_NAME = \"eigenx-cli\";\nconst EIGENX_DEV_SERVICE_NAME = \"eigenx-cli-dev\";\nconst EIGENX_ACCOUNT_PREFIX = \"eigenx-\"; // eigenx-cli prefixes account names\n\n// go-keyring encoding constants (used by eigenx-cli on macOS)\nconst GO_KEYRING_BASE64_PREFIX = \"go-keyring-base64:\";\nconst GO_KEYRING_ENCODED_PREFIX = \"go-keyring-encoded:\"; // legacy hex encoding\n\nexport interface StoredKey {\n address: string;\n}\n\nexport interface LegacyKey {\n environment: string;\n address: string;\n source: \"eigenx\" | \"eigenx-dev\";\n}\n\n/**\n * Store a private key in OS keyring\n *\n * Note: Stores a single key for all environments.\n * The environment parameter is kept for API compatibility but is ignored.\n */\nexport async function storePrivateKey(privateKey: string): Promise<void> {\n // Validate private key format\n const normalizedKey = normalizePrivateKey(privateKey);\n\n // Validate by deriving address (will throw if invalid)\n const isValid = validatePrivateKey(normalizedKey);\n if (!isValid) {\n throw new Error(\"Invalid private key format\");\n }\n\n // Store in single-key format\n const entry = new AsyncEntry(SERVICE_NAME, ACCOUNT_NAME);\n try {\n await entry.setPassword(normalizedKey);\n } catch (err: any) {\n throw new Error(\n `Failed to store key in OS keyring: ${err?.message ?? err}. Ensure keyring service is available.`,\n );\n }\n}\n\n/**\n * Get a private key from OS keyring\n *\n * Note: Returns the single stored key for all environments.\n * The environment parameter is kept for API compatibility but is ignored.\n */\nexport async function getPrivateKey(): Promise<Hex | null> {\n const entry = new AsyncEntry(SERVICE_NAME, ACCOUNT_NAME);\n try {\n const key = await entry.getPassword();\n if (key && validatePrivateKey(key)) {\n return key as Hex;\n }\n } catch {\n // Key not found\n }\n\n return null;\n}\n\n/**\n * Delete a private key from OS keyring\n * Returns true if deletion was successful, false otherwise\n *\n * Note: Deletes the single stored key.\n * The environment parameter is kept for API compatibility but is ignored.\n */\nexport async function deletePrivateKey(): Promise<boolean> {\n const entry = new AsyncEntry(SERVICE_NAME, ACCOUNT_NAME);\n try {\n await entry.deletePassword();\n return true;\n } catch {\n console.warn(\"No key found in keyring\");\n return false;\n }\n}\n\n/**\n * List all stored keys\n * Returns an array with the single stored key (if it exists)\n */\nexport async function listStoredKeys(): Promise<StoredKey[]> {\n const keys: StoredKey[] = [];\n\n const creds = findCredentials(SERVICE_NAME);\n for (const cred of creds) {\n if (cred.account === ACCOUNT_NAME) {\n try {\n const address = getAddressFromPrivateKey(cred.password as Hex);\n keys.push({ address });\n } catch (err) {\n console.warn(`Warning: Invalid key found, skipping: ${err}`);\n }\n }\n }\n\n return keys;\n}\n\n/**\n * Check if a key exists\n *\n * Note: Checks for the single stored key.\n * The environment parameter is kept for API compatibility but is ignored.\n */\nexport async function keyExists(): Promise<boolean> {\n const key = await getPrivateKey();\n return key !== null;\n}\n\n/**\n * Get legacy keys from eigenx-cli\n * Returns an array of keys found in eigenx-cli keyring formats\n */\nexport async function getLegacyKeys(): Promise<LegacyKey[]> {\n const keys: LegacyKey[] = [];\n\n // 1. Check eigenx-cli production keys\n try {\n const eigenxCreds = findCredentials(EIGENX_SERVICE_NAME);\n for (const cred of eigenxCreds) {\n // eigenx-cli stores keys with account name \"eigenx-<environment>\"\n // Strip the prefix to get the environment name\n const accountName = cred.account;\n if (!accountName.startsWith(EIGENX_ACCOUNT_PREFIX)) {\n continue; // Skip if it doesn't have the expected prefix\n }\n const environment = accountName.substring(EIGENX_ACCOUNT_PREFIX.length);\n\n try {\n // Decode go-keyring encoding (used on macOS)\n const decodedKey = decodeGoKeyringValue(cred.password);\n const address = getAddressFromPrivateKey(decodedKey as Hex);\n keys.push({ environment, address, source: \"eigenx\" });\n } catch (err) {\n console.warn(\n `Warning: Invalid key found for ${environment} (eigenx-cli), skipping: ${err}`,\n );\n }\n }\n } catch {\n // eigenx-cli service not found, that's ok\n }\n\n // 2. Check eigenx-cli dev keys\n try {\n const eigenxDevCreds = findCredentials(EIGENX_DEV_SERVICE_NAME);\n for (const cred of eigenxDevCreds) {\n // eigenx-cli stores keys with account name \"eigenx-<environment>\"\n // Strip the prefix to get the environment name\n const accountName = cred.account;\n if (!accountName.startsWith(EIGENX_ACCOUNT_PREFIX)) {\n continue; // Skip if it doesn't have the expected prefix\n }\n const environment = accountName.substring(EIGENX_ACCOUNT_PREFIX.length);\n\n try {\n // Decode go-keyring encoding (used on macOS)\n const decodedKey = decodeGoKeyringValue(cred.password);\n const address = getAddressFromPrivateKey(decodedKey as Hex);\n keys.push({ environment, address, source: \"eigenx-dev\" });\n } catch (err) {\n console.warn(\n `Warning: Invalid key found for ${environment} (eigenx-dev), skipping: ${err}`,\n );\n }\n }\n } catch {\n // eigenx-dev service not found, that's ok\n }\n\n return keys;\n}\n\n/**\n * Get a specific legacy private key from eigenx-cli keyring\n */\nexport async function getLegacyPrivateKey(\n environment: string,\n source: \"eigenx\" | \"eigenx-dev\",\n): Promise<string | null> {\n const serviceName = source === \"eigenx\" ? EIGENX_SERVICE_NAME : EIGENX_DEV_SERVICE_NAME;\n\n // eigenx-cli stores keys with account name \"eigenx-<environment>\"\n const accountName = EIGENX_ACCOUNT_PREFIX + environment;\n\n const entry = new AsyncEntry(serviceName, accountName);\n try {\n const rawKey = await entry.getPassword();\n if (rawKey) {\n // Decode go-keyring encoding (used on macOS)\n const decodedKey = decodeGoKeyringValue(rawKey);\n if (validatePrivateKey(decodedKey)) {\n return decodedKey;\n }\n }\n } catch {\n // Key not found\n }\n\n return null;\n}\n\n/**\n * Delete a specific legacy private key from eigenx-cli keyring\n * Returns true if deletion was successful, false otherwise\n */\nexport async function deleteLegacyPrivateKey(\n environment: string,\n source: \"eigenx\" | \"eigenx-dev\",\n): Promise<boolean> {\n const serviceName = source === \"eigenx\" ? EIGENX_SERVICE_NAME : EIGENX_DEV_SERVICE_NAME;\n\n // eigenx-cli stores keys with account name \"eigenx-<environment>\"\n const accountName = EIGENX_ACCOUNT_PREFIX + environment;\n\n const entry = new AsyncEntry(serviceName, accountName);\n try {\n await entry.deletePassword();\n return true;\n } catch {\n console.warn(`No key found for ${environment} in ${source}`);\n return false;\n }\n}\n\n/**\n * Validate private key format\n */\nexport function validatePrivateKey(privateKey: string): boolean {\n try {\n getAddressFromPrivateKey(privateKey);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Get address from private key\n */\nexport function getAddressFromPrivateKey(privateKey: string): string {\n const normalized = normalizePrivateKey(privateKey);\n return privateKeyToAddress(normalized);\n}\n\n/**\n * Decode go-keyring encoded values\n *\n * go-keyring (used by eigenx-cli) stores values with special encoding on macOS:\n * - \"go-keyring-base64:\" prefix + base64-encoded value\n * - \"go-keyring-encoded:\" prefix + hex-encoded value (legacy)\n *\n * This function detects and decodes these formats.\n */\nfunction decodeGoKeyringValue(rawValue: string): string {\n // Check for base64 encoding (primary format)\n if (rawValue.startsWith(GO_KEYRING_BASE64_PREFIX)) {\n const encoded = rawValue.substring(GO_KEYRING_BASE64_PREFIX.length);\n try {\n // Decode base64\n const decoded = Buffer.from(encoded, \"base64\").toString(\"utf8\");\n return decoded;\n } catch (err) {\n console.warn(`Warning: Failed to decode go-keyring base64 value: ${err}`);\n return rawValue; // Return as-is if decoding fails\n }\n }\n\n // Check for hex encoding (legacy format)\n if (rawValue.startsWith(GO_KEYRING_ENCODED_PREFIX)) {\n const encoded = rawValue.substring(GO_KEYRING_ENCODED_PREFIX.length);\n try {\n // Decode hex\n const decoded = Buffer.from(encoded, \"hex\").toString(\"utf8\");\n return decoded;\n } catch (err) {\n console.warn(`Warning: Failed to decode go-keyring hex value: ${err}`);\n return rawValue; // Return as-is if decoding fails\n }\n }\n\n // No encoding detected, return as-is\n return rawValue;\n}\n\n/**\n * Normalize private key (ensure 0x prefix)\n */\nfunction normalizePrivateKey(privateKey: string): Hex {\n if (!privateKey.startsWith(\"0x\")) {\n return `0x${privateKey}`;\n }\n return privateKey as Hex;\n}\n","/**\n * Private Key Resolution\n *\n * Implements 3-tier priority system for private key retrieval:\n * 1. Command-line flag (--private-key)\n * 2. Environment variable (ECLOUD_PRIVATE_KEY)\n * 3. OS keyring (stored via `ecloud auth login`)\n */\n\nimport { Hex } from \"viem\";\nimport { getPrivateKey, validatePrivateKey } from \"./keyring\";\n\nexport interface PrivateKeySource {\n key: Hex;\n source: string;\n}\n\n/**\n * Get private key from any available source\n *\n * Priority order:\n * 1. Direct parameter (from --private-key flag)\n * 2. Environment variable (ECLOUD_PRIVATE_KEY)\n * 3. OS keyring (single key for all environments)\n *\n * Returns null if no key found\n */\nexport async function getPrivateKeyWithSource(options: {\n privateKey?: string; // From flag\n}): Promise<PrivateKeySource | null> {\n // 1. Check direct parameter (flag)\n if (options.privateKey) {\n if (!validatePrivateKey(options.privateKey)) {\n throw new Error(\n \"Invalid private key format provided via command flag. Please check and try again.\",\n );\n }\n return {\n key: options.privateKey as Hex,\n source: \"command flag\",\n };\n }\n\n // 2. Check environment variable\n const envKey = process.env.ECLOUD_PRIVATE_KEY as Hex;\n if (envKey) {\n if (!validatePrivateKey(envKey)) {\n throw new Error(\n \"Invalid private key format provided via environment variable. Please check and try again.\",\n );\n }\n return {\n key: envKey,\n source: \"environment variable (ECLOUD_PRIVATE_KEY)\",\n };\n }\n\n // 3. Check OS keyring (single key for all environments)\n const keyringKey = await getPrivateKey();\n if (keyringKey) {\n return {\n key: keyringKey,\n source: \"stored credentials\",\n };\n }\n\n return null;\n}\n\n/**\n * Get private key with source or throw error\n */\nexport async function requirePrivateKey(options: {\n privateKey?: string;\n}): Promise<PrivateKeySource> {\n const result = await getPrivateKeyWithSource({\n privateKey: options.privateKey,\n });\n\n if (!result) {\n throw new Error(\n `Private key required. Please provide it via:\\n` +\n ` • Keyring: ecloud auth login\\n` +\n ` • Flag: --private-key YOUR_KEY\\n` +\n ` • Environment: export ECLOUD_PRIVATE_KEY=YOUR_KEY`,\n );\n }\n\n return result;\n}\n","/**\n * Private Key Generation\n *\n * Generate new secp256k1 private keys for Ethereum\n */\n\nimport { generatePrivateKey, privateKeyToAddress } from \"viem/accounts\";\n\nexport interface GeneratedKey {\n privateKey: string;\n address: string;\n}\n\n/**\n * Generate a new secp256k1 private key\n */\nexport function generateNewPrivateKey(): GeneratedKey {\n const privateKey = generatePrivateKey();\n const address = privateKeyToAddress(privateKey);\n\n return {\n privateKey,\n address,\n };\n}\n","/**\n * BillingAPI Client to manage product subscriptions\n * Standalone client - does not depend on chain infrastructure\n */\n\nimport axios, { AxiosResponse } from \"axios\";\nimport { Hex } from \"viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport { ProductID, CreateSubscriptionResponse, ProductSubscriptionResponse } from \"../types\";\nimport { calculateBillingAuthSignature } from \"./auth\";\nimport { BillingEnvironmentConfig } from \"../types\";\n\nexport class BillingApiClient {\n private readonly account: ReturnType<typeof privateKeyToAccount>;\n private readonly config: BillingEnvironmentConfig;\n\n constructor(config: BillingEnvironmentConfig, privateKey: Hex) {\n this.account = privateKeyToAccount(privateKey);\n this.config = config;\n }\n\n async createSubscription(productId: ProductID = \"compute\"): Promise<CreateSubscriptionResponse> {\n const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;\n const resp = await this.makeAuthenticatedRequest(endpoint, \"POST\", productId);\n return resp.json();\n }\n\n async getSubscription(productId: ProductID = \"compute\"): Promise<ProductSubscriptionResponse> {\n const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;\n const resp = await this.makeAuthenticatedRequest(endpoint, \"GET\", productId);\n return resp.json();\n }\n\n async cancelSubscription(productId: ProductID = \"compute\"): Promise<void> {\n const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;\n await this.makeAuthenticatedRequest(endpoint, \"DELETE\", productId);\n }\n\n /**\n * Make an authenticated request to the billing API\n */\n private async makeAuthenticatedRequest(\n url: string,\n method: \"GET\" | \"POST\" | \"DELETE\",\n productId: ProductID,\n ): Promise<{ json: () => Promise<any>; text: () => Promise<string> }> {\n // Calculate expiry (5 minutes from now)\n const expiry = BigInt(Math.floor(Date.now() / 1000) + 5 * 60);\n\n // Use EIP-712 typed data signature for billing auth\n const { signature } = await calculateBillingAuthSignature({\n account: this.account,\n product: productId,\n expiry,\n });\n\n // Prepare headers\n const headers: Record<string, string> = {\n Authorization: `Bearer ${signature}`,\n \"X-Account\": this.account.address,\n \"X-Expiry\": expiry.toString(),\n };\n\n try {\n // Use axios to make the request\n const response: AxiosResponse = await axios({\n method,\n url,\n headers,\n timeout: 30_000,\n maxRedirects: 0,\n validateStatus: () => true, // Don't throw on any status\n });\n\n const status = response.status;\n const statusText = status >= 200 && status < 300 ? \"OK\" : \"Error\";\n\n if (status < 200 || status >= 300) {\n const body =\n typeof response.data === \"string\" ? response.data : JSON.stringify(response.data);\n throw new Error(`BillingAPI request failed: ${status} ${statusText} - ${body}`);\n }\n\n // Return Response-like object for compatibility\n return {\n json: async () => response.data,\n text: async () =>\n typeof response.data === \"string\" ? response.data : JSON.stringify(response.data),\n };\n } catch (error: any) {\n // Handle network errors\n if (\n error.message?.includes(\"fetch failed\") ||\n error.message?.includes(\"ECONNREFUSED\") ||\n error.message?.includes(\"ENOTFOUND\") ||\n error.cause\n ) {\n const cause = error.cause?.message || error.cause || error.message;\n throw new Error(\n `Failed to connect to BillingAPI at ${url}: ${cause}\\n` +\n `Please check:\\n` +\n `1. Your internet connection\\n` +\n `2. The API server is accessible: ${this.config.billingApiServerURL}\\n` +\n `3. Firewall/proxy settings`,\n );\n }\n // Re-throw other errors as-is\n throw error;\n }\n }\n}\n","/**\n * Main Billing namespace entry point\n */\n\nimport { BillingApiClient } from \"../../common/utils/billingapi\";\nimport { getBillingEnvironmentConfig, getBuildType } from \"../../common/config/environment\";\nimport { getLogger, isSubscriptionActive, addHexPrefix } from \"../../common/utils\";\nimport { getAddressFromPrivateKey } from \"../../common/auth\";\nimport { withSDKTelemetry } from \"../../common/telemetry/wrapper\";\n\nimport type { Address, Hex } from \"viem\";\nimport type {\n ProductID,\n SubscriptionOpts,\n SubscribeResponse,\n CancelResponse,\n ProductSubscriptionResponse,\n} from \"../../common/types\";\n\nexport interface BillingModule {\n address: Address;\n subscribe: (opts?: SubscriptionOpts) => Promise<SubscribeResponse>;\n getStatus: (opts?: SubscriptionOpts) => Promise<ProductSubscriptionResponse>;\n cancel: (opts?: SubscriptionOpts) => Promise<CancelResponse>;\n}\n\nexport interface BillingModuleConfig {\n verbose?: boolean;\n privateKey: Hex;\n skipTelemetry?: boolean; // Skip telemetry when called from CLI\n}\n\nexport function createBillingModule(config: BillingModuleConfig): BillingModule {\n const { verbose = false, skipTelemetry = false } = config;\n const privateKey = addHexPrefix(config.privateKey);\n const address = getAddressFromPrivateKey(privateKey) as Address;\n\n const logger = getLogger(verbose);\n\n // Get billing environment configuration\n const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());\n\n // Create billing API client\n const billingApi = new BillingApiClient(billingEnvConfig, privateKey);\n\n return {\n address,\n async subscribe(opts) {\n return withSDKTelemetry(\n {\n functionName: \"subscribe\",\n skipTelemetry: skipTelemetry, // Skip if called from CLI\n properties: { productId: opts?.productId || \"compute\" },\n },\n async () => {\n const productId: ProductID = opts?.productId || \"compute\";\n\n // Check existing subscription status first\n logger.debug(`Checking existing subscription for ${productId}...`);\n const currentStatus = await billingApi.getSubscription(productId);\n\n // If already active or trialing, don't create new checkout\n if (isSubscriptionActive(currentStatus.subscriptionStatus)) {\n logger.debug(`Subscription already active: ${currentStatus.subscriptionStatus}`);\n return {\n type: \"already_active\" as const,\n status: currentStatus.subscriptionStatus,\n };\n }\n\n // If subscription has payment issues, return portal URL instead\n if (\n currentStatus.subscriptionStatus === \"past_due\" ||\n currentStatus.subscriptionStatus === \"unpaid\"\n ) {\n logger.debug(`Subscription has payment issue: ${currentStatus.subscriptionStatus}`);\n return {\n type: \"payment_issue\" as const,\n status: currentStatus.subscriptionStatus,\n portalUrl: currentStatus.portalUrl,\n };\n }\n\n // Create new checkout session\n logger.debug(`Creating subscription for ${productId}...`);\n const result = await billingApi.createSubscription(productId);\n\n logger.debug(`Checkout URL: ${result.checkoutUrl}`);\n return {\n type: \"checkout_created\" as const,\n checkoutUrl: result.checkoutUrl,\n };\n },\n );\n },\n\n async getStatus(opts) {\n return withSDKTelemetry(\n {\n functionName: \"getStatus\",\n skipTelemetry: skipTelemetry, // Skip if called from CLI\n properties: { productId: opts?.productId || \"compute\" },\n },\n async () => {\n const productId: ProductID = opts?.productId || \"compute\";\n logger.debug(`Fetching subscription status for ${productId}...`);\n\n const result = await billingApi.getSubscription(productId);\n\n logger.debug(`Subscription status: ${result.subscriptionStatus}`);\n return result;\n },\n );\n },\n\n async cancel(opts) {\n return withSDKTelemetry(\n {\n functionName: \"cancel\",\n skipTelemetry: skipTelemetry, // Skip if called from CLI\n properties: { productId: opts?.productId || \"compute\" },\n },\n async () => {\n const productId: ProductID = opts?.productId || \"compute\";\n\n // Check existing subscription status first\n logger.debug(`Checking subscription status for ${productId}...`);\n const currentStatus = await billingApi.getSubscription(productId);\n\n // If no active subscription, don't attempt to cancel\n if (!isSubscriptionActive(currentStatus.subscriptionStatus)) {\n logger.debug(`No active subscription to cancel: ${currentStatus.subscriptionStatus}`);\n return {\n type: \"no_active_subscription\" as const,\n status: currentStatus.subscriptionStatus,\n };\n }\n\n // Cancel the subscription\n logger.debug(`Canceling subscription for ${productId}...`);\n await billingApi.cancelSubscription(productId);\n\n logger.debug(`Subscription canceled successfully`);\n return {\n type: \"canceled\" as const,\n };\n },\n );\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAS,YAAY,uBAAuB;AAE5C,SAAS,2BAA2B;AAGpC,IAAM,eAAe;AACrB,IAAM,eAAe;AAGrB,IAAM,sBAAsB;AAC5B,IAAM,0BAA0B;AAChC,IAAM,wBAAwB;AAG9B,IAAM,2BAA2B;AACjC,IAAM,4BAA4B;AAkBlC,eAAsB,gBAAgB,YAAmC;AAEvE,QAAM,gBAAgB,oBAAoB,UAAU;AAGpD,QAAM,UAAU,mBAAmB,aAAa;AAChD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AAGA,QAAM,QAAQ,IAAI,WAAW,cAAc,YAAY;AACvD,MAAI;AACF,UAAM,MAAM,YAAY,aAAa;AAAA,EACvC,SAAS,KAAU;AACjB,UAAM,IAAI;AAAA,MACR,sCAAsC,KAAK,WAAW,GAAG;AAAA,IAC3D;AAAA,EACF;AACF;AAQA,eAAsB,gBAAqC;AACzD,QAAM,QAAQ,IAAI,WAAW,cAAc,YAAY;AAC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