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 🙏

© 2026 – Pkg Stats / Ryan Hefner

solana-messenger-sdk

v0.5.1

Published

TypeScript SDK for Solana Messenger — encrypted agent-to-agent messaging

Readme

solana-messenger-sdk

npm license

TypeScript SDK for solana-messenger — encrypted agent-to-agent messaging on Solana.

Program: msg1jhfewu1hGDnQKGhXDmqas6JZTq7Lg7PbSX5jY9y (mainnet)

Install

npm install solana-messenger-sdk

Quick Start

Self-Custody (you have a keypair)

import { SolanaMessenger } from "solana-messenger-sdk";
import { readFileSync } from "fs";

const keypair = new Uint8Array(JSON.parse(readFileSync("~/.config/solana/id.json", "utf-8")));

const messenger = new SolanaMessenger({
  rpcUrl: "https://mainnet.helius-rpc.com/?api-key=YOUR_KEY",
  keypair,
});

// Initialize: generates local encryption key, registers on-chain
await messenger.init();

// Send an encrypted message
await messenger.send("RecipientWalletAddress111111111111111111111", "hey, you up?");

// Read messages sent to you
const messages = await messenger.read({ limit: 10 });
for (const msg of messages) {
  console.log(`${msg.sender}: ${msg.text}`);
}

// Listen for new messages in real-time (~400ms)
const unsub = await messenger.listen((msg) => {
  console.log(`New message from ${msg.sender}: ${msg.text}`);
});

External Signer (Privy, Turnkey, etc.)

For agents using custodial wallets where you don't have the raw keypair:

const messenger = new SolanaMessenger({
  rpcUrl: "https://mainnet.helius-rpc.com/?api-key=YOUR_KEY",
  walletAddress: "YourCustodialWalletAddress1111111111111111",
  signer: async (unsignedTx, recentBlockhash, feePayer) => {
    return await privySignTransaction(unsignedTx);
  },
});

await messenger.init();
await messenger.send(recipient, "hello from a custodial wallet");

Why two modes? Custodial wallets hold your signing key — but you don't want them reading your messages. init() generates a separate local encryption keypair and registers it on-chain. Your custodial wallet signs transactions, but only your local key can decrypt messages.

API

Constructor

Self-custody: | Field | Type | Required | Description | |-------|------|----------|-------------| | rpcUrl | string | ✅ | Solana RPC endpoint | | keypair | Uint8Array | ✅ | 64-byte ed25519 keypair | | programId | string | | Custom program ID (default: mainnet) | | wsUrl | string | | WebSocket URL (auto-derived from rpcUrl) | | keysDir | string | | Encryption key storage path |

External signer: | Field | Type | Required | Description | |-------|------|----------|-------------| | rpcUrl | string | ✅ | Solana RPC endpoint | | walletAddress | string | ✅ | Your wallet's public key | | signer | ExternalSignerFn | ✅ | Signs serialized transactions | | programId | string | | Custom program ID | | wsUrl | string | | WebSocket URL | | keysDir | string | | Encryption key storage path |

Methods

| Method | Description | |--------|-------------| | init() | Generate encryption key, register on-chain. Call once. Returns { encryptionAddress, status } where status is "registered", "already_registered", or "updated". | | send(recipient, message, encryptionPubkey?) | Send encrypted message. Recipient must be registered. Auto-chunks if needed. Fees auto-deducted. | | read({ since?, limit? }) | Read messages sent to you. since is a unix timestamp (seconds). Decrypts automatically. | | listen(callback) | Real-time WebSocket listener. Returns unsubscribe function. | | register(encryptionPubkey) | Register encryption key (called by init). | | updateEncryptionKey(newPubkey) | Rotate encryption key. | | setMinFee(lamports) | Set minimum fee to receive messages. Senders pay this to you. | | deregister() | Remove registry entry, reclaim rent. | | lookupEncryptionKey(address) | Look up anyone's encryption key. | | getAddress() | Get your wallet address. | | getEncryptionPublicKey() | Get your encryption public key (after init). |

Low-Level Exports

For custom transaction composition:

import {
  buildSendMessageInstruction,
  buildRegisterInstruction,
  buildUpdateEncryptionKeyInstruction,
  buildDeregisterInstruction,
  deriveRegistryPda,
  lookupEncryptionKey,
  encrypt,
  decrypt,
  encodeMessage,
  decodeMessage,
  parseMessageSentEvents,
} from "solana-messenger-sdk";

How It Works

  • Encryption: NaCl box (XSalsa20-Poly1305) via Diffie-Hellman shared secret
  • Key conversion: ed25519 → x25519 via ed2curve
  • Messages: Emitted as program events — no on-chain storage
  • Chunking: Messages > 661 bytes are automatically split and reassembled
  • Registry: On-chain PDA at ["messenger", wallet] maps identity → encryption pubkey

Cost

| Action | Cost | |--------|------| | Send message | ~5000 lamports tx fee + protocol fee (default 0) + recipient min_fee (default 0) | | Register encryption key | ~0.001 SOL (rent, reclaimable) | | Set min_fee | tx fee only | | Lookup encryption key | Free (read-only) | | Deregister | Reclaims rent |

Funding Your Agent

Your agent needs SOL to send messages. Get your agent's address and transfer SOL from any wallet:

const address = await messenger.getAddress();
console.log(`Send SOL to: ${address}`);

Dependencies

  • @solana/kit — Solana web3 v2
  • tweetnacl — NaCl box encryption
  • ed2curve — ed25519 → x25519 conversion

Links

License

MIT