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

@meproto/crypto-primitives

v0.0.4

Published

Cryptographic primitives for the Me Protocol.

Downloads

473

Readme

@meproto/crypto-primitives

npm version License tests bundle size

Low-level cryptographic primitives for the Me Protocol.

This package provides raw, byte-level cryptography built on top of @noble/curves, @noble/hashes, and @noble/post-quantum.
It exposes no multikey, JWS, JWK, DID logic, or high-level encoding — those live in @meproto/crypto.

This package is intended for advanced users, protocol implementers, and internal Me Protocol tooling.
Most developers should use @meproto/crypto instead.


Included Primitives

🔐 Signature Algorithms

  • P-256 (secp256r1) — ECDSA (DER), SHA-256 prehash
  • Ed25519 — deterministic EdDSA
  • secp256k1 (ES256K) — ECDSA (compact 64-byte R||S), SHA-256 prehash
  • ML-DSA-87 — Post-quantum signature scheme (NIST PQC finalist)

🔑 Key Agreement / KEM

  • X25519 — ECDH (Diffie–Hellman) shared secret derivation
  • ML-KEM-1024 (Kyber-1024) — Post-quantum KEM (encapsulate/decapsulate)

🧩 Encoding & Validation Helpers

  • SEC1 P-256 compression / decompression
  • Compressed secp256k1 key validation
  • Identity encoders for Ed25519, X25519, ML-DSA-87, ML-KEM-1024
  • Public key structural validation helpers

🔧 Utilities

  • Secure random bytes (crypto.getRandomValues)
  • Constant-time byte comparison
  • Hex encoding / decoding
  • TypedArray conversion helpers (asArrayBuffer)
  • Byte concatenation helpers

Installation

pnpm add @meproto/crypto-primitives
# or
npm install @meproto/crypto-primitives
# or
yarn add @meproto/crypto-primitives

Basic Usage

Generate a P-256 keypair

import { generateP256Keypair } from "@meproto/crypto-primitives";

const { secretKey, publicKey } = generateP256Keypair();

Sign & verify with Ed25519

import { generateEd25519Keypair, signEd25519, verifyEd25519 } 
  from "@meproto/crypto-primitives";

const { secretKey, publicKey } = generateEd25519Keypair();

const msg = new TextEncoder().encode("hello");
const sig = signEd25519(msg, secretKey);

const ok = verifyEd25519(sig, msg, publicKey); // true

ECDH with X25519

import { generateX25519Keypair, deriveX25519SharedSecret } 
  from "@meproto/crypto-primitives";

const alice = generateX25519Keypair();
const bob = generateX25519Keypair();

const shared1 = deriveX25519SharedSecret(alice.secretKey, bob.publicKey);
const shared2 = deriveX25519SharedSecret(bob.secretKey, alice.publicKey);

console.log(Buffer.compare(shared1, shared2) === 0); // true

PQC KEM: ML-KEM-1024 Encapsulation / Decapsulation

import {
  generateMlKem1024Keypair,
  mlKem1024Encapsulate,
  mlKem1024Decapsulate
} from "@meproto/crypto-primitives";

const receiver = generateMlKem1024Keypair();

// Encrypt for receiver
const { sharedSecret, cipherText } = mlKem1024Encapsulate(receiver.publicKey);

// Receiver derives same secret
const recovered = mlKem1024Decapsulate(cipherText, receiver.secretKey);

secp256k1 Signing (compact 64-byte signature)

import { generateSecp256k1Keypair, signSecp256k1, verifySecp256k1 } 
  from "@meproto/crypto-primitives";

const { secretKey, publicKey } = generateSecp256k1Keypair();

const sig = signSecp256k1(new Uint8Array([1,2,3]), secretKey);
const ok = verifySecp256k1(sig, new Uint8Array([1,2,3]), publicKey);

When You Should Not Use This Package

Use @meproto/crypto instead if you need:

  • Multikey encoding
  • JWK export
  • JWS signing & verification
  • VM structural validation
  • DID:key support
  • Higher-level cryptographic operations
  • Safe opinionated defaults

This package is intentionally low-level.


License

Apache-2.0 © 2025 ReallyMe LLC