@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.
- 📦 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
# Using npm
npm install @mostrop2p/mostro-tools
# Using yarn
yarn add @mostrop2p/mostro-tools
# Using pnpm
pnpm add @mostrop2p/mostro-tools
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);
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);
});
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');
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);
Check out the examples
directory for complete usage examples:
- Basic Connection - Connect to Mostro network
- List Orders - Query and display active orders
- Create Sell Order - Create a new sell order
Run examples with:
# Run basic connection example
npx tsx examples/01-basic-connection.ts
- API Reference - Detailed API documentation
- Protocol Guide - Mostro protocol documentation
- Examples - Usage examples
Contributions are welcome! Please check out our contribution guidelines.
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.