@opendatalabs/vana-sdk 3.21.0 → 3.22.0-pr.207.e47cd30
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 +320 -4
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +364 -34
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +3 -1
- package/dist/index.node.js +323 -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 +169 -0
- package/dist/protocol/identity.cjs.map +1 -0
- package/dist/protocol/identity.d.ts +151 -0
- package/dist/protocol/identity.js +132 -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.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 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,124 @@ 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
|
+
keccak256,
|
|
32375
|
+
recoverPublicKey,
|
|
32376
|
+
toBytes
|
|
32377
|
+
} from "viem";
|
|
32378
|
+
import { publicKeyToAddress } from "viem/accounts";
|
|
32379
|
+
var ENCLAVE_IDENTITY_EVIDENCE_VERSION = 1;
|
|
32380
|
+
var USER_PS_ID_DOMAIN = "vana.ps-enclave.v1";
|
|
32381
|
+
var ENCLAVE_WALLET_PURPOSE = "vana.ps-enclave.wallet.v1";
|
|
32382
|
+
var MASTER_SIGNATURE_DELIVERY_VERSION = "vana.ps-enclave.delivery.v1";
|
|
32383
|
+
var SEALED_ENVELOPE_VERSION = 1;
|
|
32384
|
+
var VANA_MAINNET_CHAIN_ID = 1480;
|
|
32385
|
+
var MOKSHA_CHAIN_ID = 14800;
|
|
32386
|
+
var KMS_ISSUED_PREFIX = "dstack-kms-issued";
|
|
32387
|
+
var PREIMAGE_SEPARATOR = ":";
|
|
32388
|
+
var UNCOMPRESSED_PUBLIC_KEY_BYTES = 65;
|
|
32389
|
+
var UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04";
|
|
32390
|
+
var ENCLAVE_TRUST_ANCHORS = {
|
|
32391
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32392
|
+
[VANA_MAINNET_CHAIN_ID]: { kmsRootPubkey: "0x", appIds: [] },
|
|
32393
|
+
// filled at fleet provisioning; verify fails closed while empty
|
|
32394
|
+
[MOKSHA_CHAIN_ID]: { kmsRootPubkey: "0x", appIds: [] }
|
|
32395
|
+
};
|
|
32396
|
+
function userPsId(chainId, ownerAddress) {
|
|
32397
|
+
const packed = encodePacked(
|
|
32398
|
+
["string", "uint256", "address"],
|
|
32399
|
+
[USER_PS_ID_DOMAIN, BigInt(chainId), getAddress(ownerAddress)]
|
|
32400
|
+
);
|
|
32401
|
+
return keccak256(packed);
|
|
32402
|
+
}
|
|
32403
|
+
function appRootPreimage(purpose, publicKey) {
|
|
32404
|
+
const keyHex = publicKey.slice(2).toLowerCase();
|
|
32405
|
+
return keccak256(toBytes(`${purpose}${PREIMAGE_SEPARATOR}${keyHex}`));
|
|
32406
|
+
}
|
|
32407
|
+
function kmsIssuedPreimage(appId, appRootPublicKey) {
|
|
32408
|
+
const appIdHex = appId.slice(2).toLowerCase();
|
|
32409
|
+
const prefix = toBytes(
|
|
32410
|
+
`${KMS_ISSUED_PREFIX}${PREIMAGE_SEPARATOR}${appIdHex}`
|
|
32411
|
+
);
|
|
32412
|
+
const compressed = secp256k14.ProjectivePoint.fromHex(
|
|
32413
|
+
fromHex5(appRootPublicKey, "bytes")
|
|
32414
|
+
).toRawBytes(true);
|
|
32415
|
+
return keccak256(concat4([prefix, compressed]));
|
|
32416
|
+
}
|
|
32417
|
+
async function recoverChainKey(hash, signature, link) {
|
|
32418
|
+
try {
|
|
32419
|
+
return (await recoverPublicKey({ hash, signature })).toLowerCase();
|
|
32420
|
+
} catch {
|
|
32421
|
+
throw new Error(`Invalid enclave signature chain link ${link}`);
|
|
32422
|
+
}
|
|
32423
|
+
}
|
|
32424
|
+
async function verifyEnclaveIdentityEvidence(evidence, anchors) {
|
|
32425
|
+
if (evidence.v !== ENCLAVE_IDENTITY_EVIDENCE_VERSION) {
|
|
32426
|
+
throw new Error("Unsupported enclave identity evidence version");
|
|
32427
|
+
}
|
|
32428
|
+
if (!Number.isInteger(evidence.epoch) || evidence.epoch < 1) {
|
|
32429
|
+
throw new Error("Invalid enclave identity epoch");
|
|
32430
|
+
}
|
|
32431
|
+
const derivedAddress = publicKeyToAddress(evidence.publicKey);
|
|
32432
|
+
if (getAddress(derivedAddress) !== getAddress(evidence.address)) {
|
|
32433
|
+
throw new Error("Enclave public key does not match its address");
|
|
32434
|
+
}
|
|
32435
|
+
const appRootPublicKey = await recoverChainKey(
|
|
32436
|
+
appRootPreimage(evidence.purpose, evidence.publicKey),
|
|
32437
|
+
evidence.signatureChain[0],
|
|
32438
|
+
0
|
|
32439
|
+
);
|
|
32440
|
+
const kmsRootPublicKey = await recoverChainKey(
|
|
32441
|
+
kmsIssuedPreimage(evidence.appId, appRootPublicKey),
|
|
32442
|
+
evidence.signatureChain[1],
|
|
32443
|
+
1
|
|
32444
|
+
);
|
|
32445
|
+
if (anchors.kmsRootPubkey === "0x") {
|
|
32446
|
+
throw new Error("KMS root trust anchor is not provisioned");
|
|
32447
|
+
}
|
|
32448
|
+
if (kmsRootPublicKey !== anchors.kmsRootPubkey.toLowerCase()) {
|
|
32449
|
+
throw new Error("KMS root public key does not match the trust anchor");
|
|
32450
|
+
}
|
|
32451
|
+
if (keccak256(kmsRootPublicKey) !== evidence.kmsRootFingerprint.toLowerCase()) {
|
|
32452
|
+
throw new Error("KMS root fingerprint does not match the evidence");
|
|
32453
|
+
}
|
|
32454
|
+
const appId = evidence.appId.toLowerCase();
|
|
32455
|
+
if (!anchors.appIds.some((allowedAppId) => allowedAppId.toLowerCase() === appId)) {
|
|
32456
|
+
throw new Error("Enclave app ID is not trusted");
|
|
32457
|
+
}
|
|
32458
|
+
}
|
|
32459
|
+
function buildMasterSignatureDelivery(evidence, masterSignature, now = Math.floor(Date.now() / 1e3)) {
|
|
32460
|
+
deriveMasterKey(masterSignature);
|
|
32461
|
+
return {
|
|
32462
|
+
v: MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
32463
|
+
userPsId: evidence.userPsId,
|
|
32464
|
+
epoch: evidence.epoch,
|
|
32465
|
+
enclaveAddress: evidence.address,
|
|
32466
|
+
ownerAddress: evidence.ownerAddress,
|
|
32467
|
+
masterSignature,
|
|
32468
|
+
issuedAt: now
|
|
32469
|
+
};
|
|
32470
|
+
}
|
|
32471
|
+
function assertUncompressedKey(publicKey) {
|
|
32472
|
+
const hex = publicKey.slice(2);
|
|
32473
|
+
if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
32474
|
+
throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
|
|
32475
|
+
}
|
|
32476
|
+
}
|
|
32477
|
+
async function encryptMasterSignatureDelivery(delivery, publicKey, ecies) {
|
|
32478
|
+
assertUncompressedKey(publicKey);
|
|
32479
|
+
const plaintext = toBytes(JSON.stringify(delivery));
|
|
32480
|
+
const encrypted = await ecies.encrypt(fromHex5(publicKey, "bytes"), plaintext);
|
|
32481
|
+
return `0x${serializeECIES(encrypted)}`;
|
|
32482
|
+
}
|
|
32483
|
+
|
|
32366
32484
|
// src/protocol/personal-server-registration.ts
|
|
32367
32485
|
import {
|
|
32368
32486
|
isAddress
|
|
@@ -33062,7 +33180,7 @@ function buildMarkDataPointUnavailableRequest(config, input) {
|
|
|
33062
33180
|
// src/protocol/data-point-deletion.ts
|
|
33063
33181
|
import {
|
|
33064
33182
|
isAddress as isAddress5,
|
|
33065
|
-
keccak256 as
|
|
33183
|
+
keccak256 as keccak2563,
|
|
33066
33184
|
maxUint256,
|
|
33067
33185
|
stringToBytes as stringToBytes3
|
|
33068
33186
|
} from "viem";
|
|
@@ -33071,7 +33189,7 @@ import {
|
|
|
33071
33189
|
import {
|
|
33072
33190
|
encodeAbiParameters,
|
|
33073
33191
|
isAddress as isAddress4,
|
|
33074
|
-
keccak256
|
|
33192
|
+
keccak256 as keccak2562
|
|
33075
33193
|
} from "viem";
|
|
33076
33194
|
import { z } from "zod";
|
|
33077
33195
|
|
|
@@ -33155,7 +33273,7 @@ function deriveDataPointId(ownerAddress, scope) {
|
|
|
33155
33273
|
`ownerAddress is not an EVM address: ${String(ownerAddress)}`
|
|
33156
33274
|
);
|
|
33157
33275
|
}
|
|
33158
|
-
return
|
|
33276
|
+
return keccak2562(
|
|
33159
33277
|
encodeAbiParameters(
|
|
33160
33278
|
[
|
|
33161
33279
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -33382,7 +33500,7 @@ var TOMBSTONE_METADATA_HASH_PREIMAGE = "vana.data-point.tombstone.metadata.v1";
|
|
|
33382
33500
|
var TOMBSTONE_DATA_HASH = "0x30c45ee72fe56d1927701316925ab7ceacd3b6f9267061735d59396f075c6222";
|
|
33383
33501
|
var TOMBSTONE_METADATA_HASH = "0xc5255a141acd6a2ae55971b62c0a85977c2511989dc114ad2abc2b7644f57d90";
|
|
33384
33502
|
function computeTombstoneHash(preimage) {
|
|
33385
|
-
return
|
|
33503
|
+
return keccak2563(stringToBytes3(preimage));
|
|
33386
33504
|
}
|
|
33387
33505
|
function isTombstoneHashes(dataHash, metadataHash) {
|
|
33388
33506
|
return typeof dataHash === "string" && typeof metadataHash === "string" && dataHash.toLowerCase() === TOMBSTONE_DATA_HASH && metadataHash.toLowerCase() === TOMBSTONE_METADATA_HASH;
|
|
@@ -34404,6 +34522,13 @@ var QUESTION_STATUSES = [
|
|
|
34404
34522
|
"failed",
|
|
34405
34523
|
"stale"
|
|
34406
34524
|
];
|
|
34525
|
+
var DERIVATIVE_ERROR_CODES = [
|
|
34526
|
+
"inference_unavailable",
|
|
34527
|
+
"source_missing",
|
|
34528
|
+
"grant_invalid",
|
|
34529
|
+
"internal"
|
|
34530
|
+
];
|
|
34531
|
+
var DerivativeErrorCodeSchema = z5.enum(DERIVATIVE_ERROR_CODES);
|
|
34407
34532
|
var QuestionStatusSchema = z5.enum(QUESTION_STATUSES);
|
|
34408
34533
|
var QuestionRegisteredBySchema = z5.union([
|
|
34409
34534
|
z5.object({ kind: z5.literal("owner") }),
|
|
@@ -34425,6 +34550,14 @@ var DerivativeQuestionSchema = z5.object({
|
|
|
34425
34550
|
status: QuestionStatusSchema,
|
|
34426
34551
|
/** A short reason, set only while `status` is `failed`. */
|
|
34427
34552
|
error: nullableString,
|
|
34553
|
+
/**
|
|
34554
|
+
* The coarse failure class behind `error`, set only while `status` is
|
|
34555
|
+
* `failed`. `null` from a Personal Server that predates the class
|
|
34556
|
+
* (`personal-server-ts` before the status route).
|
|
34557
|
+
*/
|
|
34558
|
+
errorCode: DerivativeErrorCodeSchema.nullish().transform(
|
|
34559
|
+
(value) => value ?? null
|
|
34560
|
+
),
|
|
34428
34561
|
createdAt: z5.string(),
|
|
34429
34562
|
updatedAt: nullableString,
|
|
34430
34563
|
/** When the last compute finished, or `null` while `pending`. */
|
|
@@ -34557,6 +34690,7 @@ async function questionErrorFromResponse(response, body) {
|
|
|
34557
34690
|
);
|
|
34558
34691
|
}
|
|
34559
34692
|
}
|
|
34693
|
+
var personalServerErrorFromQuestionResponse = questionErrorFromResponse;
|
|
34560
34694
|
async function sendOnce(params, resolved, session, spec, bodyBytes) {
|
|
34561
34695
|
return sendWithFreshProof(
|
|
34562
34696
|
spec.label,
|
|
@@ -34836,6 +34970,166 @@ async function askPersonalServer(params) {
|
|
|
34836
34970
|
return { registration, record };
|
|
34837
34971
|
}
|
|
34838
34972
|
|
|
34973
|
+
// src/protocol/derivative-status.ts
|
|
34974
|
+
import { z as z6 } from "zod";
|
|
34975
|
+
var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
|
|
34976
|
+
var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
|
|
34977
|
+
var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
|
|
34978
|
+
var nullable = (schema) => schema.nullish().transform((value) => value ?? null);
|
|
34979
|
+
var DerivativeStatusSchema = z6.object({
|
|
34980
|
+
derivedScope: z6.string().min(1),
|
|
34981
|
+
status: QuestionStatusSchema,
|
|
34982
|
+
/** When the last compute finished, or `null` if none ever has. */
|
|
34983
|
+
lastComputedAt: nullable(z6.string()),
|
|
34984
|
+
/** Local version of the derived record the last compute wrote. */
|
|
34985
|
+
derivedVersion: nullable(z6.number()),
|
|
34986
|
+
derivedCollectedAt: nullable(z6.string()),
|
|
34987
|
+
/** The failure class; `null` unless `status` is `failed`. */
|
|
34988
|
+
errorCode: nullable(DerivativeErrorCodeSchema),
|
|
34989
|
+
/**
|
|
34990
|
+
* Seconds until the Personal Server's next automatic retry, or `null` when
|
|
34991
|
+
* none is pending or running — the terminal signature. Poll on this cadence
|
|
34992
|
+
* rather than guessing one.
|
|
34993
|
+
*/
|
|
34994
|
+
retryAfterSeconds: nullable(z6.number())
|
|
34995
|
+
});
|
|
34996
|
+
function derivativeStatusTarget(derivedScope) {
|
|
34997
|
+
return `${DERIVATIVE_STATUS_PATH}?derivedScope=${encodeURIComponent(derivedScope)}`;
|
|
34998
|
+
}
|
|
34999
|
+
function normalizeBaseUrl3(url) {
|
|
35000
|
+
return url.replace(/\/+$/, "");
|
|
35001
|
+
}
|
|
35002
|
+
function resolveFetch3(fetchFn) {
|
|
35003
|
+
const resolved = fetchFn ?? globalThis.fetch;
|
|
35004
|
+
if (resolved === void 0) {
|
|
35005
|
+
throw new WriteRequestError("No fetch implementation available");
|
|
35006
|
+
}
|
|
35007
|
+
return resolved;
|
|
35008
|
+
}
|
|
35009
|
+
function requireDerivedScope(derivedScope) {
|
|
35010
|
+
if (typeof derivedScope !== "string" || derivedScope.length === 0) {
|
|
35011
|
+
throw new WriteRequestError("derivedScope is required");
|
|
35012
|
+
}
|
|
35013
|
+
return derivedScope;
|
|
35014
|
+
}
|
|
35015
|
+
function sleep3(ms, signal) {
|
|
35016
|
+
if (ms <= 0) return Promise.resolve();
|
|
35017
|
+
return new Promise((resolve, reject) => {
|
|
35018
|
+
const timer = setTimeout(() => {
|
|
35019
|
+
signal?.removeEventListener("abort", onAbort);
|
|
35020
|
+
resolve();
|
|
35021
|
+
}, ms);
|
|
35022
|
+
const onAbort = () => {
|
|
35023
|
+
clearTimeout(timer);
|
|
35024
|
+
reject(abortError2(signal));
|
|
35025
|
+
};
|
|
35026
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
35027
|
+
});
|
|
35028
|
+
}
|
|
35029
|
+
function timeoutError(latest, timeoutMs) {
|
|
35030
|
+
return new DerivativeQuestionTimeoutError(
|
|
35031
|
+
`Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
|
|
35032
|
+
{
|
|
35033
|
+
derivedScope: latest.derivedScope,
|
|
35034
|
+
status: latest.status,
|
|
35035
|
+
errorCode: latest.errorCode,
|
|
35036
|
+
retryAfterSeconds: latest.retryAfterSeconds,
|
|
35037
|
+
timeoutMs
|
|
35038
|
+
}
|
|
35039
|
+
);
|
|
35040
|
+
}
|
|
35041
|
+
function abortError2(signal) {
|
|
35042
|
+
const reason = signal?.reason;
|
|
35043
|
+
return reason instanceof Error ? reason : new WriteRequestError("Derivative status wait was aborted");
|
|
35044
|
+
}
|
|
35045
|
+
function isDerivativeStatusSettled(status) {
|
|
35046
|
+
if (status.status === "ready") return true;
|
|
35047
|
+
return status.status === "failed" && status.retryAfterSeconds === null;
|
|
35048
|
+
}
|
|
35049
|
+
async function getDerivativeStatus(params) {
|
|
35050
|
+
const derivedScope = requireDerivedScope(params.derivedScope);
|
|
35051
|
+
const fetchFn = resolveFetch3(params.fetch);
|
|
35052
|
+
const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
|
|
35053
|
+
const signer = resolveWriteSigner(params.signer, { account: params.account });
|
|
35054
|
+
const headers = new Headers(params.headers);
|
|
35055
|
+
headers.set(
|
|
35056
|
+
"Authorization",
|
|
35057
|
+
await buildWeb3SignedHeader({
|
|
35058
|
+
signMessage: signer.signMessage,
|
|
35059
|
+
aud: params.audience ?? baseUrl,
|
|
35060
|
+
method: "GET",
|
|
35061
|
+
uri: DERIVATIVE_STATUS_PATH,
|
|
35062
|
+
grantId: params.grantId
|
|
35063
|
+
})
|
|
35064
|
+
);
|
|
35065
|
+
let response;
|
|
35066
|
+
try {
|
|
35067
|
+
response = await fetchFn(
|
|
35068
|
+
`${baseUrl}${derivativeStatusTarget(derivedScope)}`,
|
|
35069
|
+
{
|
|
35070
|
+
method: "GET",
|
|
35071
|
+
headers,
|
|
35072
|
+
...params.signal ? { signal: params.signal } : {}
|
|
35073
|
+
}
|
|
35074
|
+
);
|
|
35075
|
+
} catch (err) {
|
|
35076
|
+
throw new WriteTransportError(
|
|
35077
|
+
`Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
35078
|
+
1,
|
|
35079
|
+
err
|
|
35080
|
+
);
|
|
35081
|
+
}
|
|
35082
|
+
if (!response.ok) {
|
|
35083
|
+
throw await personalServerErrorFromQuestionResponse(
|
|
35084
|
+
response
|
|
35085
|
+
);
|
|
35086
|
+
}
|
|
35087
|
+
let body;
|
|
35088
|
+
try {
|
|
35089
|
+
body = await response.json();
|
|
35090
|
+
} catch (err) {
|
|
35091
|
+
throw new DerivativeQuestionRejectedError(
|
|
35092
|
+
"Derivative status response is not JSON",
|
|
35093
|
+
response.status,
|
|
35094
|
+
null,
|
|
35095
|
+
{ cause: err instanceof Error ? err.message : String(err) }
|
|
35096
|
+
);
|
|
35097
|
+
}
|
|
35098
|
+
const parsed = DerivativeStatusSchema.safeParse(body);
|
|
35099
|
+
if (!parsed.success) {
|
|
35100
|
+
throw new DerivativeQuestionRejectedError(
|
|
35101
|
+
"Derivative status response is not a status view",
|
|
35102
|
+
response.status,
|
|
35103
|
+
null,
|
|
35104
|
+
{ issues: parsed.error.issues }
|
|
35105
|
+
);
|
|
35106
|
+
}
|
|
35107
|
+
return parsed.data;
|
|
35108
|
+
}
|
|
35109
|
+
async function waitForDerivativeStatus(params) {
|
|
35110
|
+
const timeoutMs = Math.max(
|
|
35111
|
+
0,
|
|
35112
|
+
params.timeoutMs ?? DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS
|
|
35113
|
+
);
|
|
35114
|
+
const pollIntervalMs = Math.max(
|
|
35115
|
+
0,
|
|
35116
|
+
params.pollIntervalMs ?? DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS
|
|
35117
|
+
);
|
|
35118
|
+
const deadline = Date.now() + timeoutMs;
|
|
35119
|
+
for (; ; ) {
|
|
35120
|
+
if (params.signal?.aborted) throw abortError2(params.signal);
|
|
35121
|
+
const latest = await getDerivativeStatus(params);
|
|
35122
|
+
if (isDerivativeStatusSettled(latest)) return latest;
|
|
35123
|
+
const remaining = deadline - Date.now();
|
|
35124
|
+
if (remaining <= 0) throw timeoutError(latest, timeoutMs);
|
|
35125
|
+
const waitMs = latest.retryAfterSeconds === null ? pollIntervalMs : latest.retryAfterSeconds * 1e3;
|
|
35126
|
+
if (waitMs > remaining) {
|
|
35127
|
+
throw timeoutError(latest, timeoutMs);
|
|
35128
|
+
}
|
|
35129
|
+
await sleep3(waitMs, params.signal);
|
|
35130
|
+
}
|
|
35131
|
+
}
|
|
35132
|
+
|
|
34839
35133
|
// src/protocol/gateway.ts
|
|
34840
35134
|
function withGrantPermissions(grant) {
|
|
34841
35135
|
const stripped = { ...grant };
|
|
@@ -35916,9 +36210,13 @@ export {
|
|
|
35916
36210
|
ContractNotFoundError,
|
|
35917
36211
|
DATA_ACCESS_OP_TYPE,
|
|
35918
36212
|
DATA_REGISTRY_STATUS_ABI,
|
|
36213
|
+
DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
|
|
36214
|
+
DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
|
|
35919
36215
|
DEFAULT_QUESTION_POLL_INTERVAL_MS,
|
|
35920
36216
|
DEFAULT_QUESTION_TIMEOUT_MS,
|
|
36217
|
+
DERIVATIVE_ERROR_CODES,
|
|
35921
36218
|
DERIVATIVE_QUESTIONS_PATH,
|
|
36219
|
+
DERIVATIVE_STATUS_PATH,
|
|
35922
36220
|
DataFileEnvelopeSchema,
|
|
35923
36221
|
DataPointDeletedError,
|
|
35924
36222
|
DataPointNotFoundError,
|
|
@@ -35927,6 +36225,7 @@ export {
|
|
|
35927
36225
|
DerivativeComputeUnavailableError,
|
|
35928
36226
|
DerivativeCycleError,
|
|
35929
36227
|
DerivativeDerivedScopeRequiredError,
|
|
36228
|
+
DerivativeErrorCodeSchema,
|
|
35930
36229
|
DerivativeQuestionFailedError,
|
|
35931
36230
|
DerivativeQuestionInvalidError,
|
|
35932
36231
|
DerivativeQuestionNotFoundError,
|
|
@@ -35934,8 +36233,12 @@ export {
|
|
|
35934
36233
|
DerivativeQuestionSchema,
|
|
35935
36234
|
DerivativeQuestionTimeoutError,
|
|
35936
36235
|
DerivativeSourceNotGrantedError,
|
|
36236
|
+
DerivativeStatusSchema,
|
|
35937
36237
|
DropboxStorage,
|
|
35938
36238
|
ECIESError,
|
|
36239
|
+
ENCLAVE_IDENTITY_EVIDENCE_VERSION,
|
|
36240
|
+
ENCLAVE_TRUST_ANCHORS,
|
|
36241
|
+
ENCLAVE_WALLET_PURPOSE,
|
|
35939
36242
|
ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
|
|
35940
36243
|
ExpiredTokenError,
|
|
35941
36244
|
FEE_REGISTRY_ABI,
|
|
@@ -35957,6 +36260,7 @@ export {
|
|
|
35957
36260
|
LineageNodeSchema,
|
|
35958
36261
|
LineageReadError,
|
|
35959
36262
|
MASTER_KEY_MESSAGE,
|
|
36263
|
+
MASTER_SIGNATURE_DELIVERY_VERSION,
|
|
35960
36264
|
MAX_LINEAGE_SOURCES,
|
|
35961
36265
|
MAX_QUESTION_CHARS,
|
|
35962
36266
|
MAX_QUESTION_MODEL_CHARS,
|
|
@@ -35994,6 +36298,7 @@ export {
|
|
|
35994
36298
|
RedactedLineageNodeSchema,
|
|
35995
36299
|
RelayerError,
|
|
35996
36300
|
SCOPE_ACTIONS,
|
|
36301
|
+
SEALED_ENVELOPE_VERSION,
|
|
35997
36302
|
SERVER_REGISTRATION_TYPES,
|
|
35998
36303
|
ScopeSchema,
|
|
35999
36304
|
SerializationError,
|
|
@@ -36006,6 +36311,7 @@ export {
|
|
|
36006
36311
|
TOMBSTONE_METADATA_HASH,
|
|
36007
36312
|
TOMBSTONE_METADATA_HASH_PREIMAGE,
|
|
36008
36313
|
TransactionPendingError,
|
|
36314
|
+
USER_PS_ID_DOMAIN,
|
|
36009
36315
|
UserRejectedRequestError,
|
|
36010
36316
|
VanaError,
|
|
36011
36317
|
VanaStorage,
|
|
@@ -36024,6 +36330,7 @@ export {
|
|
|
36024
36330
|
WriteSessionExpiredError,
|
|
36025
36331
|
WriteTransportError,
|
|
36026
36332
|
WriteUnauthorizedError,
|
|
36333
|
+
appRootPreimage,
|
|
36027
36334
|
askPersonalServer,
|
|
36028
36335
|
assertDerivedScopeNaming,
|
|
36029
36336
|
assertValidPkceVerifier,
|
|
@@ -36037,6 +36344,7 @@ export {
|
|
|
36037
36344
|
buildEscrowPaymentHeader,
|
|
36038
36345
|
buildGrantPaymentHeader,
|
|
36039
36346
|
buildMarkDataPointUnavailableRequest,
|
|
36347
|
+
buildMasterSignatureDelivery,
|
|
36040
36348
|
buildPersonalServerDataReadRequest,
|
|
36041
36349
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
36042
36350
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
@@ -36069,6 +36377,7 @@ export {
|
|
|
36069
36377
|
decryptWithPassword,
|
|
36070
36378
|
deleteDataPoint,
|
|
36071
36379
|
deleteQuestion,
|
|
36380
|
+
derivativeStatusTarget,
|
|
36072
36381
|
deriveDataPointId,
|
|
36073
36382
|
deriveMasterKey,
|
|
36074
36383
|
deriveScopeKey,
|
|
@@ -36079,6 +36388,7 @@ export {
|
|
|
36079
36388
|
encodeDepositTokenData,
|
|
36080
36389
|
encodeSetDataPointStatusData,
|
|
36081
36390
|
encodeWriteMetadataHeader,
|
|
36391
|
+
encryptMasterSignatureDelivery,
|
|
36082
36392
|
encryptWithPassword,
|
|
36083
36393
|
escrowContractAddress,
|
|
36084
36394
|
escrowPaymentDomain,
|
|
@@ -36092,6 +36402,7 @@ export {
|
|
|
36092
36402
|
getContractAddress,
|
|
36093
36403
|
getContractController,
|
|
36094
36404
|
getContractInfo,
|
|
36405
|
+
getDerivativeStatus,
|
|
36095
36406
|
getFee,
|
|
36096
36407
|
getGatewayLineage,
|
|
36097
36408
|
getLineage,
|
|
@@ -36107,10 +36418,12 @@ export {
|
|
|
36107
36418
|
isDataPointId,
|
|
36108
36419
|
isDataPointTombstone,
|
|
36109
36420
|
isDataPortabilityGatewayConfig,
|
|
36421
|
+
isDerivativeStatusSettled,
|
|
36110
36422
|
isECIESEncrypted,
|
|
36111
36423
|
isPlatformSupported,
|
|
36112
36424
|
isRedactedLineageNode,
|
|
36113
36425
|
isTombstoneHashes,
|
|
36426
|
+
kmsIssuedPreimage,
|
|
36114
36427
|
listQuestions,
|
|
36115
36428
|
mainnetServices,
|
|
36116
36429
|
moksha,
|
|
@@ -36150,10 +36463,13 @@ export {
|
|
|
36150
36463
|
toDirectPaymentReceipt,
|
|
36151
36464
|
tombstoneDeletedAt,
|
|
36152
36465
|
tryGrantPermissions,
|
|
36466
|
+
userPsId,
|
|
36153
36467
|
vanaMainnet2 as vanaMainnet,
|
|
36468
|
+
verifyEnclaveIdentityEvidence,
|
|
36154
36469
|
verifyGrantRegistration,
|
|
36155
36470
|
verifyPkceChallenge,
|
|
36156
36471
|
verifyWeb3Signed,
|
|
36472
|
+
waitForDerivativeStatus,
|
|
36157
36473
|
waitForQuestion,
|
|
36158
36474
|
writeData,
|
|
36159
36475
|
writePersonalServerData
|