Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Rust dependencies + BIP39 support #232

Merged
merged 5 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ Parity Signer was built to be used offline. The mobile device used to run the ap
- `rustup` (tested on `rustup 1.16.0`)
- `rustc` (tested on `rustc 1.32.0 (9fda7c223 2019-01-16)`)
- `cargo` (tested on `cargo 1.32.0 (8610973aa 2019-01-02)`)
- `android_ndk` (tested on `r13b`)
- `android_ndk` (tested on `r19`)
- `Android Studio` (only for Android, tested on `Version 3.3`)
- `Xcode` (only for iOS, tested on `Version 9.4.1 (9F2000)`)
- `$NDK_HOME` envarionment variable set to ndk home directory (eg. `/usr/local/opt/android-ndk`)
- `$JAVA_HOME` envarionment variable set to java home directory (eg. `/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home`)
- `$ANDROID_HOME` environment variable set to Android SDK directory (eg. `/home/your_username/Android/Sdk`)*.

\* It's recommended to install **Android Studio** and use that to install the necessary build tools and SDKs for the Android version you want to test on. It's also the best way to test in the emulator. **DO NOT INSTALL NDK VIA ANDROID STUDIO** as that will install the latest version instead of `r13b`.
\* It's recommended to install **Android Studio** and use that to install the necessary build tools and SDKs for the Android version you want to test on. It's also the best way to test in the emulator. **DO NOT INSTALL NDK VIA ANDROID STUDIO** as that will install the latest version. Make sure to get `r19` instead.

### Setup

Expand Down Expand Up @@ -124,3 +124,11 @@ adb shell input keyevent 82
(You can find `adb` binary in your local Android SDK folder under `platform-tools`, eg. `/home/your_username/Android/Sdk/platform-tools`)

This should open a menu on the device. In that menu go to `Dev Settings` > `Debug server host & port for device`, and enter your local IP address with port 8081 (eg. `192.168.1.42:8081`). Restart the app, the error should disappear.

#### Upgrading NDK from `r13b` to `r19`

1. [Download NDK `r19`](https://developer.android.com/ndk/downloads/), unpack it in a convenient location.
1. Update your `NDK_HOME` env variable to the absolute path of the NDK directory.
1. Edit `./android/local.properties` so that `ndk.dir` points to the absolute path to the NDK directory.
1. Remove old NDK build with `rm -rf ./NDK`.
1. Build the new NDK with `./create-ndk-standalone.sh`.
12 changes: 3 additions & 9 deletions android/app/src/main/java/io/parity/signer/EthkeyBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public void brainWalletAddress(String seed, Promise promise) {
promise.resolve(ethkeyBrainwalletAddress(seed));
}

@ReactMethod
public void brainWalletSecret(String seed, Promise promise) {
promise.resolve(ethkeyBrainwalletSecret(seed));
}

@ReactMethod
public void brainWalletSign(String seed, String message, Promise promise) {
promise.resolve(ethkeyBrainwalletSign(seed, message));
Expand Down Expand Up @@ -80,8 +75,8 @@ public void blockiesIcon(String seed, Promise promise) {
}

@ReactMethod
public void randomPhrase(int words, Promise promise) {
promise.resolve(ethkeyRandomPhrase(words));
public void randomPhrase(Promise promise) {
promise.resolve(ethkeyRandomPhrase());
}

@ReactMethod
Expand All @@ -99,13 +94,12 @@ public void decryptData(String data, String password, Promise promise) {
}

private static native String ethkeyBrainwalletAddress(String seed);
private static native String ethkeyBrainwalletSecret(String seed);
private static native String ethkeyBrainwalletSign(String seed, String message);
private static native String ethkeyRlpItem(String data, int position);
private static native String ethkeyKeccak(String data);
private static native String ethkeyEthSign(String data);
private static native String ethkeyBlockiesIcon(String seed);
private static native String ethkeyRandomPhrase(int words);
private static native String ethkeyRandomPhrase();
private static native String ethkeyEncryptData(String data, String password);
private static native String ethkeyDecryptData(String data, String password);
}
22 changes: 11 additions & 11 deletions ios/EthkeyBridge.1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EthkeyBridge: NSObject {
ethkey_keypair_destroy(keypair_ptr)
resolve(address)
}

@objc func brainWalletSecret(_ seed: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var seed_ptr = seed.asPtr()
let keypair_ptr = ethkey_keypair_brainwallet(&seed_ptr)
Expand All @@ -33,7 +33,7 @@ class EthkeyBridge: NSObject {
ethkey_keypair_destroy(keypair_ptr)
resolve(secret)
}

@objc func brainWalletSign(_ seed: String, message: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
print(seed, " + ", message)
var seed_ptr = seed.asPtr()
Expand All @@ -47,7 +47,7 @@ class EthkeyBridge: NSObject {
ethkey_keypair_destroy(keypair_ptr)
resolve(signature)
}

@objc func rlpItem(_ rlp: String, position: UInt32, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var rlp_ptr = rlp.asPtr()
var error: UInt32 = 0
Expand All @@ -62,7 +62,7 @@ class EthkeyBridge: NSObject {
reject("invalid rlp", nil, nil)
}
}

@objc func keccak(_ data: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
let hash_rust_str = keccak256(&data_ptr)
Expand All @@ -72,7 +72,7 @@ class EthkeyBridge: NSObject {
rust_string_destroy(hash_rust_str)
resolve(hash)
}

@objc func ethSign(_ data: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
let hash_rust_str = eth_sign(&data_ptr)
Expand All @@ -82,7 +82,7 @@ class EthkeyBridge: NSObject {
rust_string_destroy(hash_rust_str)
resolve(hash)
}

@objc func blockiesIcon(_ seed: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var seed_ptr = seed.asPtr()
let icon_rust_str = blockies_icon(&seed_ptr)
Expand All @@ -92,16 +92,16 @@ class EthkeyBridge: NSObject {
rust_string_destroy(icon_rust_str)
resolve(icon)
}
@objc func randomPhrase(_ words: UInt32, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
let words_rust_str = random_phrase(words)

@objc func randomPhrase(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
let words_rust_str = random_phrase()
let words_rust_str_ptr = rust_string_ptr(words_rust_str)
let words = String.fromStringPtr(ptr: words_rust_str_ptr!.pointee)
rust_string_ptr_destroy(words_rust_str_ptr)
rust_string_destroy(words_rust_str)
resolve(words)
}

@objc func encryptData(_ data: String, password: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
var password_ptr = password.asPtr()
Expand All @@ -112,7 +112,7 @@ class EthkeyBridge: NSObject {
rust_string_destroy(encrypted_data_rust_str)
resolve(encrypted_data)
}

@objc func decryptData(_ data: String, password: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
var password_ptr = password.asPtr()
Expand Down
36 changes: 12 additions & 24 deletions ios/NativeSigner/EthkeyBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Foundation

@objc(EthkeyBridge)
class EthkeyBridge: NSObject {

open static func requiresMainQueueSetup() -> Bool {
return true;
}

@objc func brainWalletAddress(_ seed: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var seed_ptr = seed.asPtr()
let keypair_ptr = ethkey_keypair_brainwallet(&seed_ptr)
Expand All @@ -26,19 +26,7 @@ class EthkeyBridge: NSObject {
ethkey_keypair_destroy(keypair_ptr)
resolve(address)
}

@objc func brainWalletSecret(_ seed: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var seed_ptr = seed.asPtr()
let keypair_ptr = ethkey_keypair_brainwallet(&seed_ptr)
let secret_rust_str = ethkey_keypair_secret(keypair_ptr)
let secret_rust_str_ptr = rust_string_ptr(secret_rust_str)
let secret = String.fromStringPtr(ptr: secret_rust_str_ptr!.pointee)
rust_string_ptr_destroy(secret_rust_str_ptr)
rust_string_destroy(secret_rust_str)
ethkey_keypair_destroy(keypair_ptr)
resolve(secret)
}


@objc func brainWalletSign(_ seed: String, message: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
print(seed, " + ", message)
var seed_ptr = seed.asPtr()
Expand All @@ -52,7 +40,7 @@ class EthkeyBridge: NSObject {
ethkey_keypair_destroy(keypair_ptr)
resolve(signature)
}

@objc func rlpItem(_ rlp: String, position: UInt32, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var rlp_ptr = rlp.asPtr()
var error: UInt32 = 0
Expand All @@ -67,7 +55,7 @@ class EthkeyBridge: NSObject {
reject("invalid rlp", nil, nil)
}
}

@objc func keccak(_ data: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
let hash_rust_str = keccak256(&data_ptr)
Expand All @@ -77,7 +65,7 @@ class EthkeyBridge: NSObject {
rust_string_destroy(hash_rust_str)
resolve(hash)
}

@objc func ethSign(_ data: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
let hash_rust_str = eth_sign(&data_ptr)
Expand All @@ -87,7 +75,7 @@ class EthkeyBridge: NSObject {
rust_string_destroy(hash_rust_str)
resolve(hash)
}

@objc func blockiesIcon(_ seed: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var seed_ptr = seed.asPtr()
let icon_rust_str = blockies_icon(&seed_ptr)
Expand All @@ -97,16 +85,16 @@ class EthkeyBridge: NSObject {
rust_string_destroy(icon_rust_str)
resolve(icon)
}
@objc func randomPhrase(_ words: UInt32, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
let words_rust_str = random_phrase(words)

@objc func randomPhrase(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
let words_rust_str = random_phrase()
let words_rust_str_ptr = rust_string_ptr(words_rust_str)
let words = String.fromStringPtr(ptr: words_rust_str_ptr!.pointee)
rust_string_ptr_destroy(words_rust_str_ptr)
rust_string_destroy(words_rust_str)
resolve(words)
}

@objc func encryptData(_ data: String, password: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
var password_ptr = password.asPtr()
Expand All @@ -117,7 +105,7 @@ class EthkeyBridge: NSObject {
rust_string_destroy(encrypted_data_rust_str)
resolve(encrypted_data)
}

@objc func decryptData(_ data: String, password: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
var data_ptr = data.asPtr()
var password_ptr = password.asPtr()
Expand Down
Loading