-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.js
61 lines (51 loc) · 2.18 KB
/
wallet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var show_generate = function() {
document.getElementById("generate").style.display = "block";
document.getElementById("restore").style.display = "none";
document.getElementById("step2").style.display = "none";
};
var show_restore = function() {
document.getElementById("restore").style.display = "block";
document.getElementById("generate").style.display = "none";
document.getElementById("step2").style.display = "none";
};
var getStringWords = function(string) {
return string.replace(/^\s*(.*)\s*$/, '$1').replace(/\s+/, ' ').split(' ');
};
var genkeys = function(additional_entropy, lang) {
var seed = cnUtil.sc_reduce32(poor_mans_kdf(additional_entropy + cnUtil.rand_32()));
var keys = cnUtil.create_address(seed);
var passPhrase = mn_encode(seed, lang);
return {
keys: keys,
mnemonic: passPhrase
}
};
var restore_keys = function(lang) {
var seed_phrase = document.getElementById("seed_phrase").value;
var seed = mn_decode(seed_phrase);
var keys = cnUtil.create_address(seed);
address_widget.innerHTML = keys.public_addr;
mnemonic_widget.innerHTML = seed_phrase;
spend_key_widget.innerHTML = keys.spend.sec;
view_key_widget.innerHTML = keys.view.sec;
document.getElementById("step2").style.display = "block";
};
var genwallet = function(lang) {
document.getElementById("step2").style.display = "block";
var spend_key_widget = document.getElementById("spend_key_widget");
var view_key_widget = document.getElementById("view_key_widget");
var address_widget = document.getElementById("address_widget");
var address_qr_widget = document.getElementById("address_qr_widget");
var user_entropy_widget = document.getElementById("user_entropy_widget");
var res = genkeys(user_entropy_widget.value, lang);
var keys = res.keys;
var mnemonic = res.mnemonic;
address_widget.innerHTML = keys.public_addr;
mnemonic_widget.innerHTML = mnemonic;
spend_key_widget.innerHTML = keys.spend.sec;
view_key_widget.innerHTML = keys.view.sec;
// wallet_keys_widget.innerHTML = keys.privateKeys;
//address_qr_widget.innerHTML = "";
//qr=new QRCode(address_qr_widget, {correctLevel:QRCode.CorrectLevel.L});
//qr.makeCode("turtlecoin:"+keys.public_addr);
};