@terminal3/t3n-sdk 0.7.0 → 0.10.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.
Files changed (49) hide show
  1. package/dist/index.d.ts +266 -294
  2. package/dist/index.esm.js +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/src/client/config.d.ts +30 -10
  5. package/dist/src/client/index.d.ts +0 -4
  6. package/dist/src/client/t3n-client.d.ts +27 -64
  7. package/dist/src/config/index.d.ts +36 -2
  8. package/dist/src/index.d.ts +9 -8
  9. package/dist/src/types/auth.d.ts +6 -5
  10. package/dist/src/types/index.d.ts +13 -37
  11. package/dist/src/utils/hkdf.d.ts +36 -0
  12. package/dist/src/utils/index.d.ts +1 -0
  13. package/dist/src/wasm/interface.d.ts +54 -89
  14. package/dist/src/wasm/loader.d.ts +55 -25
  15. package/dist/src/wasm/quote-verifier/quote_verifier_bytes.d.ts +1 -0
  16. package/dist/src/wasm/quote-verifier-loader.d.ts +58 -0
  17. package/dist/wasm/generated/interfaces/host-session-interfaces-contract-dispatch.d.ts +2 -0
  18. package/dist/wasm/generated/interfaces/host-session-interfaces-entropy.d.ts +2 -0
  19. package/dist/wasm/generated/interfaces/host-session-interfaces-eth-signer.d.ts +2 -0
  20. package/dist/wasm/generated/interfaces/host-session-interfaces-kem.d.ts +3 -0
  21. package/dist/wasm/generated/interfaces/host-session-interfaces-oidc-client.d.ts +2 -0
  22. package/dist/wasm/generated/interfaces/host-session-interfaces-oidc.d.ts +3 -0
  23. package/dist/wasm/generated/interfaces/host-session-interfaces-session-ops.d.ts +9 -0
  24. package/dist/wasm/generated/interfaces/host-session-interfaces-transport.d.ts +2 -0
  25. package/dist/wasm/generated/interfaces/tee-session-client-auth.d.ts +7 -0
  26. package/dist/wasm/generated/interfaces/tee-session-client-handshake.d.ts +12 -0
  27. package/dist/wasm/generated/interfaces/tee-session-cookie.d.ts +7 -0
  28. package/dist/wasm/generated/interfaces/tee-session-server-admin.d.ts +2 -0
  29. package/dist/wasm/generated/interfaces/tee-session-server-auth.d.ts +10 -0
  30. package/dist/wasm/generated/interfaces/tee-session-server-handshake.d.ts +15 -0
  31. package/dist/wasm/generated/interfaces/tee-session-server-webhook.d.ts +6 -0
  32. package/dist/wasm/generated/interfaces/tee-session-session-crypto.d.ts +3 -0
  33. package/dist/wasm/generated/session.core.wasm +0 -0
  34. package/dist/wasm/generated/session.core2.wasm +0 -0
  35. package/dist/wasm/generated/session.core3.wasm +0 -0
  36. package/dist/wasm/generated/session.d.ts +87 -12
  37. package/dist/wasm/generated/session.js +6640 -3702
  38. package/package.json +1 -1
  39. package/dist/demo.d.ts +0 -25
  40. package/dist/src/client/actions.d.ts +0 -22
  41. package/dist/src/client/encryption.d.ts +0 -30
  42. package/dist/src/client/handlers.d.ts +0 -73
  43. package/dist/src/client/request-parser.d.ts +0 -48
  44. package/dist/wasm/generated/interfaces/component-session-client-auth.d.ts +0 -12
  45. package/dist/wasm/generated/interfaces/component-session-client-handshake.d.ts +0 -12
  46. package/dist/wasm/generated/interfaces/component-session-cookie.d.ts +0 -8
  47. package/dist/wasm/generated/interfaces/component-session-server-auth.d.ts +0 -13
  48. package/dist/wasm/generated/interfaces/component-session-server-handshake.d.ts +0 -12
  49. package/dist/wasm/generated/interfaces/component-session-session.d.ts +0 -7
@@ -1,43 +1,73 @@
1
1
  /**
2
- * WASM Component Loader
2
+ * WASM Component Loader — async direct-call shape.
3
3
  *
4
- * This module provides utilities for loading and initializing the WASM component.
5
- * The actual WASM loading implementation will depend on the build system and
6
- * deployment environment.
4
+ * Loads the `tee:session@1.0.0` jco-transpiled component. Host
5
+ * imports (`host:session-interfaces/*`) are supplied at
6
+ * instantiation; the caller can override any of them via
7
+ * `WasmLoadConfig.hostImports` to plug a custom KEM public-key
8
+ * source, ETH signer, etc. Defaults cover the common case for the
9
+ * browser SDK:
10
+ *
11
+ * - `entropy.random`: WebCrypto `getRandomValues`
12
+ * - `kem.mlKemPublicKey`: HTTP fetch of /pubkey (caller sets URL)
13
+ * - `kem.decapsulate`: server-only; client-side stub returns error
14
+ * - `eth-signer.eth-sign`: injected wallet (window.ethereum) if present
15
+ * - `session-ops.now-ms`: Date.now()
16
+ * - `session-ops.tee-address`, `set-cookie`: caller-supplied or stubs
7
17
  */
8
18
  import { WasmComponent } from "./interface";
9
19
  import { Logger } from "../utils/logger";
20
+ /**
21
+ * Host imports supplied at WASM instantiation. Any subset may be
22
+ * overridden by the caller; unset ones fall back to a safe default
23
+ * (or an error stub for server-only methods like `decapsulate`).
24
+ */
25
+ export interface SessionHostImports {
26
+ /** Fetch the server's ML-KEM public key (client-side). */
27
+ mlKemPublicKey?: () => Uint8Array | Promise<Uint8Array>;
28
+ /** CSPRNG. Defaults to WebCrypto `getRandomValues`. */
29
+ random?: (len: number) => Uint8Array;
30
+ /** EIP-191 / SIWE signer. Defaults to error (caller must supply). */
31
+ ethSign?: (message: Uint8Array) => Uint8Array | Promise<Uint8Array>;
32
+ /**
33
+ * OIDC user-interaction callback. The contract supplies the
34
+ * server-bound `nonce`; the SDK consumer runs whatever popup /
35
+ * redirect flow is appropriate for `provider` and returns the
36
+ * IdP-signed `id_token`. Defaults to error (caller must supply
37
+ * when using OIDC auth).
38
+ */
39
+ getIdToken?: (provider: string, nonce: string) => string | Promise<string>;
40
+ /** Current time in ms. Defaults to Date.now() (as bigint). */
41
+ nowMs?: () => bigint;
42
+ /** TEE address — server-only; client stub returns 20 zero bytes. */
43
+ teeAddress?: () => Uint8Array;
44
+ /** Called when the guest emits a refreshed cookie. */
45
+ setCookie?: (value: string) => void;
46
+ /**
47
+ * HTTP transport the contract uses to POST JSON-RPC requests. The
48
+ * SDK wires this to its `Transport` under the hood — the contract
49
+ * supplies the method name and params bytes; the SDK layers on the
50
+ * Session-Id header, JSON-RPC envelope, and returns the raw result
51
+ * bytes.
52
+ */
53
+ postRpc?: (method: string, sessionId: string, params: string) => string | Promise<string>;
54
+ }
10
55
  /**
11
56
  * Configuration for WASM component loading
12
57
  */
13
58
  export interface WasmLoadConfig {
14
59
  /** Path or URL to the WASM module */
15
60
  wasmPath?: string;
16
- /** Custom fetch function for loading WASM */
17
- fetchFn?: typeof fetch;
18
- /** Additional initialization options */
19
- initOptions?: Record<string, unknown>;
20
61
  /** Optional logger instance - if not provided, uses global default */
21
62
  logger?: Logger;
63
+ /** Overrides for the host-import functions. */
64
+ hostImports?: SessionHostImports;
22
65
  }
23
66
  /**
24
- * Load and initialize the T3n WASM component
67
+ * Load and initialize the T3n WASM component (async direct-call).
25
68
  *
26
- * @param config - Optional configuration for loading the WASM component
27
- * @returns Promise that resolves to the initialized WASM component
28
- *
29
- * @example
30
- * ```typescript
31
- * const wasmComponent = await loadWasmComponent({
32
- * wasmPath: '/path/to/t3n.wasm'
33
- * });
34
- * ```
69
+ * The caller normally only needs to override `mlKemPublicKey` (to
70
+ * point at the node URL) and `ethSign` (to bridge to the browser
71
+ * wallet). All other imports have sensible defaults.
35
72
  */
36
73
  export declare function loadWasmComponent(config?: WasmLoadConfig): Promise<WasmComponent>;
37
- /**
38
- * Load the real T3n WASM component
39
- *
40
- * @param logger - Logger instance for WASM operations
41
- * @returns Promise that resolves to the initialized WASM component
42
- */
43
- export declare function loadRealWasmComponent(logger: Logger): Promise<WasmComponent>;