@opendatalabs/vana-sdk 3.22.0 → 3.23.0-pr.211.341f55d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/crypto/envelope/job.cjs +355 -0
- package/dist/crypto/envelope/job.cjs.map +1 -0
- package/dist/crypto/envelope/job.d.ts +123 -0
- package/dist/crypto/envelope/job.js +333 -0
- package/dist/crypto/envelope/job.js.map +1 -0
- package/dist/direct/access-request-client.cjs +4 -0
- package/dist/direct/access-request-client.cjs.map +1 -1
- package/dist/direct/access-request-client.js +4 -0
- package/dist/direct/access-request-client.js.map +1 -1
- package/dist/direct/connect-flow.cjs +43 -1
- package/dist/direct/connect-flow.cjs.map +1 -1
- package/dist/direct/connect-flow.d.ts +12 -0
- package/dist/direct/connect-flow.js +43 -1
- package/dist/direct/connect-flow.js.map +1 -1
- package/dist/direct/types.cjs.map +1 -1
- package/dist/direct/types.d.ts +7 -0
- package/dist/direct/types.js.map +1 -1
- package/dist/direct/use-direct-vana-connect.cjs +2 -1
- package/dist/direct/use-direct-vana-connect.cjs.map +1 -1
- package/dist/direct/use-direct-vana-connect.d.ts +3 -1
- package/dist/direct/use-direct-vana-connect.js +2 -1
- package/dist/direct/use-direct-vana-connect.js.map +1 -1
- package/dist/errors.cjs +84 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +133 -0
- package/dist/errors.js +73 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.browser.d.ts +3 -0
- package/dist/index.browser.js +631 -24
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +1259 -111
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +4 -0
- package/dist/index.node.js +1223 -101
- package/dist/index.node.js.map +4 -4
- package/dist/protocol/identity.cjs +219 -0
- package/dist/protocol/identity.cjs.map +1 -0
- package/dist/protocol/identity.d.ts +193 -0
- package/dist/protocol/identity.js +183 -0
- package/dist/protocol/identity.js.map +1 -0
- package/dist/protocol/identity.test.d.ts +1 -0
- package/dist/protocol/identity.vector.test.d.ts +1 -0
- package/dist/protocol/jobs-client.cjs +540 -0
- package/dist/protocol/jobs-client.cjs.map +1 -0
- package/dist/protocol/jobs-client.d.ts +169 -0
- package/dist/protocol/jobs-client.js +547 -0
- package/dist/protocol/jobs-client.js.map +1 -0
- package/dist/protocol/jobs-client.test.d.ts +1 -0
- package/dist/protocol/jobs.cjs +64 -0
- package/dist/protocol/jobs.cjs.map +1 -0
- package/dist/protocol/jobs.d.ts +193 -0
- package/dist/protocol/jobs.js +31 -0
- package/dist/protocol/jobs.js.map +1 -0
- package/dist/protocol/jobs.test.d.ts +1 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js.map +1 -1
- package/package.json +7 -1
package/dist/index.node.cjs
CHANGED
|
@@ -1180,6 +1180,8 @@ __export(index_node_exports, {
|
|
|
1180
1180
|
BUILDER_REGISTRATION_TYPES: () => BUILDER_REGISTRATION_TYPES,
|
|
1181
1181
|
BlockchainError: () => BlockchainError,
|
|
1182
1182
|
BrowserPlatformAdapter: () => BrowserPlatformAdapter,
|
|
1183
|
+
BuilderUnknownError: () => BuilderUnknownError,
|
|
1184
|
+
CLAIM_POLL_FLOOR_MS: () => CLAIM_POLL_FLOOR_MS,
|
|
1183
1185
|
CONTRACTS: () => CONTRACTS,
|
|
1184
1186
|
CallbackStorage: () => CallbackStorage,
|
|
1185
1187
|
ContractFactory: () => ContractFactory,
|
|
@@ -1188,6 +1190,8 @@ __export(index_node_exports, {
|
|
|
1188
1190
|
DATA_REGISTRY_STATUS_ABI: () => DATA_REGISTRY_STATUS_ABI,
|
|
1189
1191
|
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS: () => DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
1190
1192
|
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS: () => DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
1193
|
+
DEFAULT_JOB_DEADLINE_SECONDS: () => DEFAULT_JOB_DEADLINE_SECONDS,
|
|
1194
|
+
DEFAULT_LEASE_SECONDS: () => DEFAULT_LEASE_SECONDS,
|
|
1191
1195
|
DEFAULT_QUESTION_POLL_INTERVAL_MS: () => DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
1192
1196
|
DEFAULT_QUESTION_TIMEOUT_MS: () => DEFAULT_QUESTION_TIMEOUT_MS,
|
|
1193
1197
|
DERIVATIVE_ERROR_CODES: () => DERIVATIVE_ERROR_CODES,
|
|
@@ -1212,6 +1216,9 @@ __export(index_node_exports, {
|
|
|
1212
1216
|
DerivativeStatusSchema: () => DerivativeStatusSchema,
|
|
1213
1217
|
DropboxStorage: () => DropboxStorage,
|
|
1214
1218
|
ECIESError: () => ECIESError,
|
|
1219
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION: () => ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
1220
|
+
ENCLAVE_TRUST_ANCHORS: () => ENCLAVE_TRUST_ANCHORS,
|
|
1221
|
+
ENCLAVE_WALLET_PURPOSE: () => ENCLAVE_WALLET_PURPOSE,
|
|
1215
1222
|
ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI2,
|
|
1216
1223
|
ExpiredTokenError: () => ExpiredTokenError,
|
|
1217
1224
|
FEE_REGISTRY_ABI: () => FEE_REGISTRY_ABI,
|
|
@@ -1220,12 +1227,25 @@ __export(index_node_exports, {
|
|
|
1220
1227
|
GRANT_REGISTRATION_TYPES: () => GRANT_REGISTRATION_TYPES,
|
|
1221
1228
|
GRANT_REVOCATION_TYPES: () => GRANT_REVOCATION_TYPES,
|
|
1222
1229
|
GoogleDriveStorage: () => GoogleDriveStorage,
|
|
1230
|
+
GrantInvalidError: () => GrantInvalidError,
|
|
1223
1231
|
InMemoryTokenStore: () => InMemoryTokenStore,
|
|
1224
1232
|
IngestResponseSchema: () => IngestResponseSchema,
|
|
1225
1233
|
InvalidConfigurationError: () => InvalidConfigurationError,
|
|
1226
1234
|
InvalidScopeEntryError: () => InvalidScopeEntryError,
|
|
1227
1235
|
InvalidSignatureError: () => InvalidSignatureError,
|
|
1228
1236
|
IpfsStorage: () => IpfsStorage,
|
|
1237
|
+
JOB_OPERATIONS: () => JOB_OPERATIONS,
|
|
1238
|
+
JOB_PROTOCOL_VERSION: () => JOB_PROTOCOL_VERSION,
|
|
1239
|
+
JOB_STATES: () => JOB_STATES,
|
|
1240
|
+
JobEnvelopeError: () => JobEnvelopeError,
|
|
1241
|
+
JobIdTakenError: () => JobIdTakenError,
|
|
1242
|
+
JobNotFoundError: () => JobNotFoundError,
|
|
1243
|
+
JobRejectedError: () => JobRejectedError,
|
|
1244
|
+
JobRequestTooLargeError: () => JobRequestTooLargeError,
|
|
1245
|
+
JobResultIntegrityError: () => JobResultIntegrityError,
|
|
1246
|
+
JobTimeoutError: () => JobTimeoutError,
|
|
1247
|
+
JobTransportError: () => JobTransportError,
|
|
1248
|
+
JobsClientError: () => JobsClientError,
|
|
1229
1249
|
LINEAGE_FIELD: () => LINEAGE_FIELD,
|
|
1230
1250
|
LINEAGE_KEY: () => LINEAGE_KEY,
|
|
1231
1251
|
LineageEntrySchema: () => LineageEntrySchema,
|
|
@@ -1233,10 +1253,16 @@ __export(index_node_exports, {
|
|
|
1233
1253
|
LineageNodeSchema: () => LineageNodeSchema,
|
|
1234
1254
|
LineageReadError: () => LineageReadError,
|
|
1235
1255
|
MASTER_KEY_MESSAGE: () => MASTER_KEY_MESSAGE,
|
|
1256
|
+
MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS: () => MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS,
|
|
1257
|
+
MASTER_SIGNATURE_DELIVERY_VERSION: () => MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
1258
|
+
MAX_ATTEMPTS: () => MAX_ATTEMPTS,
|
|
1259
|
+
MAX_JOB_DEADLINE_SECONDS: () => MAX_JOB_DEADLINE_SECONDS,
|
|
1260
|
+
MAX_LEASE_SECONDS: () => MAX_LEASE_SECONDS,
|
|
1236
1261
|
MAX_LINEAGE_SOURCES: () => MAX_LINEAGE_SOURCES,
|
|
1237
1262
|
MAX_QUESTION_CHARS: () => MAX_QUESTION_CHARS,
|
|
1238
1263
|
MAX_QUESTION_MODEL_CHARS: () => MAX_QUESTION_MODEL_CHARS,
|
|
1239
1264
|
MAX_QUESTION_SOURCE_SCOPES: () => MAX_QUESTION_SOURCE_SCOPES,
|
|
1265
|
+
MAX_WAIT_SECONDS: () => MAX_WAIT_SECONDS,
|
|
1240
1266
|
MissingAuthError: () => MissingAuthError,
|
|
1241
1267
|
NATIVE_ASSET_ADDRESS: () => NATIVE_ASSET_ADDRESS,
|
|
1242
1268
|
NATIVE_VANA_ASSET: () => NATIVE_VANA_ASSET,
|
|
@@ -1245,6 +1271,7 @@ __export(index_node_exports, {
|
|
|
1245
1271
|
NodePlatformAdapter: () => NodePlatformAdapter,
|
|
1246
1272
|
NonceError: () => NonceError,
|
|
1247
1273
|
OAuthClient: () => OAuthClient,
|
|
1274
|
+
OwnerNotReadyError: () => OwnerNotReadyError,
|
|
1248
1275
|
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
1249
1276
|
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
1250
1277
|
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION: () => PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
@@ -1270,6 +1297,7 @@ __export(index_node_exports, {
|
|
|
1270
1297
|
RedactedLineageNodeSchema: () => RedactedLineageNodeSchema,
|
|
1271
1298
|
RelayerError: () => RelayerError,
|
|
1272
1299
|
SCOPE_ACTIONS: () => SCOPE_ACTIONS,
|
|
1300
|
+
SEALED_ENVELOPE_VERSION: () => SEALED_ENVELOPE_VERSION,
|
|
1273
1301
|
SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
|
|
1274
1302
|
ScopeSchema: () => ScopeSchema,
|
|
1275
1303
|
SerializationError: () => SerializationError,
|
|
@@ -1282,6 +1310,7 @@ __export(index_node_exports, {
|
|
|
1282
1310
|
TOMBSTONE_METADATA_HASH: () => TOMBSTONE_METADATA_HASH,
|
|
1283
1311
|
TOMBSTONE_METADATA_HASH_PREIMAGE: () => TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
1284
1312
|
TransactionPendingError: () => TransactionPendingError,
|
|
1313
|
+
USER_PS_ID_DOMAIN: () => USER_PS_ID_DOMAIN,
|
|
1285
1314
|
UserRejectedRequestError: () => UserRejectedRequestError,
|
|
1286
1315
|
VanaError: () => VanaError,
|
|
1287
1316
|
VanaStorage: () => VanaStorage,
|
|
@@ -1300,6 +1329,7 @@ __export(index_node_exports, {
|
|
|
1300
1329
|
WriteSessionExpiredError: () => WriteSessionExpiredError,
|
|
1301
1330
|
WriteTransportError: () => WriteTransportError,
|
|
1302
1331
|
WriteUnauthorizedError: () => WriteUnauthorizedError,
|
|
1332
|
+
appRootPreimage: () => appRootPreimage,
|
|
1303
1333
|
askPersonalServer: () => askPersonalServer,
|
|
1304
1334
|
assertDerivedScopeNaming: () => assertDerivedScopeNaming,
|
|
1305
1335
|
assertValidPkceVerifier: () => assertValidPkceVerifier,
|
|
@@ -1313,6 +1343,7 @@ __export(index_node_exports, {
|
|
|
1313
1343
|
buildEscrowPaymentHeader: () => buildEscrowPaymentHeader,
|
|
1314
1344
|
buildGrantPaymentHeader: () => buildGrantPaymentHeader,
|
|
1315
1345
|
buildMarkDataPointUnavailableRequest: () => buildMarkDataPointUnavailableRequest,
|
|
1346
|
+
buildMasterSignatureDelivery: () => buildMasterSignatureDelivery,
|
|
1316
1347
|
buildPersonalServerDataReadRequest: () => buildPersonalServerDataReadRequest,
|
|
1317
1348
|
buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
|
|
1318
1349
|
buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -1321,6 +1352,7 @@ __export(index_node_exports, {
|
|
|
1321
1352
|
buildSetDataPointStatusRequest: () => buildSetDataPointStatusRequest,
|
|
1322
1353
|
buildWeb3SignedHeader: () => buildWeb3SignedHeader,
|
|
1323
1354
|
builderRegistrationDomain: () => builderRegistrationDomain,
|
|
1355
|
+
canonicalJobRequestBytes: () => canonicalJobRequestBytes,
|
|
1324
1356
|
chains: () => chains,
|
|
1325
1357
|
clearContractCache: () => clearContractCache,
|
|
1326
1358
|
computeBodyHash: () => computeBodyHash,
|
|
@@ -1332,6 +1364,7 @@ __export(index_node_exports, {
|
|
|
1332
1364
|
createDefaultNonceSource: () => createDefaultNonceSource,
|
|
1333
1365
|
createEscrowGatewayClient: () => createEscrowGatewayClient,
|
|
1334
1366
|
createGatewayClient: () => createGatewayClient,
|
|
1367
|
+
createJobsClient: () => createJobsClient,
|
|
1335
1368
|
createNodePlatformAdapter: () => createNodePlatformAdapter,
|
|
1336
1369
|
createPlatformAdapter: () => createPlatformAdapter,
|
|
1337
1370
|
createPlatformAdapterFor: () => createPlatformAdapterFor,
|
|
@@ -1356,6 +1389,7 @@ __export(index_node_exports, {
|
|
|
1356
1389
|
encodeDepositTokenData: () => encodeDepositTokenData,
|
|
1357
1390
|
encodeSetDataPointStatusData: () => encodeSetDataPointStatusData,
|
|
1358
1391
|
encodeWriteMetadataHeader: () => encodeWriteMetadataHeader,
|
|
1392
|
+
encryptMasterSignatureDelivery: () => encryptMasterSignatureDelivery,
|
|
1359
1393
|
encryptWithPassword: () => encryptWithPassword,
|
|
1360
1394
|
escrowContractAddress: () => escrowContractAddress,
|
|
1361
1395
|
escrowPaymentDomain: () => escrowPaymentDomain,
|
|
@@ -1390,12 +1424,15 @@ __export(index_node_exports, {
|
|
|
1390
1424
|
isPlatformSupported: () => isPlatformSupported,
|
|
1391
1425
|
isRedactedLineageNode: () => isRedactedLineageNode,
|
|
1392
1426
|
isTombstoneHashes: () => isTombstoneHashes,
|
|
1427
|
+
kmsIssuedPreimage: () => kmsIssuedPreimage,
|
|
1393
1428
|
listQuestions: () => listQuestions,
|
|
1394
1429
|
mainnetServices: () => mainnetServices,
|
|
1395
1430
|
moksha: () => moksha,
|
|
1396
1431
|
mokshaServices: () => mokshaServices,
|
|
1397
1432
|
mokshaTestnet: () => mokshaTestnet2,
|
|
1398
1433
|
normalizeBinaryMimeType: () => normalizeBinaryMimeType,
|
|
1434
|
+
openJobRequest: () => openJobRequest,
|
|
1435
|
+
openJobResult: () => openJobResult,
|
|
1399
1436
|
openWriteSession: () => openWriteSession,
|
|
1400
1437
|
parsePSError: () => parsePSError,
|
|
1401
1438
|
parsePersonalServerPaymentRequired: () => parsePersonalServerPaymentRequired,
|
|
@@ -1419,6 +1456,8 @@ __export(index_node_exports, {
|
|
|
1419
1456
|
scopeMatchesPattern: () => scopeMatchesPattern,
|
|
1420
1457
|
scopeNamespace: () => scopeNamespace,
|
|
1421
1458
|
scopeToPathSegments: () => scopeToPathSegments,
|
|
1459
|
+
sealJobRequest: () => sealJobRequest,
|
|
1460
|
+
sealJobResult: () => sealJobResult,
|
|
1422
1461
|
serializeECIES: () => serializeECIES,
|
|
1423
1462
|
serverRegistrationDomain: () => serverRegistrationDomain,
|
|
1424
1463
|
sessionCoversScope: () => sessionCoversScope,
|
|
@@ -1429,7 +1468,9 @@ __export(index_node_exports, {
|
|
|
1429
1468
|
toDirectPaymentReceipt: () => toDirectPaymentReceipt,
|
|
1430
1469
|
tombstoneDeletedAt: () => tombstoneDeletedAt,
|
|
1431
1470
|
tryGrantPermissions: () => tryGrantPermissions,
|
|
1471
|
+
userPsId: () => userPsId,
|
|
1432
1472
|
vanaMainnet: () => vanaMainnet2,
|
|
1473
|
+
verifyEnclaveIdentityEvidence: () => verifyEnclaveIdentityEvidence,
|
|
1433
1474
|
verifyGrantRegistration: () => verifyGrantRegistration,
|
|
1434
1475
|
verifyPkceChallenge: () => verifyPkceChallenge,
|
|
1435
1476
|
verifyWeb3Signed: () => verifyWeb3Signed,
|
|
@@ -1640,6 +1681,68 @@ var WriteRejectedError = class extends PersonalServerWriteError {
|
|
|
1640
1681
|
super(message, "WRITE_REJECTED", status, errorCode, details);
|
|
1641
1682
|
}
|
|
1642
1683
|
};
|
|
1684
|
+
var JobsClientError = class extends VanaError {
|
|
1685
|
+
constructor(message, code, status, errorCode = null, details) {
|
|
1686
|
+
super(message, code);
|
|
1687
|
+
this.status = status;
|
|
1688
|
+
this.errorCode = errorCode;
|
|
1689
|
+
this.details = details;
|
|
1690
|
+
}
|
|
1691
|
+
status;
|
|
1692
|
+
errorCode;
|
|
1693
|
+
details;
|
|
1694
|
+
};
|
|
1695
|
+
var BuilderUnknownError = class extends JobsClientError {
|
|
1696
|
+
constructor(message, details) {
|
|
1697
|
+
super(message, "JOB_BUILDER_UNKNOWN", 403, "BUILDER_UNKNOWN", details);
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
var GrantInvalidError = class extends JobsClientError {
|
|
1701
|
+
constructor(message, details) {
|
|
1702
|
+
super(message, "JOB_GRANT_INVALID", 403, "GRANT_INVALID", details);
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
var OwnerNotReadyError = class extends JobsClientError {
|
|
1706
|
+
constructor(message, details) {
|
|
1707
|
+
super(message, "JOB_OWNER_NOT_READY", 403, "OWNER_NOT_READY", details);
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
var JobIdTakenError = class extends JobsClientError {
|
|
1711
|
+
constructor(message, details) {
|
|
1712
|
+
super(message, "JOB_ID_TAKEN", 409, "JOB_ID_TAKEN", details);
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
var JobNotFoundError = class extends JobsClientError {
|
|
1716
|
+
constructor(message, details) {
|
|
1717
|
+
super(message, "JOB_NOT_FOUND", 404, "JOB_NOT_FOUND", details);
|
|
1718
|
+
}
|
|
1719
|
+
};
|
|
1720
|
+
var JobRequestTooLargeError = class extends JobsClientError {
|
|
1721
|
+
constructor(message, errorCode = "BODY_TOO_LARGE", details) {
|
|
1722
|
+
super(message, "JOB_REQUEST_TOO_LARGE", 413, errorCode, details);
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
var JobTimeoutError = class extends JobsClientError {
|
|
1726
|
+
constructor(message, details) {
|
|
1727
|
+
super(message, "JOB_TIMEOUT", void 0, null, details);
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
var JobResultIntegrityError = class extends JobsClientError {
|
|
1731
|
+
constructor(message, details) {
|
|
1732
|
+
super(message, "JOB_RESULT_INTEGRITY", void 0, null, details);
|
|
1733
|
+
}
|
|
1734
|
+
};
|
|
1735
|
+
var JobRejectedError = class extends JobsClientError {
|
|
1736
|
+
constructor(message, status, errorCode = null, details) {
|
|
1737
|
+
super(message, "JOB_REJECTED", status, errorCode, details);
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1740
|
+
var JobTransportError = class extends JobsClientError {
|
|
1741
|
+
constructor(message, cause) {
|
|
1742
|
+
super(message, "JOB_TRANSPORT_ERROR");
|
|
1743
|
+
this.cause = cause;
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1643
1746
|
var LineageReadError = class extends VanaError {
|
|
1644
1747
|
constructor(message, status, errorCode = null, details) {
|
|
1645
1748
|
super(message, "LINEAGE_READ_ERROR");
|
|
@@ -31628,13 +31731,13 @@ var NodeCryptoAdapter = class {
|
|
|
31628
31731
|
*/
|
|
31629
31732
|
async generateKeyPair() {
|
|
31630
31733
|
try {
|
|
31631
|
-
const
|
|
31734
|
+
const secp256k15 = import_secp256k12.default;
|
|
31632
31735
|
let privateKey;
|
|
31633
31736
|
do {
|
|
31634
31737
|
privateKey = (0, import_crypto2.randomBytes)(32);
|
|
31635
|
-
} while (!
|
|
31738
|
+
} while (!secp256k15.privateKeyVerify(privateKey));
|
|
31636
31739
|
const publicKey = Buffer.from(
|
|
31637
|
-
|
|
31740
|
+
secp256k15.publicKeyCreate(privateKey, true)
|
|
31638
31741
|
);
|
|
31639
31742
|
return {
|
|
31640
31743
|
privateKey: privateKey.toString("hex"),
|
|
@@ -32644,15 +32747,1059 @@ var RECORD_DATA_ACCESS_TYPES = {
|
|
|
32644
32747
|
]
|
|
32645
32748
|
};
|
|
32646
32749
|
|
|
32647
|
-
// src/protocol/
|
|
32750
|
+
// src/protocol/identity.ts
|
|
32751
|
+
var secp256k14 = __toESM(require("@noble/secp256k1"), 1);
|
|
32648
32752
|
var import_viem14 = require("viem");
|
|
32753
|
+
var import_accounts = require("viem/accounts");
|
|
32754
|
+
init_interface();
|
|
32755
|
+
var ENCLAVE_IDENTITY_EVIDENCE_VERSION = 1;
|
|
32756
|
+
var USER_PS_ID_DOMAIN = "vana.ps-enclave.v1";
|
|
32757
|
+
var ENCLAVE_WALLET_PURPOSE = "vana.ps-enclave.wallet.v1";
|
|
32758
|
+
var MASTER_SIGNATURE_DELIVERY_VERSION = "vana.ps-enclave.delivery.v1";
|
|
32759
|
+
var MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS = 600;
|
|
32760
|
+
var SEALED_ENVELOPE_VERSION = 1;
|
|
32761
|
+
var VANA_MAINNET_CHAIN_ID = 1480;
|
|
32762
|
+
var MOKSHA_CHAIN_ID = 14800;
|
|
32763
|
+
var KMS_ISSUED_PREFIX = "dstack-kms-issued";
|
|
32764
|
+
var PREIMAGE_SEPARATOR = ":";
|
|
32765
|
+
var UNCOMPRESSED_PUBLIC_KEY_BYTES = 65;
|
|
32766
|
+
var UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04";
|
|
32767
|
+
var EMPTY_HEX = "0x";
|
|
32768
|
+
function emptyAnchor() {
|
|
32769
|
+
return Object.freeze({
|
|
32770
|
+
kmsRootPubkey: EMPTY_HEX,
|
|
32771
|
+
appIds: Object.freeze([])
|
|
32772
|
+
});
|
|
32773
|
+
}
|
|
32774
|
+
var ENCLAVE_TRUST_ANCHORS = Object.freeze({
|
|
32775
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32776
|
+
[VANA_MAINNET_CHAIN_ID]: emptyAnchor(),
|
|
32777
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32778
|
+
[MOKSHA_CHAIN_ID]: emptyAnchor()
|
|
32779
|
+
});
|
|
32780
|
+
function userPsId(chainId, ownerAddress) {
|
|
32781
|
+
const packed = (0, import_viem14.encodePacked)(
|
|
32782
|
+
["string", "uint256", "address"],
|
|
32783
|
+
[USER_PS_ID_DOMAIN, BigInt(chainId), (0, import_viem14.getAddress)(ownerAddress)]
|
|
32784
|
+
);
|
|
32785
|
+
return (0, import_viem14.keccak256)(packed);
|
|
32786
|
+
}
|
|
32787
|
+
function compressPublicKey(publicKey) {
|
|
32788
|
+
return secp256k14.ProjectivePoint.fromHex(
|
|
32789
|
+
(0, import_viem14.fromHex)(publicKey, "bytes")
|
|
32790
|
+
).toRawBytes(true);
|
|
32791
|
+
}
|
|
32792
|
+
function sameKey(a, b) {
|
|
32793
|
+
return (0, import_viem14.toHex)(compressPublicKey(a)) === (0, import_viem14.toHex)(compressPublicKey(b));
|
|
32794
|
+
}
|
|
32795
|
+
function assertUncompressedKey(publicKey) {
|
|
32796
|
+
const hex = publicKey.slice(2);
|
|
32797
|
+
if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
32798
|
+
throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
|
|
32799
|
+
}
|
|
32800
|
+
}
|
|
32801
|
+
function appRootPreimage(purpose, publicKey) {
|
|
32802
|
+
const keyHex = (0, import_viem14.toHex)(compressPublicKey(publicKey)).slice(2);
|
|
32803
|
+
return (0, import_viem14.keccak256)((0, import_viem14.toBytes)(`${purpose}${PREIMAGE_SEPARATOR}${keyHex}`));
|
|
32804
|
+
}
|
|
32805
|
+
function kmsIssuedPreimage(appId, appRootPublicKey) {
|
|
32806
|
+
const prefix = (0, import_viem14.concat)([
|
|
32807
|
+
(0, import_viem14.toBytes)(`${KMS_ISSUED_PREFIX}${PREIMAGE_SEPARATOR}`),
|
|
32808
|
+
(0, import_viem14.fromHex)(appId, "bytes")
|
|
32809
|
+
]);
|
|
32810
|
+
const compressed = compressPublicKey(appRootPublicKey);
|
|
32811
|
+
return (0, import_viem14.keccak256)((0, import_viem14.concat)([prefix, compressed]));
|
|
32812
|
+
}
|
|
32813
|
+
async function recoverChainKey(hash, signature, link) {
|
|
32814
|
+
try {
|
|
32815
|
+
return (await (0, import_viem14.recoverPublicKey)({ hash, signature })).toLowerCase();
|
|
32816
|
+
} catch {
|
|
32817
|
+
throw new Error(`Invalid enclave signature chain link ${link}`);
|
|
32818
|
+
}
|
|
32819
|
+
}
|
|
32820
|
+
async function verifyEnclaveIdentityEvidence(evidence, anchors, expected) {
|
|
32821
|
+
if (evidence.v !== ENCLAVE_IDENTITY_EVIDENCE_VERSION) {
|
|
32822
|
+
throw new Error("Unsupported enclave identity evidence version");
|
|
32823
|
+
}
|
|
32824
|
+
if (!Number.isInteger(evidence.epoch) || evidence.epoch < 1) {
|
|
32825
|
+
throw new Error("Invalid enclave identity epoch");
|
|
32826
|
+
}
|
|
32827
|
+
if (evidence.chainId !== expected.chainId) {
|
|
32828
|
+
throw new Error(
|
|
32829
|
+
"Enclave identity chain ID does not match expected chain ID"
|
|
32830
|
+
);
|
|
32831
|
+
}
|
|
32832
|
+
if (!(0, import_viem14.isAddressEqual)(evidence.ownerAddress, expected.ownerAddress)) {
|
|
32833
|
+
throw new Error("Enclave identity owner does not match expected owner");
|
|
32834
|
+
}
|
|
32835
|
+
if (evidence.epoch !== expected.epoch) {
|
|
32836
|
+
throw new Error("Enclave identity epoch does not match expected epoch");
|
|
32837
|
+
}
|
|
32838
|
+
const expectedUserPsId = userPsId(expected.chainId, expected.ownerAddress);
|
|
32839
|
+
if (evidence.userPsId.toLowerCase() !== expectedUserPsId.toLowerCase()) {
|
|
32840
|
+
throw new Error("Enclave userPsId does not match expected identity");
|
|
32841
|
+
}
|
|
32842
|
+
if (evidence.purpose !== ENCLAVE_WALLET_PURPOSE) {
|
|
32843
|
+
throw new Error("Unexpected enclave wallet purpose");
|
|
32844
|
+
}
|
|
32845
|
+
if (anchors.kmsRootPubkey === EMPTY_HEX) {
|
|
32846
|
+
throw new Error("KMS root trust anchor is not provisioned");
|
|
32847
|
+
}
|
|
32848
|
+
assertUncompressedKey(evidence.publicKey);
|
|
32849
|
+
const derivedAddress = (0, import_accounts.publicKeyToAddress)(evidence.publicKey);
|
|
32850
|
+
if ((0, import_viem14.getAddress)(derivedAddress) !== (0, import_viem14.getAddress)(evidence.address)) {
|
|
32851
|
+
throw new Error("Enclave public key does not match its address");
|
|
32852
|
+
}
|
|
32853
|
+
const appRootPublicKey = await recoverChainKey(
|
|
32854
|
+
appRootPreimage(evidence.purpose, evidence.publicKey),
|
|
32855
|
+
evidence.signatureChain[0],
|
|
32856
|
+
0
|
|
32857
|
+
);
|
|
32858
|
+
const kmsRootPublicKey = await recoverChainKey(
|
|
32859
|
+
kmsIssuedPreimage(evidence.appId, appRootPublicKey),
|
|
32860
|
+
evidence.signatureChain[1],
|
|
32861
|
+
1
|
|
32862
|
+
);
|
|
32863
|
+
let matchesAnchor;
|
|
32864
|
+
try {
|
|
32865
|
+
matchesAnchor = sameKey(kmsRootPublicKey, anchors.kmsRootPubkey);
|
|
32866
|
+
} catch {
|
|
32867
|
+
throw new Error("KMS root trust anchor is malformed");
|
|
32868
|
+
}
|
|
32869
|
+
if (!matchesAnchor) {
|
|
32870
|
+
throw new Error("KMS root public key does not match the trust anchor");
|
|
32871
|
+
}
|
|
32872
|
+
if ((0, import_viem14.keccak256)(kmsRootPublicKey) !== evidence.kmsRootFingerprint.toLowerCase()) {
|
|
32873
|
+
throw new Error("KMS root fingerprint does not match the evidence");
|
|
32874
|
+
}
|
|
32875
|
+
const appId = evidence.appId.toLowerCase();
|
|
32876
|
+
if (!anchors.appIds.some((allowedAppId) => allowedAppId.toLowerCase() === appId)) {
|
|
32877
|
+
throw new Error("Enclave app ID is not trusted");
|
|
32878
|
+
}
|
|
32879
|
+
}
|
|
32880
|
+
async function buildMasterSignatureDelivery(evidence, masterSignature, now = Math.floor(Date.now() / 1e3)) {
|
|
32881
|
+
deriveMasterKey(masterSignature);
|
|
32882
|
+
const signerAddress = await recoverServerOwner(masterSignature);
|
|
32883
|
+
if (!(0, import_viem14.isAddressEqual)(signerAddress, evidence.ownerAddress)) {
|
|
32884
|
+
throw new Error("Master signature signer does not match evidence owner");
|
|
32885
|
+
}
|
|
32886
|
+
return {
|
|
32887
|
+
v: MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
32888
|
+
userPsId: evidence.userPsId,
|
|
32889
|
+
epoch: evidence.epoch,
|
|
32890
|
+
enclaveAddress: evidence.address,
|
|
32891
|
+
ownerAddress: evidence.ownerAddress,
|
|
32892
|
+
masterSignature,
|
|
32893
|
+
issuedAt: now
|
|
32894
|
+
};
|
|
32895
|
+
}
|
|
32896
|
+
async function encryptMasterSignatureDelivery(delivery, publicKey, ecies) {
|
|
32897
|
+
assertUncompressedKey(publicKey);
|
|
32898
|
+
if (!(0, import_viem14.isAddressEqual)((0, import_accounts.publicKeyToAddress)(publicKey), delivery.enclaveAddress)) {
|
|
32899
|
+
throw new Error(
|
|
32900
|
+
"Public key does not belong to the delivery's enclave address"
|
|
32901
|
+
);
|
|
32902
|
+
}
|
|
32903
|
+
const plaintext = (0, import_viem14.toBytes)(JSON.stringify(delivery));
|
|
32904
|
+
const encrypted = await ecies.encrypt((0, import_viem14.fromHex)(publicKey, "bytes"), plaintext);
|
|
32905
|
+
return `0x${serializeECIES(encrypted)}`;
|
|
32906
|
+
}
|
|
32907
|
+
|
|
32908
|
+
// src/protocol/jobs.ts
|
|
32909
|
+
var JOB_PROTOCOL_VERSION = 1;
|
|
32910
|
+
var JOB_OPERATIONS = ["raw_read", "inference"];
|
|
32911
|
+
var JOB_STATES = [
|
|
32912
|
+
"queued",
|
|
32913
|
+
"claimed",
|
|
32914
|
+
"running",
|
|
32915
|
+
"completed",
|
|
32916
|
+
"failed",
|
|
32917
|
+
"expired",
|
|
32918
|
+
"cancelled"
|
|
32919
|
+
];
|
|
32920
|
+
var DEFAULT_LEASE_SECONDS = 30;
|
|
32921
|
+
var MAX_LEASE_SECONDS = 300;
|
|
32922
|
+
var MAX_ATTEMPTS = 3;
|
|
32923
|
+
var MAX_WAIT_SECONDS = 25;
|
|
32924
|
+
var CLAIM_POLL_FLOOR_MS = 1e3;
|
|
32925
|
+
var DEFAULT_JOB_DEADLINE_SECONDS = 600;
|
|
32926
|
+
var MAX_JOB_DEADLINE_SECONDS = 3600;
|
|
32927
|
+
|
|
32928
|
+
// src/protocol/jobs-client.ts
|
|
32929
|
+
var import_node_crypto = require("node:crypto");
|
|
32930
|
+
var import_sha26 = require("@noble/hashes/sha2");
|
|
32931
|
+
var import_viem16 = require("viem");
|
|
32932
|
+
var import_accounts2 = require("viem/accounts");
|
|
32933
|
+
|
|
32934
|
+
// src/crypto/envelope/job.ts
|
|
32935
|
+
var import_sha25 = require("@noble/hashes/sha2");
|
|
32936
|
+
var import_viem15 = require("viem");
|
|
32937
|
+
init_constants();
|
|
32938
|
+
init_interface();
|
|
32939
|
+
var textDecoder = new TextDecoder();
|
|
32940
|
+
var textEncoder = new TextEncoder();
|
|
32941
|
+
var MAX_JOB_RESULT_HEADER_BYTES = 4096;
|
|
32942
|
+
var JOB_RESULT_LENGTH_PREFIX_BYTES = 4;
|
|
32943
|
+
var JobEnvelopeError = class extends Error {
|
|
32944
|
+
constructor(message) {
|
|
32945
|
+
super(message);
|
|
32946
|
+
this.name = "JobEnvelopeError";
|
|
32947
|
+
}
|
|
32948
|
+
};
|
|
32949
|
+
function sortJsonKeys(value) {
|
|
32950
|
+
if (Array.isArray(value)) {
|
|
32951
|
+
return value.map(sortJsonKeys);
|
|
32952
|
+
}
|
|
32953
|
+
if (value !== null && typeof value === "object") {
|
|
32954
|
+
return Object.fromEntries(
|
|
32955
|
+
Object.keys(value).sort().map((key) => [
|
|
32956
|
+
key,
|
|
32957
|
+
sortJsonKeys(value[key])
|
|
32958
|
+
])
|
|
32959
|
+
);
|
|
32960
|
+
}
|
|
32961
|
+
return value;
|
|
32962
|
+
}
|
|
32963
|
+
function canonicalJsonBytes(value) {
|
|
32964
|
+
return textEncoder.encode(JSON.stringify(sortJsonKeys(value)));
|
|
32965
|
+
}
|
|
32966
|
+
function canonicalJobRequestBytes(request) {
|
|
32967
|
+
validateJobRequest(request);
|
|
32968
|
+
return canonicalJsonBytes(request);
|
|
32969
|
+
}
|
|
32970
|
+
function requestPlaintext(envelope) {
|
|
32971
|
+
validateRequestEnvelope(envelope);
|
|
32972
|
+
return canonicalJsonBytes(envelope);
|
|
32973
|
+
}
|
|
32974
|
+
function resultPlaintext(result) {
|
|
32975
|
+
const header = textEncoder.encode(
|
|
32976
|
+
JSON.stringify({
|
|
32977
|
+
v: result.v,
|
|
32978
|
+
jobId: result.jobId,
|
|
32979
|
+
scope: result.scope,
|
|
32980
|
+
version: result.version,
|
|
32981
|
+
contentType: result.contentType
|
|
32982
|
+
})
|
|
32983
|
+
);
|
|
32984
|
+
if (header.length > MAX_JOB_RESULT_HEADER_BYTES) {
|
|
32985
|
+
throw new JobEnvelopeError(
|
|
32986
|
+
`Invalid job result: header exceeds ${MAX_JOB_RESULT_HEADER_BYTES} bytes`
|
|
32987
|
+
);
|
|
32988
|
+
}
|
|
32989
|
+
const plaintext = new Uint8Array(
|
|
32990
|
+
JOB_RESULT_LENGTH_PREFIX_BYTES + header.length + result.body.length
|
|
32991
|
+
);
|
|
32992
|
+
new DataView(plaintext.buffer).setUint32(0, header.length);
|
|
32993
|
+
plaintext.set(header, JOB_RESULT_LENGTH_PREFIX_BYTES);
|
|
32994
|
+
plaintext.set(result.body, JOB_RESULT_LENGTH_PREFIX_BYTES + header.length);
|
|
32995
|
+
return plaintext;
|
|
32996
|
+
}
|
|
32997
|
+
function parseResultPlaintext(plaintext) {
|
|
32998
|
+
if (plaintext.length < JOB_RESULT_LENGTH_PREFIX_BYTES) {
|
|
32999
|
+
throw new JobEnvelopeError(
|
|
33000
|
+
"Invalid job result: missing header length prefix"
|
|
33001
|
+
);
|
|
33002
|
+
}
|
|
33003
|
+
const headerLength = new DataView(
|
|
33004
|
+
plaintext.buffer,
|
|
33005
|
+
plaintext.byteOffset,
|
|
33006
|
+
JOB_RESULT_LENGTH_PREFIX_BYTES
|
|
33007
|
+
).getUint32(0);
|
|
33008
|
+
if (headerLength > MAX_JOB_RESULT_HEADER_BYTES) {
|
|
33009
|
+
throw new JobEnvelopeError(
|
|
33010
|
+
`Invalid job result: header exceeds ${MAX_JOB_RESULT_HEADER_BYTES} bytes`
|
|
33011
|
+
);
|
|
33012
|
+
}
|
|
33013
|
+
const remainingLength = plaintext.length - JOB_RESULT_LENGTH_PREFIX_BYTES;
|
|
33014
|
+
if (headerLength > remainingLength) {
|
|
33015
|
+
throw new JobEnvelopeError(
|
|
33016
|
+
"Invalid job result: header length exceeds payload"
|
|
33017
|
+
);
|
|
33018
|
+
}
|
|
33019
|
+
const headerEnd = JOB_RESULT_LENGTH_PREFIX_BYTES + headerLength;
|
|
33020
|
+
const header = parseObject(
|
|
33021
|
+
plaintext.subarray(JOB_RESULT_LENGTH_PREFIX_BYTES, headerEnd),
|
|
33022
|
+
"job result header"
|
|
33023
|
+
);
|
|
33024
|
+
return validateResult({ ...header, body: plaintext.subarray(headerEnd) });
|
|
33025
|
+
}
|
|
33026
|
+
function encryptedBytesToBase64(encrypted) {
|
|
33027
|
+
return toBase64((0, import_viem15.fromHex)(`0x${serializeECIES(encrypted)}`, "bytes"));
|
|
33028
|
+
}
|
|
33029
|
+
function encryptedToBytes(encrypted) {
|
|
33030
|
+
const bytes = new Uint8Array(
|
|
33031
|
+
encrypted.iv.length + encrypted.ephemPublicKey.length + encrypted.ciphertext.length + encrypted.mac.length
|
|
33032
|
+
);
|
|
33033
|
+
let offset = 0;
|
|
33034
|
+
bytes.set(encrypted.iv, offset);
|
|
33035
|
+
offset += encrypted.iv.length;
|
|
33036
|
+
bytes.set(encrypted.ephemPublicKey, offset);
|
|
33037
|
+
offset += encrypted.ephemPublicKey.length;
|
|
33038
|
+
bytes.set(encrypted.ciphertext, offset);
|
|
33039
|
+
offset += encrypted.ciphertext.length;
|
|
33040
|
+
bytes.set(encrypted.mac, offset);
|
|
33041
|
+
return bytes;
|
|
33042
|
+
}
|
|
33043
|
+
function bytesToEncrypted(bytes) {
|
|
33044
|
+
const absoluteMinLength = FORMAT.IV_LENGTH + 1 + MAC.LENGTH + 1;
|
|
33045
|
+
if (bytes.length < absoluteMinLength) {
|
|
33046
|
+
throw new ECIESError(
|
|
33047
|
+
`Invalid ECIES data: too short (${bytes.length} bytes, minimum ${absoluteMinLength} bytes required)`,
|
|
33048
|
+
"DECRYPTION_FAILED"
|
|
33049
|
+
);
|
|
33050
|
+
}
|
|
33051
|
+
const prefix = bytes[FORMAT.EPHEMERAL_KEY_OFFSET];
|
|
33052
|
+
if (prefix !== CURVE.PREFIX.UNCOMPRESSED) {
|
|
33053
|
+
throw new ECIESError(
|
|
33054
|
+
`Invalid ephemeral public key: must be uncompressed format (0x04 prefix), got 0x${prefix.toString(16).padStart(2, "0")}`,
|
|
33055
|
+
"DECRYPTION_FAILED"
|
|
33056
|
+
);
|
|
33057
|
+
}
|
|
33058
|
+
const ephemKeySize = CURVE.UNCOMPRESSED_PUBLIC_KEY_LENGTH;
|
|
33059
|
+
const minLength = FORMAT.IV_LENGTH + ephemKeySize + MAC.LENGTH + 1;
|
|
33060
|
+
if (bytes.length < minLength) {
|
|
33061
|
+
throw new ECIESError(
|
|
33062
|
+
`Invalid ECIES data: too short (${bytes.length} bytes, minimum ${minLength} bytes required)`,
|
|
33063
|
+
"DECRYPTION_FAILED"
|
|
33064
|
+
);
|
|
33065
|
+
}
|
|
33066
|
+
return {
|
|
33067
|
+
iv: bytes.subarray(FORMAT.IV_OFFSET, FORMAT.IV_OFFSET + FORMAT.IV_LENGTH),
|
|
33068
|
+
ephemPublicKey: bytes.subarray(
|
|
33069
|
+
FORMAT.EPHEMERAL_KEY_OFFSET,
|
|
33070
|
+
FORMAT.EPHEMERAL_KEY_OFFSET + ephemKeySize
|
|
33071
|
+
),
|
|
33072
|
+
ciphertext: bytes.subarray(
|
|
33073
|
+
FORMAT.EPHEMERAL_KEY_OFFSET + ephemKeySize,
|
|
33074
|
+
bytes.length - MAC.LENGTH
|
|
33075
|
+
),
|
|
33076
|
+
mac: bytes.subarray(bytes.length - MAC.LENGTH)
|
|
33077
|
+
};
|
|
33078
|
+
}
|
|
33079
|
+
function base64ToEncrypted(ciphertext) {
|
|
33080
|
+
return deserializeECIES((0, import_viem15.toHex)(fromBase64(ciphertext)));
|
|
33081
|
+
}
|
|
33082
|
+
function parseObject(plaintext, kind) {
|
|
33083
|
+
try {
|
|
33084
|
+
const value = JSON.parse(textDecoder.decode(plaintext));
|
|
33085
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
33086
|
+
throw new JobEnvelopeError(`Invalid ${kind}: expected an object`);
|
|
33087
|
+
}
|
|
33088
|
+
return value;
|
|
33089
|
+
} catch (error) {
|
|
33090
|
+
if (error instanceof JobEnvelopeError) throw error;
|
|
33091
|
+
throw new JobEnvelopeError(`Invalid ${kind}: malformed JSON`);
|
|
33092
|
+
}
|
|
33093
|
+
}
|
|
33094
|
+
function isPlainObject2(value) {
|
|
33095
|
+
if (value === null || typeof value !== "object") return false;
|
|
33096
|
+
const prototype = Object.getPrototypeOf(value);
|
|
33097
|
+
return prototype === Object.prototype || prototype === null;
|
|
33098
|
+
}
|
|
33099
|
+
function requirePlainObject(value, field, kind) {
|
|
33100
|
+
if (!isPlainObject2(value)) {
|
|
33101
|
+
throw new JobEnvelopeError(`Invalid ${kind}: invalid ${field}`);
|
|
33102
|
+
}
|
|
33103
|
+
}
|
|
33104
|
+
function requireExactKeys(value, expectedKeys, kind) {
|
|
33105
|
+
for (const key of expectedKeys) {
|
|
33106
|
+
if (!Object.hasOwn(value, key) || value[key] === void 0) {
|
|
33107
|
+
throw new JobEnvelopeError(`Invalid ${kind}: missing ${key}`);
|
|
33108
|
+
}
|
|
33109
|
+
}
|
|
33110
|
+
const expected = new Set(expectedKeys);
|
|
33111
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
33112
|
+
if (!expected.has(key)) {
|
|
33113
|
+
throw new JobEnvelopeError(
|
|
33114
|
+
`Invalid ${kind}: unknown field ${String(key)}`
|
|
33115
|
+
);
|
|
33116
|
+
}
|
|
33117
|
+
}
|
|
33118
|
+
}
|
|
33119
|
+
function requireString(value, field, kind) {
|
|
33120
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
33121
|
+
throw new JobEnvelopeError(`Invalid ${kind}: missing ${field}`);
|
|
33122
|
+
}
|
|
33123
|
+
}
|
|
33124
|
+
function validateJobRequest(value) {
|
|
33125
|
+
requirePlainObject(value, "request", "job request");
|
|
33126
|
+
requireExactKeys(
|
|
33127
|
+
value,
|
|
33128
|
+
[
|
|
33129
|
+
"v",
|
|
33130
|
+
"jobId",
|
|
33131
|
+
"owner",
|
|
33132
|
+
"builder",
|
|
33133
|
+
"builderPublicKey",
|
|
33134
|
+
"grantId",
|
|
33135
|
+
"scope",
|
|
33136
|
+
"operation",
|
|
33137
|
+
"pinnedVersion",
|
|
33138
|
+
"deadline"
|
|
33139
|
+
],
|
|
33140
|
+
"job request"
|
|
33141
|
+
);
|
|
33142
|
+
if (value.v !== JOB_PROTOCOL_VERSION) {
|
|
33143
|
+
throw new JobEnvelopeError(
|
|
33144
|
+
`Unsupported job request version: ${String(value.v)}`
|
|
33145
|
+
);
|
|
33146
|
+
}
|
|
33147
|
+
requireString(value.jobId, "jobId", "job request");
|
|
33148
|
+
if (typeof value.owner !== "string" || !(0, import_viem15.isAddress)(value.owner)) {
|
|
33149
|
+
throw new JobEnvelopeError("Invalid job request: invalid owner");
|
|
33150
|
+
}
|
|
33151
|
+
if (typeof value.builder !== "string" || !(0, import_viem15.isAddress)(value.builder)) {
|
|
33152
|
+
throw new JobEnvelopeError("Invalid job request: invalid builder");
|
|
33153
|
+
}
|
|
33154
|
+
if (typeof value.builderPublicKey !== "string" || !(0, import_viem15.isHex)(value.builderPublicKey)) {
|
|
33155
|
+
throw new JobEnvelopeError("Invalid job request: invalid builderPublicKey");
|
|
33156
|
+
}
|
|
33157
|
+
if (typeof value.grantId !== "string" || !(0, import_viem15.isHex)(value.grantId)) {
|
|
33158
|
+
throw new JobEnvelopeError("Invalid job request: invalid grantId");
|
|
33159
|
+
}
|
|
33160
|
+
requireString(value.scope, "scope", "job request");
|
|
33161
|
+
if (!JOB_OPERATIONS.includes(value.operation)) {
|
|
33162
|
+
throw new JobEnvelopeError("Invalid job request: invalid operation");
|
|
33163
|
+
}
|
|
33164
|
+
if (value.pinnedVersion !== null && typeof value.pinnedVersion !== "string") {
|
|
33165
|
+
throw new JobEnvelopeError("Invalid job request: missing pinnedVersion");
|
|
33166
|
+
}
|
|
33167
|
+
if (typeof value.deadline !== "string" || !Number.isFinite(Date.parse(value.deadline))) {
|
|
33168
|
+
throw new JobEnvelopeError("Invalid job request: invalid deadline");
|
|
33169
|
+
}
|
|
33170
|
+
return value;
|
|
33171
|
+
}
|
|
33172
|
+
function validateRequestEnvelope(value) {
|
|
33173
|
+
requirePlainObject(value, "envelope", "job request envelope");
|
|
33174
|
+
requireExactKeys(value, ["request", "auth"], "job request envelope");
|
|
33175
|
+
validateJobRequest(value.request);
|
|
33176
|
+
requireString(value.auth, "auth", "job request envelope");
|
|
33177
|
+
return value;
|
|
33178
|
+
}
|
|
33179
|
+
function validateResult(value) {
|
|
33180
|
+
requirePlainObject(value, "result", "job result");
|
|
33181
|
+
requireExactKeys(
|
|
33182
|
+
value,
|
|
33183
|
+
["v", "jobId", "scope", "version", "contentType", "body"],
|
|
33184
|
+
"job result"
|
|
33185
|
+
);
|
|
33186
|
+
if (value.v !== JOB_PROTOCOL_VERSION) {
|
|
33187
|
+
throw new JobEnvelopeError(
|
|
33188
|
+
`Unsupported job result version: ${String(value.v)}`
|
|
33189
|
+
);
|
|
33190
|
+
}
|
|
33191
|
+
for (const field of ["jobId", "scope", "contentType"]) {
|
|
33192
|
+
requireString(value[field], field, "job result");
|
|
33193
|
+
}
|
|
33194
|
+
if (!(value.body instanceof Uint8Array)) {
|
|
33195
|
+
throw new JobEnvelopeError("Invalid job result: missing body");
|
|
33196
|
+
}
|
|
33197
|
+
if (value.version !== null && typeof value.version !== "string") {
|
|
33198
|
+
throw new JobEnvelopeError("Invalid job result: missing version");
|
|
33199
|
+
}
|
|
33200
|
+
return value;
|
|
33201
|
+
}
|
|
33202
|
+
async function sealJobRequest(envelope, enclavePublicKey, ecies) {
|
|
33203
|
+
const encrypted = await ecies.encrypt(
|
|
33204
|
+
(0, import_viem15.fromHex)(enclavePublicKey, "bytes"),
|
|
33205
|
+
requestPlaintext(envelope)
|
|
33206
|
+
);
|
|
33207
|
+
return encryptedBytesToBase64(encrypted);
|
|
33208
|
+
}
|
|
33209
|
+
async function openJobRequest(ciphertext, privateKey, ecies) {
|
|
33210
|
+
const plaintext = await ecies.decrypt(
|
|
33211
|
+
privateKey,
|
|
33212
|
+
base64ToEncrypted(ciphertext)
|
|
33213
|
+
);
|
|
33214
|
+
return validateRequestEnvelope(
|
|
33215
|
+
parseObject(plaintext, "job request envelope")
|
|
33216
|
+
);
|
|
33217
|
+
}
|
|
33218
|
+
async function sealJobResult(result, builderPublicKey, ecies) {
|
|
33219
|
+
validateResult(result);
|
|
33220
|
+
const encrypted = await ecies.encrypt(
|
|
33221
|
+
(0, import_viem15.fromHex)(builderPublicKey, "bytes"),
|
|
33222
|
+
resultPlaintext(result)
|
|
33223
|
+
);
|
|
33224
|
+
const bytes = encryptedToBytes(encrypted);
|
|
33225
|
+
return { bytes, hash: (0, import_viem15.bytesToHex)((0, import_sha25.sha256)(bytes)), size: bytes.length };
|
|
33226
|
+
}
|
|
33227
|
+
async function openJobResult(sealedBytes, builderPrivateKey, ecies, expect) {
|
|
33228
|
+
const plaintext = await ecies.decrypt(
|
|
33229
|
+
(0, import_viem15.fromHex)(builderPrivateKey, "bytes"),
|
|
33230
|
+
bytesToEncrypted(sealedBytes)
|
|
33231
|
+
);
|
|
33232
|
+
const result = parseResultPlaintext(plaintext);
|
|
33233
|
+
if (result.jobId !== expect.jobId) {
|
|
33234
|
+
throw new JobEnvelopeError(
|
|
33235
|
+
`Job result ID ${result.jobId} does not match expected job ID ${expect.jobId}`
|
|
33236
|
+
);
|
|
33237
|
+
}
|
|
33238
|
+
if (expect.scope !== void 0 && result.scope !== expect.scope) {
|
|
33239
|
+
throw new JobEnvelopeError(
|
|
33240
|
+
`Job result scope ${result.scope} does not match expected scope ${expect.scope}`
|
|
33241
|
+
);
|
|
33242
|
+
}
|
|
33243
|
+
if (expect.version !== void 0 && result.version !== expect.version) {
|
|
33244
|
+
throw new JobEnvelopeError(
|
|
33245
|
+
`Job result version ${String(result.version)} does not match expected version ${String(expect.version)}`
|
|
33246
|
+
);
|
|
33247
|
+
}
|
|
33248
|
+
return result;
|
|
33249
|
+
}
|
|
33250
|
+
|
|
33251
|
+
// src/protocol/write-signer.ts
|
|
33252
|
+
function isRecord(value) {
|
|
33253
|
+
return value !== null && typeof value === "object";
|
|
33254
|
+
}
|
|
33255
|
+
function isViemWriteAccount(source) {
|
|
33256
|
+
return isRecord(source) && source.type === "local" && typeof source.address === "string" && typeof source.signMessage === "function";
|
|
33257
|
+
}
|
|
33258
|
+
function isViemWriteWalletClient(source) {
|
|
33259
|
+
return isRecord(source) && typeof source.signMessage === "function" && source.type !== "local" && (source.type === "walletClient" || "transport" in source);
|
|
33260
|
+
}
|
|
33261
|
+
function accountAddress(account) {
|
|
33262
|
+
return typeof account === "string" ? account : account.address;
|
|
33263
|
+
}
|
|
33264
|
+
function resolveWriteSigner(source, options = {}) {
|
|
33265
|
+
if (isViemWriteWalletClient(source)) {
|
|
33266
|
+
const account = options.account ?? source.account;
|
|
33267
|
+
if (account === void 0) {
|
|
33268
|
+
throw new WriteRequestError(
|
|
33269
|
+
"Viem wallet client requires an account option or account property"
|
|
33270
|
+
);
|
|
33271
|
+
}
|
|
33272
|
+
return {
|
|
33273
|
+
address: accountAddress(account),
|
|
33274
|
+
signMessage: (message) => source.signMessage({ account, message })
|
|
33275
|
+
};
|
|
33276
|
+
}
|
|
33277
|
+
if (isViemWriteAccount(source)) {
|
|
33278
|
+
return {
|
|
33279
|
+
address: source.address,
|
|
33280
|
+
signMessage: (message) => source.signMessage({ message })
|
|
33281
|
+
};
|
|
33282
|
+
}
|
|
33283
|
+
if (!isRecord(source) || typeof source.signMessage !== "function") {
|
|
33284
|
+
throw new WriteRequestError(
|
|
33285
|
+
"signer must be a viem LocalAccount, a viem WalletClient, or a { signMessage } object"
|
|
33286
|
+
);
|
|
33287
|
+
}
|
|
33288
|
+
return source;
|
|
33289
|
+
}
|
|
33290
|
+
|
|
33291
|
+
// src/protocol/jobs-client.ts
|
|
33292
|
+
var IDENTITY_PATH = "/v1/identity";
|
|
33293
|
+
var JOBS_PATH = "/v1/jobs";
|
|
33294
|
+
var JOB_EXECUTE_PATH = "/v1/jobs/execute";
|
|
33295
|
+
var AUTHORIZATION_HEADER = "Authorization";
|
|
33296
|
+
var CONTENT_TYPE_HEADER = "Content-Type";
|
|
33297
|
+
var JSON_CONTENT_TYPE = "application/json";
|
|
33298
|
+
var GET_METHOD = "GET";
|
|
33299
|
+
var POST_METHOD = "POST";
|
|
33300
|
+
var RAW_READ_OPERATION = "raw_read";
|
|
33301
|
+
var SEALED_IDENTITY_STATE = "sealed";
|
|
33302
|
+
var HTTP_OK = 200;
|
|
33303
|
+
var HTTP_ACCEPTED = 202;
|
|
33304
|
+
var HTTP_UNAUTHORIZED = 401;
|
|
33305
|
+
var HTTP_FORBIDDEN = 403;
|
|
33306
|
+
var HTTP_NOT_FOUND = 404;
|
|
33307
|
+
var HTTP_CONFLICT = 409;
|
|
33308
|
+
var HTTP_PAYLOAD_TOO_LARGE = 413;
|
|
33309
|
+
var MILLISECONDS_PER_SECOND = 1e3;
|
|
33310
|
+
var DEFAULT_JOB_TIMEOUT_MS = 12e4;
|
|
33311
|
+
var DEFAULT_JOB_POLL_MS = CLAIM_POLL_FLOOR_MS;
|
|
33312
|
+
var TERMINAL_JOB_STATES = /* @__PURE__ */ new Set([
|
|
33313
|
+
"completed",
|
|
33314
|
+
"failed",
|
|
33315
|
+
"expired",
|
|
33316
|
+
"cancelled"
|
|
33317
|
+
]);
|
|
33318
|
+
function isRecord2(value) {
|
|
33319
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
33320
|
+
}
|
|
33321
|
+
function normalizeGateway(gatewayUrl) {
|
|
33322
|
+
try {
|
|
33323
|
+
const url = new URL(gatewayUrl);
|
|
33324
|
+
if (url.pathname !== "/" || url.search !== "" || url.hash !== "") {
|
|
33325
|
+
throw new JobRejectedError(
|
|
33326
|
+
"gatewayUrl must be an origin without a path, query, or fragment"
|
|
33327
|
+
);
|
|
33328
|
+
}
|
|
33329
|
+
return {
|
|
33330
|
+
baseUrl: url.origin,
|
|
33331
|
+
audience: url.origin
|
|
33332
|
+
};
|
|
33333
|
+
} catch (error) {
|
|
33334
|
+
if (error instanceof JobRejectedError) throw error;
|
|
33335
|
+
throw new JobRejectedError(
|
|
33336
|
+
"gatewayUrl must be an absolute URL",
|
|
33337
|
+
void 0,
|
|
33338
|
+
null,
|
|
33339
|
+
{
|
|
33340
|
+
cause: error instanceof Error ? error.message : String(error)
|
|
33341
|
+
}
|
|
33342
|
+
);
|
|
33343
|
+
}
|
|
33344
|
+
}
|
|
33345
|
+
function resolveFetch(fetchFn) {
|
|
33346
|
+
const resolved = fetchFn ?? globalThis.fetch;
|
|
33347
|
+
if (resolved === void 0) {
|
|
33348
|
+
throw new JobRejectedError("No fetch implementation available");
|
|
33349
|
+
}
|
|
33350
|
+
return resolved;
|
|
33351
|
+
}
|
|
33352
|
+
function sourcePublicKey(source) {
|
|
33353
|
+
if (isRecord2(source) && typeof source["publicKey"] === "string") {
|
|
33354
|
+
return source["publicKey"];
|
|
33355
|
+
}
|
|
33356
|
+
return void 0;
|
|
33357
|
+
}
|
|
33358
|
+
function resolveBuilder(options) {
|
|
33359
|
+
if (options.builderPrivateKey && options.builderAccount) {
|
|
33360
|
+
throw new JobRejectedError(
|
|
33361
|
+
"Provide builderPrivateKey or builderAccount, not both"
|
|
33362
|
+
);
|
|
33363
|
+
}
|
|
33364
|
+
let source;
|
|
33365
|
+
try {
|
|
33366
|
+
source = options.builderPrivateKey ? (0, import_accounts2.privateKeyToAccount)(options.builderPrivateKey) : options.builderAccount;
|
|
33367
|
+
} catch (error) {
|
|
33368
|
+
throw new JobRejectedError("Invalid builder private key", void 0, null, {
|
|
33369
|
+
cause: error instanceof Error ? error.message : String(error)
|
|
33370
|
+
});
|
|
33371
|
+
}
|
|
33372
|
+
if (!source) {
|
|
33373
|
+
throw new JobRejectedError(
|
|
33374
|
+
"builderPrivateKey or builderAccount is required"
|
|
33375
|
+
);
|
|
33376
|
+
}
|
|
33377
|
+
let signer;
|
|
33378
|
+
try {
|
|
33379
|
+
signer = resolveWriteSigner(source);
|
|
33380
|
+
} catch (error) {
|
|
33381
|
+
throw new JobRejectedError("Invalid builder signer", void 0, null, {
|
|
33382
|
+
cause: error instanceof Error ? error.message : String(error)
|
|
33383
|
+
});
|
|
33384
|
+
}
|
|
33385
|
+
const publicKey = sourcePublicKey(source);
|
|
33386
|
+
if (!signer.address || !publicKey) {
|
|
33387
|
+
throw new JobRejectedError(
|
|
33388
|
+
"Builder signer must expose both address and publicKey"
|
|
33389
|
+
);
|
|
33390
|
+
}
|
|
33391
|
+
return {
|
|
33392
|
+
builder: {
|
|
33393
|
+
address: signer.address,
|
|
33394
|
+
publicKey,
|
|
33395
|
+
signMessage: signer.signMessage
|
|
33396
|
+
},
|
|
33397
|
+
...options.builderPrivateKey ? { privateKey: options.builderPrivateKey } : {}
|
|
33398
|
+
};
|
|
33399
|
+
}
|
|
33400
|
+
function clampInteger(value, fallback, minimum, maximum, field) {
|
|
33401
|
+
const resolved = value ?? fallback;
|
|
33402
|
+
if (!Number.isFinite(resolved)) {
|
|
33403
|
+
throw new JobRejectedError(`${field} must be a finite number`);
|
|
33404
|
+
}
|
|
33405
|
+
return Math.min(maximum, Math.max(minimum, Math.trunc(resolved)));
|
|
33406
|
+
}
|
|
33407
|
+
async function responseBody(response) {
|
|
33408
|
+
try {
|
|
33409
|
+
return await response.json();
|
|
33410
|
+
} catch {
|
|
33411
|
+
return null;
|
|
33412
|
+
}
|
|
33413
|
+
}
|
|
33414
|
+
function gatewayErrorBody(body, fallback) {
|
|
33415
|
+
if (!isRecord2(body)) return { code: null, message: fallback };
|
|
33416
|
+
const code = typeof body["code"] === "string" ? body["code"] : null;
|
|
33417
|
+
const message = typeof body["error"] === "string" ? body["error"] : typeof body["message"] === "string" ? body["message"] : fallback;
|
|
33418
|
+
const reason = typeof body["reason"] === "string" ? body["reason"] : void 0;
|
|
33419
|
+
const details = isRecord2(body["details"]) ? body["details"] : void 0;
|
|
33420
|
+
return {
|
|
33421
|
+
code,
|
|
33422
|
+
message,
|
|
33423
|
+
...reason ? { reason } : {},
|
|
33424
|
+
...details ? { details } : {}
|
|
33425
|
+
};
|
|
33426
|
+
}
|
|
33427
|
+
async function rejectedResponse(response, fallback) {
|
|
33428
|
+
const parsed = gatewayErrorBody(await responseBody(response), fallback);
|
|
33429
|
+
const details = response.status === HTTP_UNAUTHORIZED && parsed.reason ? { ...parsed.details, reason: parsed.reason } : parsed.details;
|
|
33430
|
+
const message = response.status === HTTP_UNAUTHORIZED && parsed.reason ? `${parsed.message}: ${parsed.reason}` : parsed.message;
|
|
33431
|
+
if (response.status === HTTP_FORBIDDEN) {
|
|
33432
|
+
if (parsed.code === "BUILDER_UNKNOWN") {
|
|
33433
|
+
return new BuilderUnknownError(parsed.message, details);
|
|
33434
|
+
}
|
|
33435
|
+
if (parsed.code === "GRANT_INVALID") {
|
|
33436
|
+
return new GrantInvalidError(parsed.message, details);
|
|
33437
|
+
}
|
|
33438
|
+
if (parsed.code === "OWNER_NOT_READY") {
|
|
33439
|
+
return new OwnerNotReadyError(parsed.message, details);
|
|
33440
|
+
}
|
|
33441
|
+
}
|
|
33442
|
+
if (response.status === HTTP_NOT_FOUND) {
|
|
33443
|
+
return new JobNotFoundError(parsed.message, details);
|
|
33444
|
+
}
|
|
33445
|
+
if (response.status === HTTP_CONFLICT && parsed.code === "JOB_ID_TAKEN") {
|
|
33446
|
+
return new JobIdTakenError(parsed.message, details);
|
|
33447
|
+
}
|
|
33448
|
+
if (response.status === HTTP_PAYLOAD_TOO_LARGE) {
|
|
33449
|
+
return new JobRequestTooLargeError(parsed.message, parsed.code, details);
|
|
33450
|
+
}
|
|
33451
|
+
return new JobRejectedError(message, response.status, parsed.code, details);
|
|
33452
|
+
}
|
|
33453
|
+
function requireStatus(value, status) {
|
|
33454
|
+
if (!isRecord2(value) || !isNonEmptyString(value["jobId"]) || typeof value["state"] !== "string" || !JOB_STATES.includes(value["state"]) || !isNonEmptyString(value["owner"]) || !isNonEmptyString(value["grantId"]) || !isNonEmptyString(value["scope"]) || !isNonEmptyString(value["operation"]) || !JOB_OPERATIONS.includes(value["operation"])) {
|
|
33455
|
+
throw new JobRejectedError(
|
|
33456
|
+
"Gateway response did not contain a job status",
|
|
33457
|
+
status
|
|
33458
|
+
);
|
|
33459
|
+
}
|
|
33460
|
+
return value;
|
|
33461
|
+
}
|
|
33462
|
+
function isNonEmptyString(value) {
|
|
33463
|
+
return typeof value === "string" && value.length > 0;
|
|
33464
|
+
}
|
|
33465
|
+
function hasMatchingIdentityKey(value) {
|
|
33466
|
+
const address = value["address"];
|
|
33467
|
+
const publicKey = value["publicKey"];
|
|
33468
|
+
if (typeof address !== "string" || !(0, import_viem16.isAddress)(address) || typeof publicKey !== "string" || !(0, import_viem16.isHex)(publicKey)) {
|
|
33469
|
+
return false;
|
|
33470
|
+
}
|
|
33471
|
+
try {
|
|
33472
|
+
return (0, import_accounts2.publicKeyToAddress)(publicKey).toLowerCase() === address.toLowerCase();
|
|
33473
|
+
} catch {
|
|
33474
|
+
return false;
|
|
33475
|
+
}
|
|
33476
|
+
}
|
|
33477
|
+
function hasExpectedIdentity(value, owner, chainId) {
|
|
33478
|
+
const identityOwner = value["ownerAddress"];
|
|
33479
|
+
const identityChainId = value["chainId"];
|
|
33480
|
+
const identityUserPsId = value["userPsId"];
|
|
33481
|
+
if (!hasMatchingIdentityKey(value) || typeof identityOwner !== "string" || !(0, import_viem16.isAddress)(identityOwner) || typeof identityChainId !== "number" || typeof identityUserPsId !== "string" || !(0, import_viem16.isHex)(identityUserPsId)) {
|
|
33482
|
+
return false;
|
|
33483
|
+
}
|
|
33484
|
+
return (0, import_viem16.isAddressEqual)(identityOwner, owner) && identityChainId === chainId && identityUserPsId.toLowerCase() === userPsId(chainId, owner).toLowerCase();
|
|
33485
|
+
}
|
|
33486
|
+
function sleep2(ms) {
|
|
33487
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
33488
|
+
}
|
|
33489
|
+
function requireFiniteDuration(value, field) {
|
|
33490
|
+
if (!Number.isFinite(value)) {
|
|
33491
|
+
throw new JobRejectedError(`${field} must be a finite number`);
|
|
33492
|
+
}
|
|
33493
|
+
return Math.max(0, value);
|
|
33494
|
+
}
|
|
33495
|
+
function createJobsClient(options) {
|
|
33496
|
+
const { baseUrl, audience } = normalizeGateway(options.gatewayUrl);
|
|
33497
|
+
const fetchFn = resolveFetch(options.fetch);
|
|
33498
|
+
const { builder, privateKey } = resolveBuilder(options);
|
|
33499
|
+
const ecies = options.ecies ?? new NodeECIESUint8Provider();
|
|
33500
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
33501
|
+
async function request(url, init, description) {
|
|
33502
|
+
try {
|
|
33503
|
+
return await fetchFn(url, init);
|
|
33504
|
+
} catch (error) {
|
|
33505
|
+
throw new JobTransportError(
|
|
33506
|
+
`${description} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
33507
|
+
error
|
|
33508
|
+
);
|
|
33509
|
+
}
|
|
33510
|
+
}
|
|
33511
|
+
async function getIdentity(owner) {
|
|
33512
|
+
const query = new URLSearchParams({
|
|
33513
|
+
owner,
|
|
33514
|
+
chainId: String(options.chainId)
|
|
33515
|
+
});
|
|
33516
|
+
const response = await request(
|
|
33517
|
+
`${baseUrl}${IDENTITY_PATH}?${query.toString()}`,
|
|
33518
|
+
{ method: GET_METHOD },
|
|
33519
|
+
"Owner identity lookup"
|
|
33520
|
+
);
|
|
33521
|
+
if (response.status === HTTP_NOT_FOUND) {
|
|
33522
|
+
const parsed = gatewayErrorBody(
|
|
33523
|
+
await responseBody(response),
|
|
33524
|
+
"Owner identity not found"
|
|
33525
|
+
);
|
|
33526
|
+
throw new OwnerNotReadyError(parsed.message, parsed.details);
|
|
33527
|
+
}
|
|
33528
|
+
if (!response.ok) {
|
|
33529
|
+
throw await rejectedResponse(response, "Owner identity lookup rejected");
|
|
33530
|
+
}
|
|
33531
|
+
const body = await responseBody(response);
|
|
33532
|
+
if (!isRecord2(body) || body["state"] !== SEALED_IDENTITY_STATE || !isRecord2(body["identity"])) {
|
|
33533
|
+
throw new OwnerNotReadyError("Owner identity is not sealed", {
|
|
33534
|
+
state: isRecord2(body) ? body["state"] : void 0
|
|
33535
|
+
});
|
|
33536
|
+
}
|
|
33537
|
+
if (!hasExpectedIdentity(body["identity"], owner, options.chainId)) {
|
|
33538
|
+
throw new JobRejectedError(
|
|
33539
|
+
"Gateway returned a malformed or mismatched owner identity",
|
|
33540
|
+
response.status
|
|
33541
|
+
);
|
|
33542
|
+
}
|
|
33543
|
+
return body["identity"];
|
|
33544
|
+
}
|
|
33545
|
+
const client = {
|
|
33546
|
+
async submitRawRead(params) {
|
|
33547
|
+
const identity = await getIdentity(params.owner);
|
|
33548
|
+
const deadlineSeconds = clampInteger(
|
|
33549
|
+
params.deadlineSeconds,
|
|
33550
|
+
DEFAULT_JOB_DEADLINE_SECONDS,
|
|
33551
|
+
1,
|
|
33552
|
+
MAX_JOB_DEADLINE_SECONDS,
|
|
33553
|
+
"deadlineSeconds"
|
|
33554
|
+
);
|
|
33555
|
+
const wait = clampInteger(params.wait, 0, 0, MAX_WAIT_SECONDS, "wait");
|
|
33556
|
+
const jobId = (0, import_node_crypto.randomUUID)();
|
|
33557
|
+
const nowMs = now().getTime();
|
|
33558
|
+
if (!Number.isFinite(nowMs)) {
|
|
33559
|
+
throw new JobRejectedError("now must return a valid Date");
|
|
33560
|
+
}
|
|
33561
|
+
const deadline = new Date(
|
|
33562
|
+
nowMs + deadlineSeconds * MILLISECONDS_PER_SECOND
|
|
33563
|
+
).toISOString();
|
|
33564
|
+
const requestBody = {
|
|
33565
|
+
v: JOB_PROTOCOL_VERSION,
|
|
33566
|
+
jobId,
|
|
33567
|
+
owner: params.owner,
|
|
33568
|
+
builder: builder.address,
|
|
33569
|
+
builderPublicKey: builder.publicKey,
|
|
33570
|
+
grantId: params.grantId,
|
|
33571
|
+
scope: params.scope,
|
|
33572
|
+
operation: RAW_READ_OPERATION,
|
|
33573
|
+
pinnedVersion: params.pinnedVersion ?? null,
|
|
33574
|
+
deadline
|
|
33575
|
+
};
|
|
33576
|
+
const auth = await buildWeb3SignedHeader({
|
|
33577
|
+
signMessage: builder.signMessage,
|
|
33578
|
+
aud: audience,
|
|
33579
|
+
method: POST_METHOD,
|
|
33580
|
+
uri: JOB_EXECUTE_PATH,
|
|
33581
|
+
bodyHash: computeBodyHash(canonicalJobRequestBytes(requestBody)),
|
|
33582
|
+
nonce: (0, import_node_crypto.randomUUID)()
|
|
33583
|
+
});
|
|
33584
|
+
const requestCiphertext = await sealJobRequest(
|
|
33585
|
+
{ request: requestBody, auth },
|
|
33586
|
+
identity.publicKey,
|
|
33587
|
+
ecies
|
|
33588
|
+
);
|
|
33589
|
+
const submission = {
|
|
33590
|
+
owner: requestBody.owner,
|
|
33591
|
+
grantId: requestBody.grantId,
|
|
33592
|
+
scope: requestBody.scope,
|
|
33593
|
+
operation: requestBody.operation,
|
|
33594
|
+
idempotencyKey: (0, import_node_crypto.randomUUID)(),
|
|
33595
|
+
jobId,
|
|
33596
|
+
deadline,
|
|
33597
|
+
requestCiphertext
|
|
33598
|
+
};
|
|
33599
|
+
const bodyBytes = new TextEncoder().encode(JSON.stringify(submission));
|
|
33600
|
+
const authorization = await buildWeb3SignedHeader({
|
|
33601
|
+
signMessage: builder.signMessage,
|
|
33602
|
+
aud: audience,
|
|
33603
|
+
method: POST_METHOD,
|
|
33604
|
+
uri: JOBS_PATH,
|
|
33605
|
+
body: bodyBytes,
|
|
33606
|
+
nonce: (0, import_node_crypto.randomUUID)()
|
|
33607
|
+
});
|
|
33608
|
+
const response = await request(
|
|
33609
|
+
`${baseUrl}${JOBS_PATH}?wait=${wait}`,
|
|
33610
|
+
{
|
|
33611
|
+
method: POST_METHOD,
|
|
33612
|
+
headers: {
|
|
33613
|
+
[AUTHORIZATION_HEADER]: authorization,
|
|
33614
|
+
[CONTENT_TYPE_HEADER]: JSON_CONTENT_TYPE
|
|
33615
|
+
},
|
|
33616
|
+
body: bodyBytes
|
|
33617
|
+
},
|
|
33618
|
+
"Job submission"
|
|
33619
|
+
);
|
|
33620
|
+
if (!response.ok) {
|
|
33621
|
+
throw await rejectedResponse(response, "Job submission rejected");
|
|
33622
|
+
}
|
|
33623
|
+
const body = await responseBody(response);
|
|
33624
|
+
if (response.status === HTTP_OK && isRecord2(body)) {
|
|
33625
|
+
const job = requireStatus(body["job"], response.status);
|
|
33626
|
+
if (job.jobId !== jobId) {
|
|
33627
|
+
throw new JobRejectedError(
|
|
33628
|
+
"Gateway returned a job id that does not match the submission",
|
|
33629
|
+
response.status
|
|
33630
|
+
);
|
|
33631
|
+
}
|
|
33632
|
+
return { jobId, state: job.state, job };
|
|
33633
|
+
}
|
|
33634
|
+
if (response.status === HTTP_ACCEPTED && isRecord2(body) && body["jobId"] === jobId && typeof body["state"] === "string" && JOB_STATES.includes(body["state"])) {
|
|
33635
|
+
return { jobId, state: body["state"] };
|
|
33636
|
+
}
|
|
33637
|
+
throw new JobRejectedError(
|
|
33638
|
+
"Gateway returned an undocumented job submission response",
|
|
33639
|
+
response.status
|
|
33640
|
+
);
|
|
33641
|
+
},
|
|
33642
|
+
async getJob(jobId) {
|
|
33643
|
+
const path = `${JOBS_PATH}/${encodeURIComponent(jobId)}`;
|
|
33644
|
+
const authorization = await buildWeb3SignedHeader({
|
|
33645
|
+
signMessage: builder.signMessage,
|
|
33646
|
+
aud: audience,
|
|
33647
|
+
method: GET_METHOD,
|
|
33648
|
+
uri: path,
|
|
33649
|
+
nonce: (0, import_node_crypto.randomUUID)()
|
|
33650
|
+
});
|
|
33651
|
+
const response = await request(
|
|
33652
|
+
`${baseUrl}${path}`,
|
|
33653
|
+
{
|
|
33654
|
+
method: GET_METHOD,
|
|
33655
|
+
headers: { [AUTHORIZATION_HEADER]: authorization }
|
|
33656
|
+
},
|
|
33657
|
+
"Job status read"
|
|
33658
|
+
);
|
|
33659
|
+
if (!response.ok) {
|
|
33660
|
+
throw await rejectedResponse(response, "Job status read rejected");
|
|
33661
|
+
}
|
|
33662
|
+
const body = await responseBody(response);
|
|
33663
|
+
return requireStatus(
|
|
33664
|
+
isRecord2(body) ? body["job"] : void 0,
|
|
33665
|
+
response.status
|
|
33666
|
+
);
|
|
33667
|
+
},
|
|
33668
|
+
async waitForJob(jobId, waitOptions = {}) {
|
|
33669
|
+
const timeoutMs = requireFiniteDuration(
|
|
33670
|
+
waitOptions.timeoutMs ?? DEFAULT_JOB_TIMEOUT_MS,
|
|
33671
|
+
"timeoutMs"
|
|
33672
|
+
);
|
|
33673
|
+
const pollMs = Math.max(
|
|
33674
|
+
CLAIM_POLL_FLOOR_MS,
|
|
33675
|
+
requireFiniteDuration(
|
|
33676
|
+
waitOptions.pollMs ?? DEFAULT_JOB_POLL_MS,
|
|
33677
|
+
"pollMs"
|
|
33678
|
+
)
|
|
33679
|
+
);
|
|
33680
|
+
const startedAt = Date.now();
|
|
33681
|
+
const callerDeadline = startedAt + timeoutMs;
|
|
33682
|
+
let latest;
|
|
33683
|
+
for (; ; ) {
|
|
33684
|
+
if (Date.now() >= callerDeadline) {
|
|
33685
|
+
throw new JobTimeoutError(
|
|
33686
|
+
`Timed out waiting for terminal job ${jobId}`,
|
|
33687
|
+
{
|
|
33688
|
+
jobId,
|
|
33689
|
+
timeoutMs,
|
|
33690
|
+
state: latest?.state
|
|
33691
|
+
}
|
|
33692
|
+
);
|
|
33693
|
+
}
|
|
33694
|
+
latest = await client.getJob(jobId);
|
|
33695
|
+
if (TERMINAL_JOB_STATES.has(latest.state)) return latest;
|
|
33696
|
+
const remaining = callerDeadline - Date.now();
|
|
33697
|
+
if (remaining <= 0) {
|
|
33698
|
+
throw new JobTimeoutError(
|
|
33699
|
+
`Timed out waiting for terminal job ${jobId}`,
|
|
33700
|
+
{
|
|
33701
|
+
jobId,
|
|
33702
|
+
timeoutMs,
|
|
33703
|
+
state: latest.state
|
|
33704
|
+
}
|
|
33705
|
+
);
|
|
33706
|
+
}
|
|
33707
|
+
await sleep2(Math.min(pollMs, remaining));
|
|
33708
|
+
}
|
|
33709
|
+
},
|
|
33710
|
+
async openResult(handle, openOptions) {
|
|
33711
|
+
if (!privateKey) {
|
|
33712
|
+
throw new JobRejectedError(
|
|
33713
|
+
"openResult requires createJobsClient({ builderPrivateKey })"
|
|
33714
|
+
);
|
|
33715
|
+
}
|
|
33716
|
+
const response = await request(
|
|
33717
|
+
handle.url,
|
|
33718
|
+
{ method: GET_METHOD },
|
|
33719
|
+
"Job result fetch"
|
|
33720
|
+
);
|
|
33721
|
+
if (!response.ok) {
|
|
33722
|
+
throw await rejectedResponse(response, "Job result fetch rejected");
|
|
33723
|
+
}
|
|
33724
|
+
let bytes;
|
|
33725
|
+
try {
|
|
33726
|
+
bytes = new Uint8Array(await response.arrayBuffer());
|
|
33727
|
+
} catch (error) {
|
|
33728
|
+
throw new JobTransportError(
|
|
33729
|
+
`Job result fetch failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
33730
|
+
error
|
|
33731
|
+
);
|
|
33732
|
+
}
|
|
33733
|
+
const actualHash = (0, import_viem16.bytesToHex)((0, import_sha26.sha256)(bytes));
|
|
33734
|
+
if (actualHash.toLowerCase() !== handle.hash.toLowerCase()) {
|
|
33735
|
+
throw new JobResultIntegrityError(
|
|
33736
|
+
"Fetched job result hash does not match its handle",
|
|
33737
|
+
{
|
|
33738
|
+
objectKey: handle.objectKey,
|
|
33739
|
+
expectedHash: handle.hash,
|
|
33740
|
+
actualHash
|
|
33741
|
+
}
|
|
33742
|
+
);
|
|
33743
|
+
}
|
|
33744
|
+
if (bytes.length !== handle.size) {
|
|
33745
|
+
throw new JobResultIntegrityError(
|
|
33746
|
+
"Fetched job result size does not match its handle",
|
|
33747
|
+
{
|
|
33748
|
+
objectKey: handle.objectKey,
|
|
33749
|
+
expectedSize: handle.size,
|
|
33750
|
+
actualSize: bytes.length
|
|
33751
|
+
}
|
|
33752
|
+
);
|
|
33753
|
+
}
|
|
33754
|
+
return openJobResult(bytes, privateKey, ecies, openOptions.expect);
|
|
33755
|
+
},
|
|
33756
|
+
async readRaw(params) {
|
|
33757
|
+
const submitted = await client.submitRawRead(params);
|
|
33758
|
+
const job = submitted.job && TERMINAL_JOB_STATES.has(submitted.job.state) ? submitted.job : await client.waitForJob(submitted.jobId, {
|
|
33759
|
+
timeoutMs: params.timeoutMs,
|
|
33760
|
+
pollMs: params.pollMs
|
|
33761
|
+
});
|
|
33762
|
+
if (job.state !== "completed") {
|
|
33763
|
+
throw new JobRejectedError(
|
|
33764
|
+
`Job ${job.jobId} ended in state ${job.state}${job.failureReason ? `: ${job.failureReason}` : ""}`,
|
|
33765
|
+
void 0,
|
|
33766
|
+
null,
|
|
33767
|
+
{
|
|
33768
|
+
jobId: job.jobId,
|
|
33769
|
+
state: job.state,
|
|
33770
|
+
...job.failureReason ? { failureReason: job.failureReason } : {}
|
|
33771
|
+
}
|
|
33772
|
+
);
|
|
33773
|
+
}
|
|
33774
|
+
if (!job.result) {
|
|
33775
|
+
throw new JobRejectedError(
|
|
33776
|
+
"Completed job status does not include a result handle",
|
|
33777
|
+
void 0,
|
|
33778
|
+
null,
|
|
33779
|
+
{ jobId: job.jobId, state: job.state }
|
|
33780
|
+
);
|
|
33781
|
+
}
|
|
33782
|
+
return client.openResult(job.result, {
|
|
33783
|
+
expect: {
|
|
33784
|
+
jobId: submitted.jobId,
|
|
33785
|
+
scope: params.scope,
|
|
33786
|
+
...params.pinnedVersion !== void 0 && params.pinnedVersion !== null ? { version: params.pinnedVersion } : {}
|
|
33787
|
+
}
|
|
33788
|
+
});
|
|
33789
|
+
}
|
|
33790
|
+
};
|
|
33791
|
+
return client;
|
|
33792
|
+
}
|
|
33793
|
+
|
|
33794
|
+
// src/protocol/personal-server-registration.ts
|
|
33795
|
+
var import_viem17 = require("viem");
|
|
32649
33796
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
32650
33797
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
32651
33798
|
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32652
33799
|
"DataPortabilityServers"
|
|
32653
33800
|
);
|
|
32654
33801
|
function assertAddress(value, name) {
|
|
32655
|
-
if (!(0,
|
|
33802
|
+
if (!(0, import_viem17.isAddress)(value)) {
|
|
32656
33803
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32657
33804
|
}
|
|
32658
33805
|
}
|
|
@@ -32738,12 +33885,12 @@ async function buildPersonalServerRegistrationSignature(input) {
|
|
|
32738
33885
|
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32739
33886
|
|
|
32740
33887
|
// src/personal-server-lite/owner-binding.ts
|
|
32741
|
-
var
|
|
33888
|
+
var import_viem18 = require("viem");
|
|
32742
33889
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
32743
33890
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32744
33891
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32745
33892
|
function assertAddress2(value, name) {
|
|
32746
|
-
if (!(0,
|
|
33893
|
+
if (!(0, import_viem18.isAddress)(value)) {
|
|
32747
33894
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32748
33895
|
}
|
|
32749
33896
|
}
|
|
@@ -32793,7 +33940,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
|
32793
33940
|
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32794
33941
|
|
|
32795
33942
|
// src/account/personal-server-registration.ts
|
|
32796
|
-
var
|
|
33943
|
+
var import_viem19 = require("viem");
|
|
32797
33944
|
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32798
33945
|
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32799
33946
|
status;
|
|
@@ -32812,7 +33959,7 @@ function trimTrailingSlash(value) {
|
|
|
32812
33959
|
return value.replace(/\/+$/, "");
|
|
32813
33960
|
}
|
|
32814
33961
|
function assertAddress3(value, name) {
|
|
32815
|
-
if (!(0,
|
|
33962
|
+
if (!(0, import_viem19.isAddress)(value)) {
|
|
32816
33963
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32817
33964
|
}
|
|
32818
33965
|
}
|
|
@@ -32833,7 +33980,7 @@ function accountErrorMessage(status, body) {
|
|
|
32833
33980
|
if (nestedMessage) {
|
|
32834
33981
|
return nestedMessage;
|
|
32835
33982
|
}
|
|
32836
|
-
if (
|
|
33983
|
+
if (isRecord3(body) && typeof body.message === "string") {
|
|
32837
33984
|
return body.message;
|
|
32838
33985
|
}
|
|
32839
33986
|
const code = accountErrorCode(body);
|
|
@@ -32847,7 +33994,7 @@ function accountErrorCode(body) {
|
|
|
32847
33994
|
if (nestedCode) {
|
|
32848
33995
|
return nestedCode;
|
|
32849
33996
|
}
|
|
32850
|
-
if (
|
|
33997
|
+
if (isRecord3(body)) {
|
|
32851
33998
|
if (typeof body.code === "string") {
|
|
32852
33999
|
return body.code;
|
|
32853
34000
|
}
|
|
@@ -32858,13 +34005,13 @@ function accountErrorCode(body) {
|
|
|
32858
34005
|
return void 0;
|
|
32859
34006
|
}
|
|
32860
34007
|
function nestedAccountErrorField(body, field) {
|
|
32861
|
-
if (!
|
|
34008
|
+
if (!isRecord3(body) || !isRecord3(body.error)) {
|
|
32862
34009
|
return void 0;
|
|
32863
34010
|
}
|
|
32864
34011
|
const value = body.error[field];
|
|
32865
34012
|
return typeof value === "string" ? value : void 0;
|
|
32866
34013
|
}
|
|
32867
|
-
function
|
|
34014
|
+
function isRecord3(value) {
|
|
32868
34015
|
return typeof value === "object" && value !== null;
|
|
32869
34016
|
}
|
|
32870
34017
|
function normalizeAccountResponse(response) {
|
|
@@ -33076,7 +34223,7 @@ function accountOwnerBindingError(error) {
|
|
|
33076
34223
|
}
|
|
33077
34224
|
|
|
33078
34225
|
// src/protocol/grants.ts
|
|
33079
|
-
var
|
|
34226
|
+
var import_viem20 = require("viem");
|
|
33080
34227
|
function isHexString(value) {
|
|
33081
34228
|
return typeof value === "string" && value.startsWith("0x");
|
|
33082
34229
|
}
|
|
@@ -33121,7 +34268,7 @@ async function verifyGrantRegistration(input) {
|
|
|
33121
34268
|
}
|
|
33122
34269
|
let valid;
|
|
33123
34270
|
try {
|
|
33124
|
-
valid = await (0,
|
|
34271
|
+
valid = await (0, import_viem20.verifyTypedData)({
|
|
33125
34272
|
address: input.grantorAddress,
|
|
33126
34273
|
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
33127
34274
|
types: GRANT_REGISTRATION_TYPES,
|
|
@@ -33156,8 +34303,8 @@ async function verifyGrantRegistration(input) {
|
|
|
33156
34303
|
}
|
|
33157
34304
|
|
|
33158
34305
|
// src/protocol/fee-registry.ts
|
|
33159
|
-
var
|
|
33160
|
-
var FEE_REGISTRY_ABI = (0,
|
|
34306
|
+
var import_viem21 = require("viem");
|
|
34307
|
+
var FEE_REGISTRY_ABI = (0, import_viem21.parseAbi)([
|
|
33161
34308
|
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33162
34309
|
"function fees(bytes32 operation) view returns (Fee)",
|
|
33163
34310
|
"function operationKey(string name) pure returns (bytes32)"
|
|
@@ -33240,7 +34387,7 @@ async function getOpFee(client, config, opType, opts) {
|
|
|
33240
34387
|
}
|
|
33241
34388
|
|
|
33242
34389
|
// src/protocol/escrow-deposit.ts
|
|
33243
|
-
var
|
|
34390
|
+
var import_viem22 = require("viem");
|
|
33244
34391
|
var ESCROW_DEPOSIT_ABI = [
|
|
33245
34392
|
{
|
|
33246
34393
|
type: "function",
|
|
@@ -33265,14 +34412,14 @@ function escrowContractAddress(config) {
|
|
|
33265
34412
|
return config.contracts.dataPortabilityEscrow;
|
|
33266
34413
|
}
|
|
33267
34414
|
function encodeDepositNativeData(input) {
|
|
33268
|
-
return (0,
|
|
34415
|
+
return (0, import_viem22.encodeFunctionData)({
|
|
33269
34416
|
abi: ESCROW_DEPOSIT_ABI,
|
|
33270
34417
|
functionName: "depositNative",
|
|
33271
34418
|
args: [input.account]
|
|
33272
34419
|
});
|
|
33273
34420
|
}
|
|
33274
34421
|
function encodeDepositTokenData(input) {
|
|
33275
|
-
return (0,
|
|
34422
|
+
return (0, import_viem22.encodeFunctionData)({
|
|
33276
34423
|
abi: ESCROW_DEPOSIT_ABI,
|
|
33277
34424
|
functionName: "depositToken",
|
|
33278
34425
|
args: [input.account, input.token, input.amount]
|
|
@@ -33293,7 +34440,7 @@ function buildDepositTokenRequest(config, input) {
|
|
|
33293
34440
|
}
|
|
33294
34441
|
|
|
33295
34442
|
// src/protocol/data-point-status.ts
|
|
33296
|
-
var
|
|
34443
|
+
var import_viem23 = require("viem");
|
|
33297
34444
|
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
33298
34445
|
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
33299
34446
|
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
@@ -33317,7 +34464,7 @@ function dataRegistryContractAddress(config) {
|
|
|
33317
34464
|
return config.contracts.dataRegistry;
|
|
33318
34465
|
}
|
|
33319
34466
|
function encodeSetDataPointStatusData(input) {
|
|
33320
|
-
return (0,
|
|
34467
|
+
return (0, import_viem23.encodeFunctionData)({
|
|
33321
34468
|
abi: DATA_REGISTRY_STATUS_ABI,
|
|
33322
34469
|
functionName: "setStatus",
|
|
33323
34470
|
args: [input.scope, input.status]
|
|
@@ -33337,14 +34484,14 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
33337
34484
|
}
|
|
33338
34485
|
|
|
33339
34486
|
// src/protocol/data-point-deletion.ts
|
|
33340
|
-
var
|
|
34487
|
+
var import_viem25 = require("viem");
|
|
33341
34488
|
|
|
33342
34489
|
// src/protocol/lineage.ts
|
|
33343
|
-
var
|
|
34490
|
+
var import_viem24 = require("viem");
|
|
33344
34491
|
var import_zod = require("zod");
|
|
33345
34492
|
|
|
33346
34493
|
// src/protocol/personal-server-error-body.ts
|
|
33347
|
-
function
|
|
34494
|
+
function isRecord4(value) {
|
|
33348
34495
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
33349
34496
|
}
|
|
33350
34497
|
async function readPersonalServerErrorBody(response) {
|
|
@@ -33354,8 +34501,8 @@ async function readPersonalServerErrorBody(response) {
|
|
|
33354
34501
|
} catch {
|
|
33355
34502
|
return { errorCode: null, message: null };
|
|
33356
34503
|
}
|
|
33357
|
-
if (!
|
|
33358
|
-
const nested =
|
|
34504
|
+
if (!isRecord4(body)) return { errorCode: null, message: null };
|
|
34505
|
+
const nested = isRecord4(body.error) ? body.error : null;
|
|
33359
34506
|
const gatewayShape = typeof body.error === "string" && typeof body.code === "string";
|
|
33360
34507
|
const code = nested?.errorCode ?? nested?.code ?? body.errorCode ?? (gatewayShape ? body.code : void 0) ?? (typeof body.error === "string" ? body.error : void 0) ?? body.code;
|
|
33361
34508
|
const message = nested?.message ?? body.message ?? (gatewayShape ? body.error : void 0);
|
|
@@ -33368,63 +34515,23 @@ async function readPersonalServerErrorBody(response) {
|
|
|
33368
34515
|
return {
|
|
33369
34516
|
errorCode: typeof code === "string" ? code : null,
|
|
33370
34517
|
message: typeof message === "string" ? message : null,
|
|
33371
|
-
...
|
|
34518
|
+
...isRecord4(details) ? { details } : {}
|
|
33372
34519
|
};
|
|
33373
34520
|
}
|
|
33374
34521
|
|
|
33375
|
-
// src/protocol/write-signer.ts
|
|
33376
|
-
function isRecord3(value) {
|
|
33377
|
-
return value !== null && typeof value === "object";
|
|
33378
|
-
}
|
|
33379
|
-
function isViemWriteAccount(source) {
|
|
33380
|
-
return isRecord3(source) && source.type === "local" && typeof source.address === "string" && typeof source.signMessage === "function";
|
|
33381
|
-
}
|
|
33382
|
-
function isViemWriteWalletClient(source) {
|
|
33383
|
-
return isRecord3(source) && typeof source.signMessage === "function" && source.type !== "local" && (source.type === "walletClient" || "transport" in source);
|
|
33384
|
-
}
|
|
33385
|
-
function accountAddress(account) {
|
|
33386
|
-
return typeof account === "string" ? account : account.address;
|
|
33387
|
-
}
|
|
33388
|
-
function resolveWriteSigner(source, options = {}) {
|
|
33389
|
-
if (isViemWriteWalletClient(source)) {
|
|
33390
|
-
const account = options.account ?? source.account;
|
|
33391
|
-
if (account === void 0) {
|
|
33392
|
-
throw new WriteRequestError(
|
|
33393
|
-
"Viem wallet client requires an account option or account property"
|
|
33394
|
-
);
|
|
33395
|
-
}
|
|
33396
|
-
return {
|
|
33397
|
-
address: accountAddress(account),
|
|
33398
|
-
signMessage: (message) => source.signMessage({ account, message })
|
|
33399
|
-
};
|
|
33400
|
-
}
|
|
33401
|
-
if (isViemWriteAccount(source)) {
|
|
33402
|
-
return {
|
|
33403
|
-
address: source.address,
|
|
33404
|
-
signMessage: (message) => source.signMessage({ message })
|
|
33405
|
-
};
|
|
33406
|
-
}
|
|
33407
|
-
if (!isRecord3(source) || typeof source.signMessage !== "function") {
|
|
33408
|
-
throw new WriteRequestError(
|
|
33409
|
-
"signer must be a viem LocalAccount, a viem WalletClient, or a { signMessage } object"
|
|
33410
|
-
);
|
|
33411
|
-
}
|
|
33412
|
-
return source;
|
|
33413
|
-
}
|
|
33414
|
-
|
|
33415
34522
|
// src/protocol/lineage.ts
|
|
33416
34523
|
var DATA_POINT_ID_PATTERN = /^0x[0-9a-fA-F]{64}$/;
|
|
33417
34524
|
function isDataPointId(value) {
|
|
33418
34525
|
return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
|
|
33419
34526
|
}
|
|
33420
34527
|
function deriveDataPointId(ownerAddress, scope) {
|
|
33421
|
-
if (!(0,
|
|
34528
|
+
if (!(0, import_viem24.isAddress)(ownerAddress, { strict: false })) {
|
|
33422
34529
|
throw new Error(
|
|
33423
34530
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
33424
34531
|
);
|
|
33425
34532
|
}
|
|
33426
|
-
return (0,
|
|
33427
|
-
(0,
|
|
34533
|
+
return (0, import_viem24.keccak256)(
|
|
34534
|
+
(0, import_viem24.encodeAbiParameters)(
|
|
33428
34535
|
[
|
|
33429
34536
|
{ name: "ownerAddress", type: "address" },
|
|
33430
34537
|
{ name: "scope", type: "string" }
|
|
@@ -33513,7 +34620,7 @@ function gatewayLineagePath(dataPointId, version) {
|
|
|
33513
34620
|
function normalizeBaseUrl(url) {
|
|
33514
34621
|
return url.replace(/\/+$/, "");
|
|
33515
34622
|
}
|
|
33516
|
-
function
|
|
34623
|
+
function resolveFetch2(fetchFn) {
|
|
33517
34624
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
33518
34625
|
if (resolved === void 0) {
|
|
33519
34626
|
throw new LineageReadError("No fetch implementation available");
|
|
@@ -33554,7 +34661,7 @@ async function parseLineageGraph(source, response) {
|
|
|
33554
34661
|
{ cause: err instanceof Error ? err.message : String(err) }
|
|
33555
34662
|
);
|
|
33556
34663
|
}
|
|
33557
|
-
const envelope =
|
|
34664
|
+
const envelope = isRecord4(body) && isRecord4(body.data) ? body : void 0;
|
|
33558
34665
|
const parsed = LineageGraphSchema.safeParse(envelope?.data ?? body);
|
|
33559
34666
|
if (!parsed.success) {
|
|
33560
34667
|
throw new LineageReadError(
|
|
@@ -33564,7 +34671,7 @@ async function parseLineageGraph(source, response) {
|
|
|
33564
34671
|
{ issues: parsed.error.issues }
|
|
33565
34672
|
);
|
|
33566
34673
|
}
|
|
33567
|
-
const proof =
|
|
34674
|
+
const proof = isRecord4(envelope?.proof) ? envelope.proof : void 0;
|
|
33568
34675
|
return proof === void 0 ? parsed.data : { ...parsed.data, proof };
|
|
33569
34676
|
}
|
|
33570
34677
|
async function sendLineageRead(source, fetchFn, url, headers) {
|
|
@@ -33585,7 +34692,7 @@ async function sendLineageRead(source, fetchFn, url, headers) {
|
|
|
33585
34692
|
return parseLineageGraph(source, response);
|
|
33586
34693
|
}
|
|
33587
34694
|
async function getPersonalServerLineage(params) {
|
|
33588
|
-
const fetchFn =
|
|
34695
|
+
const fetchFn = resolveFetch2(params.fetch);
|
|
33589
34696
|
const baseUrl = normalizeBaseUrl(params.personalServerUrl);
|
|
33590
34697
|
const audience = params.audience ?? baseUrl;
|
|
33591
34698
|
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
@@ -33620,7 +34727,7 @@ async function getGatewayLineage(params) {
|
|
|
33620
34727
|
{ dataPointId: params.dataPointId }
|
|
33621
34728
|
);
|
|
33622
34729
|
}
|
|
33623
|
-
const fetchFn =
|
|
34730
|
+
const fetchFn = resolveFetch2(params.fetch);
|
|
33624
34731
|
const baseUrl = normalizeBaseUrl(params.gatewayUrl);
|
|
33625
34732
|
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
33626
34733
|
const uri = gatewayLineagePath(
|
|
@@ -33650,7 +34757,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
33650
34757
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
33651
34758
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
33652
34759
|
function computeTombstoneHash(preimage) {
|
|
33653
|
-
return (0,
|
|
34760
|
+
return (0, import_viem25.keccak256)((0, import_viem25.stringToBytes)(preimage));
|
|
33654
34761
|
}
|
|
33655
34762
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
33656
34763
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -33669,12 +34776,12 @@ function tombstoneDeletedAt(value) {
|
|
|
33669
34776
|
return typeof deletedAt === "string" ? deletedAt : null;
|
|
33670
34777
|
}
|
|
33671
34778
|
function assertAddress4(value, name) {
|
|
33672
|
-
if (!(0,
|
|
34779
|
+
if (!(0, import_viem25.isAddress)(value)) {
|
|
33673
34780
|
throw new Error(`${name} must be a valid EVM address`);
|
|
33674
34781
|
}
|
|
33675
34782
|
}
|
|
33676
34783
|
function assertUint256(value, name) {
|
|
33677
|
-
if (value < 0n || value >
|
|
34784
|
+
if (value < 0n || value > import_viem25.maxUint256) {
|
|
33678
34785
|
throw new Error(`${name} must fit in uint256, got ${value}`);
|
|
33679
34786
|
}
|
|
33680
34787
|
}
|
|
@@ -33777,7 +34884,7 @@ async function deleteDataPoint(input) {
|
|
|
33777
34884
|
}
|
|
33778
34885
|
currentVersion = parseExpectedVersion(record.expectedVersion);
|
|
33779
34886
|
}
|
|
33780
|
-
if (currentVersion < 0n || currentVersion >=
|
|
34887
|
+
if (currentVersion < 0n || currentVersion >= import_viem25.maxUint256) {
|
|
33781
34888
|
throw new Error(
|
|
33782
34889
|
`currentVersion ${currentVersion} cannot be incremented to a uint256 tombstone version`
|
|
33783
34890
|
);
|
|
@@ -34084,17 +35191,17 @@ function tryGrantPermissions(scopes) {
|
|
|
34084
35191
|
}
|
|
34085
35192
|
|
|
34086
35193
|
// src/protocol/personal-server-write.ts
|
|
34087
|
-
var
|
|
34088
|
-
var
|
|
35194
|
+
var import_sha28 = require("@noble/hashes/sha2");
|
|
35195
|
+
var import_viem27 = require("viem");
|
|
34089
35196
|
var import_zod4 = require("zod");
|
|
34090
35197
|
|
|
34091
35198
|
// src/protocol/write-request.ts
|
|
34092
|
-
var
|
|
34093
|
-
var
|
|
35199
|
+
var import_sha27 = require("@noble/hashes/sha2");
|
|
35200
|
+
var import_viem26 = require("viem");
|
|
34094
35201
|
function normalizeBaseUrl2(url) {
|
|
34095
35202
|
return url.replace(/\/+$/, "");
|
|
34096
35203
|
}
|
|
34097
|
-
function
|
|
35204
|
+
function resolveFetch3(fetchFn) {
|
|
34098
35205
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
34099
35206
|
if (resolved === void 0) {
|
|
34100
35207
|
throw new WriteRequestError("No fetch implementation available");
|
|
@@ -34107,7 +35214,7 @@ function errorMessage(err) {
|
|
|
34107
35214
|
function finiteOr(value, fallback) {
|
|
34108
35215
|
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
34109
35216
|
}
|
|
34110
|
-
function
|
|
35217
|
+
function sleep3(ms) {
|
|
34111
35218
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
34112
35219
|
}
|
|
34113
35220
|
var issuedProofIats = /* @__PURE__ */ new Map();
|
|
@@ -34149,7 +35256,7 @@ function nextProofIat(proofKey) {
|
|
|
34149
35256
|
setIssuedProofIat(proofKey, iat, last);
|
|
34150
35257
|
const waitSec = iat - nowSec - PROOF_IAT_MAX_AHEAD_SECONDS;
|
|
34151
35258
|
if (waitSec <= 0) return Promise.resolve(iat);
|
|
34152
|
-
return
|
|
35259
|
+
return sleep3(waitSec * 1e3).then(() => iat);
|
|
34153
35260
|
}
|
|
34154
35261
|
function freshProofNonce() {
|
|
34155
35262
|
const webCrypto = globalThis.crypto;
|
|
@@ -34157,22 +35264,22 @@ function freshProofNonce() {
|
|
|
34157
35264
|
return webCrypto.randomUUID();
|
|
34158
35265
|
}
|
|
34159
35266
|
if (typeof webCrypto?.getRandomValues === "function") {
|
|
34160
|
-
return (0,
|
|
35267
|
+
return (0, import_viem26.bytesToHex)(webCrypto.getRandomValues(new Uint8Array(16)));
|
|
34161
35268
|
}
|
|
34162
35269
|
throw new WriteRequestError(
|
|
34163
35270
|
"No secure random source available to build a proof nonce; provide a crypto global"
|
|
34164
35271
|
);
|
|
34165
35272
|
}
|
|
34166
35273
|
function proofKeyFor(parts) {
|
|
34167
|
-
return (0,
|
|
34168
|
-
(0,
|
|
35274
|
+
return (0, import_viem26.bytesToHex)(
|
|
35275
|
+
(0, import_sha27.sha256)(
|
|
34169
35276
|
new TextEncoder().encode(
|
|
34170
35277
|
JSON.stringify([
|
|
34171
35278
|
parts.aud,
|
|
34172
35279
|
parts.method,
|
|
34173
35280
|
parts.uri,
|
|
34174
35281
|
parts.grantId,
|
|
34175
|
-
parts.signedBytes ? (0,
|
|
35282
|
+
parts.signedBytes ? (0, import_viem26.bytesToHex)((0, import_sha27.sha256)(parts.signedBytes)) : ""
|
|
34176
35283
|
])
|
|
34177
35284
|
)
|
|
34178
35285
|
)
|
|
@@ -34190,7 +35297,7 @@ async function sendWithFreshProof(label, fetchFn, options, proofKey, build) {
|
|
|
34190
35297
|
lastError = err;
|
|
34191
35298
|
}
|
|
34192
35299
|
if (attempt < attempts - 1) {
|
|
34193
|
-
await
|
|
35300
|
+
await sleep3(delayMs);
|
|
34194
35301
|
delayMs *= 2;
|
|
34195
35302
|
}
|
|
34196
35303
|
}
|
|
@@ -34229,7 +35336,7 @@ function dataPath(scope) {
|
|
|
34229
35336
|
return `/v1/data/${encodeURIComponent(scope)}`;
|
|
34230
35337
|
}
|
|
34231
35338
|
async function openWriteSession(params) {
|
|
34232
|
-
const fetchFn =
|
|
35339
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
34233
35340
|
const personalServerUrl = normalizeBaseUrl2(params.personalServerUrl);
|
|
34234
35341
|
const audience = params.audience ?? personalServerUrl;
|
|
34235
35342
|
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
@@ -34309,12 +35416,12 @@ async function openWriteSession(params) {
|
|
|
34309
35416
|
};
|
|
34310
35417
|
}
|
|
34311
35418
|
function isWriteSession(value) {
|
|
34312
|
-
if (!
|
|
35419
|
+
if (!isRecord4(value)) return false;
|
|
34313
35420
|
const signer = value.signer;
|
|
34314
|
-
return typeof value.personalServerUrl === "string" && typeof value.audience === "string" && typeof value.grantId === "string" && typeof value.accessToken === "string" && value.accessToken.length > 0 && typeof value.expiresAt === "number" && Number.isFinite(value.expiresAt) && Array.isArray(value.writeScopes) && value.writeScopes.every((scope) => typeof scope === "string") &&
|
|
35421
|
+
return typeof value.personalServerUrl === "string" && typeof value.audience === "string" && typeof value.grantId === "string" && typeof value.accessToken === "string" && value.accessToken.length > 0 && typeof value.expiresAt === "number" && Number.isFinite(value.expiresAt) && Array.isArray(value.writeScopes) && value.writeScopes.every((scope) => typeof scope === "string") && isRecord4(signer) && typeof signer.signMessage === "function";
|
|
34315
35422
|
}
|
|
34316
35423
|
function sessionCoversScope(session, scope) {
|
|
34317
|
-
if (!
|
|
35424
|
+
if (!isRecord4(session) || !Array.isArray(session.writeScopes) || !session.writeScopes.every((pattern) => typeof pattern === "string")) {
|
|
34318
35425
|
throw new WriteRequestError("session must come from openWriteSession");
|
|
34319
35426
|
}
|
|
34320
35427
|
return session.writeScopes.some(
|
|
@@ -34359,7 +35466,7 @@ function binaryWriteSignedBytes(input) {
|
|
|
34359
35466
|
mimeType: normalizeBinaryMimeType(input.contentType),
|
|
34360
35467
|
...input.filename ? { filename: input.filename } : {},
|
|
34361
35468
|
sizeBytes: input.bytes.length,
|
|
34362
|
-
contentHash: (0,
|
|
35469
|
+
contentHash: (0, import_viem27.bytesToHex)((0, import_sha28.sha256)(input.bytes)),
|
|
34363
35470
|
encoding: "base64",
|
|
34364
35471
|
content: toBase64(input.bytes),
|
|
34365
35472
|
...metadata !== void 0 ? { metadata } : {}
|
|
@@ -34388,7 +35495,7 @@ function assertNoReservedKeys(value, where) {
|
|
|
34388
35495
|
}
|
|
34389
35496
|
}
|
|
34390
35497
|
function isLineagePair(value) {
|
|
34391
|
-
return
|
|
35498
|
+
return isRecord4(value) && typeof value.ownerAddress === "string" && typeof value.scope === "string";
|
|
34392
35499
|
}
|
|
34393
35500
|
function normalizeLineage(lineage, derivedScope) {
|
|
34394
35501
|
if (!Array.isArray(lineage)) {
|
|
@@ -34407,7 +35514,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
34407
35514
|
for (const entry of lineage) {
|
|
34408
35515
|
let id;
|
|
34409
35516
|
if (isLineagePair(entry)) {
|
|
34410
|
-
if (!(0,
|
|
35517
|
+
if (!(0, import_viem27.isAddress)(entry.ownerAddress, { strict: false })) {
|
|
34411
35518
|
throw new WriteRequestError(
|
|
34412
35519
|
"lineage source ownerAddress must be an EVM address",
|
|
34413
35520
|
{ ownerAddress: entry.ownerAddress }
|
|
@@ -34456,7 +35563,7 @@ function assertNoLineageField(value, where) {
|
|
|
34456
35563
|
}
|
|
34457
35564
|
function buildMetadataHeader(metadata, sources) {
|
|
34458
35565
|
if (metadata !== void 0) {
|
|
34459
|
-
if (!
|
|
35566
|
+
if (!isRecord4(metadata)) {
|
|
34460
35567
|
throw new WriteRequestError("metadata must be a plain object");
|
|
34461
35568
|
}
|
|
34462
35569
|
assertNoReservedKeys(metadata, "metadata");
|
|
@@ -34509,7 +35616,7 @@ function prepareWrite(params) {
|
|
|
34509
35616
|
if (params.data === void 0) {
|
|
34510
35617
|
throw new WriteRequestError("Pass data (a JSON object) or binary");
|
|
34511
35618
|
}
|
|
34512
|
-
if (!
|
|
35619
|
+
if (!isRecord4(params.data)) {
|
|
34513
35620
|
throw new WriteRequestError("data must be a plain JSON object");
|
|
34514
35621
|
}
|
|
34515
35622
|
if (params.metadata !== void 0) {
|
|
@@ -34560,7 +35667,7 @@ async function writeData(params) {
|
|
|
34560
35667
|
if (!isWriteSession(session)) {
|
|
34561
35668
|
throw new WriteRequestError("session must come from openWriteSession");
|
|
34562
35669
|
}
|
|
34563
|
-
const fetchFn =
|
|
35670
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
34564
35671
|
if (typeof params.scope !== "string" || params.scope.length === 0) {
|
|
34565
35672
|
throw new WriteRequestError("scope is required");
|
|
34566
35673
|
}
|
|
@@ -34752,7 +35859,7 @@ function resolveRequest(params) {
|
|
|
34752
35859
|
"signer must be a viem LocalAccount, a viem WalletClient, or a { signMessage } object"
|
|
34753
35860
|
);
|
|
34754
35861
|
}
|
|
34755
|
-
const fetchFn =
|
|
35862
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
34756
35863
|
const baseUrl = normalizeBaseUrl2(params.personalServerUrl);
|
|
34757
35864
|
const audience = params.audience ?? baseUrl;
|
|
34758
35865
|
return {
|
|
@@ -35085,7 +36192,7 @@ async function waitForQuestion(params) {
|
|
|
35085
36192
|
}
|
|
35086
36193
|
);
|
|
35087
36194
|
}
|
|
35088
|
-
await
|
|
36195
|
+
await sleep3(Math.min(pollIntervalMs, remaining));
|
|
35089
36196
|
}
|
|
35090
36197
|
}
|
|
35091
36198
|
async function askPersonalServer(params) {
|
|
@@ -35149,7 +36256,7 @@ function derivativeStatusTarget(derivedScope) {
|
|
|
35149
36256
|
function normalizeBaseUrl3(url) {
|
|
35150
36257
|
return url.replace(/\/+$/, "");
|
|
35151
36258
|
}
|
|
35152
|
-
function
|
|
36259
|
+
function resolveFetch4(fetchFn) {
|
|
35153
36260
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
35154
36261
|
if (resolved === void 0) {
|
|
35155
36262
|
throw new WriteRequestError("No fetch implementation available");
|
|
@@ -35162,7 +36269,7 @@ function requireDerivedScope(derivedScope) {
|
|
|
35162
36269
|
}
|
|
35163
36270
|
return derivedScope;
|
|
35164
36271
|
}
|
|
35165
|
-
function
|
|
36272
|
+
function sleep4(ms, signal) {
|
|
35166
36273
|
if (ms <= 0) return Promise.resolve();
|
|
35167
36274
|
return new Promise((resolve, reject) => {
|
|
35168
36275
|
const timer = setTimeout(() => {
|
|
@@ -35198,7 +36305,7 @@ function isDerivativeStatusSettled(status) {
|
|
|
35198
36305
|
}
|
|
35199
36306
|
async function getDerivativeStatus(params) {
|
|
35200
36307
|
const derivedScope = requireDerivedScope(params.derivedScope);
|
|
35201
|
-
const fetchFn =
|
|
36308
|
+
const fetchFn = resolveFetch4(params.fetch);
|
|
35202
36309
|
const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
|
|
35203
36310
|
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
35204
36311
|
const headers = new Headers(params.headers);
|
|
@@ -35276,7 +36383,7 @@ async function waitForDerivativeStatus(params) {
|
|
|
35276
36383
|
if (waitMs > remaining) {
|
|
35277
36384
|
throw timeoutError(latest, timeoutMs);
|
|
35278
36385
|
}
|
|
35279
|
-
await
|
|
36386
|
+
await sleep4(waitMs, params.signal);
|
|
35280
36387
|
}
|
|
35281
36388
|
}
|
|
35282
36389
|
|
|
@@ -36309,7 +37416,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
|
36309
37416
|
"server_not_configured",
|
|
36310
37417
|
"content_too_large"
|
|
36311
37418
|
]);
|
|
36312
|
-
function
|
|
37419
|
+
function isRecord5(value) {
|
|
36313
37420
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
36314
37421
|
}
|
|
36315
37422
|
function normalizeCode(value) {
|
|
@@ -36320,10 +37427,10 @@ function normalizeCode(value) {
|
|
|
36320
37427
|
return KNOWN_CODES.has(code) ? code : null;
|
|
36321
37428
|
}
|
|
36322
37429
|
function extractPSErrorBody(body) {
|
|
36323
|
-
if (!
|
|
37430
|
+
if (!isRecord5(body)) {
|
|
36324
37431
|
return null;
|
|
36325
37432
|
}
|
|
36326
|
-
const nested =
|
|
37433
|
+
const nested = isRecord5(body.error) ? body.error : null;
|
|
36327
37434
|
const code = normalizeCode(
|
|
36328
37435
|
nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
|
|
36329
37436
|
);
|
|
@@ -36355,6 +37462,8 @@ async function parsePSError(response) {
|
|
|
36355
37462
|
BUILDER_REGISTRATION_TYPES,
|
|
36356
37463
|
BlockchainError,
|
|
36357
37464
|
BrowserPlatformAdapter,
|
|
37465
|
+
BuilderUnknownError,
|
|
37466
|
+
CLAIM_POLL_FLOOR_MS,
|
|
36358
37467
|
CONTRACTS,
|
|
36359
37468
|
CallbackStorage,
|
|
36360
37469
|
ContractFactory,
|
|
@@ -36363,6 +37472,8 @@ async function parsePSError(response) {
|
|
|
36363
37472
|
DATA_REGISTRY_STATUS_ABI,
|
|
36364
37473
|
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
36365
37474
|
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
37475
|
+
DEFAULT_JOB_DEADLINE_SECONDS,
|
|
37476
|
+
DEFAULT_LEASE_SECONDS,
|
|
36366
37477
|
DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
36367
37478
|
DEFAULT_QUESTION_TIMEOUT_MS,
|
|
36368
37479
|
DERIVATIVE_ERROR_CODES,
|
|
@@ -36387,6 +37498,9 @@ async function parsePSError(response) {
|
|
|
36387
37498
|
DerivativeStatusSchema,
|
|
36388
37499
|
DropboxStorage,
|
|
36389
37500
|
ECIESError,
|
|
37501
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
37502
|
+
ENCLAVE_TRUST_ANCHORS,
|
|
37503
|
+
ENCLAVE_WALLET_PURPOSE,
|
|
36390
37504
|
ESCROW_DEPOSIT_ABI,
|
|
36391
37505
|
ExpiredTokenError,
|
|
36392
37506
|
FEE_REGISTRY_ABI,
|
|
@@ -36395,12 +37509,25 @@ async function parsePSError(response) {
|
|
|
36395
37509
|
GRANT_REGISTRATION_TYPES,
|
|
36396
37510
|
GRANT_REVOCATION_TYPES,
|
|
36397
37511
|
GoogleDriveStorage,
|
|
37512
|
+
GrantInvalidError,
|
|
36398
37513
|
InMemoryTokenStore,
|
|
36399
37514
|
IngestResponseSchema,
|
|
36400
37515
|
InvalidConfigurationError,
|
|
36401
37516
|
InvalidScopeEntryError,
|
|
36402
37517
|
InvalidSignatureError,
|
|
36403
37518
|
IpfsStorage,
|
|
37519
|
+
JOB_OPERATIONS,
|
|
37520
|
+
JOB_PROTOCOL_VERSION,
|
|
37521
|
+
JOB_STATES,
|
|
37522
|
+
JobEnvelopeError,
|
|
37523
|
+
JobIdTakenError,
|
|
37524
|
+
JobNotFoundError,
|
|
37525
|
+
JobRejectedError,
|
|
37526
|
+
JobRequestTooLargeError,
|
|
37527
|
+
JobResultIntegrityError,
|
|
37528
|
+
JobTimeoutError,
|
|
37529
|
+
JobTransportError,
|
|
37530
|
+
JobsClientError,
|
|
36404
37531
|
LINEAGE_FIELD,
|
|
36405
37532
|
LINEAGE_KEY,
|
|
36406
37533
|
LineageEntrySchema,
|
|
@@ -36408,10 +37535,16 @@ async function parsePSError(response) {
|
|
|
36408
37535
|
LineageNodeSchema,
|
|
36409
37536
|
LineageReadError,
|
|
36410
37537
|
MASTER_KEY_MESSAGE,
|
|
37538
|
+
MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS,
|
|
37539
|
+
MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
37540
|
+
MAX_ATTEMPTS,
|
|
37541
|
+
MAX_JOB_DEADLINE_SECONDS,
|
|
37542
|
+
MAX_LEASE_SECONDS,
|
|
36411
37543
|
MAX_LINEAGE_SOURCES,
|
|
36412
37544
|
MAX_QUESTION_CHARS,
|
|
36413
37545
|
MAX_QUESTION_MODEL_CHARS,
|
|
36414
37546
|
MAX_QUESTION_SOURCE_SCOPES,
|
|
37547
|
+
MAX_WAIT_SECONDS,
|
|
36415
37548
|
MissingAuthError,
|
|
36416
37549
|
NATIVE_ASSET_ADDRESS,
|
|
36417
37550
|
NATIVE_VANA_ASSET,
|
|
@@ -36420,6 +37553,7 @@ async function parsePSError(response) {
|
|
|
36420
37553
|
NodePlatformAdapter,
|
|
36421
37554
|
NonceError,
|
|
36422
37555
|
OAuthClient,
|
|
37556
|
+
OwnerNotReadyError,
|
|
36423
37557
|
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
36424
37558
|
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
36425
37559
|
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
@@ -36445,6 +37579,7 @@ async function parsePSError(response) {
|
|
|
36445
37579
|
RedactedLineageNodeSchema,
|
|
36446
37580
|
RelayerError,
|
|
36447
37581
|
SCOPE_ACTIONS,
|
|
37582
|
+
SEALED_ENVELOPE_VERSION,
|
|
36448
37583
|
SERVER_REGISTRATION_TYPES,
|
|
36449
37584
|
ScopeSchema,
|
|
36450
37585
|
SerializationError,
|
|
@@ -36457,6 +37592,7 @@ async function parsePSError(response) {
|
|
|
36457
37592
|
TOMBSTONE_METADATA_HASH,
|
|
36458
37593
|
TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
36459
37594
|
TransactionPendingError,
|
|
37595
|
+
USER_PS_ID_DOMAIN,
|
|
36460
37596
|
UserRejectedRequestError,
|
|
36461
37597
|
VanaError,
|
|
36462
37598
|
VanaStorage,
|
|
@@ -36475,6 +37611,7 @@ async function parsePSError(response) {
|
|
|
36475
37611
|
WriteSessionExpiredError,
|
|
36476
37612
|
WriteTransportError,
|
|
36477
37613
|
WriteUnauthorizedError,
|
|
37614
|
+
appRootPreimage,
|
|
36478
37615
|
askPersonalServer,
|
|
36479
37616
|
assertDerivedScopeNaming,
|
|
36480
37617
|
assertValidPkceVerifier,
|
|
@@ -36488,6 +37625,7 @@ async function parsePSError(response) {
|
|
|
36488
37625
|
buildEscrowPaymentHeader,
|
|
36489
37626
|
buildGrantPaymentHeader,
|
|
36490
37627
|
buildMarkDataPointUnavailableRequest,
|
|
37628
|
+
buildMasterSignatureDelivery,
|
|
36491
37629
|
buildPersonalServerDataReadRequest,
|
|
36492
37630
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
36493
37631
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -36496,6 +37634,7 @@ async function parsePSError(response) {
|
|
|
36496
37634
|
buildSetDataPointStatusRequest,
|
|
36497
37635
|
buildWeb3SignedHeader,
|
|
36498
37636
|
builderRegistrationDomain,
|
|
37637
|
+
canonicalJobRequestBytes,
|
|
36499
37638
|
chains,
|
|
36500
37639
|
clearContractCache,
|
|
36501
37640
|
computeBodyHash,
|
|
@@ -36507,6 +37646,7 @@ async function parsePSError(response) {
|
|
|
36507
37646
|
createDefaultNonceSource,
|
|
36508
37647
|
createEscrowGatewayClient,
|
|
36509
37648
|
createGatewayClient,
|
|
37649
|
+
createJobsClient,
|
|
36510
37650
|
createNodePlatformAdapter,
|
|
36511
37651
|
createPlatformAdapter,
|
|
36512
37652
|
createPlatformAdapterFor,
|
|
@@ -36531,6 +37671,7 @@ async function parsePSError(response) {
|
|
|
36531
37671
|
encodeDepositTokenData,
|
|
36532
37672
|
encodeSetDataPointStatusData,
|
|
36533
37673
|
encodeWriteMetadataHeader,
|
|
37674
|
+
encryptMasterSignatureDelivery,
|
|
36534
37675
|
encryptWithPassword,
|
|
36535
37676
|
escrowContractAddress,
|
|
36536
37677
|
escrowPaymentDomain,
|
|
@@ -36565,12 +37706,15 @@ async function parsePSError(response) {
|
|
|
36565
37706
|
isPlatformSupported,
|
|
36566
37707
|
isRedactedLineageNode,
|
|
36567
37708
|
isTombstoneHashes,
|
|
37709
|
+
kmsIssuedPreimage,
|
|
36568
37710
|
listQuestions,
|
|
36569
37711
|
mainnetServices,
|
|
36570
37712
|
moksha,
|
|
36571
37713
|
mokshaServices,
|
|
36572
37714
|
mokshaTestnet,
|
|
36573
37715
|
normalizeBinaryMimeType,
|
|
37716
|
+
openJobRequest,
|
|
37717
|
+
openJobResult,
|
|
36574
37718
|
openWriteSession,
|
|
36575
37719
|
parsePSError,
|
|
36576
37720
|
parsePersonalServerPaymentRequired,
|
|
@@ -36594,6 +37738,8 @@ async function parsePSError(response) {
|
|
|
36594
37738
|
scopeMatchesPattern,
|
|
36595
37739
|
scopeNamespace,
|
|
36596
37740
|
scopeToPathSegments,
|
|
37741
|
+
sealJobRequest,
|
|
37742
|
+
sealJobResult,
|
|
36597
37743
|
serializeECIES,
|
|
36598
37744
|
serverRegistrationDomain,
|
|
36599
37745
|
sessionCoversScope,
|
|
@@ -36604,7 +37750,9 @@ async function parsePSError(response) {
|
|
|
36604
37750
|
toDirectPaymentReceipt,
|
|
36605
37751
|
tombstoneDeletedAt,
|
|
36606
37752
|
tryGrantPermissions,
|
|
37753
|
+
userPsId,
|
|
36607
37754
|
vanaMainnet,
|
|
37755
|
+
verifyEnclaveIdentityEvidence,
|
|
36608
37756
|
verifyGrantRegistration,
|
|
36609
37757
|
verifyPkceChallenge,
|
|
36610
37758
|
verifyWeb3Signed,
|