# Tasks: 多平台对冲账号管理模块

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

## Execution Flow (main)
```
1. Load plan.md from feature directory ✅
   → Extract: TypeScript/Node.js, tweetnacl, js-sha3, crypto, AccountRegistry pattern
   → Structure: src/core/credential-manager/ (AccountRegistry简化模式)
2. Load design documents:
   → data-model.md: HedgingAccountPool, AccountStatus, module integration entities
   → contracts/: credential-manager.ts (ICredentialManager), pacifica-signer.ts
   → research.md: @noble/ed25519, file watching, platform detection decisions
   → quickstart.md: basic usage, signing, hot-reload, multi-platform scenarios
3. Generate tasks by category ✅:
   → Setup: TypeScript project, dependencies, AccountRegistry structure
   → Tests: contract tests (TDD), integration tests, performance tests
   → Core: types, hedging models, signer strategies, unified interface
   → Integration: file watching, platform detection, module interaction
   → Polish: unit tests, performance verification, examples
4. Apply task rules ✅:
   → Different files = [P] parallel execution
   → Tests before implementation (TDD)
   → AccountRegistry simplification pattern (no over-design)
   → Module interaction capabilities for trading system
5. Number tasks sequentially (T001-T039) ✅
6. Generate dependency graph with hedging priorities ✅
7. Create parallel execution examples ✅
8. SUCCESS: Tasks ready for hedging account management implementation
```

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

## Path Conventions
- **AccountRegistry模式**: `src/core/credential-manager/` integrated into existing structure
- **测试**: `tests/` (contract/, integration/, unit/, performance/) following existing patterns
- **类型**: `src/types/credential.ts` and `src/types/platformAdapter.ts`
- **示例**: `src/examples/` for hedging usage examples

## Phase 3.1: Setup
- [x] T001 Create credential-manager directory structure in src/core/credential-manager/
- [x] T002 Install hedging-focused dependencies: @noble/ed25519, js-sha3, crypto, chokidar
- [x] T003 [P] Configure TypeScript strict mode and @/ path aliases for credential manager
- [x] T004 [P] Setup ESLint rules and Prettier formatting for credential manager module
- [x] T005 Create modular Jest config: tests/jest.config.credential-manager.js

## Phase 3.2: Tests First (TDD) ⚠️ MUST COMPLETE BEFORE 3.3
**CRITICAL: These tests MUST be written and MUST FAIL before ANY implementation**
- [x] T006 [P] Contract test for ICredentialManager interface in tests/contract/credential-manager.contract.test.ts
- [x] T007 [P] Contract test for IPacificaSigner interface in tests/contract/pacifica-signer.contract.test.ts
- [x] T008 [P] Contract test for signer strategies in tests/contract/signer-strategies.contract.test.ts
- [x] T009 [P] Contract test for AccountRegistry in tests/contract/account-registry.contract.test.ts
- [x] T010 [P] Contract test for HedgingAccountPool in tests/contract/hedging-account-pool.contract.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 hot-reload config in tests/integration/hot-reload.integration.test.ts
- [x] T013 [P] Integration test for hedging workflows in tests/integration/hedging-workflows.integration.test.ts
- [x] T014 [P] Performance test for <50ms signing in tests/performance/signing-performance.test.ts
- [x] T015 [P] Performance test for <100ms hot-reload in tests/performance.test.ts

## Phase 3.3: Core Types and Models (ONLY after tests are failing)
- [x] T016 [P] Create credential types in src/types/credential.ts based on data-model.md
- [x] T017 [P] Create platform adapter types in src/types/platformAdapter.ts
- [x] T018 [P] Implement AccountRegistry in src/core/credential-manager/AccountRegistry.ts using simplified pattern
- [x] T019 [P] Implement HedgingAccountPool model in src/core/credential-manager/HedgingAccountPool.ts
- [x] T020 [P] Implement AccountStatus model in src/core/credential-manager/AccountStatus.ts

## Phase 3.4: Signer Strategies (Platform-specific implementations)
- [x] T021 [P] Implement PacificaSigner strategy in src/core/credential-manager/signers/PacificaSigner.ts
- [x] T022 [P] Implement AsterSigner strategy in src/core/credential-manager/signers/AsterSigner.ts
- [x] T023 [P] Implement BinanceSigner strategy in src/core/credential-manager/signers/BinanceSigner.ts
- [x] T024 [P] Implement platform detection utils in src/core/credential-manager/PlatformDetector.ts
- [x] T025 [P] Implement config validator in src/core/credential-manager/ConfigValidator.ts

## Phase 3.5: Core Services (Unified interfaces)
- [x] T026 Implement UnifiedSigner service in src/core/credential-manager/UnifiedSigner.ts
- [x] T027 Implement ConfigLoader with file watching in src/core/credential-manager/ConfigLoader.ts
- [x] T028 Main CredentialManager implementation in src/core/credential-manager/CredentialManager.ts
- [x] T029 CredentialManagerFactory implementation in src/core/credential-manager/CredentialManagerFactory.ts

## Phase 3.6: Module Integration (Trading system interaction)
- [x] T030 Implement TradingModuleIntegration interface in src/core/credential-manager/TradingIntegration.ts
- [x] T031 Implement ModuleEventBus for cross-module communication in src/core/credential-manager/EventBus.ts
- [x] T032 Module index with public exports in src/core/credential-manager/index.ts
- [x] T033 Error handling and CredentialManagerError classes in src/core/credential-manager/ErrorHandler.ts

## Phase 3.7: Polish and Examples
- [x] T034 [P] Unit tests for all signer strategies in tests/unit/signers/
- [x] T035 [P] Unit tests for managers and utilities in tests/unit/managers/
- [x] T036 [P] Create hedging usage examples in src/examples/credential-manager-examples.ts
- [x] T037 [P] Create configuration examples in config/accounts.example.json
- [x] T038 Performance verification and benchmarks per quickstart.md
- [x] T039 Update main project exports to include credential manager

## Dependencies
- Setup (T001-T005) before tests (T006-T015)
- Tests (T006-T015) before types/models (T016-T020)
- Types/models (T016-T020) before signer strategies (T021-T025)
- Signer strategies (T021-T025) before core services (T026-T029)
- Core services (T026-T029) before module integration (T030-T033)
- Module integration (T030-T033) before polish (T034-T039)
- T018 (AccountRegistry) blocks T028 (CredentialManager)
- T019 (HedgingAccountPool) blocks T030 (TradingIntegration)
- T024 (PlatformDetector) blocks T026 (UnifiedSigner)
- T021-T023 (All signers) block T026 (UnifiedSigner)
- T027 (ConfigLoader) blocks T028 (CredentialManager)
- T028 (CredentialManager) blocks T029 (CredentialManagerFactory)

## Parallel Example
```bash
# Launch T006-T010 together (different contract test files):
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 signer strategies in tests/contract/signer-strategies.contract.test.ts"
Task: "Contract test for AccountRegistry in tests/contract/account-registry.contract.test.ts"
Task: "Contract test for HedgingAccountPool in tests/contract/hedging-account-pool.contract.test.ts"

# Launch T016-T020 together (different type/model files):
Task: "Create credential types in src/types/credential.ts based on data-model.md"
Task: "Create platform adapter types in src/types/platformAdapter.ts"
Task: "Implement AccountRegistry in src/core/credential-manager/AccountRegistry.ts using simplified pattern"
Task: "Implement HedgingAccountPool model in src/core/credential-manager/HedgingAccountPool.ts"
Task: "Implement AccountStatus model in src/core/credential-manager/AccountStatus.ts"

# Launch T021-T025 together (different signer strategy files):
Task: "Implement PacificaSigner strategy in src/core/credential-manager/signers/PacificaSigner.ts"
Task: "Implement AsterSigner strategy in src/core/credential-manager/signers/AsterSigner.ts"
Task: "Implement BinanceSigner strategy in src/core/credential-manager/signers/BinanceSigner.ts"
Task: "Implement platform detection utils in src/core/credential-manager/PlatformDetector.ts"
Task: "Implement config validator in src/core/credential-manager/ConfigValidator.ts"
```

## Notes
- [P] tasks target different files with no dependencies - safe for parallel execution
- All contract tests MUST fail initially to ensure TDD compliance
- AccountRegistry simplification pattern enforced per constitution v1.6.0
- Performance targets: hot-reload <100ms, signing <50ms, 100+ concurrent accounts
- Hedging focus: account pools, load balancing, Delta-neutral strategy support
- Module interaction: event bus and service interfaces for trading system integration
- All file paths specify exact locations in src/core/credential-manager/ structure

## Task Generation Rules Applied
*Applied during main() execution*

1. **From Contracts**:
   - credential-manager.ts → ICredentialManager contract test [P]
   - pacifica-signer.ts → IPacificaSigner contract test [P]
   - Signer strategies → unified contract test [P]
   - AccountRegistry → dedicated contract test [P]
   - HedgingAccountPool → dedicated contract test [P]

2. **From Data Model (data-model.md)**:
   - HedgingAccountPool entity → model creation task [P]
   - AccountStatus entity → model creation task [P]
   - AccountRegistry → simplified pattern implementation [P]
   - TradingModuleIntegration → service interface task
   - ModuleEventBus → communication interface task

3. **From User Stories (quickstart.md)**:
   - Multi-platform signing example → integration test [P]
   - Hot-reload example → integration test [P]
   - Hedging workflows → integration test [P]
   - Performance test → performance test [P]

4. **Ordering Applied**:
   - Setup → Tests → Types/Models → Signers → Services → Integration → Polish
   - TDD enforced: tests before implementation
   - Dependencies preserved: AccountRegistry before CredentialManager

## Validation Checklist
*GATE: Checked before completion*

- [x] All contracts have corresponding tests (T006-T010)
- [x] All major entities have model tasks (T018-T020, T026-T029)
- [x] All tests come before implementation (T006-T015 before T016+)
- [x] Parallel tasks truly independent (different files, no dependencies)
- [x] Each task specifies exact file path in src/core/credential-manager/ structure
- [x] No task modifies same file as another [P] task
- [x] AccountRegistry simplification pattern enforced per constitution
- [x] Performance requirements specified (<100ms hot-reload, <50ms signing)
- [x] Hedging business requirements addressed (account pools, Delta-neutral support)
- [x] Module interaction capabilities included (trading system integration)

## Success Criteria
- All contract tests pass after implementation
- Hot-reload configuration completes within 100ms
- Signing operations complete within 50ms for all platforms
- Multi-platform support: Pacifica (Ed25519), Aster (EIP-191), Binance (HMAC-SHA256)
- File watching works without manual restarts
- Zero breaking changes to existing codebase structure
- AccountRegistry simplification pattern successfully implemented
- Hedging account pools support load balancing and failover
- Module interaction interfaces enable trading system integration
- Support for 100+ concurrent accounts in hedging operations