Overview
zkShuffles SDK provides IZKShuffle as a standard interface to interact with shuffle manager contract. The goal is to simplify zk proof generation and key management. With IZKShuffle interface, game developer can build zk game without any experience on cryptography including zero knowledge proof, and thus can focus on the game logic.
IZKShuffle
joinGameβ
async joinGame(gameId: number): Promise<number>
[src]
Joins the game specified by gameId
, and returns the player ID per game.
Parameters:
gameId
: number
Return:
playerId
: number
checkTurnβ
async checkTurn(gameId: number, startBlock: any = 0): Promise<GameTurn>
[src]
Queries a player's current turn in game gameId
, specified by GameTurn:
enum GameTurn {
NOP, // Not Your Turn
Shuffle, // Shuffle Turn
Deal, // Deal Decrypt Turn
Open, // Open Card
Error, // Game Error
Complete, // Game End
}
Parameters:
gameId
: number
Return:
turn
:GameTurn
shuffleβ
async shuffle(gameId: number): Promise<boolean>
[src]
Shuffles the deck in game gameId
and submits a proof on-chain.
Parameters:
gameId
: number
Return:
result
: boolean.True
is shuffle successs, otherwiseFalse
.
drawβ
async draw(gameId: number): Promise<boolean>
[src]
Draws a card in game gameId
, and submits a proof on-chain.
Parameters:
gameId
: number
Return:
result
: boolean.True
is draw successs, otherwiseFalse
openβ
async open(gameId: number, cardIds: number[]): Promise<number[]>
[src]
Opens cards specified by cardIds
and submits a proof on-chain.
open
automatically sends data to blockchain, such that it is not suitable for opening cards that are only visible to players. UseopenOffchain
instead in this case.
Parameters:
gameId
: numbercardIds
: number[]
Return:
cards
: the index of decrypted cards if open successfully; otherwise -1
openOffchainβ
async openOffchain(gameId: number, cardIds: number[]): Promise<number[]>
[src]
Opens cards specified by cardIds
. Returns card's original value if open successs, otherwise returns -1 for the card.
Different from
open
that sends the decryption onchain,openOffchain
only shows decrypted card on user machine and does not send to blockchain.
Parameters:
gameId
: numbercardIds
: number[]
Return:
cards
: number[]
getPlayerIdβ
async getPlayerId(gameId: number): Promise<number>
[src]
Gets player's id from onchain game gameId
.
Parameters:
gameId
: number
Return:
playerId
: number
queryCardsβ
async queryCards(gameId: number, cardIds: number[]): Promise<number[]>
[src]
Gets the card value specified by cardIds
from on-chain game gameId
.
Parameters:
gameId
: numbercardIds
: number[]
Return:
cards
: number[]