strike-finance-skills 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -0
- package/dist/cli.js +126 -0
- package/dist/skills/strike-account/SKILL.md +208 -0
- package/dist/skills/strike-auth/SKILL.md +200 -0
- package/dist/skills/strike-calculations/SKILL.md +399 -0
- package/dist/skills/strike-deposit/SKILL.md +192 -0
- package/dist/skills/strike-history/SKILL.md +197 -0
- package/dist/skills/strike-klines/SKILL.md +519 -0
- package/dist/skills/strike-market-data/SKILL.md +113 -0
- package/dist/skills/strike-orderbook/SKILL.md +289 -0
- package/dist/skills/strike-price-feeds/SKILL.md +314 -0
- package/dist/skills/strike-trades/SKILL.md +319 -0
- package/dist/skills/strike-trading/SKILL.md +405 -0
- package/dist/skills/strike-userstream/SKILL.md +538 -0
- package/dist/skills/strike-withdraw/SKILL.md +192 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Strike Finance Skills
|
|
2
|
+
|
|
3
|
+
AI coding assistant skills for integrating with [Strike Finance](https://strikefinance.org) — perpetuals trading, builder APIs, and real-time market data.
|
|
4
|
+
|
|
5
|
+
Works with **Claude Code**, **Codex**, **Cursor**, **GitHub Copilot**, **Gemini**, **OpenCode**, **Factory Droid**, and **Pi**.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx strike-finance-skills install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This detects which AI agents you have installed and copies skills to the correct directories. Use `--yes` to auto-install without prompting:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx strike-finance-skills install --yes
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Install for specific agents only:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx strike-finance-skills install --agents claude cursor codex
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## What's Included
|
|
26
|
+
|
|
27
|
+
| Skill | Description |
|
|
28
|
+
|-------|-------------|
|
|
29
|
+
| `strike-auth` | Authentication, builder connect, Ed25519 API wallet signing |
|
|
30
|
+
| `strike-account` | Account management, balances, portfolio |
|
|
31
|
+
| `strike-deposit` | Multi-chain deposit flow (quote, build-tx, confirm) |
|
|
32
|
+
| `strike-withdraw` | Withdrawal flow with chain-specific signatures |
|
|
33
|
+
| `strike-trading` | Orders, batch orders, bracket strategies, TWAP, leverage, margin |
|
|
34
|
+
| `strike-market-data` | Public market data (depth, trades, prices, tickers, klines, OI) |
|
|
35
|
+
| `strike-orderbook` | Orderbook REST snapshots + WebSocket delta patching |
|
|
36
|
+
| `strike-trades` | Real-time market trades + user fill history |
|
|
37
|
+
| `strike-klines` | Chart/candlestick data with mark/index price klines |
|
|
38
|
+
| `strike-price-feeds` | WebSocket channels for real-time prices, mark/index, funding |
|
|
39
|
+
| `strike-userstream` | Authenticated WebSocket for order fills, account updates, positions |
|
|
40
|
+
| `strike-calculations` | Liquidation prices, PnL, margin tiers, available balance |
|
|
41
|
+
| `strike-history` | Order, fill, funding, and transaction history |
|
|
42
|
+
|
|
43
|
+
## API Base URLs
|
|
44
|
+
|
|
45
|
+
| Environment | URL |
|
|
46
|
+
|-------------|-----|
|
|
47
|
+
| Mainnet | `https://api.strikefinance.org` |
|
|
48
|
+
| Testnet | `https://api-v2-testnet.strikefinance.org` |
|
|
49
|
+
| Market Data | `https://api.strikefinance.org/price` |
|
|
50
|
+
| Public WS | `wss://v2.strikefinance.org/ws/stream` |
|
|
51
|
+
| User WS | `wss://api.strikefinance.org/ws/user-api` |
|
|
52
|
+
|
|
53
|
+
## OpenAPI Specs
|
|
54
|
+
|
|
55
|
+
Full OpenAPI 3.0 specs are included in `openapi/` for reference:
|
|
56
|
+
- `trade-api.yaml` — Order management, leverage, margin, TWAP
|
|
57
|
+
- `user-api.yaml` — Account, positions, history
|
|
58
|
+
- `market-api.yaml` — Public market data
|
|
59
|
+
|
|
60
|
+
## Manual Install
|
|
61
|
+
|
|
62
|
+
If you prefer not to use npx, clone and copy:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
git clone https://github.com/strike-finance/builder-skills.git
|
|
66
|
+
# Claude Code
|
|
67
|
+
cp -r builder-skills/skills/* .claude/skills/
|
|
68
|
+
# Cursor
|
|
69
|
+
cp -r builder-skills/skills/* .cursor/skills/
|
|
70
|
+
# Codex
|
|
71
|
+
cp -r builder-skills/skills/* .codex/skills/
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Resources
|
|
75
|
+
|
|
76
|
+
- [Strike Finance](https://strikefinance.org)
|
|
77
|
+
- [API Documentation](https://docs.strikefinance.org)
|
|
78
|
+
- [Builder Reference](https://github.com/strike-finance/strike-builder-reference)
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
//#region src/utils/detect-agents.ts
|
|
8
|
+
const AGENT_LABELS = {
|
|
9
|
+
claude: "Claude Code",
|
|
10
|
+
codex: "Codex",
|
|
11
|
+
cursor: "Cursor",
|
|
12
|
+
copilot: "GitHub Copilot",
|
|
13
|
+
gemini: "Gemini",
|
|
14
|
+
opencode: "OpenCode",
|
|
15
|
+
droid: "Factory Droid",
|
|
16
|
+
pi: "Pi"
|
|
17
|
+
};
|
|
18
|
+
const AGENT_SKILL_DIRS = {
|
|
19
|
+
claude: ".claude/skills",
|
|
20
|
+
codex: ".codex/skills",
|
|
21
|
+
cursor: ".cursor/skills",
|
|
22
|
+
copilot: ".copilot/skills",
|
|
23
|
+
gemini: ".gemini/skills",
|
|
24
|
+
opencode: ".opencode/skills",
|
|
25
|
+
droid: ".droid/skills",
|
|
26
|
+
pi: ".pi/skills"
|
|
27
|
+
};
|
|
28
|
+
const ALL_AGENTS = [
|
|
29
|
+
"claude",
|
|
30
|
+
"codex",
|
|
31
|
+
"cursor",
|
|
32
|
+
"copilot",
|
|
33
|
+
"gemini",
|
|
34
|
+
"opencode",
|
|
35
|
+
"droid",
|
|
36
|
+
"pi"
|
|
37
|
+
];
|
|
38
|
+
function isInPath(bin) {
|
|
39
|
+
try {
|
|
40
|
+
execSync(`which ${bin}`, { stdio: "ignore" });
|
|
41
|
+
return true;
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function detectAvailableAgents() {
|
|
47
|
+
return ALL_AGENTS.filter((agent) => isInPath(agent));
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/utils/install-for-agent.ts
|
|
51
|
+
function installSkillForAgent(projectRoot, agent, skillSourceDir, skillName) {
|
|
52
|
+
const targetPath = join(projectRoot, AGENT_SKILL_DIRS[agent], skillName);
|
|
53
|
+
rmSync(targetPath, {
|
|
54
|
+
recursive: true,
|
|
55
|
+
force: true
|
|
56
|
+
});
|
|
57
|
+
mkdirSync(targetPath, { recursive: true });
|
|
58
|
+
cpSync(skillSourceDir, targetPath, { recursive: true });
|
|
59
|
+
return targetPath;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/install.ts
|
|
63
|
+
function getSkillsDirectory() {
|
|
64
|
+
return resolve(import.meta.dirname, "skills");
|
|
65
|
+
}
|
|
66
|
+
async function runInstall(options) {
|
|
67
|
+
const skillsDir = getSkillsDirectory();
|
|
68
|
+
if (!existsSync(skillsDir)) {
|
|
69
|
+
console.error(pc.red("Error: Skills directory not found at " + skillsDir));
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
const skillNames = readdirSync(skillsDir).filter((name) => existsSync(join(skillsDir, name, "SKILL.md")));
|
|
73
|
+
if (skillNames.length === 0) {
|
|
74
|
+
console.error(pc.red("Error: No skills found"));
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
console.log(pc.bold(`\n Strike Finance Skills`) + pc.dim(` — ${skillNames.length} skills\n`));
|
|
78
|
+
let selectedAgents;
|
|
79
|
+
if (options.agents && options.agents.length > 0) selectedAgents = options.agents;
|
|
80
|
+
else {
|
|
81
|
+
const detected = detectAvailableAgents();
|
|
82
|
+
if (detected.length === 0) {
|
|
83
|
+
console.log(pc.yellow(" No supported AI agents detected in PATH."));
|
|
84
|
+
console.log(pc.dim(" Supported: claude, codex, cursor, copilot, gemini, opencode, droid, pi\n"));
|
|
85
|
+
console.log(pc.dim(" Installing for all agents anyway...\n"));
|
|
86
|
+
selectedAgents = [
|
|
87
|
+
"claude",
|
|
88
|
+
"codex",
|
|
89
|
+
"cursor",
|
|
90
|
+
"copilot"
|
|
91
|
+
];
|
|
92
|
+
} else if (options.yes) selectedAgents = detected;
|
|
93
|
+
else {
|
|
94
|
+
console.log(pc.dim(" Detected agents:"));
|
|
95
|
+
detected.forEach((a) => console.log(pc.green(` ✓ ${AGENT_LABELS[a]}`)));
|
|
96
|
+
console.log();
|
|
97
|
+
selectedAgents = detected;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const projectRoot = process.cwd();
|
|
101
|
+
let installed = 0;
|
|
102
|
+
for (const agent of selectedAgents) {
|
|
103
|
+
console.log(pc.dim(` Installing for ${AGENT_LABELS[agent]}...`));
|
|
104
|
+
for (const skillName of skillNames) {
|
|
105
|
+
installSkillForAgent(projectRoot, agent, join(skillsDir, skillName), skillName);
|
|
106
|
+
installed++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
console.log(pc.green(`\n ✓ Installed ${skillNames.length} skills for ${selectedAgents.length} agent(s)\n`));
|
|
110
|
+
console.log(pc.dim(" Skills installed:"));
|
|
111
|
+
skillNames.forEach((s) => console.log(pc.dim(` • ${s}`)));
|
|
112
|
+
console.log();
|
|
113
|
+
console.log(pc.dim(" Agents:"));
|
|
114
|
+
selectedAgents.forEach((a) => console.log(pc.dim(` • ${AGENT_LABELS[a]}`)));
|
|
115
|
+
console.log();
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/cli.ts
|
|
119
|
+
const program = new Command();
|
|
120
|
+
program.name("strike-finance-skills").description("Install Strike Finance AI coding assistant skills for trading bots and builder integrations").version("0.0.1");
|
|
121
|
+
program.command("install").description("Install Strike Finance skills for detected AI agents").option("-y, --yes", "Auto-install to all detected agents without prompting").option("--agents <agents...>", "Specify agents to install for (claude, codex, cursor, copilot, gemini, opencode, droid, pi)").action(async (options) => {
|
|
122
|
+
await runInstall(options);
|
|
123
|
+
});
|
|
124
|
+
program.parse();
|
|
125
|
+
//#endregion
|
|
126
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: strike-account
|
|
3
|
+
description: Strike Finance account management — create accounts, query balances, update profiles. Use when building account setup or balance displays.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Strike Finance Account Management
|
|
7
|
+
|
|
8
|
+
## Create Account
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
POST /v2/account
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Creates a new trading account. Requires authentication headers.
|
|
15
|
+
|
|
16
|
+
## Get Account Info
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
GET /v2/account
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Query Parameters:**
|
|
23
|
+
|
|
24
|
+
| Param | Type | Required | Notes |
|
|
25
|
+
|-------|------|----------|-------|
|
|
26
|
+
| `account_id` | string | No | Specify to fetch a particular account |
|
|
27
|
+
| `vault_id` | string | No | Fetch vault account (unauthenticated access allowed) |
|
|
28
|
+
|
|
29
|
+
One of `account_id` or `vault_id` may be provided. If neither is provided, returns the authenticated user's account.
|
|
30
|
+
|
|
31
|
+
**Response (GetAccountResponse):**
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"account_id": "acc_abc123",
|
|
36
|
+
"blockchain": "ethereum",
|
|
37
|
+
"blockchain_address": "0x...",
|
|
38
|
+
"wallet_balance": "10000.00",
|
|
39
|
+
"available_balance": "7500.00",
|
|
40
|
+
"unrealized_pnl": "-250.00",
|
|
41
|
+
"margin_balance": "9750.00",
|
|
42
|
+
"total_margin": "2500.00",
|
|
43
|
+
"position_initial_margin": "2000.00",
|
|
44
|
+
"maintenance_margin": "500.00",
|
|
45
|
+
"symbol_settings": {
|
|
46
|
+
"BTCUSD": {
|
|
47
|
+
"margin_mode": "cross",
|
|
48
|
+
"leverage": 10,
|
|
49
|
+
"allow_pre_trade": true
|
|
50
|
+
},
|
|
51
|
+
"ETHUSD": {
|
|
52
|
+
"margin_mode": "cross",
|
|
53
|
+
"leverage": 5,
|
|
54
|
+
"allow_pre_trade": false
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Fields:**
|
|
61
|
+
|
|
62
|
+
| Field | Type | Description |
|
|
63
|
+
|-------|------|-------------|
|
|
64
|
+
| `account_id` | string | Unique account identifier |
|
|
65
|
+
| `blockchain` | string | Blockchain the account is on |
|
|
66
|
+
| `blockchain_address` | string | On-chain wallet address |
|
|
67
|
+
| `wallet_balance` | string | Total wallet balance (deposits - withdrawals + realized PnL) |
|
|
68
|
+
| `available_balance` | string | Balance available for new positions and withdrawals |
|
|
69
|
+
| `unrealized_pnl` | string | Unrealized profit/loss across all open positions |
|
|
70
|
+
| `margin_balance` | string | wallet_balance + unrealized_pnl |
|
|
71
|
+
| `total_margin` | string | Total margin used (initial + maintenance) |
|
|
72
|
+
| `position_initial_margin` | string | Initial margin locked in open positions |
|
|
73
|
+
| `maintenance_margin` | string | Minimum margin required to keep positions open |
|
|
74
|
+
| `symbol_settings` | Record<string, SymbolSettings> | Per-symbol trading configuration |
|
|
75
|
+
|
|
76
|
+
## Get Balances
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
GET /v2/balances
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Returns a detailed balance breakdown for the authenticated account.
|
|
83
|
+
|
|
84
|
+
**Response:**
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"walletBalance": "10000.00",
|
|
89
|
+
"unrealizedPnl": "-250.00",
|
|
90
|
+
"marginBalance": "9750.00",
|
|
91
|
+
"maintMargin": "500.00",
|
|
92
|
+
"initialMargin": "2500.00",
|
|
93
|
+
"positionInitialMargin": "2000.00",
|
|
94
|
+
"openOrderInitialMargin": "500.00",
|
|
95
|
+
"crossWalletBalance": "10000.00",
|
|
96
|
+
"crossUnPnl": "-250.00",
|
|
97
|
+
"availableBalance": "7250.00",
|
|
98
|
+
"maxWithdrawAmount": "7250.00",
|
|
99
|
+
"marginAvailable": true,
|
|
100
|
+
"updateTime": 1700000000000
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Fields:**
|
|
105
|
+
|
|
106
|
+
| Field | Type | Description |
|
|
107
|
+
|-------|------|-------------|
|
|
108
|
+
| `walletBalance` | string | Total wallet balance |
|
|
109
|
+
| `unrealizedPnl` | string | Unrealized PnL across all positions |
|
|
110
|
+
| `marginBalance` | string | walletBalance + unrealizedPnl |
|
|
111
|
+
| `maintMargin` | string | Maintenance margin requirement |
|
|
112
|
+
| `initialMargin` | string | Total initial margin (positions + orders) |
|
|
113
|
+
| `positionInitialMargin` | string | Initial margin for open positions |
|
|
114
|
+
| `openOrderInitialMargin` | string | Initial margin reserved for open orders |
|
|
115
|
+
| `crossWalletBalance` | string | Cross-margin wallet balance |
|
|
116
|
+
| `crossUnPnl` | string | Cross-margin unrealized PnL |
|
|
117
|
+
| `availableBalance` | string | Balance available for trading |
|
|
118
|
+
| `maxWithdrawAmount` | string | Maximum amount that can be withdrawn |
|
|
119
|
+
| `marginAvailable` | boolean | Whether margin is available for new positions |
|
|
120
|
+
| `updateTime` | number | Unix timestamp (milliseconds) of last update |
|
|
121
|
+
|
|
122
|
+
## Get Portfolio
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
GET /v2/portfolio
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Returns a comprehensive portfolio summary for the authenticated account.
|
|
129
|
+
|
|
130
|
+
**Response:**
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"account": {
|
|
135
|
+
"accountValue": "9750.00",
|
|
136
|
+
"positionValue": "20000.00",
|
|
137
|
+
"availableBalance": "7250.00",
|
|
138
|
+
"allTimePnl": "1500.00",
|
|
139
|
+
"realizedPnl": "1750.00",
|
|
140
|
+
"unrealizedPnl": "-250.00",
|
|
141
|
+
"allTimeVolume": "150000.00"
|
|
142
|
+
},
|
|
143
|
+
"volume": "50000.00",
|
|
144
|
+
"fees": "25.00",
|
|
145
|
+
"history": [
|
|
146
|
+
[1700000000000, "9500.00", "1500.00", "-200.00"],
|
|
147
|
+
[1700086400000, "9750.00", "1750.00", "-250.00"]
|
|
148
|
+
],
|
|
149
|
+
"feeTier": 1,
|
|
150
|
+
"feeTiers": [
|
|
151
|
+
{ "tier": 0, "makerFee": "0.0002", "takerFee": "0.0005", "volumeThreshold": "0" },
|
|
152
|
+
{ "tier": 1, "makerFee": "0.00015", "takerFee": "0.0004", "volumeThreshold": "100000" }
|
|
153
|
+
],
|
|
154
|
+
"volume_history": [],
|
|
155
|
+
"feeDiscountRate": "0.1",
|
|
156
|
+
"isTradingEnabled": true
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Fields:**
|
|
161
|
+
|
|
162
|
+
| Field | Type | Description |
|
|
163
|
+
|-------|------|-------------|
|
|
164
|
+
| `account` | object | Core account metrics |
|
|
165
|
+
| `account.accountValue` | string | Total account value (margin balance) |
|
|
166
|
+
| `account.positionValue` | string | Notional value of all open positions |
|
|
167
|
+
| `account.availableBalance` | string | Available balance for trading |
|
|
168
|
+
| `account.allTimePnl` | string | All-time profit/loss |
|
|
169
|
+
| `account.realizedPnl` | string | All-time realized PnL |
|
|
170
|
+
| `account.unrealizedPnl` | string | Current unrealized PnL |
|
|
171
|
+
| `account.allTimeVolume` | string | Total trading volume |
|
|
172
|
+
| `volume` | string | Recent trading volume (fee tier period) |
|
|
173
|
+
| `fees` | string | Fees paid in the current period |
|
|
174
|
+
| `history` | array | Array of [timestamp, accountValue, realizedPnl, unrealizedPnl] |
|
|
175
|
+
| `feeTier` | number | Current fee tier level |
|
|
176
|
+
| `feeTiers` | array | All available fee tiers with rates and thresholds |
|
|
177
|
+
| `volume_history` | array | Historical volume data |
|
|
178
|
+
| `feeDiscountRate` | string | Active fee discount rate |
|
|
179
|
+
| `isTradingEnabled` | boolean | Whether trading is currently enabled for the account |
|
|
180
|
+
|
|
181
|
+
## Update Profile
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
POST /v2/account/profile
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Updates the user's profile. Uses multipart form data.
|
|
188
|
+
|
|
189
|
+
**Form Fields:**
|
|
190
|
+
|
|
191
|
+
| Field | Type | Required | Description |
|
|
192
|
+
|-------|------|----------|-------------|
|
|
193
|
+
| `nickname` | string | No | Display name |
|
|
194
|
+
| `avatarFile` | File | No | Avatar image file |
|
|
195
|
+
|
|
196
|
+
**Example:**
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const formData = new FormData();
|
|
200
|
+
formData.append("nickname", "TraderJoe");
|
|
201
|
+
formData.append("avatarFile", avatarFile);
|
|
202
|
+
|
|
203
|
+
await authenticatedFetch(baseUrl, "/v2/account/profile", {
|
|
204
|
+
method: "POST",
|
|
205
|
+
body: formData,
|
|
206
|
+
// Do NOT set Content-Type header — browser sets it with boundary
|
|
207
|
+
});
|
|
208
|
+
```
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: strike-auth
|
|
3
|
+
description: Strike Finance API authentication — builder connect, API wallet signing, Ed25519 keypairs. Use when implementing auth, sign up, or request signing.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Strike Finance Authentication
|
|
7
|
+
|
|
8
|
+
## API Servers
|
|
9
|
+
|
|
10
|
+
| Environment | Base URL |
|
|
11
|
+
|-------------|----------|
|
|
12
|
+
| Mainnet | `https://api.strikefinance.org` |
|
|
13
|
+
| Testnet | `https://api-v2-testnet.strikefinance.org` |
|
|
14
|
+
|
|
15
|
+
## Ed25519 Keypair Generation
|
|
16
|
+
|
|
17
|
+
Generate a keypair using `@noble/ed25519` for API wallet signing:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import * as ed from "@noble/ed25519";
|
|
21
|
+
|
|
22
|
+
const privateKey = ed.utils.randomPrivateKey(); // 32 bytes
|
|
23
|
+
const publicKey = await ed.getPublicKeyAsync(privateKey); // 32 bytes
|
|
24
|
+
const publicKeyHex = Buffer.from(publicKey).toString("hex"); // 64 hex chars
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Builder Connect Flow
|
|
28
|
+
|
|
29
|
+
### Step 1: Request Signature
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
POST /auth/builder/request-signature
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Body:**
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"address": "0xYourWalletAddress",
|
|
40
|
+
"chain": "ethereum",
|
|
41
|
+
"public_key": "64-char-hex-ed25519-public-key",
|
|
42
|
+
"code": "your-builder-code",
|
|
43
|
+
"max_fee_bps": 50
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- `chain` — `"ethereum"` | `"solana"` | `"cardano"`
|
|
48
|
+
- `public_key` — 64 hex character Ed25519 public key
|
|
49
|
+
- `max_fee_bps` — 0 to 100 (basis points)
|
|
50
|
+
|
|
51
|
+
**Response:**
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"nonce": "abc123",
|
|
56
|
+
"message_to_sign": "Sign this message to connect..."
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Step 2: Verify Signature
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
POST /auth/builder/verify-signature
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Body:**
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"address": "0xYourWalletAddress",
|
|
71
|
+
"chain": "ethereum",
|
|
72
|
+
"nonce": "abc123",
|
|
73
|
+
"wallet_signature": "0xSignedMessage..."
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Response:**
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"account_id": "acc_abc123",
|
|
82
|
+
"builder_code": "your-builder-code",
|
|
83
|
+
"max_fee_bps": 50,
|
|
84
|
+
"api_wallet_id": "aw_xyz789",
|
|
85
|
+
"api_wallet_public_key": "64-char-hex-public-key",
|
|
86
|
+
"api_wallet_created_at": "2025-01-15T00:00:00Z"
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## API Wallet Auth Headers
|
|
91
|
+
|
|
92
|
+
All subsequent authenticated requests must include these headers:
|
|
93
|
+
|
|
94
|
+
| Header | Format | Example |
|
|
95
|
+
|--------|--------|---------|
|
|
96
|
+
| `X-API-Wallet-Public-Key` | 64 hex chars | `a1b2c3...` |
|
|
97
|
+
| `X-API-Wallet-Signature` | 128 hex chars (Ed25519) | `d4e5f6...` |
|
|
98
|
+
| `X-API-Wallet-Timestamp` | Unix seconds | `1700000000` |
|
|
99
|
+
| `X-API-Wallet-Nonce` | UUID v4 | `550e8400-e29b-41d4-a716-446655440000` |
|
|
100
|
+
|
|
101
|
+
## Signature Message Format
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
{METHOD}:{PATH}:{TIMESTAMP}:{NONCE}:{BODY_HASH}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- `METHOD` — uppercase HTTP method (GET, POST, PUT, DELETE)
|
|
108
|
+
- `PATH` — request path (e.g., `/v2/account`)
|
|
109
|
+
- `TIMESTAMP` — Unix seconds as string
|
|
110
|
+
- `NONCE` — UUID v4
|
|
111
|
+
- `BODY_HASH` — SHA-256 hex digest of the JSON body; use empty string `""` for GET requests
|
|
112
|
+
|
|
113
|
+
## TypeScript Code Example
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import * as ed from "@noble/ed25519";
|
|
117
|
+
import { sha512 } from "@noble/hashes/sha512";
|
|
118
|
+
import { createHash, randomUUID } from "crypto";
|
|
119
|
+
|
|
120
|
+
// Required for @noble/ed25519
|
|
121
|
+
ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));
|
|
122
|
+
|
|
123
|
+
interface AuthHeaders {
|
|
124
|
+
"X-API-Wallet-Public-Key": string;
|
|
125
|
+
"X-API-Wallet-Signature": string;
|
|
126
|
+
"X-API-Wallet-Timestamp": string;
|
|
127
|
+
"X-API-Wallet-Nonce": string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function signRequest(
|
|
131
|
+
method: string,
|
|
132
|
+
path: string,
|
|
133
|
+
body: string | undefined,
|
|
134
|
+
privateKey: Uint8Array,
|
|
135
|
+
publicKeyHex: string
|
|
136
|
+
): AuthHeaders {
|
|
137
|
+
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
138
|
+
const nonce = randomUUID();
|
|
139
|
+
const bodyHash = createHash("sha256")
|
|
140
|
+
.update(body ?? "")
|
|
141
|
+
.digest("hex");
|
|
142
|
+
|
|
143
|
+
const message = `${method.toUpperCase()}:${path}:${timestamp}:${nonce}:${bodyHash}`;
|
|
144
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
145
|
+
const signature = ed.sign(messageBytes, privateKey);
|
|
146
|
+
const signatureHex = Buffer.from(signature).toString("hex");
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
"X-API-Wallet-Public-Key": publicKeyHex,
|
|
150
|
+
"X-API-Wallet-Signature": signatureHex,
|
|
151
|
+
"X-API-Wallet-Timestamp": timestamp,
|
|
152
|
+
"X-API-Wallet-Nonce": nonce,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function authenticatedFetch(
|
|
157
|
+
baseUrl: string,
|
|
158
|
+
path: string,
|
|
159
|
+
options: { method?: string; body?: object },
|
|
160
|
+
privateKey: Uint8Array,
|
|
161
|
+
publicKeyHex: string
|
|
162
|
+
): Promise<Response> {
|
|
163
|
+
const method = options.method ?? "GET";
|
|
164
|
+
const bodyStr = options.body ? JSON.stringify(options.body) : undefined;
|
|
165
|
+
|
|
166
|
+
const headers = signRequest(method, path, bodyStr, privateKey, publicKeyHex);
|
|
167
|
+
|
|
168
|
+
const response = await fetch(`${baseUrl}${path}`, {
|
|
169
|
+
method,
|
|
170
|
+
headers: {
|
|
171
|
+
"Content-Type": "application/json",
|
|
172
|
+
...headers,
|
|
173
|
+
},
|
|
174
|
+
body: bodyStr,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if (response.status === 401) {
|
|
178
|
+
// Clear stored credentials
|
|
179
|
+
window.dispatchEvent(new Event("strike:session-expired"));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return response;
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Session Expiry Handling
|
|
187
|
+
|
|
188
|
+
On receiving a `401 Unauthorized` response:
|
|
189
|
+
|
|
190
|
+
1. Clear all stored credentials (private key, public key)
|
|
191
|
+
2. Dispatch a `"strike:session-expired"` custom event on `window`
|
|
192
|
+
3. Redirect the user to re-authenticate
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
window.addEventListener("strike:session-expired", () => {
|
|
196
|
+
localStorage.removeItem("strike_api_wallet_private_key");
|
|
197
|
+
localStorage.removeItem("strike_api_wallet_public_key");
|
|
198
|
+
// Redirect to connect page or show re-auth modal
|
|
199
|
+
});
|
|
200
|
+
```
|