@opendatalabs/vana-sdk 4.0.0 → 4.2.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/errors.cjs +2 -2
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +7 -1
- package/dist/errors.js +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/index.browser.d.ts +1 -1
- package/dist/index.browser.js +7 -8
- package/dist/index.browser.js.map +2 -2
- package/dist/index.node.cjs +865 -442
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +919 -494
- package/dist/index.node.js.map +4 -4
- package/dist/protocol/identity.cjs +7 -8
- package/dist/protocol/identity.cjs.map +1 -1
- package/dist/protocol/identity.js +7 -8
- package/dist/protocol/identity.js.map +1 -1
- package/dist/protocol/jobs-client.cjs +196 -25
- package/dist/protocol/jobs-client.cjs.map +1 -1
- package/dist/protocol/jobs-client.d.ts +39 -1
- package/dist/protocol/jobs-client.js +199 -26
- package/dist/protocol/jobs-client.js.map +1 -1
- package/dist/protocol/jobs.cjs.map +1 -1
- package/dist/protocol/jobs.d.ts +71 -1
- package/dist/protocol/jobs.js.map +1 -1
- package/package.json +1 -1
package/dist/index.node.cjs
CHANGED
|
@@ -1205,10 +1205,10 @@ __export(index_node_exports, {
|
|
|
1205
1205
|
ENCLAVE_IDENTITY_EVIDENCE_VERSION: () => ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
1206
1206
|
ENCLAVE_TRUST_ANCHORS: () => ENCLAVE_TRUST_ANCHORS,
|
|
1207
1207
|
ENCLAVE_WALLET_PURPOSE: () => ENCLAVE_WALLET_PURPOSE,
|
|
1208
|
-
ESCROW_DEPOSIT_ABI: () =>
|
|
1208
|
+
ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI,
|
|
1209
1209
|
EscrowWithdrawalLifecycleError: () => EscrowWithdrawalLifecycleError,
|
|
1210
1210
|
EscrowWithdrawalRejectionError: () => EscrowWithdrawalRejectionError,
|
|
1211
|
-
ExpiredTokenError: () =>
|
|
1211
|
+
ExpiredTokenError: () => import_errors15.ExpiredTokenError,
|
|
1212
1212
|
FEE_REGISTRY_ABI: () => FEE_REGISTRY_ABI,
|
|
1213
1213
|
GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
|
|
1214
1214
|
GRANT_OP_TYPE: () => GRANT_OP_TYPE,
|
|
@@ -1218,7 +1218,7 @@ __export(index_node_exports, {
|
|
|
1218
1218
|
InMemoryTokenStore: () => InMemoryTokenStore,
|
|
1219
1219
|
IngestResponseSchema: () => IngestResponseSchema,
|
|
1220
1220
|
InvalidScopeEntryError: () => InvalidScopeEntryError,
|
|
1221
|
-
InvalidSignatureError: () =>
|
|
1221
|
+
InvalidSignatureError: () => import_errors15.InvalidSignatureError,
|
|
1222
1222
|
IpfsStorage: () => IpfsStorage,
|
|
1223
1223
|
JOB_OPERATIONS: () => JOB_OPERATIONS,
|
|
1224
1224
|
JOB_PROTOCOL_VERSION: () => JOB_PROTOCOL_VERSION,
|
|
@@ -1242,7 +1242,7 @@ __export(index_node_exports, {
|
|
|
1242
1242
|
MAX_QUESTION_MODEL_CHARS: () => MAX_QUESTION_MODEL_CHARS,
|
|
1243
1243
|
MAX_QUESTION_SOURCE_SCOPES: () => MAX_QUESTION_SOURCE_SCOPES,
|
|
1244
1244
|
MAX_WAIT_SECONDS: () => MAX_WAIT_SECONDS,
|
|
1245
|
-
MissingAuthError: () =>
|
|
1245
|
+
MissingAuthError: () => import_errors15.MissingAuthError,
|
|
1246
1246
|
NATIVE_ASSET_ADDRESS: () => NATIVE_ASSET_ADDRESS,
|
|
1247
1247
|
NATIVE_VANA_ASSET: () => NATIVE_VANA_ASSET,
|
|
1248
1248
|
NodeECIESProvider: () => NodeECIESUint8Provider,
|
|
@@ -31922,7 +31922,7 @@ async function verifyWeb3Signed(params) {
|
|
|
31922
31922
|
}
|
|
31923
31923
|
|
|
31924
31924
|
// src/index.node.ts
|
|
31925
|
-
var
|
|
31925
|
+
var import_errors15 = require("./auth/errors.cjs");
|
|
31926
31926
|
|
|
31927
31927
|
// src/auth/pkce.ts
|
|
31928
31928
|
var PKCE_VERIFIER_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
@@ -32380,15 +32380,14 @@ var PREIMAGE_SEPARATOR = ":";
|
|
|
32380
32380
|
var UNCOMPRESSED_PUBLIC_KEY_BYTES = 65;
|
|
32381
32381
|
var UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04";
|
|
32382
32382
|
var EMPTY_HEX = "0x";
|
|
32383
|
-
|
|
32384
|
-
|
|
32385
|
-
|
|
32386
|
-
|
|
32387
|
-
|
|
32388
|
-
}
|
|
32383
|
+
var MAINNET_ANCHOR = Object.freeze({
|
|
32384
|
+
kmsRootPubkey: "0x0434c76e0c3f52ec64cbf9bbf5c910c272330166fd656c0a86bb330963e46910e1a0e6fa51bec74be2f9129342707636060d85856d102cee8290185409ecf7422f",
|
|
32385
|
+
appIds: Object.freeze([
|
|
32386
|
+
"0x01bb1b6dcaf1ea170f1480c5e53b093f384d939a"
|
|
32387
|
+
])
|
|
32388
|
+
});
|
|
32389
32389
|
var ENCLAVE_TRUST_ANCHORS = Object.freeze({
|
|
32390
|
-
|
|
32391
|
-
[VANA_MAINNET_CHAIN_ID]: emptyAnchor(),
|
|
32390
|
+
[VANA_MAINNET_CHAIN_ID]: MAINNET_ANCHOR,
|
|
32392
32391
|
// Moksha workers share this dstack app and KMS root; the controller does not derive owner keys.
|
|
32393
32392
|
[MOKSHA_CHAIN_ID]: Object.freeze({
|
|
32394
32393
|
kmsRootPubkey: "0x0434c76e0c3f52ec64cbf9bbf5c910c272330166fd656c0a86bb330963e46910e1a0e6fa51bec74be2f9129342707636060d85856d102cee8290185409ecf7422f",
|
|
@@ -32548,7 +32547,7 @@ var MAX_JOB_DEADLINE_SECONDS = 3600;
|
|
|
32548
32547
|
// src/protocol/jobs-client.ts
|
|
32549
32548
|
var import_node_crypto = require("node:crypto");
|
|
32550
32549
|
var import_sha26 = require("@noble/hashes/sha2");
|
|
32551
|
-
var
|
|
32550
|
+
var import_viem17 = require("viem");
|
|
32552
32551
|
var import_accounts2 = require("viem/accounts");
|
|
32553
32552
|
|
|
32554
32553
|
// src/crypto/envelope/job.ts
|
|
@@ -33325,6 +33324,517 @@ async function openJobResult(sealedBytes, builderPrivateKey, ecies, expect) {
|
|
|
33325
33324
|
|
|
33326
33325
|
// src/protocol/jobs-client.ts
|
|
33327
33326
|
var import_errors3 = require("./errors.cjs");
|
|
33327
|
+
var import_errors4 = require("./direct/errors.cjs");
|
|
33328
|
+
|
|
33329
|
+
// src/config/contracts.config.ts
|
|
33330
|
+
var CONTRACTS2 = {
|
|
33331
|
+
// ========================================
|
|
33332
|
+
// DATA PORTABILITY CONTRACTS
|
|
33333
|
+
// ========================================
|
|
33334
|
+
DataPortabilityEscrow: {
|
|
33335
|
+
addresses: {
|
|
33336
|
+
14800: "0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3",
|
|
33337
|
+
1480: "0x07d7769081adc3a3DBe91f5E4B98E9A5a6B292e3"
|
|
33338
|
+
}
|
|
33339
|
+
},
|
|
33340
|
+
FeeRegistry: {
|
|
33341
|
+
addresses: {
|
|
33342
|
+
14800: "0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2",
|
|
33343
|
+
1480: "0xb4FA18443E0FA6cdC0280D20b8cCDB2377D13Bf2"
|
|
33344
|
+
}
|
|
33345
|
+
},
|
|
33346
|
+
// V2 deployment (DataPortabilityPermissionsV2Proxy). The gateway is the source
|
|
33347
|
+
// of truth for which deployment is live; verify with
|
|
33348
|
+
// `cast call <address> "eip712Domain()(bytes1,string,string,uint256,address,bytes32,uint256[])"`
|
|
33349
|
+
// which must return the domain name "Vana Data Portability".
|
|
33350
|
+
DataPortabilityPermissions: {
|
|
33351
|
+
addresses: {
|
|
33352
|
+
14800: "0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011",
|
|
33353
|
+
1480: "0x4d3FA76064D88e0454cFc4CaD7e5FeC3e3124011"
|
|
33354
|
+
}
|
|
33355
|
+
},
|
|
33356
|
+
// V2 deployment (DataPortabilityServersV2Proxy) on both chains.
|
|
33357
|
+
DataPortabilityServers: {
|
|
33358
|
+
addresses: {
|
|
33359
|
+
14800: "0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab",
|
|
33360
|
+
1480: "0xCae2CE0e9caa6643ed28186cF57bd40Bd9E17Eab"
|
|
33361
|
+
}
|
|
33362
|
+
},
|
|
33363
|
+
DataPortabilityGrantees: {
|
|
33364
|
+
addresses: {
|
|
33365
|
+
14800: "0x8325C0A0948483EdA023A1A2Fd895e62C5131234",
|
|
33366
|
+
1480: "0x8325C0A0948483EdA023A1A2Fd895e62C5131234"
|
|
33367
|
+
}
|
|
33368
|
+
},
|
|
33369
|
+
DataRegistry: {
|
|
33370
|
+
addresses: {
|
|
33371
|
+
14800: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C",
|
|
33372
|
+
1480: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C"
|
|
33373
|
+
}
|
|
33374
|
+
},
|
|
33375
|
+
// ========================================
|
|
33376
|
+
// COMPUTING INFRASTRUCTURE
|
|
33377
|
+
// ========================================
|
|
33378
|
+
ComputeEngine: {
|
|
33379
|
+
addresses: {
|
|
33380
|
+
14800: "0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd",
|
|
33381
|
+
1480: "0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd"
|
|
33382
|
+
}
|
|
33383
|
+
},
|
|
33384
|
+
ComputeEngineTreasury: {
|
|
33385
|
+
addresses: {
|
|
33386
|
+
14800: "0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1",
|
|
33387
|
+
1480: "0xceB33C501B624D984bD1Ed3298f6D1d8F7CE03d1"
|
|
33388
|
+
},
|
|
33389
|
+
discovery: {
|
|
33390
|
+
parent: "ComputeEngine",
|
|
33391
|
+
getter: "computeEngineTreasury"
|
|
33392
|
+
}
|
|
33393
|
+
},
|
|
33394
|
+
QueryEngine: {
|
|
33395
|
+
addresses: {
|
|
33396
|
+
14800: "0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490",
|
|
33397
|
+
1480: "0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490"
|
|
33398
|
+
}
|
|
33399
|
+
},
|
|
33400
|
+
VanaTreasury: {
|
|
33401
|
+
addresses: {
|
|
33402
|
+
14800: "0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9",
|
|
33403
|
+
1480: "0x8B32Ef32f22e72cc25D53f6E858f57cAe7E198f9"
|
|
33404
|
+
},
|
|
33405
|
+
discovery: {
|
|
33406
|
+
parent: "QueryEngine",
|
|
33407
|
+
getter: "queryEngineTreasury"
|
|
33408
|
+
}
|
|
33409
|
+
},
|
|
33410
|
+
DataRefinerRegistry: {
|
|
33411
|
+
addresses: {
|
|
33412
|
+
14800: "0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c",
|
|
33413
|
+
1480: "0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c"
|
|
33414
|
+
}
|
|
33415
|
+
},
|
|
33416
|
+
ComputeInstructionRegistry: {
|
|
33417
|
+
addresses: {
|
|
33418
|
+
14800: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5",
|
|
33419
|
+
1480: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5"
|
|
33420
|
+
}
|
|
33421
|
+
},
|
|
33422
|
+
// ========================================
|
|
33423
|
+
// TEE POOLS (Canonical Deployments)
|
|
33424
|
+
// ========================================
|
|
33425
|
+
TeePoolPhala: {
|
|
33426
|
+
addresses: {
|
|
33427
|
+
14800: "0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A",
|
|
33428
|
+
1480: "0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A"
|
|
33429
|
+
}
|
|
33430
|
+
},
|
|
33431
|
+
TeePoolEphemeralStandard: {
|
|
33432
|
+
addresses: {
|
|
33433
|
+
14800: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A",
|
|
33434
|
+
1480: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A"
|
|
33435
|
+
}
|
|
33436
|
+
},
|
|
33437
|
+
TeePoolPersistentStandard: {
|
|
33438
|
+
addresses: {
|
|
33439
|
+
14800: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76",
|
|
33440
|
+
1480: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76"
|
|
33441
|
+
}
|
|
33442
|
+
},
|
|
33443
|
+
TeePoolPersistentGpu: {
|
|
33444
|
+
addresses: {
|
|
33445
|
+
14800: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9",
|
|
33446
|
+
1480: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9"
|
|
33447
|
+
}
|
|
33448
|
+
},
|
|
33449
|
+
TeePoolDedicatedStandard: {
|
|
33450
|
+
addresses: {
|
|
33451
|
+
14800: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d",
|
|
33452
|
+
1480: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d"
|
|
33453
|
+
}
|
|
33454
|
+
},
|
|
33455
|
+
TeePoolDedicatedGpu: {
|
|
33456
|
+
addresses: {
|
|
33457
|
+
14800: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E",
|
|
33458
|
+
1480: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E"
|
|
33459
|
+
}
|
|
33460
|
+
},
|
|
33461
|
+
// ========================================
|
|
33462
|
+
// VANA EPOCH / DLP REGISTRY
|
|
33463
|
+
// ========================================
|
|
33464
|
+
// Note: DLP rewards-specific contracts (DLPPerformance, DLPRewardDeployer,
|
|
33465
|
+
// DLPRewardDeployerTreasury, DLPRewardSwap, SwapHelper) were removed in the
|
|
33466
|
+
// protocol unification cleanup. VanaEpoch, DLPRegistry, and DLPRegistryTreasury
|
|
33467
|
+
// are kept because they may be referenced beyond the rewards system.
|
|
33468
|
+
VanaEpoch: {
|
|
33469
|
+
addresses: {
|
|
33470
|
+
14800: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0",
|
|
33471
|
+
1480: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0"
|
|
33472
|
+
}
|
|
33473
|
+
},
|
|
33474
|
+
DLPRegistry: {
|
|
33475
|
+
addresses: {
|
|
33476
|
+
14800: "0x4D59880a924526d1dD33260552Ff4328b1E18a43",
|
|
33477
|
+
1480: "0x4D59880a924526d1dD33260552Ff4328b1E18a43"
|
|
33478
|
+
}
|
|
33479
|
+
},
|
|
33480
|
+
DLPRegistryTreasury: {
|
|
33481
|
+
addresses: {
|
|
33482
|
+
14800: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a",
|
|
33483
|
+
1480: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a"
|
|
33484
|
+
},
|
|
33485
|
+
discovery: {
|
|
33486
|
+
parent: "DLPRegistry",
|
|
33487
|
+
getter: "treasury"
|
|
33488
|
+
}
|
|
33489
|
+
},
|
|
33490
|
+
// ========================================
|
|
33491
|
+
// VANA POOL (STAKING)
|
|
33492
|
+
// ========================================
|
|
33493
|
+
VanaPoolStaking: {
|
|
33494
|
+
addresses: {
|
|
33495
|
+
14800: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e",
|
|
33496
|
+
1480: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e"
|
|
33497
|
+
}
|
|
33498
|
+
},
|
|
33499
|
+
VanaPoolTreasury: {
|
|
33500
|
+
addresses: {
|
|
33501
|
+
14800: "0x143BE72CF2541604A7691933CAccd6D9cC17c003",
|
|
33502
|
+
1480: "0x143BE72CF2541604A7691933CAccd6D9cC17c003"
|
|
33503
|
+
},
|
|
33504
|
+
discovery: {
|
|
33505
|
+
parent: "VanaPoolStaking",
|
|
33506
|
+
getter: "vanaPoolTreasury"
|
|
33507
|
+
}
|
|
33508
|
+
},
|
|
33509
|
+
VanaPoolEntity: {
|
|
33510
|
+
addresses: {
|
|
33511
|
+
14800: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30",
|
|
33512
|
+
1480: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30"
|
|
33513
|
+
},
|
|
33514
|
+
discovery: {
|
|
33515
|
+
parent: "VanaPoolStaking",
|
|
33516
|
+
getter: "vanaPoolEntity"
|
|
33517
|
+
}
|
|
33518
|
+
},
|
|
33519
|
+
// ========================================
|
|
33520
|
+
// DLP DEPLOYMENT & TOKEN SYSTEM
|
|
33521
|
+
// ========================================
|
|
33522
|
+
DATFactory: {
|
|
33523
|
+
addresses: {
|
|
33524
|
+
14800: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644",
|
|
33525
|
+
1480: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644"
|
|
33526
|
+
}
|
|
33527
|
+
},
|
|
33528
|
+
DAT: {
|
|
33529
|
+
addresses: {
|
|
33530
|
+
14800: "0xA706b93ccED89f13340673889e29F0a5cd84212d",
|
|
33531
|
+
1480: "0xA706b93ccED89f13340673889e29F0a5cd84212d"
|
|
33532
|
+
}
|
|
33533
|
+
},
|
|
33534
|
+
DATPausable: {
|
|
33535
|
+
addresses: {
|
|
33536
|
+
14800: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e",
|
|
33537
|
+
1480: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e"
|
|
33538
|
+
}
|
|
33539
|
+
},
|
|
33540
|
+
DATVotes: {
|
|
33541
|
+
addresses: {
|
|
33542
|
+
14800: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831",
|
|
33543
|
+
1480: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831"
|
|
33544
|
+
}
|
|
33545
|
+
},
|
|
33546
|
+
// ========================================
|
|
33547
|
+
// EXTERNAL DEPENDENCIES (DeFi)
|
|
33548
|
+
// ========================================
|
|
33549
|
+
WVANA: {
|
|
33550
|
+
addresses: {
|
|
33551
|
+
14800: "0xbccc4b4c6530F82FE309c5E845E50b5E9C89f2AD",
|
|
33552
|
+
1480: "0x00EDdD9621Fb08436d0331c149D1690909a5906d"
|
|
33553
|
+
}
|
|
33554
|
+
},
|
|
33555
|
+
UniswapV3NonfungiblePositionManager: {
|
|
33556
|
+
addresses: {
|
|
33557
|
+
14800: "0x48Bd633f4B9128a38Ebb4a48b6975EB3Eaf1931b",
|
|
33558
|
+
1480: "0x45a2992e1bFdCF9b9AcE0a84A238f2E56F481816"
|
|
33559
|
+
}
|
|
33560
|
+
},
|
|
33561
|
+
UniswapV3QuoterV2: {
|
|
33562
|
+
addresses: {
|
|
33563
|
+
14800: "0x3152246f3CD4dD465292Dd4Ffd792E2Cf602e332",
|
|
33564
|
+
1480: "0x1b13728ea3C90863990aC0e05987CfeC1888908c"
|
|
33565
|
+
}
|
|
33566
|
+
},
|
|
33567
|
+
// ========================================
|
|
33568
|
+
// UTILITY CONTRACTS
|
|
33569
|
+
// ========================================
|
|
33570
|
+
Multicall3: {
|
|
33571
|
+
addresses: {
|
|
33572
|
+
14800: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E",
|
|
33573
|
+
1480: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E"
|
|
33574
|
+
}
|
|
33575
|
+
},
|
|
33576
|
+
Multisend: {
|
|
33577
|
+
addresses: {
|
|
33578
|
+
14800: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d",
|
|
33579
|
+
1480: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d"
|
|
33580
|
+
}
|
|
33581
|
+
}
|
|
33582
|
+
};
|
|
33583
|
+
|
|
33584
|
+
// src/protocol/escrow.ts
|
|
33585
|
+
var import_viem16 = require("viem");
|
|
33586
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
33587
|
+
GenericPayment: [
|
|
33588
|
+
{ name: "payerAddress", type: "address" },
|
|
33589
|
+
{ name: "opType", type: "string" },
|
|
33590
|
+
{ name: "opId", type: "bytes32" },
|
|
33591
|
+
{ name: "asset", type: "address" },
|
|
33592
|
+
{ name: "amount", type: "uint256" },
|
|
33593
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
33594
|
+
]
|
|
33595
|
+
};
|
|
33596
|
+
function genericPaymentDomain(chainId, escrowContract) {
|
|
33597
|
+
return {
|
|
33598
|
+
name: "Vana Data Portability",
|
|
33599
|
+
version: "1",
|
|
33600
|
+
chainId,
|
|
33601
|
+
verifyingContract: escrowContract
|
|
33602
|
+
};
|
|
33603
|
+
}
|
|
33604
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
33605
|
+
{
|
|
33606
|
+
type: "function",
|
|
33607
|
+
name: "depositNative",
|
|
33608
|
+
stateMutability: "payable",
|
|
33609
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33610
|
+
outputs: []
|
|
33611
|
+
},
|
|
33612
|
+
{
|
|
33613
|
+
type: "function",
|
|
33614
|
+
name: "depositToken",
|
|
33615
|
+
stateMutability: "nonpayable",
|
|
33616
|
+
inputs: [
|
|
33617
|
+
{ name: "account", type: "address" },
|
|
33618
|
+
{ name: "token", type: "address" },
|
|
33619
|
+
{ name: "amount", type: "uint256" }
|
|
33620
|
+
],
|
|
33621
|
+
outputs: []
|
|
33622
|
+
}
|
|
33623
|
+
];
|
|
33624
|
+
var NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
33625
|
+
var EscrowWithdrawalLifecycleError = class extends Error {
|
|
33626
|
+
constructor(httpStatus, result) {
|
|
33627
|
+
super(result.error);
|
|
33628
|
+
this.httpStatus = httpStatus;
|
|
33629
|
+
this.result = result;
|
|
33630
|
+
}
|
|
33631
|
+
httpStatus;
|
|
33632
|
+
result;
|
|
33633
|
+
name = "EscrowWithdrawalLifecycleError";
|
|
33634
|
+
};
|
|
33635
|
+
var EscrowWithdrawalRejectionError = class extends Error {
|
|
33636
|
+
constructor(httpStatus, result) {
|
|
33637
|
+
super(result.error);
|
|
33638
|
+
this.httpStatus = httpStatus;
|
|
33639
|
+
this.result = result;
|
|
33640
|
+
}
|
|
33641
|
+
httpStatus;
|
|
33642
|
+
result;
|
|
33643
|
+
name = "EscrowWithdrawalRejectionError";
|
|
33644
|
+
};
|
|
33645
|
+
function createEscrowGatewayClient(baseUrl) {
|
|
33646
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
33647
|
+
async function throwOnError(res, context) {
|
|
33648
|
+
if (!res.ok) {
|
|
33649
|
+
let detail = "";
|
|
33650
|
+
try {
|
|
33651
|
+
const body = await res.json();
|
|
33652
|
+
if (body.error) detail = `: ${body.error}`;
|
|
33653
|
+
} catch {
|
|
33654
|
+
}
|
|
33655
|
+
throw new Error(
|
|
33656
|
+
`Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`
|
|
33657
|
+
);
|
|
33658
|
+
}
|
|
33659
|
+
}
|
|
33660
|
+
async function throwOnWithdrawError(res) {
|
|
33661
|
+
if (res.ok) return;
|
|
33662
|
+
let body;
|
|
33663
|
+
try {
|
|
33664
|
+
body = await res.json();
|
|
33665
|
+
} catch {
|
|
33666
|
+
throw new Error(
|
|
33667
|
+
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}`
|
|
33668
|
+
);
|
|
33669
|
+
}
|
|
33670
|
+
if (isEscrowWithdrawalFailureResult(body)) {
|
|
33671
|
+
throw new EscrowWithdrawalLifecycleError(res.status, body);
|
|
33672
|
+
}
|
|
33673
|
+
if (isEscrowWithdrawalRejectedResult(body)) {
|
|
33674
|
+
throw new EscrowWithdrawalRejectionError(res.status, body);
|
|
33675
|
+
}
|
|
33676
|
+
const error = getGatewayErrorMessage(body);
|
|
33677
|
+
throw new Error(
|
|
33678
|
+
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}${error ? `: ${error}` : ""}`
|
|
33679
|
+
);
|
|
33680
|
+
}
|
|
33681
|
+
return {
|
|
33682
|
+
async submitDeposit({ txHash }) {
|
|
33683
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33684
|
+
method: "POST",
|
|
33685
|
+
headers: { "Content-Type": "application/json" },
|
|
33686
|
+
body: JSON.stringify({ txHash })
|
|
33687
|
+
});
|
|
33688
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33689
|
+
await throwOnError(res, "POST /v1/escrow/deposit");
|
|
33690
|
+
}
|
|
33691
|
+
return res.json();
|
|
33692
|
+
},
|
|
33693
|
+
async getEscrowBalance(account) {
|
|
33694
|
+
const res = await fetch(
|
|
33695
|
+
`${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`
|
|
33696
|
+
);
|
|
33697
|
+
await throwOnError(res, "GET /v1/escrow/balance");
|
|
33698
|
+
return res.json();
|
|
33699
|
+
},
|
|
33700
|
+
async syncEscrowBalance(account) {
|
|
33701
|
+
const res = await fetch(
|
|
33702
|
+
`${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,
|
|
33703
|
+
{ method: "POST" }
|
|
33704
|
+
);
|
|
33705
|
+
await throwOnError(res, "POST /v1/escrow/balance/sync");
|
|
33706
|
+
return res.json();
|
|
33707
|
+
},
|
|
33708
|
+
async payForOp({
|
|
33709
|
+
payerAddress,
|
|
33710
|
+
opType,
|
|
33711
|
+
opId,
|
|
33712
|
+
asset,
|
|
33713
|
+
amount,
|
|
33714
|
+
paymentNonce,
|
|
33715
|
+
signature,
|
|
33716
|
+
accessRecord
|
|
33717
|
+
}) {
|
|
33718
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33719
|
+
method: "POST",
|
|
33720
|
+
headers: {
|
|
33721
|
+
"Content-Type": "application/json",
|
|
33722
|
+
Authorization: `Web3Signed ${signature}`
|
|
33723
|
+
},
|
|
33724
|
+
body: JSON.stringify({
|
|
33725
|
+
payerAddress,
|
|
33726
|
+
opType,
|
|
33727
|
+
opId,
|
|
33728
|
+
asset,
|
|
33729
|
+
amount,
|
|
33730
|
+
paymentNonce,
|
|
33731
|
+
...accessRecord ? { accessRecord } : {}
|
|
33732
|
+
})
|
|
33733
|
+
});
|
|
33734
|
+
await throwOnError(res, "POST /v1/escrow/pay");
|
|
33735
|
+
return res.json();
|
|
33736
|
+
},
|
|
33737
|
+
async withdraw({
|
|
33738
|
+
account,
|
|
33739
|
+
asset,
|
|
33740
|
+
amount,
|
|
33741
|
+
withdrawNonce,
|
|
33742
|
+
deadline,
|
|
33743
|
+
signature
|
|
33744
|
+
}) {
|
|
33745
|
+
const res = await fetch(`${base}/v1/escrow/withdraw`, {
|
|
33746
|
+
method: "POST",
|
|
33747
|
+
headers: {
|
|
33748
|
+
"Content-Type": "application/json",
|
|
33749
|
+
Authorization: `Web3Signed ${signature}`
|
|
33750
|
+
},
|
|
33751
|
+
body: JSON.stringify({
|
|
33752
|
+
account,
|
|
33753
|
+
asset,
|
|
33754
|
+
amount,
|
|
33755
|
+
withdrawNonce,
|
|
33756
|
+
deadline
|
|
33757
|
+
})
|
|
33758
|
+
});
|
|
33759
|
+
await throwOnWithdrawError(res);
|
|
33760
|
+
return res.json();
|
|
33761
|
+
},
|
|
33762
|
+
async getWithdrawNonce(account) {
|
|
33763
|
+
const res = await fetch(
|
|
33764
|
+
`${base}/v1/escrow/withdraw/nonce?account=${encodeURIComponent(account)}`,
|
|
33765
|
+
{ cache: "no-store" }
|
|
33766
|
+
);
|
|
33767
|
+
await throwOnError(res, "GET /v1/escrow/withdraw/nonce");
|
|
33768
|
+
const body = await res.json();
|
|
33769
|
+
if (!isWithdrawNonceResponse(body, account)) {
|
|
33770
|
+
throw new Error(
|
|
33771
|
+
"GET /v1/escrow/withdraw/nonce: invalid response structure"
|
|
33772
|
+
);
|
|
33773
|
+
}
|
|
33774
|
+
return body;
|
|
33775
|
+
}
|
|
33776
|
+
};
|
|
33777
|
+
}
|
|
33778
|
+
function getGatewayErrorMessage(body) {
|
|
33779
|
+
if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
|
|
33780
|
+
return body.error;
|
|
33781
|
+
}
|
|
33782
|
+
return void 0;
|
|
33783
|
+
}
|
|
33784
|
+
function isEscrowWithdrawalFailureResult(body) {
|
|
33785
|
+
if (typeof body !== "object" || body === null) return false;
|
|
33786
|
+
const value = body;
|
|
33787
|
+
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));
|
|
33788
|
+
}
|
|
33789
|
+
function isEscrowWithdrawalRejectedResult(body) {
|
|
33790
|
+
if (typeof body !== "object" || body === null) return false;
|
|
33791
|
+
const value = body;
|
|
33792
|
+
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);
|
|
33793
|
+
}
|
|
33794
|
+
function isWithdrawalRejectionCode(value) {
|
|
33795
|
+
return value === "below_minimum" || value === "deadline_too_far" || value === "expired" || value === "insufficient_available" || value === "stale_nonce";
|
|
33796
|
+
}
|
|
33797
|
+
function optionalUint256Decimal(value) {
|
|
33798
|
+
return value === void 0 || isUint256Decimal(value);
|
|
33799
|
+
}
|
|
33800
|
+
function isAddressHex(value) {
|
|
33801
|
+
return typeof value === "string" && (0, import_viem16.isHex)(value, { strict: true }) && value.length === 42;
|
|
33802
|
+
}
|
|
33803
|
+
function isHash(value) {
|
|
33804
|
+
return typeof value === "string" && (0, import_viem16.isHex)(value, { strict: true }) && value.length === 66;
|
|
33805
|
+
}
|
|
33806
|
+
function isUint256Decimal(value) {
|
|
33807
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 78) {
|
|
33808
|
+
return false;
|
|
33809
|
+
}
|
|
33810
|
+
if (!/^(0|[1-9]\d*)$/.test(value)) return false;
|
|
33811
|
+
return BigInt(value) <= 2n ** 256n - 1n;
|
|
33812
|
+
}
|
|
33813
|
+
function isBlockNumber(value) {
|
|
33814
|
+
return value === null || isUint256Decimal(value);
|
|
33815
|
+
}
|
|
33816
|
+
function isWithdrawNonceResponse(body, requestedAccount) {
|
|
33817
|
+
if (typeof body !== "object" || body === null) return false;
|
|
33818
|
+
const value = body;
|
|
33819
|
+
if (value.success !== true) return false;
|
|
33820
|
+
if (!isAddressHex(value.account)) return false;
|
|
33821
|
+
if (value.account.toLowerCase() !== requestedAccount.toLowerCase())
|
|
33822
|
+
return false;
|
|
33823
|
+
if (typeof value.chainId !== "string") return false;
|
|
33824
|
+
if (!/^(0|[1-9]\d*)$/.test(value.chainId)) return false;
|
|
33825
|
+
const isLastNull = value.lastWithdrawNonce === null;
|
|
33826
|
+
const lastNonceValid = isLastNull || isUint256Decimal(value.lastWithdrawNonce);
|
|
33827
|
+
if (!lastNonceValid) return false;
|
|
33828
|
+
if (!isUint256Decimal(value.nextWithdrawNonce)) return false;
|
|
33829
|
+
if (isLastNull) {
|
|
33830
|
+
return value.nextWithdrawNonce === "1";
|
|
33831
|
+
}
|
|
33832
|
+
const lastNonce = BigInt(value.lastWithdrawNonce);
|
|
33833
|
+
const nextNonce = BigInt(value.nextWithdrawNonce);
|
|
33834
|
+
const expectedNextNonce = lastNonce + 1n;
|
|
33835
|
+
if (expectedNextNonce > 2n ** 256n - 1n) return false;
|
|
33836
|
+
return nextNonce === expectedNextNonce;
|
|
33837
|
+
}
|
|
33328
33838
|
|
|
33329
33839
|
// src/protocol/write-signer.ts
|
|
33330
33840
|
var import_errors2 = require("./errors.cjs");
|
|
@@ -33370,7 +33880,9 @@ function resolveWriteSigner(source, options = {}) {
|
|
|
33370
33880
|
// src/protocol/jobs-client.ts
|
|
33371
33881
|
var IDENTITY_PATH = "/v1/identity";
|
|
33372
33882
|
var JOBS_PATH = "/v1/jobs";
|
|
33883
|
+
var JOB_QUOTE_PATH = "/v1/jobs/quote";
|
|
33373
33884
|
var JOB_EXECUTE_PATH = "/v1/jobs/execute";
|
|
33885
|
+
var JOB_ACCESS_OP_TYPE = "job_access";
|
|
33374
33886
|
var AUTHORIZATION_HEADER = "Authorization";
|
|
33375
33887
|
var CONTENT_TYPE_HEADER = "Content-Type";
|
|
33376
33888
|
var JSON_CONTENT_TYPE = "application/json";
|
|
@@ -33384,7 +33896,11 @@ var HTTP_UNAUTHORIZED = 401;
|
|
|
33384
33896
|
var HTTP_FORBIDDEN = 403;
|
|
33385
33897
|
var HTTP_NOT_FOUND = 404;
|
|
33386
33898
|
var HTTP_CONFLICT = 409;
|
|
33899
|
+
var HTTP_PAYMENT_REQUIRED = 402;
|
|
33387
33900
|
var HTTP_PAYLOAD_TOO_LARGE = 413;
|
|
33901
|
+
var NONCE_TIMESTAMP_SHIFT = 32n;
|
|
33902
|
+
var UINT256_DECIMAL = /^(0|[1-9]\d*)$/;
|
|
33903
|
+
var POSITIVE_UINT256_DECIMAL = /^[1-9]\d*$/;
|
|
33388
33904
|
var MILLISECONDS_PER_SECOND = 1e3;
|
|
33389
33905
|
var DEFAULT_JOB_TIMEOUT_MS = 12e4;
|
|
33390
33906
|
var DEFAULT_JOB_POLL_MS = CLAIM_POLL_FLOOR_MS;
|
|
@@ -33467,11 +33983,17 @@ function resolveBuilder(options) {
|
|
|
33467
33983
|
"Builder signer must expose both address and publicKey"
|
|
33468
33984
|
);
|
|
33469
33985
|
}
|
|
33986
|
+
const typedDataSigner = source.signTypedData;
|
|
33470
33987
|
return {
|
|
33471
33988
|
builder: {
|
|
33472
33989
|
address: signer.address,
|
|
33473
33990
|
publicKey,
|
|
33474
|
-
signMessage: signer.signMessage
|
|
33991
|
+
signMessage: signer.signMessage,
|
|
33992
|
+
...typedDataSigner ? {
|
|
33993
|
+
signTypedData: typedDataSigner.bind(
|
|
33994
|
+
source
|
|
33995
|
+
)
|
|
33996
|
+
} : {}
|
|
33475
33997
|
},
|
|
33476
33998
|
...options.builderPrivateKey ? { privateKey: options.builderPrivateKey } : {}
|
|
33477
33999
|
};
|
|
@@ -33555,7 +34077,7 @@ function isResultHandle(value) {
|
|
|
33555
34077
|
function hasMatchingIdentityKey(value) {
|
|
33556
34078
|
const address = value["address"];
|
|
33557
34079
|
const publicKey = value["publicKey"];
|
|
33558
|
-
if (typeof address !== "string" || !(0,
|
|
34080
|
+
if (typeof address !== "string" || !(0, import_viem17.isAddress)(address) || typeof publicKey !== "string" || !(0, import_viem17.isHex)(publicKey)) {
|
|
33559
34081
|
return false;
|
|
33560
34082
|
}
|
|
33561
34083
|
try {
|
|
@@ -33568,14 +34090,59 @@ function hasExpectedIdentity(value, owner, chainId) {
|
|
|
33568
34090
|
const identityOwner = value["ownerAddress"];
|
|
33569
34091
|
const identityChainId = value["chainId"];
|
|
33570
34092
|
const identityUserPsId = value["userPsId"];
|
|
33571
|
-
if (!hasMatchingIdentityKey(value) || typeof identityOwner !== "string" || !(0,
|
|
34093
|
+
if (!hasMatchingIdentityKey(value) || typeof identityOwner !== "string" || !(0, import_viem17.isAddress)(identityOwner) || typeof identityChainId !== "number" || typeof identityUserPsId !== "string" || !(0, import_viem17.isHex)(identityUserPsId)) {
|
|
33572
34094
|
return false;
|
|
33573
34095
|
}
|
|
33574
|
-
return (0,
|
|
34096
|
+
return (0, import_viem17.isAddressEqual)(identityOwner, owner) && identityChainId === chainId && identityUserPsId.toLowerCase() === userPsId(chainId, owner).toLowerCase();
|
|
33575
34097
|
}
|
|
33576
34098
|
function sleep2(ms) {
|
|
33577
34099
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
33578
34100
|
}
|
|
34101
|
+
function resolveEscrowContract(options) {
|
|
34102
|
+
if (options.escrowContract) return options.escrowContract;
|
|
34103
|
+
const addresses = CONTRACTS2["DataPortabilityEscrow"]?.addresses;
|
|
34104
|
+
const address = addresses?.[options.chainId];
|
|
34105
|
+
if (!address || !(0, import_viem17.isAddress)(address)) {
|
|
34106
|
+
throw new import_errors3.JobRejectedError(
|
|
34107
|
+
`No DataPortabilityEscrow address for chain ${options.chainId}; pass escrowContract`
|
|
34108
|
+
);
|
|
34109
|
+
}
|
|
34110
|
+
return address;
|
|
34111
|
+
}
|
|
34112
|
+
function nextPaymentNonce() {
|
|
34113
|
+
const random = new Uint32Array(1);
|
|
34114
|
+
globalThis.crypto.getRandomValues(random);
|
|
34115
|
+
return (BigInt(Date.now()) << NONCE_TIMESTAMP_SHIFT) + BigInt(random[0] ?? 0);
|
|
34116
|
+
}
|
|
34117
|
+
function parseJobQuote(body) {
|
|
34118
|
+
if (!isRecord2(body)) return null;
|
|
34119
|
+
const { chainId, price, asset, payable, enforced } = body;
|
|
34120
|
+
if (typeof chainId !== "number" || !Number.isSafeInteger(chainId))
|
|
34121
|
+
return null;
|
|
34122
|
+
if (typeof price !== "string" || !UINT256_DECIMAL.test(price)) return null;
|
|
34123
|
+
if (typeof asset !== "string" || !(0, import_viem17.isAddress)(asset)) return null;
|
|
34124
|
+
if (typeof payable !== "boolean" || typeof enforced !== "boolean")
|
|
34125
|
+
return null;
|
|
34126
|
+
return { chainId, price, asset, payable, enforced };
|
|
34127
|
+
}
|
|
34128
|
+
async function paymentQuote(response) {
|
|
34129
|
+
const body = await responseBody(response);
|
|
34130
|
+
const asset = isRecord2(body) ? body["asset"] : void 0;
|
|
34131
|
+
const amount = isRecord2(body) ? body["amount"] : void 0;
|
|
34132
|
+
if (typeof asset !== "string" || !(0, import_viem17.isAddress)(asset) || typeof amount !== "string" || !POSITIVE_UINT256_DECIMAL.test(amount)) {
|
|
34133
|
+
throw new import_errors3.JobRejectedError(
|
|
34134
|
+
"Gateway asked for payment without a usable quote",
|
|
34135
|
+
response.status
|
|
34136
|
+
);
|
|
34137
|
+
}
|
|
34138
|
+
return { asset, amount };
|
|
34139
|
+
}
|
|
34140
|
+
async function paymentRefusal(response) {
|
|
34141
|
+
const body = await responseBody(response);
|
|
34142
|
+
const parsed = isRecord2(body) ? body : {};
|
|
34143
|
+
const message = typeof parsed["error"] === "string" ? parsed["error"] : "This read requires payment the builder escrow cannot back";
|
|
34144
|
+
return { message, details: parsed };
|
|
34145
|
+
}
|
|
33579
34146
|
function requireFiniteDuration(value, field) {
|
|
33580
34147
|
if (!Number.isFinite(value)) {
|
|
33581
34148
|
throw new import_errors3.JobRejectedError(`${field} must be a finite number`);
|
|
@@ -33588,6 +34155,73 @@ function createJobsClient(options) {
|
|
|
33588
34155
|
const { builder, privateKey } = resolveBuilder(options);
|
|
33589
34156
|
const ecies = options.ecies ?? new NodeECIESUint8Provider();
|
|
33590
34157
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
34158
|
+
async function signQuote(jobId, quote) {
|
|
34159
|
+
if (!builder.signTypedData) {
|
|
34160
|
+
throw new import_errors3.JobRejectedError(
|
|
34161
|
+
"This read is charged, but the builder signer cannot sign typed data"
|
|
34162
|
+
);
|
|
34163
|
+
}
|
|
34164
|
+
const paymentNonce = nextPaymentNonce();
|
|
34165
|
+
const signature = await builder.signTypedData({
|
|
34166
|
+
domain: genericPaymentDomain(
|
|
34167
|
+
options.chainId,
|
|
34168
|
+
resolveEscrowContract(options)
|
|
34169
|
+
),
|
|
34170
|
+
types: GENERIC_PAYMENT_TYPES,
|
|
34171
|
+
primaryType: "GenericPayment",
|
|
34172
|
+
message: {
|
|
34173
|
+
payerAddress: builder.address,
|
|
34174
|
+
opType: JOB_ACCESS_OP_TYPE,
|
|
34175
|
+
opId: (0, import_viem17.keccak256)((0, import_viem17.toHex)(jobId.toLowerCase())),
|
|
34176
|
+
asset: quote.asset,
|
|
34177
|
+
amount: BigInt(quote.amount),
|
|
34178
|
+
paymentNonce
|
|
34179
|
+
}
|
|
34180
|
+
});
|
|
34181
|
+
return {
|
|
34182
|
+
signature,
|
|
34183
|
+
amount: quote.amount,
|
|
34184
|
+
asset: quote.asset,
|
|
34185
|
+
paymentNonce: paymentNonce.toString()
|
|
34186
|
+
};
|
|
34187
|
+
}
|
|
34188
|
+
async function postSubmission(submission, wait) {
|
|
34189
|
+
const identifiers = {
|
|
34190
|
+
jobId: submission.jobId,
|
|
34191
|
+
idempotencyKey: submission.idempotencyKey
|
|
34192
|
+
};
|
|
34193
|
+
const bodyBytes = new TextEncoder().encode(JSON.stringify(submission));
|
|
34194
|
+
const authorization = await buildWeb3SignedHeader({
|
|
34195
|
+
signMessage: builder.signMessage,
|
|
34196
|
+
aud: audience,
|
|
34197
|
+
method: POST_METHOD,
|
|
34198
|
+
uri: JOBS_PATH,
|
|
34199
|
+
body: bodyBytes,
|
|
34200
|
+
nonce: (0, import_node_crypto.randomUUID)()
|
|
34201
|
+
});
|
|
34202
|
+
try {
|
|
34203
|
+
return await request(
|
|
34204
|
+
`${baseUrl}${JOBS_PATH}?wait=${wait}`,
|
|
34205
|
+
{
|
|
34206
|
+
method: POST_METHOD,
|
|
34207
|
+
headers: {
|
|
34208
|
+
[AUTHORIZATION_HEADER]: authorization,
|
|
34209
|
+
[CONTENT_TYPE_HEADER]: JSON_CONTENT_TYPE
|
|
34210
|
+
},
|
|
34211
|
+
body: bodyBytes
|
|
34212
|
+
},
|
|
34213
|
+
"Job submission"
|
|
34214
|
+
);
|
|
34215
|
+
} catch (error) {
|
|
34216
|
+
if (error instanceof import_errors3.JobTransportError) {
|
|
34217
|
+
throw new import_errors3.JobTransportError(error.message, error.cause, {
|
|
34218
|
+
...error.details,
|
|
34219
|
+
...identifiers
|
|
34220
|
+
});
|
|
34221
|
+
}
|
|
34222
|
+
throw error;
|
|
34223
|
+
}
|
|
34224
|
+
}
|
|
33591
34225
|
async function request(url, init, description) {
|
|
33592
34226
|
try {
|
|
33593
34227
|
return await fetchFn(url, init);
|
|
@@ -33643,7 +34277,8 @@ function createJobsClient(options) {
|
|
|
33643
34277
|
"deadlineSeconds"
|
|
33644
34278
|
);
|
|
33645
34279
|
const wait = clampInteger(params.wait, 0, 0, MAX_WAIT_SECONDS, "wait");
|
|
33646
|
-
const jobId = (0, import_node_crypto.randomUUID)();
|
|
34280
|
+
const jobId = params.jobId ?? (0, import_node_crypto.randomUUID)();
|
|
34281
|
+
const idempotencyKey = params.idempotencyKey ?? (0, import_node_crypto.randomUUID)();
|
|
33647
34282
|
const nowMs = now().getTime();
|
|
33648
34283
|
if (!Number.isFinite(nowMs)) {
|
|
33649
34284
|
throw new import_errors3.JobRejectedError("now must return a valid Date");
|
|
@@ -33681,32 +34316,41 @@ function createJobsClient(options) {
|
|
|
33681
34316
|
grantId: requestBody.grantId,
|
|
33682
34317
|
scope: requestBody.scope,
|
|
33683
34318
|
operation: requestBody.operation,
|
|
33684
|
-
idempotencyKey
|
|
34319
|
+
idempotencyKey,
|
|
33685
34320
|
jobId,
|
|
33686
34321
|
deadline,
|
|
33687
|
-
requestCiphertext
|
|
34322
|
+
requestCiphertext,
|
|
34323
|
+
...params.maxPrice === void 0 ? {} : { maxPrice: params.maxPrice }
|
|
33688
34324
|
};
|
|
33689
|
-
|
|
33690
|
-
|
|
33691
|
-
|
|
33692
|
-
|
|
33693
|
-
|
|
33694
|
-
|
|
33695
|
-
|
|
33696
|
-
|
|
33697
|
-
|
|
33698
|
-
|
|
33699
|
-
|
|
33700
|
-
|
|
33701
|
-
|
|
33702
|
-
|
|
33703
|
-
|
|
33704
|
-
|
|
33705
|
-
|
|
33706
|
-
|
|
33707
|
-
|
|
33708
|
-
|
|
33709
|
-
|
|
34325
|
+
let response = await postSubmission(submission, wait);
|
|
34326
|
+
if (response.status === HTTP_PAYMENT_REQUIRED) {
|
|
34327
|
+
const quote = await paymentQuote(response);
|
|
34328
|
+
if (params.maxPrice !== void 0 && BigInt(quote.amount) > BigInt(params.maxPrice)) {
|
|
34329
|
+
throw new import_errors4.PaymentRequiredError(
|
|
34330
|
+
"The quoted price is above the maxPrice you set for this read",
|
|
34331
|
+
{
|
|
34332
|
+
jobId,
|
|
34333
|
+
scope: params.scope,
|
|
34334
|
+
grantId: params.grantId,
|
|
34335
|
+
asset: quote.asset,
|
|
34336
|
+
amount: quote.amount,
|
|
34337
|
+
maxPrice: params.maxPrice
|
|
34338
|
+
}
|
|
34339
|
+
);
|
|
34340
|
+
}
|
|
34341
|
+
submission.payment = await signQuote(jobId, quote);
|
|
34342
|
+
submission.priceAsset = quote.asset;
|
|
34343
|
+
response = await postSubmission(submission, wait);
|
|
34344
|
+
if (response.status === HTTP_PAYMENT_REQUIRED) {
|
|
34345
|
+
const refusal = await paymentRefusal(response);
|
|
34346
|
+
throw new import_errors4.PaymentRequiredError(refusal.message, {
|
|
34347
|
+
jobId,
|
|
34348
|
+
scope: params.scope,
|
|
34349
|
+
grantId: params.grantId,
|
|
34350
|
+
...refusal.details
|
|
34351
|
+
});
|
|
34352
|
+
}
|
|
34353
|
+
}
|
|
33710
34354
|
if (!response.ok) {
|
|
33711
34355
|
throw await rejectedResponse(response, "Job submission rejected");
|
|
33712
34356
|
}
|
|
@@ -33729,6 +34373,40 @@ function createJobsClient(options) {
|
|
|
33729
34373
|
response.status
|
|
33730
34374
|
);
|
|
33731
34375
|
},
|
|
34376
|
+
async quoteJob() {
|
|
34377
|
+
const authorization = await buildWeb3SignedHeader({
|
|
34378
|
+
signMessage: builder.signMessage,
|
|
34379
|
+
aud: audience,
|
|
34380
|
+
method: GET_METHOD,
|
|
34381
|
+
uri: JOB_QUOTE_PATH,
|
|
34382
|
+
nonce: (0, import_node_crypto.randomUUID)()
|
|
34383
|
+
});
|
|
34384
|
+
const response = await request(
|
|
34385
|
+
`${baseUrl}${JOB_QUOTE_PATH}`,
|
|
34386
|
+
{
|
|
34387
|
+
method: GET_METHOD,
|
|
34388
|
+
headers: { [AUTHORIZATION_HEADER]: authorization }
|
|
34389
|
+
},
|
|
34390
|
+
"Job quote"
|
|
34391
|
+
);
|
|
34392
|
+
if (!response.ok) {
|
|
34393
|
+
throw await rejectedResponse(response, "Job quote rejected");
|
|
34394
|
+
}
|
|
34395
|
+
const quote = parseJobQuote(await responseBody(response));
|
|
34396
|
+
if (!quote) {
|
|
34397
|
+
throw new import_errors3.JobRejectedError(
|
|
34398
|
+
"Gateway returned an undocumented job quote",
|
|
34399
|
+
response.status
|
|
34400
|
+
);
|
|
34401
|
+
}
|
|
34402
|
+
if (quote.chainId !== options.chainId) {
|
|
34403
|
+
throw new import_errors3.JobRejectedError(
|
|
34404
|
+
`Gateway quoted chain ${quote.chainId}, not the configured ${options.chainId}`,
|
|
34405
|
+
response.status
|
|
34406
|
+
);
|
|
34407
|
+
}
|
|
34408
|
+
return quote;
|
|
34409
|
+
},
|
|
33732
34410
|
async getJob(jobId) {
|
|
33733
34411
|
const path = `${JOBS_PATH}/${encodeURIComponent(jobId)}`;
|
|
33734
34412
|
const authorization = await buildWeb3SignedHeader({
|
|
@@ -33820,7 +34498,7 @@ function createJobsClient(options) {
|
|
|
33820
34498
|
error
|
|
33821
34499
|
);
|
|
33822
34500
|
}
|
|
33823
|
-
const actualHash = (0,
|
|
34501
|
+
const actualHash = (0, import_viem17.bytesToHex)((0, import_sha26.sha256)(bytes));
|
|
33824
34502
|
if (actualHash.toLowerCase() !== handle.hash.toLowerCase()) {
|
|
33825
34503
|
throw new import_errors3.JobResultIntegrityError(
|
|
33826
34504
|
"Fetched job result hash does not match its handle",
|
|
@@ -33882,14 +34560,14 @@ function createJobsClient(options) {
|
|
|
33882
34560
|
}
|
|
33883
34561
|
|
|
33884
34562
|
// src/protocol/personal-server-registration.ts
|
|
33885
|
-
var
|
|
34563
|
+
var import_viem18 = require("viem");
|
|
33886
34564
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
33887
34565
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
33888
34566
|
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
33889
34567
|
"DataPortabilityServers"
|
|
33890
34568
|
);
|
|
33891
34569
|
function assertAddress(value, name) {
|
|
33892
|
-
if (!(0,
|
|
34570
|
+
if (!(0, import_viem18.isAddress)(value)) {
|
|
33893
34571
|
throw new Error(`${name} must be a valid EVM address`);
|
|
33894
34572
|
}
|
|
33895
34573
|
}
|
|
@@ -33975,12 +34653,12 @@ async function buildPersonalServerRegistrationSignature(input) {
|
|
|
33975
34653
|
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
33976
34654
|
|
|
33977
34655
|
// src/personal-server-lite/owner-binding.ts
|
|
33978
|
-
var
|
|
34656
|
+
var import_viem19 = require("viem");
|
|
33979
34657
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
33980
34658
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
33981
34659
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
33982
34660
|
function assertAddress2(value, name) {
|
|
33983
|
-
if (!(0,
|
|
34661
|
+
if (!(0, import_viem19.isAddress)(value)) {
|
|
33984
34662
|
throw new Error(`${name} must be a valid EVM address`);
|
|
33985
34663
|
}
|
|
33986
34664
|
}
|
|
@@ -34030,7 +34708,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
|
34030
34708
|
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
34031
34709
|
|
|
34032
34710
|
// src/account/personal-server-registration.ts
|
|
34033
|
-
var
|
|
34711
|
+
var import_viem20 = require("viem");
|
|
34034
34712
|
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
34035
34713
|
var AccountPersonalServerRegistrationError = class extends Error {
|
|
34036
34714
|
status;
|
|
@@ -34049,7 +34727,7 @@ function trimTrailingSlash(value) {
|
|
|
34049
34727
|
return value.replace(/\/+$/, "");
|
|
34050
34728
|
}
|
|
34051
34729
|
function assertAddress3(value, name) {
|
|
34052
|
-
if (!(0,
|
|
34730
|
+
if (!(0, import_viem20.isAddress)(value)) {
|
|
34053
34731
|
throw new Error(`${name} must be a valid EVM address`);
|
|
34054
34732
|
}
|
|
34055
34733
|
}
|
|
@@ -34313,7 +34991,7 @@ function accountOwnerBindingError(error) {
|
|
|
34313
34991
|
}
|
|
34314
34992
|
|
|
34315
34993
|
// src/protocol/grants.ts
|
|
34316
|
-
var
|
|
34994
|
+
var import_viem21 = require("viem");
|
|
34317
34995
|
function isHexString(value) {
|
|
34318
34996
|
return typeof value === "string" && value.startsWith("0x");
|
|
34319
34997
|
}
|
|
@@ -34358,7 +35036,7 @@ async function verifyGrantRegistration(input) {
|
|
|
34358
35036
|
}
|
|
34359
35037
|
let valid;
|
|
34360
35038
|
try {
|
|
34361
|
-
valid = await (0,
|
|
35039
|
+
valid = await (0, import_viem21.verifyTypedData)({
|
|
34362
35040
|
address: input.grantorAddress,
|
|
34363
35041
|
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
34364
35042
|
types: GRANT_REGISTRATION_TYPES,
|
|
@@ -34393,8 +35071,8 @@ async function verifyGrantRegistration(input) {
|
|
|
34393
35071
|
}
|
|
34394
35072
|
|
|
34395
35073
|
// src/protocol/fee-registry.ts
|
|
34396
|
-
var
|
|
34397
|
-
var FEE_REGISTRY_ABI = (0,
|
|
35074
|
+
var import_viem22 = require("viem");
|
|
35075
|
+
var FEE_REGISTRY_ABI = (0, import_viem22.parseAbi)([
|
|
34398
35076
|
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
34399
35077
|
"function fees(bytes32 operation) view returns (Fee)",
|
|
34400
35078
|
"function operationKey(string name) pure returns (bytes32)"
|
|
@@ -34477,8 +35155,8 @@ async function getOpFee(client, config, opType, opts) {
|
|
|
34477
35155
|
}
|
|
34478
35156
|
|
|
34479
35157
|
// src/protocol/escrow-deposit.ts
|
|
34480
|
-
var
|
|
34481
|
-
var
|
|
35158
|
+
var import_viem23 = require("viem");
|
|
35159
|
+
var ESCROW_DEPOSIT_ABI2 = [
|
|
34482
35160
|
{
|
|
34483
35161
|
type: "function",
|
|
34484
35162
|
name: "depositNative",
|
|
@@ -34502,15 +35180,15 @@ function escrowContractAddress(config) {
|
|
|
34502
35180
|
return config.contracts.dataPortabilityEscrow;
|
|
34503
35181
|
}
|
|
34504
35182
|
function encodeDepositNativeData(input) {
|
|
34505
|
-
return (0,
|
|
34506
|
-
abi:
|
|
35183
|
+
return (0, import_viem23.encodeFunctionData)({
|
|
35184
|
+
abi: ESCROW_DEPOSIT_ABI2,
|
|
34507
35185
|
functionName: "depositNative",
|
|
34508
35186
|
args: [input.account]
|
|
34509
35187
|
});
|
|
34510
35188
|
}
|
|
34511
35189
|
function encodeDepositTokenData(input) {
|
|
34512
|
-
return (0,
|
|
34513
|
-
abi:
|
|
35190
|
+
return (0, import_viem23.encodeFunctionData)({
|
|
35191
|
+
abi: ESCROW_DEPOSIT_ABI2,
|
|
34514
35192
|
functionName: "depositToken",
|
|
34515
35193
|
args: [input.account, input.token, input.amount]
|
|
34516
35194
|
});
|
|
@@ -34530,7 +35208,7 @@ function buildDepositTokenRequest(config, input) {
|
|
|
34530
35208
|
}
|
|
34531
35209
|
|
|
34532
35210
|
// src/protocol/data-point-status.ts
|
|
34533
|
-
var
|
|
35211
|
+
var import_viem24 = require("viem");
|
|
34534
35212
|
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
34535
35213
|
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
34536
35214
|
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
@@ -34554,7 +35232,7 @@ function dataRegistryContractAddress(config) {
|
|
|
34554
35232
|
return config.contracts.dataRegistry;
|
|
34555
35233
|
}
|
|
34556
35234
|
function encodeSetDataPointStatusData(input) {
|
|
34557
|
-
return (0,
|
|
35235
|
+
return (0, import_viem24.encodeFunctionData)({
|
|
34558
35236
|
abi: DATA_REGISTRY_STATUS_ABI,
|
|
34559
35237
|
functionName: "setStatus",
|
|
34560
35238
|
args: [input.scope, input.status]
|
|
@@ -34574,13 +35252,13 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
34574
35252
|
}
|
|
34575
35253
|
|
|
34576
35254
|
// src/protocol/data-point-deletion.ts
|
|
34577
|
-
var
|
|
34578
|
-
var
|
|
35255
|
+
var import_viem26 = require("viem");
|
|
35256
|
+
var import_errors6 = require("./errors.cjs");
|
|
34579
35257
|
|
|
34580
35258
|
// src/protocol/lineage.ts
|
|
34581
|
-
var
|
|
35259
|
+
var import_viem25 = require("viem");
|
|
34582
35260
|
var import_zod = require("zod");
|
|
34583
|
-
var
|
|
35261
|
+
var import_errors5 = require("./errors.cjs");
|
|
34584
35262
|
|
|
34585
35263
|
// src/protocol/personal-server-error-body.ts
|
|
34586
35264
|
function isRecord4(value) {
|
|
@@ -34617,13 +35295,13 @@ function isDataPointId(value) {
|
|
|
34617
35295
|
return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
|
|
34618
35296
|
}
|
|
34619
35297
|
function deriveDataPointId(ownerAddress, scope) {
|
|
34620
|
-
if (!(0,
|
|
35298
|
+
if (!(0, import_viem25.isAddress)(ownerAddress, { strict: false })) {
|
|
34621
35299
|
throw new Error(
|
|
34622
35300
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
34623
35301
|
);
|
|
34624
35302
|
}
|
|
34625
|
-
return (0,
|
|
34626
|
-
(0,
|
|
35303
|
+
return (0, import_viem25.keccak256)(
|
|
35304
|
+
(0, import_viem25.encodeAbiParameters)(
|
|
34627
35305
|
[
|
|
34628
35306
|
{ name: "ownerAddress", type: "address" },
|
|
34629
35307
|
{ name: "scope", type: "string" }
|
|
@@ -34652,7 +35330,7 @@ function derivedScopeViolatesNaming(derivedScope, sourceScope) {
|
|
|
34652
35330
|
function assertDerivedScopeNaming(derivedScope, sourceScopes) {
|
|
34653
35331
|
for (const sourceScope of sourceScopes) {
|
|
34654
35332
|
if (derivedScopeViolatesNaming(derivedScope, sourceScope)) {
|
|
34655
|
-
throw new
|
|
35333
|
+
throw new import_errors5.WriteRequestError(
|
|
34656
35334
|
`Derived scope ${derivedScope} must not share its first segment with source scope ${sourceScope}; put derivatives in the app's own namespace`,
|
|
34657
35335
|
{ scope: derivedScope, sourceScope }
|
|
34658
35336
|
);
|
|
@@ -34715,7 +35393,7 @@ function normalizeBaseUrl(url) {
|
|
|
34715
35393
|
function resolveFetch2(fetchFn) {
|
|
34716
35394
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
34717
35395
|
if (resolved === void 0) {
|
|
34718
|
-
throw new
|
|
35396
|
+
throw new import_errors5.LineageReadError("No fetch implementation available");
|
|
34719
35397
|
}
|
|
34720
35398
|
return resolved;
|
|
34721
35399
|
}
|
|
@@ -34723,7 +35401,7 @@ function normalizeVersion(version) {
|
|
|
34723
35401
|
if (version === void 0) return void 0;
|
|
34724
35402
|
const text = String(version);
|
|
34725
35403
|
if (!VERSION_PATTERN.test(text)) {
|
|
34726
|
-
throw new
|
|
35404
|
+
throw new import_errors5.LineageReadError(
|
|
34727
35405
|
"version must be a positive decimal integer",
|
|
34728
35406
|
void 0,
|
|
34729
35407
|
"INVALID_VERSION",
|
|
@@ -34734,7 +35412,7 @@ function normalizeVersion(version) {
|
|
|
34734
35412
|
}
|
|
34735
35413
|
async function lineageReadFailure(source, response) {
|
|
34736
35414
|
const { errorCode, message, details } = await readPersonalServerErrorBody(response);
|
|
34737
|
-
return new
|
|
35415
|
+
return new import_errors5.LineageReadError(
|
|
34738
35416
|
message ?? `${source} lineage read failed: ${response.status} ${response.statusText}`,
|
|
34739
35417
|
response.status,
|
|
34740
35418
|
errorCode,
|
|
@@ -34746,7 +35424,7 @@ async function parseLineageGraph(source, response) {
|
|
|
34746
35424
|
try {
|
|
34747
35425
|
body = await response.json();
|
|
34748
35426
|
} catch (err) {
|
|
34749
|
-
throw new
|
|
35427
|
+
throw new import_errors5.LineageReadError(
|
|
34750
35428
|
`${source} lineage response is not JSON`,
|
|
34751
35429
|
response.status,
|
|
34752
35430
|
null,
|
|
@@ -34756,7 +35434,7 @@ async function parseLineageGraph(source, response) {
|
|
|
34756
35434
|
const envelope = isRecord4(body) && isRecord4(body.data) ? body : void 0;
|
|
34757
35435
|
const parsed = LineageGraphSchema.safeParse(envelope?.data ?? body);
|
|
34758
35436
|
if (!parsed.success) {
|
|
34759
|
-
throw new
|
|
35437
|
+
throw new import_errors5.LineageReadError(
|
|
34760
35438
|
`${source} lineage response is not a lineage view`,
|
|
34761
35439
|
response.status,
|
|
34762
35440
|
null,
|
|
@@ -34771,7 +35449,7 @@ async function sendLineageRead(source, fetchFn, url, headers) {
|
|
|
34771
35449
|
try {
|
|
34772
35450
|
response = await fetchFn(url, { method: "GET", headers });
|
|
34773
35451
|
} catch (err) {
|
|
34774
|
-
throw new
|
|
35452
|
+
throw new import_errors5.LineageReadError(
|
|
34775
35453
|
`${source} lineage read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
34776
35454
|
void 0,
|
|
34777
35455
|
null,
|
|
@@ -34812,7 +35490,7 @@ async function getPersonalServerLineage(params) {
|
|
|
34812
35490
|
}
|
|
34813
35491
|
async function getGatewayLineage(params) {
|
|
34814
35492
|
if (!isDataPointId(params.dataPointId)) {
|
|
34815
|
-
throw new
|
|
35493
|
+
throw new import_errors5.LineageReadError(
|
|
34816
35494
|
"dataPointId must be a 32-byte hex string (see deriveDataPointId)",
|
|
34817
35495
|
void 0,
|
|
34818
35496
|
"INVALID_DATA_POINT_ID",
|
|
@@ -34849,7 +35527,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
34849
35527
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
34850
35528
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
34851
35529
|
function computeTombstoneHash(preimage) {
|
|
34852
|
-
return (0,
|
|
35530
|
+
return (0, import_viem26.keccak256)((0, import_viem26.stringToBytes)(preimage));
|
|
34853
35531
|
}
|
|
34854
35532
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
34855
35533
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -34868,12 +35546,12 @@ function tombstoneDeletedAt(value) {
|
|
|
34868
35546
|
return typeof deletedAt === "string" ? deletedAt : null;
|
|
34869
35547
|
}
|
|
34870
35548
|
function assertAddress4(value, name) {
|
|
34871
|
-
if (!(0,
|
|
35549
|
+
if (!(0, import_viem26.isAddress)(value)) {
|
|
34872
35550
|
throw new Error(`${name} must be a valid EVM address`);
|
|
34873
35551
|
}
|
|
34874
35552
|
}
|
|
34875
35553
|
function assertUint256(value, name) {
|
|
34876
|
-
if (value < 0n || value >
|
|
35554
|
+
if (value < 0n || value > import_viem26.maxUint256) {
|
|
34877
35555
|
throw new Error(`${name} must fit in uint256, got ${value}`);
|
|
34878
35556
|
}
|
|
34879
35557
|
}
|
|
@@ -34958,13 +35636,13 @@ async function deleteDataPoint(input) {
|
|
|
34958
35636
|
if (currentVersion === void 0) {
|
|
34959
35637
|
const record = await input.gateway.getDataPoint(dataPointId);
|
|
34960
35638
|
if (record === null) {
|
|
34961
|
-
throw new
|
|
35639
|
+
throw new import_errors6.DataPointNotFoundError(
|
|
34962
35640
|
`No data point registered for scope '${input.scope}' owned by ${ownerAddress}`,
|
|
34963
35641
|
{ dataPointId, scope: input.scope, ownerAddress }
|
|
34964
35642
|
);
|
|
34965
35643
|
}
|
|
34966
35644
|
if (isDataPointTombstone(record)) {
|
|
34967
|
-
throw new
|
|
35645
|
+
throw new import_errors6.DataPointDeletedError(
|
|
34968
35646
|
`Data point ${dataPointId} (scope '${input.scope}') is already deleted`,
|
|
34969
35647
|
{
|
|
34970
35648
|
dataPointId,
|
|
@@ -34976,7 +35654,7 @@ async function deleteDataPoint(input) {
|
|
|
34976
35654
|
}
|
|
34977
35655
|
currentVersion = parseExpectedVersion(record.expectedVersion);
|
|
34978
35656
|
}
|
|
34979
|
-
if (currentVersion < 0n || currentVersion >=
|
|
35657
|
+
if (currentVersion < 0n || currentVersion >= import_viem26.maxUint256) {
|
|
34980
35658
|
throw new Error(
|
|
34981
35659
|
`currentVersion ${currentVersion} cannot be incremented to a uint256 tombstone version`
|
|
34982
35660
|
);
|
|
@@ -35011,7 +35689,7 @@ async function deleteDataPoint(input) {
|
|
|
35011
35689
|
}
|
|
35012
35690
|
|
|
35013
35691
|
// src/protocol/personal-server-data.ts
|
|
35014
|
-
var
|
|
35692
|
+
var import_errors7 = require("./errors.cjs");
|
|
35015
35693
|
|
|
35016
35694
|
// src/protocol/data-file.ts
|
|
35017
35695
|
var import_zod2 = require("zod");
|
|
@@ -35071,7 +35749,7 @@ async function readPersonalServerData(params) {
|
|
|
35071
35749
|
const request = await buildPersonalServerDataReadRequest(params);
|
|
35072
35750
|
const response = await fetchFn(request);
|
|
35073
35751
|
if (response.status === 410) {
|
|
35074
|
-
throw new
|
|
35752
|
+
throw new import_errors7.DataPointDeletedError(
|
|
35075
35753
|
`Personal Server scope '${params.scope}' has been deleted`,
|
|
35076
35754
|
{
|
|
35077
35755
|
scope: params.scope,
|
|
@@ -35086,7 +35764,7 @@ async function readPersonalServerData(params) {
|
|
|
35086
35764
|
}
|
|
35087
35765
|
const body = await response.json();
|
|
35088
35766
|
if (isDataPointTombstone(body)) {
|
|
35089
|
-
throw new
|
|
35767
|
+
throw new import_errors7.DataPointDeletedError(
|
|
35090
35768
|
`Personal Server scope '${params.scope}' has been deleted`,
|
|
35091
35769
|
{ scope: params.scope, deletedAt: tombstoneDeletedAt(body) }
|
|
35092
35770
|
);
|
|
@@ -35287,21 +35965,21 @@ function tryGrantPermissions(scopes) {
|
|
|
35287
35965
|
|
|
35288
35966
|
// src/protocol/personal-server-write.ts
|
|
35289
35967
|
var import_sha28 = require("@noble/hashes/sha2");
|
|
35290
|
-
var
|
|
35968
|
+
var import_viem28 = require("viem");
|
|
35291
35969
|
var import_zod4 = require("zod");
|
|
35292
|
-
var
|
|
35970
|
+
var import_errors9 = require("./errors.cjs");
|
|
35293
35971
|
|
|
35294
35972
|
// src/protocol/write-request.ts
|
|
35295
35973
|
var import_sha27 = require("@noble/hashes/sha2");
|
|
35296
|
-
var
|
|
35297
|
-
var
|
|
35974
|
+
var import_viem27 = require("viem");
|
|
35975
|
+
var import_errors8 = require("./errors.cjs");
|
|
35298
35976
|
function normalizeBaseUrl2(url) {
|
|
35299
35977
|
return url.replace(/\/+$/, "");
|
|
35300
35978
|
}
|
|
35301
35979
|
function resolveFetch3(fetchFn) {
|
|
35302
35980
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
35303
35981
|
if (resolved === void 0) {
|
|
35304
|
-
throw new
|
|
35982
|
+
throw new import_errors8.WriteRequestError("No fetch implementation available");
|
|
35305
35983
|
}
|
|
35306
35984
|
return resolved;
|
|
35307
35985
|
}
|
|
@@ -35361,14 +36039,14 @@ function freshProofNonce() {
|
|
|
35361
36039
|
return webCrypto2.randomUUID();
|
|
35362
36040
|
}
|
|
35363
36041
|
if (typeof webCrypto2?.getRandomValues === "function") {
|
|
35364
|
-
return (0,
|
|
36042
|
+
return (0, import_viem27.bytesToHex)(webCrypto2.getRandomValues(new Uint8Array(16)));
|
|
35365
36043
|
}
|
|
35366
|
-
throw new
|
|
36044
|
+
throw new import_errors8.WriteRequestError(
|
|
35367
36045
|
"No secure random source available to build a proof nonce; provide a crypto global"
|
|
35368
36046
|
);
|
|
35369
36047
|
}
|
|
35370
36048
|
function proofKeyFor(parts) {
|
|
35371
|
-
return (0,
|
|
36049
|
+
return (0, import_viem27.bytesToHex)(
|
|
35372
36050
|
(0, import_sha27.sha256)(
|
|
35373
36051
|
new TextEncoder().encode(
|
|
35374
36052
|
JSON.stringify([
|
|
@@ -35376,7 +36054,7 @@ function proofKeyFor(parts) {
|
|
|
35376
36054
|
parts.method,
|
|
35377
36055
|
parts.uri,
|
|
35378
36056
|
parts.grantId,
|
|
35379
|
-
parts.signedBytes ? (0,
|
|
36057
|
+
parts.signedBytes ? (0, import_viem27.bytesToHex)((0, import_sha27.sha256)(parts.signedBytes)) : ""
|
|
35380
36058
|
])
|
|
35381
36059
|
)
|
|
35382
36060
|
)
|
|
@@ -35398,7 +36076,7 @@ async function sendWithFreshProof(label, fetchFn, options, proofKey, build) {
|
|
|
35398
36076
|
delayMs *= 2;
|
|
35399
36077
|
}
|
|
35400
36078
|
}
|
|
35401
|
-
throw new
|
|
36079
|
+
throw new import_errors8.WriteTransportError(
|
|
35402
36080
|
`${label} failed after ${attempts} attempt(s): ${errorMessage(lastError)}`,
|
|
35403
36081
|
attempts,
|
|
35404
36082
|
lastError
|
|
@@ -35469,7 +36147,7 @@ async function openWriteSession(params) {
|
|
|
35469
36147
|
const mintedAt = Date.now();
|
|
35470
36148
|
if (!response.ok) {
|
|
35471
36149
|
const { errorCode, message, details } = await readPersonalServerErrorBody(response);
|
|
35472
|
-
throw new
|
|
36150
|
+
throw new import_errors9.WriteSessionError(
|
|
35473
36151
|
message ?? `Write session handshake failed: ${response.status} ${response.statusText}`,
|
|
35474
36152
|
response.status,
|
|
35475
36153
|
errorCode,
|
|
@@ -35480,7 +36158,7 @@ async function openWriteSession(params) {
|
|
|
35480
36158
|
try {
|
|
35481
36159
|
body = await response.json();
|
|
35482
36160
|
} catch (err) {
|
|
35483
|
-
throw new
|
|
36161
|
+
throw new import_errors9.WriteSessionError(
|
|
35484
36162
|
"Write session response is not JSON",
|
|
35485
36163
|
response.status,
|
|
35486
36164
|
null,
|
|
@@ -35489,7 +36167,7 @@ async function openWriteSession(params) {
|
|
|
35489
36167
|
}
|
|
35490
36168
|
const parsed = WriteSessionResponseSchema.safeParse(body);
|
|
35491
36169
|
if (!parsed.success) {
|
|
35492
|
-
throw new
|
|
36170
|
+
throw new import_errors9.WriteSessionError(
|
|
35493
36171
|
"Write session response is not a session",
|
|
35494
36172
|
response.status,
|
|
35495
36173
|
null,
|
|
@@ -35497,7 +36175,7 @@ async function openWriteSession(params) {
|
|
|
35497
36175
|
);
|
|
35498
36176
|
}
|
|
35499
36177
|
if (parsed.data.token_type.toLowerCase() !== "bearer") {
|
|
35500
|
-
throw new
|
|
36178
|
+
throw new import_errors9.WriteSessionError(
|
|
35501
36179
|
`Write session token type is not Bearer: ${parsed.data.token_type}`,
|
|
35502
36180
|
response.status
|
|
35503
36181
|
);
|
|
@@ -35519,7 +36197,7 @@ function isWriteSession(value) {
|
|
|
35519
36197
|
}
|
|
35520
36198
|
function sessionCoversScope(session, scope) {
|
|
35521
36199
|
if (!isRecord4(session) || !Array.isArray(session.writeScopes) || !session.writeScopes.every((pattern) => typeof pattern === "string")) {
|
|
35522
|
-
throw new
|
|
36200
|
+
throw new import_errors9.WriteRequestError("session must come from openWriteSession");
|
|
35523
36201
|
}
|
|
35524
36202
|
return session.writeScopes.some(
|
|
35525
36203
|
(pattern) => scopeMatchesPattern(scope, pattern)
|
|
@@ -35544,12 +36222,12 @@ function encodeWriteMetadataHeader(metadata) {
|
|
|
35544
36222
|
try {
|
|
35545
36223
|
json = JSON.stringify(metadata);
|
|
35546
36224
|
} catch (err) {
|
|
35547
|
-
throw new
|
|
36225
|
+
throw new import_errors9.WriteRequestError(
|
|
35548
36226
|
`metadata is not JSON-serialisable: ${errorMessage(err)}`
|
|
35549
36227
|
);
|
|
35550
36228
|
}
|
|
35551
36229
|
if (typeof json !== "string") {
|
|
35552
|
-
throw new
|
|
36230
|
+
throw new import_errors9.WriteRequestError("metadata must serialise to JSON");
|
|
35553
36231
|
}
|
|
35554
36232
|
return json.replace(
|
|
35555
36233
|
/[\u007f-\uffff]/g,
|
|
@@ -35563,7 +36241,7 @@ function binaryWriteSignedBytes(input) {
|
|
|
35563
36241
|
mimeType: normalizeBinaryMimeType(input.contentType),
|
|
35564
36242
|
...input.filename ? { filename: input.filename } : {},
|
|
35565
36243
|
sizeBytes: input.bytes.length,
|
|
35566
|
-
contentHash: (0,
|
|
36244
|
+
contentHash: (0, import_viem28.bytesToHex)((0, import_sha28.sha256)(input.bytes)),
|
|
35567
36245
|
encoding: "base64",
|
|
35568
36246
|
content: toBase64(input.bytes),
|
|
35569
36247
|
...metadata !== void 0 ? { metadata } : {}
|
|
@@ -35584,7 +36262,7 @@ function setFilenameHeader(headers, filename) {
|
|
|
35584
36262
|
function assertNoReservedKeys(value, where) {
|
|
35585
36263
|
for (const key of RESERVED_WRITE_KEYS) {
|
|
35586
36264
|
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
35587
|
-
throw new
|
|
36265
|
+
throw new import_errors9.WriteRequestError(
|
|
35588
36266
|
`${where} must not contain the reserved ${key} key; the Personal Server stamps it`,
|
|
35589
36267
|
{ key }
|
|
35590
36268
|
);
|
|
@@ -35596,10 +36274,10 @@ function isLineagePair(value) {
|
|
|
35596
36274
|
}
|
|
35597
36275
|
function normalizeLineage(lineage, derivedScope) {
|
|
35598
36276
|
if (!Array.isArray(lineage)) {
|
|
35599
|
-
throw new
|
|
36277
|
+
throw new import_errors9.WriteRequestError("lineage must be an array of data point ids");
|
|
35600
36278
|
}
|
|
35601
36279
|
if (lineage.length > MAX_LINEAGE_SOURCES) {
|
|
35602
|
-
throw new
|
|
36280
|
+
throw new import_errors9.WriteRequestError(
|
|
35603
36281
|
`lineage lists ${lineage.length} sources; the maximum is ${MAX_LINEAGE_SOURCES}`,
|
|
35604
36282
|
{ max: MAX_LINEAGE_SOURCES, count: lineage.length }
|
|
35605
36283
|
);
|
|
@@ -35611,14 +36289,14 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
35611
36289
|
for (const entry of lineage) {
|
|
35612
36290
|
let id;
|
|
35613
36291
|
if (isLineagePair(entry)) {
|
|
35614
|
-
if (!(0,
|
|
35615
|
-
throw new
|
|
36292
|
+
if (!(0, import_viem28.isAddress)(entry.ownerAddress, { strict: false })) {
|
|
36293
|
+
throw new import_errors9.WriteRequestError(
|
|
35616
36294
|
"lineage source ownerAddress must be an EVM address",
|
|
35617
36295
|
{ ownerAddress: entry.ownerAddress }
|
|
35618
36296
|
);
|
|
35619
36297
|
}
|
|
35620
36298
|
if (entry.scope.length === 0) {
|
|
35621
|
-
throw new
|
|
36299
|
+
throw new import_errors9.WriteRequestError("lineage source scope is required");
|
|
35622
36300
|
}
|
|
35623
36301
|
id = deriveDataPointId(entry.ownerAddress, entry.scope);
|
|
35624
36302
|
sourceScopes.push(entry.scope);
|
|
@@ -35626,14 +36304,14 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
35626
36304
|
} else if (isDataPointId(entry)) {
|
|
35627
36305
|
id = entry;
|
|
35628
36306
|
} else {
|
|
35629
|
-
throw new
|
|
36307
|
+
throw new import_errors9.WriteRequestError(
|
|
35630
36308
|
"lineage entries must be 32-byte hex data point ids or { ownerAddress, scope } pairs",
|
|
35631
36309
|
{ entry }
|
|
35632
36310
|
);
|
|
35633
36311
|
}
|
|
35634
36312
|
const normalized = id.toLowerCase();
|
|
35635
36313
|
if (seen.has(normalized)) {
|
|
35636
|
-
throw new
|
|
36314
|
+
throw new import_errors9.WriteRequestError("lineage must not repeat a data point id", {
|
|
35637
36315
|
dataPointId: normalized
|
|
35638
36316
|
});
|
|
35639
36317
|
}
|
|
@@ -35642,7 +36320,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
35642
36320
|
}
|
|
35643
36321
|
for (const own of ownIds) {
|
|
35644
36322
|
if (seen.has(own)) {
|
|
35645
|
-
throw new
|
|
36323
|
+
throw new import_errors9.WriteRequestError(
|
|
35646
36324
|
"lineage must not cite the record's own data point",
|
|
35647
36325
|
{ dataPointId: own, scope: derivedScope }
|
|
35648
36326
|
);
|
|
@@ -35653,7 +36331,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
35653
36331
|
}
|
|
35654
36332
|
function assertNoLineageField(value, where) {
|
|
35655
36333
|
if (Object.prototype.hasOwnProperty.call(value, LINEAGE_FIELD)) {
|
|
35656
|
-
throw new
|
|
36334
|
+
throw new import_errors9.WriteRequestError(
|
|
35657
36335
|
`${where}.${LINEAGE_FIELD} is reserved; pass sources through the lineage option`
|
|
35658
36336
|
);
|
|
35659
36337
|
}
|
|
@@ -35661,7 +36339,7 @@ function assertNoLineageField(value, where) {
|
|
|
35661
36339
|
function buildMetadataHeader(metadata, sources) {
|
|
35662
36340
|
if (metadata !== void 0) {
|
|
35663
36341
|
if (!isRecord4(metadata)) {
|
|
35664
|
-
throw new
|
|
36342
|
+
throw new import_errors9.WriteRequestError("metadata must be a plain object");
|
|
35665
36343
|
}
|
|
35666
36344
|
assertNoReservedKeys(metadata, "metadata");
|
|
35667
36345
|
assertNoLineageField(metadata, "metadata");
|
|
@@ -35674,24 +36352,24 @@ function buildMetadataHeader(metadata, sources) {
|
|
|
35674
36352
|
}
|
|
35675
36353
|
function prepareWrite(params) {
|
|
35676
36354
|
if (params.binary !== void 0 && params.data !== void 0) {
|
|
35677
|
-
throw new
|
|
36355
|
+
throw new import_errors9.WriteRequestError("Pass either data or binary, not both");
|
|
35678
36356
|
}
|
|
35679
36357
|
const rawLineage = params.lineage;
|
|
35680
36358
|
const sources = rawLineage === void 0 || rawLineage === null ? void 0 : normalizeLineage(rawLineage, params.scope);
|
|
35681
36359
|
if (params.binary !== void 0) {
|
|
35682
36360
|
const { bytes, contentType, filename } = params.binary;
|
|
35683
36361
|
if (!(bytes instanceof Uint8Array)) {
|
|
35684
|
-
throw new
|
|
36362
|
+
throw new import_errors9.WriteRequestError("binary.bytes must be a Uint8Array");
|
|
35685
36363
|
}
|
|
35686
36364
|
if (typeof contentType !== "string" || contentType.trim() === "") {
|
|
35687
|
-
throw new
|
|
36365
|
+
throw new import_errors9.WriteRequestError("binary.contentType is required");
|
|
35688
36366
|
}
|
|
35689
36367
|
if (filename !== void 0) {
|
|
35690
36368
|
if (typeof filename !== "string") {
|
|
35691
|
-
throw new
|
|
36369
|
+
throw new import_errors9.WriteRequestError("binary.filename must be a string");
|
|
35692
36370
|
}
|
|
35693
36371
|
if (filename !== filename.trim()) {
|
|
35694
|
-
throw new
|
|
36372
|
+
throw new import_errors9.WriteRequestError(
|
|
35695
36373
|
"binary.filename must not have leading or trailing whitespace"
|
|
35696
36374
|
);
|
|
35697
36375
|
}
|
|
@@ -35711,13 +36389,13 @@ function prepareWrite(params) {
|
|
|
35711
36389
|
};
|
|
35712
36390
|
}
|
|
35713
36391
|
if (params.data === void 0) {
|
|
35714
|
-
throw new
|
|
36392
|
+
throw new import_errors9.WriteRequestError("Pass data (a JSON object) or binary");
|
|
35715
36393
|
}
|
|
35716
36394
|
if (!isRecord4(params.data)) {
|
|
35717
|
-
throw new
|
|
36395
|
+
throw new import_errors9.WriteRequestError("data must be a plain JSON object");
|
|
35718
36396
|
}
|
|
35719
36397
|
if (params.metadata !== void 0) {
|
|
35720
|
-
throw new
|
|
36398
|
+
throw new import_errors9.WriteRequestError(
|
|
35721
36399
|
"metadata applies to binary writes; put fields to store inside data"
|
|
35722
36400
|
);
|
|
35723
36401
|
}
|
|
@@ -35728,12 +36406,12 @@ function prepareWrite(params) {
|
|
|
35728
36406
|
try {
|
|
35729
36407
|
text = JSON.stringify(record);
|
|
35730
36408
|
} catch (err) {
|
|
35731
|
-
throw new
|
|
36409
|
+
throw new import_errors9.WriteRequestError(
|
|
35732
36410
|
`data is not JSON-serialisable: ${errorMessage(err)}`
|
|
35733
36411
|
);
|
|
35734
36412
|
}
|
|
35735
36413
|
if (typeof text !== "string" || !text.startsWith("{")) {
|
|
35736
|
-
throw new
|
|
36414
|
+
throw new import_errors9.WriteRequestError("data must serialise to a JSON object");
|
|
35737
36415
|
}
|
|
35738
36416
|
const body = new TextEncoder().encode(text);
|
|
35739
36417
|
return {
|
|
@@ -35746,31 +36424,31 @@ async function writeErrorFromResponse(response) {
|
|
|
35746
36424
|
const { errorCode, message, details } = await readPersonalServerErrorBody(response);
|
|
35747
36425
|
const text = message ?? `Personal Server write failed: ${response.status} ${response.statusText}`;
|
|
35748
36426
|
if (response.status === 422 || errorCode?.startsWith("LINEAGE_")) {
|
|
35749
|
-
return new
|
|
36427
|
+
return new import_errors9.WriteLineageError(text, response.status, errorCode, details);
|
|
35750
36428
|
}
|
|
35751
36429
|
switch (response.status) {
|
|
35752
36430
|
case 401:
|
|
35753
|
-
return new
|
|
36431
|
+
return new import_errors9.WriteUnauthorizedError(text, errorCode, details);
|
|
35754
36432
|
case 403:
|
|
35755
|
-
return new
|
|
36433
|
+
return new import_errors9.WriteForbiddenError(text, errorCode, details);
|
|
35756
36434
|
case 409:
|
|
35757
|
-
return new
|
|
36435
|
+
return new import_errors9.WriteConflictError(text, errorCode, details);
|
|
35758
36436
|
default:
|
|
35759
|
-
return new
|
|
36437
|
+
return new import_errors9.WriteRejectedError(text, response.status, errorCode, details);
|
|
35760
36438
|
}
|
|
35761
36439
|
}
|
|
35762
36440
|
async function writeData(params) {
|
|
35763
36441
|
const { session } = params;
|
|
35764
36442
|
if (!isWriteSession(session)) {
|
|
35765
|
-
throw new
|
|
36443
|
+
throw new import_errors9.WriteRequestError("session must come from openWriteSession");
|
|
35766
36444
|
}
|
|
35767
36445
|
const fetchFn = resolveFetch3(params.fetch);
|
|
35768
36446
|
if (typeof params.scope !== "string" || params.scope.length === 0) {
|
|
35769
|
-
throw new
|
|
36447
|
+
throw new import_errors9.WriteRequestError("scope is required");
|
|
35770
36448
|
}
|
|
35771
36449
|
const prepared = prepareWrite(params);
|
|
35772
36450
|
if (Date.now() >= session.expiresAt) {
|
|
35773
|
-
throw new
|
|
36451
|
+
throw new import_errors9.WriteSessionExpiredError(
|
|
35774
36452
|
"Write session has expired; open a new session",
|
|
35775
36453
|
{ grantId: session.grantId, expiresAt: session.expiresAt }
|
|
35776
36454
|
);
|
|
@@ -35826,7 +36504,7 @@ async function writeData(params) {
|
|
|
35826
36504
|
try {
|
|
35827
36505
|
body = await response.json();
|
|
35828
36506
|
} catch (err) {
|
|
35829
|
-
throw new
|
|
36507
|
+
throw new import_errors9.WriteRejectedError(
|
|
35830
36508
|
"Personal Server write response is not JSON",
|
|
35831
36509
|
response.status,
|
|
35832
36510
|
null,
|
|
@@ -35835,7 +36513,7 @@ async function writeData(params) {
|
|
|
35835
36513
|
}
|
|
35836
36514
|
const parsed = WriteDataResultSchema.safeParse(body);
|
|
35837
36515
|
if (!parsed.success) {
|
|
35838
|
-
throw new
|
|
36516
|
+
throw new import_errors9.WriteRejectedError(
|
|
35839
36517
|
"Personal Server write response is not an ingest result",
|
|
35840
36518
|
response.status,
|
|
35841
36519
|
null,
|
|
@@ -35862,7 +36540,7 @@ async function writePersonalServerData(params) {
|
|
|
35862
36540
|
|
|
35863
36541
|
// src/protocol/derivative-questions.ts
|
|
35864
36542
|
var import_zod5 = require("zod");
|
|
35865
|
-
var
|
|
36543
|
+
var import_errors10 = require("./errors.cjs");
|
|
35866
36544
|
var DERIVATIVE_QUESTIONS_PATH = "/v1/derivatives/questions";
|
|
35867
36545
|
var MAX_QUESTION_SOURCE_SCOPES = 16;
|
|
35868
36546
|
var MAX_QUESTION_CHARS = 8e3;
|
|
@@ -35945,15 +36623,15 @@ function fetchIdOf(fetchFn) {
|
|
|
35945
36623
|
}
|
|
35946
36624
|
function resolveRequest(params) {
|
|
35947
36625
|
if (typeof params.personalServerUrl !== "string" || params.personalServerUrl.length === 0) {
|
|
35948
|
-
throw new
|
|
36626
|
+
throw new import_errors10.WriteRequestError("personalServerUrl is required");
|
|
35949
36627
|
}
|
|
35950
36628
|
if (typeof params.grantId !== "string" || params.grantId.length === 0) {
|
|
35951
|
-
throw new
|
|
36629
|
+
throw new import_errors10.WriteRequestError(
|
|
35952
36630
|
"grantId is required; a question call runs under the grant carrying write:<derivedScope>"
|
|
35953
36631
|
);
|
|
35954
36632
|
}
|
|
35955
36633
|
if (params.signer === null || typeof params.signer !== "object") {
|
|
35956
|
-
throw new
|
|
36634
|
+
throw new import_errors10.WriteRequestError(
|
|
35957
36635
|
"signer must be a viem LocalAccount, a viem WalletClient, or a { signMessage } object"
|
|
35958
36636
|
);
|
|
35959
36637
|
}
|
|
@@ -36007,37 +36685,37 @@ async function questionErrorFromResponse(response, body) {
|
|
|
36007
36685
|
const text = message ?? `Derivative question request failed: ${response.status} ${response.statusText}`;
|
|
36008
36686
|
switch (errorCode) {
|
|
36009
36687
|
case "DERIVATIVE_SOURCE_NOT_GRANTED":
|
|
36010
|
-
return new
|
|
36688
|
+
return new import_errors10.DerivativeSourceNotGrantedError(text, errorCode, details);
|
|
36011
36689
|
case "DERIVATIVE_CYCLE":
|
|
36012
|
-
return new
|
|
36690
|
+
return new import_errors10.DerivativeCycleError(text, errorCode, details);
|
|
36013
36691
|
case "DERIVATIVE_COMPUTE_UNAVAILABLE":
|
|
36014
|
-
return new
|
|
36692
|
+
return new import_errors10.DerivativeComputeUnavailableError(text, errorCode, details);
|
|
36015
36693
|
case "DERIVATIVE_QUESTION_INVALID":
|
|
36016
36694
|
case "LINEAGE_SCOPE_UNDER_SOURCE_PREFIX":
|
|
36017
|
-
return new
|
|
36695
|
+
return new import_errors10.DerivativeQuestionInvalidError(
|
|
36018
36696
|
text,
|
|
36019
36697
|
response.status,
|
|
36020
36698
|
errorCode,
|
|
36021
36699
|
details
|
|
36022
36700
|
);
|
|
36023
36701
|
case "DERIVATIVE_QUESTION_NOT_FOUND":
|
|
36024
|
-
return new
|
|
36702
|
+
return new import_errors10.DerivativeQuestionNotFoundError(text, errorCode, details);
|
|
36025
36703
|
case "DERIVATIVE_DERIVED_SCOPE_REQUIRED":
|
|
36026
|
-
return new
|
|
36704
|
+
return new import_errors10.DerivativeDerivedScopeRequiredError(text, errorCode, details);
|
|
36027
36705
|
default:
|
|
36028
36706
|
break;
|
|
36029
36707
|
}
|
|
36030
36708
|
switch (response.status) {
|
|
36031
36709
|
case 401:
|
|
36032
|
-
return new
|
|
36710
|
+
return new import_errors10.WriteUnauthorizedError(text, errorCode, details);
|
|
36033
36711
|
case 403:
|
|
36034
|
-
return new
|
|
36712
|
+
return new import_errors10.WriteForbiddenError(text, errorCode, details);
|
|
36035
36713
|
case 404:
|
|
36036
|
-
return new
|
|
36714
|
+
return new import_errors10.DerivativeQuestionNotFoundError(text, errorCode, details);
|
|
36037
36715
|
case 409:
|
|
36038
|
-
return new
|
|
36716
|
+
return new import_errors10.WriteConflictError(text, errorCode, details);
|
|
36039
36717
|
default:
|
|
36040
|
-
return new
|
|
36718
|
+
return new import_errors10.DerivativeQuestionRejectedError(
|
|
36041
36719
|
text,
|
|
36042
36720
|
response.status,
|
|
36043
36721
|
errorCode,
|
|
@@ -36117,7 +36795,7 @@ async function sendQuestionRequest(params, spec, schema) {
|
|
|
36117
36795
|
try {
|
|
36118
36796
|
body = await response.json();
|
|
36119
36797
|
} catch (err) {
|
|
36120
|
-
throw new
|
|
36798
|
+
throw new import_errors10.DerivativeQuestionRejectedError(
|
|
36121
36799
|
`${spec.label} response is not JSON`,
|
|
36122
36800
|
response.status,
|
|
36123
36801
|
null,
|
|
@@ -36126,7 +36804,7 @@ async function sendQuestionRequest(params, spec, schema) {
|
|
|
36126
36804
|
}
|
|
36127
36805
|
const parsed = schema.safeParse(body);
|
|
36128
36806
|
if (!parsed.success) {
|
|
36129
|
-
throw new
|
|
36807
|
+
throw new import_errors10.DerivativeQuestionRejectedError(
|
|
36130
36808
|
`${spec.label} response is not a derivative question answer`,
|
|
36131
36809
|
response.status,
|
|
36132
36810
|
null,
|
|
@@ -36137,22 +36815,22 @@ async function sendQuestionRequest(params, spec, schema) {
|
|
|
36137
36815
|
}
|
|
36138
36816
|
function assertQuestionId(questionId) {
|
|
36139
36817
|
if (typeof questionId !== "string" || questionId.length === 0) {
|
|
36140
|
-
throw new
|
|
36818
|
+
throw new import_errors10.WriteRequestError("questionId is required");
|
|
36141
36819
|
}
|
|
36142
36820
|
return `${DERIVATIVE_QUESTIONS_PATH}/${encodeURIComponent(questionId)}`;
|
|
36143
36821
|
}
|
|
36144
36822
|
function registrationBody(params) {
|
|
36145
36823
|
const { derivedScope, question } = params;
|
|
36146
36824
|
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
36147
|
-
throw new
|
|
36825
|
+
throw new import_errors10.WriteRequestError("derivedScope is required");
|
|
36148
36826
|
}
|
|
36149
36827
|
if (!Array.isArray(params.sourceScopes) || params.sourceScopes.length === 0) {
|
|
36150
|
-
throw new
|
|
36828
|
+
throw new import_errors10.WriteRequestError(
|
|
36151
36829
|
"sourceScopes must be a non-empty array of scopes"
|
|
36152
36830
|
);
|
|
36153
36831
|
}
|
|
36154
36832
|
if (params.sourceScopes.length > MAX_QUESTION_SOURCE_SCOPES) {
|
|
36155
|
-
throw new
|
|
36833
|
+
throw new import_errors10.WriteRequestError(
|
|
36156
36834
|
`sourceScopes lists ${params.sourceScopes.length} scopes; the maximum is ${MAX_QUESTION_SOURCE_SCOPES}`,
|
|
36157
36835
|
{ max: MAX_QUESTION_SOURCE_SCOPES, count: params.sourceScopes.length }
|
|
36158
36836
|
);
|
|
@@ -36160,15 +36838,15 @@ function registrationBody(params) {
|
|
|
36160
36838
|
const sourceScopes = [];
|
|
36161
36839
|
for (const scope of params.sourceScopes) {
|
|
36162
36840
|
if (typeof scope !== "string" || scope.length === 0) {
|
|
36163
|
-
throw new
|
|
36841
|
+
throw new import_errors10.WriteRequestError("sourceScopes entries must be scope strings");
|
|
36164
36842
|
}
|
|
36165
36843
|
if (sourceScopes.includes(scope)) {
|
|
36166
|
-
throw new
|
|
36844
|
+
throw new import_errors10.WriteRequestError("sourceScopes must not repeat a scope", {
|
|
36167
36845
|
duplicate: scope
|
|
36168
36846
|
});
|
|
36169
36847
|
}
|
|
36170
36848
|
if (scope === derivedScope) {
|
|
36171
|
-
throw new
|
|
36849
|
+
throw new import_errors10.WriteRequestError(
|
|
36172
36850
|
"derivedScope cannot be one of its own sources",
|
|
36173
36851
|
{ scope }
|
|
36174
36852
|
);
|
|
@@ -36176,17 +36854,17 @@ function registrationBody(params) {
|
|
|
36176
36854
|
sourceScopes.push(scope);
|
|
36177
36855
|
}
|
|
36178
36856
|
if (typeof question !== "string" || question.trim() === "") {
|
|
36179
|
-
throw new
|
|
36857
|
+
throw new import_errors10.WriteRequestError("question must be a non-empty string");
|
|
36180
36858
|
}
|
|
36181
36859
|
if (question.length > MAX_QUESTION_CHARS) {
|
|
36182
|
-
throw new
|
|
36860
|
+
throw new import_errors10.WriteRequestError(
|
|
36183
36861
|
`question is ${question.length} characters; the maximum is ${MAX_QUESTION_CHARS}`,
|
|
36184
36862
|
{ max: MAX_QUESTION_CHARS, length: question.length }
|
|
36185
36863
|
);
|
|
36186
36864
|
}
|
|
36187
36865
|
if (params.model !== void 0) {
|
|
36188
36866
|
if (typeof params.model !== "string" || params.model.length > MAX_QUESTION_MODEL_CHARS || !MODEL_ID_PATTERN.test(params.model)) {
|
|
36189
|
-
throw new
|
|
36867
|
+
throw new import_errors10.WriteRequestError("model must be a provider model id", {
|
|
36190
36868
|
model: params.model
|
|
36191
36869
|
});
|
|
36192
36870
|
}
|
|
@@ -36222,7 +36900,7 @@ async function getQuestion(params) {
|
|
|
36222
36900
|
}
|
|
36223
36901
|
async function listQuestions(params) {
|
|
36224
36902
|
if (typeof params.derivedScope !== "string" || params.derivedScope.length === 0) {
|
|
36225
|
-
throw new
|
|
36903
|
+
throw new import_errors10.WriteRequestError(
|
|
36226
36904
|
"derivedScope is required; a builder may only list its own questions on a scope it may write"
|
|
36227
36905
|
);
|
|
36228
36906
|
}
|
|
@@ -36280,7 +36958,7 @@ async function waitForQuestion(params) {
|
|
|
36280
36958
|
if (isSettled(latest.status)) return latest;
|
|
36281
36959
|
const remaining = deadline - Date.now();
|
|
36282
36960
|
if (remaining <= 0) {
|
|
36283
|
-
throw new
|
|
36961
|
+
throw new import_errors10.DerivativeQuestionTimeoutError(
|
|
36284
36962
|
`Derivative question ${latest.questionId} was still ${latest.status} after ${timeoutMs}ms`,
|
|
36285
36963
|
{
|
|
36286
36964
|
questionId: latest.questionId,
|
|
@@ -36300,7 +36978,7 @@ async function askPersonalServer(params) {
|
|
|
36300
36978
|
questionId: registered.questionId
|
|
36301
36979
|
});
|
|
36302
36980
|
if (registration.status !== "ready") {
|
|
36303
|
-
throw new
|
|
36981
|
+
throw new import_errors10.DerivativeQuestionFailedError(
|
|
36304
36982
|
`Derivative question ${registration.questionId} failed: ${registration.error ?? "no reason given"}`,
|
|
36305
36983
|
{
|
|
36306
36984
|
questionId: registration.questionId,
|
|
@@ -36327,7 +37005,7 @@ async function askPersonalServer(params) {
|
|
|
36327
37005
|
|
|
36328
37006
|
// src/protocol/derivative-status.ts
|
|
36329
37007
|
var import_zod6 = require("zod");
|
|
36330
|
-
var
|
|
37008
|
+
var import_errors11 = require("./errors.cjs");
|
|
36331
37009
|
var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
|
|
36332
37010
|
var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
|
|
36333
37011
|
var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
|
|
@@ -36358,13 +37036,13 @@ function normalizeBaseUrl3(url) {
|
|
|
36358
37036
|
function resolveFetch4(fetchFn) {
|
|
36359
37037
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
36360
37038
|
if (resolved === void 0) {
|
|
36361
|
-
throw new
|
|
37039
|
+
throw new import_errors11.WriteRequestError("No fetch implementation available");
|
|
36362
37040
|
}
|
|
36363
37041
|
return resolved;
|
|
36364
37042
|
}
|
|
36365
37043
|
function requireDerivedScope(derivedScope) {
|
|
36366
37044
|
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
36367
|
-
throw new
|
|
37045
|
+
throw new import_errors11.WriteRequestError("derivedScope is required");
|
|
36368
37046
|
}
|
|
36369
37047
|
return derivedScope;
|
|
36370
37048
|
}
|
|
@@ -36383,7 +37061,7 @@ function sleep4(ms, signal) {
|
|
|
36383
37061
|
});
|
|
36384
37062
|
}
|
|
36385
37063
|
function timeoutError(latest, timeoutMs) {
|
|
36386
|
-
return new
|
|
37064
|
+
return new import_errors11.DerivativeQuestionTimeoutError(
|
|
36387
37065
|
`Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
|
|
36388
37066
|
{
|
|
36389
37067
|
derivedScope: latest.derivedScope,
|
|
@@ -36396,7 +37074,7 @@ function timeoutError(latest, timeoutMs) {
|
|
|
36396
37074
|
}
|
|
36397
37075
|
function abortError2(signal) {
|
|
36398
37076
|
const reason = signal?.reason;
|
|
36399
|
-
return reason instanceof Error ? reason : new
|
|
37077
|
+
return reason instanceof Error ? reason : new import_errors11.WriteRequestError("Derivative status wait was aborted");
|
|
36400
37078
|
}
|
|
36401
37079
|
function isDerivativeStatusSettled(status) {
|
|
36402
37080
|
if (status.status === "ready") return true;
|
|
@@ -36429,7 +37107,7 @@ async function getDerivativeStatus(params) {
|
|
|
36429
37107
|
}
|
|
36430
37108
|
);
|
|
36431
37109
|
} catch (err) {
|
|
36432
|
-
throw new
|
|
37110
|
+
throw new import_errors11.WriteTransportError(
|
|
36433
37111
|
`Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
36434
37112
|
1,
|
|
36435
37113
|
err
|
|
@@ -36444,7 +37122,7 @@ async function getDerivativeStatus(params) {
|
|
|
36444
37122
|
try {
|
|
36445
37123
|
body = await response.json();
|
|
36446
37124
|
} catch (err) {
|
|
36447
|
-
throw new
|
|
37125
|
+
throw new import_errors11.DerivativeQuestionRejectedError(
|
|
36448
37126
|
"Derivative status response is not JSON",
|
|
36449
37127
|
response.status,
|
|
36450
37128
|
null,
|
|
@@ -36453,7 +37131,7 @@ async function getDerivativeStatus(params) {
|
|
|
36453
37131
|
}
|
|
36454
37132
|
const parsed = DerivativeStatusSchema.safeParse(body);
|
|
36455
37133
|
if (!parsed.success) {
|
|
36456
|
-
throw new
|
|
37134
|
+
throw new import_errors11.DerivativeQuestionRejectedError(
|
|
36457
37135
|
"Derivative status response is not a status view",
|
|
36458
37136
|
response.status,
|
|
36459
37137
|
null,
|
|
@@ -36487,7 +37165,7 @@ async function waitForDerivativeStatus(params) {
|
|
|
36487
37165
|
}
|
|
36488
37166
|
|
|
36489
37167
|
// src/protocol/gateway.ts
|
|
36490
|
-
var
|
|
37168
|
+
var import_errors12 = require("./errors.cjs");
|
|
36491
37169
|
function withGrantPermissions(grant) {
|
|
36492
37170
|
const stripped = { ...grant };
|
|
36493
37171
|
delete stripped.permissions;
|
|
@@ -36533,7 +37211,7 @@ function createGatewayClient(baseUrl) {
|
|
|
36533
37211
|
}
|
|
36534
37212
|
async function deletedError(res, details) {
|
|
36535
37213
|
const body = await readBody(res);
|
|
36536
|
-
return new
|
|
37214
|
+
return new import_errors12.DataPointDeletedError(
|
|
36537
37215
|
`Data point ${details.dataPointId ?? details.scope ?? ""} has been deleted`,
|
|
36538
37216
|
{ ...details, deletedAt: tombstoneDeletedAt(body) }
|
|
36539
37217
|
);
|
|
@@ -36606,7 +37284,7 @@ function createGatewayClient(baseUrl) {
|
|
|
36606
37284
|
}
|
|
36607
37285
|
const record = await unwrapEnvelope(res);
|
|
36608
37286
|
if (!options?.includeDeleted && isDataPointTombstone(record)) {
|
|
36609
|
-
throw new
|
|
37287
|
+
throw new import_errors12.DataPointDeletedError(
|
|
36610
37288
|
`Data point ${dataPointId} has been deleted`,
|
|
36611
37289
|
{
|
|
36612
37290
|
dataPointId,
|
|
@@ -36768,7 +37446,7 @@ function createGatewayClient(baseUrl) {
|
|
|
36768
37446
|
})
|
|
36769
37447
|
});
|
|
36770
37448
|
if (res.status === 404) {
|
|
36771
|
-
throw new
|
|
37449
|
+
throw new import_errors12.DataPointNotFoundError(
|
|
36772
37450
|
`Data point ${dataPointId} (scope '${params.scope}') is not registered`,
|
|
36773
37451
|
details
|
|
36774
37452
|
);
|
|
@@ -36779,7 +37457,7 @@ function createGatewayClient(baseUrl) {
|
|
|
36779
37457
|
body2["currentExpectedVersion"]
|
|
36780
37458
|
);
|
|
36781
37459
|
const detail = stringOrUndefined(body2["error"]) ?? res.statusText;
|
|
36782
|
-
throw new
|
|
37460
|
+
throw new import_errors12.DataPointVersionConflictError(
|
|
36783
37461
|
`Gateway error: 409 ${detail}`,
|
|
36784
37462
|
{
|
|
36785
37463
|
...details,
|
|
@@ -36909,261 +37587,6 @@ function createGatewayClient(baseUrl) {
|
|
|
36909
37587
|
};
|
|
36910
37588
|
}
|
|
36911
37589
|
|
|
36912
|
-
// src/protocol/escrow.ts
|
|
36913
|
-
var import_viem28 = require("viem");
|
|
36914
|
-
var GENERIC_PAYMENT_TYPES = {
|
|
36915
|
-
GenericPayment: [
|
|
36916
|
-
{ name: "payerAddress", type: "address" },
|
|
36917
|
-
{ name: "opType", type: "string" },
|
|
36918
|
-
{ name: "opId", type: "bytes32" },
|
|
36919
|
-
{ name: "asset", type: "address" },
|
|
36920
|
-
{ name: "amount", type: "uint256" },
|
|
36921
|
-
{ name: "paymentNonce", type: "uint256" }
|
|
36922
|
-
]
|
|
36923
|
-
};
|
|
36924
|
-
function genericPaymentDomain(chainId, escrowContract) {
|
|
36925
|
-
return {
|
|
36926
|
-
name: "Vana Data Portability",
|
|
36927
|
-
version: "1",
|
|
36928
|
-
chainId,
|
|
36929
|
-
verifyingContract: escrowContract
|
|
36930
|
-
};
|
|
36931
|
-
}
|
|
36932
|
-
var ESCROW_DEPOSIT_ABI2 = [
|
|
36933
|
-
{
|
|
36934
|
-
type: "function",
|
|
36935
|
-
name: "depositNative",
|
|
36936
|
-
stateMutability: "payable",
|
|
36937
|
-
inputs: [{ name: "account", type: "address" }],
|
|
36938
|
-
outputs: []
|
|
36939
|
-
},
|
|
36940
|
-
{
|
|
36941
|
-
type: "function",
|
|
36942
|
-
name: "depositToken",
|
|
36943
|
-
stateMutability: "nonpayable",
|
|
36944
|
-
inputs: [
|
|
36945
|
-
{ name: "account", type: "address" },
|
|
36946
|
-
{ name: "token", type: "address" },
|
|
36947
|
-
{ name: "amount", type: "uint256" }
|
|
36948
|
-
],
|
|
36949
|
-
outputs: []
|
|
36950
|
-
}
|
|
36951
|
-
];
|
|
36952
|
-
var NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
36953
|
-
var EscrowWithdrawalLifecycleError = class extends Error {
|
|
36954
|
-
constructor(httpStatus, result) {
|
|
36955
|
-
super(result.error);
|
|
36956
|
-
this.httpStatus = httpStatus;
|
|
36957
|
-
this.result = result;
|
|
36958
|
-
}
|
|
36959
|
-
httpStatus;
|
|
36960
|
-
result;
|
|
36961
|
-
name = "EscrowWithdrawalLifecycleError";
|
|
36962
|
-
};
|
|
36963
|
-
var EscrowWithdrawalRejectionError = class extends Error {
|
|
36964
|
-
constructor(httpStatus, result) {
|
|
36965
|
-
super(result.error);
|
|
36966
|
-
this.httpStatus = httpStatus;
|
|
36967
|
-
this.result = result;
|
|
36968
|
-
}
|
|
36969
|
-
httpStatus;
|
|
36970
|
-
result;
|
|
36971
|
-
name = "EscrowWithdrawalRejectionError";
|
|
36972
|
-
};
|
|
36973
|
-
function createEscrowGatewayClient(baseUrl) {
|
|
36974
|
-
const base = baseUrl.replace(/\/+$/, "");
|
|
36975
|
-
async function throwOnError(res, context) {
|
|
36976
|
-
if (!res.ok) {
|
|
36977
|
-
let detail = "";
|
|
36978
|
-
try {
|
|
36979
|
-
const body = await res.json();
|
|
36980
|
-
if (body.error) detail = `: ${body.error}`;
|
|
36981
|
-
} catch {
|
|
36982
|
-
}
|
|
36983
|
-
throw new Error(
|
|
36984
|
-
`Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`
|
|
36985
|
-
);
|
|
36986
|
-
}
|
|
36987
|
-
}
|
|
36988
|
-
async function throwOnWithdrawError(res) {
|
|
36989
|
-
if (res.ok) return;
|
|
36990
|
-
let body;
|
|
36991
|
-
try {
|
|
36992
|
-
body = await res.json();
|
|
36993
|
-
} catch {
|
|
36994
|
-
throw new Error(
|
|
36995
|
-
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}`
|
|
36996
|
-
);
|
|
36997
|
-
}
|
|
36998
|
-
if (isEscrowWithdrawalFailureResult(body)) {
|
|
36999
|
-
throw new EscrowWithdrawalLifecycleError(res.status, body);
|
|
37000
|
-
}
|
|
37001
|
-
if (isEscrowWithdrawalRejectedResult(body)) {
|
|
37002
|
-
throw new EscrowWithdrawalRejectionError(res.status, body);
|
|
37003
|
-
}
|
|
37004
|
-
const error = getGatewayErrorMessage(body);
|
|
37005
|
-
throw new Error(
|
|
37006
|
-
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}${error ? `: ${error}` : ""}`
|
|
37007
|
-
);
|
|
37008
|
-
}
|
|
37009
|
-
return {
|
|
37010
|
-
async submitDeposit({ txHash }) {
|
|
37011
|
-
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
37012
|
-
method: "POST",
|
|
37013
|
-
headers: { "Content-Type": "application/json" },
|
|
37014
|
-
body: JSON.stringify({ txHash })
|
|
37015
|
-
});
|
|
37016
|
-
if (res.status !== 200 && res.status !== 202) {
|
|
37017
|
-
await throwOnError(res, "POST /v1/escrow/deposit");
|
|
37018
|
-
}
|
|
37019
|
-
return res.json();
|
|
37020
|
-
},
|
|
37021
|
-
async getEscrowBalance(account) {
|
|
37022
|
-
const res = await fetch(
|
|
37023
|
-
`${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`
|
|
37024
|
-
);
|
|
37025
|
-
await throwOnError(res, "GET /v1/escrow/balance");
|
|
37026
|
-
return res.json();
|
|
37027
|
-
},
|
|
37028
|
-
async syncEscrowBalance(account) {
|
|
37029
|
-
const res = await fetch(
|
|
37030
|
-
`${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,
|
|
37031
|
-
{ method: "POST" }
|
|
37032
|
-
);
|
|
37033
|
-
await throwOnError(res, "POST /v1/escrow/balance/sync");
|
|
37034
|
-
return res.json();
|
|
37035
|
-
},
|
|
37036
|
-
async payForOp({
|
|
37037
|
-
payerAddress,
|
|
37038
|
-
opType,
|
|
37039
|
-
opId,
|
|
37040
|
-
asset,
|
|
37041
|
-
amount,
|
|
37042
|
-
paymentNonce,
|
|
37043
|
-
signature,
|
|
37044
|
-
accessRecord
|
|
37045
|
-
}) {
|
|
37046
|
-
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
37047
|
-
method: "POST",
|
|
37048
|
-
headers: {
|
|
37049
|
-
"Content-Type": "application/json",
|
|
37050
|
-
Authorization: `Web3Signed ${signature}`
|
|
37051
|
-
},
|
|
37052
|
-
body: JSON.stringify({
|
|
37053
|
-
payerAddress,
|
|
37054
|
-
opType,
|
|
37055
|
-
opId,
|
|
37056
|
-
asset,
|
|
37057
|
-
amount,
|
|
37058
|
-
paymentNonce,
|
|
37059
|
-
...accessRecord ? { accessRecord } : {}
|
|
37060
|
-
})
|
|
37061
|
-
});
|
|
37062
|
-
await throwOnError(res, "POST /v1/escrow/pay");
|
|
37063
|
-
return res.json();
|
|
37064
|
-
},
|
|
37065
|
-
async withdraw({
|
|
37066
|
-
account,
|
|
37067
|
-
asset,
|
|
37068
|
-
amount,
|
|
37069
|
-
withdrawNonce,
|
|
37070
|
-
deadline,
|
|
37071
|
-
signature
|
|
37072
|
-
}) {
|
|
37073
|
-
const res = await fetch(`${base}/v1/escrow/withdraw`, {
|
|
37074
|
-
method: "POST",
|
|
37075
|
-
headers: {
|
|
37076
|
-
"Content-Type": "application/json",
|
|
37077
|
-
Authorization: `Web3Signed ${signature}`
|
|
37078
|
-
},
|
|
37079
|
-
body: JSON.stringify({
|
|
37080
|
-
account,
|
|
37081
|
-
asset,
|
|
37082
|
-
amount,
|
|
37083
|
-
withdrawNonce,
|
|
37084
|
-
deadline
|
|
37085
|
-
})
|
|
37086
|
-
});
|
|
37087
|
-
await throwOnWithdrawError(res);
|
|
37088
|
-
return res.json();
|
|
37089
|
-
},
|
|
37090
|
-
async getWithdrawNonce(account) {
|
|
37091
|
-
const res = await fetch(
|
|
37092
|
-
`${base}/v1/escrow/withdraw/nonce?account=${encodeURIComponent(account)}`,
|
|
37093
|
-
{ cache: "no-store" }
|
|
37094
|
-
);
|
|
37095
|
-
await throwOnError(res, "GET /v1/escrow/withdraw/nonce");
|
|
37096
|
-
const body = await res.json();
|
|
37097
|
-
if (!isWithdrawNonceResponse(body, account)) {
|
|
37098
|
-
throw new Error(
|
|
37099
|
-
"GET /v1/escrow/withdraw/nonce: invalid response structure"
|
|
37100
|
-
);
|
|
37101
|
-
}
|
|
37102
|
-
return body;
|
|
37103
|
-
}
|
|
37104
|
-
};
|
|
37105
|
-
}
|
|
37106
|
-
function getGatewayErrorMessage(body) {
|
|
37107
|
-
if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
|
|
37108
|
-
return body.error;
|
|
37109
|
-
}
|
|
37110
|
-
return void 0;
|
|
37111
|
-
}
|
|
37112
|
-
function isEscrowWithdrawalFailureResult(body) {
|
|
37113
|
-
if (typeof body !== "object" || body === null) return false;
|
|
37114
|
-
const value = body;
|
|
37115
|
-
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));
|
|
37116
|
-
}
|
|
37117
|
-
function isEscrowWithdrawalRejectedResult(body) {
|
|
37118
|
-
if (typeof body !== "object" || body === null) return false;
|
|
37119
|
-
const value = body;
|
|
37120
|
-
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);
|
|
37121
|
-
}
|
|
37122
|
-
function isWithdrawalRejectionCode(value) {
|
|
37123
|
-
return value === "below_minimum" || value === "deadline_too_far" || value === "expired" || value === "insufficient_available" || value === "stale_nonce";
|
|
37124
|
-
}
|
|
37125
|
-
function optionalUint256Decimal(value) {
|
|
37126
|
-
return value === void 0 || isUint256Decimal(value);
|
|
37127
|
-
}
|
|
37128
|
-
function isAddressHex(value) {
|
|
37129
|
-
return typeof value === "string" && (0, import_viem28.isHex)(value, { strict: true }) && value.length === 42;
|
|
37130
|
-
}
|
|
37131
|
-
function isHash(value) {
|
|
37132
|
-
return typeof value === "string" && (0, import_viem28.isHex)(value, { strict: true }) && value.length === 66;
|
|
37133
|
-
}
|
|
37134
|
-
function isUint256Decimal(value) {
|
|
37135
|
-
if (typeof value !== "string" || value.length === 0 || value.length > 78) {
|
|
37136
|
-
return false;
|
|
37137
|
-
}
|
|
37138
|
-
if (!/^(0|[1-9]\d*)$/.test(value)) return false;
|
|
37139
|
-
return BigInt(value) <= 2n ** 256n - 1n;
|
|
37140
|
-
}
|
|
37141
|
-
function isBlockNumber(value) {
|
|
37142
|
-
return value === null || isUint256Decimal(value);
|
|
37143
|
-
}
|
|
37144
|
-
function isWithdrawNonceResponse(body, requestedAccount) {
|
|
37145
|
-
if (typeof body !== "object" || body === null) return false;
|
|
37146
|
-
const value = body;
|
|
37147
|
-
if (value.success !== true) return false;
|
|
37148
|
-
if (!isAddressHex(value.account)) return false;
|
|
37149
|
-
if (value.account.toLowerCase() !== requestedAccount.toLowerCase())
|
|
37150
|
-
return false;
|
|
37151
|
-
if (typeof value.chainId !== "string") return false;
|
|
37152
|
-
if (!/^(0|[1-9]\d*)$/.test(value.chainId)) return false;
|
|
37153
|
-
const isLastNull = value.lastWithdrawNonce === null;
|
|
37154
|
-
const lastNonceValid = isLastNull || isUint256Decimal(value.lastWithdrawNonce);
|
|
37155
|
-
if (!lastNonceValid) return false;
|
|
37156
|
-
if (!isUint256Decimal(value.nextWithdrawNonce)) return false;
|
|
37157
|
-
if (isLastNull) {
|
|
37158
|
-
return value.nextWithdrawNonce === "1";
|
|
37159
|
-
}
|
|
37160
|
-
const lastNonce = BigInt(value.lastWithdrawNonce);
|
|
37161
|
-
const nextNonce = BigInt(value.nextWithdrawNonce);
|
|
37162
|
-
const expectedNextNonce = lastNonce + 1n;
|
|
37163
|
-
if (expectedNextNonce > 2n ** 256n - 1n) return false;
|
|
37164
|
-
return nextNonce === expectedNextNonce;
|
|
37165
|
-
}
|
|
37166
|
-
|
|
37167
37590
|
// src/direct/escrow-payment.ts
|
|
37168
37591
|
var GRANT_OP_TYPE = "grant";
|
|
37169
37592
|
var DATA_ACCESS_OP_TYPE = "data_access";
|
|
@@ -37400,8 +37823,8 @@ async function authorizeEscrowPayment(params) {
|
|
|
37400
37823
|
}
|
|
37401
37824
|
|
|
37402
37825
|
// src/direct/personal-server-read.ts
|
|
37403
|
-
var
|
|
37404
|
-
var
|
|
37826
|
+
var import_errors13 = require("./direct/errors.cjs");
|
|
37827
|
+
var import_errors14 = require("./errors.cjs");
|
|
37405
37828
|
function asRecord2(value) {
|
|
37406
37829
|
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
37407
37830
|
}
|
|
@@ -37445,7 +37868,7 @@ function parseLegacyGrantOperation(params) {
|
|
|
37445
37868
|
const { challengeGrantId, challengeOpId, challengeOpType, grantId } = params;
|
|
37446
37869
|
const opType = challengeOpType ?? GRANT_OP_TYPE;
|
|
37447
37870
|
if (opType !== GRANT_OP_TYPE) {
|
|
37448
|
-
throw new
|
|
37871
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37449
37872
|
"Personal Server payment challenge used an unsupported escrow op type",
|
|
37450
37873
|
402,
|
|
37451
37874
|
{ opType: challengeOpType }
|
|
@@ -37453,14 +37876,14 @@ function parseLegacyGrantOperation(params) {
|
|
|
37453
37876
|
}
|
|
37454
37877
|
const opId = challengeOpId ?? challengeGrantId ?? grantId;
|
|
37455
37878
|
if (!opId || !isBytes32Hex(opId)) {
|
|
37456
|
-
throw new
|
|
37879
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37457
37880
|
"Personal Server payment challenge used an invalid escrow op id",
|
|
37458
37881
|
402,
|
|
37459
37882
|
{ opId }
|
|
37460
37883
|
);
|
|
37461
37884
|
}
|
|
37462
37885
|
if (opId.toLowerCase() !== grantId.toLowerCase()) {
|
|
37463
|
-
throw new
|
|
37886
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37464
37887
|
"Personal Server payment challenge did not match the requested grant",
|
|
37465
37888
|
402,
|
|
37466
37889
|
{ opId, grantId }
|
|
@@ -37506,7 +37929,7 @@ function parseCanonicalDataAccessAccept(value) {
|
|
|
37506
37929
|
function parseCanonicalDataAccessPayment(params) {
|
|
37507
37930
|
const { body, grantId, raw } = params;
|
|
37508
37931
|
if (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED") {
|
|
37509
|
-
throw new
|
|
37932
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37510
37933
|
"Personal Server data-access payment response was not a canonical x402 challenge",
|
|
37511
37934
|
402
|
|
37512
37935
|
);
|
|
@@ -37545,20 +37968,20 @@ async function parsePersonalServerPaymentRequired(res, grantId) {
|
|
|
37545
37968
|
"accepts"
|
|
37546
37969
|
);
|
|
37547
37970
|
if (hasAcceptsEnvelope && (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED")) {
|
|
37548
|
-
throw new
|
|
37971
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37549
37972
|
"Personal Server grant payment response was not a canonical x402 challenge",
|
|
37550
37973
|
402
|
|
37551
37974
|
);
|
|
37552
37975
|
}
|
|
37553
37976
|
const accept = preferredLegacyAccept(body);
|
|
37554
37977
|
if (hasDataAccessMarker(body) && !accept) {
|
|
37555
|
-
throw new
|
|
37978
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37556
37979
|
"Personal Server data-access payment challenge was untrusted or incomplete",
|
|
37557
37980
|
402
|
|
37558
37981
|
);
|
|
37559
37982
|
}
|
|
37560
37983
|
if (hasAcceptsEnvelope && !accept) {
|
|
37561
|
-
throw new
|
|
37984
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37562
37985
|
"Personal Server grant payment challenge had no compatible escrow offer",
|
|
37563
37986
|
402
|
|
37564
37987
|
);
|
|
@@ -37576,7 +37999,7 @@ async function parsePersonalServerPaymentRequired(res, grantId) {
|
|
|
37576
37999
|
const accessRecord2 = parseAccessRecord(accept.accessRecord);
|
|
37577
38000
|
const hasAccessRecord = accept.accessRecord !== void 0;
|
|
37578
38001
|
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) {
|
|
37579
|
-
throw new
|
|
38002
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37580
38003
|
"Personal Server grant payment challenge was untrusted or incomplete",
|
|
37581
38004
|
402
|
|
37582
38005
|
);
|