Skip to content

Latest commit

 

History

History
178 lines (108 loc) · 9.65 KB

API.md

File metadata and controls

178 lines (108 loc) · 9.65 KB

Table of Contents

Config

createConfig

src/config.js:6-14

Creates a new configuration object.

Parameters

  • cardCount number Amount of cards in a deck. (optional, default 52)

Returns Object A configuration object.

Key

randomPrivateKey

src/key.js:8-16

Generates a private key from cryptographically strong pseudo-random data.

Returns Buffer A random private key.

createPublicKey

src/key.js:24-27

Creates a new public key.

Parameters

  • privateKey Buffer Private key to derive the public key from. (optional, default randomPrivateKey())
  • compressed boolean Determines whether the resulting public key should be compressed. (optional, default true)

Returns Buffer A public key derived from the given private key.

createKeyPair

src/key.js:35-41

Creates a new key pair, which consists of a public key and a private key.

Parameters

  • privateKey Buffer Private key to derive the public key from. (optional, default randomPrivateKey())
  • compressed boolean Determines whether the resulting public key should be compressed. (optional, default true)

Returns Object A key pair object derived from the given private key.

verifyKeyPair

src/key.js:50-51

Verifies a key pair.

Parameters

  • keyPair Object Key pair to be verified.
    • keyPair.publicKey Buffer Public key to be verified.
    • keyPair.privateKey Buffer Private key on which the verification should be based.

Returns boolean True if the key pair is valid, false otherwise.

Player

createPlayer

src/player.js:12-20

Creates a new player object.

Parameters

  • config Object Configuration object to be used.
  • randomKeyPair Function Key pair generator function, which should return a cryptographically secure random key pair on each call. (optional, default ()=>createKeyPair())
  • randomPublicKey Function Public key generator function, which should return a cryptographically secure random public key on each call. (optional, default ()=>createPublicKey())

Returns Object A player object.

Deck

createDeck

src/deck.js:24-42

Creates a new deck of cards from the given codeword fragments.

Parameters

  • cardCodewordFragmentsOfPlayers Array<(Array<Buffer>)> Card codeword fragments of each player, represented as arrays of public keys. Players shall contribute equal amounts of codeword fragments through a commitment scheme, to prevent malicious players from manipulating the generated codewords in their own favor.
  • compressed boolean Determines whether the resulting public keys should be compressed. (optional, default true)

Returns Array<Buffer> An array of public keys, each representing a card as a codeword.

isDeckDuplicateFree

src/deck.js:49-51

Checks whether a deck is duplicate-free.

Parameters

Returns boolean True if the deck is duplicate-free, false otherwise.

encryptDeck

src/deck.js:61-65

Encrypts every card of a deck using the given private key(s).

Parameters

  • deck Array<Buffer> Deck to be encrypted.
  • privateKeys (Buffer | Array<Buffer>) Private key(s) to encrypt the deck with. If multiple keys are specified, each of them will encrypt the card at its corresponding index.
  • compressed boolean Determines whether the resulting public keys should be compressed. (optional, default true)

Returns Array<Buffer> An array of public keys, each representing a card of the deck.

decryptDeck

src/deck.js:75-85

Decrypts every card of a deck using the given private key(s).

Parameters

  • deck Array<Buffer> Deck to be decrypted.
  • privateKeys (Buffer | Array<Buffer>) Private key(s) to decrypt the deck with. If multiple keys are specified, each of them will decrypt the card at its corresponding index.
  • compressed boolean Determines whether the resulting public keys should be compressed. (optional, default true)

Returns Array<Buffer> An array of public keys, each representing a card of the deck.

decryptCard

src/deck.js:97-102

Decrypts a single card using the given private keys.

Parameters

  • card Buffer Card to be decrypted.
  • privateKeys Array<Buffer> Private keys to decrypt the card with, one by one, regardless of order (as elliptic curve point multiplication, on which encryption and decryption are based on, is a commutative operation).
  • compressed boolean Determines whether the resulting public key should be compressed. (optional, default true)

Returns Buffer A public key, representing a card which can be mapped directly to a card codeword if the supplied private keys were correct.