Verify New Zealand COVID Passes in iOS apps using Swift

Overview

NzCovidPass-Swift

Swift library for verification of the NZ Covid Vaccination Pass according to https://nzcp.covid19.health.nz/

Copyright (c) 2021 Gallagher Group Ltd

Licensed under the MIT License

Overview:

This is a self-contained implementation of a verifier for the NZ COVID Pass format, written entirely in swift. It does not rely on any external servers, API's or other things, and can function purely offline.

Using the library:

You should be able to import the library directly using Swift Package Manager, by referencing this GitHub repository. Alternatively, you can clone it and reference the xcodeproj from your existing Xcode application project or workspace.

Example:

import NzCovidPass

let passPayload = "NZCP:/1/...." // get this from scanning a QR code
let verifier = PassVerifier()
do {
    let passContents = try verifier.verify(passPayload: passPayload)
    let givenName = passContents.payload.credential?.credentialSubject.givenName ?? ""
    let familyNameCandidate = passContents.payload.credential?.credentialSubject.familyName
    let dateOfBirth = passContents.payload.credential?.credentialSubject.dateOfBirth ?? ""
            
    let fullName: String
    if let familyName = familyNameCandidate {
        fullName = "\(givenName) \(familyName)"
    } else {
        fullName = givenName
    }
    
    let expiry = passContents.payload.expiry ?? Date.distantPast
} catch let err {
    switch error {
    case PassVerificationError.invalidPrefix, PassVerificationError.invalidPassComponents:
        print("This is not an NZ Covid Pass QR Code.")
    case CwtSecurityTokenValidationError.expired:
        print("Pass Expired.")
    case CwtSecurityTokenValidationError.notYetValid:
        print("Pass Not Active.")
    default:
        // any kind of structural or signature error just results in "not issued by the ministry of health"
        print("This pass was not issued by the Ministry of Health.")
    }
}

Notes:

Currently this does not dynamically download DID documents (public keys); rather the NZCP test key, and production key z12Kf7UQ are embedded in the source code. This has the advantage that it always works offline, there is no "first run" internet connection required, however it does mean if the ministry of health issues a new production keypair, then the library will need to be updated.

We expect to add dynamic downloading of DID documents in future.

Acknowledgements:

This library was implemented using the .NET NZ Covid Pass verifier by Jed Simson https://github.com/JedS6391/NzCovidPass as a reference.

While this library shares some structure, it is not a direct port. It follows different patterns and practices to suit Swift and iOS. Some parts needed to be added (CBOR and Base32), and some parts have been simplified, however credit must be given to Jed; his implementation helped us develop this library more quickly and to a higher degree of quality.

You might also like...
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.

Features • Classes and Extensions Compatibility • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog • Exa

Vaccine is a framework that aims to make your apps immune to recompile-disease.
Vaccine is a framework that aims to make your apps immune to recompile-disease.

Vaccine Description Vaccine is a framework that aims to make your apps immune to recompile-disease. Vaccine provides a straightforward way to make you

Command line apps for hacking on baseball stats

Thes are some swift command line apps I use to hack on my roto baseball league. No warranty or claim of usability what-so-ever. This represents work I

Tools and helpers to make building apps faster and safer.

The UBFoundation framework provides a set of useful tools and helpers to make building apps faster and safer.

BFKit is a collection of useful classes and categories to develop Apps faster.

Swift Version • What does it do • Language support • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog •

Project shows how to unit test asynchronous API calls in Swift using Mocking without using any 3rd party software

UnitTestingNetworkCalls-Swift Project shows how to unit test asynchronous API ca

TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app.
TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app.

TypeStyle TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app. Featu

A way to easily add Cocoapod licenses and App Version to your iOS App using the Settings Bundle
A way to easily add Cocoapod licenses and App Version to your iOS App using the Settings Bundle

EasyAbout Requirements: cocoapods version 1.4.0 or above. Why you should use Well, it is always nice to give credit to the ones who helped you 😃 Bonu

Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

Owner
Gallagher Security
Gallagher Security
Generate and Preview Passbook Passes

Note: This project is no longer being maintained. Passbook is an iOS 6 feature that manages boarding passes, movie tickets, retail coupons, & loyalty

Nomad CLI 324 Dec 21, 2022
What's new in Swift 5.x

wnis Resources What's new in Swift? Swift CHANGELOG Swift Evolution Usage $ swift run What's new in Swift (5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6): Examp

Zach Eriksen 2 Apr 3, 2022
Showcase new features after an app update similar to Pages, Numbers and Keynote.

WhatsNew Description WhatsNew automatically displays a short description of the new features when users update your app. This is similar to what happe

Patrick Balestra 1.5k Jan 4, 2023
WhatsNewKit enables you to easily showcase your awesome new app features.

WhatsNewKit enables you to easily showcase your awesome new app features. It's designed from the ground up to be fully customized to your needs. Featu

Sven Tiigi 2.8k Jan 3, 2023
Backports the new @Invalidating property wrapper to older platforms

ViewInvalidating A property wrapper that backports the new @Invalidating property wrapper to older versions of iOS/tvOS/macOS. For more information on

Suyash Srijan 61 Nov 23, 2022
IOS-Bootcamp-Examples - Learn to Swift while building apps - With IOS Development Bootcamp

IOS-Bootcamp-Examples Learn to Swift while building apps - With IOS Development

Bilge Çakar 9 Dec 21, 2022
Updeto is a simple package that help update checker for iOS Apps

Updeto is a simple package that will help you to check if the currently installed version is the same as the latest one available on App Store.

Manuel Sánchez 8 Jul 8, 2022
Message passing between iOS apps and extensions.

MMWormhole MMWormhole creates a bridge between an iOS or OS X extension and its containing application. The wormhole is meant to be used to pass data

Mutual Mobile 3.9k Dec 28, 2022
An open source Instapaper clone that features apps and extensions that use native UI Components for Mac and iOS.

TODO: Screenshot outdated Hipstapaper - iOS and Mac Reading List App A macOS, iOS, and iPadOS app written 100% in SwiftUI. Hipstapaper is an app that

Jeffrey Bergier 51 Nov 15, 2022