Last active
October 2, 2023 19:38
-
-
Save j5bot/8d2099f995f8df22f605864d728ee049 to your computer and use it in GitHub Desktop.
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
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