@agentsbank/sdk 1.0.7
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/.env +38 -0
- package/CHANGELOG.md +45 -0
- package/README.md +337 -0
- package/SKILL.md +250 -0
- package/package.json +46 -0
- package/security-config.ts +264 -0
- package/tsconfig.json +16 -0
package/.env
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# AgentsBank SDK - Environment Variables
|
|
2
|
+
# SECURITY WARNING: Never commit .env to version control
|
|
3
|
+
|
|
4
|
+
# ============================================
|
|
5
|
+
# API Configuration (REQUIRED)
|
|
6
|
+
# ============================================
|
|
7
|
+
# Base URL of AgentsBank API
|
|
8
|
+
AGENTSBANK_API_URL=https://api.agentsbank.online
|
|
9
|
+
|
|
10
|
+
# ============================================
|
|
11
|
+
# Authentication (Choose ONE method)
|
|
12
|
+
# ============================================
|
|
13
|
+
|
|
14
|
+
# METHOD 1: API Key (Recommended for production)
|
|
15
|
+
AGENTSBANK_API_KEY=your-api-key-here-do-not-share
|
|
16
|
+
|
|
17
|
+
# METHOD 2: Agent Credentials (For testing/setup)
|
|
18
|
+
# Uncomment and fill only if using credential-based auth
|
|
19
|
+
# AGENTSBANK_AGENT_USERNAME=agent_name
|
|
20
|
+
# AGENTSBANK_AGENT_PASSWORD=agent_password_secret
|
|
21
|
+
|
|
22
|
+
# ============================================
|
|
23
|
+
# Optional: Pre-authenticated Token
|
|
24
|
+
# ============================================
|
|
25
|
+
# Only needed if you have a pre-issued JWT token
|
|
26
|
+
# AGENTSBANK_AUTH_TOKEN=jwt-token-here
|
|
27
|
+
|
|
28
|
+
# ============================================
|
|
29
|
+
# Optional: Runtime Configuration
|
|
30
|
+
# ============================================
|
|
31
|
+
# Timeout for API requests (in milliseconds)
|
|
32
|
+
SDK_REQUEST_TIMEOUT=10000
|
|
33
|
+
|
|
34
|
+
# Enable verbose logging for debugging
|
|
35
|
+
SDK_DEBUG=false
|
|
36
|
+
|
|
37
|
+
# Custom audit logging endpoint (optional)
|
|
38
|
+
# SDK_AUDIT_LOG_ENDPOINT=https://logs.example.com/audit
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the AgentsBank SDK are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.7] - 2026-02-14
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **Critical**: Fixed all SDK endpoint paths to include `/api` prefix for compatibility with backend routing
|
|
12
|
+
- `/auth/agent/login` → `/api/auth/agent/login`
|
|
13
|
+
- `/wallets` → `/api/wallets`
|
|
14
|
+
- `/transactions` → `/api/transactions`
|
|
15
|
+
- All wallet, transaction, and auth endpoints updated
|
|
16
|
+
- **Enhanced error handling**: Added response interceptor to provide detailed error messages
|
|
17
|
+
- API errors now show status codes and endpoint URLs
|
|
18
|
+
- Network errors provide guidance on API availability
|
|
19
|
+
- Authentication errors suggest credential verification
|
|
20
|
+
- **SDK configuration**: Updated default API URL from `api.agentsbank.ai` to `api.agentsbank.online`
|
|
21
|
+
- **Login error messages**: Improved authentication error feedback with specific guidance
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- Response error interceptor for better debugging experience
|
|
25
|
+
- Network error detection with "API might be offline" message
|
|
26
|
+
- Endpoint URL in error messages for easier troubleshooting
|
|
27
|
+
|
|
28
|
+
### Security
|
|
29
|
+
- No changes to security constraints. SDK continues to require:
|
|
30
|
+
- Explicit API credentials (apiUrl + apiKey or agent credentials)
|
|
31
|
+
- UserApprovalContext for financial operations
|
|
32
|
+
- Audit logging for all transactions
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## [0.1.0] - 2026-01-15
|
|
37
|
+
|
|
38
|
+
### Initial Release
|
|
39
|
+
- Basic SDK for AgentsBank financial operations
|
|
40
|
+
- Support for wallet management (create, list, get balance)
|
|
41
|
+
- Transaction management (send, track, history)
|
|
42
|
+
- Authentication with API keys or agent credentials
|
|
43
|
+
- User approval context for financial operations
|
|
44
|
+
- Comprehensive audit logging
|
|
45
|
+
- Security-first design with credential requirements
|
package/README.md
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# AgentsBank SDK - Security & Integration Guide
|
|
2
|
+
|
|
3
|
+
## ⚠️ Critical Security Requirements
|
|
4
|
+
|
|
5
|
+
This SDK manages **real financial transactions** on blockchain networks. It is **not autonomously invocable** and requires explicit human approval for all financial operations.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 📋 Credential Checklist
|
|
10
|
+
|
|
11
|
+
Before using this SDK in any environment, ensure:
|
|
12
|
+
|
|
13
|
+
- ✅ **API URL Configured**: `AGENTSBANK_API_URL` environment variable is set
|
|
14
|
+
- ✅ **Authentication Enabled**: Provide one of:
|
|
15
|
+
- `AGENTSBANK_API_KEY` (recommended for production)
|
|
16
|
+
- `AGENTSBANK_AGENT_USERNAME` + `AGENTSBANK_AGENT_PASSWORD`
|
|
17
|
+
- Pre-issued JWT token via `token` config
|
|
18
|
+
- ✅ **Credentials Stored Securely**: Never hardcode credentials; use environment variables only
|
|
19
|
+
- ✅ **Audit Logging Enabled**: Pass custom `auditLogger` to track all operations
|
|
20
|
+
- ✅ **.gitignore Updated**: Ensure `.env` files are never committed
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 🚀 Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @agentsbank/sdk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Setup
|
|
31
|
+
|
|
32
|
+
1. **Get credentials** from https://dashboard.agentsbank.ai
|
|
33
|
+
2. **Copy environment template**:
|
|
34
|
+
```bash
|
|
35
|
+
cp .env.example .env
|
|
36
|
+
```
|
|
37
|
+
3. **Fill in credentials** in `.env`
|
|
38
|
+
4. **Load credentials** in your app:
|
|
39
|
+
```typescript
|
|
40
|
+
import dotenv from 'dotenv';
|
|
41
|
+
dotenv.config();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 💰 Basic Usage
|
|
47
|
+
|
|
48
|
+
### Initialize SDK
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { AgentsBankSDK, UserApprovalContext } from '@agentsbank/sdk';
|
|
52
|
+
|
|
53
|
+
const bank = new AgentsBankSDK({
|
|
54
|
+
apiUrl: process.env.AGENTSBANK_API_URL!,
|
|
55
|
+
apiKey: process.env.AGENTSBANK_API_KEY!,
|
|
56
|
+
// Optional: custom audit logger
|
|
57
|
+
auditLogger: (event) => {
|
|
58
|
+
console.log(`[${event.operation}] ${event.status}`, event);
|
|
59
|
+
// Send to logging service (Datadog, LogRocket, etc.)
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Read-Only Operations (No Approval Needed)
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// List wallets
|
|
68
|
+
const wallets = await bank.listWallets();
|
|
69
|
+
|
|
70
|
+
// Get wallet details
|
|
71
|
+
const wallet = await bank.getWallet(walletId);
|
|
72
|
+
|
|
73
|
+
// Check balance
|
|
74
|
+
const balance = await bank.getBalance(walletId);
|
|
75
|
+
|
|
76
|
+
// Estimate gas cost
|
|
77
|
+
const gasEstimate = await bank.estimateGas(walletId, toAddress, amount);
|
|
78
|
+
|
|
79
|
+
// View transaction history
|
|
80
|
+
const history = await bank.getTransactionHistory(walletId, limit);
|
|
81
|
+
|
|
82
|
+
// Get statistics
|
|
83
|
+
const stats = await bank.getStats(walletId, days);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 🔒 Financial Operations (Requires User Approval)
|
|
87
|
+
|
|
88
|
+
**IMPORTANT**: All financial operations require `UserApprovalContext` to prevent autonomous execution.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// ⚠️ Create wallet (financial operation)
|
|
92
|
+
const newWallet = await bank.createWallet('ethereum', 'non-custodial');
|
|
93
|
+
|
|
94
|
+
// ⚠️ Send transaction (MUST have user approval)
|
|
95
|
+
const approval: UserApprovalContext = {
|
|
96
|
+
userId: 'user_123', // ID of human who approved
|
|
97
|
+
approvedAt: new Date(), // When approval was granted
|
|
98
|
+
reason: 'User confirmed in UI', // Audit trail reason
|
|
99
|
+
approvalMethod: 'ui', // How was it approved?
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const transaction = await bank.sendTransaction(
|
|
103
|
+
walletId,
|
|
104
|
+
'0xRecipient...',
|
|
105
|
+
'1.5',
|
|
106
|
+
approval, // ← User approval context (REQUIRED)
|
|
107
|
+
'ETH'
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
console.log('Transaction ID:', transaction.tx_id);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Transaction Monitoring
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// Wait for confirmation
|
|
117
|
+
const confirmed = await bank.waitForConfirmation(
|
|
118
|
+
transaction.tx_id,
|
|
119
|
+
300000, // max wait: 5 minutes
|
|
120
|
+
5000 // poll every 5 seconds
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
console.log('Final status:', confirmed.status); // 'confirmed' | 'failed'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## 🔑 Authentication Methods
|
|
129
|
+
|
|
130
|
+
### Method 1: API Key (Recommended)
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
const bank = new AgentsBankSDK({
|
|
134
|
+
apiUrl: 'https://api.agentsbank.ai',
|
|
135
|
+
apiKey: process.env.AGENTSBANK_API_KEY, // From dashboard
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Method 2: Agent Credentials
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const bank = new AgentsBankSDK({
|
|
143
|
+
apiUrl: 'https://api.agentsbank.ai',
|
|
144
|
+
agentUsername: process.env.AGENTSBANK_AGENT_USERNAME,
|
|
145
|
+
agentPassword: process.env.AGENTSBANK_AGENT_PASSWORD,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Login to get JWT token
|
|
149
|
+
const token = await bank.login();
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Method 3: Pre-Issued Token
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const bank = new AgentsBankSDK({
|
|
156
|
+
apiUrl: 'https://api.agentsbank.ai',
|
|
157
|
+
token: process.env.AGENTSBANK_AUTH_TOKEN, // JWT from previous auth
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 🛡️ Best Practices
|
|
164
|
+
|
|
165
|
+
### 1. Never Commit Credentials
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Add to .gitignore
|
|
169
|
+
echo ".env" >> .gitignore
|
|
170
|
+
echo ".env.local" >> .gitignore
|
|
171
|
+
echo ".env.*.local" >> .gitignore
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### 2. Use Environment-Specific Credentials
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# development
|
|
178
|
+
AGENTSBANK_API_URL=https://sandbox.agentsbank.ai
|
|
179
|
+
AGENTSBANK_API_KEY=sk_sandbox_...
|
|
180
|
+
|
|
181
|
+
# production
|
|
182
|
+
AGENTSBANK_API_URL=https://api.agentsbank.ai
|
|
183
|
+
AGENTSBANK_API_KEY=sk_prod_...
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 3. Implement Custom Audit Logging
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
const bank = new AgentsBankSDK({
|
|
190
|
+
apiUrl: process.env.AGENTSBANK_API_URL!,
|
|
191
|
+
apiKey: process.env.AGENTSBANK_API_KEY!,
|
|
192
|
+
auditLogger: async (event) => {
|
|
193
|
+
// Send critical events to monitoring service
|
|
194
|
+
if (event.operation === 'transaction_send') {
|
|
195
|
+
await sendToDatadog({
|
|
196
|
+
metric: 'agentsbank.transaction',
|
|
197
|
+
tags: [`status:${event.status}`],
|
|
198
|
+
value: event.amount,
|
|
199
|
+
timestamp: event.timestamp,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### 4. Validate Recipient Addresses
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
function isValidEthereumAddress(address: string): boolean {
|
|
210
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!isValidEthereumAddress(recipientAddress)) {
|
|
214
|
+
throw new Error('Invalid Ethereum address');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Proceed with transaction
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 5. Implement Rate Limiting
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import rateLimit from 'express-rate-limit';
|
|
224
|
+
|
|
225
|
+
const transactionLimiter = rateLimit({
|
|
226
|
+
windowMs: 60 * 1000, // 1 minute
|
|
227
|
+
max: 5, // Max 5 transactions per minute
|
|
228
|
+
message: 'Too many transactions, please try again later'
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
app.post('/api/send-transaction', transactionLimiter, async (req, res) => {
|
|
232
|
+
// Handle transaction
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### 6. Rotate Credentials Periodically
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
// Monthly credential rotation
|
|
240
|
+
const newApiKey = await bank.regenerateApiKey();
|
|
241
|
+
// Update AGENTSBANK_API_KEY in production environment
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### 7. Enable 2FA for High-Value Transactions
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
const approval: UserApprovalContext = {
|
|
248
|
+
userId: user.id,
|
|
249
|
+
approvedAt: new Date(),
|
|
250
|
+
reason: `2FA verified at ${new Date().toISOString()}`,
|
|
251
|
+
approvalMethod: '2fa', // Document approval method
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const tx = await bank.sendTransaction(walletId, recipient, amount, approval);
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## ⚠️ Error Handling
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
import { AxiosError } from 'axios';
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
await bank.sendTransaction(walletId, recipient, amount, approval);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (axios.isAxiosError(error)) {
|
|
268
|
+
const statusCode = error.response?.status;
|
|
269
|
+
const errorData = error.response?.data;
|
|
270
|
+
|
|
271
|
+
if (statusCode === 400) {
|
|
272
|
+
// Bad request - validation error
|
|
273
|
+
console.error('Invalid parameters:', errorData);
|
|
274
|
+
} else if (statusCode === 401) {
|
|
275
|
+
// Unauthorized - credentials invalid
|
|
276
|
+
console.error('Authentication failed');
|
|
277
|
+
} else if (statusCode === 429) {
|
|
278
|
+
// Rate limited
|
|
279
|
+
console.error('Too many requests, retry after 60s');
|
|
280
|
+
} else if (statusCode === 500) {
|
|
281
|
+
// Server error
|
|
282
|
+
console.error('AgentsBank API error');
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 🔍 Audit Logs & Compliance
|
|
292
|
+
|
|
293
|
+
All SDK operations are logged with:
|
|
294
|
+
|
|
295
|
+
- **Timestamp**: When operation occurred
|
|
296
|
+
- **Operation**: What was performed (login, wallet_create, transaction_send, etc.)
|
|
297
|
+
- **Status**: success | failed | initiated
|
|
298
|
+
- **User ID**: Who performed the operation
|
|
299
|
+
- **Wallet ID**: Which wallet was affected
|
|
300
|
+
- **Transaction ID**: For financial operations
|
|
301
|
+
- **Amount & Recipient**: For transactions (for reconciliation)
|
|
302
|
+
- **Error Details**: If operation failed
|
|
303
|
+
|
|
304
|
+
### Retention Policy
|
|
305
|
+
|
|
306
|
+
- **Production**: Retain audit logs for 7 years (financial compliance)
|
|
307
|
+
- **Development**: Retain for 90 days minimum
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## 🚀 Production Deployment Checklist
|
|
312
|
+
|
|
313
|
+
- ✅ API credentials stored in secrets manager (AWS Secrets, Azure KeyVault, etc.)
|
|
314
|
+
- ✅ Custom audit logger sending logs to monitoring service
|
|
315
|
+
- ✅ Rate limiting configured on API endpoints
|
|
316
|
+
- ✅ 2FA enabled for high-value transactions
|
|
317
|
+
- ✅ Recipient address validation implemented
|
|
318
|
+
- ✅ Transaction amount limits set per agent
|
|
319
|
+
- ✅ Error monitoring enabled (Sentry, DataDog, etc.)
|
|
320
|
+
- ✅ Automated credential rotation scheduled monthly
|
|
321
|
+
- ✅ Daily audit log reviews
|
|
322
|
+
- ✅ Incident response plan documented
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## 📞 Support
|
|
327
|
+
|
|
328
|
+
- **Documentation**: https://docs.agentsbank.ai
|
|
329
|
+
- **Dashboard**: https://dashboard.agentsbank.ai
|
|
330
|
+
- **Status Page**: https://status.agentsbank.ai
|
|
331
|
+
- **Security Issues**: security@agentsbank.ai
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
**Version**: 0.1.0
|
|
336
|
+
**Last Updated**: February 2026
|
|
337
|
+
**Node.js**: 18+
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# AgentsBank SDK - Financial Operations Skill
|
|
2
|
+
|
|
3
|
+
**Status:** Production-grade, requires explicit user invocation for financial operations
|
|
4
|
+
**Version:** 0.1.0
|
|
5
|
+
**Risk Level:** High (financial transactions)
|
|
6
|
+
**Autonomy:** ❌ Disabled for autonomous execution
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ⚠️ Security & Credential Requirements
|
|
11
|
+
|
|
12
|
+
This is a **financial transaction SDK** that requires explicit credentials and user authorization. It is **NOT autonomously invocable** for security reasons.
|
|
13
|
+
|
|
14
|
+
### Required Environment Variables
|
|
15
|
+
|
|
16
|
+
```env
|
|
17
|
+
# API Configuration (REQUIRED - NO DEFAULT)
|
|
18
|
+
AGENTSBANK_API_URL=https://api.agentsbank.ai
|
|
19
|
+
|
|
20
|
+
# Authentication (Choose ONE)
|
|
21
|
+
AGENTSBANK_API_KEY=your-api-key-here
|
|
22
|
+
# OR
|
|
23
|
+
AGENTSBANK_AGENT_USERNAME=agent_name
|
|
24
|
+
AGENTSBANK_AGENT_PASSWORD=agent_password_secret
|
|
25
|
+
|
|
26
|
+
# Optional runtime token (if pre-authenticated)
|
|
27
|
+
AGENTSBANK_AUTH_TOKEN=jwt-token-here
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- **`AGENTSBANK_API_URL`** (required): Base URL of the AgentsBank API endpoint
|
|
31
|
+
- No defaults → must be explicitly set
|
|
32
|
+
- Scope: API connectivity only
|
|
33
|
+
|
|
34
|
+
- **`AGENTSBANK_API_KEY`** OR credentials (required for auth):
|
|
35
|
+
- Primary authentication method
|
|
36
|
+
- Scope: Wallet creation, transactions, balance queries
|
|
37
|
+
- Must be rotated regularly
|
|
38
|
+
- Cannot be embedded in code
|
|
39
|
+
|
|
40
|
+
- **`AGENTSBANK_AUTH_TOKEN`** (optional): Pre-issued JWT token
|
|
41
|
+
- Use if already authenticated
|
|
42
|
+
- Shorter scope than API key
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 🔐 Credential Security Boundaries
|
|
47
|
+
|
|
48
|
+
| Operation | Credential Required | Scope | Risk |
|
|
49
|
+
|-----------|-------------------|-------|------|
|
|
50
|
+
| Wallet Management | API Key + Agent Auth | Read/Write | 🔴 High |
|
|
51
|
+
| Transactions | API Key + Agent Auth | Write only | 🔴 Critical |
|
|
52
|
+
| Balance Query | API Key | Read only | 🟡 Medium |
|
|
53
|
+
| Gas Estimation | API Key | Informational | 🟢 Low |
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 🚫 Autonomous Execution Policy
|
|
58
|
+
|
|
59
|
+
**This SDK MUST NOT be autonomously invoked by AI agents.** Financial operations require:
|
|
60
|
+
|
|
61
|
+
1. **Explicit User Confirmation** – User must authorize before any transaction
|
|
62
|
+
2. **Human Review** – Transaction details must be reviewed and approved
|
|
63
|
+
3. **Audit Trail** – All operations logged with timestamp and actor
|
|
64
|
+
4. **Rate Limiting** – API enforces per-agent limits to prevent abuse
|
|
65
|
+
|
|
66
|
+
### Enforce Constraints in Code
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// REQUIRED: Check for user authorization flag
|
|
70
|
+
if (!context.userApproval) {
|
|
71
|
+
throw new Error('Financial operations require explicit user authorization');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// REQUIRED: Log transaction intent before execution
|
|
75
|
+
logger.info('User authorized transaction', {
|
|
76
|
+
agentId: config.agentId,
|
|
77
|
+
recipient: toAddress,
|
|
78
|
+
amount: amount,
|
|
79
|
+
timestamp: new Date()
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// REQUIRED: Never retry failed financial operations without user re-approval
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 📦 Installation
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm install @agentsbank/sdk
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Setup Steps
|
|
94
|
+
|
|
95
|
+
1. **Obtain Credentials**
|
|
96
|
+
- Request API key from dashboard: https://dashboard.agentsbank.ai
|
|
97
|
+
- OR set `AGENTSBANK_AGENT_USERNAME` + `AGENTSBANK_AGENT_PASSWORD`
|
|
98
|
+
- Securely store credentials (never commit to git)
|
|
99
|
+
|
|
100
|
+
2. **Configure Environment**
|
|
101
|
+
```bash
|
|
102
|
+
cp .env.example .env
|
|
103
|
+
# Edit .env with your credentials
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
3. **Initialize SDK**
|
|
107
|
+
```typescript
|
|
108
|
+
import { AgentsBankSDK } from '@agentsbank/sdk';
|
|
109
|
+
|
|
110
|
+
const bank = new AgentsBankSDK({
|
|
111
|
+
apiUrl: process.env.AGENTSBANK_API_URL,
|
|
112
|
+
apiKey: process.env.AGENTSBANK_API_KEY,
|
|
113
|
+
// OR credentials:
|
|
114
|
+
agentUsername: process.env.AGENTSBANK_AGENT_USERNAME,
|
|
115
|
+
agentPassword: process.env.AGENTSBANK_AGENT_PASSWORD,
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 💰 Core Capabilities
|
|
122
|
+
|
|
123
|
+
### Wallet Management
|
|
124
|
+
- **`createWallet(chain, type)`** – Create new multi-chain wallet
|
|
125
|
+
- Chains: `ethereum`, `bsc`, `solana`
|
|
126
|
+
- Types: `custodial`, `non-custodial`
|
|
127
|
+
- ⚠️ Custodial wallets require setup confirmationSecurity
|
|
128
|
+
|
|
129
|
+
- **`listWallets()`** – List all wallets for agent
|
|
130
|
+
- **`getWallet(walletId)`** – Retrieve wallet details
|
|
131
|
+
- **`getBalance(walletId)`** – Query wallet balance across assets
|
|
132
|
+
|
|
133
|
+
### Transaction Operations
|
|
134
|
+
- **`sendTransaction(walletId, toAddress, amount, currency)`** – Execute transfer
|
|
135
|
+
- **Requires:** Explicit user approval before execution
|
|
136
|
+
- **Returns:** Transaction ID for tracking
|
|
137
|
+
- **Timeout:** 300s default (configurable)
|
|
138
|
+
|
|
139
|
+
- **`getTransaction(txId)`** – Retrieve transaction status
|
|
140
|
+
- **`getTransactionHistory(walletId, limit)`** – List recent transactions
|
|
141
|
+
- **`waitForConfirmation(txId)`** – Poll until confirmed or timeout
|
|
142
|
+
|
|
143
|
+
### Utilities
|
|
144
|
+
- **`estimateGas(walletId, toAddress, amount)`** – Get gas cost estimate (informational only)
|
|
145
|
+
- **`getStats(walletId, days)`** – Historical transaction metrics
|
|
146
|
+
- **`refreshToken()`** – Renew JWT token before expiry
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 🔍 Audit & Compliance
|
|
151
|
+
|
|
152
|
+
All financial operations trigger:
|
|
153
|
+
|
|
154
|
+
- ✅ Agent authentication verification
|
|
155
|
+
- ✅ Transaction signature & validation
|
|
156
|
+
- ✅ Rate limit enforcement (per-agent per-minute)
|
|
157
|
+
- ✅ Immutable audit log entry
|
|
158
|
+
- ✅ Optional webhook notification to recipient
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## ⚡ Quick Example
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { AgentsBankSDK } from '@agentsbank/sdk';
|
|
166
|
+
|
|
167
|
+
// 1. Initialize with API Key
|
|
168
|
+
const bank = new AgentsBankSDK({
|
|
169
|
+
apiUrl: 'https://api.agentsbank.ai',
|
|
170
|
+
apiKey: process.env.AGENTSBANK_API_KEY
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// 2. Get or create wallet
|
|
174
|
+
let wallet = await bank.listWallets().then(w => w[0]);
|
|
175
|
+
if (!wallet) {
|
|
176
|
+
wallet = await bank.createWallet('ethereum', 'non-custodial');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 3. Check balance
|
|
180
|
+
const balance = await bank.getBalance(wallet.wallet_id);
|
|
181
|
+
console.log('Balance:', balance);
|
|
182
|
+
|
|
183
|
+
// 4. ONLY with user approval:
|
|
184
|
+
if (userConfirmsTransaction) {
|
|
185
|
+
const tx = await bank.sendTransaction(
|
|
186
|
+
wallet.wallet_id,
|
|
187
|
+
'0xRecipient...',
|
|
188
|
+
'1.5',
|
|
189
|
+
'ETH'
|
|
190
|
+
);
|
|
191
|
+
console.log('Tx ID:', tx.tx_id);
|
|
192
|
+
|
|
193
|
+
// 5. Wait for confirmation
|
|
194
|
+
const confirmed = await bank.waitForConfirmation(tx.tx_id);
|
|
195
|
+
console.log('Status:', confirmed.status);
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## 🛑 Error Handling
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
try {
|
|
205
|
+
await bank.sendTransaction(walletId, recipient, amount, currency);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
if (error.message.includes('Invalid wallet')) {
|
|
208
|
+
console.error('Wallet not found');
|
|
209
|
+
} else if (error.message.includes('Insufficient balance')) {
|
|
210
|
+
console.error('Not enough funds');
|
|
211
|
+
} else if (error.message.includes('Rate limit exceeded')) {
|
|
212
|
+
console.error('Too many requests - try again later');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## 🚀 Best Practices
|
|
220
|
+
|
|
221
|
+
1. **Never store credentials in code** – Use environment variables only
|
|
222
|
+
2. **Rotate API keys monthly** – Call `regenerateApiKey()` and update `.env`
|
|
223
|
+
3. **Validate recipient addresses** – Always verify before transaction
|
|
224
|
+
4. **Use non-custodial wallets** for agents when possible
|
|
225
|
+
5. **Monitor transaction history** – Regular audits via `getTransactionHistory()`
|
|
226
|
+
6. **Set low rate limits** – Start with 1-5 transactions/minute per agent
|
|
227
|
+
7. **Enable webhook notifications** – Get real-time transaction confirmations
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## 📞 Support & Security Issues
|
|
232
|
+
|
|
233
|
+
- Dashboard: https://dashboard.agentsbank.ai
|
|
234
|
+
- Docs: https://docs.agentsbank.ai
|
|
235
|
+
- Report security issues: security@agentsbank.ai (not public issues)
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 📋 Compliance Notes
|
|
240
|
+
|
|
241
|
+
- **OAuth2 Support**: Via API Key or JWT bearer token
|
|
242
|
+
- **Webhook Support**: Transaction confirmations, balance updates
|
|
243
|
+
- **Sandbox Mode**: Available via `AGENTSBANK_ENVIRONMENT=sandbox` env var
|
|
244
|
+
- **Audit Trail**: All transactions immutably logged with actor, timestamp, amount
|
|
245
|
+
- **PCI DSS Notes**: Private keys never transmitted over network; stored encrypted at rest
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
**Last Updated:** February 2026
|
|
250
|
+
**Requires:** Node.js 18+, @agentsbank/sdk ^0.1.0
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentsbank/sdk",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "🔒 Secure Financial SDK for AgentsBank - Multi-chain wallet & transaction management. Requires explicit credentials and user authorization for financial operations.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"publish": "npm publish"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"ai-agents",
|
|
14
|
+
"blockchain",
|
|
15
|
+
"banking",
|
|
16
|
+
"sdk",
|
|
17
|
+
"web3",
|
|
18
|
+
"ethereum",
|
|
19
|
+
"financial-operations",
|
|
20
|
+
"security",
|
|
21
|
+
"credentials-required",
|
|
22
|
+
"user-approval-required"
|
|
23
|
+
],
|
|
24
|
+
"author": "AgentsBank.ai",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"security": {
|
|
27
|
+
"requiresCredentials": [
|
|
28
|
+
"AGENTSBANK_API_URL",
|
|
29
|
+
"AGENTSBANK_API_KEY or (AGENTSBANK_AGENT_USERNAME + AGENTSBANK_AGENT_PASSWORD)"
|
|
30
|
+
],
|
|
31
|
+
"autonomousExecutionAllowed": false,
|
|
32
|
+
"riskLevel": "high",
|
|
33
|
+
"financialOperations": true,
|
|
34
|
+
"requiresUserApproval": true
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"axios": "^1.6.5"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^20.10.6",
|
|
41
|
+
"typescript": "^5.3.3"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentsBank SDK Security Configuration
|
|
3
|
+
*
|
|
4
|
+
* Defines security constraints and validation rules for the SDK
|
|
5
|
+
* To be used during development and deployment validation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const SDK_SECURITY_CONFIG = {
|
|
9
|
+
// ============================================
|
|
10
|
+
// Required Credentials
|
|
11
|
+
// ============================================
|
|
12
|
+
requiredCredentials: [
|
|
13
|
+
'AGENTSBANK_API_URL',
|
|
14
|
+
'AGENTSBANK_API_KEY | (AGENTSBANK_AGENT_USERNAME + AGENTSBANK_AGENT_PASSWORD)'
|
|
15
|
+
],
|
|
16
|
+
|
|
17
|
+
// ============================================
|
|
18
|
+
// Risk Assessment
|
|
19
|
+
// ============================================
|
|
20
|
+
riskLevel: 'HIGH' as const, // Financial transaction platform
|
|
21
|
+
financialOperations: true,
|
|
22
|
+
autonomousExecutionAllowed: false, // CRITICAL: Must not be autonomously invocable
|
|
23
|
+
|
|
24
|
+
// ============================================
|
|
25
|
+
// Credential Scope & Constraints
|
|
26
|
+
// ============================================
|
|
27
|
+
credentialScopes: {
|
|
28
|
+
'AGENTSBANK_API_URL': {
|
|
29
|
+
required: true,
|
|
30
|
+
type: 'url' as const,
|
|
31
|
+
description: 'Base URL of AgentsBank API',
|
|
32
|
+
example: 'https://api.agentsbank.ai',
|
|
33
|
+
defaultIfMissing: null, // NO DEFAULT - must be explicit
|
|
34
|
+
},
|
|
35
|
+
'AGENTSBANK_API_KEY': {
|
|
36
|
+
required: false,
|
|
37
|
+
type: 'secret' as const,
|
|
38
|
+
description: 'API Key for authentication (recommended)',
|
|
39
|
+
example: 'sk_live_...',
|
|
40
|
+
rotationInterval: 30 * 24 * 60 * 60 * 1000, // 30 days in ms
|
|
41
|
+
defaultIfMissing: null,
|
|
42
|
+
},
|
|
43
|
+
'AGENTSBANK_AGENT_USERNAME': {
|
|
44
|
+
required: false,
|
|
45
|
+
type: 'string' as const,
|
|
46
|
+
description: 'Agent username (alternative auth method)',
|
|
47
|
+
example: 'agent_123',
|
|
48
|
+
defaultIfMissing: null,
|
|
49
|
+
},
|
|
50
|
+
'AGENTSBANK_AGENT_PASSWORD': {
|
|
51
|
+
required: false,
|
|
52
|
+
type: 'secret' as const,
|
|
53
|
+
description: 'Agent password (alternative auth method)',
|
|
54
|
+
example: 'secret_password',
|
|
55
|
+
defaultIfMissing: null,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
// ============================================
|
|
60
|
+
// Financial Operation Constraints
|
|
61
|
+
// ============================================
|
|
62
|
+
financialOperationConstraints: {
|
|
63
|
+
sendTransaction: {
|
|
64
|
+
requiresUserApprovalContext: true,
|
|
65
|
+
requiresUserId: true,
|
|
66
|
+
requiresApprovalTimestamp: true,
|
|
67
|
+
auditLoggingRequired: true,
|
|
68
|
+
atomicity: 'required' as const, // Must succeed or fail completely
|
|
69
|
+
rollbackOnFailure: true,
|
|
70
|
+
},
|
|
71
|
+
createWallet: {
|
|
72
|
+
requiresUserApprovalContext: false, // Optional for wallet creation
|
|
73
|
+
auditLoggingRequired: true,
|
|
74
|
+
typeValidation: ['custodial', 'non-custodial'],
|
|
75
|
+
},
|
|
76
|
+
estimateGas: {
|
|
77
|
+
requiresUserApprovalContext: false,
|
|
78
|
+
auditLoggingRequired: false, // Informational only
|
|
79
|
+
cacheable: true, // Can cache results for same params
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// ============================================
|
|
84
|
+
// Audit Trail Requirements
|
|
85
|
+
// ============================================
|
|
86
|
+
auditRequirements: {
|
|
87
|
+
requiredFields: [
|
|
88
|
+
'timestamp',
|
|
89
|
+
'operation',
|
|
90
|
+
'status',
|
|
91
|
+
'userId', // For financial operations
|
|
92
|
+
'walletId', // For wallet operations
|
|
93
|
+
],
|
|
94
|
+
retention: {
|
|
95
|
+
production: 7 * 365 * 24 * 60 * 60 * 1000, // 7 years
|
|
96
|
+
development: 90 * 24 * 60 * 60 * 1000, // 90 days
|
|
97
|
+
},
|
|
98
|
+
sensitiveOperations: [
|
|
99
|
+
'transaction_send',
|
|
100
|
+
'auth_login',
|
|
101
|
+
'token_refresh',
|
|
102
|
+
'wallet_create'
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
// ============================================
|
|
107
|
+
// Deployment Constraints
|
|
108
|
+
// ============================================
|
|
109
|
+
deploymentConstraints: {
|
|
110
|
+
allowedEnvironments: ['development', 'staging', 'production'],
|
|
111
|
+
productionRequirements: [
|
|
112
|
+
'Credentials stored in secrets manager',
|
|
113
|
+
'Custom audit logger configured',
|
|
114
|
+
'Rate limiting enabled',
|
|
115
|
+
'Error monitoring (Sentry, DataDog, etc.)',
|
|
116
|
+
'Credential rotation scheduled',
|
|
117
|
+
],
|
|
118
|
+
forbiddenPatternsInCode: [
|
|
119
|
+
'sk_live_', // API keys should not be in code
|
|
120
|
+
'sk_sandbox_',
|
|
121
|
+
'password:',
|
|
122
|
+
'secret:',
|
|
123
|
+
'token:',
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
// ============================================
|
|
128
|
+
// Rate Limiting Defaults
|
|
129
|
+
// ============================================
|
|
130
|
+
rateLimiting: {
|
|
131
|
+
transactionsPerMinute: 5,
|
|
132
|
+
maxAmountPerTransaction: '1000', // Max 1000 of currency
|
|
133
|
+
maxDailyAmount: '10000', // Max 10000 per day per agent
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
// ============================================
|
|
137
|
+
// Validation Functions
|
|
138
|
+
// ============================================
|
|
139
|
+
validators: {
|
|
140
|
+
isValidApiUrl: (url: string | undefined): boolean => {
|
|
141
|
+
if (!url) return false;
|
|
142
|
+
try {
|
|
143
|
+
new URL(url);
|
|
144
|
+
return url.startsWith('https://');
|
|
145
|
+
} catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
isValidApiKey: (key: string | undefined): boolean => {
|
|
151
|
+
if (!key) return false;
|
|
152
|
+
return key.startsWith('sk_') && key.length > 20;
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
isValidEthereumAddress: (address: string): boolean => {
|
|
156
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
isValidAmount: (amount: string): boolean => {
|
|
160
|
+
const num = parseFloat(amount);
|
|
161
|
+
return !isNaN(num) && num > 0;
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
} as const;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Validates SDK configuration before use
|
|
168
|
+
* Throws error if validation fails
|
|
169
|
+
*/
|
|
170
|
+
export function validateSDKConfiguration(config: Record<string, any>): void {
|
|
171
|
+
// Check required API URL
|
|
172
|
+
if (!config.apiUrl) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
'SECURITY VALIDATION FAILED: AGENTSBANK_API_URL is required. ' +
|
|
175
|
+
'See SKILL.md for credential requirements.'
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!SDK_SECURITY_CONFIG.validators.isValidApiUrl(config.apiUrl)) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
'SECURITY VALIDATION FAILED: Invalid API URL. ' +
|
|
182
|
+
'Must be HTTPS URL. Example: https://api.agentsbank.ai'
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Check at least one authentication method
|
|
187
|
+
const hasApiKey = !!config.apiKey && SDK_SECURITY_CONFIG.validators.isValidApiKey(config.apiKey);
|
|
188
|
+
const hasCredentials = config.agentUsername && config.agentPassword;
|
|
189
|
+
const hasToken = !!config.token;
|
|
190
|
+
|
|
191
|
+
if (!hasApiKey && !hasCredentials && !hasToken) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
'SECURITY VALIDATION FAILED: No authentication provided. ' +
|
|
194
|
+
'Provide one of: apiKey, (agentUsername + agentPassword), or token. ' +
|
|
195
|
+
'See SKILL.md for setup instructions.'
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Validates user approval context for financial operations
|
|
202
|
+
*/
|
|
203
|
+
export function validateUserApprovalContext(approval: any): void {
|
|
204
|
+
if (!approval) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
'SECURITY ERROR: User approval context required for financial operations. ' +
|
|
207
|
+
'Cannot execute financial operations autonomously.'
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!approval.userId) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
'SECURITY ERROR: approval.userId required. ' +
|
|
214
|
+
'Must identify human who approved this operation.'
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!approval.approvedAt || !(approval.approvedAt instanceof Date)) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
'SECURITY ERROR: approval.approvedAt required (Date object). ' +
|
|
221
|
+
'Must have timestamp of when approval was granted.'
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Check approval is recent (within last hour)
|
|
226
|
+
const ageMs = Date.now() - approval.approvedAt.getTime();
|
|
227
|
+
const maxAgeMs = 60 * 60 * 1000; // 1 hour
|
|
228
|
+
|
|
229
|
+
if (ageMs > maxAgeMs) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`SECURITY ERROR: Approval too old (${Math.round(ageMs / 1000)}s). ` +
|
|
232
|
+
'User approval must be renewed within 1 hour of transaction.'
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Validates financial operation parameters
|
|
239
|
+
*/
|
|
240
|
+
export function validateFinancialOperationParams(
|
|
241
|
+
walletId: string,
|
|
242
|
+
toAddress: string,
|
|
243
|
+
amount: string
|
|
244
|
+
): void {
|
|
245
|
+
if (!walletId) {
|
|
246
|
+
throw new Error('walletId is required');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!toAddress) {
|
|
250
|
+
throw new Error('toAddress is required');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (!SDK_SECURITY_CONFIG.validators.isValidEthereumAddress(toAddress)) {
|
|
254
|
+
throw new Error(`Invalid Ethereum address: ${toAddress}`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (!amount) {
|
|
258
|
+
throw new Error('amount is required');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!SDK_SECURITY_CONFIG.validators.isValidAmount(amount)) {
|
|
262
|
+
throw new Error(`Invalid amount: ${amount}. Must be a positive number.`);
|
|
263
|
+
}
|
|
264
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"outDir": "../../dist/sdk",
|
|
7
|
+
"rootDir": "../../src/sdk",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"moduleResolution": "bundler"
|
|
13
|
+
},
|
|
14
|
+
"include": ["../../src/sdk"],
|
|
15
|
+
"exclude": ["../../dist"]
|
|
16
|
+
}
|