Commit 9d87defc authored by Marek Kotewicz's avatar Marek Kotewicz
Browse files

display real signatures in qr code

parent 88b3ceb9
...@@ -35,6 +35,7 @@ class EthkeyBridge: NSObject { ...@@ -35,6 +35,7 @@ class EthkeyBridge: NSObject {
} }
@objc func brainWalletSign(_ seed: String, message: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void { @objc func brainWalletSign(_ seed: String, message: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
print(seed, " + ", message)
var seed_ptr = seed.asPtr() var seed_ptr = seed.asPtr()
var message_ptr = message.asPtr() var message_ptr = message.asPtr()
let keypair_ptr = ethkey_keypair_brainwallet(&seed_ptr) let keypair_ptr = ethkey_keypair_brainwallet(&seed_ptr)
...@@ -61,4 +62,14 @@ class EthkeyBridge: NSObject { ...@@ -61,4 +62,14 @@ class EthkeyBridge: NSObject {
reject("invalid rlp", nil, nil) 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)
let hash_rust_str_ptr = rust_string_ptr(hash_rust_str)
let hash = String.fromStringPtr(ptr: hash_rust_str_ptr!.pointee)
rust_string_ptr_destroy(hash_rust_str_ptr)
rust_string_destroy(hash_rust_str)
resolve(hash)
}
} }
...@@ -11,11 +11,9 @@ ...@@ -11,11 +11,9 @@
@interface RCT_EXTERN_MODULE(EthkeyBridge, NSObject) @interface RCT_EXTERN_MODULE(EthkeyBridge, NSObject)
RCT_EXTERN_METHOD(brainWalletAddress:(NSString*)seed resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(brainWalletAddress:(NSString*)seed resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
//RCT_EXTERN_METHOD(brainWalletSecret:(NSString*)seed callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(brainWalletSecret:(NSString*)seed resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(brainWalletSecret:(NSString*)seed resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
//RCT_EXTERN_METHOD(brainWalletSign:(NSString*)seed message:(NSString*)message callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(brainWalletSign:(NSString*)seed message:(NSString*)message resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(brainWalletSign:(NSString*)seed message:(NSString*)message resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
//RCT_EXTERN_METHOD(rlpItem:(NSString*)rlp position:(NSUInteger)position callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(rlpItem:(NSString*)rlp position:(NSUInteger)position 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)
@end @end
...@@ -8,6 +8,7 @@ libc = "0.2" ...@@ -8,6 +8,7 @@ libc = "0.2"
rustc-serialize = "0.3" rustc-serialize = "0.3"
ethkey = { git = "https://github.com/ethcore/parity" } ethkey = { git = "https://github.com/ethcore/parity" }
rlp = { git = "https://github.com/ethcore/parity" } rlp = { git = "https://github.com/ethcore/parity" }
tiny-keccak = "1.1"
[lib] [lib]
name = "signer" name = "signer"
......
...@@ -46,3 +46,7 @@ struct rust_string* ethkey_keypair_sign(const struct keypair_ptr* keypair, const ...@@ -46,3 +46,7 @@ struct rust_string* ethkey_keypair_sign(const struct keypair_ptr* keypair, const
// returns rlp item at given position // returns rlp item at given position
struct rust_string* rlp_item(const struct rust_string_ptr* rlp, const unsigned position, unsigned* error); struct rust_string* rlp_item(const struct rust_string_ptr* rlp, const unsigned position, unsigned* error);
// sha3 ffi
struct rust_string* keccak256(const struct rust_string_ptr* data);
extern crate libc; extern crate libc;
extern crate rustc_serialize; extern crate rustc_serialize;
extern crate tiny_keccak;
extern crate ethkey; extern crate ethkey;
extern crate rlp; extern crate rlp;
mod string; mod string;
use rustc_serialize::hex::{ToHex, FromHex}; use rustc_serialize::hex::{ToHex, FromHex};
use tiny_keccak::Keccak;
use ethkey::{KeyPair, Generator, Brain, Message, sign}; use ethkey::{KeyPair, Generator, Brain, Message, sign};
use rlp::{UntrustedRlp, View}; use rlp::{UntrustedRlp, View};
...@@ -81,6 +83,17 @@ pub unsafe extern fn rlp_item(rlp: *mut StringPtr, position: u32, error: *mut u3 ...@@ -81,6 +83,17 @@ pub unsafe extern fn rlp_item(rlp: *mut StringPtr, position: u32, error: *mut u3
} }
} }
#[no_mangle]
pub unsafe extern fn keccak256(data: *mut StringPtr) -> *mut String {
let data = (*data).as_str();
let hex = data.from_hex().unwrap();
let mut res: [u8; 32] = [0; 32];
let mut keccak = Keccak::new_keccak256();
keccak.update(&hex);
keccak.finalize(&mut res);
Box::into_raw(Box::new(res.to_hex()))
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::safe_rlp_item; use super::safe_rlp_item;
......
...@@ -10,9 +10,9 @@ export function scannedTx(rlp, transaction) { ...@@ -10,9 +10,9 @@ export function scannedTx(rlp, transaction) {
} }
} }
export function signedTx(data) { export function signedTx(signature) {
return { return {
type: SIGNED_TX, type: SIGNED_TX,
data: data, signature: signature,
} }
} }
...@@ -39,9 +39,6 @@ const scenes = Actions.create( ...@@ -39,9 +39,6 @@ const scenes = Actions.create(
<Scene key='scan' <Scene key='scan'
component={QrScanner} component={QrScanner}
title='Scan QR' title='Scan QR'
rightTitle="Skip*"
onRight={() => Actions.confirm()}
rightButtonTextStyle={styles.navibarTitle}
/> />
<Scene key='confirm' component={ConfirmTransaction} title='Sign Tx' <Scene key='confirm' component={ConfirmTransaction} title='Sign Tx'
backTitle='Back' backTitle='Back'
......
...@@ -25,12 +25,11 @@ export default class Pin extends Component { ...@@ -25,12 +25,11 @@ export default class Pin extends Component {
multiline={false} multiline={false}
autoFocus={true} autoFocus={true}
returnKeyType='next' returnKeyType='next'
keyboardType='numeric'
numberOfLines={1} numberOfLines={1}
fontSize={24} fontSize={24}
onChangeText={(text) => {this.setState({text: text})}} onChangeText={(text) => {this.setState({text: text})}}
value={this.state.text} value={this.state.text}
onEndEditing={() => { this.props.onNextPressed(this.state.text, this.props.account) }} onEndEditing={() => { this.props.onNextPressed(this.state.text, this.props.account, this.props.extra) }}
/> />
</View> </View>
) )
......
...@@ -7,16 +7,28 @@ import { Actions } from 'react-native-router-flux' ...@@ -7,16 +7,28 @@ import { Actions } from 'react-native-router-flux'
import Pin from '../components/Pin' import Pin from '../components/Pin'
import { addAccount, setPin } from '../actions/accounts' import { addAccount, setPin } from '../actions/accounts'
import { signedTx } from '../actions/transactions' import { signedTx } from '../actions/transactions'
import { keccak, brainWalletSign } from '../util/native'
const mapStateToPropsEnterPin = (state, ownProps) => ({ const mapStateToPropsEnterPin = (state, ownProps) => ({
account: state.accounts.selected, account: state.accounts.selected,
extra: state.transactions.pendingTransaction.rlp,
}) })
async function signTransaction(dispatch, account, rlp) {
try {
let hash = await keccak(rlp)
let signature = await brainWalletSign(account.seed, hash)
dispatch(signedTx(signature))
Actions.display()
} catch (e) {
console.log(e)
}
}
const mapDispatchToPropsEnterPin = (dispatch, ownProps) => ({ const mapDispatchToPropsEnterPin = (dispatch, ownProps) => ({
onNextPressed: (pin, account) => { onNextPressed: (pin, account, rlp) => {
if (pin === account.pin) { if (pin === account.pin) {
dispatch(signedTx('my super awesome data')) signTransaction(dispatch, account, rlp)
Actions.display()
} else { } else {
Alert.alert('Invalid pin') Alert.alert('Invalid pin')
} }
......
...@@ -6,10 +6,12 @@ const initialAccounts = { ...@@ -6,10 +6,12 @@ const initialAccounts = {
all: [{ all: [{
address: 'bF35fAA9C265bAf50C9CFF8c389C363B05753275', address: 'bF35fAA9C265bAf50C9CFF8c389C363B05753275',
name: 'Test: Wallet', name: 'Test: Wallet',
seed: '123',
pin: '', pin: '',
}, { }, {
address: '4EECf99D543B278106ac0c0e8ffe616F2137f10a', address: '4EECf99D543B278106ac0c0e8ffe616F2137f10a',
name: 'Test: LockMyEther', name: 'Test: LockMyEther',
seed: '123',
pin: '', pin: '',
}], }],
selected: {}, selected: {},
......
...@@ -8,8 +8,7 @@ const initialState = { ...@@ -8,8 +8,7 @@ const initialState = {
rlp: '', rlp: '',
}, },
signedTransaction: { signedTransaction: {
transaction: {}, signature: '',
rlp: '',
}, },
} }
...@@ -24,7 +23,7 @@ export default function transactions(state = initialState, action) { ...@@ -24,7 +23,7 @@ export default function transactions(state = initialState, action) {
}) })
case SIGNED_TX: case SIGNED_TX:
return Object.assign({}, state, { return Object.assign({}, state, {
signedTransaction: action.data, signedTransaction: action.signature,
}) })
default: default:
return state return state
......
...@@ -4,3 +4,4 @@ export const brainWalletAddress = EthkeyBridge.brainWalletAddress ...@@ -4,3 +4,4 @@ export const brainWalletAddress = EthkeyBridge.brainWalletAddress
export const brainWalletSecret = EthkeyBridge.brainWalletSecret export const brainWalletSecret = EthkeyBridge.brainWalletSecret
export const brainWalletSign = EthkeyBridge.brainWalletSign export const brainWalletSign = EthkeyBridge.brainWalletSign
export const rlpItem = EthkeyBridge.rlpItem export const rlpItem = EthkeyBridge.rlpItem
export const keccak = EthkeyBridge.keccak
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