@openfort/cli 0.1.13 → 0.1.15
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 +47 -18
- package/package.json +2 -2
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
|
}
|
|
@@ -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,7 +2695,7 @@ 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
|
}
|
|
@@ -2775,7 +2804,7 @@ ${publicKey}
|
|
|
2775
2804
|
});
|
|
2776
2805
|
if (!registerRes.ok) {
|
|
2777
2806
|
const text = await registerRes.text();
|
|
2778
|
-
throw new
|
|
2807
|
+
throw new Errors3.IncurError({
|
|
2779
2808
|
code: "REGISTER_SECRET_FAILED",
|
|
2780
2809
|
message: `Failed to register wallet secret: ${text}`,
|
|
2781
2810
|
retryable: true
|
|
@@ -2791,7 +2820,7 @@ ${publicKey}
|
|
|
2791
2820
|
});
|
|
2792
2821
|
if (!storeRes.ok) {
|
|
2793
2822
|
const text = await storeRes.text();
|
|
2794
|
-
throw new
|
|
2823
|
+
throw new Errors3.IncurError({
|
|
2795
2824
|
code: "STORE_KEY_FAILED",
|
|
2796
2825
|
message: `Failed to store wallet key reference: ${text}`,
|
|
2797
2826
|
retryable: true
|
|
@@ -2832,7 +2861,7 @@ backendWallet.command("revoke", {
|
|
|
2832
2861
|
const keyId = process.env.OPENFORT_WALLET_KEY_ID;
|
|
2833
2862
|
const privateKeyBase64 = process.env.OPENFORT_WALLET_SECRET;
|
|
2834
2863
|
if (!keyId || !privateKeyBase64) {
|
|
2835
|
-
throw new
|
|
2864
|
+
throw new Errors3.IncurError({
|
|
2836
2865
|
code: "MISSING_WALLET_KEY",
|
|
2837
2866
|
message: "OPENFORT_WALLET_KEY_ID and OPENFORT_WALLET_SECRET must be set. Run `backend-wallet setup` first.",
|
|
2838
2867
|
hint: "Run: openfort backend-wallet setup"
|
|
@@ -2853,7 +2882,7 @@ backendWallet.command("revoke", {
|
|
|
2853
2882
|
});
|
|
2854
2883
|
if (!res.ok) {
|
|
2855
2884
|
const text = await res.text();
|
|
2856
|
-
throw new
|
|
2885
|
+
throw new Errors3.IncurError({
|
|
2857
2886
|
code: "REVOKE_SECRET_FAILED",
|
|
2858
2887
|
message: `Failed to revoke wallet secret: ${text}`,
|
|
2859
2888
|
retryable: true
|
|
@@ -2898,7 +2927,7 @@ ${publicKey}
|
|
|
2898
2927
|
});
|
|
2899
2928
|
if (!rotateRes.ok) {
|
|
2900
2929
|
const text = await rotateRes.text();
|
|
2901
|
-
throw new
|
|
2930
|
+
throw new Errors3.IncurError({
|
|
2902
2931
|
code: "ROTATE_SECRET_FAILED",
|
|
2903
2932
|
message: `Failed to rotate wallet secret: ${text}`,
|
|
2904
2933
|
retryable: true
|
|
@@ -2914,7 +2943,7 @@ ${publicKey}
|
|
|
2914
2943
|
});
|
|
2915
2944
|
if (!storeRes.ok) {
|
|
2916
2945
|
const text = await storeRes.text();
|
|
2917
|
-
throw new
|
|
2946
|
+
throw new Errors3.IncurError({
|
|
2918
2947
|
code: "STORE_KEY_FAILED",
|
|
2919
2948
|
message: `Failed to store rotated wallet key reference: ${text}`,
|
|
2920
2949
|
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.15",
|
|
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",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"main": "./dist/cli.js",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@openfort/openfort-node": "^0.10.2",
|
|
23
|
-
"incur": "^0.3.
|
|
23
|
+
"incur": "^0.3.25",
|
|
24
24
|
"open": "^11.0.0",
|
|
25
25
|
"viem": "^2.47.2"
|
|
26
26
|
},
|