@terminal3/t3n-sdk 0.8.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.
- package/dist/index.d.ts +173 -292
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/src/client/config.d.ts +30 -10
- package/dist/src/client/index.d.ts +0 -4
- package/dist/src/client/t3n-client.d.ts +27 -64
- package/dist/src/index.d.ts +7 -6
- package/dist/src/types/auth.d.ts +6 -5
- package/dist/src/types/index.d.ts +13 -37
- package/dist/src/utils/hkdf.d.ts +36 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/wasm/interface.d.ts +54 -89
- package/dist/src/wasm/loader.d.ts +55 -25
- package/dist/wasm/generated/interfaces/host-session-interfaces-contract-dispatch.d.ts +2 -0
- package/dist/wasm/generated/interfaces/host-session-interfaces-entropy.d.ts +2 -0
- package/dist/wasm/generated/interfaces/host-session-interfaces-eth-signer.d.ts +2 -0
- package/dist/wasm/generated/interfaces/host-session-interfaces-kem.d.ts +3 -0
- package/dist/wasm/generated/interfaces/host-session-interfaces-oidc-client.d.ts +2 -0
- package/dist/wasm/generated/interfaces/host-session-interfaces-oidc.d.ts +3 -0
- package/dist/wasm/generated/interfaces/host-session-interfaces-session-ops.d.ts +9 -0
- package/dist/wasm/generated/interfaces/host-session-interfaces-transport.d.ts +2 -0
- package/dist/wasm/generated/interfaces/tee-session-client-auth.d.ts +7 -0
- package/dist/wasm/generated/interfaces/tee-session-client-handshake.d.ts +12 -0
- package/dist/wasm/generated/interfaces/tee-session-cookie.d.ts +7 -0
- package/dist/wasm/generated/interfaces/tee-session-server-admin.d.ts +2 -0
- package/dist/wasm/generated/interfaces/tee-session-server-auth.d.ts +10 -0
- package/dist/wasm/generated/interfaces/tee-session-server-handshake.d.ts +15 -0
- package/dist/wasm/generated/interfaces/tee-session-server-webhook.d.ts +6 -0
- package/dist/wasm/generated/interfaces/tee-session-session-crypto.d.ts +3 -0
- package/dist/wasm/generated/session.core.wasm +0 -0
- package/dist/wasm/generated/session.core2.wasm +0 -0
- package/dist/wasm/generated/session.core3.wasm +0 -0
- package/dist/wasm/generated/session.d.ts +87 -12
- package/dist/wasm/generated/session.js +6640 -3702
- package/package.json +1 -1
- package/dist/demo.d.ts +0 -25
- package/dist/src/client/actions.d.ts +0 -22
- package/dist/src/client/encryption.d.ts +0 -30
- package/dist/src/client/handlers.d.ts +0 -73
- package/dist/src/client/request-parser.d.ts +0 -48
- package/dist/wasm/generated/interfaces/component-session-client-auth.d.ts +0 -12
- package/dist/wasm/generated/interfaces/component-session-client-handshake.d.ts +0 -12
- package/dist/wasm/generated/interfaces/component-session-cookie.d.ts +0 -8
- package/dist/wasm/generated/interfaces/component-session-server-auth.d.ts +0 -13
- package/dist/wasm/generated/interfaces/component-session-server-handshake.d.ts +0 -12
- 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
|
|
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
|
|
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
|
-
/**
|
|
34
|
-
|
|
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
|
}
|
|
@@ -1,88 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* T3n Client -
|
|
2
|
+
* T3n Client — thin host-function provider + WASM sequencer.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
|
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
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
49
|
+
buildPostRpcHostImport(): (method: string, _sessionIdFromGuest: string, params: string) => Promise<string>;
|
|
50
|
+
private sendRpcRaw;
|
|
88
51
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* T3n TypeScript SDK
|
|
3
3
|
*
|
|
4
|
-
* A
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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,10 +14,9 @@ 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,
|
|
17
|
+
export type { SessionId, Did, OidcCredentials, AuthInput, EthAuthInput, OidcAuthInput, } from "./types";
|
|
16
18
|
export { SessionStatus, AuthMethod, createEthAuthInput, createOidcAuthInput, } from "./types";
|
|
17
|
-
export {
|
|
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";
|
package/dist/src/types/auth.d.ts
CHANGED
|
@@ -18,14 +18,15 @@ export interface EthereumSigner {
|
|
|
18
18
|
/**
|
|
19
19
|
* OIDC credentials interface.
|
|
20
20
|
*
|
|
21
|
-
* The TEE generates a session-binding nonce
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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;
|
|
@@ -1,104 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* WASM Component Interface
|
|
2
|
+
* WASM Component Interface — async direct-call.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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
|
-
|
|
33
|
+
runOidc(sessionKeys: Uint8Array, provider: string): AuthOutcome;
|
|
51
34
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
session: SessionCrypto;
|
|
64
|
+
clientHandshake: ClientHandshake;
|
|
65
|
+
clientAuth: ClientAuth;
|
|
66
|
+
serverHandshake: ServerHandshake;
|
|
67
|
+
sessionCrypto: SessionCrypto;
|
|
68
|
+
cookie: CookieIface;
|
|
104
69
|
}
|
|
@@ -1,43 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* WASM Component Loader
|
|
2
|
+
* WASM Component Loader — async direct-call shape.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
27
|
-
*
|
|
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>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @module Interface host:session-interfaces/session-ops@1.0.0 **/
|
|
2
|
+
export function nowMs(): bigint;
|
|
3
|
+
export function teeAddress(): Uint8Array;
|
|
4
|
+
export function fetchOrCreateDid(authenticatorHashes: Array<Uint8Array>, did: string | undefined): string;
|
|
5
|
+
export function fetchProviderConfig(providerId: string): Uint8Array;
|
|
6
|
+
export function setCookie(cookieValue: string): void;
|
|
7
|
+
export function registerScript(name: string, version: string, wasmBytes: Uint8Array, sourceHash: string | undefined): boolean;
|
|
8
|
+
export function syncUserAuths(): Uint8Array;
|
|
9
|
+
export function updateMeasurements(measurementsBase64: string): boolean;
|