@reticlehq/core 3.6.0 → 3.8.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/dist/activation-entry.d.ts +9 -0
- package/dist/activation-entry.js +9 -0
- package/dist/artifacts/artifacts-entry.d.ts +2 -0
- package/dist/artifacts/artifacts-entry.js +2 -0
- package/dist/artifacts/drive-script.d.ts +222 -116
- package/dist/artifacts/drive-script.js +24 -1
- package/dist/artifacts/flow-constants.d.ts +33 -0
- package/dist/artifacts/flow-constants.js +35 -0
- package/dist/artifacts/flow-expect-flat.d.ts +8 -8
- package/dist/artifacts/flow-results.d.ts +461 -0
- package/dist/artifacts/flow-results.js +1 -0
- package/dist/artifacts/flow-types.d.ts +177 -543
- package/dist/artifacts/flow-types.js +17 -2
- package/dist/artifacts/harness-credits.d.ts +42 -0
- package/dist/artifacts/harness-credits.js +72 -0
- package/dist/artifacts/harness-map.d.ts +98 -0
- package/dist/artifacts/harness-map.js +36 -0
- package/dist/artifacts/impact.d.ts +355 -149
- package/dist/artifacts/impact.js +84 -49
- package/dist/artifacts/journal.d.ts +81 -11
- package/dist/artifacts/journal.js +39 -0
- package/dist/artifacts/prompt-context.d.ts +12 -0
- package/dist/artifacts/prompt-context.js +14 -3
- package/dist/artifacts/screenshot-upload.d.ts +51 -0
- package/dist/artifacts/screenshot-upload.js +26 -0
- package/dist/graph/app-graph.d.ts +137 -0
- package/dist/graph/app-graph.js +498 -0
- package/dist/hooks/hook-events.d.ts +26 -26
- package/dist/hud-entry.d.ts +1 -0
- package/dist/hud-entry.js +2 -0
- package/dist/identity/checkout.d.ts +41 -0
- package/dist/identity/checkout.js +118 -0
- package/dist/identity/state-dir.d.ts +23 -0
- package/dist/identity/state-dir.js +43 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +15 -0
- package/dist/onboarding.d.ts +30 -1
- package/dist/onboarding.js +25 -0
- package/dist/realm/registry.js +19 -1
- package/dist/registry/dev-server-registry.d.ts +2 -2
- package/dist/schema/command-message.json +30 -0
- package/dist/schema/command-name.json +3 -1
- package/dist/schema/event-message.json +3 -1
- package/dist/schema/event-payloads.json +156 -3
- package/dist/schema/event-type.json +3 -1
- package/dist/schema/hello-message.json +21 -0
- package/dist/schema/reticle-event.json +3 -1
- package/dist/schema/reticle-message.json +54 -1
- package/dist/telemetry-bug.d.ts +169 -0
- package/dist/telemetry-bug.js +123 -0
- package/dist/telemetry-entry.d.ts +2 -1
- package/dist/telemetry-entry.js +2 -1
- package/dist/telemetry-feedback.d.ts +16 -2
- package/dist/telemetry-feedback.js +19 -0
- package/dist/telemetry-session.d.ts +91 -2
- package/dist/telemetry-session.js +65 -0
- package/dist/telemetry-signals.d.ts +557 -0
- package/dist/telemetry-signals.js +225 -0
- package/dist/telemetry.d.ts +649 -296
- package/dist/telemetry.js +110 -119
- package/dist/verdict/check-sentence.d.ts +34 -0
- package/dist/verdict/check-sentence.js +228 -0
- package/dist/verdict/consequence.d.ts +15 -0
- package/dist/verdict/consequence.js +11 -0
- package/dist/verdict/disparity.d.ts +105 -0
- package/dist/verdict/disparity.js +40 -0
- package/dist/verdict/findings.d.ts +16 -0
- package/dist/verdict/findings.js +22 -0
- package/dist/verdict/instrumentation-coverage.d.ts +84 -0
- package/dist/verdict/instrumentation-coverage.js +182 -0
- package/dist/verdict/instrumentation-gap.d.ts +79 -0
- package/dist/verdict/instrumentation-gap.js +65 -1
- package/dist/verdict/intent.d.ts +19 -5
- package/dist/verdict/intent.js +13 -1
- package/dist/verdict/predicate-tree.d.ts +17 -0
- package/dist/verdict/predicate-tree.js +37 -0
- package/dist/verdict/predicate.d.ts +16 -1
- package/dist/verdict/predicate.js +188 -13
- package/dist/verdict/property-assertion.d.ts +2 -2
- package/dist/verdict/run-report.d.ts +166 -0
- package/dist/verdict/run-report.js +53 -0
- package/dist/verdict/security.d.ts +60 -1
- package/dist/verdict/security.js +174 -12
- package/dist/verdict/verification-run.d.ts +713 -68
- package/dist/verdict/verification-run.js +113 -0
- package/dist/verdict/verify-progress.d.ts +6 -6
- package/dist/wire/constants/constants.d.ts +69 -155
- package/dist/wire/constants/constants.js +78 -159
- package/dist/wire/constants/discovery.d.ts +4 -4
- package/dist/wire/constants/discovery.js +4 -4
- package/dist/wire/constants/event-types.d.ts +35 -1
- package/dist/wire/constants/event-types.js +33 -1
- package/dist/wire/constants/hud-controls.js +15 -5
- package/dist/wire/constants/hud-use.d.ts +33 -4
- package/dist/wire/constants/hud-use.js +30 -4
- package/dist/wire/constants/mcp-wire.d.ts +26 -0
- package/dist/wire/constants/mcp-wire.js +26 -0
- package/dist/wire/constants/response-body-reason.d.ts +19 -0
- package/dist/wire/constants/response-body-reason.js +18 -0
- package/dist/wire/constants/reticle-chrome.d.ts +19 -0
- package/dist/wire/constants/reticle-chrome.js +19 -0
- package/dist/wire/constants/reticle-env.d.ts +138 -0
- package/dist/wire/constants/reticle-env.js +138 -0
- package/dist/wire/constants/session-constants.d.ts +26 -2
- package/dist/wire/constants/session-constants.js +26 -2
- package/dist/wire/desktop-contract.d.ts +8 -0
- package/dist/wire/desktop-contract.js +11 -0
- package/dist/wire/event-payloads.d.ts +202 -36
- package/dist/wire/event-payloads.js +100 -16
- package/dist/wire/messages.d.ts +193 -54
- package/dist/wire/messages.js +25 -1
- package/dist/wire/narrow.d.ts +6 -0
- package/dist/wire/narrow.js +26 -0
- package/dist/wire/next-step.d.ts +90 -0
- package/dist/wire/next-step.js +37 -0
- package/dist/wire/platform-link.d.ts +84 -0
- package/dist/wire/platform-link.js +57 -6
- package/dist/wire/production/activation-ticket.d.ts +64 -0
- package/dist/wire/production/activation-ticket.js +148 -0
- package/dist/wire/production/hello-mode.d.ts +35 -0
- package/dist/wire/production/hello-mode.js +32 -0
- package/dist/wire/production/production-policy.d.ts +138 -0
- package/dist/wire/production/production-policy.js +133 -0
- package/dist/wire/tool-names.d.ts +4 -0
- package/dist/wire/tool-names.js +4 -0
- package/dist/wire/types.d.ts +90 -52
- package/dist/wire/types.js +5 -0
- package/dist/words/notices.d.ts +1 -1
- package/dist/words/notices.js +1 -1
- package/dist/words/upgrade.js +1 -1
- package/dist/words/writing-rule.d.ts +14 -0
- package/dist/words/writing-rule.js +17 -0
- package/package.json +5 -1
package/dist/wire/messages.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { HudPanel, HudToggle, HudView } from './constants/hud-use.js';
|
|
2
|
+
import { HudPanel, HudPromptSurface, HudToggle, HudView } from './constants/hud-use.js';
|
|
3
3
|
import { EventAttribution, EventType, RETICLE_MIN_PROTOCOL_VERSION, RETICLE_PROTOCOL_VERSION, MessageKind, TRANSPORT_LIMITS, } from './constants/constants.js';
|
|
4
4
|
import { HumanControlKind, MarkAnchorStrategy } from './constants/session-constants.js';
|
|
5
5
|
import { MAX_WIRE_REDACT_KEYS, MAX_WIRE_REDACT_KEY_LENGTH } from './redaction.js';
|
|
@@ -7,6 +7,8 @@ import { DOCUMENT_ID_LENGTH } from '../identity/document-identity.js';
|
|
|
7
7
|
import { NO_EDITS_OBSERVED } from '../identity/edit-epoch.js';
|
|
8
8
|
import { PlatformProfile } from './platform.js';
|
|
9
9
|
import { ChannelId } from './channel.js';
|
|
10
|
+
import { HelloEnv, HelloInstrumentation, HelloScope } from './production/hello-mode.js';
|
|
11
|
+
import { OutwardAction } from '../verdict/security.js';
|
|
10
12
|
const sessionIdSchema = z.string().min(1).max(TRANSPORT_LIMITS.MAX_SESSION_ID_LENGTH);
|
|
11
13
|
const refSchema = z.string().max(TRANSPORT_LIMITS.MAX_REF_LENGTH);
|
|
12
14
|
const documentIdSchema = z.string().min(1).max(DOCUMENT_ID_LENGTH);
|
|
@@ -35,6 +37,8 @@ export const HudUseDataSchema = z.object({
|
|
|
35
37
|
panel: z.nativeEnum(HudPanel).optional(),
|
|
36
38
|
/** A rail slide that became the visible one. Its shape is checked where it is counted. */
|
|
37
39
|
slide: z.string().max(56).optional(),
|
|
40
|
+
/** A sign-in or link prompt became visible on this surface. */
|
|
41
|
+
prompt: z.nativeEnum(HudPromptSurface).optional(),
|
|
38
42
|
});
|
|
39
43
|
/**
|
|
40
44
|
* Human review: the narrowed payload of a HUMAN_MARK event. A human flagged a mistake pinned to an
|
|
@@ -134,6 +138,16 @@ export const HelloMessageSchema = z.object({
|
|
|
134
138
|
.max(TRANSPORT_LIMITS.MAX_ADAPTERS),
|
|
135
139
|
/** Optional browser/bridge pairing token. Required when the bridge configures one. */
|
|
136
140
|
token: z.string().max(TRANSPORT_LIMITS.MAX_TOKEN_LENGTH).optional(),
|
|
141
|
+
/**
|
|
142
|
+
* Where this page runs. ABSENT MEANS `development`: every SDK before this field was a dev build.
|
|
143
|
+
* The bridge accepts `production` only with a session nonce, never with the pairing token.
|
|
144
|
+
*/
|
|
145
|
+
env: z.nativeEnum(HelloEnv).optional(),
|
|
146
|
+
/**
|
|
147
|
+
* What a drive may do here: `observe` or `act`. Absent means `act` in development. The bridge
|
|
148
|
+
* refuses a production HELLO without it, and a page can only narrow what its nonce granted.
|
|
149
|
+
*/
|
|
150
|
+
scope: z.nativeEnum(HelloScope).optional(),
|
|
137
151
|
/**
|
|
138
152
|
* What kind of surface this is: a browser document, a web page in somebody else's window, a
|
|
139
153
|
* native view tree, or no rendering surface at all. See platform.ts.
|
|
@@ -213,6 +227,11 @@ export const HelloMessageSchema = z.object({
|
|
|
213
227
|
* would suppress the honest gap for every app that simply has no source mapping at all.
|
|
214
228
|
*/
|
|
215
229
|
sourceMapping: z.boolean().optional(),
|
|
230
|
+
/**
|
|
231
|
+
* Who put the SDK in this page: `installed` by the app, or `injected` from outside by a hosted
|
|
232
|
+
* verifier. ABSENT means `installed`. See `HelloInstrumentation`.
|
|
233
|
+
*/
|
|
234
|
+
instrumentation: z.nativeEnum(HelloInstrumentation).optional(),
|
|
216
235
|
/**
|
|
217
236
|
* The version of the SDK in the page, so a version-skewed pair can SAY so.
|
|
218
237
|
*
|
|
@@ -260,6 +279,11 @@ export const CommandMessageSchema = z.object({
|
|
|
260
279
|
args: z.record(z.unknown()).default({}),
|
|
261
280
|
/** Set when the Harness sent it, so the HUD can say who is driving. */
|
|
262
281
|
by: z.nativeEnum(CommandActor).optional(),
|
|
282
|
+
/**
|
|
283
|
+
* Set on a Harness command a model chose: the outward actions (`OutwardAction`) its journey asks
|
|
284
|
+
* for. The page presses no other outward control. Absent: not gated (an agent, a saved flow).
|
|
285
|
+
*/
|
|
286
|
+
outward: z.object({ allowed: z.array(z.nativeEnum(OutwardAction)).max(16) }).optional(),
|
|
263
287
|
});
|
|
264
288
|
/** Browser -> agent reply to a command. */
|
|
265
289
|
export const CommandResultSchema = z.object({
|
package/dist/wire/narrow.d.ts
CHANGED
|
@@ -37,3 +37,9 @@ export declare function asNumber(value: unknown): number | undefined;
|
|
|
37
37
|
* move, and a move that also changes behaviour is two changes wearing one message.
|
|
38
38
|
*/
|
|
39
39
|
export declare function asRecord(value: unknown): Record<string, unknown>;
|
|
40
|
+
/** Whether the value is an object other than `null` or an array; `asRecord` lets arrays through. */
|
|
41
|
+
export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
42
|
+
/** The URL's origin, or nothing when it is absent or does not parse. */
|
|
43
|
+
export declare function originOf(url: string | undefined): string | undefined;
|
|
44
|
+
/** The URL's pathname, or nothing when it is absent or does not parse. */
|
|
45
|
+
export declare function pathOf(url: string | undefined): string | undefined;
|
package/dist/wire/narrow.js
CHANGED
|
@@ -43,3 +43,29 @@ export function asNumber(value) {
|
|
|
43
43
|
export function asRecord(value) {
|
|
44
44
|
return 'object' === typeof value && value !== null ? value : {};
|
|
45
45
|
}
|
|
46
|
+
/** Whether the value is an object other than `null` or an array; `asRecord` lets arrays through. */
|
|
47
|
+
export function isPlainRecord(value) {
|
|
48
|
+
return 'object' === typeof value && value !== null && !Array.isArray(value);
|
|
49
|
+
}
|
|
50
|
+
/** The URL's origin, or nothing when it is absent or does not parse. */
|
|
51
|
+
export function originOf(url) {
|
|
52
|
+
if (url === undefined)
|
|
53
|
+
return undefined;
|
|
54
|
+
try {
|
|
55
|
+
return new URL(url).origin;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** The URL's pathname, or nothing when it is absent or does not parse. */
|
|
62
|
+
export function pathOf(url) {
|
|
63
|
+
if (url === undefined)
|
|
64
|
+
return undefined;
|
|
65
|
+
try {
|
|
66
|
+
return new URL(url).pathname;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to do next, and who does it, when Reticle refuses something.
|
|
3
|
+
*
|
|
4
|
+
* One file because the daemon, the HUD and the agent each say part of the same answer. When each
|
|
5
|
+
* wrote its own, the Harness refusal said `reticle connect` and the recovery beside it said
|
|
6
|
+
* `npx @reticlehq/server connect`: two spellings of one command, in one answer.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
/** The command that signs a person in and links a project. The docs spell it this way. */
|
|
10
|
+
export declare const CONNECT_COMMAND = "reticle connect";
|
|
11
|
+
/** The refusals that say what to do next as data rather than in a sentence. */
|
|
12
|
+
export declare const RefusalCode: {
|
|
13
|
+
/** The Harness was asked for, and this project is not linked to the platform it runs on. */
|
|
14
|
+
readonly HARNESS_NOT_LINKED: "harness_not_linked";
|
|
15
|
+
};
|
|
16
|
+
export type RefusalCode = (typeof RefusalCode)[keyof typeof RefusalCode];
|
|
17
|
+
/** Who takes a next step: the person (a command to run) or the agent (a tool to call). */
|
|
18
|
+
export declare const NextWho: {
|
|
19
|
+
readonly HUMAN: "human";
|
|
20
|
+
readonly AGENT: "agent";
|
|
21
|
+
};
|
|
22
|
+
export declare const NextStepSchema: z.ZodDiscriminatedUnion<"who", [z.ZodObject<{
|
|
23
|
+
who: z.ZodLiteral<"human">;
|
|
24
|
+
run: z.ZodString;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
who: "human";
|
|
27
|
+
run: string;
|
|
28
|
+
}, {
|
|
29
|
+
who: "human";
|
|
30
|
+
run: string;
|
|
31
|
+
}>, z.ZodObject<{
|
|
32
|
+
who: z.ZodLiteral<"agent">;
|
|
33
|
+
tool: z.ZodString;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
tool: string;
|
|
36
|
+
who: "agent";
|
|
37
|
+
}, {
|
|
38
|
+
tool: string;
|
|
39
|
+
who: "agent";
|
|
40
|
+
}>]>;
|
|
41
|
+
export type NextStep = z.infer<typeof NextStepSchema>;
|
|
42
|
+
/** A coded refusal, as it rides on a tool's error envelope beside `error`. */
|
|
43
|
+
export declare const CodedRefusalSchema: z.ZodObject<{
|
|
44
|
+
code: z.ZodEnum<["harness_not_linked"]>;
|
|
45
|
+
next: z.ZodArray<z.ZodDiscriminatedUnion<"who", [z.ZodObject<{
|
|
46
|
+
who: z.ZodLiteral<"human">;
|
|
47
|
+
run: z.ZodString;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
who: "human";
|
|
50
|
+
run: string;
|
|
51
|
+
}, {
|
|
52
|
+
who: "human";
|
|
53
|
+
run: string;
|
|
54
|
+
}>, z.ZodObject<{
|
|
55
|
+
who: z.ZodLiteral<"agent">;
|
|
56
|
+
tool: z.ZodString;
|
|
57
|
+
}, "strip", z.ZodTypeAny, {
|
|
58
|
+
tool: string;
|
|
59
|
+
who: "agent";
|
|
60
|
+
}, {
|
|
61
|
+
tool: string;
|
|
62
|
+
who: "agent";
|
|
63
|
+
}>]>, "many">;
|
|
64
|
+
}, "strip", z.ZodTypeAny, {
|
|
65
|
+
code: "harness_not_linked";
|
|
66
|
+
next: ({
|
|
67
|
+
who: "human";
|
|
68
|
+
run: string;
|
|
69
|
+
} | {
|
|
70
|
+
tool: string;
|
|
71
|
+
who: "agent";
|
|
72
|
+
})[];
|
|
73
|
+
}, {
|
|
74
|
+
code: "harness_not_linked";
|
|
75
|
+
next: ({
|
|
76
|
+
who: "human";
|
|
77
|
+
run: string;
|
|
78
|
+
} | {
|
|
79
|
+
tool: string;
|
|
80
|
+
who: "agent";
|
|
81
|
+
})[];
|
|
82
|
+
}>;
|
|
83
|
+
export type CodedRefusal = z.infer<typeof CodedRefusalSchema>;
|
|
84
|
+
/** Not linked: the person connects, or the agent drives the journey itself. */
|
|
85
|
+
export declare const HARNESS_NOT_LINKED_NEXT: readonly NextStep[];
|
|
86
|
+
/**
|
|
87
|
+
* The same refusal, for the person on the HUD: one sentence, the command, no tool names. No credit
|
|
88
|
+
* number either: free credit is granted once per person, so the engine cannot know what is left.
|
|
89
|
+
*/
|
|
90
|
+
export declare const HARNESS_NOT_LINKED_HUMAN = "Connect your Reticle account to run the Harness: `reticle connect`.";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to do next, and who does it, when Reticle refuses something.
|
|
3
|
+
*
|
|
4
|
+
* One file because the daemon, the HUD and the agent each say part of the same answer. When each
|
|
5
|
+
* wrote its own, the Harness refusal said `reticle connect` and the recovery beside it said
|
|
6
|
+
* `npx @reticlehq/server connect`: two spellings of one command, in one answer.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { ReticleTool } from './tool-names.js';
|
|
10
|
+
/** The command that signs a person in and links a project. The docs spell it this way. */
|
|
11
|
+
export const CONNECT_COMMAND = 'reticle connect';
|
|
12
|
+
/** The refusals that say what to do next as data rather than in a sentence. */
|
|
13
|
+
export const RefusalCode = {
|
|
14
|
+
/** The Harness was asked for, and this project is not linked to the platform it runs on. */
|
|
15
|
+
HARNESS_NOT_LINKED: 'harness_not_linked',
|
|
16
|
+
};
|
|
17
|
+
/** Who takes a next step: the person (a command to run) or the agent (a tool to call). */
|
|
18
|
+
export const NextWho = { HUMAN: 'human', AGENT: 'agent' };
|
|
19
|
+
export const NextStepSchema = z.discriminatedUnion('who', [
|
|
20
|
+
z.object({ who: z.literal(NextWho.HUMAN), run: z.string() }),
|
|
21
|
+
z.object({ who: z.literal(NextWho.AGENT), tool: z.string() }),
|
|
22
|
+
]);
|
|
23
|
+
/** A coded refusal, as it rides on a tool's error envelope beside `error`. */
|
|
24
|
+
export const CodedRefusalSchema = z.object({
|
|
25
|
+
code: z.enum([RefusalCode.HARNESS_NOT_LINKED]),
|
|
26
|
+
next: z.array(NextStepSchema),
|
|
27
|
+
});
|
|
28
|
+
/** Not linked: the person connects, or the agent drives the journey itself. */
|
|
29
|
+
export const HARNESS_NOT_LINKED_NEXT = [
|
|
30
|
+
{ who: NextWho.HUMAN, run: CONNECT_COMMAND },
|
|
31
|
+
{ who: NextWho.AGENT, tool: ReticleTool.ACT_AND_WAIT },
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* The same refusal, for the person on the HUD: one sentence, the command, no tool names. No credit
|
|
35
|
+
* number either: free credit is granted once per person, so the engine cannot know what is left.
|
|
36
|
+
*/
|
|
37
|
+
export const HARNESS_NOT_LINKED_HUMAN = `Connect your Reticle account to run the Harness: \`${CONNECT_COMMAND}\`.`;
|
|
@@ -57,6 +57,14 @@ export interface DriveSpec {
|
|
|
57
57
|
maxSteps?: number;
|
|
58
58
|
/** Whether pictures of the page may leave the machine. */
|
|
59
59
|
record?: boolean;
|
|
60
|
+
/** A plan the platform saved: run it as it stands instead of asking for a new one. */
|
|
61
|
+
plan?: string;
|
|
62
|
+
/**
|
|
63
|
+
* A person started this run (Run plan, Re-verify, Run suite) and so acknowledged the saved flows'
|
|
64
|
+
* own destructive steps: their replays may take them. A fresh action the model decides keeps the
|
|
65
|
+
* guard whatever this says.
|
|
66
|
+
*/
|
|
67
|
+
confirmDangerous?: boolean;
|
|
60
68
|
}
|
|
61
69
|
export interface SpecIgnored {
|
|
62
70
|
field: string;
|
|
@@ -94,6 +102,13 @@ export interface ToolSessionResult {
|
|
|
94
102
|
result?: unknown;
|
|
95
103
|
error?: string;
|
|
96
104
|
ms: number;
|
|
105
|
+
/**
|
|
106
|
+
* When the call started and ended on the daemon's clock (epoch ms). The platform saw only its own
|
|
107
|
+
* send and the reply, which folds the network and the queue into the tool's time. Optional: an
|
|
108
|
+
* older daemon does not send them.
|
|
109
|
+
*/
|
|
110
|
+
startedAt?: number;
|
|
111
|
+
endedAt?: number;
|
|
97
112
|
}
|
|
98
113
|
/** The platform's answer to a session ask: the next calls, or that the drive is over. */
|
|
99
114
|
export interface ToolSessionReply {
|
|
@@ -159,3 +174,72 @@ export declare const LinkPath: {
|
|
|
159
174
|
/** One turn of a tool session: results in, next calls out. */
|
|
160
175
|
readonly driveSession: (id: string) => string;
|
|
161
176
|
};
|
|
177
|
+
/**
|
|
178
|
+
* What a daemon adds to each local-apps report so the platform can say what an app is missing and
|
|
179
|
+
* why a page never connected. Every key is additive: a platform that predates one ignores it.
|
|
180
|
+
*/
|
|
181
|
+
export declare const LinkReportKey: {
|
|
182
|
+
/** Per app: the channels its page announced in its HELLO. */
|
|
183
|
+
readonly CHANNELS: "channels";
|
|
184
|
+
/** Per app: instrumentation gaps its verdicts recorded, deduped by kind + missing, newest first. */
|
|
185
|
+
readonly GAPS: "gaps";
|
|
186
|
+
/** Per app: the framework adapters its page announced. */
|
|
187
|
+
readonly ADAPTERS: "adapters";
|
|
188
|
+
/**
|
|
189
|
+
* Per app: coverage capabilities that do not apply to it (`CoverageCapability` values, see
|
|
190
|
+
* `NotApplicableSchema`), excluded from both sides of the coverage score. Always sent, empty when
|
|
191
|
+
* every capability applies.
|
|
192
|
+
*/
|
|
193
|
+
readonly NOT_APPLICABLE: "notApplicable";
|
|
194
|
+
/** Top level: dev servers listening on this machine that no Reticle page has connected from. */
|
|
195
|
+
readonly DEV_SERVERS: "devServers";
|
|
196
|
+
/** Top level: the last page handshake this daemon refused, and why. */
|
|
197
|
+
readonly HELLO_FAILURE: "helloFailure";
|
|
198
|
+
/** Top level: `.reticle` folders holding runs that never reached the platform. */
|
|
199
|
+
readonly UNSYNCED: "unsynced";
|
|
200
|
+
};
|
|
201
|
+
/** How many recorded gaps one app reports. */
|
|
202
|
+
export declare const LINK_APP_GAPS_MAX = 20;
|
|
203
|
+
/** One recorded instrumentation gap, as an app report carries it. */
|
|
204
|
+
export interface LinkAppGap {
|
|
205
|
+
kind: string;
|
|
206
|
+
missing: string;
|
|
207
|
+
fix: string;
|
|
208
|
+
seenAt: number;
|
|
209
|
+
}
|
|
210
|
+
/** A dev server listening on localhost with no connected Reticle page. */
|
|
211
|
+
export interface LinkDevServer {
|
|
212
|
+
url: string;
|
|
213
|
+
port: number;
|
|
214
|
+
}
|
|
215
|
+
/** The last refused page handshake: version skew, token, port or protocol, in `reason`. */
|
|
216
|
+
export interface LinkHelloFailure {
|
|
217
|
+
reason: string;
|
|
218
|
+
at: number;
|
|
219
|
+
sdkVersion?: string;
|
|
220
|
+
}
|
|
221
|
+
/** A `.reticle` folder with runs that never reached the platform. `root` is `~`-relative. */
|
|
222
|
+
export interface LinkUnsyncedRoot {
|
|
223
|
+
root: string;
|
|
224
|
+
runs: number;
|
|
225
|
+
linked: boolean;
|
|
226
|
+
/** The project the folder belongs to, so a board lists only its own. Absent when none is named. */
|
|
227
|
+
projectId?: string;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Markers a daemon adds to an app's `channels` beside the protocol channel ids, for the two
|
|
231
|
+
* capabilities no channel names. Sent only on evidence, never while the gap that names the same
|
|
232
|
+
* capability is recorded: absence of both reads as "not seen yet", never as covered.
|
|
233
|
+
*/
|
|
234
|
+
export declare const CoverageMarker: {
|
|
235
|
+
/** The page carries `data-reticle-source` (the build plugin is active). */
|
|
236
|
+
readonly SOURCE: "source";
|
|
237
|
+
/** The app's snapshots show `data-testid` on its controls. */
|
|
238
|
+
readonly TESTID: "testid";
|
|
239
|
+
};
|
|
240
|
+
export type CoverageMarker = (typeof CoverageMarker)[keyof typeof CoverageMarker];
|
|
241
|
+
/**
|
|
242
|
+
* The file:line capability's name (`CoverageCapability.SOURCE_MAPPING` is this). Here, beside the
|
|
243
|
+
* markers, so a page can say it does not apply without loading the coverage rules into first load.
|
|
244
|
+
*/
|
|
245
|
+
export declare const SOURCE_MAPPING_CAPABILITY = "file:line source mapping";
|
|
@@ -65,6 +65,7 @@ export const SpecIgnoredReason = {
|
|
|
65
65
|
UNAVAILABLE: 'unavailable',
|
|
66
66
|
};
|
|
67
67
|
const PERSONA_MAX = 2_000;
|
|
68
|
+
const PLAN_ID_MAX = 128;
|
|
68
69
|
const STEPS_MAX = 500;
|
|
69
70
|
/** Each field of a spec, validated on its own so one bad field never costs the others. */
|
|
70
71
|
const SPEC_FIELDS = {
|
|
@@ -78,6 +79,8 @@ const SPEC_FIELDS = {
|
|
|
78
79
|
persona: z.string().min(1).max(PERSONA_MAX),
|
|
79
80
|
maxSteps: z.number().int().min(1).max(STEPS_MAX),
|
|
80
81
|
record: z.boolean(),
|
|
82
|
+
plan: z.string().min(1).max(PLAN_ID_MAX),
|
|
83
|
+
confirmDangerous: z.boolean(),
|
|
81
84
|
};
|
|
82
85
|
/**
|
|
83
86
|
* Read a spec as far as it can be read. Never throws: a field that does not validate, or that this
|
|
@@ -86,8 +89,9 @@ const SPEC_FIELDS = {
|
|
|
86
89
|
export function parseDriveSpec(raw) {
|
|
87
90
|
const ignored = [];
|
|
88
91
|
const spec = {};
|
|
89
|
-
if ('object' !== typeof raw || null === raw || Array.isArray(raw))
|
|
92
|
+
if ('object' !== typeof raw || null === raw || Array.isArray(raw)) {
|
|
90
93
|
return { spec, ignored };
|
|
94
|
+
}
|
|
91
95
|
for (const [field, value] of Object.entries(raw)) {
|
|
92
96
|
const schema = SPEC_FIELDS[field];
|
|
93
97
|
if (schema === undefined) {
|
|
@@ -95,10 +99,12 @@ export function parseDriveSpec(raw) {
|
|
|
95
99
|
continue;
|
|
96
100
|
}
|
|
97
101
|
const parsed = schema.safeParse(value);
|
|
98
|
-
if (parsed.success)
|
|
102
|
+
if (parsed.success) {
|
|
99
103
|
spec[field] = parsed.data;
|
|
100
|
-
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
101
106
|
ignored.push({ field, reason: SpecIgnoredReason.INVALID });
|
|
107
|
+
}
|
|
102
108
|
}
|
|
103
109
|
return { spec, ignored };
|
|
104
110
|
}
|
|
@@ -132,8 +138,9 @@ const SessionCallSchema = z.object({
|
|
|
132
138
|
* dropped; the platform sees no result for its `seq` and decides what that means.
|
|
133
139
|
*/
|
|
134
140
|
export function parseToolSessionReply(raw) {
|
|
135
|
-
if ('object' !== typeof raw || null === raw)
|
|
141
|
+
if ('object' !== typeof raw || null === raw) {
|
|
136
142
|
return { calls: [], done: true };
|
|
143
|
+
}
|
|
137
144
|
const record = raw;
|
|
138
145
|
const calls = (Array.isArray(record.calls) ? record.calls : [])
|
|
139
146
|
.slice(0, TOOL_SESSION_LIMITS.MAX_BATCH)
|
|
@@ -157,12 +164,14 @@ export function parseLinkNotices(raw) {
|
|
|
157
164
|
const levels = new Set(Object.values(LinkNoticeLevel));
|
|
158
165
|
return (Array.isArray(raw) ? raw : [])
|
|
159
166
|
.flatMap((entry) => {
|
|
160
|
-
if ('object' !== typeof entry || null === entry)
|
|
167
|
+
if ('object' !== typeof entry || null === entry) {
|
|
161
168
|
return [];
|
|
169
|
+
}
|
|
162
170
|
const notice = entry;
|
|
163
171
|
const text = 'string' === typeof notice.text ? notice.text.trim() : '';
|
|
164
|
-
if ('string' !== typeof notice.level || !levels.has(notice.level) || 0 === text.length)
|
|
172
|
+
if ('string' !== typeof notice.level || !levels.has(notice.level) || 0 === text.length) {
|
|
165
173
|
return [];
|
|
174
|
+
}
|
|
166
175
|
const url = 'string' === typeof notice.url && /^https?:\/\//i.test(notice.url) ? notice.url : undefined;
|
|
167
176
|
return [
|
|
168
177
|
{
|
|
@@ -187,3 +196,45 @@ export const LinkPath = {
|
|
|
187
196
|
/** One turn of a tool session: results in, next calls out. */
|
|
188
197
|
driveSession: (id) => `/v1/harness/local-drives/${encodeURIComponent(id)}/session`,
|
|
189
198
|
};
|
|
199
|
+
/**
|
|
200
|
+
* What a daemon adds to each local-apps report so the platform can say what an app is missing and
|
|
201
|
+
* why a page never connected. Every key is additive: a platform that predates one ignores it.
|
|
202
|
+
*/
|
|
203
|
+
export const LinkReportKey = {
|
|
204
|
+
/** Per app: the channels its page announced in its HELLO. */
|
|
205
|
+
CHANNELS: 'channels',
|
|
206
|
+
/** Per app: instrumentation gaps its verdicts recorded, deduped by kind + missing, newest first. */
|
|
207
|
+
GAPS: 'gaps',
|
|
208
|
+
/** Per app: the framework adapters its page announced. */
|
|
209
|
+
ADAPTERS: 'adapters',
|
|
210
|
+
/**
|
|
211
|
+
* Per app: coverage capabilities that do not apply to it (`CoverageCapability` values, see
|
|
212
|
+
* `NotApplicableSchema`), excluded from both sides of the coverage score. Always sent, empty when
|
|
213
|
+
* every capability applies.
|
|
214
|
+
*/
|
|
215
|
+
NOT_APPLICABLE: 'notApplicable',
|
|
216
|
+
/** Top level: dev servers listening on this machine that no Reticle page has connected from. */
|
|
217
|
+
DEV_SERVERS: 'devServers',
|
|
218
|
+
/** Top level: the last page handshake this daemon refused, and why. */
|
|
219
|
+
HELLO_FAILURE: 'helloFailure',
|
|
220
|
+
/** Top level: `.reticle` folders holding runs that never reached the platform. */
|
|
221
|
+
UNSYNCED: 'unsynced',
|
|
222
|
+
};
|
|
223
|
+
/** How many recorded gaps one app reports. */
|
|
224
|
+
export const LINK_APP_GAPS_MAX = 20;
|
|
225
|
+
/**
|
|
226
|
+
* Markers a daemon adds to an app's `channels` beside the protocol channel ids, for the two
|
|
227
|
+
* capabilities no channel names. Sent only on evidence, never while the gap that names the same
|
|
228
|
+
* capability is recorded: absence of both reads as "not seen yet", never as covered.
|
|
229
|
+
*/
|
|
230
|
+
export const CoverageMarker = {
|
|
231
|
+
/** The page carries `data-reticle-source` (the build plugin is active). */
|
|
232
|
+
SOURCE: 'source',
|
|
233
|
+
/** The app's snapshots show `data-testid` on its controls. */
|
|
234
|
+
TESTID: 'testid',
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* The file:line capability's name (`CoverageCapability.SOURCE_MAPPING` is this). Here, beside the
|
|
238
|
+
* markers, so a page can say it does not apply without loading the coverage rules into first load.
|
|
239
|
+
*/
|
|
240
|
+
export const SOURCE_MAPPING_CAPABILITY = 'file:line source mapping';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { HelloScope } from './hello-mode.js';
|
|
2
|
+
/**
|
|
3
|
+
* The activation ticket a page checks for itself before it loads the SDK on a live site.
|
|
4
|
+
*
|
|
5
|
+
* The service mints it and signs it with Ed25519. The page carries only the public key, so it can
|
|
6
|
+
* check the ticket with no round trip and no secret. Format: `<payload>.<signature>`. Both parts
|
|
7
|
+
* are base64url. `payload` is the JSON of `ActivationTicketPayload`, and the signature covers the
|
|
8
|
+
* ASCII bytes of the payload part as it is written.
|
|
9
|
+
*
|
|
10
|
+
* Hand-narrowed and not a zod schema on purpose: the page-side loader imports this file, and zod
|
|
11
|
+
* would put a schema library into every page load of a live site to check six fields.
|
|
12
|
+
*/
|
|
13
|
+
/** The query parameter the site opens with. The page loader removes it from the address bar. */
|
|
14
|
+
export declare const PRODUCTION_ACTIVATE_PARAM = "reticle_activate";
|
|
15
|
+
/** The only ticket format this file reads. A new format gets a new number. */
|
|
16
|
+
export declare const ACTIVATION_TICKET_VERSION = 1;
|
|
17
|
+
export interface ActivationTicketPayload {
|
|
18
|
+
v: typeof ACTIVATION_TICKET_VERSION;
|
|
19
|
+
/** The single-use HELLO token the bridge minted for this drive. The page sends it as `token`. */
|
|
20
|
+
nonce: string;
|
|
21
|
+
/** The page origin the ticket is for. Another origin refuses it. */
|
|
22
|
+
origin: string;
|
|
23
|
+
/** The bridge the page connects to. `wss://`, or `ws://` on a loopback host only. */
|
|
24
|
+
bridge: string;
|
|
25
|
+
scope: HelloScope;
|
|
26
|
+
/** When the ticket stops being valid, in epoch ms. */
|
|
27
|
+
exp: number;
|
|
28
|
+
}
|
|
29
|
+
/** Why a page refused a ticket. The page does nothing in each case. */
|
|
30
|
+
export declare const ActivationRefusal: {
|
|
31
|
+
readonly MALFORMED: "malformed ticket";
|
|
32
|
+
readonly BAD_SIGNATURE: "the signature does not verify";
|
|
33
|
+
readonly EXPIRED: "the ticket expired";
|
|
34
|
+
readonly WRONG_ORIGIN: "the ticket is for another origin";
|
|
35
|
+
readonly INSECURE_BRIDGE: "the bridge is not wss:// or a loopback ws://";
|
|
36
|
+
};
|
|
37
|
+
export type ActivationRefusal = (typeof ActivationRefusal)[keyof typeof ActivationRefusal];
|
|
38
|
+
export type ActivationVerdict = {
|
|
39
|
+
ok: true;
|
|
40
|
+
payload: ActivationTicketPayload;
|
|
41
|
+
} | {
|
|
42
|
+
ok: false;
|
|
43
|
+
reason: ActivationRefusal;
|
|
44
|
+
};
|
|
45
|
+
type Subtle = typeof globalThis.crypto.subtle;
|
|
46
|
+
type SigningKey = Parameters<Subtle['sign']>[1];
|
|
47
|
+
export declare function toBase64Url(bytes: Uint8Array): string;
|
|
48
|
+
/**
|
|
49
|
+
* Check a ticket against the service's public key (base64url, raw 32 bytes), the page origin and
|
|
50
|
+
* the clock. Never throws.
|
|
51
|
+
*/
|
|
52
|
+
export declare function verifyActivationTicket(ticket: string, options: {
|
|
53
|
+
publicKey: string;
|
|
54
|
+
origin: string;
|
|
55
|
+
now: number;
|
|
56
|
+
subtle?: Subtle;
|
|
57
|
+
}): Promise<ActivationVerdict>;
|
|
58
|
+
/**
|
|
59
|
+
* Mint a ticket. For the service only: it holds the Ed25519 private key, and the key never leaves
|
|
60
|
+
* it. Import a PKCS#8 key with `crypto.subtle.importKey('pkcs8', der, { name: 'Ed25519' }, false,
|
|
61
|
+
* ['sign'])`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function signActivationTicket(privateKey: SigningKey, payload: ActivationTicketPayload, subtle?: Subtle): Promise<string>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { HelloScope } from './hello-mode.js';
|
|
2
|
+
import { isLoopbackHostname } from '../../verdict/security.js';
|
|
3
|
+
/**
|
|
4
|
+
* The activation ticket a page checks for itself before it loads the SDK on a live site.
|
|
5
|
+
*
|
|
6
|
+
* The service mints it and signs it with Ed25519. The page carries only the public key, so it can
|
|
7
|
+
* check the ticket with no round trip and no secret. Format: `<payload>.<signature>`. Both parts
|
|
8
|
+
* are base64url. `payload` is the JSON of `ActivationTicketPayload`, and the signature covers the
|
|
9
|
+
* ASCII bytes of the payload part as it is written.
|
|
10
|
+
*
|
|
11
|
+
* Hand-narrowed and not a zod schema on purpose: the page-side loader imports this file, and zod
|
|
12
|
+
* would put a schema library into every page load of a live site to check six fields.
|
|
13
|
+
*/
|
|
14
|
+
/** The query parameter the site opens with. The page loader removes it from the address bar. */
|
|
15
|
+
export const PRODUCTION_ACTIVATE_PARAM = 'reticle_activate';
|
|
16
|
+
/** The only ticket format this file reads. A new format gets a new number. */
|
|
17
|
+
export const ACTIVATION_TICKET_VERSION = 1;
|
|
18
|
+
/** Joins the payload part and the signature part. */
|
|
19
|
+
const TICKET_SEPARATOR = '.';
|
|
20
|
+
const ED25519 = 'Ed25519';
|
|
21
|
+
const RAW_KEY_FORMAT = 'raw';
|
|
22
|
+
const WS_PROTOCOL = 'ws:';
|
|
23
|
+
const WSS_PROTOCOL = 'wss:';
|
|
24
|
+
/** Bounds, so a page never parses an unbounded string from its own address bar. */
|
|
25
|
+
const MAX_TICKET_LENGTH = 4096;
|
|
26
|
+
const MAX_FIELD_LENGTH = 2048;
|
|
27
|
+
/** Why a page refused a ticket. The page does nothing in each case. */
|
|
28
|
+
export const ActivationRefusal = {
|
|
29
|
+
MALFORMED: 'malformed ticket',
|
|
30
|
+
BAD_SIGNATURE: 'the signature does not verify',
|
|
31
|
+
EXPIRED: 'the ticket expired',
|
|
32
|
+
WRONG_ORIGIN: 'the ticket is for another origin',
|
|
33
|
+
INSECURE_BRIDGE: 'the bridge is not wss:// or a loopback ws://',
|
|
34
|
+
};
|
|
35
|
+
export function toBase64Url(bytes) {
|
|
36
|
+
let binary = '';
|
|
37
|
+
for (const byte of bytes)
|
|
38
|
+
binary += String.fromCharCode(byte);
|
|
39
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
40
|
+
}
|
|
41
|
+
/** Undefined when the text is not base64url. */
|
|
42
|
+
function fromBase64Url(text) {
|
|
43
|
+
if (!/^[A-Za-z0-9_-]*$/.test(text))
|
|
44
|
+
return undefined;
|
|
45
|
+
try {
|
|
46
|
+
const binary = atob(text.replace(/-/g, '+').replace(/_/g, '/'));
|
|
47
|
+
const bytes = new Uint8Array(binary.length);
|
|
48
|
+
for (let i = 0; i < binary.length; i++)
|
|
49
|
+
bytes[i] = binary.charCodeAt(i);
|
|
50
|
+
return bytes;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const isText = (value) => 'string' === typeof value && 0 < value.length && value.length <= MAX_FIELD_LENGTH;
|
|
57
|
+
function readPayload(part) {
|
|
58
|
+
const bytes = fromBase64Url(part);
|
|
59
|
+
if (bytes === undefined)
|
|
60
|
+
return undefined;
|
|
61
|
+
let value;
|
|
62
|
+
try {
|
|
63
|
+
value = JSON.parse(new TextDecoder().decode(bytes));
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
if (typeof value !== 'object' || null === value)
|
|
69
|
+
return undefined;
|
|
70
|
+
const p = value;
|
|
71
|
+
const scope = Object.values(HelloScope).find((s) => s === p.scope);
|
|
72
|
+
if (p.v !== ACTIVATION_TICKET_VERSION ||
|
|
73
|
+
!isText(p.nonce) ||
|
|
74
|
+
!isText(p.origin) ||
|
|
75
|
+
!isText(p.bridge) ||
|
|
76
|
+
scope === undefined ||
|
|
77
|
+
typeof p.exp !== 'number' ||
|
|
78
|
+
!Number.isFinite(p.exp)) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
v: ACTIVATION_TICKET_VERSION,
|
|
83
|
+
nonce: p.nonce,
|
|
84
|
+
origin: p.origin,
|
|
85
|
+
bridge: p.bridge,
|
|
86
|
+
scope,
|
|
87
|
+
exp: p.exp,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function secureBridge(bridge) {
|
|
91
|
+
try {
|
|
92
|
+
const url = new URL(bridge);
|
|
93
|
+
if (url.protocol === WSS_PROTOCOL)
|
|
94
|
+
return true;
|
|
95
|
+
return url.protocol === WS_PROTOCOL && isLoopbackHostname(url.hostname);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async function signatureVerifies(subtle, publicKey, signature, signed) {
|
|
102
|
+
const raw = fromBase64Url(publicKey);
|
|
103
|
+
if (raw === undefined)
|
|
104
|
+
return false;
|
|
105
|
+
try {
|
|
106
|
+
const key = await subtle.importKey(RAW_KEY_FORMAT, raw, { name: ED25519 }, false, ['verify']);
|
|
107
|
+
return await subtle.verify({ name: ED25519 }, key, signature, signed);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// A malformed key, or a browser with no Ed25519. Both mean: do not activate.
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Check a ticket against the service's public key (base64url, raw 32 bytes), the page origin and
|
|
116
|
+
* the clock. Never throws.
|
|
117
|
+
*/
|
|
118
|
+
export async function verifyActivationTicket(ticket, options) {
|
|
119
|
+
const parts = ticket.length <= MAX_TICKET_LENGTH ? ticket.split(TICKET_SEPARATOR) : [];
|
|
120
|
+
const [payloadPart, signaturePart] = parts;
|
|
121
|
+
const payload = 2 === parts.length && payloadPart !== undefined ? readPayload(payloadPart) : undefined;
|
|
122
|
+
const signature = signaturePart === undefined ? undefined : fromBase64Url(signaturePart);
|
|
123
|
+
if (payload === undefined || signature === undefined || payloadPart === undefined) {
|
|
124
|
+
return { ok: false, reason: ActivationRefusal.MALFORMED };
|
|
125
|
+
}
|
|
126
|
+
const subtle = options.subtle ?? globalThis.crypto.subtle;
|
|
127
|
+
const signed = new TextEncoder().encode(payloadPart);
|
|
128
|
+
if (!(await signatureVerifies(subtle, options.publicKey, signature, signed))) {
|
|
129
|
+
return { ok: false, reason: ActivationRefusal.BAD_SIGNATURE };
|
|
130
|
+
}
|
|
131
|
+
if (payload.exp <= options.now)
|
|
132
|
+
return { ok: false, reason: ActivationRefusal.EXPIRED };
|
|
133
|
+
if (payload.origin !== options.origin)
|
|
134
|
+
return { ok: false, reason: ActivationRefusal.WRONG_ORIGIN };
|
|
135
|
+
if (!secureBridge(payload.bridge))
|
|
136
|
+
return { ok: false, reason: ActivationRefusal.INSECURE_BRIDGE };
|
|
137
|
+
return { ok: true, payload };
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Mint a ticket. For the service only: it holds the Ed25519 private key, and the key never leaves
|
|
141
|
+
* it. Import a PKCS#8 key with `crypto.subtle.importKey('pkcs8', der, { name: 'Ed25519' }, false,
|
|
142
|
+
* ['sign'])`.
|
|
143
|
+
*/
|
|
144
|
+
export async function signActivationTicket(privateKey, payload, subtle = globalThis.crypto.subtle) {
|
|
145
|
+
const payloadPart = toBase64Url(new TextEncoder().encode(JSON.stringify(payload)));
|
|
146
|
+
const signature = await subtle.sign({ name: ED25519 }, privateKey, new TextEncoder().encode(payloadPart));
|
|
147
|
+
return `${payloadPart}${TICKET_SEPARATOR}${toBase64Url(new Uint8Array(signature))}`;
|
|
148
|
+
}
|