eslint + prettier
This commit is contained in:
parent
355e22bcd6
commit
5bed911bfc
11 changed files with 1567 additions and 15 deletions
11
.editorconfig
Normal file
11
.editorconfig
Normal file
|
@ -0,0 +1,11 @@
|
|||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
23
.eslintrc.json
Normal file
23
.eslintrc.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"commonjs": true,
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
},
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"no-const-assign": "warn",
|
||||
"no-this-before-super": "warn",
|
||||
"no-undef": "warn",
|
||||
"no-unreachable": "warn",
|
||||
"no-unused-vars": "warn",
|
||||
"constructor-super": "warn",
|
||||
"valid-typeof": "warn"
|
||||
}
|
||||
}
|
4
.prettierrc
Normal file
4
.prettierrc
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"printWidth": 120,
|
||||
"trailingComma": "es5"
|
||||
}
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
See the live demo at https://js-keygen.surge.sh
|
||||
|
||||
There is no way to generate a ssh keypair on the chrome book, but we have access to chrome and the webcrypto API. I had to do all sorts of gymnastics to convert the generated keypair to something that can be consummed by SSH.
|
||||
For some explanation see http://blog.roumanoff.com/2015/09/using-webcrypto-api-to-generate-keypair.html
|
||||
|
||||
There is no way to generate a ssh keypair on a chromebook, but we have access to chrome and the webcrypto API. I had to do all sorts of gymnastics to convert the generated keypair to something that can be consummed by SSH.
|
||||
|
||||
* I had to learn about the WebCrypto API - which was the initial goal
|
||||
* I had to learn about JWK
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/*jslint browser: true, sloppy: true */
|
||||
//adapted from https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-08#appendix-C
|
||||
|
||||
function base64urlEncode(arg) {
|
||||
|
@ -24,5 +23,7 @@ function base64urlDecode(s) {
|
|||
default:
|
||||
throw "Illegal base64url string!";
|
||||
}
|
||||
return window.atob(s); // Standard base64 decoder
|
||||
return window.atob(s); // Regular base64 decoder
|
||||
}
|
||||
|
||||
module.exports = { base64urlDecode, base64urlEncode };
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/*jslint browser: true, sloppy: true, vars: true, indent: 2*/
|
||||
var console, generateKeyPair;
|
||||
var generateKeyPair;
|
||||
|
||||
function copy(id) {
|
||||
return function() {
|
||||
|
@ -22,17 +21,17 @@ function buildHref(data) {
|
|||
return "data:application/octet-stream;charset=utf-8;base64," + window.btoa(data);
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
document.querySelector("#savePrivate").addEventListener("click", function(event) {
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
document.querySelector("#savePrivate").addEventListener("click", function() {
|
||||
document.querySelector("a#private").click();
|
||||
});
|
||||
document.querySelector("#copyPrivate").addEventListener("click", copy("#privateKey"));
|
||||
document.querySelector("#savePublic").addEventListener("click", function(event) {
|
||||
document.querySelector("#savePublic").addEventListener("click", function() {
|
||||
document.querySelector("a#public").click();
|
||||
});
|
||||
document.querySelector("#copyPublic").addEventListener("click", copy("#publicKey"));
|
||||
|
||||
document.querySelector("#generate").addEventListener("click", function(event) {
|
||||
document.querySelector("#generate").addEventListener("click", function() {
|
||||
var name = document.querySelector("#name").value || "name";
|
||||
document.querySelector("a#private").setAttribute("download", name + "_rsa");
|
||||
document.querySelector("a#public").setAttribute("download", name + "_rsa.pub");
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/*jslint browser: true, devel: true, sloppy: true, vars: true*/
|
||||
/*globals Uint8Array, Promise */
|
||||
var extractable = true;
|
||||
var encodePrivateKey, encodePublicKey;
|
||||
|
||||
|
@ -54,3 +52,5 @@ function generateKeyPair(alg, size, name) {
|
|||
return Promise.all([privateKey, publicKey]);
|
||||
});
|
||||
}
|
||||
|
||||
module.exportKey = { arrayBufferToBase64, generateKeyPair };
|
||||
|
|
1507
package-lock.json
generated
Normal file
1507
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -4,7 +4,12 @@
|
|||
"description": "Generate a key pair using the webcrypto API",
|
||||
"main": "js-keygen.js",
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"devDependencies": {
|
||||
"eslint": "4.17.0",
|
||||
"eslint-config-airbnb-base": "^12.1.0",
|
||||
"eslint-config-prettier": "^2.9.0",
|
||||
"eslint-plugin-import": "^2.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"To run test open test/index.html in your browser\""
|
||||
},
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/*jslint browser: true, devel: true, bitwise: true, sloppy: true, vars: true*/
|
||||
|
||||
var base64urlDecode;
|
||||
|
||||
function arrayToString(a) {
|
||||
|
@ -127,3 +125,5 @@ function encodePrivateKey(jwk) {
|
|||
var a = [0x30].concat(len, seq); // seq is 0x30
|
||||
return arrayToPem(a);
|
||||
}
|
||||
|
||||
module.exports = { base64urlToArray, decodePublicKey, encodePublicKey, encodePrivateKey };
|
||||
|
|
Loading…
Reference in a new issue