@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
@@ -2,7 +2,7 @@
2
2
  * Configuration types for T3n Client
3
3
  */
4
4
  import { WasmComponent } from "../wasm";
5
- import { SessionId, GuestToHostHandlers } from "../types";
5
+ import { SessionId } from "../types";
6
6
  import { Logger, LogLevel } from "../utils/logger";
7
7
  import { Transport } from "./transport";
8
8
  /**
@@ -11,7 +11,7 @@ import { Transport } from "./transport";
11
11
  export interface T3nClientConfig {
12
12
  /** Base URL of the T3n node (used if transport not provided) */
13
13
  baseUrl?: string;
14
- /** WASM component instance for cryptographic operations */
14
+ /** WASM component instance (async direct-call `tee:session@1.0.0`). */
15
15
  wasmComponent: WasmComponent;
16
16
  /** Optional transport layer - if not provided, uses HttpTransport with baseUrl */
17
17
  transport?: Transport;
@@ -21,15 +21,35 @@ export interface T3nClientConfig {
21
21
  timeout?: number;
22
22
  /** Optional custom headers to include in requests */
23
23
  headers?: Record<string, string>;
24
- /**
25
- * Log level for this client instance.
26
- * Defaults to global log level (LogLevel.ERROR) if not specified.
27
- * Use LogLevel.DEBUG for verbose logging, LogLevel.INFO for informational messages,
28
- * LogLevel.WARN for warnings, or LogLevel.ERROR for errors only.
29
- */
24
+ /** Log level for this client instance. */
30
25
  logLevel?: LogLevel;
31
26
  /** Optional custom logger - if provided, overrides logLevel */
32
27
  logger?: Logger;
33
- /** Optional guest-to-host request handlers - provides custom behavior for WASM requests */
34
- handlers?: GuestToHostHandlers;
28
+ /**
29
+ * Optional signer bridge used by `authenticate()` for the ETH
30
+ * (SIWE) flow. Given the SIWE message bytes, the callback must
31
+ * produce a 65-byte `(r || s || v)` signature over the EIP-191
32
+ * personal-sign digest — matching `cryptography::ecdsa::eth`
33
+ * recovery on the node. A convenience wrapper for raw-private-key
34
+ * signing is planned for the follow-up commit that lands full
35
+ * ETH auth support.
36
+ */
37
+ ethSign?: (message: Uint8Array) => Promise<Uint8Array>;
38
+ /**
39
+ * Ethereum address (0x-prefixed, 20 bytes hex) of the user
40
+ * authenticating. Required by `authenticate()` for the ETH flow —
41
+ * the server recovers the signer from the SIWE message and
42
+ * compares to this address.
43
+ */
44
+ ethAddress?: string;
45
+ /**
46
+ * SIWE domain / URI / chain-id used in the message the SDK builds.
47
+ * Matches `SiwePolicy` on the server — the server's allowlist
48
+ * policy (if configured in NodeConfig) only accepts matching
49
+ * values. Defaults: domain `"localhost"`, URL `"https://trinity.io"`,
50
+ * chain ID `1` (Ethereum mainnet).
51
+ */
52
+ siweDomain?: string;
53
+ siweUrl?: string;
54
+ siweChainId?: number;
35
55
  }
@@ -4,7 +4,3 @@
4
4
  export * from "./config";
5
5
  export * from "./transport";
6
6
  export * from "./t3n-client";
7
- export * from "./handlers";
8
- export * from "./encryption";
9
- export * from "./actions";
10
- export * from "./request-parser";
@@ -1,88 +1,51 @@
1
1
  /**
2
- * T3n Client - Main SDK class
2
+ * T3n Client — thin host-function provider + WASM sequencer.
3
3
  *
4
- * Provides a simple interface for establishing secure sessions with T3n nodes.
5
- * All cryptographic complexity is handled in WASM components.
4
+ * The SDK communicates with the session contract strictly through
5
+ * WIT:
6
+ * - Calls `clientHandshake.run(sid)` — contract handles ML-KEM
7
+ * encapsulation, HKDF, POSTs via `host.transport.postRpc`,
8
+ * derives session keys, returns them.
9
+ * - Calls `clientAuth.runEth(keys, address, ...)` — contract
10
+ * builds the SIWE message, signs via `host.eth-signer.ethSign`,
11
+ * POSTs + parses the Finish response, returns the DID.
12
+ * - For `execute()`, the SDK just encrypts the JSON-RPC payload
13
+ * via `sessionCrypto.encrypt` and POSTs it through its transport.
14
+ *
15
+ * No SIWE building, no HKDF, no hex/base64 shuffling, no wire
16
+ * envelopes outside the contract. The contract is the single source
17
+ * of protocol truth.
6
18
  */
7
19
  import { T3nClientConfig } from "./config";
8
20
  import { SessionId, Did, SessionStatus, AuthInput, HandshakeResult } from "../types";
9
- /**
10
- * Main T3n SDK Client
11
- */
12
21
  export declare class T3nClient {
13
22
  private readonly config;
14
23
  private readonly transport;
15
24
  private readonly sessionId;
16
25
  private readonly logger;
17
- private readonly encryption;
18
26
  private status;
19
- private wasmState;
27
+ private sessionKeys;
20
28
  private did;
21
- private handshakeResult;
22
29
  constructor(config: T3nClientConfig);
23
- /**
24
- * Start the handshake process with the T3n node
25
- */
26
30
  handshake(): Promise<HandshakeResult>;
27
- /**
28
- * Authenticate with the T3n node.
29
- *
30
- * For OIDC, this runs a two-step nonce-bound flow:
31
- * 1. Sends `InitOidcAuth` to server → receives session-binding nonce.
32
- * 2. Calls `getIdToken(nonce)` callback so the app can include the
33
- * nonce in the Google authorization URL.
34
- * 3. Sends `SubmitIdToken` with the nonce-bearing token → receives DID.
35
- */
36
31
  authenticate(authInput: AuthInput): Promise<Did>;
37
- /**
38
- * OIDC two-step authentication with session-binding nonce.
39
- *
40
- * Bypasses the WASM client state machine and makes two encrypted
41
- * RPC calls directly:
42
- * 1. `InitOidcAuth { provider }` → server generates nonce → returns
43
- * `ProvideNonce { nonce }`.
44
- * 2. App calls `getIdToken(nonce)` to obtain a nonce-bound `id_token`.
45
- * 3. `SubmitIdToken { id_token }` → server verifies token + nonce →
46
- * returns `Finish { did }`.
47
- */
48
- private authenticateOidc;
49
- /**
50
- * Execute an action on the T3n node
51
- */
52
32
  execute(payload: unknown): Promise<string>;
53
33
  getSessionId(): SessionId;
54
34
  getStatus(): SessionStatus;
55
35
  getDid(): Did | null;
36
+ isAuthenticated(): boolean;
56
37
  getLastSetCookie(): string | null;
57
38
  getLastResponseHeaders(): Record<string, string>;
58
- isAuthenticated(): boolean;
59
- /**
60
- * Run a WASM state machine flow to completion
61
- */
62
- private runFlow;
63
- /**
64
- * Try to finalize the current flow
65
- */
66
- private tryFinalize;
67
- /**
68
- * Handle a WASM request based on its type
69
- */
70
- private handleWasmRequest;
71
39
  /**
72
- * Handle a send-remote request by calling the RPC endpoint
73
- */
74
- private handleSendRemote;
75
- private captureHandshakeResult;
76
- /**
77
- * Handle a guest-to-host request using configured handlers
78
- */
79
- private handleGuestToHost;
80
- /**
81
- * Send an RPC request with automatic encryption/decryption
82
- */
83
- private sendRpcRequest;
84
- /**
85
- * Get the current session state for encryption
40
+ * Build the `host.transport.postRpc` callback the contract uses for
41
+ * all its HTTP round-trips. Must be passed into `loadWasmComponent`
42
+ * at instantiation time so the contract can POST during handshake
43
+ * and auth.
44
+ *
45
+ * `params` from the contract is the opaque JSON-RPC params (already
46
+ * encrypted where encryption is needed). The SDK wraps in the
47
+ * JSON-RPC envelope and injects the Session-Id header.
86
48
  */
87
- private getSessionState;
49
+ buildPostRpcHostImport(): (method: string, _sessionIdFromGuest: string, params: string) => Promise<string>;
50
+ private sendRpcRaw;
88
51
  }
@@ -12,6 +12,18 @@ import type { SdkConfig, Environment } from "./types";
12
12
  * or by passing `baseUrl` to `T3nClient`.
13
13
  */
14
14
  export declare const NODE_URLS: Record<Environment, string>;
15
+ /** DKG attestation bundle from the cluster. */
16
+ export interface DkgAttestation {
17
+ /** Sorted base58 peer IDs that participated in DKG. */
18
+ peer_ids: string[];
19
+ /** Per-node TDX quotes keyed by base58 peer ID (base64-encoded). */
20
+ quotes: Record<string, string>;
21
+ /**
22
+ * Base64-encoded raw attestation message: `encaps_key || sorted_peer_ids`.
23
+ * Each quote's `report_data` is `keccak512(attestation_msg)`.
24
+ */
25
+ attestation_msg: string;
26
+ }
15
27
  /**
16
28
  * Set the active environment. Clears any previous URL override and the key
17
29
  * cache so the next fetch uses the new environment's default URL.
@@ -32,10 +44,30 @@ export declare function setNodeUrl(url: string | null): void;
32
44
  /** Resolve the active node URL: explicit `baseUrl` > override > env default. */
33
45
  export declare function getNodeUrl(baseUrl?: string): string;
34
46
  /**
35
- * Fetch the ML-KEM root public key from `${nodeUrl}/status`. Cached per URL.
36
- * The node must be in the `Ready` phase and expose `encaps_key`.
47
+ * Fetch the ML-KEM root public key from `${nodeUrl}/status`. Cached
48
+ * per URL because the key is stable for the cluster's lifetime (a
49
+ * new DKG means a full redeploy; callers clear the cache via
50
+ * `clearKeyCache()` or `setNodeUrl()` in that case).
51
+ *
52
+ * Returns only the base64-encoded key. For the DKG attestation
53
+ * bundle (which changes over time as peer quotes replicate via
54
+ * Raft), call `fetchDkgAttestation()` \u2014 that path is
55
+ * intentionally uncached.
37
56
  */
38
57
  export declare function fetchMlKemPublicKey(baseUrl?: string): Promise<string>;
58
+ /**
59
+ * Fetch the DKG attestation bundle from `${nodeUrl}/status`. Never
60
+ * cached \u2014 peer quotes are written to consensus KV asynchronously
61
+ * during cluster bootstrap, so early reads may see a subset of the
62
+ * expected quotes. Caching would pin an incomplete bundle and cause
63
+ * spurious `valid_count < expected_count` failures in
64
+ * `verifyDkgAttestation()` for the whole process lifetime.
65
+ *
66
+ * Returns `undefined` when the node has not yet published an
67
+ * attestation (e.g. still bootstrapping, or running with a mock
68
+ * signer where attestation is skipped by design).
69
+ */
70
+ export declare function fetchDkgAttestation(baseUrl?: string): Promise<DkgAttestation | undefined>;
39
71
  /** Clear the cached ML-KEM public keys. Useful in tests. */
40
72
  export declare function clearKeyCache(): void;
41
73
  /**
@@ -44,5 +76,7 @@ export declare function clearKeyCache(): void;
44
76
  * `fetchMlKemPublicKey()`.
45
77
  */
46
78
  export declare function loadConfig(baseUrl?: string): SdkConfig;
79
+ export { verifyTdxQuote, verifyDkgAttestation } from "../wasm/quote-verifier-loader";
80
+ export type { QuoteVerifyResult, DkgVerifyResult, PeerQuoteResult, } from "../wasm/quote-verifier-loader";
47
81
  export type { SdkConfig, Environment, ConfigValidationResult } from "./types";
48
82
  export { validateConfig } from "./loader";
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * T3n TypeScript SDK
3
3
  *
4
- * A minimal TypeScript SDK that mirrors the server's RPC handler approach,
5
- * keeping all state machine logic hidden in WASM and providing a clean,
6
- * agnostic wrapper that doesn't expose authentication methods or internal states.
4
+ * A thin host-function provider over the `tee:session` WASM
5
+ * contract. The SDK supplies host imports (transport, wallet, OIDC
6
+ * popup, KEM pubkey, RNG, time, cookie sink) at jco instantiation
7
+ * time and calls the contract's typed exports for handshake, auth,
8
+ * and session crypto. The contract owns every protocol detail.
7
9
  */
8
10
  export { T3nClient } from "./client";
9
11
  export type { T3nClientConfig } from "./client";
@@ -12,12 +14,11 @@ export type { Logger } from "./utils/logger";
12
14
  export { LogLevel, createLogger, getLogger, setGlobalLogLevel, getGlobalLogLevel, } from "./utils/logger";
13
15
  export type { Transport, JsonRpcRequest, JsonRpcResponse } from "./client";
14
16
  export { HttpTransport, MockTransport } from "./client";
15
- export type { SessionId, Did, OidcCredentials, AuthInput, EthAuthInput, OidcAuthInput, GuestToHostHandler, GuestToHostHandlers, } from "./types";
17
+ export type { SessionId, Did, OidcCredentials, AuthInput, EthAuthInput, OidcAuthInput, } from "./types";
16
18
  export { SessionStatus, AuthMethod, createEthAuthInput, createOidcAuthInput, } from "./types";
17
- export { metamask_sign, metamask_get_address, eth_get_address, createDefaultHandlers, createMlKemPublicKeyHandler, createRandomHandler, } from "./client/handlers";
18
- export type { WasmComponent, ClientHandshake, ClientAuth, SessionCrypto, WasmNextResult, } from "./wasm";
19
+ export type { WasmComponent, ClientHandshake, ClientAuth, ServerHandshake, SessionCrypto, CookieIface, ClientSessionKeys, ServerSessionKeys, HandshakeOutcome, AuthOutcome, ServerOutcome, Validation, SessionHostImports, } from "./wasm";
19
20
  export { loadWasmComponent } from "./wasm";
20
21
  export { generateRandomString, generateUUID, getScriptVersion, stringToBytes, bytesToString, redactSecrets, redactSecretsFromJson, } from "./utils";
21
22
  export { T3nError, SessionStateError, AuthenticationError, HandshakeError, RpcError, WasmError, decodeWasmErrorMessage, extractWasmError, } from "./utils/errors";
22
- export type { SdkConfig, Environment, ConfigValidationResult } from "./config";
23
- export { loadConfig, fetchMlKemPublicKey, clearKeyCache, getEnvironmentName, getEnvironment, setEnvironment, setNodeUrl, getNodeUrl, NODE_URLS, validateConfig, } from "./config";
23
+ export type { SdkConfig, Environment, ConfigValidationResult, DkgAttestation, QuoteVerifyResult, DkgVerifyResult, PeerQuoteResult, } from "./config";
24
+ export { loadConfig, fetchMlKemPublicKey, fetchDkgAttestation, verifyTdxQuote, verifyDkgAttestation, clearKeyCache, getEnvironmentName, getEnvironment, setEnvironment, setNodeUrl, getNodeUrl, NODE_URLS, validateConfig, } from "./config";
@@ -18,14 +18,15 @@ export interface EthereumSigner {
18
18
  /**
19
19
  * OIDC credentials interface.
20
20
  *
21
- * The TEE generates a session-binding nonce that must be included in
22
- * the Google authorization URL (`&nonce=…`). The `getIdToken` callback
23
- * receives this nonce and must return the `id_token` JWT obtained
24
- * from the OIDC provider with the nonce baked into its claims.
21
+ * The TEE generates a session-binding nonce; the user-interaction
22
+ * step is wired at WASM load time via `hostImports.getIdToken`
23
+ * (see `loadWasmComponent`), mirroring how `hostImports.ethSign`
24
+ * supplies wallet access. The contract calls `getIdToken(provider,
25
+ * nonce)` from inside `runOidc` and feeds the returned `id_token`
26
+ * to the server.
25
27
  */
26
28
  export interface OidcCredentials {
27
29
  provider: string;
28
- getIdToken: (nonce: string) => Promise<string>;
29
30
  }
30
31
  /**
31
32
  * Base authentication input with method discriminator
@@ -1,42 +1,18 @@
1
1
  /**
2
- * Public types export for T3n SDK
3
- */
4
- /**
5
- * Guest-to-Host request handler function type
2
+ * Public types export for T3n SDK.
6
3
  *
7
- * Handles requests from WASM guest that need host (SDK) to perform side
8
- * effects. The exact shape of `requestData` depends on the specific
9
- * handler see `GuestToHostHandlers` below for the per-handler shapes.
10
- * The wrapper layer in `T3nClient.handleGuestToHost` parses the JSON
11
- * envelope and calls the matching handler with the parsed data, so
12
- * each handler's implementation should narrow `requestData` to its
13
- * own expected shape.
14
- */
15
- export type GuestToHostHandler = (requestData: Record<string, unknown>) => Promise<Uint8Array>;
16
- /**
17
- * Map of guest-to-host request handlers
18
- * Keys match the guest_to_host tag values from the WASM
4
+ * The legacy `GuestToHostHandler` / `GuestToHostHandlers` types are
5
+ * gone the SDK is now strictly a thin host-function provider. The
6
+ * `tee:session` contract owns every protocol detail (SIWE message
7
+ * build, HKDF, AES-GCM, wire-envelope wrapping); the SDK supplies a
8
+ * small set of host imports (`mlKemPublicKey`, `random`, `ethSign`,
9
+ * `getIdToken`, `nowMs`, `setCookie`, `postRpc`) at jco instantiation
10
+ * time and calls the contract's typed WIT exports
11
+ * (`clientHandshake.run`, `clientAuth.runEth` / `runOidc`,
12
+ * `sessionCrypto.encrypt` / `decrypt`).
13
+ *
14
+ * See `src/wasm/loader.ts` for the host-import surface and
15
+ * `src/client/t3n-client.ts` for the consumer-facing API.
19
16
  */
20
- export interface GuestToHostHandlers {
21
- /**
22
- * Handle Ethereum signature requests
23
- * requestData: { guest_to_host: "EthSign", challenge: string (base64) }
24
- * Returns: JSON bytes of { host_to_guest: "EthSign", challenge: string, signature: string }
25
- */
26
- EthSign?: GuestToHostHandler;
27
- /**
28
- * Handle MlKem public key requests
29
- * requestData: { guest_to_host: "MlKemPublicKey" }
30
- * Returns: JSON bytes of { host_to_guest: "MlKemPublicKey", key: string }
31
- */
32
- MlKemPublicKey?: GuestToHostHandler;
33
- /**
34
- * Handle random bytes requests
35
- * requestData: { guest_to_host: "Random", len?: number }
36
- * Returns: JSON bytes of { host_to_guest: "Random", bytes: string (base64) }
37
- */
38
- Random?: GuestToHostHandler;
39
- [key: string]: GuestToHostHandler | undefined;
40
- }
41
17
  export * from "./session";
42
18
  export * from "./auth";
@@ -0,0 +1,36 @@
1
+ /**
2
+ * HKDF-SHA256 key derivation that mirrors `session::session::derive_keys`
3
+ * in the node (`node/session/src/session.rs`).
4
+ *
5
+ * The server derives two directional keys from the raw ML-KEM shared
6
+ * secret using HKDF-Extract-then-Expand with:
7
+ * - salt = b"" (empty)
8
+ * - ikm = the 32-byte raw KEM shared secret
9
+ * - info = b"t3-session-v1-c2s" | b"t3-session-v1-s2c"
10
+ * - L = 32 bytes each
11
+ *
12
+ * The client must derive the same pair so that c2s / s2c line up on
13
+ * both sides. WebCrypto's `subtle.deriveBits` with `HKDF` does
14
+ * Extract+Expand in one call, so the TS implementation collapses to a
15
+ * few lines per direction.
16
+ */
17
+ /**
18
+ * Derive directional session keys from the raw ML-KEM shared secret.
19
+ *
20
+ * @param rawSecret 32 bytes from `handshakeAsync.clientRun` (the
21
+ * `ClientPending.secret` field).
22
+ * @returns `{ c2s, s2c }` — each 32 bytes, suitable for AES-256-GCM.
23
+ */
24
+ export declare function deriveDirectionalKeys(rawSecret: Uint8Array): Promise<{
25
+ c2s: Uint8Array;
26
+ s2c: Uint8Array;
27
+ }>;
28
+ /**
29
+ * Pack directional keys for the client-side session-crypto WASM calls.
30
+ *
31
+ * The contract's `session-crypto.encrypt`/`decrypt` interprets its
32
+ * `keys` argument as `encrypt_key || decrypt_key`. The client
33
+ * encrypts with c2s and decrypts with s2c, so the client packs
34
+ * `c2s || s2c`.
35
+ */
36
+ export declare function packClientSessionKeys(c2s: Uint8Array, s2c: Uint8Array): Uint8Array;
@@ -4,6 +4,7 @@
4
4
  export * from "./crypto";
5
5
  export * from "./contract-version";
6
6
  export * from "./errors";
7
+ export * from "./hkdf";
7
8
  export * from "./logger";
8
9
  export * from "./redaction";
9
10
  export * from "./session";
@@ -1,104 +1,69 @@
1
1
  /**
2
- * WASM Component Interface - Mirrors the WIT specification exactly
2
+ * WASM Component Interface async direct-call.
3
3
  *
4
- * This interface works with completely opaque byte arrays, just like the WIT interface.
5
- * The TypeScript SDK doesn't know about internal state machine phases or details.
4
+ * Mirrors `tee:session@1.0.0` WIT world. The SDK talks to the WASM
5
+ * only through these exports (plus host imports supplied at
6
+ * instantiation); all protocol glue lives inside the contract.
6
7
  */
7
- /**
8
- * Result type for WASM next() operations
9
- */
10
- export interface WasmNextResult {
11
- state: Uint8Array;
12
- request: Uint8Array;
8
+ export interface ClientSessionKeys {
9
+ /** `encrypt_key || decrypt_key`, 64 bytes. */
10
+ blob: Uint8Array;
11
+ sid: Uint8Array;
12
+ }
13
+ export interface HandshakeOutcome {
14
+ keys: ClientSessionKeys;
15
+ authenticated: boolean;
16
+ did?: string;
17
+ expirySec: bigint;
13
18
  }
14
- /**
15
- * Client handshake operations - completely opaque byte arrays only
16
- */
17
19
  export interface ClientHandshake {
18
- /**
19
- * Process next step in handshake
20
- * @param state - Current handshake state (null for initial call)
21
- * @param action - Action to process (opaque bytes)
22
- * @returns Promise with new state and request to send
23
- */
24
- next(state: Uint8Array | null, action: Uint8Array): Promise<WasmNextResult>;
25
- /**
26
- * Attempt to finalize handshake
27
- * @param state - Current handshake state
28
- * @returns Promise with session bytes if successful
29
- * @throws Error if handshake not ready to finalize
30
- */
31
- finish(state: Uint8Array): Promise<Uint8Array>;
20
+ run(sid: Uint8Array, cookie: string | undefined): HandshakeOutcome;
21
+ }
22
+ export interface AuthOutcome {
23
+ did: string;
24
+ cookie?: string;
32
25
  }
33
- /**
34
- * Client authentication operations - completely opaque byte arrays only
35
- */
36
26
  export interface ClientAuth {
27
+ runEth(sessionKeys: Uint8Array, ethAddress: string, siweDomain: string | undefined, siweUrl: string | undefined, siweChainId: bigint | undefined): AuthOutcome;
37
28
  /**
38
- * Process next step in authentication
39
- * @param state - Current auth state (null for initial call)
40
- * @param action - Action to process (opaque bytes)
41
- * @returns Promise with new state and request to send
42
- */
43
- next(state: Uint8Array | null, action: Uint8Array): Promise<WasmNextResult>;
44
- /**
45
- * Attempt to finalize authentication
46
- * @param state - Current auth state
47
- * @returns Promise with DID bytes if successful
48
- * @throws Error if authentication not ready to finalize
29
+ * Run the full OIDC flow in one call. The contract drives both
30
+ * server round-trips and invokes the SDK's `getIdToken(provider,
31
+ * nonce)` host import in between to obtain the IdP-signed token.
49
32
  */
50
- finish(state: Uint8Array): Promise<Uint8Array>;
33
+ runOidc(sessionKeys: Uint8Array, provider: string): AuthOutcome;
51
34
  }
52
- /**
53
- * Client authentication operations - completely opaque byte arrays only
54
- */
55
- export interface ClientExecute {
56
- /**
57
- * Process next step in authentication
58
- * @param state - Current auth state (null for initial call)
59
- * @param action - Action to process (opaque bytes)
60
- * @returns Promise with new state and request to send
61
- */
62
- next(state: Uint8Array | null, action: Uint8Array): Promise<WasmNextResult>;
63
- /**
64
- * Attempt to finalize authentication
65
- * @param state - Current auth state
66
- * @returns Promise with DID bytes if successful
67
- * @throws Error if authentication not ready to finalize
68
- */
69
- finish(state: Uint8Array): Promise<Uint8Array>;
35
+ export interface ServerSessionKeys {
36
+ c2s: Uint8Array;
37
+ s2c: Uint8Array;
38
+ sid: Uint8Array;
39
+ }
40
+ export interface ServerOutcome {
41
+ keys: ServerSessionKeys;
42
+ authenticated: boolean;
43
+ did?: string;
44
+ expirySec: bigint;
45
+ refreshedCookie?: string;
46
+ }
47
+ export interface ServerHandshake {
48
+ run(sid: Uint8Array, ciphertext: Uint8Array, cookieValue: string | undefined): ServerOutcome;
70
49
  }
71
- /**
72
- * Session encryption/decryption operations - completely opaque byte arrays only
73
- */
74
50
  export interface SessionCrypto {
75
- /**
76
- * Encrypt plaintext using session
77
- * @param session - Session state (opaque bytes)
78
- * @param plaintext - Data to encrypt
79
- * @returns Promise with encrypted bytes
80
- */
81
- encrypt(session: Uint8Array, plaintext: Uint8Array): Promise<Uint8Array>;
82
- /**
83
- * Decrypt ciphertext using session
84
- * @param session - Session state (opaque bytes)
85
- * @param ciphertext - Data to decrypt
86
- * @returns Promise with decrypted bytes
87
- */
88
- decrypt(session: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array>;
51
+ encrypt(keys: Uint8Array, plaintext: Uint8Array): Uint8Array;
52
+ decrypt(keys: Uint8Array, ciphertext: Uint8Array): Uint8Array;
89
53
  }
90
- /**
91
- * Main WASM Component interface - mirrors the WIT interface exactly
92
- *
93
- * This is completely opaque to the TypeScript layer. All state machine logic,
94
- * authentication flows, and cryptographic operations are handled in WASM.
95
- */
54
+ export interface Validation {
55
+ authenticated: boolean;
56
+ did?: string;
57
+ exp: bigint;
58
+ }
59
+ export interface CookieIface {
60
+ validate(cookieValue: string, teeAddress: Uint8Array, nowSec: bigint): Validation;
61
+ }
62
+ /** Fully instantiated session component. */
96
63
  export interface WasmComponent {
97
- /** Client handshake operations */
98
- flow: {
99
- handshake: ClientHandshake;
100
- auth: ClientAuth;
101
- execute: ClientExecute;
102
- };
103
- session: SessionCrypto;
64
+ clientHandshake: ClientHandshake;
65
+ clientAuth: ClientAuth;
66
+ serverHandshake: ServerHandshake;
67
+ sessionCrypto: SessionCrypto;
68
+ cookie: CookieIface;
104
69
  }