Compare commits
142
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3369498c9f | ||
|
|
3bbdf13ef7 | ||
|
|
af61b0213a | ||
|
|
31e057dc04 | ||
|
|
7548329c59 | ||
|
|
8cf7cbff80 | ||
|
|
9679ae2ea5 | ||
|
|
b9f242aa11 | ||
|
|
d1098e969a | ||
|
|
f602fadf80 | ||
|
|
67ba4d5596 | ||
|
|
05f25401ec | ||
|
|
bca8a10e7d | ||
|
|
cb7fc7fb55 | ||
|
|
958adb1e72 | ||
|
|
62421a6fc5 | ||
|
|
ad9cb78c70 | ||
|
|
c867f6d40d | ||
|
|
b65839bfb8 | ||
|
|
5ced24fc82 | ||
|
|
8fc8c734a4 | ||
|
|
ea2e3bedd7 | ||
|
|
d045041604 | ||
|
|
40a2dd360a | ||
|
|
4024884b70 | ||
|
|
2dc8360b6f | ||
|
|
9c09588b8b | ||
|
|
8fd1534891 | ||
|
|
e520e4b8c2 | ||
|
|
58e3031310 | ||
|
|
6d95a0d85d | ||
|
|
ea45d8c7c6 | ||
|
|
2c639d61a2 | ||
|
|
d3bb09466d | ||
|
|
97b4bdcb3c | ||
|
|
b6498e3a7d | ||
|
|
805aaf956c | ||
|
|
44b75fddd2 | ||
|
|
6c36a08ddb | ||
|
|
b3ea0b5bf3 | ||
|
|
9df9f47df5 | ||
|
|
e6292fa3ea | ||
|
|
cd93a1fb11 | ||
|
|
26e01dd0f0 | ||
|
|
9d1c14e1ff | ||
|
|
0755278f1f | ||
|
|
ae19c52317 | ||
|
|
bd2b0ed50e | ||
|
|
6f10bf1dd5 | ||
|
|
6da5774757 | ||
|
|
b3d56547fb | ||
|
|
70b9633252 | ||
|
|
89bb22046c | ||
|
|
f322b67096 | ||
|
|
a7b277e701 | ||
|
|
c944aa7f2b | ||
|
|
3f1e320b7a | ||
|
|
ace294cdd6 | ||
|
|
5350c30a25 | ||
|
|
8d80f25a2e | ||
|
|
98cf9d82ac | ||
|
|
612b74b203 | ||
|
|
a8c8d286c4 | ||
|
|
05853ce367 | ||
|
|
f431c7d6cb | ||
|
|
c19d58bb5d | ||
|
|
ff570d4720 | ||
|
|
c0d09e3a49 | ||
|
|
d5feacb4ee | ||
|
|
eeeaa26819 | ||
|
|
29b3a3c578 | ||
|
|
b7fe831dd7 | ||
|
|
26db8dfd25 | ||
|
|
59052a36d7 | ||
|
|
900de62a4c | ||
|
|
267bf1184f | ||
|
|
38ca8597e2 | ||
|
|
cf7e3138c9 | ||
|
|
8fb12850d7 | ||
|
|
73c41d1a3d | ||
|
|
905bcb6f0d | ||
|
|
29fe98beb3 | ||
|
|
79a7576ee1 | ||
|
|
c9fbb9a3f3 | ||
|
|
2d5893d562 | ||
|
|
c97d629a7d | ||
|
|
34a76aeef9 | ||
|
|
3638d7ee42 | ||
|
|
1e0f6e30c8 | ||
|
|
8fe4af0da8 | ||
|
|
8027427b1a | ||
|
|
2718a08879 | ||
|
|
0b1b319e8e | ||
|
|
d6bac19ca0 | ||
|
|
3febebfba1 | ||
|
|
da4eb7bdbe | ||
|
|
edb34edbfb | ||
|
|
a891033668 | ||
|
|
33653e7c57 | ||
|
|
48f645145d | ||
|
|
fdf2f0e50a | ||
|
|
182dd2b524 | ||
|
|
5a4e9206bb | ||
|
|
033b43f583 | ||
|
|
b495513a09 | ||
|
|
77781391ec | ||
|
|
9db4993920 | ||
|
|
e55c0ef1f8 | ||
|
|
69b84e8c99 | ||
|
|
8f5534a899 | ||
|
|
4ba5e8a771 | ||
|
|
aef6461e32 | ||
|
|
f1f61d8ab2 | ||
|
|
58c9e8e8df | ||
|
|
f2dda77c81 | ||
|
|
348fc01041 | ||
|
|
d9ccdd6a7d | ||
|
|
7b1e6cce65 | ||
|
|
b9a66144b3 | ||
|
|
8032e1c30f | ||
|
|
56069b4b07 | ||
|
|
7f416b0380 | ||
|
|
8cf3cf5785 | ||
|
|
a6da0a7889 | ||
|
|
97de3e6066 | ||
|
|
d6378e434f | ||
|
|
d7854a33bb | ||
|
|
e0448b0960 | ||
|
|
c7a37ffef8 | ||
|
|
9e6df66bfd | ||
|
|
c8b803ab07 | ||
|
|
0bc6dcd93c | ||
|
|
f6fe495046 | ||
|
|
45ca4d49e5 | ||
|
|
8b6fb829bd | ||
|
|
a15dbca837 | ||
|
|
04b0fb6fcb | ||
|
|
2d15fd6d50 | ||
|
|
fcd50896c0 | ||
|
|
4c2aada5dc | ||
|
|
2dffe6aae4 | ||
|
|
0dfa0ecee6 |
+11
-3
@@ -1,4 +1,6 @@
|
||||
/example
|
||||
|
||||
#
|
||||
# OSX
|
||||
#
|
||||
.DS_Store
|
||||
@@ -8,7 +10,7 @@
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
|
||||
|
||||
|
||||
# Xcode
|
||||
#
|
||||
@@ -29,7 +31,7 @@ DerivedData
|
||||
*.ipa
|
||||
*.xcuserstate
|
||||
project.xcworkspace
|
||||
|
||||
|
||||
|
||||
# Android/IntelliJ
|
||||
#
|
||||
@@ -43,4 +45,10 @@ local.properties
|
||||
buck-out/
|
||||
\.buckd/
|
||||
*.keystore
|
||||
|
||||
|
||||
/lib
|
||||
|
||||
# VSCode + Java
|
||||
android/.project
|
||||
android/.settings
|
||||
.vscode
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
|
||||
# react-native-status-keycard
|
||||
# React Native Status Keycard [](https://badge.fury.io/js/react-native-status-keycard)
|
||||
|
||||
React Native library to interact with [Keycard](https://keycard.status.im/) using [Java SDK](https://github.com/status-im/status-keycard-java)
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
@@ -11,18 +14,12 @@
|
||||
|
||||
### Manual installation
|
||||
|
||||
|
||||
#### iOS
|
||||
|
||||
1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
|
||||
2. Go to `node_modules` ➜ `react-native-status-keycard` and add `RNStatusKeycard.xcodeproj`
|
||||
3. In XCode, in the project navigator, select your project. Add `libRNStatusKeycard.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
|
||||
4. Run your project (`Cmd+R`)<
|
||||
Android is the only platform supported by now.
|
||||
|
||||
#### Android
|
||||
|
||||
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
|
||||
- Add `import com.reactlibrary.RNStatusKeycardPackage;` to the imports at the top of the file
|
||||
1. Open up `android/app/src/main/java/[...]/MainApplication.java`
|
||||
- Add `import im.status.ethereum.keycard.RNStatusKeycardPackage;` to the imports at the top of the file
|
||||
- Add `new RNStatusKeycardPackage()` to the list returned by the `getPackages()` method
|
||||
2. Append the following lines to `android/settings.gradle`:
|
||||
```
|
||||
@@ -33,21 +30,15 @@
|
||||
```
|
||||
compile project(':react-native-status-keycard')
|
||||
```
|
||||
4. Add `<uses-permission android:name="android.permission.NFC"/>` to `android/app/src/main/AndroidManifest.xml` to enable NFC permission.
|
||||
|
||||
#### Windows
|
||||
[Read it! :D](https://github.com/ReactWindows/react-native)
|
||||
|
||||
1. In Visual Studio add the `RNStatusKeycard.sln` in `node_modules/react-native-status-keycard/windows/RNStatusKeycard.sln` folder to their solution, reference from their app.
|
||||
2. Open up your `MainPage.cs` app
|
||||
- Add `using Status.Keycard.RNStatusKeycard;` to the usings at the top of the file
|
||||
- Add `new RNStatusKeycardPackage()` to the `List<IReactPackage>` returned by the `Packages` method
|
||||
|
||||
5. Make sure `minSdkVersion` is 18 in `android/build.gradle`.
|
||||
|
||||
## Usage
|
||||
```javascript
|
||||
import RNStatusKeycard from 'react-native-status-keycard';
|
||||
|
||||
// TODO: What to do with the module?
|
||||
RNStatusKeycard;
|
||||
```
|
||||
Take a look into [docs](./docs/usage.md)
|
||||
|
||||
For more usage examples, please refer to https://github.com/status-im/status-react (assuming you can read Clojure)
|
||||
|
||||
For Keycard API documention, please look into https://status.im/keycard_api/
|
||||
|
||||
@@ -23,6 +23,11 @@ android {
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -39,6 +44,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'com.facebook.react:react-native:+'
|
||||
implementation 'com.madgag.spongycastle:core:1.58.0.0'
|
||||
implementation 'com.github.status-im.status-keycard-java:android:2.0.0'
|
||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.60'
|
||||
implementation 'org.apache.commons:commons-lang3:3.9'
|
||||
implementation 'com.github.status-im.status-keycard-java:android:3.0.4'
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.reactlibrary">
|
||||
package="im.status.ethereum.keycard">
|
||||
|
||||
</manifest>
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -14,6 +14,7 @@ import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -23,7 +24,7 @@ import im.status.keycard.io.APDUException;
|
||||
|
||||
public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
|
||||
private static final String TAG = "StatusKeycard";
|
||||
private static final String CAP_FILENAME = "keycard.cap";
|
||||
private static final String CAP_FILENAME = "keycard_v2.2.1.cap";
|
||||
private SmartCard smartCard;
|
||||
private final ReactApplicationContext reactContext;
|
||||
|
||||
@@ -41,8 +42,10 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
|
||||
@Override
|
||||
public void onHostResume() {
|
||||
if (this.smartCard == null) {
|
||||
this.smartCard = new SmartCard(getCurrentActivity(), reactContext);
|
||||
this.smartCard = new SmartCard(reactContext);
|
||||
}
|
||||
|
||||
smartCard.start(getCurrentActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,13 +54,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);
|
||||
}
|
||||
@@ -80,24 +82,11 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void start(final Promise promise) {
|
||||
if (smartCard != null) {
|
||||
if (smartCard.start()) {
|
||||
promise.resolve(true);
|
||||
} else {
|
||||
promise.reject("Error", "Not supported on this device");
|
||||
}
|
||||
} else {
|
||||
promise.reject("Error", "smartCard is not initialized yet");
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void init(final Promise promise) {
|
||||
public void init(final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
SmartCardSecrets s = smartCard.init();
|
||||
SmartCardSecrets s = smartCard.init(pin);
|
||||
|
||||
WritableMap params = Arguments.createMap();
|
||||
params.putString("pin", s.getPin());
|
||||
@@ -131,11 +120,11 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void generateMnemonic(final String pairing, final Promise promise) {
|
||||
public void generateMnemonic(final String words, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.generateMnemonic(pairing));
|
||||
promise.resolve(smartCard.generateMnemonic(words));
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
@@ -145,11 +134,11 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void generateAndLoadKey(final String mnemonic, final String pairing, final String pin, final Promise promise) {
|
||||
public void generateAndLoadKey(final String mnemonic, final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.generateAndLoadKey(mnemonic, pairing, pin));
|
||||
promise.resolve(smartCard.generateAndLoadKey(mnemonic, pin));
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
@@ -159,22 +148,12 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getApplicationInfo(final String pairingBase64, final Promise promise) {
|
||||
public void saveMnemonic(final String mnemonic, final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.getApplicationInfo(pairingBase64));
|
||||
smartCard.saveMnemonic(mnemonic, pin);
|
||||
promise.resolve(true);
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
@@ -184,32 +163,138 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getKeys(final String pairing, final String pin, final Promise promise) {
|
||||
public void getApplicationInfo(final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.getKeys(pairing, pin));
|
||||
promise.resolve(smartCard.getApplicationInfo());
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void factoryReset(final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.factoryReset());
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void deriveKey(final String path, final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
smartCard.deriveKey(path, pin);
|
||||
promise.resolve(path);
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void exportKey(final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.exportKey(pin));
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void exportKeyWithPath(final String pin, final String path, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.exportKeyWithPath(pin, path));
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getKeys(final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.getKeys(pin));
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void importKeys(final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.importKeys(pin));
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void sign(final String pin, final String hash, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.sign(pin, hash));
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void signWithPath(final String pin, final String path, final String hash, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.signWithPath(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);
|
||||
@@ -235,12 +320,12 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void installAppletAndInitCard(final Promise promise) {
|
||||
public void installAppletAndInitCard(final String pin, final Promise promise) {
|
||||
final ReactContext ctx = this.reactContext;
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
SmartCardSecrets s = smartCard.installAppletAndInitCard(ctx.getAssets(), CAP_FILENAME);
|
||||
SmartCardSecrets s = smartCard.installAppletAndInitCard(pin, ctx.getAssets(), CAP_FILENAME);
|
||||
|
||||
WritableMap params = Arguments.createMap();
|
||||
params.putString("pin", s.getPin());
|
||||
@@ -252,74 +337,178 @@ 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);
|
||||
}
|
||||
public void verifyPin(final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
promise.resolve(smartCard.verifyPin(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);
|
||||
}
|
||||
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 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);
|
||||
}
|
||||
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 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);
|
||||
}
|
||||
public void changePin(final String currentPin, final String newPin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
smartCard.changePin(currentPin, newPin);
|
||||
promise.resolve(true);
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void unblockPin(final String puk, final String newPin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
smartCard.unblockPin(puk, newPin);
|
||||
promise.resolve(true);
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void unpair(final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
smartCard.unpair(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 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);
|
||||
}
|
||||
public void removeKey(final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
smartCard.removeKey(pin);
|
||||
promise.resolve(true);
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
@ReactMethod
|
||||
public void removeKeyWithUnpair(final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
smartCard.removeKeyWithUnpair(pin);
|
||||
promise.resolve(true);
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void unpairAndDelete(final String pin, final Promise promise) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
smartCard.unpairAndDelete(pin);
|
||||
promise.resolve(true);
|
||||
} catch (IOException | APDUException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
promise.reject(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
// These three methods below are a nop on Android since NFC is always listening and we have a custom UI. They are needed in iOS to show the NFC dialog
|
||||
@ReactMethod
|
||||
public void startNFC(String prompt, final Promise promise) {
|
||||
promise.resolve(true);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void stopNFC(String error, final Promise promise) {
|
||||
promise.resolve(true);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void setNFCMessage(String message, final Promise promise) {
|
||||
promise.resolve(true);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void setPairings(ReadableMap pairings, final Promise promise) {
|
||||
smartCard.setPairings(pairings);
|
||||
promise.resolve(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,52 +8,61 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.EventLog;
|
||||
import android.util.Log;
|
||||
|
||||
import com.facebook.react.bridge.*;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import im.status.keycard.applet.RecoverableSignature;
|
||||
import im.status.keycard.globalplatform.GlobalPlatformCommandSet;
|
||||
import im.status.keycard.io.APDUException;
|
||||
import im.status.keycard.io.APDUResponse;
|
||||
import im.status.keycard.io.CardChannel;
|
||||
import im.status.keycard.io.CardListener;
|
||||
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;
|
||||
import im.status.keycard.applet.KeyPath;
|
||||
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
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 HashMap<String, String> pairings;
|
||||
|
||||
private static final String WALLET_PATH = "m/44'/0'/0'/0/0";
|
||||
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);
|
||||
this.pairings = new HashMap<>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -64,8 +73,17 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
Log.d(TAG, s);
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
this.cardManager.start();
|
||||
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);
|
||||
@@ -77,6 +95,12 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(Activity activity) {
|
||||
if (activity != null && nfcAdapter != null) {
|
||||
nfcAdapter.disableReaderMode(activity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(final CardChannel channel) {
|
||||
this.cardChannel = channel;
|
||||
@@ -85,7 +109,7 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
eventEmitter.emit( "keyCardOnDisconnected", null);
|
||||
eventEmitter.emit("keyCardOnDisconnected", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,16 +118,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() {
|
||||
@@ -114,13 +142,13 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
}
|
||||
}
|
||||
|
||||
public SmartCardSecrets init() throws IOException, APDUException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
public SmartCardSecrets init(final String userPin) throws IOException, APDUException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
|
||||
cmdSet.select().checkOK();
|
||||
|
||||
eventEmitter.emit("keycardInstallationProgress", 0.90);
|
||||
|
||||
SmartCardSecrets s = SmartCardSecrets.generate();
|
||||
SmartCardSecrets s = SmartCardSecrets.generate(userPin);
|
||||
|
||||
eventEmitter.emit("keycardInstallationProgress", 0.93);
|
||||
|
||||
@@ -133,12 +161,13 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
|
||||
public String pair(String pairingPassword) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
|
||||
log("Pairing password: " + pairingPassword);
|
||||
Log.i(TAG, "Applet selection successful");
|
||||
|
||||
// First thing to do is selecting the applet on the card.
|
||||
ApplicationInfo info = new ApplicationInfo(cmdSet.select().checkOK().getData());
|
||||
Log.i(TAG, "Instance UID: " + Hex.toHexString(info.getInstanceUID()));
|
||||
String instanceUID = Hex.toHexString(info.getInstanceUID());
|
||||
Log.i(TAG, "Instance UID: " + instanceUID);
|
||||
Log.i(TAG, "Key UID: " + Hex.toHexString(info.getKeyUID()));
|
||||
Log.i(TAG, "Secure channel public key: " + Hex.toHexString(info.getSecureChannelPubKey()));
|
||||
Log.i(TAG, "Application version: " + info.getAppVersionString());
|
||||
Log.i(TAG, "Free pairing slots: " + info.getFreePairingSlots());
|
||||
@@ -146,41 +175,30 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
cmdSet.autoPair(pairingPassword);
|
||||
|
||||
Pairing pairing = cmdSet.getPairing();
|
||||
log("Pairing index: " + pairing.getPairingIndex());
|
||||
log("Pairing key: " + Hex.toHexString(pairing.getPairingKey()));
|
||||
log("Pairing toBase64: " + pairing.toBase64());
|
||||
|
||||
pairings.put(instanceUID, pairing.toBase64());
|
||||
return pairing.toBase64();
|
||||
}
|
||||
|
||||
public String generateMnemonic(String pairingBase64) 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");
|
||||
public String generateMnemonic(String words) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = securedCommandSet();
|
||||
|
||||
Mnemonic mnemonic = new Mnemonic(cmdSet.generateMnemonic(KeycardCommandSet.GENERATE_MNEMONIC_12_WORDS).checkOK().getData());
|
||||
mnemonic.fetchBIP39EnglishWordlist();
|
||||
|
||||
Scanner scanner = new Scanner(words);
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
while(scanner.hasNextLine()) {
|
||||
list.add(scanner.nextLine());
|
||||
}
|
||||
scanner.close();
|
||||
|
||||
String [] wordsList = list.toArray(new String[WORDS_LIST_SIZE]);
|
||||
mnemonic.setWordlist(wordsList);
|
||||
|
||||
return mnemonic.toMnemonicPhrase();
|
||||
}
|
||||
|
||||
public void saveMnemonic(String mnemonic, String pairingBase64, 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");
|
||||
public void saveMnemonic(String mnemonic, String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
byte[] seed = Mnemonic.toBinarySeed(mnemonic, "");
|
||||
cmdSet.loadKey(seed);
|
||||
@@ -188,7 +206,23 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
log("seed loaded to card");
|
||||
}
|
||||
|
||||
public WritableMap getApplicationInfo(final String pairingBase64) throws IOException, APDUException {
|
||||
public boolean tryDefaultPairing(KeycardCommandSet cmdSet, String instanceUID, WritableMap cardInfo) throws IOException {
|
||||
try {
|
||||
cmdSet.autoPair("KeycardDefaultPairing");
|
||||
|
||||
Pairing pairing = cmdSet.getPairing();
|
||||
pairings.put(instanceUID, pairing.toBase64());
|
||||
cardInfo.putString("new-pairing", pairing.toBase64());
|
||||
|
||||
openSecureChannel(cmdSet);
|
||||
return true;
|
||||
} catch(APDUException e) {
|
||||
Log.i(TAG, "autoOpenSecureChannel failed: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public WritableMap getApplicationInfo() throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
|
||||
ApplicationInfo info = new ApplicationInfo(cmdSet.select().checkOK().getData());
|
||||
|
||||
@@ -198,24 +232,28 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
cardInfo.putBoolean("initialized?", info.isInitializedCard());
|
||||
|
||||
if (info.isInitializedCard()) {
|
||||
Log.i(TAG, "Instance UID: " + Hex.toHexString(info.getInstanceUID()));
|
||||
String instanceUID = Hex.toHexString(info.getInstanceUID());
|
||||
|
||||
Log.i(TAG, "Instance UID: " + instanceUID);
|
||||
Log.i(TAG, "Key UID: " + Hex.toHexString(info.getKeyUID()));
|
||||
Log.i(TAG, "Secure channel public key: " + Hex.toHexString(info.getSecureChannelPubKey()));
|
||||
Log.i(TAG, "Application version: " + info.getAppVersionString());
|
||||
Log.i(TAG, "Free pairing slots: " + info.getFreePairingSlots());
|
||||
|
||||
if (info.hasMasterKey()) {
|
||||
Log.i(TAG, "Key UID: " + Hex.toHexString(info.getKeyUID()));
|
||||
Boolean isPaired = false;
|
||||
|
||||
if (!pairings.containsKey(instanceUID)) {
|
||||
isPaired = tryDefaultPairing(cmdSet, instanceUID, cardInfo);
|
||||
} else {
|
||||
Log.i(TAG, "The card has no master key");
|
||||
try {
|
||||
openSecureChannel(cmdSet);
|
||||
isPaired = true;
|
||||
} catch(APDUException e) {
|
||||
isPaired = tryDefaultPairing(cmdSet, instanceUID, cardInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (pairingBase64.length() > 0) {
|
||||
Pairing pairing = new Pairing(pairingBase64);
|
||||
cmdSet.setPairing(pairing);
|
||||
|
||||
cmdSet.autoOpenSecureChannel();
|
||||
Log.i(TAG, "secure channel opened");
|
||||
|
||||
if (isPaired) {
|
||||
ApplicationStatus status = new ApplicationStatus(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_APPLICATION).checkOK().getData());
|
||||
|
||||
Log.i(TAG, "PIN retry counter: " + status.getPINRetryCount());
|
||||
@@ -226,7 +264,9 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
}
|
||||
|
||||
cardInfo.putBoolean("has-master-key?", info.hasMasterKey());
|
||||
cardInfo.putBoolean("paired?", isPaired);
|
||||
cardInfo.putString("instance-uid", Hex.toHexString(info.getInstanceUID()));
|
||||
cardInfo.putString("key-uid", Hex.toHexString(info.getKeyUID()));
|
||||
cardInfo.putString("secure-channel-pub-key", Hex.toHexString(info.getSecureChannelPubKey()));
|
||||
cardInfo.putString("app-version", info.getAppVersionString());
|
||||
cardInfo.putInt("free-pairing-slots", info.getFreePairingSlots());
|
||||
@@ -235,132 +275,156 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
return cardInfo;
|
||||
}
|
||||
|
||||
public void deriveKey(final String path, final String pairingBase64, final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
|
||||
public WritableMap factoryReset() throws IOException, APDUException {
|
||||
GlobalPlatformCommandSet cmdSet = new GlobalPlatformCommandSet(this.cardChannel);
|
||||
cmdSet.select().checkOK();
|
||||
Log.i(TAG, "ISD selected");
|
||||
|
||||
Pairing pairing = new Pairing(pairingBase64);
|
||||
cmdSet.setPairing(pairing);
|
||||
cmdSet.openSecureChannel();
|
||||
Log.i(TAG, "SecureChannel opened");
|
||||
|
||||
cmdSet.autoOpenSecureChannel();
|
||||
Log.i(TAG, "secure channel opened");
|
||||
cmdSet.deleteKeycardInstance().checkSW(APDUResponse.SW_OK, APDUResponse.SW_REFERENCED_DATA_NOT_FOUND);
|
||||
Log.i(TAG, "Keycard applet instance deleted");
|
||||
|
||||
cmdSet.verifyPIN(pin).checkOK();
|
||||
Log.i(TAG, "pin verified");
|
||||
cmdSet.installKeycardApplet().checkOK();
|
||||
Log.i(TAG, "Keycard applet instance re-installed");
|
||||
|
||||
ApplicationInfo info = new ApplicationInfo(new KeycardCommandSet(this.cardChannel).select().checkOK().getData());
|
||||
Log.i(TAG, "Selecting the newly installed Keycard applet succeeded");
|
||||
|
||||
WritableMap cardInfo = Arguments.createMap();
|
||||
cardInfo.putBoolean("initialized?", info.isInitializedCard());
|
||||
|
||||
return cardInfo;
|
||||
}
|
||||
|
||||
public void deriveKey(final String path, final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
KeyPath currentPath = new KeyPath(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_KEY_PATH).checkOK().getData());
|
||||
Log.i(TAG, "Current key path: " + currentPath);
|
||||
|
||||
if (!currentPath.toString().equals("m/44'/0'/0'/0/0")) {
|
||||
if (!currentPath.toString().equals(path)) {
|
||||
cmdSet.deriveKey(path).checkOK();
|
||||
Log.i(TAG, "Derived m/44'/0'/0'/0/0");
|
||||
Log.i(TAG, "Derived " + path);
|
||||
}
|
||||
}
|
||||
|
||||
public String exportKey(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");
|
||||
public String exportKey(final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
byte[] key = cmdSet.exportCurrentKey(true).checkOK().getData();
|
||||
|
||||
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();
|
||||
public String exportKeyWithPath(final String pin, final String path) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
Pairing pairing = new Pairing(pairingBase64);
|
||||
cmdSet.setPairing(pairing);
|
||||
byte[] key = BIP32KeyPair.fromTLV(cmdSet.exportKey(path, false, true).checkOK().getData()).getPublicKey();
|
||||
|
||||
cmdSet.autoOpenSecureChannel();
|
||||
Log.i(TAG, "secure channel opened");
|
||||
|
||||
cmdSet.verifyPIN(pin).checkOK();
|
||||
Log.i(TAG, "pin verified");
|
||||
|
||||
|
||||
cmdSet.deriveKey(WALLET_PATH).checkOK();
|
||||
Log.i(TAG, "Derived " + WALLET_PATH);
|
||||
|
||||
byte[] tlv = cmdSet.exportCurrentKey(true).checkOK().getData();
|
||||
BIP32KeyPair walletKeyPair = BIP32KeyPair.fromTLV(tlv);
|
||||
|
||||
|
||||
cmdSet.deriveKey(WHISPER_PATH).checkOK();
|
||||
Log.i(TAG, "Derived " + WHISPER_PATH);
|
||||
|
||||
byte[] tlv2 = cmdSet.exportCurrentKey(false).checkOK().getData();
|
||||
BIP32KeyPair whisperKeyPair = BIP32KeyPair.fromTLV(tlv2);
|
||||
|
||||
|
||||
cmdSet.deriveKey(ENCRYPTION_PATH).checkOK();
|
||||
Log.i(TAG, "Derived " + ENCRYPTION_PATH);
|
||||
|
||||
byte[] tlv3 = cmdSet.exportCurrentKey(false).checkOK().getData();
|
||||
BIP32KeyPair encryptionKeyPair = BIP32KeyPair.fromTLV(tlv3);
|
||||
|
||||
WritableMap data = Arguments.createMap();
|
||||
data.putString("wallet-address", Hex.toHexString(walletKeyPair.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()));
|
||||
|
||||
return data;
|
||||
return Hex.toHexString(key);
|
||||
}
|
||||
|
||||
public WritableMap generateAndLoadKey(final String mnemonic, final String pairingBase64, final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
|
||||
cmdSet.select().checkOK();
|
||||
public WritableMap getKeys(final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
Pairing pairing = new Pairing(pairingBase64);
|
||||
cmdSet.setPairing(pairing);
|
||||
byte[] tlvWhisper = cmdSet.exportKey(WHISPER_PATH, false, false).checkOK().getData();
|
||||
BIP32KeyPair whisperKeyPair = BIP32KeyPair.fromTLV(tlvWhisper);
|
||||
|
||||
cmdSet.autoOpenSecureChannel();
|
||||
Log.i(TAG, "secure channel opened");
|
||||
byte[] tlvEncryption = cmdSet.exportKey(ENCRYPTION_PATH, false, false).checkOK().getData();
|
||||
BIP32KeyPair encryptionKeyPair = BIP32KeyPair.fromTLV(tlvEncryption);
|
||||
|
||||
cmdSet.verifyPIN(pin).checkOK();
|
||||
Log.i(TAG, "pin verified");
|
||||
|
||||
byte[] seed = Mnemonic.toBinarySeed(mnemonic, "");
|
||||
BIP32KeyPair keyPair = BIP32KeyPair.fromBinarySeed(seed);
|
||||
|
||||
cmdSet.loadKey(keyPair);
|
||||
log("keypair loaded to card");
|
||||
|
||||
cmdSet.deriveKey(WALLET_PATH).checkOK();
|
||||
Log.i(TAG, "Derived " + WALLET_PATH);
|
||||
|
||||
byte[] tlv = cmdSet.exportCurrentKey(true).checkOK().getData();
|
||||
BIP32KeyPair walletKeyPair = BIP32KeyPair.fromTLV(tlv);
|
||||
|
||||
cmdSet.deriveKey(WHISPER_PATH).checkOK();
|
||||
Log.i(TAG, "Derived " + WHISPER_PATH);
|
||||
|
||||
byte[] tlv2 = cmdSet.exportCurrentKey(false).checkOK().getData();
|
||||
BIP32KeyPair whisperKeyPair = BIP32KeyPair.fromTLV(tlv2);
|
||||
|
||||
cmdSet.deriveKey(ENCRYPTION_PATH).checkOK();
|
||||
Log.i(TAG, "Derived " + ENCRYPTION_PATH);
|
||||
|
||||
byte[] tlv3 = cmdSet.exportCurrentKey(false).checkOK().getData();
|
||||
BIP32KeyPair encryptionKeyPair = BIP32KeyPair.fromTLV(tlv3);
|
||||
ApplicationInfo info = cmdSet.getApplicationInfo();
|
||||
|
||||
WritableMap data = Arguments.createMap();
|
||||
data.putString("wallet-address", Hex.toHexString(walletKeyPair.toEthereumAddress()));
|
||||
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;
|
||||
}
|
||||
|
||||
public WritableMap importKeys(final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
byte[] tlvEncryption = cmdSet.exportKey(ENCRYPTION_PATH, false, false).checkOK().getData();
|
||||
BIP32KeyPair encryptionKeyPair = BIP32KeyPair.fromTLV(tlvEncryption);
|
||||
|
||||
byte[] tlvMaster = cmdSet.exportKey(MASTER_PATH, false, true).checkOK().getData();
|
||||
BIP32KeyPair masterPair = BIP32KeyPair.fromTLV(tlvMaster);
|
||||
|
||||
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, false, true).checkOK().getData();
|
||||
BIP32KeyPair walletKeyPair = BIP32KeyPair.fromTLV(tlvWallet);
|
||||
|
||||
ApplicationInfo info = cmdSet.getApplicationInfo();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public WritableMap generateAndLoadKey(final String mnemonic, final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
byte[] seed = Mnemonic.toBinarySeed(mnemonic, "");
|
||||
BIP32KeyPair keyPair = BIP32KeyPair.fromBinarySeed(seed);
|
||||
|
||||
cmdSet.loadKey(keyPair).checkOK();
|
||||
log("keypair loaded to card");
|
||||
|
||||
byte[] tlvRoot = cmdSet.exportKey(ROOT_PATH, false, true).checkOK().getData();
|
||||
Log.i(TAG, "Derived " + ROOT_PATH);
|
||||
BIP32KeyPair rootKeyPair = BIP32KeyPair.fromTLV(tlvRoot);
|
||||
|
||||
byte[] tlvWhisper = cmdSet.exportKey(WHISPER_PATH, false, false).checkOK().getData();
|
||||
Log.i(TAG, "Derived " + WHISPER_PATH);
|
||||
BIP32KeyPair whisperKeyPair = BIP32KeyPair.fromTLV(tlvWhisper);
|
||||
|
||||
byte[] tlvEncryption = cmdSet.exportKey(ENCRYPTION_PATH, false, false).checkOK().getData();
|
||||
Log.i(TAG, "Derived " + ENCRYPTION_PATH);
|
||||
BIP32KeyPair encryptionKeyPair = BIP32KeyPair.fromTLV(tlvEncryption);
|
||||
|
||||
byte[] tlvWallet = cmdSet.exportKey(WALLET_PATH, false, 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()));
|
||||
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;
|
||||
}
|
||||
@@ -370,77 +434,53 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
installer.start();
|
||||
}
|
||||
|
||||
public SmartCardSecrets installAppletAndInitCard(AssetManager assets, String capPath) throws IOException, APDUException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
public SmartCardSecrets installAppletAndInitCard(final String userPin, AssetManager assets, String capPath) throws IOException, APDUException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
Installer installer = new Installer(this.cardChannel, assets, capPath, eventEmitter);
|
||||
installer.start();
|
||||
|
||||
return init();
|
||||
return init(userPin);
|
||||
}
|
||||
|
||||
public int 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");
|
||||
|
||||
ApplicationStatus status = new ApplicationStatus(cmdSet.getStatus(KeycardCommandSet.GET_STATUS_P1_APPLICATION).checkOK().getData());
|
||||
|
||||
return status.getPINRetryCount();
|
||||
public int verifyPin(final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
return 3;
|
||||
}
|
||||
|
||||
public void changePin(final String pairingBase64, final String currentPin, final String newPin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
|
||||
cmdSet.select().checkOK();
|
||||
public void changePairingPassword(final String pin, final String pairingPassword) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
Pairing pairing = new Pairing(pairingBase64);
|
||||
cmdSet.setPairing(pairing);
|
||||
cmdSet.changePairingPassword(pairingPassword);
|
||||
Log.i(TAG, "pairing password changed");
|
||||
}
|
||||
|
||||
cmdSet.autoOpenSecureChannel();
|
||||
Log.i(TAG, "secure channel opened");
|
||||
public void changePUK(final String pin, final String puk) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
cmdSet.verifyPIN(currentPin).checkOK();
|
||||
Log.i(TAG, "pin verified");
|
||||
cmdSet.changePUK(puk);
|
||||
Log.i(TAG, "puk changed");
|
||||
}
|
||||
|
||||
cmdSet.changePIN(0, newPin);
|
||||
public void changePin(final String currentPin, final String newPin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(currentPin);
|
||||
|
||||
cmdSet.changePIN(newPin);
|
||||
Log.i(TAG, "pin changed");
|
||||
}
|
||||
|
||||
public void unblockPin(final String pairingBase64, final String puk, final String newPin) 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");
|
||||
public void unblockPin(final String puk, final String newPin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = securedCommandSet();
|
||||
|
||||
cmdSet.unblockPIN(puk, newPin).checkOK();
|
||||
Log.i(TAG, "pin unblocked");
|
||||
}
|
||||
|
||||
public void unpair(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");
|
||||
public void unpair(final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
cmdSet.autoUnpair();
|
||||
Log.i(TAG, "card unpaired");
|
||||
String instanceUID = Hex.toHexString(cmdSet.getApplicationInfo().getInstanceUID());
|
||||
pairings.remove(instanceUID);
|
||||
}
|
||||
|
||||
public void delete() throws IOException, APDUException {
|
||||
@@ -454,9 +494,154 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
|
||||
Log.i(TAG, "instance and package deleted");
|
||||
}
|
||||
|
||||
public void unpairAndDelete(final String pairingBase64, final String pin) throws IOException, APDUException {
|
||||
unpair(pairingBase64, pin);
|
||||
public void removeKey(final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
cmdSet.removeKey();
|
||||
Log.i(TAG, "key removed");
|
||||
}
|
||||
|
||||
public void removeKeyWithUnpair(final String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
cmdSet.removeKey();
|
||||
Log.i(TAG, "key removed");
|
||||
|
||||
cmdSet.unpairOthers();
|
||||
Log.i(TAG, "unpaired others");
|
||||
|
||||
cmdSet.autoUnpair();
|
||||
Log.i(TAG, "card unpaired");
|
||||
|
||||
String instanceUID = Hex.toHexString(cmdSet.getApplicationInfo().getInstanceUID());
|
||||
pairings.remove(instanceUID);
|
||||
}
|
||||
|
||||
public void unpairAndDelete(final String pin) throws IOException, APDUException {
|
||||
unpair(pin);
|
||||
delete();
|
||||
}
|
||||
|
||||
public String sign(final String pin, final String message) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public String signWithPath(final String pin, final String path, final String message) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void setPairings(ReadableMap newPairings) {
|
||||
pairings.clear();
|
||||
Iterator<Map.Entry<String,Object>> i = newPairings.getEntryIterator();
|
||||
while (i.hasNext()) {
|
||||
Map.Entry<String, Object> entry = i.next();
|
||||
String value = ((ReadableMap) entry.getValue()).getString("pairing");
|
||||
pairings.put(entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
|
||||
private KeycardCommandSet authenticatedCommandSet(String pin) throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = securedCommandSet();
|
||||
cmdSet.verifyPIN(pin).checkOK();
|
||||
Log.i(TAG, "pin verified");
|
||||
|
||||
return cmdSet;
|
||||
}
|
||||
|
||||
private KeycardCommandSet securedCommandSet() throws IOException, APDUException {
|
||||
KeycardCommandSet cmdSet = new KeycardCommandSet(this.cardChannel);
|
||||
cmdSet.select().checkOK();
|
||||
openSecureChannel(cmdSet);
|
||||
|
||||
return cmdSet;
|
||||
}
|
||||
|
||||
private void openSecureChannel(KeycardCommandSet cmdSet) throws IOException, APDUException {
|
||||
String instanceUID = Hex.toHexString(cmdSet.getApplicationInfo().getInstanceUID());
|
||||
String pairingBase64 = pairings.get(instanceUID);
|
||||
|
||||
if (pairingBase64 == null) {
|
||||
throw new APDUException("No pairing found");
|
||||
}
|
||||
|
||||
Pairing pairing = new Pairing(pairingBase64);
|
||||
cmdSet.setPairing(pairing);
|
||||
|
||||
cmdSet.autoOpenSecureChannel();
|
||||
Log.i(TAG, "secure channel opened");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package im.status.ethereum.keycard;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Base64;
|
||||
|
||||
import static android.util.Base64.NO_PADDING;
|
||||
import static android.util.Base64.NO_WRAP;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
@@ -27,12 +28,18 @@ public class SmartCardSecrets {
|
||||
this.pairingPassword = pairingPassword;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static SmartCardSecrets generate() throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
String pairingPassword = randomToken(12);
|
||||
public static SmartCardSecrets generate(final String userPin) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
String pairingPassword = "KeycardDefaultPairing";
|
||||
long pinNumber = randomLong(PIN_BOUND);
|
||||
long pukNumber = randomLong(PUK_BOUND);
|
||||
String pin = String.format("%06d", pinNumber);
|
||||
|
||||
String pin;
|
||||
if (userPin.isEmpty()) {
|
||||
pin = String.format("%06d", pinNumber);
|
||||
} else {
|
||||
pin = userPin;
|
||||
}
|
||||
|
||||
String puk = String.format("%012d", pukNumber);
|
||||
|
||||
return new SmartCardSecrets(pin, puk, pairingPassword);
|
||||
@@ -56,7 +63,18 @@ public class SmartCardSecrets {
|
||||
}
|
||||
|
||||
public static String randomToken(int length) {
|
||||
return Base64.encodeToString(randomBytes(length), NO_PADDING);
|
||||
SecureRandom random = new SecureRandom();
|
||||
char[] possibleCharacters = "abcdefghijkmnpqrstuvwxyz".toCharArray();
|
||||
char[] possibleDigits = "23456789".toCharArray();
|
||||
StringBuffer buffer = new StringBuffer(length);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
char[] src = (i % 2) == 0 ? possibleCharacters : possibleDigits;
|
||||
int idx = random.nextInt(src.length);
|
||||
buffer.append(src[idx]);
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static byte[] randomBytes(int length) {
|
||||
|
||||
+288
@@ -0,0 +1,288 @@
|
||||
# Usage
|
||||
|
||||
You need to import Keycard object to interact with the card:
|
||||
|
||||
```javascript
|
||||
import Keycard from "react-native-status-keycard";
|
||||
```
|
||||
|
||||
### Listen to keycard connect/disconnect events
|
||||
|
||||
```javascript
|
||||
import { DeviceEventEmitter } from 'react-native';
|
||||
|
||||
// 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"));
|
||||
}
|
||||
```
|
||||
|
||||
### Errors
|
||||
|
||||
Library uses Promises for method calls, use `.catch` to get the error object.
|
||||
|
||||
Example:
|
||||
```javascript
|
||||
Keycard.init("123456").then(info => console.log(info)).catch(error => console.log(error))
|
||||
```
|
||||
|
||||
Error object example:
|
||||
```javascript
|
||||
{"code": "EUNSPECIFIED",
|
||||
"error": "Tag was lost."}
|
||||
```
|
||||
|
||||
### Check NFC support on device
|
||||
```javascript
|
||||
// Check if NFC is supported by device
|
||||
Keycard.nfcIsSupported().then(isSupported => isSupported ? console.log("NFC is supported") : console.log("NFC is not supported"));
|
||||
|
||||
// Check if NFC is enabled on device
|
||||
Keycard.nfcIsEnabled().then(isEnabled => isEnabled ? console.log("NFC is enabled") : console.log("NFC is not enabled"));
|
||||
|
||||
// Open device NFC settings
|
||||
Keycard.openNfcSettings();
|
||||
```
|
||||
|
||||
### Get keycard information
|
||||
```javascript
|
||||
// If keycard was not paired before, use empty string as pairing
|
||||
Keycard.getApplicationInfo("").then(info => console.log(info));
|
||||
|
||||
// If keycard is paired, use pairing key
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
Keycard.getApplicationInfo(pairing).then(info => console.log(info));
|
||||
|
||||
```
|
||||
|
||||
Returns object like this:
|
||||
```javascript
|
||||
{"free-pairing-slots": 2,
|
||||
"app-version": "2.1",
|
||||
"secure-channel-pub-key": "042bd559a6eb5843491f79150ccba6bcc04c5b6691079f7c7a0e2eea659960db1df67079b27fdf5df56a1092029a157c0dce7000af4d7c4c1131421623c0150d1c",
|
||||
"instance-uid": "21c0ce19aa9a26efc02fd32078c08527",
|
||||
"key-uid": "a88d46499e5690c6ad637e243e83cf51be3e2c67e48324b2b2def3e6a0492576",
|
||||
"has-master-key?": false,
|
||||
"paired?": false,
|
||||
"initialized?": true}
|
||||
```
|
||||
|
||||
`instance-uid` The instance UID of the applet. This ID never changes for the lifetime of the applet.
|
||||
|
||||
`key-uid` The UID of the master key on this card. Changes every time a different master key is stored. It has zero length if no key is on the card.
|
||||
|
||||
## Setup keycard
|
||||
|
||||
### Initialize the card
|
||||
```javascript
|
||||
const pin = "123456";
|
||||
Keycard.init(pin).then(secrets => console.log(secrets));
|
||||
```
|
||||
|
||||
`secrets` object contains PIN, PUK and Pairing password. You will need password to pair the card to device.
|
||||
```javascript
|
||||
{"pin": "123456",
|
||||
"puk": "123456123456",
|
||||
"password": "/xzPt+rEWVN3sMc5"}
|
||||
```
|
||||
|
||||
### Pair
|
||||
Pairs keycard to device.
|
||||
|
||||
Use password you get after keycard initialization (using `init`):
|
||||
|
||||
```javascript
|
||||
const password = "/xzPt+rEWVN3sMc5";
|
||||
Keycard.pair(password).then(pairing => console.log(pairing));
|
||||
```
|
||||
|
||||
`pairing` object contains pairing key as base64 string.
|
||||
You will need pairing key to open secure channel for most keycard operations. More info on pairing https://status.im/keycard_api/sdk_securechannel.html
|
||||
|
||||
### Generate mnemonic phrase
|
||||
```javascript
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const words = "abandon\nability\nable\nabout\n..." // bip 39 words separated by new line
|
||||
Keycard.generateMnemonic(pairing, words).then(mnemonic => console.log(mnemonic));
|
||||
```
|
||||
`mnemonic` is a string of 12 words separated by space:
|
||||
```javascript
|
||||
"sure more foil soon pretty guilt run rail biology fine obey outside"
|
||||
```
|
||||
|
||||
BIP39 words can be found here: https://raw.githubusercontent.com/bitcoin/bips/master/bip-0039/english.txt
|
||||
|
||||
### Generate and load master key
|
||||
```javascript
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const pin = "123456";
|
||||
const mnemonic = "sure more foil soon pretty guilt run rail biology fine obey outside";
|
||||
|
||||
Keycard.generateAndLoadKey(mnemonic, pairing, pin).then(data => console.log(data));
|
||||
```
|
||||
|
||||
`data` object returned:
|
||||
```javascript
|
||||
{"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",
|
||||
"encryption-public-key": "04d36d64bea374b917bc097646cb4e81061c7b0ab0872207480b886e66fb52d53774e303e2aa07a1107776f312b94663566765a8a75cf0a92b0851017b28b356a1",
|
||||
"instance-uid": "21c0ce19aa9a26efc02fd32078c08527",
|
||||
"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`
|
||||
|
||||
`encryption-public-key` is public key with derivation path `m/43'/60'/1581'/1'/0`
|
||||
|
||||
More info about key derivation: https://status.im/keycard_api/sdk_derivation_sign.html
|
||||
|
||||
### Get keys from keycard
|
||||
```javascript
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const pin = "123456";
|
||||
|
||||
Keycard.getKeys(pairing, pin).then(data => console.log(data));
|
||||
```
|
||||
|
||||
`data` object contains:
|
||||
```javascript
|
||||
{"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",
|
||||
"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";
|
||||
const pin = "123456";
|
||||
const hash = "d81bbffb92157b72ceae3da72eb8224976ba42a49621822789edb0735a0e0395";
|
||||
|
||||
Keycard.sign(pairing, pin, hash).then(sig => console.log(sig));
|
||||
```
|
||||
|
||||
Signature string returned. Example: ` d684afb4ec9ce59f2d112a9c9400bd04f5a5b2518b251dba4ad135448f2e75367c2ea6412893d8001ed9c9efeb7c7d37bc11f7dfcf27c4818cf0861da199de1900`
|
||||
|
||||
Signature consists of R, S and Recovery ID values concatenated (R+S+V).
|
||||
For example:
|
||||
|
||||
R: `79ef184db3150519a9719a38a7939fae39bbea088758745482cabe40127c7efb`
|
||||
|
||||
S: `674932db2a7a5ae4b1d9d228b3542dba83ac9ac62524a45dd984e9650ceaa736`
|
||||
|
||||
Recovery ID: `0`
|
||||
|
||||
Would produce signature: `d684afb4ec9ce59f2d112a9c9400bd04f5a5b2518b251dba4ad135448f2e75367c2ea6412893d8001ed9c9efeb7c7d37bc11f7dfcf27c4818cf0861da199de1900`
|
||||
|
||||
More info about signing: https://status.im/keycard_api/sdk_derivation_sign.html
|
||||
|
||||
### Derive key
|
||||
Changes derivation path:
|
||||
```javascript
|
||||
const path = "m/44'/60'/0'/0/0"
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const pin = "123456";
|
||||
|
||||
Keycard.deriveKey(path, pairing, pin).then(path => console.log("path changed to " + path));
|
||||
```
|
||||
More information on key derivation: https://status.im/keycard_api/sdk_derivation_sign.html
|
||||
|
||||
### Remove key
|
||||
Removes master key from keycard:
|
||||
|
||||
```javascript
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const pin = "123456";
|
||||
|
||||
Keycard.removeKey(pairing, pin).then(() => console.log("key removed"));
|
||||
```
|
||||
|
||||
### Unpair
|
||||
|
||||
Unpairs keycard from current device:
|
||||
|
||||
```javascript
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const pin = "123456";
|
||||
|
||||
Keycard.unpair(pairing, pin).then(() => console.log("keycard unpaired"));
|
||||
```
|
||||
|
||||
### Change PIN
|
||||
```javascript
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const currentPin = "123456";
|
||||
const newPin = "111111";
|
||||
|
||||
Keycard.removeKey(pairing, currentPin, newPin).then(() => console.log("pin changed"));
|
||||
```
|
||||
|
||||
### Unblock PIN
|
||||
When wrong PIN is entered 3 times keycard becomes blocked. You can unblock it with PUK code:
|
||||
```javascript
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const puk = "123456123456";
|
||||
const newPin = "111111";
|
||||
|
||||
Keycard.removeKey(pairing, puk, newPin).then(() => console.log("pin unblocked"));
|
||||
```
|
||||
|
||||
### Verify PIN
|
||||
Verifies PIN is valid:
|
||||
```javascript
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const pin = "123456";
|
||||
|
||||
Keycard.removeKey(pairing, pin).then(() => console.log("pin is valid"));
|
||||
```
|
||||
|
||||
### Delete keycard
|
||||
Deletes everything from keycard including key and the applet. Dangerous operation for advanced users only. You will need to install applet again to interact with keycard.
|
||||
|
||||
```javascript
|
||||
const pairing = "AFFdkP01GywuaJRQkGDq+OyPHBE9nECEDDCfXhpfaxlo";
|
||||
const puk = "123456123456";
|
||||
const newPin = "111111";
|
||||
|
||||
Keycard.removeKey(pairing, puk, newPin).then(() => console.log("pin unblocked"));
|
||||
```
|
||||
|
||||
### Install applet
|
||||
Keycard usually comes with installed applet. But if you have empty keycard without the applet, you can install applet with:
|
||||
```javascript
|
||||
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.
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
import { NativeModules } from 'react-native';
|
||||
|
||||
const { RNStatusKeycard } = NativeModules;
|
||||
|
||||
export default RNStatusKeycard;
|
||||
export default RNStatusKeycard;
|
||||
@@ -0,0 +1,469 @@
|
||||
import Foundation
|
||||
import Keycard
|
||||
import os.log
|
||||
|
||||
enum SmartCardError: Error {
|
||||
case invalidBase64
|
||||
case noPairing
|
||||
}
|
||||
|
||||
enum DerivationPath: String {
|
||||
case masterPath = "m"
|
||||
case rootPath = "m/44'/60'/0'/0"
|
||||
case walletPath = "m/44'/60'/0'/0/0"
|
||||
case whisperPath = "m/43'/60'/1581'/0'/0"
|
||||
case encryptionPath = "m/43'/60'/1581'/1'/0"
|
||||
}
|
||||
|
||||
class SmartCard {
|
||||
var pairings: [String: String] = [:]
|
||||
|
||||
func initialize(channel: CardChannel, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let puk = self.randomPUK()
|
||||
let pairingPassword = "KeycardDefaultPairing"
|
||||
|
||||
let cmdSet = KeycardCommandSet(cardChannel: channel)
|
||||
try cmdSet.select().checkOK()
|
||||
try cmdSet.initialize(pin: pin, puk: puk, pairingPassword: pairingPassword).checkOK()
|
||||
|
||||
resolve(["pin": pin, "puk": puk, "password": pairingPassword])
|
||||
}
|
||||
|
||||
func pair(channel: CardChannel, pairingPassword: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = KeycardCommandSet(cardChannel: channel)
|
||||
let info = try ApplicationInfo(cmdSet.select().checkOK().data)
|
||||
|
||||
logAppInfo(info)
|
||||
|
||||
try cmdSet.autoPair(password: pairingPassword)
|
||||
let pairing = Data(cmdSet.pairing!.bytes).base64EncodedString()
|
||||
self.pairings[bytesToHex(info.instanceUID)] = pairing
|
||||
resolve(pairing)
|
||||
}
|
||||
|
||||
func generateMnemonic(channel: CardChannel, words: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try securedCommandSet(channel: channel)
|
||||
|
||||
let mnemonic = try Mnemonic(rawData: cmdSet.generateMnemonic(length: GenerateMnemonicP1.length12Words).checkOK().data)
|
||||
mnemonic.wordList = words.components(separatedBy: .newlines)
|
||||
|
||||
resolve(mnemonic.toMnemonicPhrase())
|
||||
}
|
||||
|
||||
func generateAndLoadKey(channel: CardChannel, mnemonic: String, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
let seed = Mnemonic.toBinarySeed(mnemonicPhrase: mnemonic)
|
||||
let keyPair = BIP32KeyPair(fromSeed: seed)
|
||||
|
||||
try cmdSet.loadKey(keyPair: keyPair).checkOK()
|
||||
os_log("keypair loaded to card");
|
||||
|
||||
let rootKeyPair = try exportKey(cmdSet: cmdSet, path: .rootPath, makeCurrent: false, publicOnly: true)
|
||||
let whisperKeyPair = try exportKey(cmdSet: cmdSet, path: .whisperPath, makeCurrent: false, publicOnly: false)
|
||||
let encryptionKeyPair = try exportKey(cmdSet: cmdSet, path: .encryptionPath, makeCurrent: false, publicOnly: false)
|
||||
let walletKeyPair = try exportKey(cmdSet: cmdSet, path: .walletPath, makeCurrent: false, publicOnly: true)
|
||||
|
||||
let info = try ApplicationInfo(cmdSet.select().checkOK().data)
|
||||
|
||||
resolve([
|
||||
"address": bytesToHex(keyPair.toEthereumAddress()),
|
||||
"public-key": bytesToHex(keyPair.publicKey),
|
||||
"wallet-root-address": bytesToHex(rootKeyPair.toEthereumAddress()),
|
||||
"wallet-root-public-key": bytesToHex(rootKeyPair.publicKey),
|
||||
"wallet-address": bytesToHex(walletKeyPair.toEthereumAddress()),
|
||||
"wallet-public-key": bytesToHex(walletKeyPair.publicKey),
|
||||
"whisper-address": bytesToHex(whisperKeyPair.toEthereumAddress()),
|
||||
"whisper-public-key": bytesToHex(whisperKeyPair.publicKey),
|
||||
"whisper-private-key": bytesToHex(whisperKeyPair.privateKey!),
|
||||
"encryption-public-key": bytesToHex(encryptionKeyPair.publicKey),
|
||||
"instance-uid": bytesToHex(info.instanceUID),
|
||||
"key-uid": bytesToHex(info.keyUID)
|
||||
])
|
||||
}
|
||||
|
||||
func saveMnemonic(channel: CardChannel, mnemonic: String, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
let seed = Mnemonic.toBinarySeed(mnemonicPhrase: mnemonic)
|
||||
try cmdSet.loadKey(seed: seed).checkOK()
|
||||
os_log("seed loaded to card");
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
func factoryReset(channel: CardChannel, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet: GlobalPlatformCommandSet = GlobalPlatformCommandSet(cardChannel: channel);
|
||||
try cmdSet.select().checkOK()
|
||||
os_log("ISD selected")
|
||||
|
||||
try cmdSet.openSecureChannel()
|
||||
os_log("SecureChannel opened")
|
||||
|
||||
try cmdSet.deleteKeycardInstance().checkSW(StatusWord.ok, StatusWord.referencedDataNotFound)
|
||||
os_log("Keycard applet instance deleted")
|
||||
|
||||
try cmdSet.installKeycardInstance().checkOK()
|
||||
os_log("Keycard applet instance re-installed")
|
||||
|
||||
let info = try ApplicationInfo(KeycardCommandSet(cardChannel: channel).select().checkOK().data)
|
||||
os_log("Selecting the newly installed Keycard applet succeeded")
|
||||
|
||||
var cardInfo = [String: Any]()
|
||||
cardInfo["initialized?"] = info.initializedCard
|
||||
|
||||
resolve(cardInfo)
|
||||
}
|
||||
|
||||
func getApplicationInfo(channel: CardChannel, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = KeycardCommandSet(cardChannel: channel)
|
||||
let info = try ApplicationInfo(cmdSet.select().checkOK().data)
|
||||
|
||||
os_log("Card initialized? %@", String(info.initializedCard))
|
||||
var cardInfo = [String: Any]()
|
||||
cardInfo["initialized?"] = info.initializedCard
|
||||
|
||||
if (info.initializedCard) {
|
||||
logAppInfo(info)
|
||||
var isPaired = false
|
||||
|
||||
if let _ = self.pairings[bytesToHex(info.instanceUID)] {
|
||||
do {
|
||||
try openSecureChannel(cmdSet: cmdSet)
|
||||
isPaired = true
|
||||
} catch let error as CardError {
|
||||
isPaired = try tryDefaultPairing(cmdSet: cmdSet, cardInfo: &cardInfo)
|
||||
} catch let error as StatusWord {
|
||||
isPaired = try tryDefaultPairing(cmdSet: cmdSet, cardInfo: &cardInfo)
|
||||
}
|
||||
} else {
|
||||
isPaired = try tryDefaultPairing(cmdSet: cmdSet, cardInfo: &cardInfo)
|
||||
}
|
||||
|
||||
if (isPaired) {
|
||||
let status = try ApplicationStatus(cmdSet.getStatus(info: GetStatusP1.application.rawValue).checkOK().data);
|
||||
os_log("PIN retry counter: %d", status.pinRetryCount)
|
||||
os_log("PUK retry counter: %d", status.pukRetryCount)
|
||||
|
||||
cardInfo["pin-retry-counter"] = status.pinRetryCount
|
||||
cardInfo["puk-retry-counter"] = status.pukRetryCount
|
||||
}
|
||||
|
||||
cardInfo["paired?"] = isPaired
|
||||
}
|
||||
|
||||
cardInfo["has-master-key?"] = info.hasMasterKey
|
||||
cardInfo["instance-uid"] = bytesToHex(info.instanceUID)
|
||||
cardInfo["key-uid"] = bytesToHex(info.keyUID)
|
||||
cardInfo["secure-channel-pub-key"] = bytesToHex(info.secureChannelPubKey)
|
||||
cardInfo["app-version"] = info.appVersionString
|
||||
cardInfo["free-pairing-slots"] = info.freePairingSlots
|
||||
|
||||
resolve(cardInfo)
|
||||
}
|
||||
|
||||
func deriveKey(channel: CardChannel, path: String, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
let currentPath = try KeyPath(data: cmdSet.getStatus(info: GetStatusP1.keyPath.rawValue).checkOK().data);
|
||||
os_log("Current key path: %@", currentPath.description)
|
||||
|
||||
if (currentPath.description != path) {
|
||||
try cmdSet.deriveKey(path: path).checkOK()
|
||||
os_log("Derived %@", path)
|
||||
}
|
||||
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
func exportKey(channel: CardChannel, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
let key = try cmdSet.exportCurrentKey(publicOnly: true).checkOK().data
|
||||
resolve(bytesToHex(key))
|
||||
}
|
||||
|
||||
func exportKeyWithPath(channel: CardChannel, pin: String, path: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
let key = try BIP32KeyPair(fromTLV: cmdSet.exportKey(path: path, makeCurrent: false, publicOnly: true).checkOK().data).publicKey;
|
||||
|
||||
resolve(bytesToHex(key))
|
||||
}
|
||||
|
||||
func importKeys(channel: CardChannel, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
|
||||
let encryptionKeyPair = try exportKey(cmdSet: cmdSet, path: .encryptionPath, makeCurrent: false, publicOnly: false)
|
||||
let masterPair = try exportKey(cmdSet: cmdSet, path: .masterPath, makeCurrent: false, publicOnly: true)
|
||||
let rootKeyPair = try exportKey(cmdSet: cmdSet, path: .rootPath, makeCurrent: false, publicOnly: true)
|
||||
let whisperKeyPair = try exportKey(cmdSet: cmdSet, path: .whisperPath, makeCurrent: false, publicOnly: false)
|
||||
let walletKeyPair = try exportKey(cmdSet: cmdSet, path: .walletPath, makeCurrent: false, publicOnly: true)
|
||||
|
||||
let info = cmdSet.info!
|
||||
|
||||
resolve([
|
||||
"address": bytesToHex(masterPair.toEthereumAddress()),
|
||||
"public-key": bytesToHex(masterPair.publicKey),
|
||||
"wallet-root-address": bytesToHex(rootKeyPair.toEthereumAddress()),
|
||||
"wallet-root-public-key": bytesToHex(rootKeyPair.publicKey),
|
||||
"wallet-address": bytesToHex(walletKeyPair.toEthereumAddress()),
|
||||
"wallet-public-key": bytesToHex(walletKeyPair.publicKey),
|
||||
"whisper-address": bytesToHex(whisperKeyPair.toEthereumAddress()),
|
||||
"whisper-public-key": bytesToHex(whisperKeyPair.publicKey),
|
||||
"whisper-private-key": bytesToHex(whisperKeyPair.privateKey!),
|
||||
"encryption-public-key": bytesToHex(encryptionKeyPair.publicKey),
|
||||
"instance-uid": bytesToHex(info.instanceUID),
|
||||
"key-uid": bytesToHex(info.keyUID)
|
||||
])
|
||||
}
|
||||
|
||||
func getKeys(channel: CardChannel, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
|
||||
let whisperKeyPair = try exportKey(cmdSet: cmdSet, path: .whisperPath, makeCurrent: false, publicOnly: false)
|
||||
let encryptionKeyPair = try exportKey(cmdSet: cmdSet, path: .encryptionPath, makeCurrent: false, publicOnly: false)
|
||||
|
||||
let info = cmdSet.info!
|
||||
|
||||
resolve([
|
||||
"whisper-address": bytesToHex(whisperKeyPair.toEthereumAddress()),
|
||||
"whisper-public-key": bytesToHex(whisperKeyPair.publicKey),
|
||||
"whisper-private-key": bytesToHex(whisperKeyPair.privateKey!),
|
||||
"encryption-public-key": bytesToHex(encryptionKeyPair.publicKey),
|
||||
"instance-uid": bytesToHex(info.instanceUID),
|
||||
"key-uid": bytesToHex(info.keyUID)
|
||||
])
|
||||
}
|
||||
|
||||
func sign(channel: CardChannel, pin: String, message: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
let sig = try processSignature(message) { return try cmdSet.sign(hash: $0) }
|
||||
resolve(sig)
|
||||
}
|
||||
|
||||
func signWithPath(channel: CardChannel, pin: String, path: String, message: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
let sig = try processSignature(message) {
|
||||
if (cmdSet.info!.appVersion < 0x0202) {
|
||||
let currentPath = try KeyPath(data: cmdSet.getStatus(info: GetStatusP1.keyPath.rawValue).checkOK().data);
|
||||
|
||||
if (currentPath.description != path) {
|
||||
try cmdSet.deriveKey(path: path).checkOK()
|
||||
}
|
||||
|
||||
return try cmdSet.sign(hash: $0)
|
||||
} else {
|
||||
return try cmdSet.sign(hash: $0, path: path, makeCurrent: false)
|
||||
}
|
||||
}
|
||||
|
||||
resolve(sig)
|
||||
}
|
||||
|
||||
func signPinless(channel: CardChannel, message: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = CashCommandSet(cardChannel: channel)
|
||||
try cmdSet.select().checkOK()
|
||||
|
||||
let sig = try processSignature(message) { return try cmdSet.sign(data: $0) }
|
||||
resolve(sig)
|
||||
}
|
||||
|
||||
func verifyPin(channel: CardChannel, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let _ = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
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()
|
||||
os_log("pin changed")
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
func unblockPin(channel: CardChannel, puk: String, newPin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try securedCommandSet(channel: channel)
|
||||
try cmdSet.unblockPIN(puk: puk, newPIN: newPin).checkAuthOK()
|
||||
os_log("pin unblocked")
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
func unpair(channel: CardChannel, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
|
||||
try cmdSet.autoUnpair()
|
||||
os_log("card unpaired")
|
||||
|
||||
self.pairings[bytesToHex(cmdSet.info!.instanceUID)] = nil
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
func removeKey(channel: CardChannel, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
try cmdSet.removeKey().checkOK()
|
||||
os_log("key removed")
|
||||
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
func removeKeyWithUnpair(channel: CardChannel, pin: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) throws -> Void {
|
||||
let cmdSet = try authenticatedCommandSet(channel: channel, pin: pin)
|
||||
try cmdSet.removeKey().checkOK()
|
||||
os_log("key removed")
|
||||
|
||||
try cmdSet.unpairOthers()
|
||||
os_log("unpaired others")
|
||||
|
||||
try cmdSet.autoUnpair()
|
||||
os_log("card unpaired")
|
||||
|
||||
self.pairings[bytesToHex(cmdSet.info!.instanceUID)] = nil
|
||||
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
func randomPUK() -> String {
|
||||
return String(format: "%012ld", Int64.random(in: 0..<999999999999))
|
||||
}
|
||||
|
||||
func randomPairingPassword() -> String {
|
||||
let digits = "23456789"
|
||||
let letters = "abcdefghijkmnopqrstuvwxyz"
|
||||
return String((0..<5).map{ i in ((i % 2) == 0) ? letters.randomElement()! : digits.randomElement()! })
|
||||
}
|
||||
|
||||
func exportKey(cmdSet: KeycardCommandSet, path: DerivationPath, makeCurrent: Bool, publicOnly: Bool) throws -> BIP32KeyPair {
|
||||
let tlvRoot = try cmdSet.exportKey(path: path.rawValue, makeCurrent: makeCurrent, publicOnly: publicOnly).checkOK().data
|
||||
os_log("Derived %@", path.rawValue)
|
||||
return try BIP32KeyPair(fromTLV: tlvRoot)
|
||||
}
|
||||
|
||||
func setPairings(newPairings: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
||||
self.pairings.removeAll()
|
||||
for case let (instanceUID as String, v as NSDictionary) in newPairings {
|
||||
self.pairings[instanceUID] = v["pairing"] as? String
|
||||
}
|
||||
|
||||
resolve(true)
|
||||
}
|
||||
|
||||
func authenticatedCommandSet(channel: CardChannel, pin: String) throws -> KeycardCommandSet {
|
||||
let cmdSet = try securedCommandSet(channel: channel)
|
||||
try cmdSet.verifyPIN(pin: pin).checkAuthOK()
|
||||
os_log("pin verified")
|
||||
|
||||
return cmdSet;
|
||||
}
|
||||
|
||||
func securedCommandSet(channel: CardChannel) throws -> KeycardCommandSet {
|
||||
let cmdSet = KeycardCommandSet(cardChannel: channel)
|
||||
try cmdSet.select().checkOK()
|
||||
try openSecureChannel(cmdSet: cmdSet)
|
||||
|
||||
return cmdSet
|
||||
}
|
||||
|
||||
func tryDefaultPairing(cmdSet: KeycardCommandSet, cardInfo: inout [String: Any]) throws -> Bool {
|
||||
do {
|
||||
try cmdSet.autoPair(password: "KeycardDefaultPairing")
|
||||
let pairing = Data(cmdSet.pairing!.bytes).base64EncodedString()
|
||||
self.pairings[bytesToHex(cmdSet.info!.instanceUID)] = pairing
|
||||
cardInfo["new-pairing"] = pairing
|
||||
|
||||
try openSecureChannel(cmdSet: cmdSet)
|
||||
return true
|
||||
} catch let error as CardError {
|
||||
os_log("autoOpenSecureChannel failed: %@", String(describing: error));
|
||||
} catch let error as StatusWord {
|
||||
os_log("autoOpenSecureChannel failed: %@", String(describing: error));
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func openSecureChannel(cmdSet: KeycardCommandSet) throws -> Void {
|
||||
if let pairingBase64 = self.pairings[bytesToHex(cmdSet.info!.instanceUID)] {
|
||||
cmdSet.pairing = try base64ToPairing(pairingBase64)
|
||||
|
||||
try cmdSet.autoOpenSecureChannel()
|
||||
os_log("secure channel opened")
|
||||
} else {
|
||||
throw SmartCardError.noPairing
|
||||
}
|
||||
}
|
||||
|
||||
func processSignature(_ message: String, sign: ([UInt8]) throws -> APDUResponse) throws -> String {
|
||||
let hash = hexToBytes(message)
|
||||
let signature = try RecoverableSignature(hash: hash, data: sign(hash).checkOK().data)
|
||||
logSignature(hash, signature)
|
||||
return formatSignature(signature)
|
||||
}
|
||||
|
||||
func base64ToPairing(_ base64: String) throws -> Pairing {
|
||||
if let data = Data(base64Encoded: base64) {
|
||||
return Pairing(pairingData: [UInt8](data))
|
||||
} else {
|
||||
throw SmartCardError.invalidBase64
|
||||
}
|
||||
}
|
||||
|
||||
func logAppInfo(_ info: ApplicationInfo) -> Void {
|
||||
os_log("Instance UID: %@", bytesToHex(info.instanceUID))
|
||||
os_log("Key UID: %@", bytesToHex(info.keyUID))
|
||||
os_log("Secure channel public key: %@", bytesToHex(info.secureChannelPubKey))
|
||||
os_log("Application version: %@", info.appVersionString)
|
||||
os_log("Free pairing slots: %d", info.freePairingSlots)
|
||||
}
|
||||
|
||||
func logSignature(_ hash: [UInt8], _ signature: RecoverableSignature) -> Void {
|
||||
os_log("Signed hash: %@", bytesToHex(hash))
|
||||
os_log("Recovery ID: %d", signature.recId)
|
||||
os_log("R: %@", bytesToHex(signature.r))
|
||||
os_log("S: %@", bytesToHex(signature.s))
|
||||
}
|
||||
|
||||
func formatSignature(_ signature: RecoverableSignature) -> String {
|
||||
var out = Data(signature.r)
|
||||
out.append(contentsOf: signature.s)
|
||||
out.append(contentsOf: [signature.recId])
|
||||
let sig = dataToHex(out)
|
||||
|
||||
os_log("Signature: %@", sig)
|
||||
return sig
|
||||
}
|
||||
|
||||
func dataToHex(_ data: Data) -> String {
|
||||
return data.map { String(format: "%02hhx", $0) }.joined()
|
||||
}
|
||||
|
||||
func bytesToHex(_ bytes: [UInt8]) -> String {
|
||||
return bytes.map { String(format: "%02hhx", $0) }.joined()
|
||||
}
|
||||
|
||||
func hexToBytes(_ hex: String) -> [UInt8] {
|
||||
let h = hex.starts(with: "0x") ? String(hex.dropFirst(2)) : hex
|
||||
|
||||
var last = h.first
|
||||
return h.dropFirst().compactMap {
|
||||
guard
|
||||
let lastHexDigitValue = last?.hexDigitValue,
|
||||
let hexDigitValue = $0.hexDigitValue
|
||||
else {
|
||||
last = $0
|
||||
return nil
|
||||
}
|
||||
defer {
|
||||
last = nil
|
||||
}
|
||||
return UInt8(lastHexDigitValue * 16 + hexDigitValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTEventEmitter.h>
|
||||
@@ -0,0 +1,41 @@
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTEventEmitter.h>
|
||||
|
||||
@interface RCT_EXTERN_REMAP_MODULE(RNStatusKeycard, StatusKeycard, RCTEventEmitter)
|
||||
|
||||
RCT_EXTERN_METHOD(nfcIsSupported:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(nfcIsEnabled:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(openNfcSettings:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(init:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(pair:(NSString *)pairingPassword resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(generateMnemonic:(NSString *)words resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(generateAndLoadKey:(NSString *)mnemonic pin:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(saveMnemonic:(NSString *)mnemonic pin:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(getApplicationInfo:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(factoryReset:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(deriveKey:(NSString *)path pin:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(exportKey:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(exportKeyWithPath:(NSString *)pin path:(NSString *)path resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(importKeys:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(getKeys:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(sign:(NSString *)pin hash:(NSString *)hash resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(signWithPath:(NSString *)pin path:(NSString *)path hash:(NSString *)hash resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(signPinless:(NSString *)hash resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
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)
|
||||
RCT_EXTERN_METHOD(delete:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(removeKey:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(removeKeyWithUnpair:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(unpairAndDelete:(NSString *)pin resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(startNFC:(NSString *)prompt resolve:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(stopNFC:(NSString *)err resolve:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(setNFCMessage:(NSString *)message resolve:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject)
|
||||
RCT_EXTERN_METHOD(setPairings:(NSDictionary *)pairings resolve:(RCTPromiseResolveBlock)resolve reject: (RCTPromiseRejectBlock)reject)
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,293 @@
|
||||
import Foundation
|
||||
import Keycard
|
||||
import UIKit
|
||||
import os.log
|
||||
|
||||
@objc(StatusKeycard)
|
||||
class StatusKeycard: RCTEventEmitter {
|
||||
let smartCard = SmartCard()
|
||||
var cardChannel: CardChannel? = nil
|
||||
var nfcStartPrompt: String = "Hold your iPhone near a Status Keycard."
|
||||
|
||||
private var _keycardController: Any? = nil
|
||||
|
||||
@available(iOS 13.0, *)
|
||||
private var keycardController: KeycardController? {
|
||||
get {
|
||||
return _keycardController as? KeycardController
|
||||
}
|
||||
|
||||
set(kc) {
|
||||
_keycardController = kc
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func nfcIsSupported(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
||||
if #available(iOS 13.0, *) {
|
||||
resolve(KeycardController.isAvailable)
|
||||
} else {
|
||||
resolve(false)
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func nfcIsEnabled(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
||||
// On iOS NFC is always enabled (if available)
|
||||
nfcIsSupported(resolve, reject: reject)
|
||||
}
|
||||
|
||||
@objc
|
||||
func openNfcSettings(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
||||
// NFC cannot be enabled/disabled
|
||||
reject("E_KEYCARD", "Unsupported on iOS", nil)
|
||||
}
|
||||
|
||||
@objc
|
||||
func `init`(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.initialize(channel: channel, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func pair(_ pairingPassword: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.pair(channel: channel, pairingPassword: pairingPassword, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func generateMnemonic(_ words: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.generateMnemonic(channel: channel, words: words, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func generateAndLoadKey(_ mnemonic: String, pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.generateAndLoadKey(channel: channel, mnemonic: mnemonic, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func saveMnemonic(_ mnemonic: String, pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.saveMnemonic(channel: channel, mnemonic: mnemonic, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func factoryReset(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.factoryReset(channel: channel, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func getApplicationInfo(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.getApplicationInfo(channel: channel, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func deriveKey(_ path: String, pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.deriveKey(channel: channel, path: path, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func exportKey(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.exportKey(channel: channel, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func exportKeyWithPath(_ pin: String, path: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.exportKeyWithPath(channel: channel, pin: pin, path: path, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func importKeys(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.importKeys(channel: channel, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func getKeys(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.getKeys(channel: channel, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func sign(_ pin: String, hash: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.sign(channel: channel, pin: pin, message: hash, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func signWithPath(_ pin: String, path: String, hash: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.signWithPath(channel: channel, pin: pin, path: path, message: hash, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func signPinless(_ hash: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.signPinless(channel: channel, message: hash, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func installApplet(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
reject("E_KEYCARD", "Not implemented (unused)", nil)
|
||||
}
|
||||
|
||||
@objc
|
||||
func installAppletAndInitCard(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
reject("E_KEYCARD", "Not implemented (unused)", nil)
|
||||
}
|
||||
|
||||
@objc
|
||||
func verifyPin(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
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) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func unblockPin(_ puk: String, newPin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.unblockPin(channel: channel, puk: puk, newPin: newPin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func unpair(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.unpair(channel: channel, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func delete(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
reject("E_KEYCARD", "Not implemented (unused)", nil)
|
||||
}
|
||||
|
||||
@objc
|
||||
func removeKey(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.removeKey(channel: channel, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func removeKeyWithUnpair(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
keycardInvokation(reject) { [unowned self] channel in try self.smartCard.removeKeyWithUnpair(channel: channel, pin: pin, resolve: resolve, reject: reject) }
|
||||
}
|
||||
|
||||
@objc
|
||||
func unpairAndDelete(_ pin: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
reject("E_KEYCARD", "Not implemented (unused)", nil)
|
||||
}
|
||||
|
||||
@objc
|
||||
func setPairings(_ pairings: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
self.smartCard.setPairings(newPairings: pairings, resolve: resolve, reject: reject)
|
||||
}
|
||||
|
||||
@objc
|
||||
func startNFC(_ prompt: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
||||
if #available(iOS 13.0, *) {
|
||||
if (keycardController == nil) {
|
||||
self.keycardController = KeycardController(onConnect: { [unowned self] channel in
|
||||
self.cardChannel = channel
|
||||
|
||||
let feedbackGenerator = UINotificationFeedbackGenerator()
|
||||
feedbackGenerator.prepare()
|
||||
|
||||
DispatchQueue.main.async {
|
||||
feedbackGenerator.notificationOccurred(.success)
|
||||
}
|
||||
self.sendEvent(withName: "keyCardOnConnected", body: nil)
|
||||
self.keycardController?.setAlert("Connected. Don't move your card.")
|
||||
os_log("[react-native-status-keycard] card connected")
|
||||
}, onFailure: { [unowned self] error in
|
||||
self.cardChannel = nil
|
||||
self.keycardController = nil
|
||||
|
||||
os_log("[react-native-status-keycard] NFCError: %@", String(describing: error))
|
||||
|
||||
if type(of: error) is NSError.Type {
|
||||
let nsError = error as NSError
|
||||
if nsError.code == 200 && nsError.domain == "NFCError" {
|
||||
self.sendEvent(withName: "keyCardOnNFCUserCancelled", body: nil)
|
||||
} else if (nsError.code == 201 || nsError.code == 203) && (nsError.domain == "NFCError") {
|
||||
self.sendEvent(withName: "keyCardOnNFCTimeout", body: nil)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
self.nfcStartPrompt = prompt.isEmpty ? "Hold your iPhone near a Status Keycard." : prompt
|
||||
keycardController?.start(alertMessage: self.nfcStartPrompt)
|
||||
resolve(true)
|
||||
} else {
|
||||
reject("E_KEYCARD", "already started", nil)
|
||||
}
|
||||
} else {
|
||||
reject("E_KEYCARD", "unavailable", nil)
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func stopNFC(_ err: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
||||
if #available(iOS 13.0, *) {
|
||||
if (err.isEmpty) {
|
||||
self.keycardController?.stop(alertMessage: "Success")
|
||||
} else {
|
||||
self.keycardController?.stop(errorMessage: err)
|
||||
}
|
||||
self.cardChannel = nil
|
||||
self.keycardController = nil
|
||||
resolve(true)
|
||||
} else {
|
||||
reject("E_KEYCARD", "unavailable", nil)
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func setNFCMessage(_ message: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
||||
if #available(iOS 13.0, *) {
|
||||
self.keycardController?.setAlert(message)
|
||||
resolve(true)
|
||||
} else {
|
||||
reject("E_KEYCARD", "unavailable", nil)
|
||||
}
|
||||
}
|
||||
|
||||
override static func requiresMainQueueSetup() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
override func supportedEvents() -> [String]! {
|
||||
return ["keyCardOnConnected", "keyCardOnDisconnected", "keyCardOnNFCEnabled", "keyCardOnNFCDisabled", "keyCardOnNFCTimeout", "keyCardOnNFCUserCancelled"]
|
||||
}
|
||||
|
||||
func keycardInvokation(_ reject: @escaping RCTPromiseRejectBlock, body: @escaping (CardChannel) throws -> Void) {
|
||||
if #available(iOS 13.0, *) {
|
||||
if self.cardChannel != nil {
|
||||
DispatchQueue.global().async { [unowned self] in
|
||||
do {
|
||||
try body(self.cardChannel!)
|
||||
} catch {
|
||||
var errMsg = ""
|
||||
|
||||
if type(of: error) is NSError.Type {
|
||||
let nsError = error as NSError
|
||||
errMsg = "\(nsError.domain):\(nsError.code)"
|
||||
if nsError.code == 100 && nsError.domain == "NFCError" {
|
||||
self.sendEvent(withName: "keyCardOnDisconnected", body: nil)
|
||||
self.keycardController?.restartPolling()
|
||||
self.keycardController?.setAlert(self.nfcStartPrompt)
|
||||
}
|
||||
} else {
|
||||
errMsg = "\(error)"
|
||||
}
|
||||
reject("E_KEYCARD", errMsg, error)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reject("E_KEYCARD", "not connected", nil)
|
||||
}
|
||||
} else {
|
||||
reject("E_KEYCARD", "unavailable", nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 52;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
65B8C633256D352A00C6A3EE /* Keycard in Frameworks */ = {isa = PBXBuildFile; productRef = 65B8C632256D352A00C6A3EE /* Keycard */; };
|
||||
F4FF95D7245B92E800C19C63 /* StatusKeycard.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* StatusKeycard.swift */; };
|
||||
F74884362577A87A00D908D2 /* SmartCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = F74884352577A87A00D908D2 /* SmartCard.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
58B511D91A9E6C8500147676 /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = "include/$(PRODUCT_NAME)";
|
||||
dstSubfolderSpec = 16;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
134814201AA4EA6300B7C361 /* libStatusKeycard.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libStatusKeycard.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B3E7B5891CC2AC0600A0062D /* StatusKeycard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StatusKeycard.m; sourceTree = "<group>"; };
|
||||
F4FF95D5245B92E700C19C63 /* StatusKeycard-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "StatusKeycard-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
F4FF95D6245B92E800C19C63 /* StatusKeycard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusKeycard.swift; sourceTree = "<group>"; };
|
||||
F74884352577A87A00D908D2 /* SmartCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartCard.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
58B511D81A9E6C8500147676 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
65B8C633256D352A00C6A3EE /* Keycard in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
134814211AA4EA7D00B7C361 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
134814201AA4EA6300B7C361 /* libStatusKeycard.a */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
58B511D21A9E6C8500147676 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F74884352577A87A00D908D2 /* SmartCard.swift */,
|
||||
F4FF95D6245B92E800C19C63 /* StatusKeycard.swift */,
|
||||
B3E7B5891CC2AC0600A0062D /* StatusKeycard.m */,
|
||||
F4FF95D5245B92E700C19C63 /* StatusKeycard-Bridging-Header.h */,
|
||||
134814211AA4EA7D00B7C361 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
58B511DA1A9E6C8500147676 /* StatusKeycard */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "StatusKeycard" */;
|
||||
buildPhases = (
|
||||
58B511D71A9E6C8500147676 /* Sources */,
|
||||
58B511D81A9E6C8500147676 /* Frameworks */,
|
||||
58B511D91A9E6C8500147676 /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = StatusKeycard;
|
||||
packageProductDependencies = (
|
||||
65B8C632256D352A00C6A3EE /* Keycard */,
|
||||
);
|
||||
productName = RCTDataManager;
|
||||
productReference = 134814201AA4EA6300B7C361 /* libStatusKeycard.a */;
|
||||
productType = "com.apple.product-type.library.static";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
58B511D31A9E6C8500147676 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0920;
|
||||
ORGANIZATIONNAME = Facebook;
|
||||
TargetAttributes = {
|
||||
58B511DA1A9E6C8500147676 = {
|
||||
CreatedOnToolsVersion = 6.1.1;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "StatusKeycard" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
English,
|
||||
en,
|
||||
);
|
||||
mainGroup = 58B511D21A9E6C8500147676;
|
||||
packageReferences = (
|
||||
65B8C631256D352A00C6A3EE /* XCRemoteSwiftPackageReference "Keycard" */,
|
||||
);
|
||||
productRefGroup = 58B511D21A9E6C8500147676;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
58B511DA1A9E6C8500147676 /* StatusKeycard */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
58B511D71A9E6C8500147676 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
F4FF95D7245B92E800C19C63 /* StatusKeycard.swift in Sources */,
|
||||
F74884362577A87A00D908D2 /* SmartCard.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
58B511ED1A9E6C8500147676 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
58B511EE1A9E6C8500147676 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = YES;
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
58B511F01A9E6C8500147676 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
||||
"$(SRCROOT)/../../../React/**",
|
||||
"$(SRCROOT)/../../react-native/React/**",
|
||||
);
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PRODUCT_NAME = StatusKeycard;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "StatusKeycard-Bridging-Header.h";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
58B511F11A9E6C8500147676 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
||||
"$(SRCROOT)/../../../React/**",
|
||||
"$(SRCROOT)/../../react-native/React/**",
|
||||
);
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PRODUCT_NAME = StatusKeycard;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "StatusKeycard-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "StatusKeycard" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
58B511ED1A9E6C8500147676 /* Debug */,
|
||||
58B511EE1A9E6C8500147676 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "StatusKeycard" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
58B511F01A9E6C8500147676 /* Debug */,
|
||||
58B511F11A9E6C8500147676 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
|
||||
/* Begin XCRemoteSwiftPackageReference section */
|
||||
65B8C631256D352A00C6A3EE /* XCRemoteSwiftPackageReference "Keycard" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/status-im/Keycard.swift";
|
||||
requirement = {
|
||||
branch = master;
|
||||
kind = branch;
|
||||
};
|
||||
};
|
||||
/* End XCRemoteSwiftPackageReference section */
|
||||
|
||||
/* Begin XCSwiftPackageProductDependency section */
|
||||
65B8C632256D352A00C6A3EE /* Keycard */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 65B8C631256D352A00C6A3EE /* XCRemoteSwiftPackageReference "Keycard" */;
|
||||
productName = Keycard;
|
||||
};
|
||||
/* End XCSwiftPackageProductDependency section */
|
||||
};
|
||||
rootObject = 58B511D31A9E6C8500147676 /* Project object */;
|
||||
}
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
|
||||
{
|
||||
"name": "react-native-status-keycard",
|
||||
"version": "2.3.0",
|
||||
"description": "React Native library to interact with Status Keycard using NFC connection (Android only)",
|
||||
"homepage": "https://keycard.status.im/",
|
||||
"version": "2.5.38",
|
||||
"description": "React Native library to interact with Status Keycard using NFC connection",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
require "json"
|
||||
|
||||
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "react-native-status-keycard"
|
||||
s.version = package["version"]
|
||||
s.summary = package["description"]
|
||||
s.homepage = package["homepage"]
|
||||
s.license = package["license"]
|
||||
s.authors = package["author"]
|
||||
|
||||
s.platforms = { :ios => "10.0" }
|
||||
s.source = { :git => "https://github.com/status-im/react-native-status-keycard.git", :tag => "#{s.version}" }
|
||||
|
||||
|
||||
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
||||
|
||||
|
||||
s.dependency "React"
|
||||
s.dependency "Keycard"
|
||||
end
|
||||
Reference in New Issue
Block a user