-
-
Save tjade273/f26f50d2ca6f3325750d to your computer and use it in GitHub Desktop.
Created using soleditor: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://chriseth.github.io/browser-solidity/?gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library HashLadder{ | |
function genPubKey(bytes32[2][32] privKey) returns (bytes32[2][32]){ | |
bytes32[2][32] memory pubKey; | |
for(uint8 i; i< 32; i++){ | |
bytes32 pa = privKey[i][0]; | |
bytes32 pb = privKey[i][1]; | |
for(uint k; k<258; k++){ | |
pa = sha3(pa); | |
pb = sha3(pb); | |
} | |
pubKey[i] = [pa,pb]; | |
} | |
return pubKey; | |
} | |
function sign_chunk(byte chunk, bytes32[2] privKey) constant returns(bytes32[2]){ | |
bytes32[2] memory pubKey; | |
uint n = uint8(chunk); | |
bytes32 a = privKey[0]; | |
bytes32 b = privKey[1]; | |
for(uint i; i < n+1; i++){ | |
a = sha3(a); | |
} | |
for(uint j; j < 256-n; j++){ | |
b = sha3(b); | |
} | |
return([a,b]); | |
} | |
function sign(bytes message, bytes32[2][32] privKey) returns(bytes32[2][32]){ | |
bytes32 hash = sha3(message); | |
bytes32[2][32] memory sig; | |
bytes32[2][32] memory key; | |
for(uint8 i; i<32;i++){ | |
sig[i] = sign_chunk(hash[i],privKey[i]); | |
} | |
return (sig); | |
} | |
function verify_chunk(byte chunk, bytes32[2] pubKey, bytes32[2] signature) constant returns (bool){ | |
uint a_i; | |
uint b_i; | |
bytes32 a = signature[0]; | |
bytes32 b = signature[1]; | |
while(b_i <= 258 && b != pubKey[1]){ | |
b = sha3(b); | |
b_i++; | |
} | |
while(a_i <= 258 && a != pubKey[0]){ | |
a = sha3(a); | |
a_i++; | |
} | |
return (uint(chunk) == b_i - 2 && b_i == 259 - a_i); | |
//return true; | |
} | |
function verify(bytes32 msgHash, bytes32[2][32] pubKey, bytes32[2][32] signature) public returns (bool){ | |
for(uint8 i; i<32; i++){ | |
if(!verify_chunk(msgHash[i],pubKey[i],signature[i])) return false; | |
} | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "HashLadder"; | |
contract qETH { | |
HashLadder hashLib; | |
enum AuthType {Transfer, Withdrawl} | |
struct Account { | |
bytes32 pubKeyHash; | |
Authorization[] auths; | |
} | |
struct Authorization { | |
AuthType _authType; | |
address from; | |
address to; | |
uint value; | |
//Todo: add gas reimbursement for miners | |
uint8 chunksProcessed; | |
bytes32 msgHash; | |
bytes32 authHash; //Should equal pubKeyHash | |
} | |
mapping(address => Account) accounts; | |
function send(address _from, address _to, uint _value){ | |
bytes32 _msgHash = sha3(_from,_to,_value,) | |
Authorization memory auth = Authorization(AuthType.Transfer,_from,_to,_value,0); | |
accounts[_from].auths; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment