@query-farm/vgi 0.48.3 → 0.48.5

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.
Files changed (50) hide show
  1. package/README.md +51 -0
  2. package/dist/attach-secret-keyfile.d.ts +11 -0
  3. package/dist/attach-secret-options.d.ts +96 -0
  4. package/dist/catalog/attach-option.d.ts +6 -0
  5. package/dist/catalog/descriptors.d.ts +30 -0
  6. package/dist/catalog/interface.d.ts +43 -0
  7. package/dist/catalog/read-only.d.ts +16 -2
  8. package/dist/client-entry.js +1 -1
  9. package/dist/client-entry.js.map +4 -4
  10. package/dist/index.core.d.ts +4 -0
  11. package/dist/index.js +5854 -5234
  12. package/dist/index.js.map +28 -25
  13. package/dist/protocol/dispatch.d.ts +11 -0
  14. package/dist/protocol/handlers/catalog/admin.d.ts +1 -1
  15. package/dist/protocol/handlers/catalog/index.d.ts +1 -1
  16. package/dist/protocol/handlers/catalog/index_methods.d.ts +1 -1
  17. package/dist/protocol/handlers/catalog/macro.d.ts +1 -1
  18. package/dist/protocol/handlers/catalog/shared.d.ts +36 -3
  19. package/dist/protocol/handlers/catalog/table.d.ts +1 -1
  20. package/dist/protocol/handlers/catalog/view.d.ts +1 -1
  21. package/dist/protocol/handlers/function.d.ts +2 -0
  22. package/dist/protocol/handlers/table-buffering.d.ts +1 -1
  23. package/dist/serve-entry.d.ts +5 -0
  24. package/dist/serve-entry.js +514 -99
  25. package/dist/serve-entry.js.map +18 -16
  26. package/dist/worker-cf-entry.js +629 -108
  27. package/dist/worker-cf-entry.js.map +21 -18
  28. package/dist/worker.d.ts +10 -0
  29. package/dist/write-results.d.ts +57 -0
  30. package/package.json +1 -1
  31. package/src/attach-secret-keyfile.ts +185 -0
  32. package/src/attach-secret-options.ts +418 -0
  33. package/src/catalog/attach-option.ts +6 -0
  34. package/src/catalog/descriptors.ts +30 -0
  35. package/src/catalog/interface.ts +70 -0
  36. package/src/catalog/read-only.ts +123 -18
  37. package/src/index.core.ts +33 -0
  38. package/src/protocol/dispatch.ts +14 -2
  39. package/src/protocol/handlers/catalog/admin.ts +33 -18
  40. package/src/protocol/handlers/catalog/index.ts +6 -5
  41. package/src/protocol/handlers/catalog/index_methods.ts +5 -3
  42. package/src/protocol/handlers/catalog/macro.ts +7 -5
  43. package/src/protocol/handlers/catalog/shared.ts +69 -6
  44. package/src/protocol/handlers/catalog/table.ts +58 -19
  45. package/src/protocol/handlers/catalog/view.ts +9 -7
  46. package/src/protocol/handlers/function.ts +53 -19
  47. package/src/protocol/handlers/table-buffering.ts +2 -1
  48. package/src/serve-entry.ts +6 -1
  49. package/src/worker.ts +12 -0
  50. package/src/write-results.ts +174 -0
@@ -13,6 +13,17 @@ export interface ProtocolConfig {
13
13
  * unsealed — OS process ownership already enforces identity there.
14
14
  */
15
15
  signingKey?: Uint8Array | undefined;
16
+ /**
17
+ * Optional root key for secret ATTACH options (`AttachOptionSpec.secret`),
18
+ * which the framework encrypts inside `attach_opaque_data` so functions and
19
+ * transaction hooks can read them with `attachOptions()`. Defaults to the
20
+ * signing key when there is one (HTTP), else the host-local key file
21
+ * (`$VGI_ATTACH_SECRET_KEY_FILE`, or `vgi/attach-secret-options.key` under
22
+ * `$XDG_RUNTIME_DIR` / the per-user temp dir). Any length; the AEAD key is
23
+ * always derived from it with HKDF-SHA256. Every worker process that may
24
+ * receive a given attach must use the same key.
25
+ */
26
+ attachSecretKey?: Uint8Array | undefined;
16
27
  }
17
28
  /**
18
29
  * Wire name of the VGI protocol: the `vgi_rpc.protocol` routing key and the
@@ -1,3 +1,3 @@
1
1
  import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
3
+ export declare function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService>;
@@ -1,4 +1,4 @@
1
1
  import type { CatalogInterface } from "../../../catalog/interface.js";
2
2
  import type { VgiService } from "../../../generated/vgi-service.js";
3
3
  /** The catalog_* `vgi.v3` handlers, over *catalog* (or `NoCatalogError` without one). */
4
- export declare function catalogHandlers(catalog: CatalogInterface | undefined, signingKey?: Uint8Array): Partial<VgiService>;
4
+ export declare function catalogHandlers(catalog: CatalogInterface | undefined, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService>;
@@ -1,3 +1,3 @@
1
1
  import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function catalogIndexHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
3
+ export declare function catalogIndexHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService>;
@@ -1,3 +1,3 @@
1
1
  import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
3
+ export declare function catalogMacroHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService>;
@@ -1,5 +1,26 @@
1
1
  import type { AuthContext, CallContext } from "@query-farm/vgi-rpc";
2
2
  import type { CatalogInterface } from "../../../catalog/interface.js";
3
+ /**
4
+ * The keys a catalog handler group opens opaque values with: the HTTP signing
5
+ * key (absent on stdio / unix) and the optional explicit root key for secret
6
+ * ATTACH options (`attachSecretKey`; see ../../../attach-secret-options.ts).
7
+ */
8
+ export interface OpaqueKeys {
9
+ signingKey?: Uint8Array | undefined;
10
+ attachSecretKey?: Uint8Array | undefined;
11
+ }
12
+ /**
13
+ * The options a catalog_attach packs into the attach value after the catalog's
14
+ * own bytes (secret ones encrypted). See ../../../attach-secret-options.ts.
15
+ */
16
+ export interface AttachOptionsToPack {
17
+ /** The request's `options` IPC batch (null / empty: no options, no trailer). */
18
+ optionsIpc: Uint8Array | null | undefined;
19
+ /** Lower-cased names of the options declared `secret: true`. */
20
+ secretNames: ReadonlySet<string>;
21
+ /** Explicit root key for the secret options, if configured. */
22
+ attachSecretKey?: Uint8Array | undefined;
23
+ }
3
24
  export type GetCatalog = () => CatalogInterface;
4
25
  /**
5
26
  * Mint and seal a catalog_attach value: prepend a fresh framework UUID
@@ -7,8 +28,12 @@ export type GetCatalog = () => CatalogInterface;
7
28
  * across re-seals and globally unique, unlike the random-nonce ciphertext or
8
29
  * the (possibly non-unique) catalog bytes. openAttach strips the UUID back off
9
30
  * so the catalog only ever sees its own bytes. Mirrors vgi-python/-go.
31
+ *
32
+ * With `options`, the attach's ATTACH options are packed after the catalog's
33
+ * bytes (secret ones encrypted, never plaintext) so `attachOptions()` can hand
34
+ * them to every function call and transaction hook of this attach.
10
35
  */
11
- export declare function sealAttach(plaintext: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
36
+ export declare function sealAttach(plaintext: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined, options?: AttachOptionsToPack): Promise<Uint8Array>;
12
37
  /**
13
38
  * Open an attach envelope returning the FULL framework plaintext
14
39
  * uuid(16) || catalog_bytes (not stripped). Storage shards on the leading UUID.
@@ -19,7 +44,7 @@ export declare function openAttachFull(envelope: Uint8Array, auth: AuthContext |
19
44
  * framework UUID prefix is stripped. This is what catalog/function bodies see;
20
45
  * storage routing uses openAttachFull / deriveShardKey to reach the UUID.
21
46
  */
22
- export declare function openAttach(envelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
47
+ export declare function openAttach(envelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined, attachSecretKey?: Uint8Array): Promise<Uint8Array>;
23
48
  /**
24
49
  * deriveShardKey returns the Cloudflare-DO routing key for an attach:
25
50
  * "att-" + hex(the 16-byte framework UUID at the head of the unwrapped attach).
@@ -38,13 +63,21 @@ export declare function shardKeyForAttach(sealed: Uint8Array | undefined, auth:
38
63
  * to the caller's identity and the parent attach envelope it was minted under.
39
64
  */
40
65
  export declare function sealTransaction(plaintext: Uint8Array, attachEnvelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
66
+ /**
67
+ * Open a transaction_opaque_data envelope (sealed on HTTP only, no UUID prefix).
68
+ * `attachEnvelope` is the request's *sealed* attach, which the transaction
69
+ * envelope's AAD binds. A pass-through without a signing key or for an empty
70
+ * value. Catalog hooks and function bodies must see the same plaintext, or a
71
+ * worker cannot tie a function call to its transaction's commit/rollback.
72
+ */
73
+ export declare function openTransaction(envelope: Uint8Array, attachEnvelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined): Promise<Uint8Array>;
41
74
  /**
42
75
  * Wrap a catalog unary handler so its request opaque-data fields are unwrapped
43
76
  * before the body runs. Used for every catalog_* method except catalog_attach
44
77
  * / catalog_transaction_begin, which seal their outputs and are written
45
78
  * bespoke. The body sees the flattened params as a plain record.
46
79
  */
47
- export declare function catalogHandler<R>(signingKey: Uint8Array | undefined, handler: (params: Record<string, any>, ctx: CallContext) => R | Promise<R>): (params: object, ctx: CallContext) => Promise<R>;
80
+ export declare function catalogHandler<R>(keysOrSigningKey: OpaqueKeys | Uint8Array | undefined, handler: (params: Record<string, any>, ctx: CallContext) => R | Promise<R>): (params: object, ctx: CallContext) => Promise<R>;
48
81
  export declare function makeGetCatalog(catalog: CatalogInterface | undefined): GetCatalog;
49
82
  /**
50
83
  * Decode the `options` field of a catalog_attach request into a plain
@@ -1,3 +1,3 @@
1
1
  import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
3
+ export declare function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService>;
@@ -1,3 +1,3 @@
1
1
  import type { VgiService } from "../../../generated/vgi-service.js";
2
2
  import { type GetCatalog } from "./shared.js";
3
- export declare function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array): Partial<VgiService>;
3
+ export declare function catalogViewHandlers(getCatalog: GetCatalog, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService>;
@@ -3,6 +3,8 @@ import type { FunctionRegistry } from "../../functions/registry.js";
3
3
  export interface FunctionHandlerConfig {
4
4
  registry: FunctionRegistry;
5
5
  signingKey?: Uint8Array | undefined;
6
+ /** Explicit root key for secret ATTACH options (see attach-secret-options.ts). */
7
+ attachSecretKey?: Uint8Array | undefined;
6
8
  /**
7
9
  * Used to map a bind's `attach_opaque_data` to its catalog, so resolution can
8
10
  * be scoped when two catalogs declare the same schema and function name.
@@ -1,4 +1,4 @@
1
1
  import type { VgiService } from "../../generated/vgi-service.js";
2
2
  import type { FunctionRegistry } from "../../functions/registry.js";
3
3
  /** The table_buffering lifecycle's `vgi.v3` handlers. */
4
- export declare function tableBufferingHandlers(registry: FunctionRegistry, signingKey?: Uint8Array): Partial<VgiService>;
4
+ export declare function tableBufferingHandlers(registry: FunctionRegistry, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService>;
@@ -54,6 +54,11 @@ export interface ServeVgiWorkerOptions extends HostingOptions {
54
54
  hostname?: string | undefined;
55
55
  /** Overrides `$VGI_SIGNING_KEY`. 32 bytes. */
56
56
  signingKey?: Uint8Array | undefined;
57
+ /**
58
+ * Optional root key for secret ATTACH options (encrypted inside
59
+ * `attach_opaque_data` for `attachOptions()`). Defaults to the signing key.
60
+ */
61
+ attachSecretKey?: Uint8Array | undefined;
57
62
  /** Overrides `$VGI_TOKEN_TTL` (default 3600 seconds). */
58
63
  tokenTtl?: number | undefined;
59
64
  /** Overrides `$CORS_ORIGINS` (default "*"). Pass `null` to disable CORS. */