@opendatalabs/vana-sdk 3.13.2 → 3.13.4-pr.184.80a4b1f
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/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 +1 -0
- 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 +1 -0
- package/dist/direct/access-request-client.js.map +1 -1
- package/dist/direct/connect-flow.cjs +1 -1
- package/dist/direct/connect-flow.cjs.map +1 -1
- package/dist/direct/connect-flow.d.ts +1 -1
- package/dist/direct/connect-flow.js +1 -1
- package/dist/direct/connect-flow.js.map +1 -1
- package/dist/direct/controller.cjs.map +1 -1
- package/dist/direct/controller.d.ts +8 -8
- package/dist/direct/controller.js.map +1 -1
- package/dist/direct/endpoints.d.ts +1 -1
- package/dist/direct/errors.d.ts +1 -1
- package/dist/direct/escrow-payment.cjs +142 -11
- package/dist/direct/escrow-payment.cjs.map +1 -1
- package/dist/direct/escrow-payment.d.ts +65 -12
- package/dist/direct/escrow-payment.js +138 -11
- package/dist/direct/escrow-payment.js.map +1 -1
- package/dist/direct/personal-server-read.cjs +156 -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 +159 -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 +61 -22
- 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/index.browser.d.ts +44 -44
- package/dist/index.browser.js.map +2 -2
- package/dist/index.node.cjs +480 -0
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +48 -45
- package/dist/index.node.js +468 -0
- 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 +10 -0
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +8 -8
- package/dist/server.js +10 -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,
|
|
@@ -34147,6 +34159,462 @@ 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 signed = await signEscrowPayment(params);
|
|
34298
|
+
const payment = {
|
|
34299
|
+
x402Version: 1,
|
|
34300
|
+
scheme: "vana-escrow-grant",
|
|
34301
|
+
network: params.required.network ?? `vana:${params.config.chainId}`,
|
|
34302
|
+
payload: signed
|
|
34303
|
+
};
|
|
34304
|
+
return base64EncodeJson(payment);
|
|
34305
|
+
}
|
|
34306
|
+
async function buildGrantPaymentHeader(params) {
|
|
34307
|
+
return buildEscrowPaymentHeader({
|
|
34308
|
+
...params,
|
|
34309
|
+
required: {
|
|
34310
|
+
...params.required,
|
|
34311
|
+
opType: GRANT_OP_TYPE,
|
|
34312
|
+
opId: params.required.grantId
|
|
34313
|
+
}
|
|
34314
|
+
});
|
|
34315
|
+
}
|
|
34316
|
+
function asRecord(value) {
|
|
34317
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
34318
|
+
}
|
|
34319
|
+
function stringField(value, key) {
|
|
34320
|
+
const field = value?.[key];
|
|
34321
|
+
return typeof field === "string" ? field : void 0;
|
|
34322
|
+
}
|
|
34323
|
+
function isCanonicalIsoTimestamp(value) {
|
|
34324
|
+
try {
|
|
34325
|
+
return new Date(value).toISOString() === value;
|
|
34326
|
+
} catch {
|
|
34327
|
+
return false;
|
|
34328
|
+
}
|
|
34329
|
+
}
|
|
34330
|
+
function paymentResponseMetadataFromHeader(header) {
|
|
34331
|
+
if (!header) return void 0;
|
|
34332
|
+
try {
|
|
34333
|
+
const result = asRecord(base64DecodeJson(header));
|
|
34334
|
+
const breakdown = asRecord(result?.breakdown);
|
|
34335
|
+
const opType = stringField(result, "opType");
|
|
34336
|
+
const opId = stringField(result, "opId");
|
|
34337
|
+
const payerAddress = stringField(result, "payerAddress");
|
|
34338
|
+
const asset = stringField(result, "asset");
|
|
34339
|
+
const amount = stringField(result, "amount");
|
|
34340
|
+
const paymentNonce = stringField(result, "paymentNonce");
|
|
34341
|
+
const registrationFee = stringField(breakdown, "registrationFee");
|
|
34342
|
+
const dataAccessFee = stringField(breakdown, "dataAccessFee");
|
|
34343
|
+
const paidAt = stringField(result, "paidAt");
|
|
34344
|
+
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)) {
|
|
34345
|
+
return void 0;
|
|
34346
|
+
}
|
|
34347
|
+
return {
|
|
34348
|
+
opType,
|
|
34349
|
+
opId,
|
|
34350
|
+
asset,
|
|
34351
|
+
amount,
|
|
34352
|
+
paymentNonce,
|
|
34353
|
+
breakdown: {
|
|
34354
|
+
registrationFee,
|
|
34355
|
+
dataAccessFee,
|
|
34356
|
+
registrationPaid: breakdown.registrationPaid
|
|
34357
|
+
},
|
|
34358
|
+
paidAt
|
|
34359
|
+
};
|
|
34360
|
+
} catch {
|
|
34361
|
+
return void 0;
|
|
34362
|
+
}
|
|
34363
|
+
}
|
|
34364
|
+
function paymentReceiptFromHeader(header) {
|
|
34365
|
+
return paymentResponseMetadataFromHeader(header);
|
|
34366
|
+
}
|
|
34367
|
+
async function authorizeGrantPayment(params) {
|
|
34368
|
+
return authorizeEscrowPayment({
|
|
34369
|
+
...params,
|
|
34370
|
+
required: {
|
|
34371
|
+
...params.required,
|
|
34372
|
+
opType: GRANT_OP_TYPE,
|
|
34373
|
+
opId: params.required.grantId
|
|
34374
|
+
}
|
|
34375
|
+
});
|
|
34376
|
+
}
|
|
34377
|
+
async function authorizeEscrowPayment(params) {
|
|
34378
|
+
const { payerAddress, config } = params;
|
|
34379
|
+
const signed = await signEscrowPayment(params);
|
|
34380
|
+
const result = await config.client.payForOp({
|
|
34381
|
+
payerAddress,
|
|
34382
|
+
opType: signed.message.opType,
|
|
34383
|
+
opId: signed.message.opId,
|
|
34384
|
+
asset: signed.message.asset,
|
|
34385
|
+
amount: signed.message.amount,
|
|
34386
|
+
paymentNonce: signed.message.paymentNonce,
|
|
34387
|
+
signature: signed.signature,
|
|
34388
|
+
accessRecord: signed.accessRecord
|
|
34389
|
+
});
|
|
34390
|
+
return toDirectPaymentReceipt(result);
|
|
34391
|
+
}
|
|
34392
|
+
|
|
34393
|
+
// src/direct/errors.ts
|
|
34394
|
+
var PersonalServerReadError = class extends VanaError {
|
|
34395
|
+
constructor(message, status, details) {
|
|
34396
|
+
super(message, "DIRECT_PERSONAL_SERVER_READ_ERROR");
|
|
34397
|
+
this.status = status;
|
|
34398
|
+
this.details = details;
|
|
34399
|
+
}
|
|
34400
|
+
status;
|
|
34401
|
+
details;
|
|
34402
|
+
};
|
|
34403
|
+
|
|
34404
|
+
// src/direct/personal-server-read.ts
|
|
34405
|
+
function asRecord2(value) {
|
|
34406
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
34407
|
+
}
|
|
34408
|
+
function stringField2(record, field) {
|
|
34409
|
+
const value = record?.[field];
|
|
34410
|
+
return typeof value === "string" ? value : void 0;
|
|
34411
|
+
}
|
|
34412
|
+
function parseAccessRecord(value) {
|
|
34413
|
+
const record = asRecord2(value);
|
|
34414
|
+
const dataPointId = stringField2(record, "dataPointId");
|
|
34415
|
+
const version = stringField2(record, "version");
|
|
34416
|
+
const accessor = stringField2(record, "accessor");
|
|
34417
|
+
const recordId = stringField2(record, "recordId");
|
|
34418
|
+
const signature = stringField2(record, "signature");
|
|
34419
|
+
if (!dataPointId || !version || !accessor || !recordId || !signature) {
|
|
34420
|
+
return void 0;
|
|
34421
|
+
}
|
|
34422
|
+
return {
|
|
34423
|
+
dataPointId,
|
|
34424
|
+
version,
|
|
34425
|
+
accessor,
|
|
34426
|
+
recordId,
|
|
34427
|
+
signature
|
|
34428
|
+
};
|
|
34429
|
+
}
|
|
34430
|
+
function isBytes32Hex(value) {
|
|
34431
|
+
return /^0x[0-9a-fA-F]{64}$/.test(value);
|
|
34432
|
+
}
|
|
34433
|
+
var UINT256_MAX2 = (1n << 256n) - 1n;
|
|
34434
|
+
function isAddressHex(value) {
|
|
34435
|
+
return /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
34436
|
+
}
|
|
34437
|
+
function isUint256Decimal2(value, allowZero) {
|
|
34438
|
+
const pattern = allowZero ? /^(0|[1-9]\d*)$/ : /^[1-9]\d*$/;
|
|
34439
|
+
return value.length <= UINT256_MAX2.toString().length && pattern.test(value) && BigInt(value) <= UINT256_MAX2;
|
|
34440
|
+
}
|
|
34441
|
+
function isValidDataAccessRecord(record) {
|
|
34442
|
+
return isBytes32Hex(record.dataPointId) && isUint256Decimal2(record.version, false) && isAddressHex(record.accessor) && isBytes32Hex(record.recordId) && /^0x[0-9a-fA-F]{130}$/.test(record.signature);
|
|
34443
|
+
}
|
|
34444
|
+
function parseLegacyGrantOperation(params) {
|
|
34445
|
+
const { challengeGrantId, challengeOpId, challengeOpType, grantId } = params;
|
|
34446
|
+
const opType = challengeOpType ?? GRANT_OP_TYPE;
|
|
34447
|
+
if (opType !== GRANT_OP_TYPE) {
|
|
34448
|
+
throw new PersonalServerReadError(
|
|
34449
|
+
"Personal Server payment challenge used an unsupported escrow op type",
|
|
34450
|
+
402,
|
|
34451
|
+
{ opType: challengeOpType }
|
|
34452
|
+
);
|
|
34453
|
+
}
|
|
34454
|
+
const opId = challengeOpId ?? challengeGrantId ?? grantId;
|
|
34455
|
+
if (!opId || !isBytes32Hex(opId)) {
|
|
34456
|
+
throw new PersonalServerReadError(
|
|
34457
|
+
"Personal Server payment challenge used an invalid escrow op id",
|
|
34458
|
+
402,
|
|
34459
|
+
{ opId }
|
|
34460
|
+
);
|
|
34461
|
+
}
|
|
34462
|
+
if (opId.toLowerCase() !== grantId.toLowerCase()) {
|
|
34463
|
+
throw new PersonalServerReadError(
|
|
34464
|
+
"Personal Server payment challenge did not match the requested grant",
|
|
34465
|
+
402,
|
|
34466
|
+
{ opId, grantId }
|
|
34467
|
+
);
|
|
34468
|
+
}
|
|
34469
|
+
return { opType: GRANT_OP_TYPE, opId };
|
|
34470
|
+
}
|
|
34471
|
+
function hasDataAccessMarker(body) {
|
|
34472
|
+
if (stringField2(body, "opType") === DATA_ACCESS_OP_TYPE) return true;
|
|
34473
|
+
return Array.isArray(body.accepts) && body.accepts.some((value) => {
|
|
34474
|
+
const accept = asRecord2(value);
|
|
34475
|
+
return stringField2(asRecord2(accept?.message), "opType") === DATA_ACCESS_OP_TYPE;
|
|
34476
|
+
});
|
|
34477
|
+
}
|
|
34478
|
+
function parseCanonicalDataAccessAccept(value) {
|
|
34479
|
+
const accept = asRecord2(value);
|
|
34480
|
+
const message = asRecord2(accept?.message);
|
|
34481
|
+
if (stringField2(accept, "scheme") !== "vana-escrow-grant" || stringField2(message, "opType") !== DATA_ACCESS_OP_TYPE) {
|
|
34482
|
+
return null;
|
|
34483
|
+
}
|
|
34484
|
+
const network = stringField2(accept, "network");
|
|
34485
|
+
const payerAddress = stringField2(message, "payerAddress");
|
|
34486
|
+
const opId = stringField2(message, "opId");
|
|
34487
|
+
const asset = stringField2(message, "asset");
|
|
34488
|
+
const amount = stringField2(message, "amount");
|
|
34489
|
+
const paymentNonce = stringField2(message, "paymentNonce");
|
|
34490
|
+
const accessRecord = parseAccessRecord(accept?.accessRecord);
|
|
34491
|
+
const acceptAsset = stringField2(accept, "asset");
|
|
34492
|
+
const acceptAmount = stringField2(accept, "amount");
|
|
34493
|
+
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) {
|
|
34494
|
+
return null;
|
|
34495
|
+
}
|
|
34496
|
+
return {
|
|
34497
|
+
opType: DATA_ACCESS_OP_TYPE,
|
|
34498
|
+
opId,
|
|
34499
|
+
network,
|
|
34500
|
+
paymentNonce,
|
|
34501
|
+
accessRecord,
|
|
34502
|
+
asset,
|
|
34503
|
+
amount
|
|
34504
|
+
};
|
|
34505
|
+
}
|
|
34506
|
+
function parseCanonicalDataAccessPayment(params) {
|
|
34507
|
+
const { body, grantId, raw } = params;
|
|
34508
|
+
if (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED") {
|
|
34509
|
+
throw new PersonalServerReadError(
|
|
34510
|
+
"Personal Server data-access payment response was not a canonical x402 challenge",
|
|
34511
|
+
402
|
|
34512
|
+
);
|
|
34513
|
+
}
|
|
34514
|
+
const operation = Array.isArray(body.accepts) ? body.accepts.map(parseCanonicalDataAccessAccept).find((candidate) => candidate !== null) : void 0;
|
|
34515
|
+
if (!operation) {
|
|
34516
|
+
throw new PersonalServerReadError(
|
|
34517
|
+
"Personal Server data-access payment challenge was untrusted or incomplete",
|
|
34518
|
+
402
|
|
34519
|
+
);
|
|
34520
|
+
}
|
|
34521
|
+
return { grantId, raw, ...operation };
|
|
34522
|
+
}
|
|
34523
|
+
function preferredLegacyAccept(body) {
|
|
34524
|
+
if (!Array.isArray(body.accepts)) return void 0;
|
|
34525
|
+
return body.accepts.map(asRecord2).find((accept) => {
|
|
34526
|
+
const message = asRecord2(accept?.message);
|
|
34527
|
+
return stringField2(accept, "scheme") === "vana-escrow-grant" && stringField2(message, "opType") === GRANT_OP_TYPE;
|
|
34528
|
+
});
|
|
34529
|
+
}
|
|
34530
|
+
async function parsePersonalServerPaymentRequired(res, grantId) {
|
|
34531
|
+
let raw = void 0;
|
|
34532
|
+
try {
|
|
34533
|
+
raw = await res.json();
|
|
34534
|
+
} catch {
|
|
34535
|
+
raw = void 0;
|
|
34536
|
+
}
|
|
34537
|
+
const body = asRecord2(raw) ?? {};
|
|
34538
|
+
if (hasDataAccessMarker(body)) {
|
|
34539
|
+
return parseCanonicalDataAccessPayment({ body, grantId, raw });
|
|
34540
|
+
}
|
|
34541
|
+
const hasAcceptsEnvelope = Object.prototype.hasOwnProperty.call(
|
|
34542
|
+
body,
|
|
34543
|
+
"accepts"
|
|
34544
|
+
);
|
|
34545
|
+
if (hasAcceptsEnvelope && (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED")) {
|
|
34546
|
+
throw new PersonalServerReadError(
|
|
34547
|
+
"Personal Server grant payment response was not a canonical x402 challenge",
|
|
34548
|
+
402
|
|
34549
|
+
);
|
|
34550
|
+
}
|
|
34551
|
+
const accept = preferredLegacyAccept(body);
|
|
34552
|
+
if (hasAcceptsEnvelope && !accept) {
|
|
34553
|
+
throw new PersonalServerReadError(
|
|
34554
|
+
"Personal Server grant payment challenge had no compatible escrow offer",
|
|
34555
|
+
402
|
|
34556
|
+
);
|
|
34557
|
+
}
|
|
34558
|
+
if (accept) {
|
|
34559
|
+
const message = asRecord2(accept.message);
|
|
34560
|
+
const network = stringField2(accept, "network");
|
|
34561
|
+
const payerAddress = stringField2(message, "payerAddress");
|
|
34562
|
+
const opId = stringField2(message, "opId");
|
|
34563
|
+
const asset = stringField2(message, "asset");
|
|
34564
|
+
const amount = stringField2(message, "amount");
|
|
34565
|
+
const paymentNonce = stringField2(message, "paymentNonce");
|
|
34566
|
+
const acceptAsset = stringField2(accept, "asset");
|
|
34567
|
+
const acceptAmount = stringField2(accept, "amount");
|
|
34568
|
+
const accessRecord2 = parseAccessRecord(accept.accessRecord);
|
|
34569
|
+
const hasAccessRecord = accept.accessRecord !== void 0;
|
|
34570
|
+
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) {
|
|
34571
|
+
throw new PersonalServerReadError(
|
|
34572
|
+
"Personal Server grant payment challenge was untrusted or incomplete",
|
|
34573
|
+
402
|
|
34574
|
+
);
|
|
34575
|
+
}
|
|
34576
|
+
const operation2 = parseLegacyGrantOperation({
|
|
34577
|
+
challengeOpId: opId,
|
|
34578
|
+
challengeOpType: stringField2(message, "opType"),
|
|
34579
|
+
grantId
|
|
34580
|
+
});
|
|
34581
|
+
return {
|
|
34582
|
+
grantId,
|
|
34583
|
+
...operation2,
|
|
34584
|
+
network,
|
|
34585
|
+
paymentNonce,
|
|
34586
|
+
asset,
|
|
34587
|
+
amount,
|
|
34588
|
+
raw,
|
|
34589
|
+
...accessRecord2 ? { accessRecord: accessRecord2 } : {}
|
|
34590
|
+
};
|
|
34591
|
+
}
|
|
34592
|
+
const challengeGrantId = stringField2(body, "grantId");
|
|
34593
|
+
const challengeOpId = stringField2(body, "opId");
|
|
34594
|
+
const challengeOpType = stringField2(body, "opType");
|
|
34595
|
+
const accessRecord = parseAccessRecord(body.accessRecord);
|
|
34596
|
+
const operation = parseLegacyGrantOperation({
|
|
34597
|
+
challengeGrantId,
|
|
34598
|
+
challengeOpId,
|
|
34599
|
+
challengeOpType,
|
|
34600
|
+
grantId
|
|
34601
|
+
});
|
|
34602
|
+
const amountValue = stringField2(body, "amount") ?? stringField2(body, "maxAmountRequired") ?? "0";
|
|
34603
|
+
const payment = {
|
|
34604
|
+
grantId,
|
|
34605
|
+
network: stringField2(body, "network"),
|
|
34606
|
+
paymentNonce: stringField2(body, "paymentNonce"),
|
|
34607
|
+
asset: stringField2(body, "asset") ?? NATIVE_ASSET_ADDRESS,
|
|
34608
|
+
amount: amountValue,
|
|
34609
|
+
raw
|
|
34610
|
+
};
|
|
34611
|
+
return {
|
|
34612
|
+
...payment,
|
|
34613
|
+
...operation,
|
|
34614
|
+
...accessRecord ? { accessRecord } : {}
|
|
34615
|
+
};
|
|
34616
|
+
}
|
|
34617
|
+
|
|
34150
34618
|
// src/types/ps-errors.ts
|
|
34151
34619
|
var PSError = class extends Error {
|
|
34152
34620
|
constructor(code, message) {
|
|
@@ -34222,6 +34690,7 @@ async function parsePSError(response) {
|
|
|
34222
34690
|
CallbackStorage,
|
|
34223
34691
|
ContractFactory,
|
|
34224
34692
|
ContractNotFoundError,
|
|
34693
|
+
DATA_ACCESS_OP_TYPE,
|
|
34225
34694
|
DATA_REGISTRY_STATUS_ABI,
|
|
34226
34695
|
DataFileEnvelopeSchema,
|
|
34227
34696
|
DataPointStatus,
|
|
@@ -34231,6 +34700,7 @@ async function parsePSError(response) {
|
|
|
34231
34700
|
ExpiredTokenError,
|
|
34232
34701
|
FEE_REGISTRY_ABI,
|
|
34233
34702
|
GENERIC_PAYMENT_TYPES,
|
|
34703
|
+
GRANT_OP_TYPE,
|
|
34234
34704
|
GRANT_REGISTRATION_TYPES,
|
|
34235
34705
|
GRANT_REVOCATION_TYPES,
|
|
34236
34706
|
GoogleDriveStorage,
|
|
@@ -34276,8 +34746,12 @@ async function parsePSError(response) {
|
|
|
34276
34746
|
VanaError,
|
|
34277
34747
|
VanaStorage,
|
|
34278
34748
|
assertValidPkceVerifier,
|
|
34749
|
+
authorizeEscrowPayment,
|
|
34750
|
+
authorizeGrantPayment,
|
|
34279
34751
|
buildDepositNativeRequest,
|
|
34280
34752
|
buildDepositTokenRequest,
|
|
34753
|
+
buildEscrowPaymentHeader,
|
|
34754
|
+
buildGrantPaymentHeader,
|
|
34281
34755
|
buildMarkDataPointUnavailableRequest,
|
|
34282
34756
|
buildPersonalServerDataReadRequest,
|
|
34283
34757
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
@@ -34294,6 +34768,7 @@ async function parsePSError(response) {
|
|
|
34294
34768
|
contractCacheForTesting,
|
|
34295
34769
|
createBrowserPlatformAdapter,
|
|
34296
34770
|
createDataFileEnvelope,
|
|
34771
|
+
createDefaultNonceSource,
|
|
34297
34772
|
createEscrowGatewayClient,
|
|
34298
34773
|
createGatewayClient,
|
|
34299
34774
|
createNodePlatformAdapter,
|
|
@@ -34338,8 +34813,11 @@ async function parsePSError(response) {
|
|
|
34338
34813
|
mokshaServices,
|
|
34339
34814
|
mokshaTestnet,
|
|
34340
34815
|
parsePSError,
|
|
34816
|
+
parsePersonalServerPaymentRequired,
|
|
34341
34817
|
parseScope,
|
|
34342
34818
|
parseWeb3SignedHeader,
|
|
34819
|
+
paymentReceiptFromHeader,
|
|
34820
|
+
paymentResponseMetadataFromHeader,
|
|
34343
34821
|
personalServerDataReadPath,
|
|
34344
34822
|
personalServerRegistrationDomain,
|
|
34345
34823
|
readPersonalServerData,
|
|
@@ -34353,6 +34831,8 @@ async function parsePSError(response) {
|
|
|
34353
34831
|
signPersonalServerLiteOwnerBinding,
|
|
34354
34832
|
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
34355
34833
|
signPersonalServerRegistrationWithAccount,
|
|
34834
|
+
toDirectFeeBreakdown,
|
|
34835
|
+
toDirectPaymentReceipt,
|
|
34356
34836
|
vanaMainnet,
|
|
34357
34837
|
verifyGrantRegistration,
|
|
34358
34838
|
verifyPkceChallenge,
|