@opendatalabs/vana-sdk 3.22.0-pr.208.e9c19e9 → 3.22.0-pr.209.13d545d
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/crypto/envelope/job.cjs +26 -87
- package/dist/crypto/envelope/job.cjs.map +1 -1
- package/dist/crypto/envelope/job.d.ts +9 -95
- package/dist/crypto/envelope/job.js +27 -91
- package/dist/crypto/envelope/job.js.map +1 -1
- 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 +39 -265
- package/dist/index.browser.js.map +3 -3
- package/dist/index.node.cjs +36 -267
- package/dist/index.node.cjs.map +3 -3
- package/dist/index.node.d.ts +2 -2
- package/dist/index.node.js +49 -275
- package/dist/index.node.js.map +3 -3
- package/dist/protocol/eip712.cjs +2 -28
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +0 -70
- package/dist/protocol/eip712.js +1 -24
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow.cjs +2 -154
- package/dist/protocol/escrow.cjs.map +1 -1
- package/dist/protocol/escrow.d.ts +2 -145
- package/dist/protocol/escrow.js +1 -152
- package/dist/protocol/escrow.js.map +1 -1
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +38 -8
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/jobs.cjs.map +1 -1
- package/dist/protocol/jobs.d.ts +1 -23
- package/dist/protocol/jobs.js.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -31685,9 +31685,6 @@ function escrowPaymentDomain(config) {
|
|
|
31685
31685
|
config.contracts.dataPortabilityEscrow
|
|
31686
31686
|
);
|
|
31687
31687
|
}
|
|
31688
|
-
function withdrawAuthorizationDomain(config) {
|
|
31689
|
-
return escrowPaymentDomain(config);
|
|
31690
|
-
}
|
|
31691
31688
|
var GRANT_REGISTRATION_TYPES = {
|
|
31692
31689
|
GrantRegistration: [
|
|
31693
31690
|
{ name: "grantorAddress", type: "address" },
|
|
@@ -31720,15 +31717,6 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
31720
31717
|
{ name: "appUrl", type: "string" }
|
|
31721
31718
|
]
|
|
31722
31719
|
};
|
|
31723
|
-
var WITHDRAW_AUTHORIZATION_TYPES = {
|
|
31724
|
-
WithdrawAuthorization: [
|
|
31725
|
-
{ name: "account", type: "address" },
|
|
31726
|
-
{ name: "asset", type: "address" },
|
|
31727
|
-
{ name: "amount", type: "uint256" },
|
|
31728
|
-
{ name: "withdrawNonce", type: "uint256" },
|
|
31729
|
-
{ name: "deadline", type: "uint256" }
|
|
31730
|
-
]
|
|
31731
|
-
};
|
|
31732
31720
|
var ADD_DATA_TYPES = {
|
|
31733
31721
|
AddData: [
|
|
31734
31722
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -31747,14 +31735,6 @@ var RECORD_DATA_ACCESS_TYPES = {
|
|
|
31747
31735
|
{ name: "recordId", type: "bytes32" }
|
|
31748
31736
|
]
|
|
31749
31737
|
};
|
|
31750
|
-
function buildWithdrawAuthorizationTypedData(config, message) {
|
|
31751
|
-
return {
|
|
31752
|
-
domain: withdrawAuthorizationDomain(config),
|
|
31753
|
-
types: WITHDRAW_AUTHORIZATION_TYPES,
|
|
31754
|
-
primaryType: "WithdrawAuthorization",
|
|
31755
|
-
message
|
|
31756
|
-
};
|
|
31757
|
-
}
|
|
31758
31738
|
|
|
31759
31739
|
// src/protocol/identity.ts
|
|
31760
31740
|
init_interface();
|
|
@@ -31948,7 +31928,7 @@ var MAX_JOB_DEADLINE_SECONDS = 3600;
|
|
|
31948
31928
|
// src/crypto/envelope/job.ts
|
|
31949
31929
|
init_interface();
|
|
31950
31930
|
import { sha256 as sha2565 } from "@noble/hashes/sha2";
|
|
31951
|
-
import { bytesToHex as bytesToHex2, fromHex as fromHex6,
|
|
31931
|
+
import { bytesToHex as bytesToHex2, fromHex as fromHex6, toHex as toHex7 } from "viem";
|
|
31952
31932
|
var textDecoder = new TextDecoder();
|
|
31953
31933
|
var textEncoder = new TextEncoder();
|
|
31954
31934
|
var JobEnvelopeError = class extends Error {
|
|
@@ -31975,11 +31955,9 @@ function canonicalJsonBytes(value) {
|
|
|
31975
31955
|
return textEncoder.encode(JSON.stringify(sortJsonKeys(value)));
|
|
31976
31956
|
}
|
|
31977
31957
|
function canonicalJobRequestBytes(request) {
|
|
31978
|
-
validateJobRequest(request);
|
|
31979
31958
|
return canonicalJsonBytes(request);
|
|
31980
31959
|
}
|
|
31981
31960
|
function requestPlaintext(envelope) {
|
|
31982
|
-
validateRequestEnvelope(envelope);
|
|
31983
31961
|
return canonicalJsonBytes(envelope);
|
|
31984
31962
|
}
|
|
31985
31963
|
function resultPlaintext(result) {
|
|
@@ -32012,99 +31990,42 @@ function parseObject(plaintext, kind) {
|
|
|
32012
31990
|
throw new JobEnvelopeError(`Invalid ${kind}: malformed JSON`);
|
|
32013
31991
|
}
|
|
32014
31992
|
}
|
|
32015
|
-
function isPlainObject2(value) {
|
|
32016
|
-
if (value === null || typeof value !== "object") return false;
|
|
32017
|
-
const prototype = Object.getPrototypeOf(value);
|
|
32018
|
-
return prototype === Object.prototype || prototype === null;
|
|
32019
|
-
}
|
|
32020
|
-
function requirePlainObject(value, field, kind) {
|
|
32021
|
-
if (!isPlainObject2(value)) {
|
|
32022
|
-
throw new JobEnvelopeError(`Invalid ${kind}: invalid ${field}`);
|
|
32023
|
-
}
|
|
32024
|
-
}
|
|
32025
|
-
function requireExactKeys(value, expectedKeys, kind) {
|
|
32026
|
-
for (const key of expectedKeys) {
|
|
32027
|
-
if (!Object.hasOwn(value, key) || value[key] === void 0) {
|
|
32028
|
-
throw new JobEnvelopeError(`Invalid ${kind}: missing ${key}`);
|
|
32029
|
-
}
|
|
32030
|
-
}
|
|
32031
|
-
const expected = new Set(expectedKeys);
|
|
32032
|
-
for (const key of Reflect.ownKeys(value)) {
|
|
32033
|
-
if (!expected.has(key)) {
|
|
32034
|
-
throw new JobEnvelopeError(
|
|
32035
|
-
`Invalid ${kind}: unknown field ${String(key)}`
|
|
32036
|
-
);
|
|
32037
|
-
}
|
|
32038
|
-
}
|
|
32039
|
-
}
|
|
32040
31993
|
function requireString(value, field, kind) {
|
|
32041
31994
|
if (typeof value !== "string" || value.length === 0) {
|
|
32042
31995
|
throw new JobEnvelopeError(`Invalid ${kind}: missing ${field}`);
|
|
32043
31996
|
}
|
|
32044
31997
|
}
|
|
32045
|
-
function
|
|
32046
|
-
|
|
32047
|
-
|
|
32048
|
-
|
|
32049
|
-
|
|
32050
|
-
|
|
32051
|
-
|
|
32052
|
-
"owner",
|
|
32053
|
-
"builder",
|
|
32054
|
-
"builderPublicKey",
|
|
32055
|
-
"grantId",
|
|
32056
|
-
"scope",
|
|
32057
|
-
"operation",
|
|
32058
|
-
"pinnedVersion",
|
|
32059
|
-
"deadline"
|
|
32060
|
-
],
|
|
32061
|
-
"job request"
|
|
32062
|
-
);
|
|
32063
|
-
if (value.v !== JOB_PROTOCOL_VERSION) {
|
|
31998
|
+
function validateRequestEnvelope(value) {
|
|
31999
|
+
const request = value.request;
|
|
32000
|
+
if (request === null || typeof request !== "object" || Array.isArray(request)) {
|
|
32001
|
+
throw new JobEnvelopeError("Invalid job request envelope: missing request");
|
|
32002
|
+
}
|
|
32003
|
+
const fields = request;
|
|
32004
|
+
if (fields.v !== 1) {
|
|
32064
32005
|
throw new JobEnvelopeError(
|
|
32065
|
-
`Unsupported job request version: ${String(
|
|
32006
|
+
`Unsupported job request version: ${String(fields.v)}`
|
|
32066
32007
|
);
|
|
32067
32008
|
}
|
|
32068
|
-
|
|
32069
|
-
|
|
32070
|
-
|
|
32071
|
-
|
|
32072
|
-
|
|
32073
|
-
|
|
32074
|
-
|
|
32075
|
-
|
|
32076
|
-
|
|
32077
|
-
|
|
32078
|
-
|
|
32079
|
-
|
|
32080
|
-
|
|
32081
|
-
requireString(value.scope, "scope", "job request");
|
|
32082
|
-
if (!JOB_OPERATIONS.includes(value.operation)) {
|
|
32083
|
-
throw new JobEnvelopeError("Invalid job request: invalid operation");
|
|
32084
|
-
}
|
|
32085
|
-
if (value.pinnedVersion !== null && typeof value.pinnedVersion !== "string") {
|
|
32009
|
+
for (const field of [
|
|
32010
|
+
"jobId",
|
|
32011
|
+
"owner",
|
|
32012
|
+
"builder",
|
|
32013
|
+
"builderPublicKey",
|
|
32014
|
+
"grantId",
|
|
32015
|
+
"scope",
|
|
32016
|
+
"operation",
|
|
32017
|
+
"deadline"
|
|
32018
|
+
]) {
|
|
32019
|
+
requireString(fields[field], field, "job request");
|
|
32020
|
+
}
|
|
32021
|
+
if (fields.pinnedVersion !== null && typeof fields.pinnedVersion !== "string") {
|
|
32086
32022
|
throw new JobEnvelopeError("Invalid job request: missing pinnedVersion");
|
|
32087
32023
|
}
|
|
32088
|
-
if (typeof value.deadline !== "string" || !Number.isFinite(Date.parse(value.deadline))) {
|
|
32089
|
-
throw new JobEnvelopeError("Invalid job request: invalid deadline");
|
|
32090
|
-
}
|
|
32091
|
-
return value;
|
|
32092
|
-
}
|
|
32093
|
-
function validateRequestEnvelope(value) {
|
|
32094
|
-
requirePlainObject(value, "envelope", "job request envelope");
|
|
32095
|
-
requireExactKeys(value, ["request", "auth"], "job request envelope");
|
|
32096
|
-
validateJobRequest(value.request);
|
|
32097
32024
|
requireString(value.auth, "auth", "job request envelope");
|
|
32098
32025
|
return value;
|
|
32099
32026
|
}
|
|
32100
32027
|
function validateResult(value) {
|
|
32101
|
-
|
|
32102
|
-
requireExactKeys(
|
|
32103
|
-
value,
|
|
32104
|
-
["v", "jobId", "scope", "version", "contentType", "body"],
|
|
32105
|
-
"job result"
|
|
32106
|
-
);
|
|
32107
|
-
if (value.v !== JOB_PROTOCOL_VERSION) {
|
|
32028
|
+
if (value.v !== 1) {
|
|
32108
32029
|
throw new JobEnvelopeError(
|
|
32109
32030
|
`Unsupported job result version: ${String(value.v)}`
|
|
32110
32031
|
);
|
|
@@ -32120,10 +32041,10 @@ function validateResult(value) {
|
|
|
32120
32041
|
}
|
|
32121
32042
|
return value;
|
|
32122
32043
|
}
|
|
32123
|
-
async function sealJobRequest(
|
|
32044
|
+
async function sealJobRequest(e, enclavePublicKey, ecies) {
|
|
32124
32045
|
const encrypted = await ecies.encrypt(
|
|
32125
32046
|
fromHex6(enclavePublicKey, "bytes"),
|
|
32126
|
-
requestPlaintext(
|
|
32047
|
+
requestPlaintext(e)
|
|
32127
32048
|
);
|
|
32128
32049
|
return encryptedBytesToBase64(encrypted);
|
|
32129
32050
|
}
|
|
@@ -32136,11 +32057,10 @@ async function openJobRequest(ciphertext, privateKey, ecies) {
|
|
|
32136
32057
|
parseObject(plaintext, "job request envelope")
|
|
32137
32058
|
);
|
|
32138
32059
|
}
|
|
32139
|
-
async function sealJobResult(
|
|
32140
|
-
validateResult(result);
|
|
32060
|
+
async function sealJobResult(r, builderPublicKey, ecies) {
|
|
32141
32061
|
const encrypted = await ecies.encrypt(
|
|
32142
32062
|
fromHex6(builderPublicKey, "bytes"),
|
|
32143
|
-
resultPlaintext(
|
|
32063
|
+
resultPlaintext(r)
|
|
32144
32064
|
);
|
|
32145
32065
|
const ciphertext = encryptedBytesToBase64(encrypted);
|
|
32146
32066
|
const bytes = fromBase64(ciphertext);
|
|
@@ -32172,7 +32092,7 @@ async function openJobResult(ciphertext, builderPrivateKey, ecies, expect) {
|
|
|
32172
32092
|
|
|
32173
32093
|
// src/protocol/personal-server-registration.ts
|
|
32174
32094
|
import {
|
|
32175
|
-
isAddress
|
|
32095
|
+
isAddress
|
|
32176
32096
|
} from "viem";
|
|
32177
32097
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
32178
32098
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
@@ -32180,7 +32100,7 @@ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress
|
|
|
32180
32100
|
"DataPortabilityServers"
|
|
32181
32101
|
);
|
|
32182
32102
|
function assertAddress(value, name) {
|
|
32183
|
-
if (!
|
|
32103
|
+
if (!isAddress(value)) {
|
|
32184
32104
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32185
32105
|
}
|
|
32186
32106
|
}
|
|
@@ -32267,13 +32187,13 @@ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
|
32267
32187
|
|
|
32268
32188
|
// src/personal-server-lite/owner-binding.ts
|
|
32269
32189
|
import {
|
|
32270
|
-
isAddress as
|
|
32190
|
+
isAddress as isAddress2
|
|
32271
32191
|
} from "viem";
|
|
32272
32192
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
32273
32193
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32274
32194
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32275
32195
|
function assertAddress2(value, name) {
|
|
32276
|
-
if (!
|
|
32196
|
+
if (!isAddress2(value)) {
|
|
32277
32197
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32278
32198
|
}
|
|
32279
32199
|
}
|
|
@@ -32323,7 +32243,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
|
32323
32243
|
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32324
32244
|
|
|
32325
32245
|
// src/account/personal-server-registration.ts
|
|
32326
|
-
import { isAddress as
|
|
32246
|
+
import { isAddress as isAddress3 } from "viem";
|
|
32327
32247
|
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32328
32248
|
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32329
32249
|
status;
|
|
@@ -32342,7 +32262,7 @@ function trimTrailingSlash(value) {
|
|
|
32342
32262
|
return value.replace(/\/+$/, "");
|
|
32343
32263
|
}
|
|
32344
32264
|
function assertAddress3(value, name) {
|
|
32345
|
-
if (!
|
|
32265
|
+
if (!isAddress3(value)) {
|
|
32346
32266
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32347
32267
|
}
|
|
32348
32268
|
}
|
|
@@ -32868,7 +32788,7 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
32868
32788
|
|
|
32869
32789
|
// src/protocol/data-point-deletion.ts
|
|
32870
32790
|
import {
|
|
32871
|
-
isAddress as
|
|
32791
|
+
isAddress as isAddress5,
|
|
32872
32792
|
keccak256 as keccak2563,
|
|
32873
32793
|
maxUint256,
|
|
32874
32794
|
stringToBytes as stringToBytes3
|
|
@@ -32877,7 +32797,7 @@ import {
|
|
|
32877
32797
|
// src/protocol/lineage.ts
|
|
32878
32798
|
import {
|
|
32879
32799
|
encodeAbiParameters,
|
|
32880
|
-
isAddress as
|
|
32800
|
+
isAddress as isAddress4,
|
|
32881
32801
|
keccak256 as keccak2562
|
|
32882
32802
|
} from "viem";
|
|
32883
32803
|
import { z } from "zod";
|
|
@@ -32957,7 +32877,7 @@ function isDataPointId(value) {
|
|
|
32957
32877
|
return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
|
|
32958
32878
|
}
|
|
32959
32879
|
function deriveDataPointId(ownerAddress, scope) {
|
|
32960
|
-
if (!
|
|
32880
|
+
if (!isAddress4(ownerAddress, { strict: false })) {
|
|
32961
32881
|
throw new Error(
|
|
32962
32882
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
32963
32883
|
);
|
|
@@ -33208,7 +33128,7 @@ function tombstoneDeletedAt(value) {
|
|
|
33208
33128
|
return typeof deletedAt === "string" ? deletedAt : null;
|
|
33209
33129
|
}
|
|
33210
33130
|
function assertAddress4(value, name) {
|
|
33211
|
-
if (!
|
|
33131
|
+
if (!isAddress5(value)) {
|
|
33212
33132
|
throw new Error(`${name} must be a valid EVM address`);
|
|
33213
33133
|
}
|
|
33214
33134
|
}
|
|
@@ -33624,7 +33544,7 @@ function tryGrantPermissions(scopes) {
|
|
|
33624
33544
|
|
|
33625
33545
|
// src/protocol/personal-server-write.ts
|
|
33626
33546
|
import { sha256 as sha2567 } from "@noble/hashes/sha2";
|
|
33627
|
-
import { bytesToHex as bytesToHex4, isAddress as
|
|
33547
|
+
import { bytesToHex as bytesToHex4, isAddress as isAddress6 } from "viem";
|
|
33628
33548
|
import { z as z4 } from "zod";
|
|
33629
33549
|
|
|
33630
33550
|
// src/protocol/write-request.ts
|
|
@@ -33946,7 +33866,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
33946
33866
|
for (const entry of lineage) {
|
|
33947
33867
|
let id;
|
|
33948
33868
|
if (isLineagePair(entry)) {
|
|
33949
|
-
if (!
|
|
33869
|
+
if (!isAddress6(entry.ownerAddress, { strict: false })) {
|
|
33950
33870
|
throw new WriteRequestError(
|
|
33951
33871
|
"lineage source ownerAddress must be an EVM address",
|
|
33952
33872
|
{ ownerAddress: entry.ownerAddress }
|
|
@@ -35242,7 +35162,6 @@ function createGatewayClient(baseUrl) {
|
|
|
35242
35162
|
}
|
|
35243
35163
|
|
|
35244
35164
|
// src/protocol/escrow.ts
|
|
35245
|
-
import { isHex as isHex2 } from "viem";
|
|
35246
35165
|
var GENERIC_PAYMENT_TYPES = {
|
|
35247
35166
|
GenericPayment: [
|
|
35248
35167
|
{ name: "payerAddress", type: "address" },
|
|
@@ -35282,26 +35201,6 @@ var ESCROW_DEPOSIT_ABI2 = [
|
|
|
35282
35201
|
}
|
|
35283
35202
|
];
|
|
35284
35203
|
var NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
35285
|
-
var EscrowWithdrawalLifecycleError = class extends Error {
|
|
35286
|
-
constructor(httpStatus, result) {
|
|
35287
|
-
super(result.error);
|
|
35288
|
-
this.httpStatus = httpStatus;
|
|
35289
|
-
this.result = result;
|
|
35290
|
-
}
|
|
35291
|
-
httpStatus;
|
|
35292
|
-
result;
|
|
35293
|
-
name = "EscrowWithdrawalLifecycleError";
|
|
35294
|
-
};
|
|
35295
|
-
var EscrowWithdrawalRejectionError = class extends Error {
|
|
35296
|
-
constructor(httpStatus, result) {
|
|
35297
|
-
super(result.error);
|
|
35298
|
-
this.httpStatus = httpStatus;
|
|
35299
|
-
this.result = result;
|
|
35300
|
-
}
|
|
35301
|
-
httpStatus;
|
|
35302
|
-
result;
|
|
35303
|
-
name = "EscrowWithdrawalRejectionError";
|
|
35304
|
-
};
|
|
35305
35204
|
function createEscrowGatewayClient(baseUrl) {
|
|
35306
35205
|
const base = baseUrl.replace(/\/+$/, "");
|
|
35307
35206
|
async function throwOnError(res, context) {
|
|
@@ -35317,27 +35216,6 @@ function createEscrowGatewayClient(baseUrl) {
|
|
|
35317
35216
|
);
|
|
35318
35217
|
}
|
|
35319
35218
|
}
|
|
35320
|
-
async function throwOnWithdrawError(res) {
|
|
35321
|
-
if (res.ok) return;
|
|
35322
|
-
let body;
|
|
35323
|
-
try {
|
|
35324
|
-
body = await res.json();
|
|
35325
|
-
} catch {
|
|
35326
|
-
throw new Error(
|
|
35327
|
-
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}`
|
|
35328
|
-
);
|
|
35329
|
-
}
|
|
35330
|
-
if (isEscrowWithdrawalFailureResult(body)) {
|
|
35331
|
-
throw new EscrowWithdrawalLifecycleError(res.status, body);
|
|
35332
|
-
}
|
|
35333
|
-
if (isEscrowWithdrawalRejectedResult(body)) {
|
|
35334
|
-
throw new EscrowWithdrawalRejectionError(res.status, body);
|
|
35335
|
-
}
|
|
35336
|
-
const error = getGatewayErrorMessage(body);
|
|
35337
|
-
throw new Error(
|
|
35338
|
-
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}${error ? `: ${error}` : ""}`
|
|
35339
|
-
);
|
|
35340
|
-
}
|
|
35341
35219
|
return {
|
|
35342
35220
|
async submitDeposit({ txHash }) {
|
|
35343
35221
|
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
@@ -35393,108 +35271,9 @@ function createEscrowGatewayClient(baseUrl) {
|
|
|
35393
35271
|
});
|
|
35394
35272
|
await throwOnError(res, "POST /v1/escrow/pay");
|
|
35395
35273
|
return res.json();
|
|
35396
|
-
},
|
|
35397
|
-
async withdraw({
|
|
35398
|
-
account,
|
|
35399
|
-
asset,
|
|
35400
|
-
amount,
|
|
35401
|
-
withdrawNonce,
|
|
35402
|
-
deadline,
|
|
35403
|
-
signature
|
|
35404
|
-
}) {
|
|
35405
|
-
const res = await fetch(`${base}/v1/escrow/withdraw`, {
|
|
35406
|
-
method: "POST",
|
|
35407
|
-
headers: {
|
|
35408
|
-
"Content-Type": "application/json",
|
|
35409
|
-
Authorization: `Web3Signed ${signature}`
|
|
35410
|
-
},
|
|
35411
|
-
body: JSON.stringify({
|
|
35412
|
-
account,
|
|
35413
|
-
asset,
|
|
35414
|
-
amount,
|
|
35415
|
-
withdrawNonce,
|
|
35416
|
-
deadline
|
|
35417
|
-
})
|
|
35418
|
-
});
|
|
35419
|
-
await throwOnWithdrawError(res);
|
|
35420
|
-
return res.json();
|
|
35421
|
-
},
|
|
35422
|
-
async getWithdrawNonce(account) {
|
|
35423
|
-
const res = await fetch(
|
|
35424
|
-
`${base}/v1/escrow/withdraw/nonce?account=${encodeURIComponent(account)}`,
|
|
35425
|
-
{ cache: "no-store" }
|
|
35426
|
-
);
|
|
35427
|
-
await throwOnError(res, "GET /v1/escrow/withdraw/nonce");
|
|
35428
|
-
const body = await res.json();
|
|
35429
|
-
if (!isWithdrawNonceResponse(body, account)) {
|
|
35430
|
-
throw new Error(
|
|
35431
|
-
"GET /v1/escrow/withdraw/nonce: invalid response structure"
|
|
35432
|
-
);
|
|
35433
|
-
}
|
|
35434
|
-
return body;
|
|
35435
35274
|
}
|
|
35436
35275
|
};
|
|
35437
35276
|
}
|
|
35438
|
-
function getGatewayErrorMessage(body) {
|
|
35439
|
-
if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
|
|
35440
|
-
return body.error;
|
|
35441
|
-
}
|
|
35442
|
-
return void 0;
|
|
35443
|
-
}
|
|
35444
|
-
function isEscrowWithdrawalFailureResult(body) {
|
|
35445
|
-
if (typeof body !== "object" || body === null) return false;
|
|
35446
|
-
const value = body;
|
|
35447
|
-
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));
|
|
35448
|
-
}
|
|
35449
|
-
function isEscrowWithdrawalRejectedResult(body) {
|
|
35450
|
-
if (typeof body !== "object" || body === null) return false;
|
|
35451
|
-
const value = body;
|
|
35452
|
-
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);
|
|
35453
|
-
}
|
|
35454
|
-
function isWithdrawalRejectionCode(value) {
|
|
35455
|
-
return value === "below_minimum" || value === "deadline_too_far" || value === "expired" || value === "insufficient_available" || value === "stale_nonce";
|
|
35456
|
-
}
|
|
35457
|
-
function optionalUint256Decimal(value) {
|
|
35458
|
-
return value === void 0 || isUint256Decimal(value);
|
|
35459
|
-
}
|
|
35460
|
-
function isAddressHex(value) {
|
|
35461
|
-
return typeof value === "string" && isHex2(value, { strict: true }) && value.length === 42;
|
|
35462
|
-
}
|
|
35463
|
-
function isHash(value) {
|
|
35464
|
-
return typeof value === "string" && isHex2(value, { strict: true }) && value.length === 66;
|
|
35465
|
-
}
|
|
35466
|
-
function isUint256Decimal(value) {
|
|
35467
|
-
if (typeof value !== "string" || value.length === 0 || value.length > 78) {
|
|
35468
|
-
return false;
|
|
35469
|
-
}
|
|
35470
|
-
if (!/^(0|[1-9]\d*)$/.test(value)) return false;
|
|
35471
|
-
return BigInt(value) <= 2n ** 256n - 1n;
|
|
35472
|
-
}
|
|
35473
|
-
function isBlockNumber(value) {
|
|
35474
|
-
return value === null || isUint256Decimal(value);
|
|
35475
|
-
}
|
|
35476
|
-
function isWithdrawNonceResponse(body, requestedAccount) {
|
|
35477
|
-
if (typeof body !== "object" || body === null) return false;
|
|
35478
|
-
const value = body;
|
|
35479
|
-
if (value.success !== true) return false;
|
|
35480
|
-
if (!isAddressHex(value.account)) return false;
|
|
35481
|
-
if (value.account.toLowerCase() !== requestedAccount.toLowerCase())
|
|
35482
|
-
return false;
|
|
35483
|
-
if (typeof value.chainId !== "string") return false;
|
|
35484
|
-
if (!/^(0|[1-9]\d*)$/.test(value.chainId)) return false;
|
|
35485
|
-
const isLastNull = value.lastWithdrawNonce === null;
|
|
35486
|
-
const lastNonceValid = isLastNull || isUint256Decimal(value.lastWithdrawNonce);
|
|
35487
|
-
if (!lastNonceValid) return false;
|
|
35488
|
-
if (!isUint256Decimal(value.nextWithdrawNonce)) return false;
|
|
35489
|
-
if (isLastNull) {
|
|
35490
|
-
return value.nextWithdrawNonce === "1";
|
|
35491
|
-
}
|
|
35492
|
-
const lastNonce = BigInt(value.lastWithdrawNonce);
|
|
35493
|
-
const nextNonce = BigInt(value.nextWithdrawNonce);
|
|
35494
|
-
const expectedNextNonce = lastNonce + 1n;
|
|
35495
|
-
if (expectedNextNonce > 2n ** 256n - 1n) return false;
|
|
35496
|
-
return nextNonce === expectedNextNonce;
|
|
35497
|
-
}
|
|
35498
35277
|
|
|
35499
35278
|
// src/types/ps-errors.ts
|
|
35500
35279
|
var PSError = class extends Error {
|
|
@@ -35605,8 +35384,6 @@ export {
|
|
|
35605
35384
|
ENCLAVE_TRUST_ANCHORS,
|
|
35606
35385
|
ENCLAVE_WALLET_PURPOSE,
|
|
35607
35386
|
ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
|
|
35608
|
-
EscrowWithdrawalLifecycleError,
|
|
35609
|
-
EscrowWithdrawalRejectionError,
|
|
35610
35387
|
ExpiredTokenError,
|
|
35611
35388
|
FEE_REGISTRY_ABI,
|
|
35612
35389
|
GENERIC_PAYMENT_TYPES,
|
|
@@ -35689,7 +35466,6 @@ export {
|
|
|
35689
35466
|
UserRejectedRequestError,
|
|
35690
35467
|
VanaError,
|
|
35691
35468
|
VanaStorage,
|
|
35692
|
-
WITHDRAW_AUTHORIZATION_TYPES,
|
|
35693
35469
|
WRITER_ATTRIBUTION_KEY,
|
|
35694
35470
|
WRITE_CONTENT_DISPOSITION_HEADER,
|
|
35695
35471
|
WRITE_FILENAME_HEADER,
|
|
@@ -35723,7 +35499,6 @@ export {
|
|
|
35723
35499
|
buildPersonalServerRegistrationTypedData,
|
|
35724
35500
|
buildSetDataPointStatusRequest,
|
|
35725
35501
|
buildWeb3SignedHeader,
|
|
35726
|
-
buildWithdrawAuthorizationTypedData,
|
|
35727
35502
|
builderRegistrationDomain,
|
|
35728
35503
|
canonicalJobRequestBytes,
|
|
35729
35504
|
chains,
|
|
@@ -35839,7 +35614,6 @@ export {
|
|
|
35839
35614
|
verifyWeb3Signed,
|
|
35840
35615
|
waitForDerivativeStatus,
|
|
35841
35616
|
waitForQuestion,
|
|
35842
|
-
withdrawAuthorizationDomain,
|
|
35843
35617
|
writeData,
|
|
35844
35618
|
writePersonalServerData
|
|
35845
35619
|
};
|