Skip to content

Add PDF keycard parsing functionality#8946

Open
mohammadalfaiyazbitgo wants to merge 4 commits into
masterfrom
claude/compassionate-euler-DJa99
Open

Add PDF keycard parsing functionality#8946
mohammadalfaiyazbitgo wants to merge 4 commits into
masterfrom
claude/compassionate-euler-DJa99

Conversation

@mohammadalfaiyazbitgo
Copy link
Copy Markdown
Contributor

Description

This PR adds functionality to extract and parse BitGo keycard data from PDF files. It includes:

  1. New parsing module (parseKeycard.ts): Core logic to parse keycard sections (A–D) from text lines extracted from PDFs, with robust handling of:

    • Multi-line section values (base64, xpub strings)
    • Page-break labels ("Part N") that appear standalone or embedded in content
    • JSON-formatted encrypted wallet passwords with proper brace counting to detect section boundaries
    • PDF text node reconstruction into logical lines based on spatial coordinates
  2. PDF extraction module (extractKeycardFromPDF.ts): Wrapper around pdfjs-dist to extract text nodes from PDF files and convert them to keycard entries

  3. Web demo integration: Added file upload UI in the KeyCard component to allow users to upload a keycard PDF and view extracted sections in a table

  4. Dependencies: Added pdfjs-dist (^5.0.0) to both @bitgo/key-card and web-demo packages

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Added comprehensive unit tests in parseKeycardFromLines.test.ts covering:

  • Happy path with clean JSON in a single line
  • Standalone "Part N" page-break labels
  • Multiple embedded "Part N" labels within base64 content
  • "Part N" labels fused mid-line into content

All tests verify correct reconstruction of encrypted wallet password JSON and other section values.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My code compiles correctly for both Node and Browser environments
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my feature works
  • New and existing unit tests pass locally with my changes

https://claude.ai/code/session_01Pj4SsrmSnoBNj8h6zX1vaz

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo requested review from a team as code owners June 4, 2026 14:57
@mohammadalfaiyazbitgo mohammadalfaiyazbitgo marked this pull request as draft June 4, 2026 14:57
…d sdk

- add parseKeycard.ts with pure string parsing logic (parseKeycardFromLines,
  buildLinesFromPDFNodes, KeycardEntry, PDFTextNode types)
- add extractKeycardFromPDF.ts with pdfjs-dist based PDF extraction
  (browser-only; consumer must configure GlobalWorkerOptions.workerSrc)
- add pdfjs-dist ^5.0.0 dependency to @bitgo/key-card
- export new functions from module index
- add mocha unit tests for parseKeycardFromLines covering all Part N edge cases
- add pdf parse demo UI to web-demo KeyCard page with file upload,
  result table, and worker configuration for webpack

WCN-19
pdfjs-dist@5.7.x requires node >=22.13.0 || >=24, which is incompatible
with the node 20.x CI runner. downgrade to ^4.0.0 which supports node 18+.
update web-demo worker path from .mjs to .js to match v4 build output.
fix prettier formatting in web-demo KeyCard component.

WCN-19
pdfjs-dist initializes browser-only globals (DOMMatrix) at module load
time. using a static top-level import caused all tests in @bitgo/key-card
to crash in node.js environments. switching to a dynamic import() inside
extractKeycardEntriesFromPDF defers loading to call time (browser only).

WCN-19
…nsions

pdfjs-dist v4 only ships .mjs worker files (no .js variants). the previous
commit incorrectly changed the worker path to .mjs -> .js. reverted to
pdf.worker.min.mjs and added .mjs to webpack resolve extensions in both
dev and prod configs so webpack can locate the file.

WCN-19
@mohammadalfaiyazbitgo mohammadalfaiyazbitgo force-pushed the claude/compassionate-euler-DJa99 branch from 2d5100a to 45ec5bf Compare June 4, 2026 17:32
@mohammadalfaiyazbitgo mohammadalfaiyazbitgo marked this pull request as ready for review June 4, 2026 17:45
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.

1 participant