@terminal3/t3n-sdk 0.2.1 → 0.3.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 +41 -59
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/src/client/handlers.d.ts +9 -5
- package/dist/src/config/index.d.ts +29 -48
- package/dist/src/config/loader.d.ts +1 -4
- package/dist/src/config/types.d.ts +2 -2
- package/dist/src/index.d.ts +1 -1
- package/package.json +26 -25
|
@@ -26,10 +26,14 @@ export declare function metamask_get_address(): Promise<string>;
|
|
|
26
26
|
*/
|
|
27
27
|
export declare function eth_get_address(privateKey: string): string;
|
|
28
28
|
/**
|
|
29
|
-
* Create MlKemPublicKey handler that
|
|
30
|
-
*
|
|
29
|
+
* Create an MlKemPublicKey handler that lazily fetches the root public key
|
|
30
|
+
* from `${baseUrl}/status` on first invocation and caches the encoded
|
|
31
|
+
* response for subsequent calls.
|
|
32
|
+
*
|
|
33
|
+
* @param baseUrl - Optional explicit node URL. If omitted, falls back to the
|
|
34
|
+
* current environment default (see `getNodeUrl()`).
|
|
31
35
|
*/
|
|
32
|
-
export declare function createMlKemPublicKeyHandler(): GuestToHostHandler;
|
|
36
|
+
export declare function createMlKemPublicKeyHandler(baseUrl?: string): GuestToHostHandler;
|
|
33
37
|
/**
|
|
34
38
|
* Create Random handler backed by crypto.getRandomValues
|
|
35
39
|
* Note: The Rust Vec<u8> type serializes as an array of bytes, not a base64 string
|
|
@@ -38,8 +42,8 @@ export declare function createRandomHandler(): GuestToHostHandler;
|
|
|
38
42
|
/**
|
|
39
43
|
* Create the default handler set required by the T3n handshake
|
|
40
44
|
*/
|
|
41
|
-
export declare function createDefaultHandlers(): GuestToHostHandlers;
|
|
45
|
+
export declare function createDefaultHandlers(baseUrl?: string): GuestToHostHandlers;
|
|
42
46
|
/**
|
|
43
47
|
* Merge consumer-provided handlers with defaults (user handlers take precedence)
|
|
44
48
|
*/
|
|
45
|
-
export declare function mergeWithDefaultHandlers(handlers?: GuestToHostHandlers): GuestToHostHandlers;
|
|
49
|
+
export declare function mergeWithDefaultHandlers(handlers?: GuestToHostHandlers, baseUrl?: string): GuestToHostHandlers;
|
|
@@ -1,67 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Configuration entry point for T3n SDK
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - All keys (local, staging, production, test) are included in the bundle
|
|
9
|
-
* - Default environment is "production"
|
|
10
|
-
* - Use setEnvironment(env) to change the active key at runtime
|
|
11
|
-
*
|
|
12
|
-
* Binary files are converted to base64 strings at build time by the rollup binary plugin.
|
|
13
|
-
* In development mode (when running with tsx), files are read from the filesystem.
|
|
4
|
+
* The SDK no longer bundles ML-KEM root public keys. Instead, the active node
|
|
5
|
+
* URL is derived from the current environment (or an explicit override / the
|
|
6
|
+
* client's `baseUrl`), and the ML-KEM public key is fetched lazily from
|
|
7
|
+
* `${nodeUrl}/status` (`encaps_key` field) and cached per-URL.
|
|
14
8
|
*/
|
|
15
9
|
import type { SdkConfig, Environment } from "./types";
|
|
16
10
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* This function allows engineers to configure which ML-KEM public key
|
|
20
|
-
* should be used at runtime. All keys are included in the bundle, so
|
|
21
|
-
* switching environments doesn't require rebuilding.
|
|
22
|
-
*
|
|
23
|
-
* @param env - The environment identifier (local, staging, production, or test)
|
|
24
|
-
* @throws Error if the environment is invalid
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* import { setEnvironment } from '@terminal3/t3n-sdk';
|
|
29
|
-
*
|
|
30
|
-
* // Use staging environment
|
|
31
|
-
* setEnvironment('staging');
|
|
32
|
-
* ```
|
|
11
|
+
* Default node URLs per environment. Override at runtime via `setNodeUrl()`
|
|
12
|
+
* or by passing `baseUrl` to `T3nClient`.
|
|
33
13
|
*/
|
|
34
|
-
export declare
|
|
14
|
+
export declare const NODE_URLS: Record<Environment, string>;
|
|
35
15
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* Returns the currently active environment, which defaults to "production".
|
|
39
|
-
* Use setEnvironment() to change the active environment.
|
|
40
|
-
*
|
|
41
|
-
* @returns The current environment identifier
|
|
16
|
+
* Set the active environment. Clears any previous URL override and the key
|
|
17
|
+
* cache so the next fetch uses the new environment's default URL.
|
|
42
18
|
*/
|
|
19
|
+
export declare function setEnvironment(env: Environment): void;
|
|
43
20
|
export declare function getEnvironment(): Environment;
|
|
21
|
+
export declare function getEnvironmentName(): string;
|
|
44
22
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* Returns the SDK configuration with the ML-KEM public key for the
|
|
48
|
-
* currently active environment (set via setEnvironment()).
|
|
23
|
+
* Override the node URL for the current process. Pass `null` to clear and
|
|
24
|
+
* fall back to the environment default.
|
|
49
25
|
*
|
|
50
|
-
*
|
|
26
|
+
* Always clears the per-URL key cache, including the `setNodeUrl(sameUrl)`
|
|
27
|
+
* case — that's the explicit "force a refresh after a node-side ML-KEM
|
|
28
|
+
* rotation" entry point. Keeping a no-op-call optimization here would
|
|
29
|
+
* silently defeat that contract; an extra fetch on a no-op call is cheap.
|
|
51
30
|
*/
|
|
52
|
-
export declare function
|
|
31
|
+
export declare function setNodeUrl(url: string | null): void;
|
|
32
|
+
/** Resolve the active node URL: explicit `baseUrl` > override > env default. */
|
|
33
|
+
export declare function getNodeUrl(baseUrl?: string): string;
|
|
53
34
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @returns The base64-encoded ML-KEM public key for the current environment
|
|
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`.
|
|
58
37
|
*/
|
|
59
|
-
export declare function
|
|
38
|
+
export declare function fetchMlKemPublicKey(baseUrl?: string): Promise<string>;
|
|
39
|
+
/** Clear the cached ML-KEM public keys. Useful in tests. */
|
|
40
|
+
export declare function clearKeyCache(): void;
|
|
60
41
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
42
|
+
* Return the resolved SDK configuration for the current environment.
|
|
43
|
+
* Note: this no longer includes the ML-KEM key — fetch it via
|
|
44
|
+
* `fetchMlKemPublicKey()`.
|
|
64
45
|
*/
|
|
65
|
-
export declare function
|
|
46
|
+
export declare function loadConfig(baseUrl?: string): SdkConfig;
|
|
66
47
|
export type { SdkConfig, Environment, ConfigValidationResult } from "./types";
|
|
67
48
|
export { validateConfig } from "./loader";
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Configuration
|
|
3
|
-
*
|
|
4
|
-
* This module provides configuration validation utilities.
|
|
5
|
-
* All environment keys are included in the bundle, and runtime selection is done via setEnvironment().
|
|
2
|
+
* Configuration validation for T3n SDK
|
|
6
3
|
*/
|
|
7
4
|
import type { ConfigValidationResult } from "./types";
|
|
8
5
|
/**
|
|
@@ -11,8 +11,8 @@ export type Environment = "local" | "staging" | "production" | "test";
|
|
|
11
11
|
export interface SdkConfig {
|
|
12
12
|
/** Environment identifier */
|
|
13
13
|
environment: Environment;
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/** Resolved node URL (used both for RPC and for fetching the ML-KEM key) */
|
|
15
|
+
nodeUrl: string;
|
|
16
16
|
/** Configuration version */
|
|
17
17
|
version: string;
|
|
18
18
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -20,4 +20,4 @@ export { loadWasmComponent } from "./wasm";
|
|
|
20
20
|
export { generateRandomString, generateUUID, getScriptVersion, stringToBytes, bytesToString, redactSecrets, redactSecretsFromJson, } from "./utils";
|
|
21
21
|
export { T3nError, SessionStateError, AuthenticationError, HandshakeError, RpcError, WasmError, decodeWasmErrorMessage, extractWasmError, } from "./utils/errors";
|
|
22
22
|
export type { SdkConfig, Environment, ConfigValidationResult } from "./config";
|
|
23
|
-
export { loadConfig,
|
|
23
|
+
export { loadConfig, fetchMlKemPublicKey, clearKeyCache, getEnvironmentName, getEnvironment, setEnvironment, setNodeUrl, getNodeUrl, NODE_URLS, validateConfig, } from "./config";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terminal3/t3n-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "T3n TypeScript SDK - A minimal SDK that mirrors the server's RPC handler approach",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,6 +22,28 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "cross-env NODE_ENV=production T3N_SDK_SOURCEMAP=true rollup -c && pnpm run copy-wasm",
|
|
27
|
+
"build:public": "pnpm run clean && cross-env NODE_ENV=production T3N_SDK_SOURCEMAP=false rollup -c && pnpm run copy-wasm && node scripts/obfuscate-dist.js",
|
|
28
|
+
"build:watch": "cross-env NODE_ENV=development T3N_SDK_SOURCEMAP=true rollup -c -w",
|
|
29
|
+
"dev": "pnpm run build:watch",
|
|
30
|
+
"copy-wasm": "mkdir -p dist/wasm/generated && cp -r src/wasm/generated/* dist/wasm/generated/",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test:watch": "vitest",
|
|
33
|
+
"test:coverage": "vitest run --coverage",
|
|
34
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
35
|
+
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
36
|
+
"type-check": "tsc --noEmit",
|
|
37
|
+
"clean": "rimraf dist",
|
|
38
|
+
"demo": "pnpm build && tsx demo.ts",
|
|
39
|
+
"demo:dev": "tsx demo.ts",
|
|
40
|
+
"demo:real-wasm": "tsx demo.ts",
|
|
41
|
+
"verify:pack": "node scripts/verify-pack.js",
|
|
42
|
+
"prepublishOnly": "pnpm run build:public && pnpm run verify:pack",
|
|
43
|
+
"release": "node scripts/release.js release",
|
|
44
|
+
"release:tag-only": "node scripts/release.js tag-only",
|
|
45
|
+
"release:verify-version": "node scripts/release.js verify-version"
|
|
46
|
+
},
|
|
25
47
|
"keywords": [
|
|
26
48
|
"t3n",
|
|
27
49
|
"blockchain",
|
|
@@ -36,12 +58,12 @@
|
|
|
36
58
|
"repository": {
|
|
37
59
|
"type": "git",
|
|
38
60
|
"url": "https://github.com/Terminal-3/trinity",
|
|
39
|
-
"directory": "t3n-sdk"
|
|
61
|
+
"directory": "client/t3n-sdk"
|
|
40
62
|
},
|
|
41
63
|
"bugs": {
|
|
42
64
|
"url": "https://github.com/Terminal-3/trinity/issues"
|
|
43
65
|
},
|
|
44
|
-
"homepage": "https://github.com/Terminal-3/trinity/tree/main/t3n-sdk#readme",
|
|
66
|
+
"homepage": "https://github.com/Terminal-3/trinity/tree/main/client/t3n-sdk#readme",
|
|
45
67
|
"devDependencies": {
|
|
46
68
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
47
69
|
"@rollup/plugin-json": "^6.1.0",
|
|
@@ -79,26 +101,5 @@
|
|
|
79
101
|
"@bytecodealliance/jco": "^1.15.3",
|
|
80
102
|
"@bytecodealliance/preview2-shim": "^0.17.5",
|
|
81
103
|
"ethers": "^6.15.0"
|
|
82
|
-
},
|
|
83
|
-
"scripts": {
|
|
84
|
-
"build": "cross-env NODE_ENV=production T3N_SDK_SOURCEMAP=true rollup -c && pnpm run copy-wasm",
|
|
85
|
-
"build:public": "pnpm run clean && cross-env NODE_ENV=production T3N_SDK_SOURCEMAP=false rollup -c && pnpm run copy-wasm && node scripts/obfuscate-dist.js",
|
|
86
|
-
"build:watch": "cross-env NODE_ENV=development T3N_SDK_SOURCEMAP=true rollup -c -w",
|
|
87
|
-
"dev": "pnpm run build:watch",
|
|
88
|
-
"copy-wasm": "mkdir -p dist/wasm/generated && cp -r src/wasm/generated/* dist/wasm/generated/",
|
|
89
|
-
"test": "vitest run",
|
|
90
|
-
"test:watch": "vitest",
|
|
91
|
-
"test:coverage": "vitest run --coverage",
|
|
92
|
-
"lint": "eslint src --ext .ts,.tsx",
|
|
93
|
-
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
94
|
-
"type-check": "tsc --noEmit",
|
|
95
|
-
"clean": "rimraf dist",
|
|
96
|
-
"demo": "pnpm build && tsx demo.ts",
|
|
97
|
-
"demo:dev": "tsx demo.ts",
|
|
98
|
-
"demo:real-wasm": "tsx demo.ts",
|
|
99
|
-
"verify:pack": "node scripts/verify-pack.js",
|
|
100
|
-
"release": "node scripts/release.js release",
|
|
101
|
-
"release:tag-only": "node scripts/release.js tag-only",
|
|
102
|
-
"release:verify-version": "node scripts/release.js verify-version"
|
|
103
104
|
}
|
|
104
|
-
}
|
|
105
|
+
}
|