@johnhenry/wsh 0.50.0 → 0.51.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 +99 -14
- package/bin/wsh-objects-types.mjs +98 -0
- package/package.json +7 -2
- package/spec/objects.md +176 -0
- package/src/objects-core.mjs +112 -14
- package/src/objects-mcp.mjs +130 -0
- package/src/objects-schema.mjs +143 -0
- package/src/objects-type-text.mjs +95 -0
- package/src/objects-types.d.ts +38 -0
- package/src/objects-types.mjs +290 -0
- package/src/objects.d.ts +113 -5
- package/src/objects.mjs +4 -1
- package/src/page-host.d.ts +2 -2
- package/src/page-host.mjs +29 -9
- package/src/webmcp.mjs +17 -4
package/README.md
CHANGED
|
@@ -667,6 +667,7 @@ bundler drop what you do not use.
|
|
|
667
667
|
| `@johnhenry/wsh/testing` | the QMux record and frame codec (`encodeStream`, `encodeRecord`, `RecordDecoder`, `decodeFrames`, the varint and the other frame encoders), for a test that reads, alters and re-wraps what travels on a connection; and two test doubles for code that embeds wsh: `createInProcessPipeRelay({ tap })` (the real pipe relay in this process, with a `WebSocket` that dials it, a record of every message it copied, and a `tap` that may change, drop, repeat or add to what it writes, like a hostile relay) and `createMemoryPair({ host, username })` (a memory host and a client already logged in to it). **Experimental: not part of the stable API**; it may change or disappear in any release. Importing only the codec costs under 1 kB: the doubles are separate exports a bundler drops |
|
|
668
668
|
| `@johnhenry/wsh/identity` | a key in its four spellings, and `authorized_keys` lines: `fingerprint` and `podId` of a raw key, `fingerprintToPodId` / `podIdToFingerprint`, `rawKeyToOpenSsh` / `openSshToRawKey` / `parseOpenSshKey` / `publicKeyToOpenSsh`, `identityOf`, `normalizeIdentity`, `authorizedKeyLine`. Stable; see [Identity and capabilities for other implementations](#identity-and-capabilities-for-other-implementations-220) |
|
|
669
669
|
| `@johnhenry/wsh/duplex` | a full wsh session over a duplex of messages another library provides: `serveWshOverDuplex(host, { send })`, `connectWshOverDuplex({ send }, credentials)`, `createDuplexSocket`. Sealed by default; see [wsh over a duplex](#wsh-over-a-duplex-220) |
|
|
670
|
+
| `@johnhenry/wsh/objects-types` | `describeRootTypes(description, { name })`: the `.d.ts` text for a root of `wsh-objects`, from what a key may do (a pure function), and `checkTypeText`; see [Typed remotes](#typed-remotes-219) |
|
|
670
671
|
| `@johnhenry/wsh/capabilities` | `permits(capabilities, request)`: the notation of key capabilities as a pure function, the one `@johnhenry/wsh/server` and the memory host evaluate. Stable; same section |
|
|
671
672
|
| `@johnhenry/wsh/spec/*.json`, `*.md`, `wsh-v1.yaml` | the data files of the specification: `capabilities.md`, `capabilities.vectors.json`, `key-options.vectors.json`, the wire spec |
|
|
672
673
|
| `@johnhenry/wsh/server` | Node only |
|
|
@@ -698,8 +699,9 @@ optional ML-KEM backend, is left out of the measurement. What a page ships is wh
|
|
|
698
699
|
| `@johnhenry/wsh/reverse` (whole entry point) | 221.7 kB | 68.6 kB |
|
|
699
700
|
| `@johnhenry/wsh/pipe-relay` (whole entry point) | 7.0 kB | 3.0 kB |
|
|
700
701
|
| `@johnhenry/wsh/testing` (whole entry point) | 241.2 kB | 76.0 kB |
|
|
701
|
-
| `@johnhenry/wsh/page` (whole entry point) |
|
|
702
|
-
| `@johnhenry/wsh/objects` (whole entry point) |
|
|
702
|
+
| `@johnhenry/wsh/page` (whole entry point) | 327.0 kB | 104.1 kB |
|
|
703
|
+
| `@johnhenry/wsh/objects` (whole entry point) | 201.5 kB | 62.0 kB |
|
|
704
|
+
| `@johnhenry/wsh/objects-types` (whole entry point) | 10.2 kB | 4.2 kB |
|
|
703
705
|
| `@johnhenry/wsh/capabilities` (whole entry point) | 10.6 kB | 3.8 kB |
|
|
704
706
|
| `@johnhenry/wsh/identity` (whole entry point) | 15.7 kB | 5.7 kB |
|
|
705
707
|
| `@johnhenry/wsh/duplex` (whole entry point) | 140.1 kB | 42.4 kB |
|
|
@@ -934,10 +936,16 @@ await release(cart); // gives its place back; everything
|
|
|
934
936
|
so, `handles: { window: { wideEntries: true } }` (in `createPageHost`, `wideEntries: true` beside `mode: 'handles'`), or lists the paths. A wildcard in `get` alone needs no acknowledgement. A values root is not affected.
|
|
935
937
|
- **Capabilities.** `objects:ROOT[:OP]` apply unchanged: an operation through a handle is the same `get`, `call`, `set` of the producing path (a key with `objects:window:get` can read through a handle and cannot call through it).
|
|
936
938
|
- **What a handle is not.** The host's real object stays in the page: calling a method runs the page's code with the caller's plain-data arguments, as for any `call`; a handle to an object with a powerful method is as powerful as that method's entry in `call`. A handle is
|
|
937
|
-
a reference to something already reachable by a path, so it cannot reach more than the path's own entries; but a wide entry (`window.app.**`) covers every member of every object under it.
|
|
939
|
+
a reference to something already reachable by a path, so it cannot reach more than the path's own entries; but a wide entry (`window.app.**`) covers every member of every object under it. Callbacks are one-way (see below).
|
|
940
|
+
- **Events through a handle** (`on(use(handle).bus, 'ready', listener)`, or `on(use(handle), ...)` when the handle is the source itself). The source is the handle's **producing path extended as written**, and it is judged exactly as a path subscription for that
|
|
941
|
+
path would be: an `allow.on` entry that names that path and the type exactly (no wildcard in either), the key's `objects:ROOT:on`, and `authorize` (`op.text` is the extended path, `op.type` the type). **Never implied by `get` or `call`**, and never inherited: the same object reached by
|
|
942
|
+
another path is a different path with its own entry. A node handle keeps its rules (no node handle without `nodes: true`; the graph members need an entry that names them). The subscription **ends with the handle**: `release(handle)` takes the page's listener out
|
|
943
|
+
and drops what it had queued; it also ends with the channel, Stop, a navigation and a revoke, as a path subscription does. A handle released while its subscription was being authorized leaves no listener. `maxSubscriptions`, the rate, size and queue bounds and the drop counting are the same ones, shared with path subscriptions.
|
|
944
|
+
The delivery is the same too: plain copies, never the event, never a handle.
|
|
938
945
|
|
|
939
|
-
A host says what it supports with its roots (`features`: `events`, `callbacks`, and `handles` when a root opted in). A client does not send a function to a host that has not said it supports callbacks, nor use events on one that has not said so
|
|
940
|
-
a handle
|
|
946
|
+
A host says what it supports with its roots (`features`: `events`, `callbacks`, and `handles` and `handle-events` when a root opted in). A client does not send a function to a host that has not said it supports callbacks, nor use events on one that has not said so, nor subscribe through
|
|
947
|
+
a handle on one that has not said `handle-events` (0.50.0 and before; a named `unsupported` error, nothing is sent);
|
|
948
|
+
a handle-shaped answer from a host that never said it supports handles is the same error. A 0.47.0 host says nothing, so it counts as supporting none of them. A 0.50.0 client never sends a handle subscription (it refuses to write one), so it is unaffected by a 0.51.0 host.
|
|
941
949
|
|
|
942
950
|
#### Callbacks
|
|
943
951
|
|
|
@@ -957,6 +965,34 @@ await release(fn); // kills the stub (a
|
|
|
957
965
|
- The call with callbacks is a `call` for `authorize` (`op.callbacks` is how many) and for the key's `objects:ROOT:call` capability. A callback is a channel for the page's own code to push plain values to the caller: it can send whatever the page's code puts in it, within the bounds, so list `(callback)` only on calls whose
|
|
958
966
|
stub the page will use for what the caller should see.
|
|
959
967
|
|
|
968
|
+
#### An MCP face for allow-listed paths (#219)
|
|
969
|
+
|
|
970
|
+
An MCP client can use named paths of a root without the objects client: `exposeObjects({ roots, allow, mcp: { tools: [...] } })` (and, in a page host, `createPageHost({ expose: { window: { allow, mcp: { tools: [...] } } } })`, with paths relative to the root) makes **exactly the paths it names** into MCP tools:
|
|
971
|
+
|
|
972
|
+
```js
|
|
973
|
+
const handler = exposeObjects({
|
|
974
|
+
roots: { window }, allow: { get: ['window.document.title'], call: ['window.app.cart.add', 'window.app.cart.clearAll'] },
|
|
975
|
+
mcp: { tools: [
|
|
976
|
+
{ name: 'cart_add', description: 'Add a product to the cart', call: 'window.app.cart.add',
|
|
977
|
+
inputSchema: { type: 'object', properties: { sku: { type: 'string', minLength: 1 }, qty: { type: 'integer', minimum: 1 } }, required: ['sku'], additionalProperties: false } },
|
|
978
|
+
{ name: 'page_title', description: 'The title of the page', get: 'window.document.title' },
|
|
979
|
+
] },
|
|
980
|
+
}); // clearAll is allowed by call and is NOT a tool: nothing is a tool by being allowed
|
|
981
|
+
const mcp = webmcpTools({ window, tools: handler.mcpTools, allow: handler.mcpToolNames }); // createPageHost does this itself; any host with `rpc: { mcp }` or serveMcpOverDuplex can
|
|
982
|
+
```
|
|
983
|
+
|
|
984
|
+
- **What a tool is.** A **call** of one named method (`call: 'window.app.cart.add'`), or a **get** of one named value (`get: 'window.document.title'`; add `readOnly: true` to skip the question for it); a literal member path (no wildcard, no path through a call result), that the allow-lists name for that operation and that needs no listing it does not have (checked when the host is created: a tool never widens
|
|
985
|
+
the allow-list, and a path that is not listed there is a `TypeError`, not a silent tool). Each tool has a host-authored `name`, `description` and `inputSchema`, and `readOnly` (**only `readOnly: true` marks a tool read-only, a get included: with nothing said a tool asks the person like any other, because a getter can have effects**). `args: 'object'` passes the validated input as the call's one argument (the default when the schema lists properties), `args: ['a', 'b']` passes those properties as the arguments in order.
|
|
986
|
+
There is no tool for an event, a handle or a callback, and none can be made: an argument is plain data, a result is plain data or an error (a function, or an object that is not plain data, is an error that says so, never a handle).
|
|
987
|
+
- **Arguments are validated before anything runs.** `inputSchema` is checked against the far side's arguments before the person is asked and before the page's function is called, by a small bounded subset of JSON Schema (`type`, `enum`, `const`, `properties`, `required`, `additionalProperties`, `items`, `minItems`, `maxItems`, `minLength`, `maxLength`, `minimum`, `maximum`, `anyOf`; depth 8, 2000 values; no key that climbs to a prototype). **A schema that uses another keyword
|
|
988
|
+
(`$ref`, `pattern`, `oneOf`, ...) is refused when the host is created**, so what is advertised is what is checked. Write `additionalProperties: false`: with `args: 'object'` an extra property is passed to the page's function otherwise. The arguments then go through the same copy as an objects call.
|
|
989
|
+
- **The same approval, bounds and label as the WebMCP bridge**, because they are served by the same handler: a tool that is not marked read-only asks the person at the page first (`approve`, `prompt`; with no way to ask it is denied); `maxInputBytes`, `maxResultBytes`, `maxInflight`, `maxCallsPerMinute`, the call timeout, the schema size; every result is labelled untrusted page content (`_meta['wsh/untrusted']`); a page function that throws is an error result with its message and no stack.
|
|
990
|
+
`onCall` sees the calls. Remember what a read-only mark is: the host's word. A getter that has effects is still a getter, and marking it read-only skips the question.
|
|
991
|
+
- **Two notations, both required.** A key lists and calls a tool only if its capabilities permit `mcp:TOOL` (or `mcp:*`) **and** the operation on that root (`objects:ROOT` or `objects:ROOT:call` for a call, `objects:ROOT` or `objects:ROOT:get` for a get): `capabilities="mcp:cart_add,objects:window:call"`. A key that has a capability line with `mcp:TOOL` and no `objects:` entry for the root sees no tool and can call none; a key with `objects:` and no `mcp:` entry cannot open the channel. A key with no capability line has both, as for every capability.
|
|
992
|
+
The `objects:` grant is asked again when the tool runs, with the allow-list, the names that need listing and `authorize(who, op)` (`op.kind` is `get` or `call`): **a tool never widens what the objects client would be allowed for that key.**
|
|
993
|
+
- **What it does not do.** It does not make the page's function safe (it runs with the page's authority and the caller's arguments); it does not label a result as true, only as untrusted; it is no more than the allow-list plus the tool list plus the approval, and a wide allow-list entry under a tool path does not widen the tool (the tool names one path) but does widen the objects client. Wire: nothing new (the existing `mcp` channel and its methods); Rust hosts and clients have no `wsh-objects`, so there is no Rust equivalent of the host side,
|
|
994
|
+
but a Rust `wsh --sealed --via ... mcp` reaches a page host's `mcp` channel and so lists and calls these tools like any others.
|
|
995
|
+
|
|
960
996
|
**The indicator is best effort.** The page host shows a visible element while a session is connected, puts it back if the page removes it, and has a Stop button. Page code can always remove or cover a DOM element, and a tool or a
|
|
961
997
|
function the caller may call runs with the page's authority. What holds is **Stop and revoke** (they close the channel from the page's own code, whatever is on screen) and **the key's capabilities and the host's allow-lists**.
|
|
962
998
|
|
|
@@ -975,9 +1011,35 @@ reach is exactly the paths the lists name (and, below a `get`, the plain data in
|
|
|
975
1011
|
written by third parties.
|
|
976
1012
|
- A sealed session, a key login and a visible indicator (the page host) are what keep a relay and an unknown caller out; `authorize` is where an embedder asks the person.
|
|
977
1013
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1014
|
+
Size: see the size table (`npm run size`) for `@johnhenry/wsh/objects` (it contains the client and the checks the host runs on a type map), `@johnhenry/wsh/objects-types` and the page entry point. A capability per root and operation (`objects:ROOT[:OP]`) is described under [per-key capabilities](#authorized-key-options-122).
|
|
1015
|
+
Not built yet: a dial-out form.
|
|
1016
|
+
|
|
1017
|
+
#### Typed remotes (#219)
|
|
1018
|
+
|
|
1019
|
+
`@johnhenry/wsh/objects` ships `.d.ts`; `client.openObjects<T>()` returns `T`, so a typed Proxy is a `T` you give it. Three ways, from least to most generated:
|
|
1020
|
+
|
|
1021
|
+
1. **Write the value types.** `Remote<T>` maps a value type to the reference type (it `await`s to the value, has the members as references, and its methods return references); `RemoteRoots<T>` does it for the roots:
|
|
1022
|
+
`const { shop } = await client.openObjects<RemoteRoots<{ shop: Shop }>>(); const n: number = await shop.cart.add({ sku: 'A' });`. It says what you believe the host exposes; the host's allow-lists still decide. A reference is `PromiseLike`, not a `Promise`
|
|
1023
|
+
(there is no `catch` or `finally` on it: `ref.catch` is a remote property), and arguments stay plain data. `RemoteHandle<T>` carries a value type to `use(handle)`.
|
|
1024
|
+
2. **Generate them for the key that connects.** `describeRootTypes(description, { name })` from `@johnhenry/wsh/objects-types` is a **pure function** that returns the text of a `.d.ts` for one root, and `rootDescription(page.window)` fetches the `description`
|
|
1025
|
+
(the host's `types` answer): the host's allow-list entries for that root, narrowed by **this key's** `objects:ROOT:OP` capabilities, and the host's type map. A path appears in the file only if an entry names it for an operation the key holds; an operation the key lacks,
|
|
1026
|
+
a path no entry names, and a member the host refuses are not there at all (not even as `never`). A plain value is `RemoteValue<unknown>` (a `PromiseLike<unknown>`), a call is `RemoteCall<unknown[], unknown, ...>` (`(...args: unknown[]) => PromiseLike<unknown>`, continuing as the members the allow-list names under `f()`),
|
|
1027
|
+
a wildcard (`*`, `**`) is `RemoteUntyped` (`any`: the members behind it are not guessed), `allow.on` and `eventFields` become typed `on` overloads (a source offers its listed types, and a listener gets `{ type, timeStamp, isTrusted, ...fields }` or `{ type, args }`),
|
|
1028
|
+
and an entry in `allow.set` makes `set(ref, key, value)` check the key. Use it as `client.openObjects<{ window: WindowRemote }>()`.
|
|
1029
|
+
3. **Add precise types as the host.** `exposeObjects({ types: { 'window.app.cart.add': { args: '[item: { sku: string }]', result: 'number' }, 'window.document.title': { value: 'string' }, 'window.app.bus@ready': { data: '{ n: number }' } } })`
|
|
1030
|
+
(`createPageHost({ expose: { window: { types } } })` takes the same with paths relative to the root). `value` is the awaited value of a get (or the value a set takes), `args` a tuple and `result` the awaited value of a call, `data` what an event listener receives; a text may use `RemoteHandle<{ ... }>`.
|
|
1031
|
+
|
|
1032
|
+
**The host's type text is untrusted text.** It travels to the far side and is written into a file, so the far side checks it again: `checkTypeText` accepts a conservative subset of type syntax (identifiers, literals, and the punctuation of object, tuple, function, union, intersection, generic, conditional and indexed types) and refuses a new line or anything
|
|
1033
|
+
outside printable ASCII, comments (`//`, `/*`), `\`, backticks, `@`, `#`, the words `import`, `export`, `require`, `declare`, `module`, `namespace`, `global`, `typeof`, `class`, `function`, `enum`, `interface` and `eval`, unbalanced or mismatched brackets, a `;` outside braces and a `,` outside any bracket (so a text cannot close the declaration it sits in or add a member to it).
|
|
1034
|
+
Bounds: 1024 characters a text, 256 entries and 32 KiB for a root, 16 levels of nesting. A text is also refused unless an allow-list entry names its path for the operation it types, **when the host is created** and again when the far side builds the file. The text is **never evaluated**: it is copied into the string `describeRootTypes` returns, and nothing is written to a file
|
|
1035
|
+
unless you do it (the CLI below writes only when given `--out`, and not over an existing file without `--force`). A path segment that is not an identifier is written as a quoted name.
|
|
1036
|
+
|
|
1037
|
+
**What the types do not promise.** They are advisory and erased before anything runs: a type never widens what the host allows, and `authorize`, the always-refused names and the paths that must be named (`fetch`, cookies, storage, ...) still refuse at call time whatever the file says; a type can be wrong (the host's text is what the host believes, and
|
|
1038
|
+
a hand-written `T` is what you believe); `authorize` is dynamic and is not reflected; a wildcard region is untyped; whether a value arrives as a plain value, a named non-value or a handle depends on the page's data at run time, which no file can say (on a root with handles a get is `unknown` unless the host typed it `RemoteHandle<...>`); and the file describes the key that fetched it:
|
|
1039
|
+
another key gets another file, and a key that changes or expires changes the answer. The `types` answer tells a key the allow-list entries it may use, which is what `describe` would reveal path by path and nothing about a member the key may not reach.
|
|
1040
|
+
|
|
1041
|
+
**The CLI.** `wsh-objects-types [--root NAME] [--name TYPE] [--out FILE [--force]] [--sealed] [--host-key KEY] [--identity FILE] [user@]<url>` (the package's second bin; JavaScript only) connects like `wsh-mcp` does, asks for the description of one root and prints the declarations, or writes them with `--out`.
|
|
1042
|
+
The Rust `wsh` has no `wsh-objects` client and no equivalent. A host before 0.51.0 does not state the `types` feature in the `features` of its `roots` answer, and `rootDescription` then refuses with a named `unsupported` error without sending anything.
|
|
981
1043
|
|
|
982
1044
|
### WebTransport listener
|
|
983
1045
|
|
|
@@ -1648,6 +1710,26 @@ wsh-host` works (it is the same rpc channel, and a handy check). `wsh mcp` follo
|
|
|
1648
1710
|
`SessionData` with credit (#191), so `wsh mcp --sealed` and `wsh --via <pipe relay> mcp` work against a JS host, as the npm `wsh-mcp --sealed` does. Not covered: WebTransport (`https://`) opens the channel's stream but the Rust client has only
|
|
1649
1711
|
been run against WebSocket hosts.
|
|
1650
1712
|
|
|
1713
|
+
**Rust: `wsh objects`** reads and drives a host's remote objects (`wsh-objects`, written down in `spec/objects.md`; `rust-v0.18.0` carries it). It is a client only, for **sealed sessions only**:
|
|
1714
|
+
|
|
1715
|
+
```
|
|
1716
|
+
wsh --sealed [--via RELAY] objects user@host roots
|
|
1717
|
+
wsh --sealed [--via RELAY] objects user@host get window.document.title
|
|
1718
|
+
wsh --sealed [--via RELAY] objects user@host call window.app.cart.add '{"sku":"A1"}' 2 # each argument is one JSON value
|
|
1719
|
+
wsh --sealed [--via RELAY] objects user@host set window.app.n 5
|
|
1720
|
+
wsh --sealed [--via RELAY] objects user@host snapshot window.app.state --depth 3
|
|
1721
|
+
wsh --sealed [--via RELAY] objects user@host describe window.app
|
|
1722
|
+
wsh --sealed [--via RELAY] objects user@host watch window.app.bus@ready --field detail --count 3
|
|
1723
|
+
wsh --sealed [--via RELAY] objects user@host session # JSON requests on stdin, one answer line each: one connection, so a handle can be held across calls
|
|
1724
|
+
```
|
|
1725
|
+
|
|
1726
|
+
JSON on stdout. Plain data is printed as the JSON it is; bytes as `{"$bytes":"<base64>"}`, what the host could not clone as `{"$nonValue":{"kind":"function","type":"fn"}}`, a handle as `{"$handle":{...}}` (a page can build plain data that looks like these: this is an inspection format; use the library where that matters).
|
|
1727
|
+
**Text from the page is never interpreted**: names, strings, previews and error messages are printed as JSON strings in which every control character, C1 control, line or paragraph separator and bidirectional-text control is a `\uXXXX` escape. `watch` prints one line per event, `{"seq":N,"dropped":N,"dropped_here":N,"data":...}`: `dropped` is what the host dropped before it (its bounds: rate, size, queue), `dropped_here` what this side dropped when its bounded queue was full.
|
|
1728
|
+
Exit status: 0 done; 1 other failure; 2 usage, or not `--sealed`; 3 the host refused (its allow-lists, a key's `objects:` capability, a bound); 4 not found; 5 unsupported (the host does not state the channel, or `events` / `handles`, which are refused locally before anything is sent). `wsh --help objects` lists the rest.
|
|
1729
|
+
|
|
1730
|
+
In Rust code, `wsh_client::objects::ObjectsClient::open(&client)` gives `roots()`, `root(name)` and a `Target` with `get` / `call` / `construct` / `set` / `snapshot` / `describe` / `resolve(Chain)` (a whole chain such as `app.getCart().items` is one request) and `subscribe` (a bounded `Subscription`), with typed `ObjectsError`s (`Refused`, `Limit`, `NotFound`, `Unsupported`, ...) carrying the host's `reason`, values as a serde-friendly `Value` (bytes native), and `Handle`s (released with `release()`, when dropped, and when the session ends).
|
|
1731
|
+
**What it cannot do:** callbacks (passing a function to the host), events through a handle (the host offers none), and serving objects (`wsh-server` has no page host and no `wsh-objects` handler); WebTransport and Windows are not exercised. It protects nothing the host's allow-lists do not: it only speaks to a host that chose to expose objects.
|
|
1732
|
+
|
|
1651
1733
|
### Host key (fingerprint / TOFU)
|
|
1652
1734
|
|
|
1653
1735
|
Give the server an identity and the stock client can pin it:
|
|
@@ -2151,7 +2233,7 @@ instead of dragging its own toolchain and CI job into an unrelated
|
|
|
2151
2233
|
browser-app repo. It was previously deleted from clawser by accident
|
|
2152
2234
|
(2026-03-14) and restored (2026-07-05) before this move.
|
|
2153
2235
|
|
|
2154
|
-
Four crates, workspace-versioned (currently `0.
|
|
2236
|
+
Four crates, workspace-versioned (currently `0.18.0`):
|
|
2155
2237
|
|
|
2156
2238
|
| Crate | Kind | Description |
|
|
2157
2239
|
|-------|------|--------------|
|
|
@@ -2321,8 +2403,11 @@ than left to be found.
|
|
|
2321
2403
|
| Signals and resize for a one-off command | `session.signal()`, `session.resize()` | `wsh host command` forwards SIGINT/SIGTERM/SIGHUP (the same signal twice disconnects); `wsh --tty host command` also forwards terminal resizes | **Wire-unified** (`Signal`, `Resize`). The Rust `wsh-server` delivers `Signal` (#145) to a pty session's foreground process group (what ^C reaches) and to an exec-on-pipes command's own process group, for `HUP INT QUIT TERM KILL USR1 USR2 WINCH CONT STOP TSTP ALRM` (with or without `SIG`); another name is ignored, and only the control attachment of the connection that owns the channel can send one. Not delivered on Windows |
|
|
2322
2404
|
| Dial target | a URL | `wsh [user@]host` (dials `https://` then `wss://` on `--port`), or a full URL: `wsh wss://host:8443/rendezvous/ab12 command`, `ws://127.0.0.1:PORT/` | **CLI-only convenience**: a URL is dialled exactly as given (no transport fallback; `--port` and `--transport` do not apply). Plain `ws://` is accepted only to a loopback host |
|
|
2323
2405
|
| Host that runs in a browser page (`createMemoryHost`, `@johnhenry/wsh/reverse`) | yes, with injected `pty` / `fs` / `hostKey` | no (a Rust host is a process) | **JS-only**. A Rust *client* can operate such a host only with `dataStreams: false` (#132): the released Rust client over WebSocket cannot open QMux data streams, and says nothing in `Hello` that a host could use to decide. `wsh scp` works against such a host with the Rust client of the next `rust-v` release (it speaks `FileChunk`, #140); a released `rust-v0.11.0` or older `wsh scp` hangs against it (`wsh ls` and exec work) |
|
|
2324
|
-
| A page's WebMCP tools served as MCP, behind a pipe relay (#190) | `createPageHost`, `webmcpTools`, `captureWebMcp` from `@johnhenry/wsh/page`; the far side is `wsh-mcp --sealed` or `openRpc('mcp')` | the far side only: `wsh --sealed --via <relay>/r/<id> mcp user@host` (the Rust CLI, `rust-v0.17.1`+) lists and calls a page host's tools (`test/rust/wsh-mcp-page-host.test.mjs`); the Rust
|
|
2325
|
-
| Remote objects by path, `values` mode (#190): `wsh-objects`, `client.openObjects()` | `exposeObjects` / `createObjectsServer` / `createPageHost({ expose })` host side; `get`, `set`, `call`, `construct`, `snapshot`, `describe` far side (`@johnhenry/wsh/objects`) |
|
|
2406
|
+
| A page's WebMCP tools served as MCP, behind a pipe relay (#190) | `createPageHost`, `webmcpTools`, `captureWebMcp` from `@johnhenry/wsh/page`; the far side is `wsh-mcp --sealed` or `openRpc('mcp')` | the far side only: `wsh --sealed --via <relay>/r/<id> mcp user@host` (the Rust CLI, `rust-v0.17.1`+) lists and calls a page host's tools (`test/rust/wsh-mcp-page-host.test.mjs`); the Rust `wsh objects` is a `wsh-objects` client (next row), and no Rust host serves either | **JS-only** host (a page); the far side is unchanged wire (`mcp` rpc in virtual mode, #191) |
|
|
2407
|
+
| Remote objects by path, `values` mode (#190): `wsh-objects`, `client.openObjects()` | `exposeObjects` / `createObjectsServer` / `createPageHost({ expose })` host side; `get`, `set`, `call`, `construct`, `snapshot`, `describe` far side (`@johnhenry/wsh/objects`) | **Client only** (`rust-v0.18.0`, #219): `wsh_client::objects` (`ObjectsClient`, values mode, events with a bounded `Subscription`, handles) and `wsh --sealed [--via RELAY] objects user@host roots\|get\|call\|set\|snapshot\|describe\|watch\|session` (sealed sessions only; JSON on stdout; exit 3 refused, 4 not found, 5 unsupported); a feature the host does not state is refused locally. Not built: callbacks, events through a handle. `wsh-server` serves no `wsh-objects` and refuses an `objects:` key capability. The wire is `spec/objects.md`; tested against a real page host through a recording relay (`test/rust/wsh-objects.test.mjs`) | **JS host, Rust or JS far side**; an rpc protocol on the existing `rpc` channel (no new message or feature string), so a released peer simply does not offer or open it. The Rust codec gained a CBOR-value read path so byte strings survive (the existing `rpc` channels still reject them) |
|
|
2408
|
+
| Events through a handle (#219): `on(use(handle).path, type, listener)` | `@johnhenry/wsh/objects` (`exposeObjects({ handles })`); the host states `handle-events` in the `features` of its `roots` answer | none: no Rust `wsh-objects` client or host | **JS-only**; a new `subscribe` parameter (`handle`) on the existing `wsh-objects` rpc channel, offered only to a client that saw `handle-events`. A 0.50.0 host does not say it, and a new client then refuses to subscribe through a handle with a named `unsupported` error without sending anything; a 0.50.0 client cannot write such a request |
|
|
2409
|
+
| Typed remotes (#219): `describeRootTypes`, `rootDescription`, `Remote<T>`, `wsh-objects-types` | `@johnhenry/wsh/objects` (the `types` method, the `types` option, `Remote<T>`, `RemoteRoots<T>`), `@johnhenry/wsh/objects-types` (the pure generator), the `wsh-objects-types` bin | none: no Rust `wsh-objects` client or host, and the Rust CLI has no equivalent of the bin | **JS-only**; a new `types` method on the existing `wsh-objects` rpc channel and a `types` string in the `features` of its `roots` answer (no new message type or `ServerHello` feature). A 0.50.0 host does not state it, and a new client then refuses with a named `unsupported` error and sends nothing; a 0.50.0 client never calls it |
|
|
2410
|
+
| An MCP face for named object paths (#219): `exposeObjects({ mcp: { tools } })`, `createPageHost({ expose: { ROOT: { mcp: { tools } } } })` | `@johnhenry/wsh/objects` (`handler.mcpTools`, `server.invoke`) served by `webmcpTools` / `serveMcpOverDuplex` on the `mcp` channel; the far side is any MCP client (`wsh-mcp --sealed`, `client.openRpc('mcp')`) | the far side only: `wsh --sealed --via <relay>/r/<id> mcp user@host` lists and calls these tools like any `mcp` tool; no Rust `wsh-objects` host | **JS-only host**; **wire: nothing new** (the existing `mcp` rpc channel and its methods, no feature string), so any released MCP-speaking peer reaches it |
|
|
2326
2411
|
| Interactive shell UI | none -- this SDK is a protocol client, not a terminal emulator; pair with xterm.js/ghostty-web | `wsh connect`, `wsh sftp` (line-oriented REPL) | **Deliberately not unified** -- a browser embeds a terminal widget the host page owns; a CLI process owns its own TTY |
|
|
2327
2412
|
| Attach / resume | `attachSession()`, `resumeSession()`, `WshSession.seq` | `attach_session()`, `resume_session()` | **Wire-unified** (`Attach`/`Resume`/`Presence`); `seq` = cumulative output bytes. `@johnhenry/wsh/server` honours `last_seq` (bounded ring, gap errors) and answers Presence with `channel_id`/`seq`; the Rust `wsh-server` does the same (`rust-v0.2.0`+; fixed 256 KiB ring) |
|
|
2328
2413
|
| Reverse-connect / relay peer | `connectReverse()`, `trustRelayPeer()`; `@johnhenry/wsh/server`: `relay` option and `createReverseHost()` | `wsh reverse`, `wsh agent` (persistent, with startup-unit install) | **Wire-unified** (registration, discovery, signed peer records); **daemonization is CLI-only** -- a browser tab cannot be a background OS service. The Node relay is default-deny and bridges one operator per peer unless `maxOperatorsPerPeer` is raised (`busy:` reasons say so); E2E and bridged feature gates need `rust-v0.3.0`+ on the Rust side. **Several operators per peer (#93): both relays** (`maxOperatorsPerPeer`; `[relay] max_operators_per_peer`, default 1) **and both peers** (`createReverseHost({ maxOperators })`; `wsh --max-operators n reverse` / `agent run`, default 1), negotiated by `relay-multi-operator`; a Rust peer serving several operators does not seal bridges (see the reverse-mode notes), and the Rust relay leaves a peer connected when its operator leaves. The signed `KeyExchange` (`e2e-sign`) is carried by the Rust relay too |
|
|
@@ -2401,7 +2486,7 @@ plus one `SHA256SUMS` file covering every archive in the release. These
|
|
|
2401
2486
|
names are a stable contract other repos (clawser) pin and download by --
|
|
2402
2487
|
do not change them without coordinating downstream.
|
|
2403
2488
|
|
|
2404
|
-
`wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.
|
|
2489
|
+
`wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.18.0`), which is the
|
|
2405
2490
|
number in the `rust-vX.Y.Z` tag. Binaries of `rust-v0.9.0` to `rust-v0.10.0` printed a fixed `0.1.0`, so against one of those the
|
|
2406
2491
|
version cannot be read from the binary (look for a flag in `wsh --help` instead).
|
|
2407
2492
|
|
|
@@ -2524,9 +2609,9 @@ out explicitly below rather than left to be discovered.
|
|
|
2524
2609
|
a hop that can read the duplex reads every tool result and every value. The capability notation (`spec/capabilities.md`) is a **reading** of a list, not a
|
|
2525
2610
|
credential: an implementation that reads it more loosely than the vectors say grants more than the list does, which is why the vectors are shipped.
|
|
2526
2611
|
- **`wsh-objects` (`@johnhenry/wsh/objects`, #190) lets a key read, call and set the paths an allow-list names on the roots a host names, and nothing else.** An allow-list of paths means what it says
|
|
2527
|
-
only because nothing but cloneable values crosses (no handles in `values` mode; on a root that opted in to [handles](#handles), a handle is judged by the path that produced it and never widens it, and nodes need their own opt-in); what it cannot make safe is stated in
|
|
2612
|
+
only because nothing but cloneable values crosses (no handles in `values` mode; on a root that opted in to [handles](#handles), a handle is judged by the path that produced it and never widens it, and nodes need their own opt-in; an event subscription through a handle needs the producing path's own `allow.on` entry and ends with the handle); what it cannot make safe is stated in
|
|
2528
2613
|
[Remote objects](#remote-objects-johnhenrywshobjects-190): a getter or a setter on an allowed path runs, a called function does whatever it does with the page's authority, a wide pattern means its width, and a
|
|
2529
|
-
few paths (`document.cookie`, storage, `fetch`, ...) need an entry that names them. Object access is off on every host unless `exposeObjects` or `createPageHost({ expose })` is written, and `rpc:wsh-objects` is the key capability that gates it.
|
|
2614
|
+
few paths (`document.cookie`, storage, `fetch`, ...) need an entry that names them. The generated types (#219) are advisory text: the host's type map is host-authored text that is checked, bounded and never evaluated (see [Typed remotes](#typed-remotes-219)), and the file says only what the fetching key may do. The MCP face for named paths (#219) is the allow-list **plus** a list of the paths that are tools, **plus** the WebMCP bridge's approval for any tool not marked read-only: a tool needs the key's `mcp:TOOL` and `objects:ROOT:OP`, its arguments are validated before the person is asked, its results are labelled untrusted, and it makes no handle, event or callback; a called function still does whatever it does with the page's authority. Object access is off on every host unless `exposeObjects` or `createPageHost({ expose })` is written, and `rpc:wsh-objects` is the key capability that gates it.
|
|
2530
2615
|
- **`wsh-mcp` runs as a client with your key (#127).** It reads a private key file you point it at (no passphrase support: protect the
|
|
2531
2616
|
file, `0600`), logs in as you and hands the MCP client everything the host's `mcp` channel serves; whatever the MCP client (or the
|
|
2532
2617
|
model behind it) asks of those tools is done as you. It does not pin the host unless you pass `--host-key` (it warns once on stderr),
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// wsh-objects-types (#219): connect to a wsh host that serves `wsh-objects` (a page host behind a relay, any host with `exposeObjects`), ask what THIS key may do on one
|
|
3
|
+
// root, and write the TypeScript declarations for it. JavaScript only: the Rust CLI has no `wsh-objects` client. Nothing is evaluated: the host's type texts are checked and
|
|
4
|
+
// copied, and the file is written only when --out is given.
|
|
5
|
+
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
import { userInfo } from 'node:os';
|
|
9
|
+
import { writeFile } from 'node:fs/promises';
|
|
10
|
+
import { loadIdentity, defaultIdentityPath, McpBridgeError } from '../src/mcp-stdio.mjs';
|
|
11
|
+
import { WshClient } from '../src/index.mjs';
|
|
12
|
+
import { openObjects, rootDescription } from '../src/objects.mjs';
|
|
13
|
+
import { describeRootTypes } from '../src/objects-types.mjs';
|
|
14
|
+
|
|
15
|
+
const { version } = createRequire(import.meta.url)('../package.json');
|
|
16
|
+
|
|
17
|
+
const HELP = `wsh-objects-types ${version} -- the TypeScript types of a root of wsh-objects, for what this key may do
|
|
18
|
+
|
|
19
|
+
Usage: wsh-objects-types [options] [user@]<url>
|
|
20
|
+
|
|
21
|
+
<url> ws://, wss:// or https:// URL of the wsh host (a host serving the rpc channel "wsh-objects"; a page host: its operator URL)
|
|
22
|
+
-l, --user NAME login name (default: the user@ part of the URL, else $WSH_USER, $USER, or the OS user)
|
|
23
|
+
-i, --identity FILE Ed25519 private key (default: ~/.wsh/keys/default.pem, the key \`wsh keygen\` makes)
|
|
24
|
+
--root NAME the root to describe (default: the only one the key may use; required when there are several)
|
|
25
|
+
--name TYPE the name of the exported type (default: the root's name, capitalised, plus Remote)
|
|
26
|
+
-o, --out FILE write the declarations to FILE (default: standard output). An existing file is not overwritten without --force
|
|
27
|
+
--force overwrite --out
|
|
28
|
+
--sealed seal the whole session end to end and refuse a host that cannot (a host behind a relay, a page); key login only
|
|
29
|
+
--host-key KEY pin the host: a hex fingerprint, or an ssh-ed25519 line (default: not pinned, with a warning)
|
|
30
|
+
--timeout MS to log in and to open the channel (default: 15000)
|
|
31
|
+
-h, --help this text
|
|
32
|
+
-V, --version
|
|
33
|
+
|
|
34
|
+
The declarations say only what the key that connected may do (the host's allow-lists narrowed by that key's capabilities); values are \`unknown\` unless the host
|
|
35
|
+
supplied a type, which is checked and copied as text, never evaluated. Use it as: client.openObjects<{ window: WindowRemote }>().
|
|
36
|
+
Exit status: 0 written, 2 it could not be done.
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const fail = (message) => { process.stderr.write(`wsh-objects-types: ${message}\n`); process.exit(2); };
|
|
40
|
+
|
|
41
|
+
let parsed;
|
|
42
|
+
try {
|
|
43
|
+
parsed = parseArgs({
|
|
44
|
+
allowPositionals: true,
|
|
45
|
+
options: {
|
|
46
|
+
user: { type: 'string', short: 'l' },
|
|
47
|
+
identity: { type: 'string', short: 'i' },
|
|
48
|
+
root: { type: 'string' },
|
|
49
|
+
name: { type: 'string' },
|
|
50
|
+
out: { type: 'string', short: 'o' },
|
|
51
|
+
force: { type: 'boolean' },
|
|
52
|
+
sealed: { type: 'boolean' },
|
|
53
|
+
'host-key': { type: 'string' },
|
|
54
|
+
timeout: { type: 'string' },
|
|
55
|
+
help: { type: 'boolean', short: 'h' },
|
|
56
|
+
version: { type: 'boolean', short: 'V' },
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
} catch (e) { fail(`${e.message}\nTry \`wsh-objects-types --help\`.`); }
|
|
60
|
+
const { values, positionals } = parsed;
|
|
61
|
+
if (values.help) { process.stdout.write(HELP); process.exit(0); }
|
|
62
|
+
if (values.version) { process.stdout.write(`${version}\n`); process.exit(0); }
|
|
63
|
+
if (positionals.length !== 1) fail('exactly one host URL is required. Try `wsh-objects-types --help`.');
|
|
64
|
+
|
|
65
|
+
let url = positionals[0];
|
|
66
|
+
let userFromUrl;
|
|
67
|
+
const at = url.indexOf('@');
|
|
68
|
+
if (at > 0 && !url.slice(0, at).includes('/') && !url.slice(0, at).includes(':')) { userFromUrl = url.slice(0, at); url = url.slice(at + 1); }
|
|
69
|
+
if (!/^(wss?|https?):\/\//.test(url)) fail(`${url}: expected a ws://, wss:// or https:// URL`);
|
|
70
|
+
const timeout = values.timeout === undefined ? 15_000 : Number(values.timeout);
|
|
71
|
+
if (!Number.isInteger(timeout) || timeout < 1) fail('--timeout must be a whole number of at least 1');
|
|
72
|
+
const username = values.user ?? userFromUrl ?? process.env.WSH_USER ?? process.env.USER ?? userInfo().username;
|
|
73
|
+
|
|
74
|
+
const client = new WshClient();
|
|
75
|
+
let code = 0;
|
|
76
|
+
try {
|
|
77
|
+
let signer;
|
|
78
|
+
try { signer = await loadIdentity(values.identity ?? defaultIdentityPath()); } catch (e) { throw e instanceof McpBridgeError ? e : new Error(e?.message ?? String(e)); }
|
|
79
|
+
await client.connect(url, { username, signer, timeout, ...(values['host-key'] ? { expectHostKey: values['host-key'] } : {}), ...(values.sealed ? { sealSession: true } : {}) });
|
|
80
|
+
const page = await openObjects(client);
|
|
81
|
+
const roots = Object.keys(page);
|
|
82
|
+
if (roots.length === 0) throw new Error('this key may use no root of the host');
|
|
83
|
+
const root = values.root ?? (roots.length === 1 ? roots[0] : undefined);
|
|
84
|
+
if (root === undefined) throw new Error(`the host has several roots the key may use (${roots.join(', ')}): choose one with --root`);
|
|
85
|
+
if (!roots.includes(root)) throw new Error(`no root ${JSON.stringify(root)} that this key may use (${roots.join(', ')})`);
|
|
86
|
+
const text = describeRootTypes(await rootDescription(page[root]), values.name === undefined ? {} : { name: values.name });
|
|
87
|
+
if (values.out === undefined) process.stdout.write(text);
|
|
88
|
+
else {
|
|
89
|
+
await writeFile(values.out, text, { flag: values.force ? 'w' : 'wx', mode: 0o644 });
|
|
90
|
+
process.stderr.write(`wsh-objects-types: wrote ${values.out}\n`);
|
|
91
|
+
}
|
|
92
|
+
} catch (e) {
|
|
93
|
+
process.stderr.write(`wsh-objects-types: ${e?.code === 'EEXIST' ? `${values.out} exists (--force overwrites it)` : (e?.message ?? e)}\n`);
|
|
94
|
+
code = 2;
|
|
95
|
+
} finally {
|
|
96
|
+
await client.disconnect().catch(() => {});
|
|
97
|
+
}
|
|
98
|
+
process.exit(code);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/wsh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Web Shell \u2014 browser-native remote command execution over WebTransport and WebSocket with Ed25519 authentication",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
"types": "./src/objects.d.ts",
|
|
38
38
|
"import": "./src/objects.mjs"
|
|
39
39
|
},
|
|
40
|
+
"./objects-types": {
|
|
41
|
+
"types": "./src/objects-types.d.ts",
|
|
42
|
+
"import": "./src/objects-types.mjs"
|
|
43
|
+
},
|
|
40
44
|
"./testing": {
|
|
41
45
|
"types": "./src/testing.d.ts",
|
|
42
46
|
"import": "./src/testing.mjs"
|
|
@@ -62,7 +66,8 @@
|
|
|
62
66
|
"./spec/wsh-v1.yaml": "./spec/wsh-v1.yaml"
|
|
63
67
|
},
|
|
64
68
|
"bin": {
|
|
65
|
-
"wsh-mcp": "./bin/wsh-mcp.mjs"
|
|
69
|
+
"wsh-mcp": "./bin/wsh-mcp.mjs",
|
|
70
|
+
"wsh-objects-types": "./bin/wsh-objects-types.mjs"
|
|
66
71
|
},
|
|
67
72
|
"sideEffects": false,
|
|
68
73
|
"types": "./src/index.d.ts",
|
package/spec/objects.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# The `wsh-objects` protocol (remote objects)
|
|
2
|
+
|
|
3
|
+
Status: describes what `@johnhenry/wsh/objects` (`src/objects-core.mjs`, `src/objects.mjs`) serves and speaks as of 0.50.0, and what the Rust client
|
|
4
|
+
(`wsh_client::objects`, `wsh objects`) speaks. It adds nothing to the wire: this file only writes down what the code does. The JavaScript
|
|
5
|
+
implementation is the reference; where this text and `src/objects-core.mjs` differ, the code is right and this file is a bug.
|
|
6
|
+
|
|
7
|
+
A host names some **roots** (objects: a page's `window`, a worker's `self`, a Node object). A peer reaches into them **by path** and only
|
|
8
|
+
**cloneable values** cross: plain data, or a name for what is not plain data. There is no distributed object graph. What may be read, called,
|
|
9
|
+
set or listened to is decided by the host's allow-lists (paths with `*` and `**`), by `authorize`, and by the key's capabilities
|
|
10
|
+
(`objects:ROOT[:OP]`, `spec/capabilities.md`); the protocol only carries the request and the refusal.
|
|
11
|
+
|
|
12
|
+
## 1. The channel
|
|
13
|
+
|
|
14
|
+
An rpc channel of protocol `wsh-objects` (`rpc-protocol:wsh-objects` in `ServerHello.features`), opened as any rpc channel is: `Open { kind: rpc,
|
|
15
|
+
command: "wsh-objects" }`. On a sealed session or behind a relay the host states `rpc-virtual` and the channel rides `SessionData` (inside the
|
|
16
|
+
seal) with `GatewayCredit` backpressure; otherwise it is a data stream. Messages are a CBOR sequence (RFC 8742) of JSON-RPC 2.0 messages
|
|
17
|
+
(`{ jsonrpc: "2.0", id, method, params }`, `{ jsonrpc, id, result }`, `{ jsonrpc, id, error: { code, message, data? } }`, notifications without
|
|
18
|
+
`id`), bounded by `rpc-max-message:<n>` (default 1 MiB). `$/cancel { id }` cancels a request; `$/progress` is not used by this protocol.
|
|
19
|
+
|
|
20
|
+
A path is an array of segments in requests (`["app","cart","items"]`), and text with dots for people (`window.app.cart.items`). The first segment of
|
|
21
|
+
the text form is the root.
|
|
22
|
+
|
|
23
|
+
## 2. Requests (peer to host)
|
|
24
|
+
|
|
25
|
+
Every `params` is an object. A request names where it starts: `root: "window"` (a root the host listed) or `handle: "<id>"` (section 5), never both.
|
|
26
|
+
|
|
27
|
+
| method | params | result |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| `roots` | `{}` | `{ roots: [name…], features: [string…] }` |
|
|
30
|
+
| `resolve` | `{ root \| handle, ops: [op…] }` | a **wire value** (section 3) |
|
|
31
|
+
| `set` | `{ root \| handle, path: [seg…], value }` | `{ ok: true }` |
|
|
32
|
+
| `describe` | `{ root \| handle, path?: [seg…] }` | `{ type, keys: [{ key, type, own }…], truncated? }` |
|
|
33
|
+
| `snapshot` | `{ root \| handle, path?: [seg…], depth?, maxBytes? }` | a wire value; `truncated: true` when a subtree deeper than `depth` was cut to `null` |
|
|
34
|
+
| `subscribe` | `{ id, root, path?: [seg…], type, fields?: [name…] }` | `{ ok: true }` |
|
|
35
|
+
| `unsubscribe` | `{ id }` | `{ ok: true, dropped }` |
|
|
36
|
+
| `release` | `{ handle }` | `{ ok: true }` |
|
|
37
|
+
| `releaseCallback` | `{ id }` | `{ ok: true }` |
|
|
38
|
+
|
|
39
|
+
`roots` lists only the roots the key may use (`objects:ROOT[:OP]`). `features` is what the host supports: `events`, `callbacks` and (when a root opted
|
|
40
|
+
in) `handles`. A host that says nothing (before 0.48.0) supports none of them; a peer must not use a feature the host did not state.
|
|
41
|
+
|
|
42
|
+
**`resolve`** walks a whole chain in one request. `ops` is up to 32 operations, each an object with exactly one of:
|
|
43
|
+
|
|
44
|
+
- `{ get: key }` read a member;
|
|
45
|
+
- `{ call: key, args?: [value…], callbacks?: [[index, id]…] }` call the method `key` of the current value (`this` is the current value);
|
|
46
|
+
- `{ construct: key, args?, callbacks? }` `new` the constructor `key`.
|
|
47
|
+
|
|
48
|
+
The chain continues on the result of each step, so `window.app.getCart().items` is `get app, call getCart, get items`. The path an operation is
|
|
49
|
+
judged by is the keys so far, with `()` after a called one (`window.app.getCart().items`): that is what an allow-list entry names. The last operation
|
|
50
|
+
is the one the allow-list must allow (`get`, or `call`/`construct` from the `call` list); the ones before it need only be on the way to something
|
|
51
|
+
the host allows. At most 16 arguments (`maxArgs`). `callbacks` are section 6.
|
|
52
|
+
|
|
53
|
+
`set` assigns the last segment of `path` on the object the rest of it reaches. `describe` lists the names the allow-lists could walk to from the path
|
|
54
|
+
(`type` is `null`, `boolean`, `number`, `string`, `array`, `object`, `function`, `accessor`…). `snapshot` is a bounded deep copy: `depth` (whole
|
|
55
|
+
number, at most the host's `maxDepth`, 8) and `maxBytes` bound it.
|
|
56
|
+
|
|
57
|
+
**`subscribe`** listens to an event source named by an `allow.on` entry `path@type`: the object at `path` must have `addEventListener` /
|
|
58
|
+
`removeEventListener` or `on` / `off`. `id` is a whole number chosen by the peer, at least 1, not yet used on the channel. `type` is a name of
|
|
59
|
+
letters, digits and `_ $ : . -` (up to 128). `fields` (at most 16) are extra event properties the host lists for the type (`eventFields`); a field it
|
|
60
|
+
does not offer is `not-allowed`. A subscription cannot be made through a handle (0.50.0): `subscribe` takes a `root` only.
|
|
61
|
+
|
|
62
|
+
## 3. Wire values
|
|
63
|
+
|
|
64
|
+
The result of `resolve`, `snapshot` is one of:
|
|
65
|
+
|
|
66
|
+
| shape | meaning |
|
|
67
|
+
|---|---|
|
|
68
|
+
| `{ v: <plain> }` | plain data, plus `truncated: true` on a `snapshot` that cut something |
|
|
69
|
+
| `{ u: <kind>, type?, text? }` | a **named non-value**: something that cannot be cloned |
|
|
70
|
+
| `{ h: <id>, kind, type?, preview?: { keys: [name…] } }` | an opaque **handle** (section 5), only on a root that opted in and only if `features` has `handles` |
|
|
71
|
+
|
|
72
|
+
**Plain data** is `null`, booleans, numbers (integers as CBOR integers, others as floats), text, **bytes** (a CBOR byte string: an `ArrayBuffer`,
|
|
73
|
+
a typed array or a `DataView` on the host), arrays and plain objects with text keys. Inside an object or array the rule is JSON's: a member that
|
|
74
|
+
cannot be cloned (a function, a node, a class instance, a symbol, an accessor property, `undefined`, a cycle) is left out of an object and is `null`
|
|
75
|
+
in an array; the keys `__proto__`, `constructor` and `prototype` are never copied. An integer of 2^63 or more is not plain data (a non-value
|
|
76
|
+
`number`). A value is at most `maxDepth` (8) deep and `maxValueBytes` (256 KiB, and under the channel's message bound less 4096) long, else the
|
|
77
|
+
request is refused with `limit`.
|
|
78
|
+
|
|
79
|
+
**Named non-values**, `u` is one of:
|
|
80
|
+
|
|
81
|
+
| `u` | what it names | `type` / `text` |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| `undefined` | `undefined` | |
|
|
84
|
+
| `function` | a function | `type`: its name, when printable |
|
|
85
|
+
| `symbol` | a symbol | |
|
|
86
|
+
| `bigint` | a bigint | `text`: its digits |
|
|
87
|
+
| `number` | an integer too large for the wire | `text`: its rendering |
|
|
88
|
+
| `Date` | a date | `text`: ISO 8601 (or `Invalid Date`) |
|
|
89
|
+
| `RegExp` | a regular expression | `text`: its source and flags |
|
|
90
|
+
| `Error` | an error or `DOMException` | `type`: class name, `text`: its message (up to 200 characters) |
|
|
91
|
+
| `object` | any other object: a class instance, a node, a Map | `type`: its class name |
|
|
92
|
+
|
|
93
|
+
`type` is up to 64 printable ASCII characters. **Everything in `type`, `text`, names, previews and strings is the page's own text: untrusted.** A
|
|
94
|
+
peer prints it escaped and never interprets it.
|
|
95
|
+
|
|
96
|
+
**Values sent to the host** (`args`, `set`'s `value`) are plain data only: `null`, booleans, numbers, text, bytes, arrays, plain objects. The host
|
|
97
|
+
refuses any other kind (`bad-request`), a key `__proto__`, `constructor` or `prototype` (`always-refused`), values deeper than 8 or longer than
|
|
98
|
+
`maxValueBytes`.
|
|
99
|
+
|
|
100
|
+
## 4. Always-refused names and the rules that hold for every allow-list
|
|
101
|
+
|
|
102
|
+
Whatever an allow-list says, these are refused (reason `always-refused`): the path segments `__proto__`, `prototype`, `constructor`,
|
|
103
|
+
`__defineGetter__`, `__defineSetter__`, `__lookupGetter__`, `__lookupSetter__`, `eval`, `Function`, `import`, `execScript`; `call`, `apply` and
|
|
104
|
+
`bind` of a function; `setTimeout`, `setInterval` and `setImmediate` called with a string. A segment is a string of 1 to 256 characters with no
|
|
105
|
+
`.`. The names in `NEEDS_LISTING` (`document.cookie`, `localStorage`, `sessionStorage`, `indexedDB`, `navigator.credentials`, `fetch`,
|
|
106
|
+
`XMLHttpRequest`, `postMessage`, `open`; and on a root with handles the members that climb back to the window or document) are refused (reason
|
|
107
|
+
`needs-listing`) until an allow-list entry **names** them: a wildcard does not.
|
|
108
|
+
|
|
109
|
+
## 5. Handles
|
|
110
|
+
|
|
111
|
+
On a root that the host says opts in (`features` has `handles`), a function or an object that is not plain data comes back as a handle
|
|
112
|
+
`{ h, kind: "function" | "object", type?, preview? }` instead of a named non-value. A handle is **path-bound**: it stands at the path that produced
|
|
113
|
+
it, and every operation through it (`resolve`, `set`, `describe`, `snapshot` with `handle` in place of `root`) is judged by the allow-lists for that
|
|
114
|
+
path extended by the member named; a handle never widens what the path grants. `preview.keys` (up to 8 names) is told only where a `get` of the
|
|
115
|
+
path would be allowed. The id is 22 characters of base64url from the host's CSPRNG, valid on this channel only (another channel or key finds
|
|
116
|
+
nothing: `bad-request` "no such handle"). The table holds 64 handles per channel (`maxHandles`); more is `limit` and **nothing is evicted**. A
|
|
117
|
+
handle is given back by `release` and all of them when the channel ends. A handle is not an argument: it means something only on its own channel.
|
|
118
|
+
|
|
119
|
+
## 6. Callbacks
|
|
120
|
+
|
|
121
|
+
A function of the peer may be passed to a `call` or `construct` whose allow-list entry ends in `(callback)`: its place in `args` is `null` and
|
|
122
|
+
`callbacks` lists `[argumentIndex, id]` (`id` a whole number from 1, the same function the same id). The host's stub is **one-way**: calling it
|
|
123
|
+
copies its arguments as plain data, queues a `callback` notification and returns `undefined` at once. The host sends
|
|
124
|
+
`callback { id, seq, args: [value…], dropped? }`; calls beyond `maxCallbacksPerSecond` (20), larger than `maxCallbackBytes` (16 KiB), or when the
|
|
125
|
+
queue is full are dropped and counted (`dropped`, told with the next delivered call). There are at most 16 callbacks per channel
|
|
126
|
+
(`maxCallbacks`). `releaseCallback` kills a stub. `features` has `callbacks`.
|
|
127
|
+
|
|
128
|
+
## 7. Notifications (host to peer)
|
|
129
|
+
|
|
130
|
+
- `event { id, seq, data, dropped? }`: `id` is the subscription's, `seq` counts the delivered events of that subscription from 1. `data` is plain: for
|
|
131
|
+
an EventTarget source `{ type, timeStamp, isTrusted, ...fields }`, for an emitter `{ type, args: [value…] }`. `dropped` (when present) is the
|
|
132
|
+
number of events the host dropped (rate `maxEventsPerSecond` 20 per subscription, size `maxEventBytes` 16 KiB, queue `maxQueuedEvents` 100 per
|
|
133
|
+
channel, a slow reader) since the last one it delivered for that subscription. At most 16 subscriptions per channel.
|
|
134
|
+
- `callback { id, seq, args, dropped? }`: section 6.
|
|
135
|
+
- `closing { reason }`: the host is about to end the channel (the page left, Stop was pressed, a key was revoked).
|
|
136
|
+
|
|
137
|
+
A peer treats a notification for an id it does not know as noise.
|
|
138
|
+
|
|
139
|
+
## 8. Errors and limits
|
|
140
|
+
|
|
141
|
+
An error response is `{ code, message, data: { reason, ... } }`. `message` is a sentence for a person and may carry page-controlled text.
|
|
142
|
+
|
|
143
|
+
| `code` | meaning | `reason` (in `data`) |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| `-32003` | refused | `always-refused`, `not-allowed` (allow-list, or an event type or field the host does not offer), `needs-listing`, `authorize` (the host's `authorize` said no), `not-permitted` (the key's `objects:` capability does not allow the operation on the root), `gone` (the page left) |
|
|
146
|
+
| `-32002` | a bound | `limit`, with `limit` (the name: `maxOps`, `maxArgs`, `maxDepth`, `maxValueBytes`, `maxRequestsPerSecond`, `maxHandles`, `maxCallbacks`, `maxSubscriptions`, `callTimeoutMs`) and `max` |
|
|
147
|
+
| `-32602` | invalid | `bad-request`, `no-such-root` |
|
|
148
|
+
| `-32000` | failed | `bad-path` (reading a member of `null` or `undefined`), `not-a-function`, `threw` (the called code threw), `refused-by-object` (a read-only or frozen assignment), `not-an-event-source`, `cancelled`, `closed` |
|
|
149
|
+
| `-32601`, `-32600`, `-32603`, `-32001` | the rpc layer's own: method not found, invalid request, internal error, cancelled | |
|
|
150
|
+
|
|
151
|
+
`-32002` is also the rpc layer's `stream-limit` (more than 64 requests in flight). The bounds, per attached channel: 32 operations per `resolve`,
|
|
152
|
+
16 arguments, depth 8, 256 KiB per value, 200 keys per `describe`, 50 requests per second, 30 s for a call that returns a promise, and the counts
|
|
153
|
+
of sections 5 to 7.
|
|
154
|
+
|
|
155
|
+
## 9. Keys and the host's switches
|
|
156
|
+
|
|
157
|
+
The caller's key may carry `capabilities="objects:ROOT[:OP]"` (`spec/capabilities.md`): a key that names any `objects:` entry is limited to what they
|
|
158
|
+
name (the operation is `get`, `call` (also `construct`), `set` or `on`; `get` also covers `describe`, `snapshot` and walking), may open the
|
|
159
|
+
channel without `rpc:wsh-objects`, and is told only of the roots it can use. A key with no `objects:` entry is limited by `rpc:wsh-objects` alone.
|
|
160
|
+
The key's capability is asked again for every operation (an expiry holds at call time).
|
|
161
|
+
|
|
162
|
+
## 10. What a peer must do
|
|
163
|
+
|
|
164
|
+
- Open the channel only if the host states `rpc-protocol:wsh-objects`; on a sealed session also `rpc-virtual`.
|
|
165
|
+
- Ask `roots` first, and use only `features` the host stated; refuse locally, with a name, what it did not state, rather than send what a host
|
|
166
|
+
that does not know it would drop (a function it does not know is `null`).
|
|
167
|
+
- Treat every byte of text from the host as untrusted data; never interpret it, never let it reach a terminal unescaped.
|
|
168
|
+
- Bound what it accepts: the channel's message bound applies in both directions, and a subscriber that cannot keep up must drop and count, not stop
|
|
169
|
+
reading (stopping reading stops the host's credit, which is the host's backstop, but also every answer behind it).
|
|
170
|
+
|
|
171
|
+
## 11. What the released peers do
|
|
172
|
+
|
|
173
|
+
- JavaScript (`@johnhenry/wsh` 0.46.0 to 0.50.0): the reference described above. 0.46.0 and 0.47.0 hosts have no `features` in `roots`, no events, handles or
|
|
174
|
+
callbacks; a peer sees an empty `features`.
|
|
175
|
+
- Rust `wsh-server`: serves no `wsh-objects` channel and no page host, and refuses a key line with an `objects:` capability (an unknown capability
|
|
176
|
+
fails closed). Rust released before the `wsh_client::objects` client (`rust-v0.17.1` and earlier) has no objects client at all.
|