remove deprecated code

This commit is contained in:
Michele Balistreri 2024-10-15 07:32:18 +02:00
parent 2f9d46b2c7
commit 7b3df428ab
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
7 changed files with 13 additions and 191 deletions

View File

@ -14,7 +14,7 @@ React Native library to interact with [Keycard](https://keycard.status.im/) usin
### Manual installation ### Manual installation
Android is the only platform supported by now. Both iOS and Android are supported
#### Android #### Android
@ -38,7 +38,6 @@ Android is the only platform supported by now.
Take a look into [docs](./docs/usage.md) 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 more usage examples, please refer to https://github.com/status-im/status-mobile (assuming you can read Clojure)
For Keycard API documention, please look into https://status.im/keycard_api/ For Keycard API documention, please look into https://keycard.tech/docs/

View File

@ -1,83 +0,0 @@
package im.status.ethereum.keycard;
import android.content.res.AssetManager;
import android.util.Log;
import im.status.keycard.globalplatform.GlobalPlatformCommandSet;
import im.status.keycard.globalplatform.LoadCallback;
import im.status.keycard.io.APDUException;
import im.status.keycard.io.CardChannel;
import org.bouncycastle.util.encoders.Hex;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
public class Installer {
private CardChannel plainChannel;
private AssetManager assets;
private String capPath;
private EventEmitter eventEmitter;
private GlobalPlatformCommandSet cmdSet;
private static final String TAG = "SmartCardInstaller";
public Installer(CardChannel channel, AssetManager assets, String capPath, EventEmitter eventEmitter) {
this.plainChannel = channel;
this.assets = assets;
this.capPath = capPath;
this.eventEmitter = eventEmitter;
}
public void start() throws IOException, APDUException, NoSuchAlgorithmException, InvalidKeySpecException {
Log.i(TAG, "installation started...");
long startTime = System.currentTimeMillis();
eventEmitter.emit("keycardInstallationProgress", 0.05);
Log.i(TAG, "select ISD...");
cmdSet = new GlobalPlatformCommandSet(this.plainChannel);
cmdSet.select().checkOK();
Log.i(TAG, "opening secure channel...");
cmdSet.openSecureChannel();
Log.i(TAG, "deleting old version (if present)...");
cmdSet.deleteKeycardInstancesAndPackage();
eventEmitter.emit("keycardInstallationProgress", 0.1);
Log.i(TAG, "loading package...");
cmdSet.loadKeycardPackage(this.assets.open(this.capPath), new LoadCallback() {
public void blockLoaded(int loadedBlock, int blockCount) {
Log.i(TAG, String.format("load %d/%d...", loadedBlock, blockCount));
eventEmitter.emit("keycardInstallationProgress", 0.1 + (0.6 * loadedBlock / blockCount));
}
});
Log.i(TAG, "installing NDEF applet...");
cmdSet.installNDEFApplet(Hex.decode("0024d40f12616e64726f69642e636f6d3a706b67696d2e7374617475732e657468657265756d")).checkOK();
eventEmitter.emit("keycardInstallationProgress", 0.72);
eventEmitter.emitWithDelay("keycardInstallationProgress", 0.77, 3100);
eventEmitter.emitWithDelay("keycardInstallationProgress", 0.82, 6200);
eventEmitter.emitWithDelay("keycardInstallationProgress", 0.85, 8500);
Log.i(TAG, "installing Keycard applet...");
cmdSet.installKeycardApplet().checkOK();
eventEmitter.removeCallbacksAndMessages();
eventEmitter.emit("keycardInstallationProgress", 0.88);
long duration = System.currentTimeMillis() - startTime;
Log.i(TAG, String.format("\n\ninstallation completed in %d seconds", duration / 1000));
}
}

View File

@ -24,7 +24,6 @@ import im.status.keycard.io.APDUException;
public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements LifecycleEventListener { public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
private static final String TAG = "StatusKeycard"; private static final String TAG = "StatusKeycard";
private static final String CAP_FILENAME = "keycard_v2.2.1.cap";
private SmartCard smartCard; private SmartCard smartCard;
private final ReactApplicationContext reactContext; private final ReactApplicationContext reactContext;
@ -316,40 +315,12 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
@ReactMethod @ReactMethod
public void installApplet(final Promise promise) { public void installApplet(final Promise promise) {
final ReactContext ctx = this.reactContext; promise.reject("E_KEYCARD", "Not implemented (unused)");
new Thread(new Runnable() {
public void run() {
try {
smartCard.installApplet(ctx.getAssets(), CAP_FILENAME);
promise.resolve(true);
} catch (IOException | APDUException | NoSuchAlgorithmException | InvalidKeySpecException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
} }
@ReactMethod @ReactMethod
public void installAppletAndInitCard(final String pin, final Promise promise) { public void installAppletAndInitCard(final String pin, final Promise promise) {
final ReactContext ctx = this.reactContext; promise.reject("E_KEYCARD", "Not implemented (unused)");
new Thread(new Runnable() {
public void run() {
try {
SmartCardSecrets s = smartCard.installAppletAndInitCard(pin, ctx.getAssets(), CAP_FILENAME);
WritableMap params = Arguments.createMap();
params.putString("pin", s.getPin());
params.putString("puk", s.getPuk());
params.putString("password", s.getPairingPassword());
promise.resolve(params);
} catch (IOException | APDUException | NoSuchAlgorithmException | InvalidKeySpecException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
} }
@ReactMethod @ReactMethod
@ -443,17 +414,7 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
@ReactMethod @ReactMethod
public void delete(final Promise promise) { public void delete(final Promise promise) {
new Thread(new Runnable() { promise.reject("E_KEYCARD", "Not implemented (unused)");
public void run() {
try {
smartCard.delete();
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
} }
@ReactMethod @ReactMethod
@ -488,17 +449,7 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
@ReactMethod @ReactMethod
public void unpairAndDelete(final String pin, final Promise promise) { public void unpairAndDelete(final String pin, final Promise promise) {
new Thread(new Runnable() { promise.reject("E_KEYCARD", "Not implemented (unused)");
public void run() {
try {
smartCard.unpairAndDelete(pin);
promise.resolve(true);
} catch (IOException | APDUException e) {
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
} }
@ReactMethod @ReactMethod

View File

@ -474,18 +474,6 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
return data; return data;
} }
public void installApplet(AssetManager assets, String capPath) throws IOException, APDUException, NoSuchAlgorithmException, InvalidKeySpecException {
Installer installer = new Installer(this.cardChannel, assets, capPath, eventEmitter);
installer.start();
}
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(userPin);
}
public int verifyPin(final String pin) throws IOException, APDUException { public int verifyPin(final String pin) throws IOException, APDUException {
KeycardCommandSet cmdSet = authenticatedCommandSet(pin); KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
return 3; return 3;
@ -528,17 +516,6 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
pairings.remove(instanceUID); pairings.remove(instanceUID);
} }
public void delete() throws IOException, APDUException {
GlobalPlatformCommandSet cmdSet = new GlobalPlatformCommandSet(this.cardChannel);
cmdSet.select().checkOK();
cmdSet.openSecureChannel();
Log.i(TAG, "secure channel opened");
cmdSet.deleteKeycardInstancesAndPackage();
Log.i(TAG, "instance and package deleted");
}
public void removeKey(final String pin) throws IOException, APDUException { public void removeKey(final String pin) throws IOException, APDUException {
KeycardCommandSet cmdSet = authenticatedCommandSet(pin); KeycardCommandSet cmdSet = authenticatedCommandSet(pin);
@ -562,11 +539,6 @@ public class SmartCard extends BroadcastReceiver implements CardListener {
pairings.remove(instanceUID); 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 { public String sign(final String pin, final String message) throws IOException, APDUException {
KeycardCommandSet cmdSet = authenticatedCommandSet(pin); KeycardCommandSet cmdSet = authenticatedCommandSet(pin);

View File

@ -100,7 +100,7 @@ Keycard.pair(password).then(pairing => console.log(pairing));
``` ```
`pairing` object contains pairing key as base64 string. `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 You will need pairing key to open secure channel for most keycard operations. More info on pairing https://keycard.tech/docs/sdk/securechannel.html
### Generate mnemonic phrase ### Generate mnemonic phrase
```javascript ```javascript
@ -154,7 +154,7 @@ Keycard.generateAndLoadKey(mnemonic, pairing, pin).then(data => console.log(data
`encryption-public-key` is public key with derivation path `m/43'/60'/1581'/1'/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 More info about key derivation: https://keycard.tech/docs/sdk/derivation_sign.html
### Get keys from keycard ### Get keys from keycard
```javascript ```javascript
@ -205,18 +205,7 @@ Recovery ID: `0`
Would produce signature: `d684afb4ec9ce59f2d112a9c9400bd04f5a5b2518b251dba4ad135448f2e75367c2ea6412893d8001ed9c9efeb7c7d37bc11f7dfcf27c4818cf0861da199de1900` Would produce signature: `d684afb4ec9ce59f2d112a9c9400bd04f5a5b2518b251dba4ad135448f2e75367c2ea6412893d8001ed9c9efeb7c7d37bc11f7dfcf27c4818cf0861da199de1900`
More info about signing: https://status.im/keycard_api/sdk_derivation_sign.html More info about signing: https://keycard.tech/docs/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 ### Remove key
Removes master key from keycard: Removes master key from keycard:
@ -278,11 +267,5 @@ const newPin = "111111";
Keycard.removeKey(pairing, puk, newPin).then(() => console.log("pin unblocked")); 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 ### Keycard CLI
You can also interact with keycard (installing and removing applet, getting card info, etc) using [keycard cli](https://github.com/status-im/keycard-cli). You'll need a USB reader for that. You can also interact with keycard (installing and removing applet, getting card info, etc) using [keycard cli](https://github.com/status-im/keycard-cli). You'll need a USB reader for that.

View File

@ -1,12 +1,12 @@
{ {
"name": "react-native-status-keycard", "name": "react-native-status-keycard",
"homepage": "https://keycard.status.im/", "homepage": "https://keycard.tech/",
"version": "2.6.1", "version": "2.6.2",
"description": "React Native library to interact with Status Keycard using NFC connection", "description": "React Native library to interact with Status Keycard using NFC connection",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "Dmitry Novotochinov", "author": "Michele Balistreri",
"license": "MPL 2.0" "license": "MPL 2.0"
} }