Skip to content

JayWebtech/pagra-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Pagra AI - Starknet Wallet API

A comprehensive Node.js API for Starknet wallet management with Telegram bot integration and MCP (Model Context Protocol) chat functionality.

πŸš€ Quick Start

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • Supabase account and project
  • Starknet RPC endpoint access

Installation

  1. Clone and install dependencies:

    npm install
  2. Environment Setup: Create a .env file in the root directory with the following variables:

    # Server Configuration
    PORT=3000
    NODE_ENV=development
    
    # Supabase Configuration
    SUPABASE_URL=your_supabase_project_url
    SUPABASE_ANON_KEY=your_supabase_anon_key
    SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
    
    # Starknet Configuration
    STARKNET_RPC_URL=your_starknet_rpc_url
    STARKNET_NETWORK=sepolia
    
    # Telegram Bot (Optional)
    TELEGRAM_BOT_TOKEN=your_telegram_bot_token
    
    # MCP Configuration
    ANTHROPIC_API_KEY=your_anthropic_api_key
    
    # Security
    JWT_SECRET=your_jwt_secret_here
    ENCRYPTION_KEY=your_32_byte_encryption_key
  3. Database Setup:

    • Run the database migration scripts from the migrations/ folder
    • See migrations/README.md for detailed instructions

Running the Application

Development mode (with auto-reload):

npm run dev

Production mode:

npm start

The server will start on http://localhost:3000

πŸ“ Project Structure

pagra-ai/
β”œβ”€β”€ src/                     # Source code
β”‚   β”œβ”€β”€ config/              # Configuration files
β”‚   β”œβ”€β”€ helpers/             # Helper functions and utilities
β”‚   β”œβ”€β”€ services/            # Service layer (Telegram, etc.)
β”‚   └── server.js            # Main server file
β”œβ”€β”€ tests/                   # Test files and utilities
β”‚   β”œβ”€β”€ mocks/               # Mock files for testing
β”‚   β”œβ”€β”€ *.test.js            # Jest test files
β”‚   β”œβ”€β”€ test-*.js            # Manual test scripts
β”‚   └── README.md            # Testing documentation
β”œβ”€β”€ migrations/              # Database migration scripts
β”‚   β”œβ”€β”€ *.sql                # SQL migration files
β”‚   └── README.md            # Migration documentation
β”œβ”€β”€ docs/                    # Documentation
β”‚   β”œβ”€β”€ telegram-setup.md    # Telegram bot setup guide
β”‚   β”œβ”€β”€ mcp-chat-example.md  # MCP chat examples
β”‚   β”œβ”€β”€ TEST_SCENARIOS.md    # Testing scenarios
β”‚   └── README.md            # Documentation index
β”œβ”€β”€ .env                     # Environment variables (create this)
β”œβ”€β”€ package.json
└── README.md                # This file

πŸ”— API Endpoints

Core Wallet Operations

  • POST /api/start - Create new wallet account
  • POST /api/deploy_account - Deploy wallet to Starknet
  • POST /api/get_wallet_address - Get wallet address
  • POST /api/get_balance - Check wallet balance
  • POST /api/transfer - Transfer funds
  • POST /api/get_transactions - Get transaction history

Chat & AI Integration

  • POST /api/chat - Process chat messages with MCP
  • POST /api/chat/clear - Clear conversation history
  • GET /api/chat/history/:phone_number - Get chat history

Telegram Integration

  • POST /api/telegram/webhook - Telegram webhook endpoint
  • POST /api/telegram/set-webhook - Set webhook URL

System

  • GET /health - Health check endpoint
  • GET /api-docs - Swagger API documentation

πŸ› οΈ Available Scripts

  • npm run dev - Start development server with nodemon
  • npm start - Start production server
  • npm test - Run Jest tests
  • npm run test:watch - Run tests in watch mode
  • npm run test:coverage - Generate test coverage report

πŸ§ͺ Testing

The project includes comprehensive testing:

  • Automated Tests: Jest-based unit and integration tests
  • Manual Tests: Interactive testing scripts
  • Telegram Tests: Bot integration testing
  • MCP Tests: Chat functionality testing

See tests/README.md for detailed testing instructions.

πŸ—„οΈ Database

The project uses Supabase PostgreSQL with:

  • Users table: Wallet and user information
  • Transactions table: Transfer history and status
  • Row Level Security: Secure data access
  • Helper functions: Database utilities

See migrations/README.md for database setup instructions.

πŸ€– Features

Wallet Management

  • βœ… Create Starknet wallets
  • βœ… Deploy accounts to network
  • βœ… Transfer funds between wallets
  • βœ… Check balances and transaction history
  • βœ… Secure private key encryption

Telegram Bot

  • βœ… Interactive wallet operations via Telegram
  • βœ… Polling mode for development
  • βœ… Webhook mode for production
  • βœ… Natural language commands

AI Chat Integration

  • βœ… MCP (Model Context Protocol) support
  • βœ… Context-aware conversations
  • βœ… Tool integration for wallet operations
  • βœ… Conversation history management

Security

  • βœ… PIN-based authentication
  • βœ… Private key encryption
  • βœ… Rate limiting
  • βœ… Input validation
  • βœ… Row Level Security (RLS)

πŸ”§ Dependencies

Core

  • Express - Web framework
  • Supabase - Database and backend services
  • Starknet.js - Starknet blockchain integration

Security & Middleware

  • CORS - Cross-origin resource sharing
  • Helmet - Security middleware
  • Morgan - HTTP request logger
  • express-rate-limit - Rate limiting

Integrations

  • node-telegram-bot-api - Telegram bot integration
  • @anthropic-ai/sdk - Claude AI integration
  • swagger-ui-express - API documentation

Development

  • Nodemon - Development auto-reload
  • Jest - Testing framework
  • Dotenv - Environment variable management

πŸ“š Documentation

Comprehensive documentation is available in the docs/ folder:

  • Telegram Setup: Complete bot integration guide
  • MCP Chat Examples: AI chat functionality examples
  • Test Scenarios: Testing strategies and procedures

🚨 Important Security Notes

  1. Never commit .env files to version control
  2. Use strong encryption keys (32 bytes minimum)
  3. Enable RLS policies in Supabase
  4. Validate all user inputs before processing
  5. Use HTTPS in production environments
  6. Regularly rotate API keys and secrets

πŸ†˜ Troubleshooting

Common Issues

  • Supabase connection: Check environment variables and project status
  • Starknet RPC errors: Verify RPC URL and network configuration
  • Telegram bot issues: Ensure bot token is valid and webhook is set
  • Database permissions: Run migrations/fix-permissions.sql

Getting Help

  1. Check the relevant documentation in docs/
  2. Review test files in tests/ for examples
  3. Verify environment configuration
  4. Check server logs for detailed error messages

πŸ”„ Development Workflow

  1. Setup: Follow installation instructions
  2. Database: Run migrations from migrations/
  3. Testing: Use test scripts in tests/
  4. Documentation: Update relevant docs when adding features
  5. Deployment: Use production environment variables

πŸ“ˆ Next Steps

  1. Set up your Supabase database using migration scripts
  2. Configure Telegram bot (optional) using docs/telegram-setup.md
  3. Test API endpoints using provided test scripts
  4. Implement additional features as needed
  5. Deploy to production environment

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors