Merge pull request #1 from status-im/master

sync
This commit is contained in:
Bitgamma 2020-05-18 15:19:29 +03:00 committed by GitHub
commit 26db8dfd25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 2 deletions

View File

@ -204,6 +204,21 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
}).start();
}
@ReactMethod
public void exportKeyWithPath(final String pairing, final String pin, final String path, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
promise.resolve(smartCard.exportKeyWithPath(pairing, pin, path));
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void getKeys(final String pairing, final String pin, final Promise promise) {
new Thread(new Runnable() {

View File

@ -110,9 +110,13 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
boolean on = false;
switch (state) {
case NfcAdapter.STATE_ON:
eventEmitter.emit("keyCardOnNFCEnabled", null);
log("NFC ON");
break;
case NfcAdapter.STATE_OFF:
eventEmitter.emit("keyCardOnNFCDisabled", null);
log("NFC OFF");
break;
default:
log("other");
}
@ -301,6 +305,24 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
return Hex.toHexString(key);
}
public String exportKeyWithPath(final String pairingBase64, final String pin, final String path) 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");
byte[] key = BIP32KeyPair.fromTLV(cmdSet.exportKey(path, false, true).checkOK().getData()).getPublicKey();
return Hex.toHexString(key);
}
public WritableMap getKeys(final String pairingBase64, final String pin) throws IOException, APDUException {
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
cmdSet.select().checkOK();

View File

@ -11,10 +11,12 @@ import Keycard from "react-native-status-keycard";
```javascript
import { DeviceEventEmitter } from 'react-native';
// Listen to connect/disconnect events
// Listen to connect/disconnect and nfc events
componentDidMount () {
DeviceEventEmitter.addListener("keyCardOnConnected", () => console.log("keycard connected"));
DeviceEventEmitter.addListener("keyCardOnDisconnected", () => console.log("keycard disconnected"));
DeviceEventEmitter.addListener("keyCardOnNFCEnabled", () => console.log("nfc enabled"));
DeviceEventEmitter.addListener("keyCardOnNFCDisabled", () => console.log("nfc disabled"));
}
```

View File

@ -1,7 +1,7 @@
{
"name": "react-native-status-keycard",
"homepage": "https://keycard.status.im/",
"version": "2.5.15",
"version": "2.5.17",
"description": "React Native library to interact with Status Keycard using NFC connection (Android only)",
"main": "index.js",
"scripts": {