oneie 5.5.2 → 5.7.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.
Files changed (43) hide show
  1. package/README.md +29 -0
  2. package/dist/package.json +2 -2
  3. package/dist/src/index.js +15 -15
  4. package/dist/src/init.d.ts +10 -1
  5. package/dist/src/init.js +26 -11
  6. package/dist/src/join.d.ts +1 -1
  7. package/dist/src/join.js +2 -1
  8. package/dist/src/key-publish.d.ts +40 -0
  9. package/dist/src/key-publish.js +232 -0
  10. package/dist/src/key-seal.d.ts +21 -0
  11. package/dist/src/key-seal.js +142 -0
  12. package/dist/src/key.js +22 -5
  13. package/dist/src/lib/age-plugin.d.ts +51 -0
  14. package/dist/src/lib/age-plugin.js +130 -0
  15. package/dist/src/lib/env-sealed.d.ts +53 -0
  16. package/dist/src/lib/env-sealed.js +184 -0
  17. package/dist/src/lib/journey.d.ts +137 -0
  18. package/dist/src/lib/journey.js +232 -0
  19. package/dist/src/lib/key-receipt.d.ts +48 -0
  20. package/dist/src/lib/key-receipt.js +116 -0
  21. package/dist/src/lib/lock-lookup.d.ts +40 -0
  22. package/dist/src/lib/lock-lookup.js +92 -0
  23. package/dist/src/lib/message-seal.d.ts +63 -0
  24. package/dist/src/lib/message-seal.js +150 -0
  25. package/dist/src/lib/shop-init.js +2 -2
  26. package/dist/src/lib/vault-read.d.ts +24 -0
  27. package/dist/src/lib/vault-read.js +77 -0
  28. package/dist/src/media.d.ts +27 -0
  29. package/dist/src/media.js +249 -18
  30. package/dist/src/secrets-device.d.ts +32 -0
  31. package/dist/src/secrets-device.js +127 -0
  32. package/dist/src/secrets-give.d.ts +125 -0
  33. package/dist/src/secrets-give.js +236 -0
  34. package/dist/src/secrets-run.d.ts +31 -0
  35. package/dist/src/secrets-run.js +182 -0
  36. package/dist/src/secrets.d.ts +32 -0
  37. package/dist/src/secrets.js +197 -0
  38. package/dist/src/social.js +27 -8
  39. package/dist/src/start.d.ts +15 -0
  40. package/dist/src/start.js +200 -0
  41. package/dist/src/write.d.ts +43 -0
  42. package/dist/src/write.js +174 -0
  43. package/package.json +2 -2
@@ -0,0 +1,63 @@
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;
@@ -0,0 +1,150 @@
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
+ import { readFileSync } from 'node:fs';
19
+ /** The most a note or a file may be read as — a ceiling on a caller-controlled read. */
20
+ export const MAX_INPUT_BYTES = 8 * 1024 * 1024;
21
+ export const ageModule = () => import('@oneie/sdk/age');
22
+ export const messageKeyModule = () => import('@oneie/sdk/message-key');
23
+ const SECRETS_KEY_SPEC = '@oneie/sdk/secrets-key'; // a variable, so a bundler/vite does not resolve it at build time
24
+ /**
25
+ * Swappable in tests: the cli resolves `@oneie/sdk` through its own node_modules, which can be a
26
+ * published or main-tree SDK older than `./secrets-key` (C4). A test serves the source instead.
27
+ */
28
+ export const loaders = { secretsKey: () => import(/* @vite-ignore */ SECRETS_KEY_SPEC) };
29
+ export const secretsKeyModule = () => loaders.secretsKey();
30
+ /** Swappable in tests; the defaults are the process's real stdin. */
31
+ export const io = {
32
+ stdinIsTTY: () => Boolean(process.stdin.isTTY),
33
+ async readStdin() {
34
+ const chunks = [];
35
+ let n = 0;
36
+ for await (const c of process.stdin) {
37
+ const b = Buffer.isBuffer(c) ? c : Buffer.from(c);
38
+ n += b.length;
39
+ if (n > MAX_INPUT_BYTES)
40
+ throw new Error(`that is more than ${MAX_INPUT_BYTES / (1024 * 1024)} MiB — too big to seal or open here`);
41
+ chunks.push(b);
42
+ }
43
+ return new Uint8Array(Buffer.concat(chunks));
44
+ },
45
+ };
46
+ /** The 24 words from a key file. JSON with a `mnemonic` field, or a bare phrase. */
47
+ export function wordsFromKeyFile(path) {
48
+ let raw;
49
+ try {
50
+ raw = readFileSync(path, 'utf8');
51
+ }
52
+ catch {
53
+ return { ok: false, error: `cannot read the key file ${path} — make one with: one key new --out ${path} --yes-i-accept-plaintext-file`, code: 'no_key' };
54
+ }
55
+ const t = raw.trim();
56
+ if (t.startsWith('{')) {
57
+ try {
58
+ const m = JSON.parse(t).mnemonic;
59
+ if (typeof m === 'string' && m.trim())
60
+ return m;
61
+ }
62
+ catch {
63
+ /* fall through to the plain sentence */
64
+ }
65
+ return { ok: false, error: `${path} is not a key file — it has no "mnemonic" field`, code: 'no_key' };
66
+ }
67
+ return t;
68
+ }
69
+ /** The key's words: --key file, else ONE_WALLET_MNEMONIC. Never stdin, never a prompt. */
70
+ export function keyWords(keyPath) {
71
+ if (keyPath)
72
+ return wordsFromKeyFile(keyPath);
73
+ const env = process.env.ONE_WALLET_MNEMONIC?.trim();
74
+ if (env)
75
+ return env;
76
+ return { ok: false, error: 'no key — pass --key key.json (made by: one key new --out key.json) or set ONE_WALLET_MNEMONIC', code: 'no_key' };
77
+ }
78
+ /** The message key for the given key source, or a plain failure. The caller zeroes `.secret`. */
79
+ export async function loadMessageKey(keyPath) {
80
+ const words = keyWords(keyPath);
81
+ if (typeof words !== 'string')
82
+ return words;
83
+ const { messageKeyFromPhrase } = await messageKeyModule();
84
+ try {
85
+ return messageKeyFromPhrase(words);
86
+ }
87
+ catch (e) {
88
+ // The SDK's message never repeats the phrase; this one stays in this sentence too.
89
+ return { ok: false, error: e.message, code: 'bad_key' };
90
+ }
91
+ }
92
+ /** The paper (secrets) key for the given key source, or a plain failure. The caller zeroes `.secret`. */
93
+ export async function loadSecretsKey(keyPath) {
94
+ const words = keyWords(keyPath);
95
+ if (typeof words !== 'string')
96
+ return words;
97
+ let mod;
98
+ try {
99
+ mod = await secretsKeyModule();
100
+ }
101
+ catch {
102
+ return { ok: false, error: 'this @oneie/sdk is too old for the paper key — update it: npm i -g oneie@latest', code: 'sdk_too_old' };
103
+ }
104
+ try {
105
+ return mod.secretsKeyFromPhrase(words);
106
+ }
107
+ catch (e) {
108
+ return { ok: false, error: e.message, code: 'bad_key' };
109
+ }
110
+ }
111
+ /** A note from a file path, or stdin for `-` / no argument. Refuses a terminal rather than hang. */
112
+ export async function readNote(arg) {
113
+ if (arg && arg !== '-') {
114
+ try {
115
+ const b = readFileSync(arg);
116
+ if (b.length > MAX_INPUT_BYTES)
117
+ return { ok: false, error: `${arg} is more than ${MAX_INPUT_BYTES / (1024 * 1024)} MiB — too big to seal or open here`, code: 'too_big' };
118
+ return new Uint8Array(b);
119
+ }
120
+ catch {
121
+ return { ok: false, error: `cannot read ${arg}`, code: 'no_input' };
122
+ }
123
+ }
124
+ if (io.stdinIsTTY())
125
+ return { ok: false, error: 'nothing to read — pass a file, or pipe the note in (echo "hi" | one key seal --to age1…)', code: 'no_input' };
126
+ try {
127
+ return await io.readStdin();
128
+ }
129
+ catch (e) {
130
+ return { ok: false, error: e.message, code: 'too_big' };
131
+ }
132
+ }
133
+ /** Plain-word sentences for every way an age note can refuse to open. */
134
+ export function ageFailure(e) {
135
+ const code = e?.code;
136
+ switch (code) {
137
+ case 'no_identity':
138
+ return { ok: false, error: 'this note is not for your key — it was sealed to a different lock', code };
139
+ case 'tampered':
140
+ return { ok: false, error: 'this note was changed after it was sealed, or it is damaged — it cannot be trusted', code };
141
+ case 'unsupported':
142
+ return { ok: false, error: 'this note is locked with a passphrase or an ssh key, which ONE does not open — use the age tool', code };
143
+ case 'malformed':
144
+ return { ok: false, error: 'this is not an age note, or it is cut short', code };
145
+ case 'bad_key':
146
+ return { ok: false, error: e.message, code };
147
+ default:
148
+ return { ok: false, error: 'could not open this note', code: 'failed' };
149
+ }
150
+ }
@@ -45,8 +45,8 @@ export async function shopInit(deps, opts) {
45
45
  const seed = readEnvelope(seedEnv, 'pages:instantiate-shop-pack');
46
46
  if (!seed.ok)
47
47
  return { ...base, error: seed.error };
48
- // Today the receiver answers with ONE page; C9.1 answers with the whole pack.
49
- // Read both rather than making this command wait on that cycle.
48
+ // The receiver answers with all twelve role pages in `pages`; the bare `slug`
49
+ // (the home page) is the fallback for an older worker that predates them.
50
50
  const listed = Array.isArray(seed.result.pages) ? seed.result.pages : [];
51
51
  const pages = listed.map(p => p.slug).filter((s) => typeof s === 'string' && s.length > 0);
52
52
  if (!pages.length && seed.result.slug)
@@ -0,0 +1,24 @@
1
+ /**
2
+ * vault-read.ts — what the owner's vault says about a sealed file (text/secrets-plan.md
3
+ * Interface Contract #7). `one run` asks it one question: "which sha256 of `.env.sealed`
4
+ * do you know?" — the `sealed_hash` the owner set with `set_sealed_hash` (C14).
5
+ *
6
+ * `vaultLoaders.read` is the seam, swapped in tests like message-seal.ts's `loaders`.
7
+ * The default reads:
8
+ * • ONE_SECRETS_VAULT_FIXTURE — a JSON file `{ "<vaultId>": { "sealedHash": "<64 hex>" } }`
9
+ * (the vault contract is not on testnet yet), else
10
+ * • Sui JSON-RPC `sui_getObject` (showContent) on ONE_SUI_RPC, 10 s deadline, reading the
11
+ * vault's `sealed_hash` (vector<u8>, 32 bytes) as lowercase hex.
12
+ *
13
+ * A vault that has no hash set is `{ sealedHash: null }`; a read that fails, times out or
14
+ * returns something that is not 32 bytes is a Fail. The caller refuses on both.
15
+ */
16
+ import type { Fail } from './message-seal.js';
17
+ export interface VaultRead {
18
+ sealedHash: string | null;
19
+ }
20
+ /** Swappable in tests; the default is the fixture file or the Sui node. */
21
+ export declare const vaultLoaders: {
22
+ read: (id: string) => Promise<VaultRead | Fail>;
23
+ };
24
+ export declare const readVault: (id: string) => Promise<VaultRead | Fail>;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * vault-read.ts — what the owner's vault says about a sealed file (text/secrets-plan.md
3
+ * Interface Contract #7). `one run` asks it one question: "which sha256 of `.env.sealed`
4
+ * do you know?" — the `sealed_hash` the owner set with `set_sealed_hash` (C14).
5
+ *
6
+ * `vaultLoaders.read` is the seam, swapped in tests like message-seal.ts's `loaders`.
7
+ * The default reads:
8
+ * • ONE_SECRETS_VAULT_FIXTURE — a JSON file `{ "<vaultId>": { "sealedHash": "<64 hex>" } }`
9
+ * (the vault contract is not on testnet yet), else
10
+ * • Sui JSON-RPC `sui_getObject` (showContent) on ONE_SUI_RPC, 10 s deadline, reading the
11
+ * vault's `sealed_hash` (vector<u8>, 32 bytes) as lowercase hex.
12
+ *
13
+ * A vault that has no hash set is `{ sealedHash: null }`; a read that fails, times out or
14
+ * returns something that is not 32 bytes is a Fail. The caller refuses on both.
15
+ */
16
+ import { readFileSync } from 'node:fs';
17
+ const DEFAULT_RPC = 'https://fullnode.testnet.sui.io:443';
18
+ const DEADLINE_MS = 10_000;
19
+ const HEX64 = /^[0-9a-f]{64}$/;
20
+ const cannotVerify = (error) => ({ ok: false, error, code: 'cannot_verify' });
21
+ function fromFixture(path, id) {
22
+ let doc;
23
+ try {
24
+ doc = JSON.parse(readFileSync(path, 'utf8'));
25
+ }
26
+ catch {
27
+ return cannotVerify(`cannot read the vault fixture ${path}`);
28
+ }
29
+ const row = doc && typeof doc === 'object' ? doc[id] : undefined;
30
+ const h = row && typeof row === 'object' ? row.sealedHash : undefined;
31
+ if (h === undefined || h === null || h === '')
32
+ return { sealedHash: null };
33
+ if (typeof h !== 'string' || !HEX64.test(h.toLowerCase()))
34
+ return cannotVerify('the vault fixture sealedHash is not 64 hex characters');
35
+ return { sealedHash: h.toLowerCase() };
36
+ }
37
+ async function fromSui(id) {
38
+ if (!/^0x[0-9a-fA-F]{1,64}$/.test(id))
39
+ return cannotVerify('the vault id in the file header is not a Sui object id (0x…)');
40
+ const rpc = process.env.ONE_SUI_RPC?.trim() || DEFAULT_RPC;
41
+ const ctl = new AbortController();
42
+ const timer = setTimeout(() => ctl.abort(), DEADLINE_MS);
43
+ try {
44
+ const res = await fetch(rpc, {
45
+ method: 'POST',
46
+ headers: { 'content-type': 'application/json' },
47
+ body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'sui_getObject', params: [id, { showContent: true }] }),
48
+ signal: ctl.signal,
49
+ });
50
+ if (!res.ok)
51
+ return cannotVerify(`the Sui node answered ${res.status}`);
52
+ const body = (await res.json());
53
+ const raw = body.result?.data?.content?.fields?.sealed_hash;
54
+ if (raw === undefined || raw === null)
55
+ return cannotVerify('that object has no sealed_hash field — it is not a vault');
56
+ if (!Array.isArray(raw))
57
+ return cannotVerify('the vault sealed_hash is not a byte vector');
58
+ if (raw.length === 0)
59
+ return { sealedHash: null }; // the owner has not set one
60
+ if (raw.length !== 32 || !raw.every((b) => Number.isInteger(b) && b >= 0 && b <= 255))
61
+ return cannotVerify('the vault sealed_hash is not 32 bytes');
62
+ return { sealedHash: Buffer.from(raw).toString('hex') };
63
+ }
64
+ catch (e) {
65
+ return cannotVerify(e?.name === 'AbortError' ? 'the vault read timed out' : 'the vault read failed');
66
+ }
67
+ finally {
68
+ clearTimeout(timer);
69
+ }
70
+ }
71
+ async function defaultRead(id) {
72
+ const fixture = process.env.ONE_SECRETS_VAULT_FIXTURE?.trim();
73
+ return fixture ? fromFixture(fixture, id) : fromSui(id);
74
+ }
75
+ /** Swappable in tests; the default is the fixture file or the Sui node. */
76
+ export const vaultLoaders = { read: defaultRead };
77
+ export const readVault = (id) => vaultLoaders.read(id);
@@ -1,2 +1,29 @@
1
1
  import { Command } from 'commander';
2
+ /** The three containers PUT /api/media/video-upload sniffs. `.avi`/`.mkv` are
3
+ * refused locally — the door would store them, sniff them, and 415 after the
4
+ * whole upload; nothing is gained by sending 100 MB to learn that. */
5
+ export declare const VIDEO_CONTENT_TYPES: Record<string, string>;
6
+ /** The door's own ceiling (video-upload.ts MAX_BYTES) — refused before a byte is sent. */
7
+ export declare const VIDEO_MAX_BYTES: number;
8
+ /** The library hands back ROOT-RELATIVE urls. Meta, TikTok and every social
9
+ * platform fetch media by URL from their own servers, so the printed url is
10
+ * made absolute against the web host — the one form that works off this machine. */
11
+ export declare function absoluteUrl(base: string, url: string | undefined): string;
12
+ /** `{workspace}/media/{name}` — the receipt names where the bytes landed. */
13
+ export declare function workspaceOfKey(key: string | undefined): string;
14
+ export type MediaDims = {
15
+ width?: number;
16
+ height?: number;
17
+ durationS?: number;
18
+ };
19
+ /** ffprobe's `-print_format json -show_streams -show_format` → the dims the
20
+ * content:everywhere door plans on. The first video stream's width/height; the
21
+ * container's duration when it has one (an image has none). Anything unreadable
22
+ * is `{}` — a dimension is measured or absent, never guessed. */
23
+ export declare function parseProbe(json: string): MediaDims;
24
+ /** Neither upload door reports dimensions (video-upload.ts and media:upload answer
25
+ * key/url/contentType/size only), so the CLI measures the LOCAL file with ffprobe
26
+ * when there is one on this machine (`ONE_FFPROBE` names the binary; default
27
+ * `ffprobe` on PATH). `null` means it could not measure — the caller says so. */
28
+ export declare function probeMedia(path: string): MediaDims | null;
2
29
  export declare function mediaCmd(): Command;