@halonicjs/testing 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
- package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
- package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
- package/dist/adapters/integration-kit/src/index.d.ts +2 -1
- package/dist/adapters/integration-kit/src/index.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +2 -12
- package/dist/adapters/integration-kit/src/loader.js +3 -20
- package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
- package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
- package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
- package/dist/core/events/src/connector-listing-failed.js +1 -0
- package/dist/core/events/src/home-path.d.ts +4 -1
- package/dist/core/events/src/home-path.js +14 -3
- package/dist/core/events/src/index.d.ts +4 -2
- package/dist/core/events/src/index.js +2 -0
- package/dist/core/events/src/provider-notes.d.ts +16 -0
- package/dist/core/events/src/provider-notes.js +24 -0
- package/dist/core/events/src/run-basics.d.ts +103 -5
- package/dist/core/events/src/run-event.d.ts +72 -7
- package/dist/core/events/src/run-summary.d.ts +11 -1
- package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
- package/dist/core/events/src/sandbox-opened-read.js +27 -2
- package/dist/core/events/src/sandbox-opened.d.ts +37 -4
- package/dist/core/events/src/sandbox-opened.js +13 -3
- package/dist/core/events/src/summarize.js +3 -0
- package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
- package/dist/core/events/src/tool-failure-cause.js +66 -0
- package/dist/core/format/src/index.d.ts +3 -2
- package/dist/core/format/src/index.js +3 -1
- package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
- package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
- package/dist/core/format/src/kinds/agent/schema.js +3 -0
- package/dist/core/format/src/kinds/connector/kind.js +24 -3
- package/dist/core/format/src/kinds/connector/schema.d.ts +14 -0
- package/dist/core/format/src/kinds/connector/schema.js +18 -0
- package/dist/core/format/src/kinds/integration/schema.js +1 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +2 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +33 -3
- package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
- package/dist/core/format/src/kinds/plugin/checks.js +17 -5
- package/dist/core/format/src/kinds/plugin/schema.js +24 -4
- package/dist/core/format/src/kinds/provider/kind.js +40 -1
- package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
- package/dist/core/format/src/kinds/provider/types.js +22 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +10 -5
- package/dist/core/format/src/kinds/routine/schema.js +21 -15
- package/dist/core/format/src/kinds/workspace/schema.js +5 -4
- package/dist/core/format/src/parse-file.js +3 -1
- package/dist/core/format/src/shared/fields.d.ts +9 -2
- package/dist/core/format/src/shared/fields.js +15 -6
- package/dist/core/format/src/shared/guard.d.ts +8 -0
- package/dist/core/format/src/shared/guard.js +50 -1
- package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
- package/dist/core/format/src/shared/missing-keys.js +110 -0
- package/dist/core/ports/src/chat.d.ts +8 -0
- package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
- package/dist/core/ports/src/connector-start-failure.js +32 -0
- package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
- package/dist/core/ports/src/connector-tool-error.js +40 -0
- package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
- package/dist/core/ports/src/definition-store-left-out.js +47 -0
- package/dist/core/ports/src/definition-store.d.ts +13 -3
- package/dist/core/ports/src/definition-store.js +1 -1
- package/dist/core/ports/src/deploy-target.d.ts +358 -0
- package/dist/core/ports/src/deploy-target.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +55 -4
- package/dist/core/ports/src/harness.d.ts +33 -2
- package/dist/core/ports/src/host-too-old.d.ts +23 -0
- package/dist/core/ports/src/host-too-old.js +27 -0
- package/dist/core/ports/src/index.d.ts +16 -5
- package/dist/core/ports/src/index.js +15 -3
- package/dist/core/ports/src/llm-provider.d.ts +37 -6
- package/dist/core/ports/src/llm-provider.js +43 -3
- package/dist/core/ports/src/pairing-codes.d.ts +111 -0
- package/dist/core/ports/src/pairing-codes.js +336 -0
- package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
- package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
- package/dist/core/ports/src/port-versions.d.ts +6 -2
- package/dist/core/ports/src/port-versions.js +8 -0
- package/dist/core/ports/src/remote-control.d.ts +159 -0
- package/dist/core/ports/src/remote-control.js +26 -0
- package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
- package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
- package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
- package/dist/core/ports/src/remote-gateway-session.js +241 -0
- package/dist/core/ports/src/run-executor.d.ts +39 -3
- package/dist/core/ports/src/run-executor.js +1 -1
- package/dist/core/ports/src/sandbox.d.ts +19 -0
- package/dist/core/ports/src/sandbox.js +14 -0
- package/dist/core/ports/src/secrets.d.ts +32 -1
- package/dist/core/ports/src/secrets.js +19 -2
- package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
- package/dist/core/ports/src/tunnel-provider.js +65 -0
- package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
- package/dist/core/ports/src/tunnel-resolver.js +36 -0
- package/dist/core/ports/src/vcs.d.ts +30 -0
- package/dist/core/schema-kit/src/builders.d.ts +5 -0
- package/dist/core/schema-kit/src/builders.js +5 -0
- package/dist/core/std/src/hidden-characters.d.ts +9 -0
- package/dist/core/std/src/hidden-characters.js +18 -0
- package/dist/core/std/src/index.d.ts +3 -1
- package/dist/core/std/src/index.js +3 -1
- package/dist/core/std/src/path-overlap.d.ts +22 -0
- package/dist/core/std/src/path-overlap.js +57 -0
- package/dist/core/std/src/public-suffixes.generated.d.ts +1 -1
- package/dist/core/std/src/public-suffixes.generated.js +0 -1
- package/dist/core/std/src/word-diff.d.ts +28 -0
- package/dist/core/std/src/word-diff.js +77 -0
- package/dist/core/yaml/src/edit-data.d.ts +7 -0
- package/dist/core/yaml/src/edit-data.js +62 -3
- package/dist/core/yaml/src/edit.d.ts +7 -0
- package/dist/core/yaml/src/edit.js +34 -3
- package/dist/core/yaml/src/splice-node.d.ts +6 -0
- package/dist/core/yaml/src/splice-node.js +10 -0
- package/dist/core/yaml/src/splice.js +20 -10
- package/dist/testing/integration/src/checks.d.ts +5 -3
- package/dist/testing/integration/src/checks.js +31 -3
- package/package.json +9 -2
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { TunnelReason, TunnelStatus } from "./tunnel-provider.js";
|
|
2
|
+
/** Version of the {@link RemoteControl} port. A breaking change bumps it and comes with an ADR. */
|
|
3
|
+
export declare const remoteControlVersion = 1;
|
|
4
|
+
/** The platforms a paired phone can report. */
|
|
5
|
+
export declare const phonePlatforms: readonly ["android", "ios"];
|
|
6
|
+
/** One of {@link phonePlatforms}. */
|
|
7
|
+
export type PhonePlatform = (typeof phonePlatforms)[number];
|
|
8
|
+
/** A phone this computer has paired. Only public data: the host keeps no secret of the phone's. */
|
|
9
|
+
export interface PairedPhone {
|
|
10
|
+
/** The device id: a hash of the phone's public key, stable for as long as it stays paired. */
|
|
11
|
+
readonly id: string;
|
|
12
|
+
/** The name the phone gave, with " (2)", " (3)" and so on when another paired phone has it already. */
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly platform: PhonePlatform;
|
|
15
|
+
/** When Allow was pressed, as an ISO 8601 time. */
|
|
16
|
+
readonly pairedAt: string;
|
|
17
|
+
/** When its last session ended, refreshed about once a minute while one is open; absent before the first ends. */
|
|
18
|
+
readonly lastSeenAt?: string;
|
|
19
|
+
/** Whether a session with it is open now. */
|
|
20
|
+
readonly connected: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** What Settings › Remote and the status bar show, as one snapshot. */
|
|
23
|
+
export interface RemoteState {
|
|
24
|
+
/**
|
|
25
|
+
* Whether this host offers remote at all. While it is `false`, Studio shows
|
|
26
|
+
* no Remote section, and `setRemote(true)` and `startPairing` reject.
|
|
27
|
+
*/
|
|
28
|
+
readonly available: boolean;
|
|
29
|
+
/** Whether the person turned remote on. Phones stay paired while it is off. */
|
|
30
|
+
readonly on: boolean;
|
|
31
|
+
/** The tunnel provider's id, such as "tailscale", so Studio can word its reasons. */
|
|
32
|
+
readonly tunnelProviderId: string;
|
|
33
|
+
/** The tunnel's state and reason; `down` with `stopped` while remote is off. */
|
|
34
|
+
readonly tunnel: TunnelStatus;
|
|
35
|
+
/** "Let phones answer risky approvals": off by default, and settable while remote is off. */
|
|
36
|
+
readonly allowRiskyRemotely: boolean;
|
|
37
|
+
/** The paired phones, oldest pairing first. */
|
|
38
|
+
readonly phones: readonly PairedPhone[];
|
|
39
|
+
/** Whether a pairing is open now; there is at most one at a time. */
|
|
40
|
+
readonly pairing: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Why a code stopped working while its pairing stays open, waiting for `newCode` or `close`. */
|
|
43
|
+
export declare const codeEndReasons: readonly [
|
|
44
|
+
/** Pressed Don't allow. */
|
|
45
|
+
"denied",
|
|
46
|
+
/** Allow wasn't pressed within the wait. */
|
|
47
|
+
"allow-timed-out",
|
|
48
|
+
/** No phone came within the code's life. */
|
|
49
|
+
"code-expired",
|
|
50
|
+
/** The code took its last wrong try. */
|
|
51
|
+
"too-many-tries"];
|
|
52
|
+
/** One of {@link codeEndReasons}. */
|
|
53
|
+
export type CodeEndReason = (typeof codeEndReasons)[number];
|
|
54
|
+
/** Why a pairing ended without a phone. */
|
|
55
|
+
export declare const pairingEndReasons: readonly [
|
|
56
|
+
/** The dialog was closed, or `close` was called. */
|
|
57
|
+
"closed",
|
|
58
|
+
/** Remote was turned off. */
|
|
59
|
+
"remote-off",
|
|
60
|
+
/** The tunnel didn't come up or went down; the event says why. */
|
|
61
|
+
"tunnel-down",
|
|
62
|
+
/** Another pairing is already open. */
|
|
63
|
+
"busy"];
|
|
64
|
+
/** One of {@link pairingEndReasons}. */
|
|
65
|
+
export type PairingEndReason = (typeof pairingEndReasons)[number];
|
|
66
|
+
/**
|
|
67
|
+
* One step of a pairing. It starts with `code` (unless it ends at once),
|
|
68
|
+
* then `check` once a phone has used the code. A code that stops working
|
|
69
|
+
* gives `code-ended`, and the pairing stays open: `newCode` gives a new
|
|
70
|
+
* `code`. The pairing ends with exactly one of `paired` or `ended`.
|
|
71
|
+
*/
|
|
72
|
+
export type PairingEvent = {
|
|
73
|
+
/** Show this code and QR code; waiting for a phone. */
|
|
74
|
+
readonly type: "code";
|
|
75
|
+
/** The pairing code, in its plain 12-symbol form. */
|
|
76
|
+
readonly code: string;
|
|
77
|
+
/** The QR code's text, `halonic-pair:…`. */
|
|
78
|
+
readonly qr: string;
|
|
79
|
+
/** The name this computer gives itself, for "choose Tim's laptop". */
|
|
80
|
+
readonly hostName: string;
|
|
81
|
+
/** When the code stops working, as an ISO 8601 time. */
|
|
82
|
+
readonly expiresAt: string;
|
|
83
|
+
} | {
|
|
84
|
+
/** A phone used the code: show the check code and wait for Allow. */
|
|
85
|
+
readonly type: "check";
|
|
86
|
+
/** The check code, in its plain 6-symbol form. */
|
|
87
|
+
readonly checkCode: string;
|
|
88
|
+
readonly phoneName: string;
|
|
89
|
+
readonly platform: PhonePlatform;
|
|
90
|
+
/** When the wait for Allow ends, as an ISO 8601 time. */
|
|
91
|
+
readonly allowBy: string;
|
|
92
|
+
} | {
|
|
93
|
+
/** The code stopped working; the pairing waits for `newCode` or `close`. */
|
|
94
|
+
readonly type: "code-ended";
|
|
95
|
+
readonly reason: CodeEndReason;
|
|
96
|
+
} | {
|
|
97
|
+
readonly type: "paired";
|
|
98
|
+
readonly phone: PairedPhone;
|
|
99
|
+
} | {
|
|
100
|
+
readonly type: "ended";
|
|
101
|
+
readonly reason: Exclude<PairingEndReason, "tunnel-down">;
|
|
102
|
+
} | {
|
|
103
|
+
readonly type: "ended";
|
|
104
|
+
readonly reason: "tunnel-down";
|
|
105
|
+
/** Why, as the tunnel said it; remote may be off again by the time Studio shows it. */
|
|
106
|
+
readonly tunnelReason: TunnelReason;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* One open pairing, as the Pair a phone dialog drives it: one session for as
|
|
110
|
+
* long as the dialog is open, however many codes it shows (design decision 10).
|
|
111
|
+
*/
|
|
112
|
+
export interface PairingSession {
|
|
113
|
+
/**
|
|
114
|
+
* Every event so far, then each new one; the stream ends after `paired`
|
|
115
|
+
* or `ended`. Each call gives a new stream.
|
|
116
|
+
*/
|
|
117
|
+
events(): AsyncIterable<PairingEvent>;
|
|
118
|
+
/** Pairs the phone. Rejects unless the last event is `check`. */
|
|
119
|
+
allow(): Promise<void>;
|
|
120
|
+
/** Refuses the phone: the code ends with `denied`. Rejects unless the last event is `check`. */
|
|
121
|
+
deny(): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Ends the current code, if it still works, without a `code-ended`, and
|
|
124
|
+
* gives a new `code` on this session. A phone waiting at `check` is
|
|
125
|
+
* refused. Remote stays on. Rejects once the pairing has ended.
|
|
126
|
+
*/
|
|
127
|
+
newCode(): Promise<void>;
|
|
128
|
+
/** Ends the pairing with `closed`. Does nothing once it has ended. */
|
|
129
|
+
close(): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* How Studio turns remote on and off, pairs and revokes phones and sets the
|
|
133
|
+
* risky-approvals switch, on loopback to the host (requirement
|
|
134
|
+
* `ports.remote-control`). The host does the work and keeps the rules
|
|
135
|
+
* (ADR "Pairing and the end-to-end session"); Studio only shows and asks.
|
|
136
|
+
*
|
|
137
|
+
* `startPairing` turns remote on when it was off, and a pairing that ends
|
|
138
|
+
* without a phone turns it off again if it did so and no phone is paired.
|
|
139
|
+
* A code that stops working doesn't end its pairing, so a new code never
|
|
140
|
+
* restarts the tunnel.
|
|
141
|
+
* Revoking a phone closes its session at once; its agents keep running.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const pairing = await remote.startPairing();
|
|
145
|
+
* for await (const event of pairing.events()) dialog.show(event);
|
|
146
|
+
*/
|
|
147
|
+
export interface RemoteControl {
|
|
148
|
+
/** The current state first, then every change. Each call gives a new stream. */
|
|
149
|
+
state(): AsyncIterable<RemoteState>;
|
|
150
|
+
/** Turns remote on or off. Turning it off ends an open pairing with `remote-off`. */
|
|
151
|
+
setRemote(on: boolean): Promise<void>;
|
|
152
|
+
/** Opens a pairing; a second one while one is open ends at once with `busy`. */
|
|
153
|
+
startPairing(): Promise<PairingSession>;
|
|
154
|
+
/** Unpairs one phone. An id that isn't paired does nothing. */
|
|
155
|
+
revoke(phoneId: string): Promise<void>;
|
|
156
|
+
/** Unpairs every phone. */
|
|
157
|
+
revokeAll(): Promise<void>;
|
|
158
|
+
setAllowRiskyRemotely(allow: boolean): Promise<void>;
|
|
159
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Version of the {@link RemoteControl} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
+
export const remoteControlVersion = 1;
|
|
3
|
+
/** The platforms a paired phone can report. */
|
|
4
|
+
export const phonePlatforms = ["android", "ios"];
|
|
5
|
+
/** Why a code stopped working while its pairing stays open, waiting for `newCode` or `close`. */
|
|
6
|
+
export const codeEndReasons = [
|
|
7
|
+
/** Pressed Don't allow. */
|
|
8
|
+
"denied",
|
|
9
|
+
/** Allow wasn't pressed within the wait. */
|
|
10
|
+
"allow-timed-out",
|
|
11
|
+
/** No phone came within the code's life. */
|
|
12
|
+
"code-expired",
|
|
13
|
+
/** The code took its last wrong try. */
|
|
14
|
+
"too-many-tries",
|
|
15
|
+
];
|
|
16
|
+
/** Why a pairing ended without a phone. */
|
|
17
|
+
export const pairingEndReasons = [
|
|
18
|
+
/** The dialog was closed, or `close` was called. */
|
|
19
|
+
"closed",
|
|
20
|
+
/** Remote was turned off. */
|
|
21
|
+
"remote-off",
|
|
22
|
+
/** The tunnel didn't come up or went down; the event says why. */
|
|
23
|
+
"tunnel-down",
|
|
24
|
+
/** Another pairing is already open. */
|
|
25
|
+
"busy",
|
|
26
|
+
];
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The remote gateway protocol: what a phone and the desktop host's remote
|
|
3
|
+
* gateway say to each other, inside the end-to-end session (requirement
|
|
4
|
+
* `ports.remote-gateway-protocol`). It covers sessions, their events,
|
|
5
|
+
* approvals and prompt input, the end of a pairing, and nothing else. Each
|
|
6
|
+
* message is one JSON object in one Noise transport message; nothing here is
|
|
7
|
+
* ever sent in cleartext. The session around it is in
|
|
8
|
+
* `remote-gateway-session.ts` (ADR "Pairing and the end-to-end session").
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The protocol version. Both sides send it in `hello` and `welcome`, and the
|
|
12
|
+
* Noise prologue names it too, so a peer of another version fails the
|
|
13
|
+
* handshake. A host speaks exactly one and there is no negotiation. The host
|
|
14
|
+
* answers a `hello` with another version with `unsupported-version` and
|
|
15
|
+
* closes; the phone closes on a `welcome` with another version.
|
|
16
|
+
*/
|
|
17
|
+
export declare const gatewayProtocolVersion = 2;
|
|
18
|
+
/**
|
|
19
|
+
* The largest message either side accepts, in bytes of its UTF-8 JSON: one
|
|
20
|
+
* Noise transport message (65,535 bytes) less its 16-byte tag. A larger one is
|
|
21
|
+
* refused: the host sends `error` with `too-large` and closes. The host checks
|
|
22
|
+
* the size before it parses.
|
|
23
|
+
*/
|
|
24
|
+
export declare const gatewayMaxMessageBytes: number;
|
|
25
|
+
/**
|
|
26
|
+
* The longest prompt text, in UTF-16 code units. It is set from the worst
|
|
27
|
+
* case: JSON writes a control character or a lone surrogate as six bytes, so
|
|
28
|
+
* 10,000 of them take 60,000 bytes and still fit in one message with the
|
|
29
|
+
* envelope. A prompt within this length never gets `too-large`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const gatewayMaxPromptLength = 10000;
|
|
32
|
+
/**
|
|
33
|
+
* The longest id, the phone's or the host's. Every id is 1 to this many
|
|
34
|
+
* characters from `A`–`Z`, `a`–`z`, `0`–`9`, `_` and `-`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const gatewayMaxIdLength = 128;
|
|
37
|
+
/**
|
|
38
|
+
* The most sessions one connection may watch at once. A `watch` for one more
|
|
39
|
+
* gets `too-many-watches` and leaves the connection open.
|
|
40
|
+
*/
|
|
41
|
+
export declare const gatewayMaxWatches = 16;
|
|
42
|
+
/**
|
|
43
|
+
* The most bytes the host holds unsent for one connection. A phone that
|
|
44
|
+
* reads more slowly than its sessions produce events is closed when this is
|
|
45
|
+
* exceeded, never buffered without limit; it resumes by watching again.
|
|
46
|
+
*/
|
|
47
|
+
export declare const gatewayMaxBufferedBytes: number;
|
|
48
|
+
/** A session as the phone lists it. `waiting` means an approval waits for an answer. */
|
|
49
|
+
export interface GatewaySession {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly title: string;
|
|
52
|
+
readonly state: "running" | "waiting" | "done" | "failed";
|
|
53
|
+
/** The sequence number of the session's newest event. */
|
|
54
|
+
readonly lastSeq: number;
|
|
55
|
+
readonly updatedAt: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* An approval the phone may show. Only the host sets `risk`; the phone's
|
|
59
|
+
* answer carries none. A `risky` approval (a shell command, a file write, a
|
|
60
|
+
* secret, leaving the sandbox) is refused by default: every answer to it
|
|
61
|
+
* gets `not-allowed-remotely` unless the person has allowed remote answers
|
|
62
|
+
* to risky approvals for this host on the desktop. The phone asks for a
|
|
63
|
+
* biometric unlock before it sends one, but the host can't check that and
|
|
64
|
+
* never treats it as proof.
|
|
65
|
+
*/
|
|
66
|
+
export interface GatewayApproval {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly summary: string;
|
|
69
|
+
readonly risk: "normal" | "risky";
|
|
70
|
+
/** The connector the tool comes from, when it comes from one, so the phone can say which connector asks. */
|
|
71
|
+
readonly connector?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* What happened in a session, as narrow as the phone needs. The host shortens
|
|
75
|
+
* a `message` text that would make its event larger than
|
|
76
|
+
* {@link gatewayMaxMessageBytes} and ends it with "…"; the full text stays on
|
|
77
|
+
* the desktop.
|
|
78
|
+
*/
|
|
79
|
+
export type GatewayEventBody = {
|
|
80
|
+
readonly type: "message";
|
|
81
|
+
readonly role: "user" | "agent";
|
|
82
|
+
readonly text: string;
|
|
83
|
+
} | {
|
|
84
|
+
readonly type: "state";
|
|
85
|
+
readonly state: GatewaySession["state"];
|
|
86
|
+
} | {
|
|
87
|
+
readonly type: "approval-requested";
|
|
88
|
+
readonly approval: GatewayApproval;
|
|
89
|
+
} | {
|
|
90
|
+
readonly type: "approval-settled";
|
|
91
|
+
readonly approvalId: string;
|
|
92
|
+
readonly decision: "approve" | "deny";
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Why the host refused a message and closed the connection. Such an `error`
|
|
96
|
+
* has no `replyTo`, since the message it answers may not have parsed.
|
|
97
|
+
*/
|
|
98
|
+
export declare const gatewayClosingErrorCodes: readonly ["malformed", "too-large", "unsupported-version"];
|
|
99
|
+
/** Why the host refused a well-formed message and kept the connection open. */
|
|
100
|
+
export declare const gatewayRefusalCodes: readonly ["unknown-session", "unknown-approval", "not-allowed-remotely", "history-gone", "too-many-watches"];
|
|
101
|
+
/** Every error code, closing ones first. Studio words each code. */
|
|
102
|
+
export declare const gatewayErrorCodes: readonly ["malformed", "too-large", "unsupported-version", "unknown-session", "unknown-approval", "not-allowed-remotely", "history-gone", "too-many-watches"];
|
|
103
|
+
/** One of {@link gatewayErrorCodes}. */
|
|
104
|
+
export type GatewayErrorCode = (typeof gatewayErrorCodes)[number];
|
|
105
|
+
/**
|
|
106
|
+
* What the phone sends. `id` is the phone's own id for the message; the
|
|
107
|
+
* host's `ok` or refusal names it in `replyTo`.
|
|
108
|
+
*
|
|
109
|
+
* - `hello` comes first on every connection, also after a reconnect, and
|
|
110
|
+
* only once.
|
|
111
|
+
* - `watch` streams a session's events after `afterSeq`, then each new one.
|
|
112
|
+
* `afterSeq` 0 starts from the oldest event the host keeps; the host keeps
|
|
113
|
+
* every event from the oldest `approval-requested` that isn't settled.
|
|
114
|
+
* A `watch` for a session already watched replaces that watch.
|
|
115
|
+
* - **Resume.** Each session's `seq` starts at 1 and grows by one per event,
|
|
116
|
+
* never reused. After a reconnect the phone watches again from the last
|
|
117
|
+
* `seq` it saw. An `afterSeq` above the session's `lastSeq` is `malformed`.
|
|
118
|
+
* When the events after `afterSeq` are gone, the host answers
|
|
119
|
+
* `history-gone`. On `history-gone`, or a gap in `seq` within a watch, the
|
|
120
|
+
* phone drops what it holds for the session and watches from 0. It shows
|
|
121
|
+
* an approval only from an `approval-requested` event not followed by its
|
|
122
|
+
* `approval-settled`; an answer to a settled or unknown approval gets
|
|
123
|
+
* `unknown-approval`.
|
|
124
|
+
*/
|
|
125
|
+
export type GatewayClientMessage = {
|
|
126
|
+
readonly type: "hello";
|
|
127
|
+
readonly id: string;
|
|
128
|
+
readonly version: number;
|
|
129
|
+
} | {
|
|
130
|
+
readonly type: "list-sessions";
|
|
131
|
+
readonly id: string;
|
|
132
|
+
} | {
|
|
133
|
+
readonly type: "watch";
|
|
134
|
+
readonly id: string;
|
|
135
|
+
readonly sessionId: string;
|
|
136
|
+
readonly afterSeq: number;
|
|
137
|
+
} | {
|
|
138
|
+
readonly type: "unwatch";
|
|
139
|
+
readonly id: string;
|
|
140
|
+
readonly sessionId: string;
|
|
141
|
+
} | {
|
|
142
|
+
readonly type: "answer-approval";
|
|
143
|
+
readonly id: string;
|
|
144
|
+
readonly sessionId: string;
|
|
145
|
+
readonly approvalId: string;
|
|
146
|
+
readonly decision: "approve" | "deny";
|
|
147
|
+
} | {
|
|
148
|
+
readonly type: "prompt";
|
|
149
|
+
readonly id: string;
|
|
150
|
+
readonly sessionId: string;
|
|
151
|
+
readonly text: string;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Why the host ended a pairing after the phone's message 3 decrypted: the
|
|
155
|
+
* person pressed Don't allow, or didn't press Allow in time. Refusals before
|
|
156
|
+
* that are cleartext frames (`PairRefusedReason` in `remote-gateway-session.ts`).
|
|
157
|
+
*/
|
|
158
|
+
export type GatewayPairDeniedReason = "denied" | "timed-out";
|
|
159
|
+
/**
|
|
160
|
+
* What the host sends.
|
|
161
|
+
*
|
|
162
|
+
* **Pairing and reconnecting.** At the end of a pairing the host sends
|
|
163
|
+
* `paired` once the person pressed Allow, or `pair-refused` and closes; the
|
|
164
|
+
* phone sends nothing before either. After a reconnect the host sends
|
|
165
|
+
* `not-paired` and closes when it doesn't know the phone's key; it sends it
|
|
166
|
+
* only after its handshake message has proved who it is, and also at once
|
|
167
|
+
* when the phone is revoked while connected. Then, and after `paired`, the
|
|
168
|
+
* phone's first message is `hello`.
|
|
169
|
+
*
|
|
170
|
+
* **Error and close.** The host sends one `error` with a code from
|
|
171
|
+
* {@link gatewayClosingErrorCodes}, without `replyTo`, then closes the
|
|
172
|
+
* connection, for:
|
|
173
|
+
* - `too-large`: more than {@link gatewayMaxMessageBytes} bytes;
|
|
174
|
+
* - `unsupported-version`: a `hello` whose `version` isn't
|
|
175
|
+
* {@link gatewayProtocolVersion};
|
|
176
|
+
* - `malformed`: anything else that isn't exactly one listed message. That is
|
|
177
|
+
* bytes that aren't valid UTF-8, text that isn't one JSON object, an
|
|
178
|
+
* unlisted `type`, a missing, extra or wrongly typed field, an id that
|
|
179
|
+
* breaks {@link gatewayMaxIdLength}, an `afterSeq` that isn't a whole number
|
|
180
|
+
* from 0 up to the session's `lastSeq`, a prompt `text` that is empty or
|
|
181
|
+
* longer than {@link gatewayMaxPromptLength}, any message before `hello`,
|
|
182
|
+
* and a second `hello`.
|
|
183
|
+
*
|
|
184
|
+
* A well-formed message the host won't carry out gets an `error` with a code
|
|
185
|
+
* from {@link gatewayRefusalCodes} and its `replyTo`, and the connection
|
|
186
|
+
* stays open.
|
|
187
|
+
*/
|
|
188
|
+
export type GatewayHostMessage = {
|
|
189
|
+
readonly type: "welcome";
|
|
190
|
+
readonly replyTo: string;
|
|
191
|
+
readonly version: number;
|
|
192
|
+
readonly maxMessageBytes: number;
|
|
193
|
+
} | {
|
|
194
|
+
readonly type: "sessions";
|
|
195
|
+
readonly replyTo: string;
|
|
196
|
+
readonly sessions: readonly GatewaySession[];
|
|
197
|
+
} | {
|
|
198
|
+
readonly type: "event";
|
|
199
|
+
readonly sessionId: string;
|
|
200
|
+
readonly seq: number;
|
|
201
|
+
readonly at: string;
|
|
202
|
+
readonly body: GatewayEventBody;
|
|
203
|
+
} | {
|
|
204
|
+
readonly type: "ok";
|
|
205
|
+
readonly replyTo: string;
|
|
206
|
+
} | {
|
|
207
|
+
readonly type: "paired";
|
|
208
|
+
} | {
|
|
209
|
+
readonly type: "pair-refused";
|
|
210
|
+
readonly reason: GatewayPairDeniedReason;
|
|
211
|
+
} | {
|
|
212
|
+
readonly type: "not-paired";
|
|
213
|
+
} | {
|
|
214
|
+
readonly type: "error";
|
|
215
|
+
readonly code: (typeof gatewayClosingErrorCodes)[number];
|
|
216
|
+
} | {
|
|
217
|
+
readonly type: "error";
|
|
218
|
+
readonly replyTo: string;
|
|
219
|
+
readonly code: (typeof gatewayRefusalCodes)[number];
|
|
220
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The remote gateway protocol: what a phone and the desktop host's remote
|
|
3
|
+
* gateway say to each other, inside the end-to-end session (requirement
|
|
4
|
+
* `ports.remote-gateway-protocol`). It covers sessions, their events,
|
|
5
|
+
* approvals and prompt input, the end of a pairing, and nothing else. Each
|
|
6
|
+
* message is one JSON object in one Noise transport message; nothing here is
|
|
7
|
+
* ever sent in cleartext. The session around it is in
|
|
8
|
+
* `remote-gateway-session.ts` (ADR "Pairing and the end-to-end session").
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The protocol version. Both sides send it in `hello` and `welcome`, and the
|
|
12
|
+
* Noise prologue names it too, so a peer of another version fails the
|
|
13
|
+
* handshake. A host speaks exactly one and there is no negotiation. The host
|
|
14
|
+
* answers a `hello` with another version with `unsupported-version` and
|
|
15
|
+
* closes; the phone closes on a `welcome` with another version.
|
|
16
|
+
*/
|
|
17
|
+
export const gatewayProtocolVersion = 2;
|
|
18
|
+
/**
|
|
19
|
+
* The largest message either side accepts, in bytes of its UTF-8 JSON: one
|
|
20
|
+
* Noise transport message (65,535 bytes) less its 16-byte tag. A larger one is
|
|
21
|
+
* refused: the host sends `error` with `too-large` and closes. The host checks
|
|
22
|
+
* the size before it parses.
|
|
23
|
+
*/
|
|
24
|
+
export const gatewayMaxMessageBytes = 65_535 - 16;
|
|
25
|
+
/**
|
|
26
|
+
* The longest prompt text, in UTF-16 code units. It is set from the worst
|
|
27
|
+
* case: JSON writes a control character or a lone surrogate as six bytes, so
|
|
28
|
+
* 10,000 of them take 60,000 bytes and still fit in one message with the
|
|
29
|
+
* envelope. A prompt within this length never gets `too-large`.
|
|
30
|
+
*/
|
|
31
|
+
export const gatewayMaxPromptLength = 10_000;
|
|
32
|
+
/**
|
|
33
|
+
* The longest id, the phone's or the host's. Every id is 1 to this many
|
|
34
|
+
* characters from `A`–`Z`, `a`–`z`, `0`–`9`, `_` and `-`.
|
|
35
|
+
*/
|
|
36
|
+
export const gatewayMaxIdLength = 128;
|
|
37
|
+
/**
|
|
38
|
+
* The most sessions one connection may watch at once. A `watch` for one more
|
|
39
|
+
* gets `too-many-watches` and leaves the connection open.
|
|
40
|
+
*/
|
|
41
|
+
export const gatewayMaxWatches = 16;
|
|
42
|
+
/**
|
|
43
|
+
* The most bytes the host holds unsent for one connection. A phone that
|
|
44
|
+
* reads more slowly than its sessions produce events is closed when this is
|
|
45
|
+
* exceeded, never buffered without limit; it resumes by watching again.
|
|
46
|
+
*/
|
|
47
|
+
export const gatewayMaxBufferedBytes = 1024 * 1024;
|
|
48
|
+
/**
|
|
49
|
+
* Why the host refused a message and closed the connection. Such an `error`
|
|
50
|
+
* has no `replyTo`, since the message it answers may not have parsed.
|
|
51
|
+
*/
|
|
52
|
+
export const gatewayClosingErrorCodes = ["malformed", "too-large", "unsupported-version"];
|
|
53
|
+
/** Why the host refused a well-formed message and kept the connection open. */
|
|
54
|
+
export const gatewayRefusalCodes = [
|
|
55
|
+
"unknown-session",
|
|
56
|
+
"unknown-approval",
|
|
57
|
+
"not-allowed-remotely",
|
|
58
|
+
"history-gone",
|
|
59
|
+
"too-many-watches",
|
|
60
|
+
];
|
|
61
|
+
/** Every error code, closing ones first. Studio words each code. */
|
|
62
|
+
export const gatewayErrorCodes = [...gatewayClosingErrorCodes, ...gatewayRefusalCodes];
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The end-to-end session around the remote gateway protocol: the Noise
|
|
3
|
+
* handshakes, the binary frames they travel in, the two cleartext refusals,
|
|
4
|
+
* and the limits and times both sides keep (requirement
|
|
5
|
+
* `ports.remote-gateway-session`, ADR "Pairing and the end-to-end session").
|
|
6
|
+
* No crypto is done here: a Noise library does it behind an adapter.
|
|
7
|
+
*/
|
|
8
|
+
/** The Noise handshake that pairs a new phone, on the QR and the typed route alike. */
|
|
9
|
+
export declare const gatewayPairingPattern = "Noise_XXpsk3_25519_ChaChaPoly_SHA256";
|
|
10
|
+
/** The Noise handshake a paired phone reconnects with, to the host key it pinned. */
|
|
11
|
+
export declare const gatewayReconnectPattern = "Noise_IK_25519_ChaChaPoly_SHA256";
|
|
12
|
+
/**
|
|
13
|
+
* The Noise prologue of both handshakes. It names the protocol version, so a
|
|
14
|
+
* peer of another version fails the handshake instead of negotiating.
|
|
15
|
+
*/
|
|
16
|
+
export declare const gatewayNoisePrologue = "halonic-gateway/2";
|
|
17
|
+
/**
|
|
18
|
+
* The first byte of every binary WebSocket frame, which says what follows.
|
|
19
|
+
*
|
|
20
|
+
* - `pair1` to `pair3` carry the three messages of the pairing handshake,
|
|
21
|
+
* `resume1` and `resume2` the two of the reconnect handshake.
|
|
22
|
+
* - `message` carries one Noise transport message holding one gateway message.
|
|
23
|
+
* - `rekey` carries an empty transport message, the sender's last under its
|
|
24
|
+
* old key: it rekeys its sending direction after it, and the reader rekeys
|
|
25
|
+
* its receiving direction after reading it.
|
|
26
|
+
* - `handshake-failed` and `pair-refused` are the only cleartext frames. They
|
|
27
|
+
* are informative: anyone on the path could fake one, and neither may make
|
|
28
|
+
* the phone clear anything.
|
|
29
|
+
*
|
|
30
|
+
* Any other first byte, a frame of a kind the other side doesn't send, a
|
|
31
|
+
* handshake frame out of order or a text frame closes the connection.
|
|
32
|
+
*/
|
|
33
|
+
export declare const gatewayFrameKinds: {
|
|
34
|
+
readonly pair1: 1;
|
|
35
|
+
readonly pair2: 2;
|
|
36
|
+
readonly pair3: 3;
|
|
37
|
+
readonly resume1: 17;
|
|
38
|
+
readonly resume2: 18;
|
|
39
|
+
readonly message: 32;
|
|
40
|
+
readonly rekey: 33;
|
|
41
|
+
readonly "handshake-failed": 48;
|
|
42
|
+
readonly "pair-refused": 49;
|
|
43
|
+
};
|
|
44
|
+
/** One of the names in {@link gatewayFrameKinds}. */
|
|
45
|
+
export type GatewayFrameKind = keyof typeof gatewayFrameKinds;
|
|
46
|
+
/** The largest Noise message, handshake or transport, by the Noise spec. */
|
|
47
|
+
export declare const noiseMaxMessageBytes = 65535;
|
|
48
|
+
/** The largest binary frame: a kind byte and one Noise message. */
|
|
49
|
+
export declare const gatewayMaxFrameBytes: number;
|
|
50
|
+
/**
|
|
51
|
+
* The largest handshake message, without its kind byte. The longest, pairing
|
|
52
|
+
* message 3, is 32 + 16 bytes of key and tag and a payload with a name of at
|
|
53
|
+
* most {@link gatewayMaxNameBytes} and a nonce, so a larger one is an attack.
|
|
54
|
+
*/
|
|
55
|
+
export declare const gatewayMaxHandshakeBytes = 1024;
|
|
56
|
+
/** The longest name in a handshake payload, the host's or the phone's, in bytes of UTF-8. */
|
|
57
|
+
export declare const gatewayMaxNameBytes = 64;
|
|
58
|
+
/**
|
|
59
|
+
* The payload of pairing message 1, from the phone, in cleartext: its
|
|
60
|
+
* commitment to message 3, the SHA-256 of {@link pairCommitInput}, in base64url
|
|
61
|
+
* without padding (43 characters). JSON, UTF-8. The host recomputes it once
|
|
62
|
+
* message 3 decrypts, and a mismatch is a wrong try, so an attacker who knows
|
|
63
|
+
* the code can't search for a message 3 that makes the check codes match.
|
|
64
|
+
*/
|
|
65
|
+
export interface PairCommitPayload {
|
|
66
|
+
readonly commit: string;
|
|
67
|
+
}
|
|
68
|
+
/** What the phone's commitment starts with, in ASCII: it names the use and its version. */
|
|
69
|
+
export declare const pairCommitLabel = "halonic pair commit v1";
|
|
70
|
+
/** The length of the fresh nonce in pairing message 3's payload, in bytes. */
|
|
71
|
+
export declare const pairCommitNonceBytes = 16;
|
|
72
|
+
/**
|
|
73
|
+
* The bytes the phone's commitment hashes: {@link pairCommitLabel} in ASCII,
|
|
74
|
+
* the phone's static public key, and the exact bytes of its message 3 payload.
|
|
75
|
+
* Throws a `RangeError` for a key that isn't 32 bytes. The hash itself is the
|
|
76
|
+
* adapter's, like every other primitive.
|
|
77
|
+
*/
|
|
78
|
+
export declare function pairCommitInput(phoneStaticKey: Uint8Array, payload3: Uint8Array): Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* The payload of pairing message 2, from the host, encrypted: the name the
|
|
81
|
+
* phone shows for it, as {@link gatewayHostName} gives it. JSON, UTF-8.
|
|
82
|
+
*/
|
|
83
|
+
export interface PairHostPayload {
|
|
84
|
+
readonly hostName: string;
|
|
85
|
+
}
|
|
86
|
+
/** The name a host sends when nothing of its own name is left to show. */
|
|
87
|
+
export declare const gatewayFallbackHostName = "Computer";
|
|
88
|
+
/**
|
|
89
|
+
* The host's own name as it sends it in pairing message 2, so the phone can
|
|
90
|
+
* read it: without the code points the phone refuses, without spaces at either
|
|
91
|
+
* end, and cut at a whole code point to {@link gatewayMaxNameBytes} bytes of
|
|
92
|
+
* UTF-8. A lone surrogate becomes U+FFFD, since JSON can't carry it as UTF-8.
|
|
93
|
+
* When nothing is left, it is {@link gatewayFallbackHostName}.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* gatewayHostName(`Desk${String.fromCodePoint(0x202e)}kseD`); // "DeskkseD"
|
|
97
|
+
* gatewayHostName("\n"); // "Computer"
|
|
98
|
+
*/
|
|
99
|
+
export declare function gatewayHostName(name: string): string;
|
|
100
|
+
/** The name a host shows and keeps for a phone when nothing of the phone's own name is left. */
|
|
101
|
+
export declare const gatewayFallbackPhoneName = "Phone";
|
|
102
|
+
/**
|
|
103
|
+
* A name one side sent, as the other may show it: cleaned by the rules of
|
|
104
|
+
* {@link gatewayHostName}, or `fallback` when nothing is left. The host
|
|
105
|
+
* cleans a phone's name from pairing message 3 this way, with
|
|
106
|
+
* {@link gatewayFallbackPhoneName}, before it shows it next to the check code.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* gatewayReadableName(`Pixel${String.fromCodePoint(0x202e)} 8`, gatewayFallbackPhoneName); // "Pixel 8"
|
|
110
|
+
*/
|
|
111
|
+
export declare function gatewayReadableName(name: string, fallback: string): string;
|
|
112
|
+
/**
|
|
113
|
+
* The payload of pairing message 3, from the phone, encrypted: the name and
|
|
114
|
+
* platform the host shows with the check code and keeps for the phone, and a
|
|
115
|
+
* fresh nonce of {@link pairCommitNonceBytes} bytes in base64url without
|
|
116
|
+
* padding (22 characters). The nonce makes message 3 unpredictable to anyone
|
|
117
|
+
* who sees the commitment, and keeps the commitment from linking a phone across
|
|
118
|
+
* pairings. JSON, UTF-8. The reconnect handshake's payloads are empty.
|
|
119
|
+
*/
|
|
120
|
+
export interface PairPhonePayload {
|
|
121
|
+
readonly name: string;
|
|
122
|
+
readonly platform: "android" | "ios";
|
|
123
|
+
readonly nonce: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The session's times and counts. A handshake not finished
|
|
127
|
+
* `handshakeTimeoutMs` after its first frame is closed. A sender sends a
|
|
128
|
+
* `rekey` frame at the latest `rekeyAfterMs` after its last one, or as its
|
|
129
|
+
* `rekeyAfterMessages`-th transport message since, whichever comes first; a
|
|
130
|
+
* reader closes the connection when one more message arrives without it. The
|
|
131
|
+
* host ends a session `sessionMaxMs` after its handshake, and the phone
|
|
132
|
+
* reconnects with IK.
|
|
133
|
+
*/
|
|
134
|
+
export declare const gatewaySessionLimits: {
|
|
135
|
+
readonly handshakeTimeoutMs: 10000;
|
|
136
|
+
readonly rekeyAfterMs: number;
|
|
137
|
+
readonly rekeyAfterMessages: 10000;
|
|
138
|
+
readonly sessionMaxMs: number;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* The host's pairing rules, kept in memory only (build plan decision 6). A
|
|
142
|
+
* code lives `codeLifetimeMs` and pairs at most one phone: the first pairing
|
|
143
|
+
* message 3 that decrypts with it uses it up. The host then waits
|
|
144
|
+
* `allowWaitMs` for Allow. A message 3 that doesn't decrypt, or whose
|
|
145
|
+
* commitment doesn't match, is a wrong try and doesn't use the code up. So is
|
|
146
|
+
* a pairing handshake the host answered with message 2 that closes, drops or
|
|
147
|
+
* times out before a message 3 that decrypts and matches, so a leaked code
|
|
148
|
+
* can't be tried against the host's check code for free.
|
|
149
|
+
* `wrongTriesPerCode` wrong tries end the code, and the host takes at most
|
|
150
|
+
* `failedTriesPerMinute` failed tries across all codes before it refuses
|
|
151
|
+
* pairing message 1 until the minute is over.
|
|
152
|
+
*/
|
|
153
|
+
export declare const pairingRules: {
|
|
154
|
+
readonly codeLifetimeMs: number;
|
|
155
|
+
readonly allowWaitMs: number;
|
|
156
|
+
readonly wrongTriesPerCode: 5;
|
|
157
|
+
readonly failedTriesPerMinute: 10;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Why the host refused a pairing before the phone's message 3 decrypted, in
|
|
161
|
+
* the order of the byte that encodes each.
|
|
162
|
+
*
|
|
163
|
+
* - `wrong-code`: message 3 didn't decrypt; `triesLeft` is 1 to 4.
|
|
164
|
+
* - `code-ended`: the code ran out, had its last wrong try, or its dialog was
|
|
165
|
+
* closed, or no pairing is open.
|
|
166
|
+
* - `code-used`: another phone's message 3 already used the code.
|
|
167
|
+
* - `rate-limited`: the host has had too many failed tries this minute.
|
|
168
|
+
*/
|
|
169
|
+
export declare const pairRefusedReasons: readonly ["wrong-code", "code-ended", "code-used", "rate-limited"];
|
|
170
|
+
/** One of {@link pairRefusedReasons}. */
|
|
171
|
+
export type PairRefusedReason = (typeof pairRefusedReasons)[number];
|
|
172
|
+
/**
|
|
173
|
+
* A cleartext frame. `triesLeft` is 0 for every reason but `wrong-code`.
|
|
174
|
+
* After either one the host closes the connection.
|
|
175
|
+
*/
|
|
176
|
+
export type GatewayCleartextFrame = {
|
|
177
|
+
readonly kind: "handshake-failed";
|
|
178
|
+
} | {
|
|
179
|
+
readonly kind: "pair-refused";
|
|
180
|
+
readonly reason: PairRefusedReason;
|
|
181
|
+
readonly triesLeft: number;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Writes a cleartext frame: one kind byte, and for `pair-refused` the index of
|
|
185
|
+
* its reason in {@link pairRefusedReasons} and `triesLeft`. Throws a
|
|
186
|
+
* `RangeError` for a `triesLeft` the rules don't allow.
|
|
187
|
+
*/
|
|
188
|
+
export declare function encodeCleartextFrame(frame: GatewayCleartextFrame): Uint8Array;
|
|
189
|
+
/**
|
|
190
|
+
* Reads a cleartext frame, exactly as {@link encodeCleartextFrame} writes it.
|
|
191
|
+
* Anything else, including a reason or a `triesLeft` it would refuse to
|
|
192
|
+
* write, is `undefined`: the phone treats it as bytes it can't read.
|
|
193
|
+
*/
|
|
194
|
+
export declare function decodeCleartextFrame(bytes: Uint8Array): GatewayCleartextFrame | undefined;
|