@terminal3/t3n-sdk 0.3.0 → 0.4.1
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 +44 -18
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/src/client/handlers.d.ts +32 -8
- package/dist/src/client/transport.d.ts +4 -4
- package/dist/src/types/index.d.ts +9 -2
- package/dist/src/utils/logger.d.ts +4 -4
- package/dist/src/utils/redaction.d.ts +1 -1
- package/dist/src/wasm/loader.d.ts +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { GuestToHostHandler, GuestToHostHandlers } from "../types";
|
|
8
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
|
+
};
|
|
9
17
|
/**
|
|
10
18
|
* Create an EthSign handler using MetaMask (window.ethereum)
|
|
11
19
|
* @param account - MetaMask account (string address or object with address property)
|
|
@@ -13,7 +21,7 @@ import { Logger } from "../utils/logger";
|
|
|
13
21
|
* Pass a custom logger to override logging behavior for this handler.
|
|
14
22
|
* @param privateKey - Optional private key for signing (if provided, MetaMask is not used)
|
|
15
23
|
*/
|
|
16
|
-
export declare function metamask_sign(account:
|
|
24
|
+
export declare function metamask_sign(account: EthAccount, logger?: Logger, privateKey?: string | undefined): GuestToHostHandler;
|
|
17
25
|
/**
|
|
18
26
|
* Get the current MetaMask address
|
|
19
27
|
* @returns Ethereum address (lowercase, 0x prefixed)
|
|
@@ -30,20 +38,36 @@ export declare function eth_get_address(privateKey: string): string;
|
|
|
30
38
|
* from `${baseUrl}/status` on first invocation and caches the encoded
|
|
31
39
|
* response for subsequent calls.
|
|
32
40
|
*
|
|
33
|
-
* @param baseUrl -
|
|
34
|
-
*
|
|
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.
|
|
35
51
|
*/
|
|
36
|
-
export declare function createMlKemPublicKeyHandler(baseUrl
|
|
52
|
+
export declare function createMlKemPublicKeyHandler(baseUrl: string): GuestToHostHandler;
|
|
37
53
|
/**
|
|
38
54
|
* Create Random handler backed by crypto.getRandomValues
|
|
39
55
|
* Note: The Rust Vec<u8> type serializes as an array of bytes, not a base64 string
|
|
40
56
|
*/
|
|
41
57
|
export declare function createRandomHandler(): GuestToHostHandler;
|
|
42
58
|
/**
|
|
43
|
-
* Create the default handler set required by the T3n handshake
|
|
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.
|
|
44
63
|
*/
|
|
45
|
-
export declare function createDefaultHandlers(baseUrl
|
|
64
|
+
export declare function createDefaultHandlers(baseUrl: string): GuestToHostHandlers;
|
|
46
65
|
/**
|
|
47
|
-
* Merge consumer-provided handlers with defaults (user handlers take precedence)
|
|
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.
|
|
48
71
|
*/
|
|
49
|
-
export declare function mergeWithDefaultHandlers(handlers
|
|
72
|
+
export declare function mergeWithDefaultHandlers(handlers: GuestToHostHandlers | undefined, baseUrl: string): GuestToHostHandlers;
|
|
73
|
+
export {};
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
export interface JsonRpcRequest {
|
|
11
11
|
jsonrpc: "2.0";
|
|
12
12
|
method: string;
|
|
13
|
-
params:
|
|
13
|
+
params: unknown;
|
|
14
14
|
id: string | number;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
@@ -18,11 +18,11 @@ export interface JsonRpcRequest {
|
|
|
18
18
|
*/
|
|
19
19
|
export interface JsonRpcResponse {
|
|
20
20
|
jsonrpc: "2.0";
|
|
21
|
-
result?:
|
|
21
|
+
result?: unknown;
|
|
22
22
|
error?: {
|
|
23
23
|
code: number;
|
|
24
24
|
message: string;
|
|
25
|
-
data?:
|
|
25
|
+
data?: unknown;
|
|
26
26
|
};
|
|
27
27
|
id: string | number;
|
|
28
28
|
}
|
|
@@ -84,7 +84,7 @@ export declare class MockTransport implements Transport {
|
|
|
84
84
|
/**
|
|
85
85
|
* Mock an error response for a specific method
|
|
86
86
|
*/
|
|
87
|
-
mockError(method: string, code: number, message: string, data?:
|
|
87
|
+
mockError(method: string, code: number, message: string, data?: unknown): void;
|
|
88
88
|
/**
|
|
89
89
|
* Get all requests that were sent
|
|
90
90
|
*/
|
|
@@ -3,9 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
5
|
* Guest-to-Host request handler function type
|
|
6
|
-
*
|
|
6
|
+
*
|
|
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.
|
|
7
14
|
*/
|
|
8
|
-
export type GuestToHostHandler = (requestData:
|
|
15
|
+
export type GuestToHostHandler = (requestData: Record<string, unknown>) => Promise<Uint8Array>;
|
|
9
16
|
/**
|
|
10
17
|
* Map of guest-to-host request handlers
|
|
11
18
|
* Keys match the guest_to_host tag values from the WASM
|
|
@@ -49,22 +49,22 @@ export interface Logger {
|
|
|
49
49
|
* Log a debug message (most verbose)
|
|
50
50
|
* @param args - Arguments to log
|
|
51
51
|
*/
|
|
52
|
-
debug(...args:
|
|
52
|
+
debug(...args: unknown[]): void;
|
|
53
53
|
/**
|
|
54
54
|
* Log an info message
|
|
55
55
|
* @param args - Arguments to log
|
|
56
56
|
*/
|
|
57
|
-
info(...args:
|
|
57
|
+
info(...args: unknown[]): void;
|
|
58
58
|
/**
|
|
59
59
|
* Log a warning message
|
|
60
60
|
* @param args - Arguments to log
|
|
61
61
|
*/
|
|
62
|
-
warn(...args:
|
|
62
|
+
warn(...args: unknown[]): void;
|
|
63
63
|
/**
|
|
64
64
|
* Log an error message (least verbose)
|
|
65
65
|
* @param args - Arguments to log
|
|
66
66
|
*/
|
|
67
|
-
error(...args:
|
|
67
|
+
error(...args: unknown[]): void;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Set the global default log level for all components
|
|
@@ -16,7 +16,7 @@ export interface WasmLoadConfig {
|
|
|
16
16
|
/** Custom fetch function for loading WASM */
|
|
17
17
|
fetchFn?: typeof fetch;
|
|
18
18
|
/** Additional initialization options */
|
|
19
|
-
initOptions?: Record<string,
|
|
19
|
+
initOptions?: Record<string, unknown>;
|
|
20
20
|
/** Optional logger instance - if not provided, uses global default */
|
|
21
21
|
logger?: Logger;
|
|
22
22
|
}
|