@opendatalabs/vana-sdk 3.5.0 → 3.5.1-pr.159.12a6f39

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 (120) hide show
  1. package/README.md +116 -0
  2. package/dist/direct/access-request-client.cjs +104 -0
  3. package/dist/direct/access-request-client.cjs.map +1 -0
  4. package/dist/direct/access-request-client.d.ts +51 -0
  5. package/dist/direct/access-request-client.js +79 -0
  6. package/dist/direct/access-request-client.js.map +1 -0
  7. package/dist/direct/access-request-client.test.d.ts +1 -0
  8. package/dist/direct/connect-flow.cjs +152 -0
  9. package/dist/direct/connect-flow.cjs.map +1 -0
  10. package/dist/direct/connect-flow.d.ts +85 -0
  11. package/dist/direct/connect-flow.js +128 -0
  12. package/dist/direct/connect-flow.js.map +1 -0
  13. package/dist/direct/connect-flow.test.d.ts +1 -0
  14. package/dist/direct/controller.cjs +129 -0
  15. package/dist/direct/controller.cjs.map +1 -0
  16. package/dist/direct/controller.d.ts +152 -0
  17. package/dist/direct/controller.js +109 -0
  18. package/dist/direct/controller.js.map +1 -0
  19. package/dist/direct/controller.test.d.ts +1 -0
  20. package/dist/direct/endpoints.cjs +45 -0
  21. package/dist/direct/endpoints.cjs.map +1 -0
  22. package/dist/direct/endpoints.d.ts +22 -0
  23. package/dist/direct/endpoints.js +19 -0
  24. package/dist/direct/endpoints.js.map +1 -0
  25. package/dist/direct/errors.cjs +65 -0
  26. package/dist/direct/errors.cjs.map +1 -0
  27. package/dist/direct/errors.d.ts +44 -0
  28. package/dist/direct/errors.js +38 -0
  29. package/dist/direct/errors.js.map +1 -0
  30. package/dist/direct/escrow-payment.cjs +96 -0
  31. package/dist/direct/escrow-payment.cjs.map +1 -0
  32. package/dist/direct/escrow-payment.d.ts +81 -0
  33. package/dist/direct/escrow-payment.js +72 -0
  34. package/dist/direct/escrow-payment.js.map +1 -0
  35. package/dist/direct/escrow-payment.test.d.ts +1 -0
  36. package/dist/direct/personal-server-read.cjs +149 -0
  37. package/dist/direct/personal-server-read.cjs.map +1 -0
  38. package/dist/direct/personal-server-read.d.ts +103 -0
  39. package/dist/direct/personal-server-read.js +124 -0
  40. package/dist/direct/personal-server-read.js.map +1 -0
  41. package/dist/direct/personal-server-read.test.d.ts +1 -0
  42. package/dist/direct/types.cjs +35 -0
  43. package/dist/direct/types.cjs.map +1 -0
  44. package/dist/direct/types.d.ts +205 -0
  45. package/dist/direct/types.js +11 -0
  46. package/dist/direct/types.js.map +1 -0
  47. package/dist/direct/use-direct-vana-connect.cjs +68 -0
  48. package/dist/direct/use-direct-vana-connect.cjs.map +1 -0
  49. package/dist/direct/use-direct-vana-connect.d.ts +45 -0
  50. package/dist/direct/use-direct-vana-connect.js +46 -0
  51. package/dist/direct/use-direct-vana-connect.js.map +1 -0
  52. package/dist/index.browser.d.ts +7 -3
  53. package/dist/index.browser.js +513 -174
  54. package/dist/index.browser.js.map +4 -4
  55. package/dist/index.node.cjs +536 -179
  56. package/dist/index.node.cjs.map +4 -4
  57. package/dist/index.node.d.ts +7 -3
  58. package/dist/index.node.js +513 -174
  59. package/dist/index.node.js.map +4 -4
  60. package/dist/protocol/data-point-status.cjs +80 -0
  61. package/dist/protocol/data-point-status.cjs.map +1 -0
  62. package/dist/protocol/data-point-status.d.ts +34 -0
  63. package/dist/protocol/data-point-status.js +51 -0
  64. package/dist/protocol/data-point-status.js.map +1 -0
  65. package/dist/protocol/data-point-status.test.d.ts +1 -0
  66. package/dist/protocol/eip712.cjs +53 -31
  67. package/dist/protocol/eip712.cjs.map +1 -1
  68. package/dist/protocol/eip712.d.ts +98 -43
  69. package/dist/protocol/eip712.js +47 -27
  70. package/dist/protocol/eip712.js.map +1 -1
  71. package/dist/protocol/escrow-deposit.cjs +89 -0
  72. package/dist/protocol/escrow-deposit.cjs.map +1 -0
  73. package/dist/protocol/escrow-deposit.d.ts +47 -0
  74. package/dist/protocol/escrow-deposit.js +60 -0
  75. package/dist/protocol/escrow-deposit.js.map +1 -0
  76. package/dist/protocol/escrow-deposit.test.d.ts +1 -0
  77. package/dist/protocol/escrow-flow.test.d.ts +21 -0
  78. package/dist/protocol/fee-registry.cjs +116 -0
  79. package/dist/protocol/fee-registry.cjs.map +1 -0
  80. package/dist/protocol/fee-registry.d.ts +151 -0
  81. package/dist/protocol/fee-registry.js +89 -0
  82. package/dist/protocol/fee-registry.js.map +1 -0
  83. package/dist/protocol/fee-registry.test.d.ts +1 -0
  84. package/dist/protocol/gateway.cjs +107 -37
  85. package/dist/protocol/gateway.cjs.map +1 -1
  86. package/dist/protocol/gateway.d.ts +223 -57
  87. package/dist/protocol/gateway.js +107 -37
  88. package/dist/protocol/gateway.js.map +1 -1
  89. package/dist/protocol/grants.cjs +27 -64
  90. package/dist/protocol/grants.cjs.map +1 -1
  91. package/dist/protocol/grants.d.ts +6 -13
  92. package/dist/protocol/grants.js +27 -63
  93. package/dist/protocol/grants.js.map +1 -1
  94. package/dist/protocol/personal-server-data.cjs +71 -0
  95. package/dist/protocol/personal-server-data.cjs.map +1 -0
  96. package/dist/protocol/personal-server-data.d.ts +16 -0
  97. package/dist/protocol/personal-server-data.js +47 -0
  98. package/dist/protocol/personal-server-data.js.map +1 -0
  99. package/dist/protocol/personal-server-data.test.d.ts +1 -0
  100. package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
  101. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
  102. package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
  103. package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
  104. package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
  105. package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
  106. package/dist/react.cjs +32 -0
  107. package/dist/react.cjs.map +1 -0
  108. package/dist/react.d.ts +33 -0
  109. package/dist/react.js +11 -0
  110. package/dist/react.js.map +1 -0
  111. package/dist/server.cjs +73 -0
  112. package/dist/server.cjs.map +1 -0
  113. package/dist/server.d.ts +32 -0
  114. package/dist/server.js +55 -0
  115. package/dist/server.js.map +1 -0
  116. package/dist/storage/providers/vana-storage.cjs +75 -17
  117. package/dist/storage/providers/vana-storage.cjs.map +1 -1
  118. package/dist/storage/providers/vana-storage.js +75 -17
  119. package/dist/storage/providers/vana-storage.js.map +1 -1
  120. package/package.json +20 -1
@@ -3,7 +3,7 @@ export interface GatewayEnvelope<T> {
3
3
  proof: GatewayProof;
4
4
  /**
5
5
  * Cursor-based pagination metadata, present on list endpoints (e.g.
6
- * `GET /v1/files`). A sibling of `data`, not nested inside it — so callers
6
+ * `GET /v1/data`). A sibling of `data`, not nested inside it — so callers
7
7
  * that need it must read the full envelope rather than going through
8
8
  * `unwrapEnvelope`, which intentionally returns only `data`.
9
9
  */
@@ -51,75 +51,71 @@ export interface ServerInfo {
51
51
  publicKey: string;
52
52
  serverUrl: string;
53
53
  addedAt: string;
54
+ revokedAt: string | null;
55
+ }
56
+ export interface GatewayGrantFee {
57
+ asset: string;
58
+ registrationFee: string;
59
+ dataAccessFee: string;
60
+ totalDue: string;
54
61
  }
62
+ export type GatewayGrantStatus = "pending" | "submitting" | "confirmed" | "finalized" | "reorged";
55
63
  export interface GatewayGrantResponse {
56
64
  id: string;
57
65
  grantorAddress: string;
58
66
  granteeId: string;
59
- grant: string;
60
- fileIds: string[];
61
- status: "pending" | "confirmed";
67
+ scopes: string[];
68
+ status: GatewayGrantStatus;
62
69
  addedAt: string;
70
+ expiresAt: string | null;
71
+ expired: boolean;
63
72
  revokedAt: string | null;
64
73
  revocationSignature: string | null;
74
+ paymentStatus: "pending" | "paid";
75
+ paidAt: string | null;
76
+ paidBy: string | null;
77
+ grantVersion: string;
78
+ settleTxHash: string | null;
79
+ settleSubmittedAt: string | null;
80
+ revocationTxHash: string | null;
81
+ revocationSubmittedAt: string | null;
82
+ fee: GatewayGrantFee;
65
83
  }
66
- export interface GrantListItem {
84
+ export type GrantListItem = GatewayGrantResponse;
85
+ export interface DataPointRecord {
67
86
  id: string;
68
- grantorAddress: string;
69
- granteeId: string;
70
- grant: string;
71
- fileIds: string[];
72
- status: "pending" | "confirmed";
87
+ ownerAddress: string;
88
+ scope: string;
89
+ dataHash: string;
90
+ metadataHash: string;
91
+ expectedVersion: string;
73
92
  addedAt: string;
74
- revokedAt: string | null;
75
- revocationSignature: string | null;
76
- }
77
- export interface FileRecord {
78
- fileId: string;
79
- owner: string;
80
- url: string;
81
- schemaId: string;
82
- createdAt: string;
83
- /**
84
- * Soft-deletion timestamp (ISO 8601), or null if the file is active. Always present
85
- * (`normalizeFileRecord` populates it); non-null only when the gateway returns deletion state
86
- * (e.g. listed with `includeDeleted`). Drives the PS sync delete-reconciliation.
87
- */
88
- deletedAt: string | null;
89
93
  }
90
- export interface FileListResult {
91
- files: FileRecord[];
94
+ export interface DataPointListResult {
95
+ dataPoints: DataPointRecord[];
92
96
  cursor: string | null;
93
97
  }
94
- export interface ListFilesOptions {
98
+ export interface ListDataPointsOptions {
95
99
  /**
96
- * Include soft-deleted files in the result (each carries a non-null `deletedAt`). Default false.
97
- * Used by the PS sync download worker to reconcile deletions of files it already holds locally.
100
+ * Only return rows added at or after this ISO 8601 timestamp. Used by sync
101
+ * loops that want incremental tails pass the last seen `addedAt`.
98
102
  */
99
- includeDeleted?: boolean;
100
- }
101
- export interface RegisterFileParams {
102
- ownerAddress: string;
103
- url: string;
104
- schemaId: string;
105
- signature: string;
103
+ since?: string;
104
+ /** Page size. Capped at 1000 by the gateway. */
105
+ limit?: number;
106
106
  }
107
107
  export interface CreateGrantParams {
108
108
  grantorAddress: string;
109
109
  granteeId: string;
110
- grant: string;
111
- fileIds: string[];
110
+ scopes: string[];
111
+ grantVersion: string;
112
+ expiresAt: string;
112
113
  signature: string;
113
114
  }
114
115
  export interface RevokeGrantParams {
115
116
  grantId: string;
116
117
  grantorAddress: string;
117
- signature: string;
118
- }
119
- export interface DeleteFileParams {
120
- fileId: string;
121
- ownerAddress: string;
122
- /** EIP-712 FileDeletion signature, signed by the owner or the owner's registered server. */
118
+ grantVersion: string;
123
119
  signature: string;
124
120
  }
125
121
  export interface RegisterServerParams {
@@ -133,6 +129,171 @@ export interface RegisterServerResult {
133
129
  serverId?: string;
134
130
  alreadyRegistered: boolean;
135
131
  }
132
+ export interface RegisterBuilderParams {
133
+ ownerAddress: string;
134
+ granteeAddress: string;
135
+ publicKey: string;
136
+ appUrl: string;
137
+ signature: string;
138
+ }
139
+ export interface RegisterBuilderResult {
140
+ builderId?: string;
141
+ alreadyRegistered: boolean;
142
+ }
143
+ export interface RegisterDataPointParams {
144
+ ownerAddress: string;
145
+ scope: string;
146
+ dataHash: string;
147
+ metadataHash: string;
148
+ expectedVersion: string;
149
+ signature: string;
150
+ }
151
+ export interface RegisterDataPointResult {
152
+ dataPointId?: string;
153
+ expectedVersion?: string;
154
+ }
155
+ export interface AccessRecord {
156
+ dataPointId: string;
157
+ version: string;
158
+ accessor: string;
159
+ recordId: string;
160
+ signature: string;
161
+ }
162
+ export interface PayForOperationParams {
163
+ payerAddress: string;
164
+ opType: string;
165
+ opId: string;
166
+ asset: string;
167
+ amount: string;
168
+ paymentNonce: string;
169
+ signature: string;
170
+ accessRecord?: AccessRecord;
171
+ }
172
+ export interface PayForOperationResult {
173
+ opType: string;
174
+ opId: string;
175
+ payerAddress: string;
176
+ asset: string;
177
+ amount: string;
178
+ breakdown: {
179
+ registrationFee: string;
180
+ dataAccessFee: string;
181
+ registrationPaid: boolean;
182
+ };
183
+ paymentNonce: string;
184
+ paidAt: string;
185
+ }
186
+ export type SettleOpType = "grant" | "server" | "data" | "access" | "builder" | "data-status";
187
+ export type SettleItem = {
188
+ opType: SettleOpType;
189
+ opId: string;
190
+ status: "submitting" | "confirmed";
191
+ settleTxHash: string | null;
192
+ settleSubmittedAt: string | null;
193
+ chainBlockHeight: string | null;
194
+ revocationTxHash: string | null;
195
+ revocationSubmittedAt: string | null;
196
+ placeholder: boolean;
197
+ } | {
198
+ opType: SettleOpType;
199
+ opId: string;
200
+ status: "skipped";
201
+ reason: string;
202
+ } | {
203
+ opType: SettleOpType;
204
+ opId: string;
205
+ status: "failed";
206
+ error: string;
207
+ };
208
+ export interface SettlePromoteResult {
209
+ opType: SettleOpType;
210
+ opId: string;
211
+ status: "confirmed" | "failed" | "pending" | "skipped";
212
+ txHash: string;
213
+ chainBlockHeight: string | null;
214
+ reason?: string;
215
+ }
216
+ export interface SettleReconcileItem {
217
+ opId: string;
218
+ status: "finalized" | "reorged" | "unchanged";
219
+ chainBlockHeight: string | null;
220
+ settleTxHash: string | null;
221
+ reason?: string;
222
+ }
223
+ export interface SettleParams {
224
+ limit?: number;
225
+ }
226
+ export interface SettleResult {
227
+ scanned: number;
228
+ submitted: number;
229
+ confirmed: number;
230
+ skipped: number;
231
+ failed: number;
232
+ items: SettleItem[];
233
+ promoted: {
234
+ count: number;
235
+ items: SettlePromoteResult[];
236
+ };
237
+ reconciled: {
238
+ scanned: number;
239
+ finalized: number;
240
+ reorged: number;
241
+ unchanged: number;
242
+ items: SettleReconcileItem[];
243
+ };
244
+ paced?: {
245
+ iterations: number;
246
+ };
247
+ }
248
+ export interface EscrowBalanceEntry {
249
+ asset: string;
250
+ balance: string;
251
+ pendingAmount: string;
252
+ authorizedAmount: string;
253
+ availableAmount: string;
254
+ updatedAt: string | null;
255
+ }
256
+ export interface EscrowDepositSubmitted {
257
+ txHash: string;
258
+ submittedAt: string;
259
+ claimedAsset: string;
260
+ claimedAmount: string;
261
+ }
262
+ export interface EscrowDepositFinalized {
263
+ txHash: string;
264
+ finalizedAt: string | null;
265
+ blockNumber: string | null;
266
+ claimedAsset: string;
267
+ claimedAmount: string;
268
+ }
269
+ export interface EscrowDepositFailed {
270
+ txHash: string;
271
+ submittedAt: string;
272
+ claimedAsset: string;
273
+ claimedAmount: string;
274
+ lastError: string | null;
275
+ }
276
+ export interface EscrowBalance {
277
+ account: string;
278
+ balances: EscrowBalanceEntry[];
279
+ deposits: {
280
+ submitted: EscrowDepositSubmitted[];
281
+ finalized: EscrowDepositFinalized[];
282
+ failed: EscrowDepositFailed[];
283
+ };
284
+ }
285
+ export interface SubmitDepositParams {
286
+ txHash: string;
287
+ }
288
+ export interface DepositState {
289
+ txHash: string;
290
+ account: string;
291
+ status: string;
292
+ blockNumber: string | null;
293
+ submittedAt: string;
294
+ finalizedAt: string | null;
295
+ lastError: string | null;
296
+ }
136
297
  export interface GatewayClient {
137
298
  isRegisteredBuilder(address: string): Promise<boolean>;
138
299
  getBuilder(address: string): Promise<Builder | null>;
@@ -140,23 +301,28 @@ export interface GatewayClient {
140
301
  listGrantsByUser(userAddress: string): Promise<GrantListItem[]>;
141
302
  getSchemaForScope(scope: string): Promise<Schema | null>;
142
303
  getServer(address: string): Promise<ServerInfo | null>;
143
- getFile(fileId: string): Promise<FileRecord | null>;
144
- listFilesSince(owner: string, cursor: string | null, options?: ListFilesOptions): Promise<FileListResult>;
304
+ /**
305
+ * Fetch a single data point by its deterministic id (keccak256 of (owner, scope)).
306
+ * Returns null on 404. The gateway omits `status` from the response body — read it
307
+ * from the on-chain DataRegistryV2 contract when you need the canonical lifecycle state.
308
+ */
309
+ getDataPoint(dataPointId: string): Promise<DataPointRecord | null>;
310
+ /**
311
+ * Page through an owner's data points. Cursor is opaque; pass `null` for the first
312
+ * page and feed back `result.cursor` until it returns null.
313
+ */
314
+ listDataPointsByOwner(owner: string, cursor: string | null, options?: ListDataPointsOptions): Promise<DataPointListResult>;
145
315
  getSchema(schemaId: string): Promise<Schema | null>;
146
316
  registerServer(params: RegisterServerParams): Promise<RegisterServerResult>;
147
- registerFile(params: RegisterFileParams): Promise<{
148
- fileId?: string;
149
- }>;
317
+ registerBuilder(params: RegisterBuilderParams): Promise<RegisterBuilderResult>;
318
+ registerDataPoint(params: RegisterDataPointParams): Promise<RegisterDataPointResult>;
150
319
  createGrant(params: CreateGrantParams): Promise<{
151
320
  grantId?: string;
152
321
  }>;
153
322
  revokeGrant(params: RevokeGrantParams): Promise<void>;
154
- /**
155
- * Soft-deletes (de-registers) a file at the gateway. Resolves on 200 and on 409
156
- * (already deleted) — 409 is treated as idempotent success. Other non-2xx, including
157
- * 404 (file not registered), throw; the PS delete cascade decides whether a 404 is
158
- * benign (blob already gone) or a hard failure.
159
- */
160
- deleteFile(params: DeleteFileParams): Promise<void>;
323
+ getEscrowBalance(account: string): Promise<EscrowBalance>;
324
+ submitEscrowDeposit(params: SubmitDepositParams): Promise<DepositState>;
325
+ payForOperation(params: PayForOperationParams): Promise<PayForOperationResult>;
326
+ settle(params?: SettleParams): Promise<SettleResult>;
161
327
  }
162
328
  export declare function createGatewayClient(baseUrl: string): GatewayClient;
@@ -4,16 +4,6 @@ function createGatewayClient(baseUrl) {
4
4
  const envelope = await res.json();
5
5
  return envelope.data;
6
6
  }
7
- function normalizeFileRecord(record) {
8
- return {
9
- fileId: record.fileId ?? record.id ?? "",
10
- owner: record.owner ?? record.ownerAddress ?? "",
11
- url: record.url,
12
- schemaId: record.schemaId,
13
- createdAt: record.createdAt ?? record.addedAt ?? "",
14
- deletedAt: record.deletedAt ?? null
15
- };
16
- }
17
7
  function getMutationId(body, key) {
18
8
  const value = body[key] ?? body["id"];
19
9
  return typeof value === "string" ? value : void 0;
@@ -63,31 +53,33 @@ function createGatewayClient(baseUrl) {
63
53
  }
64
54
  return unwrapEnvelope(res);
65
55
  },
66
- async getFile(fileId) {
67
- const res = await fetch(`${base}/v1/files/${fileId}`);
56
+ async getDataPoint(dataPointId) {
57
+ const res = await fetch(`${base}/v1/data/${dataPointId}`);
68
58
  if (res.status === 404) return null;
69
59
  if (!res.ok) {
70
60
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
71
61
  }
72
- return normalizeFileRecord(await unwrapEnvelope(res));
62
+ return unwrapEnvelope(res);
73
63
  },
74
- async listFilesSince(owner, cursor, options) {
64
+ async listDataPointsByOwner(owner, cursor, options) {
75
65
  const params = new URLSearchParams({ user: owner });
76
66
  if (cursor !== null) {
77
67
  params.set("cursor", cursor);
78
68
  }
79
- if (options?.includeDeleted) {
80
- params.set("includeDeleted", "true");
69
+ if (options?.since) {
70
+ params.set("since", options.since);
71
+ }
72
+ if (options?.limit !== void 0) {
73
+ params.set("limit", String(options.limit));
81
74
  }
82
- const res = await fetch(`${base}/v1/files?${params.toString()}`);
75
+ const res = await fetch(`${base}/v1/data?${params.toString()}`);
83
76
  if (!res.ok) {
84
77
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
85
78
  }
86
79
  const envelope = await res.json();
87
- const { pagination } = envelope;
88
- const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
80
+ const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
89
81
  return {
90
- files: envelope.data.files.map(normalizeFileRecord),
82
+ dataPoints: envelope.data.dataPoints,
91
83
  cursor: nextCursor
92
84
  };
93
85
  },
@@ -129,8 +121,8 @@ function createGatewayClient(baseUrl) {
129
121
  alreadyRegistered: false
130
122
  };
131
123
  },
132
- async registerFile(params) {
133
- const res = await fetch(`${base}/v1/files`, {
124
+ async registerBuilder(params) {
125
+ const res = await fetch(`${base}/v1/builders`, {
134
126
  method: "POST",
135
127
  headers: {
136
128
  "Content-Type": "application/json",
@@ -138,22 +130,57 @@ function createGatewayClient(baseUrl) {
138
130
  },
139
131
  body: JSON.stringify({
140
132
  ownerAddress: params.ownerAddress,
141
- url: params.url,
142
- schemaId: params.schemaId
133
+ granteeAddress: params.granteeAddress,
134
+ publicKey: params.publicKey,
135
+ appUrl: params.appUrl
143
136
  })
144
137
  });
145
138
  if (res.status === 409) {
146
139
  const body2 = await res.json().catch(() => ({}));
147
140
  return {
148
- fileId: getMutationId(body2, "fileId")
141
+ builderId: getMutationId(
142
+ body2,
143
+ "builderId"
144
+ ),
145
+ alreadyRegistered: true
149
146
  };
150
147
  }
151
148
  if (!res.ok) {
152
149
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
153
150
  }
154
- const body = await res.json();
151
+ const body = await res.json().catch(() => ({}));
152
+ return {
153
+ builderId: getMutationId(body, "builderId"),
154
+ alreadyRegistered: false
155
+ };
156
+ },
157
+ async registerDataPoint(params) {
158
+ const res = await fetch(`${base}/v1/data`, {
159
+ method: "POST",
160
+ headers: {
161
+ "Content-Type": "application/json",
162
+ Authorization: `Web3Signed ${params.signature}`
163
+ },
164
+ body: JSON.stringify({
165
+ ownerAddress: params.ownerAddress,
166
+ scope: params.scope,
167
+ dataHash: params.dataHash,
168
+ metadataHash: params.metadataHash,
169
+ expectedVersion: params.expectedVersion
170
+ })
171
+ });
172
+ if (!res.ok) {
173
+ const body2 = await res.json().catch(() => ({}));
174
+ const detail = body2.error ?? res.statusText;
175
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
176
+ }
177
+ const body = await res.json().catch(() => ({}));
155
178
  return {
156
- fileId: getMutationId(body, "fileId")
179
+ dataPointId: getMutationId(
180
+ body,
181
+ "dataPointId"
182
+ ),
183
+ expectedVersion: body.expectedVersion
157
184
  };
158
185
  },
159
186
  async createGrant(params) {
@@ -166,8 +193,9 @@ function createGatewayClient(baseUrl) {
166
193
  body: JSON.stringify({
167
194
  grantorAddress: params.grantorAddress,
168
195
  granteeId: params.granteeId,
169
- grant: params.grant,
170
- fileIds: params.fileIds
196
+ scopes: params.scopes,
197
+ grantVersion: params.grantVersion,
198
+ expiresAt: params.expiresAt
171
199
  })
172
200
  });
173
201
  if (res.status === 409) {
@@ -192,7 +220,8 @@ function createGatewayClient(baseUrl) {
192
220
  Authorization: `Web3Signed ${params.signature}`
193
221
  },
194
222
  body: JSON.stringify({
195
- grantorAddress: params.grantorAddress
223
+ grantorAddress: params.grantorAddress,
224
+ grantVersion: params.grantVersion
196
225
  })
197
226
  });
198
227
  if (res.status === 409) return;
@@ -200,21 +229,62 @@ function createGatewayClient(baseUrl) {
200
229
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
201
230
  }
202
231
  },
203
- async deleteFile(params) {
204
- const res = await fetch(`${base}/v1/files/${params.fileId}`, {
205
- method: "DELETE",
232
+ async getEscrowBalance(account) {
233
+ const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
234
+ if (!res.ok) {
235
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
236
+ }
237
+ return await res.json();
238
+ },
239
+ async submitEscrowDeposit(params) {
240
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
241
+ method: "POST",
242
+ headers: { "Content-Type": "application/json" },
243
+ body: JSON.stringify({ txHash: params.txHash })
244
+ });
245
+ if (res.status !== 200 && res.status !== 202) {
246
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
247
+ }
248
+ return await res.json();
249
+ },
250
+ async payForOperation(params) {
251
+ const body = {
252
+ payerAddress: params.payerAddress,
253
+ opType: params.opType,
254
+ opId: params.opId,
255
+ asset: params.asset,
256
+ amount: params.amount,
257
+ paymentNonce: params.paymentNonce
258
+ };
259
+ if (params.accessRecord) {
260
+ body["accessRecord"] = params.accessRecord;
261
+ }
262
+ const res = await fetch(`${base}/v1/escrow/pay`, {
263
+ method: "POST",
206
264
  headers: {
207
265
  "Content-Type": "application/json",
208
266
  Authorization: `Web3Signed ${params.signature}`
209
267
  },
210
- body: JSON.stringify({
211
- ownerAddress: params.ownerAddress
212
- })
268
+ body: JSON.stringify(body)
269
+ });
270
+ if (!res.ok) {
271
+ throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
272
+ }
273
+ return await res.json();
274
+ },
275
+ async settle(params) {
276
+ const res = await fetch(`${base}/v1/settle`, {
277
+ method: "POST",
278
+ headers: { "Content-Type": "application/json" },
279
+ // The gateway accepts an empty body; only `limit` is recognised.
280
+ // Always send a JSON body so the gateway's req.body shape parse
281
+ // doesn't have to deal with an undefined.
282
+ body: JSON.stringify(params ?? {})
213
283
  });
214
- if (res.status === 409) return;
215
284
  if (!res.ok) {
216
285
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
217
286
  }
287
+ return await res.json();
218
288
  }
219
289
  };
220
290
  }