Created
June 9, 2015 19:33
-
-
Save dckc/b5e6adf3055e085e7db0 to your computer and use it in GitHub Desktop.
jsSHA default export and flow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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