Add comprehensive ticket validation with controlTicket() function - #22
Merged
Conversation
Design a controlTicket() function and 13 focused check helpers for comprehensive ticket validation: decode, header, security, signatures (L1/L2), expiry, specimen, activation, issuing detail, transport documents, Intercode extension, dynamic data, and content freshness. https://claude.ai/code/session_017YdSb7Xi9oSFKsXYa67bKy
- Remove level1PublicKey option, keep only level1KeyProvider callback - Level 1 signature is mandatory (error severity, not warning/skip) - Level 2 signature is conditional on level2SigningAlg being set - Validate L1 and L2 security fields independently in checkSecurityInfo - Add expectedIntercodeNetworkIds option (Set<string> of hex IDs) for network ID validation in checkIntercodeExtension - Remove dynamicContentMaxAge option, derive freshness window from security.validityDuration instead https://claude.ai/code/session_017YdSb7Xi9oSFKsXYa67bKy
- Remove level1KeyAlg from mandatory L1 security fields (only level1SigningAlg and level1Signature are required) - Clarify that intercodeIssuing.networkId is always a 3-byte Uint8Array, converted to a 6-character hex string for comparison https://claude.ai/code/session_017YdSb7Xi9oSFKsXYa67bKy
FDC1: day is absolute day-of-year, time is seconds of day. Intercode ID1: day is offset from issuing date, time is seconds since midnight (local), UTCOffset in 15-min steps, and dynamicContentDuration (seconds) takes precedence over security.validityDuration when present. https://claude.ai/code/session_017YdSb7Xi9oSFKsXYa67bKy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new ticket validation system via the
controlTicket()function, which performs comprehensive checks on decoded UIC barcode tickets. The implementation provides structured validation results across 13 distinct check categories, supporting all ticket variants including FDC1 dynamic content, Intercode 6 extensions, and multiple FCB versions.Key Changes
New
src/control.tsmodule: ImplementscontrolTicket()as the main entry point for ticket validation, along with 13 focused check helper functions:checkDecode,checkHeader,checkSecurityInfo,checkIssuingDetail,checkTransportDocumentcheckLevel2Signature,checkLevel1SignaturecheckNotExpired,checkDynamicContentFreshnesscheckNotSpecimen,checkActivatedcheckIntercodeExtension,checkDynamicDataNew types in
src/types.ts: AddedControlOptions,CheckResult, andControlResultinterfaces to support flexible validation configuration and structured result reportingUpdated
src/index.ts: ExportedcontrolTicketfunction and new validation types for public APIComprehensive test suite in
tests/control.test.ts: Tests covering all check functions across multiple ticket variants (SAMPLE, Soléa, CTS, SNCF TER, Grand Est) with scenarios for expiry, specimen detection, tampering, and missing keysNotable Implementation Details
error(makes ticket invalid),warning(informational), orinfo(purely informational)controlTicket()is async to support future key provider implementationsverifyLevel2Signature()andverifyLevel1Signature()fromverifier.tsfor cryptographic validationhttps://claude.ai/code/session_017YdSb7Xi9oSFKsXYa67bKy