Skip to content

Commit 1e84407

Browse files
authored
Merge pull request #49 from Stakely/develop
Improved docs organization and writing
2 parents 47c8e95 + 7b1d31e commit 1e84407

18 files changed

Lines changed: 233 additions & 325 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Stage 1: Base image.
44
## Start with a base image containing NodeJS so we can build Docusaurus.
5-
FROM node:lts-slim as base
5+
FROM node:24-slim as base
66
## Enable corepack.
77
# RUN corepack enable
88
## Set the working directory to `/opt/docusaurus`.

docs/staking-api/authentication.md

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,84 @@
11
---
2-
sidebar_position: 4
2+
sidebar_position: 3
33
---
44

55
import AppUrl from '@site/src/components/AppUrl';
66

77
# Authentication
88

9-
This page outlines the necessary steps and protocols for securely interacting with our API, ensuring that your data remains safe and your transactions are securely processed.
9+
This section explains how to authenticate requests to the Stakely Staking API and securely interact with its endpoints.
1010

11-
## Auth
1211

13-
To use the Staking API, you must be registered with an account on <AppUrl />. If you don't have an account yet, you can <AppUrl path="/sign-up">register here</AppUrl>.
12+
## Create API keys
1413

15-
Once registered, <AppUrl path="/sign-in">login into your account</AppUrl>, you'll have access to all the products that Stakely offers, all using the same simplified account.
14+
To use the Staking API, you must have an account on <AppUrl />. If you do not have one yet, you can <AppUrl path="/sign-up">register here</AppUrl>.
1615

17-
Manage your API keys in the Staking API dashboard at <AppUrl path="/staking-api" />. The dashboard provides a simple interface to create new keys, view existing keys, and delete keys you no longer need.
16+
Once registered, <AppUrl path="/sign-in">log in to your account</AppUrl>. A single account provides access to all Stakely products, including the Staking API.
1817

19-
## Using the API Keys
18+
API keys are managed from the Staking API dashboard at <AppUrl path="/staking-api" />. From there, you can create new keys, view existing ones, and revoke keys when no longer needed.
2019

21-
To access the crafting and reporting endpoints, you must authenticate using API keys generated through the Staking API web app at <AppUrl />.
20+
21+
## Using API keys
22+
23+
All API requests must be authenticated using an API key generated through the Staking API dashboard.
2224

2325
Include your API key in the `X-API-KEY` header with every request:
26+
2427
```http
2528
X-API-KEY: your-api-key-here
2629
```
2730

28-
For examples and pre-created code snippets in various programming languages, which will help you integrate our services smoothly, please refer to our API schema available [here](/staking-api/api-reference).
31+
Examples and ready-to-use code snippets in different programming languages are provided in later sections of the documentation, within each network-specific integration guide.
32+
33+
34+
35+
## Response signature verification (optional)
2936

30-
## Security and Verification
37+
As an additional security measure, each HTTP response includes a cryptographic signature in the `x-signature` response header. This signature allows clients to verify the integrity and authenticity of the response payload.
38+
39+
The signature is generated by signing the SHA-256 hash of the HTTP response body using Stakely’s RSA private key. Clients can verify the signature using the corresponding RSA public key provided below.
3140

32-
Ensuring the security of all transactions and data exchanges remains our top priority. To accomplish this, we have implemented a method where the signature of each HTTP response can be found in the header under the name `x-signature`. This signature is the SHA256 hash of the HTTP response body, signed using the Elliptic Curve Digital Signature Algorithm (ECDSA) with the SECP256k1 curve. To verify the integrity and authenticity of the data received, you must use the corresponding public key, which is readily accessible on the expandable bellow.
3341
<details>
34-
<summary>**PUBLIC KEY**</summary>
35-
<div>
36-
<div>Copy this value for signature verification:</div>
37-
<br/>
38-
```markup
39-
-----BEGIN PUBLIC KEY-----
40-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2TpKOJfmku7aEIrKaCMM
41-
xjA10UCixAryVsB+PIoLKTEsUiNfctwbeXcpQuPOit9H7by+ezgg/A4SCog/Dtc7
42-
fTp4Gnnq/adLNDllMeKoQCeIz/3N7TqItr+74NTAm6TkwR4lriIy/XiDpIak530f
43-
8ZXFnmQTz3Cffbio3A9DhgwC5OWjSgkYdU35Rti36OGM6pnPlipxm7KD/9ddjc+H
44-
vRY8o6kbp8Cy9QsXZqivHVvcFQ61gl8TMpgcziNgI+tDiof/SM6x6KGxuGT3s40J
45-
TZ0g98GKgynkRW22OPfK3vP1FZ0UmIRJ6tAWYTNntGjLM+vM1OOsGk+5BmEkxy/B
46-
HwIDAQAB
47-
-----END PUBLIC KEY-----
48-
```
49-
</div>
42+
<summary><strong>Public key</strong></summary>
43+
44+
```text
45+
-----BEGIN PUBLIC KEY-----
46+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2TpKOJfmku7aEIrKaCMM
47+
xjA10UCixAryVsB+PIoLKTEsUiNfctwbeXcpQuPOit9H7by+ezgg/A4SCog/Dtc7
48+
fTp4Gnnq/adLNDllMeKoQCeIz/3N7TqItr+74NTAm6TkwR4lriIy/XiDpIak530f
49+
8ZXFnmQTz3Cffbio3A9DhgwC5OWjSgkYdU35Rti36OGM6pnPlipxm7KD/9ddjc+H
50+
vRY8o6kbp8Cy9QsXZqivHVvcFQ61gl8TMpgcziNgI+tDiof/SM6x6KGxuGT3s40J
51+
TZ0g98GKgynkRW22OPfK3vP1FZ0UmIRJ6tAWYTNntGjLM+vM1OOsGk+5BmEkxy/B
52+
HwIDAQAB
53+
-----END PUBLIC KEY-----
54+
```
55+
5056
</details>
51-
This approach ensures that the data remains unaltered during transmission, thereby preserving the security and integrity of your interactions. While verification of the signature on the client side is optional, we encourage its implementation as an additional measure to further ensure the authenticity and integrity of the data received.
5257

53-
Here is an example code on how you can verify returned signature:
58+
Signature verification on the client side is optional but recommended, especially for integrations requiring additional guarantees around data integrity.
5459

55-
- Node.js Example:
56-
- Replace `publicKey` with the provided Staking API public key.
57-
- Replace `data` with the returned JSON payload at the request.
58-
- Replace `signature` with the returned signature string value located at `x-signature` header
5960

61+
### Example: signature verification in Node.js
6062

6163
```javascript
6264
const crypto = require('crypto');
6365

6466
function verifySignature(publicKey, data, signature) {
65-
const verifier = crypto.createVerify('RSA-SHA256');
66-
verifier.update(data);
67-
return verifier.verify(publicKey, signature, 'base64');
67+
const verifier = crypto.createVerify('RSA-SHA256');
68+
verifier.update(data);
69+
return verifier.verify(publicKey, signature, 'base64');
6870
}
6971

70-
// Example usage:
71-
const publicKey = '-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----'; // Your public key here
72-
const receivedData = '{"data":"Example payload"}'; // JSON string as received from the server
73-
const receivedSignature = 'received_signature_from_header'; // Signature received from the X-Signature header
72+
// Example usage
73+
const publicKey = '-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----';
74+
const receivedData = '{"data":"Example payload"}';
75+
const receivedSignature = 'signature-from-x-signature-header';
7476

7577
const isValid = verifySignature(publicKey, receivedData, receivedSignature);
7678
console.log('Is the signature valid?', isValid);
79+
```
80+
81+
82+
### Next steps
7783

78-
```
84+
Once authenticated, you can start interacting with the network-specific staking endpoints described in the following sections.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Cosmos Hub",
3+
"position": 4,
4+
"link": {
5+
"type": "doc",
6+
"id": "staking-api/cosmos-hub/index"
7+
}
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Cosmos Hub
3+
---
4+
5+
# Cosmos Hub
6+
7+
This section covers Cosmos Hub staking integrations using the Stakely Staking API. It includes Cosmos-specific notes, transaction signing examples, and the staking flows supported by Stakely.
8+
9+
## Useful links
10+
11+
- Stakely, Cosmos (ATOM) staking overview: https://stakely.io/staking/cosmos-atom-staking
12+
- Cosmos Hub delegator FAQ: https://hub.cosmos.network/main/delegators/delegator-faq
13+
- Cosmos SDK documentation: https://docs.cosmos.network/main
14+
15+
## What you will find in this section
16+
17+
- **Signing transactions**: how to sign Cosmos transactions returned by the crafting endpoints, with examples for common signing setups.
18+
- **Native staking**: end-to-end flows and endpoints for delegating, redelegating, and undelegating on Cosmos Hub.
19+
20+
## Notes
21+
22+
- Cosmos integrations require specifying the correct `chain_id` for the target network. The API provides a dedicated endpoint to list all available Cosmos networks and their corresponding `chain_id` values.
23+
- All staking operations are executed on-chain. Stakely prepares the transaction payloads, while signing is performed by your application using your preferred signing method.

docs/staking-api/cosmos/native-staking/_category_.json renamed to docs/staking-api/cosmos-hub/native-staking/_category_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"label": "Native Staking",
3-
"position":4,
3+
"position": 3,
44
"link": {
55
"type": "generated-index",
66
"description": "Cosmos Hub Native Staking Module"

docs/staking-api/cosmos/native-staking/endpoints.md renamed to docs/staking-api/cosmos-hub/native-staking/endpoints.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 3
2+
sidebar_position: 2
33
---
44

55
import StakingOpenApiLink from '@site/src/components/StakingOpenApiLink';
@@ -45,8 +45,7 @@ Need support for another network? Reach out at [admin@stakely.io](mailto:admin@s
4545

4646
If you are unsure which Cosmos networks are enabled for your account you can ask the API directly.
4747

48-
- Endpoint: [`/api/v1/cosmos/native/networks`](/staking-api/api-reference#tag/cosmoshub/get/apiv1cosmoshubnativenetworks)
49-
48+
- Endpoint: [`/api/v1/cosmos/native/networks`](/staking-api/api-reference#tag/cosmoshub/GET/api/v1/cosmoshub/native/networks)
5049
Each object in the response includes:
5150

5251
| Field | Description |
@@ -62,7 +61,7 @@ ____
6261

6362
Craft a stake transaction:
6463

65-
- Endpoint: [`/api/v1/cosmos/native/action/stake`](/staking-api/api-reference#tag/cosmoshub/post/apiv1cosmoshubnativeactionstake)
64+
- Endpoint: [`/api/v1/cosmos/native/action/stake`](/staking-api/api-reference#tag/cosmoshub/POST/api/v1/cosmoshub/native/action/stake)
6665

6766
#### Description
6867

@@ -82,7 +81,7 @@ ____
8281

8382
Craft an unstake transaction:
8483

85-
- Endpoint: [`/api/v1/cosmos/native/action/unstake`](/staking-api/api-reference#tag/cosmoshub/post/apiv1cosmoshubnativeactionunstake)
84+
- Endpoint: [`/api/v1/cosmos/native/action/unstake`](/staking-api/api-reference#tag/cosmoshub/POST/api/v1/cosmoshub/native/action/unstake)
8685

8786
#### Description
8887

@@ -102,7 +101,7 @@ ____
102101

103102
Craft a claim rewards transaction:
104103

105-
- Endpoint: [`/api/v1/cosmos/native/action/claim-rewards`](/staking-api/api-reference#tag/cosmoshub/post/apiv1cosmoshubnativeactionclaimrewards)
104+
- Endpoint: [`/api/v1/cosmos/native/action/claim-rewards`](/staking-api/api-reference#tag/cosmoshub/POST/api/v1/cosmoshub/native/action/claim-rewards)
106105

107106
#### Description
108107

@@ -122,7 +121,7 @@ ____
122121

123122
Gathers signature and unsigned tx:
124123

125-
- Endpoint: [`/api/v1/cosmos/native/action/prepare`](/staking-api/api-reference#tag/cosmoshub/post/apiv1cosmoshubnativeactionprepare)
124+
- Endpoint: [`/api/v1/cosmos/native/action/prepare`](/staking-api/api-reference#tag/cosmoshub/POST/api/v1/cosmoshub/native/action/prepare)
126125

127126
#### Description
128127

@@ -142,7 +141,7 @@ ____
142141

143142
Broadcast a signed transaction
144143

145-
- Endpoint: [`/api/v1/cosmos/native/action/broadcast`](/staking-api/api-reference#tag/cosmoshub/post/apiv1cosmoshubnativeactionbroadcast)
144+
- Endpoint: [`/api/v1/cosmos/native/action/broadcast`](/staking-api/api-reference#tag/cosmoshub/POST/api/v1/cosmoshub/native/action/broadcast)
146145

147146
#### Description
148147

@@ -154,4 +153,4 @@ Broadcast a signed transaction. Usually you will brodcast the signed transaction
154153

155154
#### Returned
156155

157-
[`BroadcastActionResponseDto`](/staking-api/api-reference#model/broadcastctionresponsedto)
156+
[`BroadcastActionResponseDto`](/staking-api/api-reference#model/broadcastctionresponsedto)

docs/staking-api/cosmos/native-staking/staking-flow.md renamed to docs/staking-api/cosmos-hub/native-staking/staking-flow.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,52 @@ Unstaking in Cosmos ecosystem is called undelegation. It is the process of withd
1616

1717
1. **Initiate Undelegation**: Use the undelegate function to start the process of withdrawing your staked ATOMs from the validator.
1818
2. **Unbonding Period**: Undelegated tokens are locked for a 21-day unbonding period, during which they do not earn rewards and cannot be transferred.
19-
3. **Completion**: After the unbonding period, tokens are released and can be freely transferred or restaked.
19+
3. **Completion**: After the unbonding period, tokens are automatically released and can be freely transferred or restaked.
2020

2121
### Claiming Rewards
2222

2323
Rewards generated from staking are not automatically added to your wallet; they must be claimed manually.
2424

25-
1. **Check Accumulated Rewards**: Verify your accumulated rewards through the rewards function or just check the explorer.
25+
1. **Check Accumulated Rewards**: Verify your accumulated rewards through the rewards function or just check an explorer.
2626
2. **Claim Rewards**: Use the `withdraw_rewards` function to transfer your accumulated staking rewards into your wallet.
2727
3. Reinvestment or Transfer: After claiming, rewards can be reinvested by staking them with a validator or used for other transactions.
2828

2929

30-
___
30+
# Staking API Diagram
3131

32-
### Extra information
32+
```mermaid
33+
sequenceDiagram
34+
autonumber
35+
actor User
36+
participant Staking API
37+
User->>+Staking API: Stake action
38+
Note left of User: Offline: Stake 10 ATOM
39+
Note right of Staking API: 🔨 Stake action crafting
40+
Staking API-->>-User: Stake action return
41+
activate User
42+
rect rgb(255,178,216)
43+
Note left of User: 📝 Sign unsigned transaction:
44+
Note left of User: a) Locally with private key 🔑
45+
Note left of User: b) Custodian 🏦
46+
end
47+
deactivate User
3348
34-
:::info
35-
You can have a look to [Protocol-staking-CosmosHub](https://learn.protocolstaking.info/detailed-explainers/staking-mechanism/cosmos-hub) **detailed information** .
36-
:::
49+
User->>+Staking API: Prepare
50+
Note right of Staking API: 🔏 Adds signature to tx
51+
Staking API-->>-User: Returns signed transaction
52+
activate User
53+
rect rgba(228, 173, 77, 0.8)
54+
Note left of User: With the signed transaction you can:
55+
Note left of User: Broadcast it by yourself using any RPC
56+
Note left of User: Send it to the broadcast endpoint
57+
end
58+
deactivate User
59+
User->>+Staking API: Broadcast
60+
Note right of Staking API: 📡 Broadcast to the network
61+
Staking API-->>-User: Returns broadcasted transaction status
62+
activate User
63+
rect rgba(50, 156, 0, 0.8)
64+
Note left of User: If success, transaction is already onchain! 🚀
65+
end
66+
deactivate User
67+
```
Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
---
2-
sidebar_position: 33
2+
sidebar_position: 2
3+
title: Signing
34
---
4-
# How to sign
55

6-
Once you have completed the first action of the flow (as explained in the diagram), you will need to sign the unsigned transaction.
6+
# How to sign transactions
77

8-
There are several ways to achieve this. We will explain a couple of them:
8+
After calling a crafting endpoint, the API returns an unsigned Cosmos transaction payload. This payload must be signed before it can be broadcast to the network.
99

10-
## Signing with private key
10+
Signing is fully handled by your application. The Stakely Staking API never has access to private keys.
1111

12-
### Signing with Cosmos SDK JS using a Private Key:
12+
The signing concepts and examples described in this section apply to all Cosmos Hub staking flows supported by the API, regardless of the specific staking method used.
13+
14+
Below are common signing approaches supported by Cosmos-based tooling.
15+
16+
17+
## Signing with a private key
18+
19+
### Signing with Cosmos SDK JS
20+
21+
This approach uses the Cosmos SDK JavaScript libraries to sign transactions locally with a private key.
22+
23+
The crafted transaction payload returned by the API is passed to the SDK signer, which produces a valid Cosmos signature. The resulting signed transaction can then be broadcast to the network.
24+
25+
This method is typically used in backend services, scripts, or environments where private keys are managed directly by the application.
1326

14-
This method involves the use of the Cosmos SDK JavaScript library, which allows developers to interact with the Cosmos blockchain directly from a JavaScript application. To sign a transaction, a developer typically imports the SDK, creates a transaction object, and then uses a private key to sign this object. This signing process is crucial as it verifies the identity of the transaction initiator and ensures the transaction cannot be altered without the initiator's consent.
1527

1628
Complete with your own wallet private key or seed at `.env`
1729

@@ -20,7 +32,6 @@ COSMOS_WALLET_SEED=
2032
COSMOS_WALLET_PRIVATE_KEY=
2133
COSMOS_RPC=
2234
COSMOS_WALLET_ADDRESS=
23-
2435
```
2536

2637
```javascript
@@ -87,19 +98,17 @@ const { signature_hex, tx_body_hex } = await signUnsignedTxWithPk({unsigned_tx_h
8798
3. Once you have the signature proceed calling `action/prepare`
8899

89100

90-
## Signing by using external custodian integration
101+
## Signing using external custodians or MPC wallets
91102

92-
### Fireblocks
103+
Transactions can also be signed using external custodians or MPC-based wallets. In this setup, private keys are never exposed to the application and signing is delegated to the external signing service.
93104

94-
Using external custodian services such as [Fireblocks](https://www.fireblocks.com/) provides an additional layer of security for transaction signing.
95-
96-
Fireblocks, as a custodian, manages the private keys on behalf of the user, ensuring they are stored securely and are not exposed during the transaction process.
105+
### Fireblocks
97106

98-
To sign a transaction, the transaction details are sent to Fireblocks via its API.
107+
Fireblocks is an example of a third-party custodian that can be used to sign Cosmos transactions generated by the Stakely Staking API.
99108

100-
Fireblocks then signs the transaction securely within its infrastructure and returns the signed transaction, ready for submission to the blockchain network.
109+
The crafted transaction payload is submitted to Fireblocks through its API. Fireblocks performs the signing operation within its secure environment and returns a signed transaction, which can then be broadcast to the blockchain network.
101110

102-
On the code example we will be providing a Javascript example with the usage of [Fireblocks SDK JS/TS](https://github.com/fireblocks/fireblocks-sdk-js)
111+
The following code example demonstrates this flow using the Fireblocks JavaScript/TypeScript SDK.
103112

104113

105114
Complete with your own Fireblocks credentials at `.env`

docs/staking-api/cosmos/_category_.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)