@opendatalabs/vana-sdk 3.23.0-pr.211.fa01520 → 4.0.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/direct/escrow-payment.cjs.map +1 -1
- package/dist/direct/escrow-payment.d.ts +2 -2
- package/dist/direct/escrow-payment.js.map +1 -1
- package/dist/index.browser.d.ts +2 -2
- package/dist/index.browser.js +173 -2
- package/dist/index.browser.js.map +3 -3
- package/dist/index.node.cjs +188 -12
- package/dist/index.node.cjs.map +3 -3
- package/dist/index.node.d.ts +2 -2
- package/dist/index.node.js +183 -12
- package/dist/index.node.js.map +3 -3
- package/dist/protocol/eip712.cjs +28 -2
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +70 -0
- package/dist/protocol/eip712.js +24 -1
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow.cjs +154 -2
- package/dist/protocol/escrow.cjs.map +1 -1
- package/dist/protocol/escrow.d.ts +145 -2
- package/dist/protocol/escrow.js +152 -1
- package/dist/protocol/escrow.js.map +1 -1
- package/dist/protocol/fixtures/moksha-identity.json +20 -0
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +8 -38
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/identity.cjs +7 -2
- package/dist/protocol/identity.cjs.map +1 -1
- package/dist/protocol/identity.js +7 -2
- package/dist/protocol/identity.js.map +1 -1
- package/package.json +1 -1
package/dist/index.node.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export { MissingAuthError, InvalidSignatureError, ExpiredTokenError, } from "./a
|
|
|
36
36
|
export { generatePkceVerifier, computePkceChallenge, verifyPkceChallenge, assertValidPkceVerifier, PKCE_VERIFIER_PATTERN, PKCE_CHALLENGE_PATTERN, } from "./auth/pkce.js";
|
|
37
37
|
export { InMemoryTokenStore, type TokenStore, type TokenRecord, } from "./auth/token-store.js";
|
|
38
38
|
export { OAuthClient, type OAuthClientConfig, type AuthorizationUrlResult, } from "./auth/oauth-client.js";
|
|
39
|
-
export { NATIVE_VANA_ASSET, dataRegistryDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, escrowPaymentDomain, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, ADD_DATA_TYPES, RECORD_DATA_ACCESS_TYPES, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, type AddDataMessage, type RecordDataAccessMessage, } from "./protocol/eip712.js";
|
|
39
|
+
export { NATIVE_VANA_ASSET, dataRegistryDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, escrowPaymentDomain, withdrawAuthorizationDomain, buildWithdrawAuthorizationTypedData, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, ADD_DATA_TYPES, RECORD_DATA_ACCESS_TYPES, WITHDRAW_AUTHORIZATION_TYPES, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, type AddDataMessage, type RecordDataAccessMessage, type WithdrawAuthorizationMessage, } from "./protocol/eip712.js";
|
|
40
40
|
export { ENCLAVE_IDENTITY_EVIDENCE_VERSION, USER_PS_ID_DOMAIN, ENCLAVE_WALLET_PURPOSE, MASTER_SIGNATURE_DELIVERY_VERSION, MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS, SEALED_ENVELOPE_VERSION, ENCLAVE_TRUST_ANCHORS, userPsId, appRootPreimage, kmsIssuedPreimage, verifyEnclaveIdentityEvidence, buildMasterSignatureDelivery, encryptMasterSignatureDelivery, type UserPsId, type EnclaveIdentityEvidence, type ExpectedIdentity, type IdentityRequest, type IdentityState, type IdentityResponse, type IdentityRegistrationRequest, type IdentityRegistrationResponse, type MasterSignatureDelivery, type SealedSecretSubmission, type SealedSecretResponse, type AesGcmBox, type SealedEnvelope, type EnclaveTrustAnchors, } from "./protocol/identity.js";
|
|
41
41
|
export { JOB_PROTOCOL_VERSION, JOB_OPERATIONS, JOB_STATES, DEFAULT_LEASE_SECONDS, MAX_LEASE_SECONDS, MAX_ATTEMPTS, MAX_WAIT_SECONDS, CLAIM_POLL_FLOOR_MS, DEFAULT_JOB_DEADLINE_SECONDS, MAX_JOB_DEADLINE_SECONDS, type JobOperation, type JobState, type PaymentState, type JobRequest, type JobRequestEnvelope, type JobSubmission, type ResultHandle, type JobStatus, type ClaimRequest, type ClaimResponse, type HeartbeatRequest, type CompleteRequest, type FailRequest, type FencedResponse, type JobResult, type TeeNodeState, type TeeNodeRegistration, type TeeNodeHeartbeat, type TeeNode, } from "./protocol/jobs.js";
|
|
42
42
|
export { createJobsClient, type JobsBuilderAccount, type JobsClientOptions, type SubmitRawReadParams, type SubmitRawReadResult, type WaitForJobOptions, type OpenJobResultOptions, type ReadRawParams, type JobsClient, } from "./protocol/jobs-client.js";
|
|
@@ -60,7 +60,7 @@ export { DERIVATIVE_STATUS_PATH, DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS, DEFAULT_D
|
|
|
60
60
|
export { deriveDataPointId, isDataPointId, scopeNamespace, derivedScopeViolatesNaming, assertDerivedScopeNaming, isRedactedLineageNode, personalServerLineagePath, gatewayLineagePath, getLineage, getPersonalServerLineage, getGatewayLineage, LineageNodeSchema, RedactedLineageNodeSchema, LineageEntrySchema, LineageGraphSchema, type LineageNode, type RedactedLineageNode, type LineageEntry, type LineageGraph, type LineageReadResult, type PersonalServerLineageParams, type GatewayLineageParams, type GetLineageParams, } from "./protocol/lineage.js";
|
|
61
61
|
export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file.js";
|
|
62
62
|
export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type OwnerServerRecord, type OwnerServersResult, type GatewayGrantFee, type GatewayGrantStatus, type GatewayGrantResponse, type GrantListItem, type DataPointRecord, type DataPointListResult, type ListDataPointsOptions, type RegisterServerParams, type RegisterServerResult, type RegisterBuilderParams, type RegisterBuilderResult, type RegisterDataPointParams, type RegisterDataPointResult, type GetDataPointOptions, type DeleteDataPointParams, type DeleteDataPointResult, type CreateGrantParams, type RevokeGrantParams, type AccessRecord, type PayForOperationParams, type PayForOperationResult, type SettleOpType, type SettleItem, type SettlePromoteResult, type SettleReconcileItem, type SettleParams, type SettleResult, type GatewayClient, } from "./protocol/gateway.js";
|
|
63
|
-
export { createEscrowGatewayClient, genericPaymentDomain, GENERIC_PAYMENT_TYPES, ESCROW_DEPOSIT_ABI, NATIVE_ASSET_ADDRESS, type GenericPaymentMessage, type EscrowBalanceEntry, type EscrowBalanceResult, type EscrowBalanceSyncResult, type DepositSubmissionResult, type PaymentBreakdown, type EscrowPayResult, type SubmitDepositParams, type PayForOpParams, type EscrowGatewayClient, type SubmittedDepositEntry, type FinalizedDepositEntry, type FailedDepositEntry, } from "./protocol/escrow.js";
|
|
63
|
+
export { createEscrowGatewayClient, genericPaymentDomain, GENERIC_PAYMENT_TYPES, ESCROW_DEPOSIT_ABI, NATIVE_ASSET_ADDRESS, type GenericPaymentMessage, type EscrowBalanceEntry, type EscrowBalanceResult, type EscrowBalanceSyncResult, type DepositSubmissionResult, type PaymentBreakdown, type EscrowPayResult, EscrowWithdrawalLifecycleError, EscrowWithdrawalRejectionError, type EscrowPaymentClient, type EscrowWithdrawalFailureResult, type EscrowWithdrawalRejectedResult, type EscrowWithdrawalRejectionCode, type EscrowWithdrawalSubmittedResult, type EscrowWithdrawalSubmittedWithoutTransaction, type EscrowWithdrawalSubmittedWithTransaction, type EscrowWithdrawalSettledResult, type EscrowWithdrawalResult, type SubmitDepositParams, type PayForOpParams, type WithdrawFromEscrowParams, type WithdrawNonceResponse, type EscrowGatewayClient, type SubmittedDepositEntry, type FinalizedDepositEntry, type FailedDepositEntry, } from "./protocol/escrow.js";
|
|
64
64
|
export { authorizeEscrowPayment, authorizeGrantPayment, buildEscrowPaymentHeader, buildGrantPaymentHeader, createDefaultNonceSource, DATA_ACCESS_OP_TYPE, GRANT_OP_TYPE, paymentReceiptFromHeader, paymentResponseMetadataFromHeader, toDirectFeeBreakdown, toDirectPaymentReceipt, type EscrowPaymentConfig, type EscrowPaymentHeaderConfig, type PaymentNonceSource, type SignTypedDataFn, } from "./direct/escrow-payment.js";
|
|
65
65
|
export { parsePersonalServerPaymentRequired, type FetchResponseLike, } from "./direct/personal-server-read.js";
|
|
66
66
|
export type { ForegroundDelivery, DirectPaymentResponseMetadata, PersonalServerDataAccessPaymentOperation, PersonalServerGrantPaymentOperation, PersonalServerPaymentOperation, PersonalServerPaymentRequired, } from "./direct/types.js";
|
package/dist/index.node.js
CHANGED
|
@@ -32018,6 +32018,9 @@ function escrowPaymentDomain(config) {
|
|
|
32018
32018
|
config.contracts.dataPortabilityEscrow
|
|
32019
32019
|
);
|
|
32020
32020
|
}
|
|
32021
|
+
function withdrawAuthorizationDomain(config) {
|
|
32022
|
+
return escrowPaymentDomain(config);
|
|
32023
|
+
}
|
|
32021
32024
|
var GRANT_REGISTRATION_TYPES = {
|
|
32022
32025
|
GrantRegistration: [
|
|
32023
32026
|
{ name: "grantorAddress", type: "address" },
|
|
@@ -32050,6 +32053,15 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32050
32053
|
{ name: "appUrl", type: "string" }
|
|
32051
32054
|
]
|
|
32052
32055
|
};
|
|
32056
|
+
var WITHDRAW_AUTHORIZATION_TYPES = {
|
|
32057
|
+
WithdrawAuthorization: [
|
|
32058
|
+
{ name: "account", type: "address" },
|
|
32059
|
+
{ name: "asset", type: "address" },
|
|
32060
|
+
{ name: "amount", type: "uint256" },
|
|
32061
|
+
{ name: "withdrawNonce", type: "uint256" },
|
|
32062
|
+
{ name: "deadline", type: "uint256" }
|
|
32063
|
+
]
|
|
32064
|
+
};
|
|
32053
32065
|
var ADD_DATA_TYPES = {
|
|
32054
32066
|
AddData: [
|
|
32055
32067
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -32068,6 +32080,14 @@ var RECORD_DATA_ACCESS_TYPES = {
|
|
|
32068
32080
|
{ name: "recordId", type: "bytes32" }
|
|
32069
32081
|
]
|
|
32070
32082
|
};
|
|
32083
|
+
function buildWithdrawAuthorizationTypedData(config, message) {
|
|
32084
|
+
return {
|
|
32085
|
+
domain: withdrawAuthorizationDomain(config),
|
|
32086
|
+
types: WITHDRAW_AUTHORIZATION_TYPES,
|
|
32087
|
+
primaryType: "WithdrawAuthorization",
|
|
32088
|
+
message
|
|
32089
|
+
};
|
|
32090
|
+
}
|
|
32071
32091
|
|
|
32072
32092
|
// src/protocol/identity.ts
|
|
32073
32093
|
init_interface();
|
|
@@ -32106,8 +32126,13 @@ function emptyAnchor() {
|
|
|
32106
32126
|
var ENCLAVE_TRUST_ANCHORS = Object.freeze({
|
|
32107
32127
|
// filled at fleet provisioning; verify fails closed while empty
|
|
32108
32128
|
[VANA_MAINNET_CHAIN_ID]: emptyAnchor(),
|
|
32109
|
-
//
|
|
32110
|
-
[MOKSHA_CHAIN_ID]:
|
|
32129
|
+
// Moksha workers share this dstack app and KMS root; the controller does not derive owner keys.
|
|
32130
|
+
[MOKSHA_CHAIN_ID]: Object.freeze({
|
|
32131
|
+
kmsRootPubkey: "0x0434c76e0c3f52ec64cbf9bbf5c910c272330166fd656c0a86bb330963e46910e1a0e6fa51bec74be2f9129342707636060d85856d102cee8290185409ecf7422f",
|
|
32132
|
+
appIds: Object.freeze([
|
|
32133
|
+
"0xec9a39de98c760e1ded9f1e97016dc5f0e357cf2"
|
|
32134
|
+
])
|
|
32135
|
+
})
|
|
32111
32136
|
});
|
|
32112
32137
|
function userPsId(chainId, ownerAddress) {
|
|
32113
32138
|
const packed = encodePacked(
|
|
@@ -36683,6 +36708,7 @@ function createGatewayClient(baseUrl) {
|
|
|
36683
36708
|
}
|
|
36684
36709
|
|
|
36685
36710
|
// src/protocol/escrow.ts
|
|
36711
|
+
import { isHex as isHex3 } from "viem";
|
|
36686
36712
|
var GENERIC_PAYMENT_TYPES = {
|
|
36687
36713
|
GenericPayment: [
|
|
36688
36714
|
{ name: "payerAddress", type: "address" },
|
|
@@ -36722,6 +36748,26 @@ var ESCROW_DEPOSIT_ABI2 = [
|
|
|
36722
36748
|
}
|
|
36723
36749
|
];
|
|
36724
36750
|
var NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
36751
|
+
var EscrowWithdrawalLifecycleError = class extends Error {
|
|
36752
|
+
constructor(httpStatus, result) {
|
|
36753
|
+
super(result.error);
|
|
36754
|
+
this.httpStatus = httpStatus;
|
|
36755
|
+
this.result = result;
|
|
36756
|
+
}
|
|
36757
|
+
httpStatus;
|
|
36758
|
+
result;
|
|
36759
|
+
name = "EscrowWithdrawalLifecycleError";
|
|
36760
|
+
};
|
|
36761
|
+
var EscrowWithdrawalRejectionError = class extends Error {
|
|
36762
|
+
constructor(httpStatus, result) {
|
|
36763
|
+
super(result.error);
|
|
36764
|
+
this.httpStatus = httpStatus;
|
|
36765
|
+
this.result = result;
|
|
36766
|
+
}
|
|
36767
|
+
httpStatus;
|
|
36768
|
+
result;
|
|
36769
|
+
name = "EscrowWithdrawalRejectionError";
|
|
36770
|
+
};
|
|
36725
36771
|
function createEscrowGatewayClient(baseUrl) {
|
|
36726
36772
|
const base = baseUrl.replace(/\/+$/, "");
|
|
36727
36773
|
async function throwOnError(res, context) {
|
|
@@ -36737,6 +36783,27 @@ function createEscrowGatewayClient(baseUrl) {
|
|
|
36737
36783
|
);
|
|
36738
36784
|
}
|
|
36739
36785
|
}
|
|
36786
|
+
async function throwOnWithdrawError(res) {
|
|
36787
|
+
if (res.ok) return;
|
|
36788
|
+
let body;
|
|
36789
|
+
try {
|
|
36790
|
+
body = await res.json();
|
|
36791
|
+
} catch {
|
|
36792
|
+
throw new Error(
|
|
36793
|
+
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}`
|
|
36794
|
+
);
|
|
36795
|
+
}
|
|
36796
|
+
if (isEscrowWithdrawalFailureResult(body)) {
|
|
36797
|
+
throw new EscrowWithdrawalLifecycleError(res.status, body);
|
|
36798
|
+
}
|
|
36799
|
+
if (isEscrowWithdrawalRejectedResult(body)) {
|
|
36800
|
+
throw new EscrowWithdrawalRejectionError(res.status, body);
|
|
36801
|
+
}
|
|
36802
|
+
const error = getGatewayErrorMessage(body);
|
|
36803
|
+
throw new Error(
|
|
36804
|
+
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}${error ? `: ${error}` : ""}`
|
|
36805
|
+
);
|
|
36806
|
+
}
|
|
36740
36807
|
return {
|
|
36741
36808
|
async submitDeposit({ txHash }) {
|
|
36742
36809
|
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
@@ -36792,9 +36859,108 @@ function createEscrowGatewayClient(baseUrl) {
|
|
|
36792
36859
|
});
|
|
36793
36860
|
await throwOnError(res, "POST /v1/escrow/pay");
|
|
36794
36861
|
return res.json();
|
|
36862
|
+
},
|
|
36863
|
+
async withdraw({
|
|
36864
|
+
account,
|
|
36865
|
+
asset,
|
|
36866
|
+
amount,
|
|
36867
|
+
withdrawNonce,
|
|
36868
|
+
deadline,
|
|
36869
|
+
signature
|
|
36870
|
+
}) {
|
|
36871
|
+
const res = await fetch(`${base}/v1/escrow/withdraw`, {
|
|
36872
|
+
method: "POST",
|
|
36873
|
+
headers: {
|
|
36874
|
+
"Content-Type": "application/json",
|
|
36875
|
+
Authorization: `Web3Signed ${signature}`
|
|
36876
|
+
},
|
|
36877
|
+
body: JSON.stringify({
|
|
36878
|
+
account,
|
|
36879
|
+
asset,
|
|
36880
|
+
amount,
|
|
36881
|
+
withdrawNonce,
|
|
36882
|
+
deadline
|
|
36883
|
+
})
|
|
36884
|
+
});
|
|
36885
|
+
await throwOnWithdrawError(res);
|
|
36886
|
+
return res.json();
|
|
36887
|
+
},
|
|
36888
|
+
async getWithdrawNonce(account) {
|
|
36889
|
+
const res = await fetch(
|
|
36890
|
+
`${base}/v1/escrow/withdraw/nonce?account=${encodeURIComponent(account)}`,
|
|
36891
|
+
{ cache: "no-store" }
|
|
36892
|
+
);
|
|
36893
|
+
await throwOnError(res, "GET /v1/escrow/withdraw/nonce");
|
|
36894
|
+
const body = await res.json();
|
|
36895
|
+
if (!isWithdrawNonceResponse(body, account)) {
|
|
36896
|
+
throw new Error(
|
|
36897
|
+
"GET /v1/escrow/withdraw/nonce: invalid response structure"
|
|
36898
|
+
);
|
|
36899
|
+
}
|
|
36900
|
+
return body;
|
|
36795
36901
|
}
|
|
36796
36902
|
};
|
|
36797
36903
|
}
|
|
36904
|
+
function getGatewayErrorMessage(body) {
|
|
36905
|
+
if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
|
|
36906
|
+
return body.error;
|
|
36907
|
+
}
|
|
36908
|
+
return void 0;
|
|
36909
|
+
}
|
|
36910
|
+
function isEscrowWithdrawalFailureResult(body) {
|
|
36911
|
+
if (typeof body !== "object" || body === null) return false;
|
|
36912
|
+
const value = body;
|
|
36913
|
+
return value.success === false && (value.status === "retryable" || value.status === "reorged" || value.status === "failed") && typeof value.error === "string" && isAddressHex(value.account) && isAddressHex(value.asset) && isUint256Decimal(value.amount) && isUint256Decimal(value.withdrawNonce) && isUint256Decimal(value.deadline) && (isHash(value.txHash) || value.txHash === null) && (!("blockNumber" in value) || isBlockNumber(value.blockNumber));
|
|
36914
|
+
}
|
|
36915
|
+
function isEscrowWithdrawalRejectedResult(body) {
|
|
36916
|
+
if (typeof body !== "object" || body === null) return false;
|
|
36917
|
+
const value = body;
|
|
36918
|
+
return value.success === false && value.status === "rejected" && isWithdrawalRejectionCode(value.code) && typeof value.error === "string" && isAddressHex(value.account) && isAddressHex(value.asset) && isUint256Decimal(value.amount) && isUint256Decimal(value.withdrawNonce) && isUint256Decimal(value.deadline) && optionalUint256Decimal(value.balance) && optionalUint256Decimal(value.authorizedAmount) && optionalUint256Decimal(value.withdrawingAmount) && optionalUint256Decimal(value.availableAmount) && optionalUint256Decimal(value.requestedAmount) && optionalUint256Decimal(value.minimumAmount);
|
|
36919
|
+
}
|
|
36920
|
+
function isWithdrawalRejectionCode(value) {
|
|
36921
|
+
return value === "below_minimum" || value === "deadline_too_far" || value === "expired" || value === "insufficient_available" || value === "stale_nonce";
|
|
36922
|
+
}
|
|
36923
|
+
function optionalUint256Decimal(value) {
|
|
36924
|
+
return value === void 0 || isUint256Decimal(value);
|
|
36925
|
+
}
|
|
36926
|
+
function isAddressHex(value) {
|
|
36927
|
+
return typeof value === "string" && isHex3(value, { strict: true }) && value.length === 42;
|
|
36928
|
+
}
|
|
36929
|
+
function isHash(value) {
|
|
36930
|
+
return typeof value === "string" && isHex3(value, { strict: true }) && value.length === 66;
|
|
36931
|
+
}
|
|
36932
|
+
function isUint256Decimal(value) {
|
|
36933
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 78) {
|
|
36934
|
+
return false;
|
|
36935
|
+
}
|
|
36936
|
+
if (!/^(0|[1-9]\d*)$/.test(value)) return false;
|
|
36937
|
+
return BigInt(value) <= 2n ** 256n - 1n;
|
|
36938
|
+
}
|
|
36939
|
+
function isBlockNumber(value) {
|
|
36940
|
+
return value === null || isUint256Decimal(value);
|
|
36941
|
+
}
|
|
36942
|
+
function isWithdrawNonceResponse(body, requestedAccount) {
|
|
36943
|
+
if (typeof body !== "object" || body === null) return false;
|
|
36944
|
+
const value = body;
|
|
36945
|
+
if (value.success !== true) return false;
|
|
36946
|
+
if (!isAddressHex(value.account)) return false;
|
|
36947
|
+
if (value.account.toLowerCase() !== requestedAccount.toLowerCase())
|
|
36948
|
+
return false;
|
|
36949
|
+
if (typeof value.chainId !== "string") return false;
|
|
36950
|
+
if (!/^(0|[1-9]\d*)$/.test(value.chainId)) return false;
|
|
36951
|
+
const isLastNull = value.lastWithdrawNonce === null;
|
|
36952
|
+
const lastNonceValid = isLastNull || isUint256Decimal(value.lastWithdrawNonce);
|
|
36953
|
+
if (!lastNonceValid) return false;
|
|
36954
|
+
if (!isUint256Decimal(value.nextWithdrawNonce)) return false;
|
|
36955
|
+
if (isLastNull) {
|
|
36956
|
+
return value.nextWithdrawNonce === "1";
|
|
36957
|
+
}
|
|
36958
|
+
const lastNonce = BigInt(value.lastWithdrawNonce);
|
|
36959
|
+
const nextNonce = BigInt(value.nextWithdrawNonce);
|
|
36960
|
+
const expectedNextNonce = lastNonce + 1n;
|
|
36961
|
+
if (expectedNextNonce > 2n ** 256n - 1n) return false;
|
|
36962
|
+
return nextNonce === expectedNextNonce;
|
|
36963
|
+
}
|
|
36798
36964
|
|
|
36799
36965
|
// src/direct/escrow-payment.ts
|
|
36800
36966
|
var GRANT_OP_TYPE = "grant";
|
|
@@ -36831,12 +36997,12 @@ var UINT256_MAX = (1n << 256n) - 1n;
|
|
|
36831
36997
|
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
36832
36998
|
var BYTES32_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
36833
36999
|
var SIGNATURE_RE = /^0x[0-9a-fA-F]{130}$/;
|
|
36834
|
-
function
|
|
37000
|
+
function isUint256Decimal2(value, allowZero) {
|
|
36835
37001
|
const pattern = allowZero ? /^(0|[1-9]\d*)$/ : /^[1-9]\d*$/;
|
|
36836
37002
|
return value.length <= UINT256_MAX.toString().length && pattern.test(value) && BigInt(value) <= UINT256_MAX;
|
|
36837
37003
|
}
|
|
36838
37004
|
function isValidAccessRecord(record) {
|
|
36839
|
-
return BYTES32_RE.test(record.dataPointId) &&
|
|
37005
|
+
return BYTES32_RE.test(record.dataPointId) && isUint256Decimal2(record.version, false) && ADDRESS_RE.test(record.accessor) && BYTES32_RE.test(record.recordId) && SIGNATURE_RE.test(record.signature);
|
|
36840
37006
|
}
|
|
36841
37007
|
function validateSigningOperation(payerAddress, required) {
|
|
36842
37008
|
if (!ADDRESS_RE.test(payerAddress)) {
|
|
@@ -36848,10 +37014,10 @@ function validateSigningOperation(payerAddress, required) {
|
|
|
36848
37014
|
if (!ADDRESS_RE.test(required.asset || NATIVE_ASSET_ADDRESS)) {
|
|
36849
37015
|
throw new Error("Payment asset must be a 20-byte EVM address");
|
|
36850
37016
|
}
|
|
36851
|
-
if (!
|
|
37017
|
+
if (!isUint256Decimal2(required.amount, true)) {
|
|
36852
37018
|
throw new Error("Payment amount must be a canonical uint256 decimal");
|
|
36853
37019
|
}
|
|
36854
|
-
if (required.paymentNonce !== void 0 && !
|
|
37020
|
+
if (required.paymentNonce !== void 0 && !isUint256Decimal2(required.paymentNonce, false)) {
|
|
36855
37021
|
throw new Error("Payment nonce must be a positive uint256 decimal");
|
|
36856
37022
|
}
|
|
36857
37023
|
const accessRecord = required.accessRecord;
|
|
@@ -36982,7 +37148,7 @@ function paymentResponseMetadataFromHeader(header) {
|
|
|
36982
37148
|
const registrationFee = stringField(breakdown, "registrationFee");
|
|
36983
37149
|
const dataAccessFee = stringField(breakdown, "dataAccessFee");
|
|
36984
37150
|
const paidAt = stringField(result, "paidAt");
|
|
36985
|
-
if (result?.success !== true || !opType || !opId || !BYTES32_RE.test(opId) || !payerAddress || !ADDRESS_RE.test(payerAddress) || !asset || !ADDRESS_RE.test(asset) || !amount || !
|
|
37151
|
+
if (result?.success !== true || !opType || !opId || !BYTES32_RE.test(opId) || !payerAddress || !ADDRESS_RE.test(payerAddress) || !asset || !ADDRESS_RE.test(asset) || !amount || !isUint256Decimal2(amount, true) || !paymentNonce || !isUint256Decimal2(paymentNonce, false) || !registrationFee || !isUint256Decimal2(registrationFee, true) || !dataAccessFee || !isUint256Decimal2(dataAccessFee, true) || typeof breakdown?.registrationPaid !== "boolean" || !paidAt || !isCanonicalIsoTimestamp(paidAt)) {
|
|
36986
37152
|
return void 0;
|
|
36987
37153
|
}
|
|
36988
37154
|
return {
|
|
@@ -37063,15 +37229,15 @@ function isBytes32Hex(value) {
|
|
|
37063
37229
|
return /^0x[0-9a-fA-F]{64}$/.test(value);
|
|
37064
37230
|
}
|
|
37065
37231
|
var UINT256_MAX2 = (1n << 256n) - 1n;
|
|
37066
|
-
function
|
|
37232
|
+
function isAddressHex2(value) {
|
|
37067
37233
|
return /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
37068
37234
|
}
|
|
37069
|
-
function
|
|
37235
|
+
function isUint256Decimal3(value, allowZero) {
|
|
37070
37236
|
const pattern = allowZero ? /^(0|[1-9]\d*)$/ : /^[1-9]\d*$/;
|
|
37071
37237
|
return value.length <= UINT256_MAX2.toString().length && pattern.test(value) && BigInt(value) <= UINT256_MAX2;
|
|
37072
37238
|
}
|
|
37073
37239
|
function isValidDataAccessRecord(record) {
|
|
37074
|
-
return isBytes32Hex(record.dataPointId) &&
|
|
37240
|
+
return isBytes32Hex(record.dataPointId) && isUint256Decimal3(record.version, false) && isAddressHex2(record.accessor) && isBytes32Hex(record.recordId) && /^0x[0-9a-fA-F]{130}$/.test(record.signature);
|
|
37075
37241
|
}
|
|
37076
37242
|
function parseLegacyGrantOperation(params) {
|
|
37077
37243
|
const { challengeGrantId, challengeOpId, challengeOpType, grantId } = params;
|
|
@@ -37122,7 +37288,7 @@ function parseCanonicalDataAccessAccept(value) {
|
|
|
37122
37288
|
const accessRecord = parseAccessRecord(accept?.accessRecord);
|
|
37123
37289
|
const acceptAsset = stringField2(accept, "asset");
|
|
37124
37290
|
const acceptAmount = stringField2(accept, "amount");
|
|
37125
|
-
if (!network || !payerAddress || !
|
|
37291
|
+
if (!network || !payerAddress || !isAddressHex2(payerAddress) || !opId || !isBytes32Hex(opId) || !asset || !isAddressHex2(asset) || !amount || !isUint256Decimal3(amount, true) || !paymentNonce || !isUint256Decimal3(paymentNonce, false) || !accessRecord || !isValidDataAccessRecord(accessRecord) || payerAddress.toLowerCase() !== accessRecord.accessor.toLowerCase() || opId.toLowerCase() !== accessRecord.recordId.toLowerCase() || !acceptAsset || acceptAsset.toLowerCase() !== asset.toLowerCase() || acceptAmount !== amount) {
|
|
37126
37292
|
return null;
|
|
37127
37293
|
}
|
|
37128
37294
|
return {
|
|
@@ -37207,7 +37373,7 @@ async function parsePersonalServerPaymentRequired(res, grantId) {
|
|
|
37207
37373
|
const acceptAmount = stringField2(accept, "amount");
|
|
37208
37374
|
const accessRecord2 = parseAccessRecord(accept.accessRecord);
|
|
37209
37375
|
const hasAccessRecord = accept.accessRecord !== void 0;
|
|
37210
|
-
if (!network || !payerAddress || !
|
|
37376
|
+
if (!network || !payerAddress || !isAddressHex2(payerAddress) || !opId || !isBytes32Hex(opId) || !asset || !isAddressHex2(asset) || !amount || !isUint256Decimal3(amount, true) || !paymentNonce || !isUint256Decimal3(paymentNonce, false) || !acceptAsset || acceptAsset.toLowerCase() !== asset.toLowerCase() || acceptAmount !== amount || hasAccessRecord && (!accessRecord2 || !isValidDataAccessRecord(accessRecord2) || accessRecord2.accessor.toLowerCase() !== payerAddress.toLowerCase()) || amount === "0" && !accessRecord2) {
|
|
37211
37377
|
throw new PersonalServerReadError(
|
|
37212
37378
|
"Personal Server grant payment challenge was untrusted or incomplete",
|
|
37213
37379
|
402
|
|
@@ -37350,6 +37516,8 @@ export {
|
|
|
37350
37516
|
ENCLAVE_TRUST_ANCHORS,
|
|
37351
37517
|
ENCLAVE_WALLET_PURPOSE,
|
|
37352
37518
|
ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
|
|
37519
|
+
EscrowWithdrawalLifecycleError,
|
|
37520
|
+
EscrowWithdrawalRejectionError,
|
|
37353
37521
|
ExpiredTokenError2 as ExpiredTokenError,
|
|
37354
37522
|
FEE_REGISTRY_ABI,
|
|
37355
37523
|
GENERIC_PAYMENT_TYPES,
|
|
@@ -37421,6 +37589,7 @@ export {
|
|
|
37421
37589
|
TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
37422
37590
|
USER_PS_ID_DOMAIN,
|
|
37423
37591
|
VanaStorage,
|
|
37592
|
+
WITHDRAW_AUTHORIZATION_TYPES,
|
|
37424
37593
|
WRITER_ATTRIBUTION_KEY,
|
|
37425
37594
|
WRITE_CONTENT_DISPOSITION_HEADER,
|
|
37426
37595
|
WRITE_FILENAME_HEADER,
|
|
@@ -37449,6 +37618,7 @@ export {
|
|
|
37449
37618
|
buildPersonalServerRegistrationTypedData,
|
|
37450
37619
|
buildSetDataPointStatusRequest,
|
|
37451
37620
|
buildWeb3SignedHeader,
|
|
37621
|
+
buildWithdrawAuthorizationTypedData,
|
|
37452
37622
|
builderRegistrationDomain,
|
|
37453
37623
|
canonicalJobRequestBytes,
|
|
37454
37624
|
chains,
|
|
@@ -37576,6 +37746,7 @@ export {
|
|
|
37576
37746
|
verifyWeb3Signed,
|
|
37577
37747
|
waitForDerivativeStatus,
|
|
37578
37748
|
waitForQuestion,
|
|
37749
|
+
withdrawAuthorizationDomain,
|
|
37579
37750
|
writeData,
|
|
37580
37751
|
writePersonalServerData
|
|
37581
37752
|
};
|