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

149 lines
6.2 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>
<%- 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="col-md-6">
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon">From</span>
<input type="text" class="form-control" id="from-id">
</div>
</div>
<div class="col-md-6">
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon">To</span>
<input type="text" class="form-control" id="to-id">
</div>
</div>
<div class="col-md-12">
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon">Amount</span>
<input type="" class="form-control" id="amount-id">
</div>
</div>
<div>
<button type="button" class="btn btn-primary btn-lg">Send</button>
</div>
</form>
<div class="mb-3">
<label for="message-id" class="form-label">Plaintext Message</label>
<textarea class="form-control" id="message-id" rows="5"></textarea>
</div>
<div class="mb-3">
<label for="private-key-id" class="form-label">Private Key</label>
<textarea class="form-control" id="private-key-id" rows="5"></textarea>
</div>
<div class="mb-3">
<button type="button" class="btn btn-primary col-auto" onclick="signMessageA()">Sign Message</button>
<button type="button" class="btn btn-primary col-auto">Primary</button>
</div>
<div class="mb-3">
<label for="signed-message-id" class="form-label">Signed Message</label>
<textarea class="form-control" id="signed-message-id" rows="5"></textarea>
</div>
<div class="mb-3">
<label for="public-key-id" class="form-label">Public Key</label>
<textarea class="form-control" id="public-key-id" rows="5"></textarea>
</div>
<div class="mb-3">
<button type="button" class="btn btn-primary col-auto" onclick="verifySig()">Verify Message</button>
</div>
</main>
</div>
</div>
<script>
const passphrase = 'super long and hard to guess secret';
var privateKey;
var privateKeyxx;
var unsignedMessageM;
async function signMessage0() {
privateKeyxx = await openpgp.readKey({ armoredKey: document.getElementById('private-key-id').value });
console.log('readKey done');
}
async function signMessage1() {
privateKey = await openpgp.decryptKey({
privateKey: privateKeyxx,
passphrase
});
console.log('decryptKey done');
}
async function signMessage2() {
unsignedMessageM = await openpgp.createCleartextMessage({ text: document.getElementById('message-id').value });
console.log('createCleartextMessage done');
}
async function signMessage3() {
document.getElementById('signed-message-id').value = await openpgp.sign({
message: unsignedMessageM, // CleartextMessage or Message object
privateKeys: privateKey, // for signing
detached: false
});
}
async function signMessageA() {
await signMessage0();
await signMessage1();
await signMessage2();
await signMessage3();
}
var signedMessage2;
var publicKey;
var verified;
async function verify0() {
signedMessage2 = await openpgp.readCleartextMessage({cleartextMessage: document.getElementById('signed-message-id').value});
}
async function verify1() {
publicKey = await openpgp.readKey({armoredKey: document.getElementById('public-key-id').value});
}
async function verify2() {
verified = await openpgp.verify({message: signedMessage2, publicKeys: publicKey});
}
async function verifySig() {
await verify0();
await verify1();
await verify2();
}
</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>