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 🙏

© 2024 – Pkg Stats / Ryan Hefner

cryptomancy-accumulator

v1.0.2

Published

a implementation of a cryptographic accumulator in for the cryptomancy suite

Downloads

5

Readme

cryptomancy-accumulator

This module implements a cryptographic accumulator, which allows the holder of a private key to prove that a given token is contained within a set without revealing the contents of the set.

API

Methods are all implemented with both synchronous and asynchronous flavours.

// Import the library
var Acc = require("cryptomancy-accumulator");

// You'll need a source of entropy too
var Source = require("cryptomancy-source");

// You probably want cryptographically secure entropy for key generation...
var secure = Source.bytes.secure(); // a function...

// Finally, you'll most likely want to be able to convert formats
var Format = require("cryptomancy-format");

Acc.genkeys(source, cb)

Generate a set of keys asynchronously.

Acc.genkeys(secure, function (err, keys) {
    console.log(keys);
    /*
        'keys' is an object containing some large numbers,
        encoded as Uint8Arrays.

        keys include two large random primes P and Q
        which ought to be kept secret.

        N is the product of those primes.
        it acts as a public key.
        people will need it to verify your proofs

        Totient is derived from P and Q, and is a bit less sensitive
        than either, but you should still keep it secret!
    */
});

Acc.genkeys.sync(source)

As above, but synchronous.

var keys = Acc.genkeys(secure);

Acc.hashToPrime(U8, cb)

You shouldn't need to use this function, but it's exposed anyway.

Call it with a Uint8Array and it will return a prime number encoded as a another Uint8Array. Given the same input, it will yield the same prime. This is important, as the verification function depends on its determinacy.

var u8 = Format.decodeUTF8('pewpewpew');

Acc.hashToPrime(u8, function (err, function (err, prime) {
    console.log(prime);
});

Acc.hashToPrime.sync(U8)

As above, but synchronous.

var prime = Acc.hashToPrime(Format.decodeUTF8('pewpewpew'));

Acc.secretly(keys, items, cb)

Create an accumulator and byproducts using your secret key

var items = [
    'a',
    'list',
    'of',
    'secret',
    'words',
].map(function (item) {
    // remember that the accumulator is made from Uint8Arrays
    return Format.decodeUTF8(item);
});

Acc.secretly(keys, items, function (err, result) {
    console.log(result);

    /*  result is an object containing:

        acc: a Uint8Array representing a very large number
        composed of all the prime factors derived from your items.

        witnesses: an array of Uint8Arrays, each representing the
        aggregation of all but one of the items prime factors.
        the prime derived by `item[i]` has `witnesses[i]` as its complement.

        primes: you shouldn't need to use the primes, but they're
        returned anyway. also in Uint8Array form.
    */
});

Acc.secretly.sync(keys, items)

As above, but synchronous.

var result = Acc.secretly.sync(keys, items);

Acc.publicly(keys, items, cb)

You can produce the same output as Acc.secretly using only the public key if you provide all the same inputs.

Acc.publicly(keys, items, function (err, result) {
    console.log(result);
    // result should be exactly equivalent to that returned from 'privately'
});

Acc.publicly.sync(keys, items)

As above, but synchronous.

var result = Acc.publicly.sync(keys, items);

Acc.verify(keys, acc, witness, item, cb)

The creator of an accumulator has a set of 'witnesses', which can be used as a proof that a particular prime is encoded within the accumulator.

// as mentioned above, each 'witness' is basically the set-theoretic
// complement of a particular item's prime.

// verification checks that modular multiplication of the witness and item
// produces a value equal to that of the supplied accumulator.

// verification only requires 'N'
// don't go distributing your private keys
Acc.verify(keys, acc, witness, item, function (err, bool) {
    if (bool) {
        // the supplied witness proves that the supplied item
        // is indeed contained within the accumulator
    }

    // but you can't prove the negative
    // this lends the system some interesting properties for deniability
});

Acc.verify.sync(keys, acc, witness, item)

As above, but synchronous.

var bool = Acc.verify(keys, acc, witness, item);
if (bool) {
    // the witness proves that the item is present in acc
}