Phyks (Lucas Verney)
d8a7d4f66a
Full rework of webplayer. Webplayer is back to its previous working state, and ready for further improvements.
33 lines
775 B
JavaScript
33 lines
775 B
JavaScript
/**
|
|
* Collection of helper function that are Ampache specific.
|
|
*/
|
|
|
|
// NPM imports
|
|
import jsSHA from "jssha";
|
|
|
|
|
|
/**
|
|
* Build an HMAC token for authentication against Ampache API.
|
|
*
|
|
* @param password User password to derive HMAC from.
|
|
* @return An object with the generated HMAC and time used.
|
|
*
|
|
* @remark This builds an HMAC as expected by Ampache API, which is not a
|
|
* standard HMAC.
|
|
*/
|
|
export function buildHMAC(password) {
|
|
const time = Math.floor(Date.now() / 1000);
|
|
|
|
let shaObj = new jsSHA("SHA-256", "TEXT");
|
|
shaObj.update(password);
|
|
const key = shaObj.getHash("HEX");
|
|
|
|
shaObj = new jsSHA("SHA-256", "TEXT");
|
|
shaObj.update(time + key);
|
|
|
|
return {
|
|
time: time,
|
|
passphrase: shaObj.getHash("HEX"),
|
|
};
|
|
}
|