特性:001-credential-manager 日期:2025-09-28 状态:Phase 0 完成
本次调研旨在解决凭证管理模块实现中的关键技术选择,重点关注Ed25519签名库、文件热加载机制、智能平台识别算法以及统一签名接口设计模式。
调研 Ed25519签名库 在 TypeScript 的最佳做法
ed25519
import { ed25519 } from '@noble/ed25519';
// 密钥生成和验证
const privateKey = ed25519.utils.randomPrivateKey();
const publicKey = await ed25519.getPublicKey(privateKey);
// Pacifica订单签名格式
const signMessage = async (message: Uint8Array, privateKey: Uint8Array) => {
const signature = await ed25519.sign(message, privateKey);
return Buffer.from(signature).toString('base64');
};
收集 文件监听 在 Node.js 的最佳实践
import fs from 'fs';
import { debounce } from 'lodash';
class ConfigWatcher {
private watcher?: fs.FSWatcher;
watch(filePath: string, callback: () => void) {
// 防抖动:避免短时间内多次触发
const debouncedCallback = debounce(callback, 100);
this.watcher = fs.watch(filePath, (eventType) => {
if (eventType === 'change') {
debouncedCallback();
}
});
}
close() {
this.watcher?.close();
}
}
调研 智能识别算法 在 多平台系统 的设计模式
interface PlatformDetector {
detect(credential: any): Platform | null;
confidence: number; // 识别置信度
}
class PacificaDetector implements PlatformDetector {
confidence = 0.9;
detect(credential: any): Platform | null {
// 检查Ed25519私钥格式 (64字符十六进制)
if (credential.privateKey &&
typeof credential.privateKey === 'string' &&
/^[0-9a-fA-F]{64}$/.test(credential.privateKey)) {
return Platform.PACIFICA;
}
return null;
}
}
class BinanceDetector implements PlatformDetector {
confidence = 0.95;
detect(credential: any): Platform | null {
// 检查API密钥对格式
if (credential.apiKey && credential.secretKey &&
typeof credential.apiKey === 'string' &&
typeof credential.secretKey === 'string') {
return Platform.BINANCE;
}
return null;
}
}
收集 统一接口设计 在 签名服务 的最佳实践
// 统一签名接口
interface SignerStrategy {
sign(message: Uint8Array, accountId: string): Promise<string>;
verify(message: Uint8Array, signature: string, publicKey: string): Promise<boolean>;
}
// 平台特定实现
class PacificaSignerStrategy implements SignerStrategy {
async sign(message: Uint8Array, accountId: string): Promise<string> {
const credential = this.getCredential(accountId);
return await ed25519.sign(message, credential.privateKey);
}
}
// 统一签名器
class UnifiedSigner {
private strategies = new Map<Platform, SignerStrategy>();
register(platform: Platform, strategy: SignerStrategy) {
this.strategies.set(platform, strategy);
}
async sign(accountId: string, message: Uint8Array): Promise<string> {
const platform = this.detectPlatform(accountId);
const strategy = this.strategies.get(platform);
return await strategy.sign(message, accountId);
}
}
决策:凭证管理直接集成到现有交易系统代码库 理由:符合宪章v1.4.0集成优先原则,专注实际业务集成而非抽象复用 备选:独立npm包(过度抽象,增加集成复杂度)
决策:使用Node.js内置fs.watch + 防抖动 理由:满足性能要求,无额外依赖,跨平台兼容 备选:第三方库(增加依赖)、轮询(性能差)
决策:专注于热加载、智能识别、统一签名 理由:用户明确要求简化,降低初始复杂度 备选:复杂的凭证管理系统(超出需求)
决策:使用@noble/ed25519
理由:纯TypeScript、性能优秀、无原生依赖
备选:sodium-native(编译复杂)、node:crypto(API限制)
文件监听兼容性
平台识别准确性
性能要求
库兼容性
所有技术调研已完成,关键决策如下:
ed25519
库,性能和安全性满足要求技术栈确定,无NEEDS CLARIFICATION项,可以进入Phase 1设计阶段。
Phase 0 状态:✅ 完成 下一阶段:Phase 1 - 设计与契约