@oneie/cli 5.7.6 → 5.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -1
- package/dist/package.json +7 -8
- package/dist/src/age-yefbe8pe.js +1 -0
- package/dist/src/evm-tx-ee2q0e3w.js +1 -0
- package/dist/src/hl-run-tgrkrk69.js +1 -0
- package/dist/src/index-0rj9wdk9.js +4 -0
- package/dist/src/index-91y484c2.js +2052 -0
- package/dist/src/index-940y3rnv.js +12 -0
- package/dist/src/index.js +1047 -121
- package/dist/src/message-key-db1xjdkw.js +1 -0
- package/dist/src/message-lock-5vr8079x.js +5 -0
- package/dist/src/sweep-order-c2p6rk8c.js +1 -0
- package/dist/src/sweep-runner-t68xe7vx.js +1 -0
- package/package.json +7 -8
- package/dist/src/agent.d.ts +0 -75
- package/dist/src/agent.js +0 -1334
- package/dist/src/agentverse.d.ts +0 -26
- package/dist/src/agentverse.js +0 -171
- package/dist/src/args.d.ts +0 -9
- package/dist/src/args.js +0 -61
- package/dist/src/auth.d.ts +0 -6
- package/dist/src/auth.js +0 -121
- package/dist/src/balances.d.ts +0 -89
- package/dist/src/balances.js +0 -202
- package/dist/src/banner.d.ts +0 -1
- package/dist/src/banner.js +0 -17
- package/dist/src/broadcast.d.ts +0 -8
- package/dist/src/broadcast.js +0 -175
- package/dist/src/catalog.d.ts +0 -12
- package/dist/src/catalog.js +0 -76
- package/dist/src/chat.d.ts +0 -2
- package/dist/src/chat.js +0 -92
- package/dist/src/client.d.ts +0 -5
- package/dist/src/client.js +0 -157
- package/dist/src/compiler.d.ts +0 -36
- package/dist/src/compiler.js +0 -366
- package/dist/src/config.d.ts +0 -24
- package/dist/src/config.js +0 -70
- package/dist/src/connect.d.ts +0 -2
- package/dist/src/connect.js +0 -64
- package/dist/src/coordinate.d.ts +0 -3
- package/dist/src/coordinate.js +0 -58
- package/dist/src/create.d.ts +0 -2
- package/dist/src/create.js +0 -113
- package/dist/src/deploy.d.ts +0 -2
- package/dist/src/deploy.js +0 -19
- package/dist/src/dev.d.ts +0 -2
- package/dist/src/dev.js +0 -75
- package/dist/src/device-flow.d.ts +0 -57
- package/dist/src/device-flow.js +0 -173
- package/dist/src/doctor.d.ts +0 -26
- package/dist/src/doctor.js +0 -146
- package/dist/src/draw.d.ts +0 -18
- package/dist/src/draw.js +0 -156
- package/dist/src/endpoint.d.ts +0 -2
- package/dist/src/endpoint.js +0 -250
- package/dist/src/env.d.ts +0 -3
- package/dist/src/env.js +0 -37
- package/dist/src/eval.d.ts +0 -2
- package/dist/src/eval.js +0 -43
- package/dist/src/fn.d.ts +0 -2
- package/dist/src/fn.js +0 -70
- package/dist/src/group.d.ts +0 -2
- package/dist/src/group.js +0 -117
- package/dist/src/hl-run.d.ts +0 -119
- package/dist/src/hl-run.js +0 -480
- package/dist/src/hl.d.ts +0 -17
- package/dist/src/hl.js +0 -148
- package/dist/src/index.d.ts +0 -2
- package/dist/src/init.d.ts +0 -76
- package/dist/src/init.js +0 -278
- package/dist/src/join.d.ts +0 -11
- package/dist/src/join.js +0 -293
- package/dist/src/key-publish.d.ts +0 -40
- package/dist/src/key-publish.js +0 -232
- package/dist/src/key-seal.d.ts +0 -21
- package/dist/src/key-seal.js +0 -142
- package/dist/src/key-sweep.d.ts +0 -93
- package/dist/src/key-sweep.js +0 -263
- package/dist/src/key.d.ts +0 -26
- package/dist/src/key.js +0 -338
- package/dist/src/lib/age-plugin.d.ts +0 -51
- package/dist/src/lib/age-plugin.js +0 -130
- package/dist/src/lib/agent-env.d.ts +0 -12
- package/dist/src/lib/agent-env.js +0 -48
- package/dist/src/lib/api-path.d.ts +0 -2
- package/dist/src/lib/api-path.js +0 -40
- package/dist/src/lib/asker.d.ts +0 -34
- package/dist/src/lib/asker.js +0 -126
- package/dist/src/lib/client.d.ts +0 -20
- package/dist/src/lib/client.js +0 -71
- package/dist/src/lib/env-sealed.d.ts +0 -53
- package/dist/src/lib/env-sealed.js +0 -184
- package/dist/src/lib/flow-tag.d.ts +0 -86
- package/dist/src/lib/flow-tag.js +0 -230
- package/dist/src/lib/hl-core/actions.d.ts +0 -99
- package/dist/src/lib/hl-core/actions.js +0 -69
- package/dist/src/lib/hl-core/eip712.d.ts +0 -33
- package/dist/src/lib/hl-core/eip712.js +0 -107
- package/dist/src/lib/hl-core/errors.d.ts +0 -10
- package/dist/src/lib/hl-core/errors.js +0 -15
- package/dist/src/lib/hl-core/exchange.d.ts +0 -24
- package/dist/src/lib/hl-core/exchange.js +0 -47
- package/dist/src/lib/hl-core/index.d.ts +0 -13
- package/dist/src/lib/hl-core/index.js +0 -14
- package/dist/src/lib/hl-core/meta.d.ts +0 -57
- package/dist/src/lib/hl-core/meta.js +0 -110
- package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
- package/dist/src/lib/hl-core/msgpack.js +0 -136
- package/dist/src/lib/hl-core/net.d.ts +0 -2
- package/dist/src/lib/hl-core/net.js +0 -7
- package/dist/src/lib/hl-core/signing.d.ts +0 -103
- package/dist/src/lib/hl-core/signing.js +0 -295
- package/dist/src/lib/hl-core/wire.d.ts +0 -34
- package/dist/src/lib/hl-core/wire.js +0 -81
- package/dist/src/lib/invoked-as.d.ts +0 -2
- package/dist/src/lib/invoked-as.js +0 -24
- package/dist/src/lib/journey-words.d.ts +0 -84
- package/dist/src/lib/journey-words.js +0 -360
- package/dist/src/lib/journey.d.ts +0 -148
- package/dist/src/lib/journey.js +0 -245
- package/dist/src/lib/key-receipt.d.ts +0 -48
- package/dist/src/lib/key-receipt.js +0 -116
- package/dist/src/lib/key-source.d.ts +0 -9
- package/dist/src/lib/key-source.js +0 -33
- package/dist/src/lib/keyfile.d.ts +0 -136
- package/dist/src/lib/keyfile.js +0 -397
- package/dist/src/lib/launch-claude.d.ts +0 -5
- package/dist/src/lib/launch-claude.js +0 -45
- package/dist/src/lib/lock-lookup.d.ts +0 -40
- package/dist/src/lib/lock-lookup.js +0 -92
- package/dist/src/lib/message-seal.d.ts +0 -63
- package/dist/src/lib/message-seal.js +0 -150
- package/dist/src/lib/network.d.ts +0 -15
- package/dist/src/lib/network.js +0 -41
- package/dist/src/lib/paths.d.ts +0 -41
- package/dist/src/lib/paths.js +0 -91
- package/dist/src/lib/plan-draw.d.ts +0 -56
- package/dist/src/lib/plan-draw.js +0 -219
- package/dist/src/lib/plan-live.d.ts +0 -20
- package/dist/src/lib/plan-live.js +0 -192
- package/dist/src/lib/qr.d.ts +0 -21
- package/dist/src/lib/qr.js +0 -402
- package/dist/src/lib/roster.d.ts +0 -20
- package/dist/src/lib/roster.js +0 -79
- package/dist/src/lib/sale-card.d.ts +0 -117
- package/dist/src/lib/sale-card.js +0 -261
- package/dist/src/lib/shop-init.d.ts +0 -62
- package/dist/src/lib/shop-init.js +0 -63
- package/dist/src/lib/sui-grpc-send.d.ts +0 -50
- package/dist/src/lib/sui-grpc-send.js +0 -89
- package/dist/src/lib/swap-core.d.ts +0 -163
- package/dist/src/lib/swap-core.js +0 -405
- package/dist/src/lib/tasks-digest.d.ts +0 -66
- package/dist/src/lib/tasks-digest.js +0 -200
- package/dist/src/lib/tasks-graph.d.ts +0 -79
- package/dist/src/lib/tasks-graph.js +0 -463
- package/dist/src/lib/tasks-lens.d.ts +0 -31
- package/dist/src/lib/tasks-lens.js +0 -47
- package/dist/src/lib/tasks-next.d.ts +0 -25
- package/dist/src/lib/tasks-next.js +0 -103
- package/dist/src/lib/tasks-prove.d.ts +0 -15
- package/dist/src/lib/tasks-prove.js +0 -68
- package/dist/src/lib/tasks-route.d.ts +0 -29
- package/dist/src/lib/tasks-route.js +0 -151
- package/dist/src/lib/tasks-score.d.ts +0 -36
- package/dist/src/lib/tasks-score.js +0 -152
- package/dist/src/lib/tasks-workspace.d.ts +0 -18
- package/dist/src/lib/tasks-workspace.js +0 -73
- package/dist/src/lib/vault-read.d.ts +0 -24
- package/dist/src/lib/vault-read.js +0 -77
- package/dist/src/lib/vaultfile.d.ts +0 -88
- package/dist/src/lib/vaultfile.js +0 -222
- package/dist/src/lib/wallet-money.d.ts +0 -222
- package/dist/src/lib/wallet-money.js +0 -578
- package/dist/src/lib/wallet-request.d.ts +0 -50
- package/dist/src/lib/wallet-request.js +0 -86
- package/dist/src/links.d.ts +0 -5
- package/dist/src/links.js +0 -45
- package/dist/src/media.d.ts +0 -29
- package/dist/src/media.js +0 -487
- package/dist/src/message-receipt.d.ts +0 -25
- package/dist/src/message-receipt.js +0 -71
- package/dist/src/message.d.ts +0 -13
- package/dist/src/message.js +0 -92
- package/dist/src/onboard.d.ts +0 -16
- package/dist/src/onboard.js +0 -149
- package/dist/src/plugin.d.ts +0 -2
- package/dist/src/plugin.js +0 -193
- package/dist/src/push.d.ts +0 -2
- package/dist/src/push.js +0 -115
- package/dist/src/render.d.ts +0 -21
- package/dist/src/render.js +0 -32
- package/dist/src/secrets-device.d.ts +0 -32
- package/dist/src/secrets-device.js +0 -127
- package/dist/src/secrets-give.d.ts +0 -125
- package/dist/src/secrets-give.js +0 -236
- package/dist/src/secrets-list.d.ts +0 -27
- package/dist/src/secrets-list.js +0 -84
- package/dist/src/secrets-run.d.ts +0 -31
- package/dist/src/secrets-run.js +0 -182
- package/dist/src/secrets.d.ts +0 -33
- package/dist/src/secrets.js +0 -200
- package/dist/src/setup.d.ts +0 -6
- package/dist/src/setup.js +0 -127
- package/dist/src/ship.d.ts +0 -2
- package/dist/src/ship.js +0 -18
- package/dist/src/shop.d.ts +0 -10
- package/dist/src/shop.js +0 -110
- package/dist/src/skill-parser.d.ts +0 -14
- package/dist/src/skill-parser.js +0 -113
- package/dist/src/skill.d.ts +0 -2
- package/dist/src/skill.js +0 -493
- package/dist/src/slug.d.ts +0 -2
- package/dist/src/slug.js +0 -6
- package/dist/src/social.d.ts +0 -2
- package/dist/src/social.js +0 -106
- package/dist/src/staff.d.ts +0 -2
- package/dist/src/staff.js +0 -104
- package/dist/src/start.d.ts +0 -15
- package/dist/src/start.js +0 -203
- package/dist/src/status.d.ts +0 -2
- package/dist/src/status.js +0 -52
- package/dist/src/substrate.d.ts +0 -2
- package/dist/src/substrate.js +0 -258
- package/dist/src/swap.d.ts +0 -93
- package/dist/src/swap.js +0 -622
- package/dist/src/tasks.d.ts +0 -2
- package/dist/src/tasks.js +0 -743
- package/dist/src/templates.d.ts +0 -1
- package/dist/src/templates.js +0 -213
- package/dist/src/trade.d.ts +0 -2
- package/dist/src/trade.js +0 -91
- package/dist/src/trail.d.ts +0 -2
- package/dist/src/trail.js +0 -41
- package/dist/src/validate.d.ts +0 -13
- package/dist/src/validate.js +0 -35
- package/dist/src/wallet-money.d.ts +0 -152
- package/dist/src/wallet-money.js +0 -564
- package/dist/src/wallet.d.ts +0 -167
- package/dist/src/wallet.js +0 -855
- package/dist/src/workflow.d.ts +0 -2
- package/dist/src/workflow.js +0 -166
- package/dist/src/write.d.ts +0 -43
- package/dist/src/write.js +0 -180
package/dist/src/lib/keyfile.js
DELETED
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* keyfile.ts — the folder key ceremony.
|
|
3
|
-
*
|
|
4
|
-
* A folder key is a SPENDING CREDENTIAL sitting in a directory someone is about
|
|
5
|
-
* to `git init`. Everything here exists because of that one sentence.
|
|
6
|
-
*
|
|
7
|
-
* THE ORDER IS THE SECURITY. The ignore entry is written BEFORE the key file is
|
|
8
|
-
* created, never after. A key written first and ignored second is exposed for
|
|
9
|
-
* the width of the gap, and the gap is where `git add -A` lives. `writeKeyFolder`
|
|
10
|
-
* therefore refuses to write the key at all if it cannot first prove the path is
|
|
11
|
-
* ignored — an unignorable folder returns `{ ok: false }` rather than a key.
|
|
12
|
-
*
|
|
13
|
-
* WHY A FOLDER AND NOT ~/.config. `oneie init` writes one key to
|
|
14
|
-
* ~/.config/oneie/key, which every project on the machine then shares: one
|
|
15
|
-
* credential, machine-wide blast radius, and no way to revoke a single project
|
|
16
|
-
* without revoking them all. A per-folder key is narrower by construction — it
|
|
17
|
-
* is the project's key, it can be revoked alone, and deleting the project
|
|
18
|
-
* deletes it.
|
|
19
|
-
*
|
|
20
|
-
* WHY THE DOTFILE NAME MATTERS. The repo root .gitignore carries `*.key` (:37)
|
|
21
|
-
* but NOT a bare `key` — so ~/.config/oneie/key would be committed by a scaffold
|
|
22
|
-
* that copied it. The file here is `agent.key`, which `*.key` already covers,
|
|
23
|
-
* AND `.oneie/` is written into the local ignore anyway. Belt and braces, because
|
|
24
|
-
* the scaffold's .gitignore is a file the user is free to edit.
|
|
25
|
-
*
|
|
26
|
-
* WHAT IS DELIBERATELY NOT HERE: wallet key material. The anonymous provision
|
|
27
|
-
* door is safe precisely BECAUSE the identity it mints cannot receive value —
|
|
28
|
-
* `agent-wallet-provision.ts` writes `addressed:false` always ("no server-side
|
|
29
|
-
* key material, ever"), and `isCreditOnlyWallet` keeps such an actor on credits.
|
|
30
|
-
* Minting a fundable identity from an unauthenticated door would turn a free
|
|
31
|
-
* empty-workspace faucet into a wallet faucet. The SERVER still never does:
|
|
32
|
-
* addresses arrive only from a key generated on the agent's machine, and for
|
|
33
|
-
* an agent row only with a signature over a fresh `wallet:challenge`
|
|
34
|
-
* (`@oneie/sdk/address-proof`). `oneie init` now runs that ceremony itself,
|
|
35
|
-
* after this one, sealing the wallet in the `wallet new` vault beside the key —
|
|
36
|
-
* never into it, and plaintext only behind --yes-i-accept-plaintext-file
|
|
37
|
-
* (`provisionLocalWallet` in init.ts; `--no-wallet` skips it).
|
|
38
|
-
*/
|
|
39
|
-
import { mkdirSync, writeFileSync, readFileSync, existsSync, chmodSync, renameSync, rmSync, realpathSync, lstatSync, openSync, writeSync, closeSync, constants as FS, } from 'node:fs';
|
|
40
|
-
import { randomBytes } from 'node:crypto';
|
|
41
|
-
import { join, resolve, relative, isAbsolute } from 'node:path';
|
|
42
|
-
import { CONFIG_DIR, MACHINE_ID_FILE, LEGACY_MACHINE_ID_FILE, firstExisting } from './paths.js';
|
|
43
|
-
/** The per-project directory holding the key, the vault and their metadata. */
|
|
44
|
-
export const KEY_DIR_NAME = '.one';
|
|
45
|
-
/**
|
|
46
|
-
* The pre-rename project directory. READ-ONLY — a folder minted before the
|
|
47
|
-
* rename keeps working; nothing is ever written here again. Same fallback shape
|
|
48
|
-
* as `paths.ts` uses for ~/.config, and for the same reason: a rename must not
|
|
49
|
-
* present as "my key stopped working".
|
|
50
|
-
*/
|
|
51
|
-
export const LEGACY_KEY_DIR_NAME = '.oneie';
|
|
52
|
-
/** `*.key` is already covered by the scaffold's root .gitignore. */
|
|
53
|
-
export const KEY_FILE_NAME = 'agent.key';
|
|
54
|
-
export const META_FILE_NAME = 'agent.json';
|
|
55
|
-
/** What the ignore file must contain before any key is written. */
|
|
56
|
-
const IGNORE_ENTRY = `${KEY_DIR_NAME}/`;
|
|
57
|
-
const IGNORE_BLOCK = [
|
|
58
|
-
'',
|
|
59
|
-
'# ONE — agent credential. Never commit.',
|
|
60
|
-
IGNORE_ENTRY,
|
|
61
|
-
'',
|
|
62
|
-
].join('\n');
|
|
63
|
-
/**
|
|
64
|
-
* True when `.gitignore` already ignores the key directory.
|
|
65
|
-
*
|
|
66
|
-
* Deliberately a literal scan, not a `git check-ignore` shell-out: the folder
|
|
67
|
-
* may not be a git repo yet (that is the common case — `npx oneie` runs before
|
|
68
|
-
* `git init`), and a check that silently passes on "not a repo" would be the
|
|
69
|
-
* false green this whole module exists to avoid.
|
|
70
|
-
*/
|
|
71
|
-
export function ignoresKeyDir(ignoreText) {
|
|
72
|
-
return ignoreText
|
|
73
|
-
.split('\n')
|
|
74
|
-
.map((l) => l.trim())
|
|
75
|
-
.some((l) => l === IGNORE_ENTRY || l === KEY_DIR_NAME || l === `/${IGNORE_ENTRY}` || l === `/${KEY_DIR_NAME}`);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Ensure `<dir>/.gitignore` ignores the key directory. Returns the path on
|
|
79
|
-
* success, or null when it could not be written — in which case the caller must
|
|
80
|
-
* NOT write a key.
|
|
81
|
-
*/
|
|
82
|
-
export function ensureIgnored(dir) {
|
|
83
|
-
const ignorePath = join(dir, '.gitignore');
|
|
84
|
-
try {
|
|
85
|
-
const existing = existsSync(ignorePath) ? readFileSync(ignorePath, 'utf8') : '';
|
|
86
|
-
if (ignoresKeyDir(existing))
|
|
87
|
-
return ignorePath;
|
|
88
|
-
// Append, never rewrite — the scaffold's own ignore rules are not ours to drop.
|
|
89
|
-
const next = existing.length && !existing.endsWith('\n') ? existing + '\n' + IGNORE_BLOCK : existing + IGNORE_BLOCK;
|
|
90
|
-
writeFileSync(ignorePath, next, { mode: 0o644 });
|
|
91
|
-
// Re-read rather than trust the write: a read-only mount or a full disk can
|
|
92
|
-
// fail without throwing on some platforms, and a key must never follow an
|
|
93
|
-
// ignore entry that is not actually on disk.
|
|
94
|
-
return ignoresKeyDir(readFileSync(ignorePath, 'utf8')) ? ignorePath : null;
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Canonical absolute path — symlinks resolved.
|
|
102
|
-
*
|
|
103
|
-
* `resolve()` alone is NOT enough for the path binding. On macOS `/tmp` is a
|
|
104
|
-
* symlink to `/private/tmp` and `/var` to `/private/var`, so a key minted at the
|
|
105
|
-
* path the user typed and read back after a `chdir` compares unequal and a
|
|
106
|
-
* legitimate credential is refused. Home directories and network mounts are
|
|
107
|
-
* symlinked on plenty of real machines too. Compare the REAL path on both sides
|
|
108
|
-
* or the check fails open on attackers and closed on users — the worst pairing.
|
|
109
|
-
*
|
|
110
|
-
* Falls back to `resolve()` when the path does not exist yet (realpath throws).
|
|
111
|
-
*/
|
|
112
|
-
export function canonicalDir(p) {
|
|
113
|
-
return canonical(p);
|
|
114
|
-
}
|
|
115
|
-
function canonical(p) {
|
|
116
|
-
try {
|
|
117
|
-
return realpathSync(resolve(p));
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
return resolve(p);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* A stable, secret-ish id for THIS machine.
|
|
125
|
-
*
|
|
126
|
-
* The path binding alone is not enough where the path is predictable. A repo
|
|
127
|
-
* that ships `.oneie/agent.json` recording `dir:
|
|
128
|
-
* "/home/runner/work/<repo>/<repo>"` matches that path on EVERY GitHub Actions
|
|
129
|
-
* checkout of it — so the clone attack the binding closes for a laptop reopens
|
|
130
|
-
* for CI, which is exactly where nobody is watching. The machine id is a value
|
|
131
|
-
* the attacker cannot guess and cannot read from the victim's repo, so a key
|
|
132
|
-
* must be BOTH at the right path AND on the right machine.
|
|
133
|
-
*
|
|
134
|
-
* Stored 0600 beside the machine-wide key. Not a secret in the cryptographic
|
|
135
|
-
* sense — it authorises nothing on its own — so a read-only or unwritable home
|
|
136
|
-
* degrades to path-only binding rather than refusing all work.
|
|
137
|
-
*/
|
|
138
|
-
export function machineId() {
|
|
139
|
-
try {
|
|
140
|
-
// Read the legacy path too: this id is baked into every .oneie/agent.json
|
|
141
|
-
// already on disk, so minting a fresh one at the new path would flip every
|
|
142
|
-
// existing folder key to `foreign` at once — a mass logout caused by a rename.
|
|
143
|
-
const existing = firstExisting(MACHINE_ID_FILE, LEGACY_MACHINE_ID_FILE);
|
|
144
|
-
if (existing) {
|
|
145
|
-
const v = readFileSync(existing, 'utf8').trim();
|
|
146
|
-
if (v)
|
|
147
|
-
return v;
|
|
148
|
-
}
|
|
149
|
-
const dir = CONFIG_DIR;
|
|
150
|
-
const file = MACHINE_ID_FILE;
|
|
151
|
-
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
152
|
-
const v = randomBytes(16).toString('hex');
|
|
153
|
-
writeFileSync(file, v + '\n', { mode: 0o600 });
|
|
154
|
-
chmodSync(file, 0o600);
|
|
155
|
-
return v;
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Write `data` to `path` at 0600, refusing to follow a symlink.
|
|
163
|
-
*
|
|
164
|
-
* `writeFileSync` FOLLOWS symlinks. An attacker who can pre-plant
|
|
165
|
-
* `.oneie/agent.key.tmp` as a link to a file they control gets our chmod(0600)
|
|
166
|
-
* and our credential written to their target — the classic pre-plant, and the
|
|
167
|
-
* 0700 directory does not help because the link is created before we ever run.
|
|
168
|
-
* `O_NOFOLLOW` makes the kernel refuse, and `O_EXCL` means we never write onto
|
|
169
|
-
* an existing file at all.
|
|
170
|
-
*/
|
|
171
|
-
export function writeSecret(path, data) {
|
|
172
|
-
// Create the 0700 parent HERE rather than assuming a caller did. writeKeyFolder
|
|
173
|
-
// happened to mkdir first; writeVaultFolder did not, and every one of its writes
|
|
174
|
-
// failed with ENOENT until this line existed. A helper that silently depends on
|
|
175
|
-
// an unstated precondition is a helper that works for exactly one caller.
|
|
176
|
-
const parent = join(path, '..');
|
|
177
|
-
assertRealDir(parent);
|
|
178
|
-
mkdirSync(parent, { recursive: true, mode: 0o700 });
|
|
179
|
-
chmodSync(parent, 0o700);
|
|
180
|
-
if (existsSync(path) && !lstatSync(path).isSymbolicLink())
|
|
181
|
-
rmSync(path, { force: true });
|
|
182
|
-
writeNoFollow(path, data);
|
|
183
|
-
}
|
|
184
|
-
function writeNoFollow(path, data) {
|
|
185
|
-
const fd = openSync(path, FS.O_WRONLY | FS.O_CREAT | FS.O_EXCL | FS.O_NOFOLLOW, 0o600);
|
|
186
|
-
try {
|
|
187
|
-
writeSync(fd, data);
|
|
188
|
-
}
|
|
189
|
-
finally {
|
|
190
|
-
closeSync(fd);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/** Refuse a key directory that is a symlink — same pre-plant, one level up. */
|
|
194
|
-
function assertRealDir(p) {
|
|
195
|
-
if (!existsSync(p))
|
|
196
|
-
return;
|
|
197
|
-
const st = lstatSync(p);
|
|
198
|
-
if (st.isSymbolicLink())
|
|
199
|
-
throw new Error(`${p} is a symlink — refusing to write a credential through it`);
|
|
200
|
-
if (!st.isDirectory())
|
|
201
|
-
throw new Error(`${p} exists and is not a directory`);
|
|
202
|
-
}
|
|
203
|
-
/** Reject a directory outside the project — the key belongs to the folder, not above it. */
|
|
204
|
-
function insideProject(dir, target) {
|
|
205
|
-
const rel = relative(resolve(dir), resolve(target));
|
|
206
|
-
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Write the key folder: ignore entry FIRST, then 0700 dir, then 0600 key via
|
|
210
|
-
* tmp+rename so a reader never observes a partial or world-readable file.
|
|
211
|
-
*
|
|
212
|
-
* Refuses (and writes nothing) when the ignore entry cannot be established.
|
|
213
|
-
*/
|
|
214
|
-
export function writeKeyFolder(input) {
|
|
215
|
-
const dir = canonical(input.dir);
|
|
216
|
-
if (!existsSync(dir))
|
|
217
|
-
return { ok: false, error: `no such directory: ${dir}` };
|
|
218
|
-
// 1. IGNORE FIRST. No ignore, no key.
|
|
219
|
-
const ignorePath = ensureIgnored(dir);
|
|
220
|
-
if (!ignorePath) {
|
|
221
|
-
return { ok: false, error: 'could not write .gitignore — refusing to write a credential that git can see' };
|
|
222
|
-
}
|
|
223
|
-
const keyDir = join(dir, KEY_DIR_NAME);
|
|
224
|
-
if (!insideProject(dir, keyDir))
|
|
225
|
-
return { ok: false, error: 'key path escapes the project directory' };
|
|
226
|
-
try {
|
|
227
|
-
// 2. 0700 — the directory itself is not listable by other local users.
|
|
228
|
-
// assertRealDir first: a pre-planted `.oneie` SYMLINK would otherwise be
|
|
229
|
-
// followed by every call below, landing the credential wherever it points.
|
|
230
|
-
assertRealDir(keyDir);
|
|
231
|
-
mkdirSync(keyDir, { recursive: true, mode: 0o700 });
|
|
232
|
-
chmodSync(keyDir, 0o700);
|
|
233
|
-
// 3. 0600 via tmp+rename. The mode is set on the tmp file BEFORE the rename,
|
|
234
|
-
// so the key is never briefly readable at the final path. chmod again
|
|
235
|
-
// because `mode` in writeFileSync is subject to the process umask.
|
|
236
|
-
const keyPath = join(keyDir, KEY_FILE_NAME);
|
|
237
|
-
const tmp = join(keyDir, `.${KEY_FILE_NAME}.tmp`);
|
|
238
|
-
// O_NOFOLLOW|O_EXCL — never follow a pre-planted link, never write onto an
|
|
239
|
-
// existing file. A stale tmp from a crashed run is removed first, by path,
|
|
240
|
-
// after the same symlink check.
|
|
241
|
-
if (existsSync(tmp) && !lstatSync(tmp).isSymbolicLink())
|
|
242
|
-
rmSync(tmp, { force: true });
|
|
243
|
-
writeNoFollow(tmp, input.apiKey + '\n');
|
|
244
|
-
renameSync(tmp, keyPath);
|
|
245
|
-
// 4. Metadata, 0600 as well — regKey is a credential too.
|
|
246
|
-
//
|
|
247
|
-
// BOTH keys land here, and they are not interchangeable. `apiKey` is
|
|
248
|
-
// workspace-scoped and is what an agent authenticates and trades with.
|
|
249
|
-
// `regKey` is uid-bound: receivers keyed on ctx.ownerSlug === uid — e.g.
|
|
250
|
-
// `lifecycle:mine`, which reads the actor's own onboarding progress —
|
|
251
|
-
// return ZERO ROWS for the apiKey, because ownerSlug resolves to the
|
|
252
|
-
// workspace aid and the fresh identity has no rows under it. A folder
|
|
253
|
-
// carrying only apiKey cannot read its own lifecycle.
|
|
254
|
-
const metaPath = join(keyDir, META_FILE_NAME);
|
|
255
|
-
const meta = {
|
|
256
|
-
workspace: input.workspace,
|
|
257
|
-
...(input.uid ? { uid: input.uid } : {}),
|
|
258
|
-
api: input.api,
|
|
259
|
-
// The ABSOLUTE path this key was minted for. readKeyFolder refuses to hand
|
|
260
|
-
// back a credential found at any other path — see its docblock.
|
|
261
|
-
dir,
|
|
262
|
-
// …and the machine. A CI checkout path is guessable; this is not.
|
|
263
|
-
...(machineId() ? { machine: machineId() } : {}),
|
|
264
|
-
...(input.regKey ? { regKey: input.regKey } : {}),
|
|
265
|
-
mintedAt: new Date().toISOString(),
|
|
266
|
-
...(input.expiresAt ? { expiresAt: new Date(input.expiresAt * 1000).toISOString() } : {}),
|
|
267
|
-
...(input.spendLimitUsd !== undefined ? { spendLimitUsd: input.spendLimitUsd } : {}),
|
|
268
|
-
note: 'Credential. Never commit. Revoke with `one auth revoke`.',
|
|
269
|
-
};
|
|
270
|
-
const metaTmp = join(keyDir, `.${META_FILE_NAME}.tmp`);
|
|
271
|
-
if (existsSync(metaTmp) && !lstatSync(metaTmp).isSymbolicLink())
|
|
272
|
-
rmSync(metaTmp, { force: true });
|
|
273
|
-
writeNoFollow(metaTmp, JSON.stringify(meta, null, 2) + '\n');
|
|
274
|
-
renameSync(metaTmp, metaPath);
|
|
275
|
-
return { ok: true, keyPath, metaPath, ignorePath };
|
|
276
|
-
}
|
|
277
|
-
catch (err) {
|
|
278
|
-
return { ok: false, error: `write failed: ${err.message}` };
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Read a folder key back, or null when the folder has none — or when the key
|
|
283
|
-
* found there was minted for a DIFFERENT directory.
|
|
284
|
-
*
|
|
285
|
-
* THE PATH BINDING IS A SECURITY CONTROL, not bookkeeping. `resolveKey` consults
|
|
286
|
-
* the current working directory, so without this check any directory you `cd`
|
|
287
|
-
* into can supply your credentials: clone a repo that ships a `.oneie/agent.key`,
|
|
288
|
-
* run one `one` command inside it, and you are authenticated as WHOEVER MINTED
|
|
289
|
-
* THAT KEY. The damage is not that your key leaks — it is that your next
|
|
290
|
-
* `one push` writes your agents and skills into THEIR workspace, and your next
|
|
291
|
-
* `one trade` spends against their ledger. That is a credential-confusion
|
|
292
|
-
* exfiltration, and the folder-key rung introduced it.
|
|
293
|
-
*
|
|
294
|
-
* `agent.json` records the absolute path the key was minted for, so a key that
|
|
295
|
-
* travelled — by clone, copy, or archive — refuses rather than authenticates.
|
|
296
|
-
* This is the same shape as git's `safe.directory`, decided per key instead of
|
|
297
|
-
* per user.
|
|
298
|
-
*
|
|
299
|
-
* A key with NO recorded `dir` is pre-binding and also refused: the whole point
|
|
300
|
-
* is that an unbound credential is the untrustworthy case, and treating a
|
|
301
|
-
* missing field as permission is how the check gets bypassed by simply deleting
|
|
302
|
-
* a line.
|
|
303
|
-
*/
|
|
304
|
-
export function readKeyFolder(dir) {
|
|
305
|
-
const root = canonical(dir);
|
|
306
|
-
// .one first, then the pre-rename .oneie — a folder minted before the rename
|
|
307
|
-
// keeps working rather than reading as "no key here".
|
|
308
|
-
const keyDir = existsSync(join(root, KEY_DIR_NAME, KEY_FILE_NAME))
|
|
309
|
-
? join(root, KEY_DIR_NAME)
|
|
310
|
-
: join(root, LEGACY_KEY_DIR_NAME);
|
|
311
|
-
const keyPath = join(keyDir, KEY_FILE_NAME);
|
|
312
|
-
if (!existsSync(keyPath))
|
|
313
|
-
return null;
|
|
314
|
-
try {
|
|
315
|
-
const apiKey = readFileSync(keyPath, 'utf8').trim();
|
|
316
|
-
if (!apiKey)
|
|
317
|
-
return null;
|
|
318
|
-
const metaPath = join(keyDir, META_FILE_NAME);
|
|
319
|
-
const meta = existsSync(metaPath)
|
|
320
|
-
? JSON.parse(readFileSync(metaPath, 'utf8'))
|
|
321
|
-
: {};
|
|
322
|
-
if (typeof meta.dir !== 'string' || canonical(meta.dir) !== root)
|
|
323
|
-
return null;
|
|
324
|
-
// The machine binding. Absent in the metadata means a key minted before this
|
|
325
|
-
// existed, or on a machine with no writable home — accepted, because the path
|
|
326
|
-
// binding still holds and refusing would break working setups. PRESENT and
|
|
327
|
-
// DIFFERENT is refused: that is a key that travelled.
|
|
328
|
-
const mine = machineId();
|
|
329
|
-
if (typeof meta.machine === 'string' && mine && meta.machine !== mine)
|
|
330
|
-
return null;
|
|
331
|
-
// Mode and ownership. A credential that is group- or world-readable, or owned
|
|
332
|
-
// by someone else, is not one we should be sending: either it leaked already
|
|
333
|
-
// or it was planted. Checked with lstat so a symlinked key is refused rather
|
|
334
|
-
// than followed to a file whose mode looks fine.
|
|
335
|
-
const st = lstatSync(keyPath);
|
|
336
|
-
if (st.isSymbolicLink())
|
|
337
|
-
return null;
|
|
338
|
-
if ((st.mode & 0o077) !== 0)
|
|
339
|
-
return null;
|
|
340
|
-
if (typeof process.getuid === 'function' && st.uid !== process.getuid())
|
|
341
|
-
return null;
|
|
342
|
-
return { apiKey, meta };
|
|
343
|
-
}
|
|
344
|
-
catch {
|
|
345
|
-
return null;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Why a folder key present on disk was not used. Separate from `readKeyFolder`
|
|
350
|
-
* so a refusal can be EXPLAINED without the reader having to hold a credential:
|
|
351
|
-
* a silent null is right for `resolveKey` and useless for `doctor`.
|
|
352
|
-
*/
|
|
353
|
-
export function keyFolderStatus(dir) {
|
|
354
|
-
const root = canonical(dir);
|
|
355
|
-
const keyPath = existsSync(join(root, KEY_DIR_NAME, KEY_FILE_NAME))
|
|
356
|
-
? join(root, KEY_DIR_NAME, KEY_FILE_NAME)
|
|
357
|
-
: join(root, LEGACY_KEY_DIR_NAME, KEY_FILE_NAME);
|
|
358
|
-
if (!existsSync(keyPath))
|
|
359
|
-
return 'none';
|
|
360
|
-
try {
|
|
361
|
-
if (!readFileSync(keyPath, 'utf8').trim())
|
|
362
|
-
return 'unreadable';
|
|
363
|
-
const metaPath = join(keyPath, '..', META_FILE_NAME);
|
|
364
|
-
if (!existsSync(metaPath))
|
|
365
|
-
return 'foreign';
|
|
366
|
-
const meta = JSON.parse(readFileSync(metaPath, 'utf8'));
|
|
367
|
-
if (typeof meta.dir !== 'string' || canonical(meta.dir) !== root)
|
|
368
|
-
return 'foreign';
|
|
369
|
-
const mine = machineId();
|
|
370
|
-
if (typeof meta.machine === 'string' && mine && meta.machine !== mine)
|
|
371
|
-
return 'foreign';
|
|
372
|
-
const st = lstatSync(keyPath);
|
|
373
|
-
if (st.isSymbolicLink())
|
|
374
|
-
return 'unsafe';
|
|
375
|
-
if ((st.mode & 0o077) !== 0)
|
|
376
|
-
return 'unsafe';
|
|
377
|
-
if (typeof process.getuid === 'function' && st.uid !== process.getuid())
|
|
378
|
-
return 'unsafe';
|
|
379
|
-
return 'ok';
|
|
380
|
-
}
|
|
381
|
-
catch {
|
|
382
|
-
return 'unreadable';
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Which workspace a command acts in: flag > AGENCY_SLUG > the workspace `npx oneie`
|
|
387
|
-
* saved beside this folder's key. The journey already knows the agent's workspace;
|
|
388
|
-
* asking for it again was a dead end (`wallet get`, `whoami`).
|
|
389
|
-
*/
|
|
390
|
-
export function workspaceFor(explicit, dir, env) {
|
|
391
|
-
if (explicit)
|
|
392
|
-
return explicit;
|
|
393
|
-
if (env.AGENCY_SLUG)
|
|
394
|
-
return env.AGENCY_SLUG;
|
|
395
|
-
const saved = readKeyFolder(dir)?.meta.workspace;
|
|
396
|
-
return typeof saved === 'string' && saved ? saved : undefined;
|
|
397
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/** Offer to launch Claude Code in a freshly scaffolded node — port of legacy
|
|
2
|
-
* 3.8.3's launch-claude.js, zero new deps (no chalk/prompts: readline is a
|
|
3
|
-
* node builtin). Only ever prompts a real human TTY; an agent shell or
|
|
4
|
-
* non-interactive run gets the manual instructions and nothing hangs. */
|
|
5
|
-
export declare function maybeLaunchClaude(dir: string): Promise<void>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
-
import { createInterface } from 'node:readline/promises';
|
|
3
|
-
import { isAgentEnvironment } from './agent-env.js';
|
|
4
|
-
function isClaudeInstalled() {
|
|
5
|
-
return spawnSync('which', ['claude'], { stdio: 'ignore' }).status === 0;
|
|
6
|
-
}
|
|
7
|
-
async function confirm(question) {
|
|
8
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
9
|
-
try {
|
|
10
|
-
const answer = (await rl.question(`${question} [Y/n] `)).trim().toLowerCase();
|
|
11
|
-
return answer === '' || answer === 'y' || answer === 'yes';
|
|
12
|
-
}
|
|
13
|
-
finally {
|
|
14
|
-
rl.close();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/** Offer to launch Claude Code in a freshly scaffolded node — port of legacy
|
|
18
|
-
* 3.8.3's launch-claude.js, zero new deps (no chalk/prompts: readline is a
|
|
19
|
-
* node builtin). Only ever prompts a real human TTY; an agent shell or
|
|
20
|
-
* non-interactive run gets the manual instructions and nothing hangs. */
|
|
21
|
-
export async function maybeLaunchClaude(dir) {
|
|
22
|
-
const claudeInstalled = isClaudeInstalled();
|
|
23
|
-
const canPrompt = claudeInstalled && process.stdin.isTTY === true && !isAgentEnvironment();
|
|
24
|
-
if (canPrompt) {
|
|
25
|
-
const launch = await confirm('\nLaunch Claude Code now?');
|
|
26
|
-
if (launch) {
|
|
27
|
-
process.stdout.write('\nLaunching Claude Code — type /do to start building.\n\n');
|
|
28
|
-
await new Promise((done) => {
|
|
29
|
-
const claude = spawn('claude', [], { stdio: 'inherit', cwd: dir });
|
|
30
|
-
claude.on('exit', () => done());
|
|
31
|
-
claude.on('error', (err) => {
|
|
32
|
-
process.stderr.write(`Failed to launch Claude Code: ${err.message}\n`);
|
|
33
|
-
done();
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
process.stdout.write('\nOpen it:\n');
|
|
40
|
-
process.stdout.write(` cd ${dir}\n`);
|
|
41
|
-
if (!claudeInstalled) {
|
|
42
|
-
process.stdout.write(' # Install Claude Code: https://claude.com/product/claude-code\n');
|
|
43
|
-
}
|
|
44
|
-
process.stdout.write(' claude # then type /do to start building\n');
|
|
45
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* lock-lookup.ts — a name's published lock, fetched AND checked, for `one key lock-of`
|
|
3
|
-
* and `one write <slug>` with no `--to`.
|
|
4
|
-
*
|
|
5
|
-
* GET <web base>/api/lock/<slug> → { ok, published, lock, suiAddress, signature, message }
|
|
6
|
-
* GET <web base>/api/lock/<slug>/<agent-id> the same, for an AGENT's own lock
|
|
7
|
-
*
|
|
8
|
-
* THE SERVER IS NOT TRUSTED. The reply is a claim; this file rebuilds the signed text from
|
|
9
|
-
* the slug and the lock, checks the Sui signature itself, and only then hands back a lock
|
|
10
|
-
* (`verifyLockRecord`, @oneie/sdk/message-lock). A swapped lock, a signature made for
|
|
11
|
-
* another name, a signer other than the address named, all stop here. What a terminal
|
|
12
|
-
* cannot check alone is that the signing address belongs to the NAME — that link is the
|
|
13
|
-
* server's, from the account's registered wallet, and every success line says so.
|
|
14
|
-
*
|
|
15
|
-
* Every way a lookup ends is its own code, because an agent branches on them:
|
|
16
|
-
* not_published the name answered and has no lock (a person must publish one)
|
|
17
|
-
* lookup_not_live 404 — the route is not deployed here (never read as "not published")
|
|
18
|
-
* unreachable / lookup_failed could not ask / the door errored
|
|
19
|
-
* unverifiable a lock WAS published and does not check out — never use it
|
|
20
|
-
* The deadline is the same 15s the write door gets (engine rule 4).
|
|
21
|
-
*/
|
|
22
|
-
import type { Fail } from './message-seal.js';
|
|
23
|
-
/** Exit code per refusal class. 1 stays the generic "refused" lane E already used. */
|
|
24
|
-
export declare const EXIT: Record<string, number>;
|
|
25
|
-
export declare const exitFor: (code: string | undefined) => number;
|
|
26
|
-
export interface CheckedLock {
|
|
27
|
-
ok: true;
|
|
28
|
-
/** The workspace half of the name. */
|
|
29
|
-
slug: string;
|
|
30
|
-
/** Set for an agent's lock (`sam/scout`): the agent id. */
|
|
31
|
-
agent?: string;
|
|
32
|
-
/** What was asked and checked: `sam` or `sam/scout`. */
|
|
33
|
-
name: string;
|
|
34
|
-
lock: string;
|
|
35
|
-
suiAddress: string;
|
|
36
|
-
publishedAt: string | null;
|
|
37
|
-
}
|
|
38
|
-
export declare const TRUST_LIMIT = "the signature is checked here; that this Sui address belongs to the name is ONE's word, from the account's registered wallet";
|
|
39
|
-
/** Fetch and verify a name's published lock — `sam`, or `sam/scout` for an agent's own. Never throws. */
|
|
40
|
-
export declare function lookupLock(base: string, name: string, fetchImpl?: typeof fetch): Promise<CheckedLock | Fail>;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* lock-lookup.ts — a name's published lock, fetched AND checked, for `one key lock-of`
|
|
3
|
-
* and `one write <slug>` with no `--to`.
|
|
4
|
-
*
|
|
5
|
-
* GET <web base>/api/lock/<slug> → { ok, published, lock, suiAddress, signature, message }
|
|
6
|
-
* GET <web base>/api/lock/<slug>/<agent-id> the same, for an AGENT's own lock
|
|
7
|
-
*
|
|
8
|
-
* THE SERVER IS NOT TRUSTED. The reply is a claim; this file rebuilds the signed text from
|
|
9
|
-
* the slug and the lock, checks the Sui signature itself, and only then hands back a lock
|
|
10
|
-
* (`verifyLockRecord`, @oneie/sdk/message-lock). A swapped lock, a signature made for
|
|
11
|
-
* another name, a signer other than the address named, all stop here. What a terminal
|
|
12
|
-
* cannot check alone is that the signing address belongs to the NAME — that link is the
|
|
13
|
-
* server's, from the account's registered wallet, and every success line says so.
|
|
14
|
-
*
|
|
15
|
-
* Every way a lookup ends is its own code, because an agent branches on them:
|
|
16
|
-
* not_published the name answered and has no lock (a person must publish one)
|
|
17
|
-
* lookup_not_live 404 — the route is not deployed here (never read as "not published")
|
|
18
|
-
* unreachable / lookup_failed could not ask / the door errored
|
|
19
|
-
* unverifiable a lock WAS published and does not check out — never use it
|
|
20
|
-
* The deadline is the same 15s the write door gets (engine rule 4).
|
|
21
|
-
*/
|
|
22
|
-
/** Exit code per refusal class. 1 stays the generic "refused" lane E already used. */
|
|
23
|
-
export const EXIT = {
|
|
24
|
-
no_key: 2, bad_key: 2, no_slug: 2, bad_derivation: 2,
|
|
25
|
-
unauthorized: 3, no_api_key: 3,
|
|
26
|
-
no_sui_address: 4, wrong_signer: 4, not_the_agent: 4,
|
|
27
|
-
bad_signature: 5, bad_lock: 5, bad_slug: 5, bad_agent: 5,
|
|
28
|
-
unreachable: 6, lookup_not_live: 6, lookup_failed: 6, db_error: 6, no_db: 6, failed: 6,
|
|
29
|
-
not_published: 7,
|
|
30
|
-
unverifiable: 8,
|
|
31
|
-
};
|
|
32
|
-
export const exitFor = (code) => EXIT[code ?? ''] ?? 1;
|
|
33
|
-
const DEADLINE_MS = 15_000;
|
|
34
|
-
export const TRUST_LIMIT = "the signature is checked here; that this Sui address belongs to the name is ONE's word, from the account's registered wallet";
|
|
35
|
-
/** Fetch and verify a name's published lock — `sam`, or `sam/scout` for an agent's own. Never throws. */
|
|
36
|
-
export async function lookupLock(base, name, fetchImpl = (...a) => fetch(...a)) {
|
|
37
|
-
const { parseLockName, verifyLockRecord } = await import('@oneie/sdk/message-lock');
|
|
38
|
-
const parsed = parseLockName(name);
|
|
39
|
-
if (!parsed) {
|
|
40
|
-
return name.includes('/')
|
|
41
|
-
? { ok: false, error: `"${name}" is not an agent name — <workspace>/<agent-id>, the agent id with letters, digits, dots, dashes or underscores`, code: 'bad_agent' }
|
|
42
|
-
: { ok: false, error: `"${name}" is not a name — lowercase letters, digits and dashes`, code: 'bad_slug' };
|
|
43
|
-
}
|
|
44
|
-
const { slug, agent } = parsed;
|
|
45
|
-
const label = agent === undefined ? slug : `${slug}/${agent}`;
|
|
46
|
-
const ctl = new AbortController();
|
|
47
|
-
const timer = setTimeout(() => ctl.abort(), DEADLINE_MS);
|
|
48
|
-
let res;
|
|
49
|
-
try {
|
|
50
|
-
const path = agent === undefined ? encodeURIComponent(slug) : `${encodeURIComponent(slug)}/${encodeURIComponent(agent)}`;
|
|
51
|
-
res = await fetchImpl(`${base}/api/lock/${path}`, { headers: { accept: 'application/json' }, signal: ctl.signal });
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
return { ok: false, error: `could not reach ${base} to look up ${label}'s lock`, code: 'unreachable' };
|
|
55
|
-
}
|
|
56
|
-
finally {
|
|
57
|
-
clearTimeout(timer);
|
|
58
|
-
}
|
|
59
|
-
if (res.status === 404) {
|
|
60
|
-
return { ok: false, error: `the lock lookup is not live on ${base} yet (it answered 404) — nothing is known about ${label}'s lock; pass --to age1… instead`, code: 'lookup_not_live' };
|
|
61
|
-
}
|
|
62
|
-
let body = null;
|
|
63
|
-
try {
|
|
64
|
-
body = (await res.json());
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
/* handled below as lookup_failed */
|
|
68
|
-
}
|
|
69
|
-
if (res.status === 400 && body?.error === 'bad_slug')
|
|
70
|
-
return { ok: false, error: `"${slug}" is not a name`, code: 'bad_slug' };
|
|
71
|
-
if (res.status === 400 && body?.error === 'bad_agent')
|
|
72
|
-
return { ok: false, error: `"${agent}" is not an agent name`, code: 'bad_agent' };
|
|
73
|
-
if (!res.ok || !body || body.ok === false || typeof body.published !== 'boolean') {
|
|
74
|
-
return { ok: false, error: `the lock lookup on ${base} did not answer properly (HTTP ${res.status}${typeof body?.error === 'string' ? `, ${body.error}` : ''}) — try again`, code: 'lookup_failed' };
|
|
75
|
-
}
|
|
76
|
-
if (!body.published) {
|
|
77
|
-
return { ok: false, error: `${label} has not published a lock — ask them for their age1… lock and pass it with --to`, code: 'not_published' };
|
|
78
|
-
}
|
|
79
|
-
const verdict = verifyLockRecord(slug, body, agent);
|
|
80
|
-
if (!verdict.ok) {
|
|
81
|
-
return { ok: false, error: `${label}'s published lock does not check out (${verdict.detail}) — it was NOT used`, code: 'unverifiable' };
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
ok: true,
|
|
85
|
-
slug,
|
|
86
|
-
...(agent === undefined ? {} : { agent }),
|
|
87
|
-
name: label,
|
|
88
|
-
lock: verdict.lock,
|
|
89
|
-
suiAddress: verdict.suiAddress,
|
|
90
|
-
publishedAt: typeof body.publishedAt === 'string' ? body.publishedAt : null,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* message-seal.ts — the shared parts of `one key lock | seal | open | identity` and
|
|
3
|
-
* `one write`: where the key comes from, where the note comes from, and what an age
|
|
4
|
-
* failure is called in plain words.
|
|
5
|
-
*
|
|
6
|
-
* THE KEY NEVER COMES FROM STDIN OR A PROMPT. `seal` and `open` read the NOTE on stdin,
|
|
7
|
-
* so the 24 words cannot also arrive there, and an agent runs these with nothing to
|
|
8
|
-
* prompt. The words come from a key file (`--key`, the file `one key new --out` writes)
|
|
9
|
-
* or from ONE_WALLET_MNEMONIC. No key is an error with a plain sentence, never a hang.
|
|
10
|
-
*
|
|
11
|
-
* THE SDK MODULES LOAD LAZILY, same reason as key-sweep.ts: key.ts registers these
|
|
12
|
-
* commands, so a static import of `@oneie/sdk/age` would crash every `one key` verb —
|
|
13
|
-
* `key new` included — on an installed SDK that predates the export.
|
|
14
|
-
*
|
|
15
|
-
* Derivation and format live in `@oneie/sdk/{age,message-key}`, which are copies of
|
|
16
|
-
* one.ie/web's lib/key/{age,message-key}.ts; the SDK test fails if either drifts.
|
|
17
|
-
*/
|
|
18
|
-
/** The most a note or a file may be read as — a ceiling on a caller-controlled read. */
|
|
19
|
-
export declare const MAX_INPUT_BYTES: number;
|
|
20
|
-
export declare const ageModule: () => Promise<typeof import("@oneie/sdk/age")>;
|
|
21
|
-
export declare const messageKeyModule: () => Promise<typeof import("@oneie/sdk/message-key")>;
|
|
22
|
-
/** The part of `@oneie/sdk/secrets-key` the cli uses, typed here so a typecheck does not need that SDK built. */
|
|
23
|
-
export interface SecretsKeyModule {
|
|
24
|
-
secretsKeyFromPhrase(mnemonic: string): {
|
|
25
|
-
recipient: string;
|
|
26
|
-
publicKey: Uint8Array;
|
|
27
|
-
secret: Uint8Array;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Swappable in tests: the cli resolves `@oneie/sdk` through its own node_modules, which can be a
|
|
32
|
-
* published or main-tree SDK older than `./secrets-key` (C4). A test serves the source instead.
|
|
33
|
-
*/
|
|
34
|
-
export declare const loaders: {
|
|
35
|
-
secretsKey: () => Promise<SecretsKeyModule>;
|
|
36
|
-
};
|
|
37
|
-
export declare const secretsKeyModule: () => Promise<SecretsKeyModule>;
|
|
38
|
-
/** Swappable in tests; the defaults are the process's real stdin. */
|
|
39
|
-
export declare const io: {
|
|
40
|
-
stdinIsTTY: () => boolean;
|
|
41
|
-
readStdin(): Promise<Uint8Array>;
|
|
42
|
-
};
|
|
43
|
-
export type Fail = {
|
|
44
|
-
ok: false;
|
|
45
|
-
error: string;
|
|
46
|
-
code?: string;
|
|
47
|
-
};
|
|
48
|
-
/** The 24 words from a key file. JSON with a `mnemonic` field, or a bare phrase. */
|
|
49
|
-
export declare function wordsFromKeyFile(path: string): string | Fail;
|
|
50
|
-
/** The key's words: --key file, else ONE_WALLET_MNEMONIC. Never stdin, never a prompt. */
|
|
51
|
-
export declare function keyWords(keyPath: string | undefined): string | Fail;
|
|
52
|
-
/** The message key for the given key source, or a plain failure. The caller zeroes `.secret`. */
|
|
53
|
-
export declare function loadMessageKey(keyPath: string | undefined): Promise<Fail | import("@oneie/sdk/message-key").MessageKey>;
|
|
54
|
-
/** The paper (secrets) key for the given key source, or a plain failure. The caller zeroes `.secret`. */
|
|
55
|
-
export declare function loadSecretsKey(keyPath: string | undefined): Promise<{
|
|
56
|
-
recipient: string;
|
|
57
|
-
publicKey: Uint8Array;
|
|
58
|
-
secret: Uint8Array;
|
|
59
|
-
} | Fail>;
|
|
60
|
-
/** A note from a file path, or stdin for `-` / no argument. Refuses a terminal rather than hang. */
|
|
61
|
-
export declare function readNote(arg: string | undefined): Promise<Uint8Array | Fail>;
|
|
62
|
-
/** Plain-word sentences for every way an age note can refuse to open. */
|
|
63
|
-
export declare function ageFailure(e: unknown): Fail;
|