@opendatalabs/vana-sdk 3.21.0 → 3.22.0-pr.207.247f7c0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/dist/index.browser.d.ts +3 -1
- package/dist/index.browser.js +371 -4
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +414 -34
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +3 -1
- package/dist/index.node.js +374 -7
- package/dist/index.node.js.map +4 -4
- package/dist/protocol/derivative-questions.cjs +22 -0
- package/dist/protocol/derivative-questions.cjs.map +1 -1
- package/dist/protocol/derivative-questions.d.ts +53 -0
- package/dist/protocol/derivative-questions.js +19 -0
- package/dist/protocol/derivative-questions.js.map +1 -1
- package/dist/protocol/derivative-status.cjs +209 -0
- package/dist/protocol/derivative-status.cjs.map +1 -0
- package/dist/protocol/derivative-status.d.ts +196 -0
- package/dist/protocol/derivative-status.js +190 -0
- package/dist/protocol/derivative-status.js.map +1 -0
- package/dist/protocol/derivative-status.test.d.ts +1 -0
- package/dist/protocol/identity.cjs +219 -0
- package/dist/protocol/identity.cjs.map +1 -0
- package/dist/protocol/identity.d.ts +193 -0
- package/dist/protocol/identity.js +183 -0
- package/dist/protocol/identity.js.map +1 -0
- package/dist/protocol/identity.test.d.ts +1 -0
- package/dist/protocol/identity.vector.test.d.ts +1 -0
- package/dist/tests/mock-personal-server.d.ts +9 -0
- package/package.json +1 -1
package/dist/index.node.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, MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS, 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,174 @@ 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 MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS = 600;
|
|
32386
|
+
var SEALED_ENVELOPE_VERSION = 1;
|
|
32387
|
+
var VANA_MAINNET_CHAIN_ID = 1480;
|
|
32388
|
+
var MOKSHA_CHAIN_ID = 14800;
|
|
32389
|
+
var KMS_ISSUED_PREFIX = "dstack-kms-issued";
|
|
32390
|
+
var PREIMAGE_SEPARATOR = ":";
|
|
32391
|
+
var UNCOMPRESSED_PUBLIC_KEY_BYTES = 65;
|
|
32392
|
+
var UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04";
|
|
32393
|
+
var EMPTY_HEX = "0x";
|
|
32394
|
+
function emptyAnchor() {
|
|
32395
|
+
return Object.freeze({
|
|
32396
|
+
kmsRootPubkey: EMPTY_HEX,
|
|
32397
|
+
appIds: Object.freeze([])
|
|
32398
|
+
});
|
|
32399
|
+
}
|
|
32400
|
+
var ENCLAVE_TRUST_ANCHORS = Object.freeze({
|
|
32401
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32402
|
+
[VANA_MAINNET_CHAIN_ID]: emptyAnchor(),
|
|
32403
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32404
|
+
[MOKSHA_CHAIN_ID]: emptyAnchor()
|
|
32405
|
+
});
|
|
32406
|
+
function userPsId(chainId, ownerAddress) {
|
|
32407
|
+
const packed = encodePacked(
|
|
32408
|
+
["string", "uint256", "address"],
|
|
32409
|
+
[USER_PS_ID_DOMAIN, BigInt(chainId), getAddress(ownerAddress)]
|
|
32410
|
+
);
|
|
32411
|
+
return keccak256(packed);
|
|
32412
|
+
}
|
|
32413
|
+
function compressPublicKey(publicKey) {
|
|
32414
|
+
return secp256k14.ProjectivePoint.fromHex(
|
|
32415
|
+
fromHex5(publicKey, "bytes")
|
|
32416
|
+
).toRawBytes(true);
|
|
32417
|
+
}
|
|
32418
|
+
function sameKey(a, b) {
|
|
32419
|
+
return toHex7(compressPublicKey(a)) === toHex7(compressPublicKey(b));
|
|
32420
|
+
}
|
|
32421
|
+
function assertUncompressedKey(publicKey) {
|
|
32422
|
+
const hex = publicKey.slice(2);
|
|
32423
|
+
if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
32424
|
+
throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
|
|
32425
|
+
}
|
|
32426
|
+
}
|
|
32427
|
+
function appRootPreimage(purpose, publicKey) {
|
|
32428
|
+
const keyHex = toHex7(compressPublicKey(publicKey)).slice(2);
|
|
32429
|
+
return keccak256(toBytes(`${purpose}${PREIMAGE_SEPARATOR}${keyHex}`));
|
|
32430
|
+
}
|
|
32431
|
+
function kmsIssuedPreimage(appId, appRootPublicKey) {
|
|
32432
|
+
const prefix = concat4([
|
|
32433
|
+
toBytes(`${KMS_ISSUED_PREFIX}${PREIMAGE_SEPARATOR}`),
|
|
32434
|
+
fromHex5(appId, "bytes")
|
|
32435
|
+
]);
|
|
32436
|
+
const compressed = compressPublicKey(appRootPublicKey);
|
|
32437
|
+
return keccak256(concat4([prefix, compressed]));
|
|
32438
|
+
}
|
|
32439
|
+
async function recoverChainKey(hash, signature, link) {
|
|
32440
|
+
try {
|
|
32441
|
+
return (await recoverPublicKey({ hash, signature })).toLowerCase();
|
|
32442
|
+
} catch {
|
|
32443
|
+
throw new Error(`Invalid enclave signature chain link ${link}`);
|
|
32444
|
+
}
|
|
32445
|
+
}
|
|
32446
|
+
async function verifyEnclaveIdentityEvidence(evidence, anchors, expected) {
|
|
32447
|
+
if (evidence.v !== ENCLAVE_IDENTITY_EVIDENCE_VERSION) {
|
|
32448
|
+
throw new Error("Unsupported enclave identity evidence version");
|
|
32449
|
+
}
|
|
32450
|
+
if (!Number.isInteger(evidence.epoch) || evidence.epoch < 1) {
|
|
32451
|
+
throw new Error("Invalid enclave identity epoch");
|
|
32452
|
+
}
|
|
32453
|
+
if (evidence.chainId !== expected.chainId) {
|
|
32454
|
+
throw new Error(
|
|
32455
|
+
"Enclave identity chain ID does not match expected chain ID"
|
|
32456
|
+
);
|
|
32457
|
+
}
|
|
32458
|
+
if (!isAddressEqual(evidence.ownerAddress, expected.ownerAddress)) {
|
|
32459
|
+
throw new Error("Enclave identity owner does not match expected owner");
|
|
32460
|
+
}
|
|
32461
|
+
if (evidence.epoch !== expected.epoch) {
|
|
32462
|
+
throw new Error("Enclave identity epoch does not match expected epoch");
|
|
32463
|
+
}
|
|
32464
|
+
const expectedUserPsId = userPsId(expected.chainId, expected.ownerAddress);
|
|
32465
|
+
if (evidence.userPsId.toLowerCase() !== expectedUserPsId.toLowerCase()) {
|
|
32466
|
+
throw new Error("Enclave userPsId does not match expected identity");
|
|
32467
|
+
}
|
|
32468
|
+
if (evidence.purpose !== ENCLAVE_WALLET_PURPOSE) {
|
|
32469
|
+
throw new Error("Unexpected enclave wallet purpose");
|
|
32470
|
+
}
|
|
32471
|
+
if (anchors.kmsRootPubkey === EMPTY_HEX) {
|
|
32472
|
+
throw new Error("KMS root trust anchor is not provisioned");
|
|
32473
|
+
}
|
|
32474
|
+
assertUncompressedKey(evidence.publicKey);
|
|
32475
|
+
const derivedAddress = publicKeyToAddress(evidence.publicKey);
|
|
32476
|
+
if (getAddress(derivedAddress) !== getAddress(evidence.address)) {
|
|
32477
|
+
throw new Error("Enclave public key does not match its address");
|
|
32478
|
+
}
|
|
32479
|
+
const appRootPublicKey = await recoverChainKey(
|
|
32480
|
+
appRootPreimage(evidence.purpose, evidence.publicKey),
|
|
32481
|
+
evidence.signatureChain[0],
|
|
32482
|
+
0
|
|
32483
|
+
);
|
|
32484
|
+
const kmsRootPublicKey = await recoverChainKey(
|
|
32485
|
+
kmsIssuedPreimage(evidence.appId, appRootPublicKey),
|
|
32486
|
+
evidence.signatureChain[1],
|
|
32487
|
+
1
|
|
32488
|
+
);
|
|
32489
|
+
let matchesAnchor;
|
|
32490
|
+
try {
|
|
32491
|
+
matchesAnchor = sameKey(kmsRootPublicKey, anchors.kmsRootPubkey);
|
|
32492
|
+
} catch {
|
|
32493
|
+
throw new Error("KMS root trust anchor is malformed");
|
|
32494
|
+
}
|
|
32495
|
+
if (!matchesAnchor) {
|
|
32496
|
+
throw new Error("KMS root public key does not match the trust anchor");
|
|
32497
|
+
}
|
|
32498
|
+
if (keccak256(kmsRootPublicKey) !== evidence.kmsRootFingerprint.toLowerCase()) {
|
|
32499
|
+
throw new Error("KMS root fingerprint does not match the evidence");
|
|
32500
|
+
}
|
|
32501
|
+
const appId = evidence.appId.toLowerCase();
|
|
32502
|
+
if (!anchors.appIds.some((allowedAppId) => allowedAppId.toLowerCase() === appId)) {
|
|
32503
|
+
throw new Error("Enclave app ID is not trusted");
|
|
32504
|
+
}
|
|
32505
|
+
}
|
|
32506
|
+
async function buildMasterSignatureDelivery(evidence, masterSignature, now = Math.floor(Date.now() / 1e3)) {
|
|
32507
|
+
deriveMasterKey(masterSignature);
|
|
32508
|
+
const signerAddress = await recoverServerOwner(masterSignature);
|
|
32509
|
+
if (!isAddressEqual(signerAddress, evidence.ownerAddress)) {
|
|
32510
|
+
throw new Error("Master signature signer does not match evidence owner");
|
|
32511
|
+
}
|
|
32512
|
+
return {
|
|
32513
|
+
v: MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
32514
|
+
userPsId: evidence.userPsId,
|
|
32515
|
+
epoch: evidence.epoch,
|
|
32516
|
+
enclaveAddress: evidence.address,
|
|
32517
|
+
ownerAddress: evidence.ownerAddress,
|
|
32518
|
+
masterSignature,
|
|
32519
|
+
issuedAt: now
|
|
32520
|
+
};
|
|
32521
|
+
}
|
|
32522
|
+
async function encryptMasterSignatureDelivery(delivery, publicKey, ecies) {
|
|
32523
|
+
assertUncompressedKey(publicKey);
|
|
32524
|
+
if (!isAddressEqual(publicKeyToAddress(publicKey), delivery.enclaveAddress)) {
|
|
32525
|
+
throw new Error(
|
|
32526
|
+
"Public key does not belong to the delivery's enclave address"
|
|
32527
|
+
);
|
|
32528
|
+
}
|
|
32529
|
+
const plaintext = toBytes(JSON.stringify(delivery));
|
|
32530
|
+
const encrypted = await ecies.encrypt(fromHex5(publicKey, "bytes"), plaintext);
|
|
32531
|
+
return `0x${serializeECIES(encrypted)}`;
|
|
32532
|
+
}
|
|
32533
|
+
|
|
32366
32534
|
// src/protocol/personal-server-registration.ts
|
|
32367
32535
|
import {
|
|
32368
32536
|
isAddress
|
|
@@ -33062,7 +33230,7 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
33062
33230
|
// src/protocol/data-point-deletion.ts
|
|
33063
33231
|
import {
|
|
33064
33232
|
isAddress as isAddress5,
|
|
33065
|
-
keccak256 as
|
|
33233
|
+
keccak256 as keccak2563,
|
|
33066
33234
|
maxUint256,
|
|
33067
33235
|
stringToBytes as stringToBytes3
|
|
33068
33236
|
} from "viem";
|
|
@@ -33071,7 +33239,7 @@ import {
|
|
|
33071
33239
|
import {
|
|
33072
33240
|
encodeAbiParameters,
|
|
33073
33241
|
isAddress as isAddress4,
|
|
33074
|
-
keccak256
|
|
33242
|
+
keccak256 as keccak2562
|
|
33075
33243
|
} from "viem";
|
|
33076
33244
|
import { z } from "zod";
|
|
33077
33245
|
|
|
@@ -33155,7 +33323,7 @@ function deriveDataPointId(ownerAddress, scope) {
|
|
|
33155
33323
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
33156
33324
|
);
|
|
33157
33325
|
}
|
|
33158
|
-
return
|
|
33326
|
+
return keccak2562(
|
|
33159
33327
|
encodeAbiParameters(
|
|
33160
33328
|
[
|
|
33161
33329
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -33382,7 +33550,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
33382
33550
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
33383
33551
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
33384
33552
|
function computeTombstoneHash(preimage) {
|
|
33385
|
-
return
|
|
33553
|
+
return keccak2563(stringToBytes3(preimage));
|
|
33386
33554
|
}
|
|
33387
33555
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
33388
33556
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -34404,6 +34572,13 @@ var QUESTION_STATUSES = [
|
|
|
34404
34572
|
"failed",
|
|
34405
34573
|
"stale"
|
|
34406
34574
|
];
|
|
34575
|
+
var DERIVATIVE_ERROR_CODES = [
|
|
34576
|
+
"inference_unavailable",
|
|
34577
|
+
"source_missing",
|
|
34578
|
+
"grant_invalid",
|
|
34579
|
+
"internal"
|
|
34580
|
+
];
|
|
34581
|
+
var DerivativeErrorCodeSchema = z5.enum(DERIVATIVE_ERROR_CODES);
|
|
34407
34582
|
var QuestionStatusSchema = z5.enum(QUESTION_STATUSES);
|
|
34408
34583
|
var QuestionRegisteredBySchema = z5.union([
|
|
34409
34584
|
z5.object({ kind: z5.literal("owner") }),
|
|
@@ -34425,6 +34600,14 @@ var DerivativeQuestionSchema = z5.object({
|
|
|
34425
34600
|
status: QuestionStatusSchema,
|
|
34426
34601
|
/** A short reason, set only while `status` is `failed`. */
|
|
34427
34602
|
error: nullableString,
|
|
34603
|
+
/**
|
|
34604
|
+
* The coarse failure class behind `error`, set only while `status` is
|
|
34605
|
+
* `failed`. `null` from a Personal Server that predates the class
|
|
34606
|
+
* (`personal-server-ts` before the status route).
|
|
34607
|
+
*/
|
|
34608
|
+
errorCode: DerivativeErrorCodeSchema.nullish().transform(
|
|
34609
|
+
(value) => value ?? null
|
|
34610
|
+
),
|
|
34428
34611
|
createdAt: z5.string(),
|
|
34429
34612
|
updatedAt: nullableString,
|
|
34430
34613
|
/** When the last compute finished, or `null` while `pending`. */
|
|
@@ -34557,6 +34740,7 @@ async function questionErrorFromResponse(response, body) {
|
|
|
34557
34740
|
);
|
|
34558
34741
|
}
|
|
34559
34742
|
}
|
|
34743
|
+
var personalServerErrorFromQuestionResponse = questionErrorFromResponse;
|
|
34560
34744
|
async function sendOnce(params, resolved, session, spec, bodyBytes) {
|
|
34561
34745
|
return sendWithFreshProof(
|
|
34562
34746
|
spec.label,
|
|
@@ -34836,6 +35020,166 @@ async function askPersonalServer(params) {
|
|
|
34836
35020
|
return { registration, record };
|
|
34837
35021
|
}
|
|
34838
35022
|
|
|
35023
|
+
// src/protocol/derivative-status.ts
|
|
35024
|
+
import { z as z6 } from "zod";
|
|
35025
|
+
var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
|
|
35026
|
+
var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
|
|
35027
|
+
var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
|
|
35028
|
+
var nullable = (schema) => schema.nullish().transform((value) => value ?? null);
|
|
35029
|
+
var DerivativeStatusSchema = z6.object({
|
|
35030
|
+
derivedScope: z6.string().min(1),
|
|
35031
|
+
status: QuestionStatusSchema,
|
|
35032
|
+
/** When the last compute finished, or `null` if none ever has. */
|
|
35033
|
+
lastComputedAt: nullable(z6.string()),
|
|
35034
|
+
/** Local version of the derived record the last compute wrote. */
|
|
35035
|
+
derivedVersion: nullable(z6.number()),
|
|
35036
|
+
derivedCollectedAt: nullable(z6.string()),
|
|
35037
|
+
/** The failure class; `null` unless `status` is `failed`. */
|
|
35038
|
+
errorCode: nullable(DerivativeErrorCodeSchema),
|
|
35039
|
+
/**
|
|
35040
|
+
* Seconds until the Personal Server's next automatic retry, or `null` when
|
|
35041
|
+
* none is pending or running — the terminal signature. Poll on this cadence
|
|
35042
|
+
* rather than guessing one.
|
|
35043
|
+
*/
|
|
35044
|
+
retryAfterSeconds: nullable(z6.number())
|
|
35045
|
+
});
|
|
35046
|
+
function derivativeStatusTarget(derivedScope) {
|
|
35047
|
+
return `${DERIVATIVE_STATUS_PATH}?derivedScope=${encodeURIComponent(derivedScope)}`;
|
|
35048
|
+
}
|
|
35049
|
+
function normalizeBaseUrl3(url) {
|
|
35050
|
+
return url.replace(/\/+$/, "");
|
|
35051
|
+
}
|
|
35052
|
+
function resolveFetch3(fetchFn) {
|
|
35053
|
+
const resolved = fetchFn ?? globalThis.fetch;
|
|
35054
|
+
if (resolved === void 0) {
|
|
35055
|
+
throw new WriteRequestError("No fetch implementation available");
|
|
35056
|
+
}
|
|
35057
|
+
return resolved;
|
|
35058
|
+
}
|
|
35059
|
+
function requireDerivedScope(derivedScope) {
|
|
35060
|
+
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
35061
|
+
throw new WriteRequestError("derivedScope is required");
|
|
35062
|
+
}
|
|
35063
|
+
return derivedScope;
|
|
35064
|
+
}
|
|
35065
|
+
function sleep3(ms, signal) {
|
|
35066
|
+
if (ms <= 0) return Promise.resolve();
|
|
35067
|
+
return new Promise((resolve, reject) => {
|
|
35068
|
+
const timer = setTimeout(() => {
|
|
35069
|
+
signal?.removeEventListener("abort", onAbort);
|
|
35070
|
+
resolve();
|
|
35071
|
+
}, ms);
|
|
35072
|
+
const onAbort = () => {
|
|
35073
|
+
clearTimeout(timer);
|
|
35074
|
+
reject(abortError2(signal));
|
|
35075
|
+
};
|
|
35076
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
35077
|
+
});
|
|
35078
|
+
}
|
|
35079
|
+
function timeoutError(latest, timeoutMs) {
|
|
35080
|
+
return new DerivativeQuestionTimeoutError(
|
|
35081
|
+
`Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
|
|
35082
|
+
{
|
|
35083
|
+
derivedScope: latest.derivedScope,
|
|
35084
|
+
status: latest.status,
|
|
35085
|
+
errorCode: latest.errorCode,
|
|
35086
|
+
retryAfterSeconds: latest.retryAfterSeconds,
|
|
35087
|
+
timeoutMs
|
|
35088
|
+
}
|
|
35089
|
+
);
|
|
35090
|
+
}
|
|
35091
|
+
function abortError2(signal) {
|
|
35092
|
+
const reason = signal?.reason;
|
|
35093
|
+
return reason instanceof Error ? reason : new WriteRequestError("Derivative status wait was aborted");
|
|
35094
|
+
}
|
|
35095
|
+
function isDerivativeStatusSettled(status) {
|
|
35096
|
+
if (status.status === "ready") return true;
|
|
35097
|
+
return status.status === "failed" && status.retryAfterSeconds === null;
|
|
35098
|
+
}
|
|
35099
|
+
async function getDerivativeStatus(params) {
|
|
35100
|
+
const derivedScope = requireDerivedScope(params.derivedScope);
|
|
35101
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
35102
|
+
const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
|
|
35103
|
+
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
35104
|
+
const headers = new Headers(params.headers);
|
|
35105
|
+
headers.set(
|
|
35106
|
+
"Authorization",
|
|
35107
|
+
await buildWeb3SignedHeader({
|
|
35108
|
+
signMessage: signer.signMessage,
|
|
35109
|
+
aud: params.audience ?? baseUrl,
|
|
35110
|
+
method: "GET",
|
|
35111
|
+
uri: DERIVATIVE_STATUS_PATH,
|
|
35112
|
+
grantId: params.grantId
|
|
35113
|
+
})
|
|
35114
|
+
);
|
|
35115
|
+
let response;
|
|
35116
|
+
try {
|
|
35117
|
+
response = await fetchFn(
|
|
35118
|
+
`${baseUrl}${derivativeStatusTarget(derivedScope)}`,
|
|
35119
|
+
{
|
|
35120
|
+
method: "GET",
|
|
35121
|
+
headers,
|
|
35122
|
+
...params.signal ? { signal: params.signal } : {}
|
|
35123
|
+
}
|
|
35124
|
+
);
|
|
35125
|
+
} catch (err) {
|
|
35126
|
+
throw new WriteTransportError(
|
|
35127
|
+
`Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
35128
|
+
1,
|
|
35129
|
+
err
|
|
35130
|
+
);
|
|
35131
|
+
}
|
|
35132
|
+
if (!response.ok) {
|
|
35133
|
+
throw await personalServerErrorFromQuestionResponse(
|
|
35134
|
+
response
|
|
35135
|
+
);
|
|
35136
|
+
}
|
|
35137
|
+
let body;
|
|
35138
|
+
try {
|
|
35139
|
+
body = await response.json();
|
|
35140
|
+
} catch (err) {
|
|
35141
|
+
throw new DerivativeQuestionRejectedError(
|
|
35142
|
+
"Derivative status response is not JSON",
|
|
35143
|
+
response.status,
|
|
35144
|
+
null,
|
|
35145
|
+
{ cause: err instanceof Error ? err.message : String(err) }
|
|
35146
|
+
);
|
|
35147
|
+
}
|
|
35148
|
+
const parsed = DerivativeStatusSchema.safeParse(body);
|
|
35149
|
+
if (!parsed.success) {
|
|
35150
|
+
throw new DerivativeQuestionRejectedError(
|
|
35151
|
+
"Derivative status response is not a status view",
|
|
35152
|
+
response.status,
|
|
35153
|
+
null,
|
|
35154
|
+
{ issues: parsed.error.issues }
|
|
35155
|
+
);
|
|
35156
|
+
}
|
|
35157
|
+
return parsed.data;
|
|
35158
|
+
}
|
|
35159
|
+
async function waitForDerivativeStatus(params) {
|
|
35160
|
+
const timeoutMs = Math.max(
|
|
35161
|
+
0,
|
|
35162
|
+
params.timeoutMs ?? DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS
|
|
35163
|
+
);
|
|
35164
|
+
const pollIntervalMs = Math.max(
|
|
35165
|
+
0,
|
|
35166
|
+
params.pollIntervalMs ?? DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS
|
|
35167
|
+
);
|
|
35168
|
+
const deadline = Date.now() + timeoutMs;
|
|
35169
|
+
for (; ; ) {
|
|
35170
|
+
if (params.signal?.aborted) throw abortError2(params.signal);
|
|
35171
|
+
const latest = await getDerivativeStatus(params);
|
|
35172
|
+
if (isDerivativeStatusSettled(latest)) return latest;
|
|
35173
|
+
const remaining = deadline - Date.now();
|
|
35174
|
+
if (remaining <= 0) throw timeoutError(latest, timeoutMs);
|
|
35175
|
+
const waitMs = latest.retryAfterSeconds === null ? pollIntervalMs : latest.retryAfterSeconds * 1e3;
|
|
35176
|
+
if (waitMs > remaining) {
|
|
35177
|
+
throw timeoutError(latest, timeoutMs);
|
|
35178
|
+
}
|
|
35179
|
+
await sleep3(waitMs, params.signal);
|
|
35180
|
+
}
|
|
35181
|
+
}
|
|
35182
|
+
|
|
34839
35183
|
// src/protocol/gateway.ts
|
|
34840
35184
|
function withGrantPermissions(grant) {
|
|
34841
35185
|
const stripped = { ...grant };
|
|
@@ -35916,9 +36260,13 @@ export {
|
|
|
35916
36260
|
ContractNotFoundError,
|
|
35917
36261
|
DATA_ACCESS_OP_TYPE,
|
|
35918
36262
|
DATA_REGISTRY_STATUS_ABI,
|
|
36263
|
+
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
36264
|
+
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
35919
36265
|
DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
35920
36266
|
DEFAULT_QUESTION_TIMEOUT_MS,
|
|
36267
|
+
DERIVATIVE_ERROR_CODES,
|
|
35921
36268
|
DERIVATIVE_QUESTIONS_PATH,
|
|
36269
|
+
DERIVATIVE_STATUS_PATH,
|
|
35922
36270
|
DataFileEnvelopeSchema,
|
|
35923
36271
|
DataPointDeletedError,
|
|
35924
36272
|
DataPointNotFoundError,
|
|
@@ -35927,6 +36275,7 @@ export {
|
|
|
35927
36275
|
DerivativeComputeUnavailableError,
|
|
35928
36276
|
DerivativeCycleError,
|
|
35929
36277
|
DerivativeDerivedScopeRequiredError,
|
|
36278
|
+
DerivativeErrorCodeSchema,
|
|
35930
36279
|
DerivativeQuestionFailedError,
|
|
35931
36280
|
DerivativeQuestionInvalidError,
|
|
35932
36281
|
DerivativeQuestionNotFoundError,
|
|
@@ -35934,8 +36283,12 @@ export {
|
|
|
35934
36283
|
DerivativeQuestionSchema,
|
|
35935
36284
|
DerivativeQuestionTimeoutError,
|
|
35936
36285
|
DerivativeSourceNotGrantedError,
|
|
36286
|
+
DerivativeStatusSchema,
|
|
35937
36287
|
DropboxStorage,
|
|
35938
36288
|
ECIESError,
|
|
36289
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
36290
|
+
ENCLAVE_TRUST_ANCHORS,
|
|
36291
|
+
ENCLAVE_WALLET_PURPOSE,
|
|
35939
36292
|
ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
|
|
35940
36293
|
ExpiredTokenError,
|
|
35941
36294
|
FEE_REGISTRY_ABI,
|
|
@@ -35957,6 +36310,8 @@ export {
|
|
|
35957
36310
|
LineageNodeSchema,
|
|
35958
36311
|
LineageReadError,
|
|
35959
36312
|
MASTER_KEY_MESSAGE,
|
|
36313
|
+
MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS,
|
|
36314
|
+
MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
35960
36315
|
MAX_LINEAGE_SOURCES,
|
|
35961
36316
|
MAX_QUESTION_CHARS,
|
|
35962
36317
|
MAX_QUESTION_MODEL_CHARS,
|
|
@@ -35994,6 +36349,7 @@ export {
|
|
|
35994
36349
|
RedactedLineageNodeSchema,
|
|
35995
36350
|
RelayerError,
|
|
35996
36351
|
SCOPE_ACTIONS,
|
|
36352
|
+
SEALED_ENVELOPE_VERSION,
|
|
35997
36353
|
SERVER_REGISTRATION_TYPES,
|
|
35998
36354
|
ScopeSchema,
|
|
35999
36355
|
SerializationError,
|
|
@@ -36006,6 +36362,7 @@ export {
|
|
|
36006
36362
|
TOMBSTONE_METADATA_HASH,
|
|
36007
36363
|
TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
36008
36364
|
TransactionPendingError,
|
|
36365
|
+
USER_PS_ID_DOMAIN,
|
|
36009
36366
|
UserRejectedRequestError,
|
|
36010
36367
|
VanaError,
|
|
36011
36368
|
VanaStorage,
|
|
@@ -36024,6 +36381,7 @@ export {
|
|
|
36024
36381
|
WriteSessionExpiredError,
|
|
36025
36382
|
WriteTransportError,
|
|
36026
36383
|
WriteUnauthorizedError,
|
|
36384
|
+
appRootPreimage,
|
|
36027
36385
|
askPersonalServer,
|
|
36028
36386
|
assertDerivedScopeNaming,
|
|
36029
36387
|
assertValidPkceVerifier,
|
|
@@ -36037,6 +36395,7 @@ export {
|
|
|
36037
36395
|
buildEscrowPaymentHeader,
|
|
36038
36396
|
buildGrantPaymentHeader,
|
|
36039
36397
|
buildMarkDataPointUnavailableRequest,
|
|
36398
|
+
buildMasterSignatureDelivery,
|
|
36040
36399
|
buildPersonalServerDataReadRequest,
|
|
36041
36400
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
36042
36401
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -36069,6 +36428,7 @@ export {
|
|
|
36069
36428
|
decryptWithPassword,
|
|
36070
36429
|
deleteDataPoint,
|
|
36071
36430
|
deleteQuestion,
|
|
36431
|
+
derivativeStatusTarget,
|
|
36072
36432
|
deriveDataPointId,
|
|
36073
36433
|
deriveMasterKey,
|
|
36074
36434
|
deriveScopeKey,
|
|
@@ -36079,6 +36439,7 @@ export {
|
|
|
36079
36439
|
encodeDepositTokenData,
|
|
36080
36440
|
encodeSetDataPointStatusData,
|
|
36081
36441
|
encodeWriteMetadataHeader,
|
|
36442
|
+
encryptMasterSignatureDelivery,
|
|
36082
36443
|
encryptWithPassword,
|
|
36083
36444
|
escrowContractAddress,
|
|
36084
36445
|
escrowPaymentDomain,
|
|
@@ -36092,6 +36453,7 @@ export {
|
|
|
36092
36453
|
getContractAddress,
|
|
36093
36454
|
getContractController,
|
|
36094
36455
|
getContractInfo,
|
|
36456
|
+
getDerivativeStatus,
|
|
36095
36457
|
getFee,
|
|
36096
36458
|
getGatewayLineage,
|
|
36097
36459
|
getLineage,
|
|
@@ -36107,10 +36469,12 @@ export {
|
|
|
36107
36469
|
isDataPointId,
|
|
36108
36470
|
isDataPointTombstone,
|
|
36109
36471
|
isDataPortabilityGatewayConfig,
|
|
36472
|
+
isDerivativeStatusSettled,
|
|
36110
36473
|
isECIESEncrypted,
|
|
36111
36474
|
isPlatformSupported,
|
|
36112
36475
|
isRedactedLineageNode,
|
|
36113
36476
|
isTombstoneHashes,
|
|
36477
|
+
kmsIssuedPreimage,
|
|
36114
36478
|
listQuestions,
|
|
36115
36479
|
mainnetServices,
|
|
36116
36480
|
moksha,
|
|
@@ -36150,10 +36514,13 @@ export {
|
|
|
36150
36514
|
toDirectPaymentReceipt,
|
|
36151
36515
|
tombstoneDeletedAt,
|
|
36152
36516
|
tryGrantPermissions,
|
|
36517
|
+
userPsId,
|
|
36153
36518
|
vanaMainnet2 as vanaMainnet,
|
|
36519
|
+
verifyEnclaveIdentityEvidence,
|
|
36154
36520
|
verifyGrantRegistration,
|
|
36155
36521
|
verifyPkceChallenge,
|
|
36156
36522
|
verifyWeb3Signed,
|
|
36523
|
+
waitForDerivativeStatus,
|
|
36157
36524
|
waitForQuestion,
|
|
36158
36525
|
writeData,
|
|
36159
36526
|
writePersonalServerData
|