{"id":22793087,"url":"https://github.com/kripod/mental-poker","last_synced_at":"2025-07-22T15:07:46.107Z","repository":{"id":57294600,"uuid":"66139342","full_name":"kripod/mental-poker","owner":"kripod","description":"A purely functional mental poker library, based on the thesis of Choongmin Lee.","archived":false,"fork":false,"pushed_at":"2018-01-30T17:56:47.000Z","size":1571,"stargazers_count":76,"open_issues_count":3,"forks_count":16,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-10T13:27:44.159Z","etag":null,"topics":["crypto","mental-poker","poker","provably-fair"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kripod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-20T09:38:01.000Z","updated_at":"2025-05-10T16:10:18.000Z","dependencies_parsed_at":"2022-08-29T08:01:47.645Z","dependency_job_id":null,"html_url":"https://github.com/kripod/mental-poker","commit_stats":null,"previous_names":["cypherpoker/cypherpoker-js","mental-poker/mental-poker-api-js"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/kripod/mental-poker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kripod%2Fmental-poker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kripod%2Fmental-poker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kripod%2Fmental-poker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kripod%2Fmental-poker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kripod","download_url":"https://codeload.github.com/kripod/mental-poker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kripod%2Fmental-poker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266516225,"owners_count":23941372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crypto","mental-poker","poker","provably-fair"],"created_at":"2024-12-12T03:17:59.756Z","updated_at":"2025-07-22T15:07:46.085Z","avatar_url":"https://github.com/kripod.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mental-poker\n\n[![Version (npm)](https://img.shields.io/npm/v/mental-poker.svg)](https://npmjs.com/package/mental-poker)\n[![Build status](https://img.shields.io/travis/kripod/mental-poker/master.svg)](https://travis-ci.org/kripod/mental-poker)\n[![Dependencies](https://img.shields.io/david/kripod/mental-poker.svg)](https://david-dm.org/kripod/mental-poker)\n[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n\nA purely functional mental poker library, based on the [thesis of Choongmin Lee][].\n\n[thesis of choongmin lee]: http://www.clee.kr/thesis.pdf\n\n## Introduction\n\nMental 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.\n\nA 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.\n\n## Getting started\n\n_It is strongly recommended to [read the specification][] before exploring the interface of the implementation._\n\nAn example of using the API can be found [here](example).\n\n[read the specification]: specs\n\n### Establishing a game\n\n#### Configuration\n\nFirstly, a configuration object has to be created and agreed upon by players.\n\n```js\nimport { createConfig } from 'mental-poker';\n\n// Set up a game with a standard 52-card deck\nconst config = createConfig(52);\n```\n\n#### Initial deck setup\n\nEach 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.\n\nPlayers should share codeword fragments with each other through a commitment scheme, to prevent malicious entities from manipulating the generated codewords in their own favor.\n\n```js\nimport { createPlayer, createDeck } from 'mental-poker';\n\nconst self = createPlayer(config);\n\n// Players should share their public data with each other\n// Sensitive information (e.g. private keys) shall be kept in secret\nconst opponents = [\n  /* Received from others */\n];\n\n// Points generation (Thesis, 3.1.1)\nconst cardCodewords = createDeck(\n  [self, ...opponents].map(player =\u003e player.cardCodewordFragments),\n);\n```\n\nAfter that, the deck shall be shuffled and each of its cards must be encrypted one by one.\n\n```js\nimport { encryptDeck, decryptDeck } from 'mental-poker';\n\n// Any kind of array shuffling algorithm may be used\nimport shuffle from 'lodash.shuffle';\n\n// The deck may also be received from the previous player in turn\nlet deck = cardCodewords;\n\n// Cascaded shuffling (Thesis, 3.1.2)\n// Each player shall shuffle the deck and encrypt it as a whole\ndeck = encryptDeck(shuffle(deck), self.keyPairs[config.cardCount].privateKey);\n\n// The deck shall be passed on to the next player\ndeck = [\n  /* And then received from someone else */\n];\n\n// Locking (Thesis, 3.1.3)\n// Each player shall decrypt the deck as a whole and encrypt its cards one by one\ndeck = encryptDeck(\n  decryptDeck(deck, self.keyPairs[config.cardCount].privateKey),\n  self.keyPairs.map(keyPair =\u003e keyPair.privateKey),\n);\n```\n\n### Drawing cards\n\nThe value of a card may be known by anyone in possession of its corresponding private keys it has been encrypted with.\n\n```js\nimport { decryptCard } from 'mental-poker';\n\n// Drawing/opening (Thesis, 3.2-3.3)\n// Choose an encrypted card at random\nconst cardEncrypted = deck[i];\n\n// Find out the codeword of the card after all the required keys are available\nconst cardDecrypted = decryptCard(\n  cardEncrypted,\n  [self, ...opponents].map(player =\u003e player.keyPairs[i].privateKey),\n);\n\n// The resulting codeword index below represents a card ID\n// If its value is -1, then someone has violated the protocol\nconst codewordIndex = cardCodewords.findIndex(cardCodeword =\u003e\n  cardCodeword.equals(cardDecrypted),\n);\n```\n\n## API\n\nPlease see the [API reference][] for further information.\n\n[api reference]: docs/API.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkripod%2Fmental-poker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkripod%2Fmental-poker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkripod%2Fmental-poker/lists"}