From f61a24ce81497532cc706c079e4916bc144d31d7 Mon Sep 17 00:00:00 2001 From: RSamaium Date: Mon, 29 Jan 2024 00:42:45 +0100 Subject: [PATCH] doc: web3 auth --- docs/.vitepress/config.js | 9 +++++ docs/web3/auth.md | 79 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 docs/web3/auth.md diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index a99a0649..4ce27b7c 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -124,6 +124,13 @@ const migrationMenu = [{ ] }] +const web3Menu = [{ + text: 'Web3', + collapsed: false, + items: [ + { text: "Authentification with wallet", link: "/web3/auth" } + ] +}] const guideMenu = [{ text: 'Quick Start', @@ -203,6 +210,7 @@ const guideMenu = [{ { text: "Create Unit Tests", link: "/guide/unit-test" }, ] }, +...web3Menu, ...migrationMenu ] @@ -276,6 +284,7 @@ module.exports = { '/advanced/': guideMenu, '/plugins/': pluginMenu, '/migration/': guideMenu, + '/web3/': guideMenu, }, plugins: ['@vuepress/active-header-links'], head: [ diff --git a/docs/web3/auth.md b/docs/web3/auth.md new file mode 100644 index 00000000..c38fb73a --- /dev/null +++ b/docs/web3/auth.md @@ -0,0 +1,79 @@ +# Authentification Integrating Web3 into RPGJS + +::: warning +The module is not complete. Further developments are in progress +::: + +## Overview + +By following this guide, you'll be able to connect to a digital wallet like MetaMask and implement Web3 capabilities both on the client and server sides. + +### Prerequisites +- Basic knowledge of RPGJS +- Familiarity with Web3 concepts +- MetaMask or similar digital wallet installed + +## Frontend Integration + +### Customization +You are free to customize the frontend as per your needs. However, an example is provided here for guidance. + +### Example: + +https://github.com/RSamaium/RPG-JS/tree/v4/packages/sample3 + +## Server-Side Integration + +### Installation + +Install the `@rpgjs/web3` plugin: + +```bash +npx rpgjs add @rpgjs/web3 +``` + +Ensure that the `@rpgjs/web3` module is the first in the list: + +Example: +```toml +modules = [ + '@rpgjs/web3', + './main', + '@rpgjs/default-gui', +] +``` + +### Setting up Configuration + +Add the following configurations: + +```toml +[auth] + jwtSecret = 'mysecret' + +[express.cors] + origin = '$ENV:VITE_GAME_URL' + credentials = true + +[express.socketIo.cors] + origin = '$ENV:VITE_GAME_URL' + credentials = true + +[socketIoClient] + withCredentials = true +``` + +## Usage + +### Endpoints +The integration introduces two endpoints: + +- `SERVER_URL + '/nonce'` +- `SERVER_URL + '/verify'` + +These endpoints help in creating an HTTP-only cookie containing a JWT (JSON Web Token). + +### API Utilization +This integration extends the `RpgPlayer` type with Web3 functionalities: + +- `player.web3.walletAddress`: Allows access to the player's wallet address.