@terminal3/t3n-sdk 3.3.0 → 3.4.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.
Files changed (42) hide show
  1. package/README.md +33 -796
  2. package/dist/index.d.ts +281 -115
  3. package/dist/index.esm.js +1 -1
  4. package/dist/index.js +1 -1
  5. package/package.json +10 -60
  6. package/README.OIDC.md +0 -216
  7. package/dist/demo.d.ts +0 -25
  8. package/dist/src/client/actions.d.ts +0 -31
  9. package/dist/src/client/config.d.ts +0 -33
  10. package/dist/src/client/contract-response.d.ts +0 -59
  11. package/dist/src/client/delegation.d.ts +0 -388
  12. package/dist/src/client/encryption.d.ts +0 -30
  13. package/dist/src/client/handlers.d.ts +0 -73
  14. package/dist/src/client/index.d.ts +0 -13
  15. package/dist/src/client/org-data.d.ts +0 -276
  16. package/dist/src/client/request-parser.d.ts +0 -48
  17. package/dist/src/client/t3n-client.d.ts +0 -544
  18. package/dist/src/client/transport.d.ts +0 -131
  19. package/dist/src/config/index.d.ts +0 -82
  20. package/dist/src/config/loader.d.ts +0 -8
  21. package/dist/src/config/types.d.ts +0 -25
  22. package/dist/src/index.d.ts +0 -39
  23. package/dist/src/types/auth.d.ts +0 -66
  24. package/dist/src/types/index.d.ts +0 -45
  25. package/dist/src/types/kyc.d.ts +0 -135
  26. package/dist/src/types/org-data.d.ts +0 -180
  27. package/dist/src/types/session.d.ts +0 -24
  28. package/dist/src/types/token.d.ts +0 -102
  29. package/dist/src/types/user.d.ts +0 -236
  30. package/dist/src/utils/contract-version.d.ts +0 -5
  31. package/dist/src/utils/crypto.d.ts +0 -52
  32. package/dist/src/utils/errors.d.ts +0 -144
  33. package/dist/src/utils/index.d.ts +0 -10
  34. package/dist/src/utils/logger.d.ts +0 -102
  35. package/dist/src/utils/redaction.d.ts +0 -13
  36. package/dist/src/utils/session.d.ts +0 -37
  37. package/dist/src/utils/shape.d.ts +0 -30
  38. package/dist/src/wasm/index.d.ts +0 -5
  39. package/dist/src/wasm/interface.d.ts +0 -110
  40. package/dist/src/wasm/loader.d.ts +0 -43
  41. package/dist/src/wasm/quote-verifier/quote_verifier_bytes.d.ts +0 -1
  42. package/dist/src/wasm/quote-verifier-loader.d.ts +0 -58
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terminal3/t3n-sdk",
3
- "version": "3.3.0",
3
+ "version": "3.4.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,35 +22,6 @@
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
- "store-token": "tsx scripts/payroll-v2-store-token.ts",
34
- "test:coverage": "vitest run --coverage",
35
- "lint": "eslint src --ext .ts,.tsx",
36
- "lint:fix": "eslint src --ext .ts,.tsx --fix",
37
- "type-check": "tsc --noEmit",
38
- "clean": "rimraf dist",
39
- "demo": "pnpm build && tsx demo.ts",
40
- "demo:dev": "tsx demo.ts",
41
- "demo:real-wasm": "tsx demo.ts",
42
- "demo:tenant:admit": "tsx --tsconfig tsconfig.demo.json tenant-demo.ts --cmd admit",
43
- "demo:tenant:setup": "tsx --tsconfig tsconfig.demo.json tenant-demo.ts --cmd setup",
44
- "demo:tenant:fix-readers": "tsx --tsconfig tsconfig.demo.json tenant-demo.ts --cmd fix-readers",
45
- "demo:tenant:search": "tsx --tsconfig tsconfig.demo.json tenant-demo.ts --cmd search",
46
- "demo:tenant:book": "tsx --tsconfig tsconfig.demo.json tenant-demo.ts --cmd book",
47
- "demo:tenant:self-admit": "tsx --tsconfig tsconfig.demo.json demo-tenant-self-admit.ts",
48
- "verify:pack": "node scripts/verify-pack.js",
49
- "prepublishOnly": "pnpm run build:public && pnpm run verify:pack",
50
- "release": "node scripts/release.js release",
51
- "release:tag-only": "node scripts/release.js tag-only",
52
- "release:verify-version": "node scripts/release.js verify-version"
53
- },
54
25
  "keywords": [
55
26
  "t3n",
56
27
  "blockchain",
@@ -71,40 +42,12 @@
71
42
  "url": "https://github.com/Terminal-3/trinity/issues"
72
43
  },
73
44
  "homepage": "https://github.com/Terminal-3/trinity/tree/main/client/t3n-sdk#readme",
74
- "devDependencies": {
75
- "@rollup/plugin-commonjs": "^25.0.8",
76
- "@rollup/plugin-json": "^6.1.0",
77
- "@rollup/plugin-node-resolve": "^15.3.1",
78
- "@rollup/plugin-replace": "^5.0.7",
79
- "@rollup/plugin-typescript": "^11.1.6",
80
- "@types/jest": "^29.5.14",
81
- "@types/mocha": "^10.0.10",
82
- "@types/node": "^20.19.39",
83
- "@typescript-eslint/eslint-plugin": "^6.21.0",
84
- "@typescript-eslint/parser": "^6.21.0",
85
- "@vitest/coverage-v8": "^4.1.4",
86
- "cpy-cli": "^4.2.0",
87
- "cross-env": "^7.0.3",
88
- "eslint": "^8.57.1",
89
- "javascript-obfuscator": "^4.2.2",
90
- "jest": "^29.7.0",
91
- "rimraf": "^5.0.10",
92
- "rollup": "^4.60.1",
93
- "rollup-plugin-dts": "^6.4.1",
94
- "ts-jest": "^29.4.9",
95
- "ts-node": "^10.9.2",
96
- "tslib": "^2.8.1",
97
- "tsx": "^4.21.0",
98
- "typescript": "^5.9.3",
99
- "vite": "^7.3.2",
100
- "vitest": "^4.1.4"
45
+ "engines": {
46
+ "node": ">=16.0.0"
101
47
  },
102
48
  "peerDependencies": {
103
49
  "typescript": ">=4.5.0"
104
50
  },
105
- "engines": {
106
- "node": ">=16.0.0"
107
- },
108
51
  "dependencies": {
109
52
  "@bytecodealliance/jco": "^1.17.6",
110
53
  "@bytecodealliance/preview2-shim": "^0.17.8",
@@ -112,5 +55,12 @@
112
55
  "@noble/hashes": "^2.2.0",
113
56
  "canonicalize": "^3.0.0",
114
57
  "ethers": "^6.16.0"
58
+ },
59
+ "t3n": {
60
+ "packMode": "public",
61
+ "supportedEnvironments": [
62
+ "testnet",
63
+ "production"
64
+ ]
115
65
  }
116
66
  }
package/README.OIDC.md DELETED
@@ -1,216 +0,0 @@
1
- # OIDC Authentication Guide
2
-
3
- ## Quick Start
4
-
5
- ### 1. Setup Google OAuth Client
6
-
7
- 1. Go to [Google Cloud Console](https://console.cloud.google.com/)
8
- 2. Create a new project or select existing one
9
- 3. Enable "Google Sign-In" API
10
- 4. Go to **Credentials** → **Create Credentials** → **OAuth 2.0 Client ID**
11
- 5. Application type: **Web application**
12
- 6. Authorized JavaScript origins:
13
- ```
14
- http://localhost:8081
15
- ```
16
- (Port 8081 is what the demo uses)
17
- 7. Copy your **Client ID**
18
-
19
- ### 2. Update the HTML File
20
-
21
- Edit `oidc-login.html` and replace:
22
-
23
- ```html
24
- data-client_id="PUT_YOUR_WEB_CLIENT_ID_HERE"
25
- ```
26
-
27
- With your actual Client ID:
28
-
29
- ```html
30
- data-client_id="YOUR_ACTUAL_CLIENT_ID.apps.googleusercontent.com"
31
- ```
32
-
33
- ### 3. Get ID Token
34
-
35
- #### Option A: Using the Helper Script (Recommended)
36
-
37
- ```bash
38
- npx tsx get-oidc-token.ts
39
- ```
40
-
41
- This will:
42
- 1. Open the browser with Google Sign-In
43
- 2. Display your ID token after sign-in
44
- 3. Provide code examples
45
-
46
- #### Option B: Manual (No CLI needed)
47
-
48
- 1. Open `oidc-login.html` in your browser:
49
- ```bash
50
- open oidc-login.html # macOS
51
- # or
52
- xdg-open oidc-login.html # Linux
53
- # or just double-click the file
54
- ```
55
-
56
- 2. Click "Sign in with Google"
57
-
58
- 3. Copy the ID token displayed
59
-
60
- 4. Use it in your code:
61
- ```typescript
62
- const authenticator = {
63
- provider: "google",
64
- id_token: "eyJhbGciOiJS..." // Your copied token
65
- };
66
-
67
- await client.performAuthentication(authenticator);
68
- ```
69
-
70
- ### 4. Use in Demo
71
-
72
- ```typescript
73
- // In demo.ts
74
- import * as readline from 'readline';
75
-
76
- async function getOidcToken(): Promise<string> {
77
- console.log('\n🔐 OIDC Authentication');
78
- console.log('1. Open oidc-login.html in your browser');
79
- console.log('2. Sign in with Google');
80
- console.log('3. Copy the ID token\n');
81
-
82
- const rl = readline.createInterface({
83
- input: process.stdin,
84
- output: process.stdout
85
- });
86
-
87
- return new Promise((resolve) => {
88
- rl.question('Paste your ID token: ', (token) => {
89
- rl.close();
90
- resolve(token.trim());
91
- });
92
- });
93
- }
94
-
95
- // Usage
96
- const idToken = await getOidcToken();
97
- const authenticator = {
98
- provider: "google",
99
- id_token: idToken
100
- };
101
-
102
- await client.performAuthentication(authenticator);
103
- ```
104
-
105
- ## Supported Providers
106
-
107
- | Provider | Status | Setup Guide |
108
- | ------------ | --------------- | -------------------------------------------------- |
109
- | **Google** | ✅ Ready | [Google OAuth Setup](https://developers.google.com/identity/sign-in/web/sign-in) |
110
- | **Microsoft** | ✅ Ready | [Azure AD Setup](https://learn.microsoft.com/en-us/azure/active-directory/) |
111
- | **Apple** | ✅ Ready | [Sign in with Apple](https://developer.apple.com/sign-in-with-apple/) |
112
- | **GitHub** | ✅ Ready | [GitHub OAuth](https://docs.github.com/en/developers/apps/building-oauth-apps) |
113
- | **Facebook** | ✅ Ready | [Facebook Login](https://developers.facebook.com/docs/facebook-login/) |
114
-
115
- ## Architecture
116
-
117
- ### Frontend-Driven PKCE Flow
118
-
119
- ```
120
- ┌─────────────┐ ┌──────────────┐ ┌─────────────┐
121
- │ Browser │ │ T3n │ │ Google │
122
- │ (Popup) │ │ Backend │ │ OAuth │
123
- └──────┬──────┘ └──────┬───────┘ └──────┬──────┘
124
- │ │ │
125
- │ 1. Generate PKCE │ │
126
- ├──────────────────────►│ │
127
- │ (code_verifier) │ │
128
- │ │ │
129
- │ 2. Redirect to OAuth │ │
130
- ├───────────────────────┼───────────────────────►│
131
- │ (with code_challenge)│ │
132
- │ │ │
133
- │ 3. User signs in │ │
134
- │◄──────────────────────┼────────────────────────┤
135
- │ │ │
136
- │ 4. Exchange code │ │
137
- │ (with code_verifier) │ │
138
- ├───────────────────────┼───────────────────────►│
139
- │ │ │
140
- │ 5. Receive ID token │ │
141
- │◄──────────────────────┼────────────────────────┤
142
- │ │ │
143
- │ 6. Send ID token │ │
144
- ├──────────────────────►│ │
145
- │ │ │
146
- │ │ 7. Verify token │
147
- │ │ (fetch JWKS & validate)
148
- │ │ │
149
- │ 8. Session created │ │
150
- │◄──────────────────────┤ │
151
- │ │ │
152
- ```
153
-
154
- ### Key Benefits
155
-
156
- - ✅ **No Backend PKCE**: Frontend handles PKCE entirely
157
- - ✅ **Stateless Backend**: No session storage for PKCE
158
- - ✅ **Secure**: Backend independently verifies tokens
159
- - ✅ **Simple CLI**: Just paste the token, no complex flow
160
- - ✅ **Works Everywhere**: Browser handles OAuth, CLI gets result
161
-
162
- ## Token Format
163
-
164
- The ID token is a JWT with three parts:
165
-
166
- ```
167
- eyJhbGciOiJSUzI1NiIsImtpZCI6Ijc... (header)
168
- .
169
- eyJpc3MiOiJodHRwczovL2FjY291bnR... (payload)
170
- .
171
- SflKxwRJSMeKKF2QT4fwpMeJf36POk6... (signature)
172
- ```
173
-
174
- ### Payload Example
175
-
176
- ```json
177
- {
178
- "iss": "https://accounts.google.com",
179
- "sub": "1234567890",
180
- "email": "user@example.com",
181
- "email_verified": true,
182
- "name": "John Doe",
183
- "picture": "https://...",
184
- "iat": 1700000000,
185
- "exp": 1700003600
186
- }
187
- ```
188
-
189
- ## Security Notes
190
-
191
- 1. **Token Expiration**: ID tokens are short-lived (typically 1 hour)
192
- 2. **Verification**: Backend always verifies token signature with JWKS
193
- 3. **Email Verified**: Backend checks `email_verified` claim
194
- 4. **CSRF Protection**: State parameter prevents CSRF attacks
195
- 5. **PKCE**: Code verifier prevents authorization code interception
196
-
197
- ## Troubleshooting
198
-
199
- ### Token Already Expired
200
-
201
- ID tokens expire quickly. If you get an error:
202
- 1. Get a fresh token from the browser
203
- 2. Use it immediately
204
-
205
- ### Invalid Token Format
206
-
207
- Make sure you copied the entire token (it's quite long!). Should have 3 parts separated by dots.
208
-
209
- ### Provider Not Found
210
-
211
- Make sure `provider` matches exactly: `"google"`, `"microsoft"`, `"apple"`, etc. (lowercase)
212
-
213
- ### CORS Errors in Browser
214
-
215
- For production, add your domain to OAuth client's authorized origins in Google Cloud Console.
216
-
package/dist/demo.d.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- * T3n SDK Real WASM Demo Script
3
- *
4
- * This script demonstrates the T3n SDK using the actual WASM component
5
- * built from the node session module.
6
- */
7
- import { SessionStatus, Did } from "./src/index";
8
- import { type ChildProcess } from "child_process";
9
- declare global {
10
- var __oidcServerProcess: ChildProcess | undefined;
11
- }
12
- interface DemoResult {
13
- sessionId: {
14
- value: string;
15
- } | null;
16
- status: SessionStatus;
17
- wasmLoaded: boolean;
18
- authenticated: boolean;
19
- did: Did | null;
20
- }
21
- /**
22
- * Main Demo Function
23
- */
24
- declare function runRealWasmDemo(): Promise<DemoResult>;
25
- export { runRealWasmDemo, type DemoResult };
@@ -1,31 +0,0 @@
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 type { 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;
23
- /**
24
- * Create the initial action for the ADD-authenticator flow: link a new
25
- * Ethereum wallet to the session's already-authenticated DID. Drives
26
- * the same client state machine as {@link createAuthAction} (eth), but
27
- * the `AddAuthenticator` tag routes the server to the link path instead
28
- * of resolve-or-mint. Only Ethereum is supported — OIDC/email identities
29
- * are established at login, not added afterwards.
30
- */
31
- export declare function createAddEthAuthAction(address: string): Uint8Array;
@@ -1,33 +0,0 @@
1
- /**
2
- * Configuration types for T3n Client
3
- */
4
- import { WasmComponent } from "../wasm";
5
- import { GuestToHostHandlers } from "../types";
6
- import { Logger, LogLevel } from "../utils/logger";
7
- import { Transport } from "./transport";
8
- /**
9
- * Configuration interface for T3n Client
10
- */
11
- export interface T3nClientConfig {
12
- /** Base URL of the T3n node (used if transport not provided) */
13
- baseUrl?: string;
14
- /** WASM component instance for cryptographic operations */
15
- wasmComponent: WasmComponent;
16
- /** Optional transport layer - if not provided, uses HttpTransport with baseUrl */
17
- transport?: Transport;
18
- /** Optional request timeout in milliseconds (default: 30000) - used for HttpTransport */
19
- timeout?: number;
20
- /** Optional custom headers to include in requests */
21
- headers?: Record<string, string>;
22
- /**
23
- * Log level for this client instance.
24
- * Defaults to global log level (LogLevel.ERROR) if not specified.
25
- * Use LogLevel.DEBUG for verbose logging, LogLevel.INFO for informational messages,
26
- * LogLevel.WARN for warnings, or LogLevel.ERROR for errors only.
27
- */
28
- logLevel?: LogLevel;
29
- /** Optional custom logger - if provided, overrides logLevel */
30
- logger?: Logger;
31
- /** Optional guest-to-host request handlers - provides custom behavior for WASM requests */
32
- handlers?: GuestToHostHandlers;
33
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * Contract response decoding for {@link T3nClient.execute}.
3
- *
4
- * ## On-wire shape
5
- *
6
- * Trinity contracts are declared as `result<list<u8>, string>` in WIT and
7
- * return JSON-encoded bytes. The server-side pipeline is:
8
- *
9
- * 1. `node/wasm/src/dynamic.rs:component_val_to_json` deserializes those
10
- * bytes to a JSON `Value` (the contract's decoded return value).
11
- * 2. `node/wasm/src/runner.rs:run_dynamic` wraps that value in a
12
- * `ContractResponse` struct internally for host-side bookkeeping —
13
- * it carries an extracted `otp_state` alongside the response.
14
- * 3. **`node/app/src/services/wasm.rs:200`** then unwraps the struct with
15
- * `Ok((response.response, tx_back))`, discarding the `otp_state` field
16
- * and returning only the inner `Value` across the `WasmExecutor` trait
17
- * boundary.
18
- * 4. `node/service/src/action.rs` serialises that plain `Value` through
19
- * the session channel.
20
- *
21
- * The client therefore receives the contract's **decoded JSON value
22
- * directly** — no `{response, otp_state}` envelope, despite what the
23
- * struct name suggests. `parseContractResponse` reflects that reality:
24
- * it does a typed `JSON.parse` with optional schema validation, nothing
25
- * more. OTP flows read their `otp_status` / OTP fields directly off the
26
- * contract's response body; there is no separate envelope field for them
27
- * on this path.
28
- */
29
- import { T3nError } from "../utils/errors";
30
- /**
31
- * Minimal validator interface. Any library that exposes `.parse(value) -> T`
32
- * (zod, valibot, superstruct, custom) is compatible.
33
- */
34
- export interface ContractResponseSchema<T> {
35
- parse(value: unknown): T;
36
- }
37
- /**
38
- * Thrown when the response string from {@link T3nClient.execute} cannot
39
- * be parsed as JSON.
40
- *
41
- * Schema-validation failures are NOT wrapped — they surface as whatever
42
- * error the caller's validator throws, preserving the rich diagnostics
43
- * those libraries already provide.
44
- */
45
- export declare class ContractResponseError extends T3nError {
46
- readonly raw?: string | undefined;
47
- constructor(message: string, raw?: string | undefined);
48
- }
49
- /**
50
- * Parse the JSON-encoded response returned by {@link T3nClient.execute}
51
- * into a typed value.
52
- *
53
- * @param raw - the string returned by {@link T3nClient.execute}
54
- * @param schema - optional validator applied to the parsed value
55
- * @returns the decoded response, typed as `T`
56
- * @throws {ContractResponseError} when `raw` is not valid JSON
57
- * @throws whatever the schema throws on validation failure (e.g. `ZodError`)
58
- */
59
- export declare function parseContractResponse<T = unknown>(raw: string, schema?: ContractResponseSchema<T>): T;