@opendatalabs/vana-sdk 3.20.1 → 3.22.0-pr.207.0dbb052
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/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/index.browser.d.ts +3 -1
- package/dist/index.browser.js +347 -4
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +389 -34
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +3 -1
- package/dist/index.node.js +350 -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 +194 -0
- package/dist/protocol/identity.cjs.map +1 -0
- package/dist/protocol/identity.d.ts +161 -0
- package/dist/protocol/identity.js +159 -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/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 +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,7 @@ __export(index_node_exports, {
|
|
|
1227
1236
|
LineageNodeSchema: () => LineageNodeSchema,
|
|
1228
1237
|
LineageReadError: () => LineageReadError,
|
|
1229
1238
|
MASTER_KEY_MESSAGE: () => MASTER_KEY_MESSAGE,
|
|
1239
|
+
MASTER_SIGNATURE_DELIVERY_VERSION: () => MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
1230
1240
|
MAX_LINEAGE_SOURCES: () => MAX_LINEAGE_SOURCES,
|
|
1231
1241
|
MAX_QUESTION_CHARS: () => MAX_QUESTION_CHARS,
|
|
1232
1242
|
MAX_QUESTION_MODEL_CHARS: () => MAX_QUESTION_MODEL_CHARS,
|
|
@@ -1264,6 +1274,7 @@ __export(index_node_exports, {
|
|
|
1264
1274
|
RedactedLineageNodeSchema: () => RedactedLineageNodeSchema,
|
|
1265
1275
|
RelayerError: () => RelayerError,
|
|
1266
1276
|
SCOPE_ACTIONS: () => SCOPE_ACTIONS,
|
|
1277
|
+
SEALED_ENVELOPE_VERSION: () => SEALED_ENVELOPE_VERSION,
|
|
1267
1278
|
SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
|
|
1268
1279
|
ScopeSchema: () => ScopeSchema,
|
|
1269
1280
|
SerializationError: () => SerializationError,
|
|
@@ -1276,6 +1287,7 @@ __export(index_node_exports, {
|
|
|
1276
1287
|
TOMBSTONE_METADATA_HASH: () => TOMBSTONE_METADATA_HASH,
|
|
1277
1288
|
TOMBSTONE_METADATA_HASH_PREIMAGE: () => TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
1278
1289
|
TransactionPendingError: () => TransactionPendingError,
|
|
1290
|
+
USER_PS_ID_DOMAIN: () => USER_PS_ID_DOMAIN,
|
|
1279
1291
|
UserRejectedRequestError: () => UserRejectedRequestError,
|
|
1280
1292
|
VanaError: () => VanaError,
|
|
1281
1293
|
VanaStorage: () => VanaStorage,
|
|
@@ -1294,6 +1306,7 @@ __export(index_node_exports, {
|
|
|
1294
1306
|
WriteSessionExpiredError: () => WriteSessionExpiredError,
|
|
1295
1307
|
WriteTransportError: () => WriteTransportError,
|
|
1296
1308
|
WriteUnauthorizedError: () => WriteUnauthorizedError,
|
|
1309
|
+
appRootPreimage: () => appRootPreimage,
|
|
1297
1310
|
askPersonalServer: () => askPersonalServer,
|
|
1298
1311
|
assertDerivedScopeNaming: () => assertDerivedScopeNaming,
|
|
1299
1312
|
assertValidPkceVerifier: () => assertValidPkceVerifier,
|
|
@@ -1307,6 +1320,7 @@ __export(index_node_exports, {
|
|
|
1307
1320
|
buildEscrowPaymentHeader: () => buildEscrowPaymentHeader,
|
|
1308
1321
|
buildGrantPaymentHeader: () => buildGrantPaymentHeader,
|
|
1309
1322
|
buildMarkDataPointUnavailableRequest: () => buildMarkDataPointUnavailableRequest,
|
|
1323
|
+
buildMasterSignatureDelivery: () => buildMasterSignatureDelivery,
|
|
1310
1324
|
buildPersonalServerDataReadRequest: () => buildPersonalServerDataReadRequest,
|
|
1311
1325
|
buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
|
|
1312
1326
|
buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -1339,6 +1353,7 @@ __export(index_node_exports, {
|
|
|
1339
1353
|
decryptWithPassword: () => decryptWithPassword,
|
|
1340
1354
|
deleteDataPoint: () => deleteDataPoint,
|
|
1341
1355
|
deleteQuestion: () => deleteQuestion,
|
|
1356
|
+
derivativeStatusTarget: () => derivativeStatusTarget,
|
|
1342
1357
|
deriveDataPointId: () => deriveDataPointId,
|
|
1343
1358
|
deriveMasterKey: () => deriveMasterKey,
|
|
1344
1359
|
deriveScopeKey: () => deriveScopeKey,
|
|
@@ -1349,6 +1364,7 @@ __export(index_node_exports, {
|
|
|
1349
1364
|
encodeDepositTokenData: () => encodeDepositTokenData,
|
|
1350
1365
|
encodeSetDataPointStatusData: () => encodeSetDataPointStatusData,
|
|
1351
1366
|
encodeWriteMetadataHeader: () => encodeWriteMetadataHeader,
|
|
1367
|
+
encryptMasterSignatureDelivery: () => encryptMasterSignatureDelivery,
|
|
1352
1368
|
encryptWithPassword: () => encryptWithPassword,
|
|
1353
1369
|
escrowContractAddress: () => escrowContractAddress,
|
|
1354
1370
|
escrowPaymentDomain: () => escrowPaymentDomain,
|
|
@@ -1362,6 +1378,7 @@ __export(index_node_exports, {
|
|
|
1362
1378
|
getContractAddress: () => getContractAddress,
|
|
1363
1379
|
getContractController: () => getContractController,
|
|
1364
1380
|
getContractInfo: () => getContractInfo,
|
|
1381
|
+
getDerivativeStatus: () => getDerivativeStatus,
|
|
1365
1382
|
getFee: () => getFee,
|
|
1366
1383
|
getGatewayLineage: () => getGatewayLineage,
|
|
1367
1384
|
getLineage: () => getLineage,
|
|
@@ -1377,10 +1394,12 @@ __export(index_node_exports, {
|
|
|
1377
1394
|
isDataPointId: () => isDataPointId,
|
|
1378
1395
|
isDataPointTombstone: () => isDataPointTombstone,
|
|
1379
1396
|
isDataPortabilityGatewayConfig: () => isDataPortabilityGatewayConfig,
|
|
1397
|
+
isDerivativeStatusSettled: () => isDerivativeStatusSettled,
|
|
1380
1398
|
isECIESEncrypted: () => isECIESEncrypted,
|
|
1381
1399
|
isPlatformSupported: () => isPlatformSupported,
|
|
1382
1400
|
isRedactedLineageNode: () => isRedactedLineageNode,
|
|
1383
1401
|
isTombstoneHashes: () => isTombstoneHashes,
|
|
1402
|
+
kmsIssuedPreimage: () => kmsIssuedPreimage,
|
|
1384
1403
|
listQuestions: () => listQuestions,
|
|
1385
1404
|
mainnetServices: () => mainnetServices,
|
|
1386
1405
|
moksha: () => moksha,
|
|
@@ -1420,10 +1439,13 @@ __export(index_node_exports, {
|
|
|
1420
1439
|
toDirectPaymentReceipt: () => toDirectPaymentReceipt,
|
|
1421
1440
|
tombstoneDeletedAt: () => tombstoneDeletedAt,
|
|
1422
1441
|
tryGrantPermissions: () => tryGrantPermissions,
|
|
1442
|
+
userPsId: () => userPsId,
|
|
1423
1443
|
vanaMainnet: () => vanaMainnet2,
|
|
1444
|
+
verifyEnclaveIdentityEvidence: () => verifyEnclaveIdentityEvidence,
|
|
1424
1445
|
verifyGrantRegistration: () => verifyGrantRegistration,
|
|
1425
1446
|
verifyPkceChallenge: () => verifyPkceChallenge,
|
|
1426
1447
|
verifyWeb3Signed: () => verifyWeb3Signed,
|
|
1448
|
+
waitForDerivativeStatus: () => waitForDerivativeStatus,
|
|
1427
1449
|
waitForQuestion: () => waitForQuestion,
|
|
1428
1450
|
writeData: () => writeData,
|
|
1429
1451
|
writePersonalServerData: () => writePersonalServerData
|
|
@@ -31618,13 +31640,13 @@ var NodeCryptoAdapter = class {
|
|
|
31618
31640
|
*/
|
|
31619
31641
|
async generateKeyPair() {
|
|
31620
31642
|
try {
|
|
31621
|
-
const
|
|
31643
|
+
const secp256k15 = import_secp256k12.default;
|
|
31622
31644
|
let privateKey;
|
|
31623
31645
|
do {
|
|
31624
31646
|
privateKey = (0, import_crypto2.randomBytes)(32);
|
|
31625
|
-
} while (!
|
|
31647
|
+
} while (!secp256k15.privateKeyVerify(privateKey));
|
|
31626
31648
|
const publicKey = Buffer.from(
|
|
31627
|
-
|
|
31649
|
+
secp256k15.publicKeyCreate(privateKey, true)
|
|
31628
31650
|
);
|
|
31629
31651
|
return {
|
|
31630
31652
|
privateKey: privateKey.toString("hex"),
|
|
@@ -32634,15 +32656,150 @@ var RECORD_DATA_ACCESS_TYPES = {
|
|
|
32634
32656
|
]
|
|
32635
32657
|
};
|
|
32636
32658
|
|
|
32637
|
-
// src/protocol/
|
|
32659
|
+
// src/protocol/identity.ts
|
|
32660
|
+
var secp256k14 = __toESM(require("@noble/secp256k1"), 1);
|
|
32638
32661
|
var import_viem14 = require("viem");
|
|
32662
|
+
var import_accounts = require("viem/accounts");
|
|
32663
|
+
init_interface();
|
|
32664
|
+
var ENCLAVE_IDENTITY_EVIDENCE_VERSION = 1;
|
|
32665
|
+
var USER_PS_ID_DOMAIN = "vana.ps-enclave.v1";
|
|
32666
|
+
var ENCLAVE_WALLET_PURPOSE = "vana.ps-enclave.wallet.v1";
|
|
32667
|
+
var MASTER_SIGNATURE_DELIVERY_VERSION = "vana.ps-enclave.delivery.v1";
|
|
32668
|
+
var SEALED_ENVELOPE_VERSION = 1;
|
|
32669
|
+
var VANA_MAINNET_CHAIN_ID = 1480;
|
|
32670
|
+
var MOKSHA_CHAIN_ID = 14800;
|
|
32671
|
+
var KMS_ISSUED_PREFIX = "dstack-kms-issued";
|
|
32672
|
+
var PREIMAGE_SEPARATOR = ":";
|
|
32673
|
+
var UNCOMPRESSED_PUBLIC_KEY_BYTES = 65;
|
|
32674
|
+
var UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04";
|
|
32675
|
+
var ENCLAVE_TRUST_ANCHORS = {
|
|
32676
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32677
|
+
[VANA_MAINNET_CHAIN_ID]: { kmsRootPubkey: "0x", appIds: [] },
|
|
32678
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32679
|
+
[MOKSHA_CHAIN_ID]: { kmsRootPubkey: "0x", appIds: [] }
|
|
32680
|
+
};
|
|
32681
|
+
function userPsId(chainId, ownerAddress) {
|
|
32682
|
+
const packed = (0, import_viem14.encodePacked)(
|
|
32683
|
+
["string", "uint256", "address"],
|
|
32684
|
+
[USER_PS_ID_DOMAIN, BigInt(chainId), (0, import_viem14.getAddress)(ownerAddress)]
|
|
32685
|
+
);
|
|
32686
|
+
return (0, import_viem14.keccak256)(packed);
|
|
32687
|
+
}
|
|
32688
|
+
function compressPublicKey(publicKey) {
|
|
32689
|
+
return secp256k14.ProjectivePoint.fromHex(
|
|
32690
|
+
(0, import_viem14.fromHex)(publicKey, "bytes")
|
|
32691
|
+
).toRawBytes(true);
|
|
32692
|
+
}
|
|
32693
|
+
function appRootPreimage(purpose, publicKey) {
|
|
32694
|
+
const keyHex = (0, import_viem14.toHex)(compressPublicKey(publicKey)).slice(2);
|
|
32695
|
+
return (0, import_viem14.keccak256)((0, import_viem14.toBytes)(`${purpose}${PREIMAGE_SEPARATOR}${keyHex}`));
|
|
32696
|
+
}
|
|
32697
|
+
function kmsIssuedPreimage(appId, appRootPublicKey) {
|
|
32698
|
+
const prefix = (0, import_viem14.concat)([
|
|
32699
|
+
(0, import_viem14.toBytes)(`${KMS_ISSUED_PREFIX}${PREIMAGE_SEPARATOR}`),
|
|
32700
|
+
(0, import_viem14.fromHex)(appId, "bytes")
|
|
32701
|
+
]);
|
|
32702
|
+
const compressed = compressPublicKey(appRootPublicKey);
|
|
32703
|
+
return (0, import_viem14.keccak256)((0, import_viem14.concat)([prefix, compressed]));
|
|
32704
|
+
}
|
|
32705
|
+
async function recoverChainKey(hash, signature, link) {
|
|
32706
|
+
try {
|
|
32707
|
+
return (await (0, import_viem14.recoverPublicKey)({ hash, signature })).toLowerCase();
|
|
32708
|
+
} catch {
|
|
32709
|
+
throw new Error(`Invalid enclave signature chain link ${link}`);
|
|
32710
|
+
}
|
|
32711
|
+
}
|
|
32712
|
+
async function verifyEnclaveIdentityEvidence(evidence, anchors, expected) {
|
|
32713
|
+
if (evidence.v !== ENCLAVE_IDENTITY_EVIDENCE_VERSION) {
|
|
32714
|
+
throw new Error("Unsupported enclave identity evidence version");
|
|
32715
|
+
}
|
|
32716
|
+
if (!Number.isInteger(evidence.epoch) || evidence.epoch < 1) {
|
|
32717
|
+
throw new Error("Invalid enclave identity epoch");
|
|
32718
|
+
}
|
|
32719
|
+
if (evidence.chainId !== expected.chainId) {
|
|
32720
|
+
throw new Error(
|
|
32721
|
+
"Enclave identity chain ID does not match expected chain ID"
|
|
32722
|
+
);
|
|
32723
|
+
}
|
|
32724
|
+
if (!(0, import_viem14.isAddressEqual)(evidence.ownerAddress, expected.ownerAddress)) {
|
|
32725
|
+
throw new Error("Enclave identity owner does not match expected owner");
|
|
32726
|
+
}
|
|
32727
|
+
if (evidence.epoch !== expected.epoch) {
|
|
32728
|
+
throw new Error("Enclave identity epoch does not match expected epoch");
|
|
32729
|
+
}
|
|
32730
|
+
const expectedUserPsId = userPsId(expected.chainId, expected.ownerAddress);
|
|
32731
|
+
if (evidence.userPsId.toLowerCase() !== expectedUserPsId.toLowerCase()) {
|
|
32732
|
+
throw new Error("Enclave userPsId does not match expected identity");
|
|
32733
|
+
}
|
|
32734
|
+
if (evidence.purpose !== ENCLAVE_WALLET_PURPOSE) {
|
|
32735
|
+
throw new Error("Unexpected enclave wallet purpose");
|
|
32736
|
+
}
|
|
32737
|
+
const derivedAddress = (0, import_accounts.publicKeyToAddress)(evidence.publicKey);
|
|
32738
|
+
if ((0, import_viem14.getAddress)(derivedAddress) !== (0, import_viem14.getAddress)(evidence.address)) {
|
|
32739
|
+
throw new Error("Enclave public key does not match its address");
|
|
32740
|
+
}
|
|
32741
|
+
const appRootPublicKey = await recoverChainKey(
|
|
32742
|
+
appRootPreimage(evidence.purpose, evidence.publicKey),
|
|
32743
|
+
evidence.signatureChain[0],
|
|
32744
|
+
0
|
|
32745
|
+
);
|
|
32746
|
+
const kmsRootPublicKey = await recoverChainKey(
|
|
32747
|
+
kmsIssuedPreimage(evidence.appId, appRootPublicKey),
|
|
32748
|
+
evidence.signatureChain[1],
|
|
32749
|
+
1
|
|
32750
|
+
);
|
|
32751
|
+
if (anchors.kmsRootPubkey === "0x") {
|
|
32752
|
+
throw new Error("KMS root trust anchor is not provisioned");
|
|
32753
|
+
}
|
|
32754
|
+
if (kmsRootPublicKey !== anchors.kmsRootPubkey.toLowerCase()) {
|
|
32755
|
+
throw new Error("KMS root public key does not match the trust anchor");
|
|
32756
|
+
}
|
|
32757
|
+
if ((0, import_viem14.keccak256)(kmsRootPublicKey) !== evidence.kmsRootFingerprint.toLowerCase()) {
|
|
32758
|
+
throw new Error("KMS root fingerprint does not match the evidence");
|
|
32759
|
+
}
|
|
32760
|
+
const appId = evidence.appId.toLowerCase();
|
|
32761
|
+
if (!anchors.appIds.some((allowedAppId) => allowedAppId.toLowerCase() === appId)) {
|
|
32762
|
+
throw new Error("Enclave app ID is not trusted");
|
|
32763
|
+
}
|
|
32764
|
+
}
|
|
32765
|
+
async function buildMasterSignatureDelivery(evidence, masterSignature, now = Math.floor(Date.now() / 1e3)) {
|
|
32766
|
+
deriveMasterKey(masterSignature);
|
|
32767
|
+
const signerAddress = await recoverServerOwner(masterSignature);
|
|
32768
|
+
if (!(0, import_viem14.isAddressEqual)(signerAddress, evidence.ownerAddress)) {
|
|
32769
|
+
throw new Error("Master signature signer does not match evidence owner");
|
|
32770
|
+
}
|
|
32771
|
+
return {
|
|
32772
|
+
v: MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
32773
|
+
userPsId: evidence.userPsId,
|
|
32774
|
+
epoch: evidence.epoch,
|
|
32775
|
+
enclaveAddress: evidence.address,
|
|
32776
|
+
ownerAddress: evidence.ownerAddress,
|
|
32777
|
+
masterSignature,
|
|
32778
|
+
issuedAt: now
|
|
32779
|
+
};
|
|
32780
|
+
}
|
|
32781
|
+
function assertUncompressedKey(publicKey) {
|
|
32782
|
+
const hex = publicKey.slice(2);
|
|
32783
|
+
if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
32784
|
+
throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
|
|
32785
|
+
}
|
|
32786
|
+
}
|
|
32787
|
+
async function encryptMasterSignatureDelivery(delivery, publicKey, ecies) {
|
|
32788
|
+
assertUncompressedKey(publicKey);
|
|
32789
|
+
const plaintext = (0, import_viem14.toBytes)(JSON.stringify(delivery));
|
|
32790
|
+
const encrypted = await ecies.encrypt((0, import_viem14.fromHex)(publicKey, "bytes"), plaintext);
|
|
32791
|
+
return `0x${serializeECIES(encrypted)}`;
|
|
32792
|
+
}
|
|
32793
|
+
|
|
32794
|
+
// src/protocol/personal-server-registration.ts
|
|
32795
|
+
var import_viem15 = require("viem");
|
|
32639
32796
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
32640
32797
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
32641
32798
|
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32642
32799
|
"DataPortabilityServers"
|
|
32643
32800
|
);
|
|
32644
32801
|
function assertAddress(value, name) {
|
|
32645
|
-
if (!(0,
|
|
32802
|
+
if (!(0, import_viem15.isAddress)(value)) {
|
|
32646
32803
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32647
32804
|
}
|
|
32648
32805
|
}
|
|
@@ -32728,12 +32885,12 @@ async function buildPersonalServerRegistrationSignature(input) {
|
|
|
32728
32885
|
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32729
32886
|
|
|
32730
32887
|
// src/personal-server-lite/owner-binding.ts
|
|
32731
|
-
var
|
|
32888
|
+
var import_viem16 = require("viem");
|
|
32732
32889
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
32733
32890
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32734
32891
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32735
32892
|
function assertAddress2(value, name) {
|
|
32736
|
-
if (!(0,
|
|
32893
|
+
if (!(0, import_viem16.isAddress)(value)) {
|
|
32737
32894
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32738
32895
|
}
|
|
32739
32896
|
}
|
|
@@ -32783,7 +32940,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
|
32783
32940
|
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32784
32941
|
|
|
32785
32942
|
// src/account/personal-server-registration.ts
|
|
32786
|
-
var
|
|
32943
|
+
var import_viem17 = require("viem");
|
|
32787
32944
|
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32788
32945
|
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32789
32946
|
status;
|
|
@@ -32802,7 +32959,7 @@ function trimTrailingSlash(value) {
|
|
|
32802
32959
|
return value.replace(/\/+$/, "");
|
|
32803
32960
|
}
|
|
32804
32961
|
function assertAddress3(value, name) {
|
|
32805
|
-
if (!(0,
|
|
32962
|
+
if (!(0, import_viem17.isAddress)(value)) {
|
|
32806
32963
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32807
32964
|
}
|
|
32808
32965
|
}
|
|
@@ -33066,7 +33223,7 @@ function accountOwnerBindingError(error) {
|
|
|
33066
33223
|
}
|
|
33067
33224
|
|
|
33068
33225
|
// src/protocol/grants.ts
|
|
33069
|
-
var
|
|
33226
|
+
var import_viem18 = require("viem");
|
|
33070
33227
|
function isHexString(value) {
|
|
33071
33228
|
return typeof value === "string" && value.startsWith("0x");
|
|
33072
33229
|
}
|
|
@@ -33111,7 +33268,7 @@ async function verifyGrantRegistration(input) {
|
|
|
33111
33268
|
}
|
|
33112
33269
|
let valid;
|
|
33113
33270
|
try {
|
|
33114
|
-
valid = await (0,
|
|
33271
|
+
valid = await (0, import_viem18.verifyTypedData)({
|
|
33115
33272
|
address: input.grantorAddress,
|
|
33116
33273
|
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
33117
33274
|
types: GRANT_REGISTRATION_TYPES,
|
|
@@ -33146,8 +33303,8 @@ async function verifyGrantRegistration(input) {
|
|
|
33146
33303
|
}
|
|
33147
33304
|
|
|
33148
33305
|
// src/protocol/fee-registry.ts
|
|
33149
|
-
var
|
|
33150
|
-
var FEE_REGISTRY_ABI = (0,
|
|
33306
|
+
var import_viem19 = require("viem");
|
|
33307
|
+
var FEE_REGISTRY_ABI = (0, import_viem19.parseAbi)([
|
|
33151
33308
|
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33152
33309
|
"function fees(bytes32 operation) view returns (Fee)",
|
|
33153
33310
|
"function operationKey(string name) pure returns (bytes32)"
|
|
@@ -33230,7 +33387,7 @@ async function getOpFee(client, config, opType, opts) {
|
|
|
33230
33387
|
}
|
|
33231
33388
|
|
|
33232
33389
|
// src/protocol/escrow-deposit.ts
|
|
33233
|
-
var
|
|
33390
|
+
var import_viem20 = require("viem");
|
|
33234
33391
|
var ESCROW_DEPOSIT_ABI = [
|
|
33235
33392
|
{
|
|
33236
33393
|
type: "function",
|
|
@@ -33255,14 +33412,14 @@ function escrowContractAddress(config) {
|
|
|
33255
33412
|
return config.contracts.dataPortabilityEscrow;
|
|
33256
33413
|
}
|
|
33257
33414
|
function encodeDepositNativeData(input) {
|
|
33258
|
-
return (0,
|
|
33415
|
+
return (0, import_viem20.encodeFunctionData)({
|
|
33259
33416
|
abi: ESCROW_DEPOSIT_ABI,
|
|
33260
33417
|
functionName: "depositNative",
|
|
33261
33418
|
args: [input.account]
|
|
33262
33419
|
});
|
|
33263
33420
|
}
|
|
33264
33421
|
function encodeDepositTokenData(input) {
|
|
33265
|
-
return (0,
|
|
33422
|
+
return (0, import_viem20.encodeFunctionData)({
|
|
33266
33423
|
abi: ESCROW_DEPOSIT_ABI,
|
|
33267
33424
|
functionName: "depositToken",
|
|
33268
33425
|
args: [input.account, input.token, input.amount]
|
|
@@ -33283,7 +33440,7 @@ function buildDepositTokenRequest(config, input) {
|
|
|
33283
33440
|
}
|
|
33284
33441
|
|
|
33285
33442
|
// src/protocol/data-point-status.ts
|
|
33286
|
-
var
|
|
33443
|
+
var import_viem21 = require("viem");
|
|
33287
33444
|
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
33288
33445
|
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
33289
33446
|
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
@@ -33307,7 +33464,7 @@ function dataRegistryContractAddress(config) {
|
|
|
33307
33464
|
return config.contracts.dataRegistry;
|
|
33308
33465
|
}
|
|
33309
33466
|
function encodeSetDataPointStatusData(input) {
|
|
33310
|
-
return (0,
|
|
33467
|
+
return (0, import_viem21.encodeFunctionData)({
|
|
33311
33468
|
abi: DATA_REGISTRY_STATUS_ABI,
|
|
33312
33469
|
functionName: "setStatus",
|
|
33313
33470
|
args: [input.scope, input.status]
|
|
@@ -33327,10 +33484,10 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
33327
33484
|
}
|
|
33328
33485
|
|
|
33329
33486
|
// src/protocol/data-point-deletion.ts
|
|
33330
|
-
var
|
|
33487
|
+
var import_viem23 = require("viem");
|
|
33331
33488
|
|
|
33332
33489
|
// src/protocol/lineage.ts
|
|
33333
|
-
var
|
|
33490
|
+
var import_viem22 = require("viem");
|
|
33334
33491
|
var import_zod = require("zod");
|
|
33335
33492
|
|
|
33336
33493
|
// src/protocol/personal-server-error-body.ts
|
|
@@ -33408,13 +33565,13 @@ function isDataPointId(value) {
|
|
|
33408
33565
|
return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
|
|
33409
33566
|
}
|
|
33410
33567
|
function deriveDataPointId(ownerAddress, scope) {
|
|
33411
|
-
if (!(0,
|
|
33568
|
+
if (!(0, import_viem22.isAddress)(ownerAddress, { strict: false })) {
|
|
33412
33569
|
throw new Error(
|
|
33413
33570
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
33414
33571
|
);
|
|
33415
33572
|
}
|
|
33416
|
-
return (0,
|
|
33417
|
-
(0,
|
|
33573
|
+
return (0, import_viem22.keccak256)(
|
|
33574
|
+
(0, import_viem22.encodeAbiParameters)(
|
|
33418
33575
|
[
|
|
33419
33576
|
{ name: "ownerAddress", type: "address" },
|
|
33420
33577
|
{ name: "scope", type: "string" }
|
|
@@ -33640,7 +33797,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
33640
33797
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
33641
33798
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
33642
33799
|
function computeTombstoneHash(preimage) {
|
|
33643
|
-
return (0,
|
|
33800
|
+
return (0, import_viem23.keccak256)((0, import_viem23.stringToBytes)(preimage));
|
|
33644
33801
|
}
|
|
33645
33802
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
33646
33803
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -33659,12 +33816,12 @@ function tombstoneDeletedAt(value) {
|
|
|
33659
33816
|
return typeof deletedAt === "string" ? deletedAt : null;
|
|
33660
33817
|
}
|
|
33661
33818
|
function assertAddress4(value, name) {
|
|
33662
|
-
if (!(0,
|
|
33819
|
+
if (!(0, import_viem23.isAddress)(value)) {
|
|
33663
33820
|
throw new Error(`${name} must be a valid EVM address`);
|
|
33664
33821
|
}
|
|
33665
33822
|
}
|
|
33666
33823
|
function assertUint256(value, name) {
|
|
33667
|
-
if (value < 0n || value >
|
|
33824
|
+
if (value < 0n || value > import_viem23.maxUint256) {
|
|
33668
33825
|
throw new Error(`${name} must fit in uint256, got ${value}`);
|
|
33669
33826
|
}
|
|
33670
33827
|
}
|
|
@@ -33767,7 +33924,7 @@ async function deleteDataPoint(input) {
|
|
|
33767
33924
|
}
|
|
33768
33925
|
currentVersion = parseExpectedVersion(record.expectedVersion);
|
|
33769
33926
|
}
|
|
33770
|
-
if (currentVersion < 0n || currentVersion >=
|
|
33927
|
+
if (currentVersion < 0n || currentVersion >= import_viem23.maxUint256) {
|
|
33771
33928
|
throw new Error(
|
|
33772
33929
|
`currentVersion ${currentVersion} cannot be incremented to a uint256 tombstone version`
|
|
33773
33930
|
);
|
|
@@ -34075,12 +34232,12 @@ function tryGrantPermissions(scopes) {
|
|
|
34075
34232
|
|
|
34076
34233
|
// src/protocol/personal-server-write.ts
|
|
34077
34234
|
var import_sha26 = require("@noble/hashes/sha2");
|
|
34078
|
-
var
|
|
34235
|
+
var import_viem25 = require("viem");
|
|
34079
34236
|
var import_zod4 = require("zod");
|
|
34080
34237
|
|
|
34081
34238
|
// src/protocol/write-request.ts
|
|
34082
34239
|
var import_sha25 = require("@noble/hashes/sha2");
|
|
34083
|
-
var
|
|
34240
|
+
var import_viem24 = require("viem");
|
|
34084
34241
|
function normalizeBaseUrl2(url) {
|
|
34085
34242
|
return url.replace(/\/+$/, "");
|
|
34086
34243
|
}
|
|
@@ -34147,14 +34304,14 @@ function freshProofNonce() {
|
|
|
34147
34304
|
return webCrypto.randomUUID();
|
|
34148
34305
|
}
|
|
34149
34306
|
if (typeof webCrypto?.getRandomValues === "function") {
|
|
34150
|
-
return (0,
|
|
34307
|
+
return (0, import_viem24.bytesToHex)(webCrypto.getRandomValues(new Uint8Array(16)));
|
|
34151
34308
|
}
|
|
34152
34309
|
throw new WriteRequestError(
|
|
34153
34310
|
"No secure random source available to build a proof nonce; provide a crypto global"
|
|
34154
34311
|
);
|
|
34155
34312
|
}
|
|
34156
34313
|
function proofKeyFor(parts) {
|
|
34157
|
-
return (0,
|
|
34314
|
+
return (0, import_viem24.bytesToHex)(
|
|
34158
34315
|
(0, import_sha25.sha256)(
|
|
34159
34316
|
new TextEncoder().encode(
|
|
34160
34317
|
JSON.stringify([
|
|
@@ -34162,7 +34319,7 @@ function proofKeyFor(parts) {
|
|
|
34162
34319
|
parts.method,
|
|
34163
34320
|
parts.uri,
|
|
34164
34321
|
parts.grantId,
|
|
34165
|
-
parts.signedBytes ? (0,
|
|
34322
|
+
parts.signedBytes ? (0, import_viem24.bytesToHex)((0, import_sha25.sha256)(parts.signedBytes)) : ""
|
|
34166
34323
|
])
|
|
34167
34324
|
)
|
|
34168
34325
|
)
|
|
@@ -34349,7 +34506,7 @@ function binaryWriteSignedBytes(input) {
|
|
|
34349
34506
|
mimeType: normalizeBinaryMimeType(input.contentType),
|
|
34350
34507
|
...input.filename ? { filename: input.filename } : {},
|
|
34351
34508
|
sizeBytes: input.bytes.length,
|
|
34352
|
-
contentHash: (0,
|
|
34509
|
+
contentHash: (0, import_viem25.bytesToHex)((0, import_sha26.sha256)(input.bytes)),
|
|
34353
34510
|
encoding: "base64",
|
|
34354
34511
|
content: toBase64(input.bytes),
|
|
34355
34512
|
...metadata !== void 0 ? { metadata } : {}
|
|
@@ -34397,7 +34554,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
34397
34554
|
for (const entry of lineage) {
|
|
34398
34555
|
let id;
|
|
34399
34556
|
if (isLineagePair(entry)) {
|
|
34400
|
-
if (!(0,
|
|
34557
|
+
if (!(0, import_viem25.isAddress)(entry.ownerAddress, { strict: false })) {
|
|
34401
34558
|
throw new WriteRequestError(
|
|
34402
34559
|
"lineage source ownerAddress must be an EVM address",
|
|
34403
34560
|
{ ownerAddress: entry.ownerAddress }
|
|
@@ -34662,6 +34819,13 @@ var QUESTION_STATUSES = [
|
|
|
34662
34819
|
"failed",
|
|
34663
34820
|
"stale"
|
|
34664
34821
|
];
|
|
34822
|
+
var DERIVATIVE_ERROR_CODES = [
|
|
34823
|
+
"inference_unavailable",
|
|
34824
|
+
"source_missing",
|
|
34825
|
+
"grant_invalid",
|
|
34826
|
+
"internal"
|
|
34827
|
+
];
|
|
34828
|
+
var DerivativeErrorCodeSchema = import_zod5.z.enum(DERIVATIVE_ERROR_CODES);
|
|
34665
34829
|
var QuestionStatusSchema = import_zod5.z.enum(QUESTION_STATUSES);
|
|
34666
34830
|
var QuestionRegisteredBySchema = import_zod5.z.union([
|
|
34667
34831
|
import_zod5.z.object({ kind: import_zod5.z.literal("owner") }),
|
|
@@ -34683,6 +34847,14 @@ var DerivativeQuestionSchema = import_zod5.z.object({
|
|
|
34683
34847
|
status: QuestionStatusSchema,
|
|
34684
34848
|
/** A short reason, set only while `status` is `failed`. */
|
|
34685
34849
|
error: nullableString,
|
|
34850
|
+
/**
|
|
34851
|
+
* The coarse failure class behind `error`, set only while `status` is
|
|
34852
|
+
* `failed`. `null` from a Personal Server that predates the class
|
|
34853
|
+
* (`personal-server-ts` before the status route).
|
|
34854
|
+
*/
|
|
34855
|
+
errorCode: DerivativeErrorCodeSchema.nullish().transform(
|
|
34856
|
+
(value) => value ?? null
|
|
34857
|
+
),
|
|
34686
34858
|
createdAt: import_zod5.z.string(),
|
|
34687
34859
|
updatedAt: nullableString,
|
|
34688
34860
|
/** When the last compute finished, or `null` while `pending`. */
|
|
@@ -34815,6 +34987,7 @@ async function questionErrorFromResponse(response, body) {
|
|
|
34815
34987
|
);
|
|
34816
34988
|
}
|
|
34817
34989
|
}
|
|
34990
|
+
var personalServerErrorFromQuestionResponse = questionErrorFromResponse;
|
|
34818
34991
|
async function sendOnce(params, resolved, session, spec, bodyBytes) {
|
|
34819
34992
|
return sendWithFreshProof(
|
|
34820
34993
|
spec.label,
|
|
@@ -35094,6 +35267,166 @@ async function askPersonalServer(params) {
|
|
|
35094
35267
|
return { registration, record };
|
|
35095
35268
|
}
|
|
35096
35269
|
|
|
35270
|
+
// src/protocol/derivative-status.ts
|
|
35271
|
+
var import_zod6 = require("zod");
|
|
35272
|
+
var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
|
|
35273
|
+
var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
|
|
35274
|
+
var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
|
|
35275
|
+
var nullable = (schema) => schema.nullish().transform((value) => value ?? null);
|
|
35276
|
+
var DerivativeStatusSchema = import_zod6.z.object({
|
|
35277
|
+
derivedScope: import_zod6.z.string().min(1),
|
|
35278
|
+
status: QuestionStatusSchema,
|
|
35279
|
+
/** When the last compute finished, or `null` if none ever has. */
|
|
35280
|
+
lastComputedAt: nullable(import_zod6.z.string()),
|
|
35281
|
+
/** Local version of the derived record the last compute wrote. */
|
|
35282
|
+
derivedVersion: nullable(import_zod6.z.number()),
|
|
35283
|
+
derivedCollectedAt: nullable(import_zod6.z.string()),
|
|
35284
|
+
/** The failure class; `null` unless `status` is `failed`. */
|
|
35285
|
+
errorCode: nullable(DerivativeErrorCodeSchema),
|
|
35286
|
+
/**
|
|
35287
|
+
* Seconds until the Personal Server's next automatic retry, or `null` when
|
|
35288
|
+
* none is pending or running — the terminal signature. Poll on this cadence
|
|
35289
|
+
* rather than guessing one.
|
|
35290
|
+
*/
|
|
35291
|
+
retryAfterSeconds: nullable(import_zod6.z.number())
|
|
35292
|
+
});
|
|
35293
|
+
function derivativeStatusTarget(derivedScope) {
|
|
35294
|
+
return `${DERIVATIVE_STATUS_PATH}?derivedScope=${encodeURIComponent(derivedScope)}`;
|
|
35295
|
+
}
|
|
35296
|
+
function normalizeBaseUrl3(url) {
|
|
35297
|
+
return url.replace(/\/+$/, "");
|
|
35298
|
+
}
|
|
35299
|
+
function resolveFetch3(fetchFn) {
|
|
35300
|
+
const resolved = fetchFn ?? globalThis.fetch;
|
|
35301
|
+
if (resolved === void 0) {
|
|
35302
|
+
throw new WriteRequestError("No fetch implementation available");
|
|
35303
|
+
}
|
|
35304
|
+
return resolved;
|
|
35305
|
+
}
|
|
35306
|
+
function requireDerivedScope(derivedScope) {
|
|
35307
|
+
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
35308
|
+
throw new WriteRequestError("derivedScope is required");
|
|
35309
|
+
}
|
|
35310
|
+
return derivedScope;
|
|
35311
|
+
}
|
|
35312
|
+
function sleep3(ms, signal) {
|
|
35313
|
+
if (ms <= 0) return Promise.resolve();
|
|
35314
|
+
return new Promise((resolve, reject) => {
|
|
35315
|
+
const timer = setTimeout(() => {
|
|
35316
|
+
signal?.removeEventListener("abort", onAbort);
|
|
35317
|
+
resolve();
|
|
35318
|
+
}, ms);
|
|
35319
|
+
const onAbort = () => {
|
|
35320
|
+
clearTimeout(timer);
|
|
35321
|
+
reject(abortError2(signal));
|
|
35322
|
+
};
|
|
35323
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
35324
|
+
});
|
|
35325
|
+
}
|
|
35326
|
+
function timeoutError(latest, timeoutMs) {
|
|
35327
|
+
return new DerivativeQuestionTimeoutError(
|
|
35328
|
+
`Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
|
|
35329
|
+
{
|
|
35330
|
+
derivedScope: latest.derivedScope,
|
|
35331
|
+
status: latest.status,
|
|
35332
|
+
errorCode: latest.errorCode,
|
|
35333
|
+
retryAfterSeconds: latest.retryAfterSeconds,
|
|
35334
|
+
timeoutMs
|
|
35335
|
+
}
|
|
35336
|
+
);
|
|
35337
|
+
}
|
|
35338
|
+
function abortError2(signal) {
|
|
35339
|
+
const reason = signal?.reason;
|
|
35340
|
+
return reason instanceof Error ? reason : new WriteRequestError("Derivative status wait was aborted");
|
|
35341
|
+
}
|
|
35342
|
+
function isDerivativeStatusSettled(status) {
|
|
35343
|
+
if (status.status === "ready") return true;
|
|
35344
|
+
return status.status === "failed" && status.retryAfterSeconds === null;
|
|
35345
|
+
}
|
|
35346
|
+
async function getDerivativeStatus(params) {
|
|
35347
|
+
const derivedScope = requireDerivedScope(params.derivedScope);
|
|
35348
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
35349
|
+
const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
|
|
35350
|
+
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
35351
|
+
const headers = new Headers(params.headers);
|
|
35352
|
+
headers.set(
|
|
35353
|
+
"Authorization",
|
|
35354
|
+
await buildWeb3SignedHeader({
|
|
35355
|
+
signMessage: signer.signMessage,
|
|
35356
|
+
aud: params.audience ?? baseUrl,
|
|
35357
|
+
method: "GET",
|
|
35358
|
+
uri: DERIVATIVE_STATUS_PATH,
|
|
35359
|
+
grantId: params.grantId
|
|
35360
|
+
})
|
|
35361
|
+
);
|
|
35362
|
+
let response;
|
|
35363
|
+
try {
|
|
35364
|
+
response = await fetchFn(
|
|
35365
|
+
`${baseUrl}${derivativeStatusTarget(derivedScope)}`,
|
|
35366
|
+
{
|
|
35367
|
+
method: "GET",
|
|
35368
|
+
headers,
|
|
35369
|
+
...params.signal ? { signal: params.signal } : {}
|
|
35370
|
+
}
|
|
35371
|
+
);
|
|
35372
|
+
} catch (err) {
|
|
35373
|
+
throw new WriteTransportError(
|
|
35374
|
+
`Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
35375
|
+
1,
|
|
35376
|
+
err
|
|
35377
|
+
);
|
|
35378
|
+
}
|
|
35379
|
+
if (!response.ok) {
|
|
35380
|
+
throw await personalServerErrorFromQuestionResponse(
|
|
35381
|
+
response
|
|
35382
|
+
);
|
|
35383
|
+
}
|
|
35384
|
+
let body;
|
|
35385
|
+
try {
|
|
35386
|
+
body = await response.json();
|
|
35387
|
+
} catch (err) {
|
|
35388
|
+
throw new DerivativeQuestionRejectedError(
|
|
35389
|
+
"Derivative status response is not JSON",
|
|
35390
|
+
response.status,
|
|
35391
|
+
null,
|
|
35392
|
+
{ cause: err instanceof Error ? err.message : String(err) }
|
|
35393
|
+
);
|
|
35394
|
+
}
|
|
35395
|
+
const parsed = DerivativeStatusSchema.safeParse(body);
|
|
35396
|
+
if (!parsed.success) {
|
|
35397
|
+
throw new DerivativeQuestionRejectedError(
|
|
35398
|
+
"Derivative status response is not a status view",
|
|
35399
|
+
response.status,
|
|
35400
|
+
null,
|
|
35401
|
+
{ issues: parsed.error.issues }
|
|
35402
|
+
);
|
|
35403
|
+
}
|
|
35404
|
+
return parsed.data;
|
|
35405
|
+
}
|
|
35406
|
+
async function waitForDerivativeStatus(params) {
|
|
35407
|
+
const timeoutMs = Math.max(
|
|
35408
|
+
0,
|
|
35409
|
+
params.timeoutMs ?? DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS
|
|
35410
|
+
);
|
|
35411
|
+
const pollIntervalMs = Math.max(
|
|
35412
|
+
0,
|
|
35413
|
+
params.pollIntervalMs ?? DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS
|
|
35414
|
+
);
|
|
35415
|
+
const deadline = Date.now() + timeoutMs;
|
|
35416
|
+
for (; ; ) {
|
|
35417
|
+
if (params.signal?.aborted) throw abortError2(params.signal);
|
|
35418
|
+
const latest = await getDerivativeStatus(params);
|
|
35419
|
+
if (isDerivativeStatusSettled(latest)) return latest;
|
|
35420
|
+
const remaining = deadline - Date.now();
|
|
35421
|
+
if (remaining <= 0) throw timeoutError(latest, timeoutMs);
|
|
35422
|
+
const waitMs = latest.retryAfterSeconds === null ? pollIntervalMs : latest.retryAfterSeconds * 1e3;
|
|
35423
|
+
if (waitMs > remaining) {
|
|
35424
|
+
throw timeoutError(latest, timeoutMs);
|
|
35425
|
+
}
|
|
35426
|
+
await sleep3(waitMs, params.signal);
|
|
35427
|
+
}
|
|
35428
|
+
}
|
|
35429
|
+
|
|
35097
35430
|
// src/protocol/gateway.ts
|
|
35098
35431
|
function withGrantPermissions(grant) {
|
|
35099
35432
|
const stripped = { ...grant };
|
|
@@ -36175,9 +36508,13 @@ async function parsePSError(response) {
|
|
|
36175
36508
|
ContractNotFoundError,
|
|
36176
36509
|
DATA_ACCESS_OP_TYPE,
|
|
36177
36510
|
DATA_REGISTRY_STATUS_ABI,
|
|
36511
|
+
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
36512
|
+
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
36178
36513
|
DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
36179
36514
|
DEFAULT_QUESTION_TIMEOUT_MS,
|
|
36515
|
+
DERIVATIVE_ERROR_CODES,
|
|
36180
36516
|
DERIVATIVE_QUESTIONS_PATH,
|
|
36517
|
+
DERIVATIVE_STATUS_PATH,
|
|
36181
36518
|
DataFileEnvelopeSchema,
|
|
36182
36519
|
DataPointDeletedError,
|
|
36183
36520
|
DataPointNotFoundError,
|
|
@@ -36186,6 +36523,7 @@ async function parsePSError(response) {
|
|
|
36186
36523
|
DerivativeComputeUnavailableError,
|
|
36187
36524
|
DerivativeCycleError,
|
|
36188
36525
|
DerivativeDerivedScopeRequiredError,
|
|
36526
|
+
DerivativeErrorCodeSchema,
|
|
36189
36527
|
DerivativeQuestionFailedError,
|
|
36190
36528
|
DerivativeQuestionInvalidError,
|
|
36191
36529
|
DerivativeQuestionNotFoundError,
|
|
@@ -36193,8 +36531,12 @@ async function parsePSError(response) {
|
|
|
36193
36531
|
DerivativeQuestionSchema,
|
|
36194
36532
|
DerivativeQuestionTimeoutError,
|
|
36195
36533
|
DerivativeSourceNotGrantedError,
|
|
36534
|
+
DerivativeStatusSchema,
|
|
36196
36535
|
DropboxStorage,
|
|
36197
36536
|
ECIESError,
|
|
36537
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
36538
|
+
ENCLAVE_TRUST_ANCHORS,
|
|
36539
|
+
ENCLAVE_WALLET_PURPOSE,
|
|
36198
36540
|
ESCROW_DEPOSIT_ABI,
|
|
36199
36541
|
ExpiredTokenError,
|
|
36200
36542
|
FEE_REGISTRY_ABI,
|
|
@@ -36216,6 +36558,7 @@ async function parsePSError(response) {
|
|
|
36216
36558
|
LineageNodeSchema,
|
|
36217
36559
|
LineageReadError,
|
|
36218
36560
|
MASTER_KEY_MESSAGE,
|
|
36561
|
+
MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
36219
36562
|
MAX_LINEAGE_SOURCES,
|
|
36220
36563
|
MAX_QUESTION_CHARS,
|
|
36221
36564
|
MAX_QUESTION_MODEL_CHARS,
|
|
@@ -36253,6 +36596,7 @@ async function parsePSError(response) {
|
|
|
36253
36596
|
RedactedLineageNodeSchema,
|
|
36254
36597
|
RelayerError,
|
|
36255
36598
|
SCOPE_ACTIONS,
|
|
36599
|
+
SEALED_ENVELOPE_VERSION,
|
|
36256
36600
|
SERVER_REGISTRATION_TYPES,
|
|
36257
36601
|
ScopeSchema,
|
|
36258
36602
|
SerializationError,
|
|
@@ -36265,6 +36609,7 @@ async function parsePSError(response) {
|
|
|
36265
36609
|
TOMBSTONE_METADATA_HASH,
|
|
36266
36610
|
TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
36267
36611
|
TransactionPendingError,
|
|
36612
|
+
USER_PS_ID_DOMAIN,
|
|
36268
36613
|
UserRejectedRequestError,
|
|
36269
36614
|
VanaError,
|
|
36270
36615
|
VanaStorage,
|
|
@@ -36283,6 +36628,7 @@ async function parsePSError(response) {
|
|
|
36283
36628
|
WriteSessionExpiredError,
|
|
36284
36629
|
WriteTransportError,
|
|
36285
36630
|
WriteUnauthorizedError,
|
|
36631
|
+
appRootPreimage,
|
|
36286
36632
|
askPersonalServer,
|
|
36287
36633
|
assertDerivedScopeNaming,
|
|
36288
36634
|
assertValidPkceVerifier,
|
|
@@ -36296,6 +36642,7 @@ async function parsePSError(response) {
|
|
|
36296
36642
|
buildEscrowPaymentHeader,
|
|
36297
36643
|
buildGrantPaymentHeader,
|
|
36298
36644
|
buildMarkDataPointUnavailableRequest,
|
|
36645
|
+
buildMasterSignatureDelivery,
|
|
36299
36646
|
buildPersonalServerDataReadRequest,
|
|
36300
36647
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
36301
36648
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -36328,6 +36675,7 @@ async function parsePSError(response) {
|
|
|
36328
36675
|
decryptWithPassword,
|
|
36329
36676
|
deleteDataPoint,
|
|
36330
36677
|
deleteQuestion,
|
|
36678
|
+
derivativeStatusTarget,
|
|
36331
36679
|
deriveDataPointId,
|
|
36332
36680
|
deriveMasterKey,
|
|
36333
36681
|
deriveScopeKey,
|
|
@@ -36338,6 +36686,7 @@ async function parsePSError(response) {
|
|
|
36338
36686
|
encodeDepositTokenData,
|
|
36339
36687
|
encodeSetDataPointStatusData,
|
|
36340
36688
|
encodeWriteMetadataHeader,
|
|
36689
|
+
encryptMasterSignatureDelivery,
|
|
36341
36690
|
encryptWithPassword,
|
|
36342
36691
|
escrowContractAddress,
|
|
36343
36692
|
escrowPaymentDomain,
|
|
@@ -36351,6 +36700,7 @@ async function parsePSError(response) {
|
|
|
36351
36700
|
getContractAddress,
|
|
36352
36701
|
getContractController,
|
|
36353
36702
|
getContractInfo,
|
|
36703
|
+
getDerivativeStatus,
|
|
36354
36704
|
getFee,
|
|
36355
36705
|
getGatewayLineage,
|
|
36356
36706
|
getLineage,
|
|
@@ -36366,10 +36716,12 @@ async function parsePSError(response) {
|
|
|
36366
36716
|
isDataPointId,
|
|
36367
36717
|
isDataPointTombstone,
|
|
36368
36718
|
isDataPortabilityGatewayConfig,
|
|
36719
|
+
isDerivativeStatusSettled,
|
|
36369
36720
|
isECIESEncrypted,
|
|
36370
36721
|
isPlatformSupported,
|
|
36371
36722
|
isRedactedLineageNode,
|
|
36372
36723
|
isTombstoneHashes,
|
|
36724
|
+
kmsIssuedPreimage,
|
|
36373
36725
|
listQuestions,
|
|
36374
36726
|
mainnetServices,
|
|
36375
36727
|
moksha,
|
|
@@ -36409,10 +36761,13 @@ async function parsePSError(response) {
|
|
|
36409
36761
|
toDirectPaymentReceipt,
|
|
36410
36762
|
tombstoneDeletedAt,
|
|
36411
36763
|
tryGrantPermissions,
|
|
36764
|
+
userPsId,
|
|
36412
36765
|
vanaMainnet,
|
|
36766
|
+
verifyEnclaveIdentityEvidence,
|
|
36413
36767
|
verifyGrantRegistration,
|
|
36414
36768
|
verifyPkceChallenge,
|
|
36415
36769
|
verifyWeb3Signed,
|
|
36770
|
+
waitForDerivativeStatus,
|
|
36416
36771
|
waitForQuestion,
|
|
36417
36772
|
writeData,
|
|
36418
36773
|
writePersonalServerData
|