File tree Expand file tree Collapse file tree 4 files changed +28
-13
lines changed
Expand file tree Collapse file tree 4 files changed +28
-13
lines changed Original file line number Diff line number Diff line change @@ -18,15 +18,29 @@ pub struct Account {
1818
1919impl Account {
2020 pub fn with_index ( wallet : & Wallet , index : u32 , prefix : & str ) -> Account {
21- let ( private_key, public_key) = Account :: get_keypair ( & wallet. seed , index) ;
22- Account {
23- index,
24- private_key,
25- public_key,
26- address : get_address ( & public_key, Some ( prefix) ) ,
27- balance : 0 ,
28- receivables : vec ! [ ] ,
29- messages : Ok ( vec ! [ ] ) ,
21+ if wallet. mnemonic . is_empty ( ) {
22+ // Generate using seed as private key.
23+ let public_key = Wallet :: get_public_key ( & wallet. seed ) ;
24+ Account {
25+ index,
26+ private_key : wallet. seed ,
27+ public_key,
28+ address : get_address ( & public_key, Some ( prefix) ) ,
29+ balance : 0 ,
30+ receivables : vec ! [ ] ,
31+ messages : Ok ( vec ! [ ] ) ,
32+ }
33+ } else {
34+ let ( private_key, public_key) = Account :: get_keypair ( & wallet. seed , index) ;
35+ Account {
36+ index,
37+ private_key,
38+ public_key,
39+ address : get_address ( & public_key, Some ( prefix) ) ,
40+ balance : 0 ,
41+ receivables : vec ! [ ] ,
42+ messages : Ok ( vec ! [ ] ) ,
43+ }
3044 }
3145 }
3246
Original file line number Diff line number Diff line change @@ -30,11 +30,12 @@ impl Wallet {
3030 wallet
3131 }
3232 pub fn new_key ( private_key : [ u8 ; 32 ] , name : String , prefix : & str ) -> Wallet {
33+ // Use seed field for private key for private key wallets.
3334 let public_key = Wallet :: get_public_key ( & private_key) ;
3435 let mut wallet = Wallet {
3536 name,
3637 mnemonic : String :: from ( "" ) ,
37- seed : [ 0u8 ; 32 ] ,
38+ seed : private_key ,
3839 indexes : vec ! [ 0 ] ,
3940 accounts : vec ! [ ] ,
4041 acc_idx : 0 ,
@@ -51,7 +52,7 @@ impl Wallet {
5152 wallet
5253 }
5354
54- fn get_public_key ( private_key : & [ u8 ; 32 ] ) -> [ u8 ; 32 ] {
55+ pub fn get_public_key ( private_key : & [ u8 ; 32 ] ) -> [ u8 ; 32 ] {
5556 let dalek = ed25519_dalek:: SecretKey :: from_bytes ( private_key) . unwrap ( ) ;
5657 let public_key = ed25519_dalek:: PublicKey :: from ( & dalek) ;
5758 public_key. to_bytes ( )
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ pub fn backup_wallet(s: &mut Cursive) {
6565 ) ;
6666 } ) ;
6767 } else {
68- let private_key = hex:: encode ( wallet. accounts [ wallet . acc_idx ] . private_key ) ;
68+ let private_key = hex:: encode ( wallet. seed ) ;
6969 content. add_button ( "Private key" , move |s| {
7070 let private_key = private_key. clone ( ) ;
7171 s. add_layer (
Original file line number Diff line number Diff line change 1- pub const VERSION : & str = "v1.2.0 " ;
1+ pub const VERSION : & str = "v1.2.1 " ;
22pub const SHOW_TO_DP : usize = 12 ;
33pub const AUTHOR : & str = "derfarctor (Author)" ;
44pub const AUTHOR_ADDR : & str = "_3kpznqbuzs3grswcqkzitd5fwky4s5cmyt76wru7kbenfwza7q9c1f1egzhm" ;
You can’t perform that action at this time.
0 commit comments