-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.html
More file actions
158 lines (133 loc) · 6.86 KB
/
index.html
File metadata and controls
158 lines (133 loc) · 6.86 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<html>
<head>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha3.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/ripemd160.js"></script>
<script src="http://procbits.com/media/2013/08/bitcoinjs-min.js"></script>
<script src="./base32.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js"></script>
<script type="text/javascript">
function createaddress() {
/*
Create NEM address function
Bitcoinjs version 0.6 draft for alpha version addresses (with filter for signed bug)
2014-09-16 owon DS
*/
var randArr = new Uint8Array(32); //create a typed array of 32 bytes (256 bits)
// var retVal = window.crypto.getRandomValues(randArr); //populate array with cryptographically secure random numbers (future use not supported by all current browsers)
var privateKeyBytes = [];
for (var i = 0; i < randArr.length; ++i)
//privateKeyBytes[i] = randArr[i]
privateKeyBytes[i] = (Math.floor(Math.random() * 256)); // not cryptographically secure but should be ok for alpha client
// testdata - edit if you would like to test with a specific private key
// var privateKeyHex = "00d80d58eae724100b5573d9d5fdfb06ab17c94669eb83285363b4a2b8e3e9f247"
// var privateKeyBytes = Crypto.util.hexToBytes(privateKeyHex)
// hex string of our private key
var privateKeyHex = Crypto.util.bytesToHex(privateKeyBytes).toUpperCase();
//console.log("Private Key Hex:" + privateKeyHex);
// create compressed public key
var eckey = new Bitcoin.ECKey(privateKeyBytes);
eckey.compressed = true;
var publicKeyHexCompressed = Crypto.util.bytesToHex(eckey.getPub());
// console.log("Pub Key compressed Hex:" + publicKeyHexCompressed.toUpperCase());
var publicKeyBytes = eckey.getPub();
//console.log("Pub Key compressed Bytes:" + publicKeyBytes);
// SHA3
var words = CryptoJS.enc.Hex.parse(publicKeyHexCompressed);
var keccakhex = CryptoJS.SHA3(words, { outputLength: 256 }).toString();
//console.log("Public Key SHA3:" + keccakhex.toUpperCase());
// RIPEMD160
var hash160 = Crypto.RIPEMD160(Crypto.util.hexToBytes(keccakhex));
//console.log("Public Key Hash160(SHA3):" + hash160.toUpperCase());
// add version byte
var version ="98";
var hashandversion = version.concat(hash160);
//console.log("Version Hex:" + version);
//console.log("HashandVersion:" + hashandversion.toUpperCase());
// create checksum
var words1 = CryptoJS.enc.Hex.parse(hashandversion);
var fullChecksum = CryptoJS.SHA3(words1, { outputLength: 256 }).toString();
var addressChecksum = fullChecksum.substr(0,8);
//console.log("Checksum first 4Bytes of SHA3(HashandVersion):" + addressChecksum.toUpperCase());
// crate unencoded HEX & byte
var unencodedAddress = hashandversion.concat(addressChecksum);
//console.log("NEM Address unencoded Hex:" + unencodedAddress.toUpperCase());
var address = (Crypto.util.hexToBytes(unencodedAddress));
//console.log("NEM Address unencoded Bytes:" + address);
// base32 encode address
var b32 = base32.encode(address);
//console.log("NEM Address Base32 encoded:" + b32.toUpperCase());
return [b32.toUpperCase(), privateKeyHex]
}
function searchkey(){
var pattern = document.getElementById("pattern").value.toUpperCase();
if (pattern != ""){
var re = new RegExp("^[A-Z2-7]+$");
if (!pattern.match(re)) {
alert("Your pattern contains illegal characters not allowed in a NEM address, please use 'A' to 'Z' and '2' to '7'. Pattern will be ignored!");
pattern = "";
}
}
var address = createaddress();
//if (pattern=null) return [address[0], address[1]];
while (address[0].indexOf(pattern) < 0) {
var address = createaddress();
}
return [address[0], address[1], address[0].indexOf(pattern)];
}
function display(){
// output
document.getElementById("button1").value="Generating, please wait...";
document.getElementById('txt_privatekey').innerHTML = "Key will be shown here after creation..."
document.getElementById("txt_address").innerHTML = "The address will be shown here after creation..."
if (document.getElementById("pattern").value.length > 2 ) {
alert("Your pattern contains 3 or more chars, it may take some time to find an address...");
}
var keypair = searchkey();
document.getElementById('txt_privatekey').innerHTML = keypair[1];
var addr_out = keypair[0].replace(document.getElementById("pattern").value.toUpperCase(),"<font color='#FF0000'>" + document.getElementById("pattern").value.toUpperCase() + "</font>");
document.getElementById("txt_address").innerHTML = addr_out;
document.getElementById("button1").value="> Generate new NEM address <";
}
</script>
<style type="text/css">
body { background-color:#42ce7e; font-family:Arial; font-size:90%; }
</style>
</head>
<body>
<center>
<h1>Create your own NEM address</h1>
<br/>
<img src="./nem.gif" alt="NEM logo">
<br/>
<h3>A new economy starts with you!</h3>
<hr>
<b>Vanity address</b>
<br/>
You can search for a vanity address including a given pattern. The script will generate new addresses until an address is found that contains the pattern. Depending on the pattern length and your luck it may take a LONG time to find a corresponing address. This is why the pattern field is limited to 5 characters atm, leave it blank to just create a new NEM address without including a pattern.<br/>
Pattern (optional):<input type="text" name="pattern" id="pattern" maxlength="5" size="10" style="text-align: center;"/>
<hr><br/>
<table border="1">
<tr>
<th>Your NEM address:</th>
<th id="txt_address">The address will be shown here after creation...</th>
</tr>
<tr>
<th>Your private key:</th>
<th id="txt_privatekey">Key will be shown here after creation...</th>
</tr>
</table>
<br/><br/>
<input type="submit" name="button" id="button1" onclick="display()" value="> Generate NEM address <" style="height:50px; width:300px"/>
<br/><br/><br/><br/>
<h3>Please note:</h3>
This website creates NEM addresses and corresponding private keys (see www.ournem.com for more info) useable in the ALPHA version of the NEM community client. The addresses and the format will change in later versions.
<br/><br/>
The address creation software is written in Javascript and runs on your local computer. The private key is generated on your device, no central server will have a copy. Please make sure that the private key is ONLY visable and accessible by you. If a 3rd party gets access to your private key they will be able to spend your funds.
<br/><br/>
This program is distributed in the hope that it will be useful, but is provided AS IS with ABSOLUTELY NO WARRANTY. The entire risk as to the quality and performance of the program is with you. In no event will any of the developers, or any other party, be liable to anyone for damages arising out of the use or inability to use the program.
<br/><br/>
Version 0.6 created by -owon-; thanks to -gimre- for providing the address creation algorithm.<br/>
The code is available at: https://github.com/owon/nemaddress
</center>
</body
</html>