@opendatalabs/vana-sdk 3.22.0-pr.207.0dbb052 → 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.
@@ -37,7 +37,7 @@ export { parseWeb3SignedHeader, verifyWeb3Signed, type Web3SignedPayload, type V
37
37
  export { buildWeb3SignedHeader, computeBodyHash, type Web3SignedSignFn, } from "./auth/web3-signed-builder.js";
38
38
  export { MissingAuthError, InvalidSignatureError, ExpiredTokenError, } from "./auth/errors.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
+ 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";
41
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";
42
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";
43
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";
@@ -31755,6 +31755,7 @@ var ENCLAVE_IDENTITY_EVIDENCE_VERSION = 1;
31755
31755
  var USER_PS_ID_DOMAIN = "vana.ps-enclave.v1";
31756
31756
  var ENCLAVE_WALLET_PURPOSE = "vana.ps-enclave.wallet.v1";
31757
31757
  var MASTER_SIGNATURE_DELIVERY_VERSION = "vana.ps-enclave.delivery.v1";
31758
+ var MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS = 600;
31758
31759
  var SEALED_ENVELOPE_VERSION = 1;
31759
31760
  var VANA_MAINNET_CHAIN_ID = 1480;
31760
31761
  var MOKSHA_CHAIN_ID = 14800;
@@ -31762,12 +31763,19 @@ var KMS_ISSUED_PREFIX = "dstack-kms-issued";
31762
31763
  var PREIMAGE_SEPARATOR = ":";
31763
31764
  var UNCOMPRESSED_PUBLIC_KEY_BYTES = 65;
31764
31765
  var UNCOMPRESSED_PUBLIC_KEY_PREFIX = "04";
31765
- var ENCLAVE_TRUST_ANCHORS = {
31766
+ var EMPTY_HEX = "0x";
31767
+ function emptyAnchor() {
31768
+ return Object.freeze({
31769
+ kmsRootPubkey: EMPTY_HEX,
31770
+ appIds: Object.freeze([])
31771
+ });
31772
+ }
31773
+ var ENCLAVE_TRUST_ANCHORS = Object.freeze({
31766
31774
  // filled at fleet provisioning; verify fails closed while empty
31767
- [VANA_MAINNET_CHAIN_ID]: { kmsRootPubkey: "0x", appIds: [] },
31775
+ [VANA_MAINNET_CHAIN_ID]: emptyAnchor(),
31768
31776
  // filled at fleet provisioning; verify fails closed while empty
31769
- [MOKSHA_CHAIN_ID]: { kmsRootPubkey: "0x", appIds: [] }
31770
- };
31777
+ [MOKSHA_CHAIN_ID]: emptyAnchor()
31778
+ });
31771
31779
  function userPsId(chainId, ownerAddress) {
31772
31780
  const packed = encodePacked(
31773
31781
  ["string", "uint256", "address"],
@@ -31780,6 +31788,15 @@ function compressPublicKey(publicKey) {
31780
31788
  fromHex5(publicKey, "bytes")
31781
31789
  ).toRawBytes(true);
31782
31790
  }
31791
+ function sameKey(a, b) {
31792
+ return toHex6(compressPublicKey(a)) === toHex6(compressPublicKey(b));
31793
+ }
31794
+ function assertUncompressedKey(publicKey) {
31795
+ const hex = publicKey.slice(2);
31796
+ if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
31797
+ throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
31798
+ }
31799
+ }
31783
31800
  function appRootPreimage(purpose, publicKey) {
31784
31801
  const keyHex = toHex6(compressPublicKey(publicKey)).slice(2);
31785
31802
  return keccak256(toBytes(`${purpose}${PREIMAGE_SEPARATOR}${keyHex}`));
@@ -31824,6 +31841,10 @@ async function verifyEnclaveIdentityEvidence(evidence, anchors, expected) {
31824
31841
  if (evidence.purpose !== ENCLAVE_WALLET_PURPOSE) {
31825
31842
  throw new Error("Unexpected enclave wallet purpose");
31826
31843
  }
31844
+ if (anchors.kmsRootPubkey === EMPTY_HEX) {
31845
+ throw new Error("KMS root trust anchor is not provisioned");
31846
+ }
31847
+ assertUncompressedKey(evidence.publicKey);
31827
31848
  const derivedAddress = publicKeyToAddress(evidence.publicKey);
31828
31849
  if (getAddress(derivedAddress) !== getAddress(evidence.address)) {
31829
31850
  throw new Error("Enclave public key does not match its address");
@@ -31838,10 +31859,13 @@ async function verifyEnclaveIdentityEvidence(evidence, anchors, expected) {
31838
31859
  evidence.signatureChain[1],
31839
31860
  1
31840
31861
  );
31841
- if (anchors.kmsRootPubkey === "0x") {
31842
- throw new Error("KMS root trust anchor is not provisioned");
31862
+ let matchesAnchor;
31863
+ try {
31864
+ matchesAnchor = sameKey(kmsRootPublicKey, anchors.kmsRootPubkey);
31865
+ } catch {
31866
+ throw new Error("KMS root trust anchor is malformed");
31843
31867
  }
31844
- if (kmsRootPublicKey !== anchors.kmsRootPubkey.toLowerCase()) {
31868
+ if (!matchesAnchor) {
31845
31869
  throw new Error("KMS root public key does not match the trust anchor");
31846
31870
  }
31847
31871
  if (keccak256(kmsRootPublicKey) !== evidence.kmsRootFingerprint.toLowerCase()) {
@@ -31868,14 +31892,13 @@ async function buildMasterSignatureDelivery(evidence, masterSignature, now = Mat
31868
31892
  issuedAt: now
31869
31893
  };
31870
31894
  }
31871
- function assertUncompressedKey(publicKey) {
31872
- const hex = publicKey.slice(2);
31873
- if (hex.length !== UNCOMPRESSED_PUBLIC_KEY_BYTES * 2 || !hex.startsWith(UNCOMPRESSED_PUBLIC_KEY_PREFIX) || !/^[0-9a-fA-F]+$/.test(hex)) {
31874
- throw new Error("Public key must be a 65-byte uncompressed secp256k1 key");
31875
- }
31876
- }
31877
31895
  async function encryptMasterSignatureDelivery(delivery, publicKey, ecies) {
31878
31896
  assertUncompressedKey(publicKey);
31897
+ if (!isAddressEqual(publicKeyToAddress(publicKey), delivery.enclaveAddress)) {
31898
+ throw new Error(
31899
+ "Public key does not belong to the delivery's enclave address"
31900
+ );
31901
+ }
31879
31902
  const plaintext = toBytes(JSON.stringify(delivery));
31880
31903
  const encrypted = await ecies.encrypt(fromHex5(publicKey, "bytes"), plaintext);
31881
31904
  return `0x${serializeECIES(encrypted)}`;
@@ -35191,6 +35214,7 @@ export {
35191
35214
  LineageNodeSchema,
35192
35215
  LineageReadError,
35193
35216
  MASTER_KEY_MESSAGE,
35217
+ MASTER_SIGNATURE_DELIVERY_MAX_AGE_SECONDS,
35194
35218
  MASTER_SIGNATURE_DELIVERY_VERSION,
35195
35219
  MAX_LINEAGE_SOURCES,
35196
35220
  MAX_QUESTION_CHARS,