expo-passkite
v1.0.2
Published
Generate Apple Wallet passes (.pkpass) and add them to iOS Wallet or Google Wallet
Maintainers
Readme
expo-passkite
Generate Apple Wallet passes (.pkpass) and add them to iOS Wallet or Google Wallet.
Documentation | API Reference | Setup Guide
Installation
npx expo install expo-passkiteConfiguration
Add the config plugin to your app.json or app.config.js:
{
"expo": {
"plugins": [
["expo-passkite", {
"passTypeIdentifiers": ["$(TeamIdentifierPrefix)pass.com.example.myapp"]
}]
]
}
}Then run prebuild:
npx expo prebuildUsage
Creating a Pass
import {
createPassBuilder,
createPass,
PassType,
BarcodeFormat,
PassImageType,
} from 'expo-passkite';
// Build pass data
const builder = createPassBuilder()
.setIdentifiers({
passTypeIdentifier: 'pass.com.example.myapp',
serialNumber: 'E5982H-I2',
teamIdentifier: 'A93A5CM278',
})
.setOrganization({
organizationName: 'Example Inc.',
description: 'Example Store Card',
logoText: 'Example',
})
.setPassType(PassType.StoreCard)
.setColors({
backgroundColor: 'rgb(206, 140, 53)',
foregroundColor: 'rgb(255, 255, 255)',
})
.addPrimaryField({
key: 'balance',
label: 'Balance',
value: '$50.00',
})
.addBarcode({
format: BarcodeFormat.QR,
message: 'https://example.com/card/E5982H-I2',
altText: 'E5982H-I2',
});
const { passData, images } = builder.build();
// Create the pass
const pass = createPass(passData, images);
// Set signing credentials (required for valid passes)
pass.setSigningCredentials({
wwdrCertificate: wwdrCertPem,
signerCertificate: signerCertPem,
signerKey: signerKeyPem,
signerKeyPassphrase: 'password', // if key is encrypted
});
// Generate .pkpass file
const pkpassBuffer = await pass.generate();
// Or generate as base64 for sending to native module
const pkpassBase64 = await pass.generateBase64();Adding to Wallet
import {
addPassToWallet,
canAddPasses,
isPassLibraryAvailable,
containsPass,
} from 'expo-passkite';
// Check if wallet is available
const available = await isPassLibraryAvailable();
const canAdd = await canAddPasses();
if (canAdd) {
// Generate pass as base64
const passBase64 = await pass.generateBase64();
// Add to wallet
const result = await addPassToWallet(passBase64);
if (result.success) {
console.log('Pass added successfully!');
} else {
console.error('Failed to add pass:', result.error);
}
}
// Check if a specific pass exists
const exists = await containsPass('pass.com.example.myapp', 'E5982H-I2');Listening to Events
import { onPassAdded, onPassRemoved } from 'expo-passkite';
// Subscribe to pass added events
const addedSubscription = onPassAdded((event) => {
console.log('Pass added:', event.passTypeIdentifier, event.serialNumber);
});
// Subscribe to pass removed events
const removedSubscription = onPassRemoved((event) => {
console.log('Pass removed:', event.passTypeIdentifier, event.serialNumber);
});
// Clean up
addedSubscription.remove();
removedSubscription.remove();Pass Types
PassType.BoardingPass- Airline, train, bus, boat boarding passesPassType.Coupon- Coupons and offersPassType.EventTicket- Concert, movie, sports event ticketsPassType.StoreCard- Loyalty and membership cardsPassType.Generic- General purpose passes
Signing Passes
To create valid passes that can be added to Apple Wallet, you need:
- Apple Developer Account with Pass Type ID capability
- Pass Type ID registered in Apple Developer Portal
- Pass Type ID Certificate (.p12 or .pem)
- Apple WWDR Certificate (Worldwide Developer Relations)
Obtaining Certificates
- Log in to Apple Developer Portal
- Go to Certificates, Identifiers & Profiles
- Create a Pass Type ID under Identifiers
- Create a Pass Type ID Certificate under Certificates
- Download the WWDR certificate from Apple
Converting Certificates
# Convert .p12 to PEM files
openssl pkcs12 -in pass.p12 -out signerCert.pem -clcerts -nokeys
openssl pkcs12 -in pass.p12 -out signerKey.pem -nocerts -nodesAndroid / Google Wallet
For Android, the addPassToWallet function expects a Google Wallet JWT token instead of a .pkpass file. You'll need to:
- Set up a Google Wallet API account
- Create pass classes and objects via the Google Wallet API
- Generate a signed JWT token server-side
- Pass the JWT to
addPassToWallet
See Google Wallet API documentation for details.
Documentation
For complete documentation, visit seventwo-studio.github.io/passkite
- Getting Started
- Setup Credentials
- Creating Passes
- Pass Types
- Wallet Integration
- API Reference
- TypeScript Types
License
MIT
