@oneie/cli 5.6.0 → 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.
- package/README.md +29 -0
- package/dist/package.json +2 -2
- package/dist/src/index.js +15 -15
- package/dist/src/init.d.ts +10 -1
- package/dist/src/init.js +26 -11
- package/dist/src/join.d.ts +1 -1
- package/dist/src/join.js +2 -1
- package/dist/src/key-publish.d.ts +40 -0
- package/dist/src/key-publish.js +232 -0
- package/dist/src/key-seal.d.ts +21 -0
- package/dist/src/key-seal.js +142 -0
- package/dist/src/key.js +22 -5
- package/dist/src/lib/age-plugin.d.ts +51 -0
- package/dist/src/lib/age-plugin.js +130 -0
- package/dist/src/lib/env-sealed.d.ts +53 -0
- package/dist/src/lib/env-sealed.js +184 -0
- package/dist/src/lib/journey.d.ts +137 -0
- package/dist/src/lib/journey.js +232 -0
- package/dist/src/lib/key-receipt.d.ts +48 -0
- package/dist/src/lib/key-receipt.js +116 -0
- package/dist/src/lib/lock-lookup.d.ts +40 -0
- package/dist/src/lib/lock-lookup.js +92 -0
- package/dist/src/lib/message-seal.d.ts +63 -0
- package/dist/src/lib/message-seal.js +150 -0
- package/dist/src/lib/vault-read.d.ts +24 -0
- package/dist/src/lib/vault-read.js +77 -0
- package/dist/src/media.d.ts +15 -0
- package/dist/src/media.js +126 -4
- package/dist/src/secrets-device.d.ts +32 -0
- package/dist/src/secrets-device.js +127 -0
- package/dist/src/secrets-give.d.ts +125 -0
- package/dist/src/secrets-give.js +236 -0
- package/dist/src/secrets-run.d.ts +31 -0
- package/dist/src/secrets-run.js +182 -0
- package/dist/src/secrets.d.ts +32 -0
- package/dist/src/secrets.js +197 -0
- package/dist/src/start.d.ts +15 -0
- package/dist/src/start.js +200 -0
- package/dist/src/write.d.ts +43 -0
- package/dist/src/write.js +174 -0
- 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
|
+
}
|
|
@@ -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);
|
package/dist/src/media.d.ts
CHANGED
|
@@ -11,4 +11,19 @@ export declare const VIDEO_MAX_BYTES: number;
|
|
|
11
11
|
export declare function absoluteUrl(base: string, url: string | undefined): string;
|
|
12
12
|
/** `{workspace}/media/{name}` — the receipt names where the bytes landed. */
|
|
13
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;
|
|
14
29
|
export declare function mediaCmd(): Command;
|
package/dist/src/media.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
2
3
|
import { readFileSync, statSync } from 'node:fs';
|
|
3
4
|
import { basename, extname } from 'node:path';
|
|
4
5
|
import { mediaListAllWith } from '@oneie/sdk';
|
|
@@ -60,6 +61,77 @@ export function absoluteUrl(base, url) {
|
|
|
60
61
|
export function workspaceOfKey(key) {
|
|
61
62
|
return key ? key.split('/')[0] ?? '' : '';
|
|
62
63
|
}
|
|
64
|
+
/** ffprobe's `-print_format json -show_streams -show_format` → the dims the
|
|
65
|
+
* content:everywhere door plans on. The first video stream's width/height; the
|
|
66
|
+
* container's duration when it has one (an image has none). Anything unreadable
|
|
67
|
+
* is `{}` — a dimension is measured or absent, never guessed. */
|
|
68
|
+
export function parseProbe(json) {
|
|
69
|
+
let parsed;
|
|
70
|
+
try {
|
|
71
|
+
parsed = JSON.parse(json);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
const out = {};
|
|
77
|
+
const stream = (parsed.streams ?? []).find((s) => s.codec_type === 'video' && typeof s.width === 'number' && typeof s.height === 'number');
|
|
78
|
+
if (stream) {
|
|
79
|
+
out.width = stream.width;
|
|
80
|
+
out.height = stream.height;
|
|
81
|
+
}
|
|
82
|
+
const d = Number(parsed.format?.duration);
|
|
83
|
+
if (Number.isFinite(d) && d > 0)
|
|
84
|
+
out.durationS = d;
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/** Neither upload door reports dimensions (video-upload.ts and media:upload answer
|
|
88
|
+
* key/url/contentType/size only), so the CLI measures the LOCAL file with ffprobe
|
|
89
|
+
* when there is one on this machine (`ONE_FFPROBE` names the binary; default
|
|
90
|
+
* `ffprobe` on PATH). `null` means it could not measure — the caller says so. */
|
|
91
|
+
export function probeMedia(path) {
|
|
92
|
+
const bin = process.env.ONE_FFPROBE || 'ffprobe';
|
|
93
|
+
try {
|
|
94
|
+
const r = spawnSync(bin, ['-v', 'error', '-print_format', 'json', '-show_streams', '-show_format', path], {
|
|
95
|
+
encoding: 'utf8',
|
|
96
|
+
timeout: 15_000,
|
|
97
|
+
});
|
|
98
|
+
if (r.error || r.status !== 0 || !r.stdout)
|
|
99
|
+
return null;
|
|
100
|
+
const dims = parseProbe(r.stdout);
|
|
101
|
+
return dims.width !== undefined ? dims : null;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** One `skip`/`impossible` row from the door, however it spells its fields —
|
|
108
|
+
* `platform`/`network`, `format`/`key`/`label`, and the `reason`. */
|
|
109
|
+
function misfitLine(row) {
|
|
110
|
+
if (!row || typeof row !== 'object')
|
|
111
|
+
return String(row);
|
|
112
|
+
const r = row;
|
|
113
|
+
const where = [r.platform ?? r.network, r.format ?? r.key ?? r.label].filter((x) => typeof x === 'string' && x).join('/');
|
|
114
|
+
const why = typeof r.reason === 'string' ? r.reason : typeof r.why === 'string' ? r.why : '';
|
|
115
|
+
return `${where || '?'}${why ? ` — ${why}` : ''}`;
|
|
116
|
+
}
|
|
117
|
+
/** The door's counts and misfits, as lines. Counts are every top-level number the
|
|
118
|
+
* door answered (posts, ads, derived, …) — printed by name, never summed into a
|
|
119
|
+
* claim. The one sentence this never prints is "published": the door drafts. */
|
|
120
|
+
function renderEverywhere(res, review) {
|
|
121
|
+
const w = process.stdout;
|
|
122
|
+
const counts = Object.entries(res)
|
|
123
|
+
.filter(([, v]) => typeof v === 'number')
|
|
124
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
125
|
+
.join(' ');
|
|
126
|
+
w.write(`everywhere ${counts || 'no counts answered'} — drafts only, nothing was published\n`);
|
|
127
|
+
for (const row of res.skipped ?? [])
|
|
128
|
+
w.write(`skip ${misfitLine(row)}\n`);
|
|
129
|
+
for (const row of res.impossible ?? [])
|
|
130
|
+
w.write(`impossible ${misfitLine(row)}\n`);
|
|
131
|
+
if (res.truncated !== undefined)
|
|
132
|
+
w.write(`TRUNCATED the door cut its answer short: ${JSON.stringify(res.truncated)}\n`);
|
|
133
|
+
w.write(`review ${review}\n`);
|
|
134
|
+
}
|
|
63
135
|
const CONTENT_TYPES = {
|
|
64
136
|
'.png': 'image/png',
|
|
65
137
|
'.jpg': 'image/jpeg',
|
|
@@ -211,6 +283,36 @@ async function draftPost(api, group, caption, platforms, mediaUrl, mediaType) {
|
|
|
211
283
|
return { ok: false, error: `social/posts → ${res.status} unreadable body` };
|
|
212
284
|
}
|
|
213
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* The same door the Everywhere panel presses: ONE ask, the pinned fields and no
|
|
288
|
+
* others — `{ workspace, campaignId, mediaUrl, mediaType, width, height,
|
|
289
|
+
* durationS, text, stageKey }`. Dims come from a local ffprobe; when there is
|
|
290
|
+
* none they are OMITTED (the door measures what it can), and the omission is
|
|
291
|
+
* returned so it is printed. Nothing here publishes — the door drafts.
|
|
292
|
+
*/
|
|
293
|
+
async function runEverywhere(opts, workspace, mediaUrl, mediaType) {
|
|
294
|
+
const dims = probeMedia(opts.path);
|
|
295
|
+
const text = opts.text ?? basename(opts.path, extname(opts.path));
|
|
296
|
+
const data = {
|
|
297
|
+
workspace,
|
|
298
|
+
campaignId: opts.campaign,
|
|
299
|
+
mediaUrl,
|
|
300
|
+
mediaType,
|
|
301
|
+
...(dims?.width !== undefined ? { width: dims.width } : {}),
|
|
302
|
+
...(dims?.height !== undefined ? { height: dims.height } : {}),
|
|
303
|
+
...(dims?.durationS !== undefined ? { durationS: dims.durationS } : {}),
|
|
304
|
+
text,
|
|
305
|
+
...(opts.stage ? { stageKey: opts.stage } : {}),
|
|
306
|
+
};
|
|
307
|
+
try {
|
|
308
|
+
// 30s is the ask door's own ceiling; the door derives and drafts inside it.
|
|
309
|
+
const res = (await asker(opts.api)('content:everywhere', data, 30_000));
|
|
310
|
+
return { res, probed: dims !== null };
|
|
311
|
+
}
|
|
312
|
+
catch (e) {
|
|
313
|
+
return { res: { ok: false, error: e instanceof Error ? e.message : String(e) }, probed: dims !== null };
|
|
314
|
+
}
|
|
315
|
+
}
|
|
214
316
|
async function finish(sub, res, sent, opts) {
|
|
215
317
|
if (res.ok === false) {
|
|
216
318
|
if (jsonMode(sub))
|
|
@@ -219,15 +321,18 @@ async function finish(sub, res, sent, opts) {
|
|
|
219
321
|
}
|
|
220
322
|
const url = absoluteUrl(resolveBase({ api: opts.api }, DEFAULT_API), res.url);
|
|
221
323
|
const workspace = res.workspace ?? workspaceOfKey(res.key);
|
|
324
|
+
const mediaType = res.kind === 'video' || (res.contentType ?? '').startsWith('video/') ? 'video' : 'image';
|
|
222
325
|
let post;
|
|
223
326
|
if (opts.post) {
|
|
224
327
|
const platforms = opts.platforms.split(',').map((p) => p.trim()).filter(Boolean);
|
|
225
|
-
const mediaType = res.kind === 'video' || (res.contentType ?? '').startsWith('video/') ? 'video' : 'image';
|
|
226
328
|
post = await draftPost(opts.api, workspace, opts.post, platforms, url, mediaType);
|
|
227
329
|
}
|
|
330
|
+
let everywhere;
|
|
331
|
+
if (opts.everywhere)
|
|
332
|
+
everywhere = await runEverywhere(opts, workspace, url, mediaType);
|
|
228
333
|
const review = `${webBase(resolveBase({ api: opts.api }, DEFAULT_API)).replace(/\/$/, '')}/u/${workspace}/marketing/social`;
|
|
229
334
|
if (jsonMode(sub)) {
|
|
230
|
-
process.stdout.write(JSON.stringify({ ...res, url, ...(post ? { post, review } : {}) }, null, 2) + '\n');
|
|
335
|
+
process.stdout.write(JSON.stringify({ ...res, url, ...(post ? { post, review } : {}), ...(everywhere ? { everywhere: everywhere.res, review, probed: everywhere.probed } : {}) }, null, 2) + '\n');
|
|
231
336
|
}
|
|
232
337
|
else {
|
|
233
338
|
// The `key` is the receipt: it names the workspace prefix the bytes ACTUALLY
|
|
@@ -236,9 +341,19 @@ async function finish(sub, res, sent, opts) {
|
|
|
236
341
|
` ${url}\n`);
|
|
237
342
|
if (post?.ok)
|
|
238
343
|
process.stdout.write(`draft post=${post.id ?? '?'} — publish it here: ${review}\n`);
|
|
344
|
+
if (everywhere) {
|
|
345
|
+
if (!everywhere.probed) {
|
|
346
|
+
process.stdout.write('note no ffprobe on this machine — width/height/duration were not sent, the door measures what it can\n');
|
|
347
|
+
}
|
|
348
|
+
if (everywhere.res.ok !== false)
|
|
349
|
+
renderEverywhere(everywhere.res, review);
|
|
350
|
+
}
|
|
239
351
|
}
|
|
240
352
|
if (post && !post.ok)
|
|
241
353
|
fail(`uploaded, but the post draft failed: ${post.error}`);
|
|
354
|
+
if (everywhere && everywhere.res.ok === false) {
|
|
355
|
+
fail(`uploaded, but content:everywhere refused: ${everywhere.res.error ?? 'unknown'}`);
|
|
356
|
+
}
|
|
242
357
|
}
|
|
243
358
|
export function mediaCmd() {
|
|
244
359
|
const cmd = new Command('media').description('A workspace media library — list the WHOLE of it, upload a local file. ' +
|
|
@@ -297,9 +412,16 @@ export function mediaCmd() {
|
|
|
297
412
|
.option('--filename <name>', 'A LABEL for the key, not a path (default: the basename). The extension always comes from the sniffed bytes.')
|
|
298
413
|
.option('--post <caption>', 'Also draft a social post carrying this media (drafts only — publish on the social page)')
|
|
299
414
|
.option('--platforms <list>', 'With --post: comma-separated platforms. Default facebook — the one platform that posts the video itself; linkedin/twitter post the caption only', 'facebook')
|
|
415
|
+
.option('--campaign <id>', 'The campaign (world_groups gid) this media is for — required by --everywhere')
|
|
416
|
+
.option('--everywhere', 'After the upload, run content:everywhere: draft it for every social format and ad format it fits, in the campaign. Drafts only; prints the skips. Dims come from a local ffprobe when there is one.')
|
|
417
|
+
.option('--text <text>', 'With --everywhere: the message the formats carry (default: the file name)')
|
|
418
|
+
.option('--stage <key>', 'With --everywhere: the campaign stage the drafts belong to')
|
|
300
419
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
301
420
|
.option('--json', 'Print the raw response')
|
|
302
421
|
.action(async (path, opts, sub) => {
|
|
422
|
+
if (opts.everywhere && !opts.campaign) {
|
|
423
|
+
return fail('--everywhere needs --campaign <id>: the drafts belong to a campaign. Nothing was sent.');
|
|
424
|
+
}
|
|
303
425
|
let size;
|
|
304
426
|
try {
|
|
305
427
|
const st = statSync(path);
|
|
@@ -328,7 +450,7 @@ export function mediaCmd() {
|
|
|
328
450
|
catch (e) {
|
|
329
451
|
return fail(e instanceof Error ? e.message : String(e));
|
|
330
452
|
}
|
|
331
|
-
return finish(sub, res, size, opts);
|
|
453
|
+
return finish(sub, res, size, { ...opts, path });
|
|
332
454
|
}
|
|
333
455
|
if (ext === '.svg') {
|
|
334
456
|
return fail(`${path} is SVG, which media:upload refuses deliberately (the public reader serves the stored type verbatim). Nothing was sent.`);
|
|
@@ -359,7 +481,7 @@ export function mediaCmd() {
|
|
|
359
481
|
catch (e) {
|
|
360
482
|
return fail(e instanceof Error ? e.message : String(e));
|
|
361
483
|
}
|
|
362
|
-
return finish(sub, res, size, opts);
|
|
484
|
+
return finish(sub, res, size, { ...opts, path });
|
|
363
485
|
});
|
|
364
486
|
return cmd;
|
|
365
487
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* secrets-device.ts — `one secrets add-device`: make this Mac a reader of your sealed files
|
|
3
|
+
* (text/secrets.md deliverable 3; text/secrets-todo.md § C3).
|
|
4
|
+
*
|
|
5
|
+
* Runs `age-plugin-se keygen --access-control current-biometry -o <identity>`: a key born
|
|
6
|
+
* in the Mac's Secure Enclave that never leaves the chip. The identity file is only a
|
|
7
|
+
* handle to that key (the chip holds the secret), written mode 600 and never overwritten
|
|
8
|
+
* without --replace. The `age1se1…` lock is then appended to ~/.one/secrets-readers.json,
|
|
9
|
+
* where C1's `seal` finds it.
|
|
10
|
+
*
|
|
11
|
+
* The access control is NOT a flag. Real use is always `current-biometry`; the test seam
|
|
12
|
+
* below is a module value the command line cannot reach.
|
|
13
|
+
*
|
|
14
|
+
* Nothing the identity holds is read or printed here: the lock comes from
|
|
15
|
+
* `age-plugin-se recipients -i`, and age-plugin-se's own output is discarded.
|
|
16
|
+
*/
|
|
17
|
+
import type { Command } from 'commander';
|
|
18
|
+
/** The Secure Enclave identity file. ONE_SECRETS_DEVICE moves it (tests). */
|
|
19
|
+
export declare function deviceIdentityFile(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Test seam. Only a test module can set it; there is no flag and no env var for it, so a
|
|
22
|
+
* person at a terminal always gets the finger rule. A key made with `none` opens without Touch ID.
|
|
23
|
+
*/
|
|
24
|
+
export declare const deviceSeam: {
|
|
25
|
+
accessControl: 'current-biometry' | 'none';
|
|
26
|
+
};
|
|
27
|
+
interface AddDeviceOpts {
|
|
28
|
+
name?: string;
|
|
29
|
+
replace?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function addDeviceAction(o: AddDeviceOpts, c: Command): Promise<void>;
|
|
32
|
+
export {};
|