blockchain/views/new-wallet.ejs
2022-01-26 19:20:35 +00:00

119 lines
5.8 KiB
Plaintext

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><%= title %></title>
<!--<link rel='stylesheet' href='/stylesheets/style.css' />-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<meta name="theme-color" content="#7952b3">
<link href="/stylesheets/dashboard.css" rel="stylesheet">
<script>
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
</script>
</head>
<body onload="generateWallet()">
<%- include('header.ejs') %>
<div class="container-fluid">
<div class="row">
<%- include('sidebar.ejs') %>
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<%- include('breadcrumb.ejs', {breadcrumb: breadcrumb}) %>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h2><%= title %></h2>
</div>
<form class="row g-3">
<div class="mb-3">
<label for="wallet-id" class="form-label">Wallet ID</label>
<input type="email" readonly class="form-control-plaintext" id="wallet-id" placeholder="id@uplink.si">
</div>
<div class="mb-3">
<label for="private-key-id" class="form-label">Private Key</label>
<textarea class="form-control-plaintext" readonly id="private-key-id" rows="5"></textarea>
</div>
<div>
<label for="public-key-id" class="form-label">Public Key</label>
<textarea class="form-control-plaintext" readonly id="public-key-id" rows="5"></textarea>
</div>
<div>
<button onclick="getFingerprintM()" type="button" class="btn btn-primary">Fingerprint</button>
</div>
<div>
<label for="fingerprint-id" class="form-label">Fingerprint</label>
<input class="form-control-plaintext" readonly id="fingerprint-id"></input>
</div>
<div>
<button onclick="saveKey()" type="button" class="btn btn-primary">Save Key</button>
</div>
</form>
</main>
</div>
</div>
<script>
function generateWallet() {
document.getElementById('wallet-id').value = uuidv4() + '@uplink.si';
generateKeys();
}
publicKey;
function generateKeys() {
(async () => {
const { privateKeyArmored, publicKeyArmored, revoationCertificate } = await openpgp.generateKey({
type: 'ecc', // Type of the key, defaults to ECC
curve: 'curve25519', // ECC curve name, defaults to curve25519
userIDs: [{ name: '', email: document.getElementById('wallet-id').value }], // you can pass multiple user IDs
passphrase: 'super long and hard to guess secret' // protects the private key
});
document.getElementById('private-key-id').value = privateKeyArmored;
document.getElementById('public-key-id').value = publicKeyArmored;
//console.log(privateKeyArmored); // '-----BEGIN PGP PRIVATE KEY BLOCK ... '
//console.log(publicKeyArmored); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
//console.log(revocationCertificate); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
publicKey = await openpgp.readKey({armoredKey: publicKeyArmored});
})();
}
async function getFingerprintM() {
document.getElementById('fingerprint-id').value = publicKey.getFingerprint();
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function saveKey() {
key = {};
key.privateKey = document.getElementById('private-key-id').value;
key.publicKey = document.getElementById('public-key-id').value;
key.fingerprint = document.getElementById('fingerprint-id').value;
key.user = document.getElementById('wallet-id').value;
download('key.txt',JSON.stringify(key));
if(typeof(Storage) !== "undefined") {
localStorage.setItem('privateKey', key.privateKey);
localStorage.setItem('publicKey', key.publicKey);
localStorage.setItem('fingerprint', key.fingerprint);
}
}
</script>
<script src="/javascripts/openpgp.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script><script src="/javascripts/dashboard.js"></script>
</body>
</html>