Skip to content

Instantly share code, notes, and snippets.

@em
Created November 14, 2011 22:40
Show Gist options
  • Save em/1365453 to your computer and use it in GitHub Desktop.
Save em/1365453 to your computer and use it in GitHub Desktop.
Workaround to sign Recurly.js billing info updates
var crypto = require('crypto');
var privateKey = 'yourprivatekey';
function signBillingInfo(accountCode) {
// copypasta from transparent post
function hash(data) {
//get the sha1 of the private key in binary
var shakey = crypto.createHash('sha1');
shakey.update(privateKey);
shakey = shakey.digest('binary');
//now make an hmac and return it as hex
var hmac = crypto.createHmac('sha1', shakey);
hmac.update(data);
return hmac.digest('hex');
}
var timestamp = Math.round((new Date()).getTime() / 1000);
var message = '['+timestamp+',billinginfoupdate,[';
message += 'account_code:' + accountCode;
message += ']]';
return hash(message) + '-' + timestamp;
}
console.log( signBillingInfo('anaccountcode') );
/* backend:
*
* signature = signBillingInfo(accountCode);
*
* view:
*
* buildBillingInfoUpdateForm({
* ...
* accountCode: '#{accountCode}'
* signature: '#{signature}'
* });
* */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment