Skip to content

Instantly share code, notes, and snippets.

@dckc
Created June 9, 2015 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dckc/b5e6adf3055e085e7db0 to your computer and use it in GitHub Desktop.
Save dckc/b5e6adf3055e085e7db0 to your computer and use it in GitHub Desktop.
jsSHA default export and flow
/* @flow */
import jsSHA from 'jssha';
export function mkHideLines(getSecret: () => string) : (pt: string) => string {
return plainText => {
var secret = getSecret();
return plainText
.split("\n")
.map(line => hmac(line, secret))
.join("\n");
};
}
function hmac(plainText, secret) {
var sha = new jsSHA(plainText, "TEXT");
return sha.getHMAC(secret, "TEXT", "SHA-256", "HEX");
}
declare module jssha {
declare class jsSHA {
getHMAC: (secret: string, ty: string,
alg: string, out: string) => string;
}
declare var exports = typeof jsSHA;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment