@layr-labs/ecloud-sdk 0.2.1-dev → 0.2.2-dev
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 +13 -5
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.d.cts +1 -1
- package/dist/billing.d.ts +1 -1
- package/dist/billing.js +13 -5
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +2106 -62
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +202 -5
- package/dist/browser.d.ts +202 -5
- package/dist/browser.js +2069 -67
- package/dist/browser.js.map +1 -1
- package/dist/{compute-B85ikS78.d.ts → compute-BYhSs8en.d.ts} +1 -1
- package/dist/{compute-CC0R7HEu.d.cts → compute-Bpjb3hYD.d.cts} +1 -1
- package/dist/compute.cjs +237 -22
- 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 +238 -27
- package/dist/compute.js.map +1 -1
- package/dist/helpers-CEvhJz7f.d.cts +742 -0
- package/dist/helpers-CQuBwQnu.d.ts +742 -0
- package/dist/{index-D5oW73Dx.d.cts → index-DeQzn_yM.d.cts} +309 -2
- package/dist/{index-D5oW73Dx.d.ts → index-DeQzn_yM.d.ts} +309 -2
- package/dist/index.cjs +394 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -88
- package/dist/index.d.ts +8 -88
- package/dist/index.js +384 -49
- package/dist/index.js.map +1 -1
- package/package.json +12 -2
- package/dist/eip7702-CXCYfOnk.d.ts +0 -400
- package/dist/eip7702-DeqoCP5b.d.cts +0 -400
package/dist/index.js
CHANGED
|
@@ -1101,6 +1101,18 @@ function extractRegistryNameNoDocker(imageRef) {
|
|
|
1101
1101
|
// src/client/common/contract/eip7702.ts
|
|
1102
1102
|
import { encodeFunctionData, encodeAbiParameters, decodeErrorResult } from "viem";
|
|
1103
1103
|
|
|
1104
|
+
// src/client/common/types/index.ts
|
|
1105
|
+
var noopLogger = {
|
|
1106
|
+
debug: () => {
|
|
1107
|
+
},
|
|
1108
|
+
info: () => {
|
|
1109
|
+
},
|
|
1110
|
+
warn: () => {
|
|
1111
|
+
},
|
|
1112
|
+
error: () => {
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1104
1116
|
// src/client/common/abis/ERC7702Delegator.json
|
|
1105
1117
|
var ERC7702Delegator_default = [
|
|
1106
1118
|
{
|
|
@@ -2186,7 +2198,7 @@ async function checkERC7702Delegation(publicClient, account, delegatorAddress) {
|
|
|
2186
2198
|
const expectedCode = `0xef0100${delegatorAddress.slice(2)}`;
|
|
2187
2199
|
return code.toLowerCase() === expectedCode.toLowerCase();
|
|
2188
2200
|
}
|
|
2189
|
-
async function executeBatch(options, logger) {
|
|
2201
|
+
async function executeBatch(options, logger = noopLogger) {
|
|
2190
2202
|
const { walletClient, publicClient, environmentConfig, executions, pendingMessage, gas } = options;
|
|
2191
2203
|
const account = walletClient.account;
|
|
2192
2204
|
if (!account) {
|
|
@@ -2270,11 +2282,7 @@ async function executeBatch(options, logger) {
|
|
|
2270
2282
|
}
|
|
2271
2283
|
|
|
2272
2284
|
// src/client/common/contract/caller.ts
|
|
2273
|
-
import {
|
|
2274
|
-
encodeFunctionData as encodeFunctionData2,
|
|
2275
|
-
decodeErrorResult as decodeErrorResult2,
|
|
2276
|
-
bytesToHex
|
|
2277
|
-
} from "viem";
|
|
2285
|
+
import { encodeFunctionData as encodeFunctionData2, decodeErrorResult as decodeErrorResult2, bytesToHex } from "viem";
|
|
2278
2286
|
|
|
2279
2287
|
// src/client/common/utils/helpers.ts
|
|
2280
2288
|
import { extractChain, createPublicClient, createWalletClient, http } from "viem";
|
|
@@ -3895,7 +3903,7 @@ async function calculateAppID(options) {
|
|
|
3895
3903
|
});
|
|
3896
3904
|
return appID;
|
|
3897
3905
|
}
|
|
3898
|
-
async function prepareDeployBatch(options, logger) {
|
|
3906
|
+
async function prepareDeployBatch(options, logger = noopLogger) {
|
|
3899
3907
|
const { walletClient, publicClient, environmentConfig, salt, release, publicLogs } = options;
|
|
3900
3908
|
const account = walletClient.account;
|
|
3901
3909
|
if (!account) {
|
|
@@ -3975,7 +3983,7 @@ async function prepareDeployBatch(options, logger) {
|
|
|
3975
3983
|
environmentConfig
|
|
3976
3984
|
};
|
|
3977
3985
|
}
|
|
3978
|
-
async function executeDeployBatch(data, context, gas, logger) {
|
|
3986
|
+
async function executeDeployBatch(data, context, gas, logger = noopLogger) {
|
|
3979
3987
|
const pendingMessage = "Deploying new app...";
|
|
3980
3988
|
const txHash = await executeBatch(
|
|
3981
3989
|
{
|
|
@@ -3990,7 +3998,7 @@ async function executeDeployBatch(data, context, gas, logger) {
|
|
|
3990
3998
|
);
|
|
3991
3999
|
return { appId: data.appId, txHash };
|
|
3992
4000
|
}
|
|
3993
|
-
async function deployApp(options, logger) {
|
|
4001
|
+
async function deployApp(options, logger = noopLogger) {
|
|
3994
4002
|
const prepared = await prepareDeployBatch(options, logger);
|
|
3995
4003
|
const data = {
|
|
3996
4004
|
appId: prepared.appId,
|
|
@@ -4005,7 +4013,15 @@ async function deployApp(options, logger) {
|
|
|
4005
4013
|
return executeDeployBatch(data, context, options.gas, logger);
|
|
4006
4014
|
}
|
|
4007
4015
|
async function prepareUpgradeBatch(options) {
|
|
4008
|
-
const {
|
|
4016
|
+
const {
|
|
4017
|
+
walletClient,
|
|
4018
|
+
publicClient,
|
|
4019
|
+
environmentConfig,
|
|
4020
|
+
appID,
|
|
4021
|
+
release,
|
|
4022
|
+
publicLogs,
|
|
4023
|
+
needsPermissionChange
|
|
4024
|
+
} = options;
|
|
4009
4025
|
const releaseForViem = {
|
|
4010
4026
|
rmsRelease: {
|
|
4011
4027
|
artifacts: release.rmsRelease.artifacts.map((artifact) => ({
|
|
@@ -4078,7 +4094,7 @@ async function prepareUpgradeBatch(options) {
|
|
|
4078
4094
|
environmentConfig
|
|
4079
4095
|
};
|
|
4080
4096
|
}
|
|
4081
|
-
async function executeUpgradeBatch(data, context, gas, logger) {
|
|
4097
|
+
async function executeUpgradeBatch(data, context, gas, logger = noopLogger) {
|
|
4082
4098
|
const pendingMessage = `Upgrading app ${data.appId}...`;
|
|
4083
4099
|
const txHash = await executeBatch(
|
|
4084
4100
|
{
|
|
@@ -4093,7 +4109,7 @@ async function executeUpgradeBatch(data, context, gas, logger) {
|
|
|
4093
4109
|
);
|
|
4094
4110
|
return txHash;
|
|
4095
4111
|
}
|
|
4096
|
-
async function upgradeApp(options, logger) {
|
|
4112
|
+
async function upgradeApp(options, logger = noopLogger) {
|
|
4097
4113
|
const prepared = await prepareUpgradeBatch(options);
|
|
4098
4114
|
const data = {
|
|
4099
4115
|
appId: prepared.appId,
|
|
@@ -4106,8 +4122,18 @@ async function upgradeApp(options, logger) {
|
|
|
4106
4122
|
};
|
|
4107
4123
|
return executeUpgradeBatch(data, context, options.gas, logger);
|
|
4108
4124
|
}
|
|
4109
|
-
async function sendAndWaitForTransaction(options, logger) {
|
|
4110
|
-
const {
|
|
4125
|
+
async function sendAndWaitForTransaction(options, logger = noopLogger) {
|
|
4126
|
+
const {
|
|
4127
|
+
walletClient,
|
|
4128
|
+
publicClient,
|
|
4129
|
+
environmentConfig,
|
|
4130
|
+
to,
|
|
4131
|
+
data,
|
|
4132
|
+
value = 0n,
|
|
4133
|
+
pendingMessage,
|
|
4134
|
+
txDescription,
|
|
4135
|
+
gas
|
|
4136
|
+
} = options;
|
|
4111
4137
|
const account = walletClient.account;
|
|
4112
4138
|
if (!account) {
|
|
4113
4139
|
throw new Error("WalletClient must have an account attached");
|
|
@@ -4227,7 +4253,13 @@ async function getAllAppsByDeveloper(publicClient, env, developer, pageSize = 10
|
|
|
4227
4253
|
const allApps = [];
|
|
4228
4254
|
const allConfigs = [];
|
|
4229
4255
|
while (true) {
|
|
4230
|
-
const { apps, appConfigs } = await getAppsByDeveloper(
|
|
4256
|
+
const { apps, appConfigs } = await getAppsByDeveloper(
|
|
4257
|
+
publicClient,
|
|
4258
|
+
env,
|
|
4259
|
+
developer,
|
|
4260
|
+
offset,
|
|
4261
|
+
pageSize
|
|
4262
|
+
);
|
|
4231
4263
|
if (apps.length === 0) break;
|
|
4232
4264
|
allApps.push(...apps);
|
|
4233
4265
|
allConfigs.push(...appConfigs);
|
|
@@ -4283,7 +4315,7 @@ async function isDelegated(options) {
|
|
|
4283
4315
|
environmentConfig.erc7702DelegatorAddress
|
|
4284
4316
|
);
|
|
4285
4317
|
}
|
|
4286
|
-
async function undelegate(options, logger) {
|
|
4318
|
+
async function undelegate(options, logger = noopLogger) {
|
|
4287
4319
|
const { walletClient, publicClient, environmentConfig } = options;
|
|
4288
4320
|
const account = walletClient.account;
|
|
4289
4321
|
if (!account) {
|
|
@@ -4381,6 +4413,129 @@ async function calculateBillingAuthSignature(options) {
|
|
|
4381
4413
|
return { signature, expiry };
|
|
4382
4414
|
}
|
|
4383
4415
|
|
|
4416
|
+
// src/client/common/auth/session.ts
|
|
4417
|
+
var SessionError = class extends Error {
|
|
4418
|
+
constructor(message, code, statusCode) {
|
|
4419
|
+
super(message);
|
|
4420
|
+
this.code = code;
|
|
4421
|
+
this.statusCode = statusCode;
|
|
4422
|
+
this.name = "SessionError";
|
|
4423
|
+
}
|
|
4424
|
+
};
|
|
4425
|
+
function stripHexPrefix2(hex) {
|
|
4426
|
+
return hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
4427
|
+
}
|
|
4428
|
+
async function parseErrorResponse(response) {
|
|
4429
|
+
try {
|
|
4430
|
+
const data = await response.json();
|
|
4431
|
+
return data.error || response.statusText;
|
|
4432
|
+
} catch {
|
|
4433
|
+
return response.statusText;
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
async function loginToComputeApi(config, request) {
|
|
4437
|
+
let response;
|
|
4438
|
+
try {
|
|
4439
|
+
response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
|
|
4440
|
+
method: "POST",
|
|
4441
|
+
credentials: "include",
|
|
4442
|
+
// Include cookies for session management
|
|
4443
|
+
headers: {
|
|
4444
|
+
"Content-Type": "application/json"
|
|
4445
|
+
},
|
|
4446
|
+
body: JSON.stringify({
|
|
4447
|
+
message: request.message,
|
|
4448
|
+
signature: stripHexPrefix2(request.signature)
|
|
4449
|
+
})
|
|
4450
|
+
});
|
|
4451
|
+
} catch (error) {
|
|
4452
|
+
throw new SessionError(
|
|
4453
|
+
`Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
|
|
4454
|
+
"NETWORK_ERROR"
|
|
4455
|
+
);
|
|
4456
|
+
}
|
|
4457
|
+
if (!response.ok) {
|
|
4458
|
+
const errorMessage = await parseErrorResponse(response);
|
|
4459
|
+
const status = response.status;
|
|
4460
|
+
if (status === 400) {
|
|
4461
|
+
if (errorMessage.toLowerCase().includes("siwe")) {
|
|
4462
|
+
throw new SessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
|
|
4463
|
+
}
|
|
4464
|
+
throw new SessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
|
|
4465
|
+
}
|
|
4466
|
+
if (status === 401) {
|
|
4467
|
+
throw new SessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
|
|
4468
|
+
}
|
|
4469
|
+
throw new SessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
|
|
4470
|
+
}
|
|
4471
|
+
const data = await response.json();
|
|
4472
|
+
return {
|
|
4473
|
+
success: data.success,
|
|
4474
|
+
address: data.address
|
|
4475
|
+
};
|
|
4476
|
+
}
|
|
4477
|
+
async function getComputeApiSession(config) {
|
|
4478
|
+
let response;
|
|
4479
|
+
try {
|
|
4480
|
+
response = await fetch(`${config.baseUrl}/auth/session`, {
|
|
4481
|
+
method: "GET",
|
|
4482
|
+
credentials: "include",
|
|
4483
|
+
// Include cookies for session management
|
|
4484
|
+
headers: {
|
|
4485
|
+
"Content-Type": "application/json"
|
|
4486
|
+
}
|
|
4487
|
+
});
|
|
4488
|
+
} catch {
|
|
4489
|
+
return {
|
|
4490
|
+
authenticated: false
|
|
4491
|
+
};
|
|
4492
|
+
}
|
|
4493
|
+
if (response.status === 401) {
|
|
4494
|
+
return {
|
|
4495
|
+
authenticated: false
|
|
4496
|
+
};
|
|
4497
|
+
}
|
|
4498
|
+
if (!response.ok) {
|
|
4499
|
+
const errorMessage = await parseErrorResponse(response);
|
|
4500
|
+
throw new SessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
|
|
4501
|
+
}
|
|
4502
|
+
const data = await response.json();
|
|
4503
|
+
return {
|
|
4504
|
+
authenticated: data.authenticated,
|
|
4505
|
+
address: data.address,
|
|
4506
|
+
chainId: data.chain_id
|
|
4507
|
+
};
|
|
4508
|
+
}
|
|
4509
|
+
async function logoutFromComputeApi(config) {
|
|
4510
|
+
let response;
|
|
4511
|
+
try {
|
|
4512
|
+
response = await fetch(`${config.baseUrl}/auth/logout`, {
|
|
4513
|
+
method: "POST",
|
|
4514
|
+
credentials: "include",
|
|
4515
|
+
// Include cookies for session management
|
|
4516
|
+
headers: {
|
|
4517
|
+
"Content-Type": "application/json"
|
|
4518
|
+
}
|
|
4519
|
+
});
|
|
4520
|
+
} catch (error) {
|
|
4521
|
+
throw new SessionError(
|
|
4522
|
+
`Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
|
|
4523
|
+
"NETWORK_ERROR"
|
|
4524
|
+
);
|
|
4525
|
+
}
|
|
4526
|
+
if (response.status === 401) {
|
|
4527
|
+
return;
|
|
4528
|
+
}
|
|
4529
|
+
if (!response.ok) {
|
|
4530
|
+
const errorMessage = await parseErrorResponse(response);
|
|
4531
|
+
throw new SessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
|
|
4532
|
+
}
|
|
4533
|
+
}
|
|
4534
|
+
async function isSessionValid(config) {
|
|
4535
|
+
const session = await getComputeApiSession(config);
|
|
4536
|
+
return session.authenticated;
|
|
4537
|
+
}
|
|
4538
|
+
|
|
4384
4539
|
// src/client/common/utils/userapi.ts
|
|
4385
4540
|
function isJsonObject(value) {
|
|
4386
4541
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -4398,15 +4553,16 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
|
|
|
4398
4553
|
var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
|
|
4399
4554
|
var CanUpdateAppProfilePermission = "0x036fef61";
|
|
4400
4555
|
function getDefaultClientId() {
|
|
4401
|
-
const version = true ? "0.2.
|
|
4556
|
+
const version = true ? "0.2.2-dev" : "0.0.0";
|
|
4402
4557
|
return `ecloud-sdk/v${version}`;
|
|
4403
4558
|
}
|
|
4404
4559
|
var UserApiClient = class {
|
|
4405
|
-
constructor(config, walletClient, publicClient,
|
|
4560
|
+
constructor(config, walletClient, publicClient, options) {
|
|
4406
4561
|
this.config = config;
|
|
4407
4562
|
this.walletClient = walletClient;
|
|
4408
4563
|
this.publicClient = publicClient;
|
|
4409
|
-
this.clientId = clientId || getDefaultClientId();
|
|
4564
|
+
this.clientId = options?.clientId || getDefaultClientId();
|
|
4565
|
+
this.useSession = options?.useSession ?? false;
|
|
4410
4566
|
}
|
|
4411
4567
|
/**
|
|
4412
4568
|
* Get the address of the connected wallet
|
|
@@ -4494,7 +4650,7 @@ var UserApiClient = class {
|
|
|
4494
4650
|
const apps = result.apps || result.Apps || [];
|
|
4495
4651
|
return apps.map((app, i) => ({
|
|
4496
4652
|
address: app.address || appIDs[i],
|
|
4497
|
-
status: app.
|
|
4653
|
+
status: app.app_status || app.App_Status || ""
|
|
4498
4654
|
}));
|
|
4499
4655
|
}
|
|
4500
4656
|
/**
|
|
@@ -4526,9 +4682,11 @@ var UserApiClient = class {
|
|
|
4526
4682
|
const headers = {
|
|
4527
4683
|
"x-client-id": this.clientId
|
|
4528
4684
|
};
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4685
|
+
if (!this.useSession) {
|
|
4686
|
+
const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
|
|
4687
|
+
const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
|
|
4688
|
+
Object.assign(headers, authHeaders);
|
|
4689
|
+
}
|
|
4532
4690
|
try {
|
|
4533
4691
|
const response = await axios.post(endpoint, formData, {
|
|
4534
4692
|
headers,
|
|
@@ -4537,8 +4695,10 @@ var UserApiClient = class {
|
|
|
4537
4695
|
// Don't throw on any status
|
|
4538
4696
|
maxContentLength: Infinity,
|
|
4539
4697
|
// Allow large file uploads
|
|
4540
|
-
maxBodyLength: Infinity
|
|
4698
|
+
maxBodyLength: Infinity,
|
|
4541
4699
|
// Allow large file uploads
|
|
4700
|
+
withCredentials: true
|
|
4701
|
+
// Include cookies for session auth
|
|
4542
4702
|
});
|
|
4543
4703
|
const status = response.status;
|
|
4544
4704
|
if (status !== 200 && status !== 201) {
|
|
@@ -4572,7 +4732,7 @@ Please check:
|
|
|
4572
4732
|
const headers = {
|
|
4573
4733
|
"x-client-id": this.clientId
|
|
4574
4734
|
};
|
|
4575
|
-
if (permission) {
|
|
4735
|
+
if (permission && !this.useSession) {
|
|
4576
4736
|
const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
|
|
4577
4737
|
const authHeaders = await this.generateAuthHeaders(permission, expiry);
|
|
4578
4738
|
Object.assign(headers, authHeaders);
|
|
@@ -4581,8 +4741,10 @@ Please check:
|
|
|
4581
4741
|
const response = await axios.get(url, {
|
|
4582
4742
|
headers,
|
|
4583
4743
|
maxRedirects: 0,
|
|
4584
|
-
validateStatus: () => true
|
|
4744
|
+
validateStatus: () => true,
|
|
4585
4745
|
// Don't throw on any status
|
|
4746
|
+
withCredentials: true
|
|
4747
|
+
// Include cookies for session auth
|
|
4586
4748
|
});
|
|
4587
4749
|
const status = response.status;
|
|
4588
4750
|
const statusText = status >= 200 && status < 300 ? "OK" : "Error";
|
|
@@ -4624,6 +4786,65 @@ Please check:
|
|
|
4624
4786
|
"X-eigenx-expiry": expiry.toString()
|
|
4625
4787
|
};
|
|
4626
4788
|
}
|
|
4789
|
+
// ==========================================================================
|
|
4790
|
+
// SIWE Session Management
|
|
4791
|
+
// ==========================================================================
|
|
4792
|
+
/**
|
|
4793
|
+
* Login to the compute API using SIWE (Sign-In with Ethereum)
|
|
4794
|
+
*
|
|
4795
|
+
* This establishes a session with the compute API by verifying the SIWE message
|
|
4796
|
+
* and signature. On success, a session cookie is set in the browser.
|
|
4797
|
+
*
|
|
4798
|
+
* @param request - Login request containing SIWE message and signature
|
|
4799
|
+
* @returns Login result with the authenticated address
|
|
4800
|
+
*
|
|
4801
|
+
* @example
|
|
4802
|
+
* ```typescript
|
|
4803
|
+
* import { createSiweMessage } from "@layr-labs/ecloud-sdk/browser";
|
|
4804
|
+
*
|
|
4805
|
+
* const { message } = createSiweMessage({
|
|
4806
|
+
* address: userAddress,
|
|
4807
|
+
* chainId: 11155111,
|
|
4808
|
+
* domain: window.location.host,
|
|
4809
|
+
* uri: window.location.origin,
|
|
4810
|
+
* });
|
|
4811
|
+
*
|
|
4812
|
+
* const signature = await signMessageAsync({ message });
|
|
4813
|
+
* const result = await client.siweLogin({ message, signature });
|
|
4814
|
+
* ```
|
|
4815
|
+
*/
|
|
4816
|
+
async siweLogin(request) {
|
|
4817
|
+
return loginToComputeApi({ baseUrl: this.config.userApiServerURL }, request);
|
|
4818
|
+
}
|
|
4819
|
+
/**
|
|
4820
|
+
* Logout from the compute API
|
|
4821
|
+
*
|
|
4822
|
+
* This destroys the current session and clears the session cookie.
|
|
4823
|
+
*
|
|
4824
|
+
* @example
|
|
4825
|
+
* ```typescript
|
|
4826
|
+
* await client.siweLogout();
|
|
4827
|
+
* ```
|
|
4828
|
+
*/
|
|
4829
|
+
async siweLogout() {
|
|
4830
|
+
return logoutFromComputeApi({ baseUrl: this.config.userApiServerURL });
|
|
4831
|
+
}
|
|
4832
|
+
/**
|
|
4833
|
+
* Get the current SIWE session status from the compute API
|
|
4834
|
+
*
|
|
4835
|
+
* @returns Session information including authentication status and address
|
|
4836
|
+
*
|
|
4837
|
+
* @example
|
|
4838
|
+
* ```typescript
|
|
4839
|
+
* const session = await client.getSiweSession();
|
|
4840
|
+
* if (session.authenticated) {
|
|
4841
|
+
* console.log(`Logged in as ${session.address}`);
|
|
4842
|
+
* }
|
|
4843
|
+
* ```
|
|
4844
|
+
*/
|
|
4845
|
+
async getSiweSession() {
|
|
4846
|
+
return getComputeApiSession({ baseUrl: this.config.userApiServerURL });
|
|
4847
|
+
}
|
|
4627
4848
|
};
|
|
4628
4849
|
function transformAppReleaseBuild(raw) {
|
|
4629
4850
|
if (!isJsonObject(raw)) return void 0;
|
|
@@ -5255,9 +5476,13 @@ var BillingApiClient = class {
|
|
|
5255
5476
|
}
|
|
5256
5477
|
return account.address;
|
|
5257
5478
|
}
|
|
5258
|
-
async createSubscription(productId = "compute") {
|
|
5479
|
+
async createSubscription(productId = "compute", options) {
|
|
5259
5480
|
const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
|
|
5260
|
-
const
|
|
5481
|
+
const body = options ? {
|
|
5482
|
+
success_url: options.successUrl,
|
|
5483
|
+
cancel_url: options.cancelUrl
|
|
5484
|
+
} : void 0;
|
|
5485
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "POST", productId, body);
|
|
5261
5486
|
return resp.json();
|
|
5262
5487
|
}
|
|
5263
5488
|
async getSubscription(productId = "compute") {
|
|
@@ -5272,7 +5497,7 @@ var BillingApiClient = class {
|
|
|
5272
5497
|
/**
|
|
5273
5498
|
* Make an authenticated request to the billing API
|
|
5274
5499
|
*/
|
|
5275
|
-
async makeAuthenticatedRequest(url, method, productId) {
|
|
5500
|
+
async makeAuthenticatedRequest(url, method, productId, body) {
|
|
5276
5501
|
const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
|
|
5277
5502
|
const { signature } = await calculateBillingAuthSignature({
|
|
5278
5503
|
walletClient: this.walletClient,
|
|
@@ -5284,11 +5509,15 @@ var BillingApiClient = class {
|
|
|
5284
5509
|
"X-Account": this.address,
|
|
5285
5510
|
"X-Expiry": expiry.toString()
|
|
5286
5511
|
};
|
|
5512
|
+
if (body) {
|
|
5513
|
+
headers["Content-Type"] = "application/json";
|
|
5514
|
+
}
|
|
5287
5515
|
try {
|
|
5288
5516
|
const response = await axios2({
|
|
5289
5517
|
method,
|
|
5290
5518
|
url,
|
|
5291
5519
|
headers,
|
|
5520
|
+
data: body,
|
|
5292
5521
|
timeout: 3e4,
|
|
5293
5522
|
maxRedirects: 0,
|
|
5294
5523
|
validateStatus: () => true
|
|
@@ -5297,8 +5526,8 @@ var BillingApiClient = class {
|
|
|
5297
5526
|
const status = response.status;
|
|
5298
5527
|
const statusText = status >= 200 && status < 300 ? "OK" : "Error";
|
|
5299
5528
|
if (status < 200 || status >= 300) {
|
|
5300
|
-
const
|
|
5301
|
-
throw new Error(`BillingAPI request failed: ${status} ${statusText} - ${
|
|
5529
|
+
const body2 = typeof response.data === "string" ? response.data : JSON.stringify(response.data);
|
|
5530
|
+
throw new Error(`BillingAPI request failed: ${status} ${statusText} - ${body2}`);
|
|
5302
5531
|
}
|
|
5303
5532
|
return {
|
|
5304
5533
|
json: async () => response.data,
|
|
@@ -6784,7 +7013,7 @@ async function logs(options, walletClient, publicClient, environmentConfig, logg
|
|
|
6784
7013
|
environmentConfig,
|
|
6785
7014
|
walletClient,
|
|
6786
7015
|
publicClient,
|
|
6787
|
-
options.clientId
|
|
7016
|
+
options.clientId ? { clientId: options.clientId } : void 0
|
|
6788
7017
|
);
|
|
6789
7018
|
let logsText;
|
|
6790
7019
|
let logsError = null;
|
|
@@ -7083,7 +7312,7 @@ function createAppModule(ctx) {
|
|
|
7083
7312
|
environment,
|
|
7084
7313
|
walletClient,
|
|
7085
7314
|
publicClient,
|
|
7086
|
-
ctx.clientId
|
|
7315
|
+
ctx.clientId ? { clientId: ctx.clientId } : void 0
|
|
7087
7316
|
);
|
|
7088
7317
|
return userApiClient.uploadAppProfile(appId, profile.name, {
|
|
7089
7318
|
website: profile.website,
|
|
@@ -7342,6 +7571,37 @@ function createBillingModule(config) {
|
|
|
7342
7571
|
|
|
7343
7572
|
// src/client/common/utils/buildapi.ts
|
|
7344
7573
|
import axios3 from "axios";
|
|
7574
|
+
var MAX_RETRIES = 5;
|
|
7575
|
+
var INITIAL_BACKOFF_MS = 1e3;
|
|
7576
|
+
var MAX_BACKOFF_MS = 3e4;
|
|
7577
|
+
async function sleep2(ms) {
|
|
7578
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
7579
|
+
}
|
|
7580
|
+
function getRetryDelay(res, attempt) {
|
|
7581
|
+
const retryAfter = res.headers["retry-after"];
|
|
7582
|
+
if (retryAfter) {
|
|
7583
|
+
const seconds = parseInt(retryAfter, 10);
|
|
7584
|
+
if (!isNaN(seconds)) {
|
|
7585
|
+
return Math.min(seconds * 1e3, MAX_BACKOFF_MS);
|
|
7586
|
+
}
|
|
7587
|
+
}
|
|
7588
|
+
return Math.min(INITIAL_BACKOFF_MS * Math.pow(2, attempt), MAX_BACKOFF_MS);
|
|
7589
|
+
}
|
|
7590
|
+
async function requestWithRetry(config) {
|
|
7591
|
+
let lastResponse;
|
|
7592
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
7593
|
+
const res = await axios3({ ...config, validateStatus: () => true });
|
|
7594
|
+
lastResponse = res;
|
|
7595
|
+
if (res.status !== 429) {
|
|
7596
|
+
return res;
|
|
7597
|
+
}
|
|
7598
|
+
if (attempt < MAX_RETRIES) {
|
|
7599
|
+
const delay = getRetryDelay(res, attempt);
|
|
7600
|
+
await sleep2(delay);
|
|
7601
|
+
}
|
|
7602
|
+
}
|
|
7603
|
+
return lastResponse;
|
|
7604
|
+
}
|
|
7345
7605
|
var BuildApiClient = class {
|
|
7346
7606
|
constructor(options) {
|
|
7347
7607
|
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
@@ -7374,24 +7634,22 @@ var BuildApiClient = class {
|
|
|
7374
7634
|
return this.authenticatedTextRequest(`/builds/${encodeURIComponent(buildId)}/logs`);
|
|
7375
7635
|
}
|
|
7376
7636
|
async listBuilds(params) {
|
|
7377
|
-
const res = await
|
|
7637
|
+
const res = await requestWithRetry({
|
|
7378
7638
|
url: `${this.baseUrl}/builds`,
|
|
7379
7639
|
method: "GET",
|
|
7380
7640
|
params,
|
|
7381
7641
|
headers: this.clientId ? { "x-client-id": this.clientId } : void 0,
|
|
7382
|
-
timeout: 6e4
|
|
7383
|
-
validateStatus: () => true
|
|
7642
|
+
timeout: 6e4
|
|
7384
7643
|
});
|
|
7385
7644
|
if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
|
|
7386
7645
|
return res.data;
|
|
7387
7646
|
}
|
|
7388
7647
|
async publicJsonRequest(path8) {
|
|
7389
|
-
const res = await
|
|
7648
|
+
const res = await requestWithRetry({
|
|
7390
7649
|
url: `${this.baseUrl}${path8}`,
|
|
7391
7650
|
method: "GET",
|
|
7392
7651
|
headers: this.clientId ? { "x-client-id": this.clientId } : void 0,
|
|
7393
|
-
timeout: 6e4
|
|
7394
|
-
validateStatus: () => true
|
|
7652
|
+
timeout: 6e4
|
|
7395
7653
|
});
|
|
7396
7654
|
if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
|
|
7397
7655
|
return res.data;
|
|
@@ -7413,13 +7671,12 @@ var BuildApiClient = class {
|
|
|
7413
7671
|
headers.Authorization = `Bearer ${signature}`;
|
|
7414
7672
|
headers["X-eigenx-expiry"] = expiry.toString();
|
|
7415
7673
|
headers["X-Account"] = this.address;
|
|
7416
|
-
const res = await
|
|
7674
|
+
const res = await requestWithRetry({
|
|
7417
7675
|
url: `${this.baseUrl}${path8}`,
|
|
7418
7676
|
method,
|
|
7419
7677
|
headers,
|
|
7420
7678
|
data: body,
|
|
7421
|
-
timeout: 6e4
|
|
7422
|
-
validateStatus: () => true
|
|
7679
|
+
timeout: 6e4
|
|
7423
7680
|
});
|
|
7424
7681
|
if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
|
|
7425
7682
|
return res.data;
|
|
@@ -7439,13 +7696,12 @@ var BuildApiClient = class {
|
|
|
7439
7696
|
headers.Authorization = `Bearer ${signature}`;
|
|
7440
7697
|
headers["X-eigenx-expiry"] = expiry.toString();
|
|
7441
7698
|
headers["X-Account"] = this.address;
|
|
7442
|
-
const res = await
|
|
7699
|
+
const res = await requestWithRetry({
|
|
7443
7700
|
url: `${this.baseUrl}${path8}`,
|
|
7444
7701
|
method: "GET",
|
|
7445
7702
|
headers,
|
|
7446
7703
|
timeout: 6e4,
|
|
7447
|
-
responseType: "text"
|
|
7448
|
-
validateStatus: () => true
|
|
7704
|
+
responseType: "text"
|
|
7449
7705
|
});
|
|
7450
7706
|
if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
|
|
7451
7707
|
return typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
@@ -7634,7 +7890,7 @@ function createBuildModule(config) {
|
|
|
7634
7890
|
if (build.status === BUILD_STATUS.FAILED) {
|
|
7635
7891
|
throw new BuildFailedError(build.errorMessage ?? "Build failed", buildId);
|
|
7636
7892
|
}
|
|
7637
|
-
await
|
|
7893
|
+
await sleep3(pollIntervalMs);
|
|
7638
7894
|
}
|
|
7639
7895
|
},
|
|
7640
7896
|
async *streamLogs(buildId, pollIntervalMs = DEFAULT_POLL_INTERVAL) {
|
|
@@ -7656,12 +7912,12 @@ function createBuildModule(config) {
|
|
|
7656
7912
|
lastLength = logs2.length;
|
|
7657
7913
|
}
|
|
7658
7914
|
if (build.status !== BUILD_STATUS.BUILDING) break;
|
|
7659
|
-
await
|
|
7915
|
+
await sleep3(pollIntervalMs);
|
|
7660
7916
|
}
|
|
7661
7917
|
}
|
|
7662
7918
|
};
|
|
7663
7919
|
}
|
|
7664
|
-
function
|
|
7920
|
+
function sleep3(ms) {
|
|
7665
7921
|
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
7666
7922
|
}
|
|
7667
7923
|
function transformBuild(raw) {
|
|
@@ -7944,6 +8200,74 @@ function generateNewPrivateKey() {
|
|
|
7944
8200
|
};
|
|
7945
8201
|
}
|
|
7946
8202
|
|
|
8203
|
+
// src/client/common/auth/siwe.ts
|
|
8204
|
+
import { SiweMessage, generateNonce as siweGenerateNonce } from "siwe";
|
|
8205
|
+
var generateNonce = siweGenerateNonce;
|
|
8206
|
+
function createSiweMessage(params) {
|
|
8207
|
+
const now = /* @__PURE__ */ new Date();
|
|
8208
|
+
const nonce = params.nonce || generateNonce();
|
|
8209
|
+
const issuedAt = params.issuedAt || now;
|
|
8210
|
+
const expirationTime = params.expirationTime || new Date(now.getTime() + 24 * 60 * 60 * 1e3);
|
|
8211
|
+
const siweMessage = new SiweMessage({
|
|
8212
|
+
domain: params.domain,
|
|
8213
|
+
address: params.address,
|
|
8214
|
+
statement: params.statement,
|
|
8215
|
+
uri: params.uri,
|
|
8216
|
+
version: "1",
|
|
8217
|
+
chainId: params.chainId,
|
|
8218
|
+
nonce,
|
|
8219
|
+
issuedAt: issuedAt.toISOString(),
|
|
8220
|
+
expirationTime: expirationTime.toISOString(),
|
|
8221
|
+
notBefore: params.notBefore?.toISOString(),
|
|
8222
|
+
requestId: params.requestId,
|
|
8223
|
+
resources: params.resources
|
|
8224
|
+
});
|
|
8225
|
+
return {
|
|
8226
|
+
message: siweMessage.prepareMessage(),
|
|
8227
|
+
params: {
|
|
8228
|
+
address: params.address,
|
|
8229
|
+
chainId: params.chainId,
|
|
8230
|
+
domain: params.domain,
|
|
8231
|
+
uri: params.uri,
|
|
8232
|
+
nonce,
|
|
8233
|
+
issuedAt,
|
|
8234
|
+
statement: params.statement,
|
|
8235
|
+
expirationTime,
|
|
8236
|
+
notBefore: params.notBefore,
|
|
8237
|
+
requestId: params.requestId,
|
|
8238
|
+
resources: params.resources
|
|
8239
|
+
}
|
|
8240
|
+
};
|
|
8241
|
+
}
|
|
8242
|
+
function parseSiweMessage(message) {
|
|
8243
|
+
try {
|
|
8244
|
+
const siweMessage = new SiweMessage(message);
|
|
8245
|
+
return {
|
|
8246
|
+
address: siweMessage.address,
|
|
8247
|
+
chainId: siweMessage.chainId,
|
|
8248
|
+
domain: siweMessage.domain,
|
|
8249
|
+
uri: siweMessage.uri,
|
|
8250
|
+
nonce: siweMessage.nonce,
|
|
8251
|
+
statement: siweMessage.statement,
|
|
8252
|
+
issuedAt: siweMessage.issuedAt ? new Date(siweMessage.issuedAt) : void 0,
|
|
8253
|
+
expirationTime: siweMessage.expirationTime ? new Date(siweMessage.expirationTime) : void 0,
|
|
8254
|
+
notBefore: siweMessage.notBefore ? new Date(siweMessage.notBefore) : void 0,
|
|
8255
|
+
requestId: siweMessage.requestId,
|
|
8256
|
+
resources: siweMessage.resources
|
|
8257
|
+
};
|
|
8258
|
+
} catch {
|
|
8259
|
+
return null;
|
|
8260
|
+
}
|
|
8261
|
+
}
|
|
8262
|
+
function isSiweMessageExpired(params) {
|
|
8263
|
+
if (!params.expirationTime) return false;
|
|
8264
|
+
return /* @__PURE__ */ new Date() > params.expirationTime;
|
|
8265
|
+
}
|
|
8266
|
+
function isSiweMessageNotYetValid(params) {
|
|
8267
|
+
if (!params.notBefore) return false;
|
|
8268
|
+
return /* @__PURE__ */ new Date() < params.notBefore;
|
|
8269
|
+
}
|
|
8270
|
+
|
|
7947
8271
|
// src/client/common/utils/instance.ts
|
|
7948
8272
|
async function getCurrentInstanceType(preflightCtx, appID, logger, clientId) {
|
|
7949
8273
|
try {
|
|
@@ -7951,7 +8275,7 @@ async function getCurrentInstanceType(preflightCtx, appID, logger, clientId) {
|
|
|
7951
8275
|
preflightCtx.environmentConfig,
|
|
7952
8276
|
preflightCtx.walletClient,
|
|
7953
8277
|
preflightCtx.publicClient,
|
|
7954
|
-
clientId
|
|
8278
|
+
clientId ? { clientId } : void 0
|
|
7955
8279
|
);
|
|
7956
8280
|
const infos = await userApiClient.getInfos([appID], 1);
|
|
7957
8281
|
if (infos.length === 0) {
|
|
@@ -8014,6 +8338,7 @@ export {
|
|
|
8014
8338
|
NotFoundError,
|
|
8015
8339
|
PRIMARY_LANGUAGES,
|
|
8016
8340
|
PostHogClient,
|
|
8341
|
+
SessionError,
|
|
8017
8342
|
TimeoutError,
|
|
8018
8343
|
UserApiClient,
|
|
8019
8344
|
addHexPrefix,
|
|
@@ -8030,6 +8355,7 @@ export {
|
|
|
8030
8355
|
createComputeModule,
|
|
8031
8356
|
createECloudClient,
|
|
8032
8357
|
createMetricsContext,
|
|
8358
|
+
createSiweMessage,
|
|
8033
8359
|
createTelemetryClient,
|
|
8034
8360
|
createClients as createViemClients,
|
|
8035
8361
|
deleteLegacyPrivateKey,
|
|
@@ -8046,6 +8372,7 @@ export {
|
|
|
8046
8372
|
fetchTemplateCatalog,
|
|
8047
8373
|
formatETH,
|
|
8048
8374
|
generateNewPrivateKey,
|
|
8375
|
+
generateNonce,
|
|
8049
8376
|
getAddressFromPrivateKey,
|
|
8050
8377
|
getAllAppsByDeveloper,
|
|
8051
8378
|
getAppLatestReleaseBlockNumbers,
|
|
@@ -8056,6 +8383,7 @@ export {
|
|
|
8056
8383
|
getBuildType,
|
|
8057
8384
|
getCategoryDescriptions,
|
|
8058
8385
|
getChainFromID,
|
|
8386
|
+
getComputeApiSession,
|
|
8059
8387
|
getCurrentInstanceType,
|
|
8060
8388
|
getEnvironmentConfig,
|
|
8061
8389
|
getLegacyKeys,
|
|
@@ -8068,10 +8396,17 @@ export {
|
|
|
8068
8396
|
isEnvironmentAvailable,
|
|
8069
8397
|
isMainnet,
|
|
8070
8398
|
isNoopClient,
|
|
8399
|
+
isSessionValid,
|
|
8400
|
+
isSiweMessageExpired,
|
|
8401
|
+
isSiweMessageNotYetValid,
|
|
8071
8402
|
isSubscriptionActive,
|
|
8072
8403
|
keyExists,
|
|
8073
8404
|
listStoredKeys,
|
|
8405
|
+
loginToComputeApi,
|
|
8406
|
+
logoutFromComputeApi,
|
|
8074
8407
|
logs,
|
|
8408
|
+
noopLogger,
|
|
8409
|
+
parseSiweMessage,
|
|
8075
8410
|
prepareDeploy,
|
|
8076
8411
|
prepareDeployFromVerifiableBuild,
|
|
8077
8412
|
prepareUpgrade,
|