mirror of
https://github.com/status-im/react-native-status-keycard.git
synced 2025-02-28 12:00:36 +00:00
add verifyPin and changePin methods
This commit is contained in:
parent
b2cf1b0a7a
commit
d2db19f49f
@ -256,4 +256,26 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void verifyPin(final String pairing, final String pin, final Promise promise) {
|
||||
try {
|
||||
smartCard.verifyPin(pairing, pin);
|
||||
promise.resolve(true);
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void changePin(final String pairing, final String currentPin, final String newPin, final Promise promise) {
|
||||
try {
|
||||
smartCard.changePin(pairing, currentPin, newPin);
|
||||
promise.resolve(true);
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -367,4 +367,27 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
return init();
|
||||
}
|
||||
|
||||
public KeycardCommandSet verifyPin(final String pairingBase64, final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
|
||||
cmdSet.select().checkOK();
|
||||
|
||||
Pairing pairing = new Pairing(pairingBase64);
|
||||
cmdSet.setPairing(pairing);
|
||||
|
||||
cmdSet.autoOpenSecureChannel();
|
||||
Log.i(TAG, "secure channel opened");
|
||||
|
||||
cmdSet.verifyPIN(pin).checkOK();
|
||||
Log.i(TAG, "pin verified");
|
||||
|
||||
return cmdSet;
|
||||
}
|
||||
|
||||
public void changePin(final String pairingBase64, final String currentPin, final String newPin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = verifyPin(pairingBase64, currentPin);
|
||||
|
||||
cmdSet.changePIN(0, newPin);
|
||||
Log.i(TAG, "pin changed");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user