diff --git a/.github/workflows/a11y.yml b/.github/workflows/a11y.yml new file mode 100644 index 0000000..21c9ff9 --- /dev/null +++ b/.github/workflows/a11y.yml @@ -0,0 +1,70 @@ +name: a11y + +on: + pull_request: + paths: + - client/** + - docs/accessibility.md + - .github/workflows/a11y.yml + push: + branches: [main] + paths: + - client/** + - docs/accessibility.md + - .github/workflows/a11y.yml + +permissions: + contents: read + +concurrency: + group: a11y-${{ github.ref }} + cancel-in-progress: true + +jobs: + audit: + name: accessibility + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 + with: + bun-version: 1.3.14 + - name: Install + working-directory: client + run: bun install --frozen-lockfile + - name: Contrast ratios + working-directory: client + run: bun run contrast + - name: Install Chrome + id: chrome + uses: browser-actions/setup-chrome@48ad923757ca74d66703209fe939badbdf80f2f4 # v2.2.0 + with: + chrome-version: 154.0.8037.92 + install-dependencies: true + - name: Build + working-directory: client + run: bun run build + - name: Serve the production build + working-directory: client + run: | + bun run preview --host 127.0.0.1 --port 4173 --strictPort > "$RUNNER_TEMP/preview.log" 2>&1 & + for _ in $(seq 1 30); do + curl --silent --fail --output /dev/null http://127.0.0.1:4173/ && exit 0 + sleep 1 + done + cat "$RUNNER_TEMP/preview.log" + echo "Preview server did not start" >&2 + exit 1 + - name: Axe, targets, reduced motion and keyboard + working-directory: client + env: + CHROME_PATH: ${{ steps.chrome.outputs.chrome-path }} + run: bun run a11y http://127.0.0.1:4173/ --json > "$RUNNER_TEMP/a11y.json" + - name: Upload report + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + with: + name: a11y-report + path: ${{ runner.temp }}/a11y.json + if-no-files-found: ignore diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml new file mode 100644 index 0000000..d2f603c --- /dev/null +++ b/.github/workflows/perf.yml @@ -0,0 +1,76 @@ +name: perf + +on: + pull_request: + paths: + - client/** + - docs/performance.md + - .github/workflows/perf.yml + push: + branches: [main] + paths: + - client/** + - docs/performance.md + - .github/workflows/perf.yml + +permissions: + contents: read + +concurrency: + group: perf-${{ github.ref }} + cancel-in-progress: true + +jobs: + budget: + name: performance budget + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 + with: + bun-version: 1.3.14 + - name: Install + working-directory: client + run: bun install --frozen-lockfile + - name: Install Chrome + id: chrome + uses: browser-actions/setup-chrome@48ad923757ca74d66703209fe939badbdf80f2f4 # v2.2.0 + with: + chrome-version: 154.0.8037.92 + install-dependencies: true + - name: Build + working-directory: client + run: bun run build + - name: Serve the production build + working-directory: client + run: | + bun run preview --host 127.0.0.1 --port 4173 --strictPort > "$RUNNER_TEMP/preview.log" 2>&1 & + for _ in $(seq 1 30); do + curl --silent --fail --output /dev/null http://127.0.0.1:4173/ && exit 0 + sleep 1 + done + cat "$RUNNER_TEMP/preview.log" + echo "Preview server did not start" >&2 + exit 1 + - name: Check the budgets + working-directory: client + env: + CHROME_PATH: ${{ steps.chrome.outputs.chrome-path }} + run: bun run perf http://127.0.0.1:4173/ --json --profile=ci > "$RUNNER_TEMP/perf.json" + - name: Summarize + if: always() + run: | + test -s "$RUNNER_TEMP/perf.json" || exit 0 + { + echo "### Performance budget" + jq -r '.budgets.throttle as $t | "- Cold load: \(.load.bytesKB) KB of \(.budgets.transferKB) KB\n- Layout shift: \(.load.clsScore) of \(.budgets.layoutShift)\n- Longest task: \(.load.longTasks.maxMs) ms of \(.budgets.longTaskMs) ms\n- Frame p99 at \(.budgets.throttle)x throttle: \(([.frames[] | select(.throttle == $t)][0].p99)) ms of \(.budgets.frameP99Ms) ms"' "$RUNNER_TEMP/perf.json" + jq -r '.violations[] | "- **Over budget:** \(.message)"' "$RUNNER_TEMP/perf.json" + } >> "$GITHUB_STEP_SUMMARY" + - name: Upload report + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + with: + name: perf-report + path: ${{ runner.temp }}/perf.json + if-no-files-found: ignore diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index be26c37..8e12cbf 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,99 @@ # Deepmark -A turn-based dungeon crawler on Stellar testnet. Descend three floors, decide what to keep, and leave a result the contract can replay. +A turn-based dungeon crawler where the Stellar contract replays every run, so a result or a relic cannot be claimed without playing for it. ![Deepmark title. A hooded figure with a lantern stands at the lip of a stone shaft, and the menu sits on the dark rock to the left.](docs/screenshots/title.jpg) -Built for the Find Your Way Meridian Hackathon. The game is live on Stellar testnet. The contract replays every run from its action log, so a result cannot be claimed without playing it, and a verified extraction mints relics as Stellar assets (`DMCOMMON`, `DMRARE`, `DMCORE`). No wallet or extension is needed. See `docs/architecture/onchain-boundary.md` for what is verified on-chain and what stays on the client. +Built for the Find Your Way Meridian Hackathon. It runs on Stellar testnet. No wallet, extension or sign-up is needed: the game creates a testnet account in your browser on the first run. -Contract (testnet): `CDL7OO7MGCNMHZBF5QPJCMBLLY3ORR44TJ54ON44M25YUX6UZ7L46UZW` +## Play in one minute -Forge a delver from predefined items, descend, and if you clear all three floors that exact delver becomes yours, as a verified token you can send down again as a veteran. +The repository is private until the submission freeze, so the live link is added here when it goes public. Until then: -![Floor 1. Open stone is lighter than the blocked rock, with a quiet gray seam. Gold corners mark the stairs.](docs/screenshots/floor.jpg) +```bash +cd client +bun install +bun run dev # open the address it prints +``` -Open floor is lighter than blocked stone, and a thin gray seam separates them. Gold corners mark the stairs. +[Bun](https://bun.com) 1.3.14 or newer is the only requirement. -![Floor 3. The boss holds the gap, a gold core relic sits past it, and the stairs climb toward the light.](docs/screenshots/floor-3.jpg) +1. Press **Enter** on the title, or choose **Forge a delver**. Pick a name, a delver, a weapon and a charm, then **Begin descent**. +2. Move with the **arrow keys** or **WASD**. Walk onto a relic to take it. Gold corners mark the stairs. +3. Walk into a guard to fight. **Enter** attacks and **Esc** retreats. +4. When a floor is clear, **Enter** descends and **Esc** extracts. Extracting banks what you hold. Dying loses it. +5. Clear all three floors and extract, and the contract replays your run and gives you that delver as a token you own. It can go down again as a veteran. -The third floor is the way out. The stairs climb toward daylight, and the core relic is the gold stone beyond the boss. If Stellar cannot open the run, the game still plays and the floor label says Practice, so it is clear that result will not be recorded. +Other keys: **L** leaderboard, **V** vault, **M** your record, **N** sound. On a phone, on-screen controls take over. -The title also fits a phone. The menu stays on the dark side of the shaft, with targets large enough to tap. +![Floor 1. Open stone is lighter than the blocked rock, with a quiet gray seam. Gold corners mark the stairs.](docs/screenshots/floor.jpg) -![Deepmark title on a narrow screen. The wordmark and the four menu buttons sit over the dark rock.](docs/screenshots/title-mobile.jpg) +If Stellar cannot be reached, the game still plays as a practice run. The floor label says Practice, and that result is not recorded. -## Run it locally +## Why Stellar -The client uses [Bun](https://bun.com) 1.3.14 or newer as its package manager. +- **Verified results.** A run is two transactions: `start_run`, where the contract issues the seed, and `finish_run`, where it replays your action log and derives the floor, score and relics itself. A forged log fails or produces a legitimate run. +- **Scarce relics.** `DMCOMMON`, `DMRARE` and `DMCORE` are Stellar assets wrapped by Stellar Asset Contracts that the game contract administers. Nothing is for sale, and no relic is minted without a verified extraction. The caveat for the current testnet issuer is under Limitations. +- **A ladder anyone can audit.** `verify_run` replays any run with no wallet and no write, from the seed in the `run_started` event and the log. -```bash -cd client -bun install -bun run dev -``` +The game is built so it is fun with the chain switched off in your head. Rendering, animation and sound never wait on a transaction, and the two calls happen while the descent plays and after the result is already on screen. The boundary and its reasons are in `docs/architecture/onchain-boundary.md`. -`bun run typecheck` checks the TypeScript project. `bun run golden` regenerates the vectors that tie the TypeScript game to the contract's Rust replay. `bun run build` typechecks and writes the production bundle to `client/dist`. +## On testnet -WASD or arrow keys to move, Enter to confirm, attack or descend, Esc to retreat or extract. M opens your record: runs in this browser, and your verified record and relic balances on Stellar testnet. `/stats` is the public traction page: every address with a finished run, run totals and best floors, read from the testnet contract. On a narrow screen the board scales to the window and on-screen controls take over. A Stellar testnet account is created and funded automatically on first run. +| Item | Id | +|---|---| +| Game contract | `CDEAFSBG7JBN6XMP4HRL7LFBL7L67K4RJK3CIRBV23W3TJQCEADZ7R6N` | +| `DMCOMMON` contract | `CAAFYL2QZU274NLA2IFDB4L6SUNVQKT6OLB6UXGL5L5LMQCFJXSUYFO3` | +| `DMRARE` contract | `CC4RQ4HLTPTXMCZ3OKDL546XXJGOQ5PI2ET6U33C2XTO4BTS6AJV4ANA` | +| `DMCORE` contract | `CC27JVKNDSUM5FDGP4JZDZTKGHJ5RJV7XHJGITTUGOUFE4DVPN6PGLMI` | +| Relic issuer (locked) | `GAD752QFRTNEMQW2SELGHQ5VAMIV3O7H4XRLJN2K2TQFGGXKNFG7CQUK` | +| Contract admin | `GCZCKB4FUIS5BGEMJOC3EQWKLGH662BOY3HFLH3WWPCGQJXOILDXP7GZ` | -## Contract +The setup and verification transactions are listed in `docs/deployments.md`. Look any of them up on [stellar.expert](https://stellar.expert/explorer/testnet). The same ids are in `client/src/stellar/config.ts`. `/stats` in the running client is a public page that lists every address with a finished run, read from the contract. -``` +## Limitations + +- **Testnet only.** There is no mainnet deployment. +- **The contract has an admin who can upgrade it.** Replay verification protects players from forged logs, not from the admin while the role exists. The role is meant to be renounced or moved to a multisig before any mainnet release. Details in `docs/threat-model.md`. +- **Delvers are not standard NFTs.** They have an owner and transfer interface shaped like the Stellar standard and differ from it in several calls and events. Explorer support has not been tested and is not claimed. See `docs/architecture/nft-standard.md`. +- **Seed rerolling is limited, not removed.** A cooldown and a visible abandoned run counter make it cost time. A solver can also play a legal perfect run. +- **The key lives in the browser.** Clearing site data loses the account and its records. A passkey account is the planned replacement. +- **No third party audit.** The review that exists is described in `docs/threat-model.md`. +- **The board is not exposed to screen readers.** See `docs/accessibility.md`. + +## Check it yourself + +```bash cd contracts/deepmark-contract -cargo test +cargo test # 63 tests plus 600 vectors played by the real client stellar contract build + +cd ../../client +bun run typecheck +bun run build # typechecks, then writes client/dist +bun run golden # regenerates the vectors the Rust replay is tested against +bun run perf # performance budgets, needs a running preview and Chrome +bun run a11y # accessibility checks, same requirements +bun run contrast # contrast ratios from the stylesheet ``` -Deployed to testnet with three relic Stellar Asset Contracts. The contract API, the action bytes and the trust model are in `contracts/deepmark-contract/README.md`. +GitHub Actions runs the client checks when `client/` changes, the contract checks when `contracts/` changes, and the performance and accessibility checks in a pinned Chrome. + +## Where things are + +| Path | What | +|---|---| +| `client/` | The game: TypeScript, Vite, canvas. `src/game` is the simulation, `src/render` the screens, `src/stellar` the chain code | +| `contracts/deepmark-contract/` | The Soroban contract. `src/{rng,world,sim}.rs` is a bit exact port of `client/src/game/` | +| `docs/architecture/onchain-boundary.md` | What is on chain, what is not, and why | +| `docs/architecture/nft-standard.md` | Delvers compared with the Stellar NFT standard | +| `docs/deployments.md` | Testnet ids and the transaction of every deployment step | +| `docs/threat-model.md` | The attacks considered, what stops each, what remains | +| `docs/performance.md`, `docs/accessibility.md` | Budgets and accessibility, with how they are measured | +| `docs/submission-checklist.md` | What is done and what is still open | + +The contract API, the action encoding and the trust model are in `contracts/deepmark-contract/README.md`. -## Checks +## Licence -GitHub Actions runs the client commands when `client/` changes, and the contract commands when `contracts/` changes. A change to either workflow file runs that workflow. The client commands are `bun run typecheck` and `bun run build`. The contract commands are `cargo test` and `stellar contract build`. +Licensed under the [Apache License 2.0](LICENSE). diff --git a/client/bun.lock b/client/bun.lock index 39014e9..79ae9a4 100644 --- a/client/bun.lock +++ b/client/bun.lock @@ -9,6 +9,7 @@ }, "devDependencies": { "@types/bun": "^1.4.2", + "axe-core": "^4.14.0", "puppeteer-core": "^25.12.0", "typescript": "^5.6.0", "vite": "^5.4.0", @@ -142,6 +143,8 @@ "asynckit": ["asynckit@0.4.0", "", {}, "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="], + "axe-core": ["axe-core@4.14.0", "", {}, "sha512-9WTZxEjsZ7b13TH8JPmbV2z8CHbl80/2hm3XPEG4JgNdQLK81IBRXmSxHfMAOkSqQeRxT/0dwNDz2GOm3zzpcQ=="], + "axios": ["axios@1.20.0", "", { "dependencies": { "follow-redirects": "^1.16.0", "form-data": "^4.0.6", "https-proxy-agent": "^5.0.1", "proxy-from-env": "^2.1.0" } }, "sha512-r8aOh8j9cGKpgQAqpzrUHnSIc6a59Y3Xf/cv8sy1DrHCkZHzQGEuoq1tARk6qSyDdtQGSDgpb9kFlruzPvrgwg=="], "bignumber.js": ["bignumber.js@11.1.5", "", {}, "sha512-6WmzCNtUnfKpbozq+hOgWaZMMzORmYBwF1xZScyoIX3QRYWeKTtxxwDOW5tIz7C9BdjkIYHGTcelCLkXg0mndw=="], diff --git a/client/index.html b/client/index.html index 6aea494..2f19f7b 100644 --- a/client/index.html +++ b/client/index.html @@ -16,27 +16,27 @@
-

Deepmark

-

+

Deepmark

+

- Deepmark needs a canvas-capable browser. + Deepmark needs a canvas-capable browser.
-