all files / src/ js-keygen-ui.ts

100% Statements 0/0
100% Branches 0/0
100% Functions 2/2
100% Lines 0/0
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                                                                                                               
// import {generateKeyPair} from './js-keygen';
 
// // TODO: any
// function copy(id: any) {
//   return function() {
//     var ta = document.querySelector(id);
//     ta.focus();
//     ta.select();
//     try {
//       var successful = document.execCommand("copy");
//       var msg = successful ? "successful" : "unsuccessful";
//       console.log("Copy key command was " + msg);
//     } catch (err) {
//       console.log("Oops, unable to copy");
//     }
//     window.getSelection()!.removeAllRanges();
//     ta.blur();
//   };
// }
 
// function buildHref(data: string) {
//   return "data:application/octet-stream;charset=utf-8;base64," + window.btoa(data);
// }
 
// // TODO: may any
// document.addEventListener("DOMContentLoaded", function() {
//   document.querySelector("#savePrivate")!.addEventListener("click", function() {
//     (document.querySelector("a#private") as any).click();
//   });
//   document.querySelector("#copyPrivate")!.addEventListener("click", copy("#privateKey"));
//   document.querySelector("#savePublic")!.addEventListener("click", function() {
//     (document.querySelector("a#public") as any).click();
//   });
//   document.querySelector("#copyPublic")!.addEventListener("click", copy("#publicKey"));
 
//   document.querySelector("#generate")!.addEventListener("click", function() {
//     var name = (document.querySelector("#name") as any).value || "name";
//     document.querySelector("a#private")!.setAttribute("download", name + "_rsa");
//     document.querySelector("a#public")!.setAttribute("download", name + "_rsa.pub");
 
//     var alg = (document.querySelector("#alg") as any).value || "RSASSA-PKCS1-v1_5";
//     var size = parseInt((document.querySelector("#size") as any).value || "2048", 10);
//     generateKeyPair(alg, size, name)
//       .then(function(keys: any) {
//         document.querySelector("#private")!.setAttribute("href", buildHref(keys[0]));
//         document.querySelector("#public")!.setAttribute("href", buildHref(keys[1]));
//         document.querySelector("#privateKey")!.textContent = keys[0];
//         document.querySelector("#publicKey")!.textContent = keys[1];
//         (document.querySelector("#result") as any).style.display = "block";
//       })
//       .catch(function(err: any) {
//         console.error(err);
//       });
//   });
// });