Skip to content

Instantly share code, notes, and snippets.

@adilsoncarvalho
Last active April 9, 2021 12:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adilsoncarvalho/06bb11feddaf61cc4b98a5192008578c to your computer and use it in GitHub Desktop.
Save adilsoncarvalho/06bb11feddaf61cc4b98a5192008578c to your computer and use it in GitHub Desktop.
MercadoBitcoin - Calculando o TAPI-MAC em NodeJS
const TAPI_SECRET = '1ebda7d457ece1330dff1c9e04cd62c4e02d1835968ff89d2fb2339f06f73028';
const EXPECTED_TAPI_MAC = '7f59ea8749ba596d5c23fa242a531746b918e5e61c9f6c8663a699736db503980f3a507ff7e2ef1336f7888d684a06c9a460d18290e7b738a61d03e25ffdeb76';
const MESSAGE = '/tapi/v3/?tapi_method=list_orders&tapi_nonce=1';
const crypto = require('crypto');
const hmac = crypto.createHmac('sha512', TAPI_SECRET);
hmac.update(MESSAGE);
const TAPI_MAC = hmac.digest('hex');
if (TAPI_MAC == EXPECTED_TAPI_MAC)
console.info("Success!");
else
console.error("The're different ;(");
import urllib
import hashlib
import hmac
MB_TAPI_SECRET = '1ebda7d457ece1330dff1c9e04cd62c4e02d1835968ff89d2fb2339f06f73028'
REQUEST_PATH = '/tapi/v3/'
params = {
'tapi_method': 'list_orders',
'tapi_nonce': 1
}
params = urllib.urlencode(params)
params_string = REQUEST_PATH + '?' + params
H = hmac.new(MB_TAPI_SECRET, digestmod=hashlib.sha512)
H.update(params_string)
tapi_mac = H.hexdigest()
print tapi_mac
# won't produce the same value as above because urlencode sorts the params hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment