UNPKG

@navigators-exploration-team/mina-mastermind

Version:

[![Integration tests](https://github.com/navigators-exploration-team/recursive-mastermind-zkApp/actions/workflows/ci.yml/badge.svg)](https://github.com/navigators-exploration-team/recursive-mastermind-zkApp/actions/workflows/ci.yml)

394 lines (393 loc) 13.7 kB
import { Field, SmartContract, State, UInt64, PublicKey, UInt32, Bool, UInt8 } from 'o1js'; import { Combination } from './utils.js'; import { StepProgramProof } from './stepProgram.js'; export { NewGameEvent, GameAcceptEvent, RewardClaimEvent, ForfeitGameEvent, ProofSubmissionEvent, MastermindZkApp, }; declare const NewGameEvent_base: (new (value: { codemasterPubKey: PublicKey; rewardAmount: UInt64; }) => { codemasterPubKey: PublicKey; rewardAmount: UInt64; }) & { _isStruct: true; } & Omit<import("o1js/dist/node/lib/provable/types/provable-intf.js").Provable<{ codemasterPubKey: PublicKey; rewardAmount: UInt64; }, { codemasterPubKey: { x: bigint; isOdd: boolean; }; rewardAmount: bigint; }>, "fromFields"> & { fromFields: (fields: import("o1js/dist/node/lib/provable/field.js").Field[]) => { codemasterPubKey: PublicKey; rewardAmount: UInt64; }; } & { fromValue: (value: { codemasterPubKey: PublicKey | { x: Field | bigint; isOdd: Bool | boolean; }; rewardAmount: number | bigint | UInt64; }) => { codemasterPubKey: PublicKey; rewardAmount: UInt64; }; toInput: (x: { codemasterPubKey: PublicKey; rewardAmount: UInt64; }) => { fields?: Field[] | undefined; packed?: [Field, number][] | undefined; }; toJSON: (x: { codemasterPubKey: PublicKey; rewardAmount: UInt64; }) => { codemasterPubKey: string; rewardAmount: string; }; fromJSON: (x: { codemasterPubKey: string; rewardAmount: string; }) => { codemasterPubKey: PublicKey; rewardAmount: UInt64; }; empty: () => { codemasterPubKey: PublicKey; rewardAmount: UInt64; }; }; declare class NewGameEvent extends NewGameEvent_base { } declare const GameAcceptEvent_base: (new (value: { codeBreakerPubKey: PublicKey; finalizeSlot: UInt32; }) => { codeBreakerPubKey: PublicKey; finalizeSlot: UInt32; }) & { _isStruct: true; } & Omit<import("o1js/dist/node/lib/provable/types/provable-intf.js").Provable<{ codeBreakerPubKey: PublicKey; finalizeSlot: UInt32; }, { codeBreakerPubKey: { x: bigint; isOdd: boolean; }; finalizeSlot: bigint; }>, "fromFields"> & { fromFields: (fields: import("o1js/dist/node/lib/provable/field.js").Field[]) => { codeBreakerPubKey: PublicKey; finalizeSlot: UInt32; }; } & { fromValue: (value: { codeBreakerPubKey: PublicKey | { x: Field | bigint; isOdd: Bool | boolean; }; finalizeSlot: number | bigint | UInt32; }) => { codeBreakerPubKey: PublicKey; finalizeSlot: UInt32; }; toInput: (x: { codeBreakerPubKey: PublicKey; finalizeSlot: UInt32; }) => { fields?: Field[] | undefined; packed?: [Field, number][] | undefined; }; toJSON: (x: { codeBreakerPubKey: PublicKey; finalizeSlot: UInt32; }) => { codeBreakerPubKey: string; finalizeSlot: string; }; fromJSON: (x: { codeBreakerPubKey: string; finalizeSlot: string; }) => { codeBreakerPubKey: PublicKey; finalizeSlot: UInt32; }; empty: () => { codeBreakerPubKey: PublicKey; finalizeSlot: UInt32; }; }; declare class GameAcceptEvent extends GameAcceptEvent_base { } declare const RewardClaimEvent_base: (new (value: { claimer: PublicKey; }) => { claimer: PublicKey; }) & { _isStruct: true; } & Omit<import("o1js/dist/node/lib/provable/types/provable-intf.js").Provable<{ claimer: PublicKey; }, { claimer: { x: bigint; isOdd: boolean; }; }>, "fromFields"> & { fromFields: (fields: import("o1js/dist/node/lib/provable/field.js").Field[]) => { claimer: PublicKey; }; } & { fromValue: (value: { claimer: PublicKey | { x: Field | bigint; isOdd: Bool | boolean; }; }) => { claimer: PublicKey; }; toInput: (x: { claimer: PublicKey; }) => { fields?: Field[] | undefined; packed?: [Field, number][] | undefined; }; toJSON: (x: { claimer: PublicKey; }) => { claimer: string; }; fromJSON: (x: { claimer: string; }) => { claimer: PublicKey; }; empty: () => { claimer: PublicKey; }; }; declare class RewardClaimEvent extends RewardClaimEvent_base { } declare const ForfeitGameEvent_base: (new (value: { playerPubKey: PublicKey; }) => { playerPubKey: PublicKey; }) & { _isStruct: true; } & Omit<import("o1js/dist/node/lib/provable/types/provable-intf.js").Provable<{ playerPubKey: PublicKey; }, { playerPubKey: { x: bigint; isOdd: boolean; }; }>, "fromFields"> & { fromFields: (fields: import("o1js/dist/node/lib/provable/field.js").Field[]) => { playerPubKey: PublicKey; }; } & { fromValue: (value: { playerPubKey: PublicKey | { x: Field | bigint; isOdd: Bool | boolean; }; }) => { playerPubKey: PublicKey; }; toInput: (x: { playerPubKey: PublicKey; }) => { fields?: Field[] | undefined; packed?: [Field, number][] | undefined; }; toJSON: (x: { playerPubKey: PublicKey; }) => { playerPubKey: string; }; fromJSON: (x: { playerPubKey: string; }) => { playerPubKey: PublicKey; }; empty: () => { playerPubKey: PublicKey; }; }; declare class ForfeitGameEvent extends ForfeitGameEvent_base { } declare const ProofSubmissionEvent_base: (new (value: { turnCount: UInt8; isSolved: import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: import("o1js/dist/node/lib/provable/bool.js").Bool; }) => { turnCount: UInt8; isSolved: import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: import("o1js/dist/node/lib/provable/bool.js").Bool; }) & { _isStruct: true; } & Omit<import("o1js/dist/node/lib/provable/types/provable-intf.js").Provable<{ turnCount: UInt8; isSolved: import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: import("o1js/dist/node/lib/provable/bool.js").Bool; }, { turnCount: { value: bigint; }; isSolved: boolean; maxAttemptsExceeded: boolean; }>, "fromFields"> & { fromFields: (fields: import("o1js/dist/node/lib/provable/field.js").Field[]) => { turnCount: UInt8; isSolved: import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: import("o1js/dist/node/lib/provable/bool.js").Bool; }; } & { fromValue: (value: { turnCount: number | UInt8 | { value: string | number | bigint | Field; }; isSolved: boolean | import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: boolean | import("o1js/dist/node/lib/provable/bool.js").Bool; }) => { turnCount: UInt8; isSolved: import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: import("o1js/dist/node/lib/provable/bool.js").Bool; }; toInput: (x: { turnCount: UInt8; isSolved: import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: import("o1js/dist/node/lib/provable/bool.js").Bool; }) => { fields?: Field[] | undefined; packed?: [Field, number][] | undefined; }; toJSON: (x: { turnCount: UInt8; isSolved: import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: import("o1js/dist/node/lib/provable/bool.js").Bool; }) => { turnCount: { value: string; }; isSolved: boolean; maxAttemptsExceeded: boolean; }; fromJSON: (x: { turnCount: { value: string; }; isSolved: boolean; maxAttemptsExceeded: boolean; }) => { turnCount: UInt8; isSolved: import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: import("o1js/dist/node/lib/provable/bool.js").Bool; }; empty: () => { turnCount: UInt8; isSolved: import("o1js/dist/node/lib/provable/bool.js").Bool; maxAttemptsExceeded: import("o1js/dist/node/lib/provable/bool.js").Bool; }; }; declare class ProofSubmissionEvent extends ProofSubmissionEvent_base { } declare class MastermindZkApp extends SmartContract { /** * `compressedState` is the compressed state variable that stores the following game states: * - `rewardAmount`: The amount of tokens to be rewarded to the codeBreaker upon solving the game. * - `finalizeSlot`: The slot at which the game will be finalized. * - `turnCount`: The current turn count of the game. * - `isSolved`: A boolean indicating whether the game has been solved or not. */ compressedState: State<import("o1js/dist/node/lib/provable/field.js").Field>; /** * `codeMasterId` is the ID of the codeMaster `Hash(PubKey)` who created the game. */ codeMasterId: State<import("o1js/dist/node/lib/provable/field.js").Field>; /** * `codeBreakerId` is the ID of the codeBreaker `Hash(PubKey)` who accepted the game. */ codeBreakerId: State<import("o1js/dist/node/lib/provable/field.js").Field>; /** * `refereeId` is the ID of the referee `Hash(PubKey)` who penalizes misbehaving players. */ refereeId: State<import("o1js/dist/node/lib/provable/field.js").Field>; /** * `solutionHash` is the hash of the secret combination and salt. */ solutionHash: State<import("o1js/dist/node/lib/provable/field.js").Field>; /** * `packedGuessHistory` is the compressed state variable that stores the history of guesses made by the code breaker. */ packedGuessHistory: State<import("o1js/dist/node/lib/provable/field.js").Field>; /** * `packedClueHistory` is the compressed state variable that stores the history of clues given by the code master. */ packedClueHistory: State<import("o1js/dist/node/lib/provable/field.js").Field>; readonly events: { newGame: typeof NewGameEvent; gameAccepted: typeof GameAcceptEvent; rewardClaimed: typeof RewardClaimEvent; gameForfeited: typeof ForfeitGameEvent; proofSubmitted: typeof ProofSubmissionEvent; }; /** * Asserts that the game is still ongoing. For internal use only. */ assertNotFinalized(finalizeSlot: UInt32, isSolved: Bool): Promise<UInt32>; deploy(): Promise<void>; /** * Initializes the game, sets the secret combination, maximum attempts, referee, and reward amount. * @param secretCombination The secret combination to be solved by the codeBreaker. * @param salt The salt to be used in the hash function to prevent pre-image attacks. * @param refereePubKey The public key of the referee who will penalize misbehaving players. * @param rewardAmount The amount of tokens to be rewarded to the codeBreaker upon solving the game. */ initGame(secretCombination: Combination, salt: Field, refereePubKey: PublicKey, rewardAmount: UInt64): Promise<void>; /** * Code breaker accepts the game and pays the reward to contract. * * @throws If the game has not been created yet, or if the game has already been accepted by the code breaker. */ acceptGame(): Promise<void>; /** * Submits a proof to on-chain that includes the all game steps and the final solution if the game is solved. * * @param proof The proof generated by using `StepProgramProof` zkProgram. * @param winnerPubKey The public key of the winner. * * @throws If the game has not been accepted yet, or if the game has already been finalized. */ submitGameProof(proof: StepProgramProof, winnerPubKey: PublicKey): Promise<void>; /** * Allows the winner to claim the reward. * @throws If the game has not been finalized yet, or if the caller is not the winner. */ claimReward(): Promise<void>; /** * Allows the referee to forfeit the game and send the reward to the player. * @param playerPubKey The public key of the player to be rewarded. * @throws If the game has been finalized, if the caller is not the referee, or if the provided public key is not a player in the game. */ forfeitWin(playerPubKey: PublicKey): Promise<void>; /** * Allows the codeBreaker to make a guess outside `stepProof` and then gives it to the codeMaster to provide a clue. * @param guessCombination The guess combination made by the codeBreaker. * @throws If the game has not been accepted yet, or if the game has already been finalized. * @throws If the game has already been solved, or if the guess is not valid. */ makeGuess(guessCombination: Combination): Promise<void>; /** * Allows the codeMaster to give a clue to the codeBreaker outside `stepProof`. * @param secretCombination The secret combination to be solved by the codeBreaker. * @param salt The salt to be used in the hash function to prevent pre-image attacks. * @throws If the game has not been accepted yet, or if the game has already been finalized. * @throws If the game has already been solved, or given secret combination and salt are not valid. */ giveClue(secretCombination: Combination, salt: Field): Promise<void>; }