Skip to content

refactor: extract APDU building functions as pure utilities#99

Merged
tomkp merged 1 commit intomasterfrom
refactor/extract-apdu-utilities
Dec 29, 2025
Merged

refactor: extract APDU building functions as pure utilities#99
tomkp merged 1 commit intomasterfrom
refactor/extract-apdu-utilities

Conversation

@tomkp
Copy link
Owner

@tomkp tomkp commented Dec 29, 2025

Summary

Extract inline APDU command building logic into reusable pure functions.

Changes

  • Add buildGetResponseCommand(bytesAvailable): Build GET RESPONSE APDU
  • Add correctLeInCommand(command, newLe): Correct Le value in command
  • Both functions exported from main module
  • Add JSDoc documentation
  • Add 7 unit tests
  • Refactor transmitWithAutoResponse to use the new functions

Example usage

import { buildGetResponseCommand, correctLeInCommand } from 'smartcard';

// Build GET RESPONSE command
const getResponse = buildGetResponseCommand(0x1c); // 00 C0 00 00 1C

// Correct Le in existing command  
const corrected = correctLeInCommand(Buffer.from([0x00, 0xb0, 0x00, 0x00, 0xff]), 0x20);

Test plan

  • All 99 unit tests pass
  • Lint passes
  • Existing transmitWithAutoResponse tests still pass

Fixes #98

Extract inline APDU command building logic into reusable pure functions:
- buildGetResponseCommand(bytesAvailable): Build GET RESPONSE APDU
- correctLeInCommand(command, newLe): Correct Le value in command

Both functions are now exported from the main module and tested independently.

- Add JSDoc documentation for both functions
- Add 7 unit tests for the new functions
- Refactor transmitWithAutoResponse to use the new functions

Fixes #98
@tomkp tomkp merged commit a62e203 into master Dec 29, 2025
9 checks passed
@tomkp tomkp deleted the refactor/extract-apdu-utilities branch December 29, 2025 16:04
tomkp added a commit that referenced this pull request Dec 29, 2025
Changes since 3.5.0:
- docs: Update README with getCards, getCard, transmitWithAutoResponse, control codes (#85)
- test: Add unit tests for parseFeatures() (#87)
- fix: Add explicit buffer bounds validation in parseFeatures() (#89)
- refactor: Extract isUnresponsiveCardError as pure function (#91)
- refactor: Consolidate addon type definitions (#93)
- test: Add createTestSetup helper to reduce boilerplate (#95)
- feat: Add typed addListener/removeListener methods (#97)
- refactor: Extract APDU building functions as pure utilities (#99)
- feat: Return ReadonlyMap from getCards() (#101)
- docs: Fix getCards() return type in README (#103)
@tomkp tomkp mentioned this pull request Dec 29, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract APDU building functions as pure utilities

1 participant