@terminal3/t3n-sdk 2.5.0 → 2.7.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.
@@ -1,46 +1,25 @@
1
1
  /**
2
- * OrgDataClient — user-signed org-data dispatch client.
2
+ * OrgDataClient — typed wrapper over the existing authenticated
3
+ * `/api/rpc` + `action.execute` pipeline.
3
4
  *
4
- * Implements the two-step flow that `node/service/src/org_data.rs`
5
- * defines:
5
+ * Unlike the removed direct `/api/user-contract/*` transport, this
6
+ * client reuses Trinity's normal session-backed ETH auth flow:
6
7
  *
7
- * 1. `POST /api/org-data/nonce` — fetch a single-use replay nonce.
8
- * 2. `POST /api/org-data/execute` — submit a signed envelope whose
9
- * EIP-191 signature covers the canonical JSON of the eight
10
- * `SignableEnvelope` fields, in the exact field-declaration order
11
- * used by the Rust struct (see `org_data.rs` lines 104–117).
8
+ * 1. `auth.handshake`
9
+ * 2. `auth.authenticate`
10
+ * 3. `action.execute`
12
11
  *
13
- * The `args_hash` is `hex(sha256(JSON.stringify(args)))` the same
14
- * binding the Rust harness (`org_data_client.rs`) computes.
15
- *
16
- * `authenticator_id` is `"eth:0x<40 lowercase hex>"` derived
17
- * deterministically from the caller's ETH secret key.
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.
18
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";
19
21
  import type { OrgContractGrants, OrgPolicyMeta, OrgWriters, DataListResponse, DataGetResponse, MutationResponse, UserGrant } from "../types/org-data";
20
- /**
21
- * Derive the `"eth:0x<40 lowercase hex>"` authenticator string
22
- * deterministically from a 32-byte ETH secret key.
23
- *
24
- * Mirrors `authenticator_id_from_eth_secret` in
25
- * `node/tests/harness/src/org_data_client.rs`.
26
- */
27
- declare function authenticatorIdFromEthSecret(ethSecret: Uint8Array): string;
28
- /**
29
- * Options accepted by {@link executeOrgDataAction}.
30
- */
31
- export interface ExecuteOrgDataActionOptions {
32
- /** Envelope TTL in seconds. Defaults to {@link DEFAULT_ENVELOPE_TTL_SECS}. */
33
- ttlSecs?: number;
34
- }
35
- /**
36
- * Sign and dispatch a user-authenticated org-data action.
37
- *
38
- * `args` MUST contain an `org_did` field matching `orgDid` — the
39
- * service verifies envelope-vs-args binding before dispatching.
40
- *
41
- * Returns the contract's JSON response on success.
42
- */
43
- declare function executeOrgDataAction(baseUrl: string, ethSecret: Uint8Array, userDid: string, orgDid: string, functionName: string, args: Record<string, unknown>, opts?: ExecuteOrgDataActionOptions): Promise<unknown>;
22
+ declare function executeOrgDataAction(client: T3nClient, baseUrl: string, functionName: string, args: Record<string, unknown>): Promise<unknown>;
44
23
  export interface CreatePolicyInput {
45
24
  orgDid: string;
46
25
  initialAdminDid: string;
@@ -107,31 +86,46 @@ export interface DataGetInput {
107
86
  /** Hex-encoded entry ID (32 hex chars). */
108
87
  entryId: string;
109
88
  }
89
+ export interface ExecuteOrgDataActionOptions {
90
+ /**
91
+ * Deprecated. The direct signed-envelope transport used this as the
92
+ * envelope expiry window; the session-backed RPC path ignores it.
93
+ */
94
+ ttlSecs?: number;
95
+ }
110
96
  /**
111
97
  * Options used when constructing an {@link OrgDataClient}.
112
98
  */
113
- export interface OrgDataClientOptions {
114
- /** Envelope TTL in seconds applied to every call. Default: 300. */
115
- ttlSecs?: number;
99
+ export interface OrgDataClientOptions extends ExecuteOrgDataActionOptions {
100
+ /** Optional preloaded WASM component for tests or shared callers. */
101
+ wasmComponent?: WasmComponent;
102
+ /** Optional transport override, primarily for tests. */
103
+ transport?: Transport;
104
+ /**
105
+ * Optional handler overrides. If `EthSign` is omitted, the client
106
+ * uses the supplied `ethSecret` to satisfy Trinity's existing ETH
107
+ * auth challenge flow automatically.
108
+ */
109
+ handlers?: GuestToHostHandlers;
116
110
  }
117
111
  /**
118
- * Client for the user-authenticated org-data dispatch API.
112
+ * Client for session-authenticated org-data contract execution.
119
113
  *
120
114
  * 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>`). Every method
122
- * transparently fetches a fresh nonce, signs the envelope with EIP-191,
123
- * and posts to `/api/org-data/execute`.
124
- *
125
- * The signing key must be the same key registered as an authenticator
126
- * (`eth:0x<addr>`) for `userDid` in the DID registry — the service
127
- * verifies this binding before dispatching any contract call.
115
+ * key, and the caller's DID (`did:t3n:<40-hex>`). The first method call
116
+ * lazily creates a `T3nClient`, completes ETH session auth, verifies that
117
+ * the authenticated DID matches `userDid`, and then reuses that session for
118
+ * subsequent contract calls.
128
119
  */
129
120
  export declare class OrgDataClient {
130
121
  private readonly baseUrl;
131
122
  private readonly ethSecret;
132
123
  private readonly userDid;
133
124
  private readonly opts;
125
+ private clientPromise;
134
126
  constructor(baseUrl: string, ethSecret: Uint8Array, userDid: string, opts?: OrgDataClientOptions);
127
+ private getAuthenticatedClient;
128
+ private initialiseClient;
135
129
  private call;
136
130
  /**
137
131
  * Initialise the data-tier policy for an existing organisation.
@@ -198,4 +192,4 @@ export declare class OrgDataClient {
198
192
  /** Retrieve a single data entry by entry ID (admin-only). */
199
193
  dataGet(input: DataGetInput): Promise<DataGetResponse>;
200
194
  }
201
- export { executeOrgDataAction, authenticatorIdFromEthSecret };
195
+ export { executeOrgDataAction };
@@ -128,17 +128,17 @@ export interface DataGetResponse {
128
128
  payload_hex: string;
129
129
  }
130
130
  /**
131
- * The signed action envelope sent to `POST /api/org-data/execute`.
131
+ * Legacy direct-route org-data envelope shape retained for compatibility.
132
132
  *
133
- * Field order matches `node/service/src/org_data.rs::OrgDataSignedAction`
134
- * and `SignableEnvelope`. The `signature` field is the EIP-191
135
- * personal_sign over the canonical JSON of the eight fields above it.
133
+ * This mirrors the removed `/api/user-contract/execute` body format from
134
+ * the transitional transport. New callers should use `OrgDataClient`,
135
+ * which now dispatches through authenticated `/api/rpc` +
136
+ * `action.execute` instead.
136
137
  */
137
138
  export interface OrgDataActionWire {
138
139
  nonce: string;
139
140
  user_did: string;
140
141
  authenticator_id: string;
141
- org_did: string;
142
142
  contract_id: string;
143
143
  function: string;
144
144
  args_hash: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terminal3/t3n-sdk",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "type": "module",
5
5
  "description": "T3n TypeScript SDK - A minimal SDK that mirrors the server's RPC handler approach",
6
6
  "main": "dist/index.js",
@@ -108,13 +108,5 @@
108
108
  "@noble/hashes": "^2.2.0",
109
109
  "canonicalize": "^3.0.0",
110
110
  "ethers": "^6.16.0"
111
- },
112
- "pnpm": {
113
- "overrides": {
114
- "rollup": ">=4.59.0",
115
- "esbuild": ">=0.25.0",
116
- "minimatch": ">=9.0.7",
117
- "postcss": ">=8.5.10"
118
- }
119
111
  }
120
- }
112
+ }