@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 CHANGED
@@ -155,22 +155,22 @@ interface Logger {
155
155
  * Log a debug message (most verbose)
156
156
  * @param args - Arguments to log
157
157
  */
158
- debug(...args: any[]): void;
158
+ debug(...args: unknown[]): void;
159
159
  /**
160
160
  * Log an info message
161
161
  * @param args - Arguments to log
162
162
  */
163
- info(...args: any[]): void;
163
+ info(...args: unknown[]): void;
164
164
  /**
165
165
  * Log a warning message
166
166
  * @param args - Arguments to log
167
167
  */
168
- warn(...args: any[]): void;
168
+ warn(...args: unknown[]): void;
169
169
  /**
170
170
  * Log an error message (least verbose)
171
171
  * @param args - Arguments to log
172
172
  */
173
- error(...args: any[]): void;
173
+ error(...args: unknown[]): void;
174
174
  }
175
175
  /**
176
176
  * Set the global default log level for all components
@@ -224,7 +224,7 @@ interface WasmLoadConfig {
224
224
  /** Custom fetch function for loading WASM */
225
225
  fetchFn?: typeof fetch;
226
226
  /** Additional initialization options */
227
- initOptions?: Record<string, any>;
227
+ initOptions?: Record<string, unknown>;
228
228
  /** Optional logger instance - if not provided, uses global default */
229
229
  logger?: Logger;
230
230
  }
@@ -320,9 +320,16 @@ declare function createOidcAuthInput(credentials: OidcCredentials): OidcAuthInpu
320
320
  */
321
321
  /**
322
322
  * Guest-to-Host request handler function type
323
- * Handles requests from WASM guest that need host (SDK) to perform side effects
323
+ *
324
+ * Handles requests from WASM guest that need host (SDK) to perform side
325
+ * effects. The exact shape of `requestData` depends on the specific
326
+ * handler — see `GuestToHostHandlers` below for the per-handler shapes.
327
+ * The wrapper layer in `T3nClient.handleGuestToHost` parses the JSON
328
+ * envelope and calls the matching handler with the parsed data, so
329
+ * each handler's implementation should narrow `requestData` to its
330
+ * own expected shape.
324
331
  */
325
- type GuestToHostHandler = (requestData: any) => Promise<Uint8Array>;
332
+ type GuestToHostHandler = (requestData: Record<string, unknown>) => Promise<Uint8Array>;
326
333
  /**
327
334
  * Map of guest-to-host request handlers
328
335
  * Keys match the guest_to_host tag values from the WASM
@@ -361,7 +368,7 @@ interface GuestToHostHandlers {
361
368
  interface JsonRpcRequest {
362
369
  jsonrpc: "2.0";
363
370
  method: string;
364
- params: any;
371
+ params: unknown;
365
372
  id: string | number;
366
373
  }
367
374
  /**
@@ -369,11 +376,11 @@ interface JsonRpcRequest {
369
376
  */
370
377
  interface JsonRpcResponse {
371
378
  jsonrpc: "2.0";
372
- result?: any;
379
+ result?: unknown;
373
380
  error?: {
374
381
  code: number;
375
382
  message: string;
376
- data?: any;
383
+ data?: unknown;
377
384
  };
378
385
  id: string | number;
379
386
  }
@@ -435,7 +442,7 @@ declare class MockTransport implements Transport {
435
442
  /**
436
443
  * Mock an error response for a specific method
437
444
  */
438
- mockError(method: string, code: number, message: string, data?: any): void;
445
+ mockError(method: string, code: number, message: string, data?: unknown): void;
439
446
  /**
440
447
  * Get all requests that were sent
441
448
  */
@@ -567,6 +574,14 @@ declare class T3nClient {
567
574
  * Examples: signing challenges, providing public keys, generating random bytes.
568
575
  */
569
576
 
577
+ /**
578
+ * Account — MetaMask handler accepts either a plain address string or an
579
+ * object with an `address` field (for compatibility with various wallet
580
+ * libraries).
581
+ */
582
+ type EthAccount = string | {
583
+ address: string;
584
+ };
570
585
  /**
571
586
  * Create an EthSign handler using MetaMask (window.ethereum)
572
587
  * @param account - MetaMask account (string address or object with address property)
@@ -574,7 +589,7 @@ declare class T3nClient {
574
589
  * Pass a custom logger to override logging behavior for this handler.
575
590
  * @param privateKey - Optional private key for signing (if provided, MetaMask is not used)
576
591
  */
577
- declare function metamask_sign(account: any, logger?: Logger, privateKey?: string | undefined): GuestToHostHandler;
592
+ declare function metamask_sign(account: EthAccount, logger?: Logger, privateKey?: string | undefined): GuestToHostHandler;
578
593
  /**
579
594
  * Get the current MetaMask address
580
595
  * @returns Ethereum address (lowercase, 0x prefixed)
@@ -591,19 +606,30 @@ declare function eth_get_address(privateKey: string): string;
591
606
  * from `${baseUrl}/status` on first invocation and caches the encoded
592
607
  * response for subsequent calls.
593
608
  *
594
- * @param baseUrl - Optional explicit node URL. If omitted, falls back to the
595
- * current environment default (see `getNodeUrl()`).
609
+ * @param baseUrl - **Required**. The node URL whose `/status` endpoint should
610
+ * serve the ML-KEM public key. Must be the same URL the
611
+ * T3nClient is constructed with — otherwise the handshake
612
+ * encrypts to one node and sends ciphertext to another.
613
+ *
614
+ * Was optional in 0.3.x, where omitting it caused the lazy
615
+ * fetch to silently fall back to `NODE_URLS[currentEnv]` and
616
+ * hit the wrong node. Three downstream consumers (demo.ts,
617
+ * t3-apps dev wallet hooks, t3n-mcp session manager) all
618
+ * hit this trap before we tightened the type.
596
619
  */
597
- declare function createMlKemPublicKeyHandler(baseUrl?: string): GuestToHostHandler;
620
+ declare function createMlKemPublicKeyHandler(baseUrl: string): GuestToHostHandler;
598
621
  /**
599
622
  * Create Random handler backed by crypto.getRandomValues
600
623
  * Note: The Rust Vec<u8> type serializes as an array of bytes, not a base64 string
601
624
  */
602
625
  declare function createRandomHandler(): GuestToHostHandler;
603
626
  /**
604
- * Create the default handler set required by the T3n handshake
627
+ * Create the default handler set required by the T3n handshake.
628
+ *
629
+ * @param baseUrl - **Required**. Forwarded to `createMlKemPublicKeyHandler`
630
+ * so the lazy /status fetch hits the right node.
605
631
  */
606
- declare function createDefaultHandlers(baseUrl?: string): GuestToHostHandlers;
632
+ declare function createDefaultHandlers(baseUrl: string): GuestToHostHandlers;
607
633
 
608
634
  /**
609
635
  * Cryptographic utilities for T3n SDK
@@ -709,7 +735,7 @@ declare function extractWasmError(error: unknown): string;
709
735
  /**
710
736
  * Redact secrets from values before logging
711
737
  */
712
- declare function redactSecrets(value: any): any;
738
+ declare function redactSecrets(value: unknown): unknown;
713
739
  /**
714
740
  * Redact secrets from a JSON string
715
741
  */