@terminal3/t3n-sdk 4.37.1 → 4.39.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
@@ -965,130 +965,522 @@ declare class ContractResponseError extends T3nError {
965
965
  declare function parseContractResponse<T = unknown>(raw: string, schema?: ContractResponseSchema<T>): T;
966
966
 
967
967
  /**
968
- * Agent-auth grants — the standing on-chain authority a user delegates to
969
- * an agent (envelope-free authorisation).
968
+ * Org-data wire types mirroring the org-data contract wire shapes.
970
969
  *
971
- * `AGENT_AUTH_MAP` is keyed by the *user* DID — one policy document per
972
- * user, global across orgs, with at most one entry per agent DID. Reads
973
- * (`agent-auth-get`) and writes (`agent-auth-update`) on
974
- * `tee:authorisations/contracts` (the policy's owning contract) are
975
- * **SelfOnly**: only the user, authenticated as themselves, may read or
976
- * write their own grants. This is the user-approval
977
- * proof the per-call delegation credential's `user_sig` used to carry.
978
- *
979
- * The write shape gained `scopes` + a validity window: the
980
- * agent's delegated org-data scopes, and an optional `[valid_from_secs,
981
- * valid_until_secs]` window. The ≤ cap *length* check is enforced contract-
982
- * side at write time; the expiry gate is host-side at read time.
983
- *
984
- * The merge below is a script-level union (R59): writing a grant for one
985
- * `(agent_did, script_name)` preserves every other script row on that
986
- * agent's entry, and every other agent's entry, unchanged.
987
- */
988
- /** A single script grant in the camelCase write-request shape. */
989
- interface AgentAuthScriptGrant {
990
- /** Contract name, or `"*"`. */
991
- scriptName: string;
992
- /** Optional semver requirement; `null` to match any version. */
993
- versionReq?: string | null;
994
- /** Functions the agent may invoke on this contract. */
970
+ * Plain TypeScript interfaces (no zod) — the SDK does not use a
971
+ * validation library for domain types; see the existing `types/` files.
972
+ *
973
+ * Each response type below is paired with a shallow runtime predicate
974
+ * (`isMutationResponse`, `isOrgPolicyMeta`, etc.) so the org-data client
975
+ * can `assertShape` the decoded payload before returning to callers.
976
+ * Predicates check the top-level structure only; nested elements
977
+ * (e.g. each `BoundGrant` inside `OrgContractDelegation.grants`) are not
978
+ * deeply validated — see `utils/shape.ts` for the rationale.
979
+ *
980
+ * Reference: the org-data wire contract.
981
+ */
982
+ /**
983
+ * Validity time-box on an agent-edge grant — serialised under the JSON key
984
+ * `window`. Both bounds are optional unix-seconds; an omitted bound is
985
+ * defaulted contract-side (`valid_from_secs` → now, `valid_until_secs` → now +
986
+ * operator cap). Mirrors the org-data `Validity` wire shape. Absent bounds
987
+ * are omitted from the wire (never sent as `null`).
988
+ */
989
+ interface Validity {
990
+ valid_from_secs?: number;
991
+ valid_until_secs?: number;
992
+ }
993
+ /**
994
+ * A grantee-bound capability grant — the element of BOTH grant-management
995
+ * surfaces: the org edge (`org-delegation-set` input / `org-delegation-get`
996
+ * output) and the flat delegation edge (`member-delegation-get` output /
997
+ * `member-delegation-update` input). Stored inline on the unified `ROLE_ASSIGNMENTS_MAP`
998
+ * edge record.
999
+ *
1000
+ * Mirrors the org-data `BoundGrant` wire shape verbatim (snake_case, no casing
1001
+ * transform): `grantee` followed by the flattened capability body. The org edge
1002
+ * populates only `functions` + `scopes`; the delegation edge additionally
1003
+ * carries the qualifiers `version_req` / `read_scopes` / `allowed_hosts` and the
1004
+ * validity `window`. All qualifier fields are optional and omitted from the wire when
1005
+ * absent (never sent as `null`), so an org grant simply leaves them unset.
1006
+ */
1007
+ interface BoundGrant {
1008
+ /** The principal (`did:t3n:<40-hex>`) this grant applies to — a user or an
1009
+ * agent DID. */
1010
+ grantee: string;
1011
+ /** Target contract id (canonical name, e.g. `"tee:z-payroll/contracts"`), or
1012
+ * `"*"`. On a read this echoes the queried contract. */
1013
+ contract_id: string;
1014
+ /** WIT function names the grantee may invoke (e.g. `"set-records"`; `["*"]`
1015
+ * matches all). */
995
1016
  functions: string[];
996
- /** Org-data scopes delegated to the agent for the contract functions to
997
- * read on its behalf. */
998
- scopes?: string[];
999
- /** Direct-read scopes the agent may enumerate itself, via whichever read
1000
- * function the contract exposes for direct enumeration. A strict subset of
1001
- * `scopes` (enforced contract-side). */
1002
- readScopes?: string[];
1003
- /** Optional validity-window start (unix seconds). */
1004
- validFromSecs?: number | null;
1005
- /** NEW: optional validity-window end (unix seconds). */
1006
- validUntilSecs?: number | null;
1007
- /** Egress hosts the agent may reach for this contract. */
1008
- allowedHosts: string[];
1017
+ /** Data scope paths the grantee may access (e.g. `"example/records"`). */
1018
+ scopes: string[];
1019
+ /** Agent edge only: optional semver requirement; omitted matches any version. */
1020
+ version_req?: string;
1021
+ /** Agent edge only: direct-read scopes the grantee may enumerate itself — a
1022
+ * subset of `scopes` (enforced contract-side). */
1023
+ read_scopes?: string[];
1024
+ /** Agent edge only: egress hosts the grantee may reach for this contract. */
1025
+ allowed_hosts?: string[];
1026
+ /** Agent edge only: optional validity time-box. */
1027
+ window?: Validity;
1009
1028
  }
1010
- /** One agent's entry in the write-request shape. */
1011
- interface AgentAuthEntry {
1012
- agentDid: string;
1013
- scripts: AgentAuthScriptGrant[];
1029
+ /**
1030
+ * Policy record for an organisation's data tier.
1031
+ *
1032
+ * Mirrors the org-data policy-meta wire shape.
1033
+ */
1034
+ interface OrgPolicyMeta {
1035
+ /** DIDs (`did:t3n:<40-hex>`) of users authorised to manage policy and read data. */
1036
+ admins: string[];
1037
+ /** Maximum number of admins allowed for this org. */
1038
+ max_admins: number;
1039
+ /** Unix timestamp (secs) when the policy was first created. */
1040
+ created_at_secs: number;
1041
+ /** Unix timestamp (secs) of the most recent policy update. */
1042
+ updated_at_secs: number;
1043
+ /**
1044
+ * Per-org ceiling on delegation-credential validity (seconds).
1045
+ *
1046
+ * Absent when no org-level cap is set — the contract omits the field
1047
+ * (never serialises null) and the cluster-wide
1048
+ * `delegation.max_credential_validity_secs` governs instead. When set,
1049
+ * the effective cap is `min(max_credential_validity_secs, cluster_ceiling)`.
1050
+ */
1051
+ max_credential_validity_secs?: number;
1014
1052
  }
1053
+ /** Shallow runtime guard for {@link OrgPolicyMeta}. */
1054
+ declare function isOrgPolicyMeta(value: unknown): value is OrgPolicyMeta;
1015
1055
  /**
1016
- * The full agent-auth policy document in the camelCase write shape:
1017
- * the per-agent grants plus the document-level discovery grants.
1056
+ * Effective org policy view returned by `org-policy-view`.
1018
1057
  *
1019
- * `discoverDids` (contract wire: `discover_dids`) is the
1020
- * list of DIDs the user lets their registered agents *enumerate the
1021
- * contracts of* via `listContracts`: an org DID grants org-mode discovery,
1022
- * the user's own DID grants self-mode discovery. It lives at document
1023
- * level — not on a script grant — because discovery must surface contracts
1024
- * the agent cannot yet call. The node's discovery gate additionally
1025
- * requires the calling agent to be named in `agents` (subject binding), so
1026
- * an unregistered agent discovers nothing regardless of this list.
1058
+ * Readable by any authenticated session (non-sensitive metadata).
1059
+ * Returns the **effective** credential validity cap:
1060
+ * `min(org.max_credential_validity_secs, cluster_ceiling)`, equal to the
1061
+ * cluster ceiling when the org has not set a per-org cap. The contract
1062
+ * always returns a value (or errors) — the field is never null.
1063
+ */
1064
+ interface OrgPolicyView {
1065
+ /**
1066
+ * Effective delegation-credential validity cap in seconds:
1067
+ * `min(org value, cluster ceiling)`, equal to the cluster ceiling when the
1068
+ * org has not set a per-org cap. Always present — mirrors the contract's
1069
+ * `PolicyViewResponse.effective_validity_secs` (org-data `org-policy-view`).
1070
+ */
1071
+ effective_validity_secs: number;
1072
+ }
1073
+ /** Shallow runtime guard for {@link OrgPolicyView}. */
1074
+ declare function isOrgPolicyView(value: unknown): value is OrgPolicyView;
1075
+ /**
1076
+ * Caller-scoped admin status returned by `org-am-i-admin`.
1077
+ *
1078
+ * Reports only whether the **calling** session's DID is in the org's admin
1079
+ * list — never the roster itself (contrast {@link OrgPolicyMeta}, returned by
1080
+ * the admin-gated `org-policy-get`). Readable by any authenticated session.
1081
+ * Mirrors the org-data `AmIAdminResponse` wire shape.
1082
+ */
1083
+ interface OrgAdminStatus {
1084
+ /** Whether the calling session is an admin of the queried org. */
1085
+ is_admin: boolean;
1086
+ }
1087
+ /** Shallow runtime guard for {@link OrgAdminStatus}. */
1088
+ declare function isOrgAdminStatus(value: unknown): value is OrgAdminStatus;
1089
+ /**
1090
+ * Standard response returned by all policy write and data mutation operations.
1091
+ *
1092
+ * Mirrors the org-data `MutationResponse` wire shape.
1093
+ */
1094
+ interface MutationResponse {
1095
+ /**
1096
+ * `"created"`, `"updated"`, `"deleted"`, or — for the agent-card mutations —
1097
+ * `"published"` / `"unpublished"`.
1098
+ */
1099
+ status: string;
1100
+ /** Hex-encoded entry ID; present on data write/delete operations. */
1101
+ entry_id?: string;
1102
+ /** Whether the target key existed before deletion; present on single-entry deletes. */
1103
+ deleted?: boolean;
1104
+ /** Number of entries removed; present on `org-data-delete-scope`. */
1105
+ deleted_entries?: number;
1106
+ tx_hash: string | null;
1107
+ }
1108
+ /**
1109
+ * Shallow runtime guard for {@link MutationResponse}.
1110
+ *
1111
+ * Only the always-present fields are checked — `status` is mandatory on
1112
+ * every mutation; `tx_hash` is non-optional but nullable. The optional
1113
+ * fields (`entry_id`, `deleted`, `deleted_entries`) are not validated
1114
+ * because their presence depends on which mutation ran.
1115
+ */
1116
+ declare function isMutationResponse(value: unknown): value is MutationResponse;
1117
+ /**
1118
+ * Response type alias for org-writers-get.
1119
+ *
1120
+ * The wire body is `{ writers: string[] }` where each entry is
1121
+ * `did:t3n:<40-hex>`.
1027
1122
  */
1028
- interface AgentAuthPolicy {
1029
- agents: AgentAuthEntry[];
1030
- discoverDids: string[];
1123
+ interface OrgWriters {
1124
+ writers: string[];
1031
1125
  }
1126
+ /** Shallow runtime guard for {@link OrgWriters}. */
1127
+ declare function isOrgWriters(value: unknown): value is OrgWriters;
1032
1128
  /**
1033
- * Parse a full `agent-auth-get` response (the stored snake_case policy
1034
- * document) into the camelCase write shape, including the document-level
1035
- * `discover_dids`. A `null` / absent response is the empty policy.
1129
+ * Response type alias for org-delegation-get.
1130
+ *
1131
+ * The wire body echoes the `contract_id` alongside the grant list.
1036
1132
  */
1037
- declare function parseAgentAuthPolicy(response: unknown): AgentAuthPolicy;
1038
- /** Extract the `agents` array from an `agent-auth-get` response. */
1039
- declare function parseAgentAuthGet(response: unknown): AgentAuthEntry[];
1040
- interface AgentAuthMergeResult {
1041
- /** Full merged `agents` list, ready for `agent-auth-update`. */
1042
- agents: AgentAuthEntry[];
1043
- /** `"<agentDid> → <scriptName>"` rows preserved from the existing policy. */
1133
+ interface OrgContractDelegation {
1134
+ contract_id: string;
1135
+ grants: BoundGrant[];
1136
+ }
1137
+ /**
1138
+ * Shallow runtime guard for {@link OrgContractDelegation}.
1139
+ *
1140
+ * Validates the immediate envelope (`contract_id: string`, `grants:
1141
+ * array`) without recursing into each `BoundGrant`. The Rust contract
1142
+ * is the source of truth for grant element shape; widening the predicate
1143
+ * here would create maintenance churn against benign field additions.
1144
+ */
1145
+ declare function isOrgContractDelegation(value: unknown): value is OrgContractDelegation;
1146
+ /**
1147
+ * One grant inside a role: a capability body (functions + scopes, without the
1148
+ * grantee, which is bound at assignment time) plus the target contract.
1149
+ * Mirrors the org-data `RoleGrant` wire shape.
1150
+ */
1151
+ interface RoleGrant {
1152
+ /** Target contract (canonical name, e.g. `"tee:z-payroll/contracts"`). */
1153
+ contract_id: string;
1154
+ /** WIT function names this grant confers. */
1155
+ functions: string[];
1156
+ /** Data scope paths this grant confers (canonicalised lowercase). */
1157
+ scopes: string[];
1158
+ }
1159
+ /**
1160
+ * A role: a named bundle of grants and/or composed sub-roles.
1161
+ * Mirrors the org-data `RoleDefinition` wire shape.
1162
+ */
1163
+ interface RoleDefinition {
1164
+ /** Org-unique role identifier (slug; function-name grammar). */
1165
+ role_id: string;
1166
+ /** Human-facing label. */
1167
+ label: string;
1168
+ /** Composite: other role ids in the same org whose grants this role confers. */
1169
+ includes: string[];
1170
+ /** Grants this role confers directly. */
1171
+ grants: RoleGrant[];
1172
+ }
1173
+ /**
1174
+ * The roles assigned to one grantee within one org.
1175
+ * Mirrors the org-data `RoleAssignments` wire shape.
1176
+ */
1177
+ interface RoleAssignments {
1178
+ /** Assigned role ids. */
1179
+ roles: string[];
1180
+ }
1181
+ /** Response for `org-role-get`; `role` is `null` when the id is unknown. */
1182
+ interface RoleGetResponse {
1183
+ role: RoleDefinition | null;
1184
+ }
1185
+ /** Shallow runtime guard for {@link RoleGetResponse}. */
1186
+ declare function isRoleGetResponse(value: unknown): value is RoleGetResponse;
1187
+ /**
1188
+ * One org-owned agent's outbound host allow-list for a single contract.
1189
+ *
1190
+ * Egress only — it carries no data scopes by construction, so it can never be
1191
+ * a second path to org data (that stays with `org-delegation-set`).
1192
+ */
1193
+ interface AgentEgressEntry {
1194
+ contract_id: string;
1195
+ /** Bare lowercase hostnames, matched exactly by the node. */
1196
+ allowed_hosts: string[];
1197
+ /** WIT functions covered; `["*"]` means all of them. */
1198
+ functions: string[];
1199
+ /** Present only when the allow-list is pinned to a version range. */
1200
+ version_req?: string;
1201
+ }
1202
+ /**
1203
+ * Response for `org-agent-egress-get`; `egress` is `null` when the agent holds
1204
+ * no egress entry for the requested contract.
1205
+ */
1206
+ interface AgentEgressGetResponse {
1207
+ egress: AgentEgressEntry | null;
1208
+ }
1209
+ /** Runtime guard for {@link AgentEgressGetResponse}. */
1210
+ declare function isAgentEgressGetResponse(value: unknown): value is AgentEgressGetResponse;
1211
+ /** Response for `org-role-assignments-get`. */
1212
+ interface RoleAssignmentsResponse {
1213
+ /** Echoed back so callers don't need to track which request this answers. */
1214
+ grantee_did: string;
1215
+ /** The grantee's assigned role ids (empty when none). */
1216
+ roles: string[];
1217
+ }
1218
+ /** Shallow runtime guard for {@link RoleAssignmentsResponse}. */
1219
+ declare function isRoleAssignmentsResponse(value: unknown): value is RoleAssignmentsResponse;
1220
+ /**
1221
+ * Input for `listAgents` — the org plus optional pagination. Omit both `cursor`
1222
+ * and `limit` for the first page at the default limit; pass a previous
1223
+ * response's `next_cursor` back as `cursor` to fetch the following page.
1224
+ */
1225
+ interface ListAgentsInput {
1226
+ orgDid: string;
1227
+ /** Opaque cursor from a previous response's `next_cursor`. */
1228
+ cursor?: string;
1229
+ /** Maximum agents to return in this page. */
1230
+ limit?: number;
1231
+ }
1232
+ /**
1233
+ * One org-owned agent in a {@link ListAgentsResponse}: the agent's DID, its
1234
+ * display name, and the number of distinct contracts it can access via a direct
1235
+ * grant. Mirrors the org-data `AgentSummary` wire shape. The name comes from the
1236
+ * agent's private card (falling back to the DID), so the FE no longer needs to
1237
+ * fetch each `public:agent_cards` entry to render the roster.
1238
+ */
1239
+ interface AgentSummary {
1240
+ /** The agent's DID (`did:t3n:<40-hex>`). */
1241
+ did: string;
1242
+ /** The agent's display name, from its private card (DID when unavailable). */
1243
+ name: string;
1244
+ /** Count of distinct contracts the agent holds a direct grant on. */
1245
+ contract_count: number;
1246
+ }
1247
+ /** Response for `org-data-list-agents`. */
1248
+ interface ListAgentsResponse {
1249
+ /** One PAGE of the org's org-owned agents, sorted by DID. */
1250
+ agents: AgentSummary[];
1251
+ /** Opaque cursor for the next page; absent on the last page. */
1252
+ next_cursor?: string;
1253
+ }
1254
+ /** A human member's org role. The closed wire domain of {@link HumanMember}. */
1255
+ type MemberRole = "admin" | "member";
1256
+ /**
1257
+ * Input for `listHumanMembers` — the org plus optional pagination. Omit both
1258
+ * `cursor` and `limit` for the first page at the default limit; pass a previous
1259
+ * response's `next_cursor` back as `cursor` to fetch the following page.
1260
+ */
1261
+ interface ListHumanMembersInput {
1262
+ orgDid: string;
1263
+ /** Opaque cursor from a previous response's `next_cursor`. */
1264
+ cursor?: string;
1265
+ /** Maximum members to return in this page. */
1266
+ limit?: number;
1267
+ }
1268
+ /**
1269
+ * One direct human member: DID plus org role. No profile PII (name/email are
1270
+ * out of scope and owned by `tee:user`). Mirrors the org-data `HumanMember`
1271
+ * wire shape.
1272
+ */
1273
+ interface HumanMember {
1274
+ /** The member's DID (`did:t3n:<40-hex>`). */
1275
+ did: string;
1276
+ /** The member's org role. */
1277
+ role: MemberRole;
1278
+ }
1279
+ /** Response for `org-data-list-human-members`. */
1280
+ interface ListHumanMembersResponse {
1281
+ /** One PAGE of the org's direct human members, sorted by DID. */
1282
+ members: HumanMember[];
1283
+ /** Opaque cursor for the next page; absent on the last page. */
1284
+ next_cursor?: string;
1285
+ }
1286
+ /** Shallow runtime guard for {@link ListHumanMembersResponse}. */
1287
+ declare function isListHumanMembersResponse(value: unknown): value is ListHumanMembersResponse;
1288
+ /** Shallow runtime guard for {@link ListAgentsResponse}. */
1289
+ declare function isListAgentsResponse(value: unknown): value is ListAgentsResponse;
1290
+ /** Response for `org-data-list`. */
1291
+ interface DataListResponse {
1292
+ /** Hex-encoded entry IDs for this page. */
1293
+ entry_ids: string[];
1294
+ /** Offset to pass for the next page. `null` when this is the last page. */
1295
+ next_offset: number | null;
1296
+ /** Total number of entries in the scope (across all pages). */
1297
+ total: number;
1298
+ }
1299
+ /** Shallow runtime guard for {@link DataListResponse}. */
1300
+ declare function isDataListResponse(value: unknown): value is DataListResponse;
1301
+ /** Secret shape discriminator (mirrors the contract `SecretKind`). */
1302
+ type SecretKind = "single_value" | "json";
1303
+ /** Metadata common to every {@link SecretView} entry. */
1304
+ interface SecretViewBase {
1305
+ /** Secret name (the `(org, name)` key tail). */
1306
+ name: string;
1307
+ /** Monotonic version, bumped on each value rotation and ACL edit. */
1308
+ version: number;
1309
+ /** Unix seconds of the most recent write. */
1310
+ updated_at_secs: number;
1311
+ }
1312
+ /**
1313
+ * The redacted per-secret summary `org-secret-list` returns — a discriminated
1314
+ * union on `kind`. The value is NEVER present: a single-value exposes only its
1315
+ * last four characters and a json secret only its sorted top-level field names.
1316
+ */
1317
+ type SecretView = (SecretViewBase & {
1318
+ kind: "single_value";
1319
+ /** Last four characters of the value (whole value when ≤ 4 chars). */
1320
+ last4: string;
1321
+ }) | (SecretViewBase & {
1322
+ kind: "json";
1323
+ /** Sorted top-level object field names (keys only, no values). */
1324
+ field_names: string[];
1325
+ });
1326
+ /** Shallow runtime guard for {@link SecretView}. */
1327
+ declare function isSecretView(value: unknown): value is SecretView;
1328
+ /**
1329
+ * Full secret record returned by `org-secret-get` — the value IS included
1330
+ * (the deliberate read-back path the READ axis exists for), along with all
1331
+ * three ACLs.
1332
+ */
1333
+ interface SecretRecord {
1334
+ name: string;
1335
+ kind: SecretKind;
1336
+ /** The value as text: the scalar for a single-value, canonical JSON object for a json secret. */
1337
+ value: string;
1338
+ version: number;
1339
+ /** READ axis — DIDs allowed to read the value back. */
1340
+ reader_dids: string[];
1341
+ /** READ axis — role ids allowed to read the value back. */
1342
+ reader_roles: string[];
1343
+ /** MANAGE axis — DIDs allowed to rotate the value. */
1344
+ manager_dids: string[];
1345
+ /** MANAGE axis — role ids allowed to rotate the value. */
1346
+ manager_roles: string[];
1347
+ /** USE axis — canonical contract ids allowed to have the value injected. */
1348
+ contract_allowlist: string[];
1349
+ created_at_secs: number;
1350
+ updated_at_secs: number;
1351
+ /** DID of the caller who last wrote the record. */
1352
+ updated_by: string;
1353
+ }
1354
+ /** Shallow runtime guard for {@link SecretRecord}. */
1355
+ declare function isSecretRecord(value: unknown): value is SecretRecord;
1356
+ /** Response for `org-secret-list`: redacted per-kind views, no values. */
1357
+ interface SecretListResponse {
1358
+ secrets: SecretView[];
1359
+ }
1360
+ /** Shallow runtime guard for {@link SecretListResponse}. */
1361
+ declare function isSecretListResponse(value: unknown): value is SecretListResponse;
1362
+ /** Response for `org-data-get`. */
1363
+ interface DataGetResponse {
1364
+ entry_id: string;
1365
+ /** Hex-encoded raw payload bytes. */
1366
+ payload_hex: string;
1367
+ }
1368
+ /** Shallow runtime guard for {@link DataGetResponse}. */
1369
+ declare function isDataGetResponse(value: unknown): value is DataGetResponse;
1370
+ /**
1371
+ * Return shape of `agentCardGet` — composed client-side from the generic
1372
+ * `org-data-get` read of the card's entry (there is no card-specific read
1373
+ * operation on the contract). To check whether a public copy exists, probe
1374
+ * the anonymous `GET /api/agent-card/{did}` endpoint.
1375
+ */
1376
+ interface AgentCardResponse {
1377
+ /** The agent whose card this is (`did:t3n:<40-hex>`). */
1378
+ agent_did: string;
1379
+ /** The stored card JSON body, verbatim. */
1380
+ card: string;
1381
+ }
1382
+ /** Shallow runtime guard for {@link AgentCardResponse}. */
1383
+ declare function isAgentCardResponse(value: unknown): value is AgentCardResponse;
1384
+ /**
1385
+ * Legacy direct-route org-data envelope shape retained for compatibility.
1386
+ *
1387
+ * This mirrors the removed `/api/user-contract/execute` body format from
1388
+ * the transitional transport. New callers should use `OrgDataClient`,
1389
+ * which now dispatches through authenticated `/api/rpc` +
1390
+ * `action.execute` instead.
1391
+ */
1392
+ interface OrgDataActionWire {
1393
+ nonce: string;
1394
+ user_did: string;
1395
+ authenticator_id: string;
1396
+ contract_id: string;
1397
+ function: string;
1398
+ args_hash: string;
1399
+ expires_at_secs: number;
1400
+ signature: string;
1401
+ }
1402
+
1403
+ /**
1404
+ * Delegation grants — the standing on-chain authority a member delegates to
1405
+ * a delegatee (envelope-free authorisation).
1406
+ *
1407
+ * The document is one flat list of {@link BoundGrant} rows plus the
1408
+ * document-level discovery grants: `{ grants, discover_dids }`. Each grant's
1409
+ * `grantee` is the delegatee DID it authorises, so there is no per-delegatee
1410
+ * grouping — a member's whole delegation surface is the single `grants` array.
1411
+ * Reads (`member-delegation-get`) and writes (`member-delegation-update`) on
1412
+ * `tee:authorisations/contracts` (the policy's owning contract) are
1413
+ * **SelfOnly**: only the member, authenticated as themselves, may read or write
1414
+ * their own grants. This is the user-approval proof the per-call delegation
1415
+ * credential's `user_sig` used to carry.
1416
+ *
1417
+ * A grant carries `functions`, the agent's delegated org-data `scopes`, the
1418
+ * direct-enumerable `read_scopes`, egress `allowed_hosts`, an optional semver
1419
+ * `version_req`, and an optional validity `window`. The ≤ cap *length* check is
1420
+ * enforced contract-side at write time; the expiry gate is host-side at read
1421
+ * time.
1422
+ *
1423
+ * The SDK is a literal snake_case mirror of the wire: {@link BoundGrant} IS the
1424
+ * wire grant shape, so reads and writes pass through untouched — there is no
1425
+ * casing transform. The only glue here is the read-merge-write helper
1426
+ * ({@link mergeGrants}) that lets a single-grant write preserve every other row
1427
+ * (the contract has no per-field merge; the document IS the new state).
1428
+ */
1429
+
1430
+ /**
1431
+ * The full delegation policy document — the shape of BOTH the `member-delegation-get`
1432
+ * output and the `member-delegation-update` input (they are identical). A flat list of
1433
+ * grant rows plus the document-level discovery grants; mirrors the contract
1434
+ * `MemberDelegationDoc` wire shape verbatim (snake_case).
1435
+ *
1436
+ * `discover_dids` is the list of DIDs the member lets their registered agents
1437
+ * *enumerate the contracts of* via `listContracts`: an org DID grants org-mode
1438
+ * discovery, the member's own DID grants self-mode discovery. It lives at
1439
+ * document level — not on a grant — because discovery must surface contracts the
1440
+ * agent cannot yet call. The node's discovery gate additionally requires the
1441
+ * calling agent to be the `grantee` of at least one grant (subject binding), so
1442
+ * an unregistered agent discovers nothing regardless of this list.
1443
+ *
1444
+ * The document IS the new state on a write: an empty `grants` list revokes all
1445
+ * delegated access, and an empty `discover_dids` persists an empty
1446
+ * discovery-grant list (there is no per-field merge). Use {@link mergeGrants} /
1447
+ * {@link mergeDiscoverDids} to read-merge-write a single grant without dropping
1448
+ * the rest.
1449
+ */
1450
+ interface MemberDelegationDoc {
1451
+ /** Every standing delegation-edge grant, each keyed by its `grantee` DID. */
1452
+ grants: BoundGrant[];
1453
+ /** Document-level discovery grants (`did:t3n:<40-hex>` entries). */
1454
+ discover_dids: string[];
1455
+ }
1456
+ /**
1457
+ * Decode a `member-delegation-get` response into a {@link MemberDelegationDoc}. The wire is
1458
+ * already snake_case, so grant rows pass through unchanged — this only defaults
1459
+ * a `null` / absent response (the empty policy) and a missing field to an empty
1460
+ * list. NOT a casing transform.
1461
+ */
1462
+ declare function parseMemberDelegationDoc(response: unknown): MemberDelegationDoc;
1463
+ interface GrantsMergeResult {
1464
+ /** Full merged grant list, ready for `member-delegation-update`. */
1465
+ grants: BoundGrant[];
1466
+ /** `"<grantee> → <contract_id>"` rows preserved from the existing policy. */
1044
1467
  preservedRows: string[];
1045
1468
  }
1046
- /** Input to the full-document write {@link T3nClient.agentAuthUpdate}. The
1047
- * document IS the new state: an empty `agents` list revokes all agent
1048
- * access, and an omitted / empty `discoverDids` persists an empty
1049
- * discovery-grant list (the contract has no per-field merge). Mirrors the
1050
- * contract `AgentAuthPolicy`. */
1051
- interface AgentAuthUpdateInput {
1052
- agents: AgentAuthEntry[];
1053
- /** Document-level discovery grants — see {@link AgentAuthPolicy}. */
1054
- discoverDids?: string[];
1055
- }
1056
- /**
1057
- * Serialise a camelCase policy document to the contract's canonical
1058
- * snake_case `agent-auth-update` wire (`agent_did` / `script_name` /
1059
- * `version_req` / `read_scopes` / `valid_from_secs` / `valid_until_secs` /
1060
- * `allowed_hosts` / `discover_dids`), so neither write path relies on the
1061
- * contract's compatibility aliases. Absent optionals are omitted (never
1062
- * sent as `null`); empty `scopes` / `read_scopes` are omitted (the
1063
- * contract defaults both to empty). `functions` and `allowed_hosts` are
1064
- * always emitted — the contract requires explicit functions (`["*"]` =
1065
- * all) and reads an absent `allowed_hosts` as deny-all egress. The
1066
- * document-level `discover_dids` (strictly snake_case — the contract
1067
- * defines no camelCase alias for it) is emitted only when non-empty; the
1068
- * contract defaults an absent list to empty.
1069
- */
1070
- declare function toAgentAuthUpdateWire(agents: AgentAuthEntry[], discoverDids?: string[]): {
1071
- agents: Array<{
1072
- agent_did: string;
1073
- scripts: Array<Record<string, unknown>>;
1074
- }>;
1075
- discover_dids?: string[];
1076
- };
1077
1469
  /**
1078
- * Order-preserving deduplicating union of discovery-grant DID lists —
1079
- * the read-merge-write counterpart of {@link mergeAgentAuthEntries} for
1080
- * the document-level `discoverDids` (the contract rejects duplicate
1081
- * entries, so the union must dedupe).
1470
+ * Merge new grant rows into the existing flat list with `(grantee, contract_id)`
1471
+ * union semantics: an existing row whose `(grantee, contract_id)` matches a new
1472
+ * row is replaced; every other existing row is preserved (and reported in
1473
+ * `preservedRows` as an audit aid). New rows for a `(grantee, contract_id)` not
1474
+ * already present are appended.
1082
1475
  */
1083
- declare function mergeDiscoverDids(existing: string[], additions: string[]): string[];
1476
+ declare function mergeGrants(existing: BoundGrant[], additions: BoundGrant[]): GrantsMergeResult;
1084
1477
  /**
1085
- * Merge new agent entries into the existing policy with script-level union
1086
- * semantics: for an agent DID present on both sides, script rows whose
1087
- * `scriptName` is not being written are preserved; rows with a matching
1088
- * `scriptName` are replaced by the new grant. Entries for other agent DIDs
1089
- * pass through unchanged.
1478
+ * Order-preserving deduplicating union of discovery-grant DID lists — the
1479
+ * read-merge-write counterpart of {@link mergeGrants} for the document-level
1480
+ * `discover_dids` (the contract rejects duplicate entries, so the union must
1481
+ * dedupe).
1090
1482
  */
1091
- declare function mergeAgentAuthEntries(existing: AgentAuthEntry[], newEntries: AgentAuthEntry[]): AgentAuthMergeResult;
1483
+ declare function mergeDiscoverDids(existing: string[], additions: string[]): string[];
1092
1484
 
1093
1485
  /**
1094
1486
  * KYC types for the `tee:user/contracts::kyc-status` short-poll
@@ -1638,7 +2030,7 @@ interface AuditPage {
1638
2030
  * Request shape for {@link T3nClient.getAuditEvents} — all fields
1639
2031
  * optional. Omit `pii_did` to read your own trail (all actors); set it to
1640
2032
  * another user's DID to read, as a delegated agent, the events you
1641
- * performed for them — admitted only while that user's agent-auth grant
2033
+ * performed for them — admitted only while that user's delegation grant
1642
2034
  * to you is live. `cursor` is the `next_cursor` from a prior page.
1643
2035
  */
1644
2036
  interface GetAuditEventsOptions {
@@ -1816,7 +2208,7 @@ interface ListContractsResult {
1816
2208
  next_offset: number | null;
1817
2209
  }
1818
2210
  /** Which standing grant a satisfied/missing entry refers to. */
1819
- type DelegationGrantKind = "agent_auth" | "user_grant";
2211
+ type DelegationGrantKind = "member_delegation" | "org_delegation";
1820
2212
  /** Params for `delegation.check` (the generic capability read). */
1821
2213
  interface GrantCheckParams {
1822
2214
  /** The target contract whose requirements are checked. */
@@ -1833,22 +2225,128 @@ interface DelegationGrantRef {
1833
2225
  grant: DelegationGrantKind;
1834
2226
  /** The target contract's canonical name. */
1835
2227
  contract: string;
1836
- functions: string[];
1837
- scopes: string[];
2228
+ functions: string[];
2229
+ scopes: string[];
2230
+ }
2231
+ /**
2232
+ * Response for `delegation.check`: the `member_delegation ∩ org_delegation` verdict.
2233
+ *
2234
+ * `disclosed` is `true` only when the agent is registered under `pii_did`, so
2235
+ * org-side status was safe to disclose; `false` yields the uniform,
2236
+ * non-disclosive verdict (`authorised:false, satisfied:[], missing:[]`) that is
2237
+ * byte-invariant to the requested capability (R5 anti-enumeration).
2238
+ */
2239
+ interface GrantCheckResult {
2240
+ authorised: boolean;
2241
+ disclosed: boolean;
2242
+ satisfied: DelegationGrantRef[];
2243
+ missing: DelegationGrantRef[];
2244
+ }
2245
+ /** Response for the `whoami` operation: who the key resolves to, and where. */
2246
+ interface WhoamiResult {
2247
+ /** The DID the relayed api key resolves to. */
2248
+ did: string;
2249
+ /**
2250
+ * The org DIDs the agent itself belongs to (its own agent-keyed membership),
2251
+ * or `[]` when it belongs to none. Each is a valid `org_did` for
2252
+ * `contracts.list` scope `"org"`, so this is the seed for browsing the agent's
2253
+ * own orgs.
2254
+ */
2255
+ organisations: string[];
2256
+ /**
2257
+ * The agent's owning / managing DID — usually the org that created it. `null`
2258
+ * for a missing record (agents created without a hosted card or agent URI have
2259
+ * no registry record), a record with no owner link, or a malformed record
2260
+ * (decode failure is logged at `WARN`, never a silent authority downgrade); a
2261
+ * snapshot read failure is surfaced as an error, not reported as `null`. The
2262
+ * owner link is mutable and may have changed since creation, so treat this as
2263
+ * best-effort, not an authority.
2264
+ */
2265
+ owner: string | null;
2266
+ }
2267
+ /** Params for the `describe.contract` operation. */
2268
+ interface DescribeContractParams {
2269
+ /**
2270
+ * Registry name: `tee:<name>/contracts` (core) or `z:<tid>:<tail>` (tenant).
2271
+ * The bare core form `contracts.list` presents (`tee:<name>` / `y:<name>`) is
2272
+ * also accepted — the node maps it onto the `/contracts` registry key — so a
2273
+ * `ListedContract.name` feeds straight in.
2274
+ */
2275
+ contract: string;
2276
+ /** Explicit version; omitted resolves the current registered version. */
2277
+ version?: string;
2278
+ }
2279
+ /** Params for the `describe.function` operation. */
2280
+ interface DescribeFunctionParams {
2281
+ /**
2282
+ * Registry name: `tee:<name>/contracts` (core) or `z:<tid>:<tail>` (tenant).
2283
+ * The bare core form `contracts.list` presents (`tee:<name>` / `y:<name>`) is
2284
+ * also accepted — the node maps it onto the `/contracts` registry key.
2285
+ */
2286
+ contract: string;
2287
+ /** The single function to project from the contract's descriptor. */
2288
+ function: string;
2289
+ /** Explicit version; omitted resolves the current registered version. */
2290
+ version?: string;
1838
2291
  }
1839
2292
  /**
1840
- * Response for `delegation.check`: the `agent_auth ∩ UserGrant` verdict.
2293
+ * One function's descriptor entry — the `describe.function` result and the
2294
+ * element type of a {@link ContractDescriptorDocument}'s `functions` array.
1841
2295
  *
1842
- * `disclosed` is `true` only when the agent is registered under `pii_did`, so
1843
- * org-side status was safe to disclose; `false` yields the uniform,
1844
- * non-disclosive verdict (`authorised:false, satisfied:[], missing:[]`) that is
1845
- * byte-invariant to the requested capability (R5 anti-enumeration).
2296
+ * Left open-ended: the descriptor document's full schema (argument schema,
2297
+ * wire projection, auth requirements) is owned by the contract descriptor
2298
+ * registry and served verbatim by the node. The named fields are the ones the
2299
+ * node's descriptor path always presents.
1846
2300
  */
1847
- interface GrantCheckResult {
1848
- authorised: boolean;
1849
- disclosed: boolean;
1850
- satisfied: DelegationGrantRef[];
1851
- missing: DelegationGrantRef[];
2301
+ interface FunctionDescriptorEntry {
2302
+ /** Contract function name (e.g. `compute-payroll`). */
2303
+ name: string;
2304
+ summary?: string;
2305
+ /** Whether the function mutates state. */
2306
+ mutates?: boolean;
2307
+ [key: string]: unknown;
2308
+ }
2309
+ /**
2310
+ * The node's descriptor document for a contract — the `descriptor` field of a
2311
+ * {@link DescribeContractResult}. Open-ended for the same reason as
2312
+ * {@link FunctionDescriptorEntry}: the node returns the registry's descriptor
2313
+ * document verbatim.
2314
+ */
2315
+ interface ContractDescriptorDocument {
2316
+ name?: string;
2317
+ version?: string;
2318
+ summary?: string;
2319
+ tags?: string[];
2320
+ functions?: FunctionDescriptorEntry[];
2321
+ [key: string]: unknown;
2322
+ }
2323
+ /**
2324
+ * Result of the `describe.contract` operation. The node wraps the descriptor
2325
+ * document with the resolved dispatch `version`, so an authorised describe hands
2326
+ * back the exact `scriptVersion` an {@link invoke} call needs alongside the
2327
+ * schema. Returned only on the authorised path; a gate miss or unknown contract
2328
+ * yields the uniform non-disclosive error, never this wrapper.
2329
+ */
2330
+ interface DescribeContractResult {
2331
+ /** The canonical registry name, echoed from the request. */
2332
+ contract: string;
2333
+ /** The resolved dispatch version — pass as `scriptVersion` to `invoke`. */
2334
+ version: string;
2335
+ /** The contract's full descriptor document. */
2336
+ descriptor: ContractDescriptorDocument;
2337
+ }
2338
+ /**
2339
+ * Result of the `describe.function` operation: the resolved dispatch `version`
2340
+ * paired with the single projected function entry. Same authorised-path-only
2341
+ * guarantee as {@link DescribeContractResult}.
2342
+ */
2343
+ interface DescribeFunctionResult {
2344
+ /** The canonical registry name, echoed from the request. */
2345
+ contract: string;
2346
+ /** The resolved dispatch version — pass as `scriptVersion` to `invoke`. */
2347
+ version: string;
2348
+ /** The single projected function's descriptor entry. */
2349
+ descriptor: FunctionDescriptorEntry;
1852
2350
  }
1853
2351
 
1854
2352
  /**
@@ -1867,8 +2365,8 @@ declare class T3nClient {
1867
2365
  /**
1868
2366
  * Resolved node base URL. Snapshotted in the constructor so the
1869
2367
  * typed contract wrappers (`kycStatus`, `getSelfEthAddress`, …)
1870
- * can call `getScriptVersion()` against the same host the
1871
- * transport talks to. Used only by the `script_version: "latest"`
2368
+ * can call `getContractVersion()` against the same host the
2369
+ * transport talks to. Used only by the `contract_version: "latest"`
1872
2370
  * resolution path in {@link executeUserContract}.
1873
2371
  */
1874
2372
  private readonly effectiveBaseUrl;
@@ -2067,7 +2565,7 @@ declare class T3nClient {
2067
2565
  * Generic capability check (`delegation.check`) — the
2068
2566
  * node-backed source for the MCP `checkDelegation` funnel tool.
2069
2567
  *
2070
- * Returns the `agent_auth ∩ UserGrant` verdict for `(agent, contract,
2568
+ * Returns the `member_delegation ∩ org_delegation` verdict for `(agent, contract,
2071
2569
  * pii_did)`: whether the acting agent (resolved from the session) holds the
2072
2570
  * standing grants that `contract`'s `functions` / `scopes` need for member
2073
2571
  * `pii_did`. The org half is vacuous for no-org (Individual-owned) targets,
@@ -2084,7 +2582,7 @@ declare class T3nClient {
2084
2582
  * the caller's own audit trail (every actor). With a `pii_did` set to
2085
2583
  * another user's DID, returns — as a delegated agent — the events the
2086
2584
  * caller performed for that user; admitted ONLY while that user's
2087
- * `agent-auth` grant to the caller is live (revocable). `cursor` is the
2585
+ * `delegation` grant to the caller is live (revocable). `cursor` is the
2088
2586
  * `next_cursor` from a prior page; `limit` clamps server-side.
2089
2587
  *
2090
2588
  * Unlike {@link getUsage}, this runs the SAME session-payload
@@ -2161,7 +2659,7 @@ declare class T3nClient {
2161
2659
  * credits.
2162
2660
  *
2163
2661
  * The returned DID is the org identifier the org-data and payroll
2164
- * surfaces expect (e.g. `OrgDataClient.setGrants({ orgDid, … })`).
2662
+ * surfaces expect (e.g. `OrgDataClient.setDelegation({ orgDid, … })`).
2165
2663
  *
2166
2664
  * @param name - human-readable organisation name (1..=128 bytes)
2167
2665
  * @returns the new organisation's DID (`did:t3n:<40-hex>`)
@@ -2305,14 +2803,14 @@ declare class T3nClient {
2305
2803
  * 1. `user-remove-organisation-attribution` — drop the membership edge
2306
2804
  * (org-admin gated; idempotent on an already-absent membership). The host
2307
2805
  * membership gate makes the detach effective immediately.
2308
- * 2. `org-remove-member-grants` — sweep the member from the org's
2309
- * per-contract `UserGrant` lists, so the capability does not silently
2806
+ * 2. `org-remove-member-delegation` — sweep the member from the org's
2807
+ * per-contract `BoundGrant` lists, so the capability does not silently
2310
2808
  * reactivate if the member later rejoins.
2311
2809
  *
2312
- * The member's `agent_auth` delegations are self-scoped (`AGENT_AUTH_MAP` is a
2313
- * per-user document an admin cannot reach), so this cannot sweep them; the host
2314
- * membership gate denies them regardless, and the member's own session can run
2315
- * {@link revokeAgentAuthForOrg} for full cleanup.
2810
+ * The member's delegations are self-scoped (the delegation edge in
2811
+ * `ROLE_ASSIGNMENTS_MAP` is a per-user document an admin cannot reach), so this
2812
+ * cannot sweep them; the host membership gate denies them regardless, and the
2813
+ * member's own session can run {@link revokeMemberDelegationForOrg} for full cleanup.
2316
2814
  *
2317
2815
  * @param orgDid - the organisation
2318
2816
  * @param userDid - the member to detach
@@ -2326,9 +2824,9 @@ declare class T3nClient {
2326
2824
  * target — the contract's self-leave branch (`caller == target`) admits it
2327
2825
  * without org-admin rights. The host membership gate makes the detach
2328
2826
  * effective immediately.
2329
- * 2. `org-remove-member-grants` — sweep the caller's own grants for the org
2827
+ * 2. `org-remove-member-delegation` — sweep the caller's own grants for the org
2330
2828
  * (the self-revocation branch, `caller == member`).
2331
- * 3. `agent-auth-revoke-org` — drop the caller's own org-scoped agent
2829
+ * 3. `member-delegation-revoke-org` — drop the caller's own org-scoped
2332
2830
  * delegations.
2333
2831
  *
2334
2832
  * Steps 2–3 leave no stale capability rows that would reactivate on a rejoin.
@@ -2337,40 +2835,42 @@ declare class T3nClient {
2337
2835
  */
2338
2836
  leaveOrganisation(orgDid: string): Promise<void>;
2339
2837
  /**
2340
- * Revoke the caller's own agent delegations scoped to one org
2341
- * (detach-cascade `agent_auth` half). Dispatches
2342
- * `agent-auth-revoke-org` on `tee:user/contracts` (**SelfOnly**): every
2343
- * `ScriptGrant` targeting a `z:<orgTid>:*` contract is removed from the
2344
- * caller's own agent-auth document.
2838
+ * Revoke the caller's own delegations scoped to one org (detach-cascade
2839
+ * `delegation` half). Dispatches `member-delegation-revoke-org` on
2840
+ * `tee:user/contracts` (**SelfOnly**): every delegation-edge grant targeting a
2841
+ * `z:<orgTid>:*` contract is removed from the caller's own delegation
2842
+ * document.
2345
2843
  *
2346
2844
  * @param orgTid - the org's z-space tenant id (`did:t3n:<hex>` or bare
2347
2845
  * 40-hex) — i.e. the `<tid>` in the org's `z:<tid>:…` contract names
2348
2846
  */
2349
- revokeAgentAuthForOrg(orgTid: string): Promise<void>;
2847
+ revokeMemberDelegationForOrg(orgTid: string): Promise<void>;
2350
2848
  /**
2351
- * Read the authenticated user's own agent-auth policy — the standing
2352
- * grants delegated to agents. Dispatches `agent-auth-get` on
2849
+ * Read the authenticated user's own delegation policy — the standing
2850
+ * grants delegated to agents. Dispatches `member-delegation-get` on
2353
2851
  * `tee:authorisations/contracts` (the policy's owning contract), which is
2354
2852
  * **SelfOnly**, so this always returns the caller's own
2355
- * `AGENT_AUTH_MAP[self]` document.
2853
+ * delegation edge in `ROLE_ASSIGNMENTS_MAP`.
2356
2854
  *
2357
- * @returns the full policy document (normalised to the camelCase write
2358
- * shape): the per-agent `agents` entries plus the document-level
2359
- * `discoverDids` discovery grants
2855
+ * @returns the full policy document as the flat snake_case wire shape: the
2856
+ * `grants` list (each row's `grantee` is the authorised delegatee DID) plus
2857
+ * the document-level `discover_dids` discovery grants
2360
2858
  * @throws if the session is not authenticated, or the contract refuses
2361
2859
  */
2362
- getAgentAuth(): Promise<AgentAuthPolicy>;
2860
+ getMemberDelegation(): Promise<MemberDelegationDoc>;
2363
2861
  /**
2364
- * Authorise an agent for one contract on the caller's own behalf
2862
+ * Authorise a delegatee for one contract on the caller's own behalf
2365
2863
  * (envelope-free authorisation). Read-merge-writes the
2366
- * caller's `AGENT_AUTH_MAP[self]` document via `agent-auth-update`
2367
- * (**SelfOnly**) with script-level union semantics, so other contracts'
2368
- * grants for this or any agent survive untouched.
2864
+ * caller's delegation edge in `ROLE_ASSIGNMENTS_MAP` via `member-delegation-update`
2865
+ * (**SelfOnly**) with `(grantee, contract_id)` union semantics, so other
2866
+ * contracts' grants for this or any delegatee survive untouched.
2369
2867
  *
2370
- * Carries the new `scopes` + validity fields: the delegated
2371
- * org-data scopes and an optional `[validFromSecs, validUntilSecs]`
2372
- * window. The ≤ cap *length* check is enforced contract-side at write
2373
- * time; the expiry gate is host-side at read time.
2868
+ * The grant is the flat wire {@link BoundGrant}: its `grantee` is the delegatee
2869
+ * DID being authorised, and it carries `functions`, the delegated org-data
2870
+ * `scopes`, direct-read `read_scopes`, egress `allowed_hosts`, an optional
2871
+ * semver `version_req`, and an optional validity `window`. The ≤ cap *length*
2872
+ * check is enforced contract-side at write time; the expiry gate is host-side
2873
+ * at read time.
2374
2874
  *
2375
2875
  * This is the write surface `getDelegationInstructions` produces the
2376
2876
  * parameters for. The caller MUST be the delegating user, authenticated as
@@ -2382,38 +2882,38 @@ declare class T3nClient {
2382
2882
  * standing discovery), and any `options.discoverDids` are unioned in
2383
2883
  * (order-preserving, deduplicated).
2384
2884
  *
2385
- * @param agentDid - the agent DID being authorised
2386
- * @param grant - the single script grant to set (contract, functions,
2387
- * scopes, validity, egress hosts)
2885
+ * @param grant - the single grant to set — a {@link BoundGrant} whose
2886
+ * `grantee` is the delegatee DID being authorised (contract_id, functions,
2887
+ * scopes, window, egress hosts)
2388
2888
  * @param options - optional `discoverDids` to union into the document's
2389
2889
  * discovery grants (org DIDs for org-mode `listContracts`, the caller's
2390
2890
  * own DID for self mode)
2391
- * @returns the script rows preserved from the existing policy (audit aid)
2891
+ * @returns the grant rows preserved from the existing policy (audit aid)
2392
2892
  * @throws if the session is not authenticated, or the contract refuses
2393
2893
  */
2394
- updateAgentAuth(agentDid: string, grant: AgentAuthScriptGrant, options?: {
2894
+ updateMemberDelegation(grant: BoundGrant, options?: {
2395
2895
  discoverDids?: string[];
2396
2896
  }): Promise<{
2397
2897
  preservedRows: string[];
2398
2898
  }>;
2399
2899
  /**
2400
2900
  * Build the canonical `ExecuteActionRequest` shape the server
2401
- * expects (`script_name`, `script_version`, `function_name`, `input`,
2901
+ * expects (`contract_id`, `contract_version`, `function_name`, `input`,
2402
2902
  * optional `pii_did`) and dispatch it through {@link execute}.
2403
2903
  *
2404
2904
  * Two pieces of glue live here that every typed user-contract
2405
2905
  * wrapper would otherwise duplicate:
2406
2906
  *
2407
2907
  * 1. **Field naming.** The server deserialises strictly into
2408
- * `script_name` / `script_version` / `function_name` —
2908
+ * `contract_id` / `contract_version` / `function_name` —
2409
2909
  * sending `contract` / `version` / `function` produces
2410
2910
  * `Invalid action request: missing field …` 400s. Centralising
2411
2911
  * the names here means every wrapper agrees with the server.
2412
- * 2. **`"latest"` resolution.** `script_version` is `SemVer` on
2912
+ * 2. **`"latest"` resolution.** `contract_version` is `SemVer` on
2413
2913
  * the server, so a literal `"latest"` cannot be parsed. We
2414
2914
  * fetch the registered current version via
2415
2915
  * `GET /api/contracts/current?name=…` (cached per script name
2416
- * in `getScriptVersion`) and forward the resolved
2916
+ * in `getContractVersion`) and forward the resolved
2417
2917
  * `MAJOR.MINOR.PATCH` string.
2418
2918
  *
2419
2919
  * Wrappers that need PII delegation can extend this helper
@@ -2423,8 +2923,8 @@ declare class T3nClient {
2423
2923
  private executeUserContract;
2424
2924
  /**
2425
2925
  * Same glue as {@link executeUserContract}, parameterised over the
2426
- * target system contract — the agent-auth wrappers dispatch on
2427
- * `tee:authorisations/contracts` (the authorisation policy's owning
2926
+ * target system contract — the delegation wrappers dispatch on
2927
+ * `tee:authorisations/contracts` (the delegation policy's owning
2428
2928
  * contract) while the rest of the user-contract surface stays on
2429
2929
  * `tee:user/contracts`.
2430
2930
  */
@@ -2678,25 +3178,24 @@ declare class T3nClient {
2678
3178
  */
2679
3179
  submitUserInput(input: SubmitUserInputArgs): Promise<SubmitUserInputResult>;
2680
3180
  /**
2681
- * Replace this user's agent-authorisation policy (`tee:user/contracts` →
2682
- * `agent-auth-update`). The supplied document IS the new state: an empty
2683
- * `agents` array revokes all agent access, and an omitted `discoverDids`
3181
+ * Replace this user's delegation policy (`tee:authorisations/contracts`
3182
+ * → `member-delegation-update`). The supplied document IS the new state: an empty
3183
+ * `grants` array revokes all delegated access, and an empty `discover_dids`
2684
3184
  * persists an empty discovery-grant list. This is the full-document
2685
- * write — use {@link T3nClient.updateAgentAuth} for the single-grant
3185
+ * write — use {@link T3nClient.updateMemberDelegation} for the single-grant
2686
3186
  * read-merge-write that preserves other contracts' grants and the
2687
3187
  * standing discovery grants.
2688
3188
  *
2689
- * Typed wrapper over the raw contract call: callers pass camelCase input;
2690
- * the SDK emits the canonical snake_case wire via
2691
- * {@link toAgentAuthUpdateWire} (carrying `scopes` / `read_scopes` /
2692
- * validity alongside `functions` / `allowed_hosts`, plus the
2693
- * document-level `discover_dids`), so it does not rely on the contract's
2694
- * compatibility aliases.
3189
+ * The {@link MemberDelegationDoc} IS the snake_case wire shape — grant rows are
3190
+ * {@link BoundGrant} verbatim — so the document passes straight through with
3191
+ * no casing transform. Absent per-grant qualifiers (`version_req` /
3192
+ * `read_scopes` / `allowed_hosts` / `window`) are simply unset on the object
3193
+ * and so omitted from the JSON.
2695
3194
  *
2696
3195
  * @throws {RpcError} if the contract rejects the policy (validation failure,
2697
- * too many agents/grants).
3196
+ * too many delegatees/grants).
2698
3197
  */
2699
- agentAuthUpdate(input: AgentAuthUpdateInput): Promise<void>;
3198
+ memberDelegationUpdate(input: MemberDelegationDoc): Promise<void>;
2700
3199
  /**
2701
3200
  * Convenience helper: run the explicit OTP roundtrip and submit
2702
3201
  * the slim user-upsert in one call.
@@ -2993,7 +3492,21 @@ declare function createDefaultHandlers(baseUrl: string, trustAnchor: TrustAnchor
2993
3492
  * component loader, or any handshake/session machinery — `invoke` is
2994
3493
  * a single fetch, nothing else.
2995
3494
  *
2996
- * ### HTTPS guard (CodeRabbit T2)
3495
+ * ### Keyed discovery transports
3496
+ * Alongside `invoke` (which acts), this module exports the keyed **discovery**
3497
+ * reads — {@link discoverWhoami}, {@link discoverListContracts},
3498
+ * {@link discoverCheckDelegation}, {@link discoverDescribeContract},
3499
+ * {@link discoverDescribeFunction}. They are the api-key counterpart of the
3500
+ * session `T3nClient.listContracts` / `checkDelegation` reads: each POSTs a
3501
+ * `{ method, params }` envelope to the node's `POST /api/discover` with the
3502
+ * same `X-T3N-Api-Key` header, HTTPS guard, timeout, and key-safe error
3503
+ * hygiene as `invoke`, and returns the node's raw JSON result. The session
3504
+ * `T3nClient` methods are untouched — these live beside `invoke`, off the
3505
+ * session client, so the relay reads never open a session. Every transport
3506
+ * shares the {@link postKeyed} core, so there is one implementation of the
3507
+ * secure-transport + secret-hygiene rules below, not two.
3508
+ *
3509
+ * ### HTTPS guard
2997
3510
  * The API key is a long-lived bearer credential relayed in a plain header,
2998
3511
  * so `invoke` refuses to send it over an insecure transport: `baseUrl`
2999
3512
  * must be `https:`, unless the host is a local-dev loopback
@@ -3001,7 +3514,7 @@ declare function createDefaultHandlers(baseUrl: string, trustAnchor: TrustAnchor
3001
3514
  * allowed. The check runs before any network activity — an insecure
3002
3515
  * `baseUrl` never gets as far as a `fetch` call.
3003
3516
  *
3004
- * ### Error hygiene (CodeRabbit T3/T4/T5)
3517
+ * ### Error hygiene
3005
3518
  * Every error `invoke` throws is a fixed, generic
3006
3519
  * {@link InvokeError} message — the response body text, the
3007
3520
  * underlying network error's message, and the api key are never
@@ -3019,13 +3532,13 @@ declare function createDefaultHandlers(baseUrl: string, trustAnchor: TrustAnchor
3019
3532
  * server-side `ExecuteActionRequest`, the same shape
3020
3533
  * `T3nClient`'s `execute*` wrappers build for the session `action.execute`
3021
3534
  * RPC. Field names are load-bearing: the server deserialises strictly into
3022
- * `script_name` / `script_version` / `function_name` (see
3535
+ * `contract_id` / `contract_version` / `function_name` (see
3023
3536
  * `T3nClient.executeSystemContract`'s doc comment) — `contract` / `version`
3024
3537
  * / `function` produce a 400.
3025
3538
  */
3026
3539
  interface InvokeRequest {
3027
- script_name: string;
3028
- script_version: string;
3540
+ contract_id: string;
3541
+ contract_version: string;
3029
3542
  function_name: string;
3030
3543
  /** Delegated-call target member; omitted for a self (non-delegated) call. */
3031
3544
  pii_did?: string;
@@ -3060,7 +3573,7 @@ interface InvokeOptions {
3060
3573
  *
3061
3574
  * The message is always one of a small set of fixed, generic strings — it
3062
3575
  * NEVER contains the raw api key, the response body text, or the
3063
- * underlying network error's message (CodeRabbit T4/T5): a server (or a
3576
+ * underlying network error's message: a server (or a
3064
3577
  * misbehaving intermediary) that echoes the key or other secrets back in
3065
3578
  * an error body must not be able to leak them through this error's
3066
3579
  * message.
@@ -3070,461 +3583,124 @@ declare class InvokeError extends T3nError {
3070
3583
  constructor(message: string, status?: number | undefined);
3071
3584
  }
3072
3585
  /**
3073
- * Execute a `z:` contract as an org agent, authenticating with an opaque
3074
- * API key — one request, no handshake, no session.
3075
- *
3076
- * @param opts - baseUrl, apiKey, and the wire request to execute
3077
- * @param schema - optional validator applied to the decoded result (e.g. a
3078
- * zod schema); anything exposing `.parse(value)` is accepted, same as
3079
- * {@link T3nClient.executeAndDecode}
3080
- * @returns the contract's decoded result, typed as `T`
3081
- * @throws {InvokeError} if `baseUrl` is insecure, on a network
3082
- * failure/timeout, or on a non-2xx response
3083
- * @throws {ContractResponseError} if the node returns a 2xx with a body
3084
- * that is not valid JSON
3085
- */
3086
- declare function invoke<T = unknown>(opts: InvokeOptions, schema?: ContractResponseSchema<T>): Promise<T>;
3087
-
3088
- /**
3089
- * Token fixed-point units (USDT-style 6 decimals).
3090
- *
3091
- * As of `tee:*` metering v2, every token amount on the wire —
3092
- * {@link BalanceRow}'s `available`/`reserved`, {@link UsageEntry.amount},
3093
- * and `total_supply` — is denominated in **base units**, where
3094
- * `1 T3N token = `{@link BASE_UNITS_PER_TOKEN}` base units`. The node
3095
- * meters the *actual* fractional cost of each operation (pro-rata by
3096
- * bytes / byte-seconds / fuel) down to `1e-6` token, so amounts are
3097
- * raw integers in base units, NOT whole tokens.
3098
- *
3099
- * The wire fields are left as raw base units (no silent rescaling — that
3100
- * would lose precision for large balances and surprise callers doing
3101
- * arithmetic). Use {@link formatTokens} to render a human "tokens"
3102
- * string and {@link toBaseUnits} to convert a token figure back.
3103
- *
3104
- * ⚠️ Breaking vs. the pre-decimals SDK: a balance that used to read `5`
3105
- * (whole tokens) now reads `5_000_000` (base units). Multiply existing
3106
- * display code through {@link formatTokens}.
3107
- */
3108
- /** Decimal places in a T3N token (fixed; mirrors the node constant). */
3109
- declare const TOKEN_DECIMALS = 6;
3110
- /** Base units per whole T3N token — `10 ** TOKEN_DECIMALS`. */
3111
- declare const BASE_UNITS_PER_TOKEN = 1000000;
3112
- /**
3113
- * Render a base-unit amount as a human-readable token string, e.g.
3114
- * `25_920_000 → "25.92"`, `1_000_000 → "1"`, `4768 → "0.004768"`.
3115
- *
3116
- * Trailing-zero fraction digits are trimmed; an integer amount renders
3117
- * with no decimal point. Accepts `number` or `bigint`; for balances
3118
- * above `Number.MAX_SAFE_INTEGER` prefer passing a `bigint`.
3119
- */
3120
- declare function formatTokens(baseUnits: number | bigint): string;
3121
- /**
3122
- * Convert a whole-or-fractional token figure to base units (rounded to
3123
- * the nearest base unit). E.g. `25.92 → 25_920_000`, `1 → 1_000_000`.
3124
- */
3125
- declare function toBaseUnits(tokens: number): number;
3126
-
3127
- /**
3128
- * Org-data wire types mirroring the org-data contract wire shapes.
3129
- *
3130
- * Plain TypeScript interfaces (no zod) — the SDK does not use a
3131
- * validation library for domain types; see the existing `types/` files.
3132
- *
3133
- * Each response type below is paired with a shallow runtime predicate
3134
- * (`isMutationResponse`, `isOrgPolicyMeta`, etc.) so the org-data client
3135
- * can `assertShape` the decoded payload before returning to callers.
3136
- * Predicates check the top-level structure only; nested elements
3137
- * (e.g. each `UserGrant` inside `OrgContractGrants.grants`) are not
3138
- * deeply validated — see `utils/shape.ts` for the rationale.
3139
- *
3140
- * Reference: the org-data wire contract.
3141
- */
3142
- /**
3143
- * Capability grant stored under `ORG_CONTRACT_GRANTS_MAP`.
3144
- *
3145
- * Mirrors the org-data `UserGrant` wire shape.
3146
- */
3147
- interface UserGrant {
3148
- /** The user this grant applies to (`did:t3n:<40-hex>`). */
3149
- user_did: string;
3150
- /** WIT function names the user may invoke (e.g. `"set-records"`). */
3151
- functions: string[];
3152
- /** Data scope paths the user may access (e.g. `"example/records"`). */
3153
- scopes: string[];
3154
- }
3155
- /**
3156
- * Policy record for an organisation's data tier.
3157
- *
3158
- * Mirrors the org-data policy-meta wire shape.
3159
- */
3160
- interface OrgPolicyMeta {
3161
- /** DIDs (`did:t3n:<40-hex>`) of users authorised to manage policy and read data. */
3162
- admins: string[];
3163
- /** Maximum number of admins allowed for this org. */
3164
- max_admins: number;
3165
- /** Unix timestamp (secs) when the policy was first created. */
3166
- created_at_secs: number;
3167
- /** Unix timestamp (secs) of the most recent policy update. */
3168
- updated_at_secs: number;
3169
- /**
3170
- * Per-org ceiling on delegation-credential validity (seconds).
3171
- *
3172
- * Absent when no org-level cap is set — the contract omits the field
3173
- * (never serialises null) and the cluster-wide
3174
- * `delegation.max_credential_validity_secs` governs instead. When set,
3175
- * the effective cap is `min(max_credential_validity_secs, cluster_ceiling)`.
3176
- */
3177
- max_credential_validity_secs?: number;
3178
- }
3179
- /** Shallow runtime guard for {@link OrgPolicyMeta}. */
3180
- declare function isOrgPolicyMeta(value: unknown): value is OrgPolicyMeta;
3181
- /**
3182
- * Effective org policy view returned by `org-policy-view`.
3183
- *
3184
- * Readable by any authenticated session (non-sensitive metadata).
3185
- * Returns the **effective** credential validity cap:
3186
- * `min(org.max_credential_validity_secs, cluster_ceiling)`, equal to the
3187
- * cluster ceiling when the org has not set a per-org cap. The contract
3188
- * always returns a value (or errors) — the field is never null.
3189
- */
3190
- interface OrgPolicyView {
3191
- /**
3192
- * Effective delegation-credential validity cap in seconds:
3193
- * `min(org value, cluster ceiling)`, equal to the cluster ceiling when the
3194
- * org has not set a per-org cap. Always present — mirrors the contract's
3195
- * `PolicyViewResponse.effective_validity_secs` (org-data `org-policy-view`).
3196
- */
3197
- effective_validity_secs: number;
3198
- }
3199
- /** Shallow runtime guard for {@link OrgPolicyView}. */
3200
- declare function isOrgPolicyView(value: unknown): value is OrgPolicyView;
3201
- /**
3202
- * Caller-scoped admin status returned by `org-am-i-admin`.
3203
- *
3204
- * Reports only whether the **calling** session's DID is in the org's admin
3205
- * list — never the roster itself (contrast {@link OrgPolicyMeta}, returned by
3206
- * the admin-gated `org-policy-get`). Readable by any authenticated session.
3207
- * Mirrors the org-data `AmIAdminResponse` wire shape.
3208
- */
3209
- interface OrgAdminStatus {
3210
- /** Whether the calling session is an admin of the queried org. */
3211
- is_admin: boolean;
3212
- }
3213
- /** Shallow runtime guard for {@link OrgAdminStatus}. */
3214
- declare function isOrgAdminStatus(value: unknown): value is OrgAdminStatus;
3215
- /**
3216
- * Standard response returned by all policy write and data mutation operations.
3217
- *
3218
- * Mirrors the org-data `MutationResponse` wire shape.
3219
- */
3220
- interface MutationResponse {
3221
- /**
3222
- * `"created"`, `"updated"`, `"deleted"`, or — for the agent-card mutations —
3223
- * `"published"` / `"unpublished"`.
3224
- */
3225
- status: string;
3226
- /** Hex-encoded entry ID; present on data write/delete operations. */
3227
- entry_id?: string;
3228
- /** Whether the target key existed before deletion; present on single-entry deletes. */
3229
- deleted?: boolean;
3230
- /** Number of entries removed; present on `org-data-delete-scope`. */
3231
- deleted_entries?: number;
3232
- tx_hash: string | null;
3233
- }
3234
- /**
3235
- * Shallow runtime guard for {@link MutationResponse}.
3236
- *
3237
- * Only the always-present fields are checked — `status` is mandatory on
3238
- * every mutation; `tx_hash` is non-optional but nullable. The optional
3239
- * fields (`entry_id`, `deleted`, `deleted_entries`) are not validated
3240
- * because their presence depends on which mutation ran.
3241
- */
3242
- declare function isMutationResponse(value: unknown): value is MutationResponse;
3243
- /**
3244
- * Response type alias for org-writers-get.
3245
- *
3246
- * The wire body is `{ writers: string[] }` where each entry is
3247
- * `did:t3n:<40-hex>`.
3248
- */
3249
- interface OrgWriters {
3250
- writers: string[];
3251
- }
3252
- /** Shallow runtime guard for {@link OrgWriters}. */
3253
- declare function isOrgWriters(value: unknown): value is OrgWriters;
3254
- /**
3255
- * Response type alias for org-grants-get.
3256
- *
3257
- * The wire body echoes the `contract_id` alongside the grant list.
3258
- */
3259
- interface OrgContractGrants {
3260
- contract_id: string;
3261
- grants: UserGrant[];
3262
- }
3263
- /**
3264
- * Shallow runtime guard for {@link OrgContractGrants}.
3265
- *
3266
- * Validates the immediate envelope (`contract_id: string`, `grants:
3267
- * array`) without recursing into each `UserGrant`. The Rust contract
3268
- * is the source of truth for grant element shape; widening the predicate
3269
- * here would create maintenance churn against benign field additions.
3270
- */
3271
- declare function isOrgContractGrants(value: unknown): value is OrgContractGrants;
3272
- /**
3273
- * One grant inside a role: a {@link UserGrant} body (without the
3274
- * grantee, which is bound at assignment time) plus the target contract.
3275
- * Mirrors the org-data `RoleGrant` wire shape.
3276
- */
3277
- interface RoleGrant {
3278
- /** Target contract (canonical name, e.g. `"tee:z-payroll/contracts"`). */
3279
- contract_id: string;
3280
- /** WIT function names this grant confers. */
3281
- functions: string[];
3282
- /** Data scope paths this grant confers (canonicalised lowercase). */
3283
- scopes: string[];
3284
- }
3285
- /**
3286
- * A role: a named bundle of grants and/or composed sub-roles.
3287
- * Mirrors the org-data `RoleDefinition` wire shape.
3288
- */
3289
- interface RoleDefinition {
3290
- /** Org-unique role identifier (slug; function-name grammar). */
3291
- role_id: string;
3292
- /** Human-facing label. */
3293
- label: string;
3294
- /** Composite: other role ids in the same org whose grants this role confers. */
3295
- includes: string[];
3296
- /** Grants this role confers directly. */
3297
- grants: RoleGrant[];
3298
- }
3299
- /**
3300
- * The roles assigned to one grantee within one org.
3301
- * Mirrors the org-data `RoleAssignments` wire shape.
3302
- */
3303
- interface RoleAssignments {
3304
- /** Assigned role ids. */
3305
- roles: string[];
3306
- }
3307
- /** Response for `org-role-get`; `role` is `null` when the id is unknown. */
3308
- interface RoleGetResponse {
3309
- role: RoleDefinition | null;
3310
- }
3311
- /** Shallow runtime guard for {@link RoleGetResponse}. */
3312
- declare function isRoleGetResponse(value: unknown): value is RoleGetResponse;
3313
- /**
3314
- * One org-owned agent's outbound host allow-list for a single contract.
3586
+ * Execute a `z:` contract as an org agent, authenticating with an opaque
3587
+ * API key — one request, no handshake, no session.
3315
3588
  *
3316
- * Egress only — it carries no data scopes by construction, so it can never be
3317
- * a second path to org data (that stays with `org-policy-set-grants`).
3589
+ * @param opts - baseUrl, apiKey, and the wire request to execute
3590
+ * @param schema - optional validator applied to the decoded result (e.g. a
3591
+ * zod schema); anything exposing `.parse(value)` is accepted, same as
3592
+ * {@link T3nClient.executeAndDecode}
3593
+ * @returns the contract's decoded result, typed as `T`
3594
+ * @throws {InvokeError} if `baseUrl` is insecure, on a network
3595
+ * failure/timeout, or on a non-2xx response
3596
+ * @throws {ContractResponseError} if the node returns a 2xx with a body
3597
+ * that is not valid JSON
3318
3598
  */
3319
- interface AgentEgressEntry {
3320
- contract_id: string;
3321
- /** Bare lowercase hostnames, matched exactly by the node. */
3322
- allowed_hosts: string[];
3323
- /** WIT functions covered; `["*"]` means all of them. */
3324
- functions: string[];
3325
- /** Present only when the allow-list is pinned to a version range. */
3326
- version_req?: string;
3327
- }
3599
+ declare function invoke<T = unknown>(opts: InvokeOptions, schema?: ContractResponseSchema<T>): Promise<T>;
3328
3600
  /**
3329
- * Response for `org-agent-egress-get`; `egress` is `null` when the agent holds
3330
- * no egress entry for the requested contract.
3601
+ * Transport options shared by the keyed discovery reads. Mirrors the transport
3602
+ * half of {@link InvokeOptions} (no `request`; the operation params are the
3603
+ * second argument of each read). Same HTTPS + secret-hygiene rules as `invoke`.
3331
3604
  */
3332
- interface AgentEgressGetResponse {
3333
- egress: AgentEgressEntry | null;
3334
- }
3335
- /** Runtime guard for {@link AgentEgressGetResponse}. */
3336
- declare function isAgentEgressGetResponse(value: unknown): value is AgentEgressGetResponse;
3337
- /** Response for `org-role-assignments-get`. */
3338
- interface RoleAssignmentsResponse {
3339
- /** Echoed back so callers don't need to track which request this answers. */
3340
- grantee_did: string;
3341
- /** The grantee's assigned role ids (empty when none). */
3342
- roles: string[];
3605
+ interface DiscoverOptions {
3606
+ /**
3607
+ * RPC base URL of the T3n node, e.g. `https://node.example.com`. Must be
3608
+ * `https:` unless the host is a local-dev loopback — see
3609
+ * {@link InvokeOptions.baseUrl}.
3610
+ */
3611
+ baseUrl: string;
3612
+ /**
3613
+ * The agent's opaque API key (`t3n_key_<...>`), relayed verbatim in the
3614
+ * `X-T3N-Api-Key` header. Never logged and never interpolated into any
3615
+ * error this module throws.
3616
+ */
3617
+ apiKey: string;
3618
+ /** Fetch timeout in ms. Defaults to 30s, matching {@link invoke}. */
3619
+ timeoutMs?: number;
3343
3620
  }
3344
- /** Shallow runtime guard for {@link RoleAssignmentsResponse}. */
3345
- declare function isRoleAssignmentsResponse(value: unknown): value is RoleAssignmentsResponse;
3346
3621
  /**
3347
- * Input for `listAgents` — the org plus optional pagination. Omit both `cursor`
3348
- * and `limit` for the first page at the default limit; pass a previous
3349
- * response's `next_cursor` back as `cursor` to fetch the following page.
3622
+ * `whoami` — resolve the DID the relayed key maps to. The node never
3623
+ * trusts a caller-supplied DID; this is the relay's sole DID source.
3624
+ *
3625
+ * @throws {InvokeError} if `baseUrl` is insecure, on a network failure/timeout,
3626
+ * or on a non-2xx response
3350
3627
  */
3351
- interface ListAgentsInput {
3352
- orgDid: string;
3353
- /** Opaque cursor from a previous response's `next_cursor`. */
3354
- cursor?: string;
3355
- /** Maximum agents to return in this page. */
3356
- limit?: number;
3357
- }
3628
+ declare function discoverWhoami(opts: DiscoverOptions): Promise<WhoamiResult>;
3358
3629
  /**
3359
- * One org-owned agent in a {@link ListAgentsResponse}: the agent's DID, its
3360
- * display name, and the number of distinct contracts it can access via a direct
3361
- * grant. Mirrors the org-data `AgentSummary` wire shape. The name comes from the
3362
- * agent's private card (falling back to the DID), so the FE no longer needs to
3363
- * fetch each `public:agent_cards` entry to render the roster.
3630
+ * `contracts.list` — the keyed counterpart of {@link T3nClient.listContracts}.
3631
+ * Absent `params` (`{}`) lists the curated `core` contracts; `org` / `self`
3632
+ * scopes are discovery-grant gated server-side (R5 non-disclosive empty page).
3633
+ *
3634
+ * @throws {InvokeError} — see {@link discoverWhoami}
3364
3635
  */
3365
- interface AgentSummary {
3366
- /** The agent's DID (`did:t3n:<40-hex>`). */
3367
- did: string;
3368
- /** The agent's display name, from its private card (DID when unavailable). */
3369
- name: string;
3370
- /** Count of distinct contracts the agent holds a direct grant on. */
3371
- contract_count: number;
3372
- }
3373
- /** Response for `org-data-list-agents`. */
3374
- interface ListAgentsResponse {
3375
- /** One PAGE of the org's org-owned agents, sorted by DID. */
3376
- agents: AgentSummary[];
3377
- /** Opaque cursor for the next page; absent on the last page. */
3378
- next_cursor?: string;
3379
- }
3380
- /** A human member's org role. The closed wire domain of {@link HumanMember}. */
3381
- type MemberRole = "admin" | "member";
3636
+ declare function discoverListContracts(opts: DiscoverOptions, params?: ListContractsParams): Promise<ListContractsResult>;
3382
3637
  /**
3383
- * Input for `listHumanMembers` — the org plus optional pagination. Omit both
3384
- * `cursor` and `limit` for the first page at the default limit; pass a previous
3385
- * response's `next_cursor` back as `cursor` to fetch the following page.
3638
+ * `delegation.check` — the keyed counterpart of
3639
+ * {@link T3nClient.checkDelegation}. Returns the `member_delegation ∩ org_delegation`
3640
+ * verdict for the acting agent (as itself, or for `params.pii_did`).
3641
+ *
3642
+ * @throws {InvokeError} — see {@link discoverWhoami}
3386
3643
  */
3387
- interface ListHumanMembersInput {
3388
- orgDid: string;
3389
- /** Opaque cursor from a previous response's `next_cursor`. */
3390
- cursor?: string;
3391
- /** Maximum members to return in this page. */
3392
- limit?: number;
3393
- }
3644
+ declare function discoverCheckDelegation(opts: DiscoverOptions, params: GrantCheckParams): Promise<GrantCheckResult>;
3394
3645
  /**
3395
- * One direct human member: DID plus org role. No profile PII (name/email are
3396
- * out of scope and owned by `tee:user`). Mirrors the org-data `HumanMember`
3397
- * wire shape.
3646
+ * `describe.contract` — the authority-gated keyed describe read. Returns
3647
+ * `{ contract, version, descriptor }`: the resolved dispatch `version` (the
3648
+ * `scriptVersion` an {@link invoke} call needs) alongside the contract's full
3649
+ * descriptor document. Unlike the session/stdio public descriptor GET, the relay
3650
+ * path is membership-gated on the contract's owning org and returns a uniform
3651
+ * non-disclosive error for both "not found" and "not authorised"
3652
+ * (anti-enumeration).
3653
+ *
3654
+ * @throws {InvokeError} — see {@link discoverWhoami}
3398
3655
  */
3399
- interface HumanMember {
3400
- /** The member's DID (`did:t3n:<40-hex>`). */
3401
- did: string;
3402
- /** The member's org role. */
3403
- role: MemberRole;
3404
- }
3405
- /** Response for `org-data-list-human-members`. */
3406
- interface ListHumanMembersResponse {
3407
- /** One PAGE of the org's direct human members, sorted by DID. */
3408
- members: HumanMember[];
3409
- /** Opaque cursor for the next page; absent on the last page. */
3410
- next_cursor?: string;
3411
- }
3412
- /** Shallow runtime guard for {@link ListHumanMembersResponse}. */
3413
- declare function isListHumanMembersResponse(value: unknown): value is ListHumanMembersResponse;
3414
- /** Shallow runtime guard for {@link ListAgentsResponse}. */
3415
- declare function isListAgentsResponse(value: unknown): value is ListAgentsResponse;
3416
- /** Response for `org-data-list`. */
3417
- interface DataListResponse {
3418
- /** Hex-encoded entry IDs for this page. */
3419
- entry_ids: string[];
3420
- /** Offset to pass for the next page. `null` when this is the last page. */
3421
- next_offset: number | null;
3422
- /** Total number of entries in the scope (across all pages). */
3423
- total: number;
3424
- }
3425
- /** Shallow runtime guard for {@link DataListResponse}. */
3426
- declare function isDataListResponse(value: unknown): value is DataListResponse;
3427
- /** Secret shape discriminator (mirrors the contract `SecretKind`). */
3428
- type SecretKind = "single_value" | "json";
3429
- /** Metadata common to every {@link SecretView} entry. */
3430
- interface SecretViewBase {
3431
- /** Secret name (the `(org, name)` key tail). */
3432
- name: string;
3433
- /** Monotonic version, bumped on each value rotation and ACL edit. */
3434
- version: number;
3435
- /** Unix seconds of the most recent write. */
3436
- updated_at_secs: number;
3437
- }
3656
+ declare function discoverDescribeContract(opts: DiscoverOptions, params: DescribeContractParams): Promise<DescribeContractResult>;
3438
3657
  /**
3439
- * The redacted per-secret summary `org-secret-list` returns — a discriminated
3440
- * union on `kind`. The value is NEVER present: a single-value exposes only its
3441
- * last four characters and a json secret only its sorted top-level field names.
3658
+ * `describe.function` — the authority-gated keyed describe read for a single
3659
+ * function. Returns `{ contract, version, descriptor }` with `descriptor` the
3660
+ * projected function entry. Same gating as {@link discoverDescribeContract}.
3661
+ *
3662
+ * @throws {InvokeError} — see {@link discoverWhoami}
3442
3663
  */
3443
- type SecretView = (SecretViewBase & {
3444
- kind: "single_value";
3445
- /** Last four characters of the value (whole value when ≤ 4 chars). */
3446
- last4: string;
3447
- }) | (SecretViewBase & {
3448
- kind: "json";
3449
- /** Sorted top-level object field names (keys only, no values). */
3450
- field_names: string[];
3451
- });
3452
- /** Shallow runtime guard for {@link SecretView}. */
3453
- declare function isSecretView(value: unknown): value is SecretView;
3664
+ declare function discoverDescribeFunction(opts: DiscoverOptions, params: DescribeFunctionParams): Promise<DescribeFunctionResult>;
3665
+
3454
3666
  /**
3455
- * Full secret record returned by `org-secret-get` — the value IS included
3456
- * (the deliberate read-back path the READ axis exists for), along with all
3457
- * three ACLs.
3667
+ * Token fixed-point units (USDT-style 6 decimals).
3668
+ *
3669
+ * As of `tee:*` metering v2, every token amount on the wire —
3670
+ * {@link BalanceRow}'s `available`/`reserved`, {@link UsageEntry.amount},
3671
+ * and `total_supply` — is denominated in **base units**, where
3672
+ * `1 T3N token = `{@link BASE_UNITS_PER_TOKEN}` base units`. The node
3673
+ * meters the *actual* fractional cost of each operation (pro-rata by
3674
+ * bytes / byte-seconds / fuel) down to `1e-6` token, so amounts are
3675
+ * raw integers in base units, NOT whole tokens.
3676
+ *
3677
+ * The wire fields are left as raw base units (no silent rescaling — that
3678
+ * would lose precision for large balances and surprise callers doing
3679
+ * arithmetic). Use {@link formatTokens} to render a human "tokens"
3680
+ * string and {@link toBaseUnits} to convert a token figure back.
3681
+ *
3682
+ * ⚠️ Breaking vs. the pre-decimals SDK: a balance that used to read `5`
3683
+ * (whole tokens) now reads `5_000_000` (base units). Multiply existing
3684
+ * display code through {@link formatTokens}.
3458
3685
  */
3459
- interface SecretRecord {
3460
- name: string;
3461
- kind: SecretKind;
3462
- /** The value as text: the scalar for a single-value, canonical JSON object for a json secret. */
3463
- value: string;
3464
- version: number;
3465
- /** READ axis — DIDs allowed to read the value back. */
3466
- reader_dids: string[];
3467
- /** READ axis — role ids allowed to read the value back. */
3468
- reader_roles: string[];
3469
- /** MANAGE axis — DIDs allowed to rotate the value. */
3470
- manager_dids: string[];
3471
- /** MANAGE axis — role ids allowed to rotate the value. */
3472
- manager_roles: string[];
3473
- /** USE axis — canonical contract ids allowed to have the value injected. */
3474
- contract_allowlist: string[];
3475
- created_at_secs: number;
3476
- updated_at_secs: number;
3477
- /** DID of the caller who last wrote the record. */
3478
- updated_by: string;
3479
- }
3480
- /** Shallow runtime guard for {@link SecretRecord}. */
3481
- declare function isSecretRecord(value: unknown): value is SecretRecord;
3482
- /** Response for `org-secret-list`: redacted per-kind views, no values. */
3483
- interface SecretListResponse {
3484
- secrets: SecretView[];
3485
- }
3486
- /** Shallow runtime guard for {@link SecretListResponse}. */
3487
- declare function isSecretListResponse(value: unknown): value is SecretListResponse;
3488
- /** Response for `org-data-get`. */
3489
- interface DataGetResponse {
3490
- entry_id: string;
3491
- /** Hex-encoded raw payload bytes. */
3492
- payload_hex: string;
3493
- }
3494
- /** Shallow runtime guard for {@link DataGetResponse}. */
3495
- declare function isDataGetResponse(value: unknown): value is DataGetResponse;
3686
+ /** Decimal places in a T3N token (fixed; mirrors the node constant). */
3687
+ declare const TOKEN_DECIMALS = 6;
3688
+ /** Base units per whole T3N token — `10 ** TOKEN_DECIMALS`. */
3689
+ declare const BASE_UNITS_PER_TOKEN = 1000000;
3496
3690
  /**
3497
- * Return shape of `agentCardGet` — composed client-side from the generic
3498
- * `org-data-get` read of the card's entry (there is no card-specific read
3499
- * operation on the contract). To check whether a public copy exists, probe
3500
- * the anonymous `GET /api/agent-card/{did}` endpoint.
3691
+ * Render a base-unit amount as a human-readable token string, e.g.
3692
+ * `25_920_000 → "25.92"`, `1_000_000 → "1"`, `4768 → "0.004768"`.
3693
+ *
3694
+ * Trailing-zero fraction digits are trimmed; an integer amount renders
3695
+ * with no decimal point. Accepts `number` or `bigint`; for balances
3696
+ * above `Number.MAX_SAFE_INTEGER` prefer passing a `bigint`.
3501
3697
  */
3502
- interface AgentCardResponse {
3503
- /** The agent whose card this is (`did:t3n:<40-hex>`). */
3504
- agent_did: string;
3505
- /** The stored card JSON body, verbatim. */
3506
- card: string;
3507
- }
3508
- /** Shallow runtime guard for {@link AgentCardResponse}. */
3509
- declare function isAgentCardResponse(value: unknown): value is AgentCardResponse;
3698
+ declare function formatTokens(baseUnits: number | bigint): string;
3510
3699
  /**
3511
- * Legacy direct-route org-data envelope shape retained for compatibility.
3512
- *
3513
- * This mirrors the removed `/api/user-contract/execute` body format from
3514
- * the transitional transport. New callers should use `OrgDataClient`,
3515
- * which now dispatches through authenticated `/api/rpc` +
3516
- * `action.execute` instead.
3700
+ * Convert a whole-or-fractional token figure to base units (rounded to
3701
+ * the nearest base unit). E.g. `25.92 → 25_920_000`, `1 → 1_000_000`.
3517
3702
  */
3518
- interface OrgDataActionWire {
3519
- nonce: string;
3520
- user_did: string;
3521
- authenticator_id: string;
3522
- contract_id: string;
3523
- function: string;
3524
- args_hash: string;
3525
- expires_at_secs: number;
3526
- signature: string;
3527
- }
3703
+ declare function toBaseUnits(tokens: number): number;
3528
3704
 
3529
3705
  /**
3530
3706
  * OrgDataClient — typed wrapper over the existing authenticated
@@ -3597,12 +3773,19 @@ interface SetWritersInput {
3597
3773
  scope: string;
3598
3774
  writers: string[];
3599
3775
  }
3600
- interface SetGrantsInput {
3776
+ /**
3777
+ * A grant to set via {@link OrgDataClient.setDelegation}. The per-grant
3778
+ * `contract_id` is injected by the SDK from the request `contractId` (the
3779
+ * contract sets it server-side regardless), so callers omit it — a read-back
3780
+ * {@link BoundGrant}, which carries `contract_id`, is still assignable.
3781
+ */
3782
+ type SetGrantInput = Omit<BoundGrant, "contract_id">;
3783
+ interface OrgDelegationSetInput {
3601
3784
  orgDid: string;
3602
3785
  contractId: string;
3603
- grants: UserGrant[];
3786
+ grants: SetGrantInput[];
3604
3787
  }
3605
- interface DeleteGrantsInput {
3788
+ interface OrgDelegationDeleteInput {
3606
3789
  orgDid: string;
3607
3790
  contractId: string;
3608
3791
  }
@@ -3611,9 +3794,9 @@ interface DeleteGrantsInput {
3611
3794
  * while executing one of the org's contracts (org-admin only).
3612
3795
  *
3613
3796
  * Egress ONLY — this confers no data authority. An agent needs BOTH this and a
3614
- * {@link OrgDataClient.setGrants} entry naming its own DID to do useful work:
3615
- * `setGrants` authorises the org data it may read, this authorises the hosts it
3616
- * may dial. No human `agent_auth` row is involved in either.
3797
+ * {@link OrgDataClient.setDelegation} entry naming its own DID to do useful work:
3798
+ * `setDelegation` authorises the org data it may read, this authorises the hosts it
3799
+ * may dial. No human delegation row is involved in either.
3617
3800
  *
3618
3801
  * Hosts are matched EXACTLY (lowercased). A scheme, port, path, or `*` wildcard
3619
3802
  * is rejected rather than stored as an entry that could never match.
@@ -3745,7 +3928,7 @@ interface DeleteScopeInput {
3745
3928
  interface PurgeOrgInput {
3746
3929
  orgDid: string;
3747
3930
  }
3748
- interface RemoveMemberGrantsInput {
3931
+ interface OrgRemoveMemberDelegationInput {
3749
3932
  orgDid: string;
3750
3933
  /** DID (`did:t3n:<40-hex>` or bare hex) to drop from every grant list. */
3751
3934
  memberDid: string;
@@ -3757,7 +3940,7 @@ interface WritersGetInput {
3757
3940
  orgDid: string;
3758
3941
  scope: string;
3759
3942
  }
3760
- interface GrantsGetInput {
3943
+ interface OrgDelegationGetInput {
3761
3944
  orgDid: string;
3762
3945
  contractId: string;
3763
3946
  }
@@ -3894,22 +4077,22 @@ declare class OrgDataClient {
3894
4077
  /** Delete a secret entirely (org-admin only). */
3895
4078
  secretDelete(input: SecretNameInput): Promise<MutationResponse>;
3896
4079
  /**
3897
- * Full replacement of the user-grant list for a contract.
4080
+ * Full replacement of the org's grant list for a contract.
3898
4081
  *
3899
4082
  * Passing an empty list removes the entry.
3900
4083
  */
3901
- setGrants(input: SetGrantsInput): Promise<MutationResponse>;
4084
+ setDelegation(input: OrgDelegationSetInput): Promise<MutationResponse>;
3902
4085
  /**
3903
4086
  * Delete the grant entry for a contract entirely.
3904
4087
  */
3905
- deleteGrants(input: DeleteGrantsInput): Promise<MutationResponse>;
4088
+ deleteDelegation(input: OrgDelegationDeleteInput): Promise<MutationResponse>;
3906
4089
  /**
3907
4090
  * Grant or replace the outbound host allow-list an org-owned agent may use
3908
4091
  * while executing one of the org's contracts (org-admin only).
3909
4092
  *
3910
4093
  * Full replacement for the `(agent, contract)` pair. Other contracts' egress
3911
4094
  * entries are untouched. See {@link SetAgentEgressInput} on why this is
3912
- * needed alongside {@link setGrants}.
4095
+ * needed alongside {@link setDelegation}.
3913
4096
  */
3914
4097
  setAgentEgress(input: SetAgentEgressInput): Promise<MutationResponse>;
3915
4098
  /**
@@ -3994,11 +4177,11 @@ declare class OrgDataClient {
3994
4177
  purgeOrg(input: PurgeOrgInput): Promise<MutationResponse>;
3995
4178
  /**
3996
4179
  * Detach-cascade grant sweep: drop `memberDid` from every
3997
- * one of the org's per-contract `UserGrant` lists. Authorised for an
4180
+ * one of the org's per-contract `BoundGrant` lists. Authorised for an
3998
4181
  * org-admin of the subject, or the member removing their own grants.
3999
4182
  * `deleted_entries` reports how many contract grant lists were rewritten.
4000
4183
  */
4001
- removeMemberGrants(input: RemoveMemberGrantsInput): Promise<MutationResponse>;
4184
+ removeMemberDelegation(input: OrgRemoveMemberDelegationInput): Promise<MutationResponse>;
4002
4185
  /** Read the policy metadata for an org (admin-only). */
4003
4186
  policyGet(input: PolicyGetInput): Promise<OrgPolicyMeta>;
4004
4187
  /**
@@ -4025,7 +4208,7 @@ declare class OrgDataClient {
4025
4208
  /** Read the writer list for a scope (admin-only). */
4026
4209
  writersGet(input: WritersGetInput): Promise<OrgWriters>;
4027
4210
  /** Read the grant list for a contract (admin-only). */
4028
- grantsGet(input: GrantsGetInput): Promise<OrgContractGrants>;
4211
+ getDelegation(input: OrgDelegationGetInput): Promise<OrgContractDelegation>;
4029
4212
  /**
4030
4213
  * List entry IDs for a scope (admin-only), paginated.
4031
4214
  *
@@ -4120,17 +4303,17 @@ declare class SessionOrgDataClient {
4120
4303
  secretList(input: SecretListInput): Promise<SecretView[]>;
4121
4304
  /** Mirrors {@link OrgDataClient.secretDelete}. */
4122
4305
  secretDelete(input: SecretNameInput): Promise<MutationResponse>;
4123
- /** Mirrors {@link OrgDataClient.setGrants}. */
4124
- setGrants(input: SetGrantsInput): Promise<MutationResponse>;
4125
- /** Mirrors {@link OrgDataClient.deleteGrants}. */
4126
- deleteGrants(input: DeleteGrantsInput): Promise<MutationResponse>;
4306
+ /** Mirrors {@link OrgDataClient.setDelegation}. */
4307
+ setDelegation(input: OrgDelegationSetInput): Promise<MutationResponse>;
4308
+ /** Mirrors {@link OrgDataClient.deleteDelegation}. */
4309
+ deleteDelegation(input: OrgDelegationDeleteInput): Promise<MutationResponse>;
4127
4310
  /**
4128
4311
  * Grant or replace the outbound host allow-list an org-owned agent may use
4129
4312
  * while executing one of the org's contracts (org-admin only).
4130
4313
  *
4131
4314
  * Full replacement for the `(agent, contract)` pair. Other contracts' egress
4132
4315
  * entries are untouched. See {@link SetAgentEgressInput} on why this is
4133
- * needed alongside {@link setGrants}.
4316
+ * needed alongside {@link setDelegation}.
4134
4317
  */
4135
4318
  setAgentEgress(input: SetAgentEgressInput): Promise<MutationResponse>;
4136
4319
  /**
@@ -4172,8 +4355,8 @@ declare class SessionOrgDataClient {
4172
4355
  deleteScope(input: DeleteScopeInput): Promise<MutationResponse>;
4173
4356
  /** Mirrors {@link OrgDataClient.purgeOrg}. */
4174
4357
  purgeOrg(input: PurgeOrgInput): Promise<MutationResponse>;
4175
- /** Mirrors {@link OrgDataClient.removeMemberGrants}. */
4176
- removeMemberGrants(input: RemoveMemberGrantsInput): Promise<MutationResponse>;
4358
+ /** Mirrors {@link OrgDataClient.removeMemberDelegation}. */
4359
+ removeMemberDelegation(input: OrgRemoveMemberDelegationInput): Promise<MutationResponse>;
4177
4360
  /** Mirrors {@link OrgDataClient.policyGet}. */
4178
4361
  policyGet(input: PolicyGetInput): Promise<OrgPolicyMeta>;
4179
4362
  /** Mirrors {@link OrgDataClient.policyView}. */
@@ -4182,8 +4365,8 @@ declare class SessionOrgDataClient {
4182
4365
  amIAdmin(input: PolicyGetInput): Promise<boolean>;
4183
4366
  /** Mirrors {@link OrgDataClient.writersGet}. */
4184
4367
  writersGet(input: WritersGetInput): Promise<OrgWriters>;
4185
- /** Mirrors {@link OrgDataClient.grantsGet}. */
4186
- grantsGet(input: GrantsGetInput): Promise<OrgContractGrants>;
4368
+ /** Mirrors {@link OrgDataClient.getDelegation}. */
4369
+ getDelegation(input: OrgDelegationGetInput): Promise<OrgContractDelegation>;
4187
4370
  /** Mirrors {@link OrgDataClient.dataList}. */
4188
4371
  dataList(input: DataListInput): Promise<DataListResponse>;
4189
4372
  /** Mirrors {@link OrgDataClient.dataGet}. */
@@ -4213,7 +4396,7 @@ declare function createOrgDataClientFromSession(t3n: T3nClient, baseUrl: string)
4213
4396
  *
4214
4397
  * Envelope-free authorisation removed the per-call delegation
4215
4398
  * credential and envelope entirely: authority is now the standing on-chain
4216
- * `agent_auth` ∩ `UserGrant` intersection the host re-reads every call, and
4399
+ * `member_delegation` ∩ `org_delegation` intersection the host re-reads every call, and
4217
4400
  * every payroll call emits the plain Direct wire variant (`{ request }`).
4218
4401
  * What remains here is the request body shape, its canonical defaults, and
4219
4402
  * the base64url / DID helpers callers still need.
@@ -4227,7 +4410,7 @@ declare function createOrgDataClientFromSession(t3n: T3nClient, baseUrl: string)
4227
4410
  /**
4228
4411
  * Canonical sorted run-pipeline function surface for the z-payroll contract
4229
4412
  * (`z:<org-tid>:payroll`). Sorted ascending. Mirrors `Z_PAYROLL_RUN_FUNCTIONS`
4230
- * in the Trinity harness; used as the `functions` set for agent-auth grants
4413
+ * in the Trinity harness; used as the `functions` set for delegation grants
4231
4414
  * and `check-delegation` queries.
4232
4415
  */
4233
4416
  declare const Z_PAYROLL_RUN_FUNCTIONS: readonly ["compute-payroll", "execute-disbursement", "finalize-audit", "submit-escalations", "validate-credentials"];
@@ -4432,7 +4615,7 @@ declare function stringToBytes(str: string): Uint8Array;
4432
4615
  */
4433
4616
  declare function bytesToString(bytes: Uint8Array): string;
4434
4617
 
4435
- declare function getScriptVersion(rpcUrl: string, scriptName: string): Promise<string>;
4618
+ declare function getContractVersion(rpcUrl: string, contractId: string): Promise<string>;
4436
4619
 
4437
4620
  /**
4438
4621
  * Secret redaction utilities for T3n SDK
@@ -4474,8 +4657,8 @@ declare function redactSecretsFromJson(jsonString: string): string;
4474
4657
  *
4475
4658
  * Predicates are intentionally shallow — they validate the immediate
4476
4659
  * top-level structure (object kind, presence/type of leading fields)
4477
- * but do not deeply validate nested elements (e.g. each `UserGrant`
4478
- * inside `OrgContractGrants.grants`). Deep validation would be brittle
4660
+ * but do not deeply validate nested elements (e.g. each `BoundGrant`
4661
+ * inside `OrgContractDelegation.grants`). Deep validation would be brittle
4479
4662
  * against benign contract additions; shallow guards catch the failure
4480
4663
  * modes that actually surface as runtime crashes (null/string/missing
4481
4664
  * top-level field).
@@ -4761,7 +4944,7 @@ interface TenantBaseClient {
4761
4944
  }
4762
4945
  interface TenantClientConfig {
4763
4946
  environment?: TenantSdkEnvironment;
4764
- /** Node URL for `getScriptVersion` during business contract execution. Falls back to `baseUrl`. */
4947
+ /** Node URL for `getContractVersion` during business contract execution. Falls back to `baseUrl`. */
4765
4948
  endpoint?: string;
4766
4949
  /**
4767
4950
  * Authenticated base client the TenantClient dispatches RPCs through.
@@ -4778,7 +4961,7 @@ interface TenantClientConfig {
4778
4961
  t3n?: TenantBaseClient;
4779
4962
  baseUrl?: string;
4780
4963
  tenantDid?: string;
4781
- tenantScriptName?: string;
4964
+ tenantContractId?: string;
4782
4965
  }
4783
4966
  type TenantStatus = "pending" | "active" | "suspended";
4784
4967
  interface TenantMeResponse {
@@ -5228,5 +5411,5 @@ declare function tenantDidHex(tenantDid: string): string;
5228
5411
  declare function validateTail(tail: string): string;
5229
5412
  declare function canonicalTenantName(tenantDid: string, tail: string): string;
5230
5413
 
5231
- 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, T3nConfigError, 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, buildSecretWriteArgs, 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, isAgentEgressGetResponse, isDataGetResponse, isDataListResponse, isListAgentsResponse, isListHumanMembersResponse, isMutationResponse, isObject, isOrgAdminStatus, isOrgContractGrants, isOrgPolicyMeta, isOrgPolicyView, isOrgUsageReport, isOrgWriters, isRoleAssignmentsResponse, isRoleGetResponse, isSecretListResponse, isSecretRecord, isSecretView, 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 };
5232
- export type { ActivityCallerType, ActivityEntry, ActivityOutcome, ActivityReport, AdmitForOrgOptions, AgentAuthEntry, AgentAuthMergeResult, AgentAuthPolicy, AgentAuthScriptGrant, AgentAuthUpdateInput, AgentCardRefInput, AgentCardResponse, AgentCardSetInput, AgentEgressEntry, AgentEgressGetResponse, AgentEgressRefInput, AgentSummary, AssignRolesInput, AuthInput, BalanceRow, ChargeReason, ClientAuth, ClientHandshake, ConfigValidationResult, ContractDescriptorFacets, ContractExecuteInput, ContractKind, ContractLifecycleStatus, ContractListDetailedOptions, ContractListDetailedPage, ContractPublishInput, ContractRegisterResult, ContractResponseSchema, ContractSetDescriptorInput, CreatePolicyInput, DataGetInput, DataGetResponse, DataListInput, DataListResponse, DelegationGrantKind, DelegationGrantRef, DeleteDataInput, DeleteGrantsInput, DeleteScopeInput, DetailedContract, Did, Direction, DkgAttestation, DkgVerifyResult, EmailOtpAuthInput, EmailOtpCredentials, Environment, EthAuthInput, ExecuteBusinessContractOptions, ExecuteOrgDataActionOptions, FetchTrustedManifestOptions, GetActivityLogOptions, GetUsageOptions, GrantCheckParams, GrantCheckResult, GranteeInput, GrantsGetInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, HumanMember, InvokeOptions, InvokeRequest, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, ListAgentsInput, ListAgentsResponse, ListContractsParams, ListContractsResult, ListContractsScope, ListHumanMembersInput, ListHumanMembersResponse, ListedContract, Logger, MapCreateInput, MapLifecycleStatus, MapResponse, MapUpdateInput, MapVisibility, MemberRole, 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, SecretKind, SecretListInput, SecretListResponse, SecretNameInput, SecretRecord, SecretSetValueInput, SecretView, SecretWriteInput, SessionCrypto, SessionId, SetAgentEgressInput, 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, TrustAnchorSource, TrustManifestPayload, UnassignRolesInput, UnsafeTrustServer, UpdateMetaInput, UsageEntry, UsagePage, UsageReportSignature, UserGrant, UserInputProfile, UserUpsertErrorKind, WasmComponent, WasmNextResult, WireBlock, WorkloadAuthInput, WriteDataInput, WriterSet, WritersGetInput };
5414
+ 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, T3nConfigError, 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, buildSecretWriteArgs, bytesToString, canonicalTenantName, clearKeyCache, clearManifestVersionFloor, compactDidFromBytes, createDefaultHandlers, createEmailOtpAuthInput, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createOrgDataClientFromSession, createRandomHandler, createUsageReportClientFromSession, createWorkloadAuthInput, decodeWasmErrorMessage, deriveAgentCardEntryId, discoverCheckDelegation, discoverDescribeContract, discoverDescribeFunction, discoverListContracts, discoverWhoami, eth_get_address, extractWasmError, fetchDkgAttestation, fetchMlKemPublicKey, fetchTrustedManifest, formatTokens, generateRandomString, generateUUID, getContractVersion, getEnvironment, getEnvironmentName, getGlobalLogLevel, getLogger, getNodeUrl, invoke, isAgentCardResponse, isAgentEgressGetResponse, isDataGetResponse, isDataListResponse, isListAgentsResponse, isListHumanMembersResponse, isMutationResponse, isObject, isOrgAdminStatus, isOrgContractDelegation, isOrgPolicyMeta, isOrgPolicyView, isOrgUsageReport, isOrgWriters, isRoleAssignmentsResponse, isRoleGetResponse, isSecretListResponse, isSecretRecord, isSecretView, isUnsafeTrustServer, loadConfig, loadWasmComponent, manifestToTrustAnchor, maskKeyMaterial, mergeDiscoverDids, mergeGrants, metamask_get_address, metamask_sign, parseContractResponse, parseMemberDelegationDoc, redactSecrets, redactSecretsFromJson, requestToWire, setEnvironment, setGlobalLogLevel, setNodeUrl, stringToBytes, tenantDidHex, toBaseUnits, validateConfig, validateTail, verifyDkgAttestation, verifyManifestSignature, verifyTdxQuote };
5415
+ export type { ActivityCallerType, ActivityEntry, ActivityOutcome, ActivityReport, AdmitForOrgOptions, AgentCardRefInput, AgentCardResponse, AgentCardSetInput, AgentEgressEntry, AgentEgressGetResponse, AgentEgressRefInput, AgentSummary, AssignRolesInput, AuthInput, BalanceRow, BoundGrant, ChargeReason, ClientAuth, ClientHandshake, ConfigValidationResult, ContractDescriptorDocument, ContractDescriptorFacets, ContractExecuteInput, ContractKind, ContractLifecycleStatus, ContractListDetailedOptions, ContractListDetailedPage, ContractPublishInput, ContractRegisterResult, ContractResponseSchema, ContractSetDescriptorInput, CreatePolicyInput, DataGetInput, DataGetResponse, DataListInput, DataListResponse, DelegationGrantKind, DelegationGrantRef, DeleteDataInput, DeleteScopeInput, DescribeContractParams, DescribeContractResult, DescribeFunctionParams, DescribeFunctionResult, DetailedContract, Did, Direction, DiscoverOptions, DkgAttestation, DkgVerifyResult, EmailOtpAuthInput, EmailOtpCredentials, Environment, EthAuthInput, ExecuteBusinessContractOptions, ExecuteOrgDataActionOptions, FetchTrustedManifestOptions, FunctionDescriptorEntry, GetActivityLogOptions, GetUsageOptions, GrantCheckParams, GrantCheckResult, GranteeInput, GrantsMergeResult, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, HumanMember, InvokeOptions, InvokeRequest, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, ListAgentsInput, ListAgentsResponse, ListContractsParams, ListContractsResult, ListContractsScope, ListHumanMembersInput, ListHumanMembersResponse, ListedContract, Logger, MapCreateInput, MapLifecycleStatus, MapResponse, MapUpdateInput, MapVisibility, MemberDelegationDoc, MemberRole, MutationResponse, OidcAuthInput, OidcCredentials, OrgAdminStatus, OrgContractDelegation, OrgDataActionWire, OrgDataClientOptions, OrgDelegationDeleteInput, OrgDelegationGetInput, OrgDelegationSetInput, OrgPolicyMeta, OrgPolicyView, OrgRemoveMemberDelegationInput, OrgUsageReport, OrgUsageReportInput, OrgWriters, OtpChannel, OtpMergeSuggestion, OtpRequestInput, OtpRequestResult, OtpVerifyInput, OtpVerifyResult, PayrollRunRequest, PeerQuoteResult, PolicyGetInput, PurgeOrgInput, QuoteVerifyResult, ReaderSet, RoleAssignments, RoleAssignmentsResponse, RoleDefinition, RoleGetResponse, RoleGrant, RoleIdInput, SdkConfig, SecretKind, SecretListInput, SecretListResponse, SecretNameInput, SecretRecord, SecretSetValueInput, SecretView, SecretWriteInput, SessionCrypto, SessionId, SetAgentEgressInput, 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, TrustAnchorSource, TrustManifestPayload, UnassignRolesInput, UnsafeTrustServer, UpdateMetaInput, UsageEntry, UsagePage, UsageReportSignature, UserInputProfile, UserUpsertErrorKind, Validity, WasmComponent, WasmNextResult, WhoamiResult, WireBlock, WorkloadAuthInput, WriteDataInput, WriterSet, WritersGetInput };