/*! * Copyright (c) 2026 Interop Alliance. All rights reserved. */ /** * The top-level WAS client. Wraps an ezcap `ZcapClient` (which holds the active * signer) and exposes the WAS containment model * (`SpacesRepository > Space > Collection > Resource`) through lazy * navigational handles. Also hosts the general delegation primitive * (`grant`), capability-rebuilding (`fromCapability`), and the signed * escape-hatch (`request`). */ import { ZcapClient } from '@interop/ezcap'; import type { HttpResponse } from '@interop/http-client'; import type { EncryptionProvider } from './codec.js'; import { Space } from './Space.js'; import { Collection } from './Collection.js'; import { Resource } from './Resource.js'; import type { GrantOptions, HandleOptions, IDelegatedZcap, ISigner, IZcap, Json, RequestInput, CollectionResourcesList, ResourceSummary, SpaceListing } from './types.js'; export declare class WasClient { #private; readonly serverUrl: string; readonly zcapClient: ZcapClient; readonly encryption?: EncryptionProvider; /** * @param options {object} * @param options.serverUrl {string} base URL for both URL building and * zcap `invocationTarget`s * @param options.zcapClient {ZcapClient} an ezcap client holding the signer * @param [options.encryption] {EncryptionProvider} the keystore that * supplies keys for collections declared encrypted (by their `encryption` * descriptor or a per-handle override); built by the * `@interop/was-client/edv` subpath. Omit for plaintext-only clients. It * does not decide *which* collections are encrypted -- that is the * descriptor/override -- so a missing key for an encrypted collection fails * closed rather than silently downgrading to plaintext. */ constructor({ serverUrl, zcapClient, encryption }: { serverUrl: string; zcapClient: ZcapClient; encryption?: EncryptionProvider; }); /** * Convenience constructor that builds the ezcap `ZcapClient` internally from * a signer, using the `Ed25519Signature2020` suite. * * @param options {object} * @param options.serverUrl {string} * @param options.signer {ISigner} * @param [options.encryption] {EncryptionProvider} see the constructor * @returns {WasClient} */ static fromSigner({ serverUrl, signer, encryption }: { serverUrl: string; signer: ISigner; encryption?: EncryptionProvider; }): WasClient; /** * The DID controlling the wrapped signer (`signer.id` without the key * fragment). Used to default `controller` on `createSpace`. * * @returns {string} */ get controllerDid(): string; /** * Returns a lazy handle to a space by id. No I/O. * * @param spaceId {string} * @param options {object} * @param [options.capability] {IZcap} * @returns {Space} */ space(spaceId: string, options?: HandleOptions): Space; /** * Creates a space (server-generated id unless `id` is given). `name` is * optional (both in the spec and on the reference server); `controller` must * match the wrapped signer's DID (which is the default). * * @param desc {object} * @param [desc.id] {string} * @param [desc.name] {string} * @param [desc.controller] {string} * @returns {Promise} */ createSpace(desc?: { id?: string; name?: string; controller?: string; }): Promise; /** * Lists the spaces in the repository visible to the wrapped signer, as a * `{ url, totalItems, items }` listing. Visibility is per-controller: the * result holds only the spaces whose controller the signed invocation is * authorized for. An unauthorized caller is not an error -- the server * returns an empty `items` list (the spec's explicit exception to 404 * masking), so nothing is revealed about which spaces exist. * * Transparently follows the server's `next` pagination links, buffering every * page into a single listing (the returned envelope omits `next`). Because a * paginating server omits `totalItems` on a truncated page, `totalItems` on * the aggregate is recomputed from the collected items -- sound here, since * the walk has gathered the complete listing. * * @returns {Promise} */ listSpaces(): Promise; /** * Reads a public (`PublicCanRead`) resource by its URL with no authorization * -- an unsigned `GET`, for consuming a shared public link. Auto-parses JSON * to an object and returns binary as a `Blob`. Returns `null` if the resource * is missing or not publicly readable (404 conflation caveat). * * @param options {object} * @param options.resourceUrl {string} the absolute resource URL * @returns {Promise} */ publicRead({ resourceUrl }: { resourceUrl: string; }): Promise; /** * Lists a public (`PublicCanRead`) collection by its URL with no authorization * -- an unsigned `GET` -- e.g. to browse a blog published as a public-read * collection. Transparently follows the server's `next` pagination links, * buffering every page into a single list (the returned envelope omits * `next`). For a large collection prefer `publicListCollectionPages()` or * `publicListCollectionItems()`, which stream one page at a time and allow * stopping early. Returns `null` if the collection is missing or not publicly * readable (404 conflation caveat). * * @param options {object} * @param options.collectionUrl {string} the absolute collection URL * @returns {Promise} */ publicListCollection({ collectionUrl }: { collectionUrl: string; }): Promise; /** * Lazily yields a public collection listing one page at a time, following the * server's `next` links on demand with unsigned `GET`s. Use this to stream a * large public collection in constant memory or to stop early. Yields nothing * if the collection is missing or not publicly readable (404 conflation * caveat). * * @param options {object} * @param options.collectionUrl {string} the absolute collection URL * @returns {AsyncGenerator} */ publicListCollectionPages({ collectionUrl }: { collectionUrl: string; }): AsyncGenerator; /** * Lazily yields each item of a public collection across every page, * flattening `publicListCollectionPages()`. Yields the listing's * `ResourceSummary` entries (id / url / contentType / name), not the resource * bodies. Yields nothing if the collection is missing or not publicly * readable (404 conflation caveat). * * @param options {object} * @param options.collectionUrl {string} the absolute collection URL * @returns {AsyncGenerator} */ publicListCollectionItems({ collectionUrl }: { collectionUrl: string; }): AsyncGenerator; /** * Rebuilds an access handle from a received capability, returning a handle at * the depth implied by the capability's `invocationTarget` (space / * collection / resource), pre-bound with that capability. * * @param zcap {IZcap} * @returns {Space | Collection | Resource} */ fromCapability(zcap: IZcap): Space | Collection | Resource; /** * The general delegation primitive. Delegates a capability per `GrantOptions` * and returns the signed zcap to hand off out-of-band. `target` (any URL) and * `capability` (a parent capability to attenuate) make this a superset of the * `space`/`collection` grant sugar. * * @param options {GrantOptions} * @returns {Promise} */ grant(options: GrantOptions): Promise; /** * The general revocation primitive -- the inverse of {@link grant}. Derives * the owning space from the capability's `invocationTarget` (which a * Space-rooted capability always addresses at or beneath) and submits it to * that space's revocation endpoint. Equivalent to * `was.space(id).revoke(zcap)`. * * Revocation is scoped to one space: there is no cross-space or global * revocation. See {@link Space.revoke} for who may call it, what it does and * does not withdraw, and why it is not idempotent. * * @param zcap {IDelegatedZcap} the delegated capability to revoke * @returns {Promise} */ revoke(zcap: IDelegatedZcap): Promise; /** * The signed escape hatch, mirroring ezcap's generic `request()`. Resolves * `path` against `serverUrl`, defaults `action` to `method`, and signs via the * wrapped client. Returns the raw `HttpResponse` and throws raw ky/ezcap * errors -- it does not apply the null-on-404 or typed-error conveniences. * * @param options {RequestInput} * @returns {Promise} */ request(options: RequestInput): Promise; } //# sourceMappingURL=WasClient.d.ts.map