bcgov / bc-wallet-mobile

BC Wallet to hold Verifiable Credentials
Apache License 2.0
61 stars 48 forks source link

Spike: How to read barcode from identity cards #2149

Closed cvarjao closed 1 month ago

cvarjao commented 1 month ago

Description

Notes:

There are two barcodes on the BC Services Card (same as on the BC DL). The serial number is a 1-D barcode on the right hand side of the back. While the 2D barcode is on the bottom side of the back. See this sample DL: https://images.ctfassets.net/nnc41duedoho/7za52YKEvPiRnuoArZz07B/d76195920ba339c03c2be814f5442090/DL-sample.jpg? The 1-D barcode is pretty straightforward and translates to raw text. Any barcode scan library will give you something like the type of barcode and the raw text.

The 2-D barcode is more complicated, and may contain more information than needed. By complicated, I mean that it's a PDF417 barcode, but doesn't follow the AAMVA standard for BC issued identity docs. The barcode for BC issued documents actually contains text in the same format as the magstripe.

APD has some server side code that converts both types of PDF417 barcodes into a "canonical" format for our needs In my opinion, our priority is the 1-D barcode for current capabilities, but the stretch goal is to extract both barcodes at the same time from the same frame (same UI interaction for the user). We can deal with the raw barcode text on the backend.

For test and sample IDs, you don't need to make any API calls yet, and you can generate as many as you need using tools like https://barcode.tec-it.com/en

  1. Open an incognito browser to https://barcode.tec-it.com/en
    • (may need to Accept Cookies)
  2. Choose 2D Codes > PDF417
  3. Enter the desired content in the text box (see next section)
  4. Click on Create Sequence
  5. Download or take a screen shot of the resulting barcode

Here's a sample of the PDF417 for BC docs (line breaks for readability):

%BCVICTORIA^SURNAME,$GIVENONE GIVENTWO^123 FIRST ST$VICTORIA BC  V8X 2S8^
?;6360281679897=260419900403=
?_%0AV8X2S8                     M183 73BRNBRN9876543212                $B\"/G:HV76W?

That same site that I list above can generate the 1D serial number barcodes. The serial numbers are currently 9 characters. 1 alpha followed by 8 digits. Like T00252783.

wadeking98 commented 1 month ago

With some minor tweaks the react native vision library supports the 1D and 2D barcodes on BC Services card and drivers license. I was able to read the two barcodes on my driver's license without any issue. Here's the code I used:

const codeScannerExperimental = useCodeScanner({
    codeTypes: ['qr', 'code-128', 'pdf-417'],
    onCodeScanned: (val)=>{console.log(val)}
  })
  return (
    <View style={[StyleSheet.absoluteFill, { transform: [{ rotate: orientationDegrees[orientation] ?? '0deg' }] }]}>
      {device && (
        <Camera
          style={StyleSheet.absoluteFill}
          device={device}
          torch={torchActive ? 'on' : 'off'}
          isActive={cameraActive}
          codeScanner={codeScannerExperimental}
          format={format}
        />
      )}
    </View>