@opendatalabs/vana-sdk 3.13.4 → 3.14.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.
- package/dist/account/personal-server-lite-owner-binding.d.ts +1 -1
- package/dist/account/personal-server-registration.d.ts +1 -1
- package/dist/auth/errors.d.ts +1 -1
- package/dist/auth/oauth-client.d.ts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/chains/index.d.ts +2 -2
- package/dist/chains.browser.d.ts +2 -2
- package/dist/chains.d.ts +2 -2
- package/dist/chains.node.d.ts +2 -2
- package/dist/config/contracts.config.cjs +1 -1
- package/dist/config/contracts.config.cjs.map +1 -1
- package/dist/config/contracts.config.js +1 -1
- package/dist/config/contracts.config.js.map +1 -1
- package/dist/contracts/contractController.d.ts +4 -4
- package/dist/core/client.d.ts +1 -1
- package/dist/crypto/ecies/base.d.ts +1 -1
- package/dist/crypto/ecies/browser.d.ts +1 -1
- package/dist/crypto/ecies/index.d.ts +2 -2
- package/dist/crypto/ecies/node.d.ts +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.d.ts +1 -1
- package/dist/direct/access-request-client.cjs +3 -1
- package/dist/direct/access-request-client.cjs.map +1 -1
- package/dist/direct/access-request-client.d.ts +2 -2
- package/dist/direct/access-request-client.js +3 -1
- package/dist/direct/access-request-client.js.map +1 -1
- package/dist/direct/connect-flow.d.ts +1 -1
- package/dist/direct/controller.cjs +72 -32
- package/dist/direct/controller.cjs.map +1 -1
- package/dist/direct/controller.d.ts +48 -10
- package/dist/direct/controller.js +77 -33
- package/dist/direct/controller.js.map +1 -1
- package/dist/direct/endpoints.d.ts +1 -1
- package/dist/direct/errors.cjs +11 -2
- package/dist/direct/errors.cjs.map +1 -1
- package/dist/direct/errors.d.ts +14 -1
- package/dist/direct/errors.js +9 -1
- package/dist/direct/errors.js.map +1 -1
- package/dist/direct/escrow-payment.cjs +147 -12
- package/dist/direct/escrow-payment.cjs.map +1 -1
- package/dist/direct/escrow-payment.d.ts +65 -12
- package/dist/direct/escrow-payment.js +143 -12
- package/dist/direct/escrow-payment.js.map +1 -1
- package/dist/direct/personal-server-read.cjs +164 -23
- package/dist/direct/personal-server-read.cjs.map +1 -1
- package/dist/direct/personal-server-read.d.ts +28 -18
- package/dist/direct/personal-server-read.js +167 -25
- package/dist/direct/personal-server-read.js.map +1 -1
- package/dist/direct/types.cjs.map +1 -1
- package/dist/direct/types.d.ts +81 -21
- package/dist/direct/types.js.map +1 -1
- package/dist/direct/use-direct-vana-connect.d.ts +1 -1
- package/dist/generated/abi/index.d.ts +25 -25
- package/dist/generated/addresses.cjs +6 -6
- package/dist/generated/addresses.cjs.map +1 -1
- package/dist/generated/addresses.d.ts +6 -6
- package/dist/generated/addresses.js +6 -6
- package/dist/generated/addresses.js.map +1 -1
- package/dist/index.browser.d.ts +44 -44
- package/dist/index.browser.js +6 -6
- package/dist/index.browser.js.map +2 -2
- package/dist/index.node.cjs +498 -6
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +48 -45
- package/dist/index.node.js +486 -6
- package/dist/index.node.js.map +4 -4
- package/dist/node.d.ts +1 -1
- package/dist/platform/browser-only.d.ts +3 -3
- package/dist/platform/browser-safe.d.ts +3 -3
- package/dist/platform/browser.d.ts +1 -1
- package/dist/platform/index.d.ts +5 -5
- package/dist/platform/node.d.ts +1 -1
- package/dist/platform/ports/openpgp-port.d.ts +1 -1
- package/dist/platform/utils.d.ts +1 -1
- package/dist/platform.browser.d.ts +4 -4
- package/dist/platform.d.ts +5 -5
- package/dist/platform.node.d.ts +5 -5
- package/dist/protocol/data-point-status.d.ts +1 -1
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow-deposit.d.ts +1 -1
- package/dist/protocol/escrow.cjs.map +1 -1
- package/dist/protocol/escrow.d.ts +11 -4
- package/dist/protocol/escrow.js.map +1 -1
- package/dist/protocol/fee-registry.d.ts +1 -1
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.d.ts +1 -1
- package/dist/protocol/personal-server-data.d.ts +2 -2
- package/dist/protocol/personal-server-registration.d.ts +2 -2
- package/dist/react.d.ts +3 -3
- package/dist/server.cjs +12 -0
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +8 -8
- package/dist/server.js +12 -0
- package/dist/server.js.map +1 -1
- package/dist/session-relay/client.d.ts +1 -1
- package/dist/session-relay/endpoints.d.ts +1 -1
- package/dist/session-relay/errors.d.ts +1 -1
- package/dist/session-relay/index.d.ts +5 -5
- package/dist/session-relay/signing.d.ts +1 -1
- package/dist/session-relay/types.d.ts +1 -1
- package/dist/session-relay.d.ts +5 -5
- package/dist/storage/default.d.ts +2 -2
- package/dist/storage/index.d.ts +16 -16
- package/dist/storage/manager.d.ts +1 -1
- package/dist/storage/providers/callback-storage.d.ts +2 -2
- package/dist/storage/providers/dropbox.d.ts +1 -1
- package/dist/storage/providers/google-drive.d.ts +1 -1
- package/dist/storage/providers/ipfs.d.ts +1 -1
- package/dist/storage/providers/pinata.d.ts +1 -1
- package/dist/storage/providers/r2.d.ts +1 -1
- package/dist/storage/providers/vana-storage.d.ts +3 -3
- package/dist/types/config.d.ts +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/types.d.ts +1 -1
- package/package.json +13 -1
package/dist/index.node.cjs
CHANGED
|
@@ -1184,6 +1184,7 @@ __export(index_node_exports, {
|
|
|
1184
1184
|
CallbackStorage: () => CallbackStorage,
|
|
1185
1185
|
ContractFactory: () => ContractFactory,
|
|
1186
1186
|
ContractNotFoundError: () => ContractNotFoundError,
|
|
1187
|
+
DATA_ACCESS_OP_TYPE: () => DATA_ACCESS_OP_TYPE,
|
|
1187
1188
|
DATA_REGISTRY_STATUS_ABI: () => DATA_REGISTRY_STATUS_ABI,
|
|
1188
1189
|
DataFileEnvelopeSchema: () => DataFileEnvelopeSchema,
|
|
1189
1190
|
DataPointStatus: () => DataPointStatus,
|
|
@@ -1193,6 +1194,7 @@ __export(index_node_exports, {
|
|
|
1193
1194
|
ExpiredTokenError: () => ExpiredTokenError,
|
|
1194
1195
|
FEE_REGISTRY_ABI: () => FEE_REGISTRY_ABI,
|
|
1195
1196
|
GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
|
|
1197
|
+
GRANT_OP_TYPE: () => GRANT_OP_TYPE,
|
|
1196
1198
|
GRANT_REGISTRATION_TYPES: () => GRANT_REGISTRATION_TYPES,
|
|
1197
1199
|
GRANT_REVOCATION_TYPES: () => GRANT_REVOCATION_TYPES,
|
|
1198
1200
|
GoogleDriveStorage: () => GoogleDriveStorage,
|
|
@@ -1238,8 +1240,12 @@ __export(index_node_exports, {
|
|
|
1238
1240
|
VanaError: () => VanaError,
|
|
1239
1241
|
VanaStorage: () => VanaStorage,
|
|
1240
1242
|
assertValidPkceVerifier: () => assertValidPkceVerifier,
|
|
1243
|
+
authorizeEscrowPayment: () => authorizeEscrowPayment,
|
|
1244
|
+
authorizeGrantPayment: () => authorizeGrantPayment,
|
|
1241
1245
|
buildDepositNativeRequest: () => buildDepositNativeRequest,
|
|
1242
1246
|
buildDepositTokenRequest: () => buildDepositTokenRequest,
|
|
1247
|
+
buildEscrowPaymentHeader: () => buildEscrowPaymentHeader,
|
|
1248
|
+
buildGrantPaymentHeader: () => buildGrantPaymentHeader,
|
|
1243
1249
|
buildMarkDataPointUnavailableRequest: () => buildMarkDataPointUnavailableRequest,
|
|
1244
1250
|
buildPersonalServerDataReadRequest: () => buildPersonalServerDataReadRequest,
|
|
1245
1251
|
buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
|
|
@@ -1256,6 +1262,7 @@ __export(index_node_exports, {
|
|
|
1256
1262
|
contractCacheForTesting: () => contractCacheForTesting,
|
|
1257
1263
|
createBrowserPlatformAdapter: () => createBrowserPlatformAdapter,
|
|
1258
1264
|
createDataFileEnvelope: () => createDataFileEnvelope,
|
|
1265
|
+
createDefaultNonceSource: () => createDefaultNonceSource,
|
|
1259
1266
|
createEscrowGatewayClient: () => createEscrowGatewayClient,
|
|
1260
1267
|
createGatewayClient: () => createGatewayClient,
|
|
1261
1268
|
createNodePlatformAdapter: () => createNodePlatformAdapter,
|
|
@@ -1300,8 +1307,11 @@ __export(index_node_exports, {
|
|
|
1300
1307
|
mokshaServices: () => mokshaServices,
|
|
1301
1308
|
mokshaTestnet: () => mokshaTestnet2,
|
|
1302
1309
|
parsePSError: () => parsePSError,
|
|
1310
|
+
parsePersonalServerPaymentRequired: () => parsePersonalServerPaymentRequired,
|
|
1303
1311
|
parseScope: () => parseScope,
|
|
1304
1312
|
parseWeb3SignedHeader: () => parseWeb3SignedHeader,
|
|
1313
|
+
paymentReceiptFromHeader: () => paymentReceiptFromHeader,
|
|
1314
|
+
paymentResponseMetadataFromHeader: () => paymentResponseMetadataFromHeader,
|
|
1305
1315
|
personalServerDataReadPath: () => personalServerDataReadPath,
|
|
1306
1316
|
personalServerRegistrationDomain: () => personalServerRegistrationDomain,
|
|
1307
1317
|
readPersonalServerData: () => readPersonalServerData,
|
|
@@ -1315,6 +1325,8 @@ __export(index_node_exports, {
|
|
|
1315
1325
|
signPersonalServerLiteOwnerBinding: () => signPersonalServerLiteOwnerBinding,
|
|
1316
1326
|
signPersonalServerLiteOwnerBindingWithAccountClient: () => signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
1317
1327
|
signPersonalServerRegistrationWithAccount: () => signPersonalServerRegistrationWithAccount,
|
|
1328
|
+
toDirectFeeBreakdown: () => toDirectFeeBreakdown,
|
|
1329
|
+
toDirectPaymentReceipt: () => toDirectPaymentReceipt,
|
|
1318
1330
|
vanaMainnet: () => vanaMainnet2,
|
|
1319
1331
|
verifyGrantRegistration: () => verifyGrantRegistration,
|
|
1320
1332
|
verifyPkceChallenge: () => verifyPkceChallenge,
|
|
@@ -28636,7 +28648,7 @@ var CONTRACTS = {
|
|
|
28636
28648
|
},
|
|
28637
28649
|
DataPortabilityServers: {
|
|
28638
28650
|
addresses: {
|
|
28639
|
-
14800: "
|
|
28651
|
+
14800: "0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab",
|
|
28640
28652
|
1480: "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c"
|
|
28641
28653
|
}
|
|
28642
28654
|
},
|
|
@@ -28794,7 +28806,7 @@ var CONTRACTS = {
|
|
|
28794
28806
|
},
|
|
28795
28807
|
_meta: {
|
|
28796
28808
|
discoveredFrom: "ComputeEngine",
|
|
28797
|
-
lastUpdated: "2026-
|
|
28809
|
+
lastUpdated: "2026-08-18"
|
|
28798
28810
|
}
|
|
28799
28811
|
},
|
|
28800
28812
|
VanaTreasury: {
|
|
@@ -28804,7 +28816,7 @@ var CONTRACTS = {
|
|
|
28804
28816
|
},
|
|
28805
28817
|
_meta: {
|
|
28806
28818
|
discoveredFrom: "QueryEngine",
|
|
28807
|
-
lastUpdated: "2026-
|
|
28819
|
+
lastUpdated: "2026-08-18"
|
|
28808
28820
|
}
|
|
28809
28821
|
},
|
|
28810
28822
|
DLPRegistryTreasury: {
|
|
@@ -28814,7 +28826,7 @@ var CONTRACTS = {
|
|
|
28814
28826
|
},
|
|
28815
28827
|
_meta: {
|
|
28816
28828
|
discoveredFrom: "DLPRegistry",
|
|
28817
|
-
lastUpdated: "2026-
|
|
28829
|
+
lastUpdated: "2026-08-18"
|
|
28818
28830
|
}
|
|
28819
28831
|
},
|
|
28820
28832
|
VanaPoolTreasury: {
|
|
@@ -28824,7 +28836,7 @@ var CONTRACTS = {
|
|
|
28824
28836
|
},
|
|
28825
28837
|
_meta: {
|
|
28826
28838
|
discoveredFrom: "VanaPoolStaking",
|
|
28827
|
-
lastUpdated: "2026-
|
|
28839
|
+
lastUpdated: "2026-08-18"
|
|
28828
28840
|
}
|
|
28829
28841
|
},
|
|
28830
28842
|
VanaPoolEntity: {
|
|
@@ -28834,7 +28846,7 @@ var CONTRACTS = {
|
|
|
28834
28846
|
},
|
|
28835
28847
|
_meta: {
|
|
28836
28848
|
discoveredFrom: "VanaPoolStaking",
|
|
28837
|
-
lastUpdated: "2026-
|
|
28849
|
+
lastUpdated: "2026-08-18"
|
|
28838
28850
|
}
|
|
28839
28851
|
}
|
|
28840
28852
|
};
|
|
@@ -34147,6 +34159,474 @@ function createEscrowGatewayClient(baseUrl) {
|
|
|
34147
34159
|
};
|
|
34148
34160
|
}
|
|
34149
34161
|
|
|
34162
|
+
// src/direct/escrow-payment.ts
|
|
34163
|
+
var GRANT_OP_TYPE = "grant";
|
|
34164
|
+
var DATA_ACCESS_OP_TYPE = "data_access";
|
|
34165
|
+
function toDirectFeeBreakdown(breakdown) {
|
|
34166
|
+
return {
|
|
34167
|
+
registrationFee: breakdown.registrationFee,
|
|
34168
|
+
dataAccessFee: breakdown.dataAccessFee,
|
|
34169
|
+
registrationPaid: breakdown.registrationPaid
|
|
34170
|
+
};
|
|
34171
|
+
}
|
|
34172
|
+
function toDirectPaymentReceipt(result) {
|
|
34173
|
+
return {
|
|
34174
|
+
opType: result.opType,
|
|
34175
|
+
opId: result.opId,
|
|
34176
|
+
asset: result.asset,
|
|
34177
|
+
amount: result.amount,
|
|
34178
|
+
paymentNonce: result.paymentNonce,
|
|
34179
|
+
breakdown: toDirectFeeBreakdown(result.breakdown),
|
|
34180
|
+
paidAt: result.paidAt
|
|
34181
|
+
};
|
|
34182
|
+
}
|
|
34183
|
+
function createDefaultNonceSource() {
|
|
34184
|
+
const counters = /* @__PURE__ */ new Map();
|
|
34185
|
+
return (payerAddress) => {
|
|
34186
|
+
const key = payerAddress.toLowerCase();
|
|
34187
|
+
const next = (counters.get(key) ?? 0n) + 1n;
|
|
34188
|
+
counters.set(key, next);
|
|
34189
|
+
return next;
|
|
34190
|
+
};
|
|
34191
|
+
}
|
|
34192
|
+
var processLocalNonceSource = createDefaultNonceSource();
|
|
34193
|
+
var UINT256_MAX = (1n << 256n) - 1n;
|
|
34194
|
+
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
34195
|
+
var BYTES32_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
34196
|
+
var SIGNATURE_RE = /^0x[0-9a-fA-F]{130}$/;
|
|
34197
|
+
function isUint256Decimal(value, allowZero) {
|
|
34198
|
+
const pattern = allowZero ? /^(0|[1-9]\d*)$/ : /^[1-9]\d*$/;
|
|
34199
|
+
return value.length <= UINT256_MAX.toString().length && pattern.test(value) && BigInt(value) <= UINT256_MAX;
|
|
34200
|
+
}
|
|
34201
|
+
function isValidAccessRecord(record) {
|
|
34202
|
+
return BYTES32_RE.test(record.dataPointId) && isUint256Decimal(record.version, false) && ADDRESS_RE.test(record.accessor) && BYTES32_RE.test(record.recordId) && SIGNATURE_RE.test(record.signature);
|
|
34203
|
+
}
|
|
34204
|
+
function validateSigningOperation(payerAddress, required) {
|
|
34205
|
+
if (!ADDRESS_RE.test(payerAddress)) {
|
|
34206
|
+
throw new Error("Payment payer must be a 20-byte EVM address");
|
|
34207
|
+
}
|
|
34208
|
+
if (!BYTES32_RE.test(required.opId)) {
|
|
34209
|
+
throw new Error("Payment operation id must be a 32-byte hex value");
|
|
34210
|
+
}
|
|
34211
|
+
if (!ADDRESS_RE.test(required.asset || NATIVE_ASSET_ADDRESS)) {
|
|
34212
|
+
throw new Error("Payment asset must be a 20-byte EVM address");
|
|
34213
|
+
}
|
|
34214
|
+
if (!isUint256Decimal(required.amount, true)) {
|
|
34215
|
+
throw new Error("Payment amount must be a canonical uint256 decimal");
|
|
34216
|
+
}
|
|
34217
|
+
if (required.paymentNonce !== void 0 && !isUint256Decimal(required.paymentNonce, false)) {
|
|
34218
|
+
throw new Error("Payment nonce must be a positive uint256 decimal");
|
|
34219
|
+
}
|
|
34220
|
+
const accessRecord = required.accessRecord;
|
|
34221
|
+
if (required.opType === DATA_ACCESS_OP_TYPE) {
|
|
34222
|
+
if (!accessRecord || !isValidAccessRecord(accessRecord)) {
|
|
34223
|
+
throw new Error("Data-access payment requires a valid access record");
|
|
34224
|
+
}
|
|
34225
|
+
if (required.opId.toLowerCase() !== accessRecord.recordId.toLowerCase()) {
|
|
34226
|
+
throw new Error(
|
|
34227
|
+
"Data-access payment operation id must equal the access record id"
|
|
34228
|
+
);
|
|
34229
|
+
}
|
|
34230
|
+
if (accessRecord.accessor.toLowerCase() !== payerAddress.toLowerCase()) {
|
|
34231
|
+
throw new Error(
|
|
34232
|
+
"Data-access payment accessor must equal the payment payer address"
|
|
34233
|
+
);
|
|
34234
|
+
}
|
|
34235
|
+
return;
|
|
34236
|
+
}
|
|
34237
|
+
if (required.amount === "0") {
|
|
34238
|
+
if (!accessRecord || !isValidAccessRecord(accessRecord) || accessRecord.accessor.toLowerCase() !== payerAddress.toLowerCase()) {
|
|
34239
|
+
throw new Error(
|
|
34240
|
+
"Zero-amount grant payments require a valid access record for the payer"
|
|
34241
|
+
);
|
|
34242
|
+
}
|
|
34243
|
+
}
|
|
34244
|
+
}
|
|
34245
|
+
function base64EncodeJson(value) {
|
|
34246
|
+
const bytes = new TextEncoder().encode(JSON.stringify(value));
|
|
34247
|
+
let binary = "";
|
|
34248
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
34249
|
+
return btoa(binary);
|
|
34250
|
+
}
|
|
34251
|
+
function base64DecodeJson(value) {
|
|
34252
|
+
const binary = atob(value);
|
|
34253
|
+
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
34254
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
34255
|
+
}
|
|
34256
|
+
async function signEscrowPayment(params) {
|
|
34257
|
+
const { payerAddress, required, config } = params;
|
|
34258
|
+
validateSigningOperation(payerAddress, required);
|
|
34259
|
+
const nonceSource = config.nonceSource ?? processLocalNonceSource;
|
|
34260
|
+
const paymentNonce = BigInt(
|
|
34261
|
+
required.paymentNonce ?? await nonceSource(payerAddress)
|
|
34262
|
+
);
|
|
34263
|
+
const asset = required.asset || NATIVE_ASSET_ADDRESS;
|
|
34264
|
+
const opId = required.opId;
|
|
34265
|
+
const amount = BigInt(required.amount);
|
|
34266
|
+
if (amount < 0n || amount > UINT256_MAX) {
|
|
34267
|
+
throw new Error("Payment amount must be a uint256");
|
|
34268
|
+
}
|
|
34269
|
+
if (paymentNonce <= 0n || paymentNonce > UINT256_MAX) {
|
|
34270
|
+
throw new Error("Payment nonce must be a positive uint256");
|
|
34271
|
+
}
|
|
34272
|
+
const message = {
|
|
34273
|
+
payerAddress,
|
|
34274
|
+
opType: required.opType,
|
|
34275
|
+
opId,
|
|
34276
|
+
asset,
|
|
34277
|
+
amount,
|
|
34278
|
+
paymentNonce
|
|
34279
|
+
};
|
|
34280
|
+
const signature = await config.signTypedData({
|
|
34281
|
+
domain: genericPaymentDomain(config.chainId, config.escrowContract),
|
|
34282
|
+
types: GENERIC_PAYMENT_TYPES,
|
|
34283
|
+
primaryType: "GenericPayment",
|
|
34284
|
+
message
|
|
34285
|
+
});
|
|
34286
|
+
return {
|
|
34287
|
+
message: {
|
|
34288
|
+
...message,
|
|
34289
|
+
amount: amount.toString(),
|
|
34290
|
+
paymentNonce: paymentNonce.toString()
|
|
34291
|
+
},
|
|
34292
|
+
signature,
|
|
34293
|
+
...required.accessRecord ? { accessRecord: required.accessRecord } : {}
|
|
34294
|
+
};
|
|
34295
|
+
}
|
|
34296
|
+
async function buildEscrowPaymentHeader(params) {
|
|
34297
|
+
const network = params.required.network ?? `vana:${params.config.chainId}`;
|
|
34298
|
+
if (network !== `vana:${params.config.chainId}`) {
|
|
34299
|
+
throw new Error("Payment network must match the configured chain");
|
|
34300
|
+
}
|
|
34301
|
+
const signed = await signEscrowPayment(params);
|
|
34302
|
+
const payment = {
|
|
34303
|
+
x402Version: 1,
|
|
34304
|
+
scheme: "vana-escrow-grant",
|
|
34305
|
+
network,
|
|
34306
|
+
payload: signed
|
|
34307
|
+
};
|
|
34308
|
+
return base64EncodeJson(payment);
|
|
34309
|
+
}
|
|
34310
|
+
async function buildGrantPaymentHeader(params) {
|
|
34311
|
+
return buildEscrowPaymentHeader({
|
|
34312
|
+
...params,
|
|
34313
|
+
required: {
|
|
34314
|
+
...params.required,
|
|
34315
|
+
opType: GRANT_OP_TYPE,
|
|
34316
|
+
opId: params.required.grantId
|
|
34317
|
+
}
|
|
34318
|
+
});
|
|
34319
|
+
}
|
|
34320
|
+
function asRecord(value) {
|
|
34321
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
34322
|
+
}
|
|
34323
|
+
function stringField(value, key) {
|
|
34324
|
+
const field = value?.[key];
|
|
34325
|
+
return typeof field === "string" ? field : void 0;
|
|
34326
|
+
}
|
|
34327
|
+
function isCanonicalIsoTimestamp(value) {
|
|
34328
|
+
try {
|
|
34329
|
+
return new Date(value).toISOString() === value;
|
|
34330
|
+
} catch {
|
|
34331
|
+
return false;
|
|
34332
|
+
}
|
|
34333
|
+
}
|
|
34334
|
+
function paymentResponseMetadataFromHeader(header) {
|
|
34335
|
+
if (!header) return void 0;
|
|
34336
|
+
try {
|
|
34337
|
+
const result = asRecord(base64DecodeJson(header));
|
|
34338
|
+
const breakdown = asRecord(result?.breakdown);
|
|
34339
|
+
const opType = stringField(result, "opType");
|
|
34340
|
+
const opId = stringField(result, "opId");
|
|
34341
|
+
const payerAddress = stringField(result, "payerAddress");
|
|
34342
|
+
const asset = stringField(result, "asset");
|
|
34343
|
+
const amount = stringField(result, "amount");
|
|
34344
|
+
const paymentNonce = stringField(result, "paymentNonce");
|
|
34345
|
+
const registrationFee = stringField(breakdown, "registrationFee");
|
|
34346
|
+
const dataAccessFee = stringField(breakdown, "dataAccessFee");
|
|
34347
|
+
const paidAt = stringField(result, "paidAt");
|
|
34348
|
+
if (result?.success !== true || !opType || !opId || !BYTES32_RE.test(opId) || !payerAddress || !ADDRESS_RE.test(payerAddress) || !asset || !ADDRESS_RE.test(asset) || !amount || !isUint256Decimal(amount, true) || !paymentNonce || !isUint256Decimal(paymentNonce, false) || !registrationFee || !isUint256Decimal(registrationFee, true) || !dataAccessFee || !isUint256Decimal(dataAccessFee, true) || typeof breakdown?.registrationPaid !== "boolean" || !paidAt || !isCanonicalIsoTimestamp(paidAt)) {
|
|
34349
|
+
return void 0;
|
|
34350
|
+
}
|
|
34351
|
+
return {
|
|
34352
|
+
opType,
|
|
34353
|
+
opId,
|
|
34354
|
+
asset,
|
|
34355
|
+
amount,
|
|
34356
|
+
paymentNonce,
|
|
34357
|
+
breakdown: {
|
|
34358
|
+
registrationFee,
|
|
34359
|
+
dataAccessFee,
|
|
34360
|
+
registrationPaid: breakdown.registrationPaid
|
|
34361
|
+
},
|
|
34362
|
+
paidAt
|
|
34363
|
+
};
|
|
34364
|
+
} catch {
|
|
34365
|
+
return void 0;
|
|
34366
|
+
}
|
|
34367
|
+
}
|
|
34368
|
+
function paymentReceiptFromHeader(header) {
|
|
34369
|
+
return paymentResponseMetadataFromHeader(header);
|
|
34370
|
+
}
|
|
34371
|
+
async function authorizeGrantPayment(params) {
|
|
34372
|
+
return authorizeEscrowPayment({
|
|
34373
|
+
...params,
|
|
34374
|
+
required: {
|
|
34375
|
+
...params.required,
|
|
34376
|
+
opType: GRANT_OP_TYPE,
|
|
34377
|
+
opId: params.required.grantId
|
|
34378
|
+
}
|
|
34379
|
+
});
|
|
34380
|
+
}
|
|
34381
|
+
async function authorizeEscrowPayment(params) {
|
|
34382
|
+
const { payerAddress, config } = params;
|
|
34383
|
+
const signed = await signEscrowPayment(params);
|
|
34384
|
+
const result = await config.client.payForOp({
|
|
34385
|
+
payerAddress,
|
|
34386
|
+
opType: signed.message.opType,
|
|
34387
|
+
opId: signed.message.opId,
|
|
34388
|
+
asset: signed.message.asset,
|
|
34389
|
+
amount: signed.message.amount,
|
|
34390
|
+
paymentNonce: signed.message.paymentNonce,
|
|
34391
|
+
signature: signed.signature,
|
|
34392
|
+
accessRecord: signed.accessRecord
|
|
34393
|
+
});
|
|
34394
|
+
return toDirectPaymentReceipt(result);
|
|
34395
|
+
}
|
|
34396
|
+
|
|
34397
|
+
// src/direct/errors.ts
|
|
34398
|
+
var PersonalServerReadError = class extends VanaError {
|
|
34399
|
+
constructor(message, status, details) {
|
|
34400
|
+
super(message, "DIRECT_PERSONAL_SERVER_READ_ERROR");
|
|
34401
|
+
this.status = status;
|
|
34402
|
+
this.details = details;
|
|
34403
|
+
}
|
|
34404
|
+
status;
|
|
34405
|
+
details;
|
|
34406
|
+
};
|
|
34407
|
+
|
|
34408
|
+
// src/direct/personal-server-read.ts
|
|
34409
|
+
function asRecord2(value) {
|
|
34410
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
34411
|
+
}
|
|
34412
|
+
function stringField2(record, field) {
|
|
34413
|
+
const value = record?.[field];
|
|
34414
|
+
return typeof value === "string" ? value : void 0;
|
|
34415
|
+
}
|
|
34416
|
+
function parseAccessRecord(value) {
|
|
34417
|
+
const record = asRecord2(value);
|
|
34418
|
+
const dataPointId = stringField2(record, "dataPointId");
|
|
34419
|
+
const version = stringField2(record, "version");
|
|
34420
|
+
const accessor = stringField2(record, "accessor");
|
|
34421
|
+
const recordId = stringField2(record, "recordId");
|
|
34422
|
+
const signature = stringField2(record, "signature");
|
|
34423
|
+
if (!dataPointId || !version || !accessor || !recordId || !signature) {
|
|
34424
|
+
return void 0;
|
|
34425
|
+
}
|
|
34426
|
+
return {
|
|
34427
|
+
dataPointId,
|
|
34428
|
+
version,
|
|
34429
|
+
accessor,
|
|
34430
|
+
recordId,
|
|
34431
|
+
signature
|
|
34432
|
+
};
|
|
34433
|
+
}
|
|
34434
|
+
function isBytes32Hex(value) {
|
|
34435
|
+
return /^0x[0-9a-fA-F]{64}$/.test(value);
|
|
34436
|
+
}
|
|
34437
|
+
var UINT256_MAX2 = (1n << 256n) - 1n;
|
|
34438
|
+
function isAddressHex(value) {
|
|
34439
|
+
return /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
34440
|
+
}
|
|
34441
|
+
function isUint256Decimal2(value, allowZero) {
|
|
34442
|
+
const pattern = allowZero ? /^(0|[1-9]\d*)$/ : /^[1-9]\d*$/;
|
|
34443
|
+
return value.length <= UINT256_MAX2.toString().length && pattern.test(value) && BigInt(value) <= UINT256_MAX2;
|
|
34444
|
+
}
|
|
34445
|
+
function isValidDataAccessRecord(record) {
|
|
34446
|
+
return isBytes32Hex(record.dataPointId) && isUint256Decimal2(record.version, false) && isAddressHex(record.accessor) && isBytes32Hex(record.recordId) && /^0x[0-9a-fA-F]{130}$/.test(record.signature);
|
|
34447
|
+
}
|
|
34448
|
+
function parseLegacyGrantOperation(params) {
|
|
34449
|
+
const { challengeGrantId, challengeOpId, challengeOpType, grantId } = params;
|
|
34450
|
+
const opType = challengeOpType ?? GRANT_OP_TYPE;
|
|
34451
|
+
if (opType !== GRANT_OP_TYPE) {
|
|
34452
|
+
throw new PersonalServerReadError(
|
|
34453
|
+
"Personal Server payment challenge used an unsupported escrow op type",
|
|
34454
|
+
402,
|
|
34455
|
+
{ opType: challengeOpType }
|
|
34456
|
+
);
|
|
34457
|
+
}
|
|
34458
|
+
const opId = challengeOpId ?? challengeGrantId ?? grantId;
|
|
34459
|
+
if (!opId || !isBytes32Hex(opId)) {
|
|
34460
|
+
throw new PersonalServerReadError(
|
|
34461
|
+
"Personal Server payment challenge used an invalid escrow op id",
|
|
34462
|
+
402,
|
|
34463
|
+
{ opId }
|
|
34464
|
+
);
|
|
34465
|
+
}
|
|
34466
|
+
if (opId.toLowerCase() !== grantId.toLowerCase()) {
|
|
34467
|
+
throw new PersonalServerReadError(
|
|
34468
|
+
"Personal Server payment challenge did not match the requested grant",
|
|
34469
|
+
402,
|
|
34470
|
+
{ opId, grantId }
|
|
34471
|
+
);
|
|
34472
|
+
}
|
|
34473
|
+
return { opType: GRANT_OP_TYPE, opId };
|
|
34474
|
+
}
|
|
34475
|
+
function hasDataAccessMarker(body) {
|
|
34476
|
+
if (stringField2(body, "opType") === DATA_ACCESS_OP_TYPE) return true;
|
|
34477
|
+
return Array.isArray(body.accepts) && body.accepts.some((value) => {
|
|
34478
|
+
const accept = asRecord2(value);
|
|
34479
|
+
return stringField2(asRecord2(accept?.message), "opType") === DATA_ACCESS_OP_TYPE;
|
|
34480
|
+
});
|
|
34481
|
+
}
|
|
34482
|
+
function parseCanonicalDataAccessAccept(value) {
|
|
34483
|
+
const accept = asRecord2(value);
|
|
34484
|
+
const message = asRecord2(accept?.message);
|
|
34485
|
+
if (stringField2(accept, "scheme") !== "vana-escrow-grant" || stringField2(message, "opType") !== DATA_ACCESS_OP_TYPE) {
|
|
34486
|
+
return null;
|
|
34487
|
+
}
|
|
34488
|
+
const network = stringField2(accept, "network");
|
|
34489
|
+
const payerAddress = stringField2(message, "payerAddress");
|
|
34490
|
+
const opId = stringField2(message, "opId");
|
|
34491
|
+
const asset = stringField2(message, "asset");
|
|
34492
|
+
const amount = stringField2(message, "amount");
|
|
34493
|
+
const paymentNonce = stringField2(message, "paymentNonce");
|
|
34494
|
+
const accessRecord = parseAccessRecord(accept?.accessRecord);
|
|
34495
|
+
const acceptAsset = stringField2(accept, "asset");
|
|
34496
|
+
const acceptAmount = stringField2(accept, "amount");
|
|
34497
|
+
if (!network || !payerAddress || !isAddressHex(payerAddress) || !opId || !isBytes32Hex(opId) || !asset || !isAddressHex(asset) || !amount || !isUint256Decimal2(amount, true) || !paymentNonce || !isUint256Decimal2(paymentNonce, false) || !accessRecord || !isValidDataAccessRecord(accessRecord) || payerAddress.toLowerCase() !== accessRecord.accessor.toLowerCase() || opId.toLowerCase() !== accessRecord.recordId.toLowerCase() || !acceptAsset || acceptAsset.toLowerCase() !== asset.toLowerCase() || acceptAmount !== amount) {
|
|
34498
|
+
return null;
|
|
34499
|
+
}
|
|
34500
|
+
return {
|
|
34501
|
+
opType: DATA_ACCESS_OP_TYPE,
|
|
34502
|
+
opId,
|
|
34503
|
+
network,
|
|
34504
|
+
paymentNonce,
|
|
34505
|
+
accessRecord,
|
|
34506
|
+
asset,
|
|
34507
|
+
amount
|
|
34508
|
+
};
|
|
34509
|
+
}
|
|
34510
|
+
function parseCanonicalDataAccessPayment(params) {
|
|
34511
|
+
const { body, grantId, raw } = params;
|
|
34512
|
+
if (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED") {
|
|
34513
|
+
throw new PersonalServerReadError(
|
|
34514
|
+
"Personal Server data-access payment response was not a canonical x402 challenge",
|
|
34515
|
+
402
|
|
34516
|
+
);
|
|
34517
|
+
}
|
|
34518
|
+
const operation = Array.isArray(body.accepts) ? body.accepts.map(parseCanonicalDataAccessAccept).find((candidate) => candidate !== null) : void 0;
|
|
34519
|
+
if (!operation) {
|
|
34520
|
+
return void 0;
|
|
34521
|
+
}
|
|
34522
|
+
return { grantId, raw, ...operation };
|
|
34523
|
+
}
|
|
34524
|
+
function preferredLegacyAccept(body) {
|
|
34525
|
+
if (!Array.isArray(body.accepts)) return void 0;
|
|
34526
|
+
return body.accepts.map(asRecord2).find((accept) => {
|
|
34527
|
+
const message = asRecord2(accept?.message);
|
|
34528
|
+
return stringField2(accept, "scheme") === "vana-escrow-grant" && stringField2(message, "opType") === GRANT_OP_TYPE;
|
|
34529
|
+
});
|
|
34530
|
+
}
|
|
34531
|
+
async function parsePersonalServerPaymentRequired(res, grantId) {
|
|
34532
|
+
let raw = void 0;
|
|
34533
|
+
try {
|
|
34534
|
+
raw = await res.json();
|
|
34535
|
+
} catch {
|
|
34536
|
+
raw = void 0;
|
|
34537
|
+
}
|
|
34538
|
+
const body = asRecord2(raw) ?? {};
|
|
34539
|
+
if (hasDataAccessMarker(body)) {
|
|
34540
|
+
const dataAccessOperation = parseCanonicalDataAccessPayment({
|
|
34541
|
+
body,
|
|
34542
|
+
grantId,
|
|
34543
|
+
raw
|
|
34544
|
+
});
|
|
34545
|
+
if (dataAccessOperation) return dataAccessOperation;
|
|
34546
|
+
}
|
|
34547
|
+
const hasAcceptsEnvelope = Object.prototype.hasOwnProperty.call(
|
|
34548
|
+
body,
|
|
34549
|
+
"accepts"
|
|
34550
|
+
);
|
|
34551
|
+
if (hasAcceptsEnvelope && (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED")) {
|
|
34552
|
+
throw new PersonalServerReadError(
|
|
34553
|
+
"Personal Server grant payment response was not a canonical x402 challenge",
|
|
34554
|
+
402
|
|
34555
|
+
);
|
|
34556
|
+
}
|
|
34557
|
+
const accept = preferredLegacyAccept(body);
|
|
34558
|
+
if (hasDataAccessMarker(body) && !accept) {
|
|
34559
|
+
throw new PersonalServerReadError(
|
|
34560
|
+
"Personal Server data-access payment challenge was untrusted or incomplete",
|
|
34561
|
+
402
|
|
34562
|
+
);
|
|
34563
|
+
}
|
|
34564
|
+
if (hasAcceptsEnvelope && !accept) {
|
|
34565
|
+
throw new PersonalServerReadError(
|
|
34566
|
+
"Personal Server grant payment challenge had no compatible escrow offer",
|
|
34567
|
+
402
|
|
34568
|
+
);
|
|
34569
|
+
}
|
|
34570
|
+
if (accept) {
|
|
34571
|
+
const message = asRecord2(accept.message);
|
|
34572
|
+
const network = stringField2(accept, "network");
|
|
34573
|
+
const payerAddress = stringField2(message, "payerAddress");
|
|
34574
|
+
const opId = stringField2(message, "opId");
|
|
34575
|
+
const asset = stringField2(message, "asset");
|
|
34576
|
+
const amount = stringField2(message, "amount");
|
|
34577
|
+
const paymentNonce = stringField2(message, "paymentNonce");
|
|
34578
|
+
const acceptAsset = stringField2(accept, "asset");
|
|
34579
|
+
const acceptAmount = stringField2(accept, "amount");
|
|
34580
|
+
const accessRecord2 = parseAccessRecord(accept.accessRecord);
|
|
34581
|
+
const hasAccessRecord = accept.accessRecord !== void 0;
|
|
34582
|
+
if (!network || !payerAddress || !isAddressHex(payerAddress) || !opId || !isBytes32Hex(opId) || !asset || !isAddressHex(asset) || !amount || !isUint256Decimal2(amount, true) || !paymentNonce || !isUint256Decimal2(paymentNonce, false) || !acceptAsset || acceptAsset.toLowerCase() !== asset.toLowerCase() || acceptAmount !== amount || hasAccessRecord && (!accessRecord2 || !isValidDataAccessRecord(accessRecord2) || accessRecord2.accessor.toLowerCase() !== payerAddress.toLowerCase()) || amount === "0" && !accessRecord2) {
|
|
34583
|
+
throw new PersonalServerReadError(
|
|
34584
|
+
"Personal Server grant payment challenge was untrusted or incomplete",
|
|
34585
|
+
402
|
|
34586
|
+
);
|
|
34587
|
+
}
|
|
34588
|
+
const operation2 = parseLegacyGrantOperation({
|
|
34589
|
+
challengeOpId: opId,
|
|
34590
|
+
challengeOpType: stringField2(message, "opType"),
|
|
34591
|
+
grantId
|
|
34592
|
+
});
|
|
34593
|
+
return {
|
|
34594
|
+
grantId,
|
|
34595
|
+
...operation2,
|
|
34596
|
+
network,
|
|
34597
|
+
paymentNonce,
|
|
34598
|
+
asset,
|
|
34599
|
+
amount,
|
|
34600
|
+
raw,
|
|
34601
|
+
...accessRecord2 ? { accessRecord: accessRecord2 } : {}
|
|
34602
|
+
};
|
|
34603
|
+
}
|
|
34604
|
+
const challengeGrantId = stringField2(body, "grantId");
|
|
34605
|
+
const challengeOpId = stringField2(body, "opId");
|
|
34606
|
+
const challengeOpType = stringField2(body, "opType");
|
|
34607
|
+
const accessRecord = parseAccessRecord(body.accessRecord);
|
|
34608
|
+
const operation = parseLegacyGrantOperation({
|
|
34609
|
+
challengeGrantId,
|
|
34610
|
+
challengeOpId,
|
|
34611
|
+
challengeOpType,
|
|
34612
|
+
grantId
|
|
34613
|
+
});
|
|
34614
|
+
const amountValue = stringField2(body, "amount") ?? stringField2(body, "maxAmountRequired") ?? "0";
|
|
34615
|
+
const payment = {
|
|
34616
|
+
grantId,
|
|
34617
|
+
network: stringField2(body, "network"),
|
|
34618
|
+
paymentNonce: stringField2(body, "paymentNonce"),
|
|
34619
|
+
asset: stringField2(body, "asset") ?? NATIVE_ASSET_ADDRESS,
|
|
34620
|
+
amount: amountValue,
|
|
34621
|
+
raw
|
|
34622
|
+
};
|
|
34623
|
+
return {
|
|
34624
|
+
...payment,
|
|
34625
|
+
...operation,
|
|
34626
|
+
...accessRecord ? { accessRecord } : {}
|
|
34627
|
+
};
|
|
34628
|
+
}
|
|
34629
|
+
|
|
34150
34630
|
// src/types/ps-errors.ts
|
|
34151
34631
|
var PSError = class extends Error {
|
|
34152
34632
|
constructor(code, message) {
|
|
@@ -34222,6 +34702,7 @@ async function parsePSError(response) {
|
|
|
34222
34702
|
CallbackStorage,
|
|
34223
34703
|
ContractFactory,
|
|
34224
34704
|
ContractNotFoundError,
|
|
34705
|
+
DATA_ACCESS_OP_TYPE,
|
|
34225
34706
|
DATA_REGISTRY_STATUS_ABI,
|
|
34226
34707
|
DataFileEnvelopeSchema,
|
|
34227
34708
|
DataPointStatus,
|
|
@@ -34231,6 +34712,7 @@ async function parsePSError(response) {
|
|
|
34231
34712
|
ExpiredTokenError,
|
|
34232
34713
|
FEE_REGISTRY_ABI,
|
|
34233
34714
|
GENERIC_PAYMENT_TYPES,
|
|
34715
|
+
GRANT_OP_TYPE,
|
|
34234
34716
|
GRANT_REGISTRATION_TYPES,
|
|
34235
34717
|
GRANT_REVOCATION_TYPES,
|
|
34236
34718
|
GoogleDriveStorage,
|
|
@@ -34276,8 +34758,12 @@ async function parsePSError(response) {
|
|
|
34276
34758
|
VanaError,
|
|
34277
34759
|
VanaStorage,
|
|
34278
34760
|
assertValidPkceVerifier,
|
|
34761
|
+
authorizeEscrowPayment,
|
|
34762
|
+
authorizeGrantPayment,
|
|
34279
34763
|
buildDepositNativeRequest,
|
|
34280
34764
|
buildDepositTokenRequest,
|
|
34765
|
+
buildEscrowPaymentHeader,
|
|
34766
|
+
buildGrantPaymentHeader,
|
|
34281
34767
|
buildMarkDataPointUnavailableRequest,
|
|
34282
34768
|
buildPersonalServerDataReadRequest,
|
|
34283
34769
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
@@ -34294,6 +34780,7 @@ async function parsePSError(response) {
|
|
|
34294
34780
|
contractCacheForTesting,
|
|
34295
34781
|
createBrowserPlatformAdapter,
|
|
34296
34782
|
createDataFileEnvelope,
|
|
34783
|
+
createDefaultNonceSource,
|
|
34297
34784
|
createEscrowGatewayClient,
|
|
34298
34785
|
createGatewayClient,
|
|
34299
34786
|
createNodePlatformAdapter,
|
|
@@ -34338,8 +34825,11 @@ async function parsePSError(response) {
|
|
|
34338
34825
|
mokshaServices,
|
|
34339
34826
|
mokshaTestnet,
|
|
34340
34827
|
parsePSError,
|
|
34828
|
+
parsePersonalServerPaymentRequired,
|
|
34341
34829
|
parseScope,
|
|
34342
34830
|
parseWeb3SignedHeader,
|
|
34831
|
+
paymentReceiptFromHeader,
|
|
34832
|
+
paymentResponseMetadataFromHeader,
|
|
34343
34833
|
personalServerDataReadPath,
|
|
34344
34834
|
personalServerRegistrationDomain,
|
|
34345
34835
|
readPersonalServerData,
|
|
@@ -34353,6 +34843,8 @@ async function parsePSError(response) {
|
|
|
34353
34843
|
signPersonalServerLiteOwnerBinding,
|
|
34354
34844
|
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
34355
34845
|
signPersonalServerRegistrationWithAccount,
|
|
34846
|
+
toDirectFeeBreakdown,
|
|
34847
|
+
toDirectPaymentReceipt,
|
|
34356
34848
|
vanaMainnet,
|
|
34357
34849
|
verifyGrantRegistration,
|
|
34358
34850
|
verifyPkceChallenge,
|