@opendatalabs/vana-sdk 3.20.1 → 3.22.0-pr.207.0a5d07b
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/README.md +64 -0
- package/dist/crypto/envelope/job.cjs +263 -0
- package/dist/crypto/envelope/job.cjs.map +1 -0
- package/dist/crypto/envelope/job.d.ts +122 -0
- package/dist/crypto/envelope/job.js +240 -0
- package/dist/crypto/envelope/job.js.map +1 -0
- package/dist/direct/access-request-client.cjs +100 -2
- package/dist/direct/access-request-client.cjs.map +1 -1
- package/dist/direct/access-request-client.d.ts +23 -1
- package/dist/direct/access-request-client.js +98 -1
- package/dist/direct/access-request-client.js.map +1 -1
- package/dist/direct/controller.cjs +4 -0
- package/dist/direct/controller.cjs.map +1 -1
- package/dist/direct/controller.d.ts +10 -1
- package/dist/direct/controller.js +6 -1
- package/dist/direct/controller.js.map +1 -1
- package/dist/direct/types.cjs.map +1 -1
- package/dist/direct/types.d.ts +45 -0
- package/dist/direct/types.js.map +1 -1
- package/dist/errors.cjs +77 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +123 -0
- package/dist/errors.js +67 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.browser.d.ts +5 -1
- package/dist/index.browser.js +721 -24
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +1309 -107
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +6 -1
- package/dist/index.node.js +1261 -97
- package/dist/index.node.js.map +4 -4
- package/dist/protocol/derivative-questions.cjs +22 -0
- package/dist/protocol/derivative-questions.cjs.map +1 -1
- package/dist/protocol/derivative-questions.d.ts +53 -0
- package/dist/protocol/derivative-questions.js +19 -0
- package/dist/protocol/derivative-questions.js.map +1 -1
- package/dist/protocol/derivative-status.cjs +209 -0
- package/dist/protocol/derivative-status.cjs.map +1 -0
- package/dist/protocol/derivative-status.d.ts +196 -0
- package/dist/protocol/derivative-status.js +190 -0
- package/dist/protocol/derivative-status.js.map +1 -0
- package/dist/protocol/derivative-status.test.d.ts +1 -0
- 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 +493 -0
- package/dist/protocol/jobs-client.cjs.map +1 -0
- package/dist/protocol/jobs-client.d.ts +167 -0
- package/dist/protocol/jobs-client.js +498 -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 +67 -0
- package/dist/protocol/jobs.cjs.map +1 -0
- package/dist/protocol/jobs.d.ts +185 -0
- package/dist/protocol/jobs.js +33 -0
- package/dist/protocol/jobs.js.map +1 -0
- package/dist/protocol/jobs.test.d.ts +1 -0
- package/dist/server.cjs +4 -2
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +4 -2
- package/dist/server.js.map +1 -1
- package/dist/tests/mock-personal-server.d.ts +9 -0
- package/package.json +7 -1
package/dist/index.browser.js
CHANGED
|
@@ -1338,6 +1338,63 @@ var WriteRejectedError = class extends PersonalServerWriteError {
|
|
|
1338
1338
|
super(message, "WRITE_REJECTED", status, errorCode, details);
|
|
1339
1339
|
}
|
|
1340
1340
|
};
|
|
1341
|
+
var JobsClientError = class extends VanaError {
|
|
1342
|
+
constructor(message, code, status, errorCode = null, details) {
|
|
1343
|
+
super(message, code);
|
|
1344
|
+
this.status = status;
|
|
1345
|
+
this.errorCode = errorCode;
|
|
1346
|
+
this.details = details;
|
|
1347
|
+
}
|
|
1348
|
+
status;
|
|
1349
|
+
errorCode;
|
|
1350
|
+
details;
|
|
1351
|
+
};
|
|
1352
|
+
var BuilderUnknownError = class extends JobsClientError {
|
|
1353
|
+
constructor(message, details) {
|
|
1354
|
+
super(message, "JOB_BUILDER_UNKNOWN", 403, "BUILDER_UNKNOWN", details);
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
var GrantInvalidError = class extends JobsClientError {
|
|
1358
|
+
constructor(message, details) {
|
|
1359
|
+
super(message, "JOB_GRANT_INVALID", 403, "GRANT_INVALID", details);
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
var OwnerNotReadyError = class extends JobsClientError {
|
|
1363
|
+
constructor(message, details) {
|
|
1364
|
+
super(message, "JOB_OWNER_NOT_READY", 403, "OWNER_NOT_READY", details);
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
var JobIdTakenError = class extends JobsClientError {
|
|
1368
|
+
constructor(message, details) {
|
|
1369
|
+
super(message, "JOB_ID_TAKEN", 409, "JOB_ID_TAKEN", details);
|
|
1370
|
+
}
|
|
1371
|
+
};
|
|
1372
|
+
var JobNotFoundError = class extends JobsClientError {
|
|
1373
|
+
constructor(message, details) {
|
|
1374
|
+
super(message, "JOB_NOT_FOUND", 404, "JOB_NOT_FOUND", details);
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
var JobRequestTooLargeError = class extends JobsClientError {
|
|
1378
|
+
constructor(message, errorCode = "BODY_TOO_LARGE", details) {
|
|
1379
|
+
super(message, "JOB_REQUEST_TOO_LARGE", 413, errorCode, details);
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
var JobTimeoutError = class extends JobsClientError {
|
|
1383
|
+
constructor(message, details) {
|
|
1384
|
+
super(message, "JOB_TIMEOUT", void 0, null, details);
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
var JobRejectedError = class extends JobsClientError {
|
|
1388
|
+
constructor(message, status, errorCode = null, details) {
|
|
1389
|
+
super(message, "JOB_REJECTED", status, errorCode, details);
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
var JobTransportError = class extends JobsClientError {
|
|
1393
|
+
constructor(message, cause) {
|
|
1394
|
+
super(message, "JOB_TRANSPORT_ERROR");
|
|
1395
|
+
this.cause = cause;
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1341
1398
|
var LineageReadError = class extends VanaError {
|
|
1342
1399
|
constructor(message, status, errorCode = null, details) {
|
|
1343
1400
|
super(message, "LINEAGE_READ_ERROR");
|
|
@@ -31736,9 +31793,423 @@ var RECORD_DATA_ACCESS_TYPES = {
|
|
|
31736
31793
|
]
|
|
31737
31794
|
};
|
|
31738
31795
|
|
|
31796
|
+
// src/protocol/identity.ts
|
|
31797
|
+
init_interface();
|
|
31798
|
+
import * as secp256k13 from "@noble/secp256k1";
|
|
31799
|
+
import {
|
|
31800
|
+
concat as concat4,
|
|
31801
|
+
encodePacked,
|
|
31802
|
+
fromHex as fromHex5,
|
|
31803
|
+
getAddress,
|
|
31804
|
+
isAddressEqual,
|
|
31805
|
+
keccak256,
|
|
31806
|
+
recoverPublicKey,
|
|
31807
|
+
toBytes,
|
|
31808
|
+
toHex as toHex6
|
|
31809
|
+
} from "viem";
|
|
31810
|
+
import { publicKeyToAddress } from "viem/accounts";
|
|
31811
|
+
var ENCLAVE_IDENTITY_EVIDENCE_VERSION = 1;
|
|
31812
|
+
var USER_PS_ID_DOMAIN = "vana.ps-enclave.v1";
|
|
31813
|
+
var ENCLAVE_WALLET_PURPOSE = "vana.ps-enclave.wallet.v1";
|
|
31814
|
+
var MASTER_SIGNATURE_DELIVERY_VERSION = "vana.ps-enclave.delivery.v1";
|
|
31815
|
+
var MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS = 600;
|
|
31816
|
+
var SEALED_ENVELOPE_VERSION = 1;
|
|
31817
|
+
var VANA_MAINNET_CHAIN_ID = 1480;
|
|
31818
|
+
var MOKSHA_CHAIN_ID = 14800;
|
|
31819
|
+
var KMS_ISSUED_PREFIX = "dstack-kms-issued";
|
|
31820
|
+
var PREIMAGE_SEPARATOR = ":";
|
|
31821
|
+
var UNCOMPRESSED_PUBLIC_KEY_BYTES = 65;
|
|
31822
|
+
var UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04";
|
|
31823
|
+
var EMPTY_HEX = "0x";
|
|
31824
|
+
function emptyAnchor() {
|
|
31825
|
+
return Object.freeze({
|
|
31826
|
+
kmsRootPubkey: EMPTY_HEX,
|
|
31827
|
+
appIds: Object.freeze([])
|
|
31828
|
+
});
|
|
31829
|
+
}
|
|
31830
|
+
var ENCLAVE_TRUST_ANCHORS = Object.freeze({
|
|
31831
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
31832
|
+
[VANA_MAINNET_CHAIN_ID]: emptyAnchor(),
|
|
31833
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
31834
|
+
[MOKSHA_CHAIN_ID]: emptyAnchor()
|
|
31835
|
+
});
|
|
31836
|
+
function userPsId(chainId, ownerAddress) {
|
|
31837
|
+
const packed = encodePacked(
|
|
31838
|
+
["string", "uint256", "address"],
|
|
31839
|
+
[USER_PS_ID_DOMAIN, BigInt(chainId), getAddress(ownerAddress)]
|
|
31840
|
+
);
|
|
31841
|
+
return keccak256(packed);
|
|
31842
|
+
}
|
|
31843
|
+
function compressPublicKey(publicKey) {
|
|
31844
|
+
return secp256k13.ProjectivePoint.fromHex(
|
|
31845
|
+
fromHex5(publicKey, "bytes")
|
|
31846
|
+
).toRawBytes(true);
|
|
31847
|
+
}
|
|
31848
|
+
function sameKey(a, b) {
|
|
31849
|
+
return toHex6(compressPublicKey(a)) === toHex6(compressPublicKey(b));
|
|
31850
|
+
}
|
|
31851
|
+
function assertUncompressedKey(publicKey) {
|
|
31852
|
+
const hex = publicKey.slice(2);
|
|
31853
|
+
if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
31854
|
+
throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
|
|
31855
|
+
}
|
|
31856
|
+
}
|
|
31857
|
+
function appRootPreimage(purpose, publicKey) {
|
|
31858
|
+
const keyHex = toHex6(compressPublicKey(publicKey)).slice(2);
|
|
31859
|
+
return keccak256(toBytes(`${purpose}${PREIMAGE_SEPARATOR}${keyHex}`));
|
|
31860
|
+
}
|
|
31861
|
+
function kmsIssuedPreimage(appId, appRootPublicKey) {
|
|
31862
|
+
const prefix = concat4([
|
|
31863
|
+
toBytes(`${KMS_ISSUED_PREFIX}${PREIMAGE_SEPARATOR}`),
|
|
31864
|
+
fromHex5(appId, "bytes")
|
|
31865
|
+
]);
|
|
31866
|
+
const compressed = compressPublicKey(appRootPublicKey);
|
|
31867
|
+
return keccak256(concat4([prefix, compressed]));
|
|
31868
|
+
}
|
|
31869
|
+
async function recoverChainKey(hash, signature, link) {
|
|
31870
|
+
try {
|
|
31871
|
+
return (await recoverPublicKey({ hash, signature })).toLowerCase();
|
|
31872
|
+
} catch {
|
|
31873
|
+
throw new Error(`Invalid enclave signature chain link ${link}`);
|
|
31874
|
+
}
|
|
31875
|
+
}
|
|
31876
|
+
async function verifyEnclaveIdentityEvidence(evidence, anchors, expected) {
|
|
31877
|
+
if (evidence.v !== ENCLAVE_IDENTITY_EVIDENCE_VERSION) {
|
|
31878
|
+
throw new Error("Unsupported enclave identity evidence version");
|
|
31879
|
+
}
|
|
31880
|
+
if (!Number.isInteger(evidence.epoch) || evidence.epoch < 1) {
|
|
31881
|
+
throw new Error("Invalid enclave identity epoch");
|
|
31882
|
+
}
|
|
31883
|
+
if (evidence.chainId !== expected.chainId) {
|
|
31884
|
+
throw new Error(
|
|
31885
|
+
"Enclave identity chain ID does not match expected chain ID"
|
|
31886
|
+
);
|
|
31887
|
+
}
|
|
31888
|
+
if (!isAddressEqual(evidence.ownerAddress, expected.ownerAddress)) {
|
|
31889
|
+
throw new Error("Enclave identity owner does not match expected owner");
|
|
31890
|
+
}
|
|
31891
|
+
if (evidence.epoch !== expected.epoch) {
|
|
31892
|
+
throw new Error("Enclave identity epoch does not match expected epoch");
|
|
31893
|
+
}
|
|
31894
|
+
const expectedUserPsId = userPsId(expected.chainId, expected.ownerAddress);
|
|
31895
|
+
if (evidence.userPsId.toLowerCase() !== expectedUserPsId.toLowerCase()) {
|
|
31896
|
+
throw new Error("Enclave userPsId does not match expected identity");
|
|
31897
|
+
}
|
|
31898
|
+
if (evidence.purpose !== ENCLAVE_WALLET_PURPOSE) {
|
|
31899
|
+
throw new Error("Unexpected enclave wallet purpose");
|
|
31900
|
+
}
|
|
31901
|
+
if (anchors.kmsRootPubkey === EMPTY_HEX) {
|
|
31902
|
+
throw new Error("KMS root trust anchor is not provisioned");
|
|
31903
|
+
}
|
|
31904
|
+
assertUncompressedKey(evidence.publicKey);
|
|
31905
|
+
const derivedAddress = publicKeyToAddress(evidence.publicKey);
|
|
31906
|
+
if (getAddress(derivedAddress) !== getAddress(evidence.address)) {
|
|
31907
|
+
throw new Error("Enclave public key does not match its address");
|
|
31908
|
+
}
|
|
31909
|
+
const appRootPublicKey = await recoverChainKey(
|
|
31910
|
+
appRootPreimage(evidence.purpose, evidence.publicKey),
|
|
31911
|
+
evidence.signatureChain[0],
|
|
31912
|
+
0
|
|
31913
|
+
);
|
|
31914
|
+
const kmsRootPublicKey = await recoverChainKey(
|
|
31915
|
+
kmsIssuedPreimage(evidence.appId, appRootPublicKey),
|
|
31916
|
+
evidence.signatureChain[1],
|
|
31917
|
+
1
|
|
31918
|
+
);
|
|
31919
|
+
let matchesAnchor;
|
|
31920
|
+
try {
|
|
31921
|
+
matchesAnchor = sameKey(kmsRootPublicKey, anchors.kmsRootPubkey);
|
|
31922
|
+
} catch {
|
|
31923
|
+
throw new Error("KMS root trust anchor is malformed");
|
|
31924
|
+
}
|
|
31925
|
+
if (!matchesAnchor) {
|
|
31926
|
+
throw new Error("KMS root public key does not match the trust anchor");
|
|
31927
|
+
}
|
|
31928
|
+
if (keccak256(kmsRootPublicKey) !== evidence.kmsRootFingerprint.toLowerCase()) {
|
|
31929
|
+
throw new Error("KMS root fingerprint does not match the evidence");
|
|
31930
|
+
}
|
|
31931
|
+
const appId = evidence.appId.toLowerCase();
|
|
31932
|
+
if (!anchors.appIds.some((allowedAppId) => allowedAppId.toLowerCase() === appId)) {
|
|
31933
|
+
throw new Error("Enclave app ID is not trusted");
|
|
31934
|
+
}
|
|
31935
|
+
}
|
|
31936
|
+
async function buildMasterSignatureDelivery(evidence, masterSignature, now = Math.floor(Date.now() / 1e3)) {
|
|
31937
|
+
deriveMasterKey(masterSignature);
|
|
31938
|
+
const signerAddress = await recoverServerOwner(masterSignature);
|
|
31939
|
+
if (!isAddressEqual(signerAddress, evidence.ownerAddress)) {
|
|
31940
|
+
throw new Error("Master signature signer does not match evidence owner");
|
|
31941
|
+
}
|
|
31942
|
+
return {
|
|
31943
|
+
v: MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
31944
|
+
userPsId: evidence.userPsId,
|
|
31945
|
+
epoch: evidence.epoch,
|
|
31946
|
+
enclaveAddress: evidence.address,
|
|
31947
|
+
ownerAddress: evidence.ownerAddress,
|
|
31948
|
+
masterSignature,
|
|
31949
|
+
issuedAt: now
|
|
31950
|
+
};
|
|
31951
|
+
}
|
|
31952
|
+
async function encryptMasterSignatureDelivery(delivery, publicKey, ecies) {
|
|
31953
|
+
assertUncompressedKey(publicKey);
|
|
31954
|
+
if (!isAddressEqual(publicKeyToAddress(publicKey), delivery.enclaveAddress)) {
|
|
31955
|
+
throw new Error(
|
|
31956
|
+
"Public key does not belong to the delivery's enclave address"
|
|
31957
|
+
);
|
|
31958
|
+
}
|
|
31959
|
+
const plaintext = toBytes(JSON.stringify(delivery));
|
|
31960
|
+
const encrypted = await ecies.encrypt(fromHex5(publicKey, "bytes"), plaintext);
|
|
31961
|
+
return `0x${serializeECIES(encrypted)}`;
|
|
31962
|
+
}
|
|
31963
|
+
|
|
31964
|
+
// src/protocol/jobs.ts
|
|
31965
|
+
var JOB_PROTOCOL_VERSION = 1;
|
|
31966
|
+
var JOB_OPERATIONS = ["raw_read", "inference"];
|
|
31967
|
+
var JOB_STATES = [
|
|
31968
|
+
"queued",
|
|
31969
|
+
"claimed",
|
|
31970
|
+
"running",
|
|
31971
|
+
"completed",
|
|
31972
|
+
"failed",
|
|
31973
|
+
"expired",
|
|
31974
|
+
"cancelled"
|
|
31975
|
+
];
|
|
31976
|
+
var DEFAULT_LEASE_SECONDS = 30;
|
|
31977
|
+
var MAX_LEASE_SECONDS = 300;
|
|
31978
|
+
var MAX_ATTEMPTS = 3;
|
|
31979
|
+
var MAX_WAIT_SECONDS = 25;
|
|
31980
|
+
var CLAIM_POLL_FLOOR_MS = 1e3;
|
|
31981
|
+
var MAX_INLINE_RESULT_BYTES = 1048576;
|
|
31982
|
+
var DEFAULT_JOB_DEADLINE_SECONDS = 600;
|
|
31983
|
+
var MAX_JOB_DEADLINE_SECONDS = 3600;
|
|
31984
|
+
|
|
31985
|
+
// src/crypto/envelope/job.ts
|
|
31986
|
+
init_interface();
|
|
31987
|
+
import { sha256 as sha2565 } from "@noble/hashes/sha2";
|
|
31988
|
+
import { bytesToHex as bytesToHex2, fromHex as fromHex6, isAddress, isHex, toHex as toHex7 } from "viem";
|
|
31989
|
+
var textDecoder = new TextDecoder();
|
|
31990
|
+
var textEncoder = new TextEncoder();
|
|
31991
|
+
var JobEnvelopeError = class extends Error {
|
|
31992
|
+
constructor(message) {
|
|
31993
|
+
super(message);
|
|
31994
|
+
this.name = "JobEnvelopeError";
|
|
31995
|
+
}
|
|
31996
|
+
};
|
|
31997
|
+
function sortJsonKeys(value) {
|
|
31998
|
+
if (Array.isArray(value)) {
|
|
31999
|
+
return value.map(sortJsonKeys);
|
|
32000
|
+
}
|
|
32001
|
+
if (value !== null && typeof value === "object") {
|
|
32002
|
+
return Object.fromEntries(
|
|
32003
|
+
Object.keys(value).sort().map((key) => [
|
|
32004
|
+
key,
|
|
32005
|
+
sortJsonKeys(value[key])
|
|
32006
|
+
])
|
|
32007
|
+
);
|
|
32008
|
+
}
|
|
32009
|
+
return value;
|
|
32010
|
+
}
|
|
32011
|
+
function canonicalJsonBytes(value) {
|
|
32012
|
+
return textEncoder.encode(JSON.stringify(sortJsonKeys(value)));
|
|
32013
|
+
}
|
|
32014
|
+
function canonicalJobRequestBytes(request) {
|
|
32015
|
+
validateJobRequest(request);
|
|
32016
|
+
return canonicalJsonBytes(request);
|
|
32017
|
+
}
|
|
32018
|
+
function requestPlaintext(envelope) {
|
|
32019
|
+
validateRequestEnvelope(envelope);
|
|
32020
|
+
return canonicalJsonBytes(envelope);
|
|
32021
|
+
}
|
|
32022
|
+
function resultPlaintext(result) {
|
|
32023
|
+
return textEncoder.encode(
|
|
32024
|
+
JSON.stringify({
|
|
32025
|
+
v: result.v,
|
|
32026
|
+
jobId: result.jobId,
|
|
32027
|
+
scope: result.scope,
|
|
32028
|
+
version: result.version,
|
|
32029
|
+
contentType: result.contentType,
|
|
32030
|
+
body: result.body
|
|
32031
|
+
})
|
|
32032
|
+
);
|
|
32033
|
+
}
|
|
32034
|
+
function encryptedBytesToBase64(encrypted) {
|
|
32035
|
+
return toBase64(fromHex6(`0x${serializeECIES(encrypted)}`, "bytes"));
|
|
32036
|
+
}
|
|
32037
|
+
function base64ToEncrypted(ciphertext) {
|
|
32038
|
+
return deserializeECIES(toHex7(fromBase64(ciphertext)));
|
|
32039
|
+
}
|
|
32040
|
+
function parseObject(plaintext, kind) {
|
|
32041
|
+
try {
|
|
32042
|
+
const value = JSON.parse(textDecoder.decode(plaintext));
|
|
32043
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
32044
|
+
throw new JobEnvelopeError(`Invalid ${kind}: expected an object`);
|
|
32045
|
+
}
|
|
32046
|
+
return value;
|
|
32047
|
+
} catch (error) {
|
|
32048
|
+
if (error instanceof JobEnvelopeError) throw error;
|
|
32049
|
+
throw new JobEnvelopeError(`Invalid ${kind}: malformed JSON`);
|
|
32050
|
+
}
|
|
32051
|
+
}
|
|
32052
|
+
function isPlainObject2(value) {
|
|
32053
|
+
if (value === null || typeof value !== "object") return false;
|
|
32054
|
+
const prototype = Object.getPrototypeOf(value);
|
|
32055
|
+
return prototype === Object.prototype || prototype === null;
|
|
32056
|
+
}
|
|
32057
|
+
function requirePlainObject(value, field, kind) {
|
|
32058
|
+
if (!isPlainObject2(value)) {
|
|
32059
|
+
throw new JobEnvelopeError(`Invalid ${kind}: invalid ${field}`);
|
|
32060
|
+
}
|
|
32061
|
+
}
|
|
32062
|
+
function requireExactKeys(value, expectedKeys, kind) {
|
|
32063
|
+
for (const key of expectedKeys) {
|
|
32064
|
+
if (!Object.hasOwn(value, key) || value[key] === void 0) {
|
|
32065
|
+
throw new JobEnvelopeError(`Invalid ${kind}: missing ${key}`);
|
|
32066
|
+
}
|
|
32067
|
+
}
|
|
32068
|
+
const expected = new Set(expectedKeys);
|
|
32069
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
32070
|
+
if (!expected.has(key)) {
|
|
32071
|
+
throw new JobEnvelopeError(
|
|
32072
|
+
`Invalid ${kind}: unknown field ${String(key)}`
|
|
32073
|
+
);
|
|
32074
|
+
}
|
|
32075
|
+
}
|
|
32076
|
+
}
|
|
32077
|
+
function requireString(value, field, kind) {
|
|
32078
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
32079
|
+
throw new JobEnvelopeError(`Invalid ${kind}: missing ${field}`);
|
|
32080
|
+
}
|
|
32081
|
+
}
|
|
32082
|
+
function validateJobRequest(value) {
|
|
32083
|
+
requirePlainObject(value, "request", "job request");
|
|
32084
|
+
requireExactKeys(
|
|
32085
|
+
value,
|
|
32086
|
+
[
|
|
32087
|
+
"v",
|
|
32088
|
+
"jobId",
|
|
32089
|
+
"owner",
|
|
32090
|
+
"builder",
|
|
32091
|
+
"builderPublicKey",
|
|
32092
|
+
"grantId",
|
|
32093
|
+
"scope",
|
|
32094
|
+
"operation",
|
|
32095
|
+
"pinnedVersion",
|
|
32096
|
+
"deadline"
|
|
32097
|
+
],
|
|
32098
|
+
"job request"
|
|
32099
|
+
);
|
|
32100
|
+
if (value.v !== JOB_PROTOCOL_VERSION) {
|
|
32101
|
+
throw new JobEnvelopeError(
|
|
32102
|
+
`Unsupported job request version: ${String(value.v)}`
|
|
32103
|
+
);
|
|
32104
|
+
}
|
|
32105
|
+
requireString(value.jobId, "jobId", "job request");
|
|
32106
|
+
if (typeof value.owner !== "string" || !isAddress(value.owner)) {
|
|
32107
|
+
throw new JobEnvelopeError("Invalid job request: invalid owner");
|
|
32108
|
+
}
|
|
32109
|
+
if (typeof value.builder !== "string" || !isAddress(value.builder)) {
|
|
32110
|
+
throw new JobEnvelopeError("Invalid job request: invalid builder");
|
|
32111
|
+
}
|
|
32112
|
+
if (typeof value.builderPublicKey !== "string" || !isHex(value.builderPublicKey)) {
|
|
32113
|
+
throw new JobEnvelopeError("Invalid job request: invalid builderPublicKey");
|
|
32114
|
+
}
|
|
32115
|
+
if (typeof value.grantId !== "string" || !isHex(value.grantId)) {
|
|
32116
|
+
throw new JobEnvelopeError("Invalid job request: invalid grantId");
|
|
32117
|
+
}
|
|
32118
|
+
requireString(value.scope, "scope", "job request");
|
|
32119
|
+
if (!JOB_OPERATIONS.includes(value.operation)) {
|
|
32120
|
+
throw new JobEnvelopeError("Invalid job request: invalid operation");
|
|
32121
|
+
}
|
|
32122
|
+
if (value.pinnedVersion !== null && typeof value.pinnedVersion !== "string") {
|
|
32123
|
+
throw new JobEnvelopeError("Invalid job request: missing pinnedVersion");
|
|
32124
|
+
}
|
|
32125
|
+
if (typeof value.deadline !== "string" || !Number.isFinite(Date.parse(value.deadline))) {
|
|
32126
|
+
throw new JobEnvelopeError("Invalid job request: invalid deadline");
|
|
32127
|
+
}
|
|
32128
|
+
return value;
|
|
32129
|
+
}
|
|
32130
|
+
function validateRequestEnvelope(value) {
|
|
32131
|
+
requirePlainObject(value, "envelope", "job request envelope");
|
|
32132
|
+
requireExactKeys(value, ["request", "auth"], "job request envelope");
|
|
32133
|
+
validateJobRequest(value.request);
|
|
32134
|
+
requireString(value.auth, "auth", "job request envelope");
|
|
32135
|
+
return value;
|
|
32136
|
+
}
|
|
32137
|
+
function validateResult(value) {
|
|
32138
|
+
requirePlainObject(value, "result", "job result");
|
|
32139
|
+
requireExactKeys(
|
|
32140
|
+
value,
|
|
32141
|
+
["v", "jobId", "scope", "version", "contentType", "body"],
|
|
32142
|
+
"job result"
|
|
32143
|
+
);
|
|
32144
|
+
if (value.v !== JOB_PROTOCOL_VERSION) {
|
|
32145
|
+
throw new JobEnvelopeError(
|
|
32146
|
+
`Unsupported job result version: ${String(value.v)}`
|
|
32147
|
+
);
|
|
32148
|
+
}
|
|
32149
|
+
for (const field of ["jobId", "scope", "contentType"]) {
|
|
32150
|
+
requireString(value[field], field, "job result");
|
|
32151
|
+
}
|
|
32152
|
+
if (typeof value.body !== "string") {
|
|
32153
|
+
throw new JobEnvelopeError("Invalid job result: missing body");
|
|
32154
|
+
}
|
|
32155
|
+
if (value.version !== null && typeof value.version !== "string") {
|
|
32156
|
+
throw new JobEnvelopeError("Invalid job result: missing version");
|
|
32157
|
+
}
|
|
32158
|
+
return value;
|
|
32159
|
+
}
|
|
32160
|
+
async function sealJobRequest(envelope, enclavePublicKey, ecies) {
|
|
32161
|
+
const encrypted = await ecies.encrypt(
|
|
32162
|
+
fromHex6(enclavePublicKey, "bytes"),
|
|
32163
|
+
requestPlaintext(envelope)
|
|
32164
|
+
);
|
|
32165
|
+
return encryptedBytesToBase64(encrypted);
|
|
32166
|
+
}
|
|
32167
|
+
async function openJobRequest(ciphertext, privateKey, ecies) {
|
|
32168
|
+
const plaintext = await ecies.decrypt(
|
|
32169
|
+
privateKey,
|
|
32170
|
+
base64ToEncrypted(ciphertext)
|
|
32171
|
+
);
|
|
32172
|
+
return validateRequestEnvelope(
|
|
32173
|
+
parseObject(plaintext, "job request envelope")
|
|
32174
|
+
);
|
|
32175
|
+
}
|
|
32176
|
+
async function sealJobResult(result, builderPublicKey, ecies) {
|
|
32177
|
+
validateResult(result);
|
|
32178
|
+
const encrypted = await ecies.encrypt(
|
|
32179
|
+
fromHex6(builderPublicKey, "bytes"),
|
|
32180
|
+
resultPlaintext(result)
|
|
32181
|
+
);
|
|
32182
|
+
const ciphertext = encryptedBytesToBase64(encrypted);
|
|
32183
|
+
const bytes = fromBase64(ciphertext);
|
|
32184
|
+
return { ciphertext, hash: bytesToHex2(sha2565(bytes)), size: bytes.length };
|
|
32185
|
+
}
|
|
32186
|
+
async function openJobResult(ciphertext, builderPrivateKey, ecies, expect) {
|
|
32187
|
+
const plaintext = await ecies.decrypt(
|
|
32188
|
+
fromHex6(builderPrivateKey, "bytes"),
|
|
32189
|
+
base64ToEncrypted(ciphertext)
|
|
32190
|
+
);
|
|
32191
|
+
const result = validateResult(parseObject(plaintext, "job result"));
|
|
32192
|
+
if (result.jobId !== expect.jobId) {
|
|
32193
|
+
throw new JobEnvelopeError(
|
|
32194
|
+
`Job result ID ${result.jobId} does not match expected job ID ${expect.jobId}`
|
|
32195
|
+
);
|
|
32196
|
+
}
|
|
32197
|
+
if (expect.scope !== void 0 && result.scope !== expect.scope) {
|
|
32198
|
+
throw new JobEnvelopeError(
|
|
32199
|
+
`Job result scope ${result.scope} does not match expected scope ${expect.scope}`
|
|
32200
|
+
);
|
|
32201
|
+
}
|
|
32202
|
+
if (expect.version !== void 0 && result.version !== expect.version) {
|
|
32203
|
+
throw new JobEnvelopeError(
|
|
32204
|
+
`Job result version ${String(result.version)} does not match expected version ${String(expect.version)}`
|
|
32205
|
+
);
|
|
32206
|
+
}
|
|
32207
|
+
return result;
|
|
32208
|
+
}
|
|
32209
|
+
|
|
31739
32210
|
// src/protocol/personal-server-registration.ts
|
|
31740
32211
|
import {
|
|
31741
|
-
isAddress
|
|
32212
|
+
isAddress as isAddress2
|
|
31742
32213
|
} from "viem";
|
|
31743
32214
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
31744
32215
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
@@ -31746,7 +32217,7 @@ var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress
|
|
|
31746
32217
|
"DataPortabilityServers"
|
|
31747
32218
|
);
|
|
31748
32219
|
function assertAddress(value, name) {
|
|
31749
|
-
if (!
|
|
32220
|
+
if (!isAddress2(value)) {
|
|
31750
32221
|
throw new Error(`${name} must be a valid EVM address`);
|
|
31751
32222
|
}
|
|
31752
32223
|
}
|
|
@@ -31833,13 +32304,13 @@ var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
|
31833
32304
|
|
|
31834
32305
|
// src/personal-server-lite/owner-binding.ts
|
|
31835
32306
|
import {
|
|
31836
|
-
isAddress as
|
|
32307
|
+
isAddress as isAddress3
|
|
31837
32308
|
} from "viem";
|
|
31838
32309
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
31839
32310
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
31840
32311
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
31841
32312
|
function assertAddress2(value, name) {
|
|
31842
|
-
if (!
|
|
32313
|
+
if (!isAddress3(value)) {
|
|
31843
32314
|
throw new Error(`${name} must be a valid EVM address`);
|
|
31844
32315
|
}
|
|
31845
32316
|
}
|
|
@@ -31889,7 +32360,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
|
31889
32360
|
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
31890
32361
|
|
|
31891
32362
|
// src/account/personal-server-registration.ts
|
|
31892
|
-
import { isAddress as
|
|
32363
|
+
import { isAddress as isAddress4 } from "viem";
|
|
31893
32364
|
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
31894
32365
|
var AccountPersonalServerRegistrationError = class extends Error {
|
|
31895
32366
|
status;
|
|
@@ -31908,7 +32379,7 @@ function trimTrailingSlash(value) {
|
|
|
31908
32379
|
return value.replace(/\/+$/, "");
|
|
31909
32380
|
}
|
|
31910
32381
|
function assertAddress3(value, name) {
|
|
31911
|
-
if (!
|
|
32382
|
+
if (!isAddress4(value)) {
|
|
31912
32383
|
throw new Error(`${name} must be a valid EVM address`);
|
|
31913
32384
|
}
|
|
31914
32385
|
}
|
|
@@ -32434,8 +32905,8 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
32434
32905
|
|
|
32435
32906
|
// src/protocol/data-point-deletion.ts
|
|
32436
32907
|
import {
|
|
32437
|
-
isAddress as
|
|
32438
|
-
keccak256 as
|
|
32908
|
+
isAddress as isAddress6,
|
|
32909
|
+
keccak256 as keccak2563,
|
|
32439
32910
|
maxUint256,
|
|
32440
32911
|
stringToBytes as stringToBytes3
|
|
32441
32912
|
} from "viem";
|
|
@@ -32443,8 +32914,8 @@ import {
|
|
|
32443
32914
|
// src/protocol/lineage.ts
|
|
32444
32915
|
import {
|
|
32445
32916
|
encodeAbiParameters,
|
|
32446
|
-
isAddress as
|
|
32447
|
-
keccak256
|
|
32917
|
+
isAddress as isAddress5,
|
|
32918
|
+
keccak256 as keccak2562
|
|
32448
32919
|
} from "viem";
|
|
32449
32920
|
import { z } from "zod";
|
|
32450
32921
|
|
|
@@ -32523,12 +32994,12 @@ function isDataPointId(value) {
|
|
|
32523
32994
|
return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
|
|
32524
32995
|
}
|
|
32525
32996
|
function deriveDataPointId(ownerAddress, scope) {
|
|
32526
|
-
if (!
|
|
32997
|
+
if (!isAddress5(ownerAddress, { strict: false })) {
|
|
32527
32998
|
throw new Error(
|
|
32528
32999
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
32529
33000
|
);
|
|
32530
33001
|
}
|
|
32531
|
-
return
|
|
33002
|
+
return keccak2562(
|
|
32532
33003
|
encodeAbiParameters(
|
|
32533
33004
|
[
|
|
32534
33005
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -32755,7 +33226,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
32755
33226
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
32756
33227
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
32757
33228
|
function computeTombstoneHash(preimage) {
|
|
32758
|
-
return
|
|
33229
|
+
return keccak2563(stringToBytes3(preimage));
|
|
32759
33230
|
}
|
|
32760
33231
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
32761
33232
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -32774,7 +33245,7 @@ function tombstoneDeletedAt(value) {
|
|
|
32774
33245
|
return typeof deletedAt === "string" ? deletedAt : null;
|
|
32775
33246
|
}
|
|
32776
33247
|
function assertAddress4(value, name) {
|
|
32777
|
-
if (!
|
|
33248
|
+
if (!isAddress6(value)) {
|
|
32778
33249
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32779
33250
|
}
|
|
32780
33251
|
}
|
|
@@ -33189,13 +33660,13 @@ function tryGrantPermissions(scopes) {
|
|
|
33189
33660
|
}
|
|
33190
33661
|
|
|
33191
33662
|
// src/protocol/personal-server-write.ts
|
|
33192
|
-
import { sha256 as
|
|
33193
|
-
import { bytesToHex as
|
|
33663
|
+
import { sha256 as sha2567 } from "@noble/hashes/sha2";
|
|
33664
|
+
import { bytesToHex as bytesToHex4, isAddress as isAddress7 } from "viem";
|
|
33194
33665
|
import { z as z4 } from "zod";
|
|
33195
33666
|
|
|
33196
33667
|
// src/protocol/write-request.ts
|
|
33197
|
-
import { sha256 as
|
|
33198
|
-
import { bytesToHex as
|
|
33668
|
+
import { sha256 as sha2566 } from "@noble/hashes/sha2";
|
|
33669
|
+
import { bytesToHex as bytesToHex3 } from "viem";
|
|
33199
33670
|
function normalizeBaseUrl2(url) {
|
|
33200
33671
|
return url.replace(/\/+$/, "");
|
|
33201
33672
|
}
|
|
@@ -33262,22 +33733,22 @@ function freshProofNonce() {
|
|
|
33262
33733
|
return webCrypto.randomUUID();
|
|
33263
33734
|
}
|
|
33264
33735
|
if (typeof webCrypto?.getRandomValues === "function") {
|
|
33265
|
-
return
|
|
33736
|
+
return bytesToHex3(webCrypto.getRandomValues(new Uint8Array(16)));
|
|
33266
33737
|
}
|
|
33267
33738
|
throw new WriteRequestError(
|
|
33268
33739
|
"No secure random source available to build a proof nonce; provide a crypto global"
|
|
33269
33740
|
);
|
|
33270
33741
|
}
|
|
33271
33742
|
function proofKeyFor(parts) {
|
|
33272
|
-
return
|
|
33273
|
-
|
|
33743
|
+
return bytesToHex3(
|
|
33744
|
+
sha2566(
|
|
33274
33745
|
new TextEncoder().encode(
|
|
33275
33746
|
JSON.stringify([
|
|
33276
33747
|
parts.aud,
|
|
33277
33748
|
parts.method,
|
|
33278
33749
|
parts.uri,
|
|
33279
33750
|
parts.grantId,
|
|
33280
|
-
parts.signedBytes ?
|
|
33751
|
+
parts.signedBytes ? bytesToHex3(sha2566(parts.signedBytes)) : ""
|
|
33281
33752
|
])
|
|
33282
33753
|
)
|
|
33283
33754
|
)
|
|
@@ -33464,7 +33935,7 @@ function binaryWriteSignedBytes(input) {
|
|
|
33464
33935
|
mimeType: normalizeBinaryMimeType(input.contentType),
|
|
33465
33936
|
...input.filename ? { filename: input.filename } : {},
|
|
33466
33937
|
sizeBytes: input.bytes.length,
|
|
33467
|
-
contentHash:
|
|
33938
|
+
contentHash: bytesToHex4(sha2567(input.bytes)),
|
|
33468
33939
|
encoding: "base64",
|
|
33469
33940
|
content: toBase64(input.bytes),
|
|
33470
33941
|
...metadata !== void 0 ? { metadata } : {}
|
|
@@ -33512,7 +33983,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
33512
33983
|
for (const entry of lineage) {
|
|
33513
33984
|
let id;
|
|
33514
33985
|
if (isLineagePair(entry)) {
|
|
33515
|
-
if (!
|
|
33986
|
+
if (!isAddress7(entry.ownerAddress, { strict: false })) {
|
|
33516
33987
|
throw new WriteRequestError(
|
|
33517
33988
|
"lineage source ownerAddress must be an EVM address",
|
|
33518
33989
|
{ ownerAddress: entry.ownerAddress }
|
|
@@ -33777,6 +34248,13 @@ var QUESTION_STATUSES = [
|
|
|
33777
34248
|
"failed",
|
|
33778
34249
|
"stale"
|
|
33779
34250
|
];
|
|
34251
|
+
var DERIVATIVE_ERROR_CODES = [
|
|
34252
|
+
"inference_unavailable",
|
|
34253
|
+
"source_missing",
|
|
34254
|
+
"grant_invalid",
|
|
34255
|
+
"internal"
|
|
34256
|
+
];
|
|
34257
|
+
var DerivativeErrorCodeSchema = z5.enum(DERIVATIVE_ERROR_CODES);
|
|
33780
34258
|
var QuestionStatusSchema = z5.enum(QUESTION_STATUSES);
|
|
33781
34259
|
var QuestionRegisteredBySchema = z5.union([
|
|
33782
34260
|
z5.object({ kind: z5.literal("owner") }),
|
|
@@ -33798,6 +34276,14 @@ var DerivativeQuestionSchema = z5.object({
|
|
|
33798
34276
|
status: QuestionStatusSchema,
|
|
33799
34277
|
/** A short reason, set only while `status` is `failed`. */
|
|
33800
34278
|
error: nullableString,
|
|
34279
|
+
/**
|
|
34280
|
+
* The coarse failure class behind `error`, set only while `status` is
|
|
34281
|
+
* `failed`. `null` from a Personal Server that predates the class
|
|
34282
|
+
* (`personal-server-ts` before the status route).
|
|
34283
|
+
*/
|
|
34284
|
+
errorCode: DerivativeErrorCodeSchema.nullish().transform(
|
|
34285
|
+
(value) => value ?? null
|
|
34286
|
+
),
|
|
33801
34287
|
createdAt: z5.string(),
|
|
33802
34288
|
updatedAt: nullableString,
|
|
33803
34289
|
/** When the last compute finished, or `null` while `pending`. */
|
|
@@ -33930,6 +34416,7 @@ async function questionErrorFromResponse(response, body) {
|
|
|
33930
34416
|
);
|
|
33931
34417
|
}
|
|
33932
34418
|
}
|
|
34419
|
+
var personalServerErrorFromQuestionResponse = questionErrorFromResponse;
|
|
33933
34420
|
async function sendOnce(params, resolved, session, spec, bodyBytes) {
|
|
33934
34421
|
return sendWithFreshProof(
|
|
33935
34422
|
spec.label,
|
|
@@ -34209,6 +34696,166 @@ async function askPersonalServer(params) {
|
|
|
34209
34696
|
return { registration, record };
|
|
34210
34697
|
}
|
|
34211
34698
|
|
|
34699
|
+
// src/protocol/derivative-status.ts
|
|
34700
|
+
import { z as z6 } from "zod";
|
|
34701
|
+
var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
|
|
34702
|
+
var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
|
|
34703
|
+
var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
|
|
34704
|
+
var nullable = (schema) => schema.nullish().transform((value) => value ?? null);
|
|
34705
|
+
var DerivativeStatusSchema = z6.object({
|
|
34706
|
+
derivedScope: z6.string().min(1),
|
|
34707
|
+
status: QuestionStatusSchema,
|
|
34708
|
+
/** When the last compute finished, or `null` if none ever has. */
|
|
34709
|
+
lastComputedAt: nullable(z6.string()),
|
|
34710
|
+
/** Local version of the derived record the last compute wrote. */
|
|
34711
|
+
derivedVersion: nullable(z6.number()),
|
|
34712
|
+
derivedCollectedAt: nullable(z6.string()),
|
|
34713
|
+
/** The failure class; `null` unless `status` is `failed`. */
|
|
34714
|
+
errorCode: nullable(DerivativeErrorCodeSchema),
|
|
34715
|
+
/**
|
|
34716
|
+
* Seconds until the Personal Server's next automatic retry, or `null` when
|
|
34717
|
+
* none is pending or running — the terminal signature. Poll on this cadence
|
|
34718
|
+
* rather than guessing one.
|
|
34719
|
+
*/
|
|
34720
|
+
retryAfterSeconds: nullable(z6.number())
|
|
34721
|
+
});
|
|
34722
|
+
function derivativeStatusTarget(derivedScope) {
|
|
34723
|
+
return `${DERIVATIVE_STATUS_PATH}?derivedScope=${encodeURIComponent(derivedScope)}`;
|
|
34724
|
+
}
|
|
34725
|
+
function normalizeBaseUrl3(url) {
|
|
34726
|
+
return url.replace(/\/+$/, "");
|
|
34727
|
+
}
|
|
34728
|
+
function resolveFetch3(fetchFn) {
|
|
34729
|
+
const resolved = fetchFn ?? globalThis.fetch;
|
|
34730
|
+
if (resolved === void 0) {
|
|
34731
|
+
throw new WriteRequestError("No fetch implementation available");
|
|
34732
|
+
}
|
|
34733
|
+
return resolved;
|
|
34734
|
+
}
|
|
34735
|
+
function requireDerivedScope(derivedScope) {
|
|
34736
|
+
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
34737
|
+
throw new WriteRequestError("derivedScope is required");
|
|
34738
|
+
}
|
|
34739
|
+
return derivedScope;
|
|
34740
|
+
}
|
|
34741
|
+
function sleep3(ms, signal) {
|
|
34742
|
+
if (ms <= 0) return Promise.resolve();
|
|
34743
|
+
return new Promise((resolve, reject) => {
|
|
34744
|
+
const timer = setTimeout(() => {
|
|
34745
|
+
signal?.removeEventListener("abort", onAbort);
|
|
34746
|
+
resolve();
|
|
34747
|
+
}, ms);
|
|
34748
|
+
const onAbort = () => {
|
|
34749
|
+
clearTimeout(timer);
|
|
34750
|
+
reject(abortError2(signal));
|
|
34751
|
+
};
|
|
34752
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
34753
|
+
});
|
|
34754
|
+
}
|
|
34755
|
+
function timeoutError(latest, timeoutMs) {
|
|
34756
|
+
return new DerivativeQuestionTimeoutError(
|
|
34757
|
+
`Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
|
|
34758
|
+
{
|
|
34759
|
+
derivedScope: latest.derivedScope,
|
|
34760
|
+
status: latest.status,
|
|
34761
|
+
errorCode: latest.errorCode,
|
|
34762
|
+
retryAfterSeconds: latest.retryAfterSeconds,
|
|
34763
|
+
timeoutMs
|
|
34764
|
+
}
|
|
34765
|
+
);
|
|
34766
|
+
}
|
|
34767
|
+
function abortError2(signal) {
|
|
34768
|
+
const reason = signal?.reason;
|
|
34769
|
+
return reason instanceof Error ? reason : new WriteRequestError("Derivative status wait was aborted");
|
|
34770
|
+
}
|
|
34771
|
+
function isDerivativeStatusSettled(status) {
|
|
34772
|
+
if (status.status === "ready") return true;
|
|
34773
|
+
return status.status === "failed" && status.retryAfterSeconds === null;
|
|
34774
|
+
}
|
|
34775
|
+
async function getDerivativeStatus(params) {
|
|
34776
|
+
const derivedScope = requireDerivedScope(params.derivedScope);
|
|
34777
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
34778
|
+
const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
|
|
34779
|
+
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
34780
|
+
const headers = new Headers(params.headers);
|
|
34781
|
+
headers.set(
|
|
34782
|
+
"Authorization",
|
|
34783
|
+
await buildWeb3SignedHeader({
|
|
34784
|
+
signMessage: signer.signMessage,
|
|
34785
|
+
aud: params.audience ?? baseUrl,
|
|
34786
|
+
method: "GET",
|
|
34787
|
+
uri: DERIVATIVE_STATUS_PATH,
|
|
34788
|
+
grantId: params.grantId
|
|
34789
|
+
})
|
|
34790
|
+
);
|
|
34791
|
+
let response;
|
|
34792
|
+
try {
|
|
34793
|
+
response = await fetchFn(
|
|
34794
|
+
`${baseUrl}${derivativeStatusTarget(derivedScope)}`,
|
|
34795
|
+
{
|
|
34796
|
+
method: "GET",
|
|
34797
|
+
headers,
|
|
34798
|
+
...params.signal ? { signal: params.signal } : {}
|
|
34799
|
+
}
|
|
34800
|
+
);
|
|
34801
|
+
} catch (err) {
|
|
34802
|
+
throw new WriteTransportError(
|
|
34803
|
+
`Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
34804
|
+
1,
|
|
34805
|
+
err
|
|
34806
|
+
);
|
|
34807
|
+
}
|
|
34808
|
+
if (!response.ok) {
|
|
34809
|
+
throw await personalServerErrorFromQuestionResponse(
|
|
34810
|
+
response
|
|
34811
|
+
);
|
|
34812
|
+
}
|
|
34813
|
+
let body;
|
|
34814
|
+
try {
|
|
34815
|
+
body = await response.json();
|
|
34816
|
+
} catch (err) {
|
|
34817
|
+
throw new DerivativeQuestionRejectedError(
|
|
34818
|
+
"Derivative status response is not JSON",
|
|
34819
|
+
response.status,
|
|
34820
|
+
null,
|
|
34821
|
+
{ cause: err instanceof Error ? err.message : String(err) }
|
|
34822
|
+
);
|
|
34823
|
+
}
|
|
34824
|
+
const parsed = DerivativeStatusSchema.safeParse(body);
|
|
34825
|
+
if (!parsed.success) {
|
|
34826
|
+
throw new DerivativeQuestionRejectedError(
|
|
34827
|
+
"Derivative status response is not a status view",
|
|
34828
|
+
response.status,
|
|
34829
|
+
null,
|
|
34830
|
+
{ issues: parsed.error.issues }
|
|
34831
|
+
);
|
|
34832
|
+
}
|
|
34833
|
+
return parsed.data;
|
|
34834
|
+
}
|
|
34835
|
+
async function waitForDerivativeStatus(params) {
|
|
34836
|
+
const timeoutMs = Math.max(
|
|
34837
|
+
0,
|
|
34838
|
+
params.timeoutMs ?? DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS
|
|
34839
|
+
);
|
|
34840
|
+
const pollIntervalMs = Math.max(
|
|
34841
|
+
0,
|
|
34842
|
+
params.pollIntervalMs ?? DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS
|
|
34843
|
+
);
|
|
34844
|
+
const deadline = Date.now() + timeoutMs;
|
|
34845
|
+
for (; ; ) {
|
|
34846
|
+
if (params.signal?.aborted) throw abortError2(params.signal);
|
|
34847
|
+
const latest = await getDerivativeStatus(params);
|
|
34848
|
+
if (isDerivativeStatusSettled(latest)) return latest;
|
|
34849
|
+
const remaining = deadline - Date.now();
|
|
34850
|
+
if (remaining <= 0) throw timeoutError(latest, timeoutMs);
|
|
34851
|
+
const waitMs = latest.retryAfterSeconds === null ? pollIntervalMs : latest.retryAfterSeconds * 1e3;
|
|
34852
|
+
if (waitMs > remaining) {
|
|
34853
|
+
throw timeoutError(latest, timeoutMs);
|
|
34854
|
+
}
|
|
34855
|
+
await sleep3(waitMs, params.signal);
|
|
34856
|
+
}
|
|
34857
|
+
}
|
|
34858
|
+
|
|
34212
34859
|
// src/protocol/gateway.ts
|
|
34213
34860
|
function withGrantPermissions(grant) {
|
|
34214
34861
|
const stripped = { ...grant };
|
|
@@ -34816,14 +35463,22 @@ export {
|
|
|
34816
35463
|
BlockchainError,
|
|
34817
35464
|
BrowserECIESUint8Provider as BrowserECIESProvider,
|
|
34818
35465
|
BrowserPlatformAdapter,
|
|
35466
|
+
BuilderUnknownError,
|
|
35467
|
+
CLAIM_POLL_FLOOR_MS,
|
|
34819
35468
|
CONTRACTS,
|
|
34820
35469
|
CallbackStorage,
|
|
34821
35470
|
ContractFactory,
|
|
34822
35471
|
ContractNotFoundError,
|
|
34823
35472
|
DATA_REGISTRY_STATUS_ABI,
|
|
35473
|
+
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
35474
|
+
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
35475
|
+
DEFAULT_JOB_DEADLINE_SECONDS,
|
|
35476
|
+
DEFAULT_LEASE_SECONDS,
|
|
34824
35477
|
DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
34825
35478
|
DEFAULT_QUESTION_TIMEOUT_MS,
|
|
35479
|
+
DERIVATIVE_ERROR_CODES,
|
|
34826
35480
|
DERIVATIVE_QUESTIONS_PATH,
|
|
35481
|
+
DERIVATIVE_STATUS_PATH,
|
|
34827
35482
|
DataFileEnvelopeSchema,
|
|
34828
35483
|
DataPointDeletedError,
|
|
34829
35484
|
DataPointNotFoundError,
|
|
@@ -34832,6 +35487,7 @@ export {
|
|
|
34832
35487
|
DerivativeComputeUnavailableError,
|
|
34833
35488
|
DerivativeCycleError,
|
|
34834
35489
|
DerivativeDerivedScopeRequiredError,
|
|
35490
|
+
DerivativeErrorCodeSchema,
|
|
34835
35491
|
DerivativeQuestionFailedError,
|
|
34836
35492
|
DerivativeQuestionInvalidError,
|
|
34837
35493
|
DerivativeQuestionNotFoundError,
|
|
@@ -34839,8 +35495,12 @@ export {
|
|
|
34839
35495
|
DerivativeQuestionSchema,
|
|
34840
35496
|
DerivativeQuestionTimeoutError,
|
|
34841
35497
|
DerivativeSourceNotGrantedError,
|
|
35498
|
+
DerivativeStatusSchema,
|
|
34842
35499
|
DropboxStorage,
|
|
34843
35500
|
ECIESError,
|
|
35501
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
35502
|
+
ENCLAVE_TRUST_ANCHORS,
|
|
35503
|
+
ENCLAVE_WALLET_PURPOSE,
|
|
34844
35504
|
ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
|
|
34845
35505
|
ExpiredTokenError,
|
|
34846
35506
|
FEE_REGISTRY_ABI,
|
|
@@ -34848,12 +35508,24 @@ export {
|
|
|
34848
35508
|
GRANT_REGISTRATION_TYPES,
|
|
34849
35509
|
GRANT_REVOCATION_TYPES,
|
|
34850
35510
|
GoogleDriveStorage,
|
|
35511
|
+
GrantInvalidError,
|
|
34851
35512
|
InMemoryTokenStore,
|
|
34852
35513
|
IngestResponseSchema,
|
|
34853
35514
|
InvalidConfigurationError,
|
|
34854
35515
|
InvalidScopeEntryError,
|
|
34855
35516
|
InvalidSignatureError,
|
|
34856
35517
|
IpfsStorage,
|
|
35518
|
+
JOB_OPERATIONS,
|
|
35519
|
+
JOB_PROTOCOL_VERSION,
|
|
35520
|
+
JOB_STATES,
|
|
35521
|
+
JobEnvelopeError,
|
|
35522
|
+
JobIdTakenError,
|
|
35523
|
+
JobNotFoundError,
|
|
35524
|
+
JobRejectedError,
|
|
35525
|
+
JobRequestTooLargeError,
|
|
35526
|
+
JobTimeoutError,
|
|
35527
|
+
JobTransportError,
|
|
35528
|
+
JobsClientError,
|
|
34857
35529
|
LINEAGE_FIELD,
|
|
34858
35530
|
LINEAGE_KEY,
|
|
34859
35531
|
LineageEntrySchema,
|
|
@@ -34861,16 +35533,24 @@ export {
|
|
|
34861
35533
|
LineageNodeSchema,
|
|
34862
35534
|
LineageReadError,
|
|
34863
35535
|
MASTER_KEY_MESSAGE,
|
|
35536
|
+
MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS,
|
|
35537
|
+
MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
35538
|
+
MAX_ATTEMPTS,
|
|
35539
|
+
MAX_INLINE_RESULT_BYTES,
|
|
35540
|
+
MAX_JOB_DEADLINE_SECONDS,
|
|
35541
|
+
MAX_LEASE_SECONDS,
|
|
34864
35542
|
MAX_LINEAGE_SOURCES,
|
|
34865
35543
|
MAX_QUESTION_CHARS,
|
|
34866
35544
|
MAX_QUESTION_MODEL_CHARS,
|
|
34867
35545
|
MAX_QUESTION_SOURCE_SCOPES,
|
|
35546
|
+
MAX_WAIT_SECONDS,
|
|
34868
35547
|
MissingAuthError,
|
|
34869
35548
|
NATIVE_ASSET_ADDRESS,
|
|
34870
35549
|
NATIVE_VANA_ASSET,
|
|
34871
35550
|
NetworkError,
|
|
34872
35551
|
NonceError,
|
|
34873
35552
|
OAuthClient,
|
|
35553
|
+
OwnerNotReadyError,
|
|
34874
35554
|
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
34875
35555
|
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
34876
35556
|
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
@@ -34896,6 +35576,7 @@ export {
|
|
|
34896
35576
|
RedactedLineageNodeSchema,
|
|
34897
35577
|
RelayerError,
|
|
34898
35578
|
SCOPE_ACTIONS,
|
|
35579
|
+
SEALED_ENVELOPE_VERSION,
|
|
34899
35580
|
SERVER_REGISTRATION_TYPES,
|
|
34900
35581
|
ScopeSchema,
|
|
34901
35582
|
SerializationError,
|
|
@@ -34908,6 +35589,7 @@ export {
|
|
|
34908
35589
|
TOMBSTONE_METADATA_HASH,
|
|
34909
35590
|
TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
34910
35591
|
TransactionPendingError,
|
|
35592
|
+
USER_PS_ID_DOMAIN,
|
|
34911
35593
|
UserRejectedRequestError,
|
|
34912
35594
|
VanaError,
|
|
34913
35595
|
VanaStorage,
|
|
@@ -34926,6 +35608,7 @@ export {
|
|
|
34926
35608
|
WriteSessionExpiredError,
|
|
34927
35609
|
WriteTransportError,
|
|
34928
35610
|
WriteUnauthorizedError,
|
|
35611
|
+
appRootPreimage,
|
|
34929
35612
|
askPersonalServer,
|
|
34930
35613
|
assertDerivedScopeNaming,
|
|
34931
35614
|
assertValidPkceVerifier,
|
|
@@ -34935,6 +35618,7 @@ export {
|
|
|
34935
35618
|
buildDepositNativeRequest,
|
|
34936
35619
|
buildDepositTokenRequest,
|
|
34937
35620
|
buildMarkDataPointUnavailableRequest,
|
|
35621
|
+
buildMasterSignatureDelivery,
|
|
34938
35622
|
buildPersonalServerDataReadRequest,
|
|
34939
35623
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
34940
35624
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -34943,6 +35627,7 @@ export {
|
|
|
34943
35627
|
buildSetDataPointStatusRequest,
|
|
34944
35628
|
buildWeb3SignedHeader,
|
|
34945
35629
|
builderRegistrationDomain,
|
|
35630
|
+
canonicalJobRequestBytes,
|
|
34946
35631
|
chains,
|
|
34947
35632
|
clearContractCache,
|
|
34948
35633
|
computeBodyHash,
|
|
@@ -34963,6 +35648,7 @@ export {
|
|
|
34963
35648
|
decryptWithPassword,
|
|
34964
35649
|
deleteDataPoint,
|
|
34965
35650
|
deleteQuestion,
|
|
35651
|
+
derivativeStatusTarget,
|
|
34966
35652
|
deriveDataPointId,
|
|
34967
35653
|
deriveMasterKey,
|
|
34968
35654
|
deriveScopeKey,
|
|
@@ -34973,6 +35659,7 @@ export {
|
|
|
34973
35659
|
encodeDepositTokenData,
|
|
34974
35660
|
encodeSetDataPointStatusData,
|
|
34975
35661
|
encodeWriteMetadataHeader,
|
|
35662
|
+
encryptMasterSignatureDelivery,
|
|
34976
35663
|
encryptWithPassword,
|
|
34977
35664
|
escrowContractAddress,
|
|
34978
35665
|
escrowPaymentDomain,
|
|
@@ -34986,6 +35673,7 @@ export {
|
|
|
34986
35673
|
getContractAddress,
|
|
34987
35674
|
getContractController,
|
|
34988
35675
|
getContractInfo,
|
|
35676
|
+
getDerivativeStatus,
|
|
34989
35677
|
getFee,
|
|
34990
35678
|
getGatewayLineage,
|
|
34991
35679
|
getLineage,
|
|
@@ -35001,16 +35689,20 @@ export {
|
|
|
35001
35689
|
isDataPointId,
|
|
35002
35690
|
isDataPointTombstone,
|
|
35003
35691
|
isDataPortabilityGatewayConfig,
|
|
35692
|
+
isDerivativeStatusSettled,
|
|
35004
35693
|
isECIESEncrypted,
|
|
35005
35694
|
isPlatformSupported,
|
|
35006
35695
|
isRedactedLineageNode,
|
|
35007
35696
|
isTombstoneHashes,
|
|
35697
|
+
kmsIssuedPreimage,
|
|
35008
35698
|
listQuestions,
|
|
35009
35699
|
mainnetServices,
|
|
35010
35700
|
moksha,
|
|
35011
35701
|
mokshaServices,
|
|
35012
35702
|
mokshaTestnet2 as mokshaTestnet,
|
|
35013
35703
|
normalizeBinaryMimeType,
|
|
35704
|
+
openJobRequest,
|
|
35705
|
+
openJobResult,
|
|
35014
35706
|
openWriteSession,
|
|
35015
35707
|
parsePSError,
|
|
35016
35708
|
parseScope,
|
|
@@ -35031,6 +35723,8 @@ export {
|
|
|
35031
35723
|
scopeMatchesPattern,
|
|
35032
35724
|
scopeNamespace,
|
|
35033
35725
|
scopeToPathSegments,
|
|
35726
|
+
sealJobRequest,
|
|
35727
|
+
sealJobResult,
|
|
35034
35728
|
serializeECIES,
|
|
35035
35729
|
serverRegistrationDomain,
|
|
35036
35730
|
sessionCoversScope,
|
|
@@ -35039,10 +35733,13 @@ export {
|
|
|
35039
35733
|
signPersonalServerRegistrationWithAccount,
|
|
35040
35734
|
tombstoneDeletedAt,
|
|
35041
35735
|
tryGrantPermissions,
|
|
35736
|
+
userPsId,
|
|
35042
35737
|
vanaMainnet2 as vanaMainnet,
|
|
35738
|
+
verifyEnclaveIdentityEvidence,
|
|
35043
35739
|
verifyGrantRegistration,
|
|
35044
35740
|
verifyPkceChallenge,
|
|
35045
35741
|
verifyWeb3Signed,
|
|
35742
|
+
waitForDerivativeStatus,
|
|
35046
35743
|
waitForQuestion,
|
|
35047
35744
|
writeData,
|
|
35048
35745
|
writePersonalServerData
|