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-oblivion

v1.0.0

Published

a flexible implementation of oblivious transfer

Downloads

6

Readme

Cryptomancy-oblivion

This module implements primitives for oblivious transfer, an interactive protocol which allows one party to choose strictly one out of some number of messages without revealing to the sender which message was chosen.

Based on kevinejohn's 'oblivious-transfer' but with different dependencies and major changes to the API.

DISCLAIMER

I have no idea how safe this is for actual use. I'm personally using it for implementing peer-to-peer games where long-term security is not a concern.

I strongly recommend against using this module for anything other than experimentation.

Use

npm install --save cryptomancy-oblivion

var OT = require("cryptomancy-oblivion");

// Alice has two messages, which can be anything
// To make it interesting, suppose they are codes which unlock prizes of different values
// Bob would like to have both messages, but Alice is forcing him to choose
var Messages = [
    'The key to door number 1',
    'The key to door number 2'
];

var Choice = 0; // 0 or 1

// the protocol uses some public parameters
// an exponent and a modulus as in RSA
var Public = OT.genkeys();

// Alice and Bob each need a 32-byte secret, generated however you like
// 'cryptomancy-source' implements various flavours of randomness, so you can use that
// it returns Uint8Arrays
var Source = require("cryptomancy-source");

var makeSecret = function () {
    return Source.bytes.secure()(32);
};

var alice_secret = makeSecret();
var bob_secret = makeSecret();

// Alice can use the public parameters to mask her secret such that she can share it with Bob
// without him learning what it is
var masked = OT.mask(Public, alice_secret);

// Bob wants what's behind Door number 1
// he can 'blind' his choice by using his secret and combining it with Alice's masked value
// Alice will use this blinded value, but she won't be able to learn which of the two doors Bob chose
var blinded = OT.blind(Public, bob_secret, masked, Choice);

// given Bob's blinded value and using her own secrets, Alice can derive two hashes
// you can derive encryption keys from these hashes. How you do so will depend on the cipher you want to use
var unmasked = OT.unmask(Public, alice_secret, masked, blinded); // an array of two hashes

// Alice can now use these two keys to encrypt the two messages
// there are a lot of ciphers you could use here, but one is provided which should work just fine
var Crypto = require("cryptomancy-oblivion/crypto");

// this cipher assumes a key made of 32 Uint8s
var Encrypted = unmasked.map(function (hash, i) {
    return Crypto.encrypt(hash.subarray(0, 32), Messages[i]);
});

// The trick is that Bob will be able to reproduce only one of the two keys
// corresponding to the choice he made.
var bob_key = OT.unblind(Public, bob_secret, masked).subarray(0, 32);

// Now he can try to decrypt both values, but only the first will work
var decrypted = Crypto.decrypt(bob_key, Encrypted[0]);
assert.equal(decrypted, Messages[0]);

Tests

npm test