@opendatalabs/vana-sdk 3.21.0 → 3.22.0-pr.207.5c11fe3
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 +343 -4
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +386 -34
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +3 -1
- package/dist/index.node.js +346 -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 +191 -0
- package/dist/protocol/identity.cjs.map +1 -0
- package/dist/protocol/identity.d.ts +164 -0
- package/dist/protocol/identity.js +155 -0
- package/dist/protocol/identity.js.map +1 -0
- package/dist/protocol/identity.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,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,147 @@ 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 appRootPreimage(purpose, publicKey) {
|
|
32689
|
+
const keyHex = publicKey.slice(2).toLowerCase();
|
|
32690
|
+
return (0, import_viem14.keccak256)((0, import_viem14.toBytes)(`${purpose}${PREIMAGE_SEPARATOR}${keyHex}`));
|
|
32691
|
+
}
|
|
32692
|
+
function kmsIssuedPreimage(appId, appRootPublicKey) {
|
|
32693
|
+
const appIdHex = appId.slice(2).toLowerCase();
|
|
32694
|
+
const prefix = (0, import_viem14.toBytes)(
|
|
32695
|
+
`${KMS_ISSUED_PREFIX}${PREIMAGE_SEPARATOR}${appIdHex}`
|
|
32696
|
+
);
|
|
32697
|
+
const compressed = secp256k14.ProjectivePoint.fromHex(
|
|
32698
|
+
(0, import_viem14.fromHex)(appRootPublicKey, "bytes")
|
|
32699
|
+
).toRawBytes(true);
|
|
32700
|
+
return (0, import_viem14.keccak256)((0, import_viem14.concat)([prefix, compressed]));
|
|
32701
|
+
}
|
|
32702
|
+
async function recoverChainKey(hash, signature, link) {
|
|
32703
|
+
try {
|
|
32704
|
+
return (await (0, import_viem14.recoverPublicKey)({ hash, signature })).toLowerCase();
|
|
32705
|
+
} catch {
|
|
32706
|
+
throw new Error(`Invalid enclave signature chain link ${link}`);
|
|
32707
|
+
}
|
|
32708
|
+
}
|
|
32709
|
+
async function verifyEnclaveIdentityEvidence(evidence, anchors, expected) {
|
|
32710
|
+
if (evidence.v !== ENCLAVE_IDENTITY_EVIDENCE_VERSION) {
|
|
32711
|
+
throw new Error("Unsupported enclave identity evidence version");
|
|
32712
|
+
}
|
|
32713
|
+
if (!Number.isInteger(evidence.epoch) || evidence.epoch < 1) {
|
|
32714
|
+
throw new Error("Invalid enclave identity epoch");
|
|
32715
|
+
}
|
|
32716
|
+
if (evidence.chainId !== expected.chainId) {
|
|
32717
|
+
throw new Error(
|
|
32718
|
+
"Enclave identity chain ID does not match expected chain ID"
|
|
32719
|
+
);
|
|
32720
|
+
}
|
|
32721
|
+
if (!(0, import_viem14.isAddressEqual)(evidence.ownerAddress, expected.ownerAddress)) {
|
|
32722
|
+
throw new Error("Enclave identity owner does not match expected owner");
|
|
32723
|
+
}
|
|
32724
|
+
if (evidence.epoch !== expected.epoch) {
|
|
32725
|
+
throw new Error("Enclave identity epoch does not match expected epoch");
|
|
32726
|
+
}
|
|
32727
|
+
const expectedUserPsId = userPsId(expected.chainId, expected.ownerAddress);
|
|
32728
|
+
if (evidence.userPsId.toLowerCase() !== expectedUserPsId.toLowerCase()) {
|
|
32729
|
+
throw new Error("Enclave userPsId does not match expected identity");
|
|
32730
|
+
}
|
|
32731
|
+
if (evidence.purpose !== ENCLAVE_WALLET_PURPOSE) {
|
|
32732
|
+
throw new Error("Unexpected enclave wallet purpose");
|
|
32733
|
+
}
|
|
32734
|
+
const derivedAddress = (0, import_accounts.publicKeyToAddress)(evidence.publicKey);
|
|
32735
|
+
if ((0, import_viem14.getAddress)(derivedAddress) !== (0, import_viem14.getAddress)(evidence.address)) {
|
|
32736
|
+
throw new Error("Enclave public key does not match its address");
|
|
32737
|
+
}
|
|
32738
|
+
const appRootPublicKey = await recoverChainKey(
|
|
32739
|
+
appRootPreimage(evidence.purpose, evidence.publicKey),
|
|
32740
|
+
evidence.signatureChain[0],
|
|
32741
|
+
0
|
|
32742
|
+
);
|
|
32743
|
+
const kmsRootPublicKey = await recoverChainKey(
|
|
32744
|
+
kmsIssuedPreimage(evidence.appId, appRootPublicKey),
|
|
32745
|
+
evidence.signatureChain[1],
|
|
32746
|
+
1
|
|
32747
|
+
);
|
|
32748
|
+
if (anchors.kmsRootPubkey === "0x") {
|
|
32749
|
+
throw new Error("KMS root trust anchor is not provisioned");
|
|
32750
|
+
}
|
|
32751
|
+
if (kmsRootPublicKey !== anchors.kmsRootPubkey.toLowerCase()) {
|
|
32752
|
+
throw new Error("KMS root public key does not match the trust anchor");
|
|
32753
|
+
}
|
|
32754
|
+
if ((0, import_viem14.keccak256)(kmsRootPublicKey) !== evidence.kmsRootFingerprint.toLowerCase()) {
|
|
32755
|
+
throw new Error("KMS root fingerprint does not match the evidence");
|
|
32756
|
+
}
|
|
32757
|
+
const appId = evidence.appId.toLowerCase();
|
|
32758
|
+
if (!anchors.appIds.some((allowedAppId) => allowedAppId.toLowerCase() === appId)) {
|
|
32759
|
+
throw new Error("Enclave app ID is not trusted");
|
|
32760
|
+
}
|
|
32761
|
+
}
|
|
32762
|
+
async function buildMasterSignatureDelivery(evidence, masterSignature, now = Math.floor(Date.now() / 1e3)) {
|
|
32763
|
+
deriveMasterKey(masterSignature);
|
|
32764
|
+
const signerAddress = await recoverServerOwner(masterSignature);
|
|
32765
|
+
if (!(0, import_viem14.isAddressEqual)(signerAddress, evidence.ownerAddress)) {
|
|
32766
|
+
throw new Error("Master signature signer does not match evidence owner");
|
|
32767
|
+
}
|
|
32768
|
+
return {
|
|
32769
|
+
v: MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
32770
|
+
userPsId: evidence.userPsId,
|
|
32771
|
+
epoch: evidence.epoch,
|
|
32772
|
+
enclaveAddress: evidence.address,
|
|
32773
|
+
ownerAddress: evidence.ownerAddress,
|
|
32774
|
+
masterSignature,
|
|
32775
|
+
issuedAt: now
|
|
32776
|
+
};
|
|
32777
|
+
}
|
|
32778
|
+
function assertUncompressedKey(publicKey) {
|
|
32779
|
+
const hex = publicKey.slice(2);
|
|
32780
|
+
if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
32781
|
+
throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
|
|
32782
|
+
}
|
|
32783
|
+
}
|
|
32784
|
+
async function encryptMasterSignatureDelivery(delivery, publicKey, ecies) {
|
|
32785
|
+
assertUncompressedKey(publicKey);
|
|
32786
|
+
const plaintext = (0, import_viem14.toBytes)(JSON.stringify(delivery));
|
|
32787
|
+
const encrypted = await ecies.encrypt((0, import_viem14.fromHex)(publicKey, "bytes"), plaintext);
|
|
32788
|
+
return `0x${serializeECIES(encrypted)}`;
|
|
32789
|
+
}
|
|
32790
|
+
|
|
32791
|
+
// src/protocol/personal-server-registration.ts
|
|
32792
|
+
var import_viem15 = require("viem");
|
|
32639
32793
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
32640
32794
|
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
32641
32795
|
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32642
32796
|
"DataPortabilityServers"
|
|
32643
32797
|
);
|
|
32644
32798
|
function assertAddress(value, name) {
|
|
32645
|
-
if (!(0,
|
|
32799
|
+
if (!(0, import_viem15.isAddress)(value)) {
|
|
32646
32800
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32647
32801
|
}
|
|
32648
32802
|
}
|
|
@@ -32728,12 +32882,12 @@ async function buildPersonalServerRegistrationSignature(input) {
|
|
|
32728
32882
|
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32729
32883
|
|
|
32730
32884
|
// src/personal-server-lite/owner-binding.ts
|
|
32731
|
-
var
|
|
32885
|
+
var import_viem16 = require("viem");
|
|
32732
32886
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
32733
32887
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32734
32888
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32735
32889
|
function assertAddress2(value, name) {
|
|
32736
|
-
if (!(0,
|
|
32890
|
+
if (!(0, import_viem16.isAddress)(value)) {
|
|
32737
32891
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32738
32892
|
}
|
|
32739
32893
|
}
|
|
@@ -32783,7 +32937,7 @@ async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
|
32783
32937
|
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32784
32938
|
|
|
32785
32939
|
// src/account/personal-server-registration.ts
|
|
32786
|
-
var
|
|
32940
|
+
var import_viem17 = require("viem");
|
|
32787
32941
|
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32788
32942
|
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32789
32943
|
status;
|
|
@@ -32802,7 +32956,7 @@ function trimTrailingSlash(value) {
|
|
|
32802
32956
|
return value.replace(/\/+$/, "");
|
|
32803
32957
|
}
|
|
32804
32958
|
function assertAddress3(value, name) {
|
|
32805
|
-
if (!(0,
|
|
32959
|
+
if (!(0, import_viem17.isAddress)(value)) {
|
|
32806
32960
|
throw new Error(`${name} must be a valid EVM address`);
|
|
32807
32961
|
}
|
|
32808
32962
|
}
|
|
@@ -33066,7 +33220,7 @@ function accountOwnerBindingError(error) {
|
|
|
33066
33220
|
}
|
|
33067
33221
|
|
|
33068
33222
|
// src/protocol/grants.ts
|
|
33069
|
-
var
|
|
33223
|
+
var import_viem18 = require("viem");
|
|
33070
33224
|
function isHexString(value) {
|
|
33071
33225
|
return typeof value === "string" && value.startsWith("0x");
|
|
33072
33226
|
}
|
|
@@ -33111,7 +33265,7 @@ async function verifyGrantRegistration(input) {
|
|
|
33111
33265
|
}
|
|
33112
33266
|
let valid;
|
|
33113
33267
|
try {
|
|
33114
|
-
valid = await (0,
|
|
33268
|
+
valid = await (0, import_viem18.verifyTypedData)({
|
|
33115
33269
|
address: input.grantorAddress,
|
|
33116
33270
|
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
33117
33271
|
types: GRANT_REGISTRATION_TYPES,
|
|
@@ -33146,8 +33300,8 @@ async function verifyGrantRegistration(input) {
|
|
|
33146
33300
|
}
|
|
33147
33301
|
|
|
33148
33302
|
// src/protocol/fee-registry.ts
|
|
33149
|
-
var
|
|
33150
|
-
var FEE_REGISTRY_ABI = (0,
|
|
33303
|
+
var import_viem19 = require("viem");
|
|
33304
|
+
var FEE_REGISTRY_ABI = (0, import_viem19.parseAbi)([
|
|
33151
33305
|
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33152
33306
|
"function fees(bytes32 operation) view returns (Fee)",
|
|
33153
33307
|
"function operationKey(string name) pure returns (bytes32)"
|
|
@@ -33230,7 +33384,7 @@ async function getOpFee(client, config, opType, opts) {
|
|
|
33230
33384
|
}
|
|
33231
33385
|
|
|
33232
33386
|
// src/protocol/escrow-deposit.ts
|
|
33233
|
-
var
|
|
33387
|
+
var import_viem20 = require("viem");
|
|
33234
33388
|
var ESCROW_DEPOSIT_ABI = [
|
|
33235
33389
|
{
|
|
33236
33390
|
type: "function",
|
|
@@ -33255,14 +33409,14 @@ function escrowContractAddress(config) {
|
|
|
33255
33409
|
return config.contracts.dataPortabilityEscrow;
|
|
33256
33410
|
}
|
|
33257
33411
|
function encodeDepositNativeData(input) {
|
|
33258
|
-
return (0,
|
|
33412
|
+
return (0, import_viem20.encodeFunctionData)({
|
|
33259
33413
|
abi: ESCROW_DEPOSIT_ABI,
|
|
33260
33414
|
functionName: "depositNative",
|
|
33261
33415
|
args: [input.account]
|
|
33262
33416
|
});
|
|
33263
33417
|
}
|
|
33264
33418
|
function encodeDepositTokenData(input) {
|
|
33265
|
-
return (0,
|
|
33419
|
+
return (0, import_viem20.encodeFunctionData)({
|
|
33266
33420
|
abi: ESCROW_DEPOSIT_ABI,
|
|
33267
33421
|
functionName: "depositToken",
|
|
33268
33422
|
args: [input.account, input.token, input.amount]
|
|
@@ -33283,7 +33437,7 @@ function buildDepositTokenRequest(config, input) {
|
|
|
33283
33437
|
}
|
|
33284
33438
|
|
|
33285
33439
|
// src/protocol/data-point-status.ts
|
|
33286
|
-
var
|
|
33440
|
+
var import_viem21 = require("viem");
|
|
33287
33441
|
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
33288
33442
|
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
33289
33443
|
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
@@ -33307,7 +33461,7 @@ function dataRegistryContractAddress(config) {
|
|
|
33307
33461
|
return config.contracts.dataRegistry;
|
|
33308
33462
|
}
|
|
33309
33463
|
function encodeSetDataPointStatusData(input) {
|
|
33310
|
-
return (0,
|
|
33464
|
+
return (0, import_viem21.encodeFunctionData)({
|
|
33311
33465
|
abi: DATA_REGISTRY_STATUS_ABI,
|
|
33312
33466
|
functionName: "setStatus",
|
|
33313
33467
|
args: [input.scope, input.status]
|
|
@@ -33327,10 +33481,10 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
33327
33481
|
}
|
|
33328
33482
|
|
|
33329
33483
|
// src/protocol/data-point-deletion.ts
|
|
33330
|
-
var
|
|
33484
|
+
var import_viem23 = require("viem");
|
|
33331
33485
|
|
|
33332
33486
|
// src/protocol/lineage.ts
|
|
33333
|
-
var
|
|
33487
|
+
var import_viem22 = require("viem");
|
|
33334
33488
|
var import_zod = require("zod");
|
|
33335
33489
|
|
|
33336
33490
|
// src/protocol/personal-server-error-body.ts
|
|
@@ -33408,13 +33562,13 @@ function isDataPointId(value) {
|
|
|
33408
33562
|
return typeof value === "string" && DATA_POINT_ID_PATTERN.test(value);
|
|
33409
33563
|
}
|
|
33410
33564
|
function deriveDataPointId(ownerAddress, scope) {
|
|
33411
|
-
if (!(0,
|
|
33565
|
+
if (!(0, import_viem22.isAddress)(ownerAddress, { strict: false })) {
|
|
33412
33566
|
throw new Error(
|
|
33413
33567
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
33414
33568
|
);
|
|
33415
33569
|
}
|
|
33416
|
-
return (0,
|
|
33417
|
-
(0,
|
|
33570
|
+
return (0, import_viem22.keccak256)(
|
|
33571
|
+
(0, import_viem22.encodeAbiParameters)(
|
|
33418
33572
|
[
|
|
33419
33573
|
{ name: "ownerAddress", type: "address" },
|
|
33420
33574
|
{ name: "scope", type: "string" }
|
|
@@ -33640,7 +33794,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
33640
33794
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
33641
33795
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
33642
33796
|
function computeTombstoneHash(preimage) {
|
|
33643
|
-
return (0,
|
|
33797
|
+
return (0, import_viem23.keccak256)((0, import_viem23.stringToBytes)(preimage));
|
|
33644
33798
|
}
|
|
33645
33799
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
33646
33800
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -33659,12 +33813,12 @@ function tombstoneDeletedAt(value) {
|
|
|
33659
33813
|
return typeof deletedAt === "string" ? deletedAt : null;
|
|
33660
33814
|
}
|
|
33661
33815
|
function assertAddress4(value, name) {
|
|
33662
|
-
if (!(0,
|
|
33816
|
+
if (!(0, import_viem23.isAddress)(value)) {
|
|
33663
33817
|
throw new Error(`${name} must be a valid EVM address`);
|
|
33664
33818
|
}
|
|
33665
33819
|
}
|
|
33666
33820
|
function assertUint256(value, name) {
|
|
33667
|
-
if (value < 0n || value >
|
|
33821
|
+
if (value < 0n || value > import_viem23.maxUint256) {
|
|
33668
33822
|
throw new Error(`${name} must fit in uint256, got ${value}`);
|
|
33669
33823
|
}
|
|
33670
33824
|
}
|
|
@@ -33767,7 +33921,7 @@ async function deleteDataPoint(input) {
|
|
|
33767
33921
|
}
|
|
33768
33922
|
currentVersion = parseExpectedVersion(record.expectedVersion);
|
|
33769
33923
|
}
|
|
33770
|
-
if (currentVersion < 0n || currentVersion >=
|
|
33924
|
+
if (currentVersion < 0n || currentVersion >= import_viem23.maxUint256) {
|
|
33771
33925
|
throw new Error(
|
|
33772
33926
|
`currentVersion ${currentVersion} cannot be incremented to a uint256 tombstone version`
|
|
33773
33927
|
);
|
|
@@ -34075,12 +34229,12 @@ function tryGrantPermissions(scopes) {
|
|
|
34075
34229
|
|
|
34076
34230
|
// src/protocol/personal-server-write.ts
|
|
34077
34231
|
var import_sha26 = require("@noble/hashes/sha2");
|
|
34078
|
-
var
|
|
34232
|
+
var import_viem25 = require("viem");
|
|
34079
34233
|
var import_zod4 = require("zod");
|
|
34080
34234
|
|
|
34081
34235
|
// src/protocol/write-request.ts
|
|
34082
34236
|
var import_sha25 = require("@noble/hashes/sha2");
|
|
34083
|
-
var
|
|
34237
|
+
var import_viem24 = require("viem");
|
|
34084
34238
|
function normalizeBaseUrl2(url) {
|
|
34085
34239
|
return url.replace(/\/+$/, "");
|
|
34086
34240
|
}
|
|
@@ -34147,14 +34301,14 @@ function freshProofNonce() {
|
|
|
34147
34301
|
return webCrypto.randomUUID();
|
|
34148
34302
|
}
|
|
34149
34303
|
if (typeof webCrypto?.getRandomValues === "function") {
|
|
34150
|
-
return (0,
|
|
34304
|
+
return (0, import_viem24.bytesToHex)(webCrypto.getRandomValues(new Uint8Array(16)));
|
|
34151
34305
|
}
|
|
34152
34306
|
throw new WriteRequestError(
|
|
34153
34307
|
"No secure random source available to build a proof nonce; provide a crypto global"
|
|
34154
34308
|
);
|
|
34155
34309
|
}
|
|
34156
34310
|
function proofKeyFor(parts) {
|
|
34157
|
-
return (0,
|
|
34311
|
+
return (0, import_viem24.bytesToHex)(
|
|
34158
34312
|
(0, import_sha25.sha256)(
|
|
34159
34313
|
new TextEncoder().encode(
|
|
34160
34314
|
JSON.stringify([
|
|
@@ -34162,7 +34316,7 @@ function proofKeyFor(parts) {
|
|
|
34162
34316
|
parts.method,
|
|
34163
34317
|
parts.uri,
|
|
34164
34318
|
parts.grantId,
|
|
34165
|
-
parts.signedBytes ? (0,
|
|
34319
|
+
parts.signedBytes ? (0, import_viem24.bytesToHex)((0, import_sha25.sha256)(parts.signedBytes)) : ""
|
|
34166
34320
|
])
|
|
34167
34321
|
)
|
|
34168
34322
|
)
|
|
@@ -34349,7 +34503,7 @@ function binaryWriteSignedBytes(input) {
|
|
|
34349
34503
|
mimeType: normalizeBinaryMimeType(input.contentType),
|
|
34350
34504
|
...input.filename ? { filename: input.filename } : {},
|
|
34351
34505
|
sizeBytes: input.bytes.length,
|
|
34352
|
-
contentHash: (0,
|
|
34506
|
+
contentHash: (0, import_viem25.bytesToHex)((0, import_sha26.sha256)(input.bytes)),
|
|
34353
34507
|
encoding: "base64",
|
|
34354
34508
|
content: toBase64(input.bytes),
|
|
34355
34509
|
...metadata !== void 0 ? { metadata } : {}
|
|
@@ -34397,7 +34551,7 @@ function normalizeLineage(lineage, derivedScope) {
|
|
|
34397
34551
|
for (const entry of lineage) {
|
|
34398
34552
|
let id;
|
|
34399
34553
|
if (isLineagePair(entry)) {
|
|
34400
|
-
if (!(0,
|
|
34554
|
+
if (!(0, import_viem25.isAddress)(entry.ownerAddress, { strict: false })) {
|
|
34401
34555
|
throw new WriteRequestError(
|
|
34402
34556
|
"lineage source ownerAddress must be an EVM address",
|
|
34403
34557
|
{ ownerAddress: entry.ownerAddress }
|
|
@@ -34662,6 +34816,13 @@ var QUESTION_STATUSES = [
|
|
|
34662
34816
|
"failed",
|
|
34663
34817
|
"stale"
|
|
34664
34818
|
];
|
|
34819
|
+
var DERIVATIVE_ERROR_CODES = [
|
|
34820
|
+
"inference_unavailable",
|
|
34821
|
+
"source_missing",
|
|
34822
|
+
"grant_invalid",
|
|
34823
|
+
"internal"
|
|
34824
|
+
];
|
|
34825
|
+
var DerivativeErrorCodeSchema = import_zod5.z.enum(DERIVATIVE_ERROR_CODES);
|
|
34665
34826
|
var QuestionStatusSchema = import_zod5.z.enum(QUESTION_STATUSES);
|
|
34666
34827
|
var QuestionRegisteredBySchema = import_zod5.z.union([
|
|
34667
34828
|
import_zod5.z.object({ kind: import_zod5.z.literal("owner") }),
|
|
@@ -34683,6 +34844,14 @@ var DerivativeQuestionSchema = import_zod5.z.object({
|
|
|
34683
34844
|
status: QuestionStatusSchema,
|
|
34684
34845
|
/** A short reason, set only while `status` is `failed`. */
|
|
34685
34846
|
error: nullableString,
|
|
34847
|
+
/**
|
|
34848
|
+
* The coarse failure class behind `error`, set only while `status` is
|
|
34849
|
+
* `failed`. `null` from a Personal Server that predates the class
|
|
34850
|
+
* (`personal-server-ts` before the status route).
|
|
34851
|
+
*/
|
|
34852
|
+
errorCode: DerivativeErrorCodeSchema.nullish().transform(
|
|
34853
|
+
(value) => value ?? null
|
|
34854
|
+
),
|
|
34686
34855
|
createdAt: import_zod5.z.string(),
|
|
34687
34856
|
updatedAt: nullableString,
|
|
34688
34857
|
/** When the last compute finished, or `null` while `pending`. */
|
|
@@ -34815,6 +34984,7 @@ async function questionErrorFromResponse(response, body) {
|
|
|
34815
34984
|
);
|
|
34816
34985
|
}
|
|
34817
34986
|
}
|
|
34987
|
+
var personalServerErrorFromQuestionResponse = questionErrorFromResponse;
|
|
34818
34988
|
async function sendOnce(params, resolved, session, spec, bodyBytes) {
|
|
34819
34989
|
return sendWithFreshProof(
|
|
34820
34990
|
spec.label,
|
|
@@ -35094,6 +35264,166 @@ async function askPersonalServer(params) {
|
|
|
35094
35264
|
return { registration, record };
|
|
35095
35265
|
}
|
|
35096
35266
|
|
|
35267
|
+
// src/protocol/derivative-status.ts
|
|
35268
|
+
var import_zod6 = require("zod");
|
|
35269
|
+
var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
|
|
35270
|
+
var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
|
|
35271
|
+
var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
|
|
35272
|
+
var nullable = (schema) => schema.nullish().transform((value) => value ?? null);
|
|
35273
|
+
var DerivativeStatusSchema = import_zod6.z.object({
|
|
35274
|
+
derivedScope: import_zod6.z.string().min(1),
|
|
35275
|
+
status: QuestionStatusSchema,
|
|
35276
|
+
/** When the last compute finished, or `null` if none ever has. */
|
|
35277
|
+
lastComputedAt: nullable(import_zod6.z.string()),
|
|
35278
|
+
/** Local version of the derived record the last compute wrote. */
|
|
35279
|
+
derivedVersion: nullable(import_zod6.z.number()),
|
|
35280
|
+
derivedCollectedAt: nullable(import_zod6.z.string()),
|
|
35281
|
+
/** The failure class; `null` unless `status` is `failed`. */
|
|
35282
|
+
errorCode: nullable(DerivativeErrorCodeSchema),
|
|
35283
|
+
/**
|
|
35284
|
+
* Seconds until the Personal Server's next automatic retry, or `null` when
|
|
35285
|
+
* none is pending or running — the terminal signature. Poll on this cadence
|
|
35286
|
+
* rather than guessing one.
|
|
35287
|
+
*/
|
|
35288
|
+
retryAfterSeconds: nullable(import_zod6.z.number())
|
|
35289
|
+
});
|
|
35290
|
+
function derivativeStatusTarget(derivedScope) {
|
|
35291
|
+
return `${DERIVATIVE_STATUS_PATH}?derivedScope=${encodeURIComponent(derivedScope)}`;
|
|
35292
|
+
}
|
|
35293
|
+
function normalizeBaseUrl3(url) {
|
|
35294
|
+
return url.replace(/\/+$/, "");
|
|
35295
|
+
}
|
|
35296
|
+
function resolveFetch3(fetchFn) {
|
|
35297
|
+
const resolved = fetchFn ?? globalThis.fetch;
|
|
35298
|
+
if (resolved === void 0) {
|
|
35299
|
+
throw new WriteRequestError("No fetch implementation available");
|
|
35300
|
+
}
|
|
35301
|
+
return resolved;
|
|
35302
|
+
}
|
|
35303
|
+
function requireDerivedScope(derivedScope) {
|
|
35304
|
+
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
35305
|
+
throw new WriteRequestError("derivedScope is required");
|
|
35306
|
+
}
|
|
35307
|
+
return derivedScope;
|
|
35308
|
+
}
|
|
35309
|
+
function sleep3(ms, signal) {
|
|
35310
|
+
if (ms <= 0) return Promise.resolve();
|
|
35311
|
+
return new Promise((resolve, reject) => {
|
|
35312
|
+
const timer = setTimeout(() => {
|
|
35313
|
+
signal?.removeEventListener("abort", onAbort);
|
|
35314
|
+
resolve();
|
|
35315
|
+
}, ms);
|
|
35316
|
+
const onAbort = () => {
|
|
35317
|
+
clearTimeout(timer);
|
|
35318
|
+
reject(abortError2(signal));
|
|
35319
|
+
};
|
|
35320
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
35321
|
+
});
|
|
35322
|
+
}
|
|
35323
|
+
function timeoutError(latest, timeoutMs) {
|
|
35324
|
+
return new DerivativeQuestionTimeoutError(
|
|
35325
|
+
`Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
|
|
35326
|
+
{
|
|
35327
|
+
derivedScope: latest.derivedScope,
|
|
35328
|
+
status: latest.status,
|
|
35329
|
+
errorCode: latest.errorCode,
|
|
35330
|
+
retryAfterSeconds: latest.retryAfterSeconds,
|
|
35331
|
+
timeoutMs
|
|
35332
|
+
}
|
|
35333
|
+
);
|
|
35334
|
+
}
|
|
35335
|
+
function abortError2(signal) {
|
|
35336
|
+
const reason = signal?.reason;
|
|
35337
|
+
return reason instanceof Error ? reason : new WriteRequestError("Derivative status wait was aborted");
|
|
35338
|
+
}
|
|
35339
|
+
function isDerivativeStatusSettled(status) {
|
|
35340
|
+
if (status.status === "ready") return true;
|
|
35341
|
+
return status.status === "failed" && status.retryAfterSeconds === null;
|
|
35342
|
+
}
|
|
35343
|
+
async function getDerivativeStatus(params) {
|
|
35344
|
+
const derivedScope = requireDerivedScope(params.derivedScope);
|
|
35345
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
35346
|
+
const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
|
|
35347
|
+
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
35348
|
+
const headers = new Headers(params.headers);
|
|
35349
|
+
headers.set(
|
|
35350
|
+
"Authorization",
|
|
35351
|
+
await buildWeb3SignedHeader({
|
|
35352
|
+
signMessage: signer.signMessage,
|
|
35353
|
+
aud: params.audience ?? baseUrl,
|
|
35354
|
+
method: "GET",
|
|
35355
|
+
uri: DERIVATIVE_STATUS_PATH,
|
|
35356
|
+
grantId: params.grantId
|
|
35357
|
+
})
|
|
35358
|
+
);
|
|
35359
|
+
let response;
|
|
35360
|
+
try {
|
|
35361
|
+
response = await fetchFn(
|
|
35362
|
+
`${baseUrl}${derivativeStatusTarget(derivedScope)}`,
|
|
35363
|
+
{
|
|
35364
|
+
method: "GET",
|
|
35365
|
+
headers,
|
|
35366
|
+
...params.signal ? { signal: params.signal } : {}
|
|
35367
|
+
}
|
|
35368
|
+
);
|
|
35369
|
+
} catch (err) {
|
|
35370
|
+
throw new WriteTransportError(
|
|
35371
|
+
`Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
35372
|
+
1,
|
|
35373
|
+
err
|
|
35374
|
+
);
|
|
35375
|
+
}
|
|
35376
|
+
if (!response.ok) {
|
|
35377
|
+
throw await personalServerErrorFromQuestionResponse(
|
|
35378
|
+
response
|
|
35379
|
+
);
|
|
35380
|
+
}
|
|
35381
|
+
let body;
|
|
35382
|
+
try {
|
|
35383
|
+
body = await response.json();
|
|
35384
|
+
} catch (err) {
|
|
35385
|
+
throw new DerivativeQuestionRejectedError(
|
|
35386
|
+
"Derivative status response is not JSON",
|
|
35387
|
+
response.status,
|
|
35388
|
+
null,
|
|
35389
|
+
{ cause: err instanceof Error ? err.message : String(err) }
|
|
35390
|
+
);
|
|
35391
|
+
}
|
|
35392
|
+
const parsed = DerivativeStatusSchema.safeParse(body);
|
|
35393
|
+
if (!parsed.success) {
|
|
35394
|
+
throw new DerivativeQuestionRejectedError(
|
|
35395
|
+
"Derivative status response is not a status view",
|
|
35396
|
+
response.status,
|
|
35397
|
+
null,
|
|
35398
|
+
{ issues: parsed.error.issues }
|
|
35399
|
+
);
|
|
35400
|
+
}
|
|
35401
|
+
return parsed.data;
|
|
35402
|
+
}
|
|
35403
|
+
async function waitForDerivativeStatus(params) {
|
|
35404
|
+
const timeoutMs = Math.max(
|
|
35405
|
+
0,
|
|
35406
|
+
params.timeoutMs ?? DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS
|
|
35407
|
+
);
|
|
35408
|
+
const pollIntervalMs = Math.max(
|
|
35409
|
+
0,
|
|
35410
|
+
params.pollIntervalMs ?? DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS
|
|
35411
|
+
);
|
|
35412
|
+
const deadline = Date.now() + timeoutMs;
|
|
35413
|
+
for (; ; ) {
|
|
35414
|
+
if (params.signal?.aborted) throw abortError2(params.signal);
|
|
35415
|
+
const latest = await getDerivativeStatus(params);
|
|
35416
|
+
if (isDerivativeStatusSettled(latest)) return latest;
|
|
35417
|
+
const remaining = deadline - Date.now();
|
|
35418
|
+
if (remaining <= 0) throw timeoutError(latest, timeoutMs);
|
|
35419
|
+
const waitMs = latest.retryAfterSeconds === null ? pollIntervalMs : latest.retryAfterSeconds * 1e3;
|
|
35420
|
+
if (waitMs > remaining) {
|
|
35421
|
+
throw timeoutError(latest, timeoutMs);
|
|
35422
|
+
}
|
|
35423
|
+
await sleep3(waitMs, params.signal);
|
|
35424
|
+
}
|
|
35425
|
+
}
|
|
35426
|
+
|
|
35097
35427
|
// src/protocol/gateway.ts
|
|
35098
35428
|
function withGrantPermissions(grant) {
|
|
35099
35429
|
const stripped = { ...grant };
|
|
@@ -36175,9 +36505,13 @@ async function parsePSError(response) {
|
|
|
36175
36505
|
ContractNotFoundError,
|
|
36176
36506
|
DATA_ACCESS_OP_TYPE,
|
|
36177
36507
|
DATA_REGISTRY_STATUS_ABI,
|
|
36508
|
+
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
36509
|
+
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
36178
36510
|
DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
36179
36511
|
DEFAULT_QUESTION_TIMEOUT_MS,
|
|
36512
|
+
DERIVATIVE_ERROR_CODES,
|
|
36180
36513
|
DERIVATIVE_QUESTIONS_PATH,
|
|
36514
|
+
DERIVATIVE_STATUS_PATH,
|
|
36181
36515
|
DataFileEnvelopeSchema,
|
|
36182
36516
|
DataPointDeletedError,
|
|
36183
36517
|
DataPointNotFoundError,
|
|
@@ -36186,6 +36520,7 @@ async function parsePSError(response) {
|
|
|
36186
36520
|
DerivativeComputeUnavailableError,
|
|
36187
36521
|
DerivativeCycleError,
|
|
36188
36522
|
DerivativeDerivedScopeRequiredError,
|
|
36523
|
+
DerivativeErrorCodeSchema,
|
|
36189
36524
|
DerivativeQuestionFailedError,
|
|
36190
36525
|
DerivativeQuestionInvalidError,
|
|
36191
36526
|
DerivativeQuestionNotFoundError,
|
|
@@ -36193,8 +36528,12 @@ async function parsePSError(response) {
|
|
|
36193
36528
|
DerivativeQuestionSchema,
|
|
36194
36529
|
DerivativeQuestionTimeoutError,
|
|
36195
36530
|
DerivativeSourceNotGrantedError,
|
|
36531
|
+
DerivativeStatusSchema,
|
|
36196
36532
|
DropboxStorage,
|
|
36197
36533
|
ECIESError,
|
|
36534
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
36535
|
+
ENCLAVE_TRUST_ANCHORS,
|
|
36536
|
+
ENCLAVE_WALLET_PURPOSE,
|
|
36198
36537
|
ESCROW_DEPOSIT_ABI,
|
|
36199
36538
|
ExpiredTokenError,
|
|
36200
36539
|
FEE_REGISTRY_ABI,
|
|
@@ -36216,6 +36555,7 @@ async function parsePSError(response) {
|
|
|
36216
36555
|
LineageNodeSchema,
|
|
36217
36556
|
LineageReadError,
|
|
36218
36557
|
MASTER_KEY_MESSAGE,
|
|
36558
|
+
MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
36219
36559
|
MAX_LINEAGE_SOURCES,
|
|
36220
36560
|
MAX_QUESTION_CHARS,
|
|
36221
36561
|
MAX_QUESTION_MODEL_CHARS,
|
|
@@ -36253,6 +36593,7 @@ async function parsePSError(response) {
|
|
|
36253
36593
|
RedactedLineageNodeSchema,
|
|
36254
36594
|
RelayerError,
|
|
36255
36595
|
SCOPE_ACTIONS,
|
|
36596
|
+
SEALED_ENVELOPE_VERSION,
|
|
36256
36597
|
SERVER_REGISTRATION_TYPES,
|
|
36257
36598
|
ScopeSchema,
|
|
36258
36599
|
SerializationError,
|
|
@@ -36265,6 +36606,7 @@ async function parsePSError(response) {
|
|
|
36265
36606
|
TOMBSTONE_METADATA_HASH,
|
|
36266
36607
|
TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
36267
36608
|
TransactionPendingError,
|
|
36609
|
+
USER_PS_ID_DOMAIN,
|
|
36268
36610
|
UserRejectedRequestError,
|
|
36269
36611
|
VanaError,
|
|
36270
36612
|
VanaStorage,
|
|
@@ -36283,6 +36625,7 @@ async function parsePSError(response) {
|
|
|
36283
36625
|
WriteSessionExpiredError,
|
|
36284
36626
|
WriteTransportError,
|
|
36285
36627
|
WriteUnauthorizedError,
|
|
36628
|
+
appRootPreimage,
|
|
36286
36629
|
askPersonalServer,
|
|
36287
36630
|
assertDerivedScopeNaming,
|
|
36288
36631
|
assertValidPkceVerifier,
|
|
@@ -36296,6 +36639,7 @@ async function parsePSError(response) {
|
|
|
36296
36639
|
buildEscrowPaymentHeader,
|
|
36297
36640
|
buildGrantPaymentHeader,
|
|
36298
36641
|
buildMarkDataPointUnavailableRequest,
|
|
36642
|
+
buildMasterSignatureDelivery,
|
|
36299
36643
|
buildPersonalServerDataReadRequest,
|
|
36300
36644
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
36301
36645
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -36328,6 +36672,7 @@ async function parsePSError(response) {
|
|
|
36328
36672
|
decryptWithPassword,
|
|
36329
36673
|
deleteDataPoint,
|
|
36330
36674
|
deleteQuestion,
|
|
36675
|
+
derivativeStatusTarget,
|
|
36331
36676
|
deriveDataPointId,
|
|
36332
36677
|
deriveMasterKey,
|
|
36333
36678
|
deriveScopeKey,
|
|
@@ -36338,6 +36683,7 @@ async function parsePSError(response) {
|
|
|
36338
36683
|
encodeDepositTokenData,
|
|
36339
36684
|
encodeSetDataPointStatusData,
|
|
36340
36685
|
encodeWriteMetadataHeader,
|
|
36686
|
+
encryptMasterSignatureDelivery,
|
|
36341
36687
|
encryptWithPassword,
|
|
36342
36688
|
escrowContractAddress,
|
|
36343
36689
|
escrowPaymentDomain,
|
|
@@ -36351,6 +36697,7 @@ async function parsePSError(response) {
|
|
|
36351
36697
|
getContractAddress,
|
|
36352
36698
|
getContractController,
|
|
36353
36699
|
getContractInfo,
|
|
36700
|
+
getDerivativeStatus,
|
|
36354
36701
|
getFee,
|
|
36355
36702
|
getGatewayLineage,
|
|
36356
36703
|
getLineage,
|
|
@@ -36366,10 +36713,12 @@ async function parsePSError(response) {
|
|
|
36366
36713
|
isDataPointId,
|
|
36367
36714
|
isDataPointTombstone,
|
|
36368
36715
|
isDataPortabilityGatewayConfig,
|
|
36716
|
+
isDerivativeStatusSettled,
|
|
36369
36717
|
isECIESEncrypted,
|
|
36370
36718
|
isPlatformSupported,
|
|
36371
36719
|
isRedactedLineageNode,
|
|
36372
36720
|
isTombstoneHashes,
|
|
36721
|
+
kmsIssuedPreimage,
|
|
36373
36722
|
listQuestions,
|
|
36374
36723
|
mainnetServices,
|
|
36375
36724
|
moksha,
|
|
@@ -36409,10 +36758,13 @@ async function parsePSError(response) {
|
|
|
36409
36758
|
toDirectPaymentReceipt,
|
|
36410
36759
|
tombstoneDeletedAt,
|
|
36411
36760
|
tryGrantPermissions,
|
|
36761
|
+
userPsId,
|
|
36412
36762
|
vanaMainnet,
|
|
36763
|
+
verifyEnclaveIdentityEvidence,
|
|
36413
36764
|
verifyGrantRegistration,
|
|
36414
36765
|
verifyPkceChallenge,
|
|
36415
36766
|
verifyWeb3Signed,
|
|
36767
|
+
waitForDerivativeStatus,
|
|
36416
36768
|
waitForQuestion,
|
|
36417
36769
|
writeData,
|
|
36418
36770
|
writePersonalServerData
|