-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add content for Gas Tank API Documentation (XDEFI-6907) (#34)
* docs: base init for Gas Tank API Documentation * base: add code sample for some feature * chore: update api endpoint * docs: update content for Gas Tank API Documentation * chore: update api endpoint * chore: fix comment * docs: update for comment * base: fix comment * base: update * base: update * chore: update * chore: small updates * chore: small update for body request * chore: update title * base: add Message Gastank docs * chore: update * chore: fix comment * chore: update endpoint --------- Co-authored-by: dp <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,176 additions
and
23 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
## Authentication | ||
|
||
### Multiple Addresses Login | ||
|
||
This endpoint facilitates the generation of JWT tokens for multiple wallet addresses in a single request. The request payload should consist of an array of objects, each containing an address and its corresponding signature. Upon successful validation of the signatures, the server will generate JWT tokens for the provided addresses. | ||
|
||
To get signatures, you can use `personal_sign` method from web3.js or ethers.js. Below is an example of how to get a signature using web3.js: | ||
|
||
::: code-group | ||
|
||
```javascript [Request] | ||
const web3 = new Web3(window.ethereum); | ||
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services"; | ||
|
||
const address1 = "0x1234567890123456789012345678901234567890"; | ||
const address2 = "0x0987654321098765432109876543210987654321"; | ||
|
||
const messageToSign = await ( | ||
await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/message`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify([address1, address2]), | ||
}) | ||
).json(); | ||
|
||
const message = messageToSign.message; | ||
|
||
|
||
const signature1 = await web3.eth.personal.sign(message, address1); | ||
const signature2 = await web3.eth.personal.sign(message, address2); | ||
|
||
await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/login`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify([ | ||
{ | ||
address: address1, // Address of the user // [!code highlight] | ||
signature: signature1, // Signature // [!code highlight] | ||
}, | ||
{ | ||
address: address2, // [!code highlight] | ||
signature: signature2, // [!code highlight] | ||
}, | ||
... | ||
]), | ||
}) | ||
.then((response) => { | ||
console.log(response); | ||
// Handle & do something with the response | ||
}) | ||
``` | ||
|
||
```json [Response] | ||
{ | ||
"access": "jwt.access.token", | ||
"refresh": "jwt.refresh.token" | ||
} | ||
``` | ||
|
||
::: | ||
|
||
You can also add new wallets to an existing JWT token. Request will be secured by JWT header. Clients need to submit an array of objects containing the address and signature for each new wallet. The server will validate the signatures and, if successful, update the existing JWT token to include the new wallets and generate new JWT. | ||
|
||
::: code-group | ||
|
||
```javascript [Request] | ||
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services"; | ||
|
||
await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/update`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${jwtToken}`, // JWT token // [!code highlight] | ||
}, | ||
body: JSON.stringify([ | ||
{ | ||
address: newAddress, // [!code highlight] | ||
signature: newSignature, // [!code highlight] | ||
}, | ||
... | ||
]), | ||
}) | ||
.then((response) => { | ||
console.log(response); | ||
// Handle & do something with the response | ||
}) | ||
``` | ||
|
||
```json [Response] | ||
{ | ||
"access": "jwt.access.token", | ||
"refresh": "jwt.refresh.token" | ||
} | ||
``` | ||
|
||
::: | ||
|
||
### Refresh JWT Token | ||
|
||
Clients can use this endpoint to obtain a new JWT token without re-authenticating, providing a refresh token. | ||
|
||
::: code-group | ||
|
||
```javascript [Request] | ||
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services"; | ||
|
||
await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/refresh`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${jwtToken}`, // JWT token // [!code highlight] | ||
}, | ||
body: JSON.stringify({ | ||
refresh: refreshToken, // Refresh token // [!code highlight] | ||
}), | ||
}).then((response) => { | ||
console.log(response); | ||
// Handle & do something with the response | ||
}); | ||
``` | ||
|
||
```json [Response] | ||
{ | ||
"access": "jwt.access.token", | ||
"refresh": "jwt.refresh.token" | ||
} | ||
``` | ||
|
||
::: |
Oops, something went wrong.