From 14d1e10cf927f93a70292249694852fbade3dc6f Mon Sep 17 00:00:00 2001
From: Eli Zibin <1131641+zibs@users.noreply.github.com>
Date: Thu, 26 Jun 2025 08:14:08 -0700
Subject: [PATCH] Add support for signed JWT passes on Android
- Introduces the `addPassWithSignedJwt` method for Android, allowing passes to be added using signed JWTs. Updates documentation to reflect the new method and clarifies usage of unsigned and signed JWTs.
- Also updates Android build configuration to use Java 17.
---
README.md | 5 +++--
android/build.gradle | 6 +++---
.../com/premieroctet/wallet/RNWalletModule.kt | 9 +++++++++
src/index.ts | 15 +++++++++++++++
4 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index d1ce82b..f4ff41b 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
A module built with [Expo Modules](https://docs.expo.dev/modules/overview/) that provides wallet features for iOS and Android.
-Uses [PassKit](https://developer.apple.com/documentation/passkit/wallet) on iOS, [Google Wallet API](https://developers.google.com/wallet/generic) on Android.
+Uses [PassKit](https://developer.apple.com/documentation/passkit/wallet) on iOS, [Google Wallet API](https://developers.google.com/wallet/generic) on Android. This now supports both signed and unsigned JWTs for Android.
@@ -88,7 +88,8 @@ export default function App() {
#### Methods
- `canAddPasses(): boolean`: Check if the device can add passes.
-- `addPass(urlOrToken: string): Promise`: Add a pass to the wallet. Returns `true` if the pass was added or if its already added. Returns `false` if the user cancelled the operation. `urlOrToken` should be the pkpass URL for iOS, and the pass JWT for Android.
+- `addPass(urlOrToken: string): Promise`: Add a pass to the wallet. Returns `true` if the pass was added or if its already added. Returns `false` if the user cancelled the operation. `urlOrToken` should be the pkpass URL for iOS, and the **unsigned** pass JWT for Android. [Read more here](https://developers.google.com/wallet/generic/android#add-a-pass)
+- `addPassWithSignedJwt(signedJwt: string): Promise`: Add a pass to the wallet using a signed JWT. Returns `true` if the pass was added or if its already added. Returns `false` if the user cancelled the operation. This is for Android only. [Read more here](https://developers.google.com/wallet/generic/android#add-a-pass)
- `hasPass(urlOrToken: string): Promise`: Check if a pass exists in the wallet. Returns `true` if the pass exists, `false` otherwise. On Android, this always returns `false`.
- `removePass(urlOrToken: string): Promise`: Remove a pass from the wallet. On Android, this is no-op. On iOS, make sure you have the correct entitlements. See [documentation](https://developer.apple.com/documentation/passkit/pkpasslibrary/1617083-removepass#discussion).
diff --git a/android/build.gradle b/android/build.gradle
index 8577ad4..43226e0 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -54,12 +54,12 @@ android {
compileSdkVersion safeExtGet("compileSdkVersion", 33)
compileOptions {
- sourceCompatibility JavaVersion.VERSION_11
- targetCompatibility JavaVersion.VERSION_11
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
- jvmTarget = JavaVersion.VERSION_11.majorVersion
+ jvmTarget = JavaVersion.VERSION_17.majorVersion
}
namespace "com.premieroctet.wallet"
diff --git a/android/src/main/java/com/premieroctet/wallet/RNWalletModule.kt b/android/src/main/java/com/premieroctet/wallet/RNWalletModule.kt
index d6e8c3f..f304487 100644
--- a/android/src/main/java/com/premieroctet/wallet/RNWalletModule.kt
+++ b/android/src/main/java/com/premieroctet/wallet/RNWalletModule.kt
@@ -50,6 +50,15 @@ class RNWalletModule : Module() {
addPassPromise = promise
}
+ AsyncFunction("addPassWithSignedJwt") { jwt: String, promise: Promise ->
+ if (appContext.currentActivity == null) {
+ promise.reject(CodedException("Current activity not found"))
+ return@AsyncFunction
+ }
+ walletClient.savePassesJwt(jwt, appContext.currentActivity!!, addToGoogleWalletRequestCode)
+ addPassPromise = promise
+ }
+
OnCreate {
if (appContext.reactContext != null) {
walletClient = Pay.getClient(appContext.reactContext!!.applicationContext)
diff --git a/src/index.ts b/src/index.ts
index 17e5f91..640c81e 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -15,6 +15,21 @@ export function addPass(urlOrToken: string): Promise {
return RNWalletModule.addPass(urlOrToken);
}
+/**
+ * @param signedJwt The signed JWT
+ * @returns boolean indicating if the pass was added
+ *
+ * @platform android
+ */
+export function addPassWithSignedJwt(signedJwt: string): Promise {
+ if (Platform.OS !== "android") {
+ console.warn("RNWallet.addPassWithSignedJwt is only available on Android");
+ return Promise.resolve(false);
+ }
+
+ return RNWalletModule.addPassWithSignedJwt(signedJwt);
+}
+
/**
* @param url The pkpass file url
* @returns boolean indicating if the pass exists in the wallet