Cryptographic Verification Tools for NEAR AI Cloud TEE-Protected AI
Python and TypeScript tools for validating NEAR AI Cloud attestation reports and response signatures. These verifiers provide cryptographic proof that your AI requests are processed in genuine Trusted Execution Environments (TEE) with hardware-enforced privacy.
- π TEE Attestation Verification - Cryptographic proof of genuine hardware
- π‘οΈ GPU TEE Verification - NVIDIA H100/H200 attestation via NRAS
- β Intel TDX Quote Validation - Verify CPU TEE measurements
- π ECDSA Signature Verification - Validate signed AI responses
- π¦ Sigstore Provenance - Container supply chain verification
- π Domain Verification - Gateway TLS attestation vs live certificate (default)
- π Multi-Server Support - Load balancer attestation aggregation
- Get NEAR AI Cloud API key from cloud.near.ai
- Python 3.10+
requests,eth-account,dcap-qvl,cryptography
- Node.js 20+
- TypeScript 5.8+
ethersfor cryptographic operationstsxfor TypeScript executiondcap-qvl-nodefor verifying TDX quotes
git clone https://github.com/nearai/nearai-cloud-verifier.git
cd nearai-cloud-verifier
# For Python
pip install -r requirements.txt
# For TypeScript
npm install -g pnpm
pnpm installexport API_KEY=sk-your-api-key-here
# Python
python3 py/model_verifier.py --model deepseek-ai/DeepSeek-V3.1
python3 py/model_verifier.py --model deepseek-ai/DeepSeek-V3.1 --verify-tls
# TypeScript
pnpm run model -- --model deepseek-ai/DeepSeek-V3.1
pnpm run model -- --model deepseek-ai/DeepSeek-V3.1 --verify-tlsexport API_KEY=sk-your-api-key-here
# Python
python3 py/chat_verifier.py --model deepseek-ai/DeepSeek-V3.1
# TypeScript
pnpm run chat -- --model deepseek-ai/DeepSeek-V3.1
# Optional: TLS PEM binding is implemented in model_verifier (gateway); chat_verifier only calls it when --verify-tls
python3 py/chat_verifier.py --model deepseek-ai/DeepSeek-V3.1 --verify-tls
pnpm run chat -- --model deepseek-ai/DeepSeek-V3.1 --verify-tlsexport API_KEY=sk-your-api-key-here
# Python - Test ECDSA encryption
python3 py/encrypted_chat_verifier.py --model deepseek-ai/DeepSeek-V3.1
# Python - Test both ECDSA and Ed25519
python3 py/encrypted_chat_verifier.py --model deepseek-ai/DeepSeek-V3.1 --test-both
# TypeScript - Test ECDSA encryption
pnpm run encrypted-chat -- --model deepseek-ai/DeepSeek-V3.1
# TypeScript - Test both algorithms
pnpm run encrypted-chat -- --model deepseek-ai/DeepSeek-V3.1 --test-both# Python β verify TLS cert is held inside TEE
python3 py/tls_verifier.py --url https://proxy.example.com:8443
# TypeScript
pnpm run tls -- --url https://proxy.example.com:8443Default behavior for domain_verifier: confirms the gatewayβs attested TLS material matches what the host serves on :443.
GET /v1/attestation/report?include_tls_fingerprint=trueβtls_certificate+gateway_attestation(withtls_cert_fingerprint)- Gateway
report_datamust bind that PEM (model_verifier.verify_attestation) - Leaf SHA256(DER) fingerprint must match the live server certificate
export BASE_URL=https://cloud-api.near.ai # optional; hostname defaults --domain
python3 py/domain_verifier.py
pnpm run domain
# Optional: --domain host --signing-address 0x... --model ...If the report has no tls_certificate, configure TLS_CERT_PATH on cloud-api.
Generates a fresh nonce, requests a new attestation, and verifies:
- GPU attestation: Submits GPU evidence payload to NVIDIA NRAS and verifies the nonce matches
- TDX report data: Validates that report data binds the signing key (ECDSA or Ed25519) and nonce
- Intel TDX quote: Verifies TDX quote with
dcap-qvllibrary - Compose manifest: Displays Docker compose manifest and verifies it matches the mr_config measurement
The model verifier also verifies the private inference gateway for
- TDX report data: Validates that report data includes the nonce in request
- Intel TDX quote: Verifies TDX quote with
dcap-qvllibrary - Compose manifest: Displays Docker compose manifest and verifies it matches the mr_config measurement
# Python
python3 py/model_verifier.py [--model MODEL_NAME]
# TypeScript
pnpm run model -- [--model MODEL_NAME]Default model: deepseek-ai/DeepSeek-V3.1
The verifier fetches attestations from the /v1/attestation/report endpoint. No API key is required for this endpoint.
========================================
π Gateway attestation
========================================
Request nonce: abc123...
π TDX report data
Signing algorithm: ecdsa
Report data binds signing address: True
Report data embeds request nonce: True
π Intel TDX quote
Intel TDX quote verified: True
Docker compose manifest attested by the enclave:
services:
cloud-api:
image: nearaidev/cloud-api@sha256:xxxxx
...
Compose sha256: abc123...
mr_config (from verified quote): 0x01abc123...
mr_config matches compose hash: True
π Sigstore provenance
Checking Sigstore accessibility for container images...
β https://search.sigstore.dev/?hash=sha256:c63f9... (HTTP 200)
========================================
π Model attestations: (#1)
========================================
Signing address: 0x1234...
Request nonce: abc123...
π TDX report data
Signing algorithm: ecdsa
Report data binds signing address: True
Report data embeds request nonce: True
π GPU attestation
GPU payload nonce matches request_nonce: True
NVIDIA attestation verdict: PASS
π Intel TDX quote
Intel TDX quote verified: True
Docker compose manifest attested by the enclave:
version: '3.8'
services:
model:
image: deepseek@sha256:77fbe5f...
...
Compose sha256: abc123...
mr_config (from verified quote): 0x01abc123...
mr_config matches compose hash: True
π Sigstore provenance
Checking Sigstore accessibility for container images...
β https://search.sigstore.dev/?hash=sha256:77fbe5f... (HTTP 200)
- β GPU TEE Measurements - Proves genuine NVIDIA H100/H200 TEE
- β Model Hash - Verifies exact model version
- β Code Hash - Confirms inference code integrity
- β Nonce Freshness - Prevents replay attacks
- β Cryptographic Binding - Signing key bound to hardware
- β Container Provenance - Verifies build supply chain
Fetches chat completions (streaming and non-streaming), verifies ECDSA signatures, and validates attestations:
- Sends chat completion request to
/v1/chat/completions - Fetches signature from
/v1/signature/{chat_id}endpoint - Verifies request hash and response hash match the signed hashes
- Recovers ECDSA signing address from signature
- Fetches fresh attestation with user-supplied nonce for the recovered signing address
- Validates attestation using the same checks as attestation verifier
Note: The verifier supplies a fresh nonce when fetching attestation (step 5), which ensures attestation freshness but means the nonce/report_data won't match the original signing context. This is expected behavior - the verifier proves the signing key is bound to valid hardware, not that a specific attestation was used for signing.
Set your API key as an environment variable:
export API_KEY=sk-your-api-key-hereOr create a .env file:
API_KEY=sk-your-api-key-hereThen run:
# Python
python3 py/model_verifier.py [--model MODEL_NAME]
# TypeScript
pnpm run model -- [--model MODEL_NAME]Default model: deepseek-ai/DeepSeek-V3.1
- β Request Body Hash - Matches server-computed hash
- β Response Text Hash - Matches server-computed hash
- β ECDSA Signature - Valid and recovers to claimed signing address
- β Signing Address Binding - Bound to hardware via TDX report data
- β GPU Attestation - Passes NVIDIA verification
- β Intel TDX Quote - Valid CPU TEE measurements
Tests end-to-end encryption for chat completions. Encrypts request messages and decrypts response content using ECDSA or Ed25519 signing algorithms.
Set your API key as an environment variable:
export API_KEY=sk-your-api-key-here# Python - Test with ECDSA (default)
python3 py/encrypted_chat_verifier.py --model deepseek-ai/DeepSeek-V3.1
# Python - Test with Ed25519
python3 py/encrypted_chat_verifier.py --model deepseek-ai/DeepSeek-V3.1 --signing-algo ed25519
# Python - Test both algorithms
python3 py/encrypted_chat_verifier.py --model deepseek-ai/DeepSeek-V3.1 --test-both
# TypeScript - Test with ECDSA (default)
pnpm run encrypted-chat -- --model deepseek-ai/DeepSeek-V3.1
# TypeScript - Test with Ed25519
pnpm run encrypted-chat -- --model deepseek-ai/DeepSeek-V3.1 --signing-algo ed25519
# TypeScript - Test both algorithms
pnpm run encrypted-chat -- --model deepseek-ai/DeepSeek-V3.1 --test-bothDefault model: deepseek-ai/DeepSeek-V3.1
- β End-to-End Encryption - Request messages encrypted with model's public key
- β Response Decryption - Response content decrypted with client's private key
- β ECDSA Encryption - ECIES (Elliptic Curve Integrated Encryption Scheme) with AES-GCM
- β Ed25519 Encryption - X25519 key exchange with ChaCha20-Poly1305
- β Streaming Support - Decrypts streaming responses in real-time
- β Non-Streaming Support - Decrypts complete non-streaming responses
The verifier automatically includes the following headers for encrypted requests:
X-Signing-Algo: Eitherecdsaored25519X-Client-Pub-Key: Client's public key in hex formatX-Model-Pub-Key: Model's public key from attestation report
Gateway TLS verification runs by default every time you run the domain verifier.
| Step | What it does |
|---|---|
| 1 | GET /v1/attestation/report?include_tls_fingerprint=true (optional signing_address) |
| 2 | verify_attestation(gateway, β¦, tls_certificate_pem) β report_data must bind the PEM |
| 3 | Leaf cert in tls_certificate must match live :443 (SHA256 fingerprint) |
export BASE_URL=https://cloud-api.near.ai # optional
python3 py/domain_verifier.py
pnpm run domain- β
Gateway
report_databindstls_certificate - β Same leaf cert served on the domain over TLS
========================================
π Domain TLS vs attestation report
========================================
Domain: cloud-api.near.ai
π Gateway attestation (include_tls_fingerprint binding)
...
π Live TLS certificate vs attested tls_certificate
Fetching certificate from live server: cloud-api.near.ai:443
Fingerprints match: True
Proves that a specific inference proxy's TLS certificate is held inside the TEE β not just trusted via CA chains. Uses a single TLS connection to fetch both the live certificate SPKI hash and the attestation report, preventing round-robin mismatches.
Verification steps:
- Connects to the proxy over TLS and extracts the live certificate's SPKI hash
- Requests attestation with
include_tls_fingerprint=trueover the same connection - Verifies the Intel TDX quote (
check_tdx_quote) - Checks
report_data[0..32] = SHA256(signing_address || spki_hash)andreport_data[32..64] = nonce - Compares the live SPKI hash against the attested
tls_cert_fingerprint
# Python β verify a specific inference proxy
python3 py/tls_verifier.py --url https://proxy.example.com:8443
# Python β with Ed25519 signing algo
python3 py/tls_verifier.py --url https://proxy.example.com:8443 --signing-algo ed25519
# TypeScript
pnpm run tls -- --url https://proxy.example.com:8443| Arg | Description |
|---|---|
--url |
HTTPS URL of the inference proxy (required) |
--signing-algo |
ecdsa (default) or ed25519 |
--token |
Bearer token if the proxy requires auth (defaults to API_KEY env) |
- β TLS Certificate Bound to TEE - Live SPKI hash matches the attested fingerprint inside the TDX quote
- β Intel TDX Quote - Hardware attestation cryptographically verified
- β Signing Address Binding - Signing key tied to TLS cert inside the TEE
- β Nonce Freshness - Prevents replay attacks
- β
GPU Attestation - NVIDIA NRAS verification (if
nvidia_payloadpresent) - β Compose Manifest - Docker compose verified against mr_config
Identifies the exact deployed cloud-api version by reading the Docker image digest out of its TDX-attested compose manifest, then resolving it to a git commit via GitHub's build attestation API.
python3 version_verifier.pyOutput:
Image: nearaidev/cloud-api@sha256:abc123...
Commit: a1b2c3d...
Build: https://github.com/nearai/cloud-api/actions/runs/...
GitHub: https://github.com/nearai/cloud-api/commit/a1b2c3d...
Requires gh CLI authenticated to GitHub.
Both scripts automatically extract all container image digests from the Docker compose manifest (matching @sha256:xxx patterns) and verify Sigstore accessibility for each image. This allows you to:
- Verify the container images were built from the expected source repository
- Review the GitHub Actions workflow that built the images
- Audit the build provenance and supply chain metadata
The verifiers check each Sigstore link with an HTTP HEAD request to ensure provenance data is available (not 404).
π Sigstore provenance
Checking Sigstore accessibility for container images...
β https://search.sigstore.dev/?hash=sha256:77fbe5f... (HTTP 200)
β https://search.sigstore.dev/?hash=sha256:abc123... (HTTP 200)
If a link returns β, the provenance data may not be available in Sigstore (either the image wasn't signed or the digest is incorrect).
In production deployments with multiple backend servers behind a load balancer:
- Each server has its own unique signing key/address
- Attestation requests with
signing_addressparameter return 404 if the address doesn't match - Response includes
model_attestations: [attestation](single-element array with this server's attestation)
When /v1/attestation/report?signing_address={addr}&nonce={nonce}:
- Broadcast the request to all backend servers
- Collect non-404 responses from servers matching the signing_address
- Merge
model_attestationsarrays from all responses - Return combined response with all servers' attestations
- Get signature β extract
signing_address - Request attestation with
signing_addressparameter - LB broadcasts β collect attestations from all servers
- Verifier finds matching attestation by comparing
signing_addressinmodel_attestations
{
"signing_address": "0xServer1...",
"intel_quote": "...",
"model_attestations": [
{"signing_address": "0xServer1...", "intel_quote": "...", ...},
{"signing_address": "0xServer2...", "intel_quote": "...", ...}
]
}The verifier filters model_attestations to find the entry matching the signature's signing_address.
TEE-Protected Inference
- Model weights in GPU TEE (NVIDIA H100/H200)
- Inference computation in GPU secure enclaves
- Complete end-to-end protection
- Verified via GPU attestation + signature verification
- β NVIDIA GPU vendor (H100/H200 TEE correctness)
- β Intel CPU vendor (TDX implementation)
- β Model operators
- β Cloud provider (AWS, GCP, Azure)
- β System administrators
- β Other users on same hardware
- β Hardware-Enforced Privacy - Data never leaves TEE in plaintext
- β Verifiable Execution - Cryptographic proof of code integrity
- β Tamper-Proof - Cannot be modified by operators or admins
- β Auditable - Full attestation reports for every request
# Python - Verify confidential model
python3 py/model_verifier.py
# Python - Verify specific model
python3 py/model_verifier.py --model deepseek-ai/DeepSeek-V3.1
# TypeScript - Verify default model
pnpm run model
# TypeScript - Verify specific model
pnpm run model -- --model deepseek-ai/DeepSeek-V3.1export API_KEY=sk-your-api-key-here
# Python
python3 py/chat_verifier.py --model deepseek-ai/DeepSeek-V3.1
# TypeScript
pnpm run chat -- --model deepseek-ai/DeepSeek-V3.1export BASE_URL=https://your-domain.near.ai
python3 py/domain_verifier.py
pnpm run domainfrom model_verifier import fetch_report, check_tdx_quote, check_gpu, check_report_data
import secrets
# Generate fresh nonce
nonce = secrets.token_hex(32)
# Fetch attestation
attestation = fetch_report("deepseek-ai/DeepSeek-V3.1", nonce)
# Verify all components
intel_result = await check_tdx_quote(attestation)
check_report_data(attestation, nonce, intel_result)
# With include_tls_fingerprint / tls_certificate: pass PEM so nonce component SHA256(nonce||SHA256(pem)) is accepted
# check_report_data(attestation, nonce, intel_result, tls_certificate_pem)
check_gpu(attestation, nonce)import {
fetchReport,
checkTdxQuote,
checkReportData,
checkGpu,
showSigstoreProvenance,
AttestationReport,
IntelResult
} from 'nearai-cloud-verifier';
import * as crypto from 'crypto';
// Generate fresh nonce
const nonce = crypto.randomBytes(32).toString('hex');
// Fetch attestation
const attestation: AttestationReport = await fetchReport('deepseek-ai/DeepSeek-V3.1', nonce);
// Verify all components
const intelResult: IntelResult = await checkTdxQuote(attestation);
checkReportData(attestation, nonce, intelResult);
// With include_tls_fingerprint: pass tlsCertificatePem as 4th arg so SHA256(nonce||SHA256(pem)) is accepted
// checkReportData(attestation, nonce, intelResult, tlsCertificatePem);
await checkGpu(attestation, nonce);
await showSigstoreProvenance(attestation);These verifiers work with NEAR AI Cloud Gateway attestation endpoints:
GET /v1/attestation/report- TEE attestation; useinclude_tls_fingerprint=truefor domain verifier (signing_addressoptional)GET /v1/signature/{chat_id}- Get response signature
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Clone from the correct URL:
https://github.com/nearai/nearai-cloud-verifier.git - Test with both Python and TypeScript verifiers:
# Test Python verifiers
python3 py/model_verifier.py --model deepseek-ai/DeepSeek-V3.1
python3 py/chat_verifier.py --model deepseek-ai/DeepSeek-V3.1
python3 py/domain_verifier.py
# Test TypeScript verifiers
pnpm run model -- --model deepseek-ai/DeepSeek-V3.1
pnpm run chat -- --model deepseek-ai/DeepSeek-V3.1
pnpm run domain- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE for details.
Built with:
- NVIDIA NRAS - GPU TEE attestation service
- Intel TDX - CPU TEE technology
- Sigstore - Container supply chain verification
Powered by NEAR AI Cloud