From 4d24ec9c6897536f3a39bdfacebdceb276789311 Mon Sep 17 00:00:00 2001 From: Saeed Dadkhah Date: Thu, 30 May 2024 10:45:47 +0330 Subject: [PATCH 1/3] Add deploy to gh-pages action --- .github/workflows/deploy-vue.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/deploy-vue.yml diff --git a/.github/workflows/deploy-vue.yml b/.github/workflows/deploy-vue.yml new file mode 100644 index 0000000..e9bd7d5 --- /dev/null +++ b/.github/workflows/deploy-vue.yml @@ -0,0 +1,30 @@ +name: Deploy + +on: + push: + branches: + - master + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '18' + + - name: Install dependencies + run: yarn install + + - name: Build + run: yarn build-only + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./dist From 840f0a992e6412ff1b211bdd6b3c45d232aaa5f4 Mon Sep 17 00:00:00 2001 From: Saeed Dadkhah Date: Thu, 30 May 2024 11:04:07 +0330 Subject: [PATCH 2/3] Fix reset --- src/components/PlayGame.vue | 12 ++++++----- src/game.ts | 42 +++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/components/PlayGame.vue b/src/components/PlayGame.vue index 5fdac6c..7717b38 100644 --- a/src/components/PlayGame.vue +++ b/src/components/PlayGame.vue @@ -136,14 +136,16 @@ const submit = async () => { const reset = async () => { try { - await game.resetState() - opponentCommited.value = false - players.value = {} - opponentRevealed.value = false - winnerIdx.value = null + await game.reset() // To clear contract's state } catch (error) { console.error(error) } + + game = new Game(nodeUrl.value, applicationId.value) + opponentCommited.value = false + players.value = {} + opponentRevealed.value = false + winnerIdx.value = null } const reveal = async () => { diff --git a/src/game.ts b/src/game.ts index 57088e6..80d6029 100644 --- a/src/game.ts +++ b/src/game.ts @@ -11,7 +11,7 @@ interface VersionRequest { } interface CreateKeyPairRequest { - seed: number[] + seed: Uint8Array } interface KeyComponents { @@ -22,7 +22,7 @@ interface KeyComponents { interface PrepareRequest { signing_key: string choice: string - nonce: number[] + nonce: Uint8Array } interface JoinRequest { @@ -36,11 +36,19 @@ interface CommitRequest { signature: string } +interface ResetRequest { + player_idx: number + commitment: string + signature: string +} + export class Game { constructor(nodeUrl: string, applicationId: string) { this.applicationId = applicationId - this.seed = [...Array(32)].map(() => ~~(Math.random() * 255)) - this.nonce = [...Array(32)].map(() => ~~(Math.random() * 255)) + this.seed = new Uint8Array(32) + crypto.getRandomValues(this.seed) + this.nonce = new Uint8Array(32) + crypto.getRandomValues(this.nonce) this.jsonRpcClient = new JsonRpcClient(nodeUrl, '/jsonrpc') } @@ -94,8 +102,16 @@ export class Game { return response.result?.output } - async resetState() { - await this.mutate('reset_state', {}) + async reset() { + if (!(this.playerIdx && this.commitment && this.signature)) { + throw new Error('Unable to call reset.') + } + + await this.mutate('reset', { + player_idx: this.playerIdx, + commitment: this.commitment, + signature: this.signature + }) } async join(playerName: string): Promise { @@ -114,9 +130,6 @@ export class Game { public_key: keys!.pk } const joinResponse = await this.mutate('join', joinParams) - console.log('**************************') - console.log(joinResponse) - console.log('**************************') this.playerIdx = joinResponse.result?.output return this.playerIdx @@ -132,26 +145,23 @@ export class Game { this.commitment = prepareResponse.result?.output![0] this.signature = prepareResponse.result?.output![1] - const commitResponse = await this.mutate('commit', { + await this.mutate('commit', { player_idx: this.playerIdx!, commitment: this.commitment!, signature: this.signature! }) - - console.log(commitResponse) } async reveal() { - const revealResponse = await this.mutate('reveal', { + await this.mutate('reveal', { player_idx: this.playerIdx, nonce: this.nonce }) - console.log(revealResponse) } applicationId: string - seed: number[] - nonce: number[] + seed: Uint8Array + nonce: Uint8Array jsonRpcClient: JsonRpcClient keys: KeyComponents | undefined commitment: string | undefined From 25cd4c8026089e581aeadca2feebb3a8f3f37130 Mon Sep 17 00:00:00 2001 From: Saeed Dadkhah Date: Thu, 30 May 2024 12:20:53 +0330 Subject: [PATCH 3/3] Update versions --- .github/workflows/deploy-vue.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-vue.yml b/.github/workflows/deploy-vue.yml index e9bd7d5..f58b252 100644 --- a/.github/workflows/deploy-vue.yml +++ b/.github/workflows/deploy-vue.yml @@ -4,16 +4,19 @@ on: push: branches: - master + pull_request: + branches: + - master jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: '18' @@ -24,7 +27,7 @@ jobs: run: yarn build-only - name: Deploy - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./dist