@query-farm/vgi 0.39.0 → 0.41.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.
@@ -1,4 +1,5 @@
1
- import { type GrantMinter, type Protocol, type TokenResolver, VgiRpcServer } from "@query-farm/vgi-rpc";
1
+ import { GrantKeys, type GrantMinter, type Protocol, type TokenResolver, VgiRpcServer } from "@query-farm/vgi-rpc";
2
+ import type { CatalogInterface } from "./catalog/interface.js";
2
3
  /** The transport a server is being built for. Only `"http"` changes what is
3
4
  * hosted (identity); the rest are recorded so the decision lives here rather
4
5
  * than at each call site. `"iroh"` is the raw TCP upstream of a
@@ -71,6 +72,19 @@ export interface HostingOptions {
71
72
  /** Maximum age of the caller's authentication for `issue_grant`, in
72
73
  * seconds. vgi-rpc's default when omitted. */
73
74
  maxAuthAge?: number;
75
+ /**
76
+ * Sealed-grant keys (vgi-rpc `GrantKeys`), turning on the framework's own
77
+ * grants on HTTP: `issue_grant` mints `vgig1.` tokens (unless
78
+ * {@link mintGrant} is supplied) and the worker's HTTP authentication accepts
79
+ * them back as bearer credentials, as the grant's owner. When omitted,
80
+ * `VGI_RPC_GRANT_KEYS` (comma-separated base64, exactly 32 bytes each, first
81
+ * mints, all verify), `VGI_RPC_GRANT_AUDIENCE` and
82
+ * `VGI_RPC_GRANT_MAX_TTL_SECONDS` are read; `serveVgiWorker` also accepts
83
+ * `--grant-key KEY` (repeatable). Unset everywhere, nothing changes. A
84
+ * malformed key refuses to start. `null` turns grants off regardless of the
85
+ * environment.
86
+ */
87
+ grantKeys?: GrantKeys | null;
74
88
  }
75
89
  /** Server-level options passed through to `VgiRpcServer`. */
76
90
  export interface BuildRpcServerOptions {
@@ -81,6 +95,19 @@ export interface BuildRpcServerOptions {
81
95
  /** Environment to read `VGI_INTROSPECT_PRINCIPALS` from. Default
82
96
  * `process.env` where it exists (not on Cloudflare Workers). */
83
97
  env?: Record<string, string | undefined>;
98
+ /**
99
+ * HTTP only: what `vgi.attach_tickets.v1` needs. Hosted when
100
+ * `signingKeyConfigured` is true -- the key came from explicit
101
+ * configuration, not generated for this process, which would make every
102
+ * ticket die on restart -- and the worker can issue grants (grant keys
103
+ * configured, or its own `mintGrant`). Otherwise the protocol is absent,
104
+ * not hosted-and-refusing.
105
+ */
106
+ attachTickets?: {
107
+ signingKey: Uint8Array | undefined;
108
+ signingKeyConfigured: boolean;
109
+ catalogInterface: CatalogInterface | undefined;
110
+ };
84
111
  }
85
112
  /**
86
113
  * Build the vgi-rpc server for a worker's `vgi.v2` protocol on `transport`.
@@ -95,3 +122,12 @@ export interface BuildRpcServerOptions {
95
122
  * on HTTP with no introspector allowlist.
96
123
  */
97
124
  export declare function buildRpcServer(primary: Protocol, hosting: HostingOptions, options: BuildRpcServerOptions): VgiRpcServer;
125
+ /**
126
+ * Collect `--grant-key KEY` / `--grant-key=KEY` (repeatable, first mints) from
127
+ * an argv, as a `GrantKeys` -- or `undefined` when none was passed, so the
128
+ * environment still applies. Audience and lifetime come from
129
+ * `VGI_RPC_GRANT_AUDIENCE` / `VGI_RPC_GRANT_MAX_TTL_SECONDS`.
130
+ *
131
+ * @throws Error A malformed key: a worker refuses to start.
132
+ */
133
+ export declare function grantKeysFromArgv(argv: readonly string[], env?: Record<string, string | undefined> | undefined): GrantKeys | undefined;
@@ -1,13 +1,21 @@
1
1
  import type { CatalogInterface } from "./catalog/interface.js";
2
2
  import type { FunctionRegistry } from "./functions/registry.js";
3
3
  import { type AuthenticateFn, type PeerResolutionOptions } from "@query-farm/vgi-rpc";
4
- import type { HostingOptions } from "./rpc-server.js";
4
+ import { type HostingOptions } from "./rpc-server.js";
5
5
  /** Environment variables `serveVgiWorker` reads. Injectable for testing. */
6
6
  export interface ServeEnv {
7
7
  PORT?: string;
8
8
  VGI_SIGNING_KEY?: string;
9
9
  VGI_TOKEN_TTL?: string;
10
10
  CORS_ORIGINS?: string;
11
+ /** Sealed-grant keys: comma-separated base64, exactly 32 bytes each, first mints. */
12
+ VGI_RPC_GRANT_KEYS?: string;
13
+ /** Audience bound into sealed grants. */
14
+ VGI_RPC_GRANT_AUDIENCE?: string;
15
+ /** Sealed-grant lifetime ceiling, seconds (default 7 days). */
16
+ VGI_RPC_GRANT_MAX_TTL_SECONDS?: string;
17
+ /** Principals allowed to call `introspect_token`, comma-separated. */
18
+ VGI_INTROSPECT_PRINCIPALS?: string;
11
19
  }
12
20
  export declare const DEFAULT_PORT = 8787;
13
21
  export declare const DEFAULT_TOKEN_TTL = 3600;
@@ -58,6 +66,10 @@ export interface ServeVgiWorkerOptions extends HostingOptions {
58
66
  quiet?: boolean;
59
67
  /** Environment source (default `process.env`). */
60
68
  env?: ServeEnv;
69
+ /** Command-line arguments to read `--grant-key KEY` (repeatable, first mints)
70
+ * from. Default `process.argv.slice(2)`. A key here takes precedence over
71
+ * `VGI_RPC_GRANT_KEYS`; an explicit {@link grantKeys} over both. */
72
+ argv?: readonly string[];
61
73
  /** Authenticates each request, returning the caller's `AuthContext`.
62
74
  * Omit for an anonymous worker (the default). */
63
75
  authenticate?: AuthenticateFn;