Skip to content

Instantly share code, notes, and snippets.

@j5bot
Last active October 2, 2023 19:38
Show Gist options
  • Save j5bot/8d2099f995f8df22f605864d728ee049 to your computer and use it in GitHub Desktop.
Save j5bot/8d2099f995f8df22f605864d728ee049 to your computer and use it in GitHub Desktop.
const NodeRSA = require('node-rsa');
export const generateWalmartHeaders = (consumerId, timestamp, publicKeyVersion, privateKey) => {
// the order here is important ... they are sorted according to the header names
const stringToSignComponents = [
consumerId,
timestamp,
publicKeyVersion
];
// join the components into one string, and add the trailing newline
const stringToSign = `${stringToSignComponents.join('\n')}\n`;
const signer = new NodeRSA(privateKey, 'pkcs1');
const signatureBuffer = signer.sign(stringToSign);
const signature = signatureBuffer.toString('base64');
return {
'WM_SEC.AUTH_SIGNATURE': signature,
'WM_CONSUMER.INTIMESTAMP': timestamp.toString(),
'WM_CONSUMER.ID': consumerId,
'WM_SEC.KEY_VERSION': publicKeyVersion.toString(),
};
};
module.exports = { generateWalmartHeaders };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment