Permalink
Browse files

Signatures now include EOS Public Key

Signature method changed to include all Ethereum Required Prefix to support more devices.
  • Loading branch information...
rosauthority authored and Webdigi committed Aug 7, 2018
1 parent 11f8287 commit da25ae773b00e502ae7c73a88d7da872fec1dfab
Showing with 27 additions and 14 deletions.
  1. +23 −10 eosio.unregd.cpp
  2. +3 −3 eosio.unregd.hpp
  3. +1 −1 setup.sh
@@ -24,7 +24,7 @@ void unregd::add(const ethereum_address& ethereum_address, const asset& balance)
/**
* Register an EOS account using the stored information (address/balance) verifying an ETH signature
*/
void unregd::regaccount(const bytes& signature, const string& account, const eosio::public_key& eos_pubkey) {
void unregd::regaccount(const bytes& signature, const string& account, const string& eos_pubkey) {

eosio_assert(signature.size() == 66, "Invalid signature");
eosio_assert(account.size() == 12, "Invalid account length");
@@ -42,20 +42,31 @@ void unregd::regaccount(const bytes& signature, const string& account, const eos

// Calculate message hash based on current TX block num/prefix
char* message = (char*)malloc(64);
sprintf(message, "%u,%u", tapos_block_num(), tapos_block_prefix());
const unsigned char* message1 = reinterpret_cast<const unsigned char * >(message);

char* nwmsg1 = (char *)malloc(64);
const abieos::public_key eos_pubkey_gen = abieos::string_to_public_key(eos_pubkey);
sprintf(message, "%u,%ld,%s", tapos_block_num(), tapos_block_prefix(), eos_pubkey.c_str());

//Ethereum Signed message prefix and length of signed message
sprintf(nwmsg1, "%s%s", "\x19", "Ethereum Signed Message:\n");
std::string newmsg = nwmsg1 + std::to_string(strlen(message)) + message;

const uint8_t* message1 = reinterpret_cast<const uint8_t* >(newmsg.c_str());

//calculate sha3 hash instead of sha256
sha3_ctx *shactx1 = (sha3_ctx *)malloc(sizeof(sha3_ctx));

checksum256 msghash1;
rhash_keccak_256_init(shactx1);
rhash_keccak_update(shactx1, message1, strlen(message));
rhash_keccak_update(shactx1, message1, newmsg.length());
rhash_keccak_final(shactx1, msghash1.hash);


array<char, 33> pubkey_char;
copy(eos_pubkey_gen.data.begin(), eos_pubkey_gen.data.end(),
pubkey_char.begin());


// Recover compressed pubkey from signature
uint8_t* pubkey = (uint8_t*)malloc(64);
uint8_t* compressed_pubkey = (uint8_t*)malloc(34);
uint8_t *pubkey = (uint8_t *)malloc(64);
uint8_t *compressed_pubkey = (uint8_t *)malloc(34);
auto res = recover_key(
&msghash1,
signature.data(),
@@ -96,7 +107,9 @@ void unregd::regaccount(const bytes& signature, const string& account, const eos
auto amount_to_purchase_8kb_of_RAM = buyrambytes(8*1024);

// Build authority with the pubkey passed as parameter
auto auth = authority{1,{{eos_pubkey,1}},{},{}};
const auto auth = authority{
1, {{{(uint8_t)abieos::key_type::k1, pubkey_char}, 1}}, {}, {}
};

// Issue to eosio.unregd the necesary EOS to buy 8K of RAM
INLINE_ACTION_SENDER(call::token, issue)( N(eosio.token), {{N(eosio),N(active)}},
@@ -14,7 +14,7 @@
#define USE_KECCAK
#include "sha3/byte_order.c"
#include "sha3/sha3.c"

#include "abieos_numeric.hpp"
#define uECC_SUPPORTS_secp160r1 0
#define uECC_SUPPORTS_secp192r1 0
#define uECC_SUPPORTS_secp224r1 0
@@ -51,8 +51,8 @@ class unregd : public contract {

// Actions
void add(const ethereum_address& ethereum_address, const asset& balance);
void regaccount(const bytes& signature, const string& account, const eosio::public_key& eos_pubkey);

void regaccount(const bytes& signature, const string& account, const string& eos_pubkey);
void printtapos();
private:
static uint8_t hex_char_to_uint(char character) {
const int x = character;
@@ -2,7 +2,7 @@
rm -rf ~/eosio-wallet/./default.wallet
cleos wallet create 2>&1 | tail -n1 | tail -c+2 | head -c-2 > /tmp/pass

cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
cleos wallet import --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
cleos create account eosio eosio.bpay EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
cleos create account eosio eosio.msig EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

0 comments on commit da25ae7

Please sign in to comment.