@terminal3/t3n-sdk 3.3.0 → 3.4.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.
Files changed (42) hide show
  1. package/README.md +33 -796
  2. package/dist/index.d.ts +281 -115
  3. package/dist/index.esm.js +1 -1
  4. package/dist/index.js +1 -1
  5. package/package.json +10 -60
  6. package/README.OIDC.md +0 -216
  7. package/dist/demo.d.ts +0 -25
  8. package/dist/src/client/actions.d.ts +0 -31
  9. package/dist/src/client/config.d.ts +0 -33
  10. package/dist/src/client/contract-response.d.ts +0 -59
  11. package/dist/src/client/delegation.d.ts +0 -388
  12. package/dist/src/client/encryption.d.ts +0 -30
  13. package/dist/src/client/handlers.d.ts +0 -73
  14. package/dist/src/client/index.d.ts +0 -13
  15. package/dist/src/client/org-data.d.ts +0 -276
  16. package/dist/src/client/request-parser.d.ts +0 -48
  17. package/dist/src/client/t3n-client.d.ts +0 -544
  18. package/dist/src/client/transport.d.ts +0 -131
  19. package/dist/src/config/index.d.ts +0 -82
  20. package/dist/src/config/loader.d.ts +0 -8
  21. package/dist/src/config/types.d.ts +0 -25
  22. package/dist/src/index.d.ts +0 -39
  23. package/dist/src/types/auth.d.ts +0 -66
  24. package/dist/src/types/index.d.ts +0 -45
  25. package/dist/src/types/kyc.d.ts +0 -135
  26. package/dist/src/types/org-data.d.ts +0 -180
  27. package/dist/src/types/session.d.ts +0 -24
  28. package/dist/src/types/token.d.ts +0 -102
  29. package/dist/src/types/user.d.ts +0 -236
  30. package/dist/src/utils/contract-version.d.ts +0 -5
  31. package/dist/src/utils/crypto.d.ts +0 -52
  32. package/dist/src/utils/errors.d.ts +0 -144
  33. package/dist/src/utils/index.d.ts +0 -10
  34. package/dist/src/utils/logger.d.ts +0 -102
  35. package/dist/src/utils/redaction.d.ts +0 -13
  36. package/dist/src/utils/session.d.ts +0 -37
  37. package/dist/src/utils/shape.d.ts +0 -30
  38. package/dist/src/wasm/index.d.ts +0 -5
  39. package/dist/src/wasm/interface.d.ts +0 -110
  40. package/dist/src/wasm/loader.d.ts +0 -43
  41. package/dist/src/wasm/quote-verifier/quote_verifier_bytes.d.ts +0 -1
  42. package/dist/src/wasm/quote-verifier-loader.d.ts +0 -58
@@ -1,276 +0,0 @@
1
- /**
2
- * OrgDataClient — typed wrapper over the existing authenticated
3
- * `/api/rpc` + `action.execute` pipeline.
4
- *
5
- * Unlike the removed direct `/api/user-contract/*` transport, this
6
- * client reuses Trinity's normal session-backed ETH auth flow:
7
- *
8
- * 1. `auth.handshake`
9
- * 2. `auth.authenticate`
10
- * 3. `action.execute`
11
- *
12
- * The class keeps its public constructor stable for callers that
13
- * already have an ETH secret key and expected DID, but internally it
14
- * owns a lazily-authenticated `T3nClient` instance rather than
15
- * constructing one-shot signed HTTP envelopes per call.
16
- */
17
- import type { Transport } from "./transport";
18
- import { T3nClient } from "./t3n-client";
19
- import type { WasmComponent } from "../wasm";
20
- import { type GuestToHostHandlers } from "../types";
21
- import type { OrgContractGrants, OrgPolicyMeta, OrgWriters, DataListResponse, DataGetResponse, MutationResponse, UserGrant } from "../types/org-data";
22
- export interface CreatePolicyInput {
23
- orgDid: string;
24
- initialAdminDid: string;
25
- maxAdmins?: number;
26
- }
27
- export interface UpdateMetaInput {
28
- orgDid: string;
29
- admins: string[];
30
- maxAdmins?: number;
31
- }
32
- export interface SetWritersInput {
33
- orgDid: string;
34
- scope: string;
35
- writers: string[];
36
- }
37
- export interface SetGrantsInput {
38
- orgDid: string;
39
- contractId: string;
40
- grants: UserGrant[];
41
- }
42
- export interface DeleteGrantsInput {
43
- orgDid: string;
44
- contractId: string;
45
- }
46
- export interface WriteDataInput {
47
- orgDid: string;
48
- scope: string;
49
- payloadHex: string;
50
- /** Explicit entry ID (32 hex chars). When present, enables idempotent upsert. */
51
- entryId?: string;
52
- /** Client-supplied monotonic counter for ID derivation when `entryId` is absent. */
53
- clientSeqNo?: number;
54
- }
55
- export interface DeleteDataInput {
56
- orgDid: string;
57
- scope: string;
58
- /** Hex-encoded entry ID (32 hex chars). */
59
- entryId: string;
60
- }
61
- export interface DeleteScopeInput {
62
- orgDid: string;
63
- scope: string;
64
- }
65
- export interface PolicyGetInput {
66
- orgDid: string;
67
- }
68
- export interface WritersGetInput {
69
- orgDid: string;
70
- scope: string;
71
- }
72
- export interface GrantsGetInput {
73
- orgDid: string;
74
- contractId: string;
75
- }
76
- export interface DataListInput {
77
- orgDid: string;
78
- scope: string;
79
- offset?: number;
80
- limit?: number;
81
- }
82
- export interface DataGetInput {
83
- orgDid: string;
84
- scope: string;
85
- /** Hex-encoded entry ID (32 hex chars). */
86
- entryId: string;
87
- }
88
- export interface ExecuteOrgDataActionOptions {
89
- /**
90
- * Deprecated. The direct signed-envelope transport used this as the
91
- * envelope expiry window; the session-backed RPC path ignores it.
92
- */
93
- ttlSecs?: number;
94
- }
95
- /**
96
- * Options used when constructing an {@link OrgDataClient}.
97
- */
98
- export interface OrgDataClientOptions extends ExecuteOrgDataActionOptions {
99
- /** Optional preloaded WASM component for tests or shared callers. */
100
- wasmComponent?: WasmComponent;
101
- /** Optional transport override, primarily for tests. */
102
- transport?: Transport;
103
- /**
104
- * Optional handler overrides. If `EthSign` is omitted, the client
105
- * uses the supplied `ethSecret` to satisfy Trinity's existing ETH
106
- * auth challenge flow automatically.
107
- */
108
- handlers?: GuestToHostHandlers;
109
- /**
110
- * Extra headers added to every `/api/rpc` request the internal
111
- * `T3nClient` makes. Mirrors `T3nClientConfig.headers` — needed when
112
- * the node sits behind an edge policy that gates `/api/rpc` on a
113
- * header (e.g. the staging Cloud Armor bypass token).
114
- */
115
- headers?: Record<string, string>;
116
- }
117
- /**
118
- * Client for session-authenticated org-data contract execution.
119
- *
120
- * Constructed with the node's base URL, the caller's 32-byte ETH secret
121
- * key, and the caller's DID (`did:t3n:<40-hex>`). The first method call
122
- * lazily creates a `T3nClient`, completes ETH session auth, verifies that
123
- * the authenticated DID matches `userDid`, and then reuses that session for
124
- * subsequent contract calls.
125
- */
126
- export declare class OrgDataClient {
127
- private readonly baseUrl;
128
- private readonly ethSecret;
129
- private readonly userDid;
130
- private readonly opts;
131
- private clientPromise;
132
- constructor(baseUrl: string, ethSecret: Uint8Array, userDid: string, opts?: OrgDataClientOptions);
133
- private getAuthenticatedClient;
134
- private initialiseClient;
135
- private call;
136
- /**
137
- * Initialise the data-tier policy for an existing organisation.
138
- *
139
- * The calling user must be named as `initialAdminDid`. New orgs created
140
- * after the org-data contract was deployed have their policy seeded
141
- * automatically by the organisation contract; call this only for orgs
142
- * that pre-date the contract deployment.
143
- */
144
- createPolicy(input: CreatePolicyInput): Promise<MutationResponse>;
145
- /**
146
- * Replace the admin list and/or `max_admins` cap on an existing policy.
147
- *
148
- * The calling user cannot remove themselves when they are the sole
149
- * remaining admin; another admin must be added first.
150
- */
151
- updateMeta(input: UpdateMetaInput): Promise<MutationResponse>;
152
- /**
153
- * Full replacement of the writer list for a data scope.
154
- *
155
- * Passing an empty list removes the entry (no writers allowed).
156
- * Scope names are canonicalised to lowercase before storage.
157
- */
158
- setWriters(input: SetWritersInput): Promise<MutationResponse>;
159
- /**
160
- * Full replacement of the user-grant list for a contract.
161
- *
162
- * Passing an empty list removes the entry.
163
- */
164
- setGrants(input: SetGrantsInput): Promise<MutationResponse>;
165
- /**
166
- * Delete the grant entry for a contract entirely.
167
- */
168
- deleteGrants(input: DeleteGrantsInput): Promise<MutationResponse>;
169
- /**
170
- * Write a data entry to the org's scope.
171
- *
172
- * When `entryId` is supplied, the call is an idempotent upsert.
173
- * When absent, `clientSeqNo` is required and the entry ID is derived
174
- * via SHA-256 from `(org_did, scope, writer_did, client_seq_no)`.
175
- */
176
- writeData(input: WriteDataInput): Promise<MutationResponse>;
177
- /** Delete a single data entry by entry ID. */
178
- deleteData(input: DeleteDataInput): Promise<MutationResponse>;
179
- /**
180
- * Bulk-delete all entries in a scope.
181
- *
182
- * Requires admin access (unlike `deleteData` which requires writer access).
183
- */
184
- deleteScope(input: DeleteScopeInput): Promise<MutationResponse>;
185
- /** Read the policy metadata for an org (admin-only). */
186
- policyGet(input: PolicyGetInput): Promise<OrgPolicyMeta>;
187
- /** Read the writer list for a scope (admin-only). */
188
- writersGet(input: WritersGetInput): Promise<OrgWriters>;
189
- /** Read the grant list for a contract (admin-only). */
190
- grantsGet(input: GrantsGetInput): Promise<OrgContractGrants>;
191
- /**
192
- * List entry IDs for a scope (admin-only), paginated.
193
- *
194
- * Pass `offset` from the previous response's `next_offset` to fetch
195
- * the next page.
196
- */
197
- dataList(input: DataListInput): Promise<DataListResponse>;
198
- /** Retrieve a single data entry by entry ID (admin-only). */
199
- dataGet(input: DataGetInput): Promise<DataGetResponse>;
200
- }
201
- /**
202
- * Session-authenticated variant of {@link OrgDataClient}.
203
- *
204
- * Where `OrgDataClient` owns its own ETH-secret-driven session lifecycle,
205
- * `SessionOrgDataClient` accepts a caller-owned {@link T3nClient}. The
206
- * caller is responsible for completing `handshake()` and `authenticate()`
207
- * on that client (e.g. via the SIWE flow used by the orgs admin UI)
208
- * BEFORE invoking any method on this class — the constructor performs no
209
- * auth lifecycle of its own.
210
- *
211
- * Dispatches through `action.execute` against `tee:org-data/contracts`,
212
- * relying on the caller-owned `T3nClient` for the preceding
213
- * `auth.handshake` / `auth.authenticate` steps, so callers get the
214
- * identical method surface as `OrgDataClient` without needing a raw ETH
215
- * secret key.
216
- *
217
- * The runtime guard only catches the no-handshake case
218
- * (`t3n.getSessionId()` returns `null`); a client that has handshaken but
219
- * not authenticated will pass the guard and instead fail later with an
220
- * `RpcError` from `action.execute`. Authorisation is similarly the
221
- * caller's responsibility — the contract will refuse calls that aren't
222
- * backed by a recognised admin / writer DID, surfaced as the usual
223
- * `'CODE: detail'` refusal string.
224
- */
225
- export declare class SessionOrgDataClient {
226
- private readonly t3n;
227
- private readonly baseUrl;
228
- /**
229
- * @param t3n - a `T3nClient` that the caller has already driven through
230
- * `handshake()` and `authenticate()`. The constructor does not verify
231
- * this; the runtime guard on each method only catches the
232
- * no-handshake case (`getSessionId()` returns `null`). A
233
- * handshake-only-no-authenticate client will fail later with an
234
- * `RpcError` from `action.execute`.
235
- * @param baseUrl - node base URL (trailing slashes stripped). Mirrors
236
- * `OrgDataClient`'s signature for ergonomic parity; used only for the
237
- * `tee:org-data/contracts` version lookup and should match the node
238
- * the supplied `t3n` is bound to.
239
- */
240
- constructor(t3n: T3nClient, baseUrl: string);
241
- private call;
242
- /** Mirrors {@link OrgDataClient.createPolicy}. */
243
- createPolicy(input: CreatePolicyInput): Promise<MutationResponse>;
244
- /** Mirrors {@link OrgDataClient.updateMeta}. */
245
- updateMeta(input: UpdateMetaInput): Promise<MutationResponse>;
246
- /** Mirrors {@link OrgDataClient.setWriters}. */
247
- setWriters(input: SetWritersInput): Promise<MutationResponse>;
248
- /** Mirrors {@link OrgDataClient.setGrants}. */
249
- setGrants(input: SetGrantsInput): Promise<MutationResponse>;
250
- /** Mirrors {@link OrgDataClient.deleteGrants}. */
251
- deleteGrants(input: DeleteGrantsInput): Promise<MutationResponse>;
252
- /** Mirrors {@link OrgDataClient.writeData}. */
253
- writeData(input: WriteDataInput): Promise<MutationResponse>;
254
- /** Mirrors {@link OrgDataClient.deleteData}. */
255
- deleteData(input: DeleteDataInput): Promise<MutationResponse>;
256
- /** Mirrors {@link OrgDataClient.deleteScope}. */
257
- deleteScope(input: DeleteScopeInput): Promise<MutationResponse>;
258
- /** Mirrors {@link OrgDataClient.policyGet}. */
259
- policyGet(input: PolicyGetInput): Promise<OrgPolicyMeta>;
260
- /** Mirrors {@link OrgDataClient.writersGet}. */
261
- writersGet(input: WritersGetInput): Promise<OrgWriters>;
262
- /** Mirrors {@link OrgDataClient.grantsGet}. */
263
- grantsGet(input: GrantsGetInput): Promise<OrgContractGrants>;
264
- /** Mirrors {@link OrgDataClient.dataList}. */
265
- dataList(input: DataListInput): Promise<DataListResponse>;
266
- /** Mirrors {@link OrgDataClient.dataGet}. */
267
- dataGet(input: DataGetInput): Promise<DataGetResponse>;
268
- }
269
- /**
270
- * Construct a {@link SessionOrgDataClient} from a caller-owned
271
- * {@link T3nClient} that has already been driven through `handshake()`
272
- * and `authenticate()`. Thin convenience wrapper — equivalent to
273
- * `new SessionOrgDataClient(t3n, baseUrl)`. See `SessionOrgDataClient`
274
- * for the full precondition contract and the runtime guard's limits.
275
- */
276
- export declare function createOrgDataClientFromSession(t3n: T3nClient, baseUrl: string): SessionOrgDataClient;
@@ -1,48 +0,0 @@
1
- /**
2
- * WASM Request Parser
3
- *
4
- * Parses and categorizes requests from the WASM state machine.
5
- * The WASM component outputs JSON with a `guest_to_host` tag that determines
6
- * how the SDK should handle the request.
7
- *
8
- * See node/session/src/abi.rs for the GuestToHost enum definition.
9
- */
10
- /**
11
- * Types of requests that can come from WASM
12
- */
13
- export declare enum WasmRequestType {
14
- /** Send data to remote server (PeerReply with action) */
15
- SendRemote = "SendRemote",
16
- /** Request to host (SDK) for side effects (MlKemPublicKey, Random, EthSign, etc.) */
17
- GuestToHost = "GuestToHost",
18
- /** Flow complete (Suspend) */
19
- Suspend = "Suspend"
20
- }
21
- /**
22
- * Parsed result from WASM request
23
- */
24
- export interface ParsedRequest {
25
- type: WasmRequestType;
26
- data: Record<string, unknown>;
27
- raw: string;
28
- }
29
- /**
30
- * Parses WASM request bytes into a categorized request type
31
- */
32
- export declare function parseWasmRequest(requestBytes: Uint8Array): ParsedRequest;
33
- /**
34
- * Check if a request should be sent to the remote server
35
- */
36
- export declare function isSendRemote(parsed: ParsedRequest): boolean;
37
- /**
38
- * Check if a request indicates flow completion
39
- */
40
- export declare function isCompletion(parsed: ParsedRequest): boolean;
41
- /**
42
- * Check if a request needs a guest-to-host handler
43
- */
44
- export declare function isGuestToHost(parsed: ParsedRequest): boolean;
45
- /**
46
- * Get the guest-to-host request type name (e.g., "MlKemPublicKey", "Random", "EthSign")
47
- */
48
- export declare function getGuestToHostType(parsed: ParsedRequest): string | null;