npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mmn-client-js

v1.0.14

Published

A comprehensive TypeScript client for interacting with MMN blockchain via JSON-RPC

Downloads

761

Readme

mmn-client-js

A comprehensive TypeScript client for interacting with the MMN blockchain ecosystem. It provides complete functionality for blockchain transactions, account management, indexer queries, and ZK proof generation.

Features

  • 🔐 Transaction signing (Ed25519 with NaCl)
  • 📝 Complete transaction lifecycle (create, sign, submit)
  • 🚀 JSON-RPC client for MMN blockchain
  • 📊 Indexer client for transaction history and wallet details
  • ZK proof generation for privacy-preserving authentication
  • 💰 Wallet management with BIP39 mnemonic support
  • 🎯 User ID to address conversion with SHA256 hashing
  • �📦 Full TypeScript support with exported types
  • 🌐 Cross-platform (Browser & Node.js compatible)

Installation

npm install mmn-client-js

Or using yarn:

yarn add mmn-client-js

Quick Start

Basic MMN Client Usage

import { MmnClient, IndexerClient, ZkClient } from 'mmn-client-js';

// Create MMN client for blockchain operations
const mmnClient = new MmnClient({
  baseUrl: 'http://localhost:8080',
  timeout: 30000,
});

// Generate ephemeral key pair for ZK authentication
const keyPair = mmnClient.generateEphemeralKeyPair();
console.log('Public Key:', keyPair.publicKey);

// Convert user ID to blockchain address
const senderAddress = mmnClient.getAddressFromUserId('user123');
const recipientAddress = mmnClient.getAddressFromUserId('user456');

// Get current nonce for sender
const nonceResponse = await mmnClient.getCurrentNonce(senderAddress);
const currentNonce = nonceResponse.nonce;

// Get account information by user ID
const account = await mmnClient.getAccountByUserId('user123');
console.log('Balance:', account.balance);

// Send a transaction
const response = await mmnClient.sendTransaction({
  sender: 'user123',
  recipient: 'user456',
  amount: '1000000000000000000',
  nonce: currentNonce + 1,
  textData: 'Hello MMN!',
  publicKey: keyPair.publicKey,
  privateKey: keyPair.privateKey,
  zkProof: 'zk-proof-string',
  zkPub: 'zk-public-string',
});

if (response.ok) {
  console.log('Transaction Hash:', response.tx_hash);
} else {
  console.error('Transaction failed:', response.error);
}

Indexer Client Usage

// Create indexer client for transaction history
const indexerClient = new IndexerClient({
  endpoint: 'https://indexer.mmn.network',
  chainId: 'mmn-mainnet',
});

// Get transaction history for a wallet
const transactions = await indexerClient.getTransactionByWallet(
  'wallet-address',
  1, // page
  50, // limit
  0 // filter: 0=all, 1=received, 2=sent
);

// Get specific transaction details
const tx = await indexerClient.getTransactionByHash('tx-hash');

// Get wallet details
const walletInfo = await indexerClient.getWalletDetail('wallet-address');

ZK Proof Client Usage

// Create ZK client for proof generation
const zkClient = new ZkClient({
  endpoint: 'https://zk.mmn.network',
  timeout: 30000,
  // chainId is not required for ZK client
});

// Generate ZK proof for authentication
const zkProof = await zkClient.getZkProofs({
  userId: 'user123',
  ephemeralPublicKey: keyPair.publicKey,
  jwt: 'jwt-token',
  address: 'wallet-address',
});

API Reference

MMN Client Configuration

interface MmnClientConfig {
  baseUrl: string; // MMN JSON-RPC base URL
  timeout?: number; // Request timeout in ms (default: 30000)
  headers?: Record<string, string>; // Additional headers
  axiosConfig?: AxiosRequestConfig; // Optional axios overrides
}

Indexer Client Configuration

interface IndexerClientConfig {
  endpoint: string; // Indexer API endpoint
  chainId: string; // Blockchain chain ID
  timeout?: number; // Request timeout in ms (default: 30000)
  headers?: Record<string, string>; // Additional headers
}

Core Methods

MMN Client Methods

generateEphemeralKeyPair(): IEphemeralKeyPair Generate a new Ed25519 key pair using BIP39 mnemonic.

const keyPair = client.generateEphemeralKeyPair();
// Returns: { privateKey: string, publicKey: string }

getAddressFromUserId(userId: string): string Convert user ID to blockchain address using SHA256 + Base58.

const address = client.getAddressFromUserId('user123');

sendTransaction(params): Promise<AddTxResponse> Create, sign, and submit a transaction.

const response = await client.sendTransaction({
  sender: 'user123',
  recipient: 'user456',
  amount: '1000000000000000000',
  nonce: 1,
  textData: 'Optional message',
  extraInfo: { type: 'transfer_token', UserSenderId: 'user123', ... },
  publicKey: 'public-key-base58',
  privateKey: 'private-key-pkcs8-hex',
  zkProof: 'zk-proof-string',
  zkPub: 'zk-public-string'
});

sendTransactionByPrivateKey(params): Promise<AddTxResponse> Create, sign (using the provided private key) and submit a transaction without relying on a client-stored keypair.

const response = await client.sendTransactionByPrivateKey({
  sender: 'user123',
  recipient: 'user456',
  amount: '1000000000000000000',
  nonce: 1,
  textData: 'Optional message',
  extraInfo: { type: 'transfer_token', UserSenderId: 'user123', ... },
  privateKey: 'private-key-pkcs8-hex'
});

getCurrentNonce(address: string, tag?: 'latest' | 'pending'): Promise<GetCurrentNonceResponse> Get current nonce for an account.

getAccountByUserId(userId: string): Promise<GetAccountByAddressResponse> Get account details by user ID.

scaleAmountToDecimals(amount: string | number, decimals: number): string Scale amount to blockchain decimals.

Indexer Client Methods

getTransactionByHash(hash: string): Promise<Transaction> Get transaction details by hash.

getTransactionByWallet(wallet: string, page: number, limit: number, filter: number): Promise<ListTransactionResponse> Get transaction history for a wallet.

  • filter: 0=all, 1=received, 2=sent

getWalletDetail(wallet: string): Promise<WalletDetail> Get wallet balance and account information.

ZK Client Methods

getZkProofs(params): Promise<IZkProof> Generate ZK proof for authentication.

const zkProof = await zkClient.getZkProofs({
  userId: 'user123',
  ephemeralPublicKey: 'ephemeral-public-key',
  jwt: 'jwt-token',
  address: 'wallet-address',
});

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For support, please open an issue on the GitHub repository.