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

@herald-protocol/sdk

v1.1.0

Published

TypeScript SDK for the Herald Privacy Registry Anchor program

Downloads

76

Readme

@herald-protocol/sdk

The official TypeScript SDK for the Herald Privacy Registry Solana program.

Herald is an on-chain registry for privacy-preserving email delivery, allowing users to register encrypted emails and manage notification preferences without revealing their plaintext address on-chain.

Installation

npm install @herald-protocol/sdk
# or
yarn add @herald-protocol/sdk
# or
pnpm add @herald-protocol/sdk

SDK Architecture

The SDK is organized into three primary clients tailored for different consumers:

  1. UserClient: Used by frontend applications (React, Next.js, Vue) to let end-users register their identities, update notification preferences, or delete their accounts using their own wallet signature.
  2. ReadClient: A signing-free client useful for quickly checking if wallets are registered, or validating if a protocol is eligible to send messages. Safe for both browsers and node backends.
  3. AuthorityClient: Specialized client used EXCLUSIVELY by the Herald Node Backend. Requires the global HERALD_AUTHORITY signature to manage protocol lifecycle and append encrypted receipts.
  4. Billing Module: A dedicated suite of clients (BillingReadClient, HelioClient, PaymentClient) located under @herald-protocol/sdk/billing to manage protocol subscription tiers, check quotas, and execute on-chain usage payments.

Configuration

All clients inherit from a shared BaseClient configuration:

import { UserClient, ReadClient, AuthorityClient } from '@herald-protocol/sdk';
import { BillingReadClient } from '@herald-protocol/sdk/billing';

const config = {
  rpcUrl: 'https://api.mainnet-beta.solana.com',
  cluster: 'mainnet-beta', // 'mainnet-beta' | 'devnet' | 'localnet'
  commitment: 'confirmed', 
};

const userClient = new UserClient(config);
const readClient = new ReadClient(config);
const billingClient = new BillingReadClient(config);

Code Examples

We recommend reviewing the standalone executable examples in the examples/ directory for full, runnable code:


Usage Guide

1. Registering a User (Frontend Wallet)

To register an identity, you must provide the user's plaintext email and their Solana Wallet. The SDK handles all necessary encryption (NaCl) and PDA derivation out of the box.

IMPORTANT: Emails are never stored in plaintext on chain. They are converted into a SHA-256 hash (for deduplication) and an encrypted payload.

import { Keypair, Transaction, sendAndConfirmTransaction } from '@solana/web3.js';
import { UserClient, encryptEmail, hashEmail } from '@herald-protocol/sdk';

async function registerUser(userWallet: Keypair, rawEmail: string) {
  // 1. Prepare secure data
  const emailHash = await hashEmail(rawEmail);
  const { encryptedEmail, nonce } = encryptEmail(rawEmail, userWallet.publicKey);

  // 2. Build the Instruction
  const ix = await userClient.registerIdentity({
    owner: userWallet.publicKey,
    encryptedEmail,
    emailHash,
    nonce,
    optIns: {
      optInAll: true,
      optInDefi: false,
      optInGovernance: false,
      optInMarketing: false,
    },
    digestMode: false,
  });

  // 3. Dispatch the Transaction
  const tx = new Transaction().add(ix);
  const signature = await sendAndConfirmTransaction(
    userClient.connection,
    tx,
    [userWallet] // User wallet signature required!
  );

  console.log('Identity registered at tx:', signature);
}

2. Updating User Preferences

Users can modify their settings to turn marketing emails off, or switch to daily digests. The updateIdentity instruction requires ONLY the fields that are changing.

// Turn off Marketing
const ix = await userClient.updateIdentity({
  owner: userWallet.publicKey,
  optIns: {
    optInMarketing: false
  }
});

3. Fetching Accounts (Read-only)

The ReadClient allows you to fetch fully deserialized accounts quickly. Use this when you do not need to alter state.

async function checkStatus(userPubkey: PublicKey) {
  // Fetch full account details
  const account = await readClient.fetchIdentityAccount(userPubkey);
  
  if (account) {
    console.log('Registered since:', account.registeredAt);
    console.log('Subscribed to all:', account.optInAll);
  } else {
    // Fast boolean check if you don't need the object data
    const isRegistered = await readClient.isRegistered(userPubkey);
    console.log('Is registered?', isRegistered);
  }
}

4. Billing & Subscriptions (Protocol Admin)

Protocols must maintain an active subscription to send notifications. The billing module provides methods to check quotas, calculate upgrade costs, and perform on-chain payments in USDC.

import { Keypair } from '@solana/web3.js';
import { PaymentClient, BillingReadClient } from '@herald-protocol/sdk/billing';

const billingRead = new BillingReadClient(config);
const paymentClient = new PaymentClient(config);

async function manageSubscription(protocolWallet: Keypair) {
  // Check remaining messaging quota
  const status = await billingRead.getSubscriptionStatus(protocolWallet.publicKey);
  console.log(`Sends remaining: ${status?.sendsRemaining}`);

  // Calculate cost for 12 months on the Growth Tier
  const cost = await paymentClient.calculateCost(protocolWallet.publicKey, 12, 'USDC');
  console.log(`Total cost: $${cost.total} USDC (Discount: ${cost.discountApplied})`);

  // Build and execute the payment transaction
  const txSignature = await paymentClient.paySubscription(
    protocolWallet.publicKey, 
    12, 
    'USDC',
    protocolWallet // Signer
  );
  console.log('Subscription fully renewed:', txSignature);
}

5. Listening for Events dynamically

The SDK can bind to the Anchor program instance to stream real-time events, such as when a user is registered or when a delivery occurs.

import { HeraldEventListener } from '@herald-protocol/sdk';

const listener = new HeraldEventListener(readClient.program);

// Hook into specific events
listener.on('NotificationDelivered', (event) => {
  console.log(`Notification sent in category ${event.category}`);
});

// Start listening WebSocket streams
listener.start();

// Cleanup when component unmounts
await listener.stop();

Architecture & Contributions

Please see CONTRIBUTING.md for details on:

  • Internal SDK architecture
  • Local Development Setup
  • Adding bindings for new Rust Program Instructions

License

MIT