core&utils: remove outdated code
parent
5ae8258b8a
commit
7903d012da
@ -1,13 +0,0 @@
|
||||
import crypto from 'crypto';
|
||||
|
||||
const encrypt = (algorithm, content) => {
|
||||
const hash = crypto.createHash(algorithm);
|
||||
hash.update(content);
|
||||
return hash.digest('hex');
|
||||
};
|
||||
|
||||
export const sha1 = (content: string) => encrypt('sha1', content);
|
||||
export const md5 = (content: string) => encrypt('md5', content);
|
||||
|
||||
global.Hydro.lib.md5 = md5;
|
||||
global.Hydro.lib.sha1 = sha1;
|
@ -1,22 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import superagent, { SuperAgentRequest } from 'superagent';
|
||||
|
||||
async function _download(url: string, path: string, retry: number) {
|
||||
const w = fs.createWriteStream(path);
|
||||
superagent.get(url).retry(retry).pipe(w);
|
||||
await new Promise((resolve, reject) => {
|
||||
w.on('finish', resolve);
|
||||
w.on('error', reject);
|
||||
});
|
||||
return path;
|
||||
}
|
||||
|
||||
function download(url: string): SuperAgentRequest;
|
||||
function download(url: string, path?: string, retry = 3) {
|
||||
if (path) return _download(url, path, retry);
|
||||
return superagent.get(url).retry(retry);
|
||||
}
|
||||
|
||||
export = download;
|
||||
|
||||
global.Hydro.lib.download = download;
|
@ -1,35 +0,0 @@
|
||||
function decodeBase64WithUriEncoding(encodedText: string) {
|
||||
return Buffer.from(encodedText, 'base64').toString('utf8');
|
||||
}
|
||||
|
||||
function unescapedString(escapedString: string) {
|
||||
escapedString += new Array(5 - (escapedString.length % 4)).join('=');
|
||||
return escapedString.replace(/-/g, '+').replace(/_/g, '/');
|
||||
}
|
||||
|
||||
function decodeJWT(idToken: string) {
|
||||
const token = idToken.split('.');
|
||||
if (token.length !== 3) {
|
||||
throw new Error('Invalid idToken');
|
||||
}
|
||||
try {
|
||||
const headerSegment = JSON.parse(decodeBase64WithUriEncoding(token[0]));
|
||||
const payloadSegment = JSON.parse(decodeBase64WithUriEncoding(token[1]));
|
||||
const signature = unescapedString(token[2]);
|
||||
return {
|
||||
dataToSign: [token[0], token[1]].join('.'),
|
||||
header: headerSegment,
|
||||
payload: payloadSegment,
|
||||
signature,
|
||||
};
|
||||
} catch (e) {
|
||||
throw new Error('Invalid payload');
|
||||
}
|
||||
}
|
||||
|
||||
export function decode(idToken: string) {
|
||||
const decodedJWT = decodeJWT(idToken);
|
||||
return decodedJWT.payload;
|
||||
}
|
||||
|
||||
global.Hydro.lib.jwt = { decode };
|
Loading…
Reference in New Issue