@opendatalabs/vana-sdk 4.2.0 → 4.3.1

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.
@@ -1208,7 +1208,7 @@ __export(index_node_exports, {
1208
1208
  ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI,
1209
1209
  EscrowWithdrawalLifecycleError: () => EscrowWithdrawalLifecycleError,
1210
1210
  EscrowWithdrawalRejectionError: () => EscrowWithdrawalRejectionError,
1211
- ExpiredTokenError: () => import_errors15.ExpiredTokenError,
1211
+ ExpiredTokenError: () => import_errors16.ExpiredTokenError,
1212
1212
  FEE_REGISTRY_ABI: () => FEE_REGISTRY_ABI,
1213
1213
  GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
1214
1214
  GRANT_OP_TYPE: () => GRANT_OP_TYPE,
@@ -1218,7 +1218,7 @@ __export(index_node_exports, {
1218
1218
  InMemoryTokenStore: () => InMemoryTokenStore,
1219
1219
  IngestResponseSchema: () => IngestResponseSchema,
1220
1220
  InvalidScopeEntryError: () => InvalidScopeEntryError,
1221
- InvalidSignatureError: () => import_errors15.InvalidSignatureError,
1221
+ InvalidSignatureError: () => import_errors16.InvalidSignatureError,
1222
1222
  IpfsStorage: () => IpfsStorage,
1223
1223
  JOB_OPERATIONS: () => JOB_OPERATIONS,
1224
1224
  JOB_PROTOCOL_VERSION: () => JOB_PROTOCOL_VERSION,
@@ -1242,7 +1242,7 @@ __export(index_node_exports, {
1242
1242
  MAX_QUESTION_MODEL_CHARS: () => MAX_QUESTION_MODEL_CHARS,
1243
1243
  MAX_QUESTION_SOURCE_SCOPES: () => MAX_QUESTION_SOURCE_SCOPES,
1244
1244
  MAX_WAIT_SECONDS: () => MAX_WAIT_SECONDS,
1245
- MissingAuthError: () => import_errors15.MissingAuthError,
1245
+ MissingAuthError: () => import_errors16.MissingAuthError,
1246
1246
  NATIVE_ASSET_ADDRESS: () => NATIVE_ASSET_ADDRESS,
1247
1247
  NATIVE_VANA_ASSET: () => NATIVE_VANA_ASSET,
1248
1248
  NodeECIESProvider: () => NodeECIESUint8Provider,
@@ -1351,6 +1351,7 @@ __export(index_node_exports, {
1351
1351
  encryptWithPassword: () => encryptWithPassword,
1352
1352
  escrowContractAddress: () => escrowContractAddress,
1353
1353
  escrowPaymentDomain: () => escrowPaymentDomain,
1354
+ findLiveGrant: () => findLiveGrant,
1354
1355
  formatScopeEntry: () => formatScopeEntry,
1355
1356
  gatewayLineagePath: () => gatewayLineagePath,
1356
1357
  generatePkceVerifier: () => generatePkceVerifier,
@@ -1384,7 +1385,9 @@ __export(index_node_exports, {
1384
1385
  isTombstoneHashes: () => isTombstoneHashes,
1385
1386
  kmsIssuedPreimage: () => kmsIssuedPreimage,
1386
1387
  listQuestions: () => listQuestions,
1388
+ liveGrantScopes: () => liveGrantScopes,
1387
1389
  mainnetServices: () => mainnetServices,
1390
+ mergeWithLiveGrant: () => mergeWithLiveGrant,
1388
1391
  moksha: () => moksha,
1389
1392
  mokshaServices: () => mokshaServices,
1390
1393
  mokshaTestnet: () => mokshaTestnet2,
@@ -1428,6 +1431,7 @@ __export(index_node_exports, {
1428
1431
  toDirectPaymentReceipt: () => toDirectPaymentReceipt,
1429
1432
  tombstoneDeletedAt: () => tombstoneDeletedAt,
1430
1433
  tryGrantPermissions: () => tryGrantPermissions,
1434
+ unionGrantScopes: () => unionGrantScopes,
1431
1435
  userPsId: () => userPsId,
1432
1436
  vanaMainnet: () => vanaMainnet2,
1433
1437
  verifyEnclaveIdentityEvidence: () => verifyEnclaveIdentityEvidence,
@@ -31922,7 +31926,7 @@ async function verifyWeb3Signed(params) {
31922
31926
  }
31923
31927
 
31924
31928
  // src/index.node.ts
31925
- var import_errors15 = require("./auth/errors.cjs");
31929
+ var import_errors16 = require("./auth/errors.cjs");
31926
31930
 
31927
31931
  // src/auth/pkce.ts
31928
31932
  var PKCE_VERIFIER_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
@@ -37587,6 +37591,101 @@ function createGatewayClient(baseUrl) {
37587
37591
  };
37588
37592
  }
37589
37593
 
37594
+ // src/direct/grant-union.ts
37595
+ var import_errors13 = require("./direct/errors.cjs");
37596
+ function dedupe(entries) {
37597
+ return [...new Set(entries)];
37598
+ }
37599
+ function isCarryable(entry) {
37600
+ try {
37601
+ parseScope(parseScopeEntry(entry).scope);
37602
+ return true;
37603
+ } catch {
37604
+ return false;
37605
+ }
37606
+ }
37607
+ function unionGrantScopes(liveScopes, scopes, removeScopes = []) {
37608
+ const remove = new Set(removeScopes);
37609
+ const conflicting = scopes.filter((entry) => remove.has(entry));
37610
+ if (conflicting.length > 0) {
37611
+ throw new import_errors13.DirectConfigError(
37612
+ `${conflicting.join(", ")} cannot be both requested and removed. Drop it from scopes or from removeScopes.`,
37613
+ { conflicting }
37614
+ );
37615
+ }
37616
+ const live = dedupe(liveScopes);
37617
+ const requested = dedupe(scopes);
37618
+ const liveSet = new Set(live);
37619
+ const removed = live.filter((entry) => remove.has(entry));
37620
+ const remaining = live.filter((entry) => !remove.has(entry));
37621
+ const notCarried = remaining.filter((entry) => !isCarryable(entry));
37622
+ const keptAll = remaining.filter(isCarryable);
37623
+ const added = requested.filter((entry) => !liveSet.has(entry));
37624
+ return {
37625
+ scopes: dedupe([...keptAll, ...added]),
37626
+ kept: keptAll,
37627
+ added,
37628
+ removed,
37629
+ notCarried,
37630
+ liveScopes: live
37631
+ };
37632
+ }
37633
+ function isActiveGrant(grant) {
37634
+ return !grant.revokedAt && !grant.expired;
37635
+ }
37636
+ function sameHex(a, b) {
37637
+ return a.toLowerCase() === b.toLowerCase();
37638
+ }
37639
+ async function findLiveGrant(gateway, owner, granteeId) {
37640
+ const grants = await gateway.listGrantsByUser(owner);
37641
+ const matching = grants.filter(
37642
+ (grant) => sameHex(grant.granteeId, granteeId) && isActiveGrant(grant)
37643
+ ).sort((a, b) => {
37644
+ const av = BigInt(a.grantVersion || "0");
37645
+ const bv = BigInt(b.grantVersion || "0");
37646
+ return av === bv ? 0 : av > bv ? -1 : 1;
37647
+ });
37648
+ return matching[0] ?? null;
37649
+ }
37650
+ async function liveGrantScopes(gateway, owner, granteeId) {
37651
+ const grant = await findLiveGrant(gateway, owner, granteeId);
37652
+ return grant ? [...grant.scopes] : [];
37653
+ }
37654
+ async function resolveGranteeId(input) {
37655
+ if (input.granteeId) {
37656
+ return input.granteeId;
37657
+ }
37658
+ if (!input.appAddress) {
37659
+ throw new import_errors13.DirectConfigError(
37660
+ "mergeWithLiveGrant needs granteeId or appAddress to find the app's grant."
37661
+ );
37662
+ }
37663
+ if (!input.gateway.getBuilder) {
37664
+ throw new import_errors13.DirectConfigError(
37665
+ "mergeWithLiveGrant needs gateway.getBuilder to resolve appAddress to a granteeId. Pass granteeId instead."
37666
+ );
37667
+ }
37668
+ const builder = await input.gateway.getBuilder(input.appAddress);
37669
+ return builder?.id ?? null;
37670
+ }
37671
+ async function mergeWithLiveGrant(input) {
37672
+ const removeScopes = input.removeScopes ?? [];
37673
+ unionGrantScopes([], input.scopes, removeScopes);
37674
+ const granteeId = await resolveGranteeId(input);
37675
+ const grant = granteeId ? await findLiveGrant(input.gateway, input.owner, granteeId) : null;
37676
+ if (!grant) {
37677
+ return {
37678
+ status: "no_live_grant",
37679
+ ...unionGrantScopes([], input.scopes, removeScopes)
37680
+ };
37681
+ }
37682
+ return {
37683
+ status: "merged",
37684
+ grantId: grant.id,
37685
+ ...unionGrantScopes(grant.scopes, input.scopes, removeScopes)
37686
+ };
37687
+ }
37688
+
37590
37689
  // src/direct/escrow-payment.ts
37591
37690
  var GRANT_OP_TYPE = "grant";
37592
37691
  var DATA_ACCESS_OP_TYPE = "data_access";
@@ -37823,8 +37922,8 @@ async function authorizeEscrowPayment(params) {
37823
37922
  }
37824
37923
 
37825
37924
  // src/direct/personal-server-read.ts
37826
- var import_errors13 = require("./direct/errors.cjs");
37827
- var import_errors14 = require("./errors.cjs");
37925
+ var import_errors14 = require("./direct/errors.cjs");
37926
+ var import_errors15 = require("./errors.cjs");
37828
37927
  function asRecord2(value) {
37829
37928
  return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
37830
37929
  }
@@ -37868,7 +37967,7 @@ function parseLegacyGrantOperation(params) {
37868
37967
  const { challengeGrantId, challengeOpId, challengeOpType, grantId } = params;
37869
37968
  const opType = challengeOpType ?? GRANT_OP_TYPE;
37870
37969
  if (opType !== GRANT_OP_TYPE) {
37871
- throw new import_errors13.PersonalServerReadError(
37970
+ throw new import_errors14.PersonalServerReadError(
37872
37971
  "Personal Server payment challenge used an unsupported escrow op type",
37873
37972
  402,
37874
37973
  { opType: challengeOpType }
@@ -37876,14 +37975,14 @@ function parseLegacyGrantOperation(params) {
37876
37975
  }
37877
37976
  const opId = challengeOpId ?? challengeGrantId ?? grantId;
37878
37977
  if (!opId || !isBytes32Hex(opId)) {
37879
- throw new import_errors13.PersonalServerReadError(
37978
+ throw new import_errors14.PersonalServerReadError(
37880
37979
  "Personal Server payment challenge used an invalid escrow op id",
37881
37980
  402,
37882
37981
  { opId }
37883
37982
  );
37884
37983
  }
37885
37984
  if (opId.toLowerCase() !== grantId.toLowerCase()) {
37886
- throw new import_errors13.PersonalServerReadError(
37985
+ throw new import_errors14.PersonalServerReadError(
37887
37986
  "Personal Server payment challenge did not match the requested grant",
37888
37987
  402,
37889
37988
  { opId, grantId }
@@ -37929,7 +38028,7 @@ function parseCanonicalDataAccessAccept(value) {
37929
38028
  function parseCanonicalDataAccessPayment(params) {
37930
38029
  const { body, grantId, raw } = params;
37931
38030
  if (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED") {
37932
- throw new import_errors13.PersonalServerReadError(
38031
+ throw new import_errors14.PersonalServerReadError(
37933
38032
  "Personal Server data-access payment response was not a canonical x402 challenge",
37934
38033
  402
37935
38034
  );
@@ -37968,20 +38067,20 @@ async function parsePersonalServerPaymentRequired(res, grantId) {
37968
38067
  "accepts"
37969
38068
  );
37970
38069
  if (hasAcceptsEnvelope && (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED")) {
37971
- throw new import_errors13.PersonalServerReadError(
38070
+ throw new import_errors14.PersonalServerReadError(
37972
38071
  "Personal Server grant payment response was not a canonical x402 challenge",
37973
38072
  402
37974
38073
  );
37975
38074
  }
37976
38075
  const accept = preferredLegacyAccept(body);
37977
38076
  if (hasDataAccessMarker(body) && !accept) {
37978
- throw new import_errors13.PersonalServerReadError(
38077
+ throw new import_errors14.PersonalServerReadError(
37979
38078
  "Personal Server data-access payment challenge was untrusted or incomplete",
37980
38079
  402
37981
38080
  );
37982
38081
  }
37983
38082
  if (hasAcceptsEnvelope && !accept) {
37984
- throw new import_errors13.PersonalServerReadError(
38083
+ throw new import_errors14.PersonalServerReadError(
37985
38084
  "Personal Server grant payment challenge had no compatible escrow offer",
37986
38085
  402
37987
38086
  );
@@ -37999,7 +38098,7 @@ async function parsePersonalServerPaymentRequired(res, grantId) {
37999
38098
  const accessRecord2 = parseAccessRecord(accept.accessRecord);
38000
38099
  const hasAccessRecord = accept.accessRecord !== void 0;
38001
38100
  if (!network || !payerAddress || !isAddressHex2(payerAddress) || !opId || !isBytes32Hex(opId) || !asset || !isAddressHex2(asset) || !amount || !isUint256Decimal3(amount, true) || !paymentNonce || !isUint256Decimal3(paymentNonce, false) || !acceptAsset || acceptAsset.toLowerCase() !== asset.toLowerCase() || acceptAmount !== amount || hasAccessRecord && (!accessRecord2 || !isValidDataAccessRecord(accessRecord2) || accessRecord2.accessor.toLowerCase() !== payerAddress.toLowerCase()) || amount === "0" && !accessRecord2) {
38002
- throw new import_errors13.PersonalServerReadError(
38101
+ throw new import_errors14.PersonalServerReadError(
38003
38102
  "Personal Server grant payment challenge was untrusted or incomplete",
38004
38103
  402
38005
38104
  );
@@ -38287,6 +38386,7 @@ async function parsePSError(response) {
38287
38386
  encryptWithPassword,
38288
38387
  escrowContractAddress,
38289
38388
  escrowPaymentDomain,
38389
+ findLiveGrant,
38290
38390
  formatScopeEntry,
38291
38391
  gatewayLineagePath,
38292
38392
  generatePkceVerifier,
@@ -38320,7 +38420,9 @@ async function parsePSError(response) {
38320
38420
  isTombstoneHashes,
38321
38421
  kmsIssuedPreimage,
38322
38422
  listQuestions,
38423
+ liveGrantScopes,
38323
38424
  mainnetServices,
38425
+ mergeWithLiveGrant,
38324
38426
  moksha,
38325
38427
  mokshaServices,
38326
38428
  mokshaTestnet,
@@ -38364,6 +38466,7 @@ async function parsePSError(response) {
38364
38466
  toDirectPaymentReceipt,
38365
38467
  tombstoneDeletedAt,
38366
38468
  tryGrantPermissions,
38469
+ unionGrantScopes,
38367
38470
  userPsId,
38368
38471
  vanaMainnet,
38369
38472
  verifyEnclaveIdentityEvidence,