Creates a new configuration object.
Parameters
cardCount
number Amount of cards in a deck. (optional, default52
)
Returns Object A configuration object.
Generates a private key from cryptographically strong pseudo-random data.
Returns Buffer A random private key.
Creates a new public key.
Parameters
privateKey
Buffer Private key to derive the public key from. (optional, defaultrandomPrivateKey()
)compressed
boolean Determines whether the resulting public key should be compressed. (optional, defaulttrue
)
Returns Buffer A public key derived from the given private key.
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, defaultrandomPrivateKey()
)compressed
boolean Determines whether the resulting public key should be compressed. (optional, defaulttrue
)
Returns Object A key pair object derived from the given private key.
Verifies a key pair.
Parameters
keyPair
Object Key pair to be verified.
Returns boolean True if the key pair is valid, false otherwise.
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.
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, defaulttrue
)
Returns Array<Buffer> An array of public keys, each representing a card as a codeword.
Checks whether a deck is duplicate-free.
Parameters
Returns boolean True if the deck is duplicate-free, false otherwise.
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, defaulttrue
)
Returns Array<Buffer> An array of public keys, each representing a card of the deck.
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, defaulttrue
)
Returns Array<Buffer> An array of public keys, each representing a card of the deck.
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, defaulttrue
)
Returns Buffer A public key, representing a card which can be mapped directly to a card codeword if the supplied private keys were correct.