@opendatalabs/vana-sdk 4.2.0 → 4.3.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.
@@ -60,6 +60,7 @@ export { DERIVATIVE_STATUS_PATH, DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS, DEFAULT_D
60
60
  export { deriveDataPointId, isDataPointId, scopeNamespace, derivedScopeViolatesNaming, assertDerivedScopeNaming, isRedactedLineageNode, personalServerLineagePath, gatewayLineagePath, getLineage, getPersonalServerLineage, getGatewayLineage, LineageNodeSchema, RedactedLineageNodeSchema, LineageEntrySchema, LineageGraphSchema, type LineageNode, type RedactedLineageNode, type LineageEntry, type LineageGraph, type LineageReadResult, type PersonalServerLineageParams, type GatewayLineageParams, type GetLineageParams, } from "./protocol/lineage.js";
61
61
  export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file.js";
62
62
  export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type OwnerServerRecord, type OwnerServersResult, type GatewayGrantFee, type GatewayGrantStatus, type GatewayGrantResponse, type GrantListItem, type DataPointRecord, type DataPointListResult, type ListDataPointsOptions, type RegisterServerParams, type RegisterServerResult, type RegisterBuilderParams, type RegisterBuilderResult, type RegisterDataPointParams, type RegisterDataPointResult, type GetDataPointOptions, type DeleteDataPointParams, type DeleteDataPointResult, type CreateGrantParams, type RevokeGrantParams, type AccessRecord, type PayForOperationParams, type PayForOperationResult, type SettleOpType, type SettleItem, type SettlePromoteResult, type SettleReconcileItem, type SettleParams, type SettleResult, type GatewayClient, } from "./protocol/gateway.js";
63
+ export { mergeWithLiveGrant, liveGrantScopes, findLiveGrant, unionGrantScopes, type GrantUnion, type GrantUnionGateway, type GrantUnionStatus, type MergeWithLiveGrantInput, type MergeWithLiveGrantResult, } from "./direct/grant-union.js";
63
64
  export { createEscrowGatewayClient, genericPaymentDomain, GENERIC_PAYMENT_TYPES, ESCROW_DEPOSIT_ABI, NATIVE_ASSET_ADDRESS, type GenericPaymentMessage, type EscrowBalanceEntry, type EscrowBalanceResult, type EscrowBalanceSyncResult, type DepositSubmissionResult, type PaymentBreakdown, type EscrowPayResult, EscrowWithdrawalLifecycleError, EscrowWithdrawalRejectionError, type EscrowPaymentClient, type EscrowWithdrawalFailureResult, type EscrowWithdrawalRejectedResult, type EscrowWithdrawalRejectionCode, type EscrowWithdrawalSubmittedResult, type EscrowWithdrawalSubmittedWithoutTransaction, type EscrowWithdrawalSubmittedWithTransaction, type EscrowWithdrawalSettledResult, type EscrowWithdrawalResult, type SubmitDepositParams, type PayForOpParams, type WithdrawFromEscrowParams, type WithdrawNonceResponse, type EscrowGatewayClient, type SubmittedDepositEntry, type FinalizedDepositEntry, type FailedDepositEntry, } from "./protocol/escrow.js";
64
65
  export { authorizeEscrowPayment, authorizeGrantPayment, buildEscrowPaymentHeader, buildGrantPaymentHeader, createDefaultNonceSource, DATA_ACCESS_OP_TYPE, GRANT_OP_TYPE, paymentReceiptFromHeader, paymentResponseMetadataFromHeader, toDirectFeeBreakdown, toDirectPaymentReceipt, type EscrowPaymentConfig, type EscrowPaymentHeaderConfig, type PaymentNonceSource, type SignTypedDataFn, } from "./direct/escrow-payment.js";
65
66
  export { parsePersonalServerPaymentRequired, type FetchResponseLike, } from "./direct/personal-server-read.js";
@@ -37387,6 +37387,101 @@ function createGatewayClient(baseUrl) {
37387
37387
  };
37388
37388
  }
37389
37389
 
37390
+ // src/direct/grant-union.ts
37391
+ import { DirectConfigError } from "./direct/errors.js";
37392
+ function dedupe(entries) {
37393
+ return [...new Set(entries)];
37394
+ }
37395
+ function isCarryable(entry) {
37396
+ try {
37397
+ parseScope(parseScopeEntry(entry).scope);
37398
+ return true;
37399
+ } catch {
37400
+ return false;
37401
+ }
37402
+ }
37403
+ function unionGrantScopes(liveScopes, scopes, removeScopes = []) {
37404
+ const remove = new Set(removeScopes);
37405
+ const conflicting = scopes.filter((entry) => remove.has(entry));
37406
+ if (conflicting.length > 0) {
37407
+ throw new DirectConfigError(
37408
+ `${conflicting.join(", ")} cannot be both requested and removed. Drop it from scopes or from removeScopes.`,
37409
+ { conflicting }
37410
+ );
37411
+ }
37412
+ const live = dedupe(liveScopes);
37413
+ const requested = dedupe(scopes);
37414
+ const liveSet = new Set(live);
37415
+ const removed = live.filter((entry) => remove.has(entry));
37416
+ const remaining = live.filter((entry) => !remove.has(entry));
37417
+ const notCarried = remaining.filter((entry) => !isCarryable(entry));
37418
+ const keptAll = remaining.filter(isCarryable);
37419
+ const added = requested.filter((entry) => !liveSet.has(entry));
37420
+ return {
37421
+ scopes: dedupe([...keptAll, ...added]),
37422
+ kept: keptAll,
37423
+ added,
37424
+ removed,
37425
+ notCarried,
37426
+ liveScopes: live
37427
+ };
37428
+ }
37429
+ function isActiveGrant(grant) {
37430
+ return !grant.revokedAt && !grant.expired;
37431
+ }
37432
+ function sameHex(a, b) {
37433
+ return a.toLowerCase() === b.toLowerCase();
37434
+ }
37435
+ async function findLiveGrant(gateway, owner, granteeId) {
37436
+ const grants = await gateway.listGrantsByUser(owner);
37437
+ const matching = grants.filter(
37438
+ (grant) => sameHex(grant.granteeId, granteeId) && isActiveGrant(grant)
37439
+ ).sort((a, b) => {
37440
+ const av = BigInt(a.grantVersion || "0");
37441
+ const bv = BigInt(b.grantVersion || "0");
37442
+ return av === bv ? 0 : av > bv ? -1 : 1;
37443
+ });
37444
+ return matching[0] ?? null;
37445
+ }
37446
+ async function liveGrantScopes(gateway, owner, granteeId) {
37447
+ const grant = await findLiveGrant(gateway, owner, granteeId);
37448
+ return grant ? [...grant.scopes] : [];
37449
+ }
37450
+ async function resolveGranteeId(input) {
37451
+ if (input.granteeId) {
37452
+ return input.granteeId;
37453
+ }
37454
+ if (!input.appAddress) {
37455
+ throw new DirectConfigError(
37456
+ "mergeWithLiveGrant needs granteeId or appAddress to find the app's grant."
37457
+ );
37458
+ }
37459
+ if (!input.gateway.getBuilder) {
37460
+ throw new DirectConfigError(
37461
+ "mergeWithLiveGrant needs gateway.getBuilder to resolve appAddress to a granteeId. Pass granteeId instead."
37462
+ );
37463
+ }
37464
+ const builder = await input.gateway.getBuilder(input.appAddress);
37465
+ return builder?.id ?? null;
37466
+ }
37467
+ async function mergeWithLiveGrant(input) {
37468
+ const removeScopes = input.removeScopes ?? [];
37469
+ unionGrantScopes([], input.scopes, removeScopes);
37470
+ const granteeId = await resolveGranteeId(input);
37471
+ const grant = granteeId ? await findLiveGrant(input.gateway, input.owner, granteeId) : null;
37472
+ if (!grant) {
37473
+ return {
37474
+ status: "no_live_grant",
37475
+ ...unionGrantScopes([], input.scopes, removeScopes)
37476
+ };
37477
+ }
37478
+ return {
37479
+ status: "merged",
37480
+ grantId: grant.id,
37481
+ ...unionGrantScopes(grant.scopes, input.scopes, removeScopes)
37482
+ };
37483
+ }
37484
+
37390
37485
  // src/direct/escrow-payment.ts
37391
37486
  var GRANT_OP_TYPE = "grant";
37392
37487
  var DATA_ACCESS_OP_TYPE = "data_access";
@@ -38086,6 +38181,7 @@ export {
38086
38181
  encryptWithPassword,
38087
38182
  escrowContractAddress,
38088
38183
  escrowPaymentDomain,
38184
+ findLiveGrant,
38089
38185
  formatScopeEntry,
38090
38186
  gatewayLineagePath,
38091
38187
  generatePkceVerifier,
@@ -38119,7 +38215,9 @@ export {
38119
38215
  isTombstoneHashes,
38120
38216
  kmsIssuedPreimage,
38121
38217
  listQuestions,
38218
+ liveGrantScopes,
38122
38219
  mainnetServices,
38220
+ mergeWithLiveGrant,
38123
38221
  moksha,
38124
38222
  mokshaServices,
38125
38223
  mokshaTestnet2 as mokshaTestnet,
@@ -38163,6 +38261,7 @@ export {
38163
38261
  toDirectPaymentReceipt,
38164
38262
  tombstoneDeletedAt,
38165
38263
  tryGrantPermissions,
38264
+ unionGrantScopes,
38166
38265
  userPsId,
38167
38266
  vanaMainnet2 as vanaMainnet,
38168
38267
  verifyEnclaveIdentityEvidence,