UNPKG

coingate-api

Version:

Coingate.com node.js wrapper

58 lines (57 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var moment = require("moment"); var request = require("request"); var crypto = require("crypto"); var Q = require("q"); var Client = /** @class */ (function () { function Client(opts) { this.opts = opts; } ; Client.prototype.getClient = function () { return new Coingate(this.opts.mode, this.opts.appId, this.opts.apiKey, this.opts.apiSecret); }; return Client; }()); exports.Client = Client; var Coingate = /** @class */ (function () { function Coingate(_mode, _appId, _apiKey, _apiSecret) { if (_mode === void 0) { _mode = 'staging'; } this.mode = _mode; this.appId = _appId; this.apiKey = _apiKey; this.apiSecret = _apiSecret; } Coingate.prototype.createOrder = function (params) { var deferred = Q.defer(); var nounce = moment().toDate().getMilliseconds(); var message = nounce + this.appId + this.apiKey; var signature = crypto.createHmac('sha256', this.apiSecret).update(message).digest('hex'); return request.post(this.getBaseUrl() + "/orders", params, function (error, response, body) { if (error) { deferred.reject(error); } if (response.body) { deferred.resolve(response.body); } else { deferred.resolve(); } return deferred.promise; }); }; Coingate.prototype.getBaseUrl = function () { if (this.mode === 'staging') { return 'https://api-sandbox.coingate.com/v1'; } else if (this.mode === 'production') { return 'https://api.coingate.com/v1'; } else { return ''; } }; return Coingate; }()); exports.Coingate = Coingate;