@sess.si/sdk 0.0.0-stage → 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 +38 -0
- package/LICENSE +201 -0
- package/NOTICE +9 -0
- package/README.md +155 -2
- 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/client.d.ts +12 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +34 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +52 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated/openapi.d.ts +2462 -0
- package/dist/generated/openapi.d.ts.map +1 -0
- package/dist/generated/openapi.js +2 -0
- package/dist/generated/openapi.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/decode.d.ts +21 -0
- package/dist/internal/decode.d.ts.map +1 -0
- package/dist/internal/decode.js +333 -0
- package/dist/internal/decode.js.map +1 -0
- package/dist/internal/json.d.ts +4 -0
- package/dist/internal/json.d.ts.map +1 -0
- package/dist/internal/json.js +75 -0
- package/dist/internal/json.js.map +1 -0
- package/dist/internal/time.d.ts +11 -0
- package/dist/internal/time.d.ts.map +1 -0
- package/dist/internal/time.js +71 -0
- package/dist/internal/time.js.map +1 -0
- package/dist/polling.d.ts +3 -0
- package/dist/polling.d.ts.map +1 -0
- package/dist/polling.js +61 -0
- package/dist/polling.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 +7 -0
- package/dist/receipts/index.d.ts.map +1 -0
- package/dist/receipts/index.js +3 -0
- package/dist/receipts/index.js.map +1 -0
- package/dist/receipts/json.d.ts +22 -0
- package/dist/receipts/json.d.ts.map +1 -0
- package/dist/receipts/json.js +152 -0
- package/dist/receipts/json.js.map +1 -0
- package/dist/receipts/key-cache.d.ts +28 -0
- package/dist/receipts/key-cache.d.ts.map +1 -0
- package/dist/receipts/key-cache.js +110 -0
- package/dist/receipts/key-cache.js.map +1 -0
- package/dist/receipts/resource.d.ts +39 -0
- package/dist/receipts/resource.d.ts.map +1 -0
- package/dist/receipts/resource.js +119 -0
- package/dist/receipts/resource.js.map +1 -0
- package/dist/receipts/verify.d.ts +90 -0
- package/dist/receipts/verify.d.ts.map +1 -0
- package/dist/receipts/verify.js +294 -0
- package/dist/receipts/verify.js.map +1 -0
- package/dist/sessions.d.ts +19 -0
- package/dist/sessions.d.ts.map +1 -0
- package/dist/sessions.js +145 -0
- package/dist/sessions.js.map +1 -0
- package/dist/transport.d.ts +29 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +447 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +149 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/webhook-resource.d.ts +13 -0
- package/dist/webhook-resource.d.ts.map +1 -0
- package/dist/webhook-resource.js +52 -0
- package/dist/webhook-resource.js.map +1 -0
- package/dist/webhooks/index.d.ts +22 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +184 -0
- package/dist/webhooks/index.js.map +1 -0
- package/package.json +78 -4
- package/src/cli/main.ts +8 -0
- package/src/cli/verify.ts +291 -0
- package/src/client.ts +41 -0
- package/src/errors.ts +96 -0
- package/src/generated/openapi.ts +2578 -0
- package/src/index.ts +4 -0
- package/src/internal/decode.ts +317 -0
- package/src/internal/json.ts +64 -0
- package/src/internal/time.ts +85 -0
- package/src/polling.ts +77 -0
- package/src/receipts/bundle.ts +547 -0
- package/src/receipts/index.ts +27 -0
- package/src/receipts/json.ts +168 -0
- package/src/receipts/key-cache.ts +143 -0
- package/src/receipts/resource.ts +227 -0
- package/src/receipts/verify.ts +468 -0
- package/src/sessions.ts +227 -0
- package/src/transport.ts +524 -0
- package/src/types.ts +135 -0
- package/src/webhook-resource.ts +81 -0
- package/src/webhooks/index.ts +246 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/internal/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,GAAG,SAAI,EACP,GAAG,SAAgB,GAClB,MAAM,CAMR;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,IAAI,IAAI,CAAA;CAAE,CAgBnG;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAIzD;AAED,uFAAuF;AACvF,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAwBlF;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBpE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { SessError } from '../errors.js';
|
|
2
|
+
export function boundedNumber(value, fallback, name, min = 1, max = 2_147_483_647) {
|
|
3
|
+
const result = value ?? fallback;
|
|
4
|
+
if (!Number.isSafeInteger(result) || result < min || result > max) {
|
|
5
|
+
throw new SessError('configuration', `${name} is outside its supported range.`, { outcome: 'not_sent' });
|
|
6
|
+
}
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
export function deadline(ms, parent) {
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const abort = () => controller.abort(parent?.reason);
|
|
12
|
+
if (parent?.aborted)
|
|
13
|
+
abort();
|
|
14
|
+
else
|
|
15
|
+
parent?.addEventListener('abort', abort, { once: true });
|
|
16
|
+
const timer = setTimeout(() => controller.abort(new SessError('timeout', 'Operation deadline exceeded.')), ms);
|
|
17
|
+
return {
|
|
18
|
+
signal: controller.signal,
|
|
19
|
+
dispose() {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
parent?.removeEventListener('abort', abort);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function abortError(signal) {
|
|
26
|
+
return signal.reason instanceof SessError && signal.reason.kind === 'timeout'
|
|
27
|
+
? new SessError('timeout', 'Operation deadline exceeded.')
|
|
28
|
+
: new SessError('aborted', 'Operation was aborted. Remote work is not cancelled.');
|
|
29
|
+
}
|
|
30
|
+
/** Enforce deadlines even when a custom fetch/provider fails to observe its signal. */
|
|
31
|
+
export function withSignal(promise, signal) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const cleanup = () => signal.removeEventListener('abort', abort);
|
|
34
|
+
const abort = () => {
|
|
35
|
+
cleanup();
|
|
36
|
+
reject(abortError(signal));
|
|
37
|
+
};
|
|
38
|
+
if (signal.aborted) {
|
|
39
|
+
promise.catch(() => { });
|
|
40
|
+
abort();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
44
|
+
promise.then((value) => {
|
|
45
|
+
cleanup();
|
|
46
|
+
resolve(value);
|
|
47
|
+
}, (error) => {
|
|
48
|
+
cleanup();
|
|
49
|
+
reject(error);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export function delay(ms, signal) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
if (signal.aborted) {
|
|
56
|
+
reject(abortError(signal));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const abort = () => {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
signal.removeEventListener('abort', abort);
|
|
62
|
+
reject(abortError(signal));
|
|
63
|
+
};
|
|
64
|
+
const timer = setTimeout(() => {
|
|
65
|
+
signal.removeEventListener('abort', abort);
|
|
66
|
+
resolve();
|
|
67
|
+
}, ms);
|
|
68
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/internal/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,UAAU,aAAa,CAC3B,KAAyB,EACzB,QAAgB,EAChB,IAAY,EACZ,GAAG,GAAG,CAAC,EACP,GAAG,GAAG,aAAa;IAEnB,MAAM,MAAM,GAAG,KAAK,IAAI,QAAQ,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,GAAG,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QAClE,MAAM,IAAI,SAAS,CAAC,eAAe,EAAE,GAAG,IAAI,kCAAkC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,EAAU,EAAE,MAAoB;IACvD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,KAA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|
|
|
1
|
+
import type { RequestOptions, Session, VersionedResult, WaitOptions, WaitResult } from './types.js';
|
|
2
|
+
export declare function waitForResponse(retrieve: (options: RequestOptions) => Promise<VersionedResult<Session>>, id: string, input: WaitOptions, clientOperationTimeoutMs: number): Promise<WaitResult>;
|
|
3
|
+
//# sourceMappingURL=polling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../src/polling.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpG,wBAAsB,eAAe,CACnC,QAAQ,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,EACxE,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,WAAW,EAClB,wBAAwB,EAAE,MAAM,GAC/B,OAAO,CAAC,UAAU,CAAC,CAkErB"}
|
package/dist/polling.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { SessError } from './errors.js';
|
|
2
|
+
import { abortError, boundedNumber, deadline, delay } from './internal/time.js';
|
|
3
|
+
import { isInteractiveSession } from './types.js';
|
|
4
|
+
export async function waitForResponse(retrieve, id, input, clientOperationTimeoutMs) {
|
|
5
|
+
if (!input || typeof input !== 'object')
|
|
6
|
+
throw new SessError('configuration', 'waitForResponse requires an exact revision.');
|
|
7
|
+
const options = { ...input };
|
|
8
|
+
const revision = boundedNumber(options.revision, 0, 'revision');
|
|
9
|
+
const timeoutMs = boundedNumber(options.timeoutMs, 10 * 60_000, 'timeoutMs');
|
|
10
|
+
const intervalMs = boundedNumber(options.intervalMs, 1500, 'intervalMs', 1000);
|
|
11
|
+
if (options.operationTimeoutMs !== undefined && typeof options.operationTimeoutMs !== 'number')
|
|
12
|
+
throw new SessError('configuration', 'operationTimeoutMs must be a positive integer duration.', {
|
|
13
|
+
outcome: 'not_sent',
|
|
14
|
+
});
|
|
15
|
+
// Validate before clamping so malformed overrides cannot become usable durations.
|
|
16
|
+
const operationTimeoutMs = boundedNumber(options.operationTimeoutMs, clientOperationTimeoutMs, 'operationTimeoutMs');
|
|
17
|
+
const budget = deadline(timeoutMs, options.signal);
|
|
18
|
+
const expires = performance.now() + timeoutMs;
|
|
19
|
+
const ended = (code, message) => new SessError('wait_ended', message, { code, sessionId: id, revision });
|
|
20
|
+
try {
|
|
21
|
+
for (;;) {
|
|
22
|
+
if (budget.signal.aborted)
|
|
23
|
+
throw abortError(budget.signal);
|
|
24
|
+
const remainingMs = Math.ceil(expires - performance.now());
|
|
25
|
+
if (remainingMs <= 0)
|
|
26
|
+
throw ended('WAIT_TIMEOUT', 'Human wait timed out. Resume using the same Session and revision.');
|
|
27
|
+
const current = await retrieve({
|
|
28
|
+
signal: budget.signal,
|
|
29
|
+
operationTimeoutMs: Math.min(operationTimeoutMs, remainingMs),
|
|
30
|
+
maxRetries: options.maxRetries,
|
|
31
|
+
maxResponseBytes: options.maxResponseBytes,
|
|
32
|
+
});
|
|
33
|
+
if (!isInteractiveSession(current.data))
|
|
34
|
+
throw ended('NOT_INTERACTIVE', 'A display Session has no accepted human responses.');
|
|
35
|
+
const session = current.data;
|
|
36
|
+
const response = session.responses.find((item) => item.revision === revision);
|
|
37
|
+
// Retained history remains readable after a later revision or completion.
|
|
38
|
+
if (response)
|
|
39
|
+
return { session, response, meta: current.meta };
|
|
40
|
+
if (session.status === 'completed')
|
|
41
|
+
throw ended('CLOSED_WITHOUT_RESPONSE', 'Session completed without an accepted response for this revision.');
|
|
42
|
+
if (session.revision > revision)
|
|
43
|
+
throw ended('REVISION_SUPERSEDED', 'The requested unanswered revision was superseded.');
|
|
44
|
+
await delay(Math.min(intervalMs + Math.floor(Math.random() * 150), Math.max(1, Math.ceil(expires - performance.now()))), budget.signal);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (options.signal?.aborted)
|
|
49
|
+
throw new SessError('aborted', 'Human wait was aborted. The Session remains available.', {
|
|
50
|
+
sessionId: id,
|
|
51
|
+
revision,
|
|
52
|
+
});
|
|
53
|
+
if (budget.signal.aborted || performance.now() >= expires)
|
|
54
|
+
throw ended('WAIT_TIMEOUT', 'Human wait timed out. Resume using the same Session and revision.');
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
budget.dispose();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=polling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polling.js","sourceRoot":"","sources":["../src/polling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGlD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,QAAwE,EACxE,EAAU,EACV,KAAkB,EAClB,wBAAgC;IAEhC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QACrC,MAAM,IAAI,SAAS,CAAC,eAAe,EAAE,6CAA6C,CAAC,CAAC;IACtF,MAAM,OAAO,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,WAAW,CAAC,CAAC;IAC7E,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IAC/E,IAAI,OAAO,CAAC,kB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AC;YAAS,CAAC;QACT,MAAM,CAAC,OAAO,EAAE,CAAC;IACnB,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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