@singularity-layer/agentvault 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -9
- package/dist/commands/backup.d.ts +5 -0
- package/dist/commands/backup.js +2 -2
- package/dist/commands/login.js +2 -2
- package/dist/commands/pq.d.ts +29 -0
- package/dist/commands/pq.js +77 -0
- package/dist/commands/restore.d.ts +12 -1
- package/dist/commands/restore.js +62 -9
- package/dist/config.d.ts +13 -0
- package/dist/config.js +16 -1
- package/dist/deps.d.ts +4 -1
- package/dist/deps.js +4 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +110 -3
- package/dist/pqkey.d.ts +11 -0
- package/dist/pqkey.js +72 -0
- package/dist/recoveryInput.d.ts +20 -0
- package/dist/recoveryInput.js +29 -0
- package/dist/tty.d.ts +6 -0
- package/dist/tty.js +23 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -32,6 +32,30 @@ from **your** passphrase (scrypt). The vault stores ciphertext it cannot read.
|
|
|
32
32
|
That cuts both ways: **a lost passphrase cannot be recovered — not even by us.**
|
|
33
33
|
Write it down.
|
|
34
34
|
|
|
35
|
+
## Post-quantum encryption (opt-in)
|
|
36
|
+
|
|
37
|
+
The default above is already symmetric cryptography (scrypt + AES-256-GCM), which quantum computers do
|
|
38
|
+
not meaningfully weaken. Post-quantum mode adds something different: a **vault key**, a hybrid
|
|
39
|
+
X25519 + ML-KEM-768 key pair (X-Wing). Each backup's data key is wrapped to the vault **public** key,
|
|
40
|
+
so the machine making backups never holds anything that can read them, and the public-key step stays
|
|
41
|
+
secret unless both X25519 and ML-KEM-768 are broken.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
agentvault pq init # create the vault key here; shows a recovery code on the terminal only
|
|
45
|
+
agentvault pq recovery-code # show it again (interactive terminal only, never stdout)
|
|
46
|
+
agentvault pq init --also-passphrase # ...and let your passphrase restore new backups too
|
|
47
|
+
agentvault pq status # show the setting and the public key
|
|
48
|
+
agentvault pq enable --public-key <b64> # write-only machine: back up to a key made elsewhere
|
|
49
|
+
agentvault pq disable # new backups go back to passphrase only
|
|
50
|
+
agentvault restore --vault-key <file> # or --recovery-code (hidden prompt), or --recovery-code-stdin --backup <id>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Key custody, plainly: the private key lives in `~/.agentvault/vault-key.json` (owner-only) and in the
|
|
54
|
+
recovery code you write down. We never see either. The CLI never takes the code as a command-line value
|
|
55
|
+
(that would leave it in shell history); it asks at a hidden prompt or reads stdin. **Lose both and backups made without
|
|
56
|
+
`--also-passphrase` cannot be restored by anyone, including us.** Older backups keep restoring with
|
|
57
|
+
their passphrase; nothing is re-encrypted.
|
|
58
|
+
|
|
35
59
|
## Back up anything
|
|
36
60
|
|
|
37
61
|
Not on OpenClaw or Hermes? Any directory can be vaulted:
|
|
@@ -49,21 +73,27 @@ with `agentvault restore --dest` like everything else.
|
|
|
49
73
|
|---|---|
|
|
50
74
|
| `agentvault login` | Browser wallet sign-in (`--api-key` to paste a key instead) |
|
|
51
75
|
| `agentvault backup [--all] [--path <dir> --name <n>]` | Encrypt + upload detected agents, or ANY directory |
|
|
52
|
-
| `agentvault restore [--dest <dir>]` | Download, decrypt, safely unpack a snapshot |
|
|
76
|
+
| `agentvault restore [--dest <dir>] [--vault-key <file> \| --recovery-code \| --recovery-code-stdin]` | Download, decrypt, safely unpack a snapshot |
|
|
53
77
|
| `agentvault list` | Agents and snapshot counts |
|
|
78
|
+
| `agentvault pq init\|enable\|disable\|status\|recovery-code` | Opt-in post-quantum encryption with a vault key (see above) |
|
|
54
79
|
| `agentvault passphrase set\|clear` | Store the passphrase in the OS keychain (for scheduled backups) |
|
|
55
80
|
| `agentvault daemon install [--frequency weekly\|daily]` | Automatic backups (launchd/systemd) |
|
|
56
81
|
|
|
57
82
|
## Pricing
|
|
58
83
|
|
|
59
|
-
| | Free | Vault Pro
|
|
60
|
-
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
84
|
+
| | Free | Vault Pro | Vault Max |
|
|
85
|
+
|---|---|---|---|
|
|
86
|
+
| Storage | 1 GB | 10 GB | 50 GB |
|
|
87
|
+
| Snapshots | 1, rolling (new replaces old) | last 10 of **each agent** | Unlimited, full history |
|
|
88
|
+
| Monthly | $0 | $3 | $5 |
|
|
89
|
+
| Yearly | — | $30 (2 months free) | $50 (2 months free) |
|
|
90
|
+
|
|
91
|
+
Paid plans bill from your [credits](https://cloud.x402compute.cc/network/settings/credits);
|
|
92
|
+
upgrade from the dashboard. Upgrades are prorated against the period you already
|
|
93
|
+
paid for; downgrades and cancellations take effect at period end. If a renewal
|
|
94
|
+
can't be paid you drop back to free — and because every snapshot records the plan
|
|
95
|
+
it was taken under, **a downgrade or a missed payment never deletes a snapshot**
|
|
96
|
+
you took on a higher plan. A typical agent snapshot is a few MB.
|
|
67
97
|
|
|
68
98
|
## Dashboard
|
|
69
99
|
|
|
@@ -13,6 +13,11 @@ export interface BackupDeps {
|
|
|
13
13
|
uploadBlob: (blob: Buffer, url: string) => Promise<BackupResult>;
|
|
14
14
|
/** Resolve the backup passphrase (interactive prompt or keychain). */
|
|
15
15
|
resolvePassphrase: () => Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* False when post-quantum encryption is on without a passphrase wrap: the backup is encrypted to the vault
|
|
18
|
+
* public key only, so no passphrase is asked for (and none needs to be stored for automatic backups).
|
|
19
|
+
*/
|
|
20
|
+
needsPassphrase?: boolean;
|
|
16
21
|
prompter: Prompter;
|
|
17
22
|
logger: Logger;
|
|
18
23
|
/** Optional: invoked once after a successful backup to offer daemon install. */
|
package/dist/commands/backup.js
CHANGED
|
@@ -18,7 +18,7 @@ export async function runBackup(deps, opts) {
|
|
|
18
18
|
const chosen = await deps.prompter.select("Which agent to back up?", detected.map((d) => ({ value: d.framework, label: d.name })));
|
|
19
19
|
targets = detected.filter((d) => d.framework === chosen);
|
|
20
20
|
}
|
|
21
|
-
const passphrase = await deps.resolvePassphrase();
|
|
21
|
+
const passphrase = deps.needsPassphrase === false ? "" : await deps.resolvePassphrase();
|
|
22
22
|
let anySucceeded = false;
|
|
23
23
|
for (const target of targets) {
|
|
24
24
|
const agent = await ensureAgent(deps.client, target);
|
|
@@ -48,7 +48,7 @@ export async function runBackup(deps, opts) {
|
|
|
48
48
|
try {
|
|
49
49
|
const usage = await deps.client.getUsage?.();
|
|
50
50
|
if (usage?.plan === "free") {
|
|
51
|
-
deps.logger.info("Free plan: the vault keeps only your latest snapshot (across all agents). Vault Pro ($3/mo) keeps
|
|
51
|
+
deps.logger.info("Free plan: the vault keeps only your latest snapshot (across all agents). Vault Pro ($3/mo) keeps the last 10 of each agent; Vault Max ($5/mo) keeps everything — upgrade in the dashboard.");
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
catch {
|
package/dist/commands/login.js
CHANGED
|
@@ -20,7 +20,7 @@ export async function runBrowserLogin(deps) {
|
|
|
20
20
|
break;
|
|
21
21
|
await deps.verify(res.apiKey);
|
|
22
22
|
const cfg = deps.store.load();
|
|
23
|
-
deps.store.save({
|
|
23
|
+
deps.store.save({ ...cfg, token: res.apiKey });
|
|
24
24
|
deps.logger.success("Logged in.");
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
@@ -38,6 +38,6 @@ export async function runLogin(deps) {
|
|
|
38
38
|
throw new Error("no API key entered");
|
|
39
39
|
await deps.verify(key);
|
|
40
40
|
const cfg = deps.store.load();
|
|
41
|
-
deps.store.save({
|
|
41
|
+
deps.store.save({ ...cfg, token: key });
|
|
42
42
|
deps.logger.success("Logged in.");
|
|
43
43
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ConfigStore } from "../config.js";
|
|
2
|
+
import type { Logger, Prompter } from "../io.js";
|
|
3
|
+
export interface PqDeps {
|
|
4
|
+
store: ConfigStore;
|
|
5
|
+
logger: Logger;
|
|
6
|
+
prompter?: Prompter;
|
|
7
|
+
home?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Shows a secret to the person at the terminal ONLY (never stdout, never the logger), returning false
|
|
10
|
+
* when there is no terminal. Captured or piped CLI output must never contain the recovery code.
|
|
11
|
+
*/
|
|
12
|
+
showSecret?: (label: string, secret: string) => boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a vault key on this machine and turn post-quantum encryption on for new backups.
|
|
16
|
+
* Old backups stay as they are and keep restoring with their passphrase.
|
|
17
|
+
*/
|
|
18
|
+
export declare function runPqInit(deps: PqDeps, opts: {
|
|
19
|
+
alsoPassphrase: boolean;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
/** Write-only machine: encrypt to a public key made elsewhere. This machine can back up but never restore. */
|
|
22
|
+
export declare function runPqEnablePublic(deps: PqDeps, opts: {
|
|
23
|
+
publicKey: string;
|
|
24
|
+
alsoPassphrase: boolean;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
export declare function runPqDisable(deps: PqDeps): Promise<void>;
|
|
27
|
+
export declare function runPqStatus(deps: PqDeps): Promise<void>;
|
|
28
|
+
/** Show the recovery code for this machine's vault key, terminal only. */
|
|
29
|
+
export declare function runPqRecoveryCode(deps: PqDeps): Promise<void>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { encodeRecoveryCode, generateVaultKey, keyIdOf, XWING_PUBLIC_KEY_BYTES, } from "@singularity-layer/agentvault-core";
|
|
2
|
+
import { readVaultKey, vaultKeyExists, writeVaultKey } from "../pqkey.js";
|
|
3
|
+
function showRecovery(deps, code) {
|
|
4
|
+
const shown = deps.showSecret?.("RECOVERY CODE. Write it down and keep it offline. It is the only other way to restore:", code) ?? false;
|
|
5
|
+
if (!shown) {
|
|
6
|
+
deps.logger.info("Your recovery code was not printed because this is not an interactive terminal. Run `agentvault pq recovery-code` in a terminal to see it.");
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const WHAT_IT_IS = "Post-quantum encryption: each backup's data key is wrapped to your vault public key with X-Wing " +
|
|
10
|
+
"(X25519 + ML-KEM-768, hybrid), then the backup is encrypted with AES-256-GCM on this machine. " +
|
|
11
|
+
"We only ever store ciphertext.";
|
|
12
|
+
/**
|
|
13
|
+
* Create a vault key on this machine and turn post-quantum encryption on for new backups.
|
|
14
|
+
* Old backups stay as they are and keep restoring with their passphrase.
|
|
15
|
+
*/
|
|
16
|
+
export async function runPqInit(deps, opts) {
|
|
17
|
+
if (vaultKeyExists(deps.home)) {
|
|
18
|
+
deps.logger.error("A vault key already exists on this machine. Use `agentvault pq status`, or move the file away first.");
|
|
19
|
+
process.exitCode = 1;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const key = generateVaultKey();
|
|
23
|
+
const file = writeVaultKey(key, deps.home);
|
|
24
|
+
const cfg = deps.store.load();
|
|
25
|
+
deps.store.save({
|
|
26
|
+
...cfg,
|
|
27
|
+
pq: { enabled: true, publicKey: key.publicKey.toString("base64"), keyId: key.keyId, alsoPassphrase: opts.alsoPassphrase },
|
|
28
|
+
});
|
|
29
|
+
deps.logger.info(WHAT_IT_IS);
|
|
30
|
+
deps.logger.success(`Vault key created (id ${key.keyId}), saved to ${file} (readable only by you).`);
|
|
31
|
+
showRecovery(deps, encodeRecoveryCode(key.secretKey));
|
|
32
|
+
deps.logger.info(opts.alsoPassphrase
|
|
33
|
+
? "New backups can be restored with this vault key OR your passphrase."
|
|
34
|
+
: "New backups can ONLY be restored with this vault key or the recovery code. If you lose both, nobody can restore them, including us.");
|
|
35
|
+
}
|
|
36
|
+
/** Write-only machine: encrypt to a public key made elsewhere. This machine can back up but never restore. */
|
|
37
|
+
export async function runPqEnablePublic(deps, opts) {
|
|
38
|
+
const pk = Buffer.from(opts.publicKey.trim(), "base64");
|
|
39
|
+
if (pk.length !== XWING_PUBLIC_KEY_BYTES) {
|
|
40
|
+
deps.logger.error(`That is not a vault public key (expected ${XWING_PUBLIC_KEY_BYTES} bytes, base64).`);
|
|
41
|
+
process.exitCode = 1;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const keyId = keyIdOf(pk);
|
|
45
|
+
const cfg = deps.store.load();
|
|
46
|
+
deps.store.save({ ...cfg, pq: { enabled: true, publicKey: pk.toString("base64"), keyId, alsoPassphrase: opts.alsoPassphrase } });
|
|
47
|
+
deps.logger.success(`Post-quantum encryption on, to vault key ${keyId}. This machine can make backups it cannot read.`);
|
|
48
|
+
}
|
|
49
|
+
export async function runPqDisable(deps) {
|
|
50
|
+
const cfg = deps.store.load();
|
|
51
|
+
if (cfg.pq)
|
|
52
|
+
deps.store.save({ ...cfg, pq: { ...cfg.pq, enabled: false } });
|
|
53
|
+
deps.logger.success("Post-quantum encryption off for NEW backups (passphrase only). Existing backups and your vault key are unchanged.");
|
|
54
|
+
}
|
|
55
|
+
export async function runPqStatus(deps) {
|
|
56
|
+
const cfg = deps.store.load();
|
|
57
|
+
const local = readVaultKey(undefined, deps.home);
|
|
58
|
+
if (!cfg.pq?.enabled) {
|
|
59
|
+
deps.logger.info("Post-quantum encryption: off. New backups use your passphrase (AES-256-GCM).");
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
deps.logger.info(`Post-quantum encryption: on. Vault key ${cfg.pq.keyId}${cfg.pq.alsoPassphrase ? ", plus passphrase" : ""}.`);
|
|
63
|
+
}
|
|
64
|
+
deps.logger.info(local ? `Vault private key on this machine: yes (${local.keyId}).` : "Vault private key on this machine: no (this machine cannot restore post-quantum backups without --vault-key or --recovery-code).");
|
|
65
|
+
if (cfg.pq?.publicKey)
|
|
66
|
+
deps.logger.info(`Public key (for write-only machines: agentvault pq enable --public-key ...):\n${cfg.pq.publicKey}`);
|
|
67
|
+
}
|
|
68
|
+
/** Show the recovery code for this machine's vault key, terminal only. */
|
|
69
|
+
export async function runPqRecoveryCode(deps) {
|
|
70
|
+
const key = readVaultKey(undefined, deps.home);
|
|
71
|
+
if (!key) {
|
|
72
|
+
deps.logger.error("No vault key on this machine.");
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
showRecovery(deps, encodeRecoveryCode(key.secretKey));
|
|
77
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Aad } from "@singularity-layer/agentvault-core";
|
|
1
|
+
import type { Aad, BlobInfo, DecryptSecrets, VaultKey } from "@singularity-layer/agentvault-core";
|
|
2
2
|
import type { ApiClient } from "../client.js";
|
|
3
3
|
import type { Logger, Prompter } from "../io.js";
|
|
4
4
|
export interface RestoreDeps {
|
|
@@ -7,9 +7,20 @@ export interface RestoreDeps {
|
|
|
7
7
|
restoreBlob: (blob: Buffer, passphrase: string, aad: Aad, destDir: string) => Promise<void>;
|
|
8
8
|
prompter: Prompter;
|
|
9
9
|
logger: Logger;
|
|
10
|
+
/** Post-quantum (format v2) support. When absent, the v1 passphrase flow runs unchanged. */
|
|
11
|
+
pq?: {
|
|
12
|
+
blobInfo: (blob: Buffer) => BlobInfo;
|
|
13
|
+
restoreWith: (blob: Buffer, secrets: DecryptSecrets, aad: Aad, destDir: string) => Promise<void>;
|
|
14
|
+
/** The vault key to try: from --vault-key, --recovery-code, or the default key file. */
|
|
15
|
+
vaultKey: () => VaultKey | null;
|
|
16
|
+
};
|
|
10
17
|
}
|
|
11
18
|
export interface RestoreOptions {
|
|
12
19
|
dest: string;
|
|
20
|
+
/** Restore this backup without asking. */
|
|
21
|
+
backupId?: string;
|
|
22
|
+
/** stdin is in use (recovery code): never prompt; a choice that needs one is an error. */
|
|
23
|
+
noPrompts?: boolean;
|
|
13
24
|
}
|
|
14
25
|
/** List backups, let the user pick one, download + decrypt + unpack to dest. */
|
|
15
26
|
export declare function runRestore(deps: RestoreDeps, opts: RestoreOptions): Promise<void>;
|
package/dist/commands/restore.js
CHANGED
|
@@ -6,15 +6,68 @@ export async function runRestore(deps, opts) {
|
|
|
6
6
|
deps.logger.error("No backups available to restore.");
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
if (opts.backupId && !backups.some((b) => b.id === opts.backupId)) {
|
|
10
|
+
deps.logger.error(`No backup with id ${opts.backupId}. Run \`agentvault list\` to see them.`);
|
|
11
|
+
process.exitCode = 1;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (!opts.backupId && backups.length > 1 && opts.noPrompts) {
|
|
15
|
+
deps.logger.error("Several backups exist: pass --backup <id> together with --recovery-code-stdin (see `agentvault list`).");
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const backupId = opts.backupId ??
|
|
20
|
+
(backups.length === 1
|
|
21
|
+
? backups[0].id
|
|
22
|
+
: await deps.prompter.select("Which backup to restore?", backups.map((b) => ({
|
|
23
|
+
value: b.id,
|
|
24
|
+
label: `${b.id} (${b.created_at})`,
|
|
25
|
+
}))));
|
|
26
|
+
if (!deps.pq) {
|
|
27
|
+
const passphrase = await deps.prompter.password("Backup passphrase");
|
|
28
|
+
const { downloadUrl, r2Key } = await deps.client.getRestoreUrl(backupId);
|
|
29
|
+
const blob = await deps.downloadBlob(downloadUrl);
|
|
30
|
+
await deps.restoreBlob(blob, passphrase, parseAad(r2Key), opts.dest);
|
|
31
|
+
deps.logger.success(`Restored to ${opts.dest}.`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Download first, then ask only for what this particular backup needs.
|
|
16
35
|
const { downloadUrl, r2Key } = await deps.client.getRestoreUrl(backupId);
|
|
17
36
|
const blob = await deps.downloadBlob(downloadUrl);
|
|
18
|
-
|
|
19
|
-
|
|
37
|
+
const info = deps.pq.blobInfo(blob);
|
|
38
|
+
const aad = parseAad(r2Key);
|
|
39
|
+
if (info.formatVersion !== 2) {
|
|
40
|
+
if (opts.noPrompts) {
|
|
41
|
+
deps.logger.error("This backup is passphrase-encrypted (not post-quantum). Restore it without --recovery-code-stdin and enter the passphrase.");
|
|
42
|
+
process.exitCode = 1;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const passphrase = await deps.prompter.password("Backup passphrase");
|
|
46
|
+
await deps.restoreBlob(blob, passphrase, aad, opts.dest);
|
|
47
|
+
deps.logger.success(`Restored to ${opts.dest}.`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const secrets = {};
|
|
51
|
+
// A damaged or unreadable key file must not block a passphrase restore: report it and fall back.
|
|
52
|
+
let key = null;
|
|
53
|
+
try {
|
|
54
|
+
key = deps.pq.vaultKey();
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
deps.logger.error(`Could not use the vault key: ${e instanceof Error ? e.message : String(e)}`);
|
|
58
|
+
}
|
|
59
|
+
if (key && info.vaultKeyIds.includes(key.keyId)) {
|
|
60
|
+
secrets.vaultSecretKey = key.secretKey;
|
|
61
|
+
}
|
|
62
|
+
else if (info.passphrase && !opts.noPrompts) {
|
|
63
|
+
secrets.passphrase = await deps.prompter.password("Backup passphrase");
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
deps.logger.error(`This backup is post-quantum encrypted to vault key ${info.vaultKeyIds.join(", ")}. ` +
|
|
67
|
+
"Restore on the machine that holds that key, or pass --vault-key <file> or --recovery-code (hidden prompt).");
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
await deps.pq.restoreWith(blob, secrets, aad, opts.dest);
|
|
72
|
+
deps.logger.success(`Restored to ${opts.dest} (post-quantum encrypted backup).`);
|
|
20
73
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in post-quantum encryption (blob format v2). Only the PUBLIC vault key lives here; the private key
|
|
3
|
+
* is in vault-key.json (see pqkey.ts) on machines that restore, and absent on write-only machines.
|
|
4
|
+
*/
|
|
5
|
+
export interface PqConfig {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
/** X-Wing public key, base64 (1216 bytes). */
|
|
8
|
+
publicKey: string;
|
|
9
|
+
keyId: string;
|
|
10
|
+
/** Also wrap each backup with the passphrase, as a second way to restore. */
|
|
11
|
+
alsoPassphrase: boolean;
|
|
12
|
+
}
|
|
1
13
|
export interface CliConfig {
|
|
2
14
|
apiUrl: string;
|
|
3
15
|
token: string | null;
|
|
16
|
+
pq?: PqConfig | null;
|
|
4
17
|
}
|
|
5
18
|
export interface ConfigStore {
|
|
6
19
|
load(): CliConfig;
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
+
function readPq(v) {
|
|
5
|
+
if (!v || typeof v !== "object")
|
|
6
|
+
return null;
|
|
7
|
+
const o = v;
|
|
8
|
+
if (typeof o.publicKey !== "string" || typeof o.keyId !== "string")
|
|
9
|
+
return null;
|
|
10
|
+
return {
|
|
11
|
+
enabled: o.enabled === true,
|
|
12
|
+
publicKey: o.publicKey,
|
|
13
|
+
keyId: o.keyId,
|
|
14
|
+
alsoPassphrase: o.alsoPassphrase === true,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
4
17
|
const DEFAULT_API_URL = "https://compute.x402layer.cc";
|
|
5
18
|
/** Resolve the config home: explicit arg > AGENTVAULT_HOME env > ~/.agentvault. */
|
|
6
19
|
export function resolveHome(explicit) {
|
|
@@ -18,6 +31,7 @@ export function createConfigStore(explicitHome) {
|
|
|
18
31
|
return {
|
|
19
32
|
apiUrl: parsed.apiUrl ?? DEFAULT_API_URL,
|
|
20
33
|
token: parsed.token ?? null,
|
|
34
|
+
pq: readPq(parsed.pq),
|
|
21
35
|
};
|
|
22
36
|
}
|
|
23
37
|
catch {
|
|
@@ -40,7 +54,8 @@ export function createConfigStore(explicitHome) {
|
|
|
40
54
|
},
|
|
41
55
|
clear() {
|
|
42
56
|
const current = this.load();
|
|
43
|
-
|
|
57
|
+
// Logging out keeps the encryption setting: it describes the backups, not the session.
|
|
58
|
+
this.save({ apiUrl: current.apiUrl, token: null, pq: current.pq ?? null });
|
|
44
59
|
},
|
|
45
60
|
};
|
|
46
61
|
}
|
package/dist/deps.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
|
-
import { encrypt, packAgent, restoreBlob, uploadBlob } from "@singularity-layer/agentvault-core";
|
|
2
|
+
import { encrypt, packAgent, restoreBlob, restoreBlobWith, blobInfo, encryptV2, uploadBlob } from "@singularity-layer/agentvault-core";
|
|
3
3
|
import type { DetectedAgent } from "@singularity-layer/agentvault-core";
|
|
4
4
|
import { createClient } from "./client.js";
|
|
5
5
|
import { createConfigStore } from "./config.js";
|
|
@@ -27,6 +27,9 @@ export declare const realCore: {
|
|
|
27
27
|
encrypt: typeof encrypt;
|
|
28
28
|
uploadBlob: typeof uploadBlob;
|
|
29
29
|
restoreBlob: typeof restoreBlob;
|
|
30
|
+
restoreBlobWith: typeof restoreBlobWith;
|
|
31
|
+
blobInfo: typeof blobInfo;
|
|
32
|
+
encryptV2: typeof encryptV2;
|
|
30
33
|
downloadBlob: typeof downloadBlob;
|
|
31
34
|
};
|
|
32
35
|
export declare const realIo: {
|
package/dist/deps.js
CHANGED
|
@@ -2,7 +2,7 @@ import { execFile, execFileSync, spawn } from "node:child_process";
|
|
|
2
2
|
import { existsSync, mkdirSync, realpathSync, rmSync, writeFileSync, } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { dirname } from "node:path";
|
|
5
|
-
import { createRegistry, discover, encrypt, hermesAdapter, openclawAdapter, packAgent, restoreBlob, uploadBlob, } from "@singularity-layer/agentvault-core";
|
|
5
|
+
import { createRegistry, discover, encrypt, hermesAdapter, openclawAdapter, packAgent, restoreBlob, restoreBlobWith, blobInfo, encryptV2, uploadBlob, } from "@singularity-layer/agentvault-core";
|
|
6
6
|
import { createClient } from "./client.js";
|
|
7
7
|
import { createConfigStore } from "./config.js";
|
|
8
8
|
import { clackPrompter, consoleLogger } from "./io.js";
|
|
@@ -81,6 +81,9 @@ export const realCore = {
|
|
|
81
81
|
encrypt,
|
|
82
82
|
uploadBlob,
|
|
83
83
|
restoreBlob,
|
|
84
|
+
restoreBlobWith,
|
|
85
|
+
blobInfo,
|
|
86
|
+
encryptV2,
|
|
84
87
|
downloadBlob,
|
|
85
88
|
};
|
|
86
89
|
export const realIo = { prompter: clackPrompter, logger: consoleLogger };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
+
/**
|
|
4
|
+
* True when this file is the program being run, including through the npm bin symlink (`agentvault`),
|
|
5
|
+
* whose argv[1] does not end in index.js. Compared by real path.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isEntrypoint(argv1: string | undefined, self?: string): boolean;
|
|
3
8
|
export declare function buildProgram(): Command;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
3
5
|
import { Command } from "commander";
|
|
4
6
|
// The single source of truth for the version is package.json.
|
|
5
7
|
const PKG_VERSION = createRequire(import.meta.url)("../package.json").version;
|
|
@@ -13,10 +15,30 @@ import { createDeviceAuth } from "./deviceAuth.js";
|
|
|
13
15
|
import { openBrowser } from "./deps.js";
|
|
14
16
|
import { keychainPassphraseOrThrow, runPassphraseClear, runPassphraseSet, } from "./commands/passphrase.js";
|
|
15
17
|
import { runRestore } from "./commands/restore.js";
|
|
18
|
+
import { runPqDisable, runPqEnablePublic, runPqInit, runPqRecoveryCode, runPqStatus } from "./commands/pq.js";
|
|
19
|
+
import { showOnTerminal } from "./tty.js";
|
|
20
|
+
import { readVaultKey, vaultKeyFromRecoveryCode } from "./pqkey.js";
|
|
21
|
+
import { argvLeaksRecoveryCode, readAllStdin, RecoveryCodeInArgvError, resolveRecoveryCode } from "./recoveryInput.js";
|
|
16
22
|
import { createConfigStore } from "./config.js";
|
|
17
23
|
import { buildCustomTarget } from "./customTarget.js";
|
|
18
24
|
import { authedClient, downloadBlob, homedir, realCore, realDaemonFs, realExec, realIo, resolveBinPath, } from "./deps.js";
|
|
19
25
|
import { createKeychain } from "./keychain.js";
|
|
26
|
+
/**
|
|
27
|
+
* True when this file is the program being run, including through the npm bin symlink (`agentvault`),
|
|
28
|
+
* whose argv[1] does not end in index.js. Compared by real path.
|
|
29
|
+
*/
|
|
30
|
+
export function isEntrypoint(argv1, self = fileURLToPath(import.meta.url)) {
|
|
31
|
+
if (!argv1)
|
|
32
|
+
return false;
|
|
33
|
+
if (argv1.endsWith("index.js"))
|
|
34
|
+
return true;
|
|
35
|
+
try {
|
|
36
|
+
return realpathSync(argv1) === realpathSync(self);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
20
42
|
export function buildProgram() {
|
|
21
43
|
const program = new Command();
|
|
22
44
|
program
|
|
@@ -90,11 +112,22 @@ export function buildProgram() {
|
|
|
90
112
|
const resolvePassphrase = nonInteractive
|
|
91
113
|
? () => keychainPassphraseOrThrow(keychain)
|
|
92
114
|
: () => realIo.prompter.password("Backup passphrase (you'll need this to restore)");
|
|
115
|
+
// Opt-in post-quantum encryption (format v2): encrypt to the vault public key, plus the passphrase
|
|
116
|
+
// only if the user chose a second way in. Off = the v1 passphrase envelope, unchanged.
|
|
117
|
+
const pq = createConfigStore().load().pq;
|
|
118
|
+
const pqOn = Boolean(pq?.enabled);
|
|
119
|
+
const pqKey = pqOn ? Buffer.from(pq.publicKey, "base64") : null;
|
|
120
|
+
if (pqOn)
|
|
121
|
+
realIo.logger.info(`Post-quantum encryption on (vault key ${pq.keyId}).`);
|
|
122
|
+
const encrypt = pqOn
|
|
123
|
+
? async (tarball, pass, aad) => realCore.encryptV2(tarball, { recipients: [pqKey], passphrase: pq.alsoPassphrase ? pass : undefined }, aad)
|
|
124
|
+
: realCore.encrypt;
|
|
93
125
|
await runBackup({
|
|
94
126
|
client,
|
|
95
127
|
discover: realCore.discover,
|
|
96
128
|
packAgent: realCore.packAgent,
|
|
97
|
-
encrypt
|
|
129
|
+
encrypt,
|
|
130
|
+
needsPassphrase: pqOn ? pq.alsoPassphrase : true,
|
|
98
131
|
uploadBlob: realCore.uploadBlob,
|
|
99
132
|
resolvePassphrase,
|
|
100
133
|
prompter: realIo.prompter,
|
|
@@ -115,7 +148,26 @@ export function buildProgram() {
|
|
|
115
148
|
.command("restore")
|
|
116
149
|
.description("Restore an agent backup")
|
|
117
150
|
.option("--dest <dir>", "destination directory", process.cwd())
|
|
151
|
+
.option("--vault-key <file>", "vault private key file for post-quantum backups (default: ~/.agentvault/vault-key.json)")
|
|
152
|
+
.option("--recovery-code", "enter your AVPQ1- recovery code at a hidden prompt (never pass it as a value)")
|
|
153
|
+
.option("--recovery-code-stdin", "read the recovery code from standard input (use with --backup <id>)")
|
|
154
|
+
.option("--backup <id>", "restore this backup id without asking")
|
|
118
155
|
.action(async (opts) => {
|
|
156
|
+
let recoveryCode;
|
|
157
|
+
try {
|
|
158
|
+
recoveryCode = await resolveRecoveryCode({
|
|
159
|
+
argv: process.argv.slice(2),
|
|
160
|
+
prompt: Boolean(opts.recoveryCode),
|
|
161
|
+
stdin: Boolean(opts.recoveryCodeStdin),
|
|
162
|
+
prompter: realIo.prompter,
|
|
163
|
+
readStdin: readAllStdin,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
realIo.logger.error(e instanceof Error ? e.message : String(e));
|
|
168
|
+
process.exitCode = 1;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
119
171
|
const { client } = authedClient();
|
|
120
172
|
await runRestore({
|
|
121
173
|
client,
|
|
@@ -123,7 +175,19 @@ export function buildProgram() {
|
|
|
123
175
|
restoreBlob: realCore.restoreBlob,
|
|
124
176
|
prompter: realIo.prompter,
|
|
125
177
|
logger: realIo.logger,
|
|
126
|
-
|
|
178
|
+
pq: {
|
|
179
|
+
blobInfo: realCore.blobInfo,
|
|
180
|
+
restoreWith: realCore.restoreBlobWith,
|
|
181
|
+
vaultKey: () => recoveryCode
|
|
182
|
+
? vaultKeyFromRecoveryCode(recoveryCode)
|
|
183
|
+
: readVaultKey(opts.vaultKey ? String(opts.vaultKey) : undefined),
|
|
184
|
+
},
|
|
185
|
+
}, {
|
|
186
|
+
dest: opts.dest,
|
|
187
|
+
backupId: opts.backup ? String(opts.backup) : undefined,
|
|
188
|
+
// stdin carries the recovery code, so the backup cannot be picked interactively.
|
|
189
|
+
noPrompts: Boolean(opts.recoveryCodeStdin),
|
|
190
|
+
});
|
|
127
191
|
});
|
|
128
192
|
program
|
|
129
193
|
.command("list")
|
|
@@ -132,6 +196,43 @@ export function buildProgram() {
|
|
|
132
196
|
const { client } = authedClient();
|
|
133
197
|
await runList({ client, logger: realIo.logger });
|
|
134
198
|
});
|
|
199
|
+
const pqCmd = program
|
|
200
|
+
.command("pq")
|
|
201
|
+
.description("Opt-in post-quantum encryption for backups (X25519 + ML-KEM-768 vault key)");
|
|
202
|
+
const pqDeps = () => ({ store: createConfigStore(), logger: realIo.logger, prompter: realIo.prompter, showSecret: showOnTerminal });
|
|
203
|
+
pqCmd
|
|
204
|
+
.command("init")
|
|
205
|
+
.description("Create a vault key on this machine and encrypt new backups to it")
|
|
206
|
+
.option("--also-passphrase", "also let your passphrase restore new backups", false)
|
|
207
|
+
.action(async (opts) => {
|
|
208
|
+
await runPqInit(pqDeps(), { alsoPassphrase: Boolean(opts.alsoPassphrase) });
|
|
209
|
+
});
|
|
210
|
+
pqCmd
|
|
211
|
+
.command("enable")
|
|
212
|
+
.description("Encrypt new backups to a vault public key made on another machine (write-only machine)")
|
|
213
|
+
.requiredOption("--public-key <base64>", "the vault public key (agentvault pq status on the key's machine)")
|
|
214
|
+
.option("--also-passphrase", "also let your passphrase restore new backups", false)
|
|
215
|
+
.action(async (opts) => {
|
|
216
|
+
await runPqEnablePublic(pqDeps(), { publicKey: String(opts.publicKey), alsoPassphrase: Boolean(opts.alsoPassphrase) });
|
|
217
|
+
});
|
|
218
|
+
pqCmd
|
|
219
|
+
.command("disable")
|
|
220
|
+
.description("Go back to passphrase-only encryption for new backups")
|
|
221
|
+
.action(async () => {
|
|
222
|
+
await runPqDisable(pqDeps());
|
|
223
|
+
});
|
|
224
|
+
pqCmd
|
|
225
|
+
.command("recovery-code")
|
|
226
|
+
.description("Show this machine's vault key recovery code (interactive terminal only)")
|
|
227
|
+
.action(async () => {
|
|
228
|
+
await runPqRecoveryCode(pqDeps());
|
|
229
|
+
});
|
|
230
|
+
pqCmd
|
|
231
|
+
.command("status")
|
|
232
|
+
.description("Show the post-quantum encryption setting and key")
|
|
233
|
+
.action(async () => {
|
|
234
|
+
await runPqStatus(pqDeps());
|
|
235
|
+
});
|
|
135
236
|
const passphrase = program
|
|
136
237
|
.command("passphrase")
|
|
137
238
|
.description("Manage the stored backup passphrase");
|
|
@@ -188,6 +289,12 @@ export function buildProgram() {
|
|
|
188
289
|
});
|
|
189
290
|
return program;
|
|
190
291
|
}
|
|
191
|
-
if (process.argv[1]
|
|
292
|
+
if (isEntrypoint(process.argv[1])) {
|
|
293
|
+
// Checked BEFORE commander parses: a value attached to an unknown or boolean option would otherwise be
|
|
294
|
+
// echoed back in commander's own error message.
|
|
295
|
+
if (argvLeaksRecoveryCode(process.argv.slice(2))) {
|
|
296
|
+
process.stderr.write(`${new RecoveryCodeInArgvError().message}\n`);
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
192
299
|
buildProgram().parseAsync(process.argv);
|
|
193
300
|
}
|
package/dist/pqkey.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type VaultKey } from "@singularity-layer/agentvault-core";
|
|
2
|
+
/**
|
|
3
|
+
* The vault PRIVATE key file. Owner-only (0600 file in a 0700 dir), never uploaded, never sent to the API.
|
|
4
|
+
* Machines that only make backups do not need it; only machines that restore do.
|
|
5
|
+
*/
|
|
6
|
+
export declare function vaultKeyPath(home?: string): string;
|
|
7
|
+
export declare function vaultKeyExists(home?: string): boolean;
|
|
8
|
+
export declare function writeVaultKey(key: VaultKey, home?: string): string;
|
|
9
|
+
/** Load a vault key from a file path, or from the default location. Null if none. */
|
|
10
|
+
export declare function readVaultKey(file?: string, home?: string): VaultKey | null;
|
|
11
|
+
export declare function vaultKeyFromRecoveryCode(code: string): VaultKey;
|
package/dist/pqkey.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { decodeRecoveryCode, vaultKeyFromSecret } from "@singularity-layer/agentvault-core";
|
|
4
|
+
import { resolveHome } from "./config.js";
|
|
5
|
+
/**
|
|
6
|
+
* The vault PRIVATE key file. Owner-only (0600 file in a 0700 dir), never uploaded, never sent to the API.
|
|
7
|
+
* Machines that only make backups do not need it; only machines that restore do.
|
|
8
|
+
*/
|
|
9
|
+
export function vaultKeyPath(home) {
|
|
10
|
+
return join(resolveHome(home), "vault-key.json");
|
|
11
|
+
}
|
|
12
|
+
export function vaultKeyExists(home) {
|
|
13
|
+
return existsSync(vaultKeyPath(home));
|
|
14
|
+
}
|
|
15
|
+
export function writeVaultKey(key, home) {
|
|
16
|
+
const dir = resolveHome(home);
|
|
17
|
+
const file = vaultKeyPath(home);
|
|
18
|
+
if (existsSync(file)) {
|
|
19
|
+
// Overwriting would orphan every backup made with the old key. Never do it silently.
|
|
20
|
+
throw new Error(`A vault key already exists at ${file}. Move it somewhere safe first; backups made with it need it to restore.`);
|
|
21
|
+
}
|
|
22
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
23
|
+
writeFileSync(file, JSON.stringify({
|
|
24
|
+
version: 1,
|
|
25
|
+
algorithm: "X-Wing (X25519 + ML-KEM-768)",
|
|
26
|
+
keyId: key.keyId,
|
|
27
|
+
publicKey: key.publicKey.toString("base64"),
|
|
28
|
+
secretKey: key.secretKey.toString("base64"),
|
|
29
|
+
createdAt: new Date().toISOString(),
|
|
30
|
+
}, null, 2), { mode: 0o600, flag: "wx" });
|
|
31
|
+
try {
|
|
32
|
+
chmodSync(dir, 0o700);
|
|
33
|
+
chmodSync(file, 0o600);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// exotic filesystem; the file was created with 0600 already
|
|
37
|
+
}
|
|
38
|
+
return file;
|
|
39
|
+
}
|
|
40
|
+
/** Load a vault key from a file path, or from the default location. Null if none. */
|
|
41
|
+
export function readVaultKey(file, home) {
|
|
42
|
+
const path = file ?? vaultKeyPath(home);
|
|
43
|
+
if (!existsSync(path)) {
|
|
44
|
+
if (file)
|
|
45
|
+
throw new Error(`No vault key file at ${file}`);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
// Errors here never include file contents: a damaged key file can still hold most of the private key.
|
|
49
|
+
let parsed;
|
|
50
|
+
try {
|
|
51
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error(`${path} is damaged (not valid JSON)`);
|
|
55
|
+
}
|
|
56
|
+
if (typeof parsed.secretKey !== "string")
|
|
57
|
+
throw new Error(`${path} is not an Agent Vault key file`);
|
|
58
|
+
let key;
|
|
59
|
+
try {
|
|
60
|
+
key = vaultKeyFromSecret(Buffer.from(parsed.secretKey, "base64"));
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw new Error(`${path} is damaged (the key has the wrong size)`);
|
|
64
|
+
}
|
|
65
|
+
if (typeof parsed.keyId === "string" && parsed.keyId !== key.keyId) {
|
|
66
|
+
throw new Error(`${path} is damaged: its key id does not match its key`);
|
|
67
|
+
}
|
|
68
|
+
return key;
|
|
69
|
+
}
|
|
70
|
+
export function vaultKeyFromRecoveryCode(code) {
|
|
71
|
+
return vaultKeyFromSecret(decodeRecoveryCode(code));
|
|
72
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the post-quantum recovery code reaches the CLI. NEVER as a command-line value: argv is visible to
|
|
3
|
+
* every process on the machine (ps, /proc) and lands in shell history. So `--recovery-code` is a flag that
|
|
4
|
+
* opens a hidden prompt, and `--recovery-code-stdin` reads it from standard input (for scripts:
|
|
5
|
+
* `agentvault restore --recovery-code-stdin < code.txt`). A code typed into argv anyway is refused.
|
|
6
|
+
*/
|
|
7
|
+
import type { Prompter } from "./io.js";
|
|
8
|
+
export declare class RecoveryCodeInArgvError extends Error {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
/** True if any argv element carries a recovery code value. */
|
|
12
|
+
export declare function argvLeaksRecoveryCode(argv: string[]): boolean;
|
|
13
|
+
export declare function resolveRecoveryCode(input: {
|
|
14
|
+
argv: string[];
|
|
15
|
+
prompt: boolean;
|
|
16
|
+
stdin: boolean;
|
|
17
|
+
prompter: Prompter;
|
|
18
|
+
readStdin: () => Promise<string>;
|
|
19
|
+
}): Promise<string | null>;
|
|
20
|
+
export declare function readAllStdin(): Promise<string>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class RecoveryCodeInArgvError extends Error {
|
|
2
|
+
constructor() {
|
|
3
|
+
super("Do not put the recovery code on the command line (it ends up in shell history and the process list). " +
|
|
4
|
+
"Use `agentvault restore --recovery-code` (hidden prompt) or `--recovery-code-stdin`.");
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/** True if any argv element carries a recovery code value. */
|
|
8
|
+
export function argvLeaksRecoveryCode(argv) {
|
|
9
|
+
return argv.some((a) => /^--recovery-code=/i.test(a) || /^--recovery-code-stdin=/i.test(a) || /AVPQ1-/i.test(a));
|
|
10
|
+
}
|
|
11
|
+
export async function resolveRecoveryCode(input) {
|
|
12
|
+
if (argvLeaksRecoveryCode(input.argv))
|
|
13
|
+
throw new RecoveryCodeInArgvError();
|
|
14
|
+
if (input.stdin) {
|
|
15
|
+
const code = (await input.readStdin()).trim();
|
|
16
|
+
if (!code)
|
|
17
|
+
throw new Error("No recovery code on stdin.");
|
|
18
|
+
return code;
|
|
19
|
+
}
|
|
20
|
+
if (input.prompt)
|
|
21
|
+
return (await input.prompter.password("Recovery code (AVPQ1-...)")).trim();
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
export async function readAllStdin() {
|
|
25
|
+
const chunks = [];
|
|
26
|
+
for await (const c of process.stdin)
|
|
27
|
+
chunks.push(Buffer.from(c));
|
|
28
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
29
|
+
}
|
package/dist/tty.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write a secret straight to the controlling terminal, bypassing stdout and stderr, so redirected or
|
|
3
|
+
* captured output (CI logs, `| tee`, agent transcripts) never contains it. Returns false when there is
|
|
4
|
+
* no interactive terminal; the caller then tells the user how to see it later.
|
|
5
|
+
*/
|
|
6
|
+
export declare function showOnTerminal(label: string, secret: string): boolean;
|
package/dist/tty.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { closeSync, openSync, writeSync } from "node:fs";
|
|
2
|
+
/**
|
|
3
|
+
* Write a secret straight to the controlling terminal, bypassing stdout and stderr, so redirected or
|
|
4
|
+
* captured output (CI logs, `| tee`, agent transcripts) never contains it. Returns false when there is
|
|
5
|
+
* no interactive terminal; the caller then tells the user how to see it later.
|
|
6
|
+
*/
|
|
7
|
+
export function showOnTerminal(label, secret) {
|
|
8
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY || process.platform === "win32")
|
|
9
|
+
return false;
|
|
10
|
+
let fd = null;
|
|
11
|
+
try {
|
|
12
|
+
fd = openSync("/dev/tty", "w");
|
|
13
|
+
writeSync(fd, `\n${label}\n\n ${secret}\n\n`);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
if (fd !== null)
|
|
21
|
+
closeSync(fd);
|
|
22
|
+
}
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@singularity-layer/agentvault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"agentvault": "dist/index.js"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@clack/prompts": "^0.7.0",
|
|
11
11
|
"commander": "^12.1.0",
|
|
12
|
-
"@singularity-layer/agentvault-core": "0.
|
|
12
|
+
"@singularity-layer/agentvault-core": "0.2.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"vitest": "^2.1.0",
|