存储各平台的账户凭据信息,支持不同平台的凭据格式。
interface PlatformAccount {
accountId: string; // 账户唯一标识
platformId: 'pacifica' | 'aster' | 'binance' | 'okx';
alias?: string; // 账户别名
// 加密存储的凭据(根据平台不同)
credentials: {
// Pacifica: Ed25519 私钥
privateKey?: string; // base58 编码
// Aster: 以太坊私钥 + 签名者地址
ethPrivateKey?: string; // 0x 开头
signerAddress?: string; // 0x 开头
// Binance/OKX: API 凭据
apiKey?: string;
secretKey?: string;
passphrase?: string; // OKX 需要
};
// 状态信息
status: 'active' | 'inactive';
environment: 'development' | 'production';
// 使用统计
usage: {
totalSigns: number;
lastSignAt?: Date;
errorCount: number;
};
createdAt: Date;
updatedAt: Date;
}
为每个平台实现特定的签名算法。
interface SignatureAdapter {
platformId: string; // 平台标识
algorithm: 'ed25519' | 'eip191' | 'hmac-sha256';
// 签名方法
sign(data: any, credentials: any): Promise<SignatureResult>;
// 验证方法(可选)
verify?(signature: string, data: any, publicKey: string): Promise<boolean>;
}
interface SignatureResult {
signature: string;
algorithm: string;
encoding: string; // base58, hex, base64
publicKey?: string; // 如果适用
metadata?: Record<string, any>;
}
管理配置文件的加载和热重载。
interface ConfigManager {
configPath: string;
lastLoaded: Date;
// 加载的账户数据
accounts: Map<string, PlatformAccount>; // key: platformId:accountId
// 配置操作
loadConfig(): Promise<void>;
reloadConfig(): Promise<void>;
watchConfig(): void; // 监控文件变化
// 账户查询
getAccount(platformId: string, accountId: string): PlatformAccount | null;
getAccountsByPlatform(platformId: string): PlatformAccount[];
}
{
"pacifica": [
{
"accountId": "pac-main-001",
"alias": "Pacifica主账户",
"privateKey": "base58_encoded_private_key",
"environment": "production"
}
],
"aster": [
{
"accountId": "ast-hedge-001",
"alias": "Aster对冲账户",
"ethPrivateKey": "0x1234567890abcdef...",
"signerAddress": "0x742d35Cc...",
"environment": "production"
}
],
"binance": [
{
"accountId": "bn-spot-001",
"alias": "Binance现货账户",
"apiKey": "your_api_key",
"secretKey": "your_secret_key",
"environment": "production"
}
],
"okx": [
{
"accountId": "okx-perp-001",
"alias": "OKX永续账户",
"apiKey": "your_api_key",
"secretKey": "your_secret_key",
"passphrase": "your_passphrase",
"environment": "production"
}
]
}
interface CredentialManager {
// 签名服务(核心功能)
sign(platformId: string, accountId: string, data: any): Promise<SignatureResult>;
// 账户查询
getAccount(platformId: string, accountId: string): PlatformAccount | null;
listAccounts(platformId?: string): PlatformAccount[];
// 配置管理
reloadConfig(): Promise<void>;
getStatus(): ConfigStatus;
}
interface ConfigStatus {
configPath: string;
lastLoaded: Date;
accountCount: number;
platformCount: number;
isWatching: boolean;
}
accountId
: 3-50字符,字母数字和连字符platformId
: 必须是 'pacifica' | 'aster' | 'binance' | 'okx'设计完成时间: 2025-09-28 实体总数: 3个核心实体(简化) 关系复杂度: 简单(单一职责) 下一步: 简化 API 契约文档