@terminal3/t3n-sdk 1.2.0 → 1.3.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
@@ -546,12 +546,30 @@ declare class HandshakeError extends T3nError {
546
546
  constructor(message: string);
547
547
  }
548
548
  /**
549
- * Error thrown during RPC communication
549
+ * Error thrown during RPC communication.
550
+ *
551
+ * `message` is the human-readable error (preferring the server's
552
+ * `error.data.detail` when present, with the request id appended in
553
+ * `[<id>]` form so a UI that only surfaces `.message` still gives an
554
+ * operator something to grep). The structured fields below preserve
555
+ * the same info for callers that want to render or log them
556
+ * separately — e.g. a toast that shows `detail` but surfaces
557
+ * `requestId` in a "copy for support" affordance.
550
558
  */
551
559
  declare class RpcError extends T3nError {
552
560
  readonly rpcMethod?: string | undefined;
553
561
  readonly httpStatus?: number | undefined;
554
- constructor(message: string, rpcMethod?: string | undefined, httpStatus?: number | undefined);
562
+ /** Server-attached detail (JSON-RPC `error.data.detail`). User-facing kinds
563
+ * carry the specific reason here; internal kinds omit it. */
564
+ readonly detail?: string | undefined;
565
+ /** Per-request correlation id (JSON-RPC `error.data.request_id`). */
566
+ readonly requestId?: string | undefined;
567
+ constructor(message: string, rpcMethod?: string | undefined, httpStatus?: number | undefined,
568
+ /** Server-attached detail (JSON-RPC `error.data.detail`). User-facing kinds
569
+ * carry the specific reason here; internal kinds omit it. */
570
+ detail?: string | undefined,
571
+ /** Per-request correlation id (JSON-RPC `error.data.request_id`). */
572
+ requestId?: string | undefined);
555
573
  }
556
574
  /**
557
575
  * Error thrown when WASM operations fail
@@ -637,6 +655,142 @@ declare class ContractResponseError extends T3nError {
637
655
  */
638
656
  declare function parseContractResponse<T = unknown>(raw: string, schema?: ContractResponseSchema<T>): T;
639
657
 
658
+ /**
659
+ * KYC types for the `tee:user/contracts::kyc-status` short-poll
660
+ * function added in MAT-1202.
661
+ *
662
+ * The shape mirrors `tee_contracts/user/src/kyc_status.rs::KycStatusResponse`.
663
+ * Keep the two in sync — the bytes go straight from the contract
664
+ * through the JSON-RPC envelope into [[T3nClient.kycStatus]].
665
+ */
666
+
667
+ /**
668
+ * Terminal status for a Level 2 KYC verification, plus `pending`.
669
+ *
670
+ * - `pending` — provider has not delivered a verdict yet, or the
671
+ * webhook arrived but the post-action VC issuance hasn't completed.
672
+ * - `verified` — provider approved AND a VC has been issued. `vcIds`
673
+ * carries the issued credential ids.
674
+ * - `rejected` — provider declined / required resubmission /
675
+ * expired / the user abandoned the flow. `error` may carry a
676
+ * provider-supplied reason.
677
+ * - `orphan` — a Veriff webhook arrived with a `vendorData` that
678
+ * couldn't be matched to any user (T3-TS-024 §3.4). Should not
679
+ * happen in the MetaMask flow but the contract surfaces it for
680
+ * completeness.
681
+ */
682
+ type KycStatusKind = "pending" | "verified" | "rejected" | "orphan";
683
+ /**
684
+ * Snapshot returned by `tee:user/contracts::kyc-status`.
685
+ *
686
+ * Field names use camelCase on the SDK boundary even though the
687
+ * wire is snake_case — the wrapper rewrites keys at the client edge
688
+ * so callers don't see the JSON shape leaking through.
689
+ */
690
+ interface KycStatus {
691
+ /** Terminal status if reached, otherwise `pending`. */
692
+ status: KycStatusKind;
693
+ /**
694
+ * Provider being polled. Echoed back so callers that didn't
695
+ * supply one see the contract's default (`"veriff"` in phase one).
696
+ */
697
+ provider: string;
698
+ /**
699
+ * Unix-millis of the latest contract-visible event:
700
+ * VC issuance time, attestation arrival time, session-row
701
+ * `started_at_ms`, or orphan-record arrival time. Best-effort —
702
+ * `undefined` when no source carries a usable timestamp.
703
+ */
704
+ updatedAt?: number;
705
+ /**
706
+ * VC ids appended for this provider, in append order. Empty for
707
+ * `pending` / `rejected` / `orphan`.
708
+ */
709
+ vcIds: string[];
710
+ /**
711
+ * Provider-supplied reason for `rejected`, when available.
712
+ */
713
+ error?: string;
714
+ }
715
+ /**
716
+ * Polling cadence for [[T3nClient.kycStatusPoll]]. Defaults match
717
+ * T3-TS-026 §8.4: poll fast for the first 30 seconds, then back
718
+ * off, and bail after 5 minutes.
719
+ */
720
+ interface KycPollCadence {
721
+ /** Poll interval in ms while `elapsed < switchAtMs`. Default: 2000. */
722
+ fastMs: number;
723
+ /** Poll interval in ms once `elapsed >= switchAtMs`. Default: 5000. */
724
+ slowMs: number;
725
+ /** Elapsed-ms threshold to switch from fast to slow cadence. Default: 30_000. */
726
+ switchAtMs: number;
727
+ /**
728
+ * Maximum total time to spend polling before rejecting with
729
+ * [[KycStatusTimeoutError]]. Default: 300_000 (5 minutes).
730
+ */
731
+ timeoutMs: number;
732
+ }
733
+ /**
734
+ * Optional knobs for [[T3nClient.kycStatusPoll]]. Most callers won't
735
+ * touch any of these — the §8.4 defaults are baked in.
736
+ */
737
+ interface KycPollOptions {
738
+ /**
739
+ * Cancellation signal. When aborted, the helper rejects with
740
+ * `signal.reason` (or a generic `AbortError` if the consumer
741
+ * didn't supply a reason). The currently-in-flight `kycStatus()`
742
+ * call also receives the signal so it can short-circuit.
743
+ */
744
+ signal?: AbortSignal;
745
+ /**
746
+ * Called with every snapshot the helper receives, including
747
+ * non-terminal `pending` ones. Useful for surfacing intermediate
748
+ * UI states (e.g. "still waiting on provider…"). Errors thrown
749
+ * from this callback are caught and ignored — they must not
750
+ * sink the poll loop.
751
+ */
752
+ onUpdate?: (status: KycStatus) => void;
753
+ /**
754
+ * Override one or more cadence fields. Anything not specified
755
+ * uses the §8.4 defaults from [[DEFAULT_KYC_POLL_CADENCE]].
756
+ */
757
+ cadence?: Partial<KycPollCadence>;
758
+ /**
759
+ * Provider id to poll. Defaults to the contract default
760
+ * (`"veriff"` in phase one). Mirrored on the wire as
761
+ * `input.provider_id`.
762
+ */
763
+ providerId?: string;
764
+ }
765
+ /**
766
+ * Default cadence used by [[T3nClient.kycStatusPoll]] when the caller
767
+ * doesn't override `cadence.*`. Matches T3-TS-026 §8.4 verbatim.
768
+ */
769
+ declare const DEFAULT_KYC_POLL_CADENCE: KycPollCadence;
770
+ /**
771
+ * Subset of [[KycStatusKind]] that ends a poll. `pending` is the
772
+ * only non-terminal value.
773
+ */
774
+ declare const TERMINAL_KYC_STATUSES: ReadonlySet<KycStatusKind>;
775
+ /**
776
+ * Thrown by [[T3nClient.kycStatusPoll]] when the cadence's
777
+ * `timeoutMs` elapses without a terminal status arriving. The
778
+ * `lastStatus` field is the most recent (necessarily `pending`)
779
+ * snapshot the helper saw, useful for surfacing "we tried for N
780
+ * minutes but Veriff is still working" UX.
781
+ */
782
+ declare class KycStatusTimeoutError extends T3nError {
783
+ /** The §8.4 timeout the helper exhausted. */
784
+ readonly timeoutMs: number;
785
+ /** The last `pending` snapshot before timeout, if any. */
786
+ readonly lastStatus?: KycStatus | undefined;
787
+ constructor(
788
+ /** The §8.4 timeout the helper exhausted. */
789
+ timeoutMs: number,
790
+ /** The last `pending` snapshot before timeout, if any. */
791
+ lastStatus?: KycStatus | undefined);
792
+ }
793
+
640
794
  /**
641
795
  * T3n Client - Main SDK class
642
796
  *
@@ -819,6 +973,57 @@ declare class T3nClient {
819
973
  * the response cannot be decoded.
820
974
  */
821
975
  removeUserWithWalletAbandonment(): Promise<unknown>;
976
+ /**
977
+ * One-shot poll of `tee:user/contracts::kyc-status`.
978
+ *
979
+ * Returns the current snapshot of the authenticated user's Level 2
980
+ * KYC state — see [[KycStatus]] for the four possible terminal /
981
+ * non-terminal values. The caller usually wants
982
+ * [[kycStatusPoll]] (which loops with §8.4 cadence until a
983
+ * terminal status arrives), but the bare snapshot is useful for
984
+ * pages that need to render the user's standing without waiting
985
+ * (e.g. account-status views, "did the user finish KYC last time
986
+ * they were here?" gates).
987
+ *
988
+ * Phase one default — `providerId` defaults to `"veriff"` (the
989
+ * contract applies the same default when the field is absent),
990
+ * so the most common call site is `await t3n.kycStatus()`.
991
+ *
992
+ * @param providerId optional provider id, mirrored on the wire as
993
+ * `input.provider_id`. Omit for phase-one MetaMask flows.
994
+ * @throws if unauthenticated, if the node rejects the action
995
+ * (e.g. `precondition_failed:` when no `create-kyc-provider-session`
996
+ * row exists yet), or if the response shape is unexpected.
997
+ */
998
+ kycStatus(providerId?: string): Promise<KycStatus>;
999
+ /**
1000
+ * Poll `kyc-status` until a terminal status arrives or the
1001
+ * configured timeout elapses.
1002
+ *
1003
+ * Cadence defaults to T3-TS-026 §8.4: 2-second interval for the
1004
+ * first 30 seconds, then 5 seconds, with a 5-minute hard cap.
1005
+ * Override via `opts.cadence` if you need different numbers
1006
+ * (e.g. tests that don't want to wait the full 30 seconds before
1007
+ * the slow window kicks in). [[KycStatusTimeoutError]] is thrown
1008
+ * if the timeout elapses without reaching a terminal state.
1009
+ *
1010
+ * `opts.signal` cancels the loop synchronously — the helper
1011
+ * stops sleeping and rejects with the abort reason; an
1012
+ * already-in-flight `kycStatus()` request is allowed to settle
1013
+ * but its result is discarded.
1014
+ *
1015
+ * `opts.onUpdate` fires once per snapshot, including
1016
+ * intermediate `pending` ones. Errors thrown from the callback
1017
+ * are swallowed so a misbehaving UI handler can't strand the
1018
+ * poll loop.
1019
+ *
1020
+ * @throws [[KycStatusTimeoutError]] when the cadence's
1021
+ * `timeoutMs` elapses without a terminal status.
1022
+ * @throws the abort reason when `opts.signal` is aborted.
1023
+ * @throws the underlying RPC error when the contract or
1024
+ * transport raises (e.g. session expiry mid-poll).
1025
+ */
1026
+ kycStatusPoll(opts?: KycPollOptions): Promise<KycStatus>;
822
1027
  /**
823
1028
  * The server-minted session ID once handshake has completed, or
824
1029
  * `null` beforehand (pentest M-1 / MAT-983).
@@ -1184,5 +1389,5 @@ declare function clearKeyCache(): void;
1184
1389
  */
1185
1390
  declare function loadConfig(baseUrl?: string): SdkConfig;
1186
1391
 
1187
- export { AuthMethod, AuthenticationError, ContractResponseError, 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, parseContractResponse, redactSecrets, redactSecretsFromJson, setEnvironment, setGlobalLogLevel, setNodeUrl, stringToBytes, validateConfig, verifyDkgAttestation, verifyTdxQuote };
1188
- export type { AuthInput, ClientAuth, ClientHandshake, ConfigValidationResult, ContractResponseSchema, Did, DkgAttestation, DkgVerifyResult, Environment, EthAuthInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, Logger, OidcAuthInput, OidcCredentials, PeerQuoteResult, QuoteVerifyResult, SdkConfig, SessionCrypto, SessionId, T3nClientConfig, Transport, WasmComponent, WasmNextResult };
1392
+ export { AuthMethod, AuthenticationError, ContractResponseError, DEFAULT_KYC_POLL_CADENCE, HandshakeError, HttpTransport, KycStatusTimeoutError, LogLevel, MockTransport, NODE_URLS, RpcError, SessionStateError, SessionStatus, T3nClient, T3nError, TERMINAL_KYC_STATUSES, 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, parseContractResponse, redactSecrets, redactSecretsFromJson, setEnvironment, setGlobalLogLevel, setNodeUrl, stringToBytes, validateConfig, verifyDkgAttestation, verifyTdxQuote };
1393
+ export type { AuthInput, ClientAuth, ClientHandshake, ConfigValidationResult, ContractResponseSchema, Did, DkgAttestation, DkgVerifyResult, Environment, EthAuthInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, Logger, OidcAuthInput, OidcCredentials, PeerQuoteResult, QuoteVerifyResult, SdkConfig, SessionCrypto, SessionId, T3nClientConfig, Transport, WasmComponent, WasmNextResult };