Decryption Cache

Purpose of DecryptionCache

In games with asymmetric information, certain elements of the game state may be hidden from some players until specific conditions are met. When the game handler decides to reveal this hidden knowledge, it shares the necessary secret keys with the players, allowing them to decrypt the information.

The DecryptionCache class in the RACE JS SDK serves as a client-side cache for storing this revealed hidden knowledge. It maintains a mapping between randomness IDs and the corresponding decrypted values. This allows the client application to efficiently access and display the revealed information without needing to perform decryption again.

Accessing Revealed Information

To access revealed information from the DecryptionCache, you can use the getRevealed function of the AppClient or SubClient. This function takes the randomness ID as an argument and returns a map containing the decrypted values associated with that randomness.

Here's an example of accessing revealed information:

// Assuming client is an initialized AppClient or SubClient instance

const randomId = 1; // Replace with your randomness ID

const revealed = await client.getRevealed(randomId);

// Use the revealed information to update the game UI

This code snippet demonstrates how the DecryptionCache allows the client application to efficiently retrieve and utilize revealed hidden knowledge, ensuring that players have access to the complete game state when necessary.

By using the DecryptionCache, developers can improve the performance and responsiveness of their game frontends, as they don't need to perform decryption every time the game state is updated with revealed information.

Last updated