@opendatalabs/vana-sdk 4.1.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.map +2 -2
- package/dist/index.node.cjs +858 -434
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +718 -292
- package/dist/index.node.js.map +4 -4
- 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-._~";
|
|
@@ -32547,7 +32547,7 @@ var MAX_JOB_DEADLINE_SECONDS = 3600;
|
|
|
32547
32547
|
// src/protocol/jobs-client.ts
|
|
32548
32548
|
var import_node_crypto = require("node:crypto");
|
|
32549
32549
|
var import_sha26 = require("@noble/hashes/sha2");
|
|
32550
|
-
var
|
|
32550
|
+
var import_viem17 = require("viem");
|
|
32551
32551
|
var import_accounts2 = require("viem/accounts");
|
|
32552
32552
|
|
|
32553
32553
|
// src/crypto/envelope/job.ts
|
|
@@ -33324,6 +33324,517 @@ async function openJobResult(sealedBytes, builderPrivateKey, ecies, expect) {
|
|
|
33324
33324
|
|
|
33325
33325
|
// src/protocol/jobs-client.ts
|
|
33326
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
|
+
}
|
|
33327
33838
|
|
|
33328
33839
|
// src/protocol/write-signer.ts
|
|
33329
33840
|
var import_errors2 = require("./errors.cjs");
|
|
@@ -33369,7 +33880,9 @@ function resolveWriteSigner(source, options = {}) {
|
|
|
33369
33880
|
// src/protocol/jobs-client.ts
|
|
33370
33881
|
var IDENTITY_PATH = "/v1/identity";
|
|
33371
33882
|
var JOBS_PATH = "/v1/jobs";
|
|
33883
|
+
var JOB_QUOTE_PATH = "/v1/jobs/quote";
|
|
33372
33884
|
var JOB_EXECUTE_PATH = "/v1/jobs/execute";
|
|
33885
|
+
var JOB_ACCESS_OP_TYPE = "job_access";
|
|
33373
33886
|
var AUTHORIZATION_HEADER = "Authorization";
|
|
33374
33887
|
var CONTENT_TYPE_HEADER = "Content-Type";
|
|
33375
33888
|
var JSON_CONTENT_TYPE = "application/json";
|
|
@@ -33383,7 +33896,11 @@ var HTTP_UNAUTHORIZED = 401;
|
|
|
33383
33896
|
var HTTP_FORBIDDEN = 403;
|
|
33384
33897
|
var HTTP_NOT_FOUND = 404;
|
|
33385
33898
|
var HTTP_CONFLICT = 409;
|
|
33899
|
+
var HTTP_PAYMENT_REQUIRED = 402;
|
|
33386
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*$/;
|
|
33387
33904
|
var MILLISECONDS_PER_SECOND = 1e3;
|
|
33388
33905
|
var DEFAULT_JOB_TIMEOUT_MS = 12e4;
|
|
33389
33906
|
var DEFAULT_JOB_POLL_MS = CLAIM_POLL_FLOOR_MS;
|
|
@@ -33466,11 +33983,17 @@ function resolveBuilder(options) {
|
|
|
33466
33983
|
"Builder signer must expose both address and publicKey"
|
|
33467
33984
|
);
|
|
33468
33985
|
}
|
|
33986
|
+
const typedDataSigner = source.signTypedData;
|
|
33469
33987
|
return {
|
|
33470
33988
|
builder: {
|
|
33471
33989
|
address: signer.address,
|
|
33472
33990
|
publicKey,
|
|
33473
|
-
signMessage: signer.signMessage
|
|
33991
|
+
signMessage: signer.signMessage,
|
|
33992
|
+
...typedDataSigner ? {
|
|
33993
|
+
signTypedData: typedDataSigner.bind(
|
|
33994
|
+
source
|
|
33995
|
+
)
|
|
33996
|
+
} : {}
|
|
33474
33997
|
},
|
|
33475
33998
|
...options.builderPrivateKey ? { privateKey: options.builderPrivateKey } : {}
|
|
33476
33999
|
};
|
|
@@ -33554,7 +34077,7 @@ function isResultHandle(value) {
|
|
|
33554
34077
|
function hasMatchingIdentityKey(value) {
|
|
33555
34078
|
const address = value["address"];
|
|
33556
34079
|
const publicKey = value["publicKey"];
|
|
33557
|
-
if (typeof address !== "string" || !(0,
|
|
34080
|
+
if (typeof address !== "string" || !(0, import_viem17.isAddress)(address) || typeof publicKey !== "string" || !(0, import_viem17.isHex)(publicKey)) {
|
|
33558
34081
|
return false;
|
|
33559
34082
|
}
|
|
33560
34083
|
try {
|
|
@@ -33567,14 +34090,59 @@ function hasExpectedIdentity(value, owner, chainId) {
|
|
|
33567
34090
|
const identityOwner = value["ownerAddress"];
|
|
33568
34091
|
const identityChainId = value["chainId"];
|
|
33569
34092
|
const identityUserPsId = value["userPsId"];
|
|
33570
|
-
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)) {
|
|
33571
34094
|
return false;
|
|
33572
34095
|
}
|
|
33573
|
-
return (0,
|
|
34096
|
+
return (0, import_viem17.isAddressEqual)(identityOwner, owner) && identityChainId === chainId && identityUserPsId.toLowerCase() === userPsId(chainId, owner).toLowerCase();
|
|
33574
34097
|
}
|
|
33575
34098
|
function sleep2(ms) {
|
|
33576
34099
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
33577
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
|
+
}
|
|
33578
34146
|
function requireFiniteDuration(value, field) {
|
|
33579
34147
|
if (!Number.isFinite(value)) {
|
|
33580
34148
|
throw new import_errors3.JobRejectedError(`${field} must be a finite number`);
|
|
@@ -33587,6 +34155,73 @@ function createJobsClient(options) {
|
|
|
33587
34155
|
const { builder, privateKey } = resolveBuilder(options);
|
|
33588
34156
|
const ecies = options.ecies ?? new NodeECIESUint8Provider();
|
|
33589
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
|
+
}
|
|
33590
34225
|
async function request(url, init, description) {
|
|
33591
34226
|
try {
|
|
33592
34227
|
return await fetchFn(url, init);
|
|
@@ -33642,7 +34277,8 @@ function createJobsClient(options) {
|
|
|
33642
34277
|
"deadlineSeconds"
|
|
33643
34278
|
);
|
|
33644
34279
|
const wait = clampInteger(params.wait, 0, 0, MAX_WAIT_SECONDS, "wait");
|
|
33645
|
-
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)();
|
|
33646
34282
|
const nowMs = now().getTime();
|
|
33647
34283
|
if (!Number.isFinite(nowMs)) {
|
|
33648
34284
|
throw new import_errors3.JobRejectedError("now must return a valid Date");
|
|
@@ -33680,32 +34316,41 @@ function createJobsClient(options) {
|
|
|
33680
34316
|
grantId: requestBody.grantId,
|
|
33681
34317
|
scope: requestBody.scope,
|
|
33682
34318
|
operation: requestBody.operation,
|
|
33683
|
-
idempotencyKey
|
|
34319
|
+
idempotencyKey,
|
|
33684
34320
|
jobId,
|
|
33685
34321
|
deadline,
|
|
33686
|
-
requestCiphertext
|
|
34322
|
+
requestCiphertext,
|
|
34323
|
+
...params.maxPrice === void 0 ? {} : { maxPrice: params.maxPrice }
|
|
33687
34324
|
};
|
|
33688
|
-
|
|
33689
|
-
|
|
33690
|
-
|
|
33691
|
-
|
|
33692
|
-
|
|
33693
|
-
|
|
33694
|
-
|
|
33695
|
-
|
|
33696
|
-
|
|
33697
|
-
|
|
33698
|
-
|
|
33699
|
-
|
|
33700
|
-
|
|
33701
|
-
|
|
33702
|
-
|
|
33703
|
-
|
|
33704
|
-
|
|
33705
|
-
|
|
33706
|
-
|
|
33707
|
-
|
|
33708
|
-
|
|
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
|
+
}
|
|
33709
34354
|
if (!response.ok) {
|
|
33710
34355
|
throw await rejectedResponse(response, "Job submission rejected");
|
|
33711
34356
|
}
|
|
@@ -33728,6 +34373,40 @@ function createJobsClient(options) {
|
|
|
33728
34373
|
response.status
|
|
33729
34374
|
);
|
|
33730
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
|
+
},
|
|
33731
34410
|
async getJob(jobId) {
|
|
33732
34411
|
const path = `${JOBS_PATH}/${encodeURIComponent(jobId)}`;
|
|
33733
34412
|
const authorization = await buildWeb3SignedHeader({
|
|
@@ -33819,7 +34498,7 @@ function createJobsClient(options) {
|
|
|
33819
34498
|
error
|
|
33820
34499
|
);
|
|
33821
34500
|
}
|
|
33822
|
-
const actualHash = (0,
|
|
34501
|
+
const actualHash = (0, import_viem17.bytesToHex)((0, import_sha26.sha256)(bytes));
|
|
33823
34502
|
if (actualHash.toLowerCase() !== handle.hash.toLowerCase()) {
|
|
33824
34503
|
throw new import_errors3.JobResultIntegrityError(
|
|
33825
34504
|
"Fetched job result hash does not match its handle",
|
|
@@ -33881,14 +34560,14 @@ function createJobsClient(options) {
|
|
|
33881
34560
|
}
|
|
33882
34561
|
|
|
33883
34562
|
// src/protocol/personal-server-registration.ts
|
|
33884
|
-
var
|
|
34563
|
+
var import_viem18 = require("viem");
|
|
33885
34564
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
33886
34565
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
33887
34566
|
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
33888
34567
|
"DataPortabilityServers"
|
|
33889
34568
|
);
|
|
33890
34569
|
function assertAddress(value, name) {
|
|
33891
|
-
if (!(0,
|
|
34570
|
+
if (!(0, import_viem18.isAddress)(value)) {
|
|
33892
34571
|
throw new Error(`${name} must be a valid EVM address`);
|
|
33893
34572
|
}
|
|
33894
34573
|
}
|
|
@@ -33974,12 +34653,12 @@ async function buildPersonalServerRegistrationSignature(input) {
|
|
|
33974
34653
|
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
33975
34654
|
|
|
33976
34655
|
// src/personal-server-lite/owner-binding.ts
|
|
33977
|
-
var
|
|
34656
|
+
var import_viem19 = require("viem");
|
|
33978
34657
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
33979
34658
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
33980
34659
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
33981
34660
|
function assertAddress2(value, name) {
|
|
33982
|
-
if (!(0,
|
|
34661
|
+
if (!(0, import_viem19.isAddress)(value)) {
|
|
33983
34662
|
throw new Error(`${name} must be a valid EVM address`);
|
|
33984
34663
|
}
|
|
33985
34664
|
}
|
|
@@ -34029,7 +34708,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
|
34029
34708
|
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
34030
34709
|
|
|
34031
34710
|
// src/account/personal-server-registration.ts
|
|
34032
|
-
var
|
|
34711
|
+
var import_viem20 = require("viem");
|
|
34033
34712
|
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
34034
34713
|
var AccountPersonalServerRegistrationError = class extends Error {
|
|
34035
34714
|
status;
|
|
@@ -34048,7 +34727,7 @@ function trimTrailingSlash(value) {
|
|
|
34048
34727
|
return value.replace(/\/+$/, "");
|
|
34049
34728
|
}
|
|
34050
34729
|
function assertAddress3(value, name) {
|
|
34051
|
-
if (!(0,
|
|
34730
|
+
if (!(0, import_viem20.isAddress)(value)) {
|
|
34052
34731
|
throw new Error(`${name} must be a valid EVM address`);
|
|
34053
34732
|
}
|
|
34054
34733
|
}
|
|
@@ -34312,7 +34991,7 @@ function accountOwnerBindingError(error) {
|
|
|
34312
34991
|
}
|
|
34313
34992
|
|
|
34314
34993
|
// src/protocol/grants.ts
|
|
34315
|
-
var
|
|
34994
|
+
var import_viem21 = require("viem");
|
|
34316
34995
|
function isHexString(value) {
|
|
34317
34996
|
return typeof value === "string" && value.startsWith("0x");
|
|
34318
34997
|
}
|
|
@@ -34357,7 +35036,7 @@ async function verifyGrantRegistration(input) {
|
|
|
34357
35036
|
}
|
|
34358
35037
|
let valid;
|
|
34359
35038
|
try {
|
|
34360
|
-
valid = await (0,
|
|
35039
|
+
valid = await (0, import_viem21.verifyTypedData)({
|
|
34361
35040
|
address: input.grantorAddress,
|
|
34362
35041
|
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
34363
35042
|
types: GRANT_REGISTRATION_TYPES,
|
|
@@ -34392,8 +35071,8 @@ async function verifyGrantRegistration(input) {
|
|
|
34392
35071
|
}
|
|
34393
35072
|
|
|
34394
35073
|
// src/protocol/fee-registry.ts
|
|
34395
|
-
var
|
|
34396
|
-
var FEE_REGISTRY_ABI = (0,
|
|
35074
|
+
var import_viem22 = require("viem");
|
|
35075
|
+
var FEE_REGISTRY_ABI = (0, import_viem22.parseAbi)([
|
|
34397
35076
|
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
34398
35077
|
"function fees(bytes32 operation) view returns (Fee)",
|
|
34399
35078
|
"function operationKey(string name) pure returns (bytes32)"
|
|
@@ -34476,8 +35155,8 @@ async function getOpFee(client, config, opType, opts) {
|
|
|
34476
35155
|
}
|
|
34477
35156
|
|
|
34478
35157
|
// src/protocol/escrow-deposit.ts
|
|
34479
|
-
var
|
|
34480
|
-
var
|
|
35158
|
+
var import_viem23 = require("viem");
|
|
35159
|
+
var ESCROW_DEPOSIT_ABI2 = [
|
|
34481
35160
|
{
|
|
34482
35161
|
type: "function",
|
|
34483
35162
|
name: "depositNative",
|
|
@@ -34501,15 +35180,15 @@ function escrowContractAddress(config) {
|
|
|
34501
35180
|
return config.contracts.dataPortabilityEscrow;
|
|
34502
35181
|
}
|
|
34503
35182
|
function encodeDepositNativeData(input) {
|
|
34504
|
-
return (0,
|
|
34505
|
-
abi:
|
|
35183
|
+
return (0, import_viem23.encodeFunctionData)({
|
|
35184
|
+
abi: ESCROW_DEPOSIT_ABI2,
|
|
34506
35185
|
functionName: "depositNative",
|
|
34507
35186
|
args: [input.account]
|
|
34508
35187
|
});
|
|
34509
35188
|
}
|
|
34510
35189
|
function encodeDepositTokenData(input) {
|
|
34511
|
-
return (0,
|
|
34512
|
-
abi:
|
|
35190
|
+
return (0, import_viem23.encodeFunctionData)({
|
|
35191
|
+
abi: ESCROW_DEPOSIT_ABI2,
|
|
34513
35192
|
functionName: "depositToken",
|
|
34514
35193
|
args: [input.account, input.token, input.amount]
|
|
34515
35194
|
});
|
|
@@ -34529,7 +35208,7 @@ function buildDepositTokenRequest(config, input) {
|
|
|
34529
35208
|
}
|
|
34530
35209
|
|
|
34531
35210
|
// src/protocol/data-point-status.ts
|
|
34532
|
-
var
|
|
35211
|
+
var import_viem24 = require("viem");
|
|
34533
35212
|
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
34534
35213
|
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
34535
35214
|
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
@@ -34553,7 +35232,7 @@ function dataRegistryContractAddress(config) {
|
|
|
34553
35232
|
return config.contracts.dataRegistry;
|
|
34554
35233
|
}
|
|
34555
35234
|
function encodeSetDataPointStatusData(input) {
|
|
34556
|
-
return (0,
|
|
35235
|
+
return (0, import_viem24.encodeFunctionData)({
|
|
34557
35236
|
abi: DATA_REGISTRY_STATUS_ABI,
|
|
34558
35237
|
functionName: "setStatus",
|
|
34559
35238
|
args: [input.scope, input.status]
|
|
@@ -34573,13 +35252,13 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
34573
35252
|
}
|
|
34574
35253
|
|
|
34575
35254
|
// src/protocol/data-point-deletion.ts
|
|
34576
|
-
var
|
|
34577
|
-
var
|
|
35255
|
+
var import_viem26 = require("viem");
|
|
35256
|
+
var import_errors6 = require("./errors.cjs");
|
|
34578
35257
|
|
|
34579
35258
|
// src/protocol/lineage.ts
|
|
34580
|
-
var
|
|
35259
|
+
var import_viem25 = require("viem");
|
|
34581
35260
|
var import_zod = require("zod");
|
|
34582
|
-
var
|
|
35261
|
+
var import_errors5 = require("./errors.cjs");
|
|
34583
35262
|
|
|
34584
35263
|
// src/protocol/personal-server-error-body.ts
|
|
34585
35264
|
function isRecord4(value) {
|
|
@@ -34616,13 +35295,13 @@ function isDataPointId(value) {
|
|
|
34616
35295
|
return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
|
|
34617
35296
|
}
|
|
34618
35297
|
function deriveDataPointId(ownerAddress, scope) {
|
|
34619
|
-
if (!(0,
|
|
35298
|
+
if (!(0, import_viem25.isAddress)(ownerAddress, { strict: false })) {
|
|
34620
35299
|
throw new Error(
|
|
34621
35300
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
34622
35301
|
);
|
|
34623
35302
|
}
|
|
34624
|
-
return (0,
|
|
34625
|
-
(0,
|
|
35303
|
+
return (0, import_viem25.keccak256)(
|
|
35304
|
+
(0, import_viem25.encodeAbiParameters)(
|
|
34626
35305
|
[
|
|
34627
35306
|
{ name: "ownerAddress", type: "address" },
|
|
34628
35307
|
{ name: "scope", type: "string" }
|
|
@@ -34651,7 +35330,7 @@ function derivedScopeViolatesNaming(derivedScope, sourceScope) {
|
|
|
34651
35330
|
function assertDerivedScopeNaming(derivedScope, sourceScopes) {
|
|
34652
35331
|
for (const sourceScope of sourceScopes) {
|
|
34653
35332
|
if (derivedScopeViolatesNaming(derivedScope, sourceScope)) {
|
|
34654
|
-
throw new
|
|
35333
|
+
throw new import_errors5.WriteRequestError(
|
|
34655
35334
|
`Derived scope ${derivedScope} must not share its first segment with source scope ${sourceScope}; put derivatives in the app's own namespace`,
|
|
34656
35335
|
{ scope: derivedScope, sourceScope }
|
|
34657
35336
|
);
|
|
@@ -34714,7 +35393,7 @@ function normalizeBaseUrl(url) {
|
|
|
34714
35393
|
function resolveFetch2(fetchFn) {
|
|
34715
35394
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
34716
35395
|
if (resolved === void 0) {
|
|
34717
|
-
throw new
|
|
35396
|
+
throw new import_errors5.LineageReadError("No fetch implementation available");
|
|
34718
35397
|
}
|
|
34719
35398
|
return resolved;
|
|
34720
35399
|
}
|
|
@@ -34722,7 +35401,7 @@ function normalizeVersion(version) {
|
|
|
34722
35401
|
if (version === void 0) return void 0;
|
|
34723
35402
|
const text = String(version);
|
|
34724
35403
|
if (!VERSION_PATTERN.test(text)) {
|
|
34725
|
-
throw new
|
|
35404
|
+
throw new import_errors5.LineageReadError(
|
|
34726
35405
|
"version must be a positive decimal integer",
|
|
34727
35406
|
void 0,
|
|
34728
35407
|
"INVALID_VERSION",
|
|
@@ -34733,7 +35412,7 @@ function normalizeVersion(version) {
|
|
|
34733
35412
|
}
|
|
34734
35413
|
async function lineageReadFailure(source, response) {
|
|
34735
35414
|
const { errorCode, message, details } = await readPersonalServerErrorBody(response);
|
|
34736
|
-
return new
|
|
35415
|
+
return new import_errors5.LineageReadError(
|
|
34737
35416
|
message ?? `${source} lineage read failed: ${response.status} ${response.statusText}`,
|
|
34738
35417
|
response.status,
|
|
34739
35418
|
errorCode,
|
|
@@ -34745,7 +35424,7 @@ async function parseLineageGraph(source, response) {
|
|
|
34745
35424
|
try {
|
|
34746
35425
|
body = await response.json();
|
|
34747
35426
|
} catch (err) {
|
|
34748
|
-
throw new
|
|
35427
|
+
throw new import_errors5.LineageReadError(
|
|
34749
35428
|
`${source} lineage response is not JSON`,
|
|
34750
35429
|
response.status,
|
|
34751
35430
|
null,
|
|
@@ -34755,7 +35434,7 @@ async function parseLineageGraph(source, response) {
|
|
|
34755
35434
|
const envelope = isRecord4(body) && isRecord4(body.data) ? body : void 0;
|
|
34756
35435
|
const parsed = LineageGraphSchema.safeParse(envelope?.data ?? body);
|
|
34757
35436
|
if (!parsed.success) {
|
|
34758
|
-
throw new
|
|
35437
|
+
throw new import_errors5.LineageReadError(
|
|
34759
35438
|
`${source} lineage response is not a lineage view`,
|
|
34760
35439
|
response.status,
|
|
34761
35440
|
null,
|
|
@@ -34770,7 +35449,7 @@ async function sendLineageRead(source, fetchFn, url, headers) {
|
|
|
34770
35449
|
try {
|
|
34771
35450
|
response = await fetchFn(url, { method: "GET", headers });
|
|
34772
35451
|
} catch (err) {
|
|
34773
|
-
throw new
|
|
35452
|
+
throw new import_errors5.LineageReadError(
|
|
34774
35453
|
`${source} lineage read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
34775
35454
|
void 0,
|
|
34776
35455
|
null,
|
|
@@ -34811,7 +35490,7 @@ async function getPersonalServerLineage(params) {
|
|
|
34811
35490
|
}
|
|
34812
35491
|
async function getGatewayLineage(params) {
|
|
34813
35492
|
if (!isDataPointId(params.dataPointId)) {
|
|
34814
|
-
throw new
|
|
35493
|
+
throw new import_errors5.LineageReadError(
|
|
34815
35494
|
"dataPointId must be a 32-byte hex string (see deriveDataPointId)",
|
|
34816
35495
|
void 0,
|
|
34817
35496
|
"INVALID_DATA_POINT_ID",
|
|
@@ -34848,7 +35527,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
34848
35527
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
34849
35528
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
34850
35529
|
function computeTombstoneHash(preimage) {
|
|
34851
|
-
return (0,
|
|
35530
|
+
return (0, import_viem26.keccak256)((0, import_viem26.stringToBytes)(preimage));
|
|
34852
35531
|
}
|
|
34853
35532
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
34854
35533
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -34867,12 +35546,12 @@ function tombstoneDeletedAt(value) {
|
|
|
34867
35546
|
return typeof deletedAt === "string" ? deletedAt : null;
|
|
34868
35547
|
}
|
|
34869
35548
|
function assertAddress4(value, name) {
|
|
34870
|
-
if (!(0,
|
|
35549
|
+
if (!(0, import_viem26.isAddress)(value)) {
|
|
34871
35550
|
throw new Error(`${name} must be a valid EVM address`);
|
|
34872
35551
|
}
|
|
34873
35552
|
}
|
|
34874
35553
|
function assertUint256(value, name) {
|
|
34875
|
-
if (value < 0n || value >
|
|
35554
|
+
if (value < 0n || value > import_viem26.maxUint256) {
|
|
34876
35555
|
throw new Error(`${name} must fit in uint256, got ${value}`);
|
|
34877
35556
|
}
|
|
34878
35557
|
}
|
|
@@ -34957,13 +35636,13 @@ async function deleteDataPoint(input) {
|
|
|
34957
35636
|
if (currentVersion === void 0) {
|
|
34958
35637
|
const record = await input.gateway.getDataPoint(dataPointId);
|
|
34959
35638
|
if (record === null) {
|
|
34960
|
-
throw new
|
|
35639
|
+
throw new import_errors6.DataPointNotFoundError(
|
|
34961
35640
|
`No data point registered for scope '${input.scope}' owned by ${ownerAddress}`,
|
|
34962
35641
|
{ dataPointId, scope: input.scope, ownerAddress }
|
|
34963
35642
|
);
|
|
34964
35643
|
}
|
|
34965
35644
|
if (isDataPointTombstone(record)) {
|
|
34966
|
-
throw new
|
|
35645
|
+
throw new import_errors6.DataPointDeletedError(
|
|
34967
35646
|
`Data point ${dataPointId} (scope '${input.scope}') is already deleted`,
|
|
34968
35647
|
{
|
|
34969
35648
|
dataPointId,
|
|
@@ -34975,7 +35654,7 @@ async function deleteDataPoint(input) {
|
|
|
34975
35654
|
}
|
|
34976
35655
|
currentVersion = parseExpectedVersion(record.expectedVersion);
|
|
34977
35656
|
}
|
|
34978
|
-
if (currentVersion < 0n || currentVersion >=
|
|
35657
|
+
if (currentVersion < 0n || currentVersion >= import_viem26.maxUint256) {
|
|
34979
35658
|
throw new Error(
|
|
34980
35659
|
`currentVersion ${currentVersion} cannot be incremented to a uint256 tombstone version`
|
|
34981
35660
|
);
|
|
@@ -35010,7 +35689,7 @@ async function deleteDataPoint(input) {
|
|
|
35010
35689
|
}
|
|
35011
35690
|
|
|
35012
35691
|
// src/protocol/personal-server-data.ts
|
|
35013
|
-
var
|
|
35692
|
+
var import_errors7 = require("./errors.cjs");
|
|
35014
35693
|
|
|
35015
35694
|
// src/protocol/data-file.ts
|
|
35016
35695
|
var import_zod2 = require("zod");
|
|
@@ -35070,7 +35749,7 @@ async function readPersonalServerData(params) {
|
|
|
35070
35749
|
const request = await buildPersonalServerDataReadRequest(params);
|
|
35071
35750
|
const response = await fetchFn(request);
|
|
35072
35751
|
if (response.status === 410) {
|
|
35073
|
-
throw new
|
|
35752
|
+
throw new import_errors7.DataPointDeletedError(
|
|
35074
35753
|
`Personal Server scope '${params.scope}' has been deleted`,
|
|
35075
35754
|
{
|
|
35076
35755
|
scope: params.scope,
|
|
@@ -35085,7 +35764,7 @@ async function readPersonalServerData(params) {
|
|
|
35085
35764
|
}
|
|
35086
35765
|
const body = await response.json();
|
|
35087
35766
|
if (isDataPointTombstone(body)) {
|
|
35088
|
-
throw new
|
|
35767
|
+
throw new import_errors7.DataPointDeletedError(
|
|
35089
35768
|
`Personal Server scope '${params.scope}' has been deleted`,
|
|
35090
35769
|
{ scope: params.scope, deletedAt: tombstoneDeletedAt(body) }
|
|
35091
35770
|
);
|
|
@@ -35286,21 +35965,21 @@ function tryGrantPermissions(scopes) {
|
|
|
35286
35965
|
|
|
35287
35966
|
// src/protocol/personal-server-write.ts
|
|
35288
35967
|
var import_sha28 = require("@noble/hashes/sha2");
|
|
35289
|
-
var
|
|
35968
|
+
var import_viem28 = require("viem");
|
|
35290
35969
|
var import_zod4 = require("zod");
|
|
35291
|
-
var
|
|
35970
|
+
var import_errors9 = require("./errors.cjs");
|
|
35292
35971
|
|
|
35293
35972
|
// src/protocol/write-request.ts
|
|
35294
35973
|
var import_sha27 = require("@noble/hashes/sha2");
|
|
35295
|
-
var
|
|
35296
|
-
var
|
|
35974
|
+
var import_viem27 = require("viem");
|
|
35975
|
+
var import_errors8 = require("./errors.cjs");
|
|
35297
35976
|
function normalizeBaseUrl2(url) {
|
|
35298
35977
|
return url.replace(/\/+$/, "");
|
|
35299
35978
|
}
|
|
35300
35979
|
function resolveFetch3(fetchFn) {
|
|
35301
35980
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
35302
35981
|
if (resolved === void 0) {
|
|
35303
|
-
throw new
|
|
35982
|
+
throw new import_errors8.WriteRequestError("No fetch implementation available");
|
|
35304
35983
|
}
|
|
35305
35984
|
return resolved;
|
|
35306
35985
|
}
|
|
@@ -35360,14 +36039,14 @@ function freshProofNonce() {
|
|
|
35360
36039
|
return webCrypto2.randomUUID();
|
|
35361
36040
|
}
|
|
35362
36041
|
if (typeof webCrypto2?.getRandomValues === "function") {
|
|
35363
|
-
return (0,
|
|
36042
|
+
return (0, import_viem27.bytesToHex)(webCrypto2.getRandomValues(new Uint8Array(16)));
|
|
35364
36043
|
}
|
|
35365
|
-
throw new
|
|
36044
|
+
throw new import_errors8.WriteRequestError(
|
|
35366
36045
|
"No secure random source available to build a proof nonce; provide a crypto global"
|
|
35367
36046
|
);
|
|
35368
36047
|
}
|
|
35369
36048
|
function proofKeyFor(parts) {
|
|
35370
|
-
return (0,
|
|
36049
|
+
return (0, import_viem27.bytesToHex)(
|
|
35371
36050
|
(0, import_sha27.sha256)(
|
|
35372
36051
|
new TextEncoder().encode(
|
|
35373
36052
|
JSON.stringify([
|
|
@@ -35375,7 +36054,7 @@ function proofKeyFor(parts) {
|
|
|
35375
36054
|
parts.method,
|
|
35376
36055
|
parts.uri,
|
|
35377
36056
|
parts.grantId,
|
|
35378
|
-
parts.signedBytes ? (0,
|
|
36057
|
+
parts.signedBytes ? (0, import_viem27.bytesToHex)((0, import_sha27.sha256)(parts.signedBytes)) : ""
|
|
35379
36058
|
])
|
|
35380
36059
|
)
|
|
35381
36060
|
)
|
|
@@ -35397,7 +36076,7 @@ async function sendWithFreshProof(label, fetchFn, options, proofKey, build) {
|
|
|
35397
36076
|
delayMs *= 2;
|
|
35398
36077
|
}
|
|
35399
36078
|
}
|
|
35400
|
-
throw new
|
|
36079
|
+
throw new import_errors8.WriteTransportError(
|
|
35401
36080
|
`${label} failed after ${attempts} attempt(s): ${errorMessage(lastError)}`,
|
|
35402
36081
|
attempts,
|
|
35403
36082
|
lastError
|
|
@@ -35468,7 +36147,7 @@ async function openWriteSession(params) {
|
|
|
35468
36147
|
const mintedAt = Date.now();
|
|
35469
36148
|
if (!response.ok) {
|
|
35470
36149
|
const { errorCode, message, details } = await readPersonalServerErrorBody(response);
|
|
35471
|
-
throw new
|
|
36150
|
+
throw new import_errors9.WriteSessionError(
|
|
35472
36151
|
message ?? `Write session handshake failed: ${response.status} ${response.statusText}`,
|
|
35473
36152
|
response.status,
|
|
35474
36153
|
errorCode,
|
|
@@ -35479,7 +36158,7 @@ async function openWriteSession(params) {
|
|
|
35479
36158
|
try {
|
|
35480
36159
|
body = await response.json();
|
|
35481
36160
|
} catch (err) {
|
|
35482
|
-
throw new
|
|
36161
|
+
throw new import_errors9.WriteSessionError(
|
|
35483
36162
|
"Write session response is not JSON",
|
|
35484
36163
|
response.status,
|
|
35485
36164
|
null,
|
|
@@ -35488,7 +36167,7 @@ async function openWriteSession(params) {
|
|
|
35488
36167
|
}
|
|
35489
36168
|
const parsed = WriteSessionResponseSchema.safeParse(body);
|
|
35490
36169
|
if (!parsed.success) {
|
|
35491
|
-
throw new
|
|
36170
|
+
throw new import_errors9.WriteSessionError(
|
|
35492
36171
|
"Write session response is not a session",
|
|
35493
36172
|
response.status,
|
|
35494
36173
|
null,
|
|
@@ -35496,7 +36175,7 @@ async function openWriteSession(params) {
|
|
|
35496
36175
|
);
|
|
35497
36176
|
}
|
|
35498
36177
|
if (parsed.data.token_type.toLowerCase() !== "bearer") {
|
|
35499
|
-
throw new
|
|
36178
|
+
throw new import_errors9.WriteSessionError(
|
|
35500
36179
|
`Write session token type is not Bearer: ${parsed.data.token_type}`,
|
|
35501
36180
|
response.status
|
|
35502
36181
|
);
|
|
@@ -35518,7 +36197,7 @@ function isWriteSession(value) {
|
|
|
35518
36197
|
}
|
|
35519
36198
|
function sessionCoversScope(session, scope) {
|
|
35520
36199
|
if (!isRecord4(session) || !Array.isArray(session.writeScopes) || !session.writeScopes.every((pattern) => typeof pattern === "string")) {
|
|
35521
|
-
throw new
|
|
36200
|
+
throw new import_errors9.WriteRequestError("session must come from openWriteSession");
|
|
35522
36201
|
}
|
|
35523
36202
|
return session.writeScopes.some(
|
|
35524
36203
|
(pattern) => scopeMatchesPattern(scope, pattern)
|
|
@@ -35543,12 +36222,12 @@ function encodeWriteMetadataHeader(metadata) {
|
|
|
35543
36222
|
try {
|
|
35544
36223
|
json = JSON.stringify(metadata);
|
|
35545
36224
|
} catch (err) {
|
|
35546
|
-
throw new
|
|
36225
|
+
throw new import_errors9.WriteRequestError(
|
|
35547
36226
|
`metadata is not JSON-serialisable: ${errorMessage(err)}`
|
|
35548
36227
|
);
|
|
35549
36228
|
}
|
|
35550
36229
|
if (typeof json !== "string") {
|
|
35551
|
-
throw new
|
|
36230
|
+
throw new import_errors9.WriteRequestError("metadata must serialise to JSON");
|
|
35552
36231
|
}
|
|
35553
36232
|
return json.replace(
|
|
35554
36233
|
/[\u007f-\uffff]/g,
|
|
@@ -35562,7 +36241,7 @@ function binaryWriteSignedBytes(input) {
|
|
|
35562
36241
|
mimeType: normalizeBinaryMimeType(input.contentType),
|
|
35563
36242
|
...input.filename ? { filename: input.filename } : {},
|
|
35564
36243
|
sizeBytes: input.bytes.length,
|
|
35565
|
-
contentHash: (0,
|
|
36244
|
+
contentHash: (0, import_viem28.bytesToHex)((0, import_sha28.sha256)(input.bytes)),
|
|
35566
36245
|
encoding: "base64",
|
|
35567
36246
|
content: toBase64(input.bytes),
|
|
35568
36247
|
...metadata !== void 0 ? { metadata } : {}
|
|
@@ -35583,7 +36262,7 @@ function setFilenameHeader(headers, filename) {
|
|
|
35583
36262
|
function assertNoReservedKeys(value, where) {
|
|
35584
36263
|
for (const key of RESERVED_WRITE_KEYS) {
|
|
35585
36264
|
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
35586
|
-
throw new
|
|
36265
|
+
throw new import_errors9.WriteRequestError(
|
|
35587
36266
|
`${where} must not contain the reserved ${key} key; the Personal Server stamps it`,
|
|
35588
36267
|
{ key }
|
|
35589
36268
|
);
|
|
@@ -35595,10 +36274,10 @@ function isLineagePair(value) {
|
|
|
35595
36274
|
}
|
|
35596
36275
|
function normalizeLineage(lineage, derivedScope) {
|
|
35597
36276
|
if (!Array.isArray(lineage)) {
|
|
35598
|
-
throw new
|
|
36277
|
+
throw new import_errors9.WriteRequestError("lineage must be an array of data point ids");
|
|
35599
36278
|
}
|
|
35600
36279
|
if (lineage.length > MAX_LINEAGE_SOURCES) {
|
|
35601
|
-
throw new
|
|
36280
|
+
throw new import_errors9.WriteRequestError(
|
|
35602
36281
|
`lineage lists ${lineage.length} sources; the maximum is ${MAX_LINEAGE_SOURCES}`,
|
|
35603
36282
|
{ max: MAX_LINEAGE_SOURCES, count: lineage.length }
|
|
35604
36283
|
);
|
|
@@ -35610,14 +36289,14 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
35610
36289
|
for (const entry of lineage) {
|
|
35611
36290
|
let id;
|
|
35612
36291
|
if (isLineagePair(entry)) {
|
|
35613
|
-
if (!(0,
|
|
35614
|
-
throw new
|
|
36292
|
+
if (!(0, import_viem28.isAddress)(entry.ownerAddress, { strict: false })) {
|
|
36293
|
+
throw new import_errors9.WriteRequestError(
|
|
35615
36294
|
"lineage source ownerAddress must be an EVM address",
|
|
35616
36295
|
{ ownerAddress: entry.ownerAddress }
|
|
35617
36296
|
);
|
|
35618
36297
|
}
|
|
35619
36298
|
if (entry.scope.length === 0) {
|
|
35620
|
-
throw new
|
|
36299
|
+
throw new import_errors9.WriteRequestError("lineage source scope is required");
|
|
35621
36300
|
}
|
|
35622
36301
|
id = deriveDataPointId(entry.ownerAddress, entry.scope);
|
|
35623
36302
|
sourceScopes.push(entry.scope);
|
|
@@ -35625,14 +36304,14 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
35625
36304
|
} else if (isDataPointId(entry)) {
|
|
35626
36305
|
id = entry;
|
|
35627
36306
|
} else {
|
|
35628
|
-
throw new
|
|
36307
|
+
throw new import_errors9.WriteRequestError(
|
|
35629
36308
|
"lineage entries must be 32-byte hex data point ids or { ownerAddress, scope } pairs",
|
|
35630
36309
|
{ entry }
|
|
35631
36310
|
);
|
|
35632
36311
|
}
|
|
35633
36312
|
const normalized = id.toLowerCase();
|
|
35634
36313
|
if (seen.has(normalized)) {
|
|
35635
|
-
throw new
|
|
36314
|
+
throw new import_errors9.WriteRequestError("lineage must not repeat a data point id", {
|
|
35636
36315
|
dataPointId: normalized
|
|
35637
36316
|
});
|
|
35638
36317
|
}
|
|
@@ -35641,7 +36320,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
35641
36320
|
}
|
|
35642
36321
|
for (const own of ownIds) {
|
|
35643
36322
|
if (seen.has(own)) {
|
|
35644
|
-
throw new
|
|
36323
|
+
throw new import_errors9.WriteRequestError(
|
|
35645
36324
|
"lineage must not cite the record's own data point",
|
|
35646
36325
|
{ dataPointId: own, scope: derivedScope }
|
|
35647
36326
|
);
|
|
@@ -35652,7 +36331,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
35652
36331
|
}
|
|
35653
36332
|
function assertNoLineageField(value, where) {
|
|
35654
36333
|
if (Object.prototype.hasOwnProperty.call(value, LINEAGE_FIELD)) {
|
|
35655
|
-
throw new
|
|
36334
|
+
throw new import_errors9.WriteRequestError(
|
|
35656
36335
|
`${where}.${LINEAGE_FIELD} is reserved; pass sources through the lineage option`
|
|
35657
36336
|
);
|
|
35658
36337
|
}
|
|
@@ -35660,7 +36339,7 @@ function assertNoLineageField(value, where) {
|
|
|
35660
36339
|
function buildMetadataHeader(metadata, sources) {
|
|
35661
36340
|
if (metadata !== void 0) {
|
|
35662
36341
|
if (!isRecord4(metadata)) {
|
|
35663
|
-
throw new
|
|
36342
|
+
throw new import_errors9.WriteRequestError("metadata must be a plain object");
|
|
35664
36343
|
}
|
|
35665
36344
|
assertNoReservedKeys(metadata, "metadata");
|
|
35666
36345
|
assertNoLineageField(metadata, "metadata");
|
|
@@ -35673,24 +36352,24 @@ function buildMetadataHeader(metadata, sources) {
|
|
|
35673
36352
|
}
|
|
35674
36353
|
function prepareWrite(params) {
|
|
35675
36354
|
if (params.binary !== void 0 && params.data !== void 0) {
|
|
35676
|
-
throw new
|
|
36355
|
+
throw new import_errors9.WriteRequestError("Pass either data or binary, not both");
|
|
35677
36356
|
}
|
|
35678
36357
|
const rawLineage = params.lineage;
|
|
35679
36358
|
const sources = rawLineage === void 0 || rawLineage === null ? void 0 : normalizeLineage(rawLineage, params.scope);
|
|
35680
36359
|
if (params.binary !== void 0) {
|
|
35681
36360
|
const { bytes, contentType, filename } = params.binary;
|
|
35682
36361
|
if (!(bytes instanceof Uint8Array)) {
|
|
35683
|
-
throw new
|
|
36362
|
+
throw new import_errors9.WriteRequestError("binary.bytes must be a Uint8Array");
|
|
35684
36363
|
}
|
|
35685
36364
|
if (typeof contentType !== "string" || contentType.trim() === "") {
|
|
35686
|
-
throw new
|
|
36365
|
+
throw new import_errors9.WriteRequestError("binary.contentType is required");
|
|
35687
36366
|
}
|
|
35688
36367
|
if (filename !== void 0) {
|
|
35689
36368
|
if (typeof filename !== "string") {
|
|
35690
|
-
throw new
|
|
36369
|
+
throw new import_errors9.WriteRequestError("binary.filename must be a string");
|
|
35691
36370
|
}
|
|
35692
36371
|
if (filename !== filename.trim()) {
|
|
35693
|
-
throw new
|
|
36372
|
+
throw new import_errors9.WriteRequestError(
|
|
35694
36373
|
"binary.filename must not have leading or trailing whitespace"
|
|
35695
36374
|
);
|
|
35696
36375
|
}
|
|
@@ -35710,13 +36389,13 @@ function prepareWrite(params) {
|
|
|
35710
36389
|
};
|
|
35711
36390
|
}
|
|
35712
36391
|
if (params.data === void 0) {
|
|
35713
|
-
throw new
|
|
36392
|
+
throw new import_errors9.WriteRequestError("Pass data (a JSON object) or binary");
|
|
35714
36393
|
}
|
|
35715
36394
|
if (!isRecord4(params.data)) {
|
|
35716
|
-
throw new
|
|
36395
|
+
throw new import_errors9.WriteRequestError("data must be a plain JSON object");
|
|
35717
36396
|
}
|
|
35718
36397
|
if (params.metadata !== void 0) {
|
|
35719
|
-
throw new
|
|
36398
|
+
throw new import_errors9.WriteRequestError(
|
|
35720
36399
|
"metadata applies to binary writes; put fields to store inside data"
|
|
35721
36400
|
);
|
|
35722
36401
|
}
|
|
@@ -35727,12 +36406,12 @@ function prepareWrite(params) {
|
|
|
35727
36406
|
try {
|
|
35728
36407
|
text = JSON.stringify(record);
|
|
35729
36408
|
} catch (err) {
|
|
35730
|
-
throw new
|
|
36409
|
+
throw new import_errors9.WriteRequestError(
|
|
35731
36410
|
`data is not JSON-serialisable: ${errorMessage(err)}`
|
|
35732
36411
|
);
|
|
35733
36412
|
}
|
|
35734
36413
|
if (typeof text !== "string" || !text.startsWith("{")) {
|
|
35735
|
-
throw new
|
|
36414
|
+
throw new import_errors9.WriteRequestError("data must serialise to a JSON object");
|
|
35736
36415
|
}
|
|
35737
36416
|
const body = new TextEncoder().encode(text);
|
|
35738
36417
|
return {
|
|
@@ -35745,31 +36424,31 @@ async function writeErrorFromResponse(response) {
|
|
|
35745
36424
|
const { errorCode, message, details } = await readPersonalServerErrorBody(response);
|
|
35746
36425
|
const text = message ?? `Personal Server write failed: ${response.status} ${response.statusText}`;
|
|
35747
36426
|
if (response.status === 422 || errorCode?.startsWith("LINEAGE_")) {
|
|
35748
|
-
return new
|
|
36427
|
+
return new import_errors9.WriteLineageError(text, response.status, errorCode, details);
|
|
35749
36428
|
}
|
|
35750
36429
|
switch (response.status) {
|
|
35751
36430
|
case 401:
|
|
35752
|
-
return new
|
|
36431
|
+
return new import_errors9.WriteUnauthorizedError(text, errorCode, details);
|
|
35753
36432
|
case 403:
|
|
35754
|
-
return new
|
|
36433
|
+
return new import_errors9.WriteForbiddenError(text, errorCode, details);
|
|
35755
36434
|
case 409:
|
|
35756
|
-
return new
|
|
36435
|
+
return new import_errors9.WriteConflictError(text, errorCode, details);
|
|
35757
36436
|
default:
|
|
35758
|
-
return new
|
|
36437
|
+
return new import_errors9.WriteRejectedError(text, response.status, errorCode, details);
|
|
35759
36438
|
}
|
|
35760
36439
|
}
|
|
35761
36440
|
async function writeData(params) {
|
|
35762
36441
|
const { session } = params;
|
|
35763
36442
|
if (!isWriteSession(session)) {
|
|
35764
|
-
throw new
|
|
36443
|
+
throw new import_errors9.WriteRequestError("session must come from openWriteSession");
|
|
35765
36444
|
}
|
|
35766
36445
|
const fetchFn = resolveFetch3(params.fetch);
|
|
35767
36446
|
if (typeof params.scope !== "string" || params.scope.length === 0) {
|
|
35768
|
-
throw new
|
|
36447
|
+
throw new import_errors9.WriteRequestError("scope is required");
|
|
35769
36448
|
}
|
|
35770
36449
|
const prepared = prepareWrite(params);
|
|
35771
36450
|
if (Date.now() >= session.expiresAt) {
|
|
35772
|
-
throw new
|
|
36451
|
+
throw new import_errors9.WriteSessionExpiredError(
|
|
35773
36452
|
"Write session has expired; open a new session",
|
|
35774
36453
|
{ grantId: session.grantId, expiresAt: session.expiresAt }
|
|
35775
36454
|
);
|
|
@@ -35825,7 +36504,7 @@ async function writeData(params) {
|
|
|
35825
36504
|
try {
|
|
35826
36505
|
body = await response.json();
|
|
35827
36506
|
} catch (err) {
|
|
35828
|
-
throw new
|
|
36507
|
+
throw new import_errors9.WriteRejectedError(
|
|
35829
36508
|
"Personal Server write response is not JSON",
|
|
35830
36509
|
response.status,
|
|
35831
36510
|
null,
|
|
@@ -35834,7 +36513,7 @@ async function writeData(params) {
|
|
|
35834
36513
|
}
|
|
35835
36514
|
const parsed = WriteDataResultSchema.safeParse(body);
|
|
35836
36515
|
if (!parsed.success) {
|
|
35837
|
-
throw new
|
|
36516
|
+
throw new import_errors9.WriteRejectedError(
|
|
35838
36517
|
"Personal Server write response is not an ingest result",
|
|
35839
36518
|
response.status,
|
|
35840
36519
|
null,
|
|
@@ -35861,7 +36540,7 @@ async function writePersonalServerData(params) {
|
|
|
35861
36540
|
|
|
35862
36541
|
// src/protocol/derivative-questions.ts
|
|
35863
36542
|
var import_zod5 = require("zod");
|
|
35864
|
-
var
|
|
36543
|
+
var import_errors10 = require("./errors.cjs");
|
|
35865
36544
|
var DERIVATIVE_QUESTIONS_PATH = "/v1/derivatives/questions";
|
|
35866
36545
|
var MAX_QUESTION_SOURCE_SCOPES = 16;
|
|
35867
36546
|
var MAX_QUESTION_CHARS = 8e3;
|
|
@@ -35944,15 +36623,15 @@ function fetchIdOf(fetchFn) {
|
|
|
35944
36623
|
}
|
|
35945
36624
|
function resolveRequest(params) {
|
|
35946
36625
|
if (typeof params.personalServerUrl !== "string" || params.personalServerUrl.length === 0) {
|
|
35947
|
-
throw new
|
|
36626
|
+
throw new import_errors10.WriteRequestError("personalServerUrl is required");
|
|
35948
36627
|
}
|
|
35949
36628
|
if (typeof params.grantId !== "string" || params.grantId.length === 0) {
|
|
35950
|
-
throw new
|
|
36629
|
+
throw new import_errors10.WriteRequestError(
|
|
35951
36630
|
"grantId is required; a question call runs under the grant carrying write:<derivedScope>"
|
|
35952
36631
|
);
|
|
35953
36632
|
}
|
|
35954
36633
|
if (params.signer === null || typeof params.signer !== "object") {
|
|
35955
|
-
throw new
|
|
36634
|
+
throw new import_errors10.WriteRequestError(
|
|
35956
36635
|
"signer must be a viem LocalAccount, a viem WalletClient, or a { signMessage } object"
|
|
35957
36636
|
);
|
|
35958
36637
|
}
|
|
@@ -36006,37 +36685,37 @@ async function questionErrorFromResponse(response, body) {
|
|
|
36006
36685
|
const text = message ?? `Derivative question request failed: ${response.status} ${response.statusText}`;
|
|
36007
36686
|
switch (errorCode) {
|
|
36008
36687
|
case "DERIVATIVE_SOURCE_NOT_GRANTED":
|
|
36009
|
-
return new
|
|
36688
|
+
return new import_errors10.DerivativeSourceNotGrantedError(text, errorCode, details);
|
|
36010
36689
|
case "DERIVATIVE_CYCLE":
|
|
36011
|
-
return new
|
|
36690
|
+
return new import_errors10.DerivativeCycleError(text, errorCode, details);
|
|
36012
36691
|
case "DERIVATIVE_COMPUTE_UNAVAILABLE":
|
|
36013
|
-
return new
|
|
36692
|
+
return new import_errors10.DerivativeComputeUnavailableError(text, errorCode, details);
|
|
36014
36693
|
case "DERIVATIVE_QUESTION_INVALID":
|
|
36015
36694
|
case "LINEAGE_SCOPE_UNDER_SOURCE_PREFIX":
|
|
36016
|
-
return new
|
|
36695
|
+
return new import_errors10.DerivativeQuestionInvalidError(
|
|
36017
36696
|
text,
|
|
36018
36697
|
response.status,
|
|
36019
36698
|
errorCode,
|
|
36020
36699
|
details
|
|
36021
36700
|
);
|
|
36022
36701
|
case "DERIVATIVE_QUESTION_NOT_FOUND":
|
|
36023
|
-
return new
|
|
36702
|
+
return new import_errors10.DerivativeQuestionNotFoundError(text, errorCode, details);
|
|
36024
36703
|
case "DERIVATIVE_DERIVED_SCOPE_REQUIRED":
|
|
36025
|
-
return new
|
|
36704
|
+
return new import_errors10.DerivativeDerivedScopeRequiredError(text, errorCode, details);
|
|
36026
36705
|
default:
|
|
36027
36706
|
break;
|
|
36028
36707
|
}
|
|
36029
36708
|
switch (response.status) {
|
|
36030
36709
|
case 401:
|
|
36031
|
-
return new
|
|
36710
|
+
return new import_errors10.WriteUnauthorizedError(text, errorCode, details);
|
|
36032
36711
|
case 403:
|
|
36033
|
-
return new
|
|
36712
|
+
return new import_errors10.WriteForbiddenError(text, errorCode, details);
|
|
36034
36713
|
case 404:
|
|
36035
|
-
return new
|
|
36714
|
+
return new import_errors10.DerivativeQuestionNotFoundError(text, errorCode, details);
|
|
36036
36715
|
case 409:
|
|
36037
|
-
return new
|
|
36716
|
+
return new import_errors10.WriteConflictError(text, errorCode, details);
|
|
36038
36717
|
default:
|
|
36039
|
-
return new
|
|
36718
|
+
return new import_errors10.DerivativeQuestionRejectedError(
|
|
36040
36719
|
text,
|
|
36041
36720
|
response.status,
|
|
36042
36721
|
errorCode,
|
|
@@ -36116,7 +36795,7 @@ async function sendQuestionRequest(params, spec, schema) {
|
|
|
36116
36795
|
try {
|
|
36117
36796
|
body = await response.json();
|
|
36118
36797
|
} catch (err) {
|
|
36119
|
-
throw new
|
|
36798
|
+
throw new import_errors10.DerivativeQuestionRejectedError(
|
|
36120
36799
|
`${spec.label} response is not JSON`,
|
|
36121
36800
|
response.status,
|
|
36122
36801
|
null,
|
|
@@ -36125,7 +36804,7 @@ async function sendQuestionRequest(params, spec, schema) {
|
|
|
36125
36804
|
}
|
|
36126
36805
|
const parsed = schema.safeParse(body);
|
|
36127
36806
|
if (!parsed.success) {
|
|
36128
|
-
throw new
|
|
36807
|
+
throw new import_errors10.DerivativeQuestionRejectedError(
|
|
36129
36808
|
`${spec.label} response is not a derivative question answer`,
|
|
36130
36809
|
response.status,
|
|
36131
36810
|
null,
|
|
@@ -36136,22 +36815,22 @@ async function sendQuestionRequest(params, spec, schema) {
|
|
|
36136
36815
|
}
|
|
36137
36816
|
function assertQuestionId(questionId) {
|
|
36138
36817
|
if (typeof questionId !== "string" || questionId.length === 0) {
|
|
36139
|
-
throw new
|
|
36818
|
+
throw new import_errors10.WriteRequestError("questionId is required");
|
|
36140
36819
|
}
|
|
36141
36820
|
return `${DERIVATIVE_QUESTIONS_PATH}/${encodeURIComponent(questionId)}`;
|
|
36142
36821
|
}
|
|
36143
36822
|
function registrationBody(params) {
|
|
36144
36823
|
const { derivedScope, question } = params;
|
|
36145
36824
|
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
36146
|
-
throw new
|
|
36825
|
+
throw new import_errors10.WriteRequestError("derivedScope is required");
|
|
36147
36826
|
}
|
|
36148
36827
|
if (!Array.isArray(params.sourceScopes) || params.sourceScopes.length === 0) {
|
|
36149
|
-
throw new
|
|
36828
|
+
throw new import_errors10.WriteRequestError(
|
|
36150
36829
|
"sourceScopes must be a non-empty array of scopes"
|
|
36151
36830
|
);
|
|
36152
36831
|
}
|
|
36153
36832
|
if (params.sourceScopes.length > MAX_QUESTION_SOURCE_SCOPES) {
|
|
36154
|
-
throw new
|
|
36833
|
+
throw new import_errors10.WriteRequestError(
|
|
36155
36834
|
`sourceScopes lists ${params.sourceScopes.length} scopes; the maximum is ${MAX_QUESTION_SOURCE_SCOPES}`,
|
|
36156
36835
|
{ max: MAX_QUESTION_SOURCE_SCOPES, count: params.sourceScopes.length }
|
|
36157
36836
|
);
|
|
@@ -36159,15 +36838,15 @@ function registrationBody(params) {
|
|
|
36159
36838
|
const sourceScopes = [];
|
|
36160
36839
|
for (const scope of params.sourceScopes) {
|
|
36161
36840
|
if (typeof scope !== "string" || scope.length === 0) {
|
|
36162
|
-
throw new
|
|
36841
|
+
throw new import_errors10.WriteRequestError("sourceScopes entries must be scope strings");
|
|
36163
36842
|
}
|
|
36164
36843
|
if (sourceScopes.includes(scope)) {
|
|
36165
|
-
throw new
|
|
36844
|
+
throw new import_errors10.WriteRequestError("sourceScopes must not repeat a scope", {
|
|
36166
36845
|
duplicate: scope
|
|
36167
36846
|
});
|
|
36168
36847
|
}
|
|
36169
36848
|
if (scope === derivedScope) {
|
|
36170
|
-
throw new
|
|
36849
|
+
throw new import_errors10.WriteRequestError(
|
|
36171
36850
|
"derivedScope cannot be one of its own sources",
|
|
36172
36851
|
{ scope }
|
|
36173
36852
|
);
|
|
@@ -36175,17 +36854,17 @@ function registrationBody(params) {
|
|
|
36175
36854
|
sourceScopes.push(scope);
|
|
36176
36855
|
}
|
|
36177
36856
|
if (typeof question !== "string" || question.trim() === "") {
|
|
36178
|
-
throw new
|
|
36857
|
+
throw new import_errors10.WriteRequestError("question must be a non-empty string");
|
|
36179
36858
|
}
|
|
36180
36859
|
if (question.length > MAX_QUESTION_CHARS) {
|
|
36181
|
-
throw new
|
|
36860
|
+
throw new import_errors10.WriteRequestError(
|
|
36182
36861
|
`question is ${question.length} characters; the maximum is ${MAX_QUESTION_CHARS}`,
|
|
36183
36862
|
{ max: MAX_QUESTION_CHARS, length: question.length }
|
|
36184
36863
|
);
|
|
36185
36864
|
}
|
|
36186
36865
|
if (params.model !== void 0) {
|
|
36187
36866
|
if (typeof params.model !== "string" || params.model.length > MAX_QUESTION_MODEL_CHARS || !MODEL_ID_PATTERN.test(params.model)) {
|
|
36188
|
-
throw new
|
|
36867
|
+
throw new import_errors10.WriteRequestError("model must be a provider model id", {
|
|
36189
36868
|
model: params.model
|
|
36190
36869
|
});
|
|
36191
36870
|
}
|
|
@@ -36221,7 +36900,7 @@ async function getQuestion(params) {
|
|
|
36221
36900
|
}
|
|
36222
36901
|
async function listQuestions(params) {
|
|
36223
36902
|
if (typeof params.derivedScope !== "string" || params.derivedScope.length === 0) {
|
|
36224
|
-
throw new
|
|
36903
|
+
throw new import_errors10.WriteRequestError(
|
|
36225
36904
|
"derivedScope is required; a builder may only list its own questions on a scope it may write"
|
|
36226
36905
|
);
|
|
36227
36906
|
}
|
|
@@ -36279,7 +36958,7 @@ async function waitForQuestion(params) {
|
|
|
36279
36958
|
if (isSettled(latest.status)) return latest;
|
|
36280
36959
|
const remaining = deadline - Date.now();
|
|
36281
36960
|
if (remaining <= 0) {
|
|
36282
|
-
throw new
|
|
36961
|
+
throw new import_errors10.DerivativeQuestionTimeoutError(
|
|
36283
36962
|
`Derivative question ${latest.questionId} was still ${latest.status} after ${timeoutMs}ms`,
|
|
36284
36963
|
{
|
|
36285
36964
|
questionId: latest.questionId,
|
|
@@ -36299,7 +36978,7 @@ async function askPersonalServer(params) {
|
|
|
36299
36978
|
questionId: registered.questionId
|
|
36300
36979
|
});
|
|
36301
36980
|
if (registration.status !== "ready") {
|
|
36302
|
-
throw new
|
|
36981
|
+
throw new import_errors10.DerivativeQuestionFailedError(
|
|
36303
36982
|
`Derivative question ${registration.questionId} failed: ${registration.error ?? "no reason given"}`,
|
|
36304
36983
|
{
|
|
36305
36984
|
questionId: registration.questionId,
|
|
@@ -36326,7 +37005,7 @@ async function askPersonalServer(params) {
|
|
|
36326
37005
|
|
|
36327
37006
|
// src/protocol/derivative-status.ts
|
|
36328
37007
|
var import_zod6 = require("zod");
|
|
36329
|
-
var
|
|
37008
|
+
var import_errors11 = require("./errors.cjs");
|
|
36330
37009
|
var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
|
|
36331
37010
|
var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
|
|
36332
37011
|
var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
|
|
@@ -36357,13 +37036,13 @@ function normalizeBaseUrl3(url) {
|
|
|
36357
37036
|
function resolveFetch4(fetchFn) {
|
|
36358
37037
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
36359
37038
|
if (resolved === void 0) {
|
|
36360
|
-
throw new
|
|
37039
|
+
throw new import_errors11.WriteRequestError("No fetch implementation available");
|
|
36361
37040
|
}
|
|
36362
37041
|
return resolved;
|
|
36363
37042
|
}
|
|
36364
37043
|
function requireDerivedScope(derivedScope) {
|
|
36365
37044
|
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
36366
|
-
throw new
|
|
37045
|
+
throw new import_errors11.WriteRequestError("derivedScope is required");
|
|
36367
37046
|
}
|
|
36368
37047
|
return derivedScope;
|
|
36369
37048
|
}
|
|
@@ -36382,7 +37061,7 @@ function sleep4(ms, signal) {
|
|
|
36382
37061
|
});
|
|
36383
37062
|
}
|
|
36384
37063
|
function timeoutError(latest, timeoutMs) {
|
|
36385
|
-
return new
|
|
37064
|
+
return new import_errors11.DerivativeQuestionTimeoutError(
|
|
36386
37065
|
`Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
|
|
36387
37066
|
{
|
|
36388
37067
|
derivedScope: latest.derivedScope,
|
|
@@ -36395,7 +37074,7 @@ function timeoutError(latest, timeoutMs) {
|
|
|
36395
37074
|
}
|
|
36396
37075
|
function abortError2(signal) {
|
|
36397
37076
|
const reason = signal?.reason;
|
|
36398
|
-
return reason instanceof Error ? reason : new
|
|
37077
|
+
return reason instanceof Error ? reason : new import_errors11.WriteRequestError("Derivative status wait was aborted");
|
|
36399
37078
|
}
|
|
36400
37079
|
function isDerivativeStatusSettled(status) {
|
|
36401
37080
|
if (status.status === "ready") return true;
|
|
@@ -36428,7 +37107,7 @@ async function getDerivativeStatus(params) {
|
|
|
36428
37107
|
}
|
|
36429
37108
|
);
|
|
36430
37109
|
} catch (err) {
|
|
36431
|
-
throw new
|
|
37110
|
+
throw new import_errors11.WriteTransportError(
|
|
36432
37111
|
`Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
36433
37112
|
1,
|
|
36434
37113
|
err
|
|
@@ -36443,7 +37122,7 @@ async function getDerivativeStatus(params) {
|
|
|
36443
37122
|
try {
|
|
36444
37123
|
body = await response.json();
|
|
36445
37124
|
} catch (err) {
|
|
36446
|
-
throw new
|
|
37125
|
+
throw new import_errors11.DerivativeQuestionRejectedError(
|
|
36447
37126
|
"Derivative status response is not JSON",
|
|
36448
37127
|
response.status,
|
|
36449
37128
|
null,
|
|
@@ -36452,7 +37131,7 @@ async function getDerivativeStatus(params) {
|
|
|
36452
37131
|
}
|
|
36453
37132
|
const parsed = DerivativeStatusSchema.safeParse(body);
|
|
36454
37133
|
if (!parsed.success) {
|
|
36455
|
-
throw new
|
|
37134
|
+
throw new import_errors11.DerivativeQuestionRejectedError(
|
|
36456
37135
|
"Derivative status response is not a status view",
|
|
36457
37136
|
response.status,
|
|
36458
37137
|
null,
|
|
@@ -36486,7 +37165,7 @@ async function waitForDerivativeStatus(params) {
|
|
|
36486
37165
|
}
|
|
36487
37166
|
|
|
36488
37167
|
// src/protocol/gateway.ts
|
|
36489
|
-
var
|
|
37168
|
+
var import_errors12 = require("./errors.cjs");
|
|
36490
37169
|
function withGrantPermissions(grant) {
|
|
36491
37170
|
const stripped = { ...grant };
|
|
36492
37171
|
delete stripped.permissions;
|
|
@@ -36532,7 +37211,7 @@ function createGatewayClient(baseUrl) {
|
|
|
36532
37211
|
}
|
|
36533
37212
|
async function deletedError(res, details) {
|
|
36534
37213
|
const body = await readBody(res);
|
|
36535
|
-
return new
|
|
37214
|
+
return new import_errors12.DataPointDeletedError(
|
|
36536
37215
|
`Data point ${details.dataPointId ?? details.scope ?? ""} has been deleted`,
|
|
36537
37216
|
{ ...details, deletedAt: tombstoneDeletedAt(body) }
|
|
36538
37217
|
);
|
|
@@ -36605,7 +37284,7 @@ function createGatewayClient(baseUrl) {
|
|
|
36605
37284
|
}
|
|
36606
37285
|
const record = await unwrapEnvelope(res);
|
|
36607
37286
|
if (!options?.includeDeleted && isDataPointTombstone(record)) {
|
|
36608
|
-
throw new
|
|
37287
|
+
throw new import_errors12.DataPointDeletedError(
|
|
36609
37288
|
`Data point ${dataPointId} has been deleted`,
|
|
36610
37289
|
{
|
|
36611
37290
|
dataPointId,
|
|
@@ -36767,7 +37446,7 @@ function createGatewayClient(baseUrl) {
|
|
|
36767
37446
|
})
|
|
36768
37447
|
});
|
|
36769
37448
|
if (res.status === 404) {
|
|
36770
|
-
throw new
|
|
37449
|
+
throw new import_errors12.DataPointNotFoundError(
|
|
36771
37450
|
`Data point ${dataPointId} (scope '${params.scope}') is not registered`,
|
|
36772
37451
|
details
|
|
36773
37452
|
);
|
|
@@ -36778,7 +37457,7 @@ function createGatewayClient(baseUrl) {
|
|
|
36778
37457
|
body2["currentExpectedVersion"]
|
|
36779
37458
|
);
|
|
36780
37459
|
const detail = stringOrUndefined(body2["error"]) ?? res.statusText;
|
|
36781
|
-
throw new
|
|
37460
|
+
throw new import_errors12.DataPointVersionConflictError(
|
|
36782
37461
|
`Gateway error: 409 ${detail}`,
|
|
36783
37462
|
{
|
|
36784
37463
|
...details,
|
|
@@ -36908,261 +37587,6 @@ function createGatewayClient(baseUrl) {
|
|
|
36908
37587
|
};
|
|
36909
37588
|
}
|
|
36910
37589
|
|
|
36911
|
-
// src/protocol/escrow.ts
|
|
36912
|
-
var import_viem28 = require("viem");
|
|
36913
|
-
var GENERIC_PAYMENT_TYPES = {
|
|
36914
|
-
GenericPayment: [
|
|
36915
|
-
{ name: "payerAddress", type: "address" },
|
|
36916
|
-
{ name: "opType", type: "string" },
|
|
36917
|
-
{ name: "opId", type: "bytes32" },
|
|
36918
|
-
{ name: "asset", type: "address" },
|
|
36919
|
-
{ name: "amount", type: "uint256" },
|
|
36920
|
-
{ name: "paymentNonce", type: "uint256" }
|
|
36921
|
-
]
|
|
36922
|
-
};
|
|
36923
|
-
function genericPaymentDomain(chainId, escrowContract) {
|
|
36924
|
-
return {
|
|
36925
|
-
name: "Vana Data Portability",
|
|
36926
|
-
version: "1",
|
|
36927
|
-
chainId,
|
|
36928
|
-
verifyingContract: escrowContract
|
|
36929
|
-
};
|
|
36930
|
-
}
|
|
36931
|
-
var ESCROW_DEPOSIT_ABI2 = [
|
|
36932
|
-
{
|
|
36933
|
-
type: "function",
|
|
36934
|
-
name: "depositNative",
|
|
36935
|
-
stateMutability: "payable",
|
|
36936
|
-
inputs: [{ name: "account", type: "address" }],
|
|
36937
|
-
outputs: []
|
|
36938
|
-
},
|
|
36939
|
-
{
|
|
36940
|
-
type: "function",
|
|
36941
|
-
name: "depositToken",
|
|
36942
|
-
stateMutability: "nonpayable",
|
|
36943
|
-
inputs: [
|
|
36944
|
-
{ name: "account", type: "address" },
|
|
36945
|
-
{ name: "token", type: "address" },
|
|
36946
|
-
{ name: "amount", type: "uint256" }
|
|
36947
|
-
],
|
|
36948
|
-
outputs: []
|
|
36949
|
-
}
|
|
36950
|
-
];
|
|
36951
|
-
var NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
36952
|
-
var EscrowWithdrawalLifecycleError = class extends Error {
|
|
36953
|
-
constructor(httpStatus, result) {
|
|
36954
|
-
super(result.error);
|
|
36955
|
-
this.httpStatus = httpStatus;
|
|
36956
|
-
this.result = result;
|
|
36957
|
-
}
|
|
36958
|
-
httpStatus;
|
|
36959
|
-
result;
|
|
36960
|
-
name = "EscrowWithdrawalLifecycleError";
|
|
36961
|
-
};
|
|
36962
|
-
var EscrowWithdrawalRejectionError = class extends Error {
|
|
36963
|
-
constructor(httpStatus, result) {
|
|
36964
|
-
super(result.error);
|
|
36965
|
-
this.httpStatus = httpStatus;
|
|
36966
|
-
this.result = result;
|
|
36967
|
-
}
|
|
36968
|
-
httpStatus;
|
|
36969
|
-
result;
|
|
36970
|
-
name = "EscrowWithdrawalRejectionError";
|
|
36971
|
-
};
|
|
36972
|
-
function createEscrowGatewayClient(baseUrl) {
|
|
36973
|
-
const base = baseUrl.replace(/\/+$/, "");
|
|
36974
|
-
async function throwOnError(res, context) {
|
|
36975
|
-
if (!res.ok) {
|
|
36976
|
-
let detail = "";
|
|
36977
|
-
try {
|
|
36978
|
-
const body = await res.json();
|
|
36979
|
-
if (body.error) detail = `: ${body.error}`;
|
|
36980
|
-
} catch {
|
|
36981
|
-
}
|
|
36982
|
-
throw new Error(
|
|
36983
|
-
`Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`
|
|
36984
|
-
);
|
|
36985
|
-
}
|
|
36986
|
-
}
|
|
36987
|
-
async function throwOnWithdrawError(res) {
|
|
36988
|
-
if (res.ok) return;
|
|
36989
|
-
let body;
|
|
36990
|
-
try {
|
|
36991
|
-
body = await res.json();
|
|
36992
|
-
} catch {
|
|
36993
|
-
throw new Error(
|
|
36994
|
-
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}`
|
|
36995
|
-
);
|
|
36996
|
-
}
|
|
36997
|
-
if (isEscrowWithdrawalFailureResult(body)) {
|
|
36998
|
-
throw new EscrowWithdrawalLifecycleError(res.status, body);
|
|
36999
|
-
}
|
|
37000
|
-
if (isEscrowWithdrawalRejectedResult(body)) {
|
|
37001
|
-
throw new EscrowWithdrawalRejectionError(res.status, body);
|
|
37002
|
-
}
|
|
37003
|
-
const error = getGatewayErrorMessage(body);
|
|
37004
|
-
throw new Error(
|
|
37005
|
-
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}${error ? `: ${error}` : ""}`
|
|
37006
|
-
);
|
|
37007
|
-
}
|
|
37008
|
-
return {
|
|
37009
|
-
async submitDeposit({ txHash }) {
|
|
37010
|
-
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
37011
|
-
method: "POST",
|
|
37012
|
-
headers: { "Content-Type": "application/json" },
|
|
37013
|
-
body: JSON.stringify({ txHash })
|
|
37014
|
-
});
|
|
37015
|
-
if (res.status !== 200 && res.status !== 202) {
|
|
37016
|
-
await throwOnError(res, "POST /v1/escrow/deposit");
|
|
37017
|
-
}
|
|
37018
|
-
return res.json();
|
|
37019
|
-
},
|
|
37020
|
-
async getEscrowBalance(account) {
|
|
37021
|
-
const res = await fetch(
|
|
37022
|
-
`${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`
|
|
37023
|
-
);
|
|
37024
|
-
await throwOnError(res, "GET /v1/escrow/balance");
|
|
37025
|
-
return res.json();
|
|
37026
|
-
},
|
|
37027
|
-
async syncEscrowBalance(account) {
|
|
37028
|
-
const res = await fetch(
|
|
37029
|
-
`${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,
|
|
37030
|
-
{ method: "POST" }
|
|
37031
|
-
);
|
|
37032
|
-
await throwOnError(res, "POST /v1/escrow/balance/sync");
|
|
37033
|
-
return res.json();
|
|
37034
|
-
},
|
|
37035
|
-
async payForOp({
|
|
37036
|
-
payerAddress,
|
|
37037
|
-
opType,
|
|
37038
|
-
opId,
|
|
37039
|
-
asset,
|
|
37040
|
-
amount,
|
|
37041
|
-
paymentNonce,
|
|
37042
|
-
signature,
|
|
37043
|
-
accessRecord
|
|
37044
|
-
}) {
|
|
37045
|
-
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
37046
|
-
method: "POST",
|
|
37047
|
-
headers: {
|
|
37048
|
-
"Content-Type": "application/json",
|
|
37049
|
-
Authorization: `Web3Signed ${signature}`
|
|
37050
|
-
},
|
|
37051
|
-
body: JSON.stringify({
|
|
37052
|
-
payerAddress,
|
|
37053
|
-
opType,
|
|
37054
|
-
opId,
|
|
37055
|
-
asset,
|
|
37056
|
-
amount,
|
|
37057
|
-
paymentNonce,
|
|
37058
|
-
...accessRecord ? { accessRecord } : {}
|
|
37059
|
-
})
|
|
37060
|
-
});
|
|
37061
|
-
await throwOnError(res, "POST /v1/escrow/pay");
|
|
37062
|
-
return res.json();
|
|
37063
|
-
},
|
|
37064
|
-
async withdraw({
|
|
37065
|
-
account,
|
|
37066
|
-
asset,
|
|
37067
|
-
amount,
|
|
37068
|
-
withdrawNonce,
|
|
37069
|
-
deadline,
|
|
37070
|
-
signature
|
|
37071
|
-
}) {
|
|
37072
|
-
const res = await fetch(`${base}/v1/escrow/withdraw`, {
|
|
37073
|
-
method: "POST",
|
|
37074
|
-
headers: {
|
|
37075
|
-
"Content-Type": "application/json",
|
|
37076
|
-
Authorization: `Web3Signed ${signature}`
|
|
37077
|
-
},
|
|
37078
|
-
body: JSON.stringify({
|
|
37079
|
-
account,
|
|
37080
|
-
asset,
|
|
37081
|
-
amount,
|
|
37082
|
-
withdrawNonce,
|
|
37083
|
-
deadline
|
|
37084
|
-
})
|
|
37085
|
-
});
|
|
37086
|
-
await throwOnWithdrawError(res);
|
|
37087
|
-
return res.json();
|
|
37088
|
-
},
|
|
37089
|
-
async getWithdrawNonce(account) {
|
|
37090
|
-
const res = await fetch(
|
|
37091
|
-
`${base}/v1/escrow/withdraw/nonce?account=${encodeURIComponent(account)}`,
|
|
37092
|
-
{ cache: "no-store" }
|
|
37093
|
-
);
|
|
37094
|
-
await throwOnError(res, "GET /v1/escrow/withdraw/nonce");
|
|
37095
|
-
const body = await res.json();
|
|
37096
|
-
if (!isWithdrawNonceResponse(body, account)) {
|
|
37097
|
-
throw new Error(
|
|
37098
|
-
"GET /v1/escrow/withdraw/nonce: invalid response structure"
|
|
37099
|
-
);
|
|
37100
|
-
}
|
|
37101
|
-
return body;
|
|
37102
|
-
}
|
|
37103
|
-
};
|
|
37104
|
-
}
|
|
37105
|
-
function getGatewayErrorMessage(body) {
|
|
37106
|
-
if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
|
|
37107
|
-
return body.error;
|
|
37108
|
-
}
|
|
37109
|
-
return void 0;
|
|
37110
|
-
}
|
|
37111
|
-
function isEscrowWithdrawalFailureResult(body) {
|
|
37112
|
-
if (typeof body !== "object" || body === null) return false;
|
|
37113
|
-
const value = body;
|
|
37114
|
-
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));
|
|
37115
|
-
}
|
|
37116
|
-
function isEscrowWithdrawalRejectedResult(body) {
|
|
37117
|
-
if (typeof body !== "object" || body === null) return false;
|
|
37118
|
-
const value = body;
|
|
37119
|
-
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);
|
|
37120
|
-
}
|
|
37121
|
-
function isWithdrawalRejectionCode(value) {
|
|
37122
|
-
return value === "below_minimum" || value === "deadline_too_far" || value === "expired" || value === "insufficient_available" || value === "stale_nonce";
|
|
37123
|
-
}
|
|
37124
|
-
function optionalUint256Decimal(value) {
|
|
37125
|
-
return value === void 0 || isUint256Decimal(value);
|
|
37126
|
-
}
|
|
37127
|
-
function isAddressHex(value) {
|
|
37128
|
-
return typeof value === "string" && (0, import_viem28.isHex)(value, { strict: true }) && value.length === 42;
|
|
37129
|
-
}
|
|
37130
|
-
function isHash(value) {
|
|
37131
|
-
return typeof value === "string" && (0, import_viem28.isHex)(value, { strict: true }) && value.length === 66;
|
|
37132
|
-
}
|
|
37133
|
-
function isUint256Decimal(value) {
|
|
37134
|
-
if (typeof value !== "string" || value.length === 0 || value.length > 78) {
|
|
37135
|
-
return false;
|
|
37136
|
-
}
|
|
37137
|
-
if (!/^(0|[1-9]\d*)$/.test(value)) return false;
|
|
37138
|
-
return BigInt(value) <= 2n ** 256n - 1n;
|
|
37139
|
-
}
|
|
37140
|
-
function isBlockNumber(value) {
|
|
37141
|
-
return value === null || isUint256Decimal(value);
|
|
37142
|
-
}
|
|
37143
|
-
function isWithdrawNonceResponse(body, requestedAccount) {
|
|
37144
|
-
if (typeof body !== "object" || body === null) return false;
|
|
37145
|
-
const value = body;
|
|
37146
|
-
if (value.success !== true) return false;
|
|
37147
|
-
if (!isAddressHex(value.account)) return false;
|
|
37148
|
-
if (value.account.toLowerCase() !== requestedAccount.toLowerCase())
|
|
37149
|
-
return false;
|
|
37150
|
-
if (typeof value.chainId !== "string") return false;
|
|
37151
|
-
if (!/^(0|[1-9]\d*)$/.test(value.chainId)) return false;
|
|
37152
|
-
const isLastNull = value.lastWithdrawNonce === null;
|
|
37153
|
-
const lastNonceValid = isLastNull || isUint256Decimal(value.lastWithdrawNonce);
|
|
37154
|
-
if (!lastNonceValid) return false;
|
|
37155
|
-
if (!isUint256Decimal(value.nextWithdrawNonce)) return false;
|
|
37156
|
-
if (isLastNull) {
|
|
37157
|
-
return value.nextWithdrawNonce === "1";
|
|
37158
|
-
}
|
|
37159
|
-
const lastNonce = BigInt(value.lastWithdrawNonce);
|
|
37160
|
-
const nextNonce = BigInt(value.nextWithdrawNonce);
|
|
37161
|
-
const expectedNextNonce = lastNonce + 1n;
|
|
37162
|
-
if (expectedNextNonce > 2n ** 256n - 1n) return false;
|
|
37163
|
-
return nextNonce === expectedNextNonce;
|
|
37164
|
-
}
|
|
37165
|
-
|
|
37166
37590
|
// src/direct/escrow-payment.ts
|
|
37167
37591
|
var GRANT_OP_TYPE = "grant";
|
|
37168
37592
|
var DATA_ACCESS_OP_TYPE = "data_access";
|
|
@@ -37399,8 +37823,8 @@ async function authorizeEscrowPayment(params) {
|
|
|
37399
37823
|
}
|
|
37400
37824
|
|
|
37401
37825
|
// src/direct/personal-server-read.ts
|
|
37402
|
-
var
|
|
37403
|
-
var
|
|
37826
|
+
var import_errors13 = require("./direct/errors.cjs");
|
|
37827
|
+
var import_errors14 = require("./errors.cjs");
|
|
37404
37828
|
function asRecord2(value) {
|
|
37405
37829
|
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
37406
37830
|
}
|
|
@@ -37444,7 +37868,7 @@ function parseLegacyGrantOperation(params) {
|
|
|
37444
37868
|
const { challengeGrantId, challengeOpId, challengeOpType, grantId } = params;
|
|
37445
37869
|
const opType = challengeOpType ?? GRANT_OP_TYPE;
|
|
37446
37870
|
if (opType !== GRANT_OP_TYPE) {
|
|
37447
|
-
throw new
|
|
37871
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37448
37872
|
"Personal Server payment challenge used an unsupported escrow op type",
|
|
37449
37873
|
402,
|
|
37450
37874
|
{ opType: challengeOpType }
|
|
@@ -37452,14 +37876,14 @@ function parseLegacyGrantOperation(params) {
|
|
|
37452
37876
|
}
|
|
37453
37877
|
const opId = challengeOpId ?? challengeGrantId ?? grantId;
|
|
37454
37878
|
if (!opId || !isBytes32Hex(opId)) {
|
|
37455
|
-
throw new
|
|
37879
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37456
37880
|
"Personal Server payment challenge used an invalid escrow op id",
|
|
37457
37881
|
402,
|
|
37458
37882
|
{ opId }
|
|
37459
37883
|
);
|
|
37460
37884
|
}
|
|
37461
37885
|
if (opId.toLowerCase() !== grantId.toLowerCase()) {
|
|
37462
|
-
throw new
|
|
37886
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37463
37887
|
"Personal Server payment challenge did not match the requested grant",
|
|
37464
37888
|
402,
|
|
37465
37889
|
{ opId, grantId }
|
|
@@ -37505,7 +37929,7 @@ function parseCanonicalDataAccessAccept(value) {
|
|
|
37505
37929
|
function parseCanonicalDataAccessPayment(params) {
|
|
37506
37930
|
const { body, grantId, raw } = params;
|
|
37507
37931
|
if (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED") {
|
|
37508
|
-
throw new
|
|
37932
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37509
37933
|
"Personal Server data-access payment response was not a canonical x402 challenge",
|
|
37510
37934
|
402
|
|
37511
37935
|
);
|
|
@@ -37544,20 +37968,20 @@ async function parsePersonalServerPaymentRequired(res, grantId) {
|
|
|
37544
37968
|
"accepts"
|
|
37545
37969
|
);
|
|
37546
37970
|
if (hasAcceptsEnvelope && (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED")) {
|
|
37547
|
-
throw new
|
|
37971
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37548
37972
|
"Personal Server grant payment response was not a canonical x402 challenge",
|
|
37549
37973
|
402
|
|
37550
37974
|
);
|
|
37551
37975
|
}
|
|
37552
37976
|
const accept = preferredLegacyAccept(body);
|
|
37553
37977
|
if (hasDataAccessMarker(body) && !accept) {
|
|
37554
|
-
throw new
|
|
37978
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37555
37979
|
"Personal Server data-access payment challenge was untrusted or incomplete",
|
|
37556
37980
|
402
|
|
37557
37981
|
);
|
|
37558
37982
|
}
|
|
37559
37983
|
if (hasAcceptsEnvelope && !accept) {
|
|
37560
|
-
throw new
|
|
37984
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37561
37985
|
"Personal Server grant payment challenge had no compatible escrow offer",
|
|
37562
37986
|
402
|
|
37563
37987
|
);
|
|
@@ -37575,7 +37999,7 @@ async function parsePersonalServerPaymentRequired(res, grantId) {
|
|
|
37575
37999
|
const accessRecord2 = parseAccessRecord(accept.accessRecord);
|
|
37576
38000
|
const hasAccessRecord = accept.accessRecord !== void 0;
|
|
37577
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) {
|
|
37578
|
-
throw new
|
|
38002
|
+
throw new import_errors13.PersonalServerReadError(
|
|
37579
38003
|
"Personal Server grant payment challenge was untrusted or incomplete",
|
|
37580
38004
|
402
|
|
37581
38005
|
);
|