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

africa-payments-utils

v1.0.1

Published

Free, tested utilities for African payment integrations: Kenyan phone number normalization and Paystack webhook signature verification.

Readme

africa-payments-utils

Free, tested utilities for African payment integrations — the two small pieces of logic that are easy to get subtly wrong and annoying to debug when they're wrong in production.

npm install africa-payments-utils

What's in here

normalizeKenyanPhone(phone: string): string

M-Pesa and most regional payment providers require phone numbers in strict +254XXXXXXXXX format. Users type 0712..., 712..., 254712..., or the full international format interchangeably, and a naive regex fails silently.

import { normalizeKenyanPhone } from 'africa-payments-utils';

normalizeKenyanPhone('0712345678');     // '+254712345678'
normalizeKenyanPhone('254712345678');   // '+254712345678'
normalizeKenyanPhone('+254712345678');  // '+254712345678'
normalizeKenyanPhone('712345678');      // '+254712345678'

verifyPaystackSignature(rawBody, signature, secretKey): boolean

Verifies a Paystack webhook actually came from Paystack, via HMAC-SHA512 over the raw request body. Skipping this means anyone who finds your webhook URL can POST a fake "payment succeeded" event.

import { verifyPaystackSignature } from 'africa-payments-utils';

// Express: capture the raw body BEFORE it's parsed — this is the part
// most guides skip, and the signature will never match without it.
app.use(express.json({
  verify: (req, res, buf) => { (req as any).rawBody = buf; }
}));

app.post('/webhooks/paystack', (req, res) => {
  const isValid = verifyPaystackSignature(
    (req as any).rawBody,
    req.headers['x-paystack-signature'] as string,
    process.env.PAYSTACK_SECRET_KEY!
  );
  if (!isValid) return res.status(401).send('Invalid signature');

  // ... handle the verified event
});

Why this exists as its own package

Both functions are extracted from a larger payment integration engine (handles M-Pesa STK Push, Paystack, Flutterwave, webhook reconciliation, and multi-tenant setups) that I sell separately. These two pieces are useful on their own regardless of what you're building, so they're free and MIT licensed rather than locked behind anything.

If you need the rest — STK Push initiation, dropped-transaction reconciliation, a multi-tenant Prisma schema — that's here: African Payment Gateway Engine

Testing

Every claim above is covered by a real test, including the failure cases (tampered body, wrong secret, empty inputs):

pnpm install
pnpm test

License

MIT — see LICENSE.