diff --git a/android/src/main/java/im/status/ethereum/keycard/RNStatusKeycardModule.java b/android/src/main/java/im/status/ethereum/keycard/RNStatusKeycardModule.java index 062b187..6b317ae 100644 --- a/android/src/main/java/im/status/ethereum/keycard/RNStatusKeycardModule.java +++ b/android/src/main/java/im/status/ethereum/keycard/RNStatusKeycardModule.java @@ -341,6 +341,36 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements }).start(); } + @ReactMethod + public void changePairingPassword(final String pin, final String pairingPassword, final Promise promise) { + new Thread(new Runnable() { + public void run() { + try { + smartCard.changePairingPassword(pin, pairingPassword); + promise.resolve(true); + } catch (IOException | APDUException e) { + Log.d(TAG, e.getMessage()); + promise.reject(e); + } + } + }).start(); + } + + @ReactMethod + public void changePUK(final String pin, final String puk, final Promise promise) { + new Thread(new Runnable() { + public void run() { + try { + smartCard.changePUK(pin, puk); + promise.resolve(true); + } catch (IOException | APDUException e) { + Log.d(TAG, e.getMessage()); + promise.reject(e); + } + } + }).start(); + } + @ReactMethod public void changePin(final String currentPin, final String newPin, final Promise promise) { new Thread(new Runnable() { diff --git a/android/src/main/java/im/status/ethereum/keycard/SmartCard.java b/android/src/main/java/im/status/ethereum/keycard/SmartCard.java index 47289a3..6f4d167 100644 --- a/android/src/main/java/im/status/ethereum/keycard/SmartCard.java +++ b/android/src/main/java/im/status/ethereum/keycard/SmartCard.java @@ -405,10 +405,24 @@ public class SmartCard extends BroadcastReceiver implements CardListener { return 3; } + public void changePairingPassword(final String pin, final String pairingPassword) throws IOException, APDUException { + KeycardCommandSet cmdSet = authenticatedCommandSet(pin); + + cmdSet.changePairingPassword(pairingPassword); + Log.i(TAG, "pairing password changed"); + } + + public void changePUK(final String pin, final String puk) throws IOException, APDUException { + KeycardCommandSet cmdSet = authenticatedCommandSet(pin); + + cmdSet.changePUK(puk); + Log.i(TAG, "puk changed"); + } + public void changePin(final String currentPin, final String newPin) throws IOException, APDUException { KeycardCommandSet cmdSet = authenticatedCommandSet(currentPin); - cmdSet.changePIN(0, newPin); + cmdSet.changePIN(newPin); Log.i(TAG, "pin changed"); } diff --git a/ios/SmartCard.swift b/ios/SmartCard.swift index 63ed595..aa65c0a 100644 --- a/ios/SmartCard.swift +++ b/ios/SmartCard.swift @@ -243,6 +243,20 @@ class SmartCard { resolve(3) } + func changePairingPassword(channel: CardChannel, pin: String, pairingPassword: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void { + let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin) + try cmdSet.changePairingPassword(pairingPassword: pairingPassword).checkOK() + os_log("pairing password changed") + resolve(true) + } + + func changePUK(channel: CardChannel, pin: String, puk: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void { + let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin) + try cmdSet.changePUK(puk: puk).checkOK() + os_log("puk changed") + resolve(true) + } + func changePin(channel: CardChannel, currentPin: String, newPin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void { let cmdSet = try authenticatedCommandSet(channel: channel, pin: currentPin) try cmdSet.changePIN(pin: newPin).checkOK() diff --git a/ios/StatusKeycard.m b/ios/StatusKeycard.m index bef9f7b..218d404 100644 --- a/ios/StatusKeycard.m +++ b/ios/StatusKeycard.m @@ -23,6 +23,8 @@ RCT_EXTERN_METHOD(signPinless:(NSString *)hash resolve:(RCTPromiseResolveBlock)r RCT_EXTERN_METHOD(installApplet:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(installAppletAndInitCard:(String *)pin resolve: (RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(verifyPin:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) +RCT_EXTERN_METHOD(changePairingPassword:(NSString *)pin pairingPassword:(NSString *)pairingPassword resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) +RCT_EXTERN_METHOD(changePUK:(NSString *)pin puk:(NSString *)puk resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(changePin:(NSString *)currentPin newPin:(NSString *)newPin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(unblockPin:(NSString *)puk newPin:(NSString *)newPin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(unpair:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) diff --git a/ios/StatusKeycard.swift b/ios/StatusKeycard.swift index c636f44..5921c4c 100644 --- a/ios/StatusKeycard.swift +++ b/ios/StatusKeycard.swift @@ -118,6 +118,16 @@ class StatusKeycard: RCTEventEmitter { keycardInvokation(reject) { [unowned self] channel in try self.smartCard.verifyPin(channel: channel, pin: pin, resolve: resolve, reject: reject) } } + @objc + func changePairingPassword(_ pin: String, pairingPassword: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + keycardInvokation(reject) { [unowned self] channel in try self.smartCard.changePairingPassword(channel: channel, pin: pin, pairingPassword: pairingPassword, resolve: resolve, reject: reject) } + } + + @objc + func changePUK(_ pin: String, puk: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + keycardInvokation(reject) { [unowned self] channel in try self.smartCard.changePUK(channel: channel, pin: pin, puk: puk, resolve: resolve, reject: reject) } + } + @objc func changePin(_ currentPin: String, newPin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { keycardInvokation(reject) { [unowned self] channel in try self.smartCard.changePin(channel: channel, currentPin: currentPin, newPin: newPin, resolve: resolve, reject: reject) } diff --git a/package.json b/package.json index a75fc28..c93c700 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-status-keycard", "homepage": "https://keycard.status.im/", - "version": "2.5.33", + "version": "2.5.34", "description": "React Native library to interact with Status Keycard using NFC connection (Android only)", "main": "index.js", "scripts": {