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

@algorandfoundation/dp256

v1.1.0

Published

Package used to deterministically generate P256 keypairs, using BIP39.

Downloads

51

Readme

Deterministic P256 TypeScript

A TypeScript implementation for generating deterministic P-256 keypairs from BIP39 mnemonic phrases. This library enables the creation of reproducible cryptographic keypairs for WebAuthn/FIDO2 authentication across different devices.

Features

  • 🔐 Generate deterministic P-256 keypairs from BIP39 mnemonic phrases
  • 🌐 Domain-specific key generation for WebAuthn/FIDO2 use cases
  • 🔄 Cross-platform compatibility (equivalent to Swift and Kotlin implementations)
  • 🧪 Comprehensive test coverage
  • 📦 Modern TypeScript with full type support

Installation

npm install @algorandfoundation/dp256

Usage

Basic Example

import { DeterministicP256 } from '@algorandfoundation/dp256';

const dp256 = new DeterministicP256();

// Step 1: Generate derived main key from BIP39 phrase
const phrase =
  'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
const derivedKey = await dp256.genDerivedMainKeyWithBIP39(phrase);

// Step 2: Generate domain-specific keypair
const privateKey = await dp256.genDomainSpecificKeyPair(
  derivedKey,
  'webauthn.example.com', // origin/domain
  '[email protected]' // user handle
);

// Step 3: Get public key bytes
const publicKeyBytes = dp256.getPurePKBytes(privateKey);

// Step 4: Sign a payload
const payload = new TextEncoder().encode('authenticate user alice');
const signature = dp256.signWithDomainSpecificKeyPair(privateKey, payload);

console.log('Private key length:', privateKey.length); // 32 bytes
console.log('Public key length:', publicKeyBytes.length); // 64 bytes (X + Y coordinates)
console.log('Signature length:', signature.length); // 64 bytes

Advanced Configuration

// Custom salt and iteration count
const customDerivedKey = await dp256.genDerivedMainKeyWithBIP39(
  phrase,
  new TextEncoder().encode('custom-salt'), // custom salt
  100_000, // iteration count
  512 // key length in bits
);

// Multiple keypairs for same domain using counter
const keypair1 = await dp256.genDomainSpecificKeyPair(derivedKey, 'example.com', 'user', 0);
const keypair2 = await dp256.genDomainSpecificKeyPair(derivedKey, 'example.com', 'user', 1);

API Reference

genDerivedMainKeyWithBIP39(phrase, salt?, iterationCount?, keyLength?)

Generates a derived main key from a BIP39 mnemonic phrase using PBKDF2-HMAC-SHA512.

  • phrase: BIP39 mnemonic phrase
  • salt: Salt for key derivation (default: "liquid")
  • iterationCount: PBKDF2 iterations (default: 210_000)
  • keyLength: Key length in bits (default: 512)

Returns: Promise<Uint8Array>

genDomainSpecificKeyPair(derivedMainKey, origin, userHandle, counter?)

Generates a domain-specific P-256 private key.

  • derivedMainKey: Output from genDerivedMainKeyWithBIP39
  • origin: Domain/origin identifier
  • userHandle: User identifier
  • counter: Optional counter for multiple keys (default: 0)

Returns: Promise<Uint8Array>

signWithDomainSpecificKeyPair(privateKey, payload)

Signs a payload using the private key.

  • privateKey: Private key from genDomainSpecificKeyPair
  • payload: Data to sign

Returns: Uint8Array (64-byte signature)

getPurePKBytes(privateKey)

Extracts the raw public key bytes from a private key.

  • privateKey: Private key from genDomainSpecificKeyPair

Returns: Uint8Array (64-byte uncompressed public key coordinates)

Security Considerations

  • The BIP39 mnemonic phrase should be generated with sufficient entropy
  • Store the derived main key securely and never expose the original mnemonic
  • This library is designed for deterministic key generation across devices
  • The PBKDF2 iteration count provides additional security hardening

Development

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

License

Apache-2.0

Compatibility

This implementation is equivalent to the Swift and Kotlin versions and produces identical keypairs for the same inputs across all platforms.