@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.
@@ -31948,7 +31948,7 @@ var MAX_JOB_DEADLINE_SECONDS = 3600;
31948
31948
  // src/crypto/envelope/job.ts
31949
31949
  init_interface();
31950
31950
  import { sha256 as sha2565 } from "@noble/hashes/sha2";
31951
- import { bytesToHex as bytesToHex2, fromHex as fromHex6, toHex as toHex7 } from "viem";
31951
+ import { bytesToHex as bytesToHex2, fromHex as fromHex6, isAddress, isHex, toHex as toHex7 } from "viem";
31952
31952
  var textDecoder = new TextDecoder();
31953
31953
  var textEncoder = new TextEncoder();
31954
31954
  var JobEnvelopeError = class extends Error {
@@ -31975,9 +31975,11 @@ function canonicalJsonBytes(value) {
31975
31975
  return textEncoder.encode(JSON.stringify(sortJsonKeys(value)));
31976
31976
  }
31977
31977
  function canonicalJobRequestBytes(request) {
31978
+ validateJobRequest(request);
31978
31979
  return canonicalJsonBytes(request);
31979
31980
  }
31980
31981
  function requestPlaintext(envelope) {
31982
+ validateRequestEnvelope(envelope);
31981
31983
  return canonicalJsonBytes(envelope);
31982
31984
  }
31983
31985
  function resultPlaintext(result) {
@@ -32010,42 +32012,99 @@ function parseObject(plaintext, kind) {
32010
32012
  throw new JobEnvelopeError(`Invalid ${kind}: malformed JSON`);
32011
32013
  }
32012
32014
  }
32015
+ function isPlainObject2(value) {
32016
+ if (value === null || typeof value !== "object") return false;
32017
+ const prototype = Object.getPrototypeOf(value);
32018
+ return prototype === Object.prototype || prototype === null;
32019
+ }
32020
+ function requirePlainObject(value, field, kind) {
32021
+ if (!isPlainObject2(value)) {
32022
+ throw new JobEnvelopeError(`Invalid ${kind}: invalid ${field}`);
32023
+ }
32024
+ }
32025
+ function requireExactKeys(value, expectedKeys, kind) {
32026
+ for (const key of expectedKeys) {
32027
+ if (!Object.hasOwn(value, key) || value[key] === void 0) {
32028
+ throw new JobEnvelopeError(`Invalid ${kind}: missing ${key}`);
32029
+ }
32030
+ }
32031
+ const expected = new Set(expectedKeys);
32032
+ for (const key of Reflect.ownKeys(value)) {
32033
+ if (!expected.has(key)) {
32034
+ throw new JobEnvelopeError(
32035
+ `Invalid ${kind}: unknown field ${String(key)}`
32036
+ );
32037
+ }
32038
+ }
32039
+ }
32013
32040
  function requireString(value, field, kind) {
32014
32041
  if (typeof value !== "string" || value.length === 0) {
32015
32042
  throw new JobEnvelopeError(`Invalid ${kind}: missing ${field}`);
32016
32043
  }
32017
32044
  }
32018
- function validateRequestEnvelope(value) {
32019
- const request = value.request;
32020
- if (request === null || typeof request !== "object" || Array.isArray(request)) {
32021
- throw new JobEnvelopeError("Invalid job request envelope: missing request");
32022
- }
32023
- const fields = request;
32024
- if (fields.v !== 1) {
32045
+ function validateJobRequest(value) {
32046
+ requirePlainObject(value, "request", "job request");
32047
+ requireExactKeys(
32048
+ value,
32049
+ [
32050
+ "v",
32051
+ "jobId",
32052
+ "owner",
32053
+ "builder",
32054
+ "builderPublicKey",
32055
+ "grantId",
32056
+ "scope",
32057
+ "operation",
32058
+ "pinnedVersion",
32059
+ "deadline"
32060
+ ],
32061
+ "job request"
32062
+ );
32063
+ if (value.v !== JOB_PROTOCOL_VERSION) {
32025
32064
  throw new JobEnvelopeError(
32026
- `Unsupported job request version: ${String(fields.v)}`
32065
+ `Unsupported job request version: ${String(value.v)}`
32027
32066
  );
32028
32067
  }
32029
- for (const field of [
32030
- "jobId",
32031
- "owner",
32032
- "builder",
32033
- "builderPublicKey",
32034
- "grantId",
32035
- "scope",
32036
- "operation",
32037
- "deadline"
32038
- ]) {
32039
- requireString(fields[field], field, "job request");
32040
- }
32041
- if (fields.pinnedVersion !== null && typeof fields.pinnedVersion !== "string") {
32068
+ requireString(value.jobId, "jobId", "job request");
32069
+ if (typeof value.owner !== "string" || !isAddress(value.owner)) {
32070
+ throw new JobEnvelopeError("Invalid job request: invalid owner");
32071
+ }
32072
+ if (typeof value.builder !== "string" || !isAddress(value.builder)) {
32073
+ throw new JobEnvelopeError("Invalid job request: invalid builder");
32074
+ }
32075
+ if (typeof value.builderPublicKey !== "string" || !isHex(value.builderPublicKey)) {
32076
+ throw new JobEnvelopeError("Invalid job request: invalid builderPublicKey");
32077
+ }
32078
+ if (typeof value.grantId !== "string" || !isHex(value.grantId)) {
32079
+ throw new JobEnvelopeError("Invalid job request: invalid grantId");
32080
+ }
32081
+ requireString(value.scope, "scope", "job request");
32082
+ if (!JOB_OPERATIONS.includes(value.operation)) {
32083
+ throw new JobEnvelopeError("Invalid job request: invalid operation");
32084
+ }
32085
+ if (value.pinnedVersion !== null && typeof value.pinnedVersion !== "string") {
32042
32086
  throw new JobEnvelopeError("Invalid job request: missing pinnedVersion");
32043
32087
  }
32088
+ if (typeof value.deadline !== "string" || !Number.isFinite(Date.parse(value.deadline))) {
32089
+ throw new JobEnvelopeError("Invalid job request: invalid deadline");
32090
+ }
32091
+ return value;
32092
+ }
32093
+ function validateRequestEnvelope(value) {
32094
+ requirePlainObject(value, "envelope", "job request envelope");
32095
+ requireExactKeys(value, ["request", "auth"], "job request envelope");
32096
+ validateJobRequest(value.request);
32044
32097
  requireString(value.auth, "auth", "job request envelope");
32045
32098
  return value;
32046
32099
  }
32047
32100
  function validateResult(value) {
32048
- if (value.v !== 1) {
32101
+ requirePlainObject(value, "result", "job result");
32102
+ requireExactKeys(
32103
+ value,
32104
+ ["v", "jobId", "scope", "version", "contentType", "body"],
32105
+ "job result"
32106
+ );
32107
+ if (value.v !== JOB_PROTOCOL_VERSION) {
32049
32108
  throw new JobEnvelopeError(
32050
32109
  `Unsupported job result version: ${String(value.v)}`
32051
32110
  );
@@ -32061,10 +32120,10 @@ function validateResult(value) {
32061
32120
  }
32062
32121
  return value;
32063
32122
  }
32064
- async function sealJobRequest(e, enclavePublicKey, ecies) {
32123
+ async function sealJobRequest(envelope, enclavePublicKey, ecies) {
32065
32124
  const encrypted = await ecies.encrypt(
32066
32125
  fromHex6(enclavePublicKey, "bytes"),
32067
- requestPlaintext(e)
32126
+ requestPlaintext(envelope)
32068
32127
  );
32069
32128
  return encryptedBytesToBase64(encrypted);
32070
32129
  }
@@ -32077,10 +32136,11 @@ async function openJobRequest(ciphertext, privateKey, ecies) {
32077
32136
  parseObject(plaintext, "job request envelope")
32078
32137
  );
32079
32138
  }
32080
- async function sealJobResult(r, builderPublicKey, ecies) {
32139
+ async function sealJobResult(result, builderPublicKey, ecies) {
32140
+ validateResult(result);
32081
32141
  const encrypted = await ecies.encrypt(
32082
32142
  fromHex6(builderPublicKey, "bytes"),
32083
- resultPlaintext(r)
32143
+ resultPlaintext(result)
32084
32144
  );
32085
32145
  const ciphertext = encryptedBytesToBase64(encrypted);
32086
32146
  const bytes = fromBase64(ciphertext);
@@ -32112,7 +32172,7 @@ async function openJobResult(ciphertext, builderPrivateKey, ecies, expect) {
32112
32172
 
32113
32173
  // src/protocol/personal-server-registration.ts
32114
32174
  import {
32115
- isAddress
32175
+ isAddress as isAddress2
32116
32176
  } from "viem";
32117
32177
  var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
32118
32178
  var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
@@ -32120,7 +32180,7 @@ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress
32120
32180
  "DataPortabilityServers"
32121
32181
  );
32122
32182
  function assertAddress(value, name) {
32123
- if (!isAddress(value)) {
32183
+ if (!isAddress2(value)) {
32124
32184
  throw new Error(`${name} must be a valid EVM address`);
32125
32185
  }
32126
32186
  }
@@ -32207,13 +32267,13 @@ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
32207
32267
 
32208
32268
  // src/personal-server-lite/owner-binding.ts
32209
32269
  import {
32210
- isAddress as isAddress2
32270
+ isAddress as isAddress3
32211
32271
  } from "viem";
32212
32272
  var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
32213
32273
  var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
32214
32274
  var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
32215
32275
  function assertAddress2(value, name) {
32216
- if (!isAddress2(value)) {
32276
+ if (!isAddress3(value)) {
32217
32277
  throw new Error(`${name} must be a valid EVM address`);
32218
32278
  }
32219
32279
  }
@@ -32263,7 +32323,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
32263
32323
  var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
32264
32324
 
32265
32325
  // src/account/personal-server-registration.ts
32266
- import { isAddress as isAddress3 } from "viem";
32326
+ import { isAddress as isAddress4 } from "viem";
32267
32327
  var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
32268
32328
  var AccountPersonalServerRegistrationError = class extends Error {
32269
32329
  status;
@@ -32282,7 +32342,7 @@ function trimTrailingSlash(value) {
32282
32342
  return value.replace(/\/+$/, "");
32283
32343
  }
32284
32344
  function assertAddress3(value, name) {
32285
- if (!isAddress3(value)) {
32345
+ if (!isAddress4(value)) {
32286
32346
  throw new Error(`${name} must be a valid EVM address`);
32287
32347
  }
32288
32348
  }
@@ -32808,7 +32868,7 @@ function buildMarkDataPointUnavailableRequest(config, input) {
32808
32868
 
32809
32869
  // src/protocol/data-point-deletion.ts
32810
32870
  import {
32811
- isAddress as isAddress5,
32871
+ isAddress as isAddress6,
32812
32872
  keccak256 as keccak2563,
32813
32873
  maxUint256,
32814
32874
  stringToBytes as stringToBytes3
@@ -32817,7 +32877,7 @@ import {
32817
32877
  // src/protocol/lineage.ts
32818
32878
  import {
32819
32879
  encodeAbiParameters,
32820
- isAddress as isAddress4,
32880
+ isAddress as isAddress5,
32821
32881
  keccak256 as keccak2562
32822
32882
  } from "viem";
32823
32883
  import { z } from "zod";
@@ -32897,7 +32957,7 @@ function isDataPointId(value) {
32897
32957
  return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
32898
32958
  }
32899
32959
  function deriveDataPointId(ownerAddress, scope) {
32900
- if (!isAddress4(ownerAddress, { strict: false })) {
32960
+ if (!isAddress5(ownerAddress, { strict: false })) {
32901
32961
  throw new Error(
32902
32962
  `ownerAddress is not an EVM address: ${String(ownerAddress)}`
32903
32963
  );
@@ -33148,7 +33208,7 @@ function tombstoneDeletedAt(value) {
33148
33208
  return typeof deletedAt === "string" ? deletedAt : null;
33149
33209
  }
33150
33210
  function assertAddress4(value, name) {
33151
- if (!isAddress5(value)) {
33211
+ if (!isAddress6(value)) {
33152
33212
  throw new Error(`${name} must be a valid EVM address`);
33153
33213
  }
33154
33214
  }
@@ -33564,7 +33624,7 @@ function tryGrantPermissions(scopes) {
33564
33624
 
33565
33625
  // src/protocol/personal-server-write.ts
33566
33626
  import { sha256 as sha2567 } from "@noble/hashes/sha2";
33567
- import { bytesToHex as bytesToHex4, isAddress as isAddress6 } from "viem";
33627
+ import { bytesToHex as bytesToHex4, isAddress as isAddress7 } from "viem";
33568
33628
  import { z as z4 } from "zod";
33569
33629
 
33570
33630
  // src/protocol/write-request.ts
@@ -33886,7 +33946,7 @@ function normalizeLineage(lineage, derivedScope) {
33886
33946
  for (const entry of lineage) {
33887
33947
  let id;
33888
33948
  if (isLineagePair(entry)) {
33889
- if (!isAddress6(entry.ownerAddress, { strict: false })) {
33949
+ if (!isAddress7(entry.ownerAddress, { strict: false })) {
33890
33950
  throw new WriteRequestError(
33891
33951
  "lineage source ownerAddress must be an EVM address",
33892
33952
  { ownerAddress: entry.ownerAddress }
@@ -35182,7 +35242,7 @@ function createGatewayClient(baseUrl) {
35182
35242
  }
35183
35243
 
35184
35244
  // src/protocol/escrow.ts
35185
- import { isHex } from "viem";
35245
+ import { isHex as isHex2 } from "viem";
35186
35246
  var GENERIC_PAYMENT_TYPES = {
35187
35247
  GenericPayment: [
35188
35248
  { name: "payerAddress", type: "address" },
@@ -35398,10 +35458,10 @@ function optionalUint256Decimal(value) {
35398
35458
  return value === void 0 || isUint256Decimal(value);
35399
35459
  }
35400
35460
  function isAddressHex(value) {
35401
- return typeof value === "string" && isHex(value, { strict: true }) && value.length === 42;
35461
+ return typeof value === "string" && isHex2(value, { strict: true }) && value.length === 42;
35402
35462
  }
35403
35463
  function isHash(value) {
35404
- return typeof value === "string" && isHex(value, { strict: true }) && value.length === 66;
35464
+ return typeof value === "string" && isHex2(value, { strict: true }) && value.length === 66;
35405
35465
  }
35406
35466
  function isUint256Decimal(value) {
35407
35467
  if (typeof value !== "string" || value.length === 0 || value.length > 78) {