Skip to content

sagungargs15/openautopay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

OpenAutoPay

OpenAutoPay: Mesh of L402, MCP, and Nostr will revolutionize Agentic AI payments. It will empower developers to build autonomous, AI-driven payment systems that are secure, scalable, and interoperable across decentralized networks

OpenAutoPay SDK

A Python SDK for implementing the Decentralised Agentic Mesh Payments Protocol (DAMPP), integrating L402 (Lightning Network), MCP (Model Context Protocol), and Nostr.

Directory Structure

openautopay/
├── autopay-sdk/
│   ├── __init__.py
│   ├── payments.py    # L402 payment handling
│   ├── context.py     # MCP context fetching
│   ├── comms.py       # Nostr communication
│   └── sdk.py         # Main SDK class
├── examples/
│   └── marketplace.py # Example usage
└── README.md

Installation

pip install requests pynostr lnurl cryptography

Usage

See examples/marketplace.py for a sample implementation.

from autopay.sdk import OpenAutoPaySDK

# Mock keys and URLs
WALLET_KEY = "mock_lightning_wallet_key"
NOSTR_KEY = "your_nostr_private_key_hex"  # 64-char hex string
SERVICE_URL = "http://marketplace.example.com/api/data"
MCP_SERVER = "http://mcp.example.com"

# Initialize SDK
sdk = OpenAutoPaySDK(WALLET_KEY, NOSTR_KEY, MCP_SERVER)

# Process a transaction
result = sdk.process_transaction(SERVICE_URL, "Get marketplace pricing")
print(f"Transaction completed: {result}")

Features

  1. L402-based payments via Lightning Network
  2. MCP context fetching for AI-driven decisions
  3. Nostr communication for decentralized messaging

More Details

OpenAutoPay is a groundbreaking open-source Free and Open Source Software (FOSS) code repository designed to redefine Agentic AI payments. By integrating the Lightning Network’s L402 protocol, the Model Context Protocol (MCP), and the Nostr protocol, OpenAutoPay empowers developers to create autonomous, AI-driven payment systems that are secure, scalable, and interoperable across decentralized networks. This repository provides a robust framework for AI agents to handle microtransactions, access external data and tools, and communicate in a decentralized ecosystem—all while leveraging the speed and efficiency of the Lightning Network.

Key Features of OpenAutoPay

L402 Integration: L402, a Lightning Network-native payment protocol, enables pay-per-use API access and microtransactions with minimal fees. OpenAutoPay uses L402 to allow AI agents to autonomously pay for services, data, or computational resources in real-time, fostering a machine-payable economy where agents operate independently.

MCP (Model Context Protocol): MCP is an open standard for connecting Large Language Models (LLMs) to external data sources and tools. In OpenAutoPay, MCP equips AI agents with a standardized interface to dynamically fetch relevant data—such as pricing, user preferences, or transaction history—ensuring payments are intelligent and contextually appropriate.

Nostr Protocol: Nostr, a decentralized communication protocol, offers secure, censorship-resistant messaging and identity management. OpenAutoPay leverages Nostr for peer-to-peer communication between AI agents, users, and service providers, ensuring reliable exchange of payment requests, confirmations, and transaction metadata in a trustless environment.

Designed with modularity and extensibility, OpenAutoPay provides developers with tools, libraries, and documentation to craft custom Agentic AI payment solutions. From automating subscription payments to enabling AI-driven marketplace transactions or powering decentralized service ecosystems, OpenAutoPay lays the groundwork for a new era of autonomous financial interactions. Licensed under a permissive FOSS license (e.g., MIT or Apache 2.0), the project invites community contributions to evolve its capabilities and adapt to emerging use cases in the AI and blockchain space, with the Decentralised Agentic Mesh Payments Protocol (DAMPP) as its flagship protocol.

New Standard:Decentralised Agentic Mesh Payments Protocol (DAMPP)

The Decentralised Agentic Mesh Payments Protocol (DAMPP) is a novel protocol that unifies the strengths of L402, MCP, and Nostr into a cohesive standard for Agentic AI payments and interactions in a decentralized environment. Below is a detailed specification of DAMPP.

Purpose

DAMPP enables autonomous AI agents to perform secure, context-aware payments and communications in a decentralized network by meshing L402’s payment capabilities, MCP’s context integration, and Nostr’s decentralized messaging.

1. Payment Layer (L402-Based)

Mechanism: Utilizes L402’s HTTP-based payment flow, where AI agents present a Lightning Network payment preimage and macaroon to access services or data. Enhancement: Extends L402 with dynamic pricing metadata, allowing agents to negotiate payment terms based on context (e.g., resource demand or service priority). Workflow: 1. Agent requests a service via a DAMPP endpoint. 2. Service provider responds with an L402 challenge (payment hash + macaroon). 3. Agent completes the payment over Lightning Network and gains access.

2. Context Layer (MCP-Based)

Mechanism: Adopts MCP’s client-server model to connect AI agents to external data sources (e.g., APIs, databases, or file systems) and tools. Enhancement: Introduces a “Context Request Payload” (CRP) that encapsulates payment-related data (e.g., transaction purpose, budget constraints) alongside traditional MCP context queries. Workflow: 1. Agent sends a CRP to a DAMPP server specifying the data/tools needed. 2. Server authenticates the request (via L402) and returns structured context data. 3. Agent processes the data to inform payment decisions or actions.

3. Communication Layer (Nostr-Based)

Mechanism: Leverages Nostr’s public-key-based messaging for secure, decentralized communication between agents, users, and services. Enhancement: Adds a “Payment Event Type” to Nostr’s event structure, enabling agents to broadcast payment intents, confirmations, or disputes to the network. Workflow: 1. Agent generates a signed Nostr event (e.g., "Payment Intent: 500 sats for API access"). 2. Event is relayed across Nostr nodes to the service provider. 3. Provider responds with a confirmation event after payment is verified via L402.

Protocol Flow

  1. Initialization: An AI agent identifies a task requiring payment, data, and communication (e.g., purchasing API access to fetch market data).
  2. Context Fetch: The agent sends a CRP to a DAMPP server via MCP, authenticated by an L402 macaroon, to retrieve necessary context (e.g., API pricing).
  3. Payment Execution: Using L402, the agent completes a Lightning Network payment based on the retrieved context.
  4. Communication: The agent broadcasts a Nostr Payment Event to confirm the transaction, logged by the network for transparency.
  5. Action: The agent accesses the service/data and completes its task, with all interactions standardized under DAMPP.

Key Features

  1. Interoperability: Seamlessly integrates L402, MCP, and Nostr, allowing existing implementations to adopt DAMPP incrementally.
  2. Security: Combines L402’s macaroon-based authentication, MCP’s OAuth 2.1 subset, and Nostr’s cryptographic signatures for end-to-end trust.
  3. Scalability: Leverages Lightning Network for high-volume microtransactions and Nostr’s relay system for distributed communication.
  4. Agent Autonomy: Enables AI agents to negotiate, pay, and communicate without human oversight, using context-aware decision-making.

Example Use Case

An AI agent managing a decentralized marketplace uses DAMPP to:

  1. Query product pricing via MCP.
  2. Pay for the listing fee via L402 over Lightning Network.
  3. Notify the seller and buyer via Nostr events, all in a single, standardized flow.

Implementation Notes

DAMPP servers can be built as extensions to existing MCP servers, with added L402 payment gateways and Nostr relay compatibility. OpenAutoPay could serve as the reference implementation, providing sample code and libraries in Python, Rust, or JavaScript.

plaintext

# Example Nostr Payment Event
{
  "kind": 7000,  // Custom Payment Event Type
  "content": "Payment Intent: 500 sats for API access",
  "pubkey": "<agent-public-key>",
  "signature": "<cryptographic-signature>"
}

Next Steps

  1. Test: Add unit tests with mocked servers for L402, MCP, and Nostr.
  2. Expand: Implement error handling, retries, and logging.
  3. Deploy: Package as a PyPI module, npm package, or Rust crate.

About

OpenAutoPay: Mesh of L402, MCP, and Nostr will revolutionize Agentic AI payments. It will empower developers to build autonomous, AI-driven payment systems that are secure, scalable, and interoperable across decentralized networks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages