@terminal3/t3n-sdk 0.7.0 → 0.8.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 CHANGED
@@ -789,6 +789,65 @@ interface ConfigValidationResult {
789
789
  errors: string[];
790
790
  }
791
791
 
792
+ /**
793
+ * TDX quote verifier backed by the Rust `signature` crate compiled to
794
+ * WASM. Full cryptographic verification: ECDSA P-256 attestation-key
795
+ * signature, PCK certificate chain walk to Intel's root CA, and
796
+ * report_data + RTMR comparison.
797
+ *
798
+ * The WASM bytes are inlined as base64 (see quote_verifier_bytes.ts)
799
+ * so the SDK works without bundler WASM plugins and without runtime
800
+ * asset URL resolution.
801
+ */
802
+ interface QuoteVerifyResult {
803
+ valid: boolean;
804
+ error?: string;
805
+ rtmr3?: string;
806
+ report_data?: string;
807
+ }
808
+ interface PeerQuoteResult {
809
+ peer_id: string;
810
+ valid: boolean;
811
+ error?: string;
812
+ rtmr3?: string;
813
+ }
814
+ interface DkgVerifyResult {
815
+ valid: boolean;
816
+ results: PeerQuoteResult[];
817
+ valid_count: number;
818
+ expected_count: number;
819
+ error?: string;
820
+ }
821
+ /**
822
+ * Verify a single TDX attestation quote with full cryptographic verification.
823
+ *
824
+ * @param quoteB64 - Base64-encoded raw TDX v4 quote
825
+ * @param attestationMsgB64 - Base64-encoded attestation message
826
+ * (for DKG: encaps_key || sorted_peer_id_bytes)
827
+ * @param expectedRtmr3B64 - Optional base64-encoded 48-byte RTMR3
828
+ * @returns Verification result with extracted measurements
829
+ */
830
+ declare function verifyTdxQuote(quoteB64: string, attestationMsgB64: string, expectedRtmr3B64?: string): Promise<QuoteVerifyResult>;
831
+ /**
832
+ * Verify a full DKG attestation bundle: multiple TDX quotes from all
833
+ * participating nodes, plus the binding between the quotes and the
834
+ * ML-KEM encapsulation key. Checks:
835
+ * 1. attestationMsg starts with encapsKey (server can't swap the key)
836
+ * 2. Every quote's ECDSA signature chains to Intel's SGX root CA
837
+ * 3. Every quote's report_data == keccak512(attestationMsg)
838
+ * 4. Optional RTMR3 pinning per quote
839
+ *
840
+ * @param encapsKeyB64 - Base64-encoded ML-KEM encapsulation key
841
+ * (from `/status.encaps_key`)
842
+ * @param attestationMsgB64 - Base64-encoded raw attestation message
843
+ * (from `/status.dkg_attestation.attestation_msg`)
844
+ * @param peerIds - Sorted array of base58 peer IDs
845
+ * @param quotes - Map of peer_id → base64-encoded TDX quote
846
+ * @param expectedRtmr3B64 - Optional base64-encoded 48-byte RTMR3
847
+ * @returns Per-peer verification results and overall validity
848
+ */
849
+ declare function verifyDkgAttestation(encapsKeyB64: string, attestationMsgB64: string, peerIds: string[], quotes: Record<string, string>, expectedRtmr3B64?: string): Promise<DkgVerifyResult>;
850
+
792
851
  /**
793
852
  * Configuration validation for T3n SDK
794
853
  */
@@ -812,6 +871,18 @@ declare function validateConfig(config: unknown): ConfigValidationResult;
812
871
  * or by passing `baseUrl` to `T3nClient`.
813
872
  */
814
873
  declare const NODE_URLS: Record<Environment, string>;
874
+ /** DKG attestation bundle from the cluster. */
875
+ interface DkgAttestation {
876
+ /** Sorted base58 peer IDs that participated in DKG. */
877
+ peer_ids: string[];
878
+ /** Per-node TDX quotes keyed by base58 peer ID (base64-encoded). */
879
+ quotes: Record<string, string>;
880
+ /**
881
+ * Base64-encoded raw attestation message: `encaps_key || sorted_peer_ids`.
882
+ * Each quote's `report_data` is `keccak512(attestation_msg)`.
883
+ */
884
+ attestation_msg: string;
885
+ }
815
886
  /**
816
887
  * Set the active environment. Clears any previous URL override and the key
817
888
  * cache so the next fetch uses the new environment's default URL.
@@ -832,10 +903,30 @@ declare function setNodeUrl(url: string | null): void;
832
903
  /** Resolve the active node URL: explicit `baseUrl` > override > env default. */
833
904
  declare function getNodeUrl(baseUrl?: string): string;
834
905
  /**
835
- * Fetch the ML-KEM root public key from `${nodeUrl}/status`. Cached per URL.
836
- * The node must be in the `Ready` phase and expose `encaps_key`.
906
+ * Fetch the ML-KEM root public key from `${nodeUrl}/status`. Cached
907
+ * per URL because the key is stable for the cluster's lifetime (a
908
+ * new DKG means a full redeploy; callers clear the cache via
909
+ * `clearKeyCache()` or `setNodeUrl()` in that case).
910
+ *
911
+ * Returns only the base64-encoded key. For the DKG attestation
912
+ * bundle (which changes over time as peer quotes replicate via
913
+ * Raft), call `fetchDkgAttestation()` \u2014 that path is
914
+ * intentionally uncached.
837
915
  */
838
916
  declare function fetchMlKemPublicKey(baseUrl?: string): Promise<string>;
917
+ /**
918
+ * Fetch the DKG attestation bundle from `${nodeUrl}/status`. Never
919
+ * cached \u2014 peer quotes are written to consensus KV asynchronously
920
+ * during cluster bootstrap, so early reads may see a subset of the
921
+ * expected quotes. Caching would pin an incomplete bundle and cause
922
+ * spurious `valid_count < expected_count` failures in
923
+ * `verifyDkgAttestation()` for the whole process lifetime.
924
+ *
925
+ * Returns `undefined` when the node has not yet published an
926
+ * attestation (e.g. still bootstrapping, or running with a mock
927
+ * signer where attestation is skipped by design).
928
+ */
929
+ declare function fetchDkgAttestation(baseUrl?: string): Promise<DkgAttestation | undefined>;
839
930
  /** Clear the cached ML-KEM public keys. Useful in tests. */
840
931
  declare function clearKeyCache(): void;
841
932
  /**
@@ -845,5 +936,5 @@ declare function clearKeyCache(): void;
845
936
  */
846
937
  declare function loadConfig(baseUrl?: string): SdkConfig;
847
938
 
848
- export { AuthMethod, AuthenticationError, HandshakeError, HttpTransport, LogLevel, MockTransport, NODE_URLS, RpcError, SessionStateError, SessionStatus, T3nClient, T3nError, WasmError, bytesToString, clearKeyCache, createDefaultHandlers, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createRandomHandler, decodeWasmErrorMessage, eth_get_address, extractWasmError, fetchMlKemPublicKey, generateRandomString, generateUUID, getEnvironment, getEnvironmentName, getGlobalLogLevel, getLogger, getNodeUrl, getScriptVersion, loadConfig, loadWasmComponent, metamask_get_address, metamask_sign, redactSecrets, redactSecretsFromJson, setEnvironment, setGlobalLogLevel, setNodeUrl, stringToBytes, validateConfig };
849
- export type { AuthInput, ClientAuth, ClientHandshake, ConfigValidationResult, Did, Environment, EthAuthInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, Logger, OidcAuthInput, OidcCredentials, SdkConfig, SessionCrypto, SessionId, T3nClientConfig, Transport, WasmComponent, WasmNextResult };
939
+ export { AuthMethod, AuthenticationError, HandshakeError, HttpTransport, LogLevel, MockTransport, NODE_URLS, RpcError, SessionStateError, SessionStatus, T3nClient, T3nError, WasmError, bytesToString, clearKeyCache, createDefaultHandlers, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createRandomHandler, decodeWasmErrorMessage, eth_get_address, extractWasmError, fetchDkgAttestation, fetchMlKemPublicKey, generateRandomString, generateUUID, getEnvironment, getEnvironmentName, getGlobalLogLevel, getLogger, getNodeUrl, getScriptVersion, loadConfig, loadWasmComponent, metamask_get_address, metamask_sign, redactSecrets, redactSecretsFromJson, setEnvironment, setGlobalLogLevel, setNodeUrl, stringToBytes, validateConfig, verifyDkgAttestation, verifyTdxQuote };
940
+ export type { AuthInput, ClientAuth, ClientHandshake, ConfigValidationResult, Did, DkgAttestation, DkgVerifyResult, Environment, EthAuthInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, Logger, OidcAuthInput, OidcCredentials, PeerQuoteResult, QuoteVerifyResult, SdkConfig, SessionCrypto, SessionId, T3nClientConfig, Transport, WasmComponent, WasmNextResult };