Compare commits

...
Author SHA1 Message Date
Michele Balistreri f431c7d6cb use compatible bc 2020-11-09 12:04:56 +01:00
Bitgamma c19d58bb5d Merge pull request #29 from bitgamma/sdk-302-compat
upgrade to SDK 3.0.2, handle IO errors separately from APDU errors
2020-06-25 09:44:40 +03:00
Bitgamma ff570d4720 Merge pull request #30 from bitgamma/stop-start-nfc
do not store references to Activity. Start and stop reader as needed
2020-06-05 13:33:53 +03:00
Michele Balistreri c0d09e3a49 dont explicitly stop the reader 2020-06-05 12:08:30 +03:00
Michele Balistreri d5feacb4ee add null handling 2020-06-05 10:19:01 +03:00
Michele Balistreri eeeaa26819 do not store references to Activity. Start and stop reader as needed 2020-06-05 09:01:34 +03:00
Michele Balistreri 29b3a3c578 upgrade to SDK 3.0.2, handle IO errors separately from APDU errors 2020-06-04 08:04:57 +03:00
Bitgamma b7fe831dd7 Merge pull request #27 from bitgamma/master
make compatible with 2.1 Keycard applet
2020-05-18 17:33:05 +03:00
Bitgamma 26db8dfd25 Merge pull request #1 from status-im/master
sync
2020-05-18 15:19:29 +03:00
Michele Balistreri 59052a36d7 make compatible with 2.1 Keycard applet 2020-05-18 13:36:18 +03:00
Bitgamma 900de62a4c Merge pull request #23 from bitgamma/master
avoid NVM writes (to improve login speed with Keycard)
2020-04-16 11:20:47 +03:00
Michele Balistreri 267bf1184f restore compatibility with current status-react 2020-04-16 10:12:34 +03:00
Roman Volosovskyi 38ca8597e2 Add nfc state events 2020-03-05 14:54:40 +02:00
Michele Balistreri cf7e3138c9 remove redundant derivation 2020-01-09 15:48:52 +03:00
Vitaliy Vlasov 8fb12850d7 Update status-keycard-java to 3.0.1 2019-12-27 18:31:15 +02:00
Vitaliy Vlasov 73c41d1a3d Add exportKeyWithPath() fn 2019-12-27 16:32:51 +02:00
Michele Balistreri 905bcb6f0d avoid NVM writes 2019-12-23 17:03:11 +01:00
Vitaliy Vlasov 29fe98beb3 Add signPinless 2019-12-05 13:36:21 +02:00
Roman Volosovskyi 79a7576ee1 fix master key address exporting 2019-11-27 09:57:50 +02:00
Roman Volosovskyi c9fbb9a3f3 Return master key address and public key
Before this commit `Keycard.generateAndLoadKey` and
`Keyacrd.getKeys` methods returned wallet root key address and public
key in "address" and "public-key" fields correspondingly. This caused
discrepancy in the way how keys were used for on-device and keycard
accounts in Status app. For on-device accounts master key address
was used as account's deterministic id, when keycard accounts used
wallet root key address for this purpose.
2019-11-19 11:12:46 +02:00
WoosangKim 2d5893d562 add thread to avoid main thread freezing 2019-11-07 11:14:31 +01:00
Dmitry Novotochinov c97d629a7d update docs 2019-10-03 15:33:24 +03:00
Dmitry Novotochinov 34a76aeef9 2.5.12 2019-09-30 15:22:49 +03:00
Dmitry Novotochinov 3638d7ee42 add more data to getKeys() output 2019-09-30 15:22:26 +03:00
Dmitry Novotochinov 1e0f6e30c8 2.5.11 2019-09-05 18:50:43 +03:00
Dmitry Novotochinov 8fe4af0da8 derive root key at m/44'/60'/0'/0 2019-09-05 18:50:35 +03:00
Dmitry Novotochinov 8027427b1a 2.5.10 2019-09-05 12:19:40 +03:00
Dmitry Novotochinov 2718a08879 export root path key 2019-09-05 12:19:29 +03:00
Dmitry Novotochinov 0b1b319e8e 2.5.9 2019-09-05 11:21:40 +03:00
Dmitry Novotochinov d6bac19ca0 add root address and public key 2019-09-05 11:21:19 +03:00
Dmitry Novotochinov 3febebfba1 2.5.8 2019-08-20 23:01:11 +03:00
Dmitry Novotochinov da4eb7bdbe add root address and public key to generateAndLoadKey() response 2019-08-20 23:01:11 +03:00
Dmitry Novotochinov edb34edbfb 2.5.7 2019-08-02 13:57:31 +03:00
Dmitry Novotochinov a891033668 add whisper-address to getKeys() response 2019-08-02 13:57:13 +03:00
Dmitry Novotochinov 33653e7c57 2.5.6 2019-08-01 20:44:26 +03:00
Dmitry Novotochinov 48f645145d add wallet-public-key to generate keys response 2019-08-01 20:43:15 +03:00
5 changed files with 370 additions and 135 deletions
+6 -1
View File
@@ -23,6 +23,11 @@ android {
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
@@ -41,5 +46,5 @@ dependencies {
implementation 'com.facebook.react:react-native:+'
implementation 'org.bouncycastle:bcprov-jdk15on:1.60'
implementation 'org.apache.commons:commons-lang3:3.9'
implementation 'com.github.status-im.status-keycard-java:android:2.2.1'
implementation 'com.github.status-im.status-keycard-java:android:3.0.2'
}
@@ -41,9 +41,10 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
@Override
public void onHostResume() {
if (this.smartCard == null) {
this.smartCard = new SmartCard(getCurrentActivity(), reactContext);
smartCard.start();
this.smartCard = new SmartCard(reactContext);
}
smartCard.start(getCurrentActivity());
}
@Override
@@ -52,13 +53,12 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
@Override
public void onHostDestroy() {
}
@ReactMethod
public void nfcIsSupported(final Promise promise) {
if (smartCard != null) {
promise.resolve(smartCard.isNfcSupported());
promise.resolve(smartCard.isNfcSupported(getCurrentActivity()));
} else {
promise.resolve(false);
}
@@ -148,13 +148,17 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
@ReactMethod
public void saveMnemonic(final String mnemonic, final String pairing, final String pin, final Promise promise) {
try {
smartCard.saveMnemonic(mnemonic, pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
smartCard.saveMnemonic(mnemonic, pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
@@ -173,25 +177,48 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
@ReactMethod
public void deriveKey(final String path, final String pairing, final String pin, final Promise promise) {
try {
smartCard.deriveKey(path, pairing, pin);
promise.resolve(path);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
smartCard.deriveKey(path, pairing, pin);
promise.resolve(path);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void exportKey(final String pairing, final String pin, final Promise promise) {
try {
promise.resolve(smartCard.exportKey(pairing, pin));
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
promise.resolve(smartCard.exportKey(pairing, pin));
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).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() {
@@ -220,6 +247,34 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
}).start();
}
@ReactMethod
public void signWithPath(final String pairing, final String pin, final String path, final String hash, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
promise.resolve(smartCard.signWithPath(pairing, pin, path, hash));
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void signPinless(final String hash, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
promise.resolve(smartCard.signPinless(hash));
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void installApplet(final Promise promise) {
final ReactContext ctx = this.reactContext;
@@ -254,96 +309,127 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void verifyPin(final String pairing, final String pin, final Promise promise) {
try {
promise.resolve(smartCard.verifyPin(pairing, pin));
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
promise.resolve(smartCard.verifyPin(pairing, pin));
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@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);
}
new Thread(new Runnable() {
public void run() {
try {
smartCard.changePin(pairing, currentPin, newPin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void unblockPin(final String pairing, final String puk, final String newPin, final Promise promise) {
try {
smartCard.unblockPin(pairing, puk, newPin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
smartCard.unblockPin(pairing, puk, newPin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void unpair(final String pairing, final String pin, final Promise promise) {
try {
smartCard.unpair(pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
smartCard.unpair(pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void delete(final Promise promise) {
try {
smartCard.delete();
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
smartCard.delete();
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void removeKey(final String pairing, final String pin, final Promise promise) {
try {
smartCard.removeKey(pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
smartCard.removeKey(pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void removeKeyWithUnpair(final String pairing, final String pin, final Promise promise) {
try {
smartCard.removeKeyWithUnpair(pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
smartCard.removeKeyWithUnpair(pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void unpairAndDelete(final String pairing, final String pin, final Promise promise) {
try {
smartCard.unpairAndDelete(pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
new Thread(new Runnable() {
public void run() {
try {
smartCard.unpairAndDelete(pairing, pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
}
}
@@ -31,6 +31,7 @@ import im.status.keycard.android.NFCCardManager;
import im.status.keycard.applet.ApplicationStatus;
import im.status.keycard.applet.BIP32KeyPair;
import im.status.keycard.applet.Mnemonic;
import im.status.keycard.applet.CashCommandSet;
import im.status.keycard.applet.KeycardCommandSet;
import im.status.keycard.applet.Pairing;
import im.status.keycard.applet.ApplicationInfo;
@@ -40,25 +41,22 @@ import org.bouncycastle.util.encoders.Hex;
public class SmartCard extends BroadcastReceiver implements CardListener {
private NFCCardManager cardManager;
private Activity activity;
private ReactContext reactContext;
private NfcAdapter nfcAdapter;
private CardChannel cardChannel;
private EventEmitter eventEmitter;
private static final String TAG = "SmartCard";
private Boolean started = false;
private static final String MASTER_PATH = "m";
private static final String ROOT_PATH = "m/44'/60'/0'/0";
private static final String WALLET_PATH = "m/44'/60'/0'/0/0";
private static final String WHISPER_PATH = "m/43'/60'/1581'/0'/0";
private static final String ENCRYPTION_PATH = "m/43'/60'/1581'/1'/0";
private static final int WORDS_LIST_SIZE = 2048;
public SmartCard(Activity activity, ReactContext reactContext) {
public SmartCard(ReactContext reactContext) {
this.cardManager = new NFCCardManager();
this.cardManager.setCardListener(this);
this.activity = activity;
this.reactContext = reactContext;
this.nfcAdapter = NfcAdapter.getDefaultAdapter(activity.getBaseContext());
this.eventEmitter = new EventEmitter(reactContext);
}
@@ -70,23 +68,31 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
Log.d(TAG, s);
}
public boolean start() {
if (!started) {
public boolean start(Activity activity) {
if(activity == null) {
return false;
}
if (!started) {
this.nfcAdapter = NfcAdapter.getDefaultAdapter(activity.getBaseContext());
this.cardManager.start();
started = true;
}
if (this.nfcAdapter != null) {
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
activity.registerReceiver(this, filter);
nfcAdapter.enableReaderMode(activity, this.cardManager, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null);
return true;
} else {
log("not support in this device");
return false;
}
} else {
if (this.nfcAdapter != null) {
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
activity.registerReceiver(this, filter);
nfcAdapter.enableReaderMode(activity, this.cardManager, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null);
return true;
} else {
log("not support in this device");
return false;
}
}
public void stop(Activity activity) {
if (activity != null && nfcAdapter != null) {
nfcAdapter.disableReaderMode(activity);
}
}
@@ -107,16 +113,20 @@ 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");
}
}
public boolean isNfcSupported() {
return activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);
public boolean isNfcSupported(Activity activity) {
return activity != null && activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);
}
public boolean isNfcEnabled() {
@@ -226,14 +236,18 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
Boolean isPaired = false;
if (pairingBase64.length() > 0) {
try {
Pairing pairing = new Pairing(pairingBase64);
cmdSet.setPairing(pairing);
Pairing pairing = new Pairing(pairingBase64);
cmdSet.setPairing(pairing);
try {
cmdSet.autoOpenSecureChannel();
Log.i(TAG, "secure channel opened");
isPaired = true;
} catch(APDUException e) {
Log.i(TAG, "autoOpenSecureChannel failed: " + e.getMessage());
}
if (isPaired) {
ApplicationStatus status = new ApplicationStatus(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_APPLICATION).checkOK().getData());
Log.i(TAG, "PIN retry counter: " + status.getPINRetryCount());
@@ -241,8 +255,6 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
cardInfo.putInt("pin-retry-counter", status.getPINRetryCount());
cardInfo.putInt("puk-retry-counter", status.getPUKRetryCount());
} catch (IOException | IllegalArgumentException e) {
Log.i(TAG, "autoOpenSecureChannel failed: " + e.getMessage());
}
}
@@ -274,8 +286,10 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
KeyPath currentPath = new KeyPath(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_KEY_PATH).checkOK().getData());
Log.i(TAG, "Current key path: " + currentPath);
cmdSet.deriveKey(path).checkOK();
Log.i(TAG, "Derived " + path);
if (!currentPath.toString().equals(path)) {
cmdSet.deriveKey(path).checkOK();
Log.i(TAG, "Derived " + path);
}
}
public String exportKey(final String pairingBase64, final String pin) throws IOException, APDUException {
@@ -296,6 +310,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();
@@ -309,20 +341,36 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
cmdSet.verifyPIN(pin).checkOK();
Log.i(TAG, "pin verified");
byte[] tlv = cmdSet.exportKey(WALLET_PATH, true, true).checkOK().getData();
BIP32KeyPair walletKeyPair = BIP32KeyPair.fromTLV(tlv);
byte[] tlvEncryption = cmdSet.exportKey(ENCRYPTION_PATH, false, false).checkOK().getData();
BIP32KeyPair encryptionKeyPair = BIP32KeyPair.fromTLV(tlvEncryption);
byte[] tlv2 = cmdSet.exportKey(WHISPER_PATH, false, false).checkOK().getData();
BIP32KeyPair whisperKeyPair = BIP32KeyPair.fromTLV(tlv2);
byte[] tlvMaster = cmdSet.exportKey(MASTER_PATH, false, true).checkOK().getData();
BIP32KeyPair masterPair = BIP32KeyPair.fromTLV(tlvMaster);
byte[] tlv3 = cmdSet.exportKey(ENCRYPTION_PATH, false, false).checkOK().getData();
BIP32KeyPair encryptionKeyPair = BIP32KeyPair.fromTLV(tlv3);
byte[] tlvRoot = cmdSet.exportKey(ROOT_PATH, false, true).checkOK().getData();
BIP32KeyPair keyPair = BIP32KeyPair.fromTLV(tlvRoot);
byte[] tlvWhisper = cmdSet.exportKey(WHISPER_PATH, false, false).checkOK().getData();
BIP32KeyPair whisperKeyPair = BIP32KeyPair.fromTLV(tlvWhisper);
byte[] tlvWallet = cmdSet.exportKey(WALLET_PATH, true, true).checkOK().getData();
BIP32KeyPair walletKeyPair = BIP32KeyPair.fromTLV(tlvWallet);
ApplicationInfo info = new ApplicationInfo(cmdSet.select().checkOK().getData());
WritableMap data = Arguments.createMap();
data.putString("address", Hex.toHexString(masterPair.toEthereumAddress()));
data.putString("public-key", Hex.toHexString(masterPair.getPublicKey()));
data.putString("wallet-root-address", Hex.toHexString(keyPair.toEthereumAddress()));
data.putString("wallet-root-public-key", Hex.toHexString(keyPair.getPublicKey()));
data.putString("wallet-address", Hex.toHexString(walletKeyPair.toEthereumAddress()));
data.putString("wallet-public-key", Hex.toHexString(walletKeyPair.getPublicKey()));
data.putString("whisper-address", Hex.toHexString(whisperKeyPair.toEthereumAddress()));
data.putString("whisper-public-key", Hex.toHexString(whisperKeyPair.getPublicKey()));
data.putString("whisper-private-key", Hex.toHexString(whisperKeyPair.getPrivateKey()));
data.putString("encryption-public-key", Hex.toHexString(encryptionKeyPair.getPublicKey()));
data.putString("instance-uid", Hex.toHexString(info.getInstanceUID()));
data.putString("key-uid", Hex.toHexString(info.getKeyUID()));
return data;
}
@@ -343,31 +391,34 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
byte[] seed = Mnemonic.toBinarySeed(mnemonic, "");
BIP32KeyPair keyPair = BIP32KeyPair.fromBinarySeed(seed);
cmdSet.loadKey(keyPair);
cmdSet.loadKey(keyPair).checkOK();
log("keypair loaded to card");
cmdSet.deriveKey(WALLET_PATH).checkOK();
Log.i(TAG, "Derived " + WALLET_PATH);
byte[] tlvRoot = cmdSet.exportKey(ROOT_PATH, false, true).checkOK().getData();
Log.i(TAG, "Derived " + ROOT_PATH);
BIP32KeyPair rootKeyPair = BIP32KeyPair.fromTLV(tlvRoot);
byte[] tlv = cmdSet.exportCurrentKey(true).checkOK().getData();
BIP32KeyPair walletKeyPair = BIP32KeyPair.fromTLV(tlv);
cmdSet.deriveKey(WHISPER_PATH).checkOK();
byte[] tlvWhisper = cmdSet.exportKey(WHISPER_PATH, false, false).checkOK().getData();
Log.i(TAG, "Derived " + WHISPER_PATH);
BIP32KeyPair whisperKeyPair = BIP32KeyPair.fromTLV(tlvWhisper);
byte[] tlv2 = cmdSet.exportCurrentKey(false).checkOK().getData();
BIP32KeyPair whisperKeyPair = BIP32KeyPair.fromTLV(tlv2);
cmdSet.deriveKey(ENCRYPTION_PATH).checkOK();
byte[] tlvEncryption = cmdSet.exportKey(ENCRYPTION_PATH, false, false).checkOK().getData();
Log.i(TAG, "Derived " + ENCRYPTION_PATH);
BIP32KeyPair encryptionKeyPair = BIP32KeyPair.fromTLV(tlvEncryption);
byte[] tlv3 = cmdSet.exportCurrentKey(false).checkOK().getData();
BIP32KeyPair encryptionKeyPair = BIP32KeyPair.fromTLV(tlv3);
byte[] tlvWallet = cmdSet.exportKey(WALLET_PATH, true, true).checkOK().getData();
Log.i(TAG, "Derived " + WALLET_PATH);
BIP32KeyPair walletKeyPair = BIP32KeyPair.fromTLV(tlvWallet);
ApplicationInfo info = new ApplicationInfo(cmdSet.select().checkOK().getData());
WritableMap data = Arguments.createMap();
data.putString("address", Hex.toHexString(keyPair.toEthereumAddress()));
data.putString("public-key", Hex.toHexString(keyPair.getPublicKey()));
data.putString("wallet-root-address", Hex.toHexString(rootKeyPair.toEthereumAddress()));
data.putString("wallet-root-public-key", Hex.toHexString(rootKeyPair.getPublicKey()));
data.putString("wallet-address", Hex.toHexString(walletKeyPair.toEthereumAddress()));
data.putString("wallet-public-key", Hex.toHexString(walletKeyPair.getPublicKey()));
data.putString("whisper-address", Hex.toHexString(whisperKeyPair.toEthereumAddress()));
data.putString("whisper-public-key", Hex.toHexString(whisperKeyPair.getPublicKey()));
data.putString("whisper-private-key", Hex.toHexString(whisperKeyPair.getPrivateKey()));
@@ -527,4 +578,71 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
return sig;
}
public String signWithPath(final String pairingBase64, final String pin, final String path, final String message) 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[] hash = Hex.decode(message);
RecoverableSignature signature;
if (cmdSet.getApplicationInfo().getAppVersion() < 0x0202) {
String actualPath = new KeyPath(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_KEY_PATH).checkOK().getData()).toString();
if (!actualPath.equals(path)) {
cmdSet.deriveKey(path).checkOK();
}
signature = new RecoverableSignature(hash, cmdSet.sign(hash).checkOK().getData());
} else {
signature = new RecoverableSignature(hash, cmdSet.signWithPath(hash, path, false).checkOK().getData());
}
Log.i(TAG, "Signed hash: " + Hex.toHexString(hash));
Log.i(TAG, "Recovery ID: " + signature.getRecId());
Log.i(TAG, "R: " + Hex.toHexString(signature.getR()));
Log.i(TAG, "S: " + Hex.toHexString(signature.getS()));
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(signature.getR());
out.write(signature.getS());
out.write(signature.getRecId());
String sig = Hex.toHexString(out.toByteArray());
Log.i(TAG, "Signature: " + sig);
return sig;
}
public String signPinless(final String message) throws IOException, APDUException {
CashCommandSet cmdSet = new CashCommandSet(this.cardChannel);
cmdSet.select().checkOK();
byte[] hash = Hex.decode(message);
RecoverableSignature signature = new RecoverableSignature(hash, cmdSet.sign(hash).checkOK().getData());
Log.i(TAG, "Signed hash: " + Hex.toHexString(hash));
Log.i(TAG, "Recovery ID: " + signature.getRecId());
Log.i(TAG, "R: " + Hex.toHexString(signature.getR()));
Log.i(TAG, "S: " + Hex.toHexString(signature.getS()));
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(signature.getR());
out.write(signature.getS());
out.write(signature.getRecId());
String sig = Hex.toHexString(out.toByteArray());
Log.i(TAG, "Signature: " + sig);
return sig;
}
}
+32 -6
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"));
}
```
@@ -124,7 +126,12 @@ Keycard.generateAndLoadKey(mnemonic, pairing, pin).then(data => console.log(data
`data` object returned:
```javascript
{"wallet-address": "9726cbc67d170307dd80af6416ebe844e7b8eb1c",
{"address": "a89a57f4d3241e6a123ea332241d6f03790075b4",
"public-key": "04cccc3998d0e0b8d56b64fad4d1f025914b8cb72558810c74dd34454fcd6907f6f7429a0726dceec9b93c9060103ff8b2e7daa1cb9a4dd62b7ae1ba2232709555",
"wallet-root-address": "b19a57f4d3241e6a123ea332241d6f03790075b4",
"wallet-root-public-key": "0427cc3998d0e0b8d56b64fad4d1f025914b8cb72558810c74dd34454fcd6907f6f7429a0726dceec9b93c9060103ff8b2e7daa1cb9a4dd62b7ae1ba2232709555",
"wallet-address": "9726cbc67d170307dd80af6416ebe844e7b8eb1c",
"wallet-public-key": "04065670509d295cb8330e02a688eafe83dbbb317486062482725ba1036dba396d635e91afd9a9e7087c0dfeaccf30d2004d092ed250d62b5c75f8bb4c9326d409",
"whisper-address": "438e576b638bff08b2872dd708cf0240811d79af",
"whisper-public-key": "04add221cb97dde8afbf3be27b0bfb3b6842071cb1052abfc3c34d45eba944dc10dcba5d4823fe69148ae17b12ed459237124365c2f46c2b46be9537ce6efa93c8",
"whisper-private-key": "073d77b952b3b92ba66947df53d03b23bc4cc8cf10cbba1060fe25a569c8ee6b",
@@ -133,6 +140,14 @@ Keycard.generateAndLoadKey(mnemonic, pairing, pin).then(data => console.log(data
"key-uid":"a88d46499e5690c6ad637e243e83cf51be3e2c67e48324b2b2def3e6a0492576"}
```
`address` is an address of master key `m`
`public-key` is a public key of master key `m`
`wallet-root-address` is an address of root key `m/44'/60'/0'/0`
`wallet-root-public-key` is public key of root key `m/44'/60'/0'/0`
`wallet-address` is ethereum address of key with derivation path `m/44'/60'/0'/0/0`
`whisper-address` is ethereum address of key with derivation path `m/43'/60'/1581'/0'/0`
@@ -151,12 +166,23 @@ Keycard.getKeys(pairing, pin).then(data => console.log(data));
`data` object contains:
```javascript
{"encryption-public-key": "04d36d64bea374b917bc097646cb4e81061c7b0ab0872207480b886e66fb52d53774e303e2aa07a1107776f312b94663566765a8a75cf0a92b0851017b28b356a1",
{"address": "a89a57f4d3241e6a123ea332241d6f03790075b4",
"public-key": "04cccc3998d0e0b8d56b64fad4d1f025914b8cb72558810c74dd34454fcd6907f6f7429a0726dceec9b93c9060103ff8b2e7daa1cb9a4dd62b7ae1ba2232709555",
"wallet-root-address": "b19a57f4d3241e6a123ea332241d6f03790075b4",
"wallet-root-public-key": "0427cc3998d0e0b8d56b64fad4d1f025914b8cb72558810c74dd34454fcd6907f6f7429a0726dceec9b93c9060103ff8b2e7daa1cb9a4dd62b7ae1ba2232709555",
"wallet-address": "9726cbc67d170307dd80af6416ebe844e7b8eb1c",
"wallet-public-key": "04065670509d295cb8330e02a688eafe83dbbb317486062482725ba1036dba396d635e91afd9a9e7087c0dfeaccf30d2004d092ed250d62b5c75f8bb4c9326d409",
"whisper-address": "438e576b638bff08b2872dd708cf0240811d79af",
"whisper-public-key": "04add221cb97dde8afbf3be27b0bfb3b6842071cb1052abfc3c34d45eba944dc10dcba5d4823fe69148ae17b12ed459237124365c2f46c2b46be9537ce6efa93c8",
"whisper-private-key":"073d77b952b3b92ba66947df53d03b23bc4cc8cf10cbba1060fe25a569c8ee6b",
"wallet-address":"9726cbc67d170307dd80af6416ebe844e7b8eb1c"}
"whisper-private-key": "073d77b952b3b92ba66947df53d03b23bc4cc8cf10cbba1060fe25a569c8ee6b",
"encryption-public-key": "04d36d64bea374b917bc097646cb4e81061c7b0ab0872207480b886e66fb52d53774e303e2aa07a1107776f312b94663566765a8a75cf0a92b0851017b28b356a1",
"instance-uid": "21c0ce19aa9a26efc02fd32078c08527",
"key-uid":"a88d46499e5690c6ad637e243e83cf51be3e2c67e48324b2b2def3e6a0492576"}
```
Response is identical to `generateAndLoadKey`.
Please refer to `generateAndLoadKey` response for detailed description.
### Sign
```javascript
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
@@ -259,4 +285,4 @@ Keycard.installApplet().then(() => console.log("applet installed"));
```
### Keycard CLI
You can also interact with keycard (installing and removing applet, getting card info, etc) using [keycard cli](https://github.com/status-im/keycard-cli). You'll need a USB reader for that.
You can also interact with keycard (installing and removing applet, getting card info, etc) using [keycard cli](https://github.com/status-im/keycard-cli). You'll need a USB reader for that.
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "react-native-status-keycard",
"homepage": "https://keycard.status.im/",
"version": "2.5.5",
"version": "2.5.17",
"description": "React Native library to interact with Status Keycard using NFC connection (Android only)",
"main": "index.js",
"scripts": {