@terminal3/t3n-sdk 0.10.0 → 0.12.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/README.md +1 -1
- package/dist/demo.d.ts +25 -0
- package/dist/index.d.ts +347 -172
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/src/client/actions.d.ts +22 -0
- package/dist/src/client/config.d.ts +10 -30
- package/dist/src/client/encryption.d.ts +30 -0
- package/dist/src/client/handlers.d.ts +73 -0
- package/dist/src/client/index.d.ts +4 -0
- package/dist/src/client/request-parser.d.ts +48 -0
- package/dist/src/client/t3n-client.d.ts +113 -26
- package/dist/src/index.d.ts +6 -7
- package/dist/src/types/auth.d.ts +5 -6
- package/dist/src/types/index.d.ts +37 -13
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/wasm/interface.d.ts +95 -54
- package/dist/src/wasm/loader.d.ts +25 -55
- package/dist/wasm/generated/interfaces/component-session-client-auth.d.ts +12 -0
- package/dist/wasm/generated/interfaces/component-session-client-handshake.d.ts +12 -0
- package/dist/wasm/generated/interfaces/component-session-cookie.d.ts +8 -0
- package/dist/wasm/generated/interfaces/component-session-session.d.ts +7 -0
- package/dist/wasm/generated/session.core.wasm +0 -0
- package/dist/wasm/generated/session.d.ts +10 -87
- package/dist/wasm/generated/session.js +3254 -6713
- package/package.json +1 -1
- package/dist/src/utils/hkdf.d.ts +0 -36
- package/dist/wasm/generated/interfaces/host-session-interfaces-contract-dispatch.d.ts +0 -2
- package/dist/wasm/generated/interfaces/host-session-interfaces-entropy.d.ts +0 -2
- package/dist/wasm/generated/interfaces/host-session-interfaces-eth-signer.d.ts +0 -2
- package/dist/wasm/generated/interfaces/host-session-interfaces-kem.d.ts +0 -3
- package/dist/wasm/generated/interfaces/host-session-interfaces-oidc-client.d.ts +0 -2
- package/dist/wasm/generated/interfaces/host-session-interfaces-oidc.d.ts +0 -3
- package/dist/wasm/generated/interfaces/host-session-interfaces-session-ops.d.ts +0 -9
- package/dist/wasm/generated/interfaces/host-session-interfaces-transport.d.ts +0 -2
- package/dist/wasm/generated/interfaces/tee-session-client-auth.d.ts +0 -7
- package/dist/wasm/generated/interfaces/tee-session-client-handshake.d.ts +0 -12
- package/dist/wasm/generated/interfaces/tee-session-cookie.d.ts +0 -7
- package/dist/wasm/generated/interfaces/tee-session-server-admin.d.ts +0 -2
- package/dist/wasm/generated/interfaces/tee-session-server-auth.d.ts +0 -10
- package/dist/wasm/generated/interfaces/tee-session-server-handshake.d.ts +0 -15
- package/dist/wasm/generated/interfaces/tee-session-server-webhook.d.ts +0 -6
- package/dist/wasm/generated/interfaces/tee-session-session-crypto.d.ts +0 -3
- package/dist/wasm/generated/session.core2.wasm +0 -0
- package/dist/wasm/generated/session.core3.wasm +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM Action Creators
|
|
3
|
+
*
|
|
4
|
+
* Creates the initial action payloads for WASM state machines.
|
|
5
|
+
* These are JSON-serialized and passed to the WASM component to start flows.
|
|
6
|
+
*/
|
|
7
|
+
import { AuthInput } from "../types";
|
|
8
|
+
/**
|
|
9
|
+
* Create the initial handshake request
|
|
10
|
+
* This kicks off the handshake state machine in WASM
|
|
11
|
+
*/
|
|
12
|
+
export declare function createHandshakeAction(): Uint8Array;
|
|
13
|
+
/**
|
|
14
|
+
* Create the initial authentication request based on auth method
|
|
15
|
+
* @param authInput - The authentication input (Ethereum or OIDC)
|
|
16
|
+
*/
|
|
17
|
+
export declare function createAuthAction(authInput: AuthInput): Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
* Create the OIDC SubmitToken action for the second step of nonce-bound auth.
|
|
20
|
+
* @param idToken - The id_token JWT obtained from the OIDC provider with the nonce
|
|
21
|
+
*/
|
|
22
|
+
export declare function createOidcSubmitTokenAction(idToken: string): Uint8Array;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Configuration types for T3n Client
|
|
3
3
|
*/
|
|
4
4
|
import { WasmComponent } from "../wasm";
|
|
5
|
-
import { SessionId } from "../types";
|
|
5
|
+
import { SessionId, GuestToHostHandlers } 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 for cryptographic operations */
|
|
15
15
|
wasmComponent: WasmComponent;
|
|
16
16
|
/** Optional transport layer - if not provided, uses HttpTransport with baseUrl */
|
|
17
17
|
transport?: Transport;
|
|
@@ -21,35 +21,15 @@ export interface T3nClientConfig {
|
|
|
21
21
|
timeout?: number;
|
|
22
22
|
/** Optional custom headers to include in requests */
|
|
23
23
|
headers?: Record<string, string>;
|
|
24
|
-
/**
|
|
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
|
+
*/
|
|
25
30
|
logLevel?: LogLevel;
|
|
26
31
|
/** Optional custom logger - if provided, overrides logLevel */
|
|
27
32
|
logger?: Logger;
|
|
28
|
-
/**
|
|
29
|
-
|
|
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;
|
|
33
|
+
/** Optional guest-to-host request handlers - provides custom behavior for WASM requests */
|
|
34
|
+
handlers?: GuestToHostHandlers;
|
|
55
35
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Encryption Service
|
|
3
|
+
*
|
|
4
|
+
* Handles encryption and decryption of data using the established WASM session.
|
|
5
|
+
* Keeps cryptographic operations isolated and simple.
|
|
6
|
+
*/
|
|
7
|
+
import { SessionCrypto } from "../wasm";
|
|
8
|
+
import { Logger } from "../utils/logger";
|
|
9
|
+
/**
|
|
10
|
+
* Encrypts and decrypts data using an established session
|
|
11
|
+
*/
|
|
12
|
+
export declare class SessionEncryption {
|
|
13
|
+
private sessionCrypto;
|
|
14
|
+
private logger;
|
|
15
|
+
constructor(sessionCrypto: SessionCrypto, logger: Logger);
|
|
16
|
+
/**
|
|
17
|
+
* Encrypt data using the session
|
|
18
|
+
* @param sessionState - The session state bytes (from handshake)
|
|
19
|
+
* @param data - The plaintext data to encrypt
|
|
20
|
+
* @returns Base64-encoded encrypted data
|
|
21
|
+
*/
|
|
22
|
+
encrypt(sessionState: Uint8Array, data: Uint8Array): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Decrypt data using the session
|
|
25
|
+
* @param sessionState - The session state bytes (from handshake)
|
|
26
|
+
* @param encryptedData - Base64-encoded encrypted data
|
|
27
|
+
* @returns Decrypted plaintext bytes
|
|
28
|
+
*/
|
|
29
|
+
decrypt(sessionState: Uint8Array, encryptedData: string): Promise<Uint8Array>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guest-to-Host Request Handlers
|
|
3
|
+
*
|
|
4
|
+
* These handle requests from WASM that need the host environment to perform side effects.
|
|
5
|
+
* Examples: signing challenges, providing public keys, generating random bytes.
|
|
6
|
+
*/
|
|
7
|
+
import { GuestToHostHandler, GuestToHostHandlers } from "../types";
|
|
8
|
+
import { Logger } from "../utils/logger";
|
|
9
|
+
/**
|
|
10
|
+
* Account — MetaMask handler accepts either a plain address string or an
|
|
11
|
+
* object with an `address` field (for compatibility with various wallet
|
|
12
|
+
* libraries).
|
|
13
|
+
*/
|
|
14
|
+
type EthAccount = string | {
|
|
15
|
+
address: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Create an EthSign handler using MetaMask (window.ethereum)
|
|
19
|
+
* @param account - MetaMask account (string address or object with address property)
|
|
20
|
+
* @param logger - Optional logger instance. Defaults to a logger using the global log level (LogLevel.ERROR).
|
|
21
|
+
* Pass a custom logger to override logging behavior for this handler.
|
|
22
|
+
* @param privateKey - Optional private key for signing (if provided, MetaMask is not used)
|
|
23
|
+
*/
|
|
24
|
+
export declare function metamask_sign(account: EthAccount, logger?: Logger, privateKey?: string | undefined): GuestToHostHandler;
|
|
25
|
+
/**
|
|
26
|
+
* Get the current MetaMask address
|
|
27
|
+
* @returns Ethereum address (lowercase, 0x prefixed)
|
|
28
|
+
*/
|
|
29
|
+
export declare function metamask_get_address(): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Get the address for a given private key
|
|
32
|
+
* @param privateKey - Ethereum private key (0x prefixed hex string)
|
|
33
|
+
* @returns Ethereum address (lowercase, 0x prefixed)
|
|
34
|
+
*/
|
|
35
|
+
export declare function eth_get_address(privateKey: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Create an MlKemPublicKey handler that lazily fetches the root public key
|
|
38
|
+
* from `${baseUrl}/status` on first invocation and caches the encoded
|
|
39
|
+
* response for subsequent calls.
|
|
40
|
+
*
|
|
41
|
+
* @param baseUrl - **Required**. The node URL whose `/status` endpoint should
|
|
42
|
+
* serve the ML-KEM public key. Must be the same URL the
|
|
43
|
+
* T3nClient is constructed with — otherwise the handshake
|
|
44
|
+
* encrypts to one node and sends ciphertext to another.
|
|
45
|
+
*
|
|
46
|
+
* Was optional in 0.3.x, where omitting it caused the lazy
|
|
47
|
+
* fetch to silently fall back to `NODE_URLS[currentEnv]` and
|
|
48
|
+
* hit the wrong node. Three downstream consumers (demo.ts,
|
|
49
|
+
* t3-apps dev wallet hooks, t3n-mcp session manager) all
|
|
50
|
+
* hit this trap before we tightened the type.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createMlKemPublicKeyHandler(baseUrl: string): GuestToHostHandler;
|
|
53
|
+
/**
|
|
54
|
+
* Create Random handler backed by crypto.getRandomValues
|
|
55
|
+
* Note: The Rust Vec<u8> type serializes as an array of bytes, not a base64 string
|
|
56
|
+
*/
|
|
57
|
+
export declare function createRandomHandler(): GuestToHostHandler;
|
|
58
|
+
/**
|
|
59
|
+
* Create the default handler set required by the T3n handshake.
|
|
60
|
+
*
|
|
61
|
+
* @param baseUrl - **Required**. Forwarded to `createMlKemPublicKeyHandler`
|
|
62
|
+
* so the lazy /status fetch hits the right node.
|
|
63
|
+
*/
|
|
64
|
+
export declare function createDefaultHandlers(baseUrl: string): GuestToHostHandlers;
|
|
65
|
+
/**
|
|
66
|
+
* Merge consumer-provided handlers with defaults (user handlers take precedence).
|
|
67
|
+
*
|
|
68
|
+
* @param handlers - Optional consumer overrides.
|
|
69
|
+
* @param baseUrl - **Required**. Forwarded to the default handler set so the
|
|
70
|
+
* ML-KEM key fetch hits the right node.
|
|
71
|
+
*/
|
|
72
|
+
export declare function mergeWithDefaultHandlers(handlers: GuestToHostHandlers | undefined, baseUrl: string): GuestToHostHandlers;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM Request Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses and categorizes requests from the WASM state machine.
|
|
5
|
+
* The WASM component outputs JSON with a `guest_to_host` tag that determines
|
|
6
|
+
* how the SDK should handle the request.
|
|
7
|
+
*
|
|
8
|
+
* See node/session/src/abi.rs for the GuestToHost enum definition.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Types of requests that can come from WASM
|
|
12
|
+
*/
|
|
13
|
+
export declare enum WasmRequestType {
|
|
14
|
+
/** Send data to remote server (PeerReply with action) */
|
|
15
|
+
SendRemote = "SendRemote",
|
|
16
|
+
/** Request to host (SDK) for side effects (MlKemPublicKey, Random, EthSign, etc.) */
|
|
17
|
+
GuestToHost = "GuestToHost",
|
|
18
|
+
/** Flow complete (Suspend) */
|
|
19
|
+
Suspend = "Suspend"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parsed result from WASM request
|
|
23
|
+
*/
|
|
24
|
+
export interface ParsedRequest {
|
|
25
|
+
type: WasmRequestType;
|
|
26
|
+
data: Record<string, unknown>;
|
|
27
|
+
raw: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parses WASM request bytes into a categorized request type
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseWasmRequest(requestBytes: Uint8Array): ParsedRequest;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a request should be sent to the remote server
|
|
35
|
+
*/
|
|
36
|
+
export declare function isSendRemote(parsed: ParsedRequest): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a request indicates flow completion
|
|
39
|
+
*/
|
|
40
|
+
export declare function isCompletion(parsed: ParsedRequest): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Check if a request needs a guest-to-host handler
|
|
43
|
+
*/
|
|
44
|
+
export declare function isGuestToHost(parsed: ParsedRequest): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Get the guest-to-host request type name (e.g., "MlKemPublicKey", "Random", "EthSign")
|
|
47
|
+
*/
|
|
48
|
+
export declare function getGuestToHostType(parsed: ParsedRequest): string | null;
|
|
@@ -1,51 +1,138 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* T3n Client
|
|
2
|
+
* T3n Client - Main SDK class
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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.
|
|
4
|
+
* Provides a simple interface for establishing secure sessions with T3n nodes.
|
|
5
|
+
* All cryptographic complexity is handled in WASM components.
|
|
18
6
|
*/
|
|
19
7
|
import { T3nClientConfig } from "./config";
|
|
20
8
|
import { SessionId, Did, SessionStatus, AuthInput, HandshakeResult } from "../types";
|
|
9
|
+
/**
|
|
10
|
+
* Main T3n SDK Client
|
|
11
|
+
*/
|
|
21
12
|
export declare class T3nClient {
|
|
22
13
|
private readonly config;
|
|
23
14
|
private readonly transport;
|
|
24
15
|
private readonly sessionId;
|
|
25
16
|
private readonly logger;
|
|
17
|
+
private readonly encryption;
|
|
26
18
|
private status;
|
|
27
|
-
|
|
19
|
+
/**
|
|
20
|
+
* In-flight WASM state-machine bytes. Holds the opaque state
|
|
21
|
+
* returned by `flow[method].next()` between iterations of
|
|
22
|
+
* `runFlow`. Always cleared at the top of `runFlow` and again
|
|
23
|
+
* once `tryFinalize` has extracted the terminal payload — so
|
|
24
|
+
* outside of an active loop these slots are always `null`.
|
|
25
|
+
*/
|
|
26
|
+
private wasmState;
|
|
27
|
+
/**
|
|
28
|
+
* Terminal payloads produced by `flow[method].finish()`:
|
|
29
|
+
* - `handshake` → serialized session blob, used by
|
|
30
|
+
* `getSessionState()` for subsequent `session.encrypt` calls.
|
|
31
|
+
* - `auth` → serialized DID; the public `authenticate()` decodes
|
|
32
|
+
* it into `this.did` and the slot is otherwise unused.
|
|
33
|
+
* - `execute` → unused (executes return immediately to the caller).
|
|
34
|
+
*
|
|
35
|
+
* Stored in a dedicated field instead of reusing `wasmState`
|
|
36
|
+
* because the two meanings — "in-flight state machine" vs
|
|
37
|
+
* "finalized payload" — are semantically different and merging
|
|
38
|
+
* them invites the bug-class Devin flagged in PR #1140.
|
|
39
|
+
*/
|
|
40
|
+
private finalizedPayload;
|
|
28
41
|
private did;
|
|
42
|
+
private handshakeResult;
|
|
29
43
|
constructor(config: T3nClientConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Start the handshake process with the T3n node
|
|
46
|
+
*/
|
|
30
47
|
handshake(): Promise<HandshakeResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Authenticate with the T3n node.
|
|
50
|
+
*
|
|
51
|
+
* For OIDC, this runs a two-step nonce-bound flow:
|
|
52
|
+
* 1. Sends `InitOidcAuth` to server → receives session-binding nonce.
|
|
53
|
+
* 2. Calls `getIdToken(nonce)` callback so the app can include the
|
|
54
|
+
* nonce in the Google authorization URL.
|
|
55
|
+
* 3. Sends `SubmitIdToken` with the nonce-bearing token → receives DID.
|
|
56
|
+
*/
|
|
31
57
|
authenticate(authInput: AuthInput): Promise<Did>;
|
|
58
|
+
/**
|
|
59
|
+
* OIDC two-step authentication with session-binding nonce.
|
|
60
|
+
*
|
|
61
|
+
* Bypasses the WASM client state machine and makes two encrypted
|
|
62
|
+
* RPC calls directly:
|
|
63
|
+
* 1. `InitOidcAuth { provider }` → server generates nonce → returns
|
|
64
|
+
* `ProvideNonce { nonce }`.
|
|
65
|
+
* 2. App calls `getIdToken(nonce)` to obtain a nonce-bound `id_token`.
|
|
66
|
+
* 3. `SubmitIdToken { id_token }` → server verifies token + nonce →
|
|
67
|
+
* returns `Finish { did }`.
|
|
68
|
+
*/
|
|
69
|
+
private authenticateOidc;
|
|
70
|
+
/**
|
|
71
|
+
* Execute an action on the T3n node
|
|
72
|
+
*/
|
|
32
73
|
execute(payload: unknown): Promise<string>;
|
|
33
74
|
getSessionId(): SessionId;
|
|
34
75
|
getStatus(): SessionStatus;
|
|
35
76
|
getDid(): Did | null;
|
|
36
|
-
isAuthenticated(): boolean;
|
|
37
77
|
getLastSetCookie(): string | null;
|
|
38
78
|
getLastResponseHeaders(): Record<string, string>;
|
|
79
|
+
isAuthenticated(): boolean;
|
|
39
80
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
81
|
+
* Run a WASM state machine flow to completion.
|
|
82
|
+
*
|
|
83
|
+
* Clears both `wasmState[method]` and `finalizedPayload[method]`
|
|
84
|
+
* at entry so a flow that previously threw partway (e.g. an RPC
|
|
85
|
+
* error) starts from a clean slate on retry. Without the reset,
|
|
86
|
+
* stale state from the failed attempt leaks into the new flow
|
|
87
|
+
* and `tryFinalize` may either spuriously succeed or run `next()`
|
|
88
|
+
* against a state that no longer matches the action we're sending.
|
|
44
89
|
*
|
|
45
|
-
* `
|
|
46
|
-
*
|
|
47
|
-
*
|
|
90
|
+
* The `tryFinalize`-then-`next` order is load-bearing: the loop's
|
|
91
|
+
* exit condition fires *after* the previous iteration's
|
|
92
|
+
* `handleWasmRequest` has flushed the outbound peer reply, so
|
|
93
|
+
* every state-machine emission reaches the wire before we extract
|
|
94
|
+
* the final payload.
|
|
95
|
+
*/
|
|
96
|
+
private runFlow;
|
|
97
|
+
/**
|
|
98
|
+
* Try to finalize the current flow. Returns the finish() payload
|
|
99
|
+
* (a serialized Session for handshake, a serialized DID for auth)
|
|
100
|
+
* or `null` if the state machine has not reached its terminal phase
|
|
101
|
+
* yet.
|
|
102
|
+
*
|
|
103
|
+
* The "not yet finalized" case is the loop's signal to keep
|
|
104
|
+
* iterating, not a real error. Any *other* failure must propagate
|
|
105
|
+
* so callers see real WASM errors instead of silent retries that
|
|
106
|
+
* spin forever.
|
|
107
|
+
*
|
|
108
|
+
* The terminal payload is stored in `finalizedPayload[method]`
|
|
109
|
+
* (a separate field from `wasmState[method]`) so the in-flight
|
|
110
|
+
* state-machine bytes and the finalized session/DID bytes never
|
|
111
|
+
* occupy the same slot. `getSessionState()` reads from
|
|
112
|
+
* `finalizedPayload.handshake`.
|
|
113
|
+
*/
|
|
114
|
+
private tryFinalize;
|
|
115
|
+
/**
|
|
116
|
+
* Handle a WASM request based on its type
|
|
117
|
+
*/
|
|
118
|
+
private handleWasmRequest;
|
|
119
|
+
/**
|
|
120
|
+
* Handle a send-remote request by calling the RPC endpoint
|
|
121
|
+
*/
|
|
122
|
+
private handleSendRemote;
|
|
123
|
+
private captureHandshakeResult;
|
|
124
|
+
/**
|
|
125
|
+
* Handle a guest-to-host request using configured handlers
|
|
126
|
+
*/
|
|
127
|
+
private handleGuestToHost;
|
|
128
|
+
/**
|
|
129
|
+
* Send an RPC request with automatic encryption/decryption
|
|
130
|
+
*/
|
|
131
|
+
private sendRpcRequest;
|
|
132
|
+
/**
|
|
133
|
+
* Get the finalized session blob (for `session.encrypt` calls).
|
|
134
|
+
* Populated by `tryFinalize` once the handshake state machine
|
|
135
|
+
* reaches its terminal phase.
|
|
48
136
|
*/
|
|
49
|
-
|
|
50
|
-
private sendRpcRaw;
|
|
137
|
+
private getSessionState;
|
|
51
138
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* T3n TypeScript SDK
|
|
3
3
|
*
|
|
4
|
-
* A
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* time and calls the contract's typed exports for handshake, auth,
|
|
8
|
-
* and session crypto. The contract owns every protocol detail.
|
|
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.
|
|
9
7
|
*/
|
|
10
8
|
export { T3nClient } from "./client";
|
|
11
9
|
export type { T3nClientConfig } from "./client";
|
|
@@ -14,9 +12,10 @@ export type { Logger } from "./utils/logger";
|
|
|
14
12
|
export { LogLevel, createLogger, getLogger, setGlobalLogLevel, getGlobalLogLevel, } from "./utils/logger";
|
|
15
13
|
export type { Transport, JsonRpcRequest, JsonRpcResponse } from "./client";
|
|
16
14
|
export { HttpTransport, MockTransport } from "./client";
|
|
17
|
-
export type { SessionId, Did, OidcCredentials, AuthInput, EthAuthInput, OidcAuthInput, } from "./types";
|
|
15
|
+
export type { SessionId, Did, OidcCredentials, AuthInput, EthAuthInput, OidcAuthInput, GuestToHostHandler, GuestToHostHandlers, } from "./types";
|
|
18
16
|
export { SessionStatus, AuthMethod, createEthAuthInput, createOidcAuthInput, } from "./types";
|
|
19
|
-
export
|
|
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";
|
|
20
19
|
export { loadWasmComponent } from "./wasm";
|
|
21
20
|
export { generateRandomString, generateUUID, getScriptVersion, stringToBytes, bytesToString, redactSecrets, redactSecretsFromJson, } from "./utils";
|
|
22
21
|
export { T3nError, SessionStateError, AuthenticationError, HandshakeError, RpcError, WasmError, decodeWasmErrorMessage, extractWasmError, } from "./utils/errors";
|
package/dist/src/types/auth.d.ts
CHANGED
|
@@ -18,15 +18,14 @@ export interface EthereumSigner {
|
|
|
18
18
|
/**
|
|
19
19
|
* OIDC credentials interface.
|
|
20
20
|
*
|
|
21
|
-
* The TEE generates a session-binding nonce
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* nonce)` from inside `runOidc` and feeds the returned `id_token`
|
|
26
|
-
* to the server.
|
|
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.
|
|
27
25
|
*/
|
|
28
26
|
export interface OidcCredentials {
|
|
29
27
|
provider: string;
|
|
28
|
+
getIdToken: (nonce: string) => Promise<string>;
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
31
|
* Base authentication input with method discriminator
|
|
@@ -1,18 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public types export for T3n SDK
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
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`).
|
|
2
|
+
* Public types export for T3n SDK
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Guest-to-Host request handler function type
|
|
13
6
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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
|
|
16
19
|
*/
|
|
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
|
+
}
|
|
17
41
|
export * from "./session";
|
|
18
42
|
export * from "./auth";
|