@ust-protocol/cli 1.0.0-rc.2
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/LICENSE +202 -0
- package/README.md +28 -0
- package/index.mjs +206 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<!-- SPDX-License-Identifier: CC-BY-4.0 -->
|
|
2
|
+
# ust — the reference CLI
|
|
3
|
+
|
|
4
|
+
One entrypoint for [UST 1.0](https://github.com/thelabmd/UST-Protocol). The Go binary reproduces this surface, so `ust` is one static, language-agnostic tool.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm i -g @ust-protocol/cli # installs the `ust` command
|
|
8
|
+
npx @ust-protocol/cli verify doc.json # or one-shot, no install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
ust verify <file|-> verify a transcript (blob / base64 / json). exit 0 = VALID, 1 = not.
|
|
13
|
+
ust canon <file|-> print the canonical bytes + hash — diff your other-language impl against this
|
|
14
|
+
ust genesis --domain <d> run the HIGH genesis ceremony
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## `ust genesis`
|
|
18
|
+
```
|
|
19
|
+
ust genesis --domain noosphere.md --profile silver --dns cf-api
|
|
20
|
+
```
|
|
21
|
+
- `--profile bronze|silver|gold` — capacity/rigor ladder (gold forces a passphrase-encrypted backup + warns `ASSURANCE LIMIT: software-generated extractable root` unless `--signer` supplies a hardware root)
|
|
22
|
+
- `--dns manual` prints the `_ust` TXT to paste; `--dns cf-api` upserts it via the Cloudflare API (zone-scoped `CF_TOKEN`, never account-wide) and **confirms it with a DNS-over-HTTPS readback** before proceeding — Vercel-style, idempotent
|
|
23
|
+
- `--max-partitions N` — the signed capacity in the genesis (bounds earned by ceremony)
|
|
24
|
+
- `--witness url,url` — witness endpoints to PREPARE (printed for the operator; this CLI does not run the exchange)
|
|
25
|
+
|
|
26
|
+
The ceremony: generate the root key → build the self-signed genesis + a key-log adding an operational key → back up the root (split + cold) → publish `.well-known/ust-genesis` (the CLI fetches it, **verifies it, and matches its content_hash** — fail-closed) → then PREPARES the witness + anchor stage (the operator executes those). Outputs: **two verifiable UST** (`ust-genesis`, `ust-keylog-0` — `ust verify` them) + an **encrypted PKCS#8 root-key backup** (`genesis-key.enc.b64` — NOT a UST) for operator-managed split cold storage. The CLI self-verifies its outputs before finishing.
|
|
27
|
+
|
|
28
|
+
The MCP holds no key; this CLI signs locally with a key that stays on your machine.
|
package/index.mjs
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// `ust` — the reference CLI. One command hides each ceremony: verify, canon (DX diagnostic), genesis (#37).
|
|
4
|
+
// The Go binary (#34) reproduces this surface so `ust` is one static, language-agnostic entrypoint.
|
|
5
|
+
//
|
|
6
|
+
// The ceremony CORE is exported as pure functions (buildCeremony / checkPublished / cfUpsert / stageSummary /
|
|
7
|
+
// encryptKey) so a notary tool is TESTABLE end-to-end without a live network — the 9th-audit regression suite
|
|
8
|
+
// (regression.mjs) drives them directly. cmdGenesis is only the readline/network orchestrator around them.
|
|
9
|
+
import { createInterface } from 'node:readline/promises';
|
|
10
|
+
import { readFileSync, writeFileSync, realpathSync } from 'node:fs';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { createCipheriv, scryptSync, randomBytes } from 'node:crypto';
|
|
13
|
+
import * as P from 'ust-protocol';
|
|
14
|
+
import * as W from '@ust-protocol/web-signer';
|
|
15
|
+
|
|
16
|
+
const arg = (name, def) => { const i = process.argv.indexOf('--' + name); return i > -1 ? (process.argv[i + 1] ?? true) : def; };
|
|
17
|
+
const die = (msg) => { console.error('✗ ' + msg); process.exit(1); };
|
|
18
|
+
const HEADER = 'UST/1.0; ref=pkg:npm/ust-protocol; web=https://thelabmd.github.io/UST-Protocol/; call=verify(doc,{context:"data"}); hash=domain-separated; trust=resolve-by-name; proves=bytes+key+time';
|
|
19
|
+
export const decodeInput = (raw) => {
|
|
20
|
+
let s = raw.trim(); const m = '———UST(base64)———';
|
|
21
|
+
if (s.includes(m)) s = s.slice(s.lastIndexOf(m) + m.length).trim();
|
|
22
|
+
return s.startsWith('{') ? JSON.parse(s) : JSON.parse(Buffer.from(s.replace(/\s+/g, ''), 'base64').toString('utf8'));
|
|
23
|
+
};
|
|
24
|
+
const nowFrame = () => W.nowFrame();
|
|
25
|
+
// The verify context follows the record's own class: a genesis/key-log frame verifies as 'key', everything
|
|
26
|
+
// else as 'data'. This is why `ust verify ust-genesis` just works — no one should need to know the context.
|
|
27
|
+
export const contextFor = (doc) => (doc?.state?.id?.class === 'genesis' || doc?.state?.id?.class === 'key') ? 'key' : 'data';
|
|
28
|
+
|
|
29
|
+
// ─── ceremony CORE (pure, exported — a notary tool must be verifiable by tests, not just by eye) ─────────
|
|
30
|
+
|
|
31
|
+
export const encryptKey = (pkcs8, pass) => {
|
|
32
|
+
const salt = randomBytes(16), iv = randomBytes(12), key = scryptSync(pass, salt, 32);
|
|
33
|
+
const c = createCipheriv('aes-256-gcm', key, iv);
|
|
34
|
+
const ct = Buffer.concat([c.update(pkcs8), c.final()]);
|
|
35
|
+
return Buffer.concat([salt, iv, c.getAuthTag(), ct]).toString('base64');
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Build genesis + key-log[0] (adds an operational key) and SELF-CHECK both (fail-closed, 9th audit #6):
|
|
39
|
+
// a ceremony tool must never emit an output it hasn't verified. Throws before returning if either fails.
|
|
40
|
+
// `warnings` carries the gold ASSURANCE LIMIT so the orchestrator (and the test) can assert it (9th audit #5).
|
|
41
|
+
export async function buildCeremony({ domain, profile = 'silver', maxP, signerRef }) {
|
|
42
|
+
const warnings = [];
|
|
43
|
+
if (profile === 'gold' && !signerRef) warnings.push('ASSURANCE LIMIT: software-generated extractable root (not a hardware ceremony). For a true gold root use --signer pkcs11:… / an air-gapped device.');
|
|
44
|
+
const root = await W.generateSigner({ extractable: true });
|
|
45
|
+
const pkcs8 = Buffer.from(await crypto.subtle.exportKey('pkcs8', root.privateKey));
|
|
46
|
+
const { ust_id, time } = nowFrame();
|
|
47
|
+
const genValue = { pub: root.pub, role: 'name-binding-root', ...(maxP ? { max_partitions: String(maxP) } : {}) };
|
|
48
|
+
const genesis = await W.seal(P.buildState({ domain_shard: domain, ust_id, key_id: root.key_id, class: 'genesis' }, time, { genesis: { kind: 'captured', value: genValue } }), root);
|
|
49
|
+
const genHash = P.contentHash(genesis);
|
|
50
|
+
const op = await W.generateSigner();
|
|
51
|
+
const keylog0 = await W.seal(P.buildKeyLogEntry({ domain_shard: domain, ust_id, key_id: root.key_id }, time, { op: 'add', pub: op.pub, new_key_id: op.key_id }, genHash), root);
|
|
52
|
+
if (!P.isValid(P.verify(genesis))) throw new Error('self-check FAILED: genesis does not verify');
|
|
53
|
+
if (!P.isValid(P.verify(keylog0, { context: 'key' }))) throw new Error('self-check FAILED: key-log[0] does not verify');
|
|
54
|
+
return { genesis, keylog0, genHash, op, pkcs8, warnings };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Fail-closed check of the published well-known: it must VERIFY and its content_hash must MATCH the genesis
|
|
58
|
+
// we built (a semantic UST match, not a transport byte-compare — 9th audit #1). Throws on any mismatch.
|
|
59
|
+
export function checkPublished(liveText, genHash) {
|
|
60
|
+
const liveDoc = decodeInput(liveText);
|
|
61
|
+
if (!P.isValid(P.verify(liveDoc))) throw new Error('published document does not VERIFY');
|
|
62
|
+
if (P.contentHash(liveDoc) !== genHash) throw new Error('published document is not this genesis (content_hash differs) — republish exactly the ust-genesis file');
|
|
63
|
+
return liveDoc;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Cloudflare one-click: UPSERT the _ust TXT (find → PUT if present, else POST) then CONFIRM it via a
|
|
67
|
+
// DNS-over-HTTPS readback (idempotent + fail-closed, 9th audit #7). fetchImpl/sleep are injected so the
|
|
68
|
+
// regression suite exercises the update-path and the readback-failure-path with no live network.
|
|
69
|
+
export async function cfUpsert({ domain, txt, genHash, token, fetchImpl = fetch, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) }) {
|
|
70
|
+
if (!token) throw new Error('cf-api needs a ZONE-scoped CF_TOKEN (DNS:edit for this zone — never account-wide)');
|
|
71
|
+
const cf = (path, init) => fetchImpl('https://api.cloudflare.com/client/v4' + path, { ...init, headers: { Authorization: 'Bearer ' + token, 'content-type': 'application/json', ...(init?.headers) } }).then((r) => r.json());
|
|
72
|
+
const zone = (await cf(`/zones?name=${domain}`)).result?.[0]; if (!zone) throw new Error('CF zone not found / token cannot see ' + domain);
|
|
73
|
+
const rec = `_ust.${domain}`;
|
|
74
|
+
const existing = (await cf(`/zones/${zone.id}/dns_records?type=TXT&name=${rec}`)).result?.[0]; // idempotent
|
|
75
|
+
const body = JSON.stringify({ type: 'TXT', name: rec, content: txt, ttl: 300 });
|
|
76
|
+
const w = existing
|
|
77
|
+
? await cf(`/zones/${zone.id}/dns_records/${existing.id}`, { method: 'PUT', body })
|
|
78
|
+
: await cf(`/zones/${zone.id}/dns_records`, { method: 'POST', body });
|
|
79
|
+
if (!w.success) throw new Error('CF write failed: ' + (w.errors?.[0]?.message || '?'));
|
|
80
|
+
let seen = false;
|
|
81
|
+
for (let i = 0; i < 6 && !seen; i++) {
|
|
82
|
+
const doh = await fetchImpl(`https://cloudflare-dns.com/dns-query?name=${rec}&type=TXT`, { headers: { accept: 'application/dns-json' } }).then((r) => r.json()).catch(() => ({}));
|
|
83
|
+
seen = (doh.Answer || []).some((a) => (a.data || '').replace(/"/g, '').includes(genHash));
|
|
84
|
+
if (!seen) await sleep(3000);
|
|
85
|
+
}
|
|
86
|
+
if (!seen) throw new Error('CF wrote the record but DoH readback did not confirm it (propagation) — re-run or verify manually');
|
|
87
|
+
return { action: existing ? 'updated' : 'created' };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The witness/anchor stage is PREPARED, never executed by this CLI (9th audit #2). Exported so the
|
|
91
|
+
// regression suite asserts the wording can't silently regress to a false "witnesses verified / anchored".
|
|
92
|
+
export function stageSummary({ genHash, witnesses = [], profile }) {
|
|
93
|
+
return [
|
|
94
|
+
'witness/anchor STAGE PREPARED (not executed by this CLI):',
|
|
95
|
+
'witnesses to contact: ' + (witnesses.length ? witnesses.join(', ') : (profile === 'bronze' ? 'self (bronze — no external witness)' : 'none supplied — add --witness url,url for silver/gold')),
|
|
96
|
+
'anchor: queue ' + genHash + ' into your anchor chain → git + OTS/Bitcoin (operator job)',
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ─── ust verify <file|-> ─────────────────────────────────────────────────────────────────────────────
|
|
101
|
+
async function cmdVerify() {
|
|
102
|
+
const src = process.argv[3];
|
|
103
|
+
if (!src) die('usage: ust verify <file | - for stdin> [--context data|key]');
|
|
104
|
+
const raw = src === '-' ? readFileSync(0, 'utf8') : readFileSync(src, 'utf8');
|
|
105
|
+
let doc; try { doc = decodeInput(raw); } catch (e) { die('not a UST blob/base64/json: ' + e.message); }
|
|
106
|
+
const r = P.verify(doc, { context: arg('context', null) || contextFor(doc) });
|
|
107
|
+
console.log(r.result + (r.error ? ' (' + r.error + (r.detail ? ' — ' + r.detail : '') + ')' : ''));
|
|
108
|
+
if (P.isValid(r)) {
|
|
109
|
+
console.log(' identity : ' + r.identity.strength + ' (mode ' + r.identity.mode + ') ' + (r.publisher ? 'publisher ' + r.publisher : 'publisher_claimed ' + r.publisher_claimed));
|
|
110
|
+
console.log(' time : ' + r.time.strength + '/' + r.time.status + ' completeness: ' + r.completeness);
|
|
111
|
+
console.log(' ust_id : ' + r.ust_id + ' class ' + r.class + ' content_hash ' + r.content_hash);
|
|
112
|
+
}
|
|
113
|
+
process.exit(P.isValid(r) ? 0 : 1);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ─── ust canon <file|-> — the DX diagnostic (#41): print the canonical string + hash so any-language devs diff ─
|
|
117
|
+
async function cmdCanon() {
|
|
118
|
+
const src = process.argv[3];
|
|
119
|
+
if (!src) die('usage: ust canon <file | - for stdin> # prints canonical bytes + hash to diff cross-language');
|
|
120
|
+
const raw = src === '-' ? readFileSync(0, 'utf8') : readFileSync(src, 'utf8');
|
|
121
|
+
let v; try { v = JSON.parse(raw); } catch (e) { die('not JSON: ' + e.message); }
|
|
122
|
+
let canonical; try { canonical = P.canon(v); } catch (e) { die('E-CANON: ' + (e.detail || e.message) + ' (values must be NFC strings; no numbers/bools/nulls — §5)'); }
|
|
123
|
+
console.log(canonical);
|
|
124
|
+
console.error('# sha256: ' + P.H('ust:state', canonical).slice(7));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ─── ust genesis --domain <d> [--profile] [--dns] — the ceremony (#37), orchestrating the core above ──
|
|
128
|
+
async function cmdGenesis() {
|
|
129
|
+
const domain = arg('domain'); if (!domain || domain === true) die('usage: ust genesis --domain <name> [--profile bronze|silver|gold] [--dns manual|cf-api] [--signer <ref>] [--witness url,url] [--max-partitions N] [--out .]');
|
|
130
|
+
const profile = arg('profile', 'silver');
|
|
131
|
+
const dns = arg('dns', 'manual');
|
|
132
|
+
const outDir = arg('out', '.');
|
|
133
|
+
const maxP = arg('max-partitions', profile === 'gold' ? 256 : profile === 'silver' ? 64 : null);
|
|
134
|
+
const signerRef = arg('signer', null);
|
|
135
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
136
|
+
const ask = (q) => rl.question(q);
|
|
137
|
+
console.log(`\n ust genesis — ceremony for ${domain} (profile: ${profile})\n`);
|
|
138
|
+
|
|
139
|
+
// 1–2. root key + genesis + key-log[0], all self-checked (fail-closed) inside buildCeremony
|
|
140
|
+
let built; try { built = await buildCeremony({ domain, profile, maxP, signerRef }); }
|
|
141
|
+
catch (e) { rl.close(); die(e.message); }
|
|
142
|
+
const { genesis, keylog0, genHash, op, pkcs8, warnings } = built;
|
|
143
|
+
for (const w of warnings) console.log(' ⚠ ' + w);
|
|
144
|
+
console.log(' 1/5 ROOT key generated');
|
|
145
|
+
console.log(' 2/5 genesis built (self-signed) + key-log[0] adds an operational key');
|
|
146
|
+
console.log(' genesis content_hash: ' + genHash);
|
|
147
|
+
|
|
148
|
+
// backup the root key (gold forces a passphrase → AES-256-GCM; the file is an encrypted blob, NOT a UST)
|
|
149
|
+
let pass = '';
|
|
150
|
+
if (profile === 'gold') { while (pass.length < 8) pass = await ask(' set a passphrase for the root-key backup (≥8 chars, split & cold-store): '); }
|
|
151
|
+
const backup = pass ? encryptKey(pkcs8, pass) : pkcs8.toString('base64');
|
|
152
|
+
writeFileSync(`${outDir}/genesis-key${pass ? '.enc' : ''}.b64`, backup);
|
|
153
|
+
writeFileSync(`${outDir}/ust-genesis`, JSON.stringify(genesis));
|
|
154
|
+
writeFileSync(`${outDir}/ust-keylog-0`, JSON.stringify(keylog0));
|
|
155
|
+
console.log(` wrote ${outDir}/ust-genesis + ust-keylog-0 + genesis-key${pass ? '.enc' : ''}.b64 (COLD-STORE the key)`);
|
|
156
|
+
console.log(' self-check: genesis + key-log verify ✓');
|
|
157
|
+
|
|
158
|
+
// 3. DNS (profile A) — manual paste or CF one-click (upsert + DoH readback)
|
|
159
|
+
const txt = `ust-genesis=${genHash}`;
|
|
160
|
+
if (dns === 'cf-api') {
|
|
161
|
+
console.log(' 3/5 writing _ust.' + domain + ' TXT via Cloudflare API (upsert + DoH readback)…');
|
|
162
|
+
let res; try { res = await cfUpsert({ domain, txt, genHash, token: process.env.CF_TOKEN || process.env.CLOUDFLARE_API_TOKEN }); }
|
|
163
|
+
catch (e) { rl.close(); die(e.message); }
|
|
164
|
+
console.log(' ✓ _ust TXT ' + res.action + ' and confirmed by DoH readback (Vercel-style, idempotent)');
|
|
165
|
+
} else {
|
|
166
|
+
console.log(' 3/5 DNS (profile A, DNSSEC): add this TXT record, or skip for profile B (TLS-witness):');
|
|
167
|
+
console.log(' _ust.' + domain + ' TXT "' + txt + '"');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 4. publish well-known + fail-closed content-hash match
|
|
171
|
+
console.log(' 4/5 publish this file at https://' + domain + '/.well-known/ust-genesis');
|
|
172
|
+
console.log(' (the exact document in ' + outDir + '/ust-genesis)');
|
|
173
|
+
await ask(' press Enter once it is live… ');
|
|
174
|
+
try {
|
|
175
|
+
const live = await fetch(`https://${domain}/.well-known/ust-genesis`, { signal: AbortSignal.timeout(10000) }).then((r) => r.text());
|
|
176
|
+
checkPublished(live, genHash);
|
|
177
|
+
console.log(' ✓ well-known verifies and its content_hash matches (fail-closed)');
|
|
178
|
+
} catch (e) { rl.close(); die('could not confirm the published well-known: ' + e.message + ' (authoritative NOT granted — retry)'); }
|
|
179
|
+
|
|
180
|
+
// 5. witnesses + anchor — PREPARED here; the operator runs the exchange + anchor
|
|
181
|
+
const witnesses = (arg('witness', '') || '').split(',').filter(Boolean);
|
|
182
|
+
const [head, ...rest] = stageSummary({ genHash, witnesses, profile });
|
|
183
|
+
console.log(' 5/5 ' + head);
|
|
184
|
+
for (const line of rest) console.log(' ' + line);
|
|
185
|
+
|
|
186
|
+
console.log('\n ✓ GENESIS PREPARED — verified locally + at well-known');
|
|
187
|
+
console.log(' name : ' + domain);
|
|
188
|
+
console.log(' genesis : ' + genHash);
|
|
189
|
+
console.log(' operational : ' + op.key_id + ' (daily key; genesis stays cold)');
|
|
190
|
+
console.log(' max_partitions : ' + (maxP ?? '(default floor 64)'));
|
|
191
|
+
console.log(' outputs : ' + outDir + '/ust-genesis + ust-keylog-0 (two verifiable UST — `ust verify` them)');
|
|
192
|
+
console.log(' key backup : ' + outDir + '/genesis-key' + (pass ? '.enc' : '') + '.b64 (encrypted PKCS#8, NOT a UST)');
|
|
193
|
+
console.log(' → operator-managed split + cold storage (needed ~yearly to rotate/revoke)');
|
|
194
|
+
console.log(' NEXT (operator): run the witness exchange + queue the anchor to reach VALID:HIGH/TOP\n');
|
|
195
|
+
rl.close();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Run the dispatcher ONLY when executed directly — importing this module (regression suite / Go-binding
|
|
199
|
+
// harness) must not trigger the CLI or its process.exit.
|
|
200
|
+
const isMain = (() => { try { return process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url); } catch { return false; } })();
|
|
201
|
+
if (isMain) {
|
|
202
|
+
const cmd = process.argv[2];
|
|
203
|
+
const run = { verify: cmdVerify, canon: cmdCanon, genesis: cmdGenesis }[cmd];
|
|
204
|
+
if (!run) { console.error('ust — verify machine-readable state\n\n ust verify <file|-> verify a transcript (exit 0 = VALID, 1 = not)\n ust canon <file|-> print canonical bytes + hash (cross-language diff)\n ust genesis --domain <d> run the HIGH genesis ceremony\n'); process.exit(cmd ? 1 : 0); }
|
|
205
|
+
run().catch((e) => die(e.message || String(e)));
|
|
206
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ust-protocol/cli",
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
|
+
"description": "The reference `ust` CLI for UST (Universal State Transcript) 1.0 — verify a transcript, print canonical bytes for cross-language diffing, and run the HIGH genesis ceremony. One entrypoint; the Go binary reproduces this surface.",
|
|
5
|
+
"author": "THE LAB (https://thelab.md)",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": { "ust": "./index.mjs" },
|
|
8
|
+
"files": ["index.mjs", "LICENSE", "README.md"],
|
|
9
|
+
"keywords": ["ust", "cli", "verify", "genesis", "trust-infrastructure"],
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"engines": { "node": ">=20" },
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"ust-protocol": "^1.0.0-rc.7",
|
|
14
|
+
"@ust-protocol/web-signer": "^1.0.0-rc.3"
|
|
15
|
+
},
|
|
16
|
+
"repository": { "type": "git", "url": "git+https://github.com/thelabmd/UST-Protocol.git", "directory": "packages/ust-cli" },
|
|
17
|
+
"homepage": "https://github.com/thelabmd/UST-Protocol/tree/main/packages/ust-cli#readme",
|
|
18
|
+
"bugs": "https://github.com/thelabmd/UST-Protocol/issues"
|
|
19
|
+
}
|