A purely functional mental poker library, based on the thesis of Choongmin Lee.
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.
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
Firstly, a configuration object has to be created and agreed upon by players.
;// Set up a game with a standard 52-card deckconst config = ;
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.
;const self = ;// Players should share their public data with each other// Sensitive information (e.g. private keys) shall be kept in secretconst opponents =/* Received from others */;// Points generation (Thesis, 3.1.1)const cardCodewords =;
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 turnlet deck = cardCodewords;// Cascaded shuffling (Thesis, 3.1.2)// Each player shall shuffle the deck and encrypt it as a wholedeck = ;// The deck shall be passed on to the next playerdeck =/* 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 onedeck =;
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 randomconst cardEncrypted = decki;// Find out the codeword of the card after all the required keys are availableconst cardDecrypted =;// The resulting codeword index below represents a card ID// If its value is -1, then someone has violated the protocolconst codewordIndex = cardCodewords;
Please see the API reference for further information.