Commit 4f54ca94 authored by Marek Kotewicz's avatar Marek Kotewicz
Browse files

various tweaks

parent 54189492
......@@ -33,4 +33,27 @@ class EthkeyBridge: NSObject {
ethkey_keypair_destroy(keypair_ptr)
callback([secret])
}
@objc func brainWalletSign(_ seed: String, message: String, callback: RCTResponseSenderBlock) -> Void {
var seed_ptr = seed.asPtr()
var message_ptr = message.asPtr()
let keypair_ptr = ethkey_keypair_brainwallet(&seed_ptr)
let signature_rust_str = ethkey_keypair_sign(keypair_ptr, &message_ptr)
let signature_rust_str_ptr = rust_string_ptr(signature_rust_str)
let signature = String.fromStringPtr(ptr: signature_rust_str_ptr!.pointee)
rust_string_ptr_destroy(signature_rust_str_ptr)
rust_string_destroy(signature_rust_str)
ethkey_keypair_destroy(keypair_ptr)
callback([signature])
}
@objc func rlpItem(_ rlp: String, position: UInt32, callback: RCTResponseSenderBlock) -> Void {
var rlp_ptr = rlp.asPtr()
let item_rust_str = rlp_item(&rlp_ptr, position)
let item_rust_str_ptr = rust_string_ptr(item_rust_str)
let item = String.fromStringPtr(ptr: item_rust_str_ptr!.pointee)
rust_string_ptr_destroy(item_rust_str_ptr)
rust_string_destroy(item_rust_str)
callback([item])
}
}
......@@ -12,5 +12,7 @@
RCT_EXTERN_METHOD(brainWalletAddress:(NSString*)seed callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(brainWalletSecret:(NSString*)seed callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(brainWalletSign:(NSString*)seed message:(NSString*)message callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(rlpItem:(NSString*)rlp position:(NSUInteger)position callback:(RCTResponseSenderBlock)callback)
@end
......@@ -6,6 +6,7 @@ authors = ["debris <marek.kotewicz@gmail.com>"]
[dependencies]
libc = "0.2"
ethkey = { git = "https://github.com/ethcore/parity" }
rlp = { git = "https://github.com/ethcore/parity" }
[lib]
name = "signer"
......
......@@ -39,3 +39,10 @@ struct rust_string* ethkey_keypair_secret(const struct keypair_ptr* keypair);
// return keypair address
struct rust_string* ethkey_keypair_address(const struct keypair_ptr* keypair);
// returns message signed with keypair
struct rust_string* ethkey_keypair_sign(const struct keypair_ptr* keypair, const struct rust_string_ptr* message);
// rlp ffi
// returns rlp item at given position
struct rust_string* rlp_item(const struct rust_string_ptr* rlp, const unsigned position);
......@@ -3,7 +3,7 @@ extern crate ethkey;
mod string;
use ethkey::{KeyPair, Generator, Brain};
use ethkey::{KeyPair, Generator, Brain, Message, sign};
use string::StringPtr;
// string ffi
......@@ -48,3 +48,15 @@ pub unsafe extern fn ethkey_keypair_address(keypair: *mut KeyPair) -> *mut Strin
Box::into_raw(Box::new(address))
}
#[no_mangle]
pub unsafe extern fn ethkey_keypair_sign(keypair: *mut KeyPair, message: *mut StringPtr) -> *mut String {
let secret = (*keypair).secret();
let message: Message = (*message).as_str().parse().unwrap();
let signature = format!("{:?}", sign(secret, &message).unwrap());
Box::into_raw(Box::new(signature))
}
#[no_mangle]
pub unsafe extern fn rlp_item(rlp: *mut StringPtr, position: u32) -> *mut String {
unimplemented!();
}
......@@ -16,10 +16,10 @@ export default class AccountDetails extends Component {
render() {
return (
<View style={AppStyles.view}>
<Text style={styles.text}>Name</Text>
<Text style={styles.props}>{this.props.account.name ? this.props.account.name : 'no name'}</Text>
<Text style={styles.text}>Address</Text>
<Text style={styles.props}>{this.props.account.address}</Text>
<Text style={AppStyles.hintText}>Name</Text>
<Text style={AppStyles.valueText}>{this.props.account.name ? this.props.account.name : 'no name'}</Text>
<Text style={AppStyles.hintText}>Address</Text>
<Text style={AppStyles.valueText}>{this.props.account.address}</Text>
<View style={styles.buttonContainer}>
{/*<Button
style={styles.button}
......@@ -42,16 +42,9 @@ export default class AccountDetails extends Component {
}
const styles = StyleSheet.create({
text: {
marginBottom: 20,
},
props: {
marginBottom: 20,
fontSize: 16,
},
buttonContainer: {
flexDirection: 'row',
justifyContent: 'space-between'
//flexDirection: 'row',
//justifyContent: 'space-between'
},
button: {
flex: 0.5,
......
......@@ -25,7 +25,7 @@ export default class NewAccountInput extends Component {
multiline={true}
returnKeyType='default'
numberOfLines={6}
fontSize={16}
fontSize={12}
onChangeText={(text) => {
this.setState({
text: text
......
......@@ -25,6 +25,7 @@ export default class Pin extends Component {
multiline={false}
autoFocus={true}
returnKeyType='next'
keyboardType='numeric'
numberOfLines={1}
fontSize={24}
onChangeText={(text) => {this.setState({text: text})}}
......
'use strict'
import React, { Component, PropTypes } from 'react'
import { StyleSheet, View, Text, TextInput, Button } from 'react-native'
import { StyleSheet, ScrollView, View, Text, TextInput, Button } from 'react-native'
import AppStyles from '../styles'
export default class Send extends Component {
......@@ -9,62 +9,36 @@ export default class Send extends Component {
nextButtonTitle: PropTypes.string.isRequired,
nextButtonDescription: PropTypes.string.isRequired,
nextButtonAction: PropTypes.func.isRequired,
txRecipientAddress: PropTypes.string.isRequired,
txValue: PropTypes.string.isRequired,
txNonce: PropTypes.string.isRequired,
txGas: PropTypes.string.isRequired,
txGasPrice: PropTypes.string.isRequired,
txData: PropTypes.string.isRequired,
}
render() {
return (
<View style={AppStyles.view}>
<Text style={styles.hint}>recipient address</Text>
<TextInput
placeholder='the recipient address'
style={styles.input}
editable={true}
multiline={false}
autoFocus={true}
returnKeyType='next'
numberOfLines={1}
fontSize={16}
/>
<Text style={styles.hint}>amount to transfer (in ETH)</Text>
<TextInput
placeholder=''
value='0.0'
style={styles.input}
editable={true}
multiline={false}
returnKeyType='next'
numberOfLines={1}
fontSize={16}
/>
<Text style={styles.hint}>total transaction amount</Text>
<TextInput
placeholder=''
value='0.0'
style={styles.input}
editable={true}
multiline={false}
returnKeyType='next'
numberOfLines={1}
fontSize={16}
/>
<ScrollView style={AppStyles.view}>
<Text style={AppStyles.hintText}>recipient address</Text>
<Text style={AppStyles.valueText}>{this.props.txRecipientAddress}</Text>
<Text style={AppStyles.hintText}>amount to transfer (in ETH)</Text>
<Text style={AppStyles.valueText}>{this.props.txValue}</Text>
<Text style={AppStyles.hintText}>nonce</Text>
<Text style={AppStyles.valueText}>{this.props.txNonce}</Text>
<Text style={AppStyles.hintText}>gas</Text>
<Text style={AppStyles.valueText}>{this.props.txGas}</Text>
<Text style={AppStyles.hintText}>gasPrice</Text>
<Text style={AppStyles.valueText}>{this.props.txGasPrice}</Text>
<Text style={AppStyles.hintText}>data</Text>
<Text style={AppStyles.valueText}>{this.props.txData}</Text>
<Button
onPress={() => this.props.nextButtonAction()}
title={this.props.nextButtonTitle}
color="green"
accessibilityLabel={this.props.nextButtonDescription}
/>
</View>
</ScrollView>
)
}
}
const styles = StyleSheet.create({
hint: {
marginBottom: 20,
},
input: {
height: 20,
marginBottom: 20,
}
})
......@@ -8,6 +8,12 @@ import Send from '../components/Send'
const mapStateToProps = (state, ownProps) => ({
nextButtonTitle: 'Next',
nextButtonDescription: 'Choose account',
txRecipientAddress: '0xbF35fAA9C265bAf50C9CFF8c389C363B05753275',
txValue: '20 eth',
txNonce: '100',
txGas: '200',
txGasPrice: '',
txData: '',
})
const mapDispatchToProps = (dispatch, ownProps) => ({
......
......@@ -7,7 +7,7 @@ import { Actions } from 'react-native-router-flux'
import debounce from 'debounce'
import NewAccountInput from '../components/NewAccountInput'
import { words } from '../util/random'
import { brainWalletAddress } from '../util/crypto'
import { brainWalletAddress } from '../util/native'
import { selectAccount } from '../actions/accounts'
import AppStyles from '../styles'
......@@ -47,7 +47,7 @@ export class NewAccount extends Component {
var self = this;
return (
<View style={AppStyles.view}>
<Text style={styles.hint}>name</Text>
<Text style={AppStyles.hintText}>name</Text>
<TextInput
placeholder='My Account'
value={this.state.name}
......@@ -56,11 +56,11 @@ export class NewAccount extends Component {
multiline={false}
returnKeyType='next'
numberOfLines={1}
fontSize={16}
fontSize={12}
autoFocus={true}
onChangeText={(text) => {this.setState({name: text})}}
/>
<Text style={styles.hint}>brain wallet seed</Text>
<Text style={AppStyles.hintText}>brain wallet seed</Text>
<NewAccountInput seed={this.state.seed} onChangeText={
debounce((text) => {
brainWalletAddress(text, (address) => {
......@@ -71,7 +71,7 @@ export class NewAccount extends Component {
})
}, 100)}
/>
<Text style={styles.address}>0x{this.state.address}</Text>
<Text style={AppStyles.valueText}>0x{this.state.address}</Text>
<Button
onPress={() => this.props.addAccount({
seed: this.state.seed,
......
......@@ -14,5 +14,16 @@ export default StyleSheet.create({
flex: 1,
marginTop: 64,
marginBottom: 50,
}
},
hintText: {
fontSize: 14,
color: '#ccc',
marginBottom: 20,
},
valueText: {
fontSize: 12,
color: 'black',
marginBottom: 20,
fontWeight: 'bold',
},
})
import { EthkeyBridge } from 'NativeModules'
export const brainWalletAddress = EthkeyBridge.brainWalletAddress;
export const brainWalletSecret = EthkeyBridge.brainWalletSecret;
export const brainWalletAddress = EthkeyBridge.brainWalletAddress
export const brainWalletSecret = EthkeyBridge.brainWalletSecret
export const brainWalletSign = EthkeyBridge.brainWalletSign
export const rlpItem = EthkeyBridge.rlpItem
import { rlpItem } from './native'
class Transaction {
constructor(nonce, gasPrice, gas, action, value, data) {
this.nonce = nonce
this.gasPrice = gasPrice
this.gas = gas
this.action = action
this.value = value
this.data = data
}
}
export default function transactionFromRlp(rlp, callback) {
}
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