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

shogun-derive

v1.0.1

Published

Key derivation library for Shogun SDK

Downloads

5

Readme

Shogun Derive

A lightweight cryptographic key derivation library for the Shogun SDK ecosystem. This library provides deterministic key derivation from passwords or seed data, supporting multiple cryptographic standards.

Features

  • P-256 Key Derivation: Default ECDSA key pairs for signing and encryption
  • Bitcoin P2PKH Support: secp256k1 keys with Bitcoin address generation
  • Ethereum Support: secp256k1 keys with Ethereum address generation
  • PBKDF2 Key Stretching: 300,000 iterations for security
  • Unicode Support: Proper handling of international characters
  • TypeScript Support: Full type definitions included

Installation

npm install shogun-derive

Usage

Basic Usage (P-256 keys only)

import { derive } from 'shogun-derive';

const keys = await derive('my-password', 'extra-entropy');
console.log(keys.pub);  // Public key for signing
console.log(keys.priv); // Private key for signing
console.log(keys.epub); // Public key for encryption
console.log(keys.epriv); // Private key for encryption

Bitcoin Keys

import { derive } from 'shogun-derive';

const keys = await derive('my-password', 'extra-entropy', {
  includeSecp256k1Bitcoin: true
});

if (keys.secp256k1Bitcoin) {
  console.log(keys.secp256k1Bitcoin.privateKey); // Hex private key
  console.log(keys.secp256k1Bitcoin.publicKey);  // Hex public key
  console.log(keys.secp256k1Bitcoin.address);    // Bitcoin P2PKH address
}

Ethereum Keys

import { derive } from 'shogun-derive';

const keys = await derive('my-password', 'extra-entropy', {
  includeSecp256k1Ethereum: true
});

if (keys.secp256k1Ethereum) {
  console.log(keys.secp256k1Ethereum.privateKey); // 0x-prefixed hex private key
  console.log(keys.secp256k1Ethereum.publicKey);  // 0x-prefixed hex public key
  console.log(keys.secp256k1Ethereum.address);    // Ethereum address
}

All Key Types

import { derive } from 'shogun-derive';

const keys = await derive('my-password', 'extra-entropy', {
  includeP256: true,
  includeSecp256k1Bitcoin: true,
  includeSecp256k1Ethereum: true
});

// All key types will be available

Random Key Generation

import { derive } from 'shogun-derive';

// Generate keys from random entropy
const keys = await derive(undefined, undefined);

API Reference

derive(pwd, extra, options?)

Derives cryptographic keys from input data.

Parameters

  • pwd (string | Uint8Array | undefined): Password or seed data
  • extra (string | string[] | undefined): Additional entropy
  • options (DeriveOptions): Configuration options

Options

interface DeriveOptions {
  includeP256?: boolean;              // Default: true
  includeSecp256k1Bitcoin?: boolean;  // Default: false
  includeSecp256k1Ethereum?: boolean; // Default: false
}

Returns

interface DeriveResult {
  pub?: string;                       // P-256 signing public key
  priv?: string;                      // P-256 signing private key
  epub?: string;                      // P-256 encryption public key
  epriv?: string;                     // P-256 encryption private key
  secp256k1Bitcoin?: {
    privateKey: string;               // Hex private key
    publicKey: string;                // Hex public key
    address: string;                  // Bitcoin P2PKH address
  };
  secp256k1Ethereum?: {
    privateKey: string;               // 0x-prefixed hex private key
    publicKey: string;                // 0x-prefixed hex public key
    address: string;                  // Ethereum address
  };
}

Security Features

  • PBKDF2 Key Stretching: 300,000 iterations with SHA-256
  • Deterministic Output: Same input always produces same keys
  • Salt Separation: Different salts for different key types
  • Input Validation: Proper validation of input parameters
  • Unicode Normalization: NFC normalization for consistent results

Recent Fixes (v1.0.0)

Bug Fixes

  • Fixed salt type casting: Resolved issue with Uint8Array to BufferSource conversion in PBKDF2
  • Improved Unicode support: Fixed btoa() compatibility with Unicode characters
  • Added input validation: Proper validation for empty strings and arrays
  • Enhanced error handling: Better error messages for invalid inputs

Improvements

  • Type safety: Improved TypeScript type definitions
  • Documentation: Enhanced JSDoc comments
  • Test coverage: Added comprehensive test suite
  • Browser compatibility: Better cross-browser support

Development

Building

npm run build

Testing

npm test

Formatting

npm run format

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

Changelog

v1.0.0

  • Initial release
  • P-256, Bitcoin, and Ethereum key derivation
  • PBKDF2 key stretching
  • TypeScript support
  • Comprehensive test suite