10000 GitHub - MostroP2P/mostro-tools: Typescript Mostro library
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MostroP2P/mostro-tools

Repository files navigation

@mostrop2p/mostro-tools

Tools for building Mostro Clients

@mostrop2p/mostro-tools is a modern TypeScript library that simplifies building applications on the Mostro P2P protocol. It provides developers with a complete toolkit for creating decentralized, non-custodial Bitcoin trading platforms with Lightning Network support.

npm version License: MIT test coverage


Features

  • πŸ“¦ Complete Protocol Implementation: Full support for the Mostro protocol including orders, messaging, and disputes
  • ⚑ Lightning Network Integration: Built-in utilities for invoice generation and payment handling
  • πŸ”’ Advanced Key Management: Secure, deterministic key derivation (BIP-39/BIP-32) and rotation
  • πŸ” Encrypted Communications: NIP-44 and NIP-59 support for private messaging
  • πŸ“Š Order Management: Comprehensive tools for creating, listing and executing trades
  • πŸ›‘οΈ Dispute Resolution: Built-in support for handling trade disputes
  • ⭐ Reputation System: Tools for implementing user ratings and reputation tracking
  • 🧩 Modular Architecture: Extensible design allowing custom implementations and plugins

Installation

# Using npm
npm install @mostrop2p/mostro-tools

# Using yarn
yarn add @mostrop2p/mostro-tools

# Using pnpm
pnpm add @mostrop2p/mostro-tools

Quick Start

import { Mostro, KeyManager } from '@mostrop2p/mostro-tools';
import { generateMnemonic } from 'bip39';

async function main() {
  // Initialize key manager with a mnemonic phrase
  const mnemonic = generateMnemonic();
  const keyManager = new KeyManager();
  await keyManager.initialize(mnemonic);

  // Create and configure Mostro client
  const mostro = new Mostro({
    mostroPubKey: 'npub1...', // Mostro instance pubkey
    relays: ['wss://relay.damus.io', 'wss://relay.nostr.info'],
    privateKey: keyManager.getIdentityKey()!,
    debug: true,
  });

  // Connect to Mostro network
  await mostro.connect();
  console.log('Connected to Mostro network');

  // Get active orders
  const orders = await mostro.getActiveOrders();
  console.log(`Found ${orders.length} active orders`);

  // Create a new sell order
  const sellOrder = await mostro.submitOrder({
    kind: 'sell',
    status: 'pending',
    amount: 50000, // 50,000 sats
    fiat_code: 'USD',
    fiat_amount: 25, // $25 USD
    payment_method: 'BANK',
    premium: 2, // 2% premium
  });

  console.log(`Order created with ID: ${sellOrder.order?.id}`);
}

main().catch(console.error);

Core Components

Mostro Client

The main interface for interacting with the Mostro network:

// Initialize client
const mostro = new Mostro({
  mostroPubKey: 'npub1...', // Mostro instance pubkey
  relays: ['wss://relay.damus.io'],
  privateKey: keyManager.getIdentityKey()!,
});

// Connect to network
await mostro.connect();

// Listen for order updates
mostro.on('order-update', (order, event) => {
  console.log('Order updated:', order);
});

Key Management

Secure key derivation and management:

// Initialize with mnemonic
const keyManager = new KeyManager();
await keyManager.initialize('your mnemonic phrase here');

// Get identity key
const identityKey = keyManager.getIdentityKey();

// Generate trade key for a specific order
const tradeKey = await keyManager.generateTradeKey('order-id');

Order Operations

Complete order lifecycle management:

// List active orders
const orders = await mostro.getActiveOrders();

// Take a sell order
await mostro.takeSell(order);

// Add invoice for payment
await mostro.addInvoice(order, 'lnbc500...');

// Confirm fiat payment sent
await mostro.fiatSent(order);

// Release funds (for seller)
await mostro.release(order);

Examples

Check out the examples directory for complete usage examples:

Run examples with:

# Run basic connection example
npx tsx examples/01-basic-connection.ts

Documentation


Contributing

Contributions are welcome! Please check out our contribution guidelines.

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

License

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


Resources

About

Typescript Mostro library

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  
0