Commit 15f5691b authored by Marek Kotewicz's avatar Marek Kotewicz
Browse files

blockies on android

parent e86bea08
......@@ -4,6 +4,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Promise;
import android.util.Base64;
/**
* Created by marek on 20/02/2017.
......@@ -53,9 +54,15 @@ public class EthkeyBridge extends ReactContextBaseJavaModule {
promise.resolve(ethkeyKeccak(data));
}
@ReactMethod
public void blockiesIcon(String seed, Promise promise) {
promise.resolve(ethkeyBlockiesIcon(seed));
}
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 ethkeyBlockiesIcon(String seed);
}
\ No newline at end of file
......@@ -77,7 +77,7 @@ class EthkeyBridge: NSObject {
var seed_ptr = seed.asPtr()
let icon_rust_str = blockies_icon(&seed_ptr)
let icon_rust_str_ptr = rust_string_ptr(icon_rust_str)
let icon = String.fromBinaryStringPtr(ptr: icon_rust_str_ptr!.pointee)
let icon = String.fromStringPtr(ptr: icon_rust_str_ptr!.pointee)
rust_string_ptr_destroy(icon_rust_str_ptr)
rust_string_destroy(icon_rust_str)
resolve(icon)
......
......@@ -14,11 +14,6 @@ extension String {
return String(data: data as Data, encoding: String.Encoding.utf8)!
}
static func fromBinaryStringPtr(ptr: rust_string_ptr) -> String {
let data = NSData(bytes: UnsafeRawPointer(ptr.ptr), length: ptr.len)
return data.base64EncodedString(options: NSData.Base64EncodingOptions.init(rawValue: 0))
}
func asPtr() -> rust_string_ptr {
let data = self.data(using: String.Encoding.utf8, allowLossyConversion: false)!
return rust_string_ptr(ptr: (data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count), len: data.count)
......
......@@ -8,6 +8,7 @@ extern crate blockies;
mod string;
use rustc_serialize::hex::{ToHex, FromHex};
use rustc_serialize::base64::{self, ToBase64};
use tiny_keccak::Keccak;
use ethkey::{KeyPair, Generator, Brain, Message, sign};
use rlp::UntrustedRlp;
......@@ -111,7 +112,13 @@ pub unsafe extern fn blockies_icon(blockies_seed: *mut StringPtr) -> *mut String
};
create_icon(&mut result, Blockies::Ethereum(options)).unwrap();
Box::into_raw(Box::new(String::from_utf8_unchecked(result)))
let base64_icon = result.to_base64(base64::Config {
char_set: base64::CharacterSet::Standard,
newline: base64::Newline::LF,
pad: true,
line_length: None,
});
Box::into_raw(Box::new(base64_icon))
}
#[cfg(target_os = "android")]
......@@ -174,6 +181,29 @@ pub mod android {
keccak.finalize(&mut res);
env.new_string(res.to_hex()).expect("Could not create java string").into_inner()
}
#[no_mangle]
pub unsafe extern fn Java_com_nativesigner_EthkeyBridge_ethkeyBlockiesIcon(env: JNIEnv, _: JClass, seed: JString) -> jstring {
let seed: String = env.get_string(seed).expect("Invalid seed").into();
let seed: Vec<u8> = seed.into();
let mut result = Vec::new();
let options = ethereum::Options {
size: 8,
scale: 16,
seed: seed,
color: None,
background_color: None,
spot_color: None,
};
create_icon(&mut result, Blockies::Ethereum(options)).unwrap();
let base64_icon = result.to_base64(base64::Config {
char_set: base64::CharacterSet::Standard,
newline: base64::Newline::LF,
pad: true,
line_length: None,
});
env.new_string(base64_icon).expect("Could not create java string").into_inner()
}
}
#[cfg(test)]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment