Skip to content

near-examples/nearai-cloud-verification-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NEAR AI Cloud Verification Example

License: MIT Node.js NEAR AI Docs

πŸš€ Learn how to build secure, verifiable AI applications using NEAR AI Confidential Cloud

This repository demonstrates how to interact with NEAR AI's Cloud platform, verify attestations, and ensure your AI workloads run in secure, trusted execution environments (TEEs).

🌟 What You'll Learn

  • πŸ”’ Attestation Verification: Get and verify model attestations from NEAR AI Cloud
  • πŸ›‘οΈ Hardware Security: Validate NVIDIA GPU attestations for secure execution
  • πŸ” Cryptographic Verification: Verify signatures and hash integrity
  • ⚑ End-to-End Workflow: Complete pipeline from request to verified response

πŸ“‹ Prerequisites

  • Node.js 18+ and npm/pnpm
  • NEAR AI Cloud API Key (Get yours here)
  • Basic understanding of:
    • Trusted Execution Environments (TEEs)
    • Cryptographic signatures
    • Hash functions

πŸš€ Quick Start

1. Clone and Install

git clone https://github.com/near-examples/nearai-cloud-verification-example.git
cd nearai-cloud-verification-example
pnpm install  # or npm install

2. Configure Environment

Create a .env file with your NEAR AI Cloud API key: (Get yours at https://cloud.near.ai)

# .env
NEARAI_CLOUD_API_KEY=your_api_key_here

3. Run the Demo

pnpm start  # or npm start

🎯 What the Demo Does

The main demo (app.js) walks through a complete confidential AI workflow:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸš€ NEAR AI Cloud Verification Demo                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  1) Get Attestation Report                                  β”‚
β”‚     β”œβ”€ Fetch model attestation from NEAR AI Cloud           β”‚
β”‚     └─ Extract TEE signing address                          β”‚
β”‚                                                             β”‚
β”‚  2) Verify with NVIDIA                                      β”‚
β”‚     β”œβ”€ Send attestation to NVIDIA service                   β”‚
β”‚     └─ Validate hardware security claims                    β”‚
β”‚                                                             β”‚
β”‚  3) Send & Verify Chat Message                              β”‚
β”‚     β”œβ”€ Send message to NEAR AI TEE model                    β”‚
β”‚     β”œβ”€ Get result w/ cryptographic signature                β”‚
β”‚     β”œβ”€ Verify request/response hashes                       β”‚
β”‚     └─ Validate TEE signature                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ—οΈ Project Structure

nearai-confidential-cloud-examples/
β”œβ”€β”€ app.js                          # 🎯 Main demo application
β”œβ”€β”€ utils/                          # πŸ› οΈ Utility modules
β”‚   β”œβ”€β”€ api.js                      #    API interaction helpers
β”‚   β”œβ”€β”€ model-attestation.js        #    Attestation processing
β”‚   β”œβ”€β”€ send-and-verify-chat.js     #    Chat workflow
β”‚   └── verification-helpers.js     #    Crypto verification
β”œβ”€β”€ package.json                    # πŸ“¦ Dependencies
└── .env                            # πŸ” API key configuration

πŸ”§ Core Components

🌐 API Integration (utils/api.js)

import { getModelAttestation, getChatMessageSignature } from './utils/api.js';

// Get attestation for a model
const attestation = await getModelAttestation('gpt-oss-120b');

// Get signature for a chat completion
const signature = await getChatMessageSignature(chatId, modelId);

πŸ›‘οΈ Attestation Verification (utils/model-attestation.js)

import { decodeNvidiaAttestation } from './utils/model-attestation.js';

// Process NVIDIA attestation response
const nvidiaResult = decodeNvidiaAttestation(gpuVerification);

πŸ” Cryptographic Verification (utils/verification-helpers.js)

import { verifySignature, compareHashes, sha256sum } from './utils/verification-helpers.js';

// Verify cryptographic signature
const signatureResult = await verifySignature(message, signature, expectedAddress);

// Compare hash values
const hashResult = compareHashes(signatureText, requestHash, responseHash);

// Generate SHA-256 hash
const hash = sha256sum(data);

βš™οΈ Configuration

Environment Variables

Variable Description Required
NEARAI_CLOUD_API_KEY Your NEAR AI Cloud API key βœ… Yes

Model Configuration

Edit app.js to test different models:

// Available models at: https://docs.near.ai/cloud/models/
const MODEL_NAME = "deepseek-ai/DeepSeek-V3.1";    // DeepSeek Model
const MODEL_NAME = "zai-org/GLM-4.6";              // GLM 4.6 Model

πŸ”’ Security Guarantees

When you see βœ… for all checks, you have cryptographic proof that:

  • πŸ—οΈ Trusted Hardware: The AI model runs in a verified TEE
  • πŸ” Data Integrity: Request and response haven't been tampered with
  • ✍️ Authenticity: Response was signed by the verified TEE
  • πŸ›‘οΈ End-to-End Security: Complete chain of trust established

🚨 Troubleshooting

Common Issues

❌ API Key Not Found

Error: 401 Unauthorized
πŸ’‘ Tip: Make sure your NEARAI_CLOUD_API_KEY is set in the .env file

❌ Model Not Available

Error: 404 Not Found
πŸ’‘ Tip: The model name might have a typo or might not be available

❌ Network Issues

Error: fetch failed
πŸ’‘ Tip: Check your internet connection and API endpoints

πŸ”— API Endpoints

The demo interacts with these NEAR AI Cloud endpoints:

  • Attestation: https://cloud-api.near.ai/v1/attestation/report
  • Chat Completions: https://cloud-api.near.ai/v1/chat/completions
  • Signatures: https://cloud-api.near.ai/v1/signature/{chatId}

And external verification:

  • NVIDIA Attestation: https://nras.attestation.nvidia.com/v3/attest/gpu

πŸ“š Learn More

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

NEAR AI Cloud Verification Example

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published