UNPKG

1.47 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var definition_1 = require("@brontosaurus/definition");
4var crypto_1 = require("./crypto");
5var util_1 = require("./util");
6var BrontosaurusSign = (function () {
7 function BrontosaurusSign(key, body, secret) {
8 this._key = key;
9 this._body = body;
10 this._secret = secret;
11 }
12 BrontosaurusSign.create = function (key, body, secret) {
13 return new BrontosaurusSign(key, body, secret);
14 };
15 Object.defineProperty(BrontosaurusSign.prototype, "body", {
16 get: function () {
17 return this._body;
18 },
19 enumerable: true,
20 configurable: true
21 });
22 BrontosaurusSign.prototype.token = function (expireAt, issuedAt) {
23 var _this = this;
24 if (expireAt === void 0) { expireAt = Date.now(); }
25 if (issuedAt === void 0) { issuedAt = Date.now(); }
26 var header = util_1.definition.header({
27 expireAt: expireAt,
28 issuedAt: issuedAt,
29 key: this._key,
30 alg: 'RS256',
31 });
32 var body = util_1.definition.body(this.body);
33 var encrypted = definition_1.BrontosaurusDefinition.signWith(header, body, function (content) { return crypto_1.signString(content, _this._secret.private); });
34 return encrypted;
35 };
36 return BrontosaurusSign;
37}());
38exports.BrontosaurusSign = BrontosaurusSign;