mental-poker-api-js
Mental Poker API implemented in JavaScript, based on the thesis of Choongmin Lee.
Sponsored by Easygo.
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.
According to the specification of Choongmin Lee, a coalition, even if it is of the maximum size, cannot gain advantage over honest players except that players in the coalition can share their own hands.
Getting started
Please refer to the API reference to learn more about leveraging the possibilities within the library.
Establishing a game
Firstly, every player should generate points of an elliptic curve, serving as a deck of cards, on the client side. Players must share their generated points with each other in order to finish setting up a new game.
; const players = // Self ;const game = players ; // Broadcast `game.playerSelf.points` and receive the points of other players// After that, the initial deck generation process should occurgame;
Cascaded shuffling
Each player sequentially shuffles the order of the game's deck points, keeping the result in secret by encrypting it as a whole using elliptic curve point multiplication.
// Receive an encrypted deck from an opponent if not acting first in the turnif encryptedDeckOfAnOpponent game; // Shuffle the deck by self and then pass it to the next opponentconst deck = game;
Locking the deck
Each player sequentially locks the game's deck points, keeping the result in secret by encrypting the points with different keys using elliptic curve point multiplication.
// Receive an encrypted deck from an opponentgame; // Decrypt, lock and then pass the deck to the next opponent in turnconst deck = game;
Drawing a card
In the previous step, locking was done using a different secret key for each card. In order to unlock a single card of the deck, every player must provide the secret corresponding to the locked card at the selected index.
In order to open a card, the secret shall be broadcast to every participant. Otherwise, each player should only reveal the secret for the person drawing the card.
// Select a random unowned index of the deckconst cardIndex = game; // Obtain the secret of each opponent at the given card index// After that, the card can be unlockedconst card = game; // Draw the card for self without revealing itgame; // Or open it as a community cardgame;
Performance
Execute npm start
to run a benchmark which measures the performance of each
step mentioned above.