@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.
- package/README.md +33 -796
- package/dist/index.d.ts +281 -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 -276
- 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,388 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* User-to-Agent Delegation (T3-TS-030).
|
|
3
|
-
*
|
|
4
|
-
* TypeScript reference implementation of the delegation credential and
|
|
5
|
-
* envelope shapes defined in `node/tee_contracts/delegation-types`.
|
|
6
|
-
*
|
|
7
|
-
* The wire shape is byte-for-byte identical to the Rust source — pinned
|
|
8
|
-
* by the KAT fixtures under `tests/kat/`. Specifically:
|
|
9
|
-
*
|
|
10
|
-
* - `not_before_secs` / `not_after_secs` / `batch_cap_cents` are
|
|
11
|
-
* emitted as **JSON strings** (e.g. `"1700086400"`) so JS Number
|
|
12
|
-
* precision never enters the canonicalisation surface.
|
|
13
|
-
* - `nonce` (16 B), `vc_id` (16 B), `request_hash` (32 B),
|
|
14
|
-
* `agent_pubkey` (33 B compressed secp256k1), `user_sig`,
|
|
15
|
-
* `agent_sig` are emitted as **base64url-no-pad** strings.
|
|
16
|
-
* - `org_did` / `user_did` are emitted as `did:t3n:<40-hex>` (the
|
|
17
|
-
* `CompactDid` `Display` form).
|
|
18
|
-
*
|
|
19
|
-
* Canonicalisation uses the npm `canonicalize` package (RFC 8785 JCS).
|
|
20
|
-
* Cryptography uses `@noble/curves` (secp256k1) and `@noble/hashes`
|
|
21
|
-
* (sha256, keccak_256).
|
|
22
|
-
*/
|
|
23
|
-
/** Domain tag carried in `DelegationCredential.v`. */
|
|
24
|
-
export declare const DELEGATION_CREDENTIAL_DOMAIN: "ot3.delegation/1";
|
|
25
|
-
/** Domain tag prepended to the agent-side pre-image. */
|
|
26
|
-
export declare const DELEGATION_INVOCATION_DOMAIN: "ot3.invocation/1";
|
|
27
|
-
export declare const VC_ID_LEN = 16;
|
|
28
|
-
export declare const NONCE_LEN = 16;
|
|
29
|
-
export declare const REQUEST_HASH_LEN = 32;
|
|
30
|
-
export declare const AGENT_PUBKEY_LEN = 33;
|
|
31
|
-
export declare const ETH_SIG_LEN = 65;
|
|
32
|
-
export declare const MAX_CONTRACT_LEN = 46;
|
|
33
|
-
export declare const MAX_FUNCTION_LEN = 64;
|
|
34
|
-
export declare const MAX_FUNCTIONS_PER_CREDENTIAL = 16;
|
|
35
|
-
export declare const MAX_SCOPE_LEN = 64;
|
|
36
|
-
export declare const MAX_SCOPES_PER_CREDENTIAL = 32;
|
|
37
|
-
export declare const MAX_METADATA_PER_CREDENTIAL = 16;
|
|
38
|
-
export declare const MAX_METADATA_KEY_LEN = 64;
|
|
39
|
-
export declare const MAX_METADATA_VALUE_LEN = 256;
|
|
40
|
-
/**
|
|
41
|
-
* Canonical sorted list of the payroll v2 function surface. One source
|
|
42
|
-
* of truth for callers building a full-cycle credential — pass this
|
|
43
|
-
* (or a sorted subset) as `functions` to {@link buildDelegationCredential}.
|
|
44
|
-
*/
|
|
45
|
-
export declare const PAYROLL_FUNCTIONS_V1: readonly ["compute-payroll", "execute-disbursement", "finalize-audit", "submit-escalations", "validate-credentials"];
|
|
46
|
-
/** User-to-agent delegation credential body. */
|
|
47
|
-
export interface DelegationCredential {
|
|
48
|
-
/** Domain tag, must equal {@link DELEGATION_CREDENTIAL_DOMAIN}. */
|
|
49
|
-
v: string;
|
|
50
|
-
/** `did:t3n:<40-hex>` user DID. */
|
|
51
|
-
user_did: string;
|
|
52
|
-
/** 33-byte compressed secp256k1 public key the agent uses per call. */
|
|
53
|
-
agent_pubkey: Uint8Array;
|
|
54
|
-
/** `did:t3n:<40-hex>` org DID. */
|
|
55
|
-
org_did: string;
|
|
56
|
-
/** Contract id, e.g. `"tee:payroll"`. */
|
|
57
|
-
contract: string;
|
|
58
|
-
/**
|
|
59
|
-
* Functions this credential authorises. Sorted ascending, deduped,
|
|
60
|
-
* each entry non-empty lowercase ASCII, 1..=16 entries.
|
|
61
|
-
*/
|
|
62
|
-
functions: string[];
|
|
63
|
-
/** Org-data scopes the contract may read on this user's behalf. */
|
|
64
|
-
scopes: string[];
|
|
65
|
-
/** Flat key-value labels checked against the org grant. */
|
|
66
|
-
metadata: Record<string, string>;
|
|
67
|
-
/** Inclusive lower bound of the validity window (unix seconds). */
|
|
68
|
-
not_before_secs: bigint;
|
|
69
|
-
/** Inclusive upper bound of the validity window (unix seconds). */
|
|
70
|
-
not_after_secs: bigint;
|
|
71
|
-
/** Random 16-byte credential id. */
|
|
72
|
-
vc_id: Uint8Array;
|
|
73
|
-
}
|
|
74
|
-
/** Envelope wrapping a contract-specific request body. */
|
|
75
|
-
export interface DelegationEnvelope {
|
|
76
|
-
/** RFC 8785 JCS bytes of the credential, exactly as signed. */
|
|
77
|
-
credential_jcs: Uint8Array;
|
|
78
|
-
/** 65-byte EIP-191 signature over `credential_jcs`. */
|
|
79
|
-
user_sig: Uint8Array;
|
|
80
|
-
/** Per-call agent signature over the invocation pre-image. */
|
|
81
|
-
agent_sig: Uint8Array;
|
|
82
|
-
/** 16-byte agent-generated per-call nonce. */
|
|
83
|
-
nonce: Uint8Array;
|
|
84
|
-
/** SHA-256 of the canonical request body. */
|
|
85
|
-
request_hash: Uint8Array;
|
|
86
|
-
}
|
|
87
|
-
/** Payroll-specific request body wrapped by a delegation envelope. */
|
|
88
|
-
export interface PayrollRunRequest {
|
|
89
|
-
/** `did:t3n:<40-hex>` org id. */
|
|
90
|
-
org_id: string;
|
|
91
|
-
cycle_id: string;
|
|
92
|
-
pay_period_start: string;
|
|
93
|
-
pay_period_end: string;
|
|
94
|
-
/** Total cap on the run's net disbursement, in cents. */
|
|
95
|
-
batch_cap_cents: bigint;
|
|
96
|
-
/** `employee_id` → previous-cycle baseline net disbursement, cents (decimal string). */
|
|
97
|
-
historical_baselines: Record<string, string>;
|
|
98
|
-
/**
|
|
99
|
-
* Per-employee disbursement flag threshold, in cents. Mirrors
|
|
100
|
-
* `PayrollRunRequest::individual_disbursement_threshold_cents` on the Rust
|
|
101
|
-
* side. When absent the Rust contract applies its own default (SGD 15,000;
|
|
102
|
-
* `DEFAULT_INDIVIDUAL_THRESHOLD_CENTS`). When present, the value is
|
|
103
|
-
* included in the wire shape and participates in the request hash.
|
|
104
|
-
*/
|
|
105
|
-
individual_disbursement_threshold_cents?: bigint;
|
|
106
|
-
}
|
|
107
|
-
/** Default for `individual_disbursement_threshold_cents` — SGD 15,000. */
|
|
108
|
-
export declare const DEFAULT_INDIVIDUAL_THRESHOLD_CENTS = 1500000n;
|
|
109
|
-
/** Delegated invocation: the agent acts on behalf of a user. */
|
|
110
|
-
export interface PayrollInvocationDelegated {
|
|
111
|
-
envelope: DelegationEnvelope;
|
|
112
|
-
request: PayrollRunRequest;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Direct invocation: the agent acts on its own behalf. No delegation
|
|
116
|
-
* envelope is included. The principal DID is resolved by the service layer
|
|
117
|
-
* from `DynamicContext.authenticated_did`; authorisation falls through to
|
|
118
|
-
* `OrgContractGrants[org || "tee:payroll"]` for the agent's own DID.
|
|
119
|
-
*
|
|
120
|
-
* Wire shape is `{ request }` — no `envelope` field and no
|
|
121
|
-
* `authenticated_did` field. The contract's entry-point handler injects
|
|
122
|
-
* `authenticated_did` from `GenericInput.context` before calling `verify`.
|
|
123
|
-
*/
|
|
124
|
-
export interface PayrollInvocationDirect {
|
|
125
|
-
request: PayrollRunRequest;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Union of the two invocation variants. The serde-untagged enum on the
|
|
129
|
-
* contract side disambiguates by presence of `envelope` — delegated calls
|
|
130
|
-
* carry `{ envelope, request }`, direct calls carry `{ request }` only.
|
|
131
|
-
*/
|
|
132
|
-
export type PayrollInvocation = PayrollInvocationDelegated | PayrollInvocationDirect;
|
|
133
|
-
/** Response from `tee:delegation.sign`. */
|
|
134
|
-
export interface SignDelegationResponse {
|
|
135
|
-
credential_jcs: Uint8Array;
|
|
136
|
-
user_sig: Uint8Array;
|
|
137
|
-
}
|
|
138
|
-
declare function b64uEncode(input: Uint8Array): string;
|
|
139
|
-
declare function b64uDecode(input: string): Uint8Array;
|
|
140
|
-
/**
|
|
141
|
-
* Encode raw bytes to base64url-no-pad (RFC 4648 §5 with padding
|
|
142
|
-
* dropped). The same encoding T3-TS-030 wire-shape uses for binary
|
|
143
|
-
* fields (`agent_pubkey`, `vc_id`, `nonce`, `agent_sig`, `user_sig`,
|
|
144
|
-
* `request_hash`, `credential_jcs`).
|
|
145
|
-
*
|
|
146
|
-
* Public API since v2.2: callers building `PayrollInvocation` JSON
|
|
147
|
-
* for the wire (e.g. the t3n-mcp `runPayroll` handler) need this
|
|
148
|
-
* encoder to match the contract's deserializer.
|
|
149
|
-
*/
|
|
150
|
-
export declare function b64uEncodeBytes(input: Uint8Array): string;
|
|
151
|
-
/**
|
|
152
|
-
* Decode a base64url-no-pad string. Strict — rejects standard-alphabet
|
|
153
|
-
* `+` / `/` and any padding `=`.
|
|
154
|
-
*/
|
|
155
|
-
export declare function b64uDecodeStrict(input: string): Uint8Array;
|
|
156
|
-
/** @internal — preserved alias for in-tree callers. Prefer
|
|
157
|
-
* {@link b64uEncodeBytes} / {@link b64uDecodeStrict}. */
|
|
158
|
-
export declare const _b64uEncode: typeof b64uEncode;
|
|
159
|
-
/** @internal — preserved alias for in-tree callers. Prefer
|
|
160
|
-
* {@link b64uEncodeBytes} / {@link b64uDecodeStrict}. */
|
|
161
|
-
export declare const _b64uDecode: typeof b64uDecode;
|
|
162
|
-
/** Build a `did:t3n:<40-hex>` from raw 20 bytes. */
|
|
163
|
-
export declare function compactDidFromBytes(bytes: Uint8Array): string;
|
|
164
|
-
/**
|
|
165
|
-
* Canonicalise a {@link DelegationCredential} to RFC 8785 JCS bytes.
|
|
166
|
-
*
|
|
167
|
-
* Output is byte-identical to the Rust `canonicalise_credential` in
|
|
168
|
-
* `delegation-types` (pinned by `tests/kat/credential.json`).
|
|
169
|
-
*/
|
|
170
|
-
export declare function canonicaliseCredential(credential: DelegationCredential): Uint8Array;
|
|
171
|
-
/** Canonicalise an arbitrary {@link PayrollRunRequest} to JCS bytes. */
|
|
172
|
-
export declare function canonicaliseRequest(request: PayrollRunRequest): Uint8Array;
|
|
173
|
-
/** SHA-256 of the canonicalised request body. */
|
|
174
|
-
export declare function requestHash(request: PayrollRunRequest): Uint8Array;
|
|
175
|
-
/**
|
|
176
|
-
* Build the agent-side pre-image bytes:
|
|
177
|
-
* `utf8(DELEGATION_INVOCATION_DOMAIN) || vc_id || nonce || request_hash`.
|
|
178
|
-
*
|
|
179
|
-
* SHA-256 of these bytes is what the agent's secp256k1 signature is
|
|
180
|
-
* verified against.
|
|
181
|
-
*/
|
|
182
|
-
export declare function buildInvocationPreimage(vcId: Uint8Array, nonce: Uint8Array, reqHash: Uint8Array): Uint8Array;
|
|
183
|
-
/** Options for {@link buildDelegationCredential}. */
|
|
184
|
-
export interface BuildDelegationCredentialOpts {
|
|
185
|
-
user_did: string;
|
|
186
|
-
agent_pubkey: Uint8Array;
|
|
187
|
-
org_did: string;
|
|
188
|
-
contract: string;
|
|
189
|
-
/**
|
|
190
|
-
* Functions this credential authorises. Must be non-empty, sorted
|
|
191
|
-
* ascending, deduped — the same invariants enforced by
|
|
192
|
-
* {@link validateCredentialBody}.
|
|
193
|
-
*/
|
|
194
|
-
functions: string[];
|
|
195
|
-
scopes?: string[];
|
|
196
|
-
metadata?: Record<string, string>;
|
|
197
|
-
not_before_secs: bigint | number;
|
|
198
|
-
not_after_secs: bigint | number;
|
|
199
|
-
vc_id: Uint8Array;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Construct a {@link DelegationCredential} and validate body-level
|
|
203
|
-
* invariants (domain, lengths, validity window). Throws on the same
|
|
204
|
-
* conditions the Rust `validate_credential_body` rejects.
|
|
205
|
-
*/
|
|
206
|
-
export declare function buildDelegationCredential(opts: BuildDelegationCredentialOpts): DelegationCredential;
|
|
207
|
-
/**
|
|
208
|
-
* Body-level validation matching `delegation-types::validate_credential_body`,
|
|
209
|
-
* minus the `now`/`max_validity_secs` checks (which are caller-supplied).
|
|
210
|
-
* Throws with a message identifying the offending invariant.
|
|
211
|
-
*/
|
|
212
|
-
export declare function validateCredentialBody(c: DelegationCredential): void;
|
|
213
|
-
/** Compute the EIP-191 "personal_sign" digest of a message. */
|
|
214
|
-
export declare function eip191Digest(msg: Uint8Array): Uint8Array;
|
|
215
|
-
/**
|
|
216
|
-
* EIP-191 sign `jcs` under `secret`, returning a 65-byte signature
|
|
217
|
-
* (`r || s || v`, with `v` in 27/28 — Ethereum convention) and the
|
|
218
|
-
* recovered 20-byte ETH address.
|
|
219
|
-
*/
|
|
220
|
-
export declare function signCredential(jcs: Uint8Array, secret: Uint8Array): {
|
|
221
|
-
sig: Uint8Array;
|
|
222
|
-
addr: Uint8Array;
|
|
223
|
-
};
|
|
224
|
-
/**
|
|
225
|
-
* Recover the 20-byte ETH address that signed `msg` under EIP-191.
|
|
226
|
-
* Mirrors `delegation-types::eth_recover_eip191`.
|
|
227
|
-
*
|
|
228
|
-
* **Signature malleability — accepted by design.** This routine does
|
|
229
|
-
* not enforce low-s. EIP-2 mandates low-s for *transaction* signatures,
|
|
230
|
-
* but EIP-191 / `personal_sign` has no such requirement, and ethers.js
|
|
231
|
-
* / MetaMask / web3.js produce both shapes. Two distinct `(r, s)` and
|
|
232
|
-
* `(r, n − s)` pairs verify under the same recovered address — replay
|
|
233
|
-
* protection comes from the envelope's `request_hash` + `nonce`, not
|
|
234
|
-
* from byte-uniqueness of the signature.
|
|
235
|
-
*/
|
|
236
|
-
export declare function ethRecoverEip191(msg: Uint8Array, sig: Uint8Array): Uint8Array;
|
|
237
|
-
/**
|
|
238
|
-
* Sign the agent-side invocation pre-image. The signature is raw
|
|
239
|
-
* compact ECDSA (64 bytes) over `sha256(preimage)` — what
|
|
240
|
-
* `delegation-types::verify_agent_sig` accepts as the 64-byte form.
|
|
241
|
-
*/
|
|
242
|
-
export declare function signAgentInvocation(preimage: Uint8Array, secret: Uint8Array): Uint8Array;
|
|
243
|
-
/**
|
|
244
|
-
* Options for {@link DelegationCustodialClient}.
|
|
245
|
-
*/
|
|
246
|
-
export interface DelegationCustodialClientOpts {
|
|
247
|
-
/**
|
|
248
|
-
* Explicit semver string for the delegation contract (e.g. `"1.0.0"`).
|
|
249
|
-
* When omitted the client resolves `"latest"` via
|
|
250
|
-
* `GET /api/contracts/current?name=tee:delegation/contracts` (one
|
|
251
|
-
* request per client instance, cached in `getScriptVersion`).
|
|
252
|
-
*/
|
|
253
|
-
scriptVersion?: string;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Result returned by {@link DelegationCustodialClient.signCustodial}.
|
|
257
|
-
*/
|
|
258
|
-
export interface SignCustodialResult {
|
|
259
|
-
/** RFC 8785 JCS bytes of the credential, exactly as signed by the node. */
|
|
260
|
-
credentialJcs: Uint8Array;
|
|
261
|
-
/** 65-byte EIP-191 signature over `credentialJcs` produced by the TEE. */
|
|
262
|
-
userSig: Uint8Array;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Wraps the `tee:delegation/contracts::sign` function for OIDC users
|
|
266
|
-
* (or any user whose private key is held by the TEE rather than the
|
|
267
|
-
* browser).
|
|
268
|
-
*
|
|
269
|
-
* ETH-EOA users who hold their own key should call
|
|
270
|
-
* {@link signCredential} directly — no network round-trip required.
|
|
271
|
-
*
|
|
272
|
-
* The client must be constructed with an authenticated {@link T3nClient}
|
|
273
|
-
* instance and the node's base URL; `signCustodial` sends the credential
|
|
274
|
-
* body to the TEE and returns the signed bytes.
|
|
275
|
-
*
|
|
276
|
-
* Reference: `node/tests/harness/src/payroll_seed.rs` (the
|
|
277
|
-
* `tee:delegation.sign` invocation at line 550).
|
|
278
|
-
*/
|
|
279
|
-
export declare class DelegationCustodialClient {
|
|
280
|
-
private readonly t3n;
|
|
281
|
-
private readonly baseUrl;
|
|
282
|
-
private readonly opts;
|
|
283
|
-
constructor(t3n: import("./t3n-client").T3nClient, baseUrl: string, opts?: DelegationCustodialClientOpts);
|
|
284
|
-
/**
|
|
285
|
-
* Request the TEE to sign a delegation credential on behalf of the
|
|
286
|
-
* authenticated user.
|
|
287
|
-
*
|
|
288
|
-
* The `body` is sent as-is as the `input.body` field of the
|
|
289
|
-
* `tee:delegation/contracts::sign` action. Use
|
|
290
|
-
* {@link buildDelegationCredential} + the wire-shape projection to
|
|
291
|
-
* produce the correct representation — binary fields (`agent_pubkey`,
|
|
292
|
-
* `vc_id`) must be base64url-no-pad strings, and `not_before_secs` /
|
|
293
|
-
* `not_after_secs` must be decimal strings.
|
|
294
|
-
*
|
|
295
|
-
* Returns `{ credentialJcs, userSig }` — both as `Uint8Array` — ready
|
|
296
|
-
* to be passed into {@link buildPayrollInvocation}.
|
|
297
|
-
*/
|
|
298
|
-
signCustodial(body: Record<string, unknown>): Promise<SignCustodialResult>;
|
|
299
|
-
}
|
|
300
|
-
/** Options for {@link revokeDelegation}. */
|
|
301
|
-
export interface RevokeDelegationOpts {
|
|
302
|
-
/** Credential body to revoke. Already-encoded base64url-no-pad JCS bytes. */
|
|
303
|
-
credentialJcsB64u: string;
|
|
304
|
-
/**
|
|
305
|
-
* Omit (or pass `undefined`) to revoke the whole credential. Pass an
|
|
306
|
-
* array of function names to revoke a subset; the array must obey the
|
|
307
|
-
* same sort + dedupe invariants the credential's `functions` field
|
|
308
|
-
* enforces, and each entry must already appear in the credential's
|
|
309
|
-
* `functions` list (a revocation can only narrow the set, never grow
|
|
310
|
-
* it).
|
|
311
|
-
*/
|
|
312
|
-
revokedFunctions?: string[];
|
|
313
|
-
/** Authenticated {@link T3nClient} for the credential's `user_did`. */
|
|
314
|
-
client: import("./t3n-client").T3nClient;
|
|
315
|
-
/**
|
|
316
|
-
* Override the resolved delegation contract version. Defaults to
|
|
317
|
-
* whatever `GET /api/contracts/current?name=tee:delegation/contracts`
|
|
318
|
-
* returns at call time.
|
|
319
|
-
*/
|
|
320
|
-
scriptVersion?: string;
|
|
321
|
-
/** Override the node base URL used for `"latest"` resolution. */
|
|
322
|
-
baseUrl?: string;
|
|
323
|
-
}
|
|
324
|
-
/** Result of a successful {@link revokeDelegation} call. */
|
|
325
|
-
export interface RevokeDelegationResult {
|
|
326
|
-
/** Credential id (base64url-no-pad, no padding). */
|
|
327
|
-
vcId: string;
|
|
328
|
-
/**
|
|
329
|
-
* Mirrors the persisted revocation state after merging: `null` means
|
|
330
|
-
* whole-credential, a sorted array means per-function. The contract
|
|
331
|
-
* may return a larger set than `opts.revokedFunctions` when an
|
|
332
|
-
* earlier per-function revocation existed for the same credential.
|
|
333
|
-
*/
|
|
334
|
-
revokedFunctions: string[] | null;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Wraps the `tee:delegation/contracts::revoke` entrypoint. Only the
|
|
338
|
-
* credential's `user_did` may call this — the contract reads the
|
|
339
|
-
* authenticated DID from session context and rejects any other caller
|
|
340
|
-
* with `NotCredentialHolder`.
|
|
341
|
-
*
|
|
342
|
-
* Merge semantics are handled server-side: whole-credential revocations
|
|
343
|
-
* are sticky, and per-function revocations accumulate as a sorted +
|
|
344
|
-
* deduped union across calls. The returned `revokedFunctions` reflects
|
|
345
|
-
* the persisted state after merging, not just this call's input.
|
|
346
|
-
*/
|
|
347
|
-
export declare function revokeDelegation(opts: RevokeDelegationOpts): Promise<RevokeDelegationResult>;
|
|
348
|
-
/** Options for {@link buildPayrollInvocation}. */
|
|
349
|
-
export interface BuildPayrollInvocationOpts {
|
|
350
|
-
credentialJcs: Uint8Array;
|
|
351
|
-
userSig: Uint8Array;
|
|
352
|
-
/** Credential's `vc_id` — needed for the agent pre-image. */
|
|
353
|
-
vcId: Uint8Array;
|
|
354
|
-
nonce: Uint8Array;
|
|
355
|
-
request: PayrollRunRequest;
|
|
356
|
-
agentSecret: Uint8Array;
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Assemble a delegated {@link PayrollInvocationDelegated} (envelope +
|
|
360
|
-
* request) given a user-signed credential and a per-call agent secret.
|
|
361
|
-
* Computes `request_hash` from the canonical request bytes and produces an
|
|
362
|
-
* `agent_sig` over `sha256(invocation_preimage)`.
|
|
363
|
-
*
|
|
364
|
-
* When `request.individual_disbursement_threshold_cents` is undefined this
|
|
365
|
-
* function fills in {@link DEFAULT_INDIVIDUAL_THRESHOLD_CENTS} before
|
|
366
|
-
* hashing so the SDK's hash matches the Rust contract's hash (the contract
|
|
367
|
-
* applies the same default via `#[serde(default)]`).
|
|
368
|
-
*/
|
|
369
|
-
export declare function buildPayrollInvocation(opts: BuildPayrollInvocationOpts): PayrollInvocationDelegated;
|
|
370
|
-
/** Options for {@link buildPayrollDirectInvocation}. */
|
|
371
|
-
export interface BuildPayrollDirectInvocationOpts {
|
|
372
|
-
request: PayrollRunRequest;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Assemble a direct {@link PayrollInvocationDirect} — no delegation
|
|
376
|
-
* envelope. The caller supplies only the request body; the contract
|
|
377
|
-
* entry-point resolves the principal DID from
|
|
378
|
-
* `DynamicContext.authenticated_did` at runtime.
|
|
379
|
-
*
|
|
380
|
-
* Callers in direct mode must hold a grant in
|
|
381
|
-
* `OrgContractGrants[org || "tee:payroll"]` under their own DID.
|
|
382
|
-
*
|
|
383
|
-
* When `request.individual_disbursement_threshold_cents` is undefined this
|
|
384
|
-
* function fills in {@link DEFAULT_INDIVIDUAL_THRESHOLD_CENTS} so the wire
|
|
385
|
-
* shape matches the Rust contract's `#[serde(default)]` canonicalisation.
|
|
386
|
-
*/
|
|
387
|
-
export declare function buildPayrollDirectInvocation(opts: BuildPayrollDirectInvocationOpts): PayrollInvocationDirect;
|
|
388
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session Encryption Service
|
|
3
|
-
*
|
|
4
|
-
* Handles encryption and decryption of data using the established WASM session.
|
|
5
|
-
* Keeps cryptographic operations isolated and simple.
|
|
6
|
-
*/
|
|
7
|
-
import { SessionCrypto } from "../wasm";
|
|
8
|
-
import { Logger } from "../utils/logger";
|
|
9
|
-
/**
|
|
10
|
-
* Encrypts and decrypts data using an established session
|
|
11
|
-
*/
|
|
12
|
-
export declare class SessionEncryption {
|
|
13
|
-
private sessionCrypto;
|
|
14
|
-
private logger;
|
|
15
|
-
constructor(sessionCrypto: SessionCrypto, logger: Logger);
|
|
16
|
-
/**
|
|
17
|
-
* Encrypt data using the session
|
|
18
|
-
* @param sessionState - The session state bytes (from handshake)
|
|
19
|
-
* @param data - The plaintext data to encrypt
|
|
20
|
-
* @returns Base64-encoded encrypted data
|
|
21
|
-
*/
|
|
22
|
-
encrypt(sessionState: Uint8Array, data: Uint8Array): Promise<string>;
|
|
23
|
-
/**
|
|
24
|
-
* Decrypt data using the session
|
|
25
|
-
* @param sessionState - The session state bytes (from handshake)
|
|
26
|
-
* @param encryptedData - Base64-encoded encrypted data
|
|
27
|
-
* @returns Decrypted plaintext bytes
|
|
28
|
-
*/
|
|
29
|
-
decrypt(sessionState: Uint8Array, encryptedData: string): Promise<Uint8Array>;
|
|
30
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Guest-to-Host Request Handlers
|
|
3
|
-
*
|
|
4
|
-
* These handle requests from WASM that need the host environment to perform side effects.
|
|
5
|
-
* Examples: signing challenges, providing public keys, generating random bytes.
|
|
6
|
-
*/
|
|
7
|
-
import { GuestToHostHandler, GuestToHostHandlers } from "../types";
|
|
8
|
-
import { Logger } from "../utils/logger";
|
|
9
|
-
/**
|
|
10
|
-
* Account — MetaMask handler accepts either a plain address string or an
|
|
11
|
-
* object with an `address` field (for compatibility with various wallet
|
|
12
|
-
* libraries).
|
|
13
|
-
*/
|
|
14
|
-
type EthAccount = string | {
|
|
15
|
-
address: string;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Create an EthSign handler using MetaMask (window.ethereum)
|
|
19
|
-
* @param account - MetaMask account (string address or object with address property)
|
|
20
|
-
* @param logger - Optional logger instance. Defaults to a logger using the global log level (LogLevel.ERROR).
|
|
21
|
-
* Pass a custom logger to override logging behavior for this handler.
|
|
22
|
-
* @param privateKey - Optional private key for signing (if provided, MetaMask is not used)
|
|
23
|
-
*/
|
|
24
|
-
export declare function metamask_sign(account: EthAccount, logger?: Logger, privateKey?: string | undefined): GuestToHostHandler;
|
|
25
|
-
/**
|
|
26
|
-
* Get the current MetaMask address
|
|
27
|
-
* @returns Ethereum address (lowercase, 0x prefixed)
|
|
28
|
-
*/
|
|
29
|
-
export declare function metamask_get_address(): Promise<string>;
|
|
30
|
-
/**
|
|
31
|
-
* Get the address for a given private key
|
|
32
|
-
* @param privateKey - Ethereum private key (0x prefixed hex string)
|
|
33
|
-
* @returns Ethereum address (lowercase, 0x prefixed)
|
|
34
|
-
*/
|
|
35
|
-
export declare function eth_get_address(privateKey: string): string;
|
|
36
|
-
/**
|
|
37
|
-
* Create an MlKemPublicKey handler that lazily fetches the root public key
|
|
38
|
-
* from `${baseUrl}/status` on first invocation and caches the encoded
|
|
39
|
-
* response for subsequent calls.
|
|
40
|
-
*
|
|
41
|
-
* @param baseUrl - **Required**. The node URL whose `/status` endpoint should
|
|
42
|
-
* serve the ML-KEM public key. Must be the same URL the
|
|
43
|
-
* T3nClient is constructed with — otherwise the handshake
|
|
44
|
-
* encrypts to one node and sends ciphertext to another.
|
|
45
|
-
*
|
|
46
|
-
* Was optional in 0.3.x, where omitting it caused the lazy
|
|
47
|
-
* fetch to silently fall back to `NODE_URLS[currentEnv]` and
|
|
48
|
-
* hit the wrong node. Three downstream consumers (demo.ts,
|
|
49
|
-
* t3-apps dev wallet hooks, t3n-mcp session manager) all
|
|
50
|
-
* hit this trap before we tightened the type.
|
|
51
|
-
*/
|
|
52
|
-
export declare function createMlKemPublicKeyHandler(baseUrl: string): GuestToHostHandler;
|
|
53
|
-
/**
|
|
54
|
-
* Create Random handler backed by crypto.getRandomValues
|
|
55
|
-
* Note: The Rust Vec<u8> type serializes as an array of bytes, not a base64 string
|
|
56
|
-
*/
|
|
57
|
-
export declare function createRandomHandler(): GuestToHostHandler;
|
|
58
|
-
/**
|
|
59
|
-
* Create the default handler set required by the T3n handshake.
|
|
60
|
-
*
|
|
61
|
-
* @param baseUrl - **Required**. Forwarded to `createMlKemPublicKeyHandler`
|
|
62
|
-
* so the lazy /status fetch hits the right node.
|
|
63
|
-
*/
|
|
64
|
-
export declare function createDefaultHandlers(baseUrl: string): GuestToHostHandlers;
|
|
65
|
-
/**
|
|
66
|
-
* Merge consumer-provided handlers with defaults (user handlers take precedence).
|
|
67
|
-
*
|
|
68
|
-
* @param handlers - Optional consumer overrides.
|
|
69
|
-
* @param baseUrl - **Required**. Forwarded to the default handler set so the
|
|
70
|
-
* ML-KEM key fetch hits the right node.
|
|
71
|
-
*/
|
|
72
|
-
export declare function mergeWithDefaultHandlers(handlers: GuestToHostHandlers | undefined, baseUrl: string): GuestToHostHandlers;
|
|
73
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client exports for T3n SDK
|
|
3
|
-
*/
|
|
4
|
-
export * from "./config";
|
|
5
|
-
export * from "./transport";
|
|
6
|
-
export * from "./t3n-client";
|
|
7
|
-
export * from "./handlers";
|
|
8
|
-
export * from "./encryption";
|
|
9
|
-
export * from "./actions";
|
|
10
|
-
export * from "./request-parser";
|
|
11
|
-
export * from "./contract-response";
|
|
12
|
-
export * from "./delegation";
|
|
13
|
-
export * from "./org-data";
|