Implement wallet generation
MODIFY
HiddenWallet/HiddenWallet.GUI/HiddenWallet.GUI.njsproj
HiddenWallet/HiddenWallet.GUI/HiddenWallet.GUI.njsproj
<Compile Include="app\app.js">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="app\js\decryption-phase.js" />
<Compile Include="main.js" />
<Content Include="app\css\justified-nav.css" />
<Content Include="app\html\decryption-phase-content.html" />

MODIFY
HiddenWallet/HiddenWallet.GUI/app/html/decryption-phase-content.html
HiddenWallet/HiddenWallet.GUI/app/html/decryption-phase-content.html
<div class="jumbotron" id="decrypt-active">
- <form class="form-signin">
<input type="password" id="inputPassword" class="form-control" placeholder="Password" />
<br />
- <button class="btn btn-lg btn-primary btn-block" type="submit">Decrypt</button>
- </form>
+ <button class="btn btn-lg btn-primary btn-block">Decrypt</button>
</div>
+
<div class="jumbotron" id="generate-active">
- <form class="form-signin">
<input type="password" id="inputPassword" class="form-control" placeholder="Password" />
<input type="password" id="confirmPassword" class="form-control" placeholder="Confirm password" />
<br />
- <button class="btn btn-lg btn-primary btn-block" type="submit">Generate</button>
- </form>
+ <button class="btn btn-lg btn-primary btn-block" onclick="generateWallet()">Generate</button>
</div>
+
<div class="jumbotron" id="recover-active">
- <form class="form-signin">
<label>Syncronize transactions from:</label>
<input type="date" id="inputSyncFrom" class="form-control" required />
<label>Password:</label>
<div class="alert alert-info" role="alert">
<strong>Heads up!</strong> At recovery the wallet is unable to check if your password is correct or not. If you provide a wrong password a wallet will be recovered with the provided mnemonic and password combination.
</div>
- <button class="btn btn-lg btn-primary btn-block" type="submit">Recover</button>
- </form>
+ <button class="btn btn-lg btn-primary btn-block">Recover</button>
</div>
\ No newline at end of file

ADD
HiddenWallet/HiddenWallet.GUI/app/js/decryption-phase.js
+var walletExists;
+function decryptionPhaseShow(menuItem = "") {
+ if (menuItem === "") {
+ walletExists = httpGetWallet("wallet-exists").Value;
+ if (walletExists === true) {
+ decryptionPhaseShow("decrypt");
+ }
+ else {
+ decryptionPhaseShow("generate");
+ }
+ }
+ else if (menuItem === "decrypt") {
+ document.getElementById("menu").innerHTML = document.getElementById("decryption-phase-menu-frame").contentWindow.document.getElementById("decrypt-active").innerHTML;
+ if (walletExists === true) {
+ document.getElementById("content").innerHTML = document.getElementById("decryption-phase-content-frame").contentWindow.document.getElementById("decrypt-active").innerHTML;
+ }
+ else {
+ document.getElementById("content").innerHTML = '<div class="alert alert-warning" role="alert"><strong>No wallet found!</strong> Generate or recover your wallet before decrypting it!</div>';
+ }
+ }
+ else if (menuItem === "generate") {
+ document.getElementById("menu").innerHTML = document.getElementById("decryption-phase-menu-frame").contentWindow.document.getElementById("generate-active").innerHTML;
+ if (walletExists === false) {
+ document.getElementById("content").innerHTML = document.getElementById("decryption-phase-content-frame").contentWindow.document.getElementById("generate-active").innerHTML;
+ }
+ else {
+ document.getElementById("content").innerHTML = '<div class="alert alert-warning" role="alert"><strong>Wallet already exists!</strong> If you wish to continue with this operation you first need to delete or rename your wallet file!</div>';
+ }
+ }
+ else if (menuItem === "recover") {
+ document.getElementById("menu").innerHTML = document.getElementById("decryption-phase-menu-frame").contentWindow.document.getElementById("recover-active").innerHTML;
+ if (walletExists === false) {
+ document.getElementById("content").innerHTML = document.getElementById("decryption-phase-content-frame").contentWindow.document.getElementById("recover-active").innerHTML;
+ }
+ else {
+ document.getElementById("content").innerHTML = '<div class="alert alert-warning" role="alert"><strong>Wallet already exists!</strong> If you wish to continue with this operation you first need to delete or rename your wallet file!</div>';
+ }
+ }
+}
+
+function httpGetWallet(path) {
+ var theUrl = "http://localhost:5000/api/v1/wallet/" + path;
+ var xmlHttp = new XMLHttpRequest();
+ xmlHttp.open("GET", theUrl, false); // false for synchronous request
+ xmlHttp.send(null);
+ return JSON.parse(xmlHttp.responseText);
+}
+
+function httpPostWallet(path, data) {
+ var theUrl = "http://localhost:5000/api/v1/wallet/" + path;
+ var xmlHttp = new XMLHttpRequest();
+ xmlHttp.open("POST", theUrl, false); // false for synchronous request
+ xmlHttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
+ xmlHttp.send(JSON.stringify(data));
+ return JSON.parse(xmlHttp.responseText);
+}
+
+function generateWallet() {
+ var password = document.getElementById("inputPassword").value;
+ if (password !== document.getElementById("confirmPassword").value) {
+ alert("Password confirmation does not match the password", "Could not generate wallet");
+ }
+ else {
+ var obj = new Object();
+ obj.password = password;
+ var result = httpPostWallet("create", obj);
+
+ if (result.Success == false) {
+ alert(result.Message, "Could not generate wallet");
+ }
+ else {
+ var message = "Write down these mnemonic words:\n\n"
+ + result.Mnemonic + "\n\n"
+ + "You can recover your wallet on any computer with:\n"
+ + "- the mnemonic words AND\n"
+ + "- your password AND\n"
+ + "- the wallet creation time: " + result.CreationTime.substr(0, 10)
+ + "\n\n"
+ + "Unlike most other wallets if an attacker acquires your mnemonic words, it will not be able to hack your wallet without knowing your password. On the contrary, unlike other wallets, you will not be able to recover your wallet only with the mnemonic words if you lose your password.";
+ alert(message, "Wallet is successfully generated");
+ }
+ decryptionPhaseShow();
+ }
+}
\ No newline at end of file

MODIFY
HiddenWallet/HiddenWallet.GUI/index.html
HiddenWallet/HiddenWallet.GUI/index.html
<script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
<script type="text/javascript" src="app/app.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
- <script type="text/javascript">
- var walletExists;
- function decryptionPhaseShow(menuItem = "") {
- if (menuItem === "") {
- var result = httpGetWallet("wallet-exists");
- walletExists = JSON.parse(result).Value;
- if (walletExists === true) {
- decryptionPhaseShow("decrypt");
- }
- else {
- decryptionPhaseShow("generate");
- }
- }
- else if (menuItem === "decrypt") {
- document.getElementById("menu").innerHTML = document.getElementById("decryption-phase-menu-frame").contentWindow.document.getElementById("decrypt-active").innerHTML;
- if (walletExists === true) {
- document.getElementById("content").innerHTML = document.getElementById("decryption-phase-content-frame").contentWindow.document.getElementById("decrypt-active").innerHTML;
- }
- else {
- document.getElementById("content").innerHTML = '<div class="alert alert-warning" role="alert"><strong>No wallet found!</strong> Generate or recover your wallet before decrypting it!</div>';
- }
- }
- else if (menuItem === "generate") {
- document.getElementById("menu").innerHTML = document.getElementById("decryption-phase-menu-frame").contentWindow.document.getElementById("generate-active").innerHTML;
- if (walletExists === false) {
- document.getElementById("content").innerHTML = document.getElementById("decryption-phase-content-frame").contentWindow.document.getElementById("generate-active").innerHTML;
- }
- else {
- document.getElementById("content").innerHTML = '<div class="alert alert-warning" role="alert"><strong>Wallet already exists!</strong> If you wish to continue with this operation you first need to delete or rename your wallet file!</div>';
- }
- }
- else if (menuItem === "recover") {
- document.getElementById("menu").innerHTML = document.getElementById("decryption-phase-menu-frame").contentWindow.document.getElementById("recover-active").innerHTML;
- if (walletExists === false) {
- document.getElementById("content").innerHTML = document.getElementById("decryption-phase-content-frame").contentWindow.document.getElementById("recover-active").innerHTML;
- }
- else {
- document.getElementById("content").innerHTML = '<div class="alert alert-warning" role="alert"><strong>Wallet already exists!</strong> If you wish to continue with this operation you first need to delete or rename your wallet file!</div>';
- }
- }
- }
-
- function httpGetWallet(path) {
- var theUrl = "http://localhost:5000/api/v1/wallet/" + path;
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.open("GET", theUrl, false); // false for synchronous request
- xmlHttp.send(null);
- return xmlHttp.responseText;
- }
- </script>
+ <script type="text/javascript" src="app/js/decryption-phase.js"></script>
</body>
</html>
\ No newline at end of file

Implement wallet generation