@terminal3/t3n-sdk 4.20.0 → 4.22.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/cli/index.js +1 -1
- package/dist/index.d.ts +132 -11
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1997,12 +1997,15 @@ declare class T3nClient {
|
|
|
1997
1997
|
* standard authenticated `action.execute` path. The node injects the
|
|
1998
1998
|
* caller's DID into the contract call context, and the contract refuses
|
|
1999
1999
|
* unless the caller is listed as an admin of `organisationDid`. A brand
|
|
2000
|
-
* new secp256k1 wallet is minted in-TEE for the agent
|
|
2001
|
-
* DID
|
|
2002
|
-
*
|
|
2003
|
-
*
|
|
2004
|
-
*
|
|
2005
|
-
*
|
|
2000
|
+
* new secp256k1 wallet is minted in-TEE for the agent (its eth-derived
|
|
2001
|
+
* DID is returned), but the raw private key never leaves the TEE.
|
|
2002
|
+
* Instead the contract mints an opaque bearer API key —
|
|
2003
|
+
* `t3n_key_<key_id_hex>.<secret_hex>` — and returns it plus its `keyId`
|
|
2004
|
+
* (the 16-hex lookup id). The `apiKey` is the credential relayed verbatim
|
|
2005
|
+
* in the `X-T3N-Api-Key` header of a stateless `POST /api/invoke` call; only
|
|
2006
|
+
* its hash is stored on-ledger, so it is generated and returned exactly
|
|
2007
|
+
* once here and is never persisted or recoverable afterwards — the caller
|
|
2008
|
+
* must capture it immediately.
|
|
2006
2009
|
*
|
|
2007
2010
|
* Atomic provisioning + card hosting: the SAME transaction mints the
|
|
2008
2011
|
* agent, writes the agent-registry record (owner binding + the org's
|
|
@@ -2027,8 +2030,8 @@ declare class T3nClient {
|
|
|
2027
2030
|
* (`did:t3n:<40-hex>`); the caller must be one of its admins
|
|
2028
2031
|
* @param name - human-readable agent name (1..=128 bytes)
|
|
2029
2032
|
* @param options - optional atomic registration + card hosting
|
|
2030
|
-
* @returns the new agent's DID and its one-time
|
|
2031
|
-
* `agentUri` / `cardEntryId` (the hosted PRIVATE card's entry id)
|
|
2033
|
+
* @returns the new agent's DID and its one-time opaque `apiKey` + `keyId`,
|
|
2034
|
+
* plus `agentUri` / `cardEntryId` (the hosted PRIVATE card's entry id)
|
|
2032
2035
|
* when the atomic path ran
|
|
2033
2036
|
* @throws if the session is not authenticated, or if the contract
|
|
2034
2037
|
* refuses (e.g. the caller is not an admin of `organisationDid`, the
|
|
@@ -2041,7 +2044,8 @@ declare class T3nClient {
|
|
|
2041
2044
|
defaultCard?: boolean;
|
|
2042
2045
|
}): Promise<{
|
|
2043
2046
|
agentDid: Did;
|
|
2044
|
-
|
|
2047
|
+
apiKey: string;
|
|
2048
|
+
keyId: string;
|
|
2045
2049
|
agentUri?: string;
|
|
2046
2050
|
cardEntryId?: string;
|
|
2047
2051
|
}>;
|
|
@@ -2784,6 +2788,123 @@ declare function createRandomHandler(): GuestToHostHandler;
|
|
|
2784
2788
|
*/
|
|
2785
2789
|
declare function createDefaultHandlers(baseUrl: string, trustAnchor: TrustAnchorOrUnsafe): GuestToHostHandlers;
|
|
2786
2790
|
|
|
2791
|
+
/**
|
|
2792
|
+
* Stateless `api_key` agent auth.
|
|
2793
|
+
*
|
|
2794
|
+
* `invoke` posts once to `POST /api/invoke` — an HTTPS-only
|
|
2795
|
+
* endpoint (see the HTTPS-guard note below) that authenticates an org agent
|
|
2796
|
+
* by an opaque API key (`X-T3N-Api-Key: t3n_key_<...>`) and executes a
|
|
2797
|
+
* `z:` contract as that agent in the SAME request. Unlike
|
|
2798
|
+
* {@link T3nClient.execute}, there is **no** ML-KEM handshake, **no**
|
|
2799
|
+
* `Session-Id`, and **no** session state: the node derives the acting agent
|
|
2800
|
+
* DID from the relayed key per-call (`resolve_stateless_credential`
|
|
2801
|
+
* driving the session contract's `api_key` action), then runs the same
|
|
2802
|
+
* execute pipeline `action.execute` runs after `check_authentication`
|
|
2803
|
+
* (`ActionService::execute_as_did`), and returns the contract's decoded
|
|
2804
|
+
* result as a plain `Json(result)` body — NOT a JSON-RPC envelope.
|
|
2805
|
+
*
|
|
2806
|
+
* Because the response is the bare decoded value (no `{jsonrpc,result,id}`
|
|
2807
|
+
* wrapper to unwrap), decoding reuses {@link parseContractResponse} — the
|
|
2808
|
+
* exact same JSON.parse + optional-schema path {@link T3nClient.executeAndDecode}
|
|
2809
|
+
* uses for the session `execute` RPC — so callers get identical typed /
|
|
2810
|
+
* schema-validated decoding on either path.
|
|
2811
|
+
*
|
|
2812
|
+
* This module intentionally does NOT import {@link T3nClient}, the WASM
|
|
2813
|
+
* component loader, or any handshake/session machinery — `invoke` is
|
|
2814
|
+
* a single fetch, nothing else.
|
|
2815
|
+
*
|
|
2816
|
+
* ### HTTPS guard (CodeRabbit T2)
|
|
2817
|
+
* The API key is a long-lived bearer credential relayed in a plain header,
|
|
2818
|
+
* so `invoke` refuses to send it over an insecure transport: `baseUrl`
|
|
2819
|
+
* must be `https:`, unless the host is a local-dev loopback
|
|
2820
|
+
* (`localhost` / `127.0.0.1` / `[::1]`), in which case plain `http:` is
|
|
2821
|
+
* allowed. The check runs before any network activity — an insecure
|
|
2822
|
+
* `baseUrl` never gets as far as a `fetch` call.
|
|
2823
|
+
*
|
|
2824
|
+
* ### Error hygiene (CodeRabbit T3/T4/T5)
|
|
2825
|
+
* Every error `invoke` throws is a fixed, generic
|
|
2826
|
+
* {@link InvokeError} message — the response body text, the
|
|
2827
|
+
* underlying network error's message, and the api key are never
|
|
2828
|
+
* interpolated into it. This is defense in depth against a server (or a
|
|
2829
|
+
* malicious intermediary) that echoes the key or other secrets back in an
|
|
2830
|
+
* error body: whatever comes back over the wire on a non-2xx response is
|
|
2831
|
+
* discarded, not surfaced. The timeout timer also stays armed until the
|
|
2832
|
+
* response body has been fully read (or has itself timed out) — see
|
|
2833
|
+
* {@link invoke}'s implementation — so a connection that delivers
|
|
2834
|
+
* headers and then stalls on the body still respects `timeoutMs`.
|
|
2835
|
+
*/
|
|
2836
|
+
|
|
2837
|
+
/**
|
|
2838
|
+
* Wire body for `POST /api/invoke` — mirrors the server's
|
|
2839
|
+
* server-side `ExecuteActionRequest`, the same shape
|
|
2840
|
+
* `T3nClient`'s `execute*` wrappers build for the session `action.execute`
|
|
2841
|
+
* RPC. Field names are load-bearing: the server deserialises strictly into
|
|
2842
|
+
* `script_name` / `script_version` / `function_name` (see
|
|
2843
|
+
* `T3nClient.executeSystemContract`'s doc comment) — `contract` / `version`
|
|
2844
|
+
* / `function` produce a 400.
|
|
2845
|
+
*/
|
|
2846
|
+
interface InvokeRequest {
|
|
2847
|
+
script_name: string;
|
|
2848
|
+
script_version: string;
|
|
2849
|
+
function_name: string;
|
|
2850
|
+
/** Delegated-call target member; omitted for a self (non-delegated) call. */
|
|
2851
|
+
pii_did?: string;
|
|
2852
|
+
input?: unknown;
|
|
2853
|
+
}
|
|
2854
|
+
/** Options for {@link invoke}. */
|
|
2855
|
+
interface InvokeOptions {
|
|
2856
|
+
/**
|
|
2857
|
+
* RPC base URL of the T3n node, e.g. `https://node.example.com`. Must be
|
|
2858
|
+
* `https:` unless the host is a local-dev loopback (`localhost` /
|
|
2859
|
+
* `127.0.0.1` / `[::1]`) — see the module doc comment's HTTPS-guard note.
|
|
2860
|
+
*/
|
|
2861
|
+
baseUrl: string;
|
|
2862
|
+
/**
|
|
2863
|
+
* The agent's opaque API key (`t3n_key_<...>`), relayed verbatim in the
|
|
2864
|
+
* `X-T3N-Api-Key` header. Never logged and never interpolated into any
|
|
2865
|
+
* error this module throws — see the module doc comment and
|
|
2866
|
+
* {@link InvokeError}.
|
|
2867
|
+
*/
|
|
2868
|
+
apiKey: string;
|
|
2869
|
+
/** The wire request to execute, built to the {@link InvokeRequest} shape. */
|
|
2870
|
+
request: InvokeRequest;
|
|
2871
|
+
/** Fetch timeout in ms. Defaults to 30s, matching {@link HttpTransport}. */
|
|
2872
|
+
timeoutMs?: number;
|
|
2873
|
+
}
|
|
2874
|
+
/**
|
|
2875
|
+
* Thrown when `POST /api/invoke` fails at the transport or HTTP
|
|
2876
|
+
* layer (network failure, timeout, non-2xx status). Contract-level errors
|
|
2877
|
+
* the node returns as a 2xx JSON error value are NOT wrapped here — they
|
|
2878
|
+
* flow through {@link parseContractResponse}'s normal return, same as the
|
|
2879
|
+
* session `execute` path.
|
|
2880
|
+
*
|
|
2881
|
+
* The message is always one of a small set of fixed, generic strings — it
|
|
2882
|
+
* NEVER contains the raw api key, the response body text, or the
|
|
2883
|
+
* underlying network error's message (CodeRabbit T4/T5): a server (or a
|
|
2884
|
+
* misbehaving intermediary) that echoes the key or other secrets back in
|
|
2885
|
+
* an error body must not be able to leak them through this error's
|
|
2886
|
+
* message.
|
|
2887
|
+
*/
|
|
2888
|
+
declare class InvokeError extends T3nError {
|
|
2889
|
+
readonly status?: number | undefined;
|
|
2890
|
+
constructor(message: string, status?: number | undefined);
|
|
2891
|
+
}
|
|
2892
|
+
/**
|
|
2893
|
+
* Execute a `z:` contract as an org agent, authenticating with an opaque
|
|
2894
|
+
* API key — one request, no handshake, no session.
|
|
2895
|
+
*
|
|
2896
|
+
* @param opts - baseUrl, apiKey, and the wire request to execute
|
|
2897
|
+
* @param schema - optional validator applied to the decoded result (e.g. a
|
|
2898
|
+
* zod schema); anything exposing `.parse(value)` is accepted, same as
|
|
2899
|
+
* {@link T3nClient.executeAndDecode}
|
|
2900
|
+
* @returns the contract's decoded result, typed as `T`
|
|
2901
|
+
* @throws {InvokeError} if `baseUrl` is insecure, on a network
|
|
2902
|
+
* failure/timeout, or on a non-2xx response
|
|
2903
|
+
* @throws {ContractResponseError} if the node returns a 2xx with a body
|
|
2904
|
+
* that is not valid JSON
|
|
2905
|
+
*/
|
|
2906
|
+
declare function invoke<T = unknown>(opts: InvokeOptions, schema?: ContractResponseSchema<T>): Promise<T>;
|
|
2907
|
+
|
|
2787
2908
|
/**
|
|
2788
2909
|
* Token fixed-point units (USDT-style 6 decimals).
|
|
2789
2910
|
*
|
|
@@ -4494,5 +4615,5 @@ declare function tenantDidHex(tenantDid: string): string;
|
|
|
4494
4615
|
declare function validateTail(tail: string): string;
|
|
4495
4616
|
declare function canonicalTenantName(tenantDid: string, tail: string): string;
|
|
4496
4617
|
|
|
4497
|
-
export { AGENT_CARDS_SCOPE, AuthMethod, AuthenticationError, BASE_UNITS_PER_TOKEN, ContractResponseError, DEFAULT_ENVIRONMENT, DEFAULT_INDIVIDUAL_THRESHOLD_CENTS, DEFAULT_KYC_POLL_CADENCE, HandshakeError, HttpTransport, KycStatusTimeoutError, LogLevel, MockTransport, NODE_URLS, OrgDataClient, OtpRateLimitedError, RpcError, SessionExpiredError, SessionOrgDataClient, SessionStateError, SessionStatus, SessionUsageReportClient, T3nClient, T3nError, TERMINAL_KYC_STATUSES, TOKEN_DECIMALS, TenantClient, TenantContractsNamespace, TenantMapsNamespace, TenantNamespace, TenantSdkValidationError, TenantTokenNamespace, UnsupportedTenantSdkOperationError, UserUpsertError, WasmError, WireEncodingError, Z_PAYROLL_AUDIT_READ_FUNCTIONS, Z_PAYROLL_RUN_FUNCTIONS, _b64uEncode, assertShape, b64uDecodeStrict, b64uEncodeBytes, bytesToString, canonicalTenantName, clearKeyCache, clearManifestVersionFloor, compactDidFromBytes, createDefaultHandlers, createEmailOtpAuthInput, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createOrgDataClientFromSession, createRandomHandler, createUsageReportClientFromSession, createWorkloadAuthInput, decodeWasmErrorMessage, deriveAgentCardEntryId, eth_get_address, extractWasmError, fetchDkgAttestation, fetchMlKemPublicKey, fetchTrustedManifest, formatTokens, generateRandomString, generateUUID, getEnvironment, getEnvironmentName, getGlobalLogLevel, getLogger, getNodeUrl, getScriptVersion, isAgentCardResponse, isDataGetResponse, isDataListResponse, isMutationResponse, isObject, isOrgAdminStatus, isOrgContractGrants, isOrgPolicyMeta, isOrgPolicyView, isOrgUsageReport, isOrgWriters, isRoleAssignmentsResponse, isRoleGetResponse, isUnsafeTrustServer, loadConfig, loadWasmComponent, manifestToTrustAnchor, maskKeyMaterial, mergeAgentAuthEntries, mergeDiscoverDids, metamask_get_address, metamask_sign, parseAgentAuthGet, parseAgentAuthPolicy, parseContractResponse, redactSecrets, redactSecretsFromJson, requestToWire, setEnvironment, setGlobalLogLevel, setNodeUrl, stringToBytes, tenantDidHex, toAgentAuthUpdateWire, toBaseUnits, validateConfig, validateTail, verifyDkgAttestation, verifyManifestSignature, verifyTdxQuote };
|
|
4498
|
-
export type { AdmitForOrgOptions, AgentAuthEntry, AgentAuthMergeResult, AgentAuthPolicy, AgentAuthScriptGrant, AgentAuthUpdateInput, AgentCardRefInput, AgentCardResponse, AgentCardSetInput, AssignRolesInput, AuthInput, BalanceRow, ChargeReason, ClientAuth, ClientHandshake, ConfigValidationResult, ContractExecuteInput, ContractKind, ContractPublishInput, ContractRegisterResult, ContractResponseSchema, ContractSetDescriptorInput, CreatePolicyInput, DataGetInput, DataGetResponse, DataListInput, DataListResponse, DelegationGrantKind, DelegationGrantRef, DeleteDataInput, DeleteGrantsInput, DeleteScopeInput, Did, Direction, DkgAttestation, DkgVerifyResult, EmailOtpAuthInput, EmailOtpCredentials, Environment, EthAuthInput, ExecuteBusinessContractOptions, ExecuteOrgDataActionOptions, FetchTrustedManifestOptions, GetUsageOptions, GrantCheckParams, GrantCheckResult, GranteeInput, GrantsGetInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, ListContractsParams, ListContractsResult, ListContractsScope, ListedContract, Logger, MapCreateInput, MapLifecycleStatus, MapResponse, MapUpdateInput, MapVisibility, MutationResponse, OidcAuthInput, OidcCredentials, OrgAdminStatus, OrgContractGrants, OrgDataActionWire, OrgDataClientOptions, OrgPolicyMeta, OrgPolicyView, OrgUsageReport, OrgUsageReportInput, OrgWriters, OtpChannel, OtpMergeSuggestion, OtpRequestInput, OtpRequestResult, OtpVerifyInput, OtpVerifyResult, PayrollRunRequest, PeerQuoteResult, PolicyGetInput, PurgeOrgInput, QuoteVerifyResult, ReaderSet, RemoveMemberGrantsInput, RoleAssignments, RoleAssignmentsResponse, RoleDefinition, RoleGetResponse, RoleGrant, RoleIdInput, SdkConfig, SessionCrypto, SessionId, SetGrantsInput, SetRoleInput, SetWritersInput, SignedTrustManifest, StringEncoding, SubmitUserInputArgs, SubmitUserInputResult, T3nClientConfig, TenantAdmitProjection, TenantAdmitStatus, TenantBaseClient, TenantClientConfig, TenantContractExecuteInput, TenantContractPublishInput, TenantContractSetDescriptorInput, TenantExecutionSession, TenantMapCreateInput, TenantMapUpdatePatch, TenantMeResponse, TenantSdkEnvironment, TenantSelfAdmitResult, TenantStatus, TenantTargetOptions, TokenTxKind, Transport, TrustAnchor, TrustAnchorOrUnsafe, TrustManifestPayload, UnassignRolesInput, UnsafeTrustServer, UpdateMetaInput, UsageEntry, UsagePage, UsageReportSignature, UserGrant, UserInputProfile, UserUpsertErrorKind, WasmComponent, WasmNextResult, WireBlock, WorkloadAuthInput, WriteDataInput, WriterSet, WritersGetInput };
|
|
4618
|
+
export { AGENT_CARDS_SCOPE, AuthMethod, AuthenticationError, BASE_UNITS_PER_TOKEN, ContractResponseError, DEFAULT_ENVIRONMENT, DEFAULT_INDIVIDUAL_THRESHOLD_CENTS, DEFAULT_KYC_POLL_CADENCE, HandshakeError, HttpTransport, InvokeError, KycStatusTimeoutError, LogLevel, MockTransport, NODE_URLS, OrgDataClient, OtpRateLimitedError, RpcError, SessionExpiredError, SessionOrgDataClient, SessionStateError, SessionStatus, SessionUsageReportClient, T3nClient, T3nError, TERMINAL_KYC_STATUSES, TOKEN_DECIMALS, TenantClient, TenantContractsNamespace, TenantMapsNamespace, TenantNamespace, TenantSdkValidationError, TenantTokenNamespace, UnsupportedTenantSdkOperationError, UserUpsertError, WasmError, WireEncodingError, Z_PAYROLL_AUDIT_READ_FUNCTIONS, Z_PAYROLL_RUN_FUNCTIONS, _b64uEncode, assertShape, b64uDecodeStrict, b64uEncodeBytes, bytesToString, canonicalTenantName, clearKeyCache, clearManifestVersionFloor, compactDidFromBytes, createDefaultHandlers, createEmailOtpAuthInput, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createOrgDataClientFromSession, createRandomHandler, createUsageReportClientFromSession, createWorkloadAuthInput, decodeWasmErrorMessage, deriveAgentCardEntryId, eth_get_address, extractWasmError, fetchDkgAttestation, fetchMlKemPublicKey, fetchTrustedManifest, formatTokens, generateRandomString, generateUUID, getEnvironment, getEnvironmentName, getGlobalLogLevel, getLogger, getNodeUrl, getScriptVersion, invoke, isAgentCardResponse, isDataGetResponse, isDataListResponse, isMutationResponse, isObject, isOrgAdminStatus, isOrgContractGrants, isOrgPolicyMeta, isOrgPolicyView, isOrgUsageReport, isOrgWriters, isRoleAssignmentsResponse, isRoleGetResponse, isUnsafeTrustServer, loadConfig, loadWasmComponent, manifestToTrustAnchor, maskKeyMaterial, mergeAgentAuthEntries, mergeDiscoverDids, metamask_get_address, metamask_sign, parseAgentAuthGet, parseAgentAuthPolicy, parseContractResponse, redactSecrets, redactSecretsFromJson, requestToWire, setEnvironment, setGlobalLogLevel, setNodeUrl, stringToBytes, tenantDidHex, toAgentAuthUpdateWire, toBaseUnits, validateConfig, validateTail, verifyDkgAttestation, verifyManifestSignature, verifyTdxQuote };
|
|
4619
|
+
export type { AdmitForOrgOptions, AgentAuthEntry, AgentAuthMergeResult, AgentAuthPolicy, AgentAuthScriptGrant, AgentAuthUpdateInput, AgentCardRefInput, AgentCardResponse, AgentCardSetInput, AssignRolesInput, AuthInput, BalanceRow, ChargeReason, ClientAuth, ClientHandshake, ConfigValidationResult, ContractExecuteInput, ContractKind, ContractPublishInput, ContractRegisterResult, ContractResponseSchema, ContractSetDescriptorInput, CreatePolicyInput, DataGetInput, DataGetResponse, DataListInput, DataListResponse, DelegationGrantKind, DelegationGrantRef, DeleteDataInput, DeleteGrantsInput, DeleteScopeInput, Did, Direction, DkgAttestation, DkgVerifyResult, EmailOtpAuthInput, EmailOtpCredentials, Environment, EthAuthInput, ExecuteBusinessContractOptions, ExecuteOrgDataActionOptions, FetchTrustedManifestOptions, GetUsageOptions, GrantCheckParams, GrantCheckResult, GranteeInput, GrantsGetInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, InvokeOptions, InvokeRequest, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, ListContractsParams, ListContractsResult, ListContractsScope, ListedContract, Logger, MapCreateInput, MapLifecycleStatus, MapResponse, MapUpdateInput, MapVisibility, MutationResponse, OidcAuthInput, OidcCredentials, OrgAdminStatus, OrgContractGrants, OrgDataActionWire, OrgDataClientOptions, OrgPolicyMeta, OrgPolicyView, OrgUsageReport, OrgUsageReportInput, OrgWriters, OtpChannel, OtpMergeSuggestion, OtpRequestInput, OtpRequestResult, OtpVerifyInput, OtpVerifyResult, PayrollRunRequest, PeerQuoteResult, PolicyGetInput, PurgeOrgInput, QuoteVerifyResult, ReaderSet, RemoveMemberGrantsInput, RoleAssignments, RoleAssignmentsResponse, RoleDefinition, RoleGetResponse, RoleGrant, RoleIdInput, SdkConfig, SessionCrypto, SessionId, SetGrantsInput, SetRoleInput, SetWritersInput, SignedTrustManifest, StringEncoding, SubmitUserInputArgs, SubmitUserInputResult, T3nClientConfig, TenantAdmitProjection, TenantAdmitStatus, TenantBaseClient, TenantClientConfig, TenantContractExecuteInput, TenantContractPublishInput, TenantContractSetDescriptorInput, TenantExecutionSession, TenantMapCreateInput, TenantMapUpdatePatch, TenantMeResponse, TenantSdkEnvironment, TenantSelfAdmitResult, TenantStatus, TenantTargetOptions, TokenTxKind, Transport, TrustAnchor, TrustAnchorOrUnsafe, TrustManifestPayload, UnassignRolesInput, UnsafeTrustServer, UpdateMetaInput, UsageEntry, UsagePage, UsageReportSignature, UserGrant, UserInputProfile, UserUpsertErrorKind, WasmComponent, WasmNextResult, WireBlock, WorkloadAuthInput, WriteDataInput, WriterSet, WritersGetInput };
|