@terminal3/t3n-sdk 3.5.2 → 3.6.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/index.d.ts CHANGED
@@ -865,9 +865,15 @@ interface OrgDataActionWire {
865
865
  * `available` and `reserved` are `u128` on the server; the wire
866
866
  * format is a JSON number. Callers should not assume bigint until
867
867
  * the SDK migrates to a streaming parser (tracked separately).
868
+ *
869
+ * ⚠️ Amounts are in **base units** (`1 token = `
870
+ * {@link BASE_UNITS_PER_TOKEN}), not whole tokens. Use
871
+ * {@link formatTokens} to display them.
868
872
  */
869
873
  interface BalanceRow {
874
+ /** Spendable balance, in base units (see {@link formatTokens}). */
870
875
  available: number;
876
+ /** Reserved balance, in base units. */
871
877
  reserved: number;
872
878
  last_settled_seq_no: number;
873
879
  version: number;
@@ -922,6 +928,7 @@ type ChargeReason = {
922
928
  interface UsageEntry {
923
929
  seq_no: number;
924
930
  kind: TokenTxKind;
931
+ /** Amount moved, in base units (`1 token = `{@link BASE_UNITS_PER_TOKEN}); see {@link formatTokens}. */
925
932
  amount: number;
926
933
  timestamp_ms: number;
927
934
  direction: Direction;
@@ -2733,6 +2740,45 @@ declare class SessionOrgDataClient {
2733
2740
  */
2734
2741
  declare function createOrgDataClientFromSession(t3n: T3nClient, baseUrl: string): SessionOrgDataClient;
2735
2742
 
2743
+ /**
2744
+ * Token fixed-point units (USDT-style 6 decimals).
2745
+ *
2746
+ * As of `tee:*` metering v2, every token amount on the wire —
2747
+ * {@link BalanceRow}'s `available`/`reserved`, {@link UsageEntry.amount},
2748
+ * and `total_supply` — is denominated in **base units**, where
2749
+ * `1 T3N token = `{@link BASE_UNITS_PER_TOKEN}` base units`. The node
2750
+ * meters the *actual* fractional cost of each operation (pro-rata by
2751
+ * bytes / byte-seconds / fuel) down to `1e-6` token, so amounts are
2752
+ * raw integers in base units, NOT whole tokens.
2753
+ *
2754
+ * The wire fields are left as raw base units (no silent rescaling — that
2755
+ * would lose precision for large balances and surprise callers doing
2756
+ * arithmetic). Use {@link formatTokens} to render a human "tokens"
2757
+ * string and {@link toBaseUnits} to convert a token figure back.
2758
+ *
2759
+ * ⚠️ Breaking vs. the pre-decimals SDK: a balance that used to read `5`
2760
+ * (whole tokens) now reads `5_000_000` (base units). Multiply existing
2761
+ * display code through {@link formatTokens}.
2762
+ */
2763
+ /** Decimal places in a T3N token (fixed; mirrors the node constant). */
2764
+ declare const TOKEN_DECIMALS = 6;
2765
+ /** Base units per whole T3N token — `10 ** TOKEN_DECIMALS`. */
2766
+ declare const BASE_UNITS_PER_TOKEN = 1000000;
2767
+ /**
2768
+ * Render a base-unit amount as a human-readable token string, e.g.
2769
+ * `25_920_000 → "25.92"`, `1_000_000 → "1"`, `4768 → "0.004768"`.
2770
+ *
2771
+ * Trailing-zero fraction digits are trimmed; an integer amount renders
2772
+ * with no decimal point. Accepts `number` or `bigint`; for balances
2773
+ * above `Number.MAX_SAFE_INTEGER` prefer passing a `bigint`.
2774
+ */
2775
+ declare function formatTokens(baseUnits: number | bigint): string;
2776
+ /**
2777
+ * Convert a whole-or-fractional token figure to base units (rounded to
2778
+ * the nearest base unit). E.g. `25.92 → 25_920_000`, `1 → 1_000_000`.
2779
+ */
2780
+ declare function toBaseUnits(tokens: number): number;
2781
+
2736
2782
  /**
2737
2783
  * Cryptographic utilities for T3n SDK
2738
2784
  *
@@ -3185,5 +3231,5 @@ declare function tenantDidHex(tenantDid: string): string;
3185
3231
  declare function validateTail(tail: string): string;
3186
3232
  declare function canonicalTenantName(tenantDid: string, tail: string): string;
3187
3233
 
3188
- 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, TenantClient, TenantContractsNamespace, TenantMapsNamespace, TenantNamespace, TenantSdkValidationError, TenantTokenNamespace, UnsupportedTenantSdkOperationError, UserUpsertError, VC_ID_LEN, WasmError, _b64uEncode, assertShape, b64uDecodeStrict, b64uEncodeBytes, buildDelegationCredential, buildInvocationPreimage, buildPayrollDirectInvocation, buildPayrollInvocation, bytesToString, canonicalTenantName, 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, tenantDidHex, validateConfig, validateCredentialBody, validateTail, verifyDkgAttestation, verifyTdxQuote };
3234
+ export { AGENT_PUBKEY_LEN, AuthMethod, AuthenticationError, BASE_UNITS_PER_TOKEN, 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, TOKEN_DECIMALS, TenantClient, TenantContractsNamespace, TenantMapsNamespace, TenantNamespace, TenantSdkValidationError, TenantTokenNamespace, UnsupportedTenantSdkOperationError, UserUpsertError, VC_ID_LEN, WasmError, _b64uEncode, assertShape, b64uDecodeStrict, b64uEncodeBytes, buildDelegationCredential, buildInvocationPreimage, buildPayrollDirectInvocation, buildPayrollInvocation, bytesToString, canonicalTenantName, canonicaliseCredential, canonicaliseRequest, clearKeyCache, compactDidFromBytes, createDefaultHandlers, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createOrgDataClientFromSession, createRandomHandler, decodeWasmErrorMessage, eip191Digest, ethRecoverEip191, eth_get_address, extractWasmError, fetchDkgAttestation, fetchMlKemPublicKey, formatTokens, 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, tenantDidHex, toBaseUnits, validateConfig, validateCredentialBody, validateTail, verifyDkgAttestation, verifyTdxQuote };
3189
3235
  export type { AgeBand, AuthInput, BalanceRow, BuildDelegationCredentialOpts, BuildPayrollDirectInvocationOpts, BuildPayrollInvocationOpts, ChargeReason, ClientAuth, ClientHandshake, ConfigValidationResult, ContractExecuteInput, ContractPublishInput, ContractResponseSchema, CreatePolicyInput, DataGetInput, DataGetResponse, DataListInput, DataListResponse, DelegationCredential, DelegationCustodialClientOpts, DelegationEnvelope, DeleteDataInput, DeleteGrantsInput, DeleteScopeInput, Did, Direction, DkgAttestation, DkgVerifyResult, EmployeeRecord, EmploymentStatus, Environment, EthAuthInput, ExecuteBusinessContractOptions, ExecuteOrgDataActionOptions, ExpenseClaim, GetUsageOptions, GrantsGetInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, Logger, MapCreateInput, MapResponse, MapUpdateInput, MapVisibility, MutationResponse, OidcAuthInput, OidcCredentials, OrgContractGrants, OrgDataActionWire, OrgDataClientOptions, OrgPolicyMeta, OrgWriters, OtpChannel, OtpMergeSuggestion, OtpRequestInput, OtpRequestResult, OtpVerifyInput, OtpVerifyResult, PayrollInvocation, PayrollInvocationDelegated, PayrollInvocationDirect, PayrollRunRequest, PeerQuoteResult, PolicyGetInput, QuoteVerifyResult, ReaderSet, ResidencyCategory, RevokeDelegationOpts, RevokeDelegationResult, SdkConfig, SessionCrypto, SessionId, SetGrantsInput, SetWritersInput, SignCustodialResult, SignDelegationResponse, SubmitUserInputArgs, SubmitUserInputResult, T3nClientConfig, TenantAdmitProjection, TenantAdmitStatus, TenantBaseClient, TenantClientConfig, TenantContractExecuteInput, TenantContractPublishInput, TenantExecutionSession, TenantMapCreateInput, TenantMapUpdatePatch, TenantMeResponse, TenantSdkEnvironment, TenantSelfAdmitResult, TenantStatus, TokenTxKind, Transport, UpdateMetaInput, UsageEntry, UsagePage, UserGrant, UserInputProfile, UserUpsertErrorKind, WasmComponent, WasmNextResult, WriteDataInput, WriterSet, WritersGetInput };