@rstreamlabs/webtty 1.6.5 → 1.9.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/README.md +327 -22
- package/dist/chunk-7OHAFDJE.mjs +10679 -0
- package/dist/index.d.mts +5324 -5
- package/dist/index.d.ts +5324 -5
- package/dist/index.js +9658 -1058
- package/dist/index.mjs +76 -2112
- package/dist/node.d.mts +38 -0
- package/dist/node.d.ts +38 -0
- package/dist/node.js +11129 -0
- package/dist/node.mjs +451 -0
- package/examples/filesystem-sidecar/.env.local.example +1 -0
- package/examples/filesystem-sidecar/README.md +11 -0
- package/examples/filesystem-sidecar/package.json +20 -0
- package/examples/filesystem-sidecar/src/main.ts +42 -0
- package/examples/filesystem-sidecar/tsconfig.json +14 -0
- package/examples/remote-command/.env.local.example +1 -0
- package/examples/remote-command/README.md +11 -0
- package/examples/remote-command/package.json +20 -0
- package/examples/remote-command/src/main.ts +37 -0
- package/examples/remote-command/tsconfig.json +14 -0
- package/package.json +23 -3
package/dist/node.mjs
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WebTTY,
|
|
3
|
+
WebTTYCommand,
|
|
4
|
+
WebTTYFileSystem,
|
|
5
|
+
WebTTYFileSystemError,
|
|
6
|
+
WebTTYRemoteExecutor,
|
|
7
|
+
createWebTTYE2EClientPayloadCrypto,
|
|
8
|
+
createWebTTYE2EKeyContext,
|
|
9
|
+
createWebTTYE2EReplayPayloadCryptoFromKeyGrant,
|
|
10
|
+
createWebTTYE2EServerPayloadCrypto,
|
|
11
|
+
decodeWebTTYE2EKeyMaterial,
|
|
12
|
+
decryptWebTTYRecordedEvent,
|
|
13
|
+
decryptWebTTYRecordedTextLog,
|
|
14
|
+
encodeWebTTYE2EKeyMaterial,
|
|
15
|
+
executeWebTTYCommand,
|
|
16
|
+
generateWebTTYE2EIdentity,
|
|
17
|
+
generateWebTTYSigningIdentity,
|
|
18
|
+
hashWebTTYAttachGrant,
|
|
19
|
+
hashWebTTYClientCredential,
|
|
20
|
+
hashWebTTYClientProofTranscript,
|
|
21
|
+
hashWebTTYConfig,
|
|
22
|
+
hashWebTTYServerProofTranscript,
|
|
23
|
+
hashWebTTYSessionKeyGrant,
|
|
24
|
+
openWebTTYCommand,
|
|
25
|
+
parseWebDAVMultiStatus,
|
|
26
|
+
renderWebTTYRecordedTextLog,
|
|
27
|
+
resolveWebTTYExecutionURL,
|
|
28
|
+
resolveWebTTYFileSystemURL,
|
|
29
|
+
runWebTTYCommand,
|
|
30
|
+
signWebTTYClientProofTranscript,
|
|
31
|
+
signWebTTYServerProofTranscript,
|
|
32
|
+
verifyWebTTYClientProofTranscript,
|
|
33
|
+
verifyWebTTYServerProofTranscript,
|
|
34
|
+
webTTYClientProofTranscriptBytes,
|
|
35
|
+
webTTYE2EKeyID,
|
|
36
|
+
webTTYRecordedEventEncryptedPayload,
|
|
37
|
+
webTTYServerProofTranscriptBytes,
|
|
38
|
+
webTTYSigningKeyID
|
|
39
|
+
} from "./chunk-7OHAFDJE.mjs";
|
|
40
|
+
|
|
41
|
+
// src/local-e2e.ts
|
|
42
|
+
var localKeyFileVersion = 1;
|
|
43
|
+
var localKeyFileCryptoSuite = "webtty-e2e-x25519-hpke-aes-256-gcm-v1";
|
|
44
|
+
var x25519PublicKeySize = 32;
|
|
45
|
+
var payloadKeyIDSize = 16;
|
|
46
|
+
var knownServerKeyEnv = "RSTREAM_WEBTTY_KNOWN_SERVER_KEY";
|
|
47
|
+
var knownServersFileEnv = "RSTREAM_WEBTTY_KNOWN_SERVERS_FILE";
|
|
48
|
+
async function defaultWebTTYKnownServersPath(env) {
|
|
49
|
+
const path = await nodePath();
|
|
50
|
+
return path.join(
|
|
51
|
+
await homeDir(env ?? defaultEnv()),
|
|
52
|
+
".rstream",
|
|
53
|
+
"webtty",
|
|
54
|
+
"known_servers.json"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
async function parseWebTTYKnownServerKey(value) {
|
|
58
|
+
const trimmed = value.trim();
|
|
59
|
+
if (trimmed === "") {
|
|
60
|
+
throw new Error("known WebTTY server key is empty");
|
|
61
|
+
}
|
|
62
|
+
const parts = trimmed.split(":");
|
|
63
|
+
if (parts.length !== 1 && parts.length !== 2 && parts.length !== 4) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
"known WebTTY server key must be public_key, key_id:public_key, or endpoint identity"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (parts.length === 4) {
|
|
69
|
+
validateSigningKeyMaterial(parts[2] ?? "", parts[3] ?? "");
|
|
70
|
+
}
|
|
71
|
+
if (parts.length === 1) {
|
|
72
|
+
const publicKey2 = decodeFixedKeyMaterial(
|
|
73
|
+
parts[0] ?? "",
|
|
74
|
+
x25519PublicKeySize,
|
|
75
|
+
"known WebTTY server public key"
|
|
76
|
+
);
|
|
77
|
+
return { keyId: await webTTYE2EKeyID(publicKey2), publicKey: publicKey2 };
|
|
78
|
+
}
|
|
79
|
+
const keyId = decodeFixedKeyMaterial(
|
|
80
|
+
parts[0] ?? "",
|
|
81
|
+
payloadKeyIDSize,
|
|
82
|
+
"known WebTTY server key id"
|
|
83
|
+
);
|
|
84
|
+
const publicKey = decodeFixedKeyMaterial(
|
|
85
|
+
parts[1] ?? "",
|
|
86
|
+
x25519PublicKeySize,
|
|
87
|
+
"known WebTTY server public key"
|
|
88
|
+
);
|
|
89
|
+
const expectedKeyId = await webTTYE2EKeyID(publicKey);
|
|
90
|
+
if (!bytesEqual(keyId, expectedKeyId)) {
|
|
91
|
+
throw new Error("known WebTTY server key id does not match public key");
|
|
92
|
+
}
|
|
93
|
+
return { keyId, publicKey };
|
|
94
|
+
}
|
|
95
|
+
async function readWebTTYKnownServerKeysFile(filePath, env) {
|
|
96
|
+
const resolvedPath = cleanString(filePath) ?? await defaultWebTTYKnownServersPath(env);
|
|
97
|
+
const fs = await nodeFS();
|
|
98
|
+
const data = await fs.readFile(resolvedPath, "utf8");
|
|
99
|
+
return decodeWebTTYKnownServerKeysFile(data, resolvedPath);
|
|
100
|
+
}
|
|
101
|
+
async function loadWebTTYKnownServerKeysFile(filePath, env) {
|
|
102
|
+
const doc = await readWebTTYKnownServerKeysFile(filePath, env);
|
|
103
|
+
return uniqueRecipients(
|
|
104
|
+
await Promise.all(doc.known_servers.map(knownServerKeyFromEntry))
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
async function createWebTTYE2EClientPayloadCryptoFromLocalTrust(options = {}) {
|
|
108
|
+
const env = options.env ?? defaultEnv();
|
|
109
|
+
const directKeys = optionKeys(options.knownServerKey);
|
|
110
|
+
const directRecipients = await parseWebTTYKnownServerKeys(directKeys);
|
|
111
|
+
const envKey = cleanString(env[knownServerKeyEnv]);
|
|
112
|
+
const envRecipients = envKey === void 0 ? [] : [await parseWebTTYKnownServerKey(envKey)];
|
|
113
|
+
const explicitFile = cleanString(options.knownServersFile) ?? cleanString(env[knownServersFileEnv]);
|
|
114
|
+
const fileRecipients = explicitFile === void 0 ? [] : await loadWebTTYKnownServerKeysFile(explicitFile, env);
|
|
115
|
+
const explicitConfigured = directKeys.length > 0 || envKey !== void 0 || explicitFile !== void 0;
|
|
116
|
+
const defaultRecipients = explicitConfigured ? [] : await loadDefaultKnownServerRecipients(env, {
|
|
117
|
+
hostKeyId: options.hostKeyId,
|
|
118
|
+
target: options.target
|
|
119
|
+
});
|
|
120
|
+
const configured = explicitConfigured || defaultRecipients.length > 0;
|
|
121
|
+
const recipients = uniqueRecipients([
|
|
122
|
+
...directRecipients,
|
|
123
|
+
...envRecipients,
|
|
124
|
+
...fileRecipients,
|
|
125
|
+
...defaultRecipients
|
|
126
|
+
]);
|
|
127
|
+
if (!configured && options.required !== true) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
if (recipients.length === 0) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`E2E client mode requires knownServerKey, knownServersFile, ${knownServerKeyEnv}, ${knownServersFileEnv}, or ${await defaultWebTTYKnownServersPath(env)}`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return await createWebTTYE2EClientPayloadCrypto({
|
|
136
|
+
keyContext: options.keyContext,
|
|
137
|
+
recipients
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async function parseWebTTYKnownServerKeys(values) {
|
|
141
|
+
return await Promise.all(values.map(parseWebTTYKnownServerKey));
|
|
142
|
+
}
|
|
143
|
+
async function loadDefaultKnownServerRecipients(env, scope) {
|
|
144
|
+
const defaultPath = await defaultWebTTYKnownServersPath(env);
|
|
145
|
+
const defaultDoc = await readOptionalKnownServersFile(defaultPath);
|
|
146
|
+
const entries = defaultDoc === void 0 ? [] : filterKnownServerEntries(defaultDoc.known_servers, scope);
|
|
147
|
+
return entries.length === 0 ? [] : uniqueRecipients(await Promise.all(entries.map(knownServerKeyFromEntry)));
|
|
148
|
+
}
|
|
149
|
+
function filterKnownServerEntries(entries, scope) {
|
|
150
|
+
const target = cleanString(scope.target);
|
|
151
|
+
const hostKeyId = cleanString(scope.hostKeyId);
|
|
152
|
+
if (target === void 0 && hostKeyId === void 0) {
|
|
153
|
+
return [...entries];
|
|
154
|
+
}
|
|
155
|
+
const targetMatches = target === void 0 ? [] : entries.filter((entry) => entry.name === target);
|
|
156
|
+
if (hostKeyId === void 0) {
|
|
157
|
+
return targetMatches;
|
|
158
|
+
}
|
|
159
|
+
if (targetMatches.length > 0) {
|
|
160
|
+
return targetMatches.filter((entry) => entry.key_id === hostKeyId);
|
|
161
|
+
}
|
|
162
|
+
return entries.filter((entry) => entry.key_id === hostKeyId);
|
|
163
|
+
}
|
|
164
|
+
function decodeWebTTYKnownServerKeysFile(data, filePath) {
|
|
165
|
+
const parsed = parseJSONRecord(
|
|
166
|
+
data,
|
|
167
|
+
`decode known WebTTY server keys ${filePath}`
|
|
168
|
+
);
|
|
169
|
+
assertKnownKeys(
|
|
170
|
+
parsed,
|
|
171
|
+
["crypto_suite", "known_servers", "version"],
|
|
172
|
+
`known WebTTY server keys ${filePath}`
|
|
173
|
+
);
|
|
174
|
+
const version = parsed.version;
|
|
175
|
+
if (version !== localKeyFileVersion) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`unsupported known WebTTY server keys version ${String(version)}`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
const cryptoSuite = parsed.crypto_suite;
|
|
181
|
+
if (cryptoSuite !== localKeyFileCryptoSuite) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`unsupported known WebTTY server keys crypto suite ${String(cryptoSuite)}`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
const entries = parsed.known_servers;
|
|
187
|
+
if (!Array.isArray(entries)) {
|
|
188
|
+
throw new Error("known WebTTY server keys must include known_servers");
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
crypto_suite: cryptoSuite,
|
|
192
|
+
known_servers: entries.map(
|
|
193
|
+
(entry, index) => decodeKnownServerKeyEntry(entry, `known WebTTY server key ${index}`)
|
|
194
|
+
),
|
|
195
|
+
version
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function decodeKnownServerKeyEntry(value, label) {
|
|
199
|
+
const entry = asRecord(value, label);
|
|
200
|
+
assertKnownKeys(
|
|
201
|
+
entry,
|
|
202
|
+
[
|
|
203
|
+
"client_identity",
|
|
204
|
+
"created_at",
|
|
205
|
+
"key_id",
|
|
206
|
+
"name",
|
|
207
|
+
"public_key",
|
|
208
|
+
"signing_key_id",
|
|
209
|
+
"signing_public_key"
|
|
210
|
+
],
|
|
211
|
+
label
|
|
212
|
+
);
|
|
213
|
+
const name = stringField(entry, "name", label).trim();
|
|
214
|
+
if (name === "") {
|
|
215
|
+
throw new Error(`${label} name is required`);
|
|
216
|
+
}
|
|
217
|
+
const signingKeyID = optionalStringField(entry, "signing_key_id", label);
|
|
218
|
+
const signingPublicKey = optionalStringField(
|
|
219
|
+
entry,
|
|
220
|
+
"signing_public_key",
|
|
221
|
+
label
|
|
222
|
+
);
|
|
223
|
+
if (signingKeyID === void 0 !== (signingPublicKey === void 0)) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
`${label} signing_key_id and signing_public_key must be provided together`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
if (signingKeyID !== void 0 && signingPublicKey !== void 0) {
|
|
229
|
+
validateSigningKeyMaterial(signingKeyID, signingPublicKey);
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
client_identity: optionalStringField(entry, "client_identity", label),
|
|
233
|
+
created_at: optionalStringField(entry, "created_at", label),
|
|
234
|
+
key_id: stringField(entry, "key_id", label),
|
|
235
|
+
name,
|
|
236
|
+
public_key: stringField(entry, "public_key", label),
|
|
237
|
+
signing_key_id: signingKeyID,
|
|
238
|
+
signing_public_key: signingPublicKey
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
async function knownServerKeyFromEntry(entry) {
|
|
242
|
+
return await parseWebTTYKnownServerKey(`${entry.key_id}:${entry.public_key}`);
|
|
243
|
+
}
|
|
244
|
+
async function readOptionalKnownServersFile(filePath) {
|
|
245
|
+
try {
|
|
246
|
+
const fs = await nodeFS();
|
|
247
|
+
const data = await fs.readFile(filePath, "utf8");
|
|
248
|
+
return decodeWebTTYKnownServerKeysFile(data, filePath);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (isNodeErrorCode(error, "ENOENT")) {
|
|
251
|
+
return void 0;
|
|
252
|
+
}
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function appendUniqueRecipient(recipients, next) {
|
|
257
|
+
const nextKeyId = bytesFromKeyMaterial(next.keyId);
|
|
258
|
+
const nextPublicKey = bytesFromKeyMaterial(next.publicKey);
|
|
259
|
+
for (const existing of recipients) {
|
|
260
|
+
const existingKeyId = bytesFromKeyMaterial(existing.keyId);
|
|
261
|
+
if (!bytesEqual(existingKeyId, nextKeyId)) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (!bytesEqual(bytesFromKeyMaterial(existing.publicKey), nextPublicKey)) {
|
|
265
|
+
throw new Error("conflicting known WebTTY server public keys for key id");
|
|
266
|
+
}
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
recipients.push({ keyId: nextKeyId, publicKey: nextPublicKey });
|
|
270
|
+
}
|
|
271
|
+
function uniqueRecipients(recipients) {
|
|
272
|
+
const out = [];
|
|
273
|
+
for (const recipient of recipients) {
|
|
274
|
+
appendUniqueRecipient(out, recipient);
|
|
275
|
+
}
|
|
276
|
+
return out;
|
|
277
|
+
}
|
|
278
|
+
function optionKeys(value) {
|
|
279
|
+
if (value === void 0) {
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
return (Array.isArray(value) ? value : [value]).map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
283
|
+
}
|
|
284
|
+
function decodeFixedKeyMaterial(value, size, label) {
|
|
285
|
+
const decoded = decodeWebTTYE2EKeyMaterial(value.trim());
|
|
286
|
+
if (decoded.byteLength !== size) {
|
|
287
|
+
throw new Error(`${label} must decode to ${size} bytes`);
|
|
288
|
+
}
|
|
289
|
+
return decoded;
|
|
290
|
+
}
|
|
291
|
+
function validateSigningKeyMaterial(keyID, publicKey) {
|
|
292
|
+
decodeFixedKeyMaterial(keyID, 32, "known WebTTY server signing key id");
|
|
293
|
+
decodeWebTTYE2EKeyMaterial(publicKey.trim());
|
|
294
|
+
}
|
|
295
|
+
function bytesFromKeyMaterial(value) {
|
|
296
|
+
if (value === void 0) {
|
|
297
|
+
return new Uint8Array();
|
|
298
|
+
}
|
|
299
|
+
return typeof value === "string" ? decodeWebTTYE2EKeyMaterial(value) : new Uint8Array(value);
|
|
300
|
+
}
|
|
301
|
+
function bytesEqual(left, right) {
|
|
302
|
+
if (left.byteLength !== right.byteLength) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
const diff = left.reduce(
|
|
306
|
+
(current, value, index) => current | value ^ (right[index] ?? 0),
|
|
307
|
+
0
|
|
308
|
+
);
|
|
309
|
+
return diff === 0;
|
|
310
|
+
}
|
|
311
|
+
function parseJSONRecord(data, label) {
|
|
312
|
+
return asRecord(parseJSON(data, label), label);
|
|
313
|
+
}
|
|
314
|
+
function parseJSON(data, label) {
|
|
315
|
+
try {
|
|
316
|
+
return JSON.parse(data);
|
|
317
|
+
} catch (error) {
|
|
318
|
+
throw new Error(`${label}: ${errorMessage(error)}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function asRecord(value, label) {
|
|
322
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
323
|
+
throw new Error(`${label} must be an object`);
|
|
324
|
+
}
|
|
325
|
+
return Object.fromEntries(Object.entries(value));
|
|
326
|
+
}
|
|
327
|
+
function assertKnownKeys(value, allowed, label) {
|
|
328
|
+
const allowedSet = new Set(allowed);
|
|
329
|
+
for (const key of Object.keys(value)) {
|
|
330
|
+
if (!allowedSet.has(key)) {
|
|
331
|
+
throw new Error(`${label} contains unknown field ${key}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function stringField(value, key, label) {
|
|
336
|
+
const field = value[key];
|
|
337
|
+
if (typeof field !== "string") {
|
|
338
|
+
throw new Error(`${label} ${key} must be a string`);
|
|
339
|
+
}
|
|
340
|
+
return field;
|
|
341
|
+
}
|
|
342
|
+
function optionalStringField(value, key, label) {
|
|
343
|
+
const field = value[key];
|
|
344
|
+
if (field === void 0) {
|
|
345
|
+
return void 0;
|
|
346
|
+
}
|
|
347
|
+
if (typeof field !== "string") {
|
|
348
|
+
throw new Error(`${label} ${key} must be a string`);
|
|
349
|
+
}
|
|
350
|
+
return field;
|
|
351
|
+
}
|
|
352
|
+
function cleanString(value) {
|
|
353
|
+
const trimmed = value?.trim();
|
|
354
|
+
return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
|
|
355
|
+
}
|
|
356
|
+
function defaultEnv() {
|
|
357
|
+
const env = objectField(objectField(globalThis, "process"), "env");
|
|
358
|
+
return env === void 0 ? {} : stringRecord(env);
|
|
359
|
+
}
|
|
360
|
+
async function homeDir(env) {
|
|
361
|
+
const configured = cleanString(env.HOME) ?? cleanString(env.USERPROFILE);
|
|
362
|
+
if (configured !== void 0) {
|
|
363
|
+
return configured;
|
|
364
|
+
}
|
|
365
|
+
const os = await import("os");
|
|
366
|
+
const resolved = os.homedir();
|
|
367
|
+
if (resolved === "") {
|
|
368
|
+
throw new Error("unable to resolve user home directory");
|
|
369
|
+
}
|
|
370
|
+
return resolved;
|
|
371
|
+
}
|
|
372
|
+
async function nodePath() {
|
|
373
|
+
try {
|
|
374
|
+
return await import("path");
|
|
375
|
+
} catch {
|
|
376
|
+
throw new Error("local WebTTY E2E trust helpers require a Node.js runtime");
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
async function nodeFS() {
|
|
380
|
+
try {
|
|
381
|
+
return await import("fs/promises");
|
|
382
|
+
} catch {
|
|
383
|
+
throw new Error("local WebTTY E2E trust helpers require a Node.js runtime");
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function isNodeErrorCode(error, code) {
|
|
387
|
+
return objectField(error, "code") === code;
|
|
388
|
+
}
|
|
389
|
+
function objectField(value, key) {
|
|
390
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
391
|
+
return void 0;
|
|
392
|
+
}
|
|
393
|
+
return Object.fromEntries(Object.entries(value))[key];
|
|
394
|
+
}
|
|
395
|
+
function stringRecord(value) {
|
|
396
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
397
|
+
return {};
|
|
398
|
+
}
|
|
399
|
+
return Object.fromEntries(
|
|
400
|
+
Object.entries(value).filter(
|
|
401
|
+
([, entry]) => typeof entry === "string" || entry === void 0
|
|
402
|
+
)
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
function errorMessage(error) {
|
|
406
|
+
return error instanceof Error ? error.message : String(error);
|
|
407
|
+
}
|
|
408
|
+
export {
|
|
409
|
+
WebTTY,
|
|
410
|
+
WebTTYCommand,
|
|
411
|
+
WebTTYFileSystem,
|
|
412
|
+
WebTTYFileSystemError,
|
|
413
|
+
WebTTYRemoteExecutor,
|
|
414
|
+
createWebTTYE2EClientPayloadCrypto,
|
|
415
|
+
createWebTTYE2EClientPayloadCryptoFromLocalTrust,
|
|
416
|
+
createWebTTYE2EKeyContext,
|
|
417
|
+
createWebTTYE2EReplayPayloadCryptoFromKeyGrant,
|
|
418
|
+
createWebTTYE2EServerPayloadCrypto,
|
|
419
|
+
decodeWebTTYE2EKeyMaterial,
|
|
420
|
+
decryptWebTTYRecordedEvent,
|
|
421
|
+
decryptWebTTYRecordedTextLog,
|
|
422
|
+
defaultWebTTYKnownServersPath,
|
|
423
|
+
encodeWebTTYE2EKeyMaterial,
|
|
424
|
+
executeWebTTYCommand,
|
|
425
|
+
generateWebTTYE2EIdentity,
|
|
426
|
+
generateWebTTYSigningIdentity,
|
|
427
|
+
hashWebTTYAttachGrant,
|
|
428
|
+
hashWebTTYClientCredential,
|
|
429
|
+
hashWebTTYClientProofTranscript,
|
|
430
|
+
hashWebTTYConfig,
|
|
431
|
+
hashWebTTYServerProofTranscript,
|
|
432
|
+
hashWebTTYSessionKeyGrant,
|
|
433
|
+
loadWebTTYKnownServerKeysFile,
|
|
434
|
+
openWebTTYCommand,
|
|
435
|
+
parseWebDAVMultiStatus,
|
|
436
|
+
parseWebTTYKnownServerKey,
|
|
437
|
+
readWebTTYKnownServerKeysFile,
|
|
438
|
+
renderWebTTYRecordedTextLog,
|
|
439
|
+
resolveWebTTYExecutionURL,
|
|
440
|
+
resolveWebTTYFileSystemURL,
|
|
441
|
+
runWebTTYCommand,
|
|
442
|
+
signWebTTYClientProofTranscript,
|
|
443
|
+
signWebTTYServerProofTranscript,
|
|
444
|
+
verifyWebTTYClientProofTranscript,
|
|
445
|
+
verifyWebTTYServerProofTranscript,
|
|
446
|
+
webTTYClientProofTranscriptBytes,
|
|
447
|
+
webTTYE2EKeyID,
|
|
448
|
+
webTTYRecordedEventEncryptedPayload,
|
|
449
|
+
webTTYServerProofTranscriptBytes,
|
|
450
|
+
webTTYSigningKeyID
|
|
451
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
RSTREAM_WEBTTY_URL='https://host.example.t.rstream.io?rstream.token=XXX'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# `rstream-webtty-filesystem-sidecar-example`
|
|
2
|
+
|
|
3
|
+
Example of using `@rstreamlabs/webtty` to read and write files through the optional WebDAV filesystem sidecar.
|
|
4
|
+
|
|
5
|
+
The sample only needs the WebTTY URL. If you build an inventory-driven integration, pass the advertised `fs_path` from `rstream webtty list -o json` as the SDK `fsPath` option.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
cp .env.local.example .env.local
|
|
9
|
+
npm install
|
|
10
|
+
npm start
|
|
11
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rstream-webtty-filesystem-sidecar-example",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Example of using the WebTTY filesystem sidecar through rstream.",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@rstreamlabs/webtty": "file:../..",
|
|
9
|
+
"dotenv": "^17.2.2"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "tsx src/main.ts",
|
|
13
|
+
"type-check": "tsc --noEmit"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^25",
|
|
17
|
+
"tsx": "^4.21.0",
|
|
18
|
+
"typescript": "5.9.3"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// See LICENSE file in the project root for license information.
|
|
2
|
+
|
|
3
|
+
import dotenv from "dotenv";
|
|
4
|
+
import { WebTTYFileSystem } from "@rstreamlabs/webtty";
|
|
5
|
+
|
|
6
|
+
dotenv.config({ path: ".env.local" });
|
|
7
|
+
|
|
8
|
+
function env(name: string): string {
|
|
9
|
+
const value = process.env[name];
|
|
10
|
+
if (value) return value;
|
|
11
|
+
throw new Error(`Missing required environment variable: ${name}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function readText(stream: ReadableStream<Uint8Array>): Promise<string> {
|
|
15
|
+
const reader = stream.getReader();
|
|
16
|
+
const chunks = await readChunks(reader);
|
|
17
|
+
reader.releaseLock();
|
|
18
|
+
return new TextDecoder().decode(Buffer.concat(chunks));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function readChunks(
|
|
22
|
+
reader: ReadableStreamDefaultReader<Uint8Array>,
|
|
23
|
+
chunks: readonly Uint8Array[] = [],
|
|
24
|
+
): Promise<readonly Uint8Array[]> {
|
|
25
|
+
const result = await reader.read();
|
|
26
|
+
return result.done ? chunks : readChunks(reader, [...chunks, result.value]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function main(): Promise<void> {
|
|
30
|
+
const fs = new WebTTYFileSystem({
|
|
31
|
+
url: env("RSTREAM_WEBTTY_URL"),
|
|
32
|
+
});
|
|
33
|
+
await fs.writeFile("/codex-note.txt", "written through rstream WebTTY\n");
|
|
34
|
+
console.log(await fs.readdir("/"));
|
|
35
|
+
console.log(await fs.readText("/codex-note.txt"));
|
|
36
|
+
console.log(await readText(await fs.readStream("/codex-note.txt")));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
main().catch((error) => {
|
|
40
|
+
console.error(error);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"esModuleInterop": true,
|
|
4
|
+
"forceConsistentCasingInFileNames": true,
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"target": "ES2022",
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*.ts"]
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
RSTREAM_WEBTTY_URL='wss://host.example.t.rstream.io?rstream.token=XXX'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# `rstream-webtty-remote-command-example`
|
|
2
|
+
|
|
3
|
+
Example of using `@rstreamlabs/webtty` to run collected and streaming commands through a WebTTY server.
|
|
4
|
+
|
|
5
|
+
The sample only needs the WebTTY URL. If you build an inventory-driven integration, pass the advertised `exec_path` from `rstream webtty list -o json` as the SDK `execPath` option.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
cp .env.local.example .env.local
|
|
9
|
+
npm install
|
|
10
|
+
npm start
|
|
11
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rstream-webtty-remote-command-example",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Example of running WebTTY commands through rstream.",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@rstreamlabs/webtty": "file:../..",
|
|
9
|
+
"dotenv": "^17.2.2"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "tsx src/main.ts",
|
|
13
|
+
"type-check": "tsc --noEmit"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^25",
|
|
17
|
+
"tsx": "^4.21.0",
|
|
18
|
+
"typescript": "5.9.3"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// See LICENSE file in the project root for license information.
|
|
2
|
+
|
|
3
|
+
import dotenv from "dotenv";
|
|
4
|
+
import { WebTTYRemoteExecutor } from "@rstreamlabs/webtty";
|
|
5
|
+
|
|
6
|
+
dotenv.config({ path: ".env.local" });
|
|
7
|
+
|
|
8
|
+
function env(name: string): string {
|
|
9
|
+
const value = process.env[name];
|
|
10
|
+
if (value) return value;
|
|
11
|
+
throw new Error(`Missing required environment variable: ${name}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function main(): Promise<void> {
|
|
15
|
+
const executor = new WebTTYRemoteExecutor({
|
|
16
|
+
url: env("RSTREAM_WEBTTY_URL"),
|
|
17
|
+
});
|
|
18
|
+
const result = await executor.runCommand("sh", ["-lc", "uname -a && pwd"], {
|
|
19
|
+
timeoutMs: 30_000,
|
|
20
|
+
});
|
|
21
|
+
console.log({ exitCode: result.exitCode, stdout: result.stdout });
|
|
22
|
+
const command = await executor.openCommand("sh", [
|
|
23
|
+
"-lc",
|
|
24
|
+
"for i in 1 2 3; do echo tick:$i; sleep 1; done",
|
|
25
|
+
]);
|
|
26
|
+
for await (const entry of command.logs()) {
|
|
27
|
+
process[entry.stream === "stdout" ? "stdout" : "stderr"].write(entry.data);
|
|
28
|
+
}
|
|
29
|
+
const status = await command.wait();
|
|
30
|
+
if (!status.success)
|
|
31
|
+
throw new Error(`Remote command exited with ${status.exitCode}.`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
main().catch((error) => {
|
|
35
|
+
console.error(error);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"esModuleInterop": true,
|
|
4
|
+
"forceConsistentCasingInFileNames": true,
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"target": "ES2022",
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*.ts"]
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rstreamlabs/webtty",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Client-side implementation of the rstream WebTTY protocol.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rstreamlabs/rstream-js",
|
|
8
|
+
"directory": "packages/webtty"
|
|
9
|
+
},
|
|
5
10
|
"license": "Apache-2.0",
|
|
6
11
|
"main": "./dist/index.js",
|
|
7
12
|
"module": "./dist/index.mjs",
|
|
8
13
|
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./node": {
|
|
21
|
+
"types": "./dist/node.d.ts",
|
|
22
|
+
"import": "./dist/node.mjs",
|
|
23
|
+
"require": "./dist/node.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
9
27
|
"files": [
|
|
10
28
|
"dist",
|
|
29
|
+
"examples",
|
|
11
30
|
"README.md"
|
|
12
31
|
],
|
|
13
32
|
"scripts": {
|
|
@@ -18,6 +37,7 @@
|
|
|
18
37
|
"lint": "eslint \"./**/*.ts*\"",
|
|
19
38
|
"pretest": "npm run generate-proto-files && npm run build",
|
|
20
39
|
"test": "node --test ./test/**/*.test.cjs",
|
|
40
|
+
"test:runtime": "node ./test/runtime-e2e.mjs",
|
|
21
41
|
"type-check": "tsc --noEmit"
|
|
22
42
|
},
|
|
23
43
|
"devDependencies": {
|
|
@@ -25,13 +45,13 @@
|
|
|
25
45
|
"@types/node": "^25",
|
|
26
46
|
"eslint-config": "*",
|
|
27
47
|
"eslint": "9.39.4",
|
|
28
|
-
"protobufjs-cli": "^2.0
|
|
48
|
+
"protobufjs-cli": "^2.4.0",
|
|
29
49
|
"tsup": "^8.5.1",
|
|
30
50
|
"typescript-config": "*",
|
|
31
51
|
"typescript": "5.9.3"
|
|
32
52
|
},
|
|
33
53
|
"dependencies": {
|
|
34
|
-
"protobufjs": "^8.0
|
|
54
|
+
"protobufjs": "^8.4.0"
|
|
35
55
|
},
|
|
36
56
|
"publishConfig": {
|
|
37
57
|
"access": "public"
|