UNPKG

linkpay-api

Version:

LinkPay JS/TS API SDK

33 lines (32 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Signature = void 0; var crypto_1 = require("crypto"); var utils_1 = require("../common/utils"); var Signature = /** @class */ (function () { function Signature(httpMethod, urlString, key, httpBody) { this.httpMethod = httpMethod; this.urlString = urlString; this.dateTime = (0, utils_1.genYYYYMMDDThhmmsshh00)(); this.key = key; this.msgID = (0, utils_1.genUUIDWithoutDash)(); this.httpBody = httpBody ? JSON.stringify(httpBody) : ''; } Signature.prototype.toString = function () { return "".concat(this.httpMethod, "\n").concat(this.urlString, "\n").concat(this.dateTime, "\n").concat(this.key, "\n").concat(this.msgID).concat(this.httpBody ? "\n".concat(this.httpBody) : ''); }; Signature.prototype.sha256 = function () { var str = this.toString(); console.log(str); var hash = (0, crypto_1.createHash)('sha256').update(str).digest('hex'); return hash; }; Signature.prototype.sha512 = function () { var str = this.toString(); var hash = (0, crypto_1.createHash)('sha512').update(str).digest('hex'); return hash; }; return Signature; }()); exports.Signature = Signature; exports.default = Signature;