@opendatalabs/vana-sdk 3.22.0-pr.208.28eb140 → 3.22.0-pr.208.e9c19e9

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.
@@ -32575,7 +32575,7 @@ var MAX_JOB_DEADLINE_SECONDS = 3600;
32575
32575
  // src/crypto/envelope/job.ts
32576
32576
  init_interface();
32577
32577
  import { sha256 as sha2565 } from "@noble/hashes/sha2";
32578
- import { bytesToHex as bytesToHex2, fromHex as fromHex6, toHex as toHex8 } from "viem";
32578
+ import { bytesToHex as bytesToHex2, fromHex as fromHex6, isAddress, isHex, toHex as toHex8 } from "viem";
32579
32579
  var textDecoder = new TextDecoder();
32580
32580
  var textEncoder = new TextEncoder();
32581
32581
  var JobEnvelopeError = class extends Error {
@@ -32602,9 +32602,11 @@ function canonicalJsonBytes(value) {
32602
32602
  return textEncoder.encode(JSON.stringify(sortJsonKeys(value)));
32603
32603
  }
32604
32604
  function canonicalJobRequestBytes(request) {
32605
+ validateJobRequest(request);
32605
32606
  return canonicalJsonBytes(request);
32606
32607
  }
32607
32608
  function requestPlaintext(envelope) {
32609
+ validateRequestEnvelope(envelope);
32608
32610
  return canonicalJsonBytes(envelope);
32609
32611
  }
32610
32612
  function resultPlaintext(result) {
@@ -32637,42 +32639,99 @@ function parseObject(plaintext, kind) {
32637
32639
  throw new JobEnvelopeError(`Invalid ${kind}: malformed JSON`);
32638
32640
  }
32639
32641
  }
32642
+ function isPlainObject2(value) {
32643
+ if (value === null || typeof value !== "object") return false;
32644
+ const prototype = Object.getPrototypeOf(value);
32645
+ return prototype === Object.prototype || prototype === null;
32646
+ }
32647
+ function requirePlainObject(value, field, kind) {
32648
+ if (!isPlainObject2(value)) {
32649
+ throw new JobEnvelopeError(`Invalid ${kind}: invalid ${field}`);
32650
+ }
32651
+ }
32652
+ function requireExactKeys(value, expectedKeys, kind) {
32653
+ for (const key of expectedKeys) {
32654
+ if (!Object.hasOwn(value, key) || value[key] === void 0) {
32655
+ throw new JobEnvelopeError(`Invalid ${kind}: missing ${key}`);
32656
+ }
32657
+ }
32658
+ const expected = new Set(expectedKeys);
32659
+ for (const key of Reflect.ownKeys(value)) {
32660
+ if (!expected.has(key)) {
32661
+ throw new JobEnvelopeError(
32662
+ `Invalid ${kind}: unknown field ${String(key)}`
32663
+ );
32664
+ }
32665
+ }
32666
+ }
32640
32667
  function requireString(value, field, kind) {
32641
32668
  if (typeof value !== "string" || value.length === 0) {
32642
32669
  throw new JobEnvelopeError(`Invalid ${kind}: missing ${field}`);
32643
32670
  }
32644
32671
  }
32645
- function validateRequestEnvelope(value) {
32646
- const request = value.request;
32647
- if (request === null || typeof request !== "object" || Array.isArray(request)) {
32648
- throw new JobEnvelopeError("Invalid job request envelope: missing request");
32649
- }
32650
- const fields = request;
32651
- if (fields.v !== 1) {
32672
+ function validateJobRequest(value) {
32673
+ requirePlainObject(value, "request", "job request");
32674
+ requireExactKeys(
32675
+ value,
32676
+ [
32677
+ "v",
32678
+ "jobId",
32679
+ "owner",
32680
+ "builder",
32681
+ "builderPublicKey",
32682
+ "grantId",
32683
+ "scope",
32684
+ "operation",
32685
+ "pinnedVersion",
32686
+ "deadline"
32687
+ ],
32688
+ "job request"
32689
+ );
32690
+ if (value.v !== JOB_PROTOCOL_VERSION) {
32652
32691
  throw new JobEnvelopeError(
32653
- `Unsupported job request version: ${String(fields.v)}`
32692
+ `Unsupported job request version: ${String(value.v)}`
32654
32693
  );
32655
32694
  }
32656
- for (const field of [
32657
- "jobId",
32658
- "owner",
32659
- "builder",
32660
- "builderPublicKey",
32661
- "grantId",
32662
- "scope",
32663
- "operation",
32664
- "deadline"
32665
- ]) {
32666
- requireString(fields[field], field, "job request");
32667
- }
32668
- if (fields.pinnedVersion !== null && typeof fields.pinnedVersion !== "string") {
32695
+ requireString(value.jobId, "jobId", "job request");
32696
+ if (typeof value.owner !== "string" || !isAddress(value.owner)) {
32697
+ throw new JobEnvelopeError("Invalid job request: invalid owner");
32698
+ }
32699
+ if (typeof value.builder !== "string" || !isAddress(value.builder)) {
32700
+ throw new JobEnvelopeError("Invalid job request: invalid builder");
32701
+ }
32702
+ if (typeof value.builderPublicKey !== "string" || !isHex(value.builderPublicKey)) {
32703
+ throw new JobEnvelopeError("Invalid job request: invalid builderPublicKey");
32704
+ }
32705
+ if (typeof value.grantId !== "string" || !isHex(value.grantId)) {
32706
+ throw new JobEnvelopeError("Invalid job request: invalid grantId");
32707
+ }
32708
+ requireString(value.scope, "scope", "job request");
32709
+ if (!JOB_OPERATIONS.includes(value.operation)) {
32710
+ throw new JobEnvelopeError("Invalid job request: invalid operation");
32711
+ }
32712
+ if (value.pinnedVersion !== null && typeof value.pinnedVersion !== "string") {
32669
32713
  throw new JobEnvelopeError("Invalid job request: missing pinnedVersion");
32670
32714
  }
32715
+ if (typeof value.deadline !== "string" || !Number.isFinite(Date.parse(value.deadline))) {
32716
+ throw new JobEnvelopeError("Invalid job request: invalid deadline");
32717
+ }
32718
+ return value;
32719
+ }
32720
+ function validateRequestEnvelope(value) {
32721
+ requirePlainObject(value, "envelope", "job request envelope");
32722
+ requireExactKeys(value, ["request", "auth"], "job request envelope");
32723
+ validateJobRequest(value.request);
32671
32724
  requireString(value.auth, "auth", "job request envelope");
32672
32725
  return value;
32673
32726
  }
32674
32727
  function validateResult(value) {
32675
- if (value.v !== 1) {
32728
+ requirePlainObject(value, "result", "job result");
32729
+ requireExactKeys(
32730
+ value,
32731
+ ["v", "jobId", "scope", "version", "contentType", "body"],
32732
+ "job result"
32733
+ );
32734
+ if (value.v !== JOB_PROTOCOL_VERSION) {
32676
32735
  throw new JobEnvelopeError(
32677
32736
  `Unsupported job result version: ${String(value.v)}`
32678
32737
  );
@@ -32688,10 +32747,10 @@ function validateResult(value) {
32688
32747
  }
32689
32748
  return value;
32690
32749
  }
32691
- async function sealJobRequest(e, enclavePublicKey, ecies) {
32750
+ async function sealJobRequest(envelope, enclavePublicKey, ecies) {
32692
32751
  const encrypted = await ecies.encrypt(
32693
32752
  fromHex6(enclavePublicKey, "bytes"),
32694
- requestPlaintext(e)
32753
+ requestPlaintext(envelope)
32695
32754
  );
32696
32755
  return encryptedBytesToBase64(encrypted);
32697
32756
  }
@@ -32704,10 +32763,11 @@ async function openJobRequest(ciphertext, privateKey, ecies) {
32704
32763
  parseObject(plaintext, "job request envelope")
32705
32764
  );
32706
32765
  }
32707
- async function sealJobResult(r, builderPublicKey, ecies) {
32766
+ async function sealJobResult(result, builderPublicKey, ecies) {
32767
+ validateResult(result);
32708
32768
  const encrypted = await ecies.encrypt(
32709
32769
  fromHex6(builderPublicKey, "bytes"),
32710
- resultPlaintext(r)
32770
+ resultPlaintext(result)
32711
32771
  );
32712
32772
  const ciphertext = encryptedBytesToBase64(encrypted);
32713
32773
  const bytes = fromBase64(ciphertext);
@@ -32739,7 +32799,7 @@ async function openJobResult(ciphertext, builderPrivateKey, ecies, expect) {
32739
32799
 
32740
32800
  // src/protocol/personal-server-registration.ts
32741
32801
  import {
32742
- isAddress
32802
+ isAddress as isAddress2
32743
32803
  } from "viem";
32744
32804
  var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
32745
32805
  var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
@@ -32747,7 +32807,7 @@ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress
32747
32807
  "DataPortabilityServers"
32748
32808
  );
32749
32809
  function assertAddress(value, name) {
32750
- if (!isAddress(value)) {
32810
+ if (!isAddress2(value)) {
32751
32811
  throw new Error(`${name} must be a valid EVM address`);
32752
32812
  }
32753
32813
  }
@@ -32834,13 +32894,13 @@ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32834
32894
 
32835
32895
  // src/personal-server-lite/owner-binding.ts
32836
32896
  import {
32837
- isAddress as isAddress2
32897
+ isAddress as isAddress3
32838
32898
  } from "viem";
32839
32899
  var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
32840
32900
  var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32841
32901
  var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32842
32902
  function assertAddress2(value, name) {
32843
- if (!isAddress2(value)) {
32903
+ if (!isAddress3(value)) {
32844
32904
  throw new Error(`${name} must be a valid EVM address`);
32845
32905
  }
32846
32906
  }
@@ -32890,7 +32950,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
32890
32950
  var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
32891
32951
 
32892
32952
  // src/account/personal-server-registration.ts
32893
- import { isAddress as isAddress3 } from "viem";
32953
+ import { isAddress as isAddress4 } from "viem";
32894
32954
  var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
32895
32955
  var AccountPersonalServerRegistrationError = class extends Error {
32896
32956
  status;
@@ -32909,7 +32969,7 @@ function trimTrailingSlash(value) {
32909
32969
  return value.replace(/\/+$/, "");
32910
32970
  }
32911
32971
  function assertAddress3(value, name) {
32912
- if (!isAddress3(value)) {
32972
+ if (!isAddress4(value)) {
32913
32973
  throw new Error(`${name} must be a valid EVM address`);
32914
32974
  }
32915
32975
  }
@@ -33435,7 +33495,7 @@ function buildMarkDataPointUnavailableRequest(config, input) {
33435
33495
 
33436
33496
  // src/protocol/data-point-deletion.ts
33437
33497
  import {
33438
- isAddress as isAddress5,
33498
+ isAddress as isAddress6,
33439
33499
  keccak256 as keccak2563,
33440
33500
  maxUint256,
33441
33501
  stringToBytes as stringToBytes3
@@ -33444,7 +33504,7 @@ import {
33444
33504
  // src/protocol/lineage.ts
33445
33505
  import {
33446
33506
  encodeAbiParameters,
33447
- isAddress as isAddress4,
33507
+ isAddress as isAddress5,
33448
33508
  keccak256 as keccak2562
33449
33509
  } from "viem";
33450
33510
  import { z } from "zod";
@@ -33524,7 +33584,7 @@ function isDataPointId(value) {
33524
33584
  return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
33525
33585
  }
33526
33586
  function deriveDataPointId(ownerAddress, scope) {
33527
- if (!isAddress4(ownerAddress, { strict: false })) {
33587
+ if (!isAddress5(ownerAddress, { strict: false })) {
33528
33588
  throw new Error(
33529
33589
  `ownerAddress is not an EVM address: ${String(ownerAddress)}`
33530
33590
  );
@@ -33775,7 +33835,7 @@ function tombstoneDeletedAt(value) {
33775
33835
  return typeof deletedAt === "string" ? deletedAt : null;
33776
33836
  }
33777
33837
  function assertAddress4(value, name) {
33778
- if (!isAddress5(value)) {
33838
+ if (!isAddress6(value)) {
33779
33839
  throw new Error(`${name} must be a valid EVM address`);
33780
33840
  }
33781
33841
  }
@@ -34191,7 +34251,7 @@ function tryGrantPermissions(scopes) {
34191
34251
 
34192
34252
  // src/protocol/personal-server-write.ts
34193
34253
  import { sha256 as sha2567 } from "@noble/hashes/sha2";
34194
- import { bytesToHex as bytesToHex4, isAddress as isAddress6 } from "viem";
34254
+ import { bytesToHex as bytesToHex4, isAddress as isAddress7 } from "viem";
34195
34255
  import { z as z4 } from "zod";
34196
34256
 
34197
34257
  // src/protocol/write-request.ts
@@ -34513,7 +34573,7 @@ function normalizeLineage(lineage, derivedScope) {
34513
34573
  for (const entry of lineage) {
34514
34574
  let id;
34515
34575
  if (isLineagePair(entry)) {
34516
- if (!isAddress6(entry.ownerAddress, { strict: false })) {
34576
+ if (!isAddress7(entry.ownerAddress, { strict: false })) {
34517
34577
  throw new WriteRequestError(
34518
34578
  "lineage source ownerAddress must be an EVM address",
34519
34579
  { ownerAddress: entry.ownerAddress }
@@ -35809,7 +35869,7 @@ function createGatewayClient(baseUrl) {
35809
35869
  }
35810
35870
 
35811
35871
  // src/protocol/escrow.ts
35812
- import { isHex } from "viem";
35872
+ import { isHex as isHex2 } from "viem";
35813
35873
  var GENERIC_PAYMENT_TYPES = {
35814
35874
  GenericPayment: [
35815
35875
  { name: "payerAddress", type: "address" },
@@ -36025,10 +36085,10 @@ function optionalUint256Decimal(value) {
36025
36085
  return value === void 0 || isUint256Decimal(value);
36026
36086
  }
36027
36087
  function isAddressHex(value) {
36028
- return typeof value === "string" && isHex(value, { strict: true }) && value.length === 42;
36088
+ return typeof value === "string" && isHex2(value, { strict: true }) && value.length === 42;
36029
36089
  }
36030
36090
  function isHash(value) {
36031
- return typeof value === "string" && isHex(value, { strict: true }) && value.length === 66;
36091
+ return typeof value === "string" && isHex2(value, { strict: true }) && value.length === 66;
36032
36092
  }
36033
36093
  function isUint256Decimal(value) {
36034
36094
  if (typeof value !== "string" || value.length === 0 || value.length > 78) {