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

@nao1215/horcrux

v0.0.3

Published

A TypeScript library for splitting files into encrypted fragments (horcruxes) inspired by Harry Potter

Readme

Horcrux

logo

Horcrux is TypeScript library for splitting files into encrypted fragments (horcruxes) inspired by Harry Potter. Split your files into multiple pieces where only a subset is needed to restore the original - no password required!!

If you have a file you want to keep secret, you can split it with Horcrux and hide the horcruxes so that only you can restore the original file. Horcrux works on both Node.js and React Native platforms.

Features

  • With Encryption: AES-256-OFB encryption for data protection
  • Shamir's Secret Sharing: Split encryption keys using mathematical secret sharing
  • Flexible Thresholds: Choose how many pieces are needed for restoration
  • Cross-Platform: Works with Node.js and React Native
  • No Password Needed: Keys are split across horcruxes

example

Installation

npm install @nao1215/horcrux

Quick Start

import { split, bind, nodeAdapter } from '@nao1215/horcrux';
import { saveHorcruxes } from '@nao1215/horcrux/core/split';

// Split a file into 5 pieces, need 3 to restore
const result = await split('secret.pdf', 5, 3);

// Save horcruxes (creates secret_1_of_5.horcrux, etc.)
const files = await saveHorcruxes(result.horcruxes, './output', nodeAdapter);

// Later: Restore from any 3 horcruxes
await bind(files.slice(0, 3), 'restored_secret.pdf');

Two Modes

  • Redundant Mode (threshold < total): Each horcrux contains the full encrypted file
  • Space-Efficient Mode (threshold = total): Encrypted data is distributed across horcruxes

API Documentation

Basic Functions

split(inputPath, total, threshold)

Split a file into horcruxes.

const result = await split('document.pdf', 5, 3);
// Creates 5 horcruxes, need any 3 to restore

bind(horcruxPaths, outputPath)

Restore a file from horcruxes.

await bind(['horcrux1.horcrux', 'horcrux2.horcrux', 'horcrux3.horcrux'], 'restored.pdf');

Advanced Usage

Buffer Operations

import { splitBuffer } from '@nao1215/horcrux';
import { bindHorcruxes } from '@nao1215/horcrux/core/bind';

// Split in-memory data
const data = Buffer.from('Secret message');
const result = await splitBuffer(data, 'message.txt', {
  total: 4,
  threshold: 2
});

// Restore from horcruxes
const restored = await bindHorcruxes(result.horcruxes.slice(0, 2));
console.log(restored.data.toString()); // 'Secret message'

Custom Platform Adapters

import { splitFile, nodeAdapter } from '@nao1215/horcrux';

// Use specific adapter
const result = await splitFile('file.txt', {
  total: 5,
  threshold: 3
}, nodeAdapter);

Auto-Discovery

import { autoBind, nodeAdapter } from '@nao1215/horcrux';

// Automatically find and restore horcruxes from a directory
const result = await autoBind('./horcrux_directory', nodeAdapter);

Platform Support

Node.js

Full support out of the box using native crypto and fs modules.

React Native

Requires additional setup:

npm install react-native-fs react-native-crypto
# or
npm install expo-crypto expo-file-system

Then configure:

import { configureReactNative } from '@nao1215/horcrux/adapters/react-native';
import RNFS from 'react-native-fs';
import Crypto from 'react-native-crypto';

configureReactNative(RNFS, Crypto);

Security Considerations

  • Keys are generated using cryptographically secure random number generators
  • Each horcrux includes metadata (filename, timestamp) in plaintext
  • The encryption uses AES-256 in OFB mode with a zero IV
  • Horcruxes from different split operations cannot be mixed

Use Cases

  • Long-term Storage: Store files without worrying about forgetting passwords
  • Distributed Backup: Store horcruxes across multiple locations/services
  • Secure Sharing: Share files where multiple parties must cooperate to access
  • Secret file: Create a file that can only be viewed by following a specific procedure

Contributing

Contributions are welcome! Please see the Contributing Guide for more details.

Testing

# Run all tests
npm test

# Run with coverage
npm run test:coverage

# React Native adapter contract tests
npm run test:react-native

# Watch mode
npm run test:watch

Development

# Install dependencies
npm install

# Build the project
npm run build

# Run linter
npm run lint

# Type checking
npm run typecheck

License

MIT LICENCE

Acknowledgments

Inspired by: