Commit e86bea08 authored by Marek Kotewicz's avatar Marek Kotewicz
Browse files

blockies identicons working on iOS

parent 7f183b78
......@@ -72,4 +72,14 @@ 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)
let icon_rust_str_ptr = rust_string_ptr(icon_rust_str)
let icon = String.fromBinaryStringPtr(ptr: icon_rust_str_ptr!.pointee)
rust_string_ptr_destroy(icon_rust_str_ptr)
rust_string_destroy(icon_rust_str)
resolve(icon)
}
}
......@@ -15,5 +15,6 @@ RCT_EXTERN_METHOD(brainWalletSecret:(NSString*)seed resolve:(RCTPromiseResolveBl
RCT_EXTERN_METHOD(brainWalletSign:(NSString*)seed message:(NSString*)message resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(rlpItem:(NSString*)rlp position:(NSUInteger)position resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(keccak:(NSString*)data resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(blockiesIcon:(NSString*)seed resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
@end
......@@ -14,6 +14,11 @@ 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)
......
......@@ -2,6 +2,7 @@
name = "signer"
version = "0.1.0"
dependencies = [
"blockies 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethkey 0.2.0 (git+https://github.com/ethcore/parity)",
"jni 0.3.1 (git+https://github.com/prevoty/jni-rs)",
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -10,6 +11,11 @@ dependencies = [
"tiny-keccak 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "adler32"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "arrayvec"
version = "0.3.20"
......@@ -35,6 +41,20 @@ dependencies = [
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "blockies"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hsl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byteorder"
version = "1.0.0"
......@@ -53,6 +73,15 @@ dependencies = [
"ascii 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "deflate"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"adler32 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "elastic-array"
version = "0.6.0"
......@@ -61,6 +90,14 @@ dependencies = [
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "enum_primitive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "error-chain"
version = "0.9.0"
......@@ -81,7 +118,7 @@ dependencies = [
[[package]]
name = "ethcore-bigint"
version = "0.1.2"
source = "git+https://github.com/ethcore/parity#7a773b42bf03fa9a0fc7795adb0ef0a245158836"
source = "git+https://github.com/ethcore/parity#9efab789aa875ad3b6930403135ea9bdf1c3468b"
dependencies = [
"bigint 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -93,7 +130,7 @@ dependencies = [
[[package]]
name = "ethkey"
version = "0.2.0"
source = "git+https://github.com/ethcore/parity#7a773b42bf03fa9a0fc7795adb0ef0a245158836"
source = "git+https://github.com/ethcore/parity#9efab789aa875ad3b6930403135ea9bdf1c3468b"
dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth-secp256k1 0.5.6 (git+https://github.com/ethcore/rust-secp256k1)",
......@@ -110,6 +147,11 @@ name = "gcc"
version = "0.3.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "heapsize"
version = "0.3.8"
......@@ -118,6 +160,30 @@ dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "hsl"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "image"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"num-rational 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"png 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "inflate"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "jni"
version = "0.3.1"
......@@ -167,11 +233,53 @@ dependencies = [
"odds 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-iter"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-rational"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "odds"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "png"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"deflate 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
"inflate 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.3.15"
......@@ -188,8 +296,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rlp"
version = "0.1.0"
source = "git+https://github.com/ethcore/parity#7a773b42bf03fa9a0fc7795adb0ef0a245158836"
source = "git+https://github.com/ethcore/parity#9efab789aa875ad3b6930403135ea9bdf1c3468b"
dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"elastic-array 0.6.0 (git+https://github.com/ethcore/elastic-array)",
"ethcore-bigint 0.1.2 (git+https://github.com/ethcore/parity)",
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -259,19 +368,28 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum adler32 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ff33fe13a08dbce05bcefa2c68eea4844941437e33d6f808240b54d7157b9cd"
"checksum arrayvec 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d89f1b0e242270b5b797778af0c8d182a1a2ccac5d8d6fadf414223cc0fab096"
"checksum ascii 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae7d751998c189c1d4468cf0a39bb2eae052a9c58d50ebb3b9591ee3813ad50"
"checksum bigint 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4987c855cbe118271721d21f16cacdfedfe7dbeb7ea5970e4ae33db06602e3f2"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum blockies 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "88f848260161ae4410b5133744d5f47b7b126cf1bb4a08a552f2de328022f1d3"
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
"checksum cesu8 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
"checksum combine 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89749770bffc77cb34db11b60d5d4b197388b46bc7774ac8acbde33c26ad6c08"
"checksum deflate 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ebb02aaf4b775afc96684b8402510a338086974e38570a1f65bea8c202eb77a7"
"checksum elastic-array 0.6.0 (git+https://github.com/ethcore/elastic-array)" = "<none>"
"checksum enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180"
"checksum error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e92ecf0a508c8e074c0e6fa8fe0fa38414848ad4dfc4db6f74c5e9753330b248"
"checksum eth-secp256k1 0.5.6 (git+https://github.com/ethcore/rust-secp256k1)" = "<none>"
"checksum ethcore-bigint 0.1.2 (git+https://github.com/ethcore/parity)" = "<none>"
"checksum ethkey 0.2.0 (git+https://github.com/ethcore/parity)" = "<none>"
"checksum gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)" = "c07c758b972368e703a562686adb39125707cc1ef3399da8c019fc6c2498a75d"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "5a376f7402b85be6e0ba504243ecbc0709c48019ecc6286d0540c2e359050c88"
"checksum hsl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "575fb7f1167f3b88ed825e90eb14918ac460461fdeaa3965c6a50951dee1c970"
"checksum image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "979bad0502082fd60053a490282e87d6c89650942e3a270e0d4c83569c7f5899"
"checksum inflate 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7e0062d2dc2f17d2f13750d95316ae8a2ff909af0fda957084f5defd87c43bb"
"checksum jni 0.3.1 (git+https://github.com/prevoty/jni-rs)" = "<none>"
"checksum jni-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "83ba0fad4625733b25833da250d0c84058314e1a276f4939f3e87c195997c206"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
......@@ -279,7 +397,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5"
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
"checksum nodrop 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "52cd74cd09beba596430cc6e3091b74007169a56246e1262f0ba451ea95117b2"
"checksum num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "21e4df1098d1d797d27ef0c69c178c3fab64941559b290fcae198e0825c9c8b5"
"checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e"
"checksum num-rational 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "c2dc5ea04020a8f18318ae485c751f8cfa1c0e69dcf465c29ddaaa64a313cc44"
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
"checksum odds 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "c3df9b730298cea3a1c3faa90b7e2f9df3a9c400d0936d6015e6165734eefcba"
"checksum png 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3cb773e9a557edb568ce9935cf783e3cdcabe06a9449d41b3e5506d88e582c82"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd35cc9a8bdec562c757e3d43c1526b5c6d2653e23e2315065bc25556550753"
"checksum rlp 0.1.0 (git+https://github.com/ethcore/parity)" = "<none>"
......
......@@ -9,6 +9,7 @@ rustc-serialize = "0.3"
ethkey = { git = "https://github.com/ethcore/parity" }
rlp = { git = "https://github.com/ethcore/parity" }
tiny-keccak = "1.1"
blockies = "0.1"
[target.'cfg(target_os="android")'.dependencies]
jni = { git = "https://github.com/prevoty/jni-rs", default-features = false }
......
......@@ -50,3 +50,7 @@ struct rust_string* rlp_item(const struct rust_string_ptr* rlp, const unsigned p
// sha3 ffi
struct rust_string* keccak256(const struct rust_string_ptr* data);
// blockies ffi
struct rust_string* blockies_icon(const struct rust_string_ptr* blockies_seed);
......@@ -3,13 +3,15 @@ extern crate rustc_serialize;
extern crate tiny_keccak;
extern crate ethkey;
extern crate rlp;
extern crate blockies;
mod string;
use rustc_serialize::hex::{ToHex, FromHex};
use tiny_keccak::Keccak;
use ethkey::{KeyPair, Generator, Brain, Message, sign};
use rlp::{UntrustedRlp, View};
use rlp::UntrustedRlp;
use blockies::{Blockies, create_icon, ethereum};
use string::StringPtr;
......@@ -94,6 +96,24 @@ pub unsafe extern fn keccak256(data: *mut StringPtr) -> *mut String {
Box::into_raw(Box::new(res.to_hex()))
}
#[no_mangle]
pub unsafe extern fn blockies_icon(blockies_seed: *mut StringPtr) -> *mut String {
let blockies_seed = (*blockies_seed).as_str();
let seed: Vec<u8> = blockies_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();
Box::into_raw(Box::new(String::from_utf8_unchecked(result)))
}
#[cfg(target_os = "android")]
#[allow(non_snake_case)]
pub mod android {
......
'use strict'
import React, { Component, PropTypes } from 'react'
import { TouchableHighlight, StyleSheet, View, Text } from 'react-native'
import { TouchableHighlight, StyleSheet, View, Text, Image } from 'react-native'
import { blockiesIcon } from '../util/native'
async function displayIcon(self, seed) {
try {
let icon = await blockiesIcon(seed)
self.setState({
icon: 'data:image/png;base64,' + icon,
})
} catch (e) {
console.log(e)
}
}
export default class AccountListRow extends Component {
static propTypes = {
......@@ -10,12 +23,22 @@ export default class AccountListRow extends Component {
onPress: PropTypes.func.isRequired,
}
constructor(props) {
super(props)
this.state = {}
}
render() {
displayIcon(this, this.props.lowerText)
return (
<TouchableHighlight style={styles.row} onPress={this.props.onPress} underlayColor='#0004'>
<View style={{flexDirection: 'column'}}>
<View style={{flexDirection: 'row'}}>
<View style={styles.square}/>
<Image
style={styles.square}
source={{uri: this.state.icon}}
/>
<View style={{flexDirection: 'column'}}>
<Text style={styles.upperText} ellipsizeMode="middle" numberOfLines={1}>{this.props.upperText}</Text>
<Text style={styles.lowerText} ellipsizeMode="middle" numberOfLines={1}>{this.props.lowerText}</Text>
......@@ -36,8 +59,9 @@ const styles = StyleSheet.create({
square: {
height: 60,
width: 60,
backgroundColor: '#D8D8D8',
//backgroundColor: '#D8D8D8',
marginRight: 10,
resizeMode: 'contain',
},
upperText: {
marginTop: 20,
......@@ -49,5 +73,5 @@ const styles = StyleSheet.create({
marginTop: 5,
color: '#aaa',
fontSize: 10,
}
},
})
......@@ -5,3 +5,4 @@ export const brainWalletSecret = (seed) => EthkeyBridge.brainWalletSecret(seed)
export const brainWalletSign = (seed, message) => EthkeyBridge.brainWalletSign(seed, message)
export const rlpItem = (rlp, position) => EthkeyBridge.rlpItem(rlp, position)
export const keccak = (data) => EthkeyBridge.keccak(data)
export const blockiesIcon = (seed) => EthkeyBridge.blockiesIcon(seed)
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