4428 Commits

Author SHA1 Message Date
J8k3
c7a4b6358a Rename Parse EMV TLV → EMV Parse TLV (naming convention)
Domain prefix must come first per AGENTS.md convention. All references
updated: op file, Categories.json, tests, PAYMENT_RECIPES.md, lib comment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 04:25:28 -04:00
Jacob Marks
040da1fd92
Modify EMV recipes in README.md
Updated EMV-related recipes in the README.
2026-05-21 22:33:08 -04:00
J8k3
a44fc20da0 Fix lint: comma-spacing in Payment.mjs test; document full lint command
eslint:tests catches Payment.mjs too — document that npx grunt eslint runs
all five targets, not just eslint:core.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 20:03:37 -04:00
J8k3
8e0c192973 Fix lint: brace-style, comma-spacing, key-spacing, JSDoc, operator-linebreak
11 ESLint errors across 6 files introduced in the ARQC/ARPC/TLV/Script ops.
Also document the constructor-JSDoc and operator-linebreak rules in AGENTS.md
to prevent recurrence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 19:44:13 -04:00
J8k3
32622a01de AGENTS.md: add reciprocal knowledge loop rule to APC cross-reference
The one-way rule (CyberChef gaps → GitHub issue) didn't cover the return path.
New paragraph: discoveries from CyberChef sessions (PCI rules, algorithm edge cases,
HSM commands) must be written back into the MCP server in the same session.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 19:28:29 -04:00
J8k3
2b9c92bae6 Enforce same-commit docs + APC check rule in AGENTS.md
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 19:28:28 -04:00
J8k3
a35b5aa23c Docs: add EMV Build Script Data ops to PAYMENT_RECIPES.md
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 19:28:27 -04:00
J8k3
eeb16eaaa8 Add EMV Build Script Data and Build PIN Change Script Data operations
Also fixes expectedError test format (OperationErrors surface as result
strings, not result.error) and updates PAYMENT_RECIPES.md docs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 19:28:25 -04:00
J8k3
259b9740a7 Add EMV Build/Parse ARPC Data operations
- EMV Build ARPC Data: assembles ARPC preimage from named fields; Method 1 (Visa/Amex/Discover: ARQC+ARC, 10 bytes) and Method 2 (Mastercard: ARQC+CSU+optional PAD, 12-20 bytes); outputs hex (chainable into EMV Generate ARPC), JSON, or annotated
- EMV Parse ARPC Data: inverse; parses hex preimage back into named fields by method
- Shared lib EmvArpc.mjs with build/parse/format functions
- 6 new tests in Payment.mjs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 19:28:24 -04:00
J8k3
10bb87b320 Add EMV Build/Parse ARQC Data and Parse EMV TLV operations (issues #11)
- EMV Build ARQC Data: assembles 10-field CDOL1 preimage from args; outputs hex (chainable into EMV Generate ARQC), JSON, or annotated TLV
- EMV Parse ARQC Data: inverse; parses flat 33-byte CDOL1 hex back into named fields
- Parse EMV TLV: BER-TLV parser with 102-entry EMV tag dictionary; handles constructed/nested tags, 1- and 2-byte tags, long-form lengths; dictionary mode lists all known tags
- Shared libs: EmvCdol.mjs (CDOL1 field defs), EmvTlv.mjs (parser), EmvTlvDictionary.mjs (tag dict)
- 12 new tests in Payment.mjs covering all three operations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 19:28:23 -04:00
Jacob Marks
f90fba92fd
Fix typos and enhance README clarity
Corrected typos and improved clarity in the README.
2026-05-21 12:42:49 -04:00
Jacob Marks
a87e24cad5
Revise README for CyberChef Payments focus
Updated the README to reflect the focus on payment cryptography operations, clarified the development status, and modified section headings.
2026-05-21 12:30:50 -04:00
Jacob Marks
8d45d908e6
Revise CyberChef recipes in README
Updated links for PIN and EMV generation recipes.
2026-05-21 07:59:53 -04:00
J8k3
c44873ab3f Fix lint: expand inline try/catch in KeyComponentCombine; add brace-style rule to AGENTS.md
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 22:22:51 -04:00
J8k3
28cda9bad9 Add Key Component Split and Combine operations (issue #2)
XOR key ceremony helpers: split a key into 2-8 components and recombine.
Chains cleanly with Key Generate and wrap/encrypt operations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 22:06:32 -04:00
J8k3
79ac440b14 Docs: AGENTS.md, PAYMENT_RECIPES.md, README.md updates
- AGENTS.md: add APC cross-reference, security constraint, ESLint, and gap-filing instructions
- PAYMENT_RECIPES.md: DUKPT AES key status to Externally cross-checked; VISA PVV APC results updated with second key cross-check
- README.md: PIN Block Translate Encrypted in coverage list and recipe links

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 21:49:34 -04:00
J8k3
ffc5fcbf41 Add PIN Block Translate Encrypted; fix CBOR v9 encode; fix EMV MAC tests; fix bcrypt node test
- PIN Block Translate Encrypted: new operation with 5 tests; registered in Payments category
- CBOR v9: fix Encoder streaming/Buffer pool issue; JSDoc on helpers
- EMV Generate MAC: fix empty-input hex parse, stale 3-arg test, missing padding method in verify test
- parseHexBytes: accept empty string as valid 0-byte hex
- bcrypt node test: accept $2a prefix from bcryptjs v2.4.3

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 19:04:35 -04:00
J8k3
c628207471 Add DUKPT session key variant, PIN block edge case, and EMV MAC boundary tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 15:44:34 -04:00
J8k3
31310d5d57 PAYMENT_RECIPES: explain ISO9797 Method 1/2; update EMV MAC APC comparison row 2026-05-19 21:13:12 -04:00
J8k3
9015ea9f40 EMV Generate/Verify MAC: add padding method selector (default Method 2) 2026-05-19 20:43:25 -04:00
J8k3
0d08681d55 PAYMENT_RECIPES: add APC comparison results; fix PIN translation note 2026-05-19 19:40:23 -04:00
J8k3
e09d6df31e Fix AES DUKPT derivation: use AES-ECB, 32-bit tree, usage 0x8000
X9.24-3 uses AES_Encrypt_ECB for all derivation steps, not AES-CMAC.
Intermediate tree nodes use key usage 0x8000 (not 0x0000), and the
binary tree traversal must cover all 32 counter bits (not 21).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 15:06:58 -04:00
J8k3
2dbccc613f AGENTS: explicit ban on running npm build/start on Windows
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 11:22:13 -04:00
J8k3
8ac6cc1980 Add PIN Generate op: random PIN with optional clear PIN block output
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 10:16:19 -04:00
J8k3
af84b44117 AGENTS: grunt task alias, IBM 3624 naming example, end-of-cycle review prompt
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 09:37:59 -04:00
J8k3
292f4afbb8 Rename IBM 3624 ops to PIN-domain-first; use crypto.getRandomValues in PAN generator
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 09:34:51 -04:00
J8k3
b724fc4b8c Fix AES DUKPT derivation data format; add X9.24-3 test vectors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 23:02:01 -04:00
J8k3
e864259c1e Fix VISA PVV decimalization: use two-pass algorithm per Visa spec
decimalizePvv() was using a single-pass that immediately mapped A-F to
0-5. The Visa PVV spec (matching ANSI X9.8 and jPOS behavior) requires
two-pass: collect all decimal digits (0-9) first; only then re-scan
mapping A=0 B=1 C=2 D=3 E=4 F=5. This matches decimalizeCvvHex() which
was already correct. Bug produced wrong PVV whenever a hex letter appeared
before the first decimal digit in the encrypted output.

Test vectors updated from "6077" (single-pass result) to "6776" (correct
two-pass result) for the encrypted PVV hex 6A77E65CFE349D60.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 21:53:28 -04:00
J8k3
a2880a4dfc Add Format 1/3 PIN block tests and Generate→Verify chain tests
PIN block coverage:
- PIN Block Build: ISO Format 1 deterministic (fill 0xF, no PAN)
- PIN Block Parse: ISO Format 1
- PIN Block Build: ISO Format 3 deterministic (fill 0xA, PAN-bound)
- PIN Block Parse: ISO Format 3

Chain tests (exercises the input/arg swap work and confirms output flows correctly):
- VISA PVV Generate → Verify
- IBM 3624 Generate PIN Offset → Verify PIN
- EMV Generate ARQC → Verify ARQC

Closes part of issue #12 (testing gaps).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 21:33:06 -04:00
J8k3
0d08b2fc04 Update README and PAYMENT_RECIPES for shipped AES DUKPT and removed op
README:
- Added DUKPT AES key derivation to current coverage (ANSI X9.24-3, 12-byte KSN, AES-128)
- Expanded DUKPT TDES line to include standard/KSN details for clarity
- Removed AES DUKPT from Future extensions (it shipped)

PAYMENT_RECIPES:
- Replaced "deprecated" with "removed" for Translate Payment PIN Data (issue #4 was resolved)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 20:33:34 -04:00
J8k3
5709c11be3 Add build commands to AGENTS.md; document CVV2/iCVV service-code forcing in card validation ops
AGENTS.md:
- Added npm start (dev server), npm run build (prod), and NODE_OPTIONS heap-size tip from upstream Getting-started wiki

Card Validation Data Generate/Verify:
- Added Profile behaviour note to both descriptions: CVV2 forces service code 000, iCVV forces 999, the arg is ignored for those profiles

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 20:25:52 -04:00
J8k3
f4bd260363 Absorb PAYMENT_VALIDATION_AUDIT.md into PAYMENT_RECIPES.md; tighten AGENTS.md
PAYMENT_RECIPES.md:
- Removed stale AWS_PAYMENT_CRYPTOGRAPHY_RECIPES.md and PAYMENT_VALIDATION_AUDIT.md cross-references
- Added Validation Status section: class legend, full op matrix (current names, includes DUKPT Derive AES Key, HSM parse ops; removes deprecated Translate Payment PIN Data), release posture, references

AGENTS.md:
- Added Code Style section pointing to CONTRIBUTING.md conventions
- Merged "When Docker is unavailable" rule into Test And Debugging Baseline
- Removed now-redundant Current Project Preference section

PAYMENT_VALIDATION_AUDIT.md deleted (content absorbed above)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 20:24:48 -04:00
J8k3
09040b6bb7 Semantic/usability fixes across four payment operations
- PIN Data Verify: add Output as JSON toggle (was always returning JSON with no way to get plain boolean; all other verify ops have this toggle)
- EMV Verify MAC: fix inlineHelp to say "session integrity key" (was "session key", inconsistent with arg name and description body)
- DUKPT Derive TDES Key: replace stale "AES DUKPT not implemented" note with pointer to DUKPT Derive AES Key operation
- EMV Generate MAC (PIN Change): replace "Emulation helper" / "This emulation" with "Test helper" / "This operation" throughout description, inlineHelp, and arg comment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 15:53:49 -04:00
J8k3
be3af3ab48 Add payment recipe example URLs to README; remove stale AWS branding doc; add squash rule to AGENTS.md
- Appended 23 pre-built payment recipe chain URLs (p01-p23) to README
- Removed link to AWS_PAYMENT_CRYPTOGRAPHY_RECIPES.md from README (replaced by PAYMENT_RECIPES.md)
- Deleted AWS_PAYMENT_CRYPTOGRAPHY_RECIPES.md (stale pre-debranding artifact)
- Added squash/amend guidance to Commit Scope in AGENTS.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 15:45:25 -04:00
J8k3
a312c23fbc Swap input/arg on all Verify operations for recipe chaining
PVV Verify, IBM 3624 Verify PIN, and EMV Verify ARQC all previously took
the long preimage data as input and the short cryptogram/offset as an arg,
which broke natural recipe chaining from their Generate counterparts.

Swapped each: the short output (PVV, offset, ARQC) now flows in as input;
the preimage/PIN data moves to an arg. Also added an Output as JSON toggle
to EMV Verify ARQC for consistency with other verify operations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 15:45:12 -04:00
J8k3
cb0f535aec Add syntax-only scope note to both HSM Parse operations
Both HSM Parse Thales Command and HSM Parse Futurex Command parse
message framing and field structure only; they do not interpret,
validate, or execute command payloads. Added a prominent Scope note
to this.description and this.inlineHelp on both operations so users
see the limitation before relying on the output for semantic analysis.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 14:42:46 -04:00
J8k3
b345d5b8e9 Fix DUKPT TDES counter accumulation in deriveSessionBaseKey
The per-bit loop was setting the FULL counter value on every hit instead
of OR-ing in one bit at a time. For any counter with more than one set
bit the two calls to nonReversibleKeyGen received the same ksnReg and
produced wrong derived keys. The existing test vector used counter 0x08
(one set bit), which masked the bug.

Fix: accumulate bits with |= so ksnReg grows one bit per iteration:
  ksnReg[7] |= (bit >> 16) & 0x1F
  ksnReg[8] |= (bit >> 8) & 0xFF
  ksnReg[9] |= bit & 0xFF

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 14:41:42 -04:00
J8k3
17cc3f9cb9 Fix SHA-224 KCV bug, simplify DUKPT variant logic, add AGENTS.md rules
- CalculatePaymentKCV: fix HMAC SHA-224 using SHA-512/224 (forge.md.sha512.sha224)
  instead of standard SHA-224 (now uses "sha224" string, consistent with other HMAC methods)
- PaymentMac: collapse 3-clause DUKPT variant ternary to single expression; the
  ISO 9797-1 fallback to "MAC Request" was already correct and is now explicit
- AGENTS.md: renumber steps 1-7 sequentially; add step 6 — review and update
  this.description/inlineHelp/testDataSamples whenever changing a recipe

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 14:27:27 -04:00
J8k3
0da4c99a0c Fix PAN generation: random prefix within range, Mastercard series option
Two bugs in generateBrandPan:
1. For networks with multiple prefix rules, always picked the same rule
   (Mastercard always 2-series, AmEx always 37, Discover always 6011)
2. Always used the start of the range as the prefix, so Mastercard
   generated 51xxxxx or 2221xxxxxx every time instead of any value
   in 51-55 or 2221-2720

Fix both: pick a random prefix rule and a random prefix within start..end.

Add a "Mastercard series" arg to PAN Generate so callers can explicitly
request 5-series (51-55), 2-series (2221-2720), or leave it random.
The curated sample path is unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 14:18:22 -04:00
J8k3
eba7e37185 Fix TR-31/TR-34 op names and sort Payments category alphabetically
Rename two ops to follow the domain-prefix-first convention:
  "Parse TR-31 Key Block"    -> "TR-31 Parse Key Block"
  "Parse TR-34 Key Transport" -> "TR-34 Parse Key Transport"

Sort all 33 Payments category entries alphabetically in Categories.json.
With domain-prefix names the prefixes cluster related ops naturally, so
alphabetical order is also logical order.

Update PAYMENT_RECIPES.md UI Arrangement section to document alphabetical
ordering. Fix stale lowercase references in AWS_PAYMENT_CRYPTOGRAPHY_RECIPES.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 14:11:06 -04:00
J8k3
c6d530348e Document generated config files in Payment Operation Maintenance
After the op-rename batch, the runtime threw 'f[e.module][e.name] is not
a constructor' for every renamed op because Payment.mjs and index.mjs are
gitignored generated files that were never regenerated after this.name
was updated.

Add a rule to AGENTS.md step 6 naming the three generated files, the
symptom of a stale registry, and the two-command fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 12:35:41 -04:00
J8k3
fc6ac7806e Improve testDataSamples: random placeholders and recipeConfig chains
Replace six static inputs that held hardcoded keys or PINs with the
appropriate __RANDOM_*__ placeholder so the populate button delivers a
fresh value each time rather than a fixed test vector:
  - PIN Data Generate, IBM 3624 Generate PIN Offset, VISA PVV Generate
    → __RANDOM_PIN_4__
  - DUKPT Derive TDES Key, AS2805 Generate KEK Validation
    → __RANDOM_TDES_16_HEX__
  - DUKPT Derive AES Key → __RANDOM_AES_128_HEX__

Add a recipeConfig chain sample to two ops where the output of
Key Generate flows directly into the next op as input:
  - Card Validation Data Generate: Key Generate → Card Validation Data Generate
  - Payment Calculate KCV: Key Generate → Payment Calculate KCV

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 10:01:31 -04:00
J8k3
634c835dfd Rename payment ops to domain-prefix-first; remove upstream ops from Payments category
All 31 payment operation display names now lead with their domain prefix
(EMV, DUKPT, PIN Block, PAN, etc.) so they sort and scan by topic in the
UI list. 8 upstream CyberChef ops (AES Encrypt/Decrypt, Triple DES,
AES Key Wrap/Unwrap, HMAC, CMAC) removed from the Payments category.

Updated: op this.name fields, Categories.json, Payment.mjs tests,
PAYMENT_RECIPES.md, AWS_PAYMENT_CRYPTOGRAPHY_RECIPES.md, AGENTS.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 09:29:52 -04:00
github-actions[bot]
32ef373485 Merge remote-tracking branch 'upstream/master' 2026-05-18 09:37:11 +00:00
J8k3
f246a7dcf9 Rename Derive DUKPT Key to Derive DUKPT TDES Key
Mirrors the naming convention of Derive DUKPT AES Key.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 21:56:03 -04:00
Jacob Marks
01f396d121 Fix #4: delete TranslatePaymentPINData (duplicate of TranslatePINBlock) 2026-05-17 20:34:52 -04:00
Jacob Marks
0aadfb94e3 Fix GenerateTestPAN: random fills, suppress cardType when unknown 2026-05-17 13:33:28 -04:00
Jacob Marks
c405326f03 Fix 3 test assertions: TR-31 compliance fields, PAN card-type fields 2026-05-17 08:24:13 -04:00
Jacob Marks
cd4442cc62 Fix 3 test assertions: TR-31 compliance fields, PAN card-type fields 2026-05-17 08:23:10 -04:00
Jacob Marks
6fc1c26b24 Fix Payment.mjs: correct 4 op names (payShield/Futurex uppercase C, TR-31 Key Block, TR-34 Key Transport) and TR-34 expected output 2026-05-17 08:16:56 -04:00