@openfort/cli 0.1.14 → 0.1.16
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/dist/cli.js +59 -25
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -15,7 +15,7 @@ import { Cli as Cli14, z as z14 } from "incur";
|
|
|
15
15
|
import { randomBytes } from "crypto";
|
|
16
16
|
import { createServer } from "http";
|
|
17
17
|
import open from "open";
|
|
18
|
-
import { Cli, z } from "incur";
|
|
18
|
+
import { Cli, z, Errors } from "incur";
|
|
19
19
|
|
|
20
20
|
// src/constants.ts
|
|
21
21
|
var API_BASE_URL = process.env.OPENFORT_BASE_URL || "https://api.openfort.io";
|
|
@@ -24,6 +24,27 @@ var AUTH_PAGE_URL = process.env.OPENFORT_AUTH_PAGE_URL || "https://dashboard.ope
|
|
|
24
24
|
var CLI_CALLBACK_PORT = Number(process.env.OPENFORT_CLI_CALLBACK_PORT) || 8271;
|
|
25
25
|
|
|
26
26
|
// src/commands/login.ts
|
|
27
|
+
async function createPublishableKey(apiKey, projectId) {
|
|
28
|
+
const res = await fetch(`${API_BASE_URL}/v1/project/apikey`, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: {
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
Authorization: `Bearer ${apiKey}`,
|
|
33
|
+
project: projectId
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify({ type: "pk" })
|
|
36
|
+
});
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
const text = await res.text();
|
|
39
|
+
throw new Errors.IncurError({
|
|
40
|
+
code: "CREATE_PUBLISHABLE_KEY_FAILED",
|
|
41
|
+
message: `Failed to create publishable key: ${text}`,
|
|
42
|
+
retryable: true
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const data = await res.json();
|
|
46
|
+
return data.token;
|
|
47
|
+
}
|
|
27
48
|
function base64url(buffer) {
|
|
28
49
|
return buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
29
50
|
}
|
|
@@ -294,11 +315,19 @@ var login = Cli.create("login", {
|
|
|
294
315
|
console.log("Waiting for authentication...\n");
|
|
295
316
|
}
|
|
296
317
|
const { apiKey, publishableKey, projectId, project } = await waitForCallback(port, state);
|
|
318
|
+
let finalPublishableKey = publishableKey;
|
|
319
|
+
if (!finalPublishableKey) {
|
|
320
|
+
if (!projectId) {
|
|
321
|
+
throw new Errors.IncurError({
|
|
322
|
+
code: "MISSING_PROJECT_ID",
|
|
323
|
+
message: "Cannot create publishable key: project ID was not returned from the OAuth callback."
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
finalPublishableKey = await createPublishableKey(apiKey, projectId);
|
|
327
|
+
}
|
|
297
328
|
ensureConfigDir();
|
|
298
329
|
writeEnvKey(CREDENTIALS_PATH, "OPENFORT_API_KEY", apiKey);
|
|
299
|
-
|
|
300
|
-
writeEnvKey(CREDENTIALS_PATH, "OPENFORT_PUBLISHABLE_KEY", publishableKey);
|
|
301
|
-
}
|
|
330
|
+
writeEnvKey(CREDENTIALS_PATH, "OPENFORT_PUBLISHABLE_KEY", finalPublishableKey);
|
|
302
331
|
if (projectId) {
|
|
303
332
|
writeEnvKey(CREDENTIALS_PATH, "OPENFORT_PROJECT_ID", projectId);
|
|
304
333
|
}
|
|
@@ -979,7 +1008,7 @@ var contractItem = z3.object({
|
|
|
979
1008
|
chainId: z3.number(),
|
|
980
1009
|
address: z3.string(),
|
|
981
1010
|
deleted: z3.boolean(),
|
|
982
|
-
abi: z3.array(z3.
|
|
1011
|
+
abi: z3.array(z3.unknown()),
|
|
983
1012
|
publicVerification: z3.boolean()
|
|
984
1013
|
});
|
|
985
1014
|
var contracts = Cli3.create("contracts", {
|
|
@@ -1392,7 +1421,7 @@ policies.command("get", {
|
|
|
1392
1421
|
accountId: z5.string().nullable(),
|
|
1393
1422
|
enabled: z5.boolean(),
|
|
1394
1423
|
priority: z5.number(),
|
|
1395
|
-
rules: z5.array(z5.
|
|
1424
|
+
rules: z5.array(z5.unknown())
|
|
1396
1425
|
}),
|
|
1397
1426
|
async run(c) {
|
|
1398
1427
|
const p = await getOpenfort().policies.get(c.args.id);
|
|
@@ -1997,7 +2026,7 @@ var sessionItem = z8.object({
|
|
|
1997
2026
|
isActive: z8.boolean(),
|
|
1998
2027
|
nextAction: z8.object({
|
|
1999
2028
|
type: z8.string(),
|
|
2000
|
-
payload: z8.
|
|
2029
|
+
payload: z8.unknown().optional()
|
|
2001
2030
|
}).optional()
|
|
2002
2031
|
});
|
|
2003
2032
|
var sessions = Cli8.create("sessions", {
|
|
@@ -2206,7 +2235,7 @@ var transactionIntentItem = z9.object({
|
|
|
2206
2235
|
gasFee: z9.string().optional(),
|
|
2207
2236
|
status: z9.number().optional(),
|
|
2208
2237
|
to: z9.string().optional(),
|
|
2209
|
-
error: z9.
|
|
2238
|
+
error: z9.unknown().optional()
|
|
2210
2239
|
}).optional(),
|
|
2211
2240
|
interactions: z9.array(z9.object({
|
|
2212
2241
|
to: z9.string().optional(),
|
|
@@ -2215,7 +2244,7 @@ var transactionIntentItem = z9.object({
|
|
|
2215
2244
|
})).optional(),
|
|
2216
2245
|
nextAction: z9.object({
|
|
2217
2246
|
type: z9.string(),
|
|
2218
|
-
payload: z9.
|
|
2247
|
+
payload: z9.unknown().optional()
|
|
2219
2248
|
}).optional()
|
|
2220
2249
|
});
|
|
2221
2250
|
var transactions = Cli9.create("transactions", {
|
|
@@ -2426,7 +2455,7 @@ transactions.command("estimate", {
|
|
|
2426
2455
|
});
|
|
2427
2456
|
|
|
2428
2457
|
// src/commands/embedded-wallet.ts
|
|
2429
|
-
import { Cli as Cli10, z as z10, Errors } from "incur";
|
|
2458
|
+
import { Cli as Cli10, z as z10, Errors as Errors2 } from "incur";
|
|
2430
2459
|
var embeddedWallet = Cli10.create("embedded-wallet", {
|
|
2431
2460
|
description: "Configure embedded wallet (Shield) API keys."
|
|
2432
2461
|
});
|
|
@@ -2450,7 +2479,7 @@ embeddedWallet.command("setup", {
|
|
|
2450
2479
|
async run(c) {
|
|
2451
2480
|
const publishableKey = process.env.OPENFORT_PUBLISHABLE_KEY;
|
|
2452
2481
|
if (!publishableKey) {
|
|
2453
|
-
throw new
|
|
2482
|
+
throw new Errors2.IncurError({
|
|
2454
2483
|
code: "MISSING_PUBLISHABLE_KEY",
|
|
2455
2484
|
message: "OPENFORT_PUBLISHABLE_KEY environment variable is required to create Shield keys.",
|
|
2456
2485
|
hint: "Run: openfort login"
|
|
@@ -2460,7 +2489,7 @@ embeddedWallet.command("setup", {
|
|
|
2460
2489
|
const environment = apiKey.startsWith("sk_live_") ? "live" : "test";
|
|
2461
2490
|
const projectId = c.options.project || process.env.OPENFORT_PROJECT_ID;
|
|
2462
2491
|
if (!projectId) {
|
|
2463
|
-
throw new
|
|
2492
|
+
throw new Errors2.IncurError({
|
|
2464
2493
|
code: "MISSING_PROJECT_ID",
|
|
2465
2494
|
message: "Project ID is required. Pass --project or set OPENFORT_PROJECT_ID.",
|
|
2466
2495
|
hint: "Run: openfort login"
|
|
@@ -2480,7 +2509,7 @@ embeddedWallet.command("setup", {
|
|
|
2480
2509
|
});
|
|
2481
2510
|
if (!registerRes.ok) {
|
|
2482
2511
|
const text = await registerRes.text();
|
|
2483
|
-
throw new
|
|
2512
|
+
throw new Errors2.IncurError({
|
|
2484
2513
|
code: "SHIELD_REGISTER_FAILED",
|
|
2485
2514
|
message: `Shield registration failed: ${text}`,
|
|
2486
2515
|
retryable: true
|
|
@@ -2488,7 +2517,7 @@ embeddedWallet.command("setup", {
|
|
|
2488
2517
|
}
|
|
2489
2518
|
const shieldData = await registerRes.json();
|
|
2490
2519
|
if (shieldData.error) {
|
|
2491
|
-
throw new
|
|
2520
|
+
throw new Errors2.IncurError({
|
|
2492
2521
|
code: "SHIELD_REGISTER_ERROR",
|
|
2493
2522
|
message: `Shield registration error: ${shieldData.error}`
|
|
2494
2523
|
});
|
|
@@ -2504,7 +2533,7 @@ embeddedWallet.command("setup", {
|
|
|
2504
2533
|
});
|
|
2505
2534
|
if (!res.ok) {
|
|
2506
2535
|
const text = await res.text();
|
|
2507
|
-
throw new
|
|
2536
|
+
throw new Errors2.IncurError({
|
|
2508
2537
|
code: "PERSIST_KEY_FAILED",
|
|
2509
2538
|
message: `Failed to persist ${type} key: ${text}`,
|
|
2510
2539
|
retryable: true
|
|
@@ -2532,7 +2561,7 @@ embeddedWallet.command("setup", {
|
|
|
2532
2561
|
});
|
|
2533
2562
|
if (!linkRes.ok) {
|
|
2534
2563
|
const text = await linkRes.text();
|
|
2535
|
-
throw new
|
|
2564
|
+
throw new Errors2.IncurError({
|
|
2536
2565
|
code: "SHIELD_LINK_FAILED",
|
|
2537
2566
|
message: `Failed to link Openfort provider to Shield: ${text}`,
|
|
2538
2567
|
retryable: true
|
|
@@ -2666,15 +2695,20 @@ users.command("delete", {
|
|
|
2666
2695
|
|
|
2667
2696
|
// src/commands/backend-wallet.ts
|
|
2668
2697
|
import { randomBytes as randomBytes2, subtle } from "crypto";
|
|
2669
|
-
import { Cli as Cli12, z as z12, Errors as
|
|
2698
|
+
import { Cli as Cli12, z as z12, Errors as Errors3 } from "incur";
|
|
2670
2699
|
function arrayBufferToBase64(buffer) {
|
|
2671
2700
|
return Buffer.from(buffer).toString("base64");
|
|
2672
2701
|
}
|
|
2673
2702
|
function arrayBufferToBase64Url(buffer) {
|
|
2674
2703
|
return Buffer.from(buffer).toString("base64url");
|
|
2675
2704
|
}
|
|
2705
|
+
function toArrayBuffer(bytes) {
|
|
2706
|
+
const buffer = new ArrayBuffer(bytes.byteLength);
|
|
2707
|
+
new Uint8Array(buffer).set(bytes);
|
|
2708
|
+
return buffer;
|
|
2709
|
+
}
|
|
2676
2710
|
function stringToArrayBuffer(str) {
|
|
2677
|
-
return new TextEncoder().encode(str);
|
|
2711
|
+
return toArrayBuffer(new TextEncoder().encode(str));
|
|
2678
2712
|
}
|
|
2679
2713
|
function formatPEMBody(base64) {
|
|
2680
2714
|
return base64.match(/.{1,64}/g)?.join("\n") || base64;
|
|
@@ -2690,7 +2724,7 @@ function sortObjectKeys(obj) {
|
|
|
2690
2724
|
return sorted;
|
|
2691
2725
|
}
|
|
2692
2726
|
async function importPrivateKey(base64) {
|
|
2693
|
-
const binaryDer = Buffer.from(base64, "base64");
|
|
2727
|
+
const binaryDer = toArrayBuffer(Buffer.from(base64, "base64"));
|
|
2694
2728
|
return subtle.importKey(
|
|
2695
2729
|
"pkcs8",
|
|
2696
2730
|
binaryDer,
|
|
@@ -2775,7 +2809,7 @@ ${publicKey}
|
|
|
2775
2809
|
});
|
|
2776
2810
|
if (!registerRes.ok) {
|
|
2777
2811
|
const text = await registerRes.text();
|
|
2778
|
-
throw new
|
|
2812
|
+
throw new Errors3.IncurError({
|
|
2779
2813
|
code: "REGISTER_SECRET_FAILED",
|
|
2780
2814
|
message: `Failed to register wallet secret: ${text}`,
|
|
2781
2815
|
retryable: true
|
|
@@ -2791,7 +2825,7 @@ ${publicKey}
|
|
|
2791
2825
|
});
|
|
2792
2826
|
if (!storeRes.ok) {
|
|
2793
2827
|
const text = await storeRes.text();
|
|
2794
|
-
throw new
|
|
2828
|
+
throw new Errors3.IncurError({
|
|
2795
2829
|
code: "STORE_KEY_FAILED",
|
|
2796
2830
|
message: `Failed to store wallet key reference: ${text}`,
|
|
2797
2831
|
retryable: true
|
|
@@ -2832,7 +2866,7 @@ backendWallet.command("revoke", {
|
|
|
2832
2866
|
const keyId = process.env.OPENFORT_WALLET_KEY_ID;
|
|
2833
2867
|
const privateKeyBase64 = process.env.OPENFORT_WALLET_SECRET;
|
|
2834
2868
|
if (!keyId || !privateKeyBase64) {
|
|
2835
|
-
throw new
|
|
2869
|
+
throw new Errors3.IncurError({
|
|
2836
2870
|
code: "MISSING_WALLET_KEY",
|
|
2837
2871
|
message: "OPENFORT_WALLET_KEY_ID and OPENFORT_WALLET_SECRET must be set. Run `backend-wallet setup` first.",
|
|
2838
2872
|
hint: "Run: openfort backend-wallet setup"
|
|
@@ -2853,7 +2887,7 @@ backendWallet.command("revoke", {
|
|
|
2853
2887
|
});
|
|
2854
2888
|
if (!res.ok) {
|
|
2855
2889
|
const text = await res.text();
|
|
2856
|
-
throw new
|
|
2890
|
+
throw new Errors3.IncurError({
|
|
2857
2891
|
code: "REVOKE_SECRET_FAILED",
|
|
2858
2892
|
message: `Failed to revoke wallet secret: ${text}`,
|
|
2859
2893
|
retryable: true
|
|
@@ -2898,7 +2932,7 @@ ${publicKey}
|
|
|
2898
2932
|
});
|
|
2899
2933
|
if (!rotateRes.ok) {
|
|
2900
2934
|
const text = await rotateRes.text();
|
|
2901
|
-
throw new
|
|
2935
|
+
throw new Errors3.IncurError({
|
|
2902
2936
|
code: "ROTATE_SECRET_FAILED",
|
|
2903
2937
|
message: `Failed to rotate wallet secret: ${text}`,
|
|
2904
2938
|
retryable: true
|
|
@@ -2914,7 +2948,7 @@ ${publicKey}
|
|
|
2914
2948
|
});
|
|
2915
2949
|
if (!storeRes.ok) {
|
|
2916
2950
|
const text = await storeRes.text();
|
|
2917
|
-
throw new
|
|
2951
|
+
throw new Errors3.IncurError({
|
|
2918
2952
|
code: "STORE_KEY_FAILED",
|
|
2919
2953
|
message: `Failed to store rotated wallet key reference: ${text}`,
|
|
2920
2954
|
retryable: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfort/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Openfort CLI — manage wallets, policies, and transactions from the terminal.",
|
|
5
5
|
"author": "Openfort (https://www.openfort.io)",
|
|
6
6
|
"bugs": "https://github.com/openfort-xyz/cli/issues",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "./dist/cli.js",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@openfort/openfort-node": "^0.10.
|
|
23
|
-
"incur": "^0.
|
|
22
|
+
"@openfort/openfort-node": "^0.10.5",
|
|
23
|
+
"incur": "^0.4.10",
|
|
24
24
|
"open": "^11.0.0",
|
|
25
|
-
"viem": "^2.
|
|
25
|
+
"viem": "^2.53.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@changesets/changelog-github": "^0.5.1",
|