Convert backend code to ES modules

Bundling code now with Rollup for its flat bundling and tree shaking
support. Front end code still goes through Webpack for browser support.
This commit is contained in:
Zaid Abdulla committed 2019-02-04 23:47:54 -08:00
1 parent 824639976f
commit 1e41c72d60
62 files changed
+718 -898

No files matched your search

+7 -11
View File
@@ -18,9 +18,9 @@
*/
"use strict";
const crypto = require("crypto");
import { createHash } from "crypto";
function parseAuthHeader(authHeader) {
export function parseAuthHeader(authHeader) {
authHeader = authHeader.trim();
const method = authHeader.split(" ", 1)[0];
const res = { method: method };
@@ -53,11 +53,11 @@ function parseAuthHeader(authHeader) {
return res;
}
function basic(username, password) {
export function basic(username, password) {
return "Basic " + Buffer.from(`${username}:${password}`).toString("base64");
}
function digest(username, password, uri, httpMethod, body, authHeader) {
export function digest(username, password, uri, httpMethod, body, authHeader) {
const cnonce = "0a4f113b";
const nc = "00000001";
let qop;
@@ -68,7 +68,7 @@ function digest(username, password, uri, httpMethod, body, authHeader) {
else qop = authHeader.qop;
}
let ha1 = crypto.createHash("md5");
let ha1 = createHash("md5");
ha1
.update(username)
.update(":")
@@ -78,7 +78,7 @@ function digest(username, password, uri, httpMethod, body, authHeader) {
// TODO support "MD5-sess" algorithm directive
ha1 = ha1.digest("hex");
let ha2 = crypto.createHash("md5");
let ha2 = createHash("md5");
ha2
.update(httpMethod)
.update(":")
@@ -86,7 +86,7 @@ function digest(username, password, uri, httpMethod, body, authHeader) {
if (qop === "auth-int") ha2.update(":").update(body);
ha2 = ha2.digest("hex");
const hash = crypto.createHash("md5");
const hash = createHash("md5");
hash
.update(ha1)
.update(":")
@@ -113,7 +113,3 @@ function digest(username, password, uri, httpMethod, body, authHeader) {
return authString;
}
exports.parseAuthHeader = parseAuthHeader;
exports.basic = basic;
exports.digest = digest;