# Tasks: 凭证管理模块 (Credential Manager)

**Input**: Design documents from `/Users/he/projects/binance-api/specs/001-credential-manager/`
**Prerequisites**: plan.md ✅, research.md ✅, data-model.md ✅, contracts/ ✅

## Execution Flow (main)
```
1. Load plan.md from feature directory ✅
   → Extract: TypeScript 5.1.0, Node.js 18.12+, tweetnacl, ethers, Jest
   → Structure: src/core/credential-manager/ (集成优先架构)
2. Load design documents:
   → data-model.md: Platform, Account, Signer, ConfigLoader entities
   → contracts/: credential-manager.ts, pacifica-signer.ts
   → research.md: Ed25519签名库、文件监听、智能识别、统一接口
3. Generate tasks by category ✅:
   → Setup: 项目结构、依赖安装、TypeScript配置
   → Tests: 契约测试、集成测试、性能测试
   → Core: 类型定义、凭证加载、签名策略
   → Integration: 平台适配器、文件监听、性能验证
   → Polish: 单元测试、错误处理、文档
4. Apply task rules ✅:
   → 不同文件 = [P] 并行执行
   → 测试先行 (TDD)
   → 类型定义先于实现
5. Number tasks sequentially (T001-T036) ✅
6. Generate dependency graph ✅
7. Create parallel execution examples ✅
```

## Format: `[ID] [P?] Description`
- **[P]**: Can run in parallel (different files, no dependencies)
- Include exact file paths in descriptions

## Path Conventions
- **集成架构**: `src/core/credential-manager/` in existing codebase
- **测试**: `tests/` (contract/, integration/, unit/, performance/)
- **类型**: `src/types/credential.ts`
- **示例**: `examples/`

## Phase 3.1: Setup
- [x] T001 Create credential manager directory structure in src/core/credential-manager/
- [x] T002 Install additional dependencies: tweetnacl for Ed25519 signatures
- [x] T003 [P] Configure TypeScript paths for @/core/credential-manager imports
- [x] T004 [P] Setup Jest test environment for credential manager module

## Phase 3.2: Tests First (TDD) ⚠️ MUST COMPLETE BEFORE 3.3
**CRITICAL: These tests MUST be written and MUST FAIL before ANY implementation**
- [x] T005 [P] Contract test for ICredentialManager interface in tests/contract/credential-manager.contract.test.ts
- [x] T006 [P] Contract test for IPacificaSigner interface in tests/contract/pacifica-signer.contract.test.ts
- [x] T007 [P] Contract test for IBinanceSigner interface in tests/contract/binance-signer.contract.test.ts
- [x] T008 [P] Contract test for IAsterSigner interface in tests/contract/aster-signer.contract.test.ts
- [x] T009 [P] Contract test for IConfigLoader interface in tests/contract/config-loader.contract.test.ts
- [x] T010 [P] Integration test for hot config reload in tests/integration/hot-reload.integration.test.ts
- [x] T011 [P] Integration test for multi-platform signing in tests/integration/multi-platform-signing.integration.test.ts
- [x] T012 [P] Integration test for performance requirements in tests/integration/performance.integration.test.ts

## Phase 3.3: Core Type Definitions (ONLY after tests are failing)
- [x] T013 [P] Platform and SignatureType enums in src/types/credential.ts
- [x] T014 [P] Credentials type definitions in src/types/credential.ts
- [x] T015 [P] Account interface definition in src/types/credential.ts
- [x] T016 [P] Signer interfaces in src/types/credential.ts
- [x] T017 [P] ConfigLoader interfaces in src/types/credential.ts
- [x] T018 [P] Error types and result interfaces in src/types/credential.ts

## Phase 3.4: Core Implementation
- [x] T019 Platform detection utility in src/core/credential-manager/PlatformDetector.ts
- [x] T020 Base credential validator in src/core/credential-manager/CredentialValidator.ts
- [x] T021 [P] Pacifica signer implementation in src/core/credential-manager/signers/PacificaSigner.ts
- [x] T022 [P] Binance signer implementation in src/core/credential-manager/signers/BinanceSigner.ts
- [x] T023 [P] Aster signer implementation in src/core/credential-manager/signers/AsterSigner.ts
- [x] T024 Signer factory in src/core/credential-manager/SignerFactory.ts
- [x] T025 Config file loader with JSON/YAML support in src/core/credential-manager/ConfigLoader.ts
- [x] T026 File watcher with debouncing in src/core/credential-manager/FileWatcher.ts
- [x] T027 Main credential manager implementation in src/core/credential-manager/CredentialManager.ts

## Phase 3.5: Integration & Exports
- [x] T028 Module index with public exports in src/core/credential-manager/index.ts
- [x] T029 Configuration schema validation in src/core/credential-manager/ConfigValidator.ts
- [x] T030 Error handling and logging integration in src/core/credential-manager/ErrorHandler.ts

## Phase 3.6: Polish
- [ ] T031 [P] Unit tests for platform detection in tests/unit/platform-detector.unit.test.ts
- [ ] T032 [P] Unit tests for credential validation in tests/unit/credential-validator.unit.test.ts
- [ ] T033 [P] Unit tests for file watching in tests/unit/file-watcher.unit.test.ts
- [ ] T034 [P] Performance benchmarks (<100ms reload, <50ms signing) in tests/performance/benchmark.test.ts
- [ ] T035 [P] Example configuration files in examples/credential-config.json and examples/credential-config.yaml
- [ ] T036 Update main project exports to include credential manager

## Dependencies
- Setup (T001-T004) before tests (T005-T012)
- Tests (T005-T012) before type definitions (T013-T018)
- Type definitions (T013-T018) before implementations (T019-T027)
- Platform detection (T019) blocks signer factory (T024)
- Credential validator (T020) blocks config loader (T025)
- File watcher (T026) blocks credential manager (T027)
- All signers (T021-T023) before signer factory (T024)
- Signer factory (T024) blocks credential manager (T027)
- Config loader (T025) blocks credential manager (T027)
- Core implementation before integration (T028-T030)
- Integration before polish (T031-T036)

## Parallel Example
```
# Launch T005-T012 together:
Task: "Contract test for ICredentialManager interface in tests/contract/credential-manager.contract.test.ts"
Task: "Contract test for IPacificaSigner interface in tests/contract/pacifica-signer.contract.test.ts"
Task: "Contract test for IBinanceSigner interface in tests/contract/binance-signer.contract.test.ts"
Task: "Contract test for IAsterSigner interface in tests/contract/aster-signer.contract.test.ts"
Task: "Contract test for IConfigLoader interface in tests/contract/config-loader.contract.test.ts"
Task: "Integration test for hot config reload in tests/integration/hot-reload.integration.test.ts"
Task: "Integration test for multi-platform signing in tests/integration/multi-platform-signing.integration.test.ts"
Task: "Integration test for performance requirements in tests/integration/performance.integration.test.ts"

# Launch T013-T018 together:
Task: "Platform and SignatureType enums in src/types/credential.ts"
Task: "Credentials type definitions in src/types/credential.ts"
Task: "Account interface definition in src/types/credential.ts"
Task: "Signer interfaces in src/types/credential.ts"
Task: "ConfigLoader interfaces in src/types/credential.ts"
Task: "Error types and result interfaces in src/types/credential.ts"

# Launch T021-T023 together (after T019-T020 complete):
Task: "Pacifica signer implementation in src/core/credential-manager/signers/PacificaSigner.ts"
Task: "Binance signer implementation in src/core/credential-manager/signers/BinanceSigner.ts"
Task: "Aster signer implementation in src/core/credential-manager/signers/AsterSigner.ts"
```

## Notes
- [P] tasks = different files, no dependencies between them
- Verify contract tests fail before implementing interfaces
- 集成优先架构: direct implementation in existing codebase structure
- Performance targets: hot reload <100ms, signing <50ms
- Integration-first: direct implementation in existing codebase structure
- All file paths use absolute paths from repository root

## Task Generation Rules Applied

1. **From Contracts**:
   - credential-manager.ts → contract test task T005 [P]
   - pacifica-signer.ts → contract test task T006 [P]
   - Additional signers → contract test tasks T007-T008 [P]
   - ConfigLoader → contract test task T009 [P]

2. **From Data Model**:
   - Platform entity → enum definition task T013 [P]
   - Account entity → interface definition task T015 [P]
   - Credentials → type definition task T014 [P]
   - Signer → interface definition task T016 [P]
   - ConfigLoader → interface definition task T017 [P]

3. **From User Stories** (quickstart.md):
   - Hot reload scenario → integration test T010 [P]
   - Multi-platform signing → integration test T011 [P]
   - Performance requirements → integration test T012 [P]

4. **Ordering Applied**:
   - Setup → Tests → Types → Implementation → Integration → Polish
   - Dependencies respected (platform detection before signers, etc.)

## Validation Checklist ✅

- [x] All contracts have corresponding tests (T005-T009)
- [x] All entities have type definition tasks (T013-T017)
- [x] All tests come before implementation (T005-T012 before T019-T027)
- [x] Parallel tasks truly independent (different files)
- [x] Each task specifies exact file path
- [x] No task modifies same file as another [P] task
- [x] Performance requirements addressed (T012, T034)
- [x] Integration-first architecture maintained
- [x] TDD approach enforced (tests must fail before implementation)

## Success Criteria
- All contract tests pass after implementation
- Hot reload completes within 100ms
- Signing operations complete within 50ms
- Multi-platform support for Pacifica (Ed25519), Aster (EIP-191), Binance (HMAC-SHA256)
- File watching works without manual restarts
- Zero breaking changes to existing codebase
- Memory usage stays under 50MB
- Support for 50+ concurrent accounts