-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
126 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,95 @@ | ||
# The Ten gateway | ||
|
||
See the documentation [here](https://docs.ten.xyz/wallet-extension/wallet-extension/). | ||
# Ten Gateway Documentation | ||
|
||
## Developer notes | ||
For a comprehensive overview, refer to the [official documentation](https://docs.ten.xyz/docs/tools-infrastructure/hosted-gateway). | ||
|
||
Running gateway frontend locally requires building static files first. | ||
To do that, run `npm run build` in `tools/walletextension/frontend` folder. | ||
## Running the Gateway Locally | ||
|
||
The precompiled binaries for macOS ARM64, macOS AMD64, Windows AMD64 and Linux AMD64 can be built by running the | ||
following commands from the `tools/walletextension/main` folder: | ||
### Backend | ||
|
||
``` | ||
To run the backend locally, it is recommended to use **port 1443** to avoid conflicts with the frontend service, which typically runs on port 3000. First, build the backend using the `go build` command. Navigate to the `tools/walletextension/main` folder and use the following commands to build for your respective operating system: | ||
|
||
```bash | ||
# macOS AMD64 | ||
env GOOS=darwin GOARCH=amd64 go build -o ../bin/wallet_extension_macos_amd64 . | ||
env GOOS=darwin GOARCH=arm64 go build -o ../bin/wallet_extension_macos_arm64 . | ||
|
||
# macOS ARM64 | ||
env GOOS=darwin GOARCH=arm64 go build -o ../bin/wallet_extension_macos_arm64 . | ||
|
||
# Windows AMD64 | ||
env GOOS=windows GOARCH=amd64 go build -o ../bin/wallet_extension_win_amd64.exe . | ||
|
||
# Linux AMD64 | ||
env GOOS=linux GOARCH=amd64 go build -o ../bin/wallet_extension_linux_amd64 . | ||
``` | ||
|
||
The binaries will be created in the `tools/walletextension/bin` folder. | ||
The binaries will be available in the `tools/walletextension/bin` directory. | ||
Run the compiled binary and specify the desired port. | ||
Example: | ||
|
||
### Structure | ||
|
||
This package follows the same structure of `host` and `enclave`. | ||
|
||
It uses a container to wrap the services that are required to allow the wallet extension to fulfill the business logic. | ||
```bash | ||
./wallet_extension_macos_arm64 --port 1443 | ||
``` | ||
|
||
### Running Wallet Extension with Docker | ||
### Additional Backend Configuration Options | ||
|
||
- **`--host`**: The host where the wallet extension should open the port. Default: `127.0.0.1`. | ||
- **`--port`**: The port on which to serve the wallet extension. Default: `3000`. | ||
- **`--portWS`**: The port on which to serve websocket JSON RPC requests. Default: `3001`. | ||
- **`--nodeHost`**: The host on which to connect to the Obscuro node. Default: `erpc.sepolia-testnet.ten.xyz`. | ||
- **`--nodePortHTTP`**: The port on which to connect to the Obscuro node via RPC over HTTP. Default: `80`. | ||
- **`--nodePortWS`**: The port on which to connect to the Obscuro node via RPC over websockets. Default: `81`. | ||
- **`--logPath`**: The path to use for the wallet extension's log file. Default: `sys_out`. | ||
- **`--databasePath`**: The path for the wallet extension's database file. Default: `.obscuro/gateway_database.db`. | ||
- **`--verbose`**: Flag to enable verbose logging of wallet extension traffic. Default: `false`. | ||
- **`--dbType`**: Define the database type (`sqlite` or `mariaDB`). Default: `sqlite`. | ||
- **`--dbConnectionURL`**: If `dbType` is set to `mariaDB`, this must be set. | ||
- **`--tenChainID`**: ChainID of the Ten network that the gateway is communicating with. Default: `443`. | ||
- **`--storeIncomingTxs`**: Flag to enable storing incoming transactions in the database for debugging purposes. Default: `true`. | ||
- **`--rateLimitUserComputeTime`**: Represents how much compute time a user is allowed to use within the `rateLimitWindow` time. Set to `0` to disable rate limiting. Default: `10s`. | ||
- **`--rateLimitWindow`**: Time window in which a user is allowed to use the defined compute time. Default: `1m`. | ||
- **`--maxConcurrentRequestsPerUser`**: Number of concurrent requests allowed per user. Default: `3`. | ||
|
||
|
||
### Frontend | ||
|
||
Once the backend is running, navigate to the `tools/walletextension/frontend` directory and execute the following commands: | ||
|
||
```bash | ||
npm install | ||
npm run dev | ||
``` | ||
|
||
To build a docker image use docker build command. Please note that you need to run it from the root of the repository. | ||
To run the container you can use `./docker_run.sh`. You can add parameters to the script, and they are passed to the wallet extension | ||
(example: `-host=0.0.0.0` to be able to access wallet extension endpoints via localhost). | ||
The frontend will be accessible on `http://localhost:3000`. | ||
|
||
## HTTP Endpoints | ||
|
||
### HTTP Endpoints | ||
Ten Gateway exposes several HTTP endpoints for interaction: | ||
|
||
For interacting with Ten Gateway, there are the following HTTP endpoints available: | ||
- **`GET /v1/join`** | ||
Generates and returns a `userID`, which needs to be added as a query parameter `u` in your Metamask (or another provider) URL to identify you. | ||
|
||
- `GET /v1/join` | ||
- **`POST /v1/authenticate?token=$EncryptionToken`** | ||
Submits a signed message in the format `Register <userID> for <account>`, proving ownership of the private keys for the account, and links that account with the `userID`. | ||
|
||
It generates and returns userID which needs to be added as a query parameter "u" to the URL in your Metamask | ||
(or another provider) as it identifies you. | ||
- **`GET /v1/query/address?token=$EncryptionToken&a=$Address`** | ||
Returns a JSON response indicating whether the address "a" is registered for the user "u". | ||
|
||
- `POST /v1/authenticate?token=$EncryptionToken` | ||
- **`POST /v1/revoke?token=$EncryptionToken`** | ||
Deletes the userId along with the associated authenticated viewing keys. | ||
|
||
With this endpoint, you submit a signed message in the format `Register <userID> for <account>` | ||
from that account which proves that you hold private keys for it, and it links that account with your userID. | ||
- **`GET /v1/health`** | ||
Returns a health status of the service. | ||
|
||
- `GET /v1/query/address?token=$EncryptionToken&a=$Address` | ||
- **`GET /v1/network-health`** | ||
Returns the health status of the node. | ||
|
||
This endpoint responds with a JSON of true or false if the address "a" is already registered for user "u" | ||
- **`GET /v1/network-config`** | ||
Returns the network configuration details. | ||
|
||
- **`GET /v1/version`** | ||
Returns the current version of the gateway | ||
|
||
- `POST "/v1/revoke?token=$EncryptionToken"` | ||
- **`GET /v1/getmessage`** | ||
Generates and returns a message for the user to sign based on the provided encryption token. | ||
|
||
When this endpoint is triggered, the userId with the authenticated viewing keys should be deleted. |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,41 @@ | ||
# Use an official Node.js 22 as a parent image | ||
FROM node:22-alpine | ||
# Use an official Node.js LTS version as a base image | ||
FROM node:20-alpine AS base | ||
|
||
WORKDIR /usr/src/app | ||
|
||
# ARG for build-time variable (GATEWAY_API_URL) | ||
ARG GATEWAY_API_URL | ||
|
||
# ENV for URL to be used in the app | ||
ENV NEXT_PUBLIC_API_GATEWAY_URL=${GATEWAY_API_URL} | ||
ENV PORT=80 | ||
|
||
# Copy package.json and package-lock.json (or yarn.lock) into the container | ||
COPY package*.json ./ | ||
# Set the working directory | ||
WORKDIR /usr/src/app | ||
|
||
RUN npm install | ||
COPY . . | ||
# Copy the necessary files to the working directory | ||
COPY tools/walletextension/frontend/ . | ||
|
||
# Install dependencies | ||
RUN npm ci | ||
|
||
# Build the Next.js app | ||
RUN npm run build | ||
|
||
# Reduce the size of the final image by using a lighter base image | ||
FROM node:20-alpine AS runner | ||
|
||
# Set the working directory | ||
WORKDIR /usr/src/app | ||
|
||
# Copy only the necessary files from the build stage | ||
COPY --from=base /usr/src/app/.next ./.next | ||
COPY --from=base /usr/src/app/public ./public | ||
COPY --from=base /usr/src/app/package*.json ./ | ||
|
||
# Install production dependencies | ||
RUN npm ci --production | ||
|
||
|
||
# Set the environment variables | ||
ENV PORT=80 | ||
|
||
# Expose the port | ||
EXPOSE 80 | ||
CMD ["npm", "start"] | ||
|
||
# Start the application | ||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
output: "export", | ||
// distDir should be "../api/static" in production but .next in development | ||
distDir: process.env.NODE_ENV === "development" ? ".next" : "../api/static", | ||
images: { | ||
unoptimized: true, | ||
}, | ||
// base path for static files should be "" in development but "/static" in production | ||
basePath: process.env.NODE_ENV === "development" ? "" : "/static", | ||
}; | ||
|
||
module.exports = nextConfig; |
Oops, something went wrong.