@opendatalabs/vana-sdk 3.13.4 → 3.14.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.
- 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.js
CHANGED
|
@@ -28463,7 +28463,7 @@ var CONTRACTS = {
|
|
|
28463
28463
|
},
|
|
28464
28464
|
DataPortabilityServers: {
|
|
28465
28465
|
addresses: {
|
|
28466
|
-
14800: "
|
|
28466
|
+
14800: "0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab",
|
|
28467
28467
|
1480: "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c"
|
|
28468
28468
|
}
|
|
28469
28469
|
},
|
|
@@ -28621,7 +28621,7 @@ var CONTRACTS = {
|
|
|
28621
28621
|
},
|
|
28622
28622
|
_meta: {
|
|
28623
28623
|
discoveredFrom: "ComputeEngine",
|
|
28624
|
-
lastUpdated: "2026-
|
|
28624
|
+
lastUpdated: "2026-08-18"
|
|
28625
28625
|
}
|
|
28626
28626
|
},
|
|
28627
28627
|
VanaTreasury: {
|
|
@@ -28631,7 +28631,7 @@ var CONTRACTS = {
|
|
|
28631
28631
|
},
|
|
28632
28632
|
_meta: {
|
|
28633
28633
|
discoveredFrom: "QueryEngine",
|
|
28634
|
-
lastUpdated: "2026-
|
|
28634
|
+
lastUpdated: "2026-08-18"
|
|
28635
28635
|
}
|
|
28636
28636
|
},
|
|
28637
28637
|
DLPRegistryTreasury: {
|
|
@@ -28641,7 +28641,7 @@ var CONTRACTS = {
|
|
|
28641
28641
|
},
|
|
28642
28642
|
_meta: {
|
|
28643
28643
|
discoveredFrom: "DLPRegistry",
|
|
28644
|
-
lastUpdated: "2026-
|
|
28644
|
+
lastUpdated: "2026-08-18"
|
|
28645
28645
|
}
|
|
28646
28646
|
},
|
|
28647
28647
|
VanaPoolTreasury: {
|
|
@@ -28651,7 +28651,7 @@ var CONTRACTS = {
|
|
|
28651
28651
|
},
|
|
28652
28652
|
_meta: {
|
|
28653
28653
|
discoveredFrom: "VanaPoolStaking",
|
|
28654
|
-
lastUpdated: "2026-
|
|
28654
|
+
lastUpdated: "2026-08-18"
|
|
28655
28655
|
}
|
|
28656
28656
|
},
|
|
28657
28657
|
VanaPoolEntity: {
|
|
@@ -28661,7 +28661,7 @@ var CONTRACTS = {
|
|
|
28661
28661
|
},
|
|
28662
28662
|
_meta: {
|
|
28663
28663
|
discoveredFrom: "VanaPoolStaking",
|
|
28664
|
-
lastUpdated: "2026-
|
|
28664
|
+
lastUpdated: "2026-08-18"
|
|
28665
28665
|
}
|
|
28666
28666
|
}
|
|
28667
28667
|
};
|
|
@@ -33988,6 +33988,474 @@ function createEscrowGatewayClient(baseUrl) {
|
|
|
33988
33988
|
};
|
|
33989
33989
|
}
|
|
33990
33990
|
|
|
33991
|
+
// src/direct/escrow-payment.ts
|
|
33992
|
+
var GRANT_OP_TYPE = "grant";
|
|
33993
|
+
var DATA_ACCESS_OP_TYPE = "data_access";
|
|
33994
|
+
function toDirectFeeBreakdown(breakdown) {
|
|
33995
|
+
return {
|
|
33996
|
+
registrationFee: breakdown.registrationFee,
|
|
33997
|
+
dataAccessFee: breakdown.dataAccessFee,
|
|
33998
|
+
registrationPaid: breakdown.registrationPaid
|
|
33999
|
+
};
|
|
34000
|
+
}
|
|
34001
|
+
function toDirectPaymentReceipt(result) {
|
|
34002
|
+
return {
|
|
34003
|
+
opType: result.opType,
|
|
34004
|
+
opId: result.opId,
|
|
34005
|
+
asset: result.asset,
|
|
34006
|
+
amount: result.amount,
|
|
34007
|
+
paymentNonce: result.paymentNonce,
|
|
34008
|
+
breakdown: toDirectFeeBreakdown(result.breakdown),
|
|
34009
|
+
paidAt: result.paidAt
|
|
34010
|
+
};
|
|
34011
|
+
}
|
|
34012
|
+
function createDefaultNonceSource() {
|
|
34013
|
+
const counters = /* @__PURE__ */ new Map();
|
|
34014
|
+
return (payerAddress) => {
|
|
34015
|
+
const key = payerAddress.toLowerCase();
|
|
34016
|
+
const next = (counters.get(key) ?? 0n) + 1n;
|
|
34017
|
+
counters.set(key, next);
|
|
34018
|
+
return next;
|
|
34019
|
+
};
|
|
34020
|
+
}
|
|
34021
|
+
var processLocalNonceSource = createDefaultNonceSource();
|
|
34022
|
+
var UINT256_MAX = (1n << 256n) - 1n;
|
|
34023
|
+
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
34024
|
+
var BYTES32_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
34025
|
+
var SIGNATURE_RE = /^0x[0-9a-fA-F]{130}$/;
|
|
34026
|
+
function isUint256Decimal(value, allowZero) {
|
|
34027
|
+
const pattern = allowZero ? /^(0|[1-9]\d*)$/ : /^[1-9]\d*$/;
|
|
34028
|
+
return value.length <= UINT256_MAX.toString().length && pattern.test(value) && BigInt(value) <= UINT256_MAX;
|
|
34029
|
+
}
|
|
34030
|
+
function isValidAccessRecord(record) {
|
|
34031
|
+
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);
|
|
34032
|
+
}
|
|
34033
|
+
function validateSigningOperation(payerAddress, required) {
|
|
34034
|
+
if (!ADDRESS_RE.test(payerAddress)) {
|
|
34035
|
+
throw new Error("Payment payer must be a 20-byte EVM address");
|
|
34036
|
+
}
|
|
34037
|
+
if (!BYTES32_RE.test(required.opId)) {
|
|
34038
|
+
throw new Error("Payment operation id must be a 32-byte hex value");
|
|
34039
|
+
}
|
|
34040
|
+
if (!ADDRESS_RE.test(required.asset || NATIVE_ASSET_ADDRESS)) {
|
|
34041
|
+
throw new Error("Payment asset must be a 20-byte EVM address");
|
|
34042
|
+
}
|
|
34043
|
+
if (!isUint256Decimal(required.amount, true)) {
|
|
34044
|
+
throw new Error("Payment amount must be a canonical uint256 decimal");
|
|
34045
|
+
}
|
|
34046
|
+
if (required.paymentNonce !== void 0 && !isUint256Decimal(required.paymentNonce, false)) {
|
|
34047
|
+
throw new Error("Payment nonce must be a positive uint256 decimal");
|
|
34048
|
+
}
|
|
34049
|
+
const accessRecord = required.accessRecord;
|
|
34050
|
+
if (required.opType === DATA_ACCESS_OP_TYPE) {
|
|
34051
|
+
if (!accessRecord || !isValidAccessRecord(accessRecord)) {
|
|
34052
|
+
throw new Error("Data-access payment requires a valid access record");
|
|
34053
|
+
}
|
|
34054
|
+
if (required.opId.toLowerCase() !== accessRecord.recordId.toLowerCase()) {
|
|
34055
|
+
throw new Error(
|
|
34056
|
+
"Data-access payment operation id must equal the access record id"
|
|
34057
|
+
);
|
|
34058
|
+
}
|
|
34059
|
+
if (accessRecord.accessor.toLowerCase() !== payerAddress.toLowerCase()) {
|
|
34060
|
+
throw new Error(
|
|
34061
|
+
"Data-access payment accessor must equal the payment payer address"
|
|
34062
|
+
);
|
|
34063
|
+
}
|
|
34064
|
+
return;
|
|
34065
|
+
}
|
|
34066
|
+
if (required.amount === "0") {
|
|
34067
|
+
if (!accessRecord || !isValidAccessRecord(accessRecord) || accessRecord.accessor.toLowerCase() !== payerAddress.toLowerCase()) {
|
|
34068
|
+
throw new Error(
|
|
34069
|
+
"Zero-amount grant payments require a valid access record for the payer"
|
|
34070
|
+
);
|
|
34071
|
+
}
|
|
34072
|
+
}
|
|
34073
|
+
}
|
|
34074
|
+
function base64EncodeJson(value) {
|
|
34075
|
+
const bytes = new TextEncoder().encode(JSON.stringify(value));
|
|
34076
|
+
let binary = "";
|
|
34077
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
34078
|
+
return btoa(binary);
|
|
34079
|
+
}
|
|
34080
|
+
function base64DecodeJson(value) {
|
|
34081
|
+
const binary = atob(value);
|
|
34082
|
+
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
34083
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
34084
|
+
}
|
|
34085
|
+
async function signEscrowPayment(params) {
|
|
34086
|
+
const { payerAddress, required, config } = params;
|
|
34087
|
+
validateSigningOperation(payerAddress, required);
|
|
34088
|
+
const nonceSource = config.nonceSource ?? processLocalNonceSource;
|
|
34089
|
+
const paymentNonce = BigInt(
|
|
34090
|
+
required.paymentNonce ?? await nonceSource(payerAddress)
|
|
34091
|
+
);
|
|
34092
|
+
const asset = required.asset || NATIVE_ASSET_ADDRESS;
|
|
34093
|
+
const opId = required.opId;
|
|
34094
|
+
const amount = BigInt(required.amount);
|
|
34095
|
+
if (amount < 0n || amount > UINT256_MAX) {
|
|
34096
|
+
throw new Error("Payment amount must be a uint256");
|
|
34097
|
+
}
|
|
34098
|
+
if (paymentNonce <= 0n || paymentNonce > UINT256_MAX) {
|
|
34099
|
+
throw new Error("Payment nonce must be a positive uint256");
|
|
34100
|
+
}
|
|
34101
|
+
const message = {
|
|
34102
|
+
payerAddress,
|
|
34103
|
+
opType: required.opType,
|
|
34104
|
+
opId,
|
|
34105
|
+
asset,
|
|
34106
|
+
amount,
|
|
34107
|
+
paymentNonce
|
|
34108
|
+
};
|
|
34109
|
+
const signature = await config.signTypedData({
|
|
34110
|
+
domain: genericPaymentDomain(config.chainId, config.escrowContract),
|
|
34111
|
+
types: GENERIC_PAYMENT_TYPES,
|
|
34112
|
+
primaryType: "GenericPayment",
|
|
34113
|
+
message
|
|
34114
|
+
});
|
|
34115
|
+
return {
|
|
34116
|
+
message: {
|
|
34117
|
+
...message,
|
|
34118
|
+
amount: amount.toString(),
|
|
34119
|
+
paymentNonce: paymentNonce.toString()
|
|
34120
|
+
},
|
|
34121
|
+
signature,
|
|
34122
|
+
...required.accessRecord ? { accessRecord: required.accessRecord } : {}
|
|
34123
|
+
};
|
|
34124
|
+
}
|
|
34125
|
+
async function buildEscrowPaymentHeader(params) {
|
|
34126
|
+
const network = params.required.network ?? `vana:${params.config.chainId}`;
|
|
34127
|
+
if (network !== `vana:${params.config.chainId}`) {
|
|
34128
|
+
throw new Error("Payment network must match the configured chain");
|
|
34129
|
+
}
|
|
34130
|
+
const signed = await signEscrowPayment(params);
|
|
34131
|
+
const payment = {
|
|
34132
|
+
x402Version: 1,
|
|
34133
|
+
scheme: "vana-escrow-grant",
|
|
34134
|
+
network,
|
|
34135
|
+
payload: signed
|
|
34136
|
+
};
|
|
34137
|
+
return base64EncodeJson(payment);
|
|
34138
|
+
}
|
|
34139
|
+
async function buildGrantPaymentHeader(params) {
|
|
34140
|
+
return buildEscrowPaymentHeader({
|
|
34141
|
+
...params,
|
|
34142
|
+
required: {
|
|
34143
|
+
...params.required,
|
|
34144
|
+
opType: GRANT_OP_TYPE,
|
|
34145
|
+
opId: params.required.grantId
|
|
34146
|
+
}
|
|
34147
|
+
});
|
|
34148
|
+
}
|
|
34149
|
+
function asRecord(value) {
|
|
34150
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
34151
|
+
}
|
|
34152
|
+
function stringField(value, key) {
|
|
34153
|
+
const field = value?.[key];
|
|
34154
|
+
return typeof field === "string" ? field : void 0;
|
|
34155
|
+
}
|
|
34156
|
+
function isCanonicalIsoTimestamp(value) {
|
|
34157
|
+
try {
|
|
34158
|
+
return new Date(value).toISOString() === value;
|
|
34159
|
+
} catch {
|
|
34160
|
+
return false;
|
|
34161
|
+
}
|
|
34162
|
+
}
|
|
34163
|
+
function paymentResponseMetadataFromHeader(header) {
|
|
34164
|
+
if (!header) return void 0;
|
|
34165
|
+
try {
|
|
34166
|
+
const result = asRecord(base64DecodeJson(header));
|
|
34167
|
+
const breakdown = asRecord(result?.breakdown);
|
|
34168
|
+
const opType = stringField(result, "opType");
|
|
34169
|
+
const opId = stringField(result, "opId");
|
|
34170
|
+
const payerAddress = stringField(result, "payerAddress");
|
|
34171
|
+
const asset = stringField(result, "asset");
|
|
34172
|
+
const amount = stringField(result, "amount");
|
|
34173
|
+
const paymentNonce = stringField(result, "paymentNonce");
|
|
34174
|
+
const registrationFee = stringField(breakdown, "registrationFee");
|
|
34175
|
+
const dataAccessFee = stringField(breakdown, "dataAccessFee");
|
|
34176
|
+
const paidAt = stringField(result, "paidAt");
|
|
34177
|
+
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)) {
|
|
34178
|
+
return void 0;
|
|
34179
|
+
}
|
|
34180
|
+
return {
|
|
34181
|
+
opType,
|
|
34182
|
+
opId,
|
|
34183
|
+
asset,
|
|
34184
|
+
amount,
|
|
34185
|
+
paymentNonce,
|
|
34186
|
+
breakdown: {
|
|
34187
|
+
registrationFee,
|
|
34188
|
+
dataAccessFee,
|
|
34189
|
+
registrationPaid: breakdown.registrationPaid
|
|
34190
|
+
},
|
|
34191
|
+
paidAt
|
|
34192
|
+
};
|
|
34193
|
+
} catch {
|
|
34194
|
+
return void 0;
|
|
34195
|
+
}
|
|
34196
|
+
}
|
|
34197
|
+
function paymentReceiptFromHeader(header) {
|
|
34198
|
+
return paymentResponseMetadataFromHeader(header);
|
|
34199
|
+
}
|
|
34200
|
+
async function authorizeGrantPayment(params) {
|
|
34201
|
+
return authorizeEscrowPayment({
|
|
34202
|
+
...params,
|
|
34203
|
+
required: {
|
|
34204
|
+
...params.required,
|
|
34205
|
+
opType: GRANT_OP_TYPE,
|
|
34206
|
+
opId: params.required.grantId
|
|
34207
|
+
}
|
|
34208
|
+
});
|
|
34209
|
+
}
|
|
34210
|
+
async function authorizeEscrowPayment(params) {
|
|
34211
|
+
const { payerAddress, config } = params;
|
|
34212
|
+
const signed = await signEscrowPayment(params);
|
|
34213
|
+
const result = await config.client.payForOp({
|
|
34214
|
+
payerAddress,
|
|
34215
|
+
opType: signed.message.opType,
|
|
34216
|
+
opId: signed.message.opId,
|
|
34217
|
+
asset: signed.message.asset,
|
|
34218
|
+
amount: signed.message.amount,
|
|
34219
|
+
paymentNonce: signed.message.paymentNonce,
|
|
34220
|
+
signature: signed.signature,
|
|
34221
|
+
accessRecord: signed.accessRecord
|
|
34222
|
+
});
|
|
34223
|
+
return toDirectPaymentReceipt(result);
|
|
34224
|
+
}
|
|
34225
|
+
|
|
34226
|
+
// src/direct/errors.ts
|
|
34227
|
+
var PersonalServerReadError = class extends VanaError {
|
|
34228
|
+
constructor(message, status, details) {
|
|
34229
|
+
super(message, "DIRECT_PERSONAL_SERVER_READ_ERROR");
|
|
34230
|
+
this.status = status;
|
|
34231
|
+
this.details = details;
|
|
34232
|
+
}
|
|
34233
|
+
status;
|
|
34234
|
+
details;
|
|
34235
|
+
};
|
|
34236
|
+
|
|
34237
|
+
// src/direct/personal-server-read.ts
|
|
34238
|
+
function asRecord2(value) {
|
|
34239
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
34240
|
+
}
|
|
34241
|
+
function stringField2(record, field) {
|
|
34242
|
+
const value = record?.[field];
|
|
34243
|
+
return typeof value === "string" ? value : void 0;
|
|
34244
|
+
}
|
|
34245
|
+
function parseAccessRecord(value) {
|
|
34246
|
+
const record = asRecord2(value);
|
|
34247
|
+
const dataPointId = stringField2(record, "dataPointId");
|
|
34248
|
+
const version = stringField2(record, "version");
|
|
34249
|
+
const accessor = stringField2(record, "accessor");
|
|
34250
|
+
const recordId = stringField2(record, "recordId");
|
|
34251
|
+
const signature = stringField2(record, "signature");
|
|
34252
|
+
if (!dataPointId || !version || !accessor || !recordId || !signature) {
|
|
34253
|
+
return void 0;
|
|
34254
|
+
}
|
|
34255
|
+
return {
|
|
34256
|
+
dataPointId,
|
|
34257
|
+
version,
|
|
34258
|
+
accessor,
|
|
34259
|
+
recordId,
|
|
34260
|
+
signature
|
|
34261
|
+
};
|
|
34262
|
+
}
|
|
34263
|
+
function isBytes32Hex(value) {
|
|
34264
|
+
return /^0x[0-9a-fA-F]{64}$/.test(value);
|
|
34265
|
+
}
|
|
34266
|
+
var UINT256_MAX2 = (1n << 256n) - 1n;
|
|
34267
|
+
function isAddressHex(value) {
|
|
34268
|
+
return /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
34269
|
+
}
|
|
34270
|
+
function isUint256Decimal2(value, allowZero) {
|
|
34271
|
+
const pattern = allowZero ? /^(0|[1-9]\d*)$/ : /^[1-9]\d*$/;
|
|
34272
|
+
return value.length <= UINT256_MAX2.toString().length && pattern.test(value) && BigInt(value) <= UINT256_MAX2;
|
|
34273
|
+
}
|
|
34274
|
+
function isValidDataAccessRecord(record) {
|
|
34275
|
+
return isBytes32Hex(record.dataPointId) && isUint256Decimal2(record.version, false) && isAddressHex(record.accessor) && isBytes32Hex(record.recordId) && /^0x[0-9a-fA-F]{130}$/.test(record.signature);
|
|
34276
|
+
}
|
|
34277
|
+
function parseLegacyGrantOperation(params) {
|
|
34278
|
+
const { challengeGrantId, challengeOpId, challengeOpType, grantId } = params;
|
|
34279
|
+
const opType = challengeOpType ?? GRANT_OP_TYPE;
|
|
34280
|
+
if (opType !== GRANT_OP_TYPE) {
|
|
34281
|
+
throw new PersonalServerReadError(
|
|
34282
|
+
"Personal Server payment challenge used an unsupported escrow op type",
|
|
34283
|
+
402,
|
|
34284
|
+
{ opType: challengeOpType }
|
|
34285
|
+
);
|
|
34286
|
+
}
|
|
34287
|
+
const opId = challengeOpId ?? challengeGrantId ?? grantId;
|
|
34288
|
+
if (!opId || !isBytes32Hex(opId)) {
|
|
34289
|
+
throw new PersonalServerReadError(
|
|
34290
|
+
"Personal Server payment challenge used an invalid escrow op id",
|
|
34291
|
+
402,
|
|
34292
|
+
{ opId }
|
|
34293
|
+
);
|
|
34294
|
+
}
|
|
34295
|
+
if (opId.toLowerCase() !== grantId.toLowerCase()) {
|
|
34296
|
+
throw new PersonalServerReadError(
|
|
34297
|
+
"Personal Server payment challenge did not match the requested grant",
|
|
34298
|
+
402,
|
|
34299
|
+
{ opId, grantId }
|
|
34300
|
+
);
|
|
34301
|
+
}
|
|
34302
|
+
return { opType: GRANT_OP_TYPE, opId };
|
|
34303
|
+
}
|
|
34304
|
+
function hasDataAccessMarker(body) {
|
|
34305
|
+
if (stringField2(body, "opType") === DATA_ACCESS_OP_TYPE) return true;
|
|
34306
|
+
return Array.isArray(body.accepts) && body.accepts.some((value) => {
|
|
34307
|
+
const accept = asRecord2(value);
|
|
34308
|
+
return stringField2(asRecord2(accept?.message), "opType") === DATA_ACCESS_OP_TYPE;
|
|
34309
|
+
});
|
|
34310
|
+
}
|
|
34311
|
+
function parseCanonicalDataAccessAccept(value) {
|
|
34312
|
+
const accept = asRecord2(value);
|
|
34313
|
+
const message = asRecord2(accept?.message);
|
|
34314
|
+
if (stringField2(accept, "scheme") !== "vana-escrow-grant" || stringField2(message, "opType") !== DATA_ACCESS_OP_TYPE) {
|
|
34315
|
+
return null;
|
|
34316
|
+
}
|
|
34317
|
+
const network = stringField2(accept, "network");
|
|
34318
|
+
const payerAddress = stringField2(message, "payerAddress");
|
|
34319
|
+
const opId = stringField2(message, "opId");
|
|
34320
|
+
const asset = stringField2(message, "asset");
|
|
34321
|
+
const amount = stringField2(message, "amount");
|
|
34322
|
+
const paymentNonce = stringField2(message, "paymentNonce");
|
|
34323
|
+
const accessRecord = parseAccessRecord(accept?.accessRecord);
|
|
34324
|
+
const acceptAsset = stringField2(accept, "asset");
|
|
34325
|
+
const acceptAmount = stringField2(accept, "amount");
|
|
34326
|
+
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) {
|
|
34327
|
+
return null;
|
|
34328
|
+
}
|
|
34329
|
+
return {
|
|
34330
|
+
opType: DATA_ACCESS_OP_TYPE,
|
|
34331
|
+
opId,
|
|
34332
|
+
network,
|
|
34333
|
+
paymentNonce,
|
|
34334
|
+
accessRecord,
|
|
34335
|
+
asset,
|
|
34336
|
+
amount
|
|
34337
|
+
};
|
|
34338
|
+
}
|
|
34339
|
+
function parseCanonicalDataAccessPayment(params) {
|
|
34340
|
+
const { body, grantId, raw } = params;
|
|
34341
|
+
if (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED") {
|
|
34342
|
+
throw new PersonalServerReadError(
|
|
34343
|
+
"Personal Server data-access payment response was not a canonical x402 challenge",
|
|
34344
|
+
402
|
|
34345
|
+
);
|
|
34346
|
+
}
|
|
34347
|
+
const operation = Array.isArray(body.accepts) ? body.accepts.map(parseCanonicalDataAccessAccept).find((candidate) => candidate !== null) : void 0;
|
|
34348
|
+
if (!operation) {
|
|
34349
|
+
return void 0;
|
|
34350
|
+
}
|
|
34351
|
+
return { grantId, raw, ...operation };
|
|
34352
|
+
}
|
|
34353
|
+
function preferredLegacyAccept(body) {
|
|
34354
|
+
if (!Array.isArray(body.accepts)) return void 0;
|
|
34355
|
+
return body.accepts.map(asRecord2).find((accept) => {
|
|
34356
|
+
const message = asRecord2(accept?.message);
|
|
34357
|
+
return stringField2(accept, "scheme") === "vana-escrow-grant" && stringField2(message, "opType") === GRANT_OP_TYPE;
|
|
34358
|
+
});
|
|
34359
|
+
}
|
|
34360
|
+
async function parsePersonalServerPaymentRequired(res, grantId) {
|
|
34361
|
+
let raw = void 0;
|
|
34362
|
+
try {
|
|
34363
|
+
raw = await res.json();
|
|
34364
|
+
} catch {
|
|
34365
|
+
raw = void 0;
|
|
34366
|
+
}
|
|
34367
|
+
const body = asRecord2(raw) ?? {};
|
|
34368
|
+
if (hasDataAccessMarker(body)) {
|
|
34369
|
+
const dataAccessOperation = parseCanonicalDataAccessPayment({
|
|
34370
|
+
body,
|
|
34371
|
+
grantId,
|
|
34372
|
+
raw
|
|
34373
|
+
});
|
|
34374
|
+
if (dataAccessOperation) return dataAccessOperation;
|
|
34375
|
+
}
|
|
34376
|
+
const hasAcceptsEnvelope = Object.prototype.hasOwnProperty.call(
|
|
34377
|
+
body,
|
|
34378
|
+
"accepts"
|
|
34379
|
+
);
|
|
34380
|
+
if (hasAcceptsEnvelope && (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED")) {
|
|
34381
|
+
throw new PersonalServerReadError(
|
|
34382
|
+
"Personal Server grant payment response was not a canonical x402 challenge",
|
|
34383
|
+
402
|
|
34384
|
+
);
|
|
34385
|
+
}
|
|
34386
|
+
const accept = preferredLegacyAccept(body);
|
|
34387
|
+
if (hasDataAccessMarker(body) && !accept) {
|
|
34388
|
+
throw new PersonalServerReadError(
|
|
34389
|
+
"Personal Server data-access payment challenge was untrusted or incomplete",
|
|
34390
|
+
402
|
|
34391
|
+
);
|
|
34392
|
+
}
|
|
34393
|
+
if (hasAcceptsEnvelope && !accept) {
|
|
34394
|
+
throw new PersonalServerReadError(
|
|
34395
|
+
"Personal Server grant payment challenge had no compatible escrow offer",
|
|
34396
|
+
402
|
|
34397
|
+
);
|
|
34398
|
+
}
|
|
34399
|
+
if (accept) {
|
|
34400
|
+
const message = asRecord2(accept.message);
|
|
34401
|
+
const network = stringField2(accept, "network");
|
|
34402
|
+
const payerAddress = stringField2(message, "payerAddress");
|
|
34403
|
+
const opId = stringField2(message, "opId");
|
|
34404
|
+
const asset = stringField2(message, "asset");
|
|
34405
|
+
const amount = stringField2(message, "amount");
|
|
34406
|
+
const paymentNonce = stringField2(message, "paymentNonce");
|
|
34407
|
+
const acceptAsset = stringField2(accept, "asset");
|
|
34408
|
+
const acceptAmount = stringField2(accept, "amount");
|
|
34409
|
+
const accessRecord2 = parseAccessRecord(accept.accessRecord);
|
|
34410
|
+
const hasAccessRecord = accept.accessRecord !== void 0;
|
|
34411
|
+
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) {
|
|
34412
|
+
throw new PersonalServerReadError(
|
|
34413
|
+
"Personal Server grant payment challenge was untrusted or incomplete",
|
|
34414
|
+
402
|
|
34415
|
+
);
|
|
34416
|
+
}
|
|
34417
|
+
const operation2 = parseLegacyGrantOperation({
|
|
34418
|
+
challengeOpId: opId,
|
|
34419
|
+
challengeOpType: stringField2(message, "opType"),
|
|
34420
|
+
grantId
|
|
34421
|
+
});
|
|
34422
|
+
return {
|
|
34423
|
+
grantId,
|
|
34424
|
+
...operation2,
|
|
34425
|
+
network,
|
|
34426
|
+
paymentNonce,
|
|
34427
|
+
asset,
|
|
34428
|
+
amount,
|
|
34429
|
+
raw,
|
|
34430
|
+
...accessRecord2 ? { accessRecord: accessRecord2 } : {}
|
|
34431
|
+
};
|
|
34432
|
+
}
|
|
34433
|
+
const challengeGrantId = stringField2(body, "grantId");
|
|
34434
|
+
const challengeOpId = stringField2(body, "opId");
|
|
34435
|
+
const challengeOpType = stringField2(body, "opType");
|
|
34436
|
+
const accessRecord = parseAccessRecord(body.accessRecord);
|
|
34437
|
+
const operation = parseLegacyGrantOperation({
|
|
34438
|
+
challengeGrantId,
|
|
34439
|
+
challengeOpId,
|
|
34440
|
+
challengeOpType,
|
|
34441
|
+
grantId
|
|
34442
|
+
});
|
|
34443
|
+
const amountValue = stringField2(body, "amount") ?? stringField2(body, "maxAmountRequired") ?? "0";
|
|
34444
|
+
const payment = {
|
|
34445
|
+
grantId,
|
|
34446
|
+
network: stringField2(body, "network"),
|
|
34447
|
+
paymentNonce: stringField2(body, "paymentNonce"),
|
|
34448
|
+
asset: stringField2(body, "asset") ?? NATIVE_ASSET_ADDRESS,
|
|
34449
|
+
amount: amountValue,
|
|
34450
|
+
raw
|
|
34451
|
+
};
|
|
34452
|
+
return {
|
|
34453
|
+
...payment,
|
|
34454
|
+
...operation,
|
|
34455
|
+
...accessRecord ? { accessRecord } : {}
|
|
34456
|
+
};
|
|
34457
|
+
}
|
|
34458
|
+
|
|
33991
34459
|
// src/types/ps-errors.ts
|
|
33992
34460
|
var PSError = class extends Error {
|
|
33993
34461
|
constructor(code, message) {
|
|
@@ -34062,6 +34530,7 @@ export {
|
|
|
34062
34530
|
CallbackStorage,
|
|
34063
34531
|
ContractFactory,
|
|
34064
34532
|
ContractNotFoundError,
|
|
34533
|
+
DATA_ACCESS_OP_TYPE,
|
|
34065
34534
|
DATA_REGISTRY_STATUS_ABI,
|
|
34066
34535
|
DataFileEnvelopeSchema,
|
|
34067
34536
|
DataPointStatus,
|
|
@@ -34071,6 +34540,7 @@ export {
|
|
|
34071
34540
|
ExpiredTokenError,
|
|
34072
34541
|
FEE_REGISTRY_ABI,
|
|
34073
34542
|
GENERIC_PAYMENT_TYPES,
|
|
34543
|
+
GRANT_OP_TYPE,
|
|
34074
34544
|
GRANT_REGISTRATION_TYPES,
|
|
34075
34545
|
GRANT_REVOCATION_TYPES,
|
|
34076
34546
|
GoogleDriveStorage,
|
|
@@ -34116,8 +34586,12 @@ export {
|
|
|
34116
34586
|
VanaError,
|
|
34117
34587
|
VanaStorage,
|
|
34118
34588
|
assertValidPkceVerifier,
|
|
34589
|
+
authorizeEscrowPayment,
|
|
34590
|
+
authorizeGrantPayment,
|
|
34119
34591
|
buildDepositNativeRequest,
|
|
34120
34592
|
buildDepositTokenRequest,
|
|
34593
|
+
buildEscrowPaymentHeader,
|
|
34594
|
+
buildGrantPaymentHeader,
|
|
34121
34595
|
buildMarkDataPointUnavailableRequest,
|
|
34122
34596
|
buildPersonalServerDataReadRequest,
|
|
34123
34597
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
@@ -34134,6 +34608,7 @@ export {
|
|
|
34134
34608
|
contractCacheForTesting,
|
|
34135
34609
|
createBrowserPlatformAdapter,
|
|
34136
34610
|
createDataFileEnvelope,
|
|
34611
|
+
createDefaultNonceSource,
|
|
34137
34612
|
createEscrowGatewayClient,
|
|
34138
34613
|
createGatewayClient,
|
|
34139
34614
|
createNodePlatformAdapter,
|
|
@@ -34178,8 +34653,11 @@ export {
|
|
|
34178
34653
|
mokshaServices,
|
|
34179
34654
|
mokshaTestnet2 as mokshaTestnet,
|
|
34180
34655
|
parsePSError,
|
|
34656
|
+
parsePersonalServerPaymentRequired,
|
|
34181
34657
|
parseScope,
|
|
34182
34658
|
parseWeb3SignedHeader,
|
|
34659
|
+
paymentReceiptFromHeader,
|
|
34660
|
+
paymentResponseMetadataFromHeader,
|
|
34183
34661
|
personalServerDataReadPath,
|
|
34184
34662
|
personalServerRegistrationDomain,
|
|
34185
34663
|
readPersonalServerData,
|
|
@@ -34193,6 +34671,8 @@ export {
|
|
|
34193
34671
|
signPersonalServerLiteOwnerBinding,
|
|
34194
34672
|
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
34195
34673
|
signPersonalServerRegistrationWithAccount,
|
|
34674
|
+
toDirectFeeBreakdown,
|
|
34675
|
+
toDirectPaymentReceipt,
|
|
34196
34676
|
vanaMainnet2 as vanaMainnet,
|
|
34197
34677
|
verifyGrantRegistration,
|
|
34198
34678
|
verifyPkceChallenge,
|