-
Notifications
You must be signed in to change notification settings - Fork 5
/
util.js
20 lines (17 loc) · 836 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* eslint-disable camelcase */
const crypto = require('crypto')
exports.signatureFor = ({ timestamp, method, path = String.prototype, body = String.prototype }, { npm_config_coinbase_pro_api_secret = String.prototype } = process.env, { createHmac } = crypto) => {
const buffer = Buffer.from(npm_config_coinbase_pro_api_secret, 'base64')
return createHmac('sha256', buffer)
.update(timestamp + method.toUpperCase() + path + body)
.digest('base64')
}
exports.configurationFor = ({ sandbox, hostname, key, passphrase, secret } = Object.prototype) => {
return {
npm_config_coinbase_pro_api_sandbox: String(sandbox),
npm_config_coinbase_pro_api_hostname: hostname,
npm_config_coinbase_pro_api_key: key,
npm_config_coinbase_pro_api_passphrase: passphrase,
npm_config_coinbase_pro_api_secret: secret
}
}