@opendatalabs/vana-sdk 3.21.0 → 3.22.0-pr.207.247f7c0
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/index.browser.d.ts +3 -1
- package/dist/index.browser.js +371 -4
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +414 -34
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +3 -1
- package/dist/index.node.js +374 -7
- 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/tests/mock-personal-server.d.ts +9 -0
- package/package.json +1 -1
package/dist/index.node.cjs
CHANGED
|
@@ -1186,9 +1186,13 @@ __export(index_node_exports, {
|
|
|
1186
1186
|
ContractNotFoundError: () => ContractNotFoundError,
|
|
1187
1187
|
DATA_ACCESS_OP_TYPE: () => DATA_ACCESS_OP_TYPE,
|
|
1188
1188
|
DATA_REGISTRY_STATUS_ABI: () => DATA_REGISTRY_STATUS_ABI,
|
|
1189
|
+
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS: () => DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
1190
|
+
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS: () => DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
1189
1191
|
DEFAULT_QUESTION_POLL_INTERVAL_MS: () => DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
1190
1192
|
DEFAULT_QUESTION_TIMEOUT_MS: () => DEFAULT_QUESTION_TIMEOUT_MS,
|
|
1193
|
+
DERIVATIVE_ERROR_CODES: () => DERIVATIVE_ERROR_CODES,
|
|
1191
1194
|
DERIVATIVE_QUESTIONS_PATH: () => DERIVATIVE_QUESTIONS_PATH,
|
|
1195
|
+
DERIVATIVE_STATUS_PATH: () => DERIVATIVE_STATUS_PATH,
|
|
1192
1196
|
DataFileEnvelopeSchema: () => DataFileEnvelopeSchema,
|
|
1193
1197
|
DataPointDeletedError: () => DataPointDeletedError,
|
|
1194
1198
|
DataPointNotFoundError: () => DataPointNotFoundError,
|
|
@@ -1197,6 +1201,7 @@ __export(index_node_exports, {
|
|
|
1197
1201
|
DerivativeComputeUnavailableError: () => DerivativeComputeUnavailableError,
|
|
1198
1202
|
DerivativeCycleError: () => DerivativeCycleError,
|
|
1199
1203
|
DerivativeDerivedScopeRequiredError: () => DerivativeDerivedScopeRequiredError,
|
|
1204
|
+
DerivativeErrorCodeSchema: () => DerivativeErrorCodeSchema,
|
|
1200
1205
|
DerivativeQuestionFailedError: () => DerivativeQuestionFailedError,
|
|
1201
1206
|
DerivativeQuestionInvalidError: () => DerivativeQuestionInvalidError,
|
|
1202
1207
|
DerivativeQuestionNotFoundError: () => DerivativeQuestionNotFoundError,
|
|
@@ -1204,8 +1209,12 @@ __export(index_node_exports, {
|
|
|
1204
1209
|
DerivativeQuestionSchema: () => DerivativeQuestionSchema,
|
|
1205
1210
|
DerivativeQuestionTimeoutError: () => DerivativeQuestionTimeoutError,
|
|
1206
1211
|
DerivativeSourceNotGrantedError: () => DerivativeSourceNotGrantedError,
|
|
1212
|
+
DerivativeStatusSchema: () => DerivativeStatusSchema,
|
|
1207
1213
|
DropboxStorage: () => DropboxStorage,
|
|
1208
1214
|
ECIESError: () => ECIESError,
|
|
1215
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION: () => ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
1216
|
+
ENCLAVE_TRUST_ANCHORS: () => ENCLAVE_TRUST_ANCHORS,
|
|
1217
|
+
ENCLAVE_WALLET_PURPOSE: () => ENCLAVE_WALLET_PURPOSE,
|
|
1209
1218
|
ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI2,
|
|
1210
1219
|
ExpiredTokenError: () => ExpiredTokenError,
|
|
1211
1220
|
FEE_REGISTRY_ABI: () => FEE_REGISTRY_ABI,
|
|
@@ -1227,6 +1236,8 @@ __export(index_node_exports, {
|
|
|
1227
1236
|
LineageNodeSchema: () => LineageNodeSchema,
|
|
1228
1237
|
LineageReadError: () => LineageReadError,
|
|
1229
1238
|
MASTER_KEY_MESSAGE: () => MASTER_KEY_MESSAGE,
|
|
1239
|
+
MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS: () => MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS,
|
|
1240
|
+
MASTER_SIGNATURE_DELIVERY_VERSION: () => MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
1230
1241
|
MAX_LINEAGE_SOURCES: () => MAX_LINEAGE_SOURCES,
|
|
1231
1242
|
MAX_QUESTION_CHARS: () => MAX_QUESTION_CHARS,
|
|
1232
1243
|
MAX_QUESTION_MODEL_CHARS: () => MAX_QUESTION_MODEL_CHARS,
|
|
@@ -1264,6 +1275,7 @@ __export(index_node_exports, {
|
|
|
1264
1275
|
RedactedLineageNodeSchema: () => RedactedLineageNodeSchema,
|
|
1265
1276
|
RelayerError: () => RelayerError,
|
|
1266
1277
|
SCOPE_ACTIONS: () => SCOPE_ACTIONS,
|
|
1278
|
+
SEALED_ENVELOPE_VERSION: () => SEALED_ENVELOPE_VERSION,
|
|
1267
1279
|
SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
|
|
1268
1280
|
ScopeSchema: () => ScopeSchema,
|
|
1269
1281
|
SerializationError: () => SerializationError,
|
|
@@ -1276,6 +1288,7 @@ __export(index_node_exports, {
|
|
|
1276
1288
|
TOMBSTONE_METADATA_HASH: () => TOMBSTONE_METADATA_HASH,
|
|
1277
1289
|
TOMBSTONE_METADATA_HASH_PREIMAGE: () => TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
1278
1290
|
TransactionPendingError: () => TransactionPendingError,
|
|
1291
|
+
USER_PS_ID_DOMAIN: () => USER_PS_ID_DOMAIN,
|
|
1279
1292
|
UserRejectedRequestError: () => UserRejectedRequestError,
|
|
1280
1293
|
VanaError: () => VanaError,
|
|
1281
1294
|
VanaStorage: () => VanaStorage,
|
|
@@ -1294,6 +1307,7 @@ __export(index_node_exports, {
|
|
|
1294
1307
|
WriteSessionExpiredError: () => WriteSessionExpiredError,
|
|
1295
1308
|
WriteTransportError: () => WriteTransportError,
|
|
1296
1309
|
WriteUnauthorizedError: () => WriteUnauthorizedError,
|
|
1310
|
+
appRootPreimage: () => appRootPreimage,
|
|
1297
1311
|
askPersonalServer: () => askPersonalServer,
|
|
1298
1312
|
assertDerivedScopeNaming: () => assertDerivedScopeNaming,
|
|
1299
1313
|
assertValidPkceVerifier: () => assertValidPkceVerifier,
|
|
@@ -1307,6 +1321,7 @@ __export(index_node_exports, {
|
|
|
1307
1321
|
buildEscrowPaymentHeader: () => buildEscrowPaymentHeader,
|
|
1308
1322
|
buildGrantPaymentHeader: () => buildGrantPaymentHeader,
|
|
1309
1323
|
buildMarkDataPointUnavailableRequest: () => buildMarkDataPointUnavailableRequest,
|
|
1324
|
+
buildMasterSignatureDelivery: () => buildMasterSignatureDelivery,
|
|
1310
1325
|
buildPersonalServerDataReadRequest: () => buildPersonalServerDataReadRequest,
|
|
1311
1326
|
buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
|
|
1312
1327
|
buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -1339,6 +1354,7 @@ __export(index_node_exports, {
|
|
|
1339
1354
|
decryptWithPassword: () => decryptWithPassword,
|
|
1340
1355
|
deleteDataPoint: () => deleteDataPoint,
|
|
1341
1356
|
deleteQuestion: () => deleteQuestion,
|
|
1357
|
+
derivativeStatusTarget: () => derivativeStatusTarget,
|
|
1342
1358
|
deriveDataPointId: () => deriveDataPointId,
|
|
1343
1359
|
deriveMasterKey: () => deriveMasterKey,
|
|
1344
1360
|
deriveScopeKey: () => deriveScopeKey,
|
|
@@ -1349,6 +1365,7 @@ __export(index_node_exports, {
|
|
|
1349
1365
|
encodeDepositTokenData: () => encodeDepositTokenData,
|
|
1350
1366
|
encodeSetDataPointStatusData: () => encodeSetDataPointStatusData,
|
|
1351
1367
|
encodeWriteMetadataHeader: () => encodeWriteMetadataHeader,
|
|
1368
|
+
encryptMasterSignatureDelivery: () => encryptMasterSignatureDelivery,
|
|
1352
1369
|
encryptWithPassword: () => encryptWithPassword,
|
|
1353
1370
|
escrowContractAddress: () => escrowContractAddress,
|
|
1354
1371
|
escrowPaymentDomain: () => escrowPaymentDomain,
|
|
@@ -1362,6 +1379,7 @@ __export(index_node_exports, {
|
|
|
1362
1379
|
getContractAddress: () => getContractAddress,
|
|
1363
1380
|
getContractController: () => getContractController,
|
|
1364
1381
|
getContractInfo: () => getContractInfo,
|
|
1382
|
+
getDerivativeStatus: () => getDerivativeStatus,
|
|
1365
1383
|
getFee: () => getFee,
|
|
1366
1384
|
getGatewayLineage: () => getGatewayLineage,
|
|
1367
1385
|
getLineage: () => getLineage,
|
|
@@ -1377,10 +1395,12 @@ __export(index_node_exports, {
|
|
|
1377
1395
|
isDataPointId: () => isDataPointId,
|
|
1378
1396
|
isDataPointTombstone: () => isDataPointTombstone,
|
|
1379
1397
|
isDataPortabilityGatewayConfig: () => isDataPortabilityGatewayConfig,
|
|
1398
|
+
isDerivativeStatusSettled: () => isDerivativeStatusSettled,
|
|
1380
1399
|
isECIESEncrypted: () => isECIESEncrypted,
|
|
1381
1400
|
isPlatformSupported: () => isPlatformSupported,
|
|
1382
1401
|
isRedactedLineageNode: () => isRedactedLineageNode,
|
|
1383
1402
|
isTombstoneHashes: () => isTombstoneHashes,
|
|
1403
|
+
kmsIssuedPreimage: () => kmsIssuedPreimage,
|
|
1384
1404
|
listQuestions: () => listQuestions,
|
|
1385
1405
|
mainnetServices: () => mainnetServices,
|
|
1386
1406
|
moksha: () => moksha,
|
|
@@ -1420,10 +1440,13 @@ __export(index_node_exports, {
|
|
|
1420
1440
|
toDirectPaymentReceipt: () => toDirectPaymentReceipt,
|
|
1421
1441
|
tombstoneDeletedAt: () => tombstoneDeletedAt,
|
|
1422
1442
|
tryGrantPermissions: () => tryGrantPermissions,
|
|
1443
|
+
userPsId: () => userPsId,
|
|
1423
1444
|
vanaMainnet: () => vanaMainnet2,
|
|
1445
|
+
verifyEnclaveIdentityEvidence: () => verifyEnclaveIdentityEvidence,
|
|
1424
1446
|
verifyGrantRegistration: () => verifyGrantRegistration,
|
|
1425
1447
|
verifyPkceChallenge: () => verifyPkceChallenge,
|
|
1426
1448
|
verifyWeb3Signed: () => verifyWeb3Signed,
|
|
1449
|
+
waitForDerivativeStatus: () => waitForDerivativeStatus,
|
|
1427
1450
|
waitForQuestion: () => waitForQuestion,
|
|
1428
1451
|
writeData: () => writeData,
|
|
1429
1452
|
writePersonalServerData: () => writePersonalServerData
|
|
@@ -31618,13 +31641,13 @@ var NodeCryptoAdapter = class {
|
|
|
31618
31641
|
*/
|
|
31619
31642
|
async generateKeyPair() {
|
|
31620
31643
|
try {
|
|
31621
|
-
const
|
|
31644
|
+
const secp256k15 = import_secp256k12.default;
|
|
31622
31645
|
let privateKey;
|
|
31623
31646
|
do {
|
|
31624
31647
|
privateKey = (0, import_crypto2.randomBytes)(32);
|
|
31625
|
-
} while (!
|
|
31648
|
+
} while (!secp256k15.privateKeyVerify(privateKey));
|
|
31626
31649
|
const publicKey = Buffer.from(
|
|
31627
|
-
|
|
31650
|
+
secp256k15.publicKeyCreate(privateKey, true)
|
|
31628
31651
|
);
|
|
31629
31652
|
return {
|
|
31630
31653
|
privateKey: privateKey.toString("hex"),
|
|
@@ -32634,15 +32657,173 @@ var RECORD_DATA_ACCESS_TYPES = {
|
|
|
32634
32657
|
]
|
|
32635
32658
|
};
|
|
32636
32659
|
|
|
32637
|
-
// src/protocol/
|
|
32660
|
+
// src/protocol/identity.ts
|
|
32661
|
+
var secp256k14 = __toESM(require("@noble/secp256k1"), 1);
|
|
32638
32662
|
var import_viem14 = require("viem");
|
|
32663
|
+
var import_accounts = require("viem/accounts");
|
|
32664
|
+
init_interface();
|
|
32665
|
+
var ENCLAVE_IDENTITY_EVIDENCE_VERSION = 1;
|
|
32666
|
+
var USER_PS_ID_DOMAIN = "vana.ps-enclave.v1";
|
|
32667
|
+
var ENCLAVE_WALLET_PURPOSE = "vana.ps-enclave.wallet.v1";
|
|
32668
|
+
var MASTER_SIGNATURE_DELIVERY_VERSION = "vana.ps-enclave.delivery.v1";
|
|
32669
|
+
var MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS = 600;
|
|
32670
|
+
var SEALED_ENVELOPE_VERSION = 1;
|
|
32671
|
+
var VANA_MAINNET_CHAIN_ID = 1480;
|
|
32672
|
+
var MOKSHA_CHAIN_ID = 14800;
|
|
32673
|
+
var KMS_ISSUED_PREFIX = "dstack-kms-issued";
|
|
32674
|
+
var PREIMAGE_SEPARATOR = ":";
|
|
32675
|
+
var UNCOMPRESSED_PUBLIC_KEY_BYTES = 65;
|
|
32676
|
+
var UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04";
|
|
32677
|
+
var EMPTY_HEX = "0x";
|
|
32678
|
+
function emptyAnchor() {
|
|
32679
|
+
return Object.freeze({
|
|
32680
|
+
kmsRootPubkey: EMPTY_HEX,
|
|
32681
|
+
appIds: Object.freeze([])
|
|
32682
|
+
});
|
|
32683
|
+
}
|
|
32684
|
+
var ENCLAVE_TRUST_ANCHORS = Object.freeze({
|
|
32685
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32686
|
+
[VANA_MAINNET_CHAIN_ID]: emptyAnchor(),
|
|
32687
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32688
|
+
[MOKSHA_CHAIN_ID]: emptyAnchor()
|
|
32689
|
+
});
|
|
32690
|
+
function userPsId(chainId, ownerAddress) {
|
|
32691
|
+
const packed = (0, import_viem14.encodePacked)(
|
|
32692
|
+
["string", "uint256", "address"],
|
|
32693
|
+
[USER_PS_ID_DOMAIN, BigInt(chainId), (0, import_viem14.getAddress)(ownerAddress)]
|
|
32694
|
+
);
|
|
32695
|
+
return (0, import_viem14.keccak256)(packed);
|
|
32696
|
+
}
|
|
32697
|
+
function compressPublicKey(publicKey) {
|
|
32698
|
+
return secp256k14.ProjectivePoint.fromHex(
|
|
32699
|
+
(0, import_viem14.fromHex)(publicKey, "bytes")
|
|
32700
|
+
).toRawBytes(true);
|
|
32701
|
+
}
|
|
32702
|
+
function sameKey(a, b) {
|
|
32703
|
+
return (0, import_viem14.toHex)(compressPublicKey(a)) === (0, import_viem14.toHex)(compressPublicKey(b));
|
|
32704
|
+
}
|
|
32705
|
+
function assertUncompressedKey(publicKey) {
|
|
32706
|
+
const hex = publicKey.slice(2);
|
|
32707
|
+
if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
32708
|
+
throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
|
|
32709
|
+
}
|
|
32710
|
+
}
|
|
32711
|
+
function appRootPreimage(purpose, publicKey) {
|
|
32712
|
+
const keyHex = (0, import_viem14.toHex)(compressPublicKey(publicKey)).slice(2);
|
|
32713
|
+
return (0, import_viem14.keccak256)((0, import_viem14.toBytes)(`${purpose}${PREIMAGE_SEPARATOR}${keyHex}`));
|
|
32714
|
+
}
|
|
32715
|
+
function kmsIssuedPreimage(appId, appRootPublicKey) {
|
|
32716
|
+
const prefix = (0, import_viem14.concat)([
|
|
32717
|
+
(0, import_viem14.toBytes)(`${KMS_ISSUED_PREFIX}${PREIMAGE_SEPARATOR}`),
|
|
32718
|
+
(0, import_viem14.fromHex)(appId, "bytes")
|
|
32719
|
+
]);
|
|
32720
|
+
const compressed = compressPublicKey(appRootPublicKey);
|
|
32721
|
+
return (0, import_viem14.keccak256)((0, import_viem14.concat)([prefix, compressed]));
|
|
32722
|
+
}
|
|
32723
|
+
async function recoverChainKey(hash, signature, link) {
|
|
32724
|
+
try {
|
|
32725
|
+
return (await (0, import_viem14.recoverPublicKey)({ hash, signature })).toLowerCase();
|
|
32726
|
+
} catch {
|
|
32727
|
+
throw new Error(`Invalid enclave signature chain link ${link}`);
|
|
32728
|
+
}
|
|
32729
|
+
}
|
|
32730
|
+
async function verifyEnclaveIdentityEvidence(evidence, anchors, expected) {
|
|
32731
|
+
if (evidence.v !== ENCLAVE_IDENTITY_EVIDENCE_VERSION) {
|
|
32732
|
+
throw new Error("Unsupported enclave identity evidence version");
|
|
32733
|
+
}
|
|
32734
|
+
if (!Number.isInteger(evidence.epoch) || evidence.epoch < 1) {
|
|
32735
|
+
throw new Error("Invalid enclave identity epoch");
|
|
32736
|
+
}
|
|
32737
|
+
if (evidence.chainId !== expected.chainId) {
|
|
32738
|
+
throw new Error(
|
|
32739
|
+
"Enclave identity chain ID does not match expected chain ID"
|
|
32740
|
+
);
|
|
32741
|
+
}
|
|
32742
|
+
if (!(0, import_viem14.isAddressEqual)(evidence.ownerAddress, expected.ownerAddress)) {
|
|
32743
|
+
throw new Error("Enclave identity owner does not match expected owner");
|
|
32744
|
+
}
|
|
32745
|
+
if (evidence.epoch !== expected.epoch) {
|
|
32746
|
+
throw new Error("Enclave identity epoch does not match expected epoch");
|
|
32747
|
+
}
|
|
32748
|
+
const expectedUserPsId = userPsId(expected.chainId, expected.ownerAddress);
|
|
32749
|
+
if (evidence.userPsId.toLowerCase() !== expectedUserPsId.toLowerCase()) {
|
|
32750
|
+
throw new Error("Enclave userPsId does not match expected identity");
|
|
32751
|
+
}
|
|
32752
|
+
if (evidence.purpose !== ENCLAVE_WALLET_PURPOSE) {
|
|
32753
|
+
throw new Error("Unexpected enclave wallet purpose");
|
|
32754
|
+
}
|
|
32755
|
+
if (anchors.kmsRootPubkey === EMPTY_HEX) {
|
|
32756
|
+
throw new Error("KMS root trust anchor is not provisioned");
|
|
32757
|
+
}
|
|
32758
|
+
assertUncompressedKey(evidence.publicKey);
|
|
32759
|
+
const derivedAddress = (0, import_accounts.publicKeyToAddress)(evidence.publicKey);
|
|
32760
|
+
if ((0, import_viem14.getAddress)(derivedAddress) !== (0, import_viem14.getAddress)(evidence.address)) {
|
|
32761
|
+
throw new Error("Enclave public key does not match its address");
|
|
32762
|
+
}
|
|
32763
|
+
const appRootPublicKey = await recoverChainKey(
|
|
32764
|
+
appRootPreimage(evidence.purpose, evidence.publicKey),
|
|
32765
|
+
evidence.signatureChain[0],
|
|
32766
|
+
0
|
|
32767
|
+
);
|
|
32768
|
+
const kmsRootPublicKey = await recoverChainKey(
|
|
32769
|
+
kmsIssuedPreimage(evidence.appId, appRootPublicKey),
|
|
32770
|
+
evidence.signatureChain[1],
|
|
32771
|
+
1
|
|
32772
|
+
);
|
|
32773
|
+
let matchesAnchor;
|
|
32774
|
+
try {
|
|
32775
|
+
matchesAnchor = sameKey(kmsRootPublicKey, anchors.kmsRootPubkey);
|
|
32776
|
+
} catch {
|
|
32777
|
+
throw new Error("KMS root trust anchor is malformed");
|
|
32778
|
+
}
|
|
32779
|
+
if (!matchesAnchor) {
|
|
32780
|
+
throw new Error("KMS root public key does not match the trust anchor");
|
|
32781
|
+
}
|
|
32782
|
+
if ((0, import_viem14.keccak256)(kmsRootPublicKey) !== evidence.kmsRootFingerprint.toLowerCase()) {
|
|
32783
|
+
throw new Error("KMS root fingerprint does not match the evidence");
|
|
32784
|
+
}
|
|
32785
|
+
const appId = evidence.appId.toLowerCase();
|
|
32786
|
+
if (!anchors.appIds.some((allowedAppId) => allowedAppId.toLowerCase() === appId)) {
|
|
32787
|
+
throw new Error("Enclave app ID is not trusted");
|
|
32788
|
+
}
|
|
32789
|
+
}
|
|
32790
|
+
async function buildMasterSignatureDelivery(evidence, masterSignature, now = Math.floor(Date.now() / 1e3)) {
|
|
32791
|
+
deriveMasterKey(masterSignature);
|
|
32792
|
+
const signerAddress = await recoverServerOwner(masterSignature);
|
|
32793
|
+
if (!(0, import_viem14.isAddressEqual)(signerAddress, evidence.ownerAddress)) {
|
|
32794
|
+
throw new Error("Master signature signer does not match evidence owner");
|
|
32795
|
+
}
|
|
32796
|
+
return {
|
|
32797
|
+
v: MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
32798
|
+
userPsId: evidence.userPsId,
|
|
32799
|
+
epoch: evidence.epoch,
|
|
32800
|
+
enclaveAddress: evidence.address,
|
|
32801
|
+
ownerAddress: evidence.ownerAddress,
|
|
32802
|
+
masterSignature,
|
|
32803
|
+
issuedAt: now
|
|
32804
|
+
};
|
|
32805
|
+
}
|
|
32806
|
+
async function encryptMasterSignatureDelivery(delivery, publicKey, ecies) {
|
|
32807
|
+
assertUncompressedKey(publicKey);
|
|
32808
|
+
if (!(0, import_viem14.isAddressEqual)((0, import_accounts.publicKeyToAddress)(publicKey), delivery.enclaveAddress)) {
|
|
32809
|
+
throw new Error(
|
|
32810
|
+
"Public key does not belong to the delivery's enclave address"
|
|
32811
|
+
);
|
|
32812
|
+
}
|
|
32813
|
+
const plaintext = (0, import_viem14.toBytes)(JSON.stringify(delivery));
|
|
32814
|
+
const encrypted = await ecies.encrypt((0, import_viem14.fromHex)(publicKey, "bytes"), plaintext);
|
|
32815
|
+
return `0x${serializeECIES(encrypted)}`;
|
|
32816
|
+
}
|
|
32817
|
+
|
|
32818
|
+
// src/protocol/personal-server-registration.ts
|
|
32819
|
+
var import_viem15 = require("viem");
|
|
32639
32820
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
32640
32821
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
32641
32822
|
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32642
32823
|
"DataPortabilityServers"
|
|
32643
32824
|
);
|
|
32644
32825
|
function assertAddress(value, name) {
|
|
32645
|
-
if (!(0,
|
|
32826
|
+
if (!(0, import_viem15.isAddress)(value)) {
|
|
32646
32827
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32647
32828
|
}
|
|
32648
32829
|
}
|
|
@@ -32728,12 +32909,12 @@ async function buildPersonalServerRegistrationSignature(input) {
|
|
|
32728
32909
|
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32729
32910
|
|
|
32730
32911
|
// src/personal-server-lite/owner-binding.ts
|
|
32731
|
-
var
|
|
32912
|
+
var import_viem16 = require("viem");
|
|
32732
32913
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
32733
32914
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32734
32915
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32735
32916
|
function assertAddress2(value, name) {
|
|
32736
|
-
if (!(0,
|
|
32917
|
+
if (!(0, import_viem16.isAddress)(value)) {
|
|
32737
32918
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32738
32919
|
}
|
|
32739
32920
|
}
|
|
@@ -32783,7 +32964,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
|
32783
32964
|
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32784
32965
|
|
|
32785
32966
|
// src/account/personal-server-registration.ts
|
|
32786
|
-
var
|
|
32967
|
+
var import_viem17 = require("viem");
|
|
32787
32968
|
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32788
32969
|
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32789
32970
|
status;
|
|
@@ -32802,7 +32983,7 @@ function trimTrailingSlash(value) {
|
|
|
32802
32983
|
return value.replace(/\/+$/, "");
|
|
32803
32984
|
}
|
|
32804
32985
|
function assertAddress3(value, name) {
|
|
32805
|
-
if (!(0,
|
|
32986
|
+
if (!(0, import_viem17.isAddress)(value)) {
|
|
32806
32987
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32807
32988
|
}
|
|
32808
32989
|
}
|
|
@@ -33066,7 +33247,7 @@ function accountOwnerBindingError(error) {
|
|
|
33066
33247
|
}
|
|
33067
33248
|
|
|
33068
33249
|
// src/protocol/grants.ts
|
|
33069
|
-
var
|
|
33250
|
+
var import_viem18 = require("viem");
|
|
33070
33251
|
function isHexString(value) {
|
|
33071
33252
|
return typeof value === "string" && value.startsWith("0x");
|
|
33072
33253
|
}
|
|
@@ -33111,7 +33292,7 @@ async function verifyGrantRegistration(input) {
|
|
|
33111
33292
|
}
|
|
33112
33293
|
let valid;
|
|
33113
33294
|
try {
|
|
33114
|
-
valid = await (0,
|
|
33295
|
+
valid = await (0, import_viem18.verifyTypedData)({
|
|
33115
33296
|
address: input.grantorAddress,
|
|
33116
33297
|
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
33117
33298
|
types: GRANT_REGISTRATION_TYPES,
|
|
@@ -33146,8 +33327,8 @@ async function verifyGrantRegistration(input) {
|
|
|
33146
33327
|
}
|
|
33147
33328
|
|
|
33148
33329
|
// src/protocol/fee-registry.ts
|
|
33149
|
-
var
|
|
33150
|
-
var FEE_REGISTRY_ABI = (0,
|
|
33330
|
+
var import_viem19 = require("viem");
|
|
33331
|
+
var FEE_REGISTRY_ABI = (0, import_viem19.parseAbi)([
|
|
33151
33332
|
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33152
33333
|
"function fees(bytes32 operation) view returns (Fee)",
|
|
33153
33334
|
"function operationKey(string name) pure returns (bytes32)"
|
|
@@ -33230,7 +33411,7 @@ async function getOpFee(client, config, opType, opts) {
|
|
|
33230
33411
|
}
|
|
33231
33412
|
|
|
33232
33413
|
// src/protocol/escrow-deposit.ts
|
|
33233
|
-
var
|
|
33414
|
+
var import_viem20 = require("viem");
|
|
33234
33415
|
var ESCROW_DEPOSIT_ABI = [
|
|
33235
33416
|
{
|
|
33236
33417
|
type: "function",
|
|
@@ -33255,14 +33436,14 @@ function escrowContractAddress(config) {
|
|
|
33255
33436
|
return config.contracts.dataPortabilityEscrow;
|
|
33256
33437
|
}
|
|
33257
33438
|
function encodeDepositNativeData(input) {
|
|
33258
|
-
return (0,
|
|
33439
|
+
return (0, import_viem20.encodeFunctionData)({
|
|
33259
33440
|
abi: ESCROW_DEPOSIT_ABI,
|
|
33260
33441
|
functionName: "depositNative",
|
|
33261
33442
|
args: [input.account]
|
|
33262
33443
|
});
|
|
33263
33444
|
}
|
|
33264
33445
|
function encodeDepositTokenData(input) {
|
|
33265
|
-
return (0,
|
|
33446
|
+
return (0, import_viem20.encodeFunctionData)({
|
|
33266
33447
|
abi: ESCROW_DEPOSIT_ABI,
|
|
33267
33448
|
functionName: "depositToken",
|
|
33268
33449
|
args: [input.account, input.token, input.amount]
|
|
@@ -33283,7 +33464,7 @@ function buildDepositTokenRequest(config, input) {
|
|
|
33283
33464
|
}
|
|
33284
33465
|
|
|
33285
33466
|
// src/protocol/data-point-status.ts
|
|
33286
|
-
var
|
|
33467
|
+
var import_viem21 = require("viem");
|
|
33287
33468
|
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
33288
33469
|
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
33289
33470
|
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
@@ -33307,7 +33488,7 @@ function dataRegistryContractAddress(config) {
|
|
|
33307
33488
|
return config.contracts.dataRegistry;
|
|
33308
33489
|
}
|
|
33309
33490
|
function encodeSetDataPointStatusData(input) {
|
|
33310
|
-
return (0,
|
|
33491
|
+
return (0, import_viem21.encodeFunctionData)({
|
|
33311
33492
|
abi: DATA_REGISTRY_STATUS_ABI,
|
|
33312
33493
|
functionName: "setStatus",
|
|
33313
33494
|
args: [input.scope, input.status]
|
|
@@ -33327,10 +33508,10 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
33327
33508
|
}
|
|
33328
33509
|
|
|
33329
33510
|
// src/protocol/data-point-deletion.ts
|
|
33330
|
-
var
|
|
33511
|
+
var import_viem23 = require("viem");
|
|
33331
33512
|
|
|
33332
33513
|
// src/protocol/lineage.ts
|
|
33333
|
-
var
|
|
33514
|
+
var import_viem22 = require("viem");
|
|
33334
33515
|
var import_zod = require("zod");
|
|
33335
33516
|
|
|
33336
33517
|
// src/protocol/personal-server-error-body.ts
|
|
@@ -33408,13 +33589,13 @@ function isDataPointId(value) {
|
|
|
33408
33589
|
return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
|
|
33409
33590
|
}
|
|
33410
33591
|
function deriveDataPointId(ownerAddress, scope) {
|
|
33411
|
-
if (!(0,
|
|
33592
|
+
if (!(0, import_viem22.isAddress)(ownerAddress, { strict: false })) {
|
|
33412
33593
|
throw new Error(
|
|
33413
33594
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
33414
33595
|
);
|
|
33415
33596
|
}
|
|
33416
|
-
return (0,
|
|
33417
|
-
(0,
|
|
33597
|
+
return (0, import_viem22.keccak256)(
|
|
33598
|
+
(0, import_viem22.encodeAbiParameters)(
|
|
33418
33599
|
[
|
|
33419
33600
|
{ name: "ownerAddress", type: "address" },
|
|
33420
33601
|
{ name: "scope", type: "string" }
|
|
@@ -33640,7 +33821,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
33640
33821
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
33641
33822
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
33642
33823
|
function computeTombstoneHash(preimage) {
|
|
33643
|
-
return (0,
|
|
33824
|
+
return (0, import_viem23.keccak256)((0, import_viem23.stringToBytes)(preimage));
|
|
33644
33825
|
}
|
|
33645
33826
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
33646
33827
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -33659,12 +33840,12 @@ function tombstoneDeletedAt(value) {
|
|
|
33659
33840
|
return typeof deletedAt === "string" ? deletedAt : null;
|
|
33660
33841
|
}
|
|
33661
33842
|
function assertAddress4(value, name) {
|
|
33662
|
-
if (!(0,
|
|
33843
|
+
if (!(0, import_viem23.isAddress)(value)) {
|
|
33663
33844
|
throw new Error(`${name} must be a valid EVM address`);
|
|
33664
33845
|
}
|
|
33665
33846
|
}
|
|
33666
33847
|
function assertUint256(value, name) {
|
|
33667
|
-
if (value < 0n || value >
|
|
33848
|
+
if (value < 0n || value > import_viem23.maxUint256) {
|
|
33668
33849
|
throw new Error(`${name} must fit in uint256, got ${value}`);
|
|
33669
33850
|
}
|
|
33670
33851
|
}
|
|
@@ -33767,7 +33948,7 @@ async function deleteDataPoint(input) {
|
|
|
33767
33948
|
}
|
|
33768
33949
|
currentVersion = parseExpectedVersion(record.expectedVersion);
|
|
33769
33950
|
}
|
|
33770
|
-
if (currentVersion < 0n || currentVersion >=
|
|
33951
|
+
if (currentVersion < 0n || currentVersion >= import_viem23.maxUint256) {
|
|
33771
33952
|
throw new Error(
|
|
33772
33953
|
`currentVersion ${currentVersion} cannot be incremented to a uint256 tombstone version`
|
|
33773
33954
|
);
|
|
@@ -34075,12 +34256,12 @@ function tryGrantPermissions(scopes) {
|
|
|
34075
34256
|
|
|
34076
34257
|
// src/protocol/personal-server-write.ts
|
|
34077
34258
|
var import_sha26 = require("@noble/hashes/sha2");
|
|
34078
|
-
var
|
|
34259
|
+
var import_viem25 = require("viem");
|
|
34079
34260
|
var import_zod4 = require("zod");
|
|
34080
34261
|
|
|
34081
34262
|
// src/protocol/write-request.ts
|
|
34082
34263
|
var import_sha25 = require("@noble/hashes/sha2");
|
|
34083
|
-
var
|
|
34264
|
+
var import_viem24 = require("viem");
|
|
34084
34265
|
function normalizeBaseUrl2(url) {
|
|
34085
34266
|
return url.replace(/\/+$/, "");
|
|
34086
34267
|
}
|
|
@@ -34147,14 +34328,14 @@ function freshProofNonce() {
|
|
|
34147
34328
|
return webCrypto.randomUUID();
|
|
34148
34329
|
}
|
|
34149
34330
|
if (typeof webCrypto?.getRandomValues === "function") {
|
|
34150
|
-
return (0,
|
|
34331
|
+
return (0, import_viem24.bytesToHex)(webCrypto.getRandomValues(new Uint8Array(16)));
|
|
34151
34332
|
}
|
|
34152
34333
|
throw new WriteRequestError(
|
|
34153
34334
|
"No secure random source available to build a proof nonce; provide a crypto global"
|
|
34154
34335
|
);
|
|
34155
34336
|
}
|
|
34156
34337
|
function proofKeyFor(parts) {
|
|
34157
|
-
return (0,
|
|
34338
|
+
return (0, import_viem24.bytesToHex)(
|
|
34158
34339
|
(0, import_sha25.sha256)(
|
|
34159
34340
|
new TextEncoder().encode(
|
|
34160
34341
|
JSON.stringify([
|
|
@@ -34162,7 +34343,7 @@ function proofKeyFor(parts) {
|
|
|
34162
34343
|
parts.method,
|
|
34163
34344
|
parts.uri,
|
|
34164
34345
|
parts.grantId,
|
|
34165
|
-
parts.signedBytes ? (0,
|
|
34346
|
+
parts.signedBytes ? (0, import_viem24.bytesToHex)((0, import_sha25.sha256)(parts.signedBytes)) : ""
|
|
34166
34347
|
])
|
|
34167
34348
|
)
|
|
34168
34349
|
)
|
|
@@ -34349,7 +34530,7 @@ function binaryWriteSignedBytes(input) {
|
|
|
34349
34530
|
mimeType: normalizeBinaryMimeType(input.contentType),
|
|
34350
34531
|
...input.filename ? { filename: input.filename } : {},
|
|
34351
34532
|
sizeBytes: input.bytes.length,
|
|
34352
|
-
contentHash: (0,
|
|
34533
|
+
contentHash: (0, import_viem25.bytesToHex)((0, import_sha26.sha256)(input.bytes)),
|
|
34353
34534
|
encoding: "base64",
|
|
34354
34535
|
content: toBase64(input.bytes),
|
|
34355
34536
|
...metadata !== void 0 ? { metadata } : {}
|
|
@@ -34397,7 +34578,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
34397
34578
|
for (const entry of lineage) {
|
|
34398
34579
|
let id;
|
|
34399
34580
|
if (isLineagePair(entry)) {
|
|
34400
|
-
if (!(0,
|
|
34581
|
+
if (!(0, import_viem25.isAddress)(entry.ownerAddress, { strict: false })) {
|
|
34401
34582
|
throw new WriteRequestError(
|
|
34402
34583
|
"lineage source ownerAddress must be an EVM address",
|
|
34403
34584
|
{ ownerAddress: entry.ownerAddress }
|
|
@@ -34662,6 +34843,13 @@ var QUESTION_STATUSES = [
|
|
|
34662
34843
|
"failed",
|
|
34663
34844
|
"stale"
|
|
34664
34845
|
];
|
|
34846
|
+
var DERIVATIVE_ERROR_CODES = [
|
|
34847
|
+
"inference_unavailable",
|
|
34848
|
+
"source_missing",
|
|
34849
|
+
"grant_invalid",
|
|
34850
|
+
"internal"
|
|
34851
|
+
];
|
|
34852
|
+
var DerivativeErrorCodeSchema = import_zod5.z.enum(DERIVATIVE_ERROR_CODES);
|
|
34665
34853
|
var QuestionStatusSchema = import_zod5.z.enum(QUESTION_STATUSES);
|
|
34666
34854
|
var QuestionRegisteredBySchema = import_zod5.z.union([
|
|
34667
34855
|
import_zod5.z.object({ kind: import_zod5.z.literal("owner") }),
|
|
@@ -34683,6 +34871,14 @@ var DerivativeQuestionSchema = import_zod5.z.object({
|
|
|
34683
34871
|
status: QuestionStatusSchema,
|
|
34684
34872
|
/** A short reason, set only while `status` is `failed`. */
|
|
34685
34873
|
error: nullableString,
|
|
34874
|
+
/**
|
|
34875
|
+
* The coarse failure class behind `error`, set only while `status` is
|
|
34876
|
+
* `failed`. `null` from a Personal Server that predates the class
|
|
34877
|
+
* (`personal-server-ts` before the status route).
|
|
34878
|
+
*/
|
|
34879
|
+
errorCode: DerivativeErrorCodeSchema.nullish().transform(
|
|
34880
|
+
(value) => value ?? null
|
|
34881
|
+
),
|
|
34686
34882
|
createdAt: import_zod5.z.string(),
|
|
34687
34883
|
updatedAt: nullableString,
|
|
34688
34884
|
/** When the last compute finished, or `null` while `pending`. */
|
|
@@ -34815,6 +35011,7 @@ async function questionErrorFromResponse(response, body) {
|
|
|
34815
35011
|
);
|
|
34816
35012
|
}
|
|
34817
35013
|
}
|
|
35014
|
+
var personalServerErrorFromQuestionResponse = questionErrorFromResponse;
|
|
34818
35015
|
async function sendOnce(params, resolved, session, spec, bodyBytes) {
|
|
34819
35016
|
return sendWithFreshProof(
|
|
34820
35017
|
spec.label,
|
|
@@ -35094,6 +35291,166 @@ async function askPersonalServer(params) {
|
|
|
35094
35291
|
return { registration, record };
|
|
35095
35292
|
}
|
|
35096
35293
|
|
|
35294
|
+
// src/protocol/derivative-status.ts
|
|
35295
|
+
var import_zod6 = require("zod");
|
|
35296
|
+
var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
|
|
35297
|
+
var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
|
|
35298
|
+
var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
|
|
35299
|
+
var nullable = (schema) => schema.nullish().transform((value) => value ?? null);
|
|
35300
|
+
var DerivativeStatusSchema = import_zod6.z.object({
|
|
35301
|
+
derivedScope: import_zod6.z.string().min(1),
|
|
35302
|
+
status: QuestionStatusSchema,
|
|
35303
|
+
/** When the last compute finished, or `null` if none ever has. */
|
|
35304
|
+
lastComputedAt: nullable(import_zod6.z.string()),
|
|
35305
|
+
/** Local version of the derived record the last compute wrote. */
|
|
35306
|
+
derivedVersion: nullable(import_zod6.z.number()),
|
|
35307
|
+
derivedCollectedAt: nullable(import_zod6.z.string()),
|
|
35308
|
+
/** The failure class; `null` unless `status` is `failed`. */
|
|
35309
|
+
errorCode: nullable(DerivativeErrorCodeSchema),
|
|
35310
|
+
/**
|
|
35311
|
+
* Seconds until the Personal Server's next automatic retry, or `null` when
|
|
35312
|
+
* none is pending or running — the terminal signature. Poll on this cadence
|
|
35313
|
+
* rather than guessing one.
|
|
35314
|
+
*/
|
|
35315
|
+
retryAfterSeconds: nullable(import_zod6.z.number())
|
|
35316
|
+
});
|
|
35317
|
+
function derivativeStatusTarget(derivedScope) {
|
|
35318
|
+
return `${DERIVATIVE_STATUS_PATH}?derivedScope=${encodeURIComponent(derivedScope)}`;
|
|
35319
|
+
}
|
|
35320
|
+
function normalizeBaseUrl3(url) {
|
|
35321
|
+
return url.replace(/\/+$/, "");
|
|
35322
|
+
}
|
|
35323
|
+
function resolveFetch3(fetchFn) {
|
|
35324
|
+
const resolved = fetchFn ?? globalThis.fetch;
|
|
35325
|
+
if (resolved === void 0) {
|
|
35326
|
+
throw new WriteRequestError("No fetch implementation available");
|
|
35327
|
+
}
|
|
35328
|
+
return resolved;
|
|
35329
|
+
}
|
|
35330
|
+
function requireDerivedScope(derivedScope) {
|
|
35331
|
+
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
35332
|
+
throw new WriteRequestError("derivedScope is required");
|
|
35333
|
+
}
|
|
35334
|
+
return derivedScope;
|
|
35335
|
+
}
|
|
35336
|
+
function sleep3(ms, signal) {
|
|
35337
|
+
if (ms <= 0) return Promise.resolve();
|
|
35338
|
+
return new Promise((resolve, reject) => {
|
|
35339
|
+
const timer = setTimeout(() => {
|
|
35340
|
+
signal?.removeEventListener("abort", onAbort);
|
|
35341
|
+
resolve();
|
|
35342
|
+
}, ms);
|
|
35343
|
+
const onAbort = () => {
|
|
35344
|
+
clearTimeout(timer);
|
|
35345
|
+
reject(abortError2(signal));
|
|
35346
|
+
};
|
|
35347
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
35348
|
+
});
|
|
35349
|
+
}
|
|
35350
|
+
function timeoutError(latest, timeoutMs) {
|
|
35351
|
+
return new DerivativeQuestionTimeoutError(
|
|
35352
|
+
`Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
|
|
35353
|
+
{
|
|
35354
|
+
derivedScope: latest.derivedScope,
|
|
35355
|
+
status: latest.status,
|
|
35356
|
+
errorCode: latest.errorCode,
|
|
35357
|
+
retryAfterSeconds: latest.retryAfterSeconds,
|
|
35358
|
+
timeoutMs
|
|
35359
|
+
}
|
|
35360
|
+
);
|
|
35361
|
+
}
|
|
35362
|
+
function abortError2(signal) {
|
|
35363
|
+
const reason = signal?.reason;
|
|
35364
|
+
return reason instanceof Error ? reason : new WriteRequestError("Derivative status wait was aborted");
|
|
35365
|
+
}
|
|
35366
|
+
function isDerivativeStatusSettled(status) {
|
|
35367
|
+
if (status.status === "ready") return true;
|
|
35368
|
+
return status.status === "failed" && status.retryAfterSeconds === null;
|
|
35369
|
+
}
|
|
35370
|
+
async function getDerivativeStatus(params) {
|
|
35371
|
+
const derivedScope = requireDerivedScope(params.derivedScope);
|
|
35372
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
35373
|
+
const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
|
|
35374
|
+
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
35375
|
+
const headers = new Headers(params.headers);
|
|
35376
|
+
headers.set(
|
|
35377
|
+
"Authorization",
|
|
35378
|
+
await buildWeb3SignedHeader({
|
|
35379
|
+
signMessage: signer.signMessage,
|
|
35380
|
+
aud: params.audience ?? baseUrl,
|
|
35381
|
+
method: "GET",
|
|
35382
|
+
uri: DERIVATIVE_STATUS_PATH,
|
|
35383
|
+
grantId: params.grantId
|
|
35384
|
+
})
|
|
35385
|
+
);
|
|
35386
|
+
let response;
|
|
35387
|
+
try {
|
|
35388
|
+
response = await fetchFn(
|
|
35389
|
+
`${baseUrl}${derivativeStatusTarget(derivedScope)}`,
|
|
35390
|
+
{
|
|
35391
|
+
method: "GET",
|
|
35392
|
+
headers,
|
|
35393
|
+
...params.signal ? { signal: params.signal } : {}
|
|
35394
|
+
}
|
|
35395
|
+
);
|
|
35396
|
+
} catch (err) {
|
|
35397
|
+
throw new WriteTransportError(
|
|
35398
|
+
`Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
35399
|
+
1,
|
|
35400
|
+
err
|
|
35401
|
+
);
|
|
35402
|
+
}
|
|
35403
|
+
if (!response.ok) {
|
|
35404
|
+
throw await personalServerErrorFromQuestionResponse(
|
|
35405
|
+
response
|
|
35406
|
+
);
|
|
35407
|
+
}
|
|
35408
|
+
let body;
|
|
35409
|
+
try {
|
|
35410
|
+
body = await response.json();
|
|
35411
|
+
} catch (err) {
|
|
35412
|
+
throw new DerivativeQuestionRejectedError(
|
|
35413
|
+
"Derivative status response is not JSON",
|
|
35414
|
+
response.status,
|
|
35415
|
+
null,
|
|
35416
|
+
{ cause: err instanceof Error ? err.message : String(err) }
|
|
35417
|
+
);
|
|
35418
|
+
}
|
|
35419
|
+
const parsed = DerivativeStatusSchema.safeParse(body);
|
|
35420
|
+
if (!parsed.success) {
|
|
35421
|
+
throw new DerivativeQuestionRejectedError(
|
|
35422
|
+
"Derivative status response is not a status view",
|
|
35423
|
+
response.status,
|
|
35424
|
+
null,
|
|
35425
|
+
{ issues: parsed.error.issues }
|
|
35426
|
+
);
|
|
35427
|
+
}
|
|
35428
|
+
return parsed.data;
|
|
35429
|
+
}
|
|
35430
|
+
async function waitForDerivativeStatus(params) {
|
|
35431
|
+
const timeoutMs = Math.max(
|
|
35432
|
+
0,
|
|
35433
|
+
params.timeoutMs ?? DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS
|
|
35434
|
+
);
|
|
35435
|
+
const pollIntervalMs = Math.max(
|
|
35436
|
+
0,
|
|
35437
|
+
params.pollIntervalMs ?? DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS
|
|
35438
|
+
);
|
|
35439
|
+
const deadline = Date.now() + timeoutMs;
|
|
35440
|
+
for (; ; ) {
|
|
35441
|
+
if (params.signal?.aborted) throw abortError2(params.signal);
|
|
35442
|
+
const latest = await getDerivativeStatus(params);
|
|
35443
|
+
if (isDerivativeStatusSettled(latest)) return latest;
|
|
35444
|
+
const remaining = deadline - Date.now();
|
|
35445
|
+
if (remaining <= 0) throw timeoutError(latest, timeoutMs);
|
|
35446
|
+
const waitMs = latest.retryAfterSeconds === null ? pollIntervalMs : latest.retryAfterSeconds * 1e3;
|
|
35447
|
+
if (waitMs > remaining) {
|
|
35448
|
+
throw timeoutError(latest, timeoutMs);
|
|
35449
|
+
}
|
|
35450
|
+
await sleep3(waitMs, params.signal);
|
|
35451
|
+
}
|
|
35452
|
+
}
|
|
35453
|
+
|
|
35097
35454
|
// src/protocol/gateway.ts
|
|
35098
35455
|
function withGrantPermissions(grant) {
|
|
35099
35456
|
const stripped = { ...grant };
|
|
@@ -36175,9 +36532,13 @@ async function parsePSError(response) {
|
|
|
36175
36532
|
ContractNotFoundError,
|
|
36176
36533
|
DATA_ACCESS_OP_TYPE,
|
|
36177
36534
|
DATA_REGISTRY_STATUS_ABI,
|
|
36535
|
+
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
36536
|
+
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
36178
36537
|
DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
36179
36538
|
DEFAULT_QUESTION_TIMEOUT_MS,
|
|
36539
|
+
DERIVATIVE_ERROR_CODES,
|
|
36180
36540
|
DERIVATIVE_QUESTIONS_PATH,
|
|
36541
|
+
DERIVATIVE_STATUS_PATH,
|
|
36181
36542
|
DataFileEnvelopeSchema,
|
|
36182
36543
|
DataPointDeletedError,
|
|
36183
36544
|
DataPointNotFoundError,
|
|
@@ -36186,6 +36547,7 @@ async function parsePSError(response) {
|
|
|
36186
36547
|
DerivativeComputeUnavailableError,
|
|
36187
36548
|
DerivativeCycleError,
|
|
36188
36549
|
DerivativeDerivedScopeRequiredError,
|
|
36550
|
+
DerivativeErrorCodeSchema,
|
|
36189
36551
|
DerivativeQuestionFailedError,
|
|
36190
36552
|
DerivativeQuestionInvalidError,
|
|
36191
36553
|
DerivativeQuestionNotFoundError,
|
|
@@ -36193,8 +36555,12 @@ async function parsePSError(response) {
|
|
|
36193
36555
|
DerivativeQuestionSchema,
|
|
36194
36556
|
DerivativeQuestionTimeoutError,
|
|
36195
36557
|
DerivativeSourceNotGrantedError,
|
|
36558
|
+
DerivativeStatusSchema,
|
|
36196
36559
|
DropboxStorage,
|
|
36197
36560
|
ECIESError,
|
|
36561
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
36562
|
+
ENCLAVE_TRUST_ANCHORS,
|
|
36563
|
+
ENCLAVE_WALLET_PURPOSE,
|
|
36198
36564
|
ESCROW_DEPOSIT_ABI,
|
|
36199
36565
|
ExpiredTokenError,
|
|
36200
36566
|
FEE_REGISTRY_ABI,
|
|
@@ -36216,6 +36582,8 @@ async function parsePSError(response) {
|
|
|
36216
36582
|
LineageNodeSchema,
|
|
36217
36583
|
LineageReadError,
|
|
36218
36584
|
MASTER_KEY_MESSAGE,
|
|
36585
|
+
MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS,
|
|
36586
|
+
MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
36219
36587
|
MAX_LINEAGE_SOURCES,
|
|
36220
36588
|
MAX_QUESTION_CHARS,
|
|
36221
36589
|
MAX_QUESTION_MODEL_CHARS,
|
|
@@ -36253,6 +36621,7 @@ async function parsePSError(response) {
|
|
|
36253
36621
|
RedactedLineageNodeSchema,
|
|
36254
36622
|
RelayerError,
|
|
36255
36623
|
SCOPE_ACTIONS,
|
|
36624
|
+
SEALED_ENVELOPE_VERSION,
|
|
36256
36625
|
SERVER_REGISTRATION_TYPES,
|
|
36257
36626
|
ScopeSchema,
|
|
36258
36627
|
SerializationError,
|
|
@@ -36265,6 +36634,7 @@ async function parsePSError(response) {
|
|
|
36265
36634
|
TOMBSTONE_METADATA_HASH,
|
|
36266
36635
|
TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
36267
36636
|
TransactionPendingError,
|
|
36637
|
+
USER_PS_ID_DOMAIN,
|
|
36268
36638
|
UserRejectedRequestError,
|
|
36269
36639
|
VanaError,
|
|
36270
36640
|
VanaStorage,
|
|
@@ -36283,6 +36653,7 @@ async function parsePSError(response) {
|
|
|
36283
36653
|
WriteSessionExpiredError,
|
|
36284
36654
|
WriteTransportError,
|
|
36285
36655
|
WriteUnauthorizedError,
|
|
36656
|
+
appRootPreimage,
|
|
36286
36657
|
askPersonalServer,
|
|
36287
36658
|
assertDerivedScopeNaming,
|
|
36288
36659
|
assertValidPkceVerifier,
|
|
@@ -36296,6 +36667,7 @@ async function parsePSError(response) {
|
|
|
36296
36667
|
buildEscrowPaymentHeader,
|
|
36297
36668
|
buildGrantPaymentHeader,
|
|
36298
36669
|
buildMarkDataPointUnavailableRequest,
|
|
36670
|
+
buildMasterSignatureDelivery,
|
|
36299
36671
|
buildPersonalServerDataReadRequest,
|
|
36300
36672
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
36301
36673
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -36328,6 +36700,7 @@ async function parsePSError(response) {
|
|
|
36328
36700
|
decryptWithPassword,
|
|
36329
36701
|
deleteDataPoint,
|
|
36330
36702
|
deleteQuestion,
|
|
36703
|
+
derivativeStatusTarget,
|
|
36331
36704
|
deriveDataPointId,
|
|
36332
36705
|
deriveMasterKey,
|
|
36333
36706
|
deriveScopeKey,
|
|
@@ -36338,6 +36711,7 @@ async function parsePSError(response) {
|
|
|
36338
36711
|
encodeDepositTokenData,
|
|
36339
36712
|
encodeSetDataPointStatusData,
|
|
36340
36713
|
encodeWriteMetadataHeader,
|
|
36714
|
+
encryptMasterSignatureDelivery,
|
|
36341
36715
|
encryptWithPassword,
|
|
36342
36716
|
escrowContractAddress,
|
|
36343
36717
|
escrowPaymentDomain,
|
|
@@ -36351,6 +36725,7 @@ async function parsePSError(response) {
|
|
|
36351
36725
|
getContractAddress,
|
|
36352
36726
|
getContractController,
|
|
36353
36727
|
getContractInfo,
|
|
36728
|
+
getDerivativeStatus,
|
|
36354
36729
|
getFee,
|
|
36355
36730
|
getGatewayLineage,
|
|
36356
36731
|
getLineage,
|
|
@@ -36366,10 +36741,12 @@ async function parsePSError(response) {
|
|
|
36366
36741
|
isDataPointId,
|
|
36367
36742
|
isDataPointTombstone,
|
|
36368
36743
|
isDataPortabilityGatewayConfig,
|
|
36744
|
+
isDerivativeStatusSettled,
|
|
36369
36745
|
isECIESEncrypted,
|
|
36370
36746
|
isPlatformSupported,
|
|
36371
36747
|
isRedactedLineageNode,
|
|
36372
36748
|
isTombstoneHashes,
|
|
36749
|
+
kmsIssuedPreimage,
|
|
36373
36750
|
listQuestions,
|
|
36374
36751
|
mainnetServices,
|
|
36375
36752
|
moksha,
|
|
@@ -36409,10 +36786,13 @@ async function parsePSError(response) {
|
|
|
36409
36786
|
toDirectPaymentReceipt,
|
|
36410
36787
|
tombstoneDeletedAt,
|
|
36411
36788
|
tryGrantPermissions,
|
|
36789
|
+
userPsId,
|
|
36412
36790
|
vanaMainnet,
|
|
36791
|
+
verifyEnclaveIdentityEvidence,
|
|
36413
36792
|
verifyGrantRegistration,
|
|
36414
36793
|
verifyPkceChallenge,
|
|
36415
36794
|
verifyWeb3Signed,
|
|
36795
|
+
waitForDerivativeStatus,
|
|
36416
36796
|
waitForQuestion,
|
|
36417
36797
|
writeData,
|
|
36418
36798
|
writePersonalServerData
|