Created
November 14, 2011 22:40
-
-
Save em/1365453 to your computer and use it in GitHub Desktop.
Workaround to sign Recurly.js billing info updates
This file contains hidden or 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
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