@opendatalabs/vana-sdk 3.17.0 → 3.18.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 (47) hide show
  1. package/dist/direct/personal-server-read.cjs +20 -1
  2. package/dist/direct/personal-server-read.cjs.map +1 -1
  3. package/dist/direct/personal-server-read.js +23 -1
  4. package/dist/direct/personal-server-read.js.map +1 -1
  5. package/dist/errors.cjs +27 -0
  6. package/dist/errors.cjs.map +1 -1
  7. package/dist/errors.d.ts +67 -0
  8. package/dist/errors.js +24 -0
  9. package/dist/errors.js.map +1 -1
  10. package/dist/index.browser.d.ts +2 -1
  11. package/dist/index.browser.js +724 -309
  12. package/dist/index.browser.js.map +4 -4
  13. package/dist/index.node.cjs +736 -311
  14. package/dist/index.node.cjs.map +4 -4
  15. package/dist/index.node.d.ts +2 -1
  16. package/dist/index.node.js +724 -309
  17. package/dist/index.node.js.map +4 -4
  18. package/dist/protocol/data-point-deletion.cjs +220 -0
  19. package/dist/protocol/data-point-deletion.cjs.map +1 -0
  20. package/dist/protocol/data-point-deletion.d.ts +180 -0
  21. package/dist/protocol/data-point-deletion.js +193 -0
  22. package/dist/protocol/data-point-deletion.js.map +1 -0
  23. package/dist/protocol/data-point-deletion.test.d.ts +1 -0
  24. package/dist/protocol/gateway.cjs +145 -32
  25. package/dist/protocol/gateway.cjs.map +1 -1
  26. package/dist/protocol/gateway.d.ts +42 -3
  27. package/dist/protocol/gateway.js +156 -32
  28. package/dist/protocol/gateway.js.map +1 -1
  29. package/dist/protocol/personal-server-data.cjs +20 -1
  30. package/dist/protocol/personal-server-data.cjs.map +1 -1
  31. package/dist/protocol/personal-server-data.js +23 -1
  32. package/dist/protocol/personal-server-data.js.map +1 -1
  33. package/dist/storage/index.cjs.map +1 -1
  34. package/dist/storage/index.d.ts +1 -1
  35. package/dist/storage/index.js.map +1 -1
  36. package/dist/storage/providers/vana-storage.cjs +66 -0
  37. package/dist/storage/providers/vana-storage.cjs.map +1 -1
  38. package/dist/storage/providers/vana-storage.d.ts +26 -0
  39. package/dist/storage/providers/vana-storage.js +66 -0
  40. package/dist/storage/providers/vana-storage.js.map +1 -1
  41. package/dist/utils/response-body.cjs +46 -0
  42. package/dist/utils/response-body.cjs.map +1 -0
  43. package/dist/utils/response-body.d.ts +26 -0
  44. package/dist/utils/response-body.js +20 -0
  45. package/dist/utils/response-body.js.map +1 -0
  46. package/dist/utils/response-body.test.d.ts +1 -0
  47. package/package.json +1 -1
@@ -1358,6 +1358,27 @@ var LineageReadError = class extends VanaError {
1358
1358
  errorCode;
1359
1359
  details;
1360
1360
  };
1361
+ var DataPointDeletedError = class extends VanaError {
1362
+ constructor(message, details = {}) {
1363
+ super(message, "DATA_POINT_DELETED");
1364
+ this.details = details;
1365
+ }
1366
+ details;
1367
+ };
1368
+ var DataPointNotFoundError = class extends VanaError {
1369
+ constructor(message, details = {}) {
1370
+ super(message, "DATA_POINT_NOT_FOUND");
1371
+ this.details = details;
1372
+ }
1373
+ details;
1374
+ };
1375
+ var DataPointVersionConflictError = class extends VanaError {
1376
+ constructor(message, details = {}) {
1377
+ super(message, "DATA_POINT_VERSION_CONFLICT");
1378
+ this.details = details;
1379
+ }
1380
+ details;
1381
+ };
1361
1382
 
1362
1383
  // src/contracts/contractController.ts
1363
1384
  import {
@@ -29120,6 +29141,22 @@ function getProtocolNetworkChainId(network) {
29120
29141
  return PROTOCOL_NETWORK_CHAIN_IDS[network];
29121
29142
  }
29122
29143
 
29144
+ // src/utils/response-body.ts
29145
+ function isPlainObject(value) {
29146
+ return typeof value === "object" && value !== null && !Array.isArray(value);
29147
+ }
29148
+ async function readJsonValue(res) {
29149
+ try {
29150
+ return await res.json();
29151
+ } catch {
29152
+ return null;
29153
+ }
29154
+ }
29155
+ async function readJsonObject(res) {
29156
+ const value = await readJsonValue(res);
29157
+ return isPlainObject(value) ? value : {};
29158
+ }
29159
+
29123
29160
  // src/storage/providers/vana-storage.ts
29124
29161
  var DEFAULT_ENDPOINT = "https://storage.vana.org";
29125
29162
  var LEGACY_BLOB_PATH_PREFIX = "/v1/blobs";
@@ -29291,6 +29328,65 @@ var VanaStorage = class {
29291
29328
  }
29292
29329
  return true;
29293
29330
  }
29331
+ /**
29332
+ * Delete every version's blob under `(owner, scope)` --
29333
+ * `DELETE {prefix}/{owner}/{scope}` on vana-storage, signed with the same
29334
+ * Web3Signed header as uploads (aud = endpoint origin, empty bodyHash).
29335
+ * The worker accepts the owner's own signature or a personal server the
29336
+ * owner registered with the gateway.
29337
+ *
29338
+ * @param ownerAddress - Must equal the provider's configured owner; a
29339
+ * mismatch throws before anything is signed so this wallet can never be
29340
+ * induced to sign a delete for another namespace.
29341
+ * @param scope - The scope segment, e.g. `"instagram.profile"`.
29342
+ */
29343
+ async deleteScope(ownerAddress, scope) {
29344
+ if (ownerAddress.toLowerCase() !== this.ownerAddress) {
29345
+ throw new StorageError(
29346
+ `deleteScope owner '${ownerAddress}' does not match the configured owner '${this.ownerAddress}'`,
29347
+ "INVALID_OWNER",
29348
+ "vana-storage"
29349
+ );
29350
+ }
29351
+ if (scope.length === 0 || scope.includes("/") || isTraversalSegment(scope)) {
29352
+ throw new StorageError(
29353
+ `scope must be a single non-empty path segment, got '${scope}'`,
29354
+ "INVALID_SCOPE",
29355
+ "vana-storage"
29356
+ );
29357
+ }
29358
+ const path = `${this.blobPathPrefix}/${this.ownerAddress}/${encodeURIComponent(scope)}`;
29359
+ const header = await this.signRequest("DELETE", path);
29360
+ let response;
29361
+ try {
29362
+ response = await this.fetchImpl(`${this.endpoint}${path}`, {
29363
+ method: "DELETE",
29364
+ headers: { authorization: header }
29365
+ });
29366
+ } catch (cause) {
29367
+ throw new StorageError(
29368
+ `vana-storage scope delete network error: ${describe(cause)}`,
29369
+ "DELETE_ERROR",
29370
+ "vana-storage",
29371
+ { cause: cause instanceof Error ? cause : void 0 }
29372
+ );
29373
+ }
29374
+ if (!response.ok) {
29375
+ const responseText = await safeText(response);
29376
+ throw new StorageError(
29377
+ `vana-storage scope delete failed: ${response.status} ${response.statusText} - ${responseText}`,
29378
+ "DELETE_FAILED",
29379
+ "vana-storage"
29380
+ );
29381
+ }
29382
+ const body = await readJsonObject(response);
29383
+ return {
29384
+ deleted: typeof body["deleted"] === "boolean" ? body["deleted"] : true,
29385
+ scope: typeof body["scope"] === "string" ? body["scope"] : scope,
29386
+ count: nonNegativeInteger(body["count"]) ?? 0,
29387
+ totalBytes: nonNegativeInteger(body["totalBytes"]) ?? 0
29388
+ };
29389
+ }
29294
29390
  getConfig() {
29295
29391
  return {
29296
29392
  name: "vana-storage",
@@ -29419,6 +29515,12 @@ function encodeRelativePath(filename) {
29419
29515
  }
29420
29516
  return parts.map((p) => encodeURIComponent(p)).join("/");
29421
29517
  }
29518
+ function isTraversalSegment(segment) {
29519
+ return segment === "." || segment === "..";
29520
+ }
29521
+ function nonNegativeInteger(value) {
29522
+ return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
29523
+ }
29422
29524
  function describe(value) {
29423
29525
  if (value instanceof Error) return value.message;
29424
29526
  return String(value);
@@ -33532,266 +33634,13 @@ function buildMarkDataPointUnavailableRequest(config, input) {
33532
33634
  });
33533
33635
  }
33534
33636
 
33535
- // src/protocol/data-file.ts
33536
- import { z } from "zod";
33537
- var DataFileEnvelopeSchema = z.object({
33538
- $schema: z.string().url().optional(),
33539
- version: z.literal("1.0"),
33540
- scope: z.string(),
33541
- schemaId: z.string().optional(),
33542
- collectedAt: z.string().datetime(),
33543
- data: z.record(z.string(), z.unknown())
33544
- });
33545
- function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
33546
- return {
33547
- ...schemaUrl !== void 0 && { $schema: schemaUrl },
33548
- ...schemaId !== void 0 && { schemaId },
33549
- version: "1.0",
33550
- scope,
33551
- collectedAt,
33552
- data
33553
- };
33554
- }
33555
- var IngestResponseSchema = z.object({
33556
- scope: z.string(),
33557
- collectedAt: z.string().datetime(),
33558
- status: z.enum(["stored", "syncing"])
33559
- });
33560
-
33561
- // src/protocol/personal-server-data.ts
33562
- function personalServerDataReadPath(scope) {
33563
- return `/v1/data/${encodeURIComponent(scope)}`;
33564
- }
33565
- async function buildPersonalServerDataReadRequest(params) {
33566
- const path = personalServerDataReadPath(params.scope);
33567
- const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
33568
- const audience = params.audience ?? baseUrl;
33569
- const headers = new Headers(params.headers);
33570
- headers.set(
33571
- "Authorization",
33572
- await buildWeb3SignedHeader({
33573
- aud: audience,
33574
- grantId: params.grantId,
33575
- method: "GET",
33576
- signMessage: params.signMessage,
33577
- uri: path
33578
- })
33579
- );
33580
- return new Request(`${baseUrl}${path}`, {
33581
- headers,
33582
- method: "GET"
33583
- });
33584
- }
33585
- async function readPersonalServerData(params) {
33586
- const fetchFn = params.fetch ?? globalThis.fetch;
33587
- if (fetchFn === void 0) {
33588
- throw new Error("No fetch implementation available");
33589
- }
33590
- const request = await buildPersonalServerDataReadRequest(params);
33591
- const response = await fetchFn(request);
33592
- if (!response.ok) {
33593
- throw new Error(
33594
- `Personal Server data read failed: ${response.status} ${response.statusText}`
33595
- );
33596
- }
33597
- return DataFileEnvelopeSchema.parse(await response.json());
33598
- }
33599
-
33600
- // src/protocol/scopes.ts
33601
- import { z as z2 } from "zod";
33602
- var SOURCE_RE = /^[a-z0-9][a-z0-9_]*$/;
33603
- var TAIL_SEGMENT_RE = /^[a-zA-Z0-9][a-zA-Z0-9_]*$/;
33604
- var ScopeSchema = z2.string().refine(
33605
- (scope) => {
33606
- const parts = scope.split(".");
33607
- if (parts.length < 2 || parts.length > 3) return false;
33608
- const [source, ...tail] = parts;
33609
- return SOURCE_RE.test(source) && tail.every((part) => TAIL_SEGMENT_RE.test(part));
33610
- },
33611
- {
33612
- message: "Scope must be {source}.{category}[.{subcategory}]; source lowercase, tail may keep the historical camelCase form (e.g. spotify.savedTracks)"
33613
- }
33614
- );
33615
- function parseScope(scope) {
33616
- const validated = ScopeSchema.parse(scope);
33617
- const parts = validated.split(".");
33618
- return {
33619
- source: parts[0],
33620
- category: parts[1],
33621
- subcategory: parts[2],
33622
- raw: validated
33623
- };
33624
- }
33625
- function scopeToPathSegments(scope) {
33626
- const parsed = parseScope(scope);
33627
- const segments = [parsed.source, parsed.category];
33628
- if (parsed.subcategory) {
33629
- segments.push(parsed.subcategory);
33630
- }
33631
- return segments;
33632
- }
33633
- function scopeMatchesPattern(requestedScope, grantPattern) {
33634
- if (grantPattern === "*") return true;
33635
- if (grantPattern.endsWith(".*")) {
33636
- const prefix = grantPattern.slice(0, -1);
33637
- return requestedScope.startsWith(prefix);
33638
- }
33639
- return requestedScope === grantPattern;
33640
- }
33641
- function scopeCoveredByGrant(requestedScope, grantedScopes) {
33642
- return grantedScopes.some(
33643
- (pattern) => scopeMatchesPattern(requestedScope, pattern)
33644
- );
33645
- }
33646
-
33647
- // src/protocol/scope-actions.ts
33648
- var SCOPE_ACTIONS = ["read", "write"];
33649
- var InvalidScopeEntryError = class extends Error {
33650
- /** The offending entry, verbatim (unknown because it may not be a string). */
33651
- entry;
33652
- constructor(entry, reason) {
33653
- super(`Invalid scope entry ${describeValue(entry)}: ${reason}`);
33654
- this.name = "InvalidScopeEntryError";
33655
- this.entry = entry;
33656
- }
33657
- };
33658
- var OPERATION_SEPARATOR = ":";
33659
- function describeValue(value) {
33660
- if (typeof value === "string") return JSON.stringify(value);
33661
- if (value === null) return "null";
33662
- return `[${typeof value}]`;
33663
- }
33664
- var OPERATION_BY_PREFIX = {
33665
- write: "write"
33666
- };
33667
- function assertScopePart(entry, scope) {
33668
- if (scope.length === 0) {
33669
- throw new InvalidScopeEntryError(entry, "scope part is empty");
33670
- }
33671
- if (scope.includes(OPERATION_SEPARATOR)) {
33672
- throw new InvalidScopeEntryError(
33673
- entry,
33674
- `scope part must not contain "${OPERATION_SEPARATOR}"`
33675
- );
33676
- }
33677
- }
33678
- function parseScopeEntry(entry) {
33679
- const raw = entry;
33680
- if (typeof raw !== "string") {
33681
- throw new InvalidScopeEntryError(raw, "entry must be a string");
33682
- }
33683
- const separatorIndex = entry.indexOf(OPERATION_SEPARATOR);
33684
- if (separatorIndex === -1) {
33685
- assertScopePart(entry, entry);
33686
- return { scope: entry, action: "read" };
33687
- }
33688
- const prefix = entry.slice(0, separatorIndex);
33689
- const scope = entry.slice(separatorIndex + 1);
33690
- const action = Object.hasOwn(OPERATION_BY_PREFIX, prefix) ? OPERATION_BY_PREFIX[prefix] : void 0;
33691
- if (action === void 0) {
33692
- throw new InvalidScopeEntryError(
33693
- entry,
33694
- `unknown operation "${prefix}" (known: ${Object.keys(OPERATION_BY_PREFIX).join(", ")}; read has no prefix)`
33695
- );
33696
- }
33697
- assertScopePart(entry, scope);
33698
- return { scope, action };
33699
- }
33700
- function formatScopeEntry(parsed) {
33701
- const { scope, action } = parsed;
33702
- assertScopePart(scope, scope);
33703
- if (action === "read") return scope;
33704
- const prefix = Object.entries(OPERATION_BY_PREFIX).find(
33705
- ([, candidate]) => candidate === action
33706
- )?.[0];
33707
- if (prefix === void 0) {
33708
- throw new InvalidScopeEntryError(
33709
- scope,
33710
- `unknown action ${describeValue(action)} (known: ${SCOPE_ACTIONS.join(", ")})`
33711
- );
33712
- }
33713
- return `${prefix}${OPERATION_SEPARATOR}${scope}`;
33714
- }
33715
- function compareScopes(a, b) {
33716
- if (a < b) return -1;
33717
- if (a > b) return 1;
33718
- return 0;
33719
- }
33720
- function sortActions(actions) {
33721
- const present = new Set(actions);
33722
- return SCOPE_ACTIONS.filter((action) => present.has(action));
33723
- }
33724
- function grantPermissions(scopes) {
33725
- const byScope = /* @__PURE__ */ new Map();
33726
- for (const entry of scopes) {
33727
- const { scope, action } = parseScopeEntry(entry);
33728
- let actions = byScope.get(scope);
33729
- if (actions === void 0) {
33730
- actions = /* @__PURE__ */ new Set();
33731
- byScope.set(scope, actions);
33732
- }
33733
- actions.add(action);
33734
- }
33735
- return [...byScope.keys()].sort(compareScopes).map((scope) => ({
33736
- scope,
33737
- actions: sortActions(byScope.get(scope) ?? [])
33738
- }));
33739
- }
33740
- function permissionsToScopes(permissions) {
33741
- const byScope = /* @__PURE__ */ new Map();
33742
- for (const { scope, actions } of permissions) {
33743
- let merged = byScope.get(scope);
33744
- if (merged === void 0) {
33745
- merged = /* @__PURE__ */ new Set();
33746
- byScope.set(scope, merged);
33747
- }
33748
- for (const action of actions) {
33749
- if (!SCOPE_ACTIONS.includes(action)) {
33750
- throw new InvalidScopeEntryError(
33751
- scope,
33752
- `unknown action ${describeValue(action)} (known: ${SCOPE_ACTIONS.join(", ")})`
33753
- );
33754
- }
33755
- merged.add(action);
33756
- }
33757
- }
33758
- const entries = [];
33759
- for (const scope of [...byScope.keys()].sort(compareScopes)) {
33760
- for (const action of sortActions(byScope.get(scope) ?? [])) {
33761
- entries.push(formatScopeEntry({ scope, action }));
33762
- }
33763
- }
33764
- return entries;
33765
- }
33766
- function hasAction(scopes, scope, action) {
33767
- if (scope.includes(OPERATION_SEPARATOR)) return false;
33768
- for (const entry of scopes) {
33769
- let parsed;
33770
- try {
33771
- parsed = parseScopeEntry(entry);
33772
- } catch (error) {
33773
- if (error instanceof InvalidScopeEntryError) continue;
33774
- throw error;
33775
- }
33776
- if (parsed.action === action && scopeMatchesPattern(scope, parsed.scope)) {
33777
- return true;
33778
- }
33779
- }
33780
- return false;
33781
- }
33782
- function tryGrantPermissions(scopes) {
33783
- try {
33784
- return grantPermissions(scopes);
33785
- } catch (error) {
33786
- if (error instanceof InvalidScopeEntryError) return void 0;
33787
- throw error;
33788
- }
33789
- }
33790
-
33791
- // src/protocol/personal-server-write.ts
33792
- import { sha256 as sha2565 } from "@noble/hashes/sha2";
33793
- import { bytesToHex as bytesToHex2, isAddress as isAddress5 } from "viem";
33794
- import { z as z4 } from "zod";
33637
+ // src/protocol/data-point-deletion.ts
33638
+ import {
33639
+ isAddress as isAddress5,
33640
+ keccak256 as keccak2562,
33641
+ maxUint256,
33642
+ stringToBytes as stringToBytes3
33643
+ } from "viem";
33795
33644
 
33796
33645
  // src/protocol/lineage.ts
33797
33646
  import {
@@ -33799,7 +33648,7 @@ import {
33799
33648
  isAddress as isAddress4,
33800
33649
  keccak256
33801
33650
  } from "viem";
33802
- import { z as z3 } from "zod";
33651
+ import { z } from "zod";
33803
33652
 
33804
33653
  // src/protocol/personal-server-error-body.ts
33805
33654
  function isRecord2(value) {
@@ -33891,10 +33740,10 @@ function deriveDataPointId(ownerAddress, scope) {
33891
33740
  )
33892
33741
  );
33893
33742
  }
33894
- var DataPointIdSchema = z3.string().regex(DATA_POINT_ID_PATTERN).transform((value) => value.toLowerCase());
33743
+ var DataPointIdSchema = z.string().regex(DATA_POINT_ID_PATTERN).transform((value) => value.toLowerCase());
33895
33744
  var VERSION_PATTERN = /^[1-9]\d*$/;
33896
33745
  var NODE_VERSION_PATTERN = /^(0|[1-9]\d*)$/;
33897
- var VersionSchema = z3.union([z3.string(), z3.number()]).transform(String).refine((value) => NODE_VERSION_PATTERN.test(value), {
33746
+ var VersionSchema = z.union([z.string(), z.number()]).transform(String).refine((value) => NODE_VERSION_PATTERN.test(value), {
33898
33747
  message: "version must be a decimal integer"
33899
33748
  });
33900
33749
  var ViewVersionSchema = VersionSchema.refine(
@@ -33918,41 +33767,41 @@ function assertDerivedScopeNaming(derivedScope, sourceScopes) {
33918
33767
  }
33919
33768
  }
33920
33769
  }
33921
- var LineageNodeSchema = z3.object({
33770
+ var LineageNodeSchema = z.object({
33922
33771
  dataPointId: DataPointIdSchema,
33923
- scope: z3.string(),
33772
+ scope: z.string(),
33924
33773
  /**
33925
33774
  * The node's current version, decimal string; `"0"` for a source that no
33926
33775
  * longer resolves to a registered data point.
33927
33776
  */
33928
33777
  version: VersionSchema,
33929
33778
  /** The node's tombstone time, or `null` when live. */
33930
- deletedAt: z3.string().nullable()
33779
+ deletedAt: z.string().nullable()
33931
33780
  });
33932
- var RedactedLineageNodeSchema = z3.object({
33781
+ var RedactedLineageNodeSchema = z.object({
33933
33782
  dataPointId: DataPointIdSchema,
33934
- redacted: z3.literal(true)
33783
+ redacted: z.literal(true)
33935
33784
  });
33936
- var LineageEntrySchema = z3.union([
33785
+ var LineageEntrySchema = z.union([
33937
33786
  RedactedLineageNodeSchema,
33938
33787
  LineageNodeSchema
33939
33788
  ]);
33940
- var LineageGraphSchema = z3.object({
33789
+ var LineageGraphSchema = z.object({
33941
33790
  dataPointId: DataPointIdSchema,
33942
33791
  /** The data point owner; every node in the view belongs to it. */
33943
- ownerAddress: z3.string().optional(),
33944
- scope: z3.string(),
33792
+ ownerAddress: z.string().optional(),
33793
+ scope: z.string(),
33945
33794
  /**
33946
33795
  * The derived record's version whose lineage is shown: the requested one,
33947
33796
  * else the current one, else (current is a tombstone) the last version
33948
33797
  * that carried lineage.
33949
33798
  */
33950
33799
  version: ViewVersionSchema,
33951
- deletedAt: z3.string().nullable(),
33952
- sources: z3.array(LineageEntrySchema),
33953
- derivatives: z3.array(LineageEntrySchema),
33800
+ deletedAt: z.string().nullable(),
33801
+ sources: z.array(LineageEntrySchema),
33802
+ derivatives: z.array(LineageEntrySchema),
33954
33803
  /** `true` when `derivatives` was cut at the server's cap (1000). */
33955
- derivativesTruncated: z3.boolean().optional()
33804
+ derivativesTruncated: z.boolean().optional()
33956
33805
  });
33957
33806
  function isRedactedLineageNode(entry) {
33958
33807
  return "redacted" in entry && entry.redacted === true;
@@ -34097,7 +33946,449 @@ function getLineage(params) {
34097
33946
  return "personalServerUrl" in params ? getPersonalServerLineage(params) : getGatewayLineage(params);
34098
33947
  }
34099
33948
 
33949
+ // src/protocol/data-point-deletion.ts
33950
+ var TOMBSTONE_DATA_HASH_PREIMAGE = "vana.data-point.tombstone.v1";
33951
+ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
33952
+ var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
33953
+ var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
33954
+ function computeTombstoneHash(preimage) {
33955
+ return keccak2562(stringToBytes3(preimage));
33956
+ }
33957
+ function isTombstoneHashes(dataHash, metadataHash) {
33958
+ return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
33959
+ }
33960
+ function isDataPointTombstone(value) {
33961
+ if (!isPlainObject(value)) return false;
33962
+ if (typeof value["deletedAt"] === "string") return true;
33963
+ return isTombstoneHashes(
33964
+ typeof value["dataHash"] === "string" ? value["dataHash"] : void 0,
33965
+ typeof value["metadataHash"] === "string" ? value["metadataHash"] : void 0
33966
+ );
33967
+ }
33968
+ function tombstoneDeletedAt(value) {
33969
+ if (!isPlainObject(value)) return null;
33970
+ const deletedAt = value["deletedAt"];
33971
+ return typeof deletedAt === "string" ? deletedAt : null;
33972
+ }
33973
+ function assertAddress4(value, name) {
33974
+ if (!isAddress5(value)) {
33975
+ throw new Error(`${name} must be a valid EVM address`);
33976
+ }
33977
+ }
33978
+ function assertUint256(value, name) {
33979
+ if (value < 0n || value > maxUint256) {
33980
+ throw new Error(`${name} must fit in uint256, got ${value}`);
33981
+ }
33982
+ }
33983
+ function getAccountAddress3(account) {
33984
+ if (!account) return void 0;
33985
+ return typeof account === "string" ? account : account.address;
33986
+ }
33987
+ function isDataPointDeletionSigner(source) {
33988
+ return "address" in source && typeof source.signTypedData === "function";
33989
+ }
33990
+ function createViemDataPointDeletionSigner(source, options = {}) {
33991
+ if (isDataPointDeletionSigner(source)) {
33992
+ return source;
33993
+ }
33994
+ const accountAddress2 = getAccountAddress3(options.account) ?? getAccountAddress3(source.account);
33995
+ if (accountAddress2) {
33996
+ return {
33997
+ address: accountAddress2,
33998
+ signTypedData: (typedData) => source.signTypedData({
33999
+ ...typedData,
34000
+ account: options.account ?? source.account ?? accountAddress2
34001
+ })
34002
+ };
34003
+ }
34004
+ throw new Error(
34005
+ "Viem wallet client requires an account option or account property"
34006
+ );
34007
+ }
34008
+ function buildDataPointDeletionTypedData(input) {
34009
+ assertAddress4(input.ownerAddress, "ownerAddress");
34010
+ if (input.scope.length === 0) {
34011
+ throw new Error("scope must be a non-empty string");
34012
+ }
34013
+ if (input.expectedVersion <= 0n) {
34014
+ throw new Error("expectedVersion must be a positive version number");
34015
+ }
34016
+ assertUint256(input.expectedVersion, "expectedVersion");
34017
+ return {
34018
+ domain: dataRegistryDomain(input.config),
34019
+ types: ADD_DATA_TYPES,
34020
+ primaryType: "AddData",
34021
+ message: {
34022
+ ownerAddress: input.ownerAddress,
34023
+ scope: input.scope,
34024
+ dataHash: TOMBSTONE_DATA_HASH,
34025
+ metadataHash: TOMBSTONE_METADATA_HASH,
34026
+ expectedVersion: input.expectedVersion
34027
+ }
34028
+ };
34029
+ }
34030
+ async function buildDataPointDeletionSignature(input) {
34031
+ const typedData = buildDataPointDeletionTypedData({
34032
+ ownerAddress: input.signer.address,
34033
+ scope: input.scope,
34034
+ expectedVersion: input.expectedVersion,
34035
+ config: input.config
34036
+ });
34037
+ const signature = await input.signer.signTypedData(typedData);
34038
+ return {
34039
+ signature,
34040
+ signerAddress: input.signer.address,
34041
+ typedData
34042
+ };
34043
+ }
34044
+ function toError(value) {
34045
+ return value instanceof Error ? value : new Error(String(value));
34046
+ }
34047
+ function parseExpectedVersion(value) {
34048
+ if (typeof value !== "string" || !/^\d+$/.test(value)) {
34049
+ throw new Error(
34050
+ `Gateway returned a malformed expectedVersion: ${JSON.stringify(value)}`
34051
+ );
34052
+ }
34053
+ const parsed = BigInt(value);
34054
+ assertUint256(parsed, "Gateway expectedVersion");
34055
+ return parsed;
34056
+ }
34057
+ async function deleteDataPoint(input) {
34058
+ const ownerAddress = input.signer.address;
34059
+ const dataPointId = deriveDataPointId(ownerAddress, input.scope);
34060
+ let currentVersion = input.currentVersion;
34061
+ if (currentVersion === void 0) {
34062
+ const record = await input.gateway.getDataPoint(dataPointId);
34063
+ if (record === null) {
34064
+ throw new DataPointNotFoundError(
34065
+ `No data point registered for scope '${input.scope}' owned by ${ownerAddress}`,
34066
+ { dataPointId, scope: input.scope, ownerAddress }
34067
+ );
34068
+ }
34069
+ if (isDataPointTombstone(record)) {
34070
+ throw new DataPointDeletedError(
34071
+ `Data point ${dataPointId} (scope '${input.scope}') is already deleted`,
34072
+ {
34073
+ dataPointId,
34074
+ scope: input.scope,
34075
+ ownerAddress,
34076
+ deletedAt: tombstoneDeletedAt(record)
34077
+ }
34078
+ );
34079
+ }
34080
+ currentVersion = parseExpectedVersion(record.expectedVersion);
34081
+ }
34082
+ if (currentVersion < 0n || currentVersion >= maxUint256) {
34083
+ throw new Error(
34084
+ `currentVersion ${currentVersion} cannot be incremented to a uint256 tombstone version`
34085
+ );
34086
+ }
34087
+ const tombstoneVersion = currentVersion + 1n;
34088
+ const signed = await buildDataPointDeletionSignature({
34089
+ signer: input.signer,
34090
+ scope: input.scope,
34091
+ expectedVersion: tombstoneVersion,
34092
+ config: input.config
34093
+ });
34094
+ const tombstone = await input.gateway.deleteDataPoint({
34095
+ ownerAddress,
34096
+ scope: input.scope,
34097
+ expectedVersion: tombstoneVersion.toString(),
34098
+ signature: signed.signature
34099
+ });
34100
+ const base = {
34101
+ dataPointId,
34102
+ ownerAddress,
34103
+ scope: input.scope,
34104
+ version: tombstoneVersion.toString(),
34105
+ signature: signed.signature,
34106
+ tombstone
34107
+ };
34108
+ try {
34109
+ const storage = await input.storage.deleteScope(ownerAddress, input.scope);
34110
+ return { ...base, status: "deleted", storage };
34111
+ } catch (cause) {
34112
+ return { ...base, status: "partial", storageError: toError(cause) };
34113
+ }
34114
+ }
34115
+
34116
+ // src/protocol/data-file.ts
34117
+ import { z as z2 } from "zod";
34118
+ var DataFileEnvelopeSchema = z2.object({
34119
+ $schema: z2.string().url().optional(),
34120
+ version: z2.literal("1.0"),
34121
+ scope: z2.string(),
34122
+ schemaId: z2.string().optional(),
34123
+ collectedAt: z2.string().datetime(),
34124
+ data: z2.record(z2.string(), z2.unknown())
34125
+ });
34126
+ function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
34127
+ return {
34128
+ ...schemaUrl !== void 0 && { $schema: schemaUrl },
34129
+ ...schemaId !== void 0 && { schemaId },
34130
+ version: "1.0",
34131
+ scope,
34132
+ collectedAt,
34133
+ data
34134
+ };
34135
+ }
34136
+ var IngestResponseSchema = z2.object({
34137
+ scope: z2.string(),
34138
+ collectedAt: z2.string().datetime(),
34139
+ status: z2.enum(["stored", "syncing"])
34140
+ });
34141
+
34142
+ // src/protocol/personal-server-data.ts
34143
+ function personalServerDataReadPath(scope) {
34144
+ return `/v1/data/${encodeURIComponent(scope)}`;
34145
+ }
34146
+ async function buildPersonalServerDataReadRequest(params) {
34147
+ const path = personalServerDataReadPath(params.scope);
34148
+ const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
34149
+ const audience = params.audience ?? baseUrl;
34150
+ const headers = new Headers(params.headers);
34151
+ headers.set(
34152
+ "Authorization",
34153
+ await buildWeb3SignedHeader({
34154
+ aud: audience,
34155
+ grantId: params.grantId,
34156
+ method: "GET",
34157
+ signMessage: params.signMessage,
34158
+ uri: path
34159
+ })
34160
+ );
34161
+ return new Request(`${baseUrl}${path}`, {
34162
+ headers,
34163
+ method: "GET"
34164
+ });
34165
+ }
34166
+ async function readPersonalServerData(params) {
34167
+ const fetchFn = params.fetch ?? globalThis.fetch;
34168
+ if (fetchFn === void 0) {
34169
+ throw new Error("No fetch implementation available");
34170
+ }
34171
+ const request = await buildPersonalServerDataReadRequest(params);
34172
+ const response = await fetchFn(request);
34173
+ if (response.status === 410) {
34174
+ throw new DataPointDeletedError(
34175
+ `Personal Server scope '${params.scope}' has been deleted`,
34176
+ {
34177
+ scope: params.scope,
34178
+ deletedAt: tombstoneDeletedAt(await readJsonValue(response))
34179
+ }
34180
+ );
34181
+ }
34182
+ if (!response.ok) {
34183
+ throw new Error(
34184
+ `Personal Server data read failed: ${response.status} ${response.statusText}`
34185
+ );
34186
+ }
34187
+ const body = await response.json();
34188
+ if (isDataPointTombstone(body)) {
34189
+ throw new DataPointDeletedError(
34190
+ `Personal Server scope '${params.scope}' has been deleted`,
34191
+ { scope: params.scope, deletedAt: tombstoneDeletedAt(body) }
34192
+ );
34193
+ }
34194
+ return DataFileEnvelopeSchema.parse(body);
34195
+ }
34196
+
34197
+ // src/protocol/scopes.ts
34198
+ import { z as z3 } from "zod";
34199
+ var SOURCE_RE = /^[a-z0-9][a-z0-9_]*$/;
34200
+ var TAIL_SEGMENT_RE = /^[a-zA-Z0-9][a-zA-Z0-9_]*$/;
34201
+ var ScopeSchema = z3.string().refine(
34202
+ (scope) => {
34203
+ const parts = scope.split(".");
34204
+ if (parts.length < 2 || parts.length > 3) return false;
34205
+ const [source, ...tail] = parts;
34206
+ return SOURCE_RE.test(source) && tail.every((part) => TAIL_SEGMENT_RE.test(part));
34207
+ },
34208
+ {
34209
+ message: "Scope must be {source}.{category}[.{subcategory}]; source lowercase, tail may keep the historical camelCase form (e.g. spotify.savedTracks)"
34210
+ }
34211
+ );
34212
+ function parseScope(scope) {
34213
+ const validated = ScopeSchema.parse(scope);
34214
+ const parts = validated.split(".");
34215
+ return {
34216
+ source: parts[0],
34217
+ category: parts[1],
34218
+ subcategory: parts[2],
34219
+ raw: validated
34220
+ };
34221
+ }
34222
+ function scopeToPathSegments(scope) {
34223
+ const parsed = parseScope(scope);
34224
+ const segments = [parsed.source, parsed.category];
34225
+ if (parsed.subcategory) {
34226
+ segments.push(parsed.subcategory);
34227
+ }
34228
+ return segments;
34229
+ }
34230
+ function scopeMatchesPattern(requestedScope, grantPattern) {
34231
+ if (grantPattern === "*") return true;
34232
+ if (grantPattern.endsWith(".*")) {
34233
+ const prefix = grantPattern.slice(0, -1);
34234
+ return requestedScope.startsWith(prefix);
34235
+ }
34236
+ return requestedScope === grantPattern;
34237
+ }
34238
+ function scopeCoveredByGrant(requestedScope, grantedScopes) {
34239
+ return grantedScopes.some(
34240
+ (pattern) => scopeMatchesPattern(requestedScope, pattern)
34241
+ );
34242
+ }
34243
+
34244
+ // src/protocol/scope-actions.ts
34245
+ var SCOPE_ACTIONS = ["read", "write"];
34246
+ var InvalidScopeEntryError = class extends Error {
34247
+ /** The offending entry, verbatim (unknown because it may not be a string). */
34248
+ entry;
34249
+ constructor(entry, reason) {
34250
+ super(`Invalid scope entry ${describeValue(entry)}: ${reason}`);
34251
+ this.name = "InvalidScopeEntryError";
34252
+ this.entry = entry;
34253
+ }
34254
+ };
34255
+ var OPERATION_SEPARATOR = ":";
34256
+ function describeValue(value) {
34257
+ if (typeof value === "string") return JSON.stringify(value);
34258
+ if (value === null) return "null";
34259
+ return `[${typeof value}]`;
34260
+ }
34261
+ var OPERATION_BY_PREFIX = {
34262
+ write: "write"
34263
+ };
34264
+ function assertScopePart(entry, scope) {
34265
+ if (scope.length === 0) {
34266
+ throw new InvalidScopeEntryError(entry, "scope part is empty");
34267
+ }
34268
+ if (scope.includes(OPERATION_SEPARATOR)) {
34269
+ throw new InvalidScopeEntryError(
34270
+ entry,
34271
+ `scope part must not contain "${OPERATION_SEPARATOR}"`
34272
+ );
34273
+ }
34274
+ }
34275
+ function parseScopeEntry(entry) {
34276
+ const raw = entry;
34277
+ if (typeof raw !== "string") {
34278
+ throw new InvalidScopeEntryError(raw, "entry must be a string");
34279
+ }
34280
+ const separatorIndex = entry.indexOf(OPERATION_SEPARATOR);
34281
+ if (separatorIndex === -1) {
34282
+ assertScopePart(entry, entry);
34283
+ return { scope: entry, action: "read" };
34284
+ }
34285
+ const prefix = entry.slice(0, separatorIndex);
34286
+ const scope = entry.slice(separatorIndex + 1);
34287
+ const action = Object.hasOwn(OPERATION_BY_PREFIX, prefix) ? OPERATION_BY_PREFIX[prefix] : void 0;
34288
+ if (action === void 0) {
34289
+ throw new InvalidScopeEntryError(
34290
+ entry,
34291
+ `unknown operation "${prefix}" (known: ${Object.keys(OPERATION_BY_PREFIX).join(", ")}; read has no prefix)`
34292
+ );
34293
+ }
34294
+ assertScopePart(entry, scope);
34295
+ return { scope, action };
34296
+ }
34297
+ function formatScopeEntry(parsed) {
34298
+ const { scope, action } = parsed;
34299
+ assertScopePart(scope, scope);
34300
+ if (action === "read") return scope;
34301
+ const prefix = Object.entries(OPERATION_BY_PREFIX).find(
34302
+ ([, candidate]) => candidate === action
34303
+ )?.[0];
34304
+ if (prefix === void 0) {
34305
+ throw new InvalidScopeEntryError(
34306
+ scope,
34307
+ `unknown action ${describeValue(action)} (known: ${SCOPE_ACTIONS.join(", ")})`
34308
+ );
34309
+ }
34310
+ return `${prefix}${OPERATION_SEPARATOR}${scope}`;
34311
+ }
34312
+ function compareScopes(a, b) {
34313
+ if (a < b) return -1;
34314
+ if (a > b) return 1;
34315
+ return 0;
34316
+ }
34317
+ function sortActions(actions) {
34318
+ const present = new Set(actions);
34319
+ return SCOPE_ACTIONS.filter((action) => present.has(action));
34320
+ }
34321
+ function grantPermissions(scopes) {
34322
+ const byScope = /* @__PURE__ */ new Map();
34323
+ for (const entry of scopes) {
34324
+ const { scope, action } = parseScopeEntry(entry);
34325
+ let actions = byScope.get(scope);
34326
+ if (actions === void 0) {
34327
+ actions = /* @__PURE__ */ new Set();
34328
+ byScope.set(scope, actions);
34329
+ }
34330
+ actions.add(action);
34331
+ }
34332
+ return [...byScope.keys()].sort(compareScopes).map((scope) => ({
34333
+ scope,
34334
+ actions: sortActions(byScope.get(scope) ?? [])
34335
+ }));
34336
+ }
34337
+ function permissionsToScopes(permissions) {
34338
+ const byScope = /* @__PURE__ */ new Map();
34339
+ for (const { scope, actions } of permissions) {
34340
+ let merged = byScope.get(scope);
34341
+ if (merged === void 0) {
34342
+ merged = /* @__PURE__ */ new Set();
34343
+ byScope.set(scope, merged);
34344
+ }
34345
+ for (const action of actions) {
34346
+ if (!SCOPE_ACTIONS.includes(action)) {
34347
+ throw new InvalidScopeEntryError(
34348
+ scope,
34349
+ `unknown action ${describeValue(action)} (known: ${SCOPE_ACTIONS.join(", ")})`
34350
+ );
34351
+ }
34352
+ merged.add(action);
34353
+ }
34354
+ }
34355
+ const entries = [];
34356
+ for (const scope of [...byScope.keys()].sort(compareScopes)) {
34357
+ for (const action of sortActions(byScope.get(scope) ?? [])) {
34358
+ entries.push(formatScopeEntry({ scope, action }));
34359
+ }
34360
+ }
34361
+ return entries;
34362
+ }
34363
+ function hasAction(scopes, scope, action) {
34364
+ if (scope.includes(OPERATION_SEPARATOR)) return false;
34365
+ for (const entry of scopes) {
34366
+ let parsed;
34367
+ try {
34368
+ parsed = parseScopeEntry(entry);
34369
+ } catch (error) {
34370
+ if (error instanceof InvalidScopeEntryError) continue;
34371
+ throw error;
34372
+ }
34373
+ if (parsed.action === action && scopeMatchesPattern(scope, parsed.scope)) {
34374
+ return true;
34375
+ }
34376
+ }
34377
+ return false;
34378
+ }
34379
+ function tryGrantPermissions(scopes) {
34380
+ try {
34381
+ return grantPermissions(scopes);
34382
+ } catch (error) {
34383
+ if (error instanceof InvalidScopeEntryError) return void 0;
34384
+ throw error;
34385
+ }
34386
+ }
34387
+
34100
34388
  // src/protocol/personal-server-write.ts
34389
+ import { sha256 as sha2565 } from "@noble/hashes/sha2";
34390
+ import { bytesToHex as bytesToHex2, isAddress as isAddress6 } from "viem";
34391
+ import { z as z4 } from "zod";
34101
34392
  var WRITE_SESSION_PATH = "/v1/write/session";
34102
34393
  var WRITE_SIGNATURE_HEADER = "X-Vana-Write-Signature";
34103
34394
  var WRITE_METADATA_HEADER = "X-Vana-Metadata";
@@ -34400,7 +34691,7 @@ function normalizeLineage(lineage, derivedScope) {
34400
34691
  for (const entry of lineage) {
34401
34692
  let id;
34402
34693
  if (isLineagePair(entry)) {
34403
- if (!isAddress5(entry.ownerAddress, { strict: false })) {
34694
+ if (!isAddress6(entry.ownerAddress, { strict: false })) {
34404
34695
  throw new WriteRequestError(
34405
34696
  "lineage source ownerAddress must be an EVM address",
34406
34697
  { ownerAddress: entry.ownerAddress }
@@ -34662,14 +34953,44 @@ function withGrantPermissions(grant) {
34662
34953
  }
34663
34954
  function createGatewayClient(baseUrl) {
34664
34955
  const base = baseUrl.replace(/\/+$/, "");
34956
+ function malformedBody(res) {
34957
+ return new Error(
34958
+ `Gateway error: ${res.status} malformed response body (expected a JSON envelope)`
34959
+ );
34960
+ }
34961
+ async function readEnvelope(res) {
34962
+ const envelope = await readJsonValue(res);
34963
+ if (!isPlainObject(envelope) || !("data" in envelope)) {
34964
+ throw malformedBody(res);
34965
+ }
34966
+ return envelope;
34967
+ }
34665
34968
  async function unwrapEnvelope(res) {
34666
- const envelope = await res.json();
34667
- return envelope.data;
34969
+ return (await readEnvelope(res)).data;
34668
34970
  }
34669
34971
  function getMutationId(body, key) {
34972
+ if (!isPlainObject(body)) return void 0;
34670
34973
  const value = body[key] ?? body["id"];
34671
34974
  return typeof value === "string" ? value : void 0;
34672
34975
  }
34976
+ async function readBody(res) {
34977
+ const raw = await readJsonObject(res);
34978
+ const data = raw["data"];
34979
+ if (isPlainObject(data) && "proof" in raw) {
34980
+ return data;
34981
+ }
34982
+ return raw;
34983
+ }
34984
+ function stringOrUndefined(value) {
34985
+ return typeof value === "string" ? value : void 0;
34986
+ }
34987
+ async function deletedError(res, details) {
34988
+ const body = await readBody(res);
34989
+ return new DataPointDeletedError(
34990
+ `Data point ${details.dataPointId ?? details.scope ?? ""} has been deleted`,
34991
+ { ...details, deletedAt: tombstoneDeletedAt(body) }
34992
+ );
34993
+ }
34673
34994
  return {
34674
34995
  async isRegisteredBuilder(address) {
34675
34996
  const builder = await this.getBuilder(address);
@@ -34726,13 +35047,29 @@ function createGatewayClient(baseUrl) {
34726
35047
  }
34727
35048
  return await res.json();
34728
35049
  },
34729
- async getDataPoint(dataPointId) {
34730
- const res = await fetch(`${base}/v1/data/${dataPointId}`);
35050
+ async getDataPoint(dataPointId, options) {
35051
+ const query = options?.includeDeleted ? "?includeDeleted=true" : "";
35052
+ const res = await fetch(`${base}/v1/data/${dataPointId}${query}`);
34731
35053
  if (res.status === 404) return null;
35054
+ if (res.status === 410) {
35055
+ throw await deletedError(res, { dataPointId });
35056
+ }
34732
35057
  if (!res.ok) {
34733
35058
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
34734
35059
  }
34735
- return unwrapEnvelope(res);
35060
+ const record = await unwrapEnvelope(res);
35061
+ if (!options?.includeDeleted && isDataPointTombstone(record)) {
35062
+ throw new DataPointDeletedError(
35063
+ `Data point ${dataPointId} has been deleted`,
35064
+ {
35065
+ dataPointId,
35066
+ scope: record.scope,
35067
+ ownerAddress: record.ownerAddress,
35068
+ deletedAt: tombstoneDeletedAt(record)
35069
+ }
35070
+ );
35071
+ }
35072
+ return record;
34736
35073
  },
34737
35074
  async listDataPointsByOwner(owner, cursor, options) {
34738
35075
  const params = new URLSearchParams({ user: owner });
@@ -34745,14 +35082,24 @@ function createGatewayClient(baseUrl) {
34745
35082
  if (options?.limit !== void 0) {
34746
35083
  params.set("limit", String(options.limit));
34747
35084
  }
35085
+ if (options?.includeDeleted) {
35086
+ params.set("includeDeleted", "true");
35087
+ }
34748
35088
  const res = await fetch(`${base}/v1/data?${params.toString()}`);
34749
35089
  if (!res.ok) {
34750
35090
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
34751
35091
  }
34752
- const envelope = await res.json();
34753
- const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
35092
+ const envelope = await readEnvelope(res);
35093
+ if (!isPlainObject(envelope.data) || !Array.isArray(envelope.data["dataPoints"])) {
35094
+ throw malformedBody(res);
35095
+ }
35096
+ const rows = envelope.data["dataPoints"];
35097
+ const pagination = isPlainObject(envelope["pagination"]) ? envelope["pagination"] : void 0;
35098
+ const rawCursor = pagination?.["nextCursor"];
35099
+ const nextCursor = pagination?.["hasMore"] === false || typeof rawCursor !== "string" ? null : rawCursor;
35100
+ const dataPoints = options?.includeDeleted ? rows : rows.filter((row) => !isDataPointTombstone(row));
34754
35101
  return {
34755
- dataPoints: envelope.data.dataPoints,
35102
+ dataPoints,
34756
35103
  cursor: nextCursor
34757
35104
  };
34758
35105
  },
@@ -34779,7 +35126,7 @@ function createGatewayClient(baseUrl) {
34779
35126
  })
34780
35127
  });
34781
35128
  if (res.status === 409) {
34782
- const body2 = await res.json().catch(() => ({}));
35129
+ const body2 = await readJsonObject(res);
34783
35130
  return {
34784
35131
  serverId: getMutationId(body2, "serverId"),
34785
35132
  alreadyRegistered: true
@@ -34788,7 +35135,7 @@ function createGatewayClient(baseUrl) {
34788
35135
  if (!res.ok) {
34789
35136
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
34790
35137
  }
34791
- const body = await res.json().catch(() => ({}));
35138
+ const body = await readJsonObject(res);
34792
35139
  return {
34793
35140
  serverId: getMutationId(body, "serverId"),
34794
35141
  alreadyRegistered: false
@@ -34809,19 +35156,16 @@ function createGatewayClient(baseUrl) {
34809
35156
  })
34810
35157
  });
34811
35158
  if (res.status === 409) {
34812
- const body2 = await res.json().catch(() => ({}));
35159
+ const body2 = await readJsonObject(res);
34813
35160
  return {
34814
- builderId: getMutationId(
34815
- body2,
34816
- "builderId"
34817
- ),
35161
+ builderId: getMutationId(body2, "builderId"),
34818
35162
  alreadyRegistered: true
34819
35163
  };
34820
35164
  }
34821
35165
  if (!res.ok) {
34822
35166
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
34823
35167
  }
34824
- const body = await res.json().catch(() => ({}));
35168
+ const body = await readJsonObject(res);
34825
35169
  return {
34826
35170
  builderId: getMutationId(body, "builderId"),
34827
35171
  alreadyRegistered: false
@@ -34843,17 +35187,77 @@ function createGatewayClient(baseUrl) {
34843
35187
  })
34844
35188
  });
34845
35189
  if (!res.ok) {
34846
- const body2 = await res.json().catch(() => ({}));
34847
- const detail = body2.error ?? res.statusText;
35190
+ const body2 = await readJsonObject(res);
35191
+ const detail = stringOrUndefined(body2["error"]) ?? res.statusText;
34848
35192
  throw new Error(`Gateway error: ${res.status} ${detail}`);
34849
35193
  }
34850
- const body = await res.json().catch(() => ({}));
35194
+ const body = await readJsonObject(res);
34851
35195
  return {
34852
- dataPointId: getMutationId(
34853
- body,
34854
- "dataPointId"
34855
- ),
34856
- expectedVersion: body.expectedVersion
35196
+ dataPointId: getMutationId(body, "dataPointId"),
35197
+ expectedVersion: stringOrUndefined(body["expectedVersion"])
35198
+ };
35199
+ },
35200
+ async deleteDataPoint(params) {
35201
+ const dataPointId = deriveDataPointId(
35202
+ params.ownerAddress,
35203
+ params.scope
35204
+ );
35205
+ const details = {
35206
+ dataPointId,
35207
+ scope: params.scope,
35208
+ ownerAddress: params.ownerAddress
35209
+ };
35210
+ const res = await fetch(`${base}/v1/data/${dataPointId}`, {
35211
+ method: "DELETE",
35212
+ headers: {
35213
+ "Content-Type": "application/json",
35214
+ Authorization: `Web3Signed ${params.signature}`
35215
+ },
35216
+ body: JSON.stringify({
35217
+ ownerAddress: params.ownerAddress,
35218
+ scope: params.scope,
35219
+ expectedVersion: params.expectedVersion,
35220
+ signature: params.signature
35221
+ })
35222
+ });
35223
+ if (res.status === 404) {
35224
+ throw new DataPointNotFoundError(
35225
+ `Data point ${dataPointId} (scope '${params.scope}') is not registered`,
35226
+ details
35227
+ );
35228
+ }
35229
+ if (res.status === 409) {
35230
+ const body2 = await readBody(res);
35231
+ const currentExpectedVersion = stringOrUndefined(
35232
+ body2["currentExpectedVersion"]
35233
+ );
35234
+ const detail = stringOrUndefined(body2["error"]) ?? res.statusText;
35235
+ throw new DataPointVersionConflictError(
35236
+ `Gateway error: 409 ${detail}`,
35237
+ {
35238
+ ...details,
35239
+ expectedVersion: params.expectedVersion,
35240
+ currentExpectedVersion
35241
+ }
35242
+ );
35243
+ }
35244
+ if (res.status === 410) {
35245
+ throw await deletedError(res, details);
35246
+ }
35247
+ if (!res.ok) {
35248
+ const body2 = await readBody(res);
35249
+ const detail = stringOrUndefined(body2["error"]) ?? res.statusText;
35250
+ throw new Error(`Gateway error: ${res.status} ${detail}`);
35251
+ }
35252
+ const body = await readBody(res);
35253
+ return {
35254
+ dataPointId: getMutationId(body, "dataPointId") ?? dataPointId,
35255
+ ownerAddress: stringOrUndefined(body["ownerAddress"]),
35256
+ scope: stringOrUndefined(body["scope"]),
35257
+ dataHash: stringOrUndefined(body["dataHash"]),
35258
+ metadataHash: stringOrUndefined(body["metadataHash"]),
35259
+ expectedVersion: stringOrUndefined(body["expectedVersion"]),
35260
+ deletedAt: tombstoneDeletedAt(body)
34857
35261
  };
34858
35262
  },
34859
35263
  async createGrant(params) {
@@ -34872,18 +35276,14 @@ function createGatewayClient(baseUrl) {
34872
35276
  })
34873
35277
  });
34874
35278
  if (res.status === 409) {
34875
- const body2 = await res.json().catch(() => ({}));
34876
- return {
34877
- grantId: getMutationId(body2, "grantId")
34878
- };
35279
+ const body2 = await readJsonObject(res);
35280
+ return { grantId: getMutationId(body2, "grantId") };
34879
35281
  }
34880
35282
  if (!res.ok) {
34881
35283
  throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
34882
35284
  }
34883
- const body = await res.json();
34884
- return {
34885
- grantId: getMutationId(body, "grantId")
34886
- };
35285
+ const body = await readJsonObject(res);
35286
+ return { grantId: getMutationId(body, "grantId") };
34887
35287
  },
34888
35288
  async revokeGrant(params) {
34889
35289
  const res = await fetch(`${base}/v1/grants/${params.grantId}`, {
@@ -35621,7 +36021,10 @@ export {
35621
36021
  DATA_ACCESS_OP_TYPE,
35622
36022
  DATA_REGISTRY_STATUS_ABI,
35623
36023
  DataFileEnvelopeSchema,
36024
+ DataPointDeletedError,
36025
+ DataPointNotFoundError,
35624
36026
  DataPointStatus,
36027
+ DataPointVersionConflictError,
35625
36028
  DropboxStorage,
35626
36029
  ECIESError,
35627
36030
  ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
@@ -35681,6 +36084,10 @@ export {
35681
36084
  SignatureError,
35682
36085
  StorageError,
35683
36086
  StorageManager,
36087
+ TOMBSTONE_DATA_HASH,
36088
+ TOMBSTONE_DATA_HASH_PREIMAGE,
36089
+ TOMBSTONE_METADATA_HASH,
36090
+ TOMBSTONE_METADATA_HASH_PREIMAGE,
35684
36091
  TransactionPendingError,
35685
36092
  UserRejectedRequestError,
35686
36093
  VanaError,
@@ -35705,6 +36112,8 @@ export {
35705
36112
  authorizeEscrowPayment,
35706
36113
  authorizeGrantPayment,
35707
36114
  binaryWriteSignedBytes,
36115
+ buildDataPointDeletionSignature,
36116
+ buildDataPointDeletionTypedData,
35708
36117
  buildDepositNativeRequest,
35709
36118
  buildDepositTokenRequest,
35710
36119
  buildEscrowPaymentHeader,
@@ -35722,6 +36131,7 @@ export {
35722
36131
  clearContractCache,
35723
36132
  computeBodyHash,
35724
36133
  computePkceChallenge,
36134
+ computeTombstoneHash,
35725
36135
  contractCacheForTesting,
35726
36136
  createBrowserPlatformAdapter,
35727
36137
  createDataFileEnvelope,
@@ -35733,11 +36143,13 @@ export {
35733
36143
  createPlatformAdapterFor,
35734
36144
  createPlatformAdapterSafe,
35735
36145
  createVanaStorageProvider,
36146
+ createViemDataPointDeletionSigner,
35736
36147
  createViemPersonalServerLiteOwnerBindingSigner,
35737
36148
  createViemPersonalServerRegistrationSigner,
35738
36149
  dataRegistryContractAddress,
35739
36150
  dataRegistryDomain,
35740
36151
  decryptWithPassword,
36152
+ deleteDataPoint,
35741
36153
  deriveDataPointId,
35742
36154
  deriveMasterKey,
35743
36155
  deriveScopeKey,
@@ -35773,10 +36185,12 @@ export {
35773
36185
  grantRevocationDomain,
35774
36186
  hasAction,
35775
36187
  isDataPointId,
36188
+ isDataPointTombstone,
35776
36189
  isDataPortabilityGatewayConfig,
35777
36190
  isECIESEncrypted,
35778
36191
  isPlatformSupported,
35779
36192
  isRedactedLineageNode,
36193
+ isTombstoneHashes,
35780
36194
  mainnetServices,
35781
36195
  moksha,
35782
36196
  mokshaServices,
@@ -35811,6 +36225,7 @@ export {
35811
36225
  signPersonalServerRegistrationWithAccount,
35812
36226
  toDirectFeeBreakdown,
35813
36227
  toDirectPaymentReceipt,
36228
+ tombstoneDeletedAt,
35814
36229
  tryGrantPermissions,
35815
36230
  vanaMainnet2 as vanaMainnet,
35816
36231
  verifyGrantRegistration,