Prototype

Setting Up the Raspberry Pi Device

Setting Up the Raspberry Pi Device

Hardware Assembly

  1. Connect the R305 Fingerprint Sensor Module to the Raspberry Pi Zero W using GPIO pins.

  2. Connect the PN532 NFC Module to the Raspberry Pi Zero W using SPI or I2C.

  3. Connect the USB-C Power Bank to power the Raspberry Pi Zero W.

Software Setup

  1. Install the Raspbian OS on the Raspberry Pi Zero W.

  2. Install the necessary libraries for the NFC and fingerprint modules.

Python Script for Raspberry Pi

You'll need to install the following Python packages:

  • nfcpy for NFC communication

  • zk-stark for zk-STARK cryptography (this is a placeholder; you'll need to find or create a suitable library)

  • RPi.GPIO for GPIO control

Raspberry Code:

import nfc  # NFC library for Python
import RPi.GPIO as GPIO  # GPIO library for Raspberry Pi
from r307_fingerprint import R307  # Import your R307 fingerprint sensor module
from zk_stark_module import ZKStark  # Import your zk-STARK module
from lcd_module import LCD  # Import your LCD display module (if needed)

# GPIO Setup for the red LED and LED lamp
red_led_pin = 18
led_lamp_pin = 17  # GPIO pin for the LED lamp

GPIO.setmode(GPIO.BCM)
GPIO.setup(red_led_pin, GPIO.OUT)
GPIO.setup(led_lamp_pin, GPIO.OUT)  # Setup for LED lamp

# Initialize LCD (if needed)
lcd = LCD()

# Global variables for user data
registered_fingerprint = None
registered_zk_stark_proof = None

# Function to turn on LED lamp
def turn_on_lamp():
    GPIO.output(led_lamp_pin, GPIO.HIGH)

# Function to turn off LED lamp
def turn_off_lamp():
    GPIO.output(led_lamp_pin, GPIO.LOW)

def register_user():
    global registered_fingerprint, registered_zk_stark_proof
    fingerprint_sensor = R307()
    zk_stark = ZKStark()

    lcd.display("Place your finger on the sensor...")
    registered_fingerprint = fingerprint_sensor.read_fingerprint()

    lcd.display("Creating zk-STARK proof...")
    registered_zk_stark_proof = zk_stark.create_proof(registered_fingerprint)

    lcd.display("Deleting fingerprint data...")
    fingerprint_sensor.delete_fingerprint()

    lcd.display("User successfully registered.")

def main():
    global registered_fingerprint, registered_zk_stark_proof

    with nfc.ContactlessFrontend('usb') as clf:
        while True:
            lcd.display("Waiting for NFC communication...")
            tag = clf.connect(rdwr={'on-connect': lambda tag: False})

            # Red LED blinks once when a request comes in
            GPIO.output(red_led_pin, GPIO.HIGH)
            lcd.display("NFC Tag Detected")

            # Read fingerprint
            fingerprint_sensor = R307()
            current_fingerprint = fingerprint_sensor.read_fingerprint()

            # Verify fingerprint
            if current_fingerprint == registered_fingerprint:
                lcd.display("Fingerprint Verified")

                # zk-STARK Verification
                zk_stark = ZKStark()
                if zk_stark.verify_proof(registered_zk_stark_proof):
                    lcd.display("zk-STARK Verification Successful")
                    turn_on_lamp()  # Turn on LED lamp
                else:
                    lcd.display("zk-STARK Verification Failed")
                    turn_off_lamp()  # Turn off LED lamp
            else:
                lcd.display("Fingerprint Verification Failed")
                turn_off_lamp()  # Turn off LED lamp

            # Turn off the red LED
            GPIO.output(red_led_pin, GPIO.LOW)

            # Delete biometric data after verification
            fingerprint_sensor.delete_fingerprint()

if __name__ == "__main__":
    register_user()
    main()

Setting Up the iOS App

Xcode Project Setup

  1. Create a new Xcode project.

  2. Add the Core NFC framework to your project.

  3. Update the Info.plist to request NFC reading permission.

Swift Code for iOS App

Here's a simplified Swift code snippet to initiate NFC communication:

import Foundation
import NFC  // Import NFC library
import RPiGPIO  // Import GPIO library for Raspberry Pi
import R307  // Import R307 fingerprint sensor module
import ZKStark  // Import zk-STARK module
import LCD  // Import LCD display module (if needed)

// GPIO Setup for the red LED and LED lamp
let redLEDPin = 18
let ledLampPin = 17

var gpio = SwiftyGPIO.GPIOs(for: .RaspberryPi3)
var redLED = gpio[.P18]!
var ledLamp = gpio[.P17]!

redLED.direction = .OUT
ledLamp.direction = .OUT

// Initialize LCD (if needed)
let lcd = LCD()

// Global variables for user data
var registeredFingerprint: Data?
var registeredZKStarkProof: Data?

// Function to turn on LED lamp
func turnOnLamp() {
    ledLamp.value = 1
}

// Function to turn off LED lamp
func turnOffLamp() {
    ledLamp.value = 0
}

func registerUser() {
    let fingerprintSensor = R307()
    let zkStark = ZKStark()

    lcd.display("Place your finger on the sensor...")
    registeredFingerprint = fingerprintSensor.readFingerprint()

    lcd.display("Creating zk-STARK proof...")
    registeredZKStarkProof = zkStark.createProof(from: registeredFingerprint!)

    lcd.display("Deleting fingerprint data...")
    fingerprintSensor.deleteFingerprint()

    lcd.display("User successfully registered.")
}

func main() {
    let nfcReader = NFCReader()

    while true {
        lcd.display("Waiting for NFC communication...")
        let tag = nfcReader.connect()

        // Red LED blinks once when a request comes in
        redLED.value = 1
        lcd.display("NFC Tag Detected")

        // Read fingerprint
        let fingerprintSensor = R307()
        let currentFingerprint = fingerprintSensor.readFingerprint()

        // Verify fingerprint
        if currentFingerprint == registeredFingerprint {
            lcd.display("Fingerprint Verified")

            // zk-STARK Verification
            let zkStark = ZKStark()
            if zkStark.verifyProof(registeredZKStarkProof!) {
                lcd.display("zk-STARK Verification Successful")
                turnOnLamp()  // Turn on LED lamp
            } else {
                lcd.display("zk-STARK Verification Failed")
                turnOffLamp()  // Turn off LED lamp
            }
        } else {
            lcd.display("Fingerprint Verification Failed")
            turnOffLamp()  // Turn off LED lamp
        }

        // Turn off the red LED
        redLED.value = 0

        // Delete biometric data after verification
        fingerprintSensor.deleteFingerprint()
    }
}

// Entry point
registerUser()
main()

In this updated Swift code:

  1. A zkStarkProof variable is added to store the zk-STARK proof for the user.

  2. The initiateNFCCommunication function starts the NFC session.

  3. The readerSession(didDetectNDEFs:) function sends the zk-STARK proof along with the request to the Raspberry Pi.

  4. A createZkStarkProof function is added as a placeholder for creating a zk-STARK proof.

Last updated

Logo