@terminal3/t3n-sdk 3.3.0 → 3.4.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.
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
@@ -1,82 +0,0 @@
1
- /**
2
- * Configuration entry point for T3n SDK
3
- *
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.
8
- */
9
- import type { SdkConfig, Environment } from "./types";
10
- /**
11
- * Default node URLs per environment. Override at runtime via `setNodeUrl()`
12
- * or by passing `baseUrl` to `T3nClient`.
13
- */
14
- export declare const NODE_URLS: Record<Environment, string>;
15
- /** DKG attestation bundle from the cluster. */
16
- export interface DkgAttestation {
17
- /** Sorted base58 peer IDs that participated in DKG. */
18
- peer_ids: string[];
19
- /** Per-node TDX quotes keyed by base58 peer ID (base64-encoded). */
20
- quotes: Record<string, string>;
21
- /**
22
- * Base64-encoded raw attestation message: `encaps_key || sorted_peer_ids`.
23
- * Each quote's `report_data` is `keccak512(attestation_msg)`.
24
- */
25
- attestation_msg: string;
26
- }
27
- /**
28
- * Set the active environment. Clears any previous URL override and the key
29
- * cache so the next fetch uses the new environment's default URL.
30
- */
31
- export declare function setEnvironment(env: Environment): void;
32
- export declare function getEnvironment(): Environment;
33
- export declare function getEnvironmentName(): string;
34
- /**
35
- * Override the node URL for the current process. Pass `null` to clear and
36
- * fall back to the environment default.
37
- *
38
- * Always clears the per-URL key cache, including the `setNodeUrl(sameUrl)`
39
- * case — that's the explicit "force a refresh after a node-side ML-KEM
40
- * rotation" entry point. Keeping a no-op-call optimization here would
41
- * silently defeat that contract; an extra fetch on a no-op call is cheap.
42
- */
43
- export declare function setNodeUrl(url: string | null): void;
44
- /** Resolve the active node URL: explicit `baseUrl` > override > env default. */
45
- export declare function getNodeUrl(baseUrl?: string): string;
46
- /**
47
- * Fetch the ML-KEM root public key from `${nodeUrl}/status`. Cached
48
- * per URL because the key is stable for the cluster's lifetime (a
49
- * new DKG means a full redeploy; callers clear the cache via
50
- * `clearKeyCache()` or `setNodeUrl()` in that case).
51
- *
52
- * Returns only the base64-encoded key. For the DKG attestation
53
- * bundle (which changes over time as peer quotes replicate via
54
- * Raft), call `fetchDkgAttestation()` \u2014 that path is
55
- * intentionally uncached.
56
- */
57
- export declare function fetchMlKemPublicKey(baseUrl?: string): Promise<string>;
58
- /**
59
- * Fetch the DKG attestation bundle from `${nodeUrl}/status`. Never
60
- * cached \u2014 peer quotes are written to consensus KV asynchronously
61
- * during cluster bootstrap, so early reads may see a subset of the
62
- * expected quotes. Caching would pin an incomplete bundle and cause
63
- * spurious `valid_count < expected_count` failures in
64
- * `verifyDkgAttestation()` for the whole process lifetime.
65
- *
66
- * Returns `undefined` when the node has not yet published an
67
- * attestation (e.g. still bootstrapping, or running with a mock
68
- * signer where attestation is skipped by design).
69
- */
70
- export declare function fetchDkgAttestation(baseUrl?: string): Promise<DkgAttestation | undefined>;
71
- /** Clear the cached ML-KEM public keys. Useful in tests. */
72
- export declare function clearKeyCache(): void;
73
- /**
74
- * Return the resolved SDK configuration for the current environment.
75
- * Note: this no longer includes the ML-KEM key — fetch it via
76
- * `fetchMlKemPublicKey()`.
77
- */
78
- export declare function loadConfig(baseUrl?: string): SdkConfig;
79
- export { verifyTdxQuote, verifyDkgAttestation } from "../wasm/quote-verifier-loader";
80
- export type { QuoteVerifyResult, DkgVerifyResult, PeerQuoteResult, } from "../wasm/quote-verifier-loader";
81
- export type { SdkConfig, Environment, ConfigValidationResult } from "./types";
82
- export { validateConfig } from "./loader";
@@ -1,8 +0,0 @@
1
- /**
2
- * Configuration validation for T3n SDK
3
- */
4
- import type { ConfigValidationResult } from "./types";
5
- /**
6
- * Validate SDK configuration
7
- */
8
- export declare function validateConfig(config: unknown): ConfigValidationResult;
@@ -1,25 +0,0 @@
1
- /**
2
- * Configuration types for T3n SDK
3
- */
4
- /**
5
- * Environment type for SDK configuration
6
- */
7
- export type Environment = "local" | "staging" | "testnet" | "production" | "test";
8
- /**
9
- * SDK configuration structure
10
- */
11
- export interface SdkConfig {
12
- /** Environment identifier */
13
- environment: Environment;
14
- /** Resolved node URL (used both for RPC and for fetching the ML-KEM key) */
15
- nodeUrl: string;
16
- /** Configuration version */
17
- version: string;
18
- }
19
- /**
20
- * Configuration validation result
21
- */
22
- export interface ConfigValidationResult {
23
- valid: boolean;
24
- errors: string[];
25
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * T3n TypeScript SDK
3
- *
4
- * A minimal TypeScript SDK that mirrors the server's RPC handler approach,
5
- * keeping all state machine logic hidden in WASM and providing a clean,
6
- * agnostic wrapper that doesn't expose authentication methods or internal states.
7
- */
8
- export { T3nClient } from "./client";
9
- export type { T3nClientConfig } from "./client";
10
- export type { HandshakeResult } from "./types";
11
- export { parseContractResponse, ContractResponseError, } from "./client";
12
- export type { ContractResponseSchema, } from "./client";
13
- export type { Logger } from "./utils/logger";
14
- export { LogLevel, createLogger, getLogger, setGlobalLogLevel, getGlobalLogLevel, } from "./utils/logger";
15
- export type { Transport, JsonRpcRequest, JsonRpcResponse } from "./client";
16
- export { HttpTransport, MockTransport } from "./client";
17
- export type { SessionId, Did, OidcCredentials, AuthInput, EthAuthInput, OidcAuthInput, GuestToHostHandler, GuestToHostHandlers, } from "./types";
18
- export { SessionStatus, AuthMethod, createEthAuthInput, createOidcAuthInput, } from "./types";
19
- export type { KycStatus, KycStatusKind, KycPollOptions, KycPollCadence, } from "./types/kyc";
20
- export { DEFAULT_KYC_POLL_CADENCE, TERMINAL_KYC_STATUSES, KycStatusTimeoutError, } from "./types/kyc";
21
- export type { OtpChannel, OtpRequestInput, OtpRequestResult, OtpVerifyInput, OtpVerifyResult, OtpMergeSuggestion, UserInputProfile, SubmitUserInputArgs, SubmitUserInputResult, TenantAdmitProjection, TenantAdmitStatus, UserUpsertErrorKind, } from "./types/user";
22
- export { UserUpsertError } from "./types/user";
23
- export type { UsagePage, UsageEntry, GetUsageOptions, BalanceRow, TokenTxKind, Direction, ChargeReason, } from "./types/token";
24
- export { OrgDataClient, SessionOrgDataClient, createOrgDataClientFromSession, } from "./client/org-data";
25
- export type { OrgDataClientOptions, CreatePolicyInput, UpdateMetaInput, SetWritersInput, SetGrantsInput, DeleteGrantsInput, WriteDataInput, DeleteDataInput, DeleteScopeInput, PolicyGetInput, WritersGetInput, GrantsGetInput, DataListInput, DataGetInput, ExecuteOrgDataActionOptions, } from "./client/org-data";
26
- export type { OrgDataActionWire, OrgPolicyMeta, OrgWriters, OrgContractGrants, UserGrant, EmployeeRecord, EmploymentStatus, ResidencyCategory, AgeBand, ExpenseClaim, MutationResponse, DataListResponse, DataGetResponse, } from "./types/org-data";
27
- export { DelegationCustodialClient } from "./client/delegation";
28
- export type { DelegationCustodialClientOpts, SignCustodialResult, } from "./client/delegation";
29
- export { DELEGATION_CREDENTIAL_DOMAIN, DELEGATION_INVOCATION_DOMAIN, VC_ID_LEN, NONCE_LEN, REQUEST_HASH_LEN, AGENT_PUBKEY_LEN, ETH_SIG_LEN, MAX_FUNCTIONS_PER_CREDENTIAL, PAYROLL_FUNCTIONS_V1, DEFAULT_INDIVIDUAL_THRESHOLD_CENTS, buildDelegationCredential, validateCredentialBody, canonicaliseCredential, canonicaliseRequest, requestHash, buildInvocationPreimage, eip191Digest, signCredential, ethRecoverEip191, signAgentInvocation, buildPayrollInvocation, buildPayrollDirectInvocation, revokeDelegation, compactDidFromBytes, b64uEncodeBytes, b64uDecodeStrict, _b64uEncode, } from "./client/delegation";
30
- export type { DelegationCredential, DelegationEnvelope, PayrollRunRequest, PayrollInvocationDelegated, PayrollInvocationDirect, PayrollInvocation, SignDelegationResponse, BuildDelegationCredentialOpts, BuildPayrollInvocationOpts, BuildPayrollDirectInvocationOpts, RevokeDelegationOpts, RevokeDelegationResult, } from "./client/delegation";
31
- export { metamask_sign, metamask_get_address, eth_get_address, createDefaultHandlers, createMlKemPublicKeyHandler, createRandomHandler, } from "./client/handlers";
32
- export type { WasmComponent, ClientHandshake, ClientAuth, SessionCrypto, WasmNextResult, } from "./wasm";
33
- export { loadWasmComponent } from "./wasm";
34
- export { generateRandomString, generateUUID, getScriptVersion, stringToBytes, bytesToString, redactSecrets, redactSecretsFromJson, } from "./utils";
35
- export { T3nError, SessionStateError, AuthenticationError, HandshakeError, RpcError, SessionExpiredError, WasmError, decodeWasmErrorMessage, extractWasmError, } from "./utils/errors";
36
- export { assertShape, isObject } from "./utils/shape";
37
- export { isMutationResponse, isOrgPolicyMeta, isOrgWriters, isOrgContractGrants, isDataListResponse, isDataGetResponse, } from "./types/org-data";
38
- export type { SdkConfig, Environment, ConfigValidationResult, DkgAttestation, QuoteVerifyResult, DkgVerifyResult, PeerQuoteResult, } from "./config";
39
- export { loadConfig, fetchMlKemPublicKey, fetchDkgAttestation, verifyTdxQuote, verifyDkgAttestation, clearKeyCache, getEnvironmentName, getEnvironment, setEnvironment, setNodeUrl, getNodeUrl, NODE_URLS, validateConfig, } from "./config";
@@ -1,66 +0,0 @@
1
- /**
2
- * Authentication-related types for T3n SDK
3
- */
4
- /**
5
- * Authentication method enum
6
- */
7
- export declare enum AuthMethod {
8
- Ethereum = "eth",
9
- OIDC = "oidc"
10
- }
11
- /**
12
- * Ethereum signer interface - only what user provides to start auth
13
- */
14
- export interface EthereumSigner {
15
- getPublicKey(): string;
16
- signMessage(message: Uint8Array): Promise<Uint8Array>;
17
- }
18
- /**
19
- * OIDC credentials interface.
20
- *
21
- * The TEE generates a session-binding nonce that must be included in
22
- * the Google authorization URL (`&nonce=…`). The `getIdToken` callback
23
- * receives this nonce and must return the `id_token` JWT obtained
24
- * from the OIDC provider with the nonce baked into its claims.
25
- */
26
- export interface OidcCredentials {
27
- provider: string;
28
- getIdToken: (nonce: string) => Promise<string>;
29
- }
30
- /**
31
- * Base authentication input with method discriminator
32
- */
33
- interface BaseAuthInput {
34
- method: AuthMethod;
35
- }
36
- /**
37
- * Ethereum authentication options
38
- */
39
- export interface EthAuthOptions {
40
- ethDerived?: boolean;
41
- }
42
- /**
43
- * Ethereum authentication input
44
- */
45
- export interface EthAuthInput extends BaseAuthInput {
46
- method: AuthMethod.Ethereum;
47
- address: string;
48
- ethDerived?: boolean;
49
- }
50
- /**
51
- * OIDC authentication input
52
- */
53
- export interface OidcAuthInput extends BaseAuthInput {
54
- method: AuthMethod.OIDC;
55
- credentials: OidcCredentials;
56
- }
57
- /**
58
- * Union type for all supported authentication inputs
59
- */
60
- export type AuthInput = EthAuthInput | OidcAuthInput;
61
- /**
62
- * Helper functions to create auth inputs
63
- */
64
- export declare function createEthAuthInput(address: string, options?: EthAuthOptions): EthAuthInput;
65
- export declare function createOidcAuthInput(credentials: OidcCredentials): OidcAuthInput;
66
- export {};
@@ -1,45 +0,0 @@
1
- /**
2
- * Public types export for T3n SDK
3
- */
4
- /**
5
- * Guest-to-Host request handler function type
6
- *
7
- * Handles requests from WASM guest that need host (SDK) to perform side
8
- * effects. The exact shape of `requestData` depends on the specific
9
- * handler — see `GuestToHostHandlers` below for the per-handler shapes.
10
- * The wrapper layer in `T3nClient.handleGuestToHost` parses the JSON
11
- * envelope and calls the matching handler with the parsed data, so
12
- * each handler's implementation should narrow `requestData` to its
13
- * own expected shape.
14
- */
15
- export type GuestToHostHandler = (requestData: Record<string, unknown>) => Promise<Uint8Array>;
16
- /**
17
- * Map of guest-to-host request handlers
18
- * Keys match the guest_to_host tag values from the WASM
19
- */
20
- export interface GuestToHostHandlers {
21
- /**
22
- * Handle Ethereum signature requests
23
- * requestData: { guest_to_host: "EthSign", challenge: string (base64) }
24
- * Returns: JSON bytes of { host_to_guest: "EthSign", challenge: string, signature: string }
25
- */
26
- EthSign?: GuestToHostHandler;
27
- /**
28
- * Handle MlKem public key requests
29
- * requestData: { guest_to_host: "MlKemPublicKey" }
30
- * Returns: JSON bytes of { host_to_guest: "MlKemPublicKey", key: string }
31
- */
32
- MlKemPublicKey?: GuestToHostHandler;
33
- /**
34
- * Handle random bytes requests
35
- * requestData: { guest_to_host: "Random", len?: number }
36
- * Returns: JSON bytes of { host_to_guest: "Random", bytes: string (base64) }
37
- */
38
- Random?: GuestToHostHandler;
39
- [key: string]: GuestToHostHandler | undefined;
40
- }
41
- export * from "./session";
42
- export * from "./auth";
43
- export * from "./user";
44
- export * from "./org-data";
45
- export * from "./token";
@@ -1,135 +0,0 @@
1
- /**
2
- * KYC types for the `tee:user/contracts::kyc-status` short-poll
3
- * function added in MAT-1202.
4
- *
5
- * The shape mirrors `tee_contracts/user/src/kyc_status.rs::KycStatusResponse`.
6
- * Keep the two in sync — the bytes go straight from the contract
7
- * through the JSON-RPC envelope into [[T3nClient.kycStatus]].
8
- */
9
- import { T3nError } from "../utils/errors";
10
- /**
11
- * Terminal status for a Level 2 KYC verification, plus `pending`.
12
- *
13
- * - `pending` — provider has not delivered a verdict yet, or the
14
- * webhook arrived but the post-action VC issuance hasn't completed.
15
- * - `verified` — provider approved AND a VC has been issued. `vcIds`
16
- * carries the issued credential ids.
17
- * - `rejected` — provider declined / required resubmission /
18
- * expired / the user abandoned the flow. `error` may carry a
19
- * provider-supplied reason.
20
- * - `orphan` — a Veriff webhook arrived with a `vendorData` that
21
- * couldn't be matched to any user (T3-TS-024 §3.4). Should not
22
- * happen in the MetaMask flow but the contract surfaces it for
23
- * completeness.
24
- */
25
- export type KycStatusKind = "pending" | "verified" | "rejected" | "orphan";
26
- /**
27
- * Snapshot returned by `tee:user/contracts::kyc-status`.
28
- *
29
- * Field names use camelCase on the SDK boundary even though the
30
- * wire is snake_case — the wrapper rewrites keys at the client edge
31
- * so callers don't see the JSON shape leaking through.
32
- */
33
- export interface KycStatus {
34
- /** Terminal status if reached, otherwise `pending`. */
35
- status: KycStatusKind;
36
- /**
37
- * Provider being polled. Echoed back so callers that didn't
38
- * supply one see the contract's default (`"veriff"` in phase one).
39
- */
40
- provider: string;
41
- /**
42
- * Unix-millis of the latest contract-visible event:
43
- * VC issuance time, attestation arrival time, session-row
44
- * `started_at_ms`, or orphan-record arrival time. Best-effort —
45
- * `undefined` when no source carries a usable timestamp.
46
- */
47
- updatedAt?: number;
48
- /**
49
- * VC ids appended for this provider, in append order. Empty for
50
- * `pending` / `rejected` / `orphan`.
51
- */
52
- vcIds: string[];
53
- /**
54
- * Provider-supplied reason for `rejected`, when available.
55
- */
56
- error?: string;
57
- }
58
- /**
59
- * Polling cadence for [[T3nClient.kycStatusPoll]]. Defaults match
60
- * T3-TS-026 §8.4: poll fast for the first 30 seconds, then back
61
- * off, and bail after 5 minutes.
62
- */
63
- export interface KycPollCadence {
64
- /** Poll interval in ms while `elapsed < switchAtMs`. Default: 2000. */
65
- fastMs: number;
66
- /** Poll interval in ms once `elapsed >= switchAtMs`. Default: 5000. */
67
- slowMs: number;
68
- /** Elapsed-ms threshold to switch from fast to slow cadence. Default: 30_000. */
69
- switchAtMs: number;
70
- /**
71
- * Maximum total time to spend polling before rejecting with
72
- * [[KycStatusTimeoutError]]. Default: 300_000 (5 minutes).
73
- */
74
- timeoutMs: number;
75
- }
76
- /**
77
- * Optional knobs for [[T3nClient.kycStatusPoll]]. Most callers won't
78
- * touch any of these — the §8.4 defaults are baked in.
79
- */
80
- export interface KycPollOptions {
81
- /**
82
- * Cancellation signal. When aborted, the helper rejects with
83
- * `signal.reason` (or a generic `AbortError` if the consumer
84
- * didn't supply a reason). The currently-in-flight `kycStatus()`
85
- * call also receives the signal so it can short-circuit.
86
- */
87
- signal?: AbortSignal;
88
- /**
89
- * Called with every snapshot the helper receives, including
90
- * non-terminal `pending` ones. Useful for surfacing intermediate
91
- * UI states (e.g. "still waiting on provider…"). Errors thrown
92
- * from this callback are caught and ignored — they must not
93
- * sink the poll loop.
94
- */
95
- onUpdate?: (status: KycStatus) => void;
96
- /**
97
- * Override one or more cadence fields. Anything not specified
98
- * uses the §8.4 defaults from [[DEFAULT_KYC_POLL_CADENCE]].
99
- */
100
- cadence?: Partial<KycPollCadence>;
101
- /**
102
- * Provider id to poll. Defaults to the contract default
103
- * (`"veriff"` in phase one). Mirrored on the wire as
104
- * `input.provider_id`.
105
- */
106
- providerId?: string;
107
- }
108
- /**
109
- * Default cadence used by [[T3nClient.kycStatusPoll]] when the caller
110
- * doesn't override `cadence.*`. Matches T3-TS-026 §8.4 verbatim.
111
- */
112
- export declare const DEFAULT_KYC_POLL_CADENCE: KycPollCadence;
113
- /**
114
- * Subset of [[KycStatusKind]] that ends a poll. `pending` is the
115
- * only non-terminal value.
116
- */
117
- export declare const TERMINAL_KYC_STATUSES: ReadonlySet<KycStatusKind>;
118
- /**
119
- * Thrown by [[T3nClient.kycStatusPoll]] when the cadence's
120
- * `timeoutMs` elapses without a terminal status arriving. The
121
- * `lastStatus` field is the most recent (necessarily `pending`)
122
- * snapshot the helper saw, useful for surfacing "we tried for N
123
- * minutes but Veriff is still working" UX.
124
- */
125
- export declare class KycStatusTimeoutError extends T3nError {
126
- /** The §8.4 timeout the helper exhausted. */
127
- readonly timeoutMs: number;
128
- /** The last `pending` snapshot before timeout, if any. */
129
- readonly lastStatus?: KycStatus | undefined;
130
- constructor(
131
- /** The §8.4 timeout the helper exhausted. */
132
- timeoutMs: number,
133
- /** The last `pending` snapshot before timeout, if any. */
134
- lastStatus?: KycStatus | undefined);
135
- }
@@ -1,180 +0,0 @@
1
- /**
2
- * Org-data wire types mirroring the Rust contract shapes in
3
- * `tee-contract-org-data` and `org-data-types`.
4
- *
5
- * Plain TypeScript interfaces (no zod) — the SDK does not use a
6
- * validation library for domain types; see the existing `types/` files.
7
- *
8
- * Each response type below is paired with a shallow runtime predicate
9
- * (`isMutationResponse`, `isOrgPolicyMeta`, etc.) so the org-data client
10
- * can `assertShape` the decoded payload before returning to callers.
11
- * Predicates check the top-level structure only; nested elements
12
- * (e.g. each `UserGrant` inside `OrgContractGrants.grants`) are not
13
- * deeply validated — see `utils/shape.ts` for the rationale.
14
- *
15
- * Reference: `org-data-types/src/lib.rs` and
16
- * `tee-contract-org-data/src/org_data.rs`.
17
- */
18
- /**
19
- * Capability grant stored under `ORG_CONTRACT_GRANTS_MAP`.
20
- *
21
- * Mirrors `org_data_types::UserGrant`.
22
- */
23
- export interface UserGrant {
24
- /** The user this grant applies to (`did:t3n:<40-hex>`). */
25
- user_did: string;
26
- /** WIT function names the user may invoke (e.g. `"run-payroll"`). */
27
- functions: string[];
28
- /** Data scope paths the user may access (e.g. `"payroll/employees"`). */
29
- scopes: string[];
30
- /**
31
- * Optional key-value constraints that must match the request metadata
32
- * exactly for every key present in this map.
33
- */
34
- constraints: Record<string, string>;
35
- /** Unix timestamp (secs) after which this grant is expired. `null` means never expires. */
36
- expires_at_secs: number | null;
37
- }
38
- /**
39
- * Policy record for an organisation's data tier.
40
- *
41
- * Mirrors `org_data_types::OrgPolicyMeta`.
42
- */
43
- export interface OrgPolicyMeta {
44
- /** DIDs (`did:t3n:<40-hex>`) of users authorised to manage policy and read data. */
45
- admins: string[];
46
- /** Maximum number of admins allowed for this org. */
47
- max_admins: number;
48
- /** Unix timestamp (secs) when the policy was first created. */
49
- created_at_secs: number;
50
- /** Unix timestamp (secs) of the most recent policy update. */
51
- updated_at_secs: number;
52
- }
53
- /** Shallow runtime guard for {@link OrgPolicyMeta}. */
54
- export declare function isOrgPolicyMeta(value: unknown): value is OrgPolicyMeta;
55
- export type EmploymentStatus = "Active" | "Terminated";
56
- /** Singapore CPF residency categories. */
57
- export type ResidencyCategory = "Citizen" | "Pr1" | "Pr2" | "PrThreePlus" | "Foreigner";
58
- export type AgeBand = "Under35" | "Age35To45" | "Age45To50" | "Age50To55" | "Age55To60" | "Age60To65" | "Over65";
59
- export interface ExpenseClaim {
60
- claim_id: string;
61
- amount_cents: number;
62
- category: string;
63
- description: string;
64
- per_diem_days?: number;
65
- }
66
- /**
67
- * Employee data row stored under `OrgData[org || "payroll/employees" || entry_id]`.
68
- *
69
- * Mirrors `tee-contract-payroll::types::EmployeeRecord`.
70
- */
71
- export interface EmployeeRecord {
72
- employee_id: string;
73
- employment_status: EmploymentStatus;
74
- is_on_probation: boolean;
75
- hire_date: string;
76
- termination_date?: string;
77
- /** Monthly gross base salary in integer cents SGD. */
78
- base_salary_cents: number;
79
- unpaid_leave_days: number;
80
- working_days_in_period: number;
81
- overtime_hours: number;
82
- hourly_rate_cents: number;
83
- residency: ResidencyCategory;
84
- age_band: AgeBand;
85
- expense_claims: ExpenseClaim[];
86
- /** Opaque reference used by the service layer for disbursement. */
87
- bank_account_ref: string;
88
- bank_account_changed_recently: boolean;
89
- }
90
- /**
91
- * Standard response returned by all policy write and data mutation operations.
92
- *
93
- * Mirrors `tee-contract-org-data::org_data::MutationResponse`.
94
- */
95
- export interface MutationResponse {
96
- /** `"created"`, `"updated"`, or `"deleted"`. */
97
- status: string;
98
- /** Hex-encoded entry ID; present on data write/delete operations. */
99
- entry_id?: string;
100
- /** Whether the target key existed before deletion; present on single-entry deletes. */
101
- deleted?: boolean;
102
- /** Number of entries removed; present on `org-data-delete-scope`. */
103
- deleted_entries?: number;
104
- tx_hash: string | null;
105
- }
106
- /**
107
- * Shallow runtime guard for {@link MutationResponse}.
108
- *
109
- * Only the always-present fields are checked — `status` is mandatory on
110
- * every mutation; `tx_hash` is non-optional but nullable. The optional
111
- * fields (`entry_id`, `deleted`, `deleted_entries`) are not validated
112
- * because their presence depends on which mutation ran.
113
- */
114
- export declare function isMutationResponse(value: unknown): value is MutationResponse;
115
- /**
116
- * Response type alias for org-writers-get.
117
- *
118
- * The wire body is `{ writers: string[] }` where each entry is
119
- * `did:t3n:<40-hex>`.
120
- */
121
- export interface OrgWriters {
122
- writers: string[];
123
- }
124
- /** Shallow runtime guard for {@link OrgWriters}. */
125
- export declare function isOrgWriters(value: unknown): value is OrgWriters;
126
- /**
127
- * Response type alias for org-grants-get.
128
- *
129
- * The wire body echoes the `contract_id` alongside the grant list.
130
- */
131
- export interface OrgContractGrants {
132
- contract_id: string;
133
- grants: UserGrant[];
134
- }
135
- /**
136
- * Shallow runtime guard for {@link OrgContractGrants}.
137
- *
138
- * Validates the immediate envelope (`contract_id: string`, `grants:
139
- * array`) without recursing into each `UserGrant`. The Rust contract
140
- * is the source of truth for grant element shape; widening the predicate
141
- * here would create maintenance churn against benign field additions.
142
- */
143
- export declare function isOrgContractGrants(value: unknown): value is OrgContractGrants;
144
- /** Response for `org-data-list`. */
145
- export interface DataListResponse {
146
- /** Hex-encoded entry IDs for this page. */
147
- entry_ids: string[];
148
- /** Offset to pass for the next page. `null` when this is the last page. */
149
- next_offset: number | null;
150
- /** Total number of entries in the scope (across all pages). */
151
- total: number;
152
- }
153
- /** Shallow runtime guard for {@link DataListResponse}. */
154
- export declare function isDataListResponse(value: unknown): value is DataListResponse;
155
- /** Response for `org-data-get`. */
156
- export interface DataGetResponse {
157
- entry_id: string;
158
- /** Hex-encoded raw payload bytes. */
159
- payload_hex: string;
160
- }
161
- /** Shallow runtime guard for {@link DataGetResponse}. */
162
- export declare function isDataGetResponse(value: unknown): value is DataGetResponse;
163
- /**
164
- * Legacy direct-route org-data envelope shape retained for compatibility.
165
- *
166
- * This mirrors the removed `/api/user-contract/execute` body format from
167
- * the transitional transport. New callers should use `OrgDataClient`,
168
- * which now dispatches through authenticated `/api/rpc` +
169
- * `action.execute` instead.
170
- */
171
- export interface OrgDataActionWire {
172
- nonce: string;
173
- user_did: string;
174
- authenticator_id: string;
175
- contract_id: string;
176
- function: string;
177
- args_hash: string;
178
- expires_at_secs: number;
179
- signature: string;
180
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Session-related types for T3n SDK
3
- */
4
- export interface SessionId {
5
- readonly value: string;
6
- }
7
- export interface Did {
8
- readonly value: string;
9
- toString(): string;
10
- }
11
- export interface HandshakeResult {
12
- readonly sessionId: SessionId;
13
- readonly expiry: number;
14
- readonly authenticated: boolean;
15
- readonly did?: Did;
16
- }
17
- /**
18
- * Simple status enum - mirrors server SessionStatus only
19
- */
20
- export declare enum SessionStatus {
21
- Init = 0,
22
- Encrypted = 1,
23
- Authenticated = 2
24
- }