@terminal3/t3n-sdk 2.13.0 → 3.1.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/README.md CHANGED
@@ -27,17 +27,18 @@ import {
27
27
  loadWasmComponent,
28
28
  createEthAuthInput,
29
29
  eth_get_address,
30
- eth_sign,
30
+ metamask_sign,
31
31
  } from "@terminal3/t3n-sdk";
32
32
 
33
33
  const wasmComponent = await loadWasmComponent();
34
34
  const privateKey = process.env.T3N_DEMO_KEY!;
35
+ const address = eth_get_address(privateKey);
35
36
 
36
37
  const client = new T3nClient({
37
38
  baseUrl: "https://t3n-node.example.com",
38
39
  wasmComponent,
39
40
  handlers: {
40
- EthSign: eth_sign(privateKey),
41
+ EthSign: metamask_sign(address, undefined, privateKey),
41
42
  },
42
43
  });
43
44
 
@@ -55,15 +56,16 @@ import {
55
56
  T3nClient,
56
57
  createEthAuthInput,
57
58
  eth_get_address,
58
- eth_sign,
59
+ metamask_sign,
59
60
  } from "@terminal3/t3n-sdk";
60
61
 
61
62
  const privateKey = "0x...";
63
+ const address = eth_get_address(privateKey);
62
64
 
63
65
  const client = new T3nClient({
64
66
  wasmComponent: await loadWasmComponent(),
65
67
  handlers: {
66
- EthSign: eth_sign(privateKey),
68
+ EthSign: metamask_sign(address, undefined, privateKey),
67
69
  },
68
70
  });
69
71
 
@@ -306,7 +308,10 @@ interface T3nClientConfig {
306
308
  ### Example with Custom Configuration
307
309
 
308
310
  ```typescript
309
- import { T3nClient, LogLevel } from '@terminal3/t3n-sdk';
311
+ import { T3nClient, LogLevel, eth_get_address, metamask_sign } from '@terminal3/t3n-sdk';
312
+
313
+ const privateKey = process.env.T3N_DEMO_KEY!;
314
+ const address = eth_get_address(privateKey);
310
315
 
311
316
  const client = new T3nClient({
312
317
  baseUrl: "https://t3n-node.example.com",
@@ -318,7 +323,7 @@ const client = new T3nClient({
318
323
  'X-Custom-Header': 'custom-value'
319
324
  },
320
325
  handlers: {
321
- EthSign: eth_sign(privateKey),
326
+ EthSign: metamask_sign(address, undefined, privateKey),
322
327
  MlKemPublicKey: ml_kem_public_key(),
323
328
  Random: random(),
324
329
  }
@@ -873,11 +878,13 @@ To use the real WASM component:
873
878
 
874
879
  ### Mock Component for Testing
875
880
 
881
+ `loadWasmComponent()` automatically falls back to a built-in mock when the real WASM file is not present. No extra setup needed in test environments:
882
+
876
883
  ```typescript
877
- import { createMockWasmComponent } from '@terminal3/t3n-sdk';
884
+ import { loadWasmComponent } from '@terminal3/t3n-sdk';
878
885
 
879
- // Use mock component for testing
880
- const mockComponent = createMockWasmComponent();
886
+ // In test environments (no real WASM file present), this returns a mock automatically
887
+ const wasmComponent = await loadWasmComponent();
881
888
  ```
882
889
 
883
890
  ### WASM Component Features
package/dist/index.d.ts CHANGED
@@ -1968,6 +1968,13 @@ declare const NONCE_LEN = 16;
1968
1968
  declare const REQUEST_HASH_LEN = 32;
1969
1969
  declare const AGENT_PUBKEY_LEN = 33;
1970
1970
  declare const ETH_SIG_LEN = 65;
1971
+ declare const MAX_FUNCTIONS_PER_CREDENTIAL = 16;
1972
+ /**
1973
+ * Canonical sorted list of the payroll v2 function surface. One source
1974
+ * of truth for callers building a full-cycle credential — pass this
1975
+ * (or a sorted subset) as `functions` to {@link buildDelegationCredential}.
1976
+ */
1977
+ declare const PAYROLL_FUNCTIONS_V1: readonly ["compute-payroll", "execute-disbursement", "finalize-audit", "submit-escalations", "validate-credentials"];
1971
1978
  /** User-to-agent delegation credential body. */
1972
1979
  interface DelegationCredential {
1973
1980
  /** Domain tag, must equal {@link DELEGATION_CREDENTIAL_DOMAIN}. */
@@ -1980,8 +1987,11 @@ interface DelegationCredential {
1980
1987
  org_did: string;
1981
1988
  /** Contract id, e.g. `"tee:payroll"`. */
1982
1989
  contract: string;
1983
- /** Function name, e.g. `"run-payroll"`. */
1984
- function: string;
1990
+ /**
1991
+ * Functions this credential authorises. Sorted ascending, deduped,
1992
+ * each entry non-empty lowercase ASCII, 1..=16 entries.
1993
+ */
1994
+ functions: string[];
1985
1995
  /** Org-data scopes the contract may read on this user's behalf. */
1986
1996
  scopes: string[];
1987
1997
  /** Flat key-value labels checked against the org grant. */
@@ -2104,7 +2114,12 @@ interface BuildDelegationCredentialOpts {
2104
2114
  agent_pubkey: Uint8Array;
2105
2115
  org_did: string;
2106
2116
  contract: string;
2107
- function: string;
2117
+ /**
2118
+ * Functions this credential authorises. Must be non-empty, sorted
2119
+ * ascending, deduped — the same invariants enforced by
2120
+ * {@link validateCredentialBody}.
2121
+ */
2122
+ functions: string[];
2108
2123
  scopes?: string[];
2109
2124
  metadata?: Record<string, string>;
2110
2125
  not_before_secs: bigint | number;
@@ -2210,6 +2225,54 @@ declare class DelegationCustodialClient {
2210
2225
  */
2211
2226
  signCustodial(body: Record<string, unknown>): Promise<SignCustodialResult>;
2212
2227
  }
2228
+ /** Options for {@link revokeDelegation}. */
2229
+ interface RevokeDelegationOpts {
2230
+ /** Credential body to revoke. Already-encoded base64url-no-pad JCS bytes. */
2231
+ credentialJcsB64u: string;
2232
+ /**
2233
+ * Omit (or pass `undefined`) to revoke the whole credential. Pass an
2234
+ * array of function names to revoke a subset; the array must obey the
2235
+ * same sort + dedupe invariants the credential's `functions` field
2236
+ * enforces, and each entry must already appear in the credential's
2237
+ * `functions` list (a revocation can only narrow the set, never grow
2238
+ * it).
2239
+ */
2240
+ revokedFunctions?: string[];
2241
+ /** Authenticated {@link T3nClient} for the credential's `user_did`. */
2242
+ client: T3nClient;
2243
+ /**
2244
+ * Override the resolved delegation contract version. Defaults to
2245
+ * whatever `GET /api/contracts/current?name=tee:delegation/contracts`
2246
+ * returns at call time.
2247
+ */
2248
+ scriptVersion?: string;
2249
+ /** Override the node base URL used for `"latest"` resolution. */
2250
+ baseUrl?: string;
2251
+ }
2252
+ /** Result of a successful {@link revokeDelegation} call. */
2253
+ interface RevokeDelegationResult {
2254
+ /** Credential id (base64url-no-pad, no padding). */
2255
+ vcId: string;
2256
+ /**
2257
+ * Mirrors the persisted revocation state after merging: `null` means
2258
+ * whole-credential, a sorted array means per-function. The contract
2259
+ * may return a larger set than `opts.revokedFunctions` when an
2260
+ * earlier per-function revocation existed for the same credential.
2261
+ */
2262
+ revokedFunctions: string[] | null;
2263
+ }
2264
+ /**
2265
+ * Wraps the `tee:delegation/contracts::revoke` entrypoint. Only the
2266
+ * credential's `user_did` may call this — the contract reads the
2267
+ * authenticated DID from session context and rejects any other caller
2268
+ * with `NotCredentialHolder`.
2269
+ *
2270
+ * Merge semantics are handled server-side: whole-credential revocations
2271
+ * are sticky, and per-function revocations accumulate as a sorted +
2272
+ * deduped union across calls. The returned `revokedFunctions` reflects
2273
+ * the persisted state after merging, not just this call's input.
2274
+ */
2275
+ declare function revokeDelegation(opts: RevokeDelegationOpts): Promise<RevokeDelegationResult>;
2213
2276
  /** Options for {@link buildPayrollInvocation}. */
2214
2277
  interface BuildPayrollInvocationOpts {
2215
2278
  credentialJcs: Uint8Array;
@@ -2769,5 +2832,5 @@ declare function clearKeyCache(): void;
2769
2832
  */
2770
2833
  declare function loadConfig(baseUrl?: string): SdkConfig;
2771
2834
 
2772
- export { AGENT_PUBKEY_LEN, AuthMethod, AuthenticationError, ContractResponseError, DEFAULT_INDIVIDUAL_THRESHOLD_CENTS, DEFAULT_KYC_POLL_CADENCE, DELEGATION_CREDENTIAL_DOMAIN, DELEGATION_INVOCATION_DOMAIN, DelegationCustodialClient, ETH_SIG_LEN, HandshakeError, HttpTransport, KycStatusTimeoutError, LogLevel, MockTransport, NODE_URLS, NONCE_LEN, OrgDataClient, REQUEST_HASH_LEN, RpcError, SessionExpiredError, SessionOrgDataClient, SessionStateError, SessionStatus, T3nClient, T3nError, TERMINAL_KYC_STATUSES, UserUpsertError, VC_ID_LEN, WasmError, _b64uEncode, assertShape, b64uDecodeStrict, b64uEncodeBytes, buildDelegationCredential, buildInvocationPreimage, buildPayrollDirectInvocation, buildPayrollInvocation, bytesToString, canonicaliseCredential, canonicaliseRequest, clearKeyCache, compactDidFromBytes, createDefaultHandlers, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createOrgDataClientFromSession, createRandomHandler, decodeWasmErrorMessage, eip191Digest, ethRecoverEip191, eth_get_address, extractWasmError, fetchDkgAttestation, fetchMlKemPublicKey, generateRandomString, generateUUID, getEnvironment, getEnvironmentName, getGlobalLogLevel, getLogger, getNodeUrl, getScriptVersion, isDataGetResponse, isDataListResponse, isMutationResponse, isObject, isOrgContractGrants, isOrgPolicyMeta, isOrgWriters, loadConfig, loadWasmComponent, metamask_get_address, metamask_sign, parseContractResponse, redactSecrets, redactSecretsFromJson, requestHash, setEnvironment, setGlobalLogLevel, setNodeUrl, signAgentInvocation, signCredential, stringToBytes, validateConfig, validateCredentialBody, verifyDkgAttestation, verifyTdxQuote };
2773
- export type { AgeBand, AuthInput, BuildDelegationCredentialOpts, BuildPayrollDirectInvocationOpts, BuildPayrollInvocationOpts, ClientAuth, ClientHandshake, ConfigValidationResult, ContractResponseSchema, CreatePolicyInput, DataGetInput, DataGetResponse, DataListInput, DataListResponse, DelegationCredential, DelegationCustodialClientOpts, DelegationEnvelope, DeleteDataInput, DeleteGrantsInput, DeleteScopeInput, Did, DkgAttestation, DkgVerifyResult, EmployeeRecord, EmploymentStatus, Environment, EthAuthInput, ExecuteOrgDataActionOptions, ExpenseClaim, GrantsGetInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, Logger, MutationResponse, OidcAuthInput, OidcCredentials, OrgContractGrants, OrgDataActionWire, OrgDataClientOptions, OrgPolicyMeta, OrgWriters, OtpChannel, OtpMergeSuggestion, OtpRequestInput, OtpRequestResult, OtpVerifyInput, OtpVerifyResult, PayrollInvocation, PayrollInvocationDelegated, PayrollInvocationDirect, PayrollRunRequest, PeerQuoteResult, PolicyGetInput, QuoteVerifyResult, ResidencyCategory, SdkConfig, SessionCrypto, SessionId, SetGrantsInput, SetWritersInput, SignCustodialResult, SignDelegationResponse, SubmitUserInputArgs, SubmitUserInputResult, T3nClientConfig, TenantAdmitProjection, TenantAdmitStatus, Transport, UpdateMetaInput, UserGrant, UserInputProfile, UserUpsertErrorKind, WasmComponent, WasmNextResult, WriteDataInput, WritersGetInput };
2835
+ export { AGENT_PUBKEY_LEN, AuthMethod, AuthenticationError, ContractResponseError, DEFAULT_INDIVIDUAL_THRESHOLD_CENTS, DEFAULT_KYC_POLL_CADENCE, DELEGATION_CREDENTIAL_DOMAIN, DELEGATION_INVOCATION_DOMAIN, DelegationCustodialClient, ETH_SIG_LEN, HandshakeError, HttpTransport, KycStatusTimeoutError, LogLevel, MAX_FUNCTIONS_PER_CREDENTIAL, MockTransport, NODE_URLS, NONCE_LEN, OrgDataClient, PAYROLL_FUNCTIONS_V1, REQUEST_HASH_LEN, RpcError, SessionExpiredError, SessionOrgDataClient, SessionStateError, SessionStatus, T3nClient, T3nError, TERMINAL_KYC_STATUSES, UserUpsertError, VC_ID_LEN, WasmError, _b64uEncode, assertShape, b64uDecodeStrict, b64uEncodeBytes, buildDelegationCredential, buildInvocationPreimage, buildPayrollDirectInvocation, buildPayrollInvocation, bytesToString, canonicaliseCredential, canonicaliseRequest, clearKeyCache, compactDidFromBytes, createDefaultHandlers, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createOrgDataClientFromSession, createRandomHandler, decodeWasmErrorMessage, eip191Digest, ethRecoverEip191, eth_get_address, extractWasmError, fetchDkgAttestation, fetchMlKemPublicKey, generateRandomString, generateUUID, getEnvironment, getEnvironmentName, getGlobalLogLevel, getLogger, getNodeUrl, getScriptVersion, isDataGetResponse, isDataListResponse, isMutationResponse, isObject, isOrgContractGrants, isOrgPolicyMeta, isOrgWriters, loadConfig, loadWasmComponent, metamask_get_address, metamask_sign, parseContractResponse, redactSecrets, redactSecretsFromJson, requestHash, revokeDelegation, setEnvironment, setGlobalLogLevel, setNodeUrl, signAgentInvocation, signCredential, stringToBytes, validateConfig, validateCredentialBody, verifyDkgAttestation, verifyTdxQuote };
2836
+ export type { AgeBand, AuthInput, BalanceRow, BuildDelegationCredentialOpts, BuildPayrollDirectInvocationOpts, BuildPayrollInvocationOpts, ChargeReason, ClientAuth, ClientHandshake, ConfigValidationResult, ContractResponseSchema, CreatePolicyInput, DataGetInput, DataGetResponse, DataListInput, DataListResponse, DelegationCredential, DelegationCustodialClientOpts, DelegationEnvelope, DeleteDataInput, DeleteGrantsInput, DeleteScopeInput, Did, Direction, DkgAttestation, DkgVerifyResult, EmployeeRecord, EmploymentStatus, Environment, EthAuthInput, ExecuteOrgDataActionOptions, ExpenseClaim, GetUsageOptions, GrantsGetInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, Logger, MutationResponse, OidcAuthInput, OidcCredentials, OrgContractGrants, OrgDataActionWire, OrgDataClientOptions, OrgPolicyMeta, OrgWriters, OtpChannel, OtpMergeSuggestion, OtpRequestInput, OtpRequestResult, OtpVerifyInput, OtpVerifyResult, PayrollInvocation, PayrollInvocationDelegated, PayrollInvocationDirect, PayrollRunRequest, PeerQuoteResult, PolicyGetInput, QuoteVerifyResult, ResidencyCategory, RevokeDelegationOpts, RevokeDelegationResult, SdkConfig, SessionCrypto, SessionId, SetGrantsInput, SetWritersInput, SignCustodialResult, SignDelegationResponse, SubmitUserInputArgs, SubmitUserInputResult, T3nClientConfig, TenantAdmitProjection, TenantAdmitStatus, TokenTxKind, Transport, UpdateMetaInput, UsageEntry, UsagePage, UserGrant, UserInputProfile, UserUpsertErrorKind, WasmComponent, WasmNextResult, WriteDataInput, WritersGetInput };