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

**Input**: Design documents from `/specs/001-credential-manager/`
**Prerequisites**: plan.md (required), research.md, data-model.md, contracts/

## Execution Flow (main)
```
1. Load plan.md from feature directory
   → Extract: TypeScript 5.1+, @noble/ed25519, Node.js fs.watch, strategy pattern
   → Structure: libs/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: 库结构、依赖安装、@noble/ed25519
   → Tests: 契约测试、集成测试、性能测试
   → Core: 凭证管理器、平台检测器、签名器
   → Integration: 文件监听、配置加载、错误处理
   → Polish: 单元测试、性能验证、快速开始文档
4. Apply TDD rules:
   → 契约测试先行（必须失败）
   → 不同文件标记[P]并行
   → 签名操作<50ms、文件加载<100ms性能要求
5. Number tasks sequentially (T001, T002...)
6. Validate completeness: 所有契约有测试、所有实体有模型
```

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

## Path Conventions
- **独立库**: `libs/credential-manager/` at repository root
- **测试**: `libs/credential-manager/tests/` (contract/, integration/, unit/)
- **源码**: `libs/credential-manager/src/` (core/, platforms/, loaders/)

## Phase 3.1: Setup
- [x] T001 Create libs/credential-manager/ directory structure per implementation plan
- [x] T002 Initialize TypeScript library project with package.json in libs/credential-manager/
- [x] T003 [P] Install @noble/ed25519 dependency in libs/credential-manager/package.json
- [x] T004 [P] Configure TypeScript config in libs/credential-manager/tsconfig.json
- [x] T005 [P] Configure Jest testing in libs/credential-manager/jest.config.js
- [x] T006 [P] Configure ESLint and Prettier in libs/credential-manager/

## Phase 3.2: Tests First (TDD) ⚠️ MUST COMPLETE BEFORE 3.3
**CRITICAL: These tests MUST be written and MUST FAIL before ANY implementation**
- [x] T007 [P] Contract test ICredentialManager interface in libs/credential-manager/tests/contract/test_credential_manager.ts
- [x] T008 [P] Contract test IPacificaSigner interface in libs/credential-manager/tests/contract/test_pacifica_signer.ts
- [x] T009 [P] Contract test IConfigLoader interface in libs/credential-manager/tests/contract/test_config_loader.ts
- [x] T010 [P] Contract test ISigner interface in libs/credential-manager/tests/contract/test_signer.ts
- [x] T011 [P] Integration test hot loading 配置文件 in libs/credential-manager/tests/integration/test_hot_loading.ts
- [x] T012 [P] Integration test 智能平台识别 in libs/credential-manager/tests/integration/test_platform_detection.ts
- [x] T013 [P] Integration test Pacifica签名流程 in libs/credential-manager/tests/integration/test_pacifica_signing.ts
- [x] T014 [P] Integration test 多账户管理 in libs/credential-manager/tests/integration/test_account_management.ts
- [x] T015 [P] Performance test 签名操作<50ms in libs/credential-manager/tests/integration/test_performance.ts

## Phase 3.3: Core Implementation (ONLY after tests are failing)
- [x] T016 [P] Platform enum and types in libs/credential-manager/src/core/types.ts
- [x] T017 [P] Account model in libs/credential-manager/src/core/Account.ts
- [x] T018 [P] ConfigLoader implementation in libs/credential-manager/src/loaders/ConfigLoader.ts
- [x] T019 [P] PlatformDetector service in libs/credential-manager/src/core/PlatformDetector.ts
- [x] T020 [P] PacificaDetector strategy in libs/credential-manager/src/platforms/pacifica/PacificaDetector.ts
- [x] T021 [P] AsterDetector strategy in libs/credential-manager/src/platforms/aster/AsterDetector.ts
- [x] T022 [P] BinanceDetector strategy in libs/credential-manager/src/platforms/binance/BinanceDetector.ts
- [x] T023 PacificaSigner implementation in libs/credential-manager/src/platforms/pacifica/PacificaSigner.ts
- [x] T024 PacificaMessageSerializer utility in libs/credential-manager/src/platforms/pacifica/MessageSerializer.ts
- [x] T025 PacificaKeyUtils utility in libs/credential-manager/src/platforms/pacifica/KeyUtils.ts
- [x] T026 UnifiedSigner service in libs/credential-manager/src/core/Signer.ts
- [x] T027 CredentialManager main service in libs/credential-manager/src/core/CredentialManager.ts
- [x] T028 [P] Error handling classes in libs/credential-manager/src/core/errors.ts
- [x] T029 CredentialManagerFactory in libs/credential-manager/src/core/CredentialManagerFactory.ts

## Phase 3.4: Integration
- [ ] T030 File watching integration with fs.watch in ConfigLoader
- [ ] T031 [P] JSON Schema validation in ConfigLoader
- [ ] T032 [P] Logging integration throughout library
- [ ] T033 Platform strategy registration system in UnifiedSigner
- [ ] T034 [P] Metrics collection for PacificaSigner performance
- [ ] T035 Public API exports in libs/credential-manager/src/index.ts

## Phase 3.5: Polish
- [ ] T036 [P] Unit tests for PlatformDetector in libs/credential-manager/tests/unit/test_platform_detector.ts
- [ ] T037 [P] Unit tests for PacificaKeyUtils in libs/credential-manager/tests/unit/test_pacifica_key_utils.ts
- [ ] T038 [P] Unit tests for MessageSerializer in libs/credential-manager/tests/unit/test_message_serializer.ts
- [ ] T039 [P] Unit tests for error handling in libs/credential-manager/tests/unit/test_errors.ts
- [ ] T040 Performance verification tests (<100ms loading, <50ms signing)
- [ ] T041 [P] Update quickstart.md with final API examples
- [ ] T042 [P] Create README.md for credential-manager library
- [ ] T043 [P] Remove debug logging and optimize for production
- [ ] T044 Integration test running quickstart scenarios

## Dependencies
- Setup (T001-T006) before everything
- Tests (T007-T015) before implementation (T016-T029)
- T016 blocks T017-T019 (types dependency)
- T018 blocks T030-T031 (ConfigLoader dependency)
- T019 blocks T020-T022 (detector interface dependency)
- T023-T025 must complete before T026 (PacificaSigner dependency)
- T026-T027 blocks T033 (signer dependency)
- T029 blocks T035 (factory dependency)
- Implementation before polish (T036-T044)

## Parallel Example
```
# Launch contract tests T007-T010 together:
Task: "Contract test ICredentialManager interface in libs/credential-manager/tests/contract/test_credential_manager.ts"
Task: "Contract test IPacificaSigner interface in libs/credential-manager/tests/contract/test_pacifica_signer.ts"
Task: "Contract test IConfigLoader interface in libs/credential-manager/tests/contract/test_config_loader.ts"
Task: "Contract test ISigner interface in libs/credential-manager/tests/contract/test_signer.ts"

# Launch platform detectors T020-T022 together:
Task: "PacificaDetector strategy in libs/credential-manager/src/platforms/pacifica/PacificaDetector.ts"
Task: "AsterDetector strategy in libs/credential-manager/src/platforms/aster/AsterDetector.ts"
Task: "BinanceDetector strategy in libs/credential-manager/src/platforms/binance/BinanceDetector.ts"
```

## Notes
- [P] tasks = different files, no dependencies
- Verify contract tests fail before implementing
- 库优先架构: 独立package.json in libs/credential-manager/
- 性能要求: 签名<50ms, 文件加载<100ms
- Ed25519签名使用@noble/ed25519库
- 配置文件热加载使用Node.js fs.watch
- 平台智能识别使用多重检测器模式

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

1. **From Contracts**:
   - credential-manager.ts → ICredentialManager, IConfigLoader, ISigner contract tests [P]
   - pacifica-signer.ts → IPacificaSigner contract test [P]

2. **From Data Model**:
   - Platform, Account, Signer → model creation tasks [P]
   - ConfigLoader → file watching and validation tasks

3. **From User Stories (quickstart.md)**:
   - 基础使用 → account management integration test [P]
   - 签名操作 → Pacifica signing integration test [P]
   - 热加载监听 → hot loading integration test [P]
   - 多平台签名 → platform detection integration test [P]

4. **Ordering**:
   - Setup → Tests → Models → Services → Integration → Polish
   - 文件监听依赖ConfigLoader
   - 签名器依赖平台检测器
   - 工厂依赖所有核心组件

## Validation Checklist
*GATE: Checked by main() before returning*

- [ ] All contracts have corresponding tests (T007-T010)
- [ ] All entities have model tasks (T016-T018)
- [ ] All tests come before implementation (T007-T015 before T016-T029)
- [ ] Parallel tasks truly independent ([P] marked correctly)
- [ ] Each task specifies exact file path (libs/credential-manager/...)
- [ ] No task modifies same file as another [P] task
- [ ] Performance requirements included (T015, T040)
- [ ] TDD workflow enforced (契约测试必须先失败)
- [ ] 库优先架构 supported (独立package.json in T002)

## 关键特性验证
- **热加载**: T011验证fs.watch文件监听<100ms
- **智能识别**: T012验证平台检测器准确性
- **Pacifica签名**: T013验证Ed25519签名<50ms
- **多账户**: T014验证账户管理和隔离
- **性能**: T015和T040验证所有性能要求