@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.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export { generatePkceVerifier, computePkceChallenge, verifyPkceChallenge, assert
|
|
|
37
37
|
export { InMemoryTokenStore, type TokenStore, type TokenRecord, } from "./auth/token-store.js";
|
|
38
38
|
export { OAuthClient, type OAuthClientConfig, type AuthorizationUrlResult, } from "./auth/oauth-client.js";
|
|
39
39
|
export { NATIVE_VANA_ASSET, dataRegistryDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, escrowPaymentDomain, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, ADD_DATA_TYPES, RECORD_DATA_ACCESS_TYPES, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, type AddDataMessage, type RecordDataAccessMessage, } from "./protocol/eip712.js";
|
|
40
|
+
export { ENCLAVE_IDENTITY_EVIDENCE_VERSION, USER_PS_ID_DOMAIN, ENCLAVE_WALLET_PURPOSE, MASTER_SIGNATURE_DELIVERY_VERSION, SEALED_ENVELOPE_VERSION, ENCLAVE_TRUST_ANCHORS, userPsId, appRootPreimage, kmsIssuedPreimage, verifyEnclaveIdentityEvidence, buildMasterSignatureDelivery, encryptMasterSignatureDelivery, type UserPsId, type EnclaveIdentityEvidence, type ExpectedIdentity, type IdentityRequest, type IdentityState, type IdentityResponse, type IdentityRegistrationRequest, type IdentityRegistrationResponse, type MasterSignatureDelivery, type SealedSecretSubmission, type SealedSecretResponse, type AesGcmBox, type SealedEnvelope, type EnclaveTrustAnchors, } from "./protocol/identity.js";
|
|
40
41
|
export { PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID, PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT, personalServerRegistrationDomain, createViemPersonalServerRegistrationSigner, buildPersonalServerRegistrationTypedData, buildPersonalServerRegistrationSignature, registerPersonalServerSignature, type PersonalServerRegistrationTypedData, type PersonalServerRegistrationSigner, type PersonalServerRegistrationDomainInput, type ViemPersonalServerRegistrationWalletClient, type ViemPersonalServerRegistrationSignerSource, type BuildPersonalServerRegistrationTypedDataInput, type BuildPersonalServerRegistrationSignatureInput, type PersonalServerRegistrationSignature, } from "./protocol/personal-server-registration.js";
|
|
41
42
|
export { PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION, PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE, PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX, buildPersonalServerLiteOwnerBindingMessage, createViemPersonalServerLiteOwnerBindingSigner, buildPersonalServerLiteOwnerBindingSignature, signPersonalServerLiteOwnerBinding, type PersonalServerLiteOwnerBindingPurpose, type PersonalServerLiteOwnerBindingMessage, type PersonalServerLiteOwnerBindingSigner, type ViemPersonalServerLiteOwnerBindingWalletClient, type ViemPersonalServerLiteOwnerBindingSignerSource, type BuildPersonalServerLiteOwnerBindingSignatureInput, type PersonalServerLiteOwnerBindingSignature, } from "./personal-server-lite/owner-binding.js";
|
|
42
43
|
export { ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT, AccountPersonalServerRegistrationError, signPersonalServerRegistrationWithAccount, type AccountPersonalServerRegistrationIntent, type AccountPersonalServerRegistrationSignature, type AccountPersonalServerRegistrationStatus, type AccountPersonalServerRegistrationRequest, type AccountPersonalServerRegistrationConfig, type AccountSignedPersonalServerRegistration, type AccountConfirmationRequiredPersonalServerRegistration, type AccountFallbackSignedPersonalServerRegistration, type AccountPersonalServerRegistrationResult, } from "./account/personal-server-registration.js";
|
|
@@ -51,7 +52,8 @@ export { ScopeSchema, parseScope, scopeToPathSegments, scopeMatchesPattern, scop
|
|
|
51
52
|
export { SCOPE_ACTIONS, InvalidScopeEntryError, parseScopeEntry, formatScopeEntry, grantPermissions, permissionsToScopes, tryGrantPermissions, hasAction, type ScopeAction, type ParsedScopeEntry, type GrantPermission, } from "./protocol/scope-actions.js";
|
|
52
53
|
export { WRITE_SESSION_PATH, WRITE_SIGNATURE_HEADER, WRITE_METADATA_HEADER, WRITE_FILENAME_HEADER, WRITE_CONTENT_DISPOSITION_HEADER, WRITER_ATTRIBUTION_KEY, LINEAGE_KEY, LINEAGE_FIELD, MAX_LINEAGE_SOURCES, RESERVED_WRITE_KEYS, openWriteSession, writeData, writePersonalServerData, sessionCoversScope, binaryWriteSignedBytes, normalizeBinaryMimeType, parseWriteMetadataHeader, encodeWriteMetadataHeader, type WriteTransportRetryOptions, type WriteSession, type OpenWriteSessionParams, type WriteBinaryPayload, type LineageSource, type WriteJsonDataParams, type WriteBinaryDataParams, type WriteDataParams, type WriteDataResult, type WritePersonalServerDataParams, type WritePersonalServerDataResult, type BinaryWriteSignedBytesInput, } from "./protocol/personal-server-write.js";
|
|
53
54
|
export { resolveWriteSigner, type WriteSigner, type WriteSignerSource, type ViemWriteAccount, type ViemWriteWalletClient, type ResolveWriteSignerOptions, } from "./protocol/write-signer.js";
|
|
54
|
-
export { DERIVATIVE_QUESTIONS_PATH, MAX_QUESTION_SOURCE_SCOPES, MAX_QUESTION_CHARS, MAX_QUESTION_MODEL_CHARS, DEFAULT_QUESTION_TIMEOUT_MS, DEFAULT_QUESTION_POLL_INTERVAL_MS, QUESTION_STATUSES, registerQuestion, getQuestion, listQuestions, recomputeQuestion, deleteQuestion, waitForQuestion, askPersonalServer, QuestionStatusSchema, QuestionRegisteredBySchema, DerivativeQuestionSchema, QuestionRecomputeResultSchema, QuestionDeleteResultSchema, type QuestionStatus, type QuestionRegisteredBy, type DerivativeQuestion, type QuestionRecomputeResult, type QuestionDeleteResult, type DerivativeQuestionAuthParams, type RegisterQuestionParams, type GetQuestionParams, type ListQuestionsParams, type RecomputeQuestionParams, type DeleteQuestionParams, type WaitForQuestionParams, type AskPersonalServerParams, type AskPersonalServerResult, } from "./protocol/derivative-questions.js";
|
|
55
|
+
export { DERIVATIVE_QUESTIONS_PATH, MAX_QUESTION_SOURCE_SCOPES, MAX_QUESTION_CHARS, MAX_QUESTION_MODEL_CHARS, DEFAULT_QUESTION_TIMEOUT_MS, DEFAULT_QUESTION_POLL_INTERVAL_MS, QUESTION_STATUSES, DERIVATIVE_ERROR_CODES, DerivativeErrorCodeSchema, type DerivativeErrorCode, registerQuestion, getQuestion, listQuestions, recomputeQuestion, deleteQuestion, waitForQuestion, askPersonalServer, QuestionStatusSchema, QuestionRegisteredBySchema, DerivativeQuestionSchema, QuestionRecomputeResultSchema, QuestionDeleteResultSchema, type QuestionStatus, type QuestionRegisteredBy, type DerivativeQuestion, type QuestionRecomputeResult, type QuestionDeleteResult, type DerivativeQuestionAuthParams, type RegisterQuestionParams, type GetQuestionParams, type ListQuestionsParams, type RecomputeQuestionParams, type DeleteQuestionParams, type WaitForQuestionParams, type AskPersonalServerParams, type AskPersonalServerResult, } from "./protocol/derivative-questions.js";
|
|
56
|
+
export { DERIVATIVE_STATUS_PATH, DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS, DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS, derivativeStatusTarget, getDerivativeStatus, waitForDerivativeStatus, isDerivativeStatusSettled, DerivativeStatusSchema, type DerivativeStatus, type GetDerivativeStatusParams, type WaitForDerivativeStatusParams, } from "./protocol/derivative-status.js";
|
|
55
57
|
export { deriveDataPointId, isDataPointId, scopeNamespace, derivedScopeViolatesNaming, assertDerivedScopeNaming, isRedactedLineageNode, personalServerLineagePath, gatewayLineagePath, getLineage, getPersonalServerLineage, getGatewayLineage, LineageNodeSchema, RedactedLineageNodeSchema, LineageEntrySchema, LineageGraphSchema, type LineageNode, type RedactedLineageNode, type LineageEntry, type LineageGraph, type LineageReadResult, type PersonalServerLineageParams, type GatewayLineageParams, type GetLineageParams, } from "./protocol/lineage.js";
|
|
56
58
|
export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file.js";
|
|
57
59
|
export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type OwnerServerRecord, type OwnerServersResult, type GatewayGrantFee, type GatewayGrantStatus, type GatewayGrantResponse, type GrantListItem, type DataPointRecord, type DataPointListResult, type ListDataPointsOptions, type RegisterServerParams, type RegisterServerResult, type RegisterBuilderParams, type RegisterBuilderResult, type RegisterDataPointParams, type RegisterDataPointResult, type GetDataPointOptions, type DeleteDataPointParams, type DeleteDataPointResult, type CreateGrantParams, type RevokeGrantParams, type AccessRecord, type PayForOperationParams, type PayForOperationResult, type SettleOpType, type SettleItem, type SettlePromoteResult, type SettleReconcileItem, type SettleParams, type SettleResult, type GatewayClient, } from "./protocol/gateway.js";
|
package/dist/index.node.js
CHANGED
|
@@ -31347,13 +31347,13 @@ var NodeCryptoAdapter = class {
|
|
|
31347
31347
|
*/
|
|
31348
31348
|
async generateKeyPair() {
|
|
31349
31349
|
try {
|
|
31350
|
-
const
|
|
31350
|
+
const secp256k15 = secp256k1Import2;
|
|
31351
31351
|
let privateKey;
|
|
31352
31352
|
do {
|
|
31353
31353
|
privateKey = randomBytes2(32);
|
|
31354
|
-
} while (!
|
|
31354
|
+
} while (!secp256k15.privateKeyVerify(privateKey));
|
|
31355
31355
|
const publicKey = Buffer.from(
|
|
31356
|
-
|
|
31356
|
+
secp256k15.publicKeyCreate(privateKey, true)
|
|
31357
31357
|
);
|
|
31358
31358
|
return {
|
|
31359
31359
|
privateKey: privateKey.toString("hex"),
|
|
@@ -32363,6 +32363,151 @@ var RECORD_DATA_ACCESS_TYPES = {
|
|
|
32363
32363
|
]
|
|
32364
32364
|
};
|
|
32365
32365
|
|
|
32366
|
+
// src/protocol/identity.ts
|
|
32367
|
+
init_interface();
|
|
32368
|
+
import * as secp256k14 from "@noble/secp256k1";
|
|
32369
|
+
import {
|
|
32370
|
+
concat as concat4,
|
|
32371
|
+
encodePacked,
|
|
32372
|
+
fromHex as fromHex5,
|
|
32373
|
+
getAddress,
|
|
32374
|
+
isAddressEqual,
|
|
32375
|
+
keccak256,
|
|
32376
|
+
recoverPublicKey,
|
|
32377
|
+
toBytes,
|
|
32378
|
+
toHex as toHex7
|
|
32379
|
+
} from "viem";
|
|
32380
|
+
import { publicKeyToAddress } from "viem/accounts";
|
|
32381
|
+
var ENCLAVE_IDENTITY_EVIDENCE_VERSION = 1;
|
|
32382
|
+
var USER_PS_ID_DOMAIN = "vana.ps-enclave.v1";
|
|
32383
|
+
var ENCLAVE_WALLET_PURPOSE = "vana.ps-enclave.wallet.v1";
|
|
32384
|
+
var MASTER_SIGNATURE_DELIVERY_VERSION = "vana.ps-enclave.delivery.v1";
|
|
32385
|
+
var SEALED_ENVELOPE_VERSION = 1;
|
|
32386
|
+
var VANA_MAINNET_CHAIN_ID = 1480;
|
|
32387
|
+
var MOKSHA_CHAIN_ID = 14800;
|
|
32388
|
+
var KMS_ISSUED_PREFIX = "dstack-kms-issued";
|
|
32389
|
+
var PREIMAGE_SEPARATOR = ":";
|
|
32390
|
+
var UNCOMPRESSED_PUBLIC_KEY_BYTES = 65;
|
|
32391
|
+
var UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04";
|
|
32392
|
+
var ENCLAVE_TRUST_ANCHORS = {
|
|
32393
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32394
|
+
[VANA_MAINNET_CHAIN_ID]: { kmsRootPubkey: "0x", appIds: [] },
|
|
32395
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32396
|
+
[MOKSHA_CHAIN_ID]: { kmsRootPubkey: "0x", appIds: [] }
|
|
32397
|
+
};
|
|
32398
|
+
function userPsId(chainId, ownerAddress) {
|
|
32399
|
+
const packed = encodePacked(
|
|
32400
|
+
["string", "uint256", "address"],
|
|
32401
|
+
[USER_PS_ID_DOMAIN, BigInt(chainId), getAddress(ownerAddress)]
|
|
32402
|
+
);
|
|
32403
|
+
return keccak256(packed);
|
|
32404
|
+
}
|
|
32405
|
+
function compressPublicKey(publicKey) {
|
|
32406
|
+
return secp256k14.ProjectivePoint.fromHex(
|
|
32407
|
+
fromHex5(publicKey, "bytes")
|
|
32408
|
+
).toRawBytes(true);
|
|
32409
|
+
}
|
|
32410
|
+
function appRootPreimage(purpose, publicKey) {
|
|
32411
|
+
const keyHex = toHex7(compressPublicKey(publicKey)).slice(2);
|
|
32412
|
+
return keccak256(toBytes(`${purpose}${PREIMAGE_SEPARATOR}${keyHex}`));
|
|
32413
|
+
}
|
|
32414
|
+
function kmsIssuedPreimage(appId, appRootPublicKey) {
|
|
32415
|
+
const prefix = concat4([
|
|
32416
|
+
toBytes(`${KMS_ISSUED_PREFIX}${PREIMAGE_SEPARATOR}`),
|
|
32417
|
+
fromHex5(appId, "bytes")
|
|
32418
|
+
]);
|
|
32419
|
+
const compressed = compressPublicKey(appRootPublicKey);
|
|
32420
|
+
return keccak256(concat4([prefix, compressed]));
|
|
32421
|
+
}
|
|
32422
|
+
async function recoverChainKey(hash, signature, link) {
|
|
32423
|
+
try {
|
|
32424
|
+
return (await recoverPublicKey({ hash, signature })).toLowerCase();
|
|
32425
|
+
} catch {
|
|
32426
|
+
throw new Error(`Invalid enclave signature chain link ${link}`);
|
|
32427
|
+
}
|
|
32428
|
+
}
|
|
32429
|
+
async function verifyEnclaveIdentityEvidence(evidence, anchors, expected) {
|
|
32430
|
+
if (evidence.v !== ENCLAVE_IDENTITY_EVIDENCE_VERSION) {
|
|
32431
|
+
throw new Error("Unsupported enclave identity evidence version");
|
|
32432
|
+
}
|
|
32433
|
+
if (!Number.isInteger(evidence.epoch) || evidence.epoch < 1) {
|
|
32434
|
+
throw new Error("Invalid enclave identity epoch");
|
|
32435
|
+
}
|
|
32436
|
+
if (evidence.chainId !== expected.chainId) {
|
|
32437
|
+
throw new Error(
|
|
32438
|
+
"Enclave identity chain ID does not match expected chain ID"
|
|
32439
|
+
);
|
|
32440
|
+
}
|
|
32441
|
+
if (!isAddressEqual(evidence.ownerAddress, expected.ownerAddress)) {
|
|
32442
|
+
throw new Error("Enclave identity owner does not match expected owner");
|
|
32443
|
+
}
|
|
32444
|
+
if (evidence.epoch !== expected.epoch) {
|
|
32445
|
+
throw new Error("Enclave identity epoch does not match expected epoch");
|
|
32446
|
+
}
|
|
32447
|
+
const expectedUserPsId = userPsId(expected.chainId, expected.ownerAddress);
|
|
32448
|
+
if (evidence.userPsId.toLowerCase() !== expectedUserPsId.toLowerCase()) {
|
|
32449
|
+
throw new Error("Enclave userPsId does not match expected identity");
|
|
32450
|
+
}
|
|
32451
|
+
if (evidence.purpose !== ENCLAVE_WALLET_PURPOSE) {
|
|
32452
|
+
throw new Error("Unexpected enclave wallet purpose");
|
|
32453
|
+
}
|
|
32454
|
+
const derivedAddress = publicKeyToAddress(evidence.publicKey);
|
|
32455
|
+
if (getAddress(derivedAddress) !== getAddress(evidence.address)) {
|
|
32456
|
+
throw new Error("Enclave public key does not match its address");
|
|
32457
|
+
}
|
|
32458
|
+
const appRootPublicKey = await recoverChainKey(
|
|
32459
|
+
appRootPreimage(evidence.purpose, evidence.publicKey),
|
|
32460
|
+
evidence.signatureChain[0],
|
|
32461
|
+
0
|
|
32462
|
+
);
|
|
32463
|
+
const kmsRootPublicKey = await recoverChainKey(
|
|
32464
|
+
kmsIssuedPreimage(evidence.appId, appRootPublicKey),
|
|
32465
|
+
evidence.signatureChain[1],
|
|
32466
|
+
1
|
|
32467
|
+
);
|
|
32468
|
+
if (anchors.kmsRootPubkey === "0x") {
|
|
32469
|
+
throw new Error("KMS root trust anchor is not provisioned");
|
|
32470
|
+
}
|
|
32471
|
+
if (kmsRootPublicKey !== anchors.kmsRootPubkey.toLowerCase()) {
|
|
32472
|
+
throw new Error("KMS root public key does not match the trust anchor");
|
|
32473
|
+
}
|
|
32474
|
+
if (keccak256(kmsRootPublicKey) !== evidence.kmsRootFingerprint.toLowerCase()) {
|
|
32475
|
+
throw new Error("KMS root fingerprint does not match the evidence");
|
|
32476
|
+
}
|
|
32477
|
+
const appId = evidence.appId.toLowerCase();
|
|
32478
|
+
if (!anchors.appIds.some((allowedAppId) => allowedAppId.toLowerCase() === appId)) {
|
|
32479
|
+
throw new Error("Enclave app ID is not trusted");
|
|
32480
|
+
}
|
|
32481
|
+
}
|
|
32482
|
+
async function buildMasterSignatureDelivery(evidence, masterSignature, now = Math.floor(Date.now() / 1e3)) {
|
|
32483
|
+
deriveMasterKey(masterSignature);
|
|
32484
|
+
const signerAddress = await recoverServerOwner(masterSignature);
|
|
32485
|
+
if (!isAddressEqual(signerAddress, evidence.ownerAddress)) {
|
|
32486
|
+
throw new Error("Master signature signer does not match evidence owner");
|
|
32487
|
+
}
|
|
32488
|
+
return {
|
|
32489
|
+
v: MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
32490
|
+
userPsId: evidence.userPsId,
|
|
32491
|
+
epoch: evidence.epoch,
|
|
32492
|
+
enclaveAddress: evidence.address,
|
|
32493
|
+
ownerAddress: evidence.ownerAddress,
|
|
32494
|
+
masterSignature,
|
|
32495
|
+
issuedAt: now
|
|
32496
|
+
};
|
|
32497
|
+
}
|
|
32498
|
+
function assertUncompressedKey(publicKey) {
|
|
32499
|
+
const hex = publicKey.slice(2);
|
|
32500
|
+
if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
32501
|
+
throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
|
|
32502
|
+
}
|
|
32503
|
+
}
|
|
32504
|
+
async function encryptMasterSignatureDelivery(delivery, publicKey, ecies) {
|
|
32505
|
+
assertUncompressedKey(publicKey);
|
|
32506
|
+
const plaintext = toBytes(JSON.stringify(delivery));
|
|
32507
|
+
const encrypted = await ecies.encrypt(fromHex5(publicKey, "bytes"), plaintext);
|
|
32508
|
+
return `0x${serializeECIES(encrypted)}`;
|
|
32509
|
+
}
|
|
32510
|
+
|
|
32366
32511
|
// src/protocol/personal-server-registration.ts
|
|
32367
32512
|
import {
|
|
32368
32513
|
isAddress
|
|
@@ -33062,7 +33207,7 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
33062
33207
|
// src/protocol/data-point-deletion.ts
|
|
33063
33208
|
import {
|
|
33064
33209
|
isAddress as isAddress5,
|
|
33065
|
-
keccak256 as
|
|
33210
|
+
keccak256 as keccak2563,
|
|
33066
33211
|
maxUint256,
|
|
33067
33212
|
stringToBytes as stringToBytes3
|
|
33068
33213
|
} from "viem";
|
|
@@ -33071,7 +33216,7 @@ import {
|
|
|
33071
33216
|
import {
|
|
33072
33217
|
encodeAbiParameters,
|
|
33073
33218
|
isAddress as isAddress4,
|
|
33074
|
-
keccak256
|
|
33219
|
+
keccak256 as keccak2562
|
|
33075
33220
|
} from "viem";
|
|
33076
33221
|
import { z } from "zod";
|
|
33077
33222
|
|
|
@@ -33155,7 +33300,7 @@ function deriveDataPointId(ownerAddress, scope) {
|
|
|
33155
33300
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
33156
33301
|
);
|
|
33157
33302
|
}
|
|
33158
|
-
return
|
|
33303
|
+
return keccak2562(
|
|
33159
33304
|
encodeAbiParameters(
|
|
33160
33305
|
[
|
|
33161
33306
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -33382,7 +33527,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
33382
33527
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
33383
33528
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
33384
33529
|
function computeTombstoneHash(preimage) {
|
|
33385
|
-
return
|
|
33530
|
+
return keccak2563(stringToBytes3(preimage));
|
|
33386
33531
|
}
|
|
33387
33532
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
33388
33533
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -34404,6 +34549,13 @@ var QUESTION_STATUSES = [
|
|
|
34404
34549
|
"failed",
|
|
34405
34550
|
"stale"
|
|
34406
34551
|
];
|
|
34552
|
+
var DERIVATIVE_ERROR_CODES = [
|
|
34553
|
+
"inference_unavailable",
|
|
34554
|
+
"source_missing",
|
|
34555
|
+
"grant_invalid",
|
|
34556
|
+
"internal"
|
|
34557
|
+
];
|
|
34558
|
+
var DerivativeErrorCodeSchema = z5.enum(DERIVATIVE_ERROR_CODES);
|
|
34407
34559
|
var QuestionStatusSchema = z5.enum(QUESTION_STATUSES);
|
|
34408
34560
|
var QuestionRegisteredBySchema = z5.union([
|
|
34409
34561
|
z5.object({ kind: z5.literal("owner") }),
|
|
@@ -34425,6 +34577,14 @@ var DerivativeQuestionSchema = z5.object({
|
|
|
34425
34577
|
status: QuestionStatusSchema,
|
|
34426
34578
|
/** A short reason, set only while `status` is `failed`. */
|
|
34427
34579
|
error: nullableString,
|
|
34580
|
+
/**
|
|
34581
|
+
* The coarse failure class behind `error`, set only while `status` is
|
|
34582
|
+
* `failed`. `null` from a Personal Server that predates the class
|
|
34583
|
+
* (`personal-server-ts` before the status route).
|
|
34584
|
+
*/
|
|
34585
|
+
errorCode: DerivativeErrorCodeSchema.nullish().transform(
|
|
34586
|
+
(value) => value ?? null
|
|
34587
|
+
),
|
|
34428
34588
|
createdAt: z5.string(),
|
|
34429
34589
|
updatedAt: nullableString,
|
|
34430
34590
|
/** When the last compute finished, or `null` while `pending`. */
|
|
@@ -34557,6 +34717,7 @@ async function questionErrorFromResponse(response, body) {
|
|
|
34557
34717
|
);
|
|
34558
34718
|
}
|
|
34559
34719
|
}
|
|
34720
|
+
var personalServerErrorFromQuestionResponse = questionErrorFromResponse;
|
|
34560
34721
|
async function sendOnce(params, resolved, session, spec, bodyBytes) {
|
|
34561
34722
|
return sendWithFreshProof(
|
|
34562
34723
|
spec.label,
|
|
@@ -34836,6 +34997,166 @@ async function askPersonalServer(params) {
|
|
|
34836
34997
|
return { registration, record };
|
|
34837
34998
|
}
|
|
34838
34999
|
|
|
35000
|
+
// src/protocol/derivative-status.ts
|
|
35001
|
+
import { z as z6 } from "zod";
|
|
35002
|
+
var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
|
|
35003
|
+
var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
|
|
35004
|
+
var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
|
|
35005
|
+
var nullable = (schema) => schema.nullish().transform((value) => value ?? null);
|
|
35006
|
+
var DerivativeStatusSchema = z6.object({
|
|
35007
|
+
derivedScope: z6.string().min(1),
|
|
35008
|
+
status: QuestionStatusSchema,
|
|
35009
|
+
/** When the last compute finished, or `null` if none ever has. */
|
|
35010
|
+
lastComputedAt: nullable(z6.string()),
|
|
35011
|
+
/** Local version of the derived record the last compute wrote. */
|
|
35012
|
+
derivedVersion: nullable(z6.number()),
|
|
35013
|
+
derivedCollectedAt: nullable(z6.string()),
|
|
35014
|
+
/** The failure class; `null` unless `status` is `failed`. */
|
|
35015
|
+
errorCode: nullable(DerivativeErrorCodeSchema),
|
|
35016
|
+
/**
|
|
35017
|
+
* Seconds until the Personal Server's next automatic retry, or `null` when
|
|
35018
|
+
* none is pending or running — the terminal signature. Poll on this cadence
|
|
35019
|
+
* rather than guessing one.
|
|
35020
|
+
*/
|
|
35021
|
+
retryAfterSeconds: nullable(z6.number())
|
|
35022
|
+
});
|
|
35023
|
+
function derivativeStatusTarget(derivedScope) {
|
|
35024
|
+
return `${DERIVATIVE_STATUS_PATH}?derivedScope=${encodeURIComponent(derivedScope)}`;
|
|
35025
|
+
}
|
|
35026
|
+
function normalizeBaseUrl3(url) {
|
|
35027
|
+
return url.replace(/\/+$/, "");
|
|
35028
|
+
}
|
|
35029
|
+
function resolveFetch3(fetchFn) {
|
|
35030
|
+
const resolved = fetchFn ?? globalThis.fetch;
|
|
35031
|
+
if (resolved === void 0) {
|
|
35032
|
+
throw new WriteRequestError("No fetch implementation available");
|
|
35033
|
+
}
|
|
35034
|
+
return resolved;
|
|
35035
|
+
}
|
|
35036
|
+
function requireDerivedScope(derivedScope) {
|
|
35037
|
+
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
35038
|
+
throw new WriteRequestError("derivedScope is required");
|
|
35039
|
+
}
|
|
35040
|
+
return derivedScope;
|
|
35041
|
+
}
|
|
35042
|
+
function sleep3(ms, signal) {
|
|
35043
|
+
if (ms <= 0) return Promise.resolve();
|
|
35044
|
+
return new Promise((resolve, reject) => {
|
|
35045
|
+
const timer = setTimeout(() => {
|
|
35046
|
+
signal?.removeEventListener("abort", onAbort);
|
|
35047
|
+
resolve();
|
|
35048
|
+
}, ms);
|
|
35049
|
+
const onAbort = () => {
|
|
35050
|
+
clearTimeout(timer);
|
|
35051
|
+
reject(abortError2(signal));
|
|
35052
|
+
};
|
|
35053
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
35054
|
+
});
|
|
35055
|
+
}
|
|
35056
|
+
function timeoutError(latest, timeoutMs) {
|
|
35057
|
+
return new DerivativeQuestionTimeoutError(
|
|
35058
|
+
`Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
|
|
35059
|
+
{
|
|
35060
|
+
derivedScope: latest.derivedScope,
|
|
35061
|
+
status: latest.status,
|
|
35062
|
+
errorCode: latest.errorCode,
|
|
35063
|
+
retryAfterSeconds: latest.retryAfterSeconds,
|
|
35064
|
+
timeoutMs
|
|
35065
|
+
}
|
|
35066
|
+
);
|
|
35067
|
+
}
|
|
35068
|
+
function abortError2(signal) {
|
|
35069
|
+
const reason = signal?.reason;
|
|
35070
|
+
return reason instanceof Error ? reason : new WriteRequestError("Derivative status wait was aborted");
|
|
35071
|
+
}
|
|
35072
|
+
function isDerivativeStatusSettled(status) {
|
|
35073
|
+
if (status.status === "ready") return true;
|
|
35074
|
+
return status.status === "failed" && status.retryAfterSeconds === null;
|
|
35075
|
+
}
|
|
35076
|
+
async function getDerivativeStatus(params) {
|
|
35077
|
+
const derivedScope = requireDerivedScope(params.derivedScope);
|
|
35078
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
35079
|
+
const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
|
|
35080
|
+
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
35081
|
+
const headers = new Headers(params.headers);
|
|
35082
|
+
headers.set(
|
|
35083
|
+
"Authorization",
|
|
35084
|
+
await buildWeb3SignedHeader({
|
|
35085
|
+
signMessage: signer.signMessage,
|
|
35086
|
+
aud: params.audience ?? baseUrl,
|
|
35087
|
+
method: "GET",
|
|
35088
|
+
uri: DERIVATIVE_STATUS_PATH,
|
|
35089
|
+
grantId: params.grantId
|
|
35090
|
+
})
|
|
35091
|
+
);
|
|
35092
|
+
let response;
|
|
35093
|
+
try {
|
|
35094
|
+
response = await fetchFn(
|
|
35095
|
+
`${baseUrl}${derivativeStatusTarget(derivedScope)}`,
|
|
35096
|
+
{
|
|
35097
|
+
method: "GET",
|
|
35098
|
+
headers,
|
|
35099
|
+
...params.signal ? { signal: params.signal } : {}
|
|
35100
|
+
}
|
|
35101
|
+
);
|
|
35102
|
+
} catch (err) {
|
|
35103
|
+
throw new WriteTransportError(
|
|
35104
|
+
`Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
35105
|
+
1,
|
|
35106
|
+
err
|
|
35107
|
+
);
|
|
35108
|
+
}
|
|
35109
|
+
if (!response.ok) {
|
|
35110
|
+
throw await personalServerErrorFromQuestionResponse(
|
|
35111
|
+
response
|
|
35112
|
+
);
|
|
35113
|
+
}
|
|
35114
|
+
let body;
|
|
35115
|
+
try {
|
|
35116
|
+
body = await response.json();
|
|
35117
|
+
} catch (err) {
|
|
35118
|
+
throw new DerivativeQuestionRejectedError(
|
|
35119
|
+
"Derivative status response is not JSON",
|
|
35120
|
+
response.status,
|
|
35121
|
+
null,
|
|
35122
|
+
{ cause: err instanceof Error ? err.message : String(err) }
|
|
35123
|
+
);
|
|
35124
|
+
}
|
|
35125
|
+
const parsed = DerivativeStatusSchema.safeParse(body);
|
|
35126
|
+
if (!parsed.success) {
|
|
35127
|
+
throw new DerivativeQuestionRejectedError(
|
|
35128
|
+
"Derivative status response is not a status view",
|
|
35129
|
+
response.status,
|
|
35130
|
+
null,
|
|
35131
|
+
{ issues: parsed.error.issues }
|
|
35132
|
+
);
|
|
35133
|
+
}
|
|
35134
|
+
return parsed.data;
|
|
35135
|
+
}
|
|
35136
|
+
async function waitForDerivativeStatus(params) {
|
|
35137
|
+
const timeoutMs = Math.max(
|
|
35138
|
+
0,
|
|
35139
|
+
params.timeoutMs ?? DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS
|
|
35140
|
+
);
|
|
35141
|
+
const pollIntervalMs = Math.max(
|
|
35142
|
+
0,
|
|
35143
|
+
params.pollIntervalMs ?? DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS
|
|
35144
|
+
);
|
|
35145
|
+
const deadline = Date.now() + timeoutMs;
|
|
35146
|
+
for (; ; ) {
|
|
35147
|
+
if (params.signal?.aborted) throw abortError2(params.signal);
|
|
35148
|
+
const latest = await getDerivativeStatus(params);
|
|
35149
|
+
if (isDerivativeStatusSettled(latest)) return latest;
|
|
35150
|
+
const remaining = deadline - Date.now();
|
|
35151
|
+
if (remaining <= 0) throw timeoutError(latest, timeoutMs);
|
|
35152
|
+
const waitMs = latest.retryAfterSeconds === null ? pollIntervalMs : latest.retryAfterSeconds * 1e3;
|
|
35153
|
+
if (waitMs > remaining) {
|
|
35154
|
+
throw timeoutError(latest, timeoutMs);
|
|
35155
|
+
}
|
|
35156
|
+
await sleep3(waitMs, params.signal);
|
|
35157
|
+
}
|
|
35158
|
+
}
|
|
35159
|
+
|
|
34839
35160
|
// src/protocol/gateway.ts
|
|
34840
35161
|
function withGrantPermissions(grant) {
|
|
34841
35162
|
const stripped = { ...grant };
|
|
@@ -35916,9 +36237,13 @@ export {
|
|
|
35916
36237
|
ContractNotFoundError,
|
|
35917
36238
|
DATA_ACCESS_OP_TYPE,
|
|
35918
36239
|
DATA_REGISTRY_STATUS_ABI,
|
|
36240
|
+
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
36241
|
+
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
35919
36242
|
DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
35920
36243
|
DEFAULT_QUESTION_TIMEOUT_MS,
|
|
36244
|
+
DERIVATIVE_ERROR_CODES,
|
|
35921
36245
|
DERIVATIVE_QUESTIONS_PATH,
|
|
36246
|
+
DERIVATIVE_STATUS_PATH,
|
|
35922
36247
|
DataFileEnvelopeSchema,
|
|
35923
36248
|
DataPointDeletedError,
|
|
35924
36249
|
DataPointNotFoundError,
|
|
@@ -35927,6 +36252,7 @@ export {
|
|
|
35927
36252
|
DerivativeComputeUnavailableError,
|
|
35928
36253
|
DerivativeCycleError,
|
|
35929
36254
|
DerivativeDerivedScopeRequiredError,
|
|
36255
|
+
DerivativeErrorCodeSchema,
|
|
35930
36256
|
DerivativeQuestionFailedError,
|
|
35931
36257
|
DerivativeQuestionInvalidError,
|
|
35932
36258
|
DerivativeQuestionNotFoundError,
|
|
@@ -35934,8 +36260,12 @@ export {
|
|
|
35934
36260
|
DerivativeQuestionSchema,
|
|
35935
36261
|
DerivativeQuestionTimeoutError,
|
|
35936
36262
|
DerivativeSourceNotGrantedError,
|
|
36263
|
+
DerivativeStatusSchema,
|
|
35937
36264
|
DropboxStorage,
|
|
35938
36265
|
ECIESError,
|
|
36266
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
36267
|
+
ENCLAVE_TRUST_ANCHORS,
|
|
36268
|
+
ENCLAVE_WALLET_PURPOSE,
|
|
35939
36269
|
ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
|
|
35940
36270
|
ExpiredTokenError,
|
|
35941
36271
|
FEE_REGISTRY_ABI,
|
|
@@ -35957,6 +36287,7 @@ export {
|
|
|
35957
36287
|
LineageNodeSchema,
|
|
35958
36288
|
LineageReadError,
|
|
35959
36289
|
MASTER_KEY_MESSAGE,
|
|
36290
|
+
MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
35960
36291
|
MAX_LINEAGE_SOURCES,
|
|
35961
36292
|
MAX_QUESTION_CHARS,
|
|
35962
36293
|
MAX_QUESTION_MODEL_CHARS,
|
|
@@ -35994,6 +36325,7 @@ export {
|
|
|
35994
36325
|
RedactedLineageNodeSchema,
|
|
35995
36326
|
RelayerError,
|
|
35996
36327
|
SCOPE_ACTIONS,
|
|
36328
|
+
SEALED_ENVELOPE_VERSION,
|
|
35997
36329
|
SERVER_REGISTRATION_TYPES,
|
|
35998
36330
|
ScopeSchema,
|
|
35999
36331
|
SerializationError,
|
|
@@ -36006,6 +36338,7 @@ export {
|
|
|
36006
36338
|
TOMBSTONE_METADATA_HASH,
|
|
36007
36339
|
TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
36008
36340
|
TransactionPendingError,
|
|
36341
|
+
USER_PS_ID_DOMAIN,
|
|
36009
36342
|
UserRejectedRequestError,
|
|
36010
36343
|
VanaError,
|
|
36011
36344
|
VanaStorage,
|
|
@@ -36024,6 +36357,7 @@ export {
|
|
|
36024
36357
|
WriteSessionExpiredError,
|
|
36025
36358
|
WriteTransportError,
|
|
36026
36359
|
WriteUnauthorizedError,
|
|
36360
|
+
appRootPreimage,
|
|
36027
36361
|
askPersonalServer,
|
|
36028
36362
|
assertDerivedScopeNaming,
|
|
36029
36363
|
assertValidPkceVerifier,
|
|
@@ -36037,6 +36371,7 @@ export {
|
|
|
36037
36371
|
buildEscrowPaymentHeader,
|
|
36038
36372
|
buildGrantPaymentHeader,
|
|
36039
36373
|
buildMarkDataPointUnavailableRequest,
|
|
36374
|
+
buildMasterSignatureDelivery,
|
|
36040
36375
|
buildPersonalServerDataReadRequest,
|
|
36041
36376
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
36042
36377
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -36069,6 +36404,7 @@ export {
|
|
|
36069
36404
|
decryptWithPassword,
|
|
36070
36405
|
deleteDataPoint,
|
|
36071
36406
|
deleteQuestion,
|
|
36407
|
+
derivativeStatusTarget,
|
|
36072
36408
|
deriveDataPointId,
|
|
36073
36409
|
deriveMasterKey,
|
|
36074
36410
|
deriveScopeKey,
|
|
@@ -36079,6 +36415,7 @@ export {
|
|
|
36079
36415
|
encodeDepositTokenData,
|
|
36080
36416
|
encodeSetDataPointStatusData,
|
|
36081
36417
|
encodeWriteMetadataHeader,
|
|
36418
|
+
encryptMasterSignatureDelivery,
|
|
36082
36419
|
encryptWithPassword,
|
|
36083
36420
|
escrowContractAddress,
|
|
36084
36421
|
escrowPaymentDomain,
|
|
@@ -36092,6 +36429,7 @@ export {
|
|
|
36092
36429
|
getContractAddress,
|
|
36093
36430
|
getContractController,
|
|
36094
36431
|
getContractInfo,
|
|
36432
|
+
getDerivativeStatus,
|
|
36095
36433
|
getFee,
|
|
36096
36434
|
getGatewayLineage,
|
|
36097
36435
|
getLineage,
|
|
@@ -36107,10 +36445,12 @@ export {
|
|
|
36107
36445
|
isDataPointId,
|
|
36108
36446
|
isDataPointTombstone,
|
|
36109
36447
|
isDataPortabilityGatewayConfig,
|
|
36448
|
+
isDerivativeStatusSettled,
|
|
36110
36449
|
isECIESEncrypted,
|
|
36111
36450
|
isPlatformSupported,
|
|
36112
36451
|
isRedactedLineageNode,
|
|
36113
36452
|
isTombstoneHashes,
|
|
36453
|
+
kmsIssuedPreimage,
|
|
36114
36454
|
listQuestions,
|
|
36115
36455
|
mainnetServices,
|
|
36116
36456
|
moksha,
|
|
@@ -36150,10 +36490,13 @@ export {
|
|
|
36150
36490
|
toDirectPaymentReceipt,
|
|
36151
36491
|
tombstoneDeletedAt,
|
|
36152
36492
|
tryGrantPermissions,
|
|
36493
|
+
userPsId,
|
|
36153
36494
|
vanaMainnet2 as vanaMainnet,
|
|
36495
|
+
verifyEnclaveIdentityEvidence,
|
|
36154
36496
|
verifyGrantRegistration,
|
|
36155
36497
|
verifyPkceChallenge,
|
|
36156
36498
|
verifyWeb3Signed,
|
|
36499
|
+
waitForDerivativeStatus,
|
|
36157
36500
|
waitForQuestion,
|
|
36158
36501
|
writeData,
|
|
36159
36502
|
writePersonalServerData
|