@terminal3/t3n-sdk 3.0.0 → 3.2.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
@@ -1433,6 +1433,27 @@ declare class T3nClient {
1433
1433
  * 3. Sends `SubmitIdToken` with the nonce-bearing token → receives DID.
1434
1434
  */
1435
1435
  authenticate(authInput: AuthInput): Promise<Did>;
1436
+ /**
1437
+ * Add an Ethereum wallet as an additional authenticator on the
1438
+ * already-authenticated account.
1439
+ *
1440
+ * Proves control of the wallet via SIWE and links it to the session's
1441
+ * EXISTING DID (resolved server-side from the session) — it does NOT
1442
+ * mint a new DID and does NOT change the session: `this.did` and
1443
+ * `this.status` are left untouched, and no new cookie is issued.
1444
+ *
1445
+ * Requires a completed {@link authenticate} first (e.g. an OIDC
1446
+ * login). Only Ethereum is supported — OIDC/email identities are
1447
+ * established at login, not added afterwards.
1448
+ *
1449
+ * Reuses the same client-side eth state machine as login, but posts
1450
+ * to the authenticated `auth.add-authenticator` route. If the wallet
1451
+ * is already linked to a different account, the server rejects with a
1452
+ * typed `eth_auth_map_conflict` error (resolve via account merge).
1453
+ *
1454
+ * @returns the existing DID the wallet was linked to.
1455
+ */
1456
+ addAuthMethod(authInput: EthAuthInput): Promise<Did>;
1436
1457
  /**
1437
1458
  * OIDC two-step authentication with session-binding nonce.
1438
1459
  *
@@ -2833,4 +2854,4 @@ declare function clearKeyCache(): void;
2833
2854
  declare function loadConfig(baseUrl?: string): SdkConfig;
2834
2855
 
2835
2856
  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, 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, RevokeDelegationOpts, RevokeDelegationResult, SdkConfig, SessionCrypto, SessionId, SetGrantsInput, SetWritersInput, SignCustodialResult, SignDelegationResponse, SubmitUserInputArgs, SubmitUserInputResult, T3nClientConfig, TenantAdmitProjection, TenantAdmitStatus, Transport, UpdateMetaInput, UserGrant, UserInputProfile, UserUpsertErrorKind, WasmComponent, WasmNextResult, WriteDataInput, WritersGetInput };
2857
+ 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 };