joeblack.git

ref: master

./index.html


  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
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<link rel="stylesheet" href="style.css" />
		<title>Joe Black</title>
		<script src="wasm_exec.js"></script>
		<script>
			const go = new Go();
			WebAssembly.instantiateStreaming(fetch('joeblack.wasm'), go.importObject).then((result) => {
					go.run(result.instance);
			});
		</script>
		<script defer>
			function process() {
				const share1 = document.getElementById('share1');
				const share2 = document.getElementById('share2');
				const share3 = document.getElementById('share3');

				let key = '';
				let isPaperKey = false;
				let keyPromise = undefined;
				if (share2.value == '' && share3.value == '') {
					keyPromise = new Promise(function(resolve, reject) {
						key = decodePaperKey(share1.value);
						isPaperKey = true;
						resolve(1);
					});
				} else {
					keyPromise = fetch('burnt').then(burntResponse => {
						if (!burntResponse.ok) {
							return "ERR: Nie można pobrać spalonych udziałów";
						}
						return burntResponse.text();
					}).then(burnt => {
						if (burnt.startsWith('ERR: ')) {
							alert(burnt);
							throw '';
						}
						key = decodeSSS(share1.value, share2.value, share3.value, burnt)
						if (key.startsWith('ERR: ')) {
							alert(key);
							throw '';
						}
					});
				}

				keyPromise.then(result => {
					return fetch('payload')
				}).then(payloadResponse => {
					if (!payloadResponse.ok) {
						return "ERR: Nie można pobrać sejfu";
					}
					return payloadResponse.text();
				}).then(payload => {
					if (payload.startsWith('ERR: ')) {
						alert(payload);
						throw '';
					}
					let will_secrets_res = decryptPayload(key, payload, isPaperKey);
					if (will_secrets_res.startsWith('ERR: ')) {
						alert(will_secrets_res);
						throw '';
					}
					let will_secrets = will_secrets_res.split('|');
					let will = will_secrets[0];
					let secrets = will_secrets.slice(1).join('|');

					let secretsA = document.createElement('a');
					let secretsBlob = new Blob([secrets], {type: 'text/plain'});
					secretsA.setAttribute('href', URL.createObjectURL(secretsBlob));
					secretsA.setAttribute('download', 'secrets.txt');
					secretsA.style.display = 'none';
					document.body.appendChild(secretsA);
					secretsA.click();
					document.body.removeChild(secretsA);

					let willA = document.createElement('a');
					let byteArray = Uint8Array.from(
						atob(will).split('').map(char => char.charCodeAt(0))
					);
					let willBlob =  new Blob([byteArray], { type: 'application/pdf' });
					willA.setAttribute('href', URL.createObjectURL(willBlob));
					willA.setAttribute('download', 'will.pdf');
					willA.style.display = 'none';
					document.body.appendChild(willA);
					willA.click();
					document.body.removeChild(willA);
				});
			}
		</script>
	</head>
	<body>
		<main>
			<h1>Joe Black of mine</h1>
			<label for="share1">Udział #1 (24 wyrazy)</label>
			<textarea id="share1" style=" width: 100%"></textarea>
			<label for="share2">Udział #2 (24 wyrazy)</label>
			<textarea id="share2" style=" width: 100%"></textarea>
			<label for="share3">Udział #3 (24 wyrazy)</label>
			<textarea id="share3" style=" width: 100%"></textarea>
			<button id="button" style="font-size: 1.5rem" onClick="process();">Dalej »</button>
		</main>
	</body>
</html>