@sess.si/sdk 0.1.0-rc.4 → 0.1.0-rc.5
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/CHANGELOG.md +13 -0
- package/README.md +35 -16
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +8 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/verify.d.ts +14 -0
- package/dist/cli/verify.d.ts.map +1 -0
- package/dist/cli/verify.js +277 -0
- package/dist/cli/verify.js.map +1 -0
- package/dist/receipts/bundle.d.ts +124 -0
- package/dist/receipts/bundle.d.ts.map +1 -0
- package/dist/receipts/bundle.js +424 -0
- package/dist/receipts/bundle.js.map +1 -0
- package/dist/receipts/index.d.ts +2 -0
- package/dist/receipts/index.d.ts.map +1 -1
- package/dist/receipts/index.js +1 -0
- package/dist/receipts/index.js.map +1 -1
- package/package.json +7 -3
- package/src/cli/main.ts +8 -0
- package/src/cli/verify.ts +291 -0
- package/src/receipts/bundle.ts +547 -0
- package/src/receipts/index.ts +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.0-rc.5 — 2026-10-15
|
|
4
|
+
|
|
5
|
+
- `verifyDecisionBundle` in `@sess.si/sdk/receipts`: offline verification of a bundle-v1 decision
|
|
6
|
+
bundle against the issuer and keys the caller trusts, with the Sess core's checks, order, bounds,
|
|
7
|
+
reasons and result object, proven against the shared conformance corpus. `BUNDLE_LIMITS` exports
|
|
8
|
+
its size bounds. `verifyDecisionReceipt` is unchanged.
|
|
9
|
+
- The `sess` executable: `sess verify <file> --issuer <url> --keys <jwks.json>` prints a short
|
|
10
|
+
summary (or `--json`), exits 0 valid, 1 invalid, 2 usage error, and makes no network calls.
|
|
11
|
+
- Verbatim receipt-v1 and bundle-v1 specifications in the source repository's `docs/spec/`, checked
|
|
12
|
+
against the Sess copies.
|
|
13
|
+
- The README's first screen installs from npm (`@sess.si/sdk@next`), runs the quickstart and says what
|
|
14
|
+
you'll see; it no longer describes installing a candidate tarball. Release status follows it.
|
|
15
|
+
|
|
3
16
|
## 0.1.0-rc.4 — 2026-10-14
|
|
4
17
|
|
|
5
18
|
Documentation and packaging only; the library source is unchanged from `0.1.0-rc.3`. The README's
|
package/README.md
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
# SESS SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Ask a person a question from your server and continue with their verified answer. `@sess.si/sdk`
|
|
4
|
+
creates a hosted SESS page, waits for the answer on the exact Surface revision, verifies its signed
|
|
5
|
+
receipt, and continues the same Session.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
interaction and business logic; SESS owns the hosted UI, state, routing and authorization.
|
|
8
|
-
|
|
9
|
-
**Start here:** the [plain-Node quickstart](examples/quickstart-node/README.md) is a runnable
|
|
10
|
-
program. It needs only `SESS_API_KEY`; it prints the private human link before it starts waiting,
|
|
11
|
-
then verifies the person's answer and completes the Session.
|
|
12
|
-
|
|
13
|
-
**Release status:** the [changelog](CHANGELOG.md) describes each version. To see which versions the
|
|
14
|
-
registry actually serves and under which tag, run `npm view @sess.si/sdk dist-tags`. Install a published version with:
|
|
7
|
+
**Install** from npm:
|
|
15
8
|
|
|
16
9
|
```sh
|
|
17
|
-
npm install @sess.si/sdk
|
|
10
|
+
npm install --save-exact @sess.si/sdk@next
|
|
18
11
|
```
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
**Run** the [plain-Node quickstart](examples/quickstart-node/README.md), a complete program that
|
|
14
|
+
needs only `SESS_API_KEY`.
|
|
15
|
+
|
|
16
|
+
**What you'll see:** a private human link, printed before the program starts waiting. Open it on any
|
|
17
|
+
device and answer; the program prints the verified answer and completes the Session.
|
|
18
|
+
|
|
19
|
+
**Release status:** every SDK release so far is a `0.1.0` release candidate, served under the `next`
|
|
20
|
+
dist-tag. There is no stable release yet: do not install the bare name, whose `latest` tag points at a
|
|
21
|
+
deprecated `0.0.0-stage` placeholder. The [changelog](CHANGELOG.md) describes each version;
|
|
22
|
+
`npm view @sess.si/sdk dist-tags` shows what the registry serves now.
|
|
23
23
|
|
|
24
24
|
## Create and verify an interaction
|
|
25
25
|
|
|
@@ -83,6 +83,25 @@ The [quickstart function](examples/quickstart.ts) includes a private delivery ca
|
|
|
83
83
|
answer is still the current expected business step before publishing or completing. Its store
|
|
84
84
|
and worker lease are application-owned. See [Integration](docs/integration.md).
|
|
85
85
|
|
|
86
|
+
## Check a decision bundle
|
|
87
|
+
|
|
88
|
+
A decision bundle is one accepted decision that its owner chose to share: the signed receipt, the
|
|
89
|
+
exact Surface and input, and the issuer's public keys. Check it on your own computer, with keys you
|
|
90
|
+
trust (never the keys inside the bundle):
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
npx -p @sess.si/sdk@0.1.0-rc.5 sess verify bundle.json --issuer https://api.sess.si --keys sess-receipt-keys.json
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The `sess` command first ships in `0.1.0-rc.5`; name that version (or a later one) exactly, because
|
|
97
|
+
the bare package name resolves to the `latest` placeholder, which has no command.
|
|
98
|
+
|
|
99
|
+
You'll see `Valid decision bundle.` and what was accepted, when, on which revision; or `Invalid`
|
|
100
|
+
and the first reason. Exit status is 0 valid, 1 invalid, 2 usage error; add `--json` for the full
|
|
101
|
+
result. Nothing is sent anywhere. In code, use `verifyDecisionBundle` from `@sess.si/sdk/receipts`
|
|
102
|
+
([Security](docs/security.md#decision-bundles)). Formats: [receipt-v1](docs/spec/receipt-v1.md) and
|
|
103
|
+
[bundle-v1](docs/spec/bundle-v1.md).
|
|
104
|
+
|
|
86
105
|
## Runtime and imports
|
|
87
106
|
|
|
88
107
|
Supported: maintained Node 22 releases at or above 22.14, and Node 24 (recommended).
|
|
@@ -128,7 +147,7 @@ contract is served at [OpenAPI](https://api.sess.si/openapi.json).
|
|
|
128
147
|
- [Security](docs/security.md) and [receipt example](examples/receipt-verification.ts).
|
|
129
148
|
- [Webhooks](docs/webhooks.md) and [Node receiver with a durable-inbox boundary](examples/webhook-receiver.ts).
|
|
130
149
|
- [Compatibility](docs/compatibility.md), [testbed migration](docs/migration.md) and [release runbook](docs/releasing.md).
|
|
131
|
-
- [
|
|
150
|
+
- [Plain-Node quickstart](examples/quickstart-node/README.md): a complete program, from the first call to the verified answer.
|
|
132
151
|
|
|
133
152
|
The present runtime can require manual browser refresh between rounds. Owner polling in this
|
|
134
153
|
SDK does not change that browser behavior. Appearance configuration and front-door invocation
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":""}
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The `sess` executable. The only command is `sess verify <bundle.json>` (see ./verify.ts).
|
|
3
|
+
import { runCli } from './verify.js';
|
|
4
|
+
process.exitCode = await runCli(process.argv.slice(2), {
|
|
5
|
+
stdout: (text) => process.stdout.write(text),
|
|
6
|
+
stderr: (text) => process.stderr.write(text),
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AACA,4FAA4F;AAC5F,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACrD,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;IAC5C,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;CAC7C,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Exit codes: valid, invalid bundle, usage or file error. */
|
|
2
|
+
export declare const EXIT: Readonly<{
|
|
3
|
+
valid: 0;
|
|
4
|
+
invalid: 1;
|
|
5
|
+
usage: 2;
|
|
6
|
+
}>;
|
|
7
|
+
export interface CliIo {
|
|
8
|
+
stdout: (text: string) => void;
|
|
9
|
+
stderr: (text: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const USAGE = "Usage: sess verify <bundle.json> --issuer <url> --keys <jwks.json> [options]\n\nChecks a Sess decision bundle on this computer against the issuer and keys you trust.\nNothing is sent anywhere. Keys inside the bundle are never trusted.\n\nRequired:\n --issuer <url> the receipt issuer you trust, for example https://api.sess.si\n --keys <file> that issuer's public keys (a JWK Set) you obtained yourself\n\nExpected context (optional; only what you pass is checked):\n --audience <id> the workspace the decision must belong to\n --workspace <id> the workspace ID\n --session <id> the Session ID\n --event <id> the Event ID\n --revision <n> the Surface revision\n --action <id> the action ID\n\nOther:\n --now <time> check at this RFC 3339 time instead of now\n --json print the full result as JSON\n -h, --help show this help\n\nExit status: 0 valid, 1 invalid, 2 usage or file error.\n";
|
|
12
|
+
/** Runs `sess <argv>`; resolves to the exit code. Never throws. */
|
|
13
|
+
export declare function runCli(argv: readonly string[], io: CliIo): Promise<number>;
|
|
14
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/cli/verify.ts"],"names":[],"mappings":"AAaA,8DAA8D;AAC9D,eAAO,MAAM,IAAI;;;;EAAoD,CAAC;AAMtE,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,eAAO,MAAM,KAAK,28BAuBjB,CAAC;AA0MF,mEAAmE;AACnE,wBAAsB,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAuChF"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// `sess verify <file>`: the CLI face of decision-bundle verification. Offline only: it reads the
|
|
2
|
+
// bundle and the keys the caller trusts from local files, verifies with verifyDecisionBundle and
|
|
3
|
+
// prints a short summary (or the result object with --json). It opens no network connection and
|
|
4
|
+
// never prints the receipt, the disclosed content or any key material.
|
|
5
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
7
|
+
import { verifyDecisionBundle, } from '../receipts/bundle.js';
|
|
8
|
+
import { validateKeySet } from '../receipts/verify.js';
|
|
9
|
+
/** Exit codes: valid, invalid bundle, usage or file error. */
|
|
10
|
+
export const EXIT = Object.freeze({ valid: 0, invalid: 1, usage: 2 });
|
|
11
|
+
/** A bundle file larger than this is not read (the bundle bound itself is 1 MiB canonical). */
|
|
12
|
+
const MAX_BUNDLE_FILE_BYTES = 16 * 1024 * 1024;
|
|
13
|
+
const MAX_KEYS_FILE_BYTES = 1024 * 1024;
|
|
14
|
+
export const USAGE = `Usage: sess verify <bundle.json> --issuer <url> --keys <jwks.json> [options]
|
|
15
|
+
|
|
16
|
+
Checks a Sess decision bundle on this computer against the issuer and keys you trust.
|
|
17
|
+
Nothing is sent anywhere. Keys inside the bundle are never trusted.
|
|
18
|
+
|
|
19
|
+
Required:
|
|
20
|
+
--issuer <url> the receipt issuer you trust, for example https://api.sess.si
|
|
21
|
+
--keys <file> that issuer's public keys (a JWK Set) you obtained yourself
|
|
22
|
+
|
|
23
|
+
Expected context (optional; only what you pass is checked):
|
|
24
|
+
--audience <id> the workspace the decision must belong to
|
|
25
|
+
--workspace <id> the workspace ID
|
|
26
|
+
--session <id> the Session ID
|
|
27
|
+
--event <id> the Event ID
|
|
28
|
+
--revision <n> the Surface revision
|
|
29
|
+
--action <id> the action ID
|
|
30
|
+
|
|
31
|
+
Other:
|
|
32
|
+
--now <time> check at this RFC 3339 time instead of now
|
|
33
|
+
--json print the full result as JSON
|
|
34
|
+
-h, --help show this help
|
|
35
|
+
|
|
36
|
+
Exit status: 0 valid, 1 invalid, 2 usage or file error.
|
|
37
|
+
`;
|
|
38
|
+
class UsageError extends Error {
|
|
39
|
+
}
|
|
40
|
+
const STRING_OPTIONS = [
|
|
41
|
+
'issuer',
|
|
42
|
+
'keys',
|
|
43
|
+
'audience',
|
|
44
|
+
'workspace',
|
|
45
|
+
'session',
|
|
46
|
+
'event',
|
|
47
|
+
'revision',
|
|
48
|
+
'action',
|
|
49
|
+
'now',
|
|
50
|
+
];
|
|
51
|
+
const RFC3339 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
52
|
+
/** Escapes characters a terminal could interpret (controls, bidi overrides, line separators). */
|
|
53
|
+
function safe(text) {
|
|
54
|
+
return text.replace(/[\u0000-\u001f\u007f-\u009f\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
55
|
+
}
|
|
56
|
+
async function readBounded(path, max, what) {
|
|
57
|
+
let size;
|
|
58
|
+
try {
|
|
59
|
+
const info = await stat(path);
|
|
60
|
+
if (!info.isFile())
|
|
61
|
+
throw new UsageError(`${what} is not a file: ${safe(path)}`);
|
|
62
|
+
size = info.size;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
if (e instanceof UsageError)
|
|
66
|
+
throw e;
|
|
67
|
+
throw new UsageError(`cannot read ${what}: ${safe(path)}`);
|
|
68
|
+
}
|
|
69
|
+
if (size > max)
|
|
70
|
+
throw new UsageError(`${what} is larger than ${max} bytes: ${safe(path)}`);
|
|
71
|
+
try {
|
|
72
|
+
return await readFile(path);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
throw new UsageError(`cannot read ${what}: ${safe(path)}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function parseJson(bytes) {
|
|
79
|
+
try {
|
|
80
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
81
|
+
return { ok: true, value: JSON.parse(text) };
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return { ok: false };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function parse(argv) {
|
|
88
|
+
let parsed;
|
|
89
|
+
try {
|
|
90
|
+
parsed = parseArgs({
|
|
91
|
+
args: [...argv],
|
|
92
|
+
allowPositionals: true,
|
|
93
|
+
strict: true,
|
|
94
|
+
tokens: true,
|
|
95
|
+
options: {
|
|
96
|
+
...Object.fromEntries(STRING_OPTIONS.map((name) => [name, { type: 'string' }])),
|
|
97
|
+
json: { type: 'boolean' },
|
|
98
|
+
help: { type: 'boolean', short: 'h' },
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
throw new UsageError('unknown option or missing option value');
|
|
104
|
+
}
|
|
105
|
+
const values = parsed.values;
|
|
106
|
+
if (values.help)
|
|
107
|
+
return 'help';
|
|
108
|
+
// A trust setting given twice is ambiguous: refuse rather than pick one.
|
|
109
|
+
const seen = new Set();
|
|
110
|
+
for (const token of parsed.tokens ?? []) {
|
|
111
|
+
if (token.kind !== 'option')
|
|
112
|
+
continue;
|
|
113
|
+
if (seen.has(token.name))
|
|
114
|
+
throw new UsageError(`--${token.name} is given more than once`);
|
|
115
|
+
seen.add(token.name);
|
|
116
|
+
}
|
|
117
|
+
const [command, file, ...rest] = parsed.positionals;
|
|
118
|
+
if (command !== 'verify')
|
|
119
|
+
throw new UsageError('the only command is: verify <bundle.json>');
|
|
120
|
+
if (file === undefined || rest.length > 0)
|
|
121
|
+
throw new UsageError('give exactly one bundle file');
|
|
122
|
+
const str = (name) => {
|
|
123
|
+
const v = values[name];
|
|
124
|
+
if (v === undefined)
|
|
125
|
+
return undefined;
|
|
126
|
+
if (typeof v !== 'string' || v.length === 0)
|
|
127
|
+
throw new UsageError(`--${name} needs a value`);
|
|
128
|
+
return v;
|
|
129
|
+
};
|
|
130
|
+
const issuer = str('issuer');
|
|
131
|
+
const keysPath = str('keys');
|
|
132
|
+
if (issuer === undefined || keysPath === undefined)
|
|
133
|
+
throw new UsageError('--issuer and --keys are required: verification only uses keys you trust');
|
|
134
|
+
const revisionText = str('revision');
|
|
135
|
+
let revision;
|
|
136
|
+
if (revisionText !== undefined) {
|
|
137
|
+
revision = Number(revisionText);
|
|
138
|
+
if (!/^[1-9][0-9]*$/.test(revisionText) || !Number.isSafeInteger(revision))
|
|
139
|
+
throw new UsageError('--revision must be a positive integer');
|
|
140
|
+
}
|
|
141
|
+
const nowText = str('now');
|
|
142
|
+
let now;
|
|
143
|
+
if (nowText !== undefined) {
|
|
144
|
+
now = new Date(nowText);
|
|
145
|
+
if (!RFC3339.test(nowText) || Number.isNaN(now.getTime()))
|
|
146
|
+
throw new UsageError('--now must be an RFC 3339 time, for example 2026-10-09T12:05:00Z');
|
|
147
|
+
}
|
|
148
|
+
const context = {};
|
|
149
|
+
const audience = str('audience');
|
|
150
|
+
const workspaceId = str('workspace');
|
|
151
|
+
const sessionId = str('session');
|
|
152
|
+
const eventId = str('event');
|
|
153
|
+
const actionId = str('action');
|
|
154
|
+
if (audience !== undefined)
|
|
155
|
+
context.audience = audience;
|
|
156
|
+
if (workspaceId !== undefined)
|
|
157
|
+
context.workspaceId = workspaceId;
|
|
158
|
+
if (sessionId !== undefined)
|
|
159
|
+
context.sessionId = sessionId;
|
|
160
|
+
if (eventId !== undefined)
|
|
161
|
+
context.eventId = eventId;
|
|
162
|
+
if (revision !== undefined)
|
|
163
|
+
context.revision = revision;
|
|
164
|
+
if (actionId !== undefined)
|
|
165
|
+
context.actionId = actionId;
|
|
166
|
+
return {
|
|
167
|
+
file,
|
|
168
|
+
issuer,
|
|
169
|
+
keysPath,
|
|
170
|
+
context: Object.keys(context).length > 0 ? context : undefined,
|
|
171
|
+
now,
|
|
172
|
+
json: values.json === true,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const REASON_TEXT = {
|
|
176
|
+
malformed: 'the file is not a bundle-v1 decision bundle',
|
|
177
|
+
oversized: 'the bundle exceeds a bundle-v1 size bound',
|
|
178
|
+
unsupported_version: 'the bundle uses a later format version',
|
|
179
|
+
receipt_malformed: 'the receipt cannot be read',
|
|
180
|
+
algorithm: 'the receipt does not use the EdDSA algorithm',
|
|
181
|
+
missing_kid: 'the receipt names no key',
|
|
182
|
+
unknown_kid: 'the receipt was signed with a key you do not trust',
|
|
183
|
+
type: 'the receipt has the wrong type',
|
|
184
|
+
signature: 'the signature does not verify with the key you trust',
|
|
185
|
+
issuer: 'the receipt is from another issuer',
|
|
186
|
+
audience: 'the receipt belongs to another workspace',
|
|
187
|
+
expired: 'the receipt has expired',
|
|
188
|
+
claims: 'the receipt claims are not valid receipt-v1 claims',
|
|
189
|
+
not_yet_valid: 'the receipt is dated in the future',
|
|
190
|
+
surface_mismatch: 'the disclosed Surface is not the one the receipt signed',
|
|
191
|
+
input_mismatch: 'the disclosed input is not the one the receipt signed',
|
|
192
|
+
context_mismatch: 'the decision is not the one you expected',
|
|
193
|
+
};
|
|
194
|
+
function summary(r) {
|
|
195
|
+
const lines = [];
|
|
196
|
+
const row = (label, value) => lines.push(` ${label.padEnd(11)} ${value}`);
|
|
197
|
+
const context = r.context.status === 'mismatch'
|
|
198
|
+
? `mismatch: ${r.context.mismatches.join(', ')}`
|
|
199
|
+
: r.context.status === 'unchecked'
|
|
200
|
+
? 'unchecked (no expected context given)'
|
|
201
|
+
: r.context.checked.length > 0
|
|
202
|
+
? `${r.context.status}: ${r.context.checked.join(', ')}`
|
|
203
|
+
: r.context.status;
|
|
204
|
+
if (r.valid && r.receipt) {
|
|
205
|
+
const c = r.receipt;
|
|
206
|
+
lines.push('Valid decision bundle.');
|
|
207
|
+
row('Accepted', `${safe(c.accepted_at)}, action ${safe(c.action.id)} on revision ${c.surface.revision}`);
|
|
208
|
+
row('Session', `${safe(c.session_id)} (event ${safe(c.event_id)}, workspace ${safe(c.workspace_id)})`);
|
|
209
|
+
row('Issuer', `${safe(c.issuer)} (key ${safe(c.key_id)})`);
|
|
210
|
+
row('Actor', "someone holding the Session's human link (not a verified person)");
|
|
211
|
+
row('Content', 'verified');
|
|
212
|
+
row('Context', context);
|
|
213
|
+
row('Purpose', r.application_purpose);
|
|
214
|
+
row('Expires', safe(c.expires_at));
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
lines.push(`Invalid decision bundle: ${r.reason}`);
|
|
218
|
+
lines.push(` ${REASON_TEXT[r.reason ?? ''] ?? ''}`);
|
|
219
|
+
row('Content', r.content);
|
|
220
|
+
row('Context', context);
|
|
221
|
+
}
|
|
222
|
+
row('Checked at', r.checked_at);
|
|
223
|
+
return `${lines.join('\n')}\n`;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* JSON with every terminal-sensitive character escaped; parses to the same value. JSON.stringify
|
|
227
|
+
* already escapes C0 controls inside strings, and the only raw characters it can leave are inside
|
|
228
|
+
* strings, where a \u escape denotes the same character.
|
|
229
|
+
*/
|
|
230
|
+
function safeJson(value) {
|
|
231
|
+
const text = JSON.stringify(value, null, 2).replace(/[\u007f-\u009f\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
232
|
+
return `${text}\n`;
|
|
233
|
+
}
|
|
234
|
+
/** Runs `sess <argv>`; resolves to the exit code. Never throws. */
|
|
235
|
+
export async function runCli(argv, io) {
|
|
236
|
+
try {
|
|
237
|
+
const parsed = parse(argv);
|
|
238
|
+
if (parsed === 'help') {
|
|
239
|
+
io.stdout(USAGE);
|
|
240
|
+
return EXIT.valid;
|
|
241
|
+
}
|
|
242
|
+
const keyBytes = await readBounded(parsed.keysPath, MAX_KEYS_FILE_BYTES, 'the --keys file');
|
|
243
|
+
const keyJson = parseJson(keyBytes);
|
|
244
|
+
let trustedKeys;
|
|
245
|
+
try {
|
|
246
|
+
if (!keyJson.ok)
|
|
247
|
+
throw new Error('not JSON');
|
|
248
|
+
trustedKeys = validateKeySet(keyJson.value);
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
throw new UsageError('the --keys file must be a JWK Set of public Ed25519 keys with unique kids (private keys are refused)');
|
|
252
|
+
}
|
|
253
|
+
const bundleBytes = await readBounded(parsed.file, MAX_BUNDLE_FILE_BYTES, 'the bundle file');
|
|
254
|
+
const bundleJson = parseJson(bundleBytes);
|
|
255
|
+
let result;
|
|
256
|
+
try {
|
|
257
|
+
// A file that is not JSON is not a bundle: the same facade reports it as malformed.
|
|
258
|
+
result = await verifyDecisionBundle(bundleJson.ok ? bundleJson.value : undefined, {
|
|
259
|
+
issuer: parsed.issuer,
|
|
260
|
+
trustedKeys,
|
|
261
|
+
...(parsed.context ? { expectedContext: parsed.context } : {}),
|
|
262
|
+
...(parsed.now ? { now: parsed.now } : {}),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
throw new UsageError('invalid verification options');
|
|
267
|
+
}
|
|
268
|
+
io.stdout(parsed.json ? safeJson(result) : summary(result));
|
|
269
|
+
return result.valid ? EXIT.valid : EXIT.invalid;
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
const message = e instanceof UsageError ? e.message : 'unexpected error';
|
|
273
|
+
io.stderr(`sess: ${message}\nRun "sess --help" for usage.\n`);
|
|
274
|
+
return EXIT.usage;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot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,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type ReceiptKeySet } from './verify.js';
|
|
2
|
+
/** Bounds of a bundle (bundle-v1 §4). A bundle beyond any of them is `oversized`. */
|
|
3
|
+
export declare const BUNDLE_LIMITS: Readonly<{
|
|
4
|
+
/** RFC 8785 canonical UTF-8 bytes of the whole bundle. */
|
|
5
|
+
bytes: 1048576;
|
|
6
|
+
/** Nesting depth of any value (the bundle object itself is depth 1). */
|
|
7
|
+
depth: 32;
|
|
8
|
+
/** Items in any one array. */
|
|
9
|
+
arrayItems: 1000;
|
|
10
|
+
/** Members of any one object. */
|
|
11
|
+
objectMembers: 1000;
|
|
12
|
+
/** JSON values in the whole bundle. */
|
|
13
|
+
nodes: 100000;
|
|
14
|
+
/** Characters of the receipt's compact JWS. */
|
|
15
|
+
receiptChars: 32768;
|
|
16
|
+
/** Public keys in `keys.keys`. */
|
|
17
|
+
keys: 16;
|
|
18
|
+
}>;
|
|
19
|
+
/** One public Ed25519 JWK as disclosed in a bundle. */
|
|
20
|
+
export interface BundleJwk {
|
|
21
|
+
kty: 'OKP';
|
|
22
|
+
crv: 'Ed25519';
|
|
23
|
+
x: string;
|
|
24
|
+
kid: string;
|
|
25
|
+
alg?: 'EdDSA';
|
|
26
|
+
use?: 'sig';
|
|
27
|
+
}
|
|
28
|
+
/** A bundle-v1 object: exactly these members. */
|
|
29
|
+
export interface DecisionBundle {
|
|
30
|
+
type: 'sess.decision-bundle';
|
|
31
|
+
version: 1;
|
|
32
|
+
/** The receipt-v1 compact JWS, exactly as issued. */
|
|
33
|
+
receipt: string;
|
|
34
|
+
/** The accepted record: the normalized Surface document and the validated input, complete. */
|
|
35
|
+
content: {
|
|
36
|
+
surface: Record<string, unknown>;
|
|
37
|
+
input: Record<string, unknown>;
|
|
38
|
+
};
|
|
39
|
+
/** The issuer's public keys. Disclosed for convenience; a verifier never trusts them. */
|
|
40
|
+
keys: {
|
|
41
|
+
keys: BundleJwk[];
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Receipt-v1 rejection codes (receipt-v1 §6). */
|
|
45
|
+
type ReceiptV1Rejection = 'malformed' | 'algorithm' | 'missing_kid' | 'unknown_kid' | 'type' | 'signature' | 'issuer' | 'audience' | 'expired' | 'claims';
|
|
46
|
+
/** Why a bundle is invalid: the first check that failed (bundle-v1 §5). */
|
|
47
|
+
export type BundleRejection = 'malformed' | 'oversized' | 'unsupported_version' | 'receipt_malformed' | Exclude<ReceiptV1Rejection, 'malformed'> | 'not_yet_valid' | 'surface_mismatch' | 'input_mismatch' | 'context_mismatch';
|
|
48
|
+
/** Application context from the caller's trusted configuration, never from the bundle. */
|
|
49
|
+
export interface ExpectedBundleContext {
|
|
50
|
+
/** The recipient the caller expects (the receipt's `aud`: the Session's workspace). */
|
|
51
|
+
audience?: string;
|
|
52
|
+
workspaceId?: string;
|
|
53
|
+
sessionId?: string;
|
|
54
|
+
eventId?: string;
|
|
55
|
+
/** The Surface revision the decision must be on. */
|
|
56
|
+
revision?: number;
|
|
57
|
+
actionId?: string;
|
|
58
|
+
}
|
|
59
|
+
/** Context member names as the result reports them (receipt claim paths). */
|
|
60
|
+
export type BundleContextField = 'audience' | 'workspace_id' | 'session_id' | 'event_id' | 'surface.revision' | 'action.id';
|
|
61
|
+
export interface VerifyDecisionBundleOptions {
|
|
62
|
+
/** The issuer the caller trusts (the receipt's `iss`). */
|
|
63
|
+
issuer: string;
|
|
64
|
+
/** The issuer's public verification keys the caller trusts. Keys inside a bundle are never used. */
|
|
65
|
+
trustedKeys: ReceiptKeySet;
|
|
66
|
+
expectedContext?: ExpectedBundleContext;
|
|
67
|
+
/** Defaults to the current time (receipt-v1 current-time expiry). */
|
|
68
|
+
now?: Date;
|
|
69
|
+
}
|
|
70
|
+
/** The verified receipt, presented only when the bundle is valid. */
|
|
71
|
+
export interface VerifiedReceiptSummary {
|
|
72
|
+
key_id: string;
|
|
73
|
+
issuer: string;
|
|
74
|
+
audience: string;
|
|
75
|
+
event_id: string;
|
|
76
|
+
session_id: string;
|
|
77
|
+
workspace_id: string;
|
|
78
|
+
step_id: string;
|
|
79
|
+
surface: {
|
|
80
|
+
revision: number;
|
|
81
|
+
hash: string;
|
|
82
|
+
renderer_version: string;
|
|
83
|
+
};
|
|
84
|
+
action: {
|
|
85
|
+
id: string;
|
|
86
|
+
label: string;
|
|
87
|
+
summary: string;
|
|
88
|
+
};
|
|
89
|
+
input_hash: string;
|
|
90
|
+
accepted_at: string;
|
|
91
|
+
expires_at: string;
|
|
92
|
+
}
|
|
93
|
+
/** The result every face reports (bundle-v1 §6). JSON-serializable. */
|
|
94
|
+
export interface DecisionBundleVerification {
|
|
95
|
+
valid: boolean;
|
|
96
|
+
reason: BundleRejection | null;
|
|
97
|
+
/** The verification time, RFC 3339 UTC. */
|
|
98
|
+
checked_at: string;
|
|
99
|
+
/** Whether the disclosed Surface and input match the receipt's hashes. */
|
|
100
|
+
content: 'verified' | 'mismatch' | 'not_checked';
|
|
101
|
+
context: {
|
|
102
|
+
status: 'verified' | 'incomplete' | 'mismatch' | 'unchecked' | 'not_checked';
|
|
103
|
+
/** The context members the caller supplied, in a fixed order. */
|
|
104
|
+
checked: BundleContextField[];
|
|
105
|
+
mismatches: BundleContextField[];
|
|
106
|
+
};
|
|
107
|
+
/** `matched_caller_context` only when the caller's full context (with audience) matched. */
|
|
108
|
+
application_purpose: 'unchecked' | 'matched_caller_context';
|
|
109
|
+
/** Link possession only: never a named or verified person. Null when invalid. */
|
|
110
|
+
actor: {
|
|
111
|
+
assurance: 'link_holder';
|
|
112
|
+
} | null;
|
|
113
|
+
receipt: VerifiedReceiptSummary | null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Verifies a bundle-v1 decision bundle offline against the issuer and keys the caller trusts.
|
|
117
|
+
* Every outcome about the bundle is a result, never an exception; only invalid options throw a
|
|
118
|
+
* TypeError. Order (bundle-v1 §5): shape and bounds; the receipt by the receipt-v1 rules; not
|
|
119
|
+
* issued in the future; the disclosed Surface and input against the receipt's hashes; then the
|
|
120
|
+
* caller's expected context.
|
|
121
|
+
*/
|
|
122
|
+
export declare function verifyDecisionBundle(bundle: unknown, options: VerifyDecisionBundleOptions): Promise<DecisionBundleVerification>;
|
|
123
|
+
export {};
|
|
124
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/receipts/bundle.ts"],"names":[],"mappings":"AAYA,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAOjE,qFAAqF;AACrF,eAAO,MAAM,aAAa;IACxB,0DAA0D;;IAE1D,wEAAwE;;IAExE,8BAA8B;;IAE9B,iCAAiC;;IAEjC,uCAAuC;;IAEvC,+CAA+C;;IAE/C,kCAAkC;;EAElC,CAAC;AAKH,uDAAuD;AACvD,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,KAAK,CAAC;IACX,GAAG,EAAE,SAAS,CAAC;IACf,CAAC,EAAE,MAAM,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,KAAK,CAAC;CACb;AAED,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,CAAC,CAAC;IACX,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,8FAA8F;IAC9F,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAC9E,yFAAyF;IACzF,IAAI,EAAE;QAAE,IAAI,EAAE,SAAS,EAAE,CAAA;KAAE,CAAC;CAC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