@tangle-network/sandbox 1.0.161 → 1.0.162

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/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { i as profileChannelReference, n as SandboxLines, r as lineInstanceKey,
10
10
  import { t as downloadFile } from "./file-download-Bo3IypMO.js";
11
11
  import { PublicTemplatePublishError, PublicTemplatesClient } from "./public-templates.js";
12
12
  import { a as LINE_APPLICATION_REPLY_MAX_CHARS, c as parseLineApplicationResult, i as gatewaySeatTransport, l as sandboxFailureKind, n as SeatSelectionError, o as LINE_APPLICATION_REQUEST_MAX_BYTES, r as createSelectSeat, s as parseLineApplicationRequest, t as ISOLATED_CREATION_ATTESTATION_VERSION } from "./core-D6HUTcWA.js";
13
- import { s as TangleSandboxClient } from "./tangle-Cvx8XhyV.js";
13
+ import { s as TangleSandboxClient } from "./tangle-Coo11OLc.js";
14
14
  import { z } from "zod";
15
15
  //#region ../../../packages/runtime-contracts/dist/model-key-proxy.js
16
16
  const MANAGED_MODEL_KEY_SENTINEL = "proxy-managed-per-request";
@@ -1,2 +1,2 @@
1
- import { _ as SandboxCreateParamTypes, a as parseQuoteResponse, c as OperatorSession, d as TANGLE_JOBS_CONTRACT, f as ITangleJobsAbi, g as JsonResponseParamTypes, h as JOB_SANDBOX_DELETE, i as jobQuoteDigest, l as OperatorSessionError, m as JOB_SANDBOX_CREATE, n as fetchQuote, o as validateQuote, p as AgentSandboxBlueprintAbi, r as inputsHashOf, s as TangleSandboxClient, t as QuoteError, u as TANGLE_CHAIN_ID, v as SandboxCreateResponseParamTypes, y as SandboxIdParamTypes } from "../tangle-Cvx8XhyV.js";
1
+ import { _ as SandboxCreateParamTypes, a as parseQuoteResponse, c as OperatorSession, d as TANGLE_JOBS_CONTRACT, f as ITangleJobsAbi, g as JsonResponseParamTypes, h as JOB_SANDBOX_DELETE, i as jobQuoteDigest, l as OperatorSessionError, m as JOB_SANDBOX_CREATE, n as fetchQuote, o as validateQuote, p as AgentSandboxBlueprintAbi, r as inputsHashOf, s as TangleSandboxClient, t as QuoteError, u as TANGLE_CHAIN_ID, v as SandboxCreateResponseParamTypes, y as SandboxIdParamTypes } from "../tangle-Coo11OLc.js";
2
2
  export { AgentSandboxBlueprintAbi, ITangleJobsAbi, JOB_SANDBOX_CREATE, JOB_SANDBOX_DELETE, JsonResponseParamTypes, OperatorSession, OperatorSessionError, QuoteError, SandboxCreateParamTypes, SandboxCreateResponseParamTypes, SandboxIdParamTypes, TANGLE_CHAIN_ID, TANGLE_JOBS_CONTRACT, TangleSandboxClient, fetchQuote, inputsHashOf, jobQuoteDigest, parseQuoteResponse, validateQuote };
@@ -630,6 +630,125 @@ var TangleChainClient = class {
630
630
  }
631
631
  };
632
632
  //#endregion
633
+ //#region src/tangle/azure-attestation.ts
634
+ var AzureAttestationError = class extends Error {
635
+ constructor(sandboxId, reason) {
636
+ super(`Azure attestation was refused for sandbox ${sandboxId}: ${reason}`);
637
+ this.name = "AzureAttestationError";
638
+ }
639
+ };
640
+ /** True when `issuer` is an https Azure Attestation host with no path or userinfo. */
641
+ function isAzureAttestationIssuer(issuer) {
642
+ return azureOrigin(issuer) !== null;
643
+ }
644
+ async function assertAzureProductionToken(sandboxId, token, attestationNonce) {
645
+ const header = decodePart$1(sandboxId, token, 0);
646
+ if (header.alg !== "RS256") throw new AzureAttestationError(sandboxId, "token must use RS256");
647
+ if (header.crit != null && (!Array.isArray(header.crit) || header.crit.length > 0)) throw new AzureAttestationError(sandboxId, "token has an unsupported critical header");
648
+ if (!header.kid) throw new AzureAttestationError(sandboxId, "token has no signing key");
649
+ const origin = azureOrigin(decodePart$1(sandboxId, token, 1).iss ?? "");
650
+ if (!origin) throw new AzureAttestationError(sandboxId, "issuer was not Azure Attestation");
651
+ if (!await verifyRs256$1(sandboxId, token, await signingKey$1(sandboxId, origin, header.kid))) throw new AzureAttestationError(sandboxId, "signature was not made by Azure Attestation");
652
+ const claims = decodePart$1(sandboxId, token, 1);
653
+ const now = Math.floor(Date.now() / 1e3);
654
+ if (typeof claims.exp !== "number" || !Number.isInteger(claims.exp) || claims.exp + 60 < now) throw new AzureAttestationError(sandboxId, "token is expired");
655
+ if (claims.nbf !== void 0 && (typeof claims.nbf !== "number" || !Number.isInteger(claims.nbf) || claims.nbf > now + 60)) throw new AzureAttestationError(sandboxId, "token is not valid yet");
656
+ if (azureOrigin(claims.iss ?? "") !== origin) throw new AzureAttestationError(sandboxId, "issuer was not Azure Attestation");
657
+ productionClaims(sandboxId, claims);
658
+ const vm = claims["x-ms-runtime"]?.["vm-configuration"];
659
+ if (vm && vm["secure-boot"] !== true) throw new AzureAttestationError(sandboxId, "secure boot is not enabled");
660
+ if (attestationNonce) nonceMatches(sandboxId, claims, attestationNonce);
661
+ }
662
+ function productionClaims(sandboxId, claims) {
663
+ if (claims["x-ms-ver"] !== "1.0") throw new AzureAttestationError(sandboxId, "token version is not 1.0");
664
+ if (claims["x-ms-compliance-status"] !== "azure-compliant-cvm") throw new AzureAttestationError(sandboxId, "token is not an Azure-compliant confidential VM");
665
+ if (claims["x-ms-attestation-type"] === "sevsnpvm") {
666
+ if (claims["x-ms-sevsnpvm-is-debuggable"] !== false) throw new AzureAttestationError(sandboxId, "SEV-SNP token is debuggable");
667
+ return;
668
+ }
669
+ if (claims["x-ms-attestation-type"] === "tdxvm") {
670
+ if (claims.dbgstat !== "disabled" || claims.tdx_td_attributes_debug !== false) throw new AzureAttestationError(sandboxId, "TDX token is debuggable");
671
+ return;
672
+ }
673
+ throw new AzureAttestationError(sandboxId, "token is not a confidential VM attestation");
674
+ }
675
+ function nonceMatches(sandboxId, claims, attestationNonce) {
676
+ const presented = (claims.nonce ?? claims.rp_data ?? "").trim().replace(/^0x/i, "").toLowerCase();
677
+ const direct = attestationNonce.trim().replace(/^0x/i, "").toLowerCase();
678
+ const padded = paddedNonceHex(attestationNonce);
679
+ if (presented.length > 0 && (presented === direct || presented === padded)) return;
680
+ throw new AzureAttestationError(sandboxId, "nonce did not match the caller challenge");
681
+ }
682
+ function paddedNonceHex(nonce) {
683
+ const hex = nonce.trim().replace(/^0x/i, "");
684
+ if (hex.length % 2 !== 0 || hex.length < 64 || hex.length > 128 || !/^[0-9a-fA-F]+$/.test(hex)) return null;
685
+ const bytes = hex.length / 2;
686
+ if (bytes < 32 || bytes > 64) return null;
687
+ return `${hex}${"0".repeat((64 - bytes) * 2)}`.toLowerCase();
688
+ }
689
+ function azureOrigin(issuer) {
690
+ let url;
691
+ try {
692
+ url = new URL(issuer);
693
+ } catch {
694
+ return null;
695
+ }
696
+ if (url.protocol !== "https:") return null;
697
+ if (url.username || url.password || url.port) return null;
698
+ if (url.pathname !== "/" && url.pathname !== "") return null;
699
+ if (url.search || url.hash) return null;
700
+ const host = url.hostname;
701
+ if (!host.endsWith(".attest.azure.net") || host.length <= 17 || host.split(".").some((label) => label.length === 0)) return null;
702
+ return `https://${host}`;
703
+ }
704
+ function decodePart$1(sandboxId, token, index) {
705
+ const encoded = token.split(".")[index];
706
+ if (!encoded) throw new AzureAttestationError(sandboxId, "evidence is not a JWT");
707
+ try {
708
+ return JSON.parse(new TextDecoder().decode(base64Url$1(encoded)));
709
+ } catch {
710
+ throw new AzureAttestationError(sandboxId, "evidence is not a JWT");
711
+ }
712
+ }
713
+ async function signingKey$1(sandboxId, origin, kid) {
714
+ const response = await fetch(`${origin}/certs`, {
715
+ redirect: "error",
716
+ signal: AbortSignal.timeout(1e4)
717
+ });
718
+ if (!response.ok) throw new AzureAttestationError(sandboxId, "attestation key fetch failed");
719
+ const key = (await response.json()).keys?.find((candidate) => candidate.kid === kid && (candidate.kty === void 0 || candidate.kty === "RSA") && (candidate.alg === void 0 || candidate.alg === "RS256") && typeof candidate.n === "string" && candidate.n.length > 0 && typeof candidate.e === "string" && candidate.e.length > 0);
720
+ if (!key) throw new AzureAttestationError(sandboxId, "attestation signing key was not published");
721
+ return key;
722
+ }
723
+ async function verifyRs256$1(sandboxId, token, jwk) {
724
+ const [header, payload, signature] = token.split(".");
725
+ if (!header || !payload || !signature || !jwk.n || !jwk.e) return false;
726
+ const subtle = globalThis.crypto?.subtle;
727
+ if (!subtle) throw new AzureAttestationError(sandboxId, "attestation verification is unavailable");
728
+ try {
729
+ const key = await subtle.importKey("jwk", {
730
+ kty: "RSA",
731
+ n: jwk.n,
732
+ e: jwk.e,
733
+ alg: "RS256",
734
+ ext: true
735
+ }, {
736
+ name: "RSASSA-PKCS1-v1_5",
737
+ hash: "SHA-256"
738
+ }, false, ["verify"]);
739
+ return await subtle.verify("RSASSA-PKCS1-v1_5", key, base64Url$1(signature), new TextEncoder().encode(`${header}.${payload}`));
740
+ } catch {
741
+ return false;
742
+ }
743
+ }
744
+ function base64Url$1(encoded) {
745
+ const padded = encoded.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - encoded.length % 4) % 4);
746
+ const binary = atob(padded);
747
+ const bytes = new Uint8Array(binary.length);
748
+ for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
749
+ return bytes;
750
+ }
751
+ //#endregion
633
752
  //#region src/tangle/gcp-attestation.ts
634
753
  /**
635
754
  * Verify a Google Confidential Space token before a Tangle create returns.
@@ -640,7 +759,7 @@ var TangleChainClient = class {
640
759
  */
641
760
  const ISSUER = "https://confidentialcomputing.googleapis.com";
642
761
  const JWKS_URL = "https://www.googleapis.com/service_accounts/v1/metadata/jwk/signer@confidentialspace-sign.iam.gserviceaccount.com";
643
- const MAX_EVIDENCE_BYTES = 8192;
762
+ const MAX_EVIDENCE_BYTES$1 = 8192;
644
763
  var GcpAttestationError = class extends Error {
645
764
  constructor(sandboxId, reason) {
646
765
  super(`GCP attestation was refused for sandbox ${sandboxId}: ${reason}`);
@@ -653,7 +772,7 @@ async function assertGcpProductionToken(sandboxId, teeAttestationJson) {
653
772
  if (!evidence) return;
654
773
  const token = compactJwt(evidence);
655
774
  if (!token) return;
656
- if (evidence.length > MAX_EVIDENCE_BYTES) throw new GcpAttestationError(sandboxId, "evidence is too large");
775
+ if (evidence.length > MAX_EVIDENCE_BYTES$1) throw new GcpAttestationError(sandboxId, "evidence is too large");
657
776
  const header = decodePart(sandboxId, token, 0);
658
777
  if (header.alg !== "RS256") throw new GcpAttestationError(sandboxId, "token must use RS256");
659
778
  if ((header.crit?.length ?? 0) > 0) throw new GcpAttestationError(sandboxId, "token has an unsupported critical header");
@@ -670,6 +789,28 @@ async function assertGcpProductionToken(sandboxId, teeAttestationJson) {
670
789
  if (claims.secboot !== true || claims.swname !== "CONFIDENTIAL_SPACE") throw new GcpAttestationError(sandboxId, "token is not a secure-boot Confidential Space token");
671
790
  if (claims.hwmodel !== "GCP_AMD_SEV" && claims.hwmodel !== "GCP_AMD_SEV_SNP") throw new GcpAttestationError(sandboxId, "hardware model is not AMD SEV");
672
791
  }
792
+ /** A compact JWT found in attestation evidence, or null when the evidence is not one. */
793
+ function confidentialJwt(teeAttestationJson) {
794
+ const evidence = jwtEvidence(teeAttestationJson);
795
+ if (!evidence) return null;
796
+ const token = compactJwt(evidence);
797
+ if (!token) return null;
798
+ return {
799
+ evidence,
800
+ token
801
+ };
802
+ }
803
+ /** Issuer claim from an unverified payload. Used only to choose a verifier. */
804
+ function unverifiedIssuer(token) {
805
+ try {
806
+ const encoded = token.split(".")[1];
807
+ if (!encoded) return null;
808
+ const claims = JSON.parse(new TextDecoder().decode(base64Url(encoded)));
809
+ return typeof claims.iss === "string" ? claims.iss : null;
810
+ } catch {
811
+ return null;
812
+ }
813
+ }
673
814
  function jwtEvidence(raw) {
674
815
  if (!raw) return null;
675
816
  let parsed;
@@ -758,6 +899,39 @@ function byteOk(value) {
758
899
  return typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 255;
759
900
  }
760
901
  //#endregion
902
+ //#region src/tangle/cloud-attestation.ts
903
+ /**
904
+ * Choose the attestation check from the token issuer.
905
+ *
906
+ * Google Confidential Space and Microsoft Azure Attestation tokens are
907
+ * refused when they do not verify. Any other JWT is refused. Evidence that
908
+ * is not a JWT, including a Nitro document or a DCAP or SNP quote, is left
909
+ * alone: this client does not reimplement those verifiers.
910
+ */
911
+ const GOOGLE_ISSUER = "https://confidentialcomputing.googleapis.com";
912
+ const MAX_EVIDENCE_BYTES = 8192;
913
+ var CloudAttestationError = class extends Error {
914
+ constructor(sandboxId, reason) {
915
+ super(`Attestation was refused for sandbox ${sandboxId}: ${reason}`);
916
+ this.name = "CloudAttestationError";
917
+ }
918
+ };
919
+ async function assertProductionAttestation(sandboxId, teeAttestationJson, attestationNonce) {
920
+ const jwt = confidentialJwt(teeAttestationJson);
921
+ if (!jwt) return;
922
+ if (jwt.evidence.length > MAX_EVIDENCE_BYTES) throw new CloudAttestationError(sandboxId, "evidence is too large");
923
+ const issuer = unverifiedIssuer(jwt.token);
924
+ if (issuer === GOOGLE_ISSUER) {
925
+ await assertGcpProductionToken(sandboxId, teeAttestationJson);
926
+ return;
927
+ }
928
+ if (issuer && isAzureAttestationIssuer(issuer)) {
929
+ await assertAzureProductionToken(sandboxId, jwt.token, attestationNonce);
930
+ return;
931
+ }
932
+ throw new CloudAttestationError(sandboxId, "attestation token issuer is not a supported confidential computing authority");
933
+ }
934
+ //#endregion
761
935
  //#region src/tangle/operator-auth.ts
762
936
  const SESSION_REFRESH_MARGIN_MS = 6e4;
763
937
  var OperatorSessionError = class extends Error {
@@ -1039,7 +1213,7 @@ var TangleSandboxClient = class {
1039
1213
  teePublicKeyJson: wireEntry.teePublicKeyJson ?? responseJson.teePublicKeyJson,
1040
1214
  attestationNonce: attestationNonceFromOptions(createOptions) ?? wireEntry.attestationNonce
1041
1215
  };
1042
- await assertGcpProductionToken(sandboxId, entry.teeAttestationJson);
1216
+ await assertProductionAttestation(sandboxId, entry.teeAttestationJson, entry.attestationNonce);
1043
1217
  this.#sandboxes.set(sandboxId, entry);
1044
1218
  if (tangleSecrets && Object.keys(tangleSecrets).length > 0) await this.injectSecrets(sandboxId, tangleSecrets);
1045
1219
  return createSandboxInstanceFromResponse(this, sandboxInfoFromEntry(entry));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sandbox",
3
- "version": "1.0.161",
3
+ "version": "1.0.162",
4
4
  "description": "Client SDK for the Tangle Sandbox platform - build AI agent applications with dev containers",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -156,12 +156,12 @@
156
156
  "@products/sandbox-test-utils": "0.0.0",
157
157
  "@repo/shared": "0.0.0",
158
158
  "@tangle-network/agent-profile-materialize": "0.27.1",
159
- "@tangle-network/runtime-contracts": "0.20.0",
160
- "@tangle-network/cli-agent-registry": "0.15.0"
159
+ "@tangle-network/cli-agent-registry": "0.15.0",
160
+ "@tangle-network/runtime-contracts": "0.20.0"
161
161
  },
162
162
  "tangleRelease": {
163
- "sourceSha": "cd96d40df8316b2c8f00fbf9590ddefa0b1fda47",
164
- "mergedAt": "2026-10-31T19:13:30-06:00"
163
+ "sourceSha": "cda91dff0079b4e2902b8de4f47a86697eceeb34",
164
+ "mergedAt": "2026-10-31T19:20:11-06:00"
165
165
  },
166
166
  "scripts": {
167
167
  "build": "node scripts/build-dist.mjs",