@terminal3/t3n-sdk 0.7.0 → 0.10.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 (49) hide show
  1. package/dist/index.d.ts +266 -294
  2. package/dist/index.esm.js +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/src/client/config.d.ts +30 -10
  5. package/dist/src/client/index.d.ts +0 -4
  6. package/dist/src/client/t3n-client.d.ts +27 -64
  7. package/dist/src/config/index.d.ts +36 -2
  8. package/dist/src/index.d.ts +9 -8
  9. package/dist/src/types/auth.d.ts +6 -5
  10. package/dist/src/types/index.d.ts +13 -37
  11. package/dist/src/utils/hkdf.d.ts +36 -0
  12. package/dist/src/utils/index.d.ts +1 -0
  13. package/dist/src/wasm/interface.d.ts +54 -89
  14. package/dist/src/wasm/loader.d.ts +55 -25
  15. package/dist/src/wasm/quote-verifier/quote_verifier_bytes.d.ts +1 -0
  16. package/dist/src/wasm/quote-verifier-loader.d.ts +58 -0
  17. package/dist/wasm/generated/interfaces/host-session-interfaces-contract-dispatch.d.ts +2 -0
  18. package/dist/wasm/generated/interfaces/host-session-interfaces-entropy.d.ts +2 -0
  19. package/dist/wasm/generated/interfaces/host-session-interfaces-eth-signer.d.ts +2 -0
  20. package/dist/wasm/generated/interfaces/host-session-interfaces-kem.d.ts +3 -0
  21. package/dist/wasm/generated/interfaces/host-session-interfaces-oidc-client.d.ts +2 -0
  22. package/dist/wasm/generated/interfaces/host-session-interfaces-oidc.d.ts +3 -0
  23. package/dist/wasm/generated/interfaces/host-session-interfaces-session-ops.d.ts +9 -0
  24. package/dist/wasm/generated/interfaces/host-session-interfaces-transport.d.ts +2 -0
  25. package/dist/wasm/generated/interfaces/tee-session-client-auth.d.ts +7 -0
  26. package/dist/wasm/generated/interfaces/tee-session-client-handshake.d.ts +12 -0
  27. package/dist/wasm/generated/interfaces/tee-session-cookie.d.ts +7 -0
  28. package/dist/wasm/generated/interfaces/tee-session-server-admin.d.ts +2 -0
  29. package/dist/wasm/generated/interfaces/tee-session-server-auth.d.ts +10 -0
  30. package/dist/wasm/generated/interfaces/tee-session-server-handshake.d.ts +15 -0
  31. package/dist/wasm/generated/interfaces/tee-session-server-webhook.d.ts +6 -0
  32. package/dist/wasm/generated/interfaces/tee-session-session-crypto.d.ts +3 -0
  33. package/dist/wasm/generated/session.core.wasm +0 -0
  34. package/dist/wasm/generated/session.core2.wasm +0 -0
  35. package/dist/wasm/generated/session.core3.wasm +0 -0
  36. package/dist/wasm/generated/session.d.ts +87 -12
  37. package/dist/wasm/generated/session.js +6640 -3702
  38. package/package.json +1 -1
  39. package/dist/demo.d.ts +0 -25
  40. package/dist/src/client/actions.d.ts +0 -22
  41. package/dist/src/client/encryption.d.ts +0 -30
  42. package/dist/src/client/handlers.d.ts +0 -73
  43. package/dist/src/client/request-parser.d.ts +0 -48
  44. package/dist/wasm/generated/interfaces/component-session-client-auth.d.ts +0 -12
  45. package/dist/wasm/generated/interfaces/component-session-client-handshake.d.ts +0 -12
  46. package/dist/wasm/generated/interfaces/component-session-cookie.d.ts +0 -8
  47. package/dist/wasm/generated/interfaces/component-session-server-auth.d.ts +0 -13
  48. package/dist/wasm/generated/interfaces/component-session-server-handshake.d.ts +0 -12
  49. package/dist/wasm/generated/interfaces/component-session-session.d.ts +0 -7
@@ -0,0 +1,58 @@
1
+ /**
2
+ * TDX quote verifier backed by the Rust `signature` crate compiled to
3
+ * WASM. Full cryptographic verification: ECDSA P-256 attestation-key
4
+ * signature, PCK certificate chain walk to Intel's root CA, and
5
+ * report_data + RTMR comparison.
6
+ *
7
+ * The WASM bytes are inlined as base64 (see quote_verifier_bytes.ts)
8
+ * so the SDK works without bundler WASM plugins and without runtime
9
+ * asset URL resolution.
10
+ */
11
+ export interface QuoteVerifyResult {
12
+ valid: boolean;
13
+ error?: string;
14
+ rtmr3?: string;
15
+ report_data?: string;
16
+ }
17
+ export interface PeerQuoteResult {
18
+ peer_id: string;
19
+ valid: boolean;
20
+ error?: string;
21
+ rtmr3?: string;
22
+ }
23
+ export interface DkgVerifyResult {
24
+ valid: boolean;
25
+ results: PeerQuoteResult[];
26
+ valid_count: number;
27
+ expected_count: number;
28
+ error?: string;
29
+ }
30
+ /**
31
+ * Verify a single TDX attestation quote with full cryptographic verification.
32
+ *
33
+ * @param quoteB64 - Base64-encoded raw TDX v4 quote
34
+ * @param attestationMsgB64 - Base64-encoded attestation message
35
+ * (for DKG: encaps_key || sorted_peer_id_bytes)
36
+ * @param expectedRtmr3B64 - Optional base64-encoded 48-byte RTMR3
37
+ * @returns Verification result with extracted measurements
38
+ */
39
+ export declare function verifyTdxQuote(quoteB64: string, attestationMsgB64: string, expectedRtmr3B64?: string): Promise<QuoteVerifyResult>;
40
+ /**
41
+ * Verify a full DKG attestation bundle: multiple TDX quotes from all
42
+ * participating nodes, plus the binding between the quotes and the
43
+ * ML-KEM encapsulation key. Checks:
44
+ * 1. attestationMsg starts with encapsKey (server can't swap the key)
45
+ * 2. Every quote's ECDSA signature chains to Intel's SGX root CA
46
+ * 3. Every quote's report_data == keccak512(attestationMsg)
47
+ * 4. Optional RTMR3 pinning per quote
48
+ *
49
+ * @param encapsKeyB64 - Base64-encoded ML-KEM encapsulation key
50
+ * (from `/status.encaps_key`)
51
+ * @param attestationMsgB64 - Base64-encoded raw attestation message
52
+ * (from `/status.dkg_attestation.attestation_msg`)
53
+ * @param peerIds - Sorted array of base58 peer IDs
54
+ * @param quotes - Map of peer_id → base64-encoded TDX quote
55
+ * @param expectedRtmr3B64 - Optional base64-encoded 48-byte RTMR3
56
+ * @returns Per-peer verification results and overall validity
57
+ */
58
+ export declare function verifyDkgAttestation(encapsKeyB64: string, attestationMsgB64: string, peerIds: string[], quotes: Record<string, string>, expectedRtmr3B64?: string): Promise<DkgVerifyResult>;
@@ -0,0 +1,2 @@
1
+ /** @module Interface host:session-interfaces/contract-dispatch@1.0.0 **/
2
+ export function executeAction(contract: string, version: string, functionName: string, did: string, payload: Uint8Array): Uint8Array;
@@ -0,0 +1,2 @@
1
+ /** @module Interface host:session-interfaces/entropy@1.0.0 **/
2
+ export function random(len: number): Uint8Array;
@@ -0,0 +1,2 @@
1
+ /** @module Interface host:session-interfaces/eth-signer@1.0.0 **/
2
+ export function ethSign(message: Uint8Array): Uint8Array;
@@ -0,0 +1,3 @@
1
+ /** @module Interface host:session-interfaces/kem@1.0.0 **/
2
+ export function mlKemPublicKey(): Uint8Array;
3
+ export function decapsulate(ciphertext: Uint8Array): Uint8Array;
@@ -0,0 +1,2 @@
1
+ /** @module Interface host:session-interfaces/oidc-client@1.0.0 **/
2
+ export function getIdToken(provider: string, nonce: string): string;
@@ -0,0 +1,3 @@
1
+ /** @module Interface host:session-interfaces/oidc@1.0.0 **/
2
+ export function fetchJwks(jwksUri: string): Uint8Array;
3
+ export function fetchClientId(providerName: string): string;
@@ -0,0 +1,9 @@
1
+ /** @module Interface host:session-interfaces/session-ops@1.0.0 **/
2
+ export function nowMs(): bigint;
3
+ export function teeAddress(): Uint8Array;
4
+ export function fetchOrCreateDid(authenticatorHashes: Array<Uint8Array>, did: string | undefined): string;
5
+ export function fetchProviderConfig(providerId: string): Uint8Array;
6
+ export function setCookie(cookieValue: string): void;
7
+ export function registerScript(name: string, version: string, wasmBytes: Uint8Array, sourceHash: string | undefined): boolean;
8
+ export function syncUserAuths(): Uint8Array;
9
+ export function updateMeasurements(measurementsBase64: string): boolean;
@@ -0,0 +1,2 @@
1
+ /** @module Interface host:session-interfaces/transport@1.0.0 **/
2
+ export function postRpc(method: string, sessionId: string, params: string): string;
@@ -0,0 +1,7 @@
1
+ /** @module Interface tee:session/client-auth@1.0.0 **/
2
+ export function runEth(sessionKeys: Uint8Array, ethAddress: string, siweDomain: string | undefined, siweUrl: string | undefined, siweChainId: bigint | undefined): Outcome;
3
+ export function runOidc(sessionKeys: Uint8Array, provider: string): Outcome;
4
+ export interface Outcome {
5
+ did: string,
6
+ cookie?: string,
7
+ }
@@ -0,0 +1,12 @@
1
+ /** @module Interface tee:session/client-handshake@1.0.0 **/
2
+ export function run(sid: Uint8Array, cookie: string | undefined): Outcome;
3
+ export interface SessionKeys {
4
+ blob: Uint8Array,
5
+ sid: Uint8Array,
6
+ }
7
+ export interface Outcome {
8
+ keys: SessionKeys,
9
+ authenticated: boolean,
10
+ did?: string,
11
+ expirySec: bigint,
12
+ }
@@ -0,0 +1,7 @@
1
+ /** @module Interface tee:session/cookie@1.0.0 **/
2
+ export function validate(value: string, teeAddress: Uint8Array, nowSec: bigint): Validation;
3
+ export interface Validation {
4
+ authenticated: boolean,
5
+ did?: string,
6
+ exp: bigint,
7
+ }
@@ -0,0 +1,2 @@
1
+ /** @module Interface tee:session/server-admin@1.0.0 **/
2
+ export function run(headers: Array<[string, string]>, body: Uint8Array): Uint8Array;
@@ -0,0 +1,10 @@
1
+ /** @module Interface tee:session/server-auth@1.0.0 **/
2
+ export function run(persistedStateBytes: Uint8Array | undefined, initialActionJson: Uint8Array, siwePolicyJson: Uint8Array): Outcome;
3
+ export interface Outcome {
4
+ responseJson: Uint8Array,
5
+ stateBytes?: Uint8Array,
6
+ cookie?: string,
7
+ did?: string,
8
+ authenticatorsJson?: Uint8Array,
9
+ finalized: boolean,
10
+ }
@@ -0,0 +1,15 @@
1
+ /** @module Interface tee:session/server-handshake@1.0.0 **/
2
+ export function run(sid: Uint8Array, ciphertext: Uint8Array, cookieValue: string | undefined): Outcome;
3
+ export interface SessionKeys {
4
+ c2s: Uint8Array,
5
+ s2c: Uint8Array,
6
+ sid: Uint8Array,
7
+ }
8
+ export interface Outcome {
9
+ keys: SessionKeys,
10
+ rawSecret: Uint8Array,
11
+ authenticated: boolean,
12
+ did?: string,
13
+ expirySec: bigint,
14
+ refreshedCookie?: string,
15
+ }
@@ -0,0 +1,6 @@
1
+ /** @module Interface tee:session/server-webhook@1.0.0 **/
2
+ export function run(providerId: string, headers: Array<[string, string]>, body: Uint8Array): Outcome;
3
+ export interface Outcome {
4
+ replyJson: Uint8Array,
5
+ finalStateBytes: Uint8Array,
6
+ }
@@ -0,0 +1,3 @@
1
+ /** @module Interface tee:session/session-crypto@1.0.0 **/
2
+ export function encrypt(keys: Uint8Array, plaintext: Uint8Array): Uint8Array;
3
+ export function decrypt(keys: Uint8Array, ciphertext: Uint8Array): Uint8Array;
@@ -1,13 +1,88 @@
1
1
  // world root:component/root
2
- export type * as WasiCliEnvironment029 from './interfaces/wasi-cli-environment.js'; // import wasi:cli/environment@0.2.9
3
- export type * as WasiCliExit029 from './interfaces/wasi-cli-exit.js'; // import wasi:cli/exit@0.2.9
4
- export type * as WasiCliStderr029 from './interfaces/wasi-cli-stderr.js'; // import wasi:cli/stderr@0.2.9
5
- export type * as WasiIoError029 from './interfaces/wasi-io-error.js'; // import wasi:io/error@0.2.9
6
- export type * as WasiIoStreams029 from './interfaces/wasi-io-streams.js'; // import wasi:io/streams@0.2.9
7
- export type * as WasiRandomRandom029 from './interfaces/wasi-random-random.js'; // import wasi:random/random@0.2.9
8
- export * as clientAuth from './interfaces/component-session-client-auth.js'; // export component:session/client-auth@0.1.0
9
- export * as serverAuth from './interfaces/component-session-server-auth.js'; // export component:session/server-auth@0.1.0
10
- export * as clientHandshake from './interfaces/component-session-client-handshake.js'; // export component:session/client-handshake@0.1.0
11
- export * as serverHandshake from './interfaces/component-session-server-handshake.js'; // export component:session/server-handshake@0.1.0
12
- export * as session from './interfaces/component-session-session.js'; // export component:session/session@0.1.0
13
- export * as cookie from './interfaces/component-session-cookie.js'; // export component:session/cookie@0.1.0
2
+ import type * as HostSessionInterfacesContractDispatch from './interfaces/host-session-interfaces-contract-dispatch.js'; // host:session-interfaces/contract-dispatch@1.0.0
3
+ import type * as HostSessionInterfacesEntropy from './interfaces/host-session-interfaces-entropy.js'; // host:session-interfaces/entropy@1.0.0
4
+ import type * as HostSessionInterfacesEthSigner from './interfaces/host-session-interfaces-eth-signer.js'; // host:session-interfaces/eth-signer@1.0.0
5
+ import type * as HostSessionInterfacesKem from './interfaces/host-session-interfaces-kem.js'; // host:session-interfaces/kem@1.0.0
6
+ import type * as HostSessionInterfacesOidcClient from './interfaces/host-session-interfaces-oidc-client.js'; // host:session-interfaces/oidc-client@1.0.0
7
+ import type * as HostSessionInterfacesOidc from './interfaces/host-session-interfaces-oidc.js'; // host:session-interfaces/oidc@1.0.0
8
+ import type * as HostSessionInterfacesSessionOps from './interfaces/host-session-interfaces-session-ops.js'; // host:session-interfaces/session-ops@1.0.0
9
+ import type * as HostSessionInterfacesTransport from './interfaces/host-session-interfaces-transport.js'; // host:session-interfaces/transport@1.0.0
10
+ import type * as WasiCliEnvironment from './interfaces/wasi-cli-environment.js'; // wasi:cli/environment@0.2.9
11
+ import type * as WasiCliExit from './interfaces/wasi-cli-exit.js'; // wasi:cli/exit@0.2.9
12
+ import type * as WasiCliStderr from './interfaces/wasi-cli-stderr.js'; // wasi:cli/stderr@0.2.9
13
+ import type * as WasiIoError from './interfaces/wasi-io-error.js'; // wasi:io/error@0.2.9
14
+ import type * as WasiIoStreams from './interfaces/wasi-io-streams.js'; // wasi:io/streams@0.2.9
15
+ import type * as WasiRandomRandom from './interfaces/wasi-random-random.js'; // wasi:random/random@0.2.9
16
+ import type * as TeeSessionClientHandshake from './interfaces/tee-session-client-handshake.js'; // tee:session/client-handshake@1.0.0
17
+ import type * as TeeSessionClientAuth from './interfaces/tee-session-client-auth.js'; // tee:session/client-auth@1.0.0
18
+ import type * as TeeSessionServerHandshake from './interfaces/tee-session-server-handshake.js'; // tee:session/server-handshake@1.0.0
19
+ import type * as TeeSessionServerAuth from './interfaces/tee-session-server-auth.js'; // tee:session/server-auth@1.0.0
20
+ import type * as TeeSessionServerAdmin from './interfaces/tee-session-server-admin.js'; // tee:session/server-admin@1.0.0
21
+ import type * as TeeSessionServerWebhook from './interfaces/tee-session-server-webhook.js'; // tee:session/server-webhook@1.0.0
22
+ import type * as TeeSessionSessionCrypto from './interfaces/tee-session-session-crypto.js'; // tee:session/session-crypto@1.0.0
23
+ import type * as TeeSessionCookie from './interfaces/tee-session-cookie.js'; // tee:session/cookie@1.0.0
24
+ export interface ImportObject {
25
+ 'host:session-interfaces/contract-dispatch@1.0.0': typeof HostSessionInterfacesContractDispatch,
26
+ 'host:session-interfaces/entropy@1.0.0': typeof HostSessionInterfacesEntropy,
27
+ 'host:session-interfaces/eth-signer@1.0.0': typeof HostSessionInterfacesEthSigner,
28
+ 'host:session-interfaces/kem@1.0.0': typeof HostSessionInterfacesKem,
29
+ 'host:session-interfaces/oidc-client@1.0.0': typeof HostSessionInterfacesOidcClient,
30
+ 'host:session-interfaces/oidc@1.0.0': typeof HostSessionInterfacesOidc,
31
+ 'host:session-interfaces/session-ops@1.0.0': typeof HostSessionInterfacesSessionOps,
32
+ 'host:session-interfaces/transport@1.0.0': typeof HostSessionInterfacesTransport,
33
+ 'wasi:cli/environment@0.2.9': typeof WasiCliEnvironment,
34
+ 'wasi:cli/exit@0.2.9': typeof WasiCliExit,
35
+ 'wasi:cli/stderr@0.2.9': typeof WasiCliStderr,
36
+ 'wasi:io/error@0.2.9': typeof WasiIoError,
37
+ 'wasi:io/streams@0.2.9': typeof WasiIoStreams,
38
+ 'wasi:random/random@0.2.9': typeof WasiRandomRandom,
39
+ }
40
+ export interface Root {
41
+ 'tee:session/client-handshake@1.0.0': typeof TeeSessionClientHandshake,
42
+ clientHandshake: typeof TeeSessionClientHandshake,
43
+ 'tee:session/client-auth@1.0.0': typeof TeeSessionClientAuth,
44
+ clientAuth: typeof TeeSessionClientAuth,
45
+ 'tee:session/server-handshake@1.0.0': typeof TeeSessionServerHandshake,
46
+ serverHandshake: typeof TeeSessionServerHandshake,
47
+ 'tee:session/server-auth@1.0.0': typeof TeeSessionServerAuth,
48
+ serverAuth: typeof TeeSessionServerAuth,
49
+ 'tee:session/server-admin@1.0.0': typeof TeeSessionServerAdmin,
50
+ serverAdmin: typeof TeeSessionServerAdmin,
51
+ 'tee:session/server-webhook@1.0.0': typeof TeeSessionServerWebhook,
52
+ serverWebhook: typeof TeeSessionServerWebhook,
53
+ 'tee:session/session-crypto@1.0.0': typeof TeeSessionSessionCrypto,
54
+ sessionCrypto: typeof TeeSessionSessionCrypto,
55
+ 'tee:session/cookie@1.0.0': typeof TeeSessionCookie,
56
+ cookie: typeof TeeSessionCookie,
57
+ }
58
+
59
+ /**
60
+ * Instantiates this component with the provided imports and
61
+ * returns a map of all the exports of the component.
62
+ *
63
+ * This function is intended to be similar to the
64
+ * `WebAssembly.instantiate` function. The second `imports`
65
+ * argument is the "import object" for wasm, except here it
66
+ * uses component-model-layer types instead of core wasm
67
+ * integers/numbers/etc.
68
+ *
69
+ * The first argument to this function, `getCoreModule`, is
70
+ * used to compile core wasm modules within the component.
71
+ * Components are composed of core wasm modules and this callback
72
+ * will be invoked per core wasm module. The caller of this
73
+ * function is responsible for reading the core wasm module
74
+ * identified by `path` and returning its compiled
75
+ * `WebAssembly.Module` object. This would use `compileStreaming`
76
+ * on the web, for example.
77
+ */
78
+ export function instantiate(
79
+ getCoreModule: (path: string) => WebAssembly.Module,
80
+ imports: ImportObject,
81
+ instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => WebAssembly.Instance
82
+ ): Root;
83
+ export function instantiate(
84
+ getCoreModule: (path: string) => WebAssembly.Module | Promise<WebAssembly.Module>,
85
+ imports: ImportObject,
86
+ instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => WebAssembly.Instance | Promise<WebAssembly.Instance>
87
+ ): Root | Promise<Root>;
88
+