@terminal3/t3n-sdk 3.2.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.
- package/README.md +33 -796
- package/dist/index.d.ts +288 -115
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +10 -60
- package/README.OIDC.md +0 -216
- package/dist/demo.d.ts +0 -25
- package/dist/src/client/actions.d.ts +0 -31
- package/dist/src/client/config.d.ts +0 -33
- package/dist/src/client/contract-response.d.ts +0 -59
- package/dist/src/client/delegation.d.ts +0 -388
- package/dist/src/client/encryption.d.ts +0 -30
- package/dist/src/client/handlers.d.ts +0 -73
- package/dist/src/client/index.d.ts +0 -13
- package/dist/src/client/org-data.d.ts +0 -269
- package/dist/src/client/request-parser.d.ts +0 -48
- package/dist/src/client/t3n-client.d.ts +0 -544
- package/dist/src/client/transport.d.ts +0 -131
- package/dist/src/config/index.d.ts +0 -82
- package/dist/src/config/loader.d.ts +0 -8
- package/dist/src/config/types.d.ts +0 -25
- package/dist/src/index.d.ts +0 -39
- package/dist/src/types/auth.d.ts +0 -66
- package/dist/src/types/index.d.ts +0 -45
- package/dist/src/types/kyc.d.ts +0 -135
- package/dist/src/types/org-data.d.ts +0 -180
- package/dist/src/types/session.d.ts +0 -24
- package/dist/src/types/token.d.ts +0 -102
- package/dist/src/types/user.d.ts +0 -236
- package/dist/src/utils/contract-version.d.ts +0 -5
- package/dist/src/utils/crypto.d.ts +0 -52
- package/dist/src/utils/errors.d.ts +0 -144
- package/dist/src/utils/index.d.ts +0 -10
- package/dist/src/utils/logger.d.ts +0 -102
- package/dist/src/utils/redaction.d.ts +0 -13
- package/dist/src/utils/session.d.ts +0 -37
- package/dist/src/utils/shape.d.ts +0 -30
- package/dist/src/wasm/index.d.ts +0 -5
- package/dist/src/wasm/interface.d.ts +0 -110
- package/dist/src/wasm/loader.d.ts +0 -43
- package/dist/src/wasm/quote-verifier/quote_verifier_bytes.d.ts +0 -1
- package/dist/src/wasm/quote-verifier-loader.d.ts +0 -58
|
@@ -1,269 +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
|
-
/**
|
|
111
|
-
* Client for session-authenticated org-data contract execution.
|
|
112
|
-
*
|
|
113
|
-
* Constructed with the node's base URL, the caller's 32-byte ETH secret
|
|
114
|
-
* key, and the caller's DID (`did:t3n:<40-hex>`). The first method call
|
|
115
|
-
* lazily creates a `T3nClient`, completes ETH session auth, verifies that
|
|
116
|
-
* the authenticated DID matches `userDid`, and then reuses that session for
|
|
117
|
-
* subsequent contract calls.
|
|
118
|
-
*/
|
|
119
|
-
export declare class OrgDataClient {
|
|
120
|
-
private readonly baseUrl;
|
|
121
|
-
private readonly ethSecret;
|
|
122
|
-
private readonly userDid;
|
|
123
|
-
private readonly opts;
|
|
124
|
-
private clientPromise;
|
|
125
|
-
constructor(baseUrl: string, ethSecret: Uint8Array, userDid: string, opts?: OrgDataClientOptions);
|
|
126
|
-
private getAuthenticatedClient;
|
|
127
|
-
private initialiseClient;
|
|
128
|
-
private call;
|
|
129
|
-
/**
|
|
130
|
-
* Initialise the data-tier policy for an existing organisation.
|
|
131
|
-
*
|
|
132
|
-
* The calling user must be named as `initialAdminDid`. New orgs created
|
|
133
|
-
* after the org-data contract was deployed have their policy seeded
|
|
134
|
-
* automatically by the organisation contract; call this only for orgs
|
|
135
|
-
* that pre-date the contract deployment.
|
|
136
|
-
*/
|
|
137
|
-
createPolicy(input: CreatePolicyInput): Promise<MutationResponse>;
|
|
138
|
-
/**
|
|
139
|
-
* Replace the admin list and/or `max_admins` cap on an existing policy.
|
|
140
|
-
*
|
|
141
|
-
* The calling user cannot remove themselves when they are the sole
|
|
142
|
-
* remaining admin; another admin must be added first.
|
|
143
|
-
*/
|
|
144
|
-
updateMeta(input: UpdateMetaInput): Promise<MutationResponse>;
|
|
145
|
-
/**
|
|
146
|
-
* Full replacement of the writer list for a data scope.
|
|
147
|
-
*
|
|
148
|
-
* Passing an empty list removes the entry (no writers allowed).
|
|
149
|
-
* Scope names are canonicalised to lowercase before storage.
|
|
150
|
-
*/
|
|
151
|
-
setWriters(input: SetWritersInput): Promise<MutationResponse>;
|
|
152
|
-
/**
|
|
153
|
-
* Full replacement of the user-grant list for a contract.
|
|
154
|
-
*
|
|
155
|
-
* Passing an empty list removes the entry.
|
|
156
|
-
*/
|
|
157
|
-
setGrants(input: SetGrantsInput): Promise<MutationResponse>;
|
|
158
|
-
/**
|
|
159
|
-
* Delete the grant entry for a contract entirely.
|
|
160
|
-
*/
|
|
161
|
-
deleteGrants(input: DeleteGrantsInput): Promise<MutationResponse>;
|
|
162
|
-
/**
|
|
163
|
-
* Write a data entry to the org's scope.
|
|
164
|
-
*
|
|
165
|
-
* When `entryId` is supplied, the call is an idempotent upsert.
|
|
166
|
-
* When absent, `clientSeqNo` is required and the entry ID is derived
|
|
167
|
-
* via SHA-256 from `(org_did, scope, writer_did, client_seq_no)`.
|
|
168
|
-
*/
|
|
169
|
-
writeData(input: WriteDataInput): Promise<MutationResponse>;
|
|
170
|
-
/** Delete a single data entry by entry ID. */
|
|
171
|
-
deleteData(input: DeleteDataInput): Promise<MutationResponse>;
|
|
172
|
-
/**
|
|
173
|
-
* Bulk-delete all entries in a scope.
|
|
174
|
-
*
|
|
175
|
-
* Requires admin access (unlike `deleteData` which requires writer access).
|
|
176
|
-
*/
|
|
177
|
-
deleteScope(input: DeleteScopeInput): Promise<MutationResponse>;
|
|
178
|
-
/** Read the policy metadata for an org (admin-only). */
|
|
179
|
-
policyGet(input: PolicyGetInput): Promise<OrgPolicyMeta>;
|
|
180
|
-
/** Read the writer list for a scope (admin-only). */
|
|
181
|
-
writersGet(input: WritersGetInput): Promise<OrgWriters>;
|
|
182
|
-
/** Read the grant list for a contract (admin-only). */
|
|
183
|
-
grantsGet(input: GrantsGetInput): Promise<OrgContractGrants>;
|
|
184
|
-
/**
|
|
185
|
-
* List entry IDs for a scope (admin-only), paginated.
|
|
186
|
-
*
|
|
187
|
-
* Pass `offset` from the previous response's `next_offset` to fetch
|
|
188
|
-
* the next page.
|
|
189
|
-
*/
|
|
190
|
-
dataList(input: DataListInput): Promise<DataListResponse>;
|
|
191
|
-
/** Retrieve a single data entry by entry ID (admin-only). */
|
|
192
|
-
dataGet(input: DataGetInput): Promise<DataGetResponse>;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Session-authenticated variant of {@link OrgDataClient}.
|
|
196
|
-
*
|
|
197
|
-
* Where `OrgDataClient` owns its own ETH-secret-driven session lifecycle,
|
|
198
|
-
* `SessionOrgDataClient` accepts a caller-owned {@link T3nClient}. The
|
|
199
|
-
* caller is responsible for completing `handshake()` and `authenticate()`
|
|
200
|
-
* on that client (e.g. via the SIWE flow used by the orgs admin UI)
|
|
201
|
-
* BEFORE invoking any method on this class — the constructor performs no
|
|
202
|
-
* auth lifecycle of its own.
|
|
203
|
-
*
|
|
204
|
-
* Dispatches through `action.execute` against `tee:org-data/contracts`,
|
|
205
|
-
* relying on the caller-owned `T3nClient` for the preceding
|
|
206
|
-
* `auth.handshake` / `auth.authenticate` steps, so callers get the
|
|
207
|
-
* identical method surface as `OrgDataClient` without needing a raw ETH
|
|
208
|
-
* secret key.
|
|
209
|
-
*
|
|
210
|
-
* The runtime guard only catches the no-handshake case
|
|
211
|
-
* (`t3n.getSessionId()` returns `null`); a client that has handshaken but
|
|
212
|
-
* not authenticated will pass the guard and instead fail later with an
|
|
213
|
-
* `RpcError` from `action.execute`. Authorisation is similarly the
|
|
214
|
-
* caller's responsibility — the contract will refuse calls that aren't
|
|
215
|
-
* backed by a recognised admin / writer DID, surfaced as the usual
|
|
216
|
-
* `'CODE: detail'` refusal string.
|
|
217
|
-
*/
|
|
218
|
-
export declare class SessionOrgDataClient {
|
|
219
|
-
private readonly t3n;
|
|
220
|
-
private readonly baseUrl;
|
|
221
|
-
/**
|
|
222
|
-
* @param t3n - a `T3nClient` that the caller has already driven through
|
|
223
|
-
* `handshake()` and `authenticate()`. The constructor does not verify
|
|
224
|
-
* this; the runtime guard on each method only catches the
|
|
225
|
-
* no-handshake case (`getSessionId()` returns `null`). A
|
|
226
|
-
* handshake-only-no-authenticate client will fail later with an
|
|
227
|
-
* `RpcError` from `action.execute`.
|
|
228
|
-
* @param baseUrl - node base URL (trailing slashes stripped). Mirrors
|
|
229
|
-
* `OrgDataClient`'s signature for ergonomic parity; used only for the
|
|
230
|
-
* `tee:org-data/contracts` version lookup and should match the node
|
|
231
|
-
* the supplied `t3n` is bound to.
|
|
232
|
-
*/
|
|
233
|
-
constructor(t3n: T3nClient, baseUrl: string);
|
|
234
|
-
private call;
|
|
235
|
-
/** Mirrors {@link OrgDataClient.createPolicy}. */
|
|
236
|
-
createPolicy(input: CreatePolicyInput): Promise<MutationResponse>;
|
|
237
|
-
/** Mirrors {@link OrgDataClient.updateMeta}. */
|
|
238
|
-
updateMeta(input: UpdateMetaInput): Promise<MutationResponse>;
|
|
239
|
-
/** Mirrors {@link OrgDataClient.setWriters}. */
|
|
240
|
-
setWriters(input: SetWritersInput): Promise<MutationResponse>;
|
|
241
|
-
/** Mirrors {@link OrgDataClient.setGrants}. */
|
|
242
|
-
setGrants(input: SetGrantsInput): Promise<MutationResponse>;
|
|
243
|
-
/** Mirrors {@link OrgDataClient.deleteGrants}. */
|
|
244
|
-
deleteGrants(input: DeleteGrantsInput): Promise<MutationResponse>;
|
|
245
|
-
/** Mirrors {@link OrgDataClient.writeData}. */
|
|
246
|
-
writeData(input: WriteDataInput): Promise<MutationResponse>;
|
|
247
|
-
/** Mirrors {@link OrgDataClient.deleteData}. */
|
|
248
|
-
deleteData(input: DeleteDataInput): Promise<MutationResponse>;
|
|
249
|
-
/** Mirrors {@link OrgDataClient.deleteScope}. */
|
|
250
|
-
deleteScope(input: DeleteScopeInput): Promise<MutationResponse>;
|
|
251
|
-
/** Mirrors {@link OrgDataClient.policyGet}. */
|
|
252
|
-
policyGet(input: PolicyGetInput): Promise<OrgPolicyMeta>;
|
|
253
|
-
/** Mirrors {@link OrgDataClient.writersGet}. */
|
|
254
|
-
writersGet(input: WritersGetInput): Promise<OrgWriters>;
|
|
255
|
-
/** Mirrors {@link OrgDataClient.grantsGet}. */
|
|
256
|
-
grantsGet(input: GrantsGetInput): Promise<OrgContractGrants>;
|
|
257
|
-
/** Mirrors {@link OrgDataClient.dataList}. */
|
|
258
|
-
dataList(input: DataListInput): Promise<DataListResponse>;
|
|
259
|
-
/** Mirrors {@link OrgDataClient.dataGet}. */
|
|
260
|
-
dataGet(input: DataGetInput): Promise<DataGetResponse>;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Construct a {@link SessionOrgDataClient} from a caller-owned
|
|
264
|
-
* {@link T3nClient} that has already been driven through `handshake()`
|
|
265
|
-
* and `authenticate()`. Thin convenience wrapper — equivalent to
|
|
266
|
-
* `new SessionOrgDataClient(t3n, baseUrl)`. See `SessionOrgDataClient`
|
|
267
|
-
* for the full precondition contract and the runtime guard's limits.
|
|
268
|
-
*/
|
|
269
|
-
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;
|