@nexus-code/remote-protocol 0.0.0-stage → 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,eAAO,MAAM,WAAW,wCAA0C,CAAC;AAEnE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;EAK3B,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,cAAc;;;;;;;;;;;;EAIzB,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAItD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAG5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,qBAAqB;;;;;;;;;;;;EAIhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAI3B,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,qEAAqE;AACrE,eAAO,MAAM,YAAY;;;;;;IAMvB,6DAA6D;;IAE7D,yDAAyD;;IAEzD,+FAA+F;;CAEvF,CAAC;AAMX,yCAAyC;AACzC,eAAO,MAAM,qB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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmHpD,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,iBAAiB,CAAC;AACnE,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,qBAAqB,IAAI,CAAC,CAAC,KAAK,CAC1E,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAC9B,CAAC;AAEF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,SAAS,CAE/D"}
package/dist/rpc.js ADDED
@@ -0,0 +1,225 @@
1
+ /**
2
+ * What one device asks another, sealed: JSON-RPC 2.0 requests, their
3
+ * answers, and the notifications a watch sends. The device that runs the
4
+ * sessions serves; the one that shows them asks.
5
+ *
6
+ * A session is named by the serving device's own ids: its workspace's and
7
+ * its tab's. The same folder has other ids on another device.
8
+ */
9
+ import { z } from "zod";
10
+ import { AssistantItemSchema, ChatStatusSchema, ViewItemSchema, ViewTaskSchema, ViewToolCallSchema, } from "./view.js";
11
+ // ---------------------------------------------------------------------------
12
+ // JSON-RPC 2.0 shapes
13
+ // ---------------------------------------------------------------------------
14
+ export const RpcIdSchema = z.union([z.number().int(), z.string()]);
15
+ export const RpcRequestSchema = z.object({
16
+ jsonrpc: z.literal("2.0"),
17
+ id: RpcIdSchema,
18
+ method: z.string(),
19
+ params: z.unknown().optional(),
20
+ });
21
+ export const RpcErrorSchema = z.object({
22
+ code: z.number().int(),
23
+ message: z.string(),
24
+ data: z.unknown().optional(),
25
+ });
26
+ // The error first: `result: z.unknown()` takes an object without one too,
27
+ // and would strip an error answer's `error`.
28
+ export const RpcResponseSchema = z.union([
29
+ z.object({ jsonrpc: z.literal("2.0"), id: RpcIdSchema, error: RpcErrorSchema }),
30
+ z.object({ jsonrpc: z.literal("2.0"), id: RpcIdSchema, result: z.unknown() }),
31
+ ]);
32
+ export const RpcNotificationSchema = z.object({
33
+ jsonrpc: z.literal("2.0"),
34
+ method: z.string(),
35
+ params: z.unknown().optional(),
36
+ });
37
+ export const RpcMessageSchema = z.union([
38
+ RpcRequestSchema,
39
+ RpcResponseSchema,
40
+ RpcNotificationSchema,
41
+ ]);
42
+ /** The error codes: JSON-RPC's own, and the protocol's from 1000. */
43
+ export const RpcErrorCode = {
44
+ ParseError: -32700,
45
+ InvalidRequest: -32600,
46
+ MethodNotFound: -32601,
47
+ InvalidParams: -32602,
48
+ InternalError: -32603,
49
+ /** No such workspace, tab or watch on the serving device. */
50
+ NotFound: 1001,
51
+ /** The serving device does not let this device do it. */
52
+ Forbidden: 1002,
53
+ /** The session cannot do it now: a chat with no request waiting, one whose program is gone. */
54
+ Unavailable: 1003,
55
+ };
56
+ // ---------------------------------------------------------------------------
57
+ // Sessions
58
+ // ---------------------------------------------------------------------------
59
+ /** A workspace of the serving device. */
60
+ export const RemoteWorkspaceSchema = z.object({
61
+ id: z.string(),
62
+ name: z.string(),
63
+ /** Its folder, on the serving device. */
64
+ path: z.string(),
65
+ });
66
+ /** Where a session stands, as the agent lists show it. */
67
+ export const SessionStateSchema = z.enum(["needs-you", "running", "new-result", "idle", "ended"]);
68
+ /** An agent session or terminal of the serving device. */
69
+ export const RemoteSessionSchema = z.object({
70
+ workspaceId: z.string(),
71
+ tabId: z.string(),
72
+ kind: z.enum(["claude", "codex", "terminal"]),
73
+ title: z.string(),
74
+ state: SessionStateSchema,
75
+ /** When it came to that state, in Unix milliseconds. */
76
+ since: z.number().optional(),
77
+ /** The last thing it said, a line. */
78
+ last: z.string().optional(),
79
+ /** The agent profile it runs with. */
80
+ profile: z.string().optional(),
81
+ /** What it waits on the user for, when it does. */
82
+ waiting: z
83
+ .object({
84
+ kind: z.enum(["permission", "question", "plan"]),
85
+ text: z.string(),
86
+ })
87
+ .optional(),
88
+ });
89
+ const SessionsSchema = z.object({
90
+ workspaces: z.array(RemoteWorkspaceSchema),
91
+ sessions: z.array(RemoteSessionSchema),
92
+ });
93
+ /** A session of the serving device, by its ids there. */
94
+ const TabRef = { workspaceId: z.string(), tabId: z.string() };
95
+ // ---------------------------------------------------------------------------
96
+ // Chats
97
+ // ---------------------------------------------------------------------------
98
+ /** Most items one chat.read gives; earlier ones come by `before`. */
99
+ export const MAX_READ_ITEMS = 500;
100
+ /**
101
+ * A page of a chat: its status, the items from `start` (before `total`),
102
+ * and the tool calls, tasks and subagents' messages they name.
103
+ */
104
+ export const ChatPageSchema = z.object({
105
+ status: ChatStatusSchema,
106
+ start: z.number().int().nonnegative(),
107
+ total: z.number().int().nonnegative(),
108
+ items: z.array(ViewItemSchema),
109
+ tools: z.record(ViewToolCallSchema),
110
+ tasks: z.record(ViewTaskSchema),
111
+ agentItems: z.record(z.array(AssistantItemSchema)),
112
+ });
113
+ /**
114
+ * What changed in a watched chat since its last update (or its watch
115
+ * began). Items are put at their index; `total` cuts the list when it got
116
+ * shorter. Tool calls, tasks and subagents' messages are put by id.
117
+ */
118
+ export const ChatUpdateSchema = z.object({
119
+ watchId: z.string(),
120
+ /** Counts the watch's updates from 1, so one lost shows. */
121
+ rev: z.number().int().positive(),
122
+ status: ChatStatusSchema.optional(),
123
+ total: z.number().int().nonnegative(),
124
+ items: z.array(z.object({ index: z.number().int().nonnegative(), item: ViewItemSchema })),
125
+ tools: z.record(ViewToolCallSchema),
126
+ tasks: z.record(ViewTaskSchema),
127
+ agentItems: z.record(z.array(AssistantItemSchema)),
128
+ });
129
+ /** The sessions' list as it is now, sent whenever it changes during a sessions.watch. */
130
+ export const SessionsUpdateSchema = SessionsSchema.extend({ watchId: z.string() });
131
+ const Ok = z.object({});
132
+ // ---------------------------------------------------------------------------
133
+ // The methods
134
+ // ---------------------------------------------------------------------------
135
+ /**
136
+ * Each method's params and result, and the capability (see ./sealed.ts)
137
+ * the serving device lists for it.
138
+ */
139
+ export const RPC_METHODS = {
140
+ "sessions.list": { capability: "sessions", params: Ok, result: SessionsSchema },
141
+ /** The list now; then a sessions.update each time it changes, until sessions.unwatch. */
142
+ "sessions.watch": {
143
+ capability: "sessions",
144
+ params: Ok,
145
+ result: SessionsSchema.extend({ watchId: z.string() }),
146
+ },
147
+ "sessions.unwatch": {
148
+ capability: "sessions",
149
+ params: z.object({ watchId: z.string() }),
150
+ result: Ok,
151
+ },
152
+ /** The chat's last `limit` items, or those before `before`. */
153
+ "chat.read": {
154
+ capability: "chat.read",
155
+ params: z.object({
156
+ ...TabRef,
157
+ before: z.number().int().nonnegative().optional(),
158
+ limit: z.number().int().positive().max(MAX_READ_ITEMS).optional(),
159
+ }),
160
+ result: ChatPageSchema,
161
+ },
162
+ /** The chat's last page now; then a chat.update each time it changes, until chat.unwatch. */
163
+ "chat.watch": {
164
+ capability: "chat.read",
165
+ params: z.object({
166
+ ...TabRef,
167
+ limit: z.number().int().positive().max(MAX_READ_ITEMS).optional(),
168
+ }),
169
+ result: ChatPageSchema.extend({ watchId: z.string() }),
170
+ },
171
+ "chat.unwatch": {
172
+ capability: "chat.read",
173
+ params: z.object({ watchId: z.string() }),
174
+ result: Ok,
175
+ },
176
+ /** Sends a message, as its composer does: during a turn, the turn reads it next. */
177
+ "chat.send": {
178
+ capability: "chat.control",
179
+ params: z.object({ ...TabRef, text: z.string().min(1) }),
180
+ result: Ok,
181
+ },
182
+ /** Answers the permission request `requestId`, as its card's buttons do. */
183
+ "chat.answer": {
184
+ capability: "chat.control",
185
+ params: z.object({
186
+ ...TabRef,
187
+ requestId: z.string(),
188
+ decision: z.enum(["allow", "deny"]),
189
+ /** Why, for a denial: the program reads it. */
190
+ message: z.string().optional(),
191
+ /** With allow: the input the tool runs with, as the user filled it (a question's answers). */
192
+ updatedInput: z.record(z.unknown()).optional(),
193
+ /** With deny: the turn stops too, as the card's "No, and stop" does. */
194
+ stop: z.boolean().optional(),
195
+ }),
196
+ result: Ok,
197
+ },
198
+ "chat.interrupt": { capability: "chat.control", params: z.object(TabRef), result: Ok },
199
+ /** Opens a chat in one of the serving device's workspaces, sending it `prompt` if given. */
200
+ "chat.new": {
201
+ capability: "chat.control",
202
+ params: z.object({
203
+ workspaceId: z.string(),
204
+ agent: z.enum(["claude", "codex"]),
205
+ prompt: z.string().optional(),
206
+ }),
207
+ result: z.object({ tabId: z.string() }),
208
+ },
209
+ "chat.close": { capability: "chat.control", params: z.object(TabRef), result: Ok },
210
+ /** A terminal's screen and the lines above it, as text. Nothing can be typed into it. */
211
+ "terminal.read": {
212
+ capability: "terminal.read",
213
+ params: z.object({ ...TabRef, lines: z.number().int().positive().max(5000).optional() }),
214
+ result: z.object({ text: z.string() }),
215
+ },
216
+ };
217
+ /** The notifications a serving device sends, by method. */
218
+ export const RPC_NOTIFICATIONS = {
219
+ "sessions.update": SessionsUpdateSchema,
220
+ "chat.update": ChatUpdateSchema,
221
+ };
222
+ export function isRpcMethod(method) {
223
+ return Object.hasOwn(RPC_METHODS, method);
224
+ }
225
+ //# sourceMappingURL=rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAEnB,8EAA8E;AAC9E,sBAAsB;AACtB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ACvB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAClC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SAC9B,CAAC;QACF,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;KACxC;IACD,YAAY,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;IAElF,yFAAyF;IACzF,eAAe,EAAE;QACf,UAAU,EAAE,eAAe;QAC3B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;QACxF,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;KACvC;CACO,CAAC;AAMX,2DAA2D;AAC3D,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,iBAAiB,EAAE,oBAAoB;IACvC,aAAa,EAAE,gBAAgB;CACvB,CAAC;AAOX,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,230 @@
1
+ /**
2
+ * What a sealed message carries, which only the account's devices can open.
3
+ *
4
+ * Sealing (v1): XChaCha20-Poly1305 with the room key, a fresh random 24-byte
5
+ * nonce per message, and the frame's routing as associated data (aadOf), so
6
+ * the relay can neither read a message nor pass it off as another's. The
7
+ * room key comes from the account key (see the account key design); every
8
+ * device of the account holds it. The bytes sealed are the message's JSON
9
+ * in UTF-8.
10
+ */
11
+ import { z } from "zod";
12
+ import { type DeviceId } from "./relay.js";
13
+ /** The version of what is sealed; a device tells it in its hello. */
14
+ export declare const PROTOCOL_VERSION = 1;
15
+ /** The HKDF info that makes the room key from the account key. */
16
+ export declare const ROOM_KEY_INFO = "nexus-remote/room-key/v1";
17
+ /**
18
+ * The associated data a message is sealed with: its routing, as the relay
19
+ * delivers it. A message the relay sends on to another device, or with
20
+ * another seq, does not open.
21
+ */
22
+ export declare function aadOf(frame: {
23
+ from: DeviceId;
24
+ to: string;
25
+ seq: number;
26
+ kid: number;
27
+ }): string;
28
+ /**
29
+ * What a device can do for another, as it says in its hello. The other
30
+ * side asks only for what is listed; a newer device lists more.
31
+ */
32
+ export declare const CAPABILITIES: readonly ["sessions", "chat.read", "chat.control", "terminal.read"];
33
+ export declare const CapabilitySchema: z.ZodString;
34
+ export type Capability = (typeof CAPABILITIES)[number];
35
+ /**
36
+ * A device introduces itself: to all the room as it joins, and to one that
37
+ * just joined. What it serves of its own sessions is `serves`; a device
38
+ * that only watches others (a phone) serves nothing.
39
+ */
40
+ export declare const HelloSchema: z.ZodObject<{
41
+ type: z.ZodLiteral<"hello">;
42
+ protocol: z.ZodNumber;
43
+ device: z.ZodObject<{
44
+ id: z.ZodString;
45
+ name: z.ZodString;
46
+ platform: z.ZodString;
47
+ }, "strip", z.ZodTypeAny, {
48
+ id: string;
49
+ name: string;
50
+ platform: string;
51
+ }, {
52
+ id: string;
53
+ name: string;
54
+ platform: string;
55
+ }>;
56
+ app: z.ZodObject<{
57
+ name: z.ZodString;
58
+ version: z.ZodString;
59
+ }, "strip", z.ZodTypeAny, {
60
+ name: string;
61
+ version: string;
62
+ }, {
63
+ name: string;
64
+ version: string;
65
+ }>;
66
+ serves: z.ZodArray<z.ZodString, "many">;
67
+ /** Whether it wants the hello of devices already there: true as it joins. */
68
+ reply: z.ZodBoolean;
69
+ }, "strip", z.ZodTypeAny, {
70
+ type: "hello";
71
+ protocol: number;
72
+ device: {
73
+ id: string;
74
+ name: string;
75
+ platform: string;
76
+ };
77
+ app: {
78
+ name: string;
79
+ version: string;
80
+ };
81
+ serves: string[];
82
+ reply: boolean;
83
+ }, {
84
+ type: "hello";
85
+ protocol: number;
86
+ device: {
87
+ id: string;
88
+ name: string;
89
+ platform: string;
90
+ };
91
+ app: {
92
+ name: string;
93
+ version: string;
94
+ };
95
+ serves: string[];
96
+ reply: boolean;
97
+ }>;
98
+ export type Hello = z.infer<typeof HelloSchema>;
99
+ /** A sealed message's content. */
100
+ export declare const SealedMessageSchema: z.ZodUnion<[z.ZodObject<{
101
+ type: z.ZodLiteral<"hello">;
102
+ protocol: z.ZodNumber;
103
+ device: z.ZodObject<{
104
+ id: z.ZodString;
105
+ name: z.ZodString;
106
+ platform: z.ZodString;
107
+ }, "strip", z.ZodTypeAny, {
108
+ id: string;
109
+ name: string;
110
+ platform: string;
111
+ }, {
112
+ id: string;
113
+ name: string;
114
+ platform: string;
115
+ }>;
116
+ app: z.ZodObject<{
117
+ name: z.ZodString;
118
+ version: z.ZodString;
119
+ }, "strip", z.ZodTypeAny, {
120
+ name: string;
121
+ version: string;
122
+ }, {
123
+ name: string;
124
+ version: string;
125
+ }>;
126
+ serves: z.ZodArray<z.ZodString, "many">;
127
+ /** Whether it wants the hello of devices already there: true as it joins. */
128
+ reply: z.ZodBoolean;
129
+ }, "strip", z.ZodTypeAny, {
130
+ type: "hello";
131
+ protocol: number;
132
+ device: {
133
+ id: string;
134
+ name: string;
135
+ platform: string;
136
+ };
137
+ app: {
138
+ name: string;
139
+ version: string;
140
+ };
141
+ serves: string[];
142
+ reply: boolean;
143
+ }, {
144
+ type: "hello";
145
+ protocol: number;
146
+ device: {
147
+ id: string;
148
+ name: string;
149
+ platform: string;
150
+ };
151
+ app: {
152
+ name: string;
153
+ version: string;
154
+ };
155
+ serves: string[];
156
+ reply: boolean;
157
+ }>, z.ZodUnion<[z.ZodObject<{
158
+ jsonrpc: z.ZodLiteral<"2.0">;
159
+ id: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
160
+ method: z.ZodString;
161
+ params: z.ZodOptional<z.ZodUnknown>;
162
+ }, "strip", z.ZodTypeAny, {
163
+ id: string | number;
164
+ jsonrpc: "2.0";
165
+ method: string;
166
+ params?: unknown;
167
+ }, {
168
+ id: string | number;
169
+ jsonrpc: "2.0";
170
+ method: string;
171
+ params?: unknown;
172
+ }>, z.ZodUnion<[z.ZodObject<{
173
+ jsonrpc: z.ZodLiteral<"2.0">;
174
+ id: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
175
+ error: z.ZodObject<{
176
+ code: z.ZodNumber;
177
+ message: z.ZodString;
178
+ data: z.ZodOptional<z.ZodUnknown>;
179
+ }, "strip", z.ZodTypeAny, {
180
+ code: number;
181
+ message: string;
182
+ data?: unknown;
183
+ }, {
184
+ code: number;
185
+ message: string;
186
+ data?: unknown;
187
+ }>;
188
+ }, "strip", z.ZodTypeAny, {
189
+ id: string | number;
190
+ error: {
191
+ code: number;
192
+ message: string;
193
+ data?: unknown;
194
+ };
195
+ jsonrpc: "2.0";
196
+ }, {
197
+ id: string | number;
198
+ error: {
199
+ code: number;
200
+ message: string;
201
+ data?: unknown;
202
+ };
203
+ jsonrpc: "2.0";
204
+ }>, z.ZodObject<{
205
+ jsonrpc: z.ZodLiteral<"2.0">;
206
+ id: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
207
+ result: z.ZodUnknown;
208
+ }, "strip", z.ZodTypeAny, {
209
+ id: string | number;
210
+ jsonrpc: "2.0";
211
+ result?: unknown;
212
+ }, {
213
+ id: string | number;
214
+ jsonrpc: "2.0";
215
+ result?: unknown;
216
+ }>]>, z.ZodObject<{
217
+ jsonrpc: z.ZodLiteral<"2.0">;
218
+ method: z.ZodString;
219
+ params: z.ZodOptional<z.ZodUnknown>;
220
+ }, "strip", z.ZodTypeAny, {
221
+ jsonrpc: "2.0";
222
+ method: string;
223
+ params?: unknown;
224
+ }, {
225
+ jsonrpc: "2.0";
226
+ method: string;
227
+ params?: unknown;
228
+ }>]>]>;
229
+ export type SealedMessage = z.infer<typeof SealedMessageSchema>;
230
+ //# sourceMappingURL=sealed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sealed.d.ts","sourceRoot":"","sources":["../src/sealed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,QAAQ,EAAkB,MAAM,YAAY,CAAC;AAG3D,qEAAqE;AACrE,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,kEAAkE;AAClE,eAAO,MAAM,aAAa,6BAA6B,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE7F;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,qEASf,CAAC;AACX,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAC3C,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;IAUtB,6EAA6E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE7E,CAAC;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEhD,kCAAkC;AAClC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;IAN9B,6EAA6E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAMJ,CAAC;AAC5E,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
package/dist/sealed.js ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * What a sealed message carries, which only the account's devices can open.
3
+ *
4
+ * Sealing (v1): XChaCha20-Poly1305 with the room key, a fresh random 24-byte
5
+ * nonce per message, and the frame's routing as associated data (aadOf), so
6
+ * the relay can neither read a message nor pass it off as another's. The
7
+ * room key comes from the account key (see the account key design); every
8
+ * device of the account holds it. The bytes sealed are the message's JSON
9
+ * in UTF-8.
10
+ */
11
+ import { z } from "zod";
12
+ import { DeviceIdSchema } from "./relay.js";
13
+ import { RpcMessageSchema } from "./rpc.js";
14
+ /** The version of what is sealed; a device tells it in its hello. */
15
+ export const PROTOCOL_VERSION = 1;
16
+ /** The HKDF info that makes the room key from the account key. */
17
+ export const ROOM_KEY_INFO = "nexus-remote/room-key/v1";
18
+ /**
19
+ * The associated data a message is sealed with: its routing, as the relay
20
+ * delivers it. A message the relay sends on to another device, or with
21
+ * another seq, does not open.
22
+ */
23
+ export function aadOf(frame) {
24
+ return `nexus-remote/v${PROTOCOL_VERSION}|${frame.from}|${frame.to}|${frame.seq}|${frame.kid}`;
25
+ }
26
+ /**
27
+ * What a device can do for another, as it says in its hello. The other
28
+ * side asks only for what is listed; a newer device lists more.
29
+ */
30
+ export const CAPABILITIES = [
31
+ /** sessions.list and the session events. */
32
+ "sessions",
33
+ /** chat.read and chat.watch. */
34
+ "chat.read",
35
+ /** chat.send, chat.answer, chat.interrupt, chat.new and chat.close. */
36
+ "chat.control",
37
+ /** terminal.read: a terminal's screen, as text. */
38
+ "terminal.read",
39
+ ];
40
+ export const CapabilitySchema = z.string();
41
+ /**
42
+ * A device introduces itself: to all the room as it joins, and to one that
43
+ * just joined. What it serves of its own sessions is `serves`; a device
44
+ * that only watches others (a phone) serves nothing.
45
+ */
46
+ export const HelloSchema = z.object({
47
+ type: z.literal("hello"),
48
+ protocol: z.number().int().positive(),
49
+ device: z.object({
50
+ id: DeviceIdSchema,
51
+ name: z.string(),
52
+ platform: z.string(),
53
+ }),
54
+ app: z.object({ name: z.string(), version: z.string() }),
55
+ serves: z.array(CapabilitySchema),
56
+ /** Whether it wants the hello of devices already there: true as it joins. */
57
+ reply: z.boolean(),
58
+ });
59
+ /** A sealed message's content. */
60
+ export const SealedMessageSchema = z.union([HelloSchema, RpcMessageSchema]);
61
+ //# sourceMappingURL=sealed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sealed.js","sourceRoot":"","sources":["../src/sealed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAiB,cAAc,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,qEAAqE;AACrE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,kEAAkE;AAClE,MAAM,CAAC,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAExD;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,KAA+D;IACnF,OAAO,iBAAiB,gBAAgB,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;AACjG,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,4CAA4C;IAC5C,UAAU;IACV,gCAAgC;IAChC,WAAW;IACX,uEAAuE;IACvE,cAAc;IACd,mDAAmD;IACnD,eAAe;CACP,CAAC;AACX,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;AAG3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAA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