mcpField
B
binance-auth

binance-auth

github.com/ticruz38安全046 次安装37 周前更新
代码仓库

关于 binance-auth

binance-auth 是用于管理 Binance API 凭据并检查账户访问状态的 Skill,支持生产环境和 testnet 配置,并提供加密存储、权限、连接及余额检查。

主要功能

  1. 01加密存储 API 凭据
  2. 02生产环境与 testnet 配置
  3. 03权限与连接检查
  4. 04查询账户余额
  5. 05管理多个账户配置

适用场景

  1. 01存储多个 Binance 账户凭据
  2. 02检查 API 密钥的交易权限
  3. 03验证账户连接状态与余额

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ticruz38/skills --skill binance-auth

安装后在 Claude Code 中输入/binance-auth确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

.gitignore
package-lock.json
package.json
tsconfig.json
src/
cli.ts
index.ts

详细介绍

Binance 身份验证 Skill

用于 Binance 加密货币交易所 API 的身份验证 Skill。基于 auth-provider 构建,用于安全地存储和管理 API 密钥。支持 Binance 生产环境和测试网环境。

功能

  • 安全存储 API 密钥:加密存储 API 密钥和密钥
  • 环境切换:在生产环境和测试网之间无缝切换
  • 权限验证:验证 API 密钥权限(现货、保证金、期货)
  • 健康检查:验证 API 连通性和密钥状态
  • 多配置文件:支持多个 Binance 账户
  • 余额查询:将账户余额检查作为健康验证的一部分

安装

npm install
npm run build

环境变量

无需环境变量——通过 CLI 按配置文件配置 API 密钥。

CLI 用法

查看状态
node dist/cli.js status
连接 API 密钥
# Production environment
node dist/cli.js connect prod \
  --key YOUR_API_KEY \
  --secret YOUR_API_SECRET \
  --env production

# Testnet environment
node dist/cli.js connect test \
  --key YOUR_API_KEY \
  --secret YOUR_API_SECRET \
  --env testnet
健康检查
# Check specific profile
node dist/cli.js health prod

# Check all profiles
node dist/cli.js health
列出配置文件
node dist/cli.js list
获取余额
node dist/cli.js balance prod
验证权限
node dist/cli.js validate prod
断开连接
node dist/cli.js disconnect prod

JavaScript/TypeScript API

初始化客户端
import { BinanceAuthClient, getBinanceAuth } from '@openclaw/binance-auth';

// Create client for specific profile
const binance = new BinanceAuthClient('prod');

// Or use singleton
const binance = getBinanceAuth('prod');
连接 API 密钥
const result = await binance.connect({
  apiKey: 'your-api-key',
  apiSecret: 'your-api-secret',
  environment: 'production', // or 'testnet'
});

if (result.success) {
  console.log('Connected! Permissions:', result.permissions);
}
检查连接
const isConnected = await binance.isConnected();
console.log('Connected:', isConnected);
获取 API 凭据
const credentials = await binance.getCredentials();
if (credentials) {
  console.log('API Key:', credentials.apiKey);
  console.log('Environment:', credentials.environment);
}
健康检查
const health = await binance.healthCheck();
console.log('Status:', health.status); // 'healthy' | 'unhealthy'
console.log('Message:', health.message);
获取账户余额
const balance = await binance.getBalance();
if (balance) {
  console.log('Total BTC:', balance.totalBTC);
  console.log('Balances:', balance.balances);
  console.log('Permissions:', balance.permissions);
}
验证权限
const validation = await binance.validatePermissions();
console.log('Valid:', validation.valid);
console.log('Can Trade:', validation.canTrade);
console.log('Can Withdraw:', validation.canWithdraw);
console.log('Permissions:', validation.permissions);
断开连接
const disconnected = await binance.disconnect();
console.log('Disconnected:', disconnected);

API 权限

Binance API 密钥可以具有以下权限:

  • SPOT - 现货交易
  • MARGIN - 保证金交易
  • FUTURES - 期货交易
  • DELIVERY - 币本位期货
  • PERM - 永久 API 密钥
  • IP_RESTRICTED - IP 限制访问

环境

生产环境
  • API 基础地址:https://api.binance.com
  • 使用真实资金进行真实交易
  • 需要已验证的 Binance 账户
测试网

存储位置

凭据存储在 auth-provider 数据库中:

~/.openclaw/skills/auth-provider/credentials.db

API 密钥使用 AES-256 加密。

TypeScript 类型

interface BinanceCredentials {
  apiKey: string;
  apiSecret: string;
  environment: 'production' | 'testnet';
  permissions?: string[];
}

interface BinanceConnectionResult {
  success: boolean;
  permissions?: string[];
  canTrade?: boolean;
  canWithdraw?: boolean;
  error?: string;
}

interface BinanceBalance {
  totalBTC: string;
  balances: Array<{
    asset: string;
    free: string;
    locked: string;
  }>;
  permissions: string[];
}

interface BinanceValidationResult {
  valid: boolean;
  permissions: string[];
  canTrade: boolean;
  canWithdraw: boolean;
}

错误处理

try {
  await binance.connect({ apiKey, apiSecret, environment: 'production' });
} catch (error) {
  if (error.message.includes('Invalid API key')) {
    // API key format is invalid
  } else if (error.message.includes('API key validation failed')) {
    // Key rejected by Binance
  }
}

安全须知

  • API 密钥存储后绝不会暴露
  • 所有 API 调用均使用 HMAC-SHA256 签名
  • 数据库文件权限为 0600(仅用户可读写)
  • 为提高安全性,请对 Binance API 密钥设置 IP 限制
  • 切勿将 API 凭据提交到版本控制系统

测试

# Type checking
npm run typecheck

# Build
npm run build

# Run CLI
npm run cli -- status

依赖项

  • @openclaw/auth-provider - 安全凭据存储
  • 使用 crypto 模块生成 HMAC-SHA256 签名

评论

支持 Markdown