GithubHelp home page GithubHelp logo

mjmau / mental-poker.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kripod/mental-poker

0.0 1.0 0.0 1.44 MB

CypherPoker API implemented in JavaScript, based on the thesis of Choongmin Lee.

Home Page: https://cypherpoker.github.io/cypherpoker-js

License: MIT License

JavaScript 100.00%

mental-poker.js's Introduction

cypherpoker-js

CypherPoker API implemented in JavaScript, based on the thesis of Choongmin Lee.

Sponsored by Easygo.

Version (npm) Build status Code coverage Dependencies Chat

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.

import { Game, Player } from 'cypherpoker';

const players = [
  new Player().generatePoints().generateSecrets(), // Self
  new Player(),
  new Player(),
  new Player(),
];
const game = new Game({ players });

// Broadcast `game.playerSelf.points` and receive the points of other players
// After that, the initial deck generation process should occur
game.generateInitialDeck();

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 turn
if (encryptedDeckOfAnOpponent) {
  game.addDeckToSequence(encryptedDeckOfAnOpponent);
}

// Shuffle the deck by self and then pass it to the next opponent
const deck = game.shuffleDeck();

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 opponent
game.addDeckToSequence(encryptedDeckOfAnOpponent);

// Decrypt, lock and then pass the deck to the next opponent in turn
const deck = game.lockDeck();

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 deck
const cardIndex = game.getRandomPickableCardIndex();

// Obtain the secret of each opponent at the given card index
// After that, the card can be unlocked
const card = game.pickCard(cardIndex);

// Draw the card for self without revealing it
game.drawCard(cardIndex);

// Or open it as a community card
game.openCard(cardIndex);

Performance

Execute npm start to run a benchmark which measures the performance of each step mentioned above.

mental-poker.js's People

Contributors

kripod avatar netzhuffle avatar

Watchers

Michael Maurer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.