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

mental-poker

v1.0.0

Published

[![Version (npm)](https://img.shields.io/npm/v/mental-poker.svg)](https://npmjs.com/package/mental-poker) [![Build status](https://img.shields.io/travis/kripod/mental-poker/master.svg)](https://travis-ci.org/kripod/mental-poker) [![Dependencies](https://i

Downloads

11

Readme

mental-poker

Version (npm) Build status Dependencies Code style: Prettier

A purely functional mental poker library, based on the thesis of Choongmin Lee.

Introduction

Mental poker makes it possible to play a fair game of poker over a physical distance without the need for a trusted third party, using cryptographic methods to shuffle and then deal from a deck of cards.

A coalition, even if it is of the maximum size, shall not gain advantage over honest players, except that players in a coalition may know the hands of each other.

Getting started

It is strongly recommended to read the specification before exploring the interface of the implementation.

An example of using the API can be found here.

Establishing a game

Configuration

Firstly, a configuration object has to be created and agreed upon by players.

import { createConfig } from 'mental-poker';

// Set up a game with a standard 52-card deck
const config = createConfig(52);

Initial deck setup

Each player shall generate a codeword fragment for each card of the configured deck type. Fragments which correspond to the same card will be combined to produce a deck of cards, represented as an array of codewords.

Players should share codeword fragments with each other through a commitment scheme, to prevent malicious entities from manipulating the generated codewords in their own favor.

import { createPlayer } from 'mental-poker';

const self = createPlayer(config);

// Players should share their public data with each other
// Sensitive information (e.g. private keys) shall be kept in secret
const opponents = [
  /* Received from others */
];

// Points generation (Thesis, 3.1.1)
const cardCodewords = createDeck(
  [self, ...opponents].map(player => player.cardCodewordFragments),
);

After that, the deck shall be shuffled and each of its cards must be encrypted one by one.

// The deck may also be received from the previous player in turn
let deck = cardCodewords;

// Cascaded shuffling (Thesis, 3.1.2)
// Each player shall shuffle the deck and encrypt it as a whole
deck = encryptDeck(shuffle(deck), self.keyPairs[config.cardCount].privateKey);

// The deck shall be passed on to the next player
deck = [
  /* And then received from someone else */
];

// Locking (Thesis, 3.1.3)
// Each player shall decrypt the deck as a whole and encrypt its cards one by one
deck = encryptDeck(
  decryptDeck(deck, self.keyPairs[config.cardCount].privateKey),
  self.keyPairs.map(keyPair => keyPair.privateKey),
);

Drawing cards

The value of a card may be known by anyone in possession of its corresponding private keys it has been encrypted with.

// Drawing/opening (Thesis, 3.2-3.3)
// Choose an encrypted card at random
const cardEncrypted = deck[i];

// Find out the codeword of the card after all the required keys are available
const cardDecrypted = decryptCard(
  cardEncrypted,
  [self, ...opponents].map(player => player.keyPairs[i].privateKey),
);

// The resulting codeword index below represents a card ID
// If its value is -1, then someone has violated the protocol
const codewordIndex = cardCodewords.findIndex(cardCodeword =>
  cardCodeword.equals(cardDecrypted),
);

API

Please see the API reference for further information.