@eluvio/elv-client-js 3.1.96 → 3.1.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,5 @@
1
1
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
2
 
3
- var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
-
5
3
  /**
6
4
  * Methods for creating and managing NTP instances and tickets
7
5
  *
@@ -64,74 +62,68 @@ var FormatNTPInfo = function FormatNTPInfo(info) {
64
62
  */
65
63
 
66
64
 
67
- exports.CreateNTPInstance = /*#__PURE__*/function () {
68
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
69
- var _this = this;
70
-
71
- var tenantId, objectId, groupAddresses, _ref$ntpClass, ntpClass, _ref$maxTickets, maxTickets, _ref$maxRedemptions, maxRedemptions, startTime, endTime, _ref$ticketLength, ticketLength, paramsJSON, groupIds;
72
-
73
- return _regeneratorRuntime.wrap(function _callee$(_context) {
74
- while (1) {
75
- switch (_context.prev = _context.next) {
76
- case 0:
77
- tenantId = _ref.tenantId, objectId = _ref.objectId, groupAddresses = _ref.groupAddresses, _ref$ntpClass = _ref.ntpClass, ntpClass = _ref$ntpClass === void 0 ? 4 : _ref$ntpClass, _ref$maxTickets = _ref.maxTickets, maxTickets = _ref$maxTickets === void 0 ? 0 : _ref$maxTickets, _ref$maxRedemptions = _ref.maxRedemptions, maxRedemptions = _ref$maxRedemptions === void 0 ? 100 : _ref$maxRedemptions, startTime = _ref.startTime, endTime = _ref.endTime, _ref$ticketLength = _ref.ticketLength, ticketLength = _ref$ticketLength === void 0 ? 6 : _ref$ticketLength;
78
- ValidatePresence("tenantId", tenantId);
79
- ValidatePresence("objectId or groupAddresses", objectId || groupAddresses);
80
-
81
- if (objectId) {
82
- ValidateObject(objectId);
83
- }
84
-
85
- if (groupAddresses) {
86
- groupAddresses.forEach(function (address) {
87
- return ValidateAddress(address);
88
- });
89
- }
90
-
91
- startTime = ValidateDate(startTime);
92
- endTime = ValidateDate(endTime);
93
- paramsJSON = ["ntp:".concat(parseInt(maxRedemptions)), "sen:".concat(parseInt(ticketLength))];
94
-
95
- if (objectId) {
96
- paramsJSON.push("qid:".concat(objectId));
97
- } else if (groupAddresses) {
98
- groupIds = groupAddresses.map(function (address) {
99
- return "igrp".concat(_this.utils.AddressToHash(address));
100
- });
101
- paramsJSON.push("gid:".concat(groupIds.join(",")));
102
- }
103
-
104
- if (startTime) {
105
- paramsJSON.push("vat:".concat(startTime));
106
- }
107
-
108
- if (endTime) {
109
- paramsJSON.push("exp:".concat(endTime));
110
- }
111
-
112
- _context.next = 13;
113
- return this.authClient.MakeKMSCall({
114
- tenantId: tenantId,
115
- methodName: "elv_createOTPInstance",
116
- params: [tenantId, ntpClass, JSON.stringify(paramsJSON), parseInt(maxTickets), Date.now()],
117
- paramTypes: ["string", "int", "string", "int", "int"]
65
+ exports.CreateNTPInstance = function _callee(_ref) {
66
+ var _this = this;
67
+
68
+ var tenantId, objectId, groupAddresses, _ref$ntpClass, ntpClass, _ref$maxTickets, maxTickets, _ref$maxRedemptions, maxRedemptions, startTime, endTime, _ref$ticketLength, ticketLength, paramsJSON, groupIds;
69
+
70
+ return _regeneratorRuntime.async(function _callee$(_context) {
71
+ while (1) {
72
+ switch (_context.prev = _context.next) {
73
+ case 0:
74
+ tenantId = _ref.tenantId, objectId = _ref.objectId, groupAddresses = _ref.groupAddresses, _ref$ntpClass = _ref.ntpClass, ntpClass = _ref$ntpClass === void 0 ? 4 : _ref$ntpClass, _ref$maxTickets = _ref.maxTickets, maxTickets = _ref$maxTickets === void 0 ? 0 : _ref$maxTickets, _ref$maxRedemptions = _ref.maxRedemptions, maxRedemptions = _ref$maxRedemptions === void 0 ? 100 : _ref$maxRedemptions, startTime = _ref.startTime, endTime = _ref.endTime, _ref$ticketLength = _ref.ticketLength, ticketLength = _ref$ticketLength === void 0 ? 6 : _ref$ticketLength;
75
+ ValidatePresence("tenantId", tenantId);
76
+ ValidatePresence("objectId or groupAddresses", objectId || groupAddresses);
77
+
78
+ if (objectId) {
79
+ ValidateObject(objectId);
80
+ }
81
+
82
+ if (groupAddresses) {
83
+ groupAddresses.forEach(function (address) {
84
+ return ValidateAddress(address);
118
85
  });
86
+ }
119
87
 
120
- case 13:
121
- return _context.abrupt("return", _context.sent);
88
+ startTime = ValidateDate(startTime);
89
+ endTime = ValidateDate(endTime);
90
+ paramsJSON = ["ntp:".concat(parseInt(maxRedemptions)), "sen:".concat(parseInt(ticketLength))];
122
91
 
123
- case 14:
124
- case "end":
125
- return _context.stop();
126
- }
92
+ if (objectId) {
93
+ paramsJSON.push("qid:".concat(objectId));
94
+ } else if (groupAddresses) {
95
+ groupIds = groupAddresses.map(function (address) {
96
+ return "igrp".concat(_this.utils.AddressToHash(address));
97
+ });
98
+ paramsJSON.push("gid:".concat(groupIds.join(",")));
99
+ }
100
+
101
+ if (startTime) {
102
+ paramsJSON.push("vat:".concat(startTime));
103
+ }
104
+
105
+ if (endTime) {
106
+ paramsJSON.push("exp:".concat(endTime));
107
+ }
108
+
109
+ _context.next = 13;
110
+ return _regeneratorRuntime.awrap(this.authClient.MakeKMSCall({
111
+ tenantId: tenantId,
112
+ methodName: "elv_createOTPInstance",
113
+ params: [tenantId, ntpClass, JSON.stringify(paramsJSON), parseInt(maxTickets), Date.now()],
114
+ paramTypes: ["string", "int", "string", "int", "int"]
115
+ }));
116
+
117
+ case 13:
118
+ return _context.abrupt("return", _context.sent);
119
+
120
+ case 14:
121
+ case "end":
122
+ return _context.stop();
127
123
  }
128
- }, _callee, this);
129
- }));
130
-
131
- return function (_x) {
132
- return _ref2.apply(this, arguments);
133
- };
134
- }();
124
+ }
125
+ }, null, this);
126
+ };
135
127
  /**
136
128
  * Update the attributes of the specified NTP instance. Only the specified attributes will be updated ; others will be unchanged.
137
129
  *
@@ -148,62 +140,56 @@ exports.CreateNTPInstance = /*#__PURE__*/function () {
148
140
  */
149
141
 
150
142
 
151
- exports.UpdateNTPInstance = /*#__PURE__*/function () {
152
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
153
- var tenantId, ntpId, _ref3$maxTickets, maxTickets, _ref3$maxRedemptions, maxRedemptions, startTime, endTime, paramsJSON, _yield$this$authClien, Ret;
154
-
155
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
156
- while (1) {
157
- switch (_context2.prev = _context2.next) {
158
- case 0:
159
- tenantId = _ref3.tenantId, ntpId = _ref3.ntpId, _ref3$maxTickets = _ref3.maxTickets, maxTickets = _ref3$maxTickets === void 0 ? 0 : _ref3$maxTickets, _ref3$maxRedemptions = _ref3.maxRedemptions, maxRedemptions = _ref3$maxRedemptions === void 0 ? 100 : _ref3$maxRedemptions, startTime = _ref3.startTime, endTime = _ref3.endTime;
160
- ValidatePresence("tenantId", tenantId);
161
- ValidatePresence("ntpId", ntpId);
162
- startTime = ValidateDate(startTime);
163
- endTime = ValidateDate(endTime);
164
- paramsJSON = [];
165
-
166
- if (maxRedemptions) {
167
- paramsJSON.push("ntp:".concat(parseInt(maxRedemptions)));
168
- }
169
-
170
- if (startTime) {
171
- paramsJSON.push("vat:".concat(startTime));
172
- }
173
-
174
- if (endTime) {
175
- paramsJSON.push("exp:".concat(endTime));
176
- }
177
-
178
- if (maxTickets) {
179
- paramsJSON.push("max:".concat(parseInt(maxTickets)));
180
- }
181
-
182
- _context2.next = 12;
183
- return this.authClient.MakeKMSCall({
184
- tenantId: tenantId,
185
- methodName: "elv_updateOTPInstance",
186
- params: [tenantId, ntpId, "update", JSON.stringify(paramsJSON), Date.now()],
187
- paramTypes: ["string", "string", "string", "string", "int"]
188
- });
189
-
190
- case 12:
191
- _yield$this$authClien = _context2.sent;
192
- Ret = _yield$this$authClien.Ret;
193
- return _context2.abrupt("return", FormatNTPInfo(JSON.parse(Ret)));
194
-
195
- case 15:
196
- case "end":
197
- return _context2.stop();
198
- }
143
+ exports.UpdateNTPInstance = function _callee2(_ref2) {
144
+ var tenantId, ntpId, _ref2$maxTickets, maxTickets, _ref2$maxRedemptions, maxRedemptions, startTime, endTime, paramsJSON, _ref3, Ret;
145
+
146
+ return _regeneratorRuntime.async(function _callee2$(_context2) {
147
+ while (1) {
148
+ switch (_context2.prev = _context2.next) {
149
+ case 0:
150
+ tenantId = _ref2.tenantId, ntpId = _ref2.ntpId, _ref2$maxTickets = _ref2.maxTickets, maxTickets = _ref2$maxTickets === void 0 ? 0 : _ref2$maxTickets, _ref2$maxRedemptions = _ref2.maxRedemptions, maxRedemptions = _ref2$maxRedemptions === void 0 ? 100 : _ref2$maxRedemptions, startTime = _ref2.startTime, endTime = _ref2.endTime;
151
+ ValidatePresence("tenantId", tenantId);
152
+ ValidatePresence("ntpId", ntpId);
153
+ startTime = ValidateDate(startTime);
154
+ endTime = ValidateDate(endTime);
155
+ paramsJSON = [];
156
+
157
+ if (maxRedemptions) {
158
+ paramsJSON.push("ntp:".concat(parseInt(maxRedemptions)));
159
+ }
160
+
161
+ if (startTime) {
162
+ paramsJSON.push("vat:".concat(startTime));
163
+ }
164
+
165
+ if (endTime) {
166
+ paramsJSON.push("exp:".concat(endTime));
167
+ }
168
+
169
+ if (maxTickets) {
170
+ paramsJSON.push("max:".concat(parseInt(maxTickets)));
171
+ }
172
+
173
+ _context2.next = 12;
174
+ return _regeneratorRuntime.awrap(this.authClient.MakeKMSCall({
175
+ tenantId: tenantId,
176
+ methodName: "elv_updateOTPInstance",
177
+ params: [tenantId, ntpId, "update", JSON.stringify(paramsJSON), Date.now()],
178
+ paramTypes: ["string", "string", "string", "string", "int"]
179
+ }));
180
+
181
+ case 12:
182
+ _ref3 = _context2.sent;
183
+ Ret = _ref3.Ret;
184
+ return _context2.abrupt("return", FormatNTPInfo(JSON.parse(Ret)));
185
+
186
+ case 15:
187
+ case "end":
188
+ return _context2.stop();
199
189
  }
200
- }, _callee2, this);
201
- }));
202
-
203
- return function (_x2) {
204
- return _ref4.apply(this, arguments);
205
- };
206
- }();
190
+ }
191
+ }, null, this);
192
+ };
207
193
  /**
208
194
  * Suspend the specified NTP instance. All tickets issued for this instance will be considered expired.
209
195
  *
@@ -216,36 +202,30 @@ exports.UpdateNTPInstance = /*#__PURE__*/function () {
216
202
  */
217
203
 
218
204
 
219
- exports.SuspendNTPInstance = /*#__PURE__*/function () {
220
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
221
- var tenantId, ntpId;
222
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
223
- while (1) {
224
- switch (_context3.prev = _context3.next) {
225
- case 0:
226
- tenantId = _ref5.tenantId, ntpId = _ref5.ntpId;
227
- ValidatePresence("tenantId", tenantId);
228
- ValidatePresence("ntpId", ntpId);
229
- _context3.next = 5;
230
- return this.authClient.MakeKMSCall({
231
- tenantId: tenantId,
232
- methodName: "elv_updateOTPInstance",
233
- params: [tenantId, ntpId, "cancel", "[]", Date.now()],
234
- paramTypes: ["string", "string", "string", "string", "int"]
235
- });
236
-
237
- case 5:
238
- case "end":
239
- return _context3.stop();
240
- }
205
+ exports.SuspendNTPInstance = function _callee3(_ref4) {
206
+ var tenantId, ntpId;
207
+ return _regeneratorRuntime.async(function _callee3$(_context3) {
208
+ while (1) {
209
+ switch (_context3.prev = _context3.next) {
210
+ case 0:
211
+ tenantId = _ref4.tenantId, ntpId = _ref4.ntpId;
212
+ ValidatePresence("tenantId", tenantId);
213
+ ValidatePresence("ntpId", ntpId);
214
+ _context3.next = 5;
215
+ return _regeneratorRuntime.awrap(this.authClient.MakeKMSCall({
216
+ tenantId: tenantId,
217
+ methodName: "elv_updateOTPInstance",
218
+ params: [tenantId, ntpId, "cancel", "[]", Date.now()],
219
+ paramTypes: ["string", "string", "string", "string", "int"]
220
+ }));
221
+
222
+ case 5:
223
+ case "end":
224
+ return _context3.stop();
241
225
  }
242
- }, _callee3, this);
243
- }));
244
-
245
- return function (_x3) {
246
- return _ref6.apply(this, arguments);
247
- };
248
- }();
226
+ }
227
+ }, null, this);
228
+ };
249
229
  /**
250
230
  * Delete the specified NTP instance. This action cannot be undone.
251
231
  *
@@ -256,36 +236,30 @@ exports.SuspendNTPInstance = /*#__PURE__*/function () {
256
236
  */
257
237
 
258
238
 
259
- exports.DeleteNTPInstance = /*#__PURE__*/function () {
260
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
261
- var tenantId, ntpId;
262
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
263
- while (1) {
264
- switch (_context4.prev = _context4.next) {
265
- case 0:
266
- tenantId = _ref7.tenantId, ntpId = _ref7.ntpId;
267
- ValidatePresence("tenantId", tenantId);
268
- ValidatePresence("ntpId", ntpId);
269
- _context4.next = 5;
270
- return this.authClient.MakeKMSCall({
271
- tenantId: tenantId,
272
- methodName: "elv_updateOTPInstance",
273
- params: [tenantId, ntpId, "delete", "[]", Date.now()],
274
- paramTypes: ["string", "string", "string", "string", "int"]
275
- });
276
-
277
- case 5:
278
- case "end":
279
- return _context4.stop();
280
- }
239
+ exports.DeleteNTPInstance = function _callee4(_ref5) {
240
+ var tenantId, ntpId;
241
+ return _regeneratorRuntime.async(function _callee4$(_context4) {
242
+ while (1) {
243
+ switch (_context4.prev = _context4.next) {
244
+ case 0:
245
+ tenantId = _ref5.tenantId, ntpId = _ref5.ntpId;
246
+ ValidatePresence("tenantId", tenantId);
247
+ ValidatePresence("ntpId", ntpId);
248
+ _context4.next = 5;
249
+ return _regeneratorRuntime.awrap(this.authClient.MakeKMSCall({
250
+ tenantId: tenantId,
251
+ methodName: "elv_updateOTPInstance",
252
+ params: [tenantId, ntpId, "delete", "[]", Date.now()],
253
+ paramTypes: ["string", "string", "string", "string", "int"]
254
+ }));
255
+
256
+ case 5:
257
+ case "end":
258
+ return _context4.stop();
281
259
  }
282
- }, _callee4, this);
283
- }));
284
-
285
- return function (_x4) {
286
- return _ref8.apply(this, arguments);
287
- };
288
- }();
260
+ }
261
+ }, null, this);
262
+ };
289
263
  /**
290
264
  * Retrieve info for NTP instances in the specified tenant
291
265
  *
@@ -299,48 +273,42 @@ exports.DeleteNTPInstance = /*#__PURE__*/function () {
299
273
  */
300
274
 
301
275
 
302
- exports.ListNTPInstances = /*#__PURE__*/function () {
303
- var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref9) {
304
- var tenantId, _ref9$count, count, _ref9$offset, offset, _yield$this$authClien2, Defs, Total;
305
-
306
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
307
- while (1) {
308
- switch (_context5.prev = _context5.next) {
309
- case 0:
310
- tenantId = _ref9.tenantId, _ref9$count = _ref9.count, count = _ref9$count === void 0 ? 10 : _ref9$count, _ref9$offset = _ref9.offset, offset = _ref9$offset === void 0 ? 0 : _ref9$offset;
311
- ValidatePresence("tenantId", tenantId);
312
- _context5.next = 4;
313
- return this.authClient.MakeKMSCall({
314
- tenantId: tenantId,
315
- methodName: "elv_listOTPInfo",
316
- params: [tenantId, offset, count],
317
- paramTypes: ["string", "int", "int"],
318
- signature: false
319
- });
320
-
321
- case 4:
322
- _yield$this$authClien2 = _context5.sent;
323
- Defs = _yield$this$authClien2.Defs;
324
- Total = _yield$this$authClien2.Total;
325
- return _context5.abrupt("return", {
326
- ntpInstances: Object.values(Defs || {}).map(FormatNTPInfo),
327
- start: offset,
328
- end: Math.min(Total, offset + count),
329
- total: Total
330
- });
331
-
332
- case 8:
333
- case "end":
334
- return _context5.stop();
335
- }
276
+ exports.ListNTPInstances = function _callee5(_ref6) {
277
+ var tenantId, _ref6$count, count, _ref6$offset, offset, _ref7, Defs, Total;
278
+
279
+ return _regeneratorRuntime.async(function _callee5$(_context5) {
280
+ while (1) {
281
+ switch (_context5.prev = _context5.next) {
282
+ case 0:
283
+ tenantId = _ref6.tenantId, _ref6$count = _ref6.count, count = _ref6$count === void 0 ? 10 : _ref6$count, _ref6$offset = _ref6.offset, offset = _ref6$offset === void 0 ? 0 : _ref6$offset;
284
+ ValidatePresence("tenantId", tenantId);
285
+ _context5.next = 4;
286
+ return _regeneratorRuntime.awrap(this.authClient.MakeKMSCall({
287
+ tenantId: tenantId,
288
+ methodName: "elv_listOTPInfo",
289
+ params: [tenantId, offset, count],
290
+ paramTypes: ["string", "int", "int"],
291
+ signature: false
292
+ }));
293
+
294
+ case 4:
295
+ _ref7 = _context5.sent;
296
+ Defs = _ref7.Defs;
297
+ Total = _ref7.Total;
298
+ return _context5.abrupt("return", {
299
+ ntpInstances: Object.values(Defs || {}).map(FormatNTPInfo),
300
+ start: offset,
301
+ end: Math.min(Total, offset + count),
302
+ total: Total
303
+ });
304
+
305
+ case 8:
306
+ case "end":
307
+ return _context5.stop();
336
308
  }
337
- }, _callee5, this);
338
- }));
339
-
340
- return function (_x5) {
341
- return _ref10.apply(this, arguments);
342
- };
343
- }();
309
+ }
310
+ }, null, this);
311
+ };
344
312
  /**
345
313
  * Retrieve a info about the specified NTP instance
346
314
  *
@@ -353,42 +321,36 @@ exports.ListNTPInstances = /*#__PURE__*/function () {
353
321
  */
354
322
 
355
323
 
356
- exports.NTPInstance = /*#__PURE__*/function () {
357
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref11) {
358
- var tenantId, ntpId;
359
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
360
- while (1) {
361
- switch (_context6.prev = _context6.next) {
362
- case 0:
363
- tenantId = _ref11.tenantId, ntpId = _ref11.ntpId;
364
- ValidatePresence("tenantId", tenantId);
365
- ValidatePresence("ntpId", ntpId);
366
- _context6.t0 = FormatNTPInfo;
367
- _context6.next = 6;
368
- return this.authClient.MakeKMSCall({
369
- tenantId: tenantId,
370
- methodName: "elv_getOTPInfo",
371
- params: [tenantId, ntpId],
372
- paramTypes: ["string", "string"],
373
- signature: false
374
- });
375
-
376
- case 6:
377
- _context6.t1 = _context6.sent;
378
- return _context6.abrupt("return", (0, _context6.t0)(_context6.t1));
379
-
380
- case 8:
381
- case "end":
382
- return _context6.stop();
383
- }
324
+ exports.NTPInstance = function _callee6(_ref8) {
325
+ var tenantId, ntpId;
326
+ return _regeneratorRuntime.async(function _callee6$(_context6) {
327
+ while (1) {
328
+ switch (_context6.prev = _context6.next) {
329
+ case 0:
330
+ tenantId = _ref8.tenantId, ntpId = _ref8.ntpId;
331
+ ValidatePresence("tenantId", tenantId);
332
+ ValidatePresence("ntpId", ntpId);
333
+ _context6.t0 = FormatNTPInfo;
334
+ _context6.next = 6;
335
+ return _regeneratorRuntime.awrap(this.authClient.MakeKMSCall({
336
+ tenantId: tenantId,
337
+ methodName: "elv_getOTPInfo",
338
+ params: [tenantId, ntpId],
339
+ paramTypes: ["string", "string"],
340
+ signature: false
341
+ }));
342
+
343
+ case 6:
344
+ _context6.t1 = _context6.sent;
345
+ return _context6.abrupt("return", (0, _context6.t0)(_context6.t1));
346
+
347
+ case 8:
348
+ case "end":
349
+ return _context6.stop();
384
350
  }
385
- }, _callee6, this);
386
- }));
387
-
388
- return function (_x6) {
389
- return _ref12.apply(this, arguments);
390
- };
391
- }();
351
+ }
352
+ }, null, this);
353
+ };
392
354
  /**
393
355
  * Issue a ticket from the specified NTP ID
394
356
  *
@@ -407,50 +369,44 @@ exports.NTPInstance = /*#__PURE__*/function () {
407
369
  */
408
370
 
409
371
 
410
- exports.IssueNTPCode = /*#__PURE__*/function () {
411
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref13) {
412
- var tenantId, ntpId, email, maxRedemptions, options, params, paramTypes;
413
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
414
- while (1) {
415
- switch (_context7.prev = _context7.next) {
416
- case 0:
417
- tenantId = _ref13.tenantId, ntpId = _ref13.ntpId, email = _ref13.email, maxRedemptions = _ref13.maxRedemptions;
418
- ValidatePresence("tenantId", tenantId);
419
- ValidatePresence("ntpId", ntpId);
420
- options = [];
421
-
422
- if (email) {
423
- options.push("eml:".concat(email));
424
- }
425
-
426
- if (maxRedemptions) {
427
- options.push("cnt:".concat(parseInt(maxRedemptions)));
428
- }
429
-
430
- params = [tenantId, ntpId, JSON.stringify(options), Date.now()];
431
- paramTypes = ["string", "string", "string", "uint"];
432
- _context7.next = 10;
433
- return this.authClient.MakeKMSCall({
434
- methodName: "elv_issueOTPCode",
435
- params: params,
436
- paramTypes: paramTypes
437
- });
438
-
439
- case 10:
440
- return _context7.abrupt("return", _context7.sent);
441
-
442
- case 11:
443
- case "end":
444
- return _context7.stop();
445
- }
372
+ exports.IssueNTPCode = function _callee7(_ref9) {
373
+ var tenantId, ntpId, email, maxRedemptions, options, params, paramTypes;
374
+ return _regeneratorRuntime.async(function _callee7$(_context7) {
375
+ while (1) {
376
+ switch (_context7.prev = _context7.next) {
377
+ case 0:
378
+ tenantId = _ref9.tenantId, ntpId = _ref9.ntpId, email = _ref9.email, maxRedemptions = _ref9.maxRedemptions;
379
+ ValidatePresence("tenantId", tenantId);
380
+ ValidatePresence("ntpId", ntpId);
381
+ options = [];
382
+
383
+ if (email) {
384
+ options.push("eml:".concat(email));
385
+ }
386
+
387
+ if (maxRedemptions) {
388
+ options.push("cnt:".concat(parseInt(maxRedemptions)));
389
+ }
390
+
391
+ params = [tenantId, ntpId, JSON.stringify(options), Date.now()];
392
+ paramTypes = ["string", "string", "string", "uint"];
393
+ _context7.next = 10;
394
+ return _regeneratorRuntime.awrap(this.authClient.MakeKMSCall({
395
+ methodName: "elv_issueOTPCode",
396
+ params: params,
397
+ paramTypes: paramTypes
398
+ }));
399
+
400
+ case 10:
401
+ return _context7.abrupt("return", _context7.sent);
402
+
403
+ case 11:
404
+ case "end":
405
+ return _context7.stop();
446
406
  }
447
- }, _callee7, this);
448
- }));
449
-
450
- return function (_x7) {
451
- return _ref14.apply(this, arguments);
452
- };
453
- }();
407
+ }
408
+ }, null, this);
409
+ };
454
410
  /**
455
411
  * Identical to IssueNTPCode, but the token is also signed by the current user.
456
412
  *
@@ -469,53 +425,47 @@ exports.IssueNTPCode = /*#__PURE__*/function () {
469
425
  */
470
426
 
471
427
 
472
- exports.IssueSignedNTPCode = /*#__PURE__*/function () {
473
- var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref15) {
474
- var tenantId, ntpId, email, maxRedemptions, result, signature, multiSig;
475
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
476
- while (1) {
477
- switch (_context8.prev = _context8.next) {
478
- case 0:
479
- tenantId = _ref15.tenantId, ntpId = _ref15.ntpId, email = _ref15.email, maxRedemptions = _ref15.maxRedemptions;
480
- _context8.next = 3;
481
- return this.IssueNTPCode({
482
- tenantId: tenantId,
483
- ntpId: ntpId,
484
- email: email,
485
- maxRedemptions: maxRedemptions
486
- });
487
-
488
- case 3:
489
- result = _context8.sent;
490
-
491
- if (!result.token) {
492
- _context8.next = 10;
493
- break;
494
- }
428
+ exports.IssueSignedNTPCode = function _callee8(_ref10) {
429
+ var tenantId, ntpId, email, maxRedemptions, result, signature, multiSig;
430
+ return _regeneratorRuntime.async(function _callee8$(_context8) {
431
+ while (1) {
432
+ switch (_context8.prev = _context8.next) {
433
+ case 0:
434
+ tenantId = _ref10.tenantId, ntpId = _ref10.ntpId, email = _ref10.email, maxRedemptions = _ref10.maxRedemptions;
435
+ _context8.next = 3;
436
+ return _regeneratorRuntime.awrap(this.IssueNTPCode({
437
+ tenantId: tenantId,
438
+ ntpId: ntpId,
439
+ email: email,
440
+ maxRedemptions: maxRedemptions
441
+ }));
442
+
443
+ case 3:
444
+ result = _context8.sent;
445
+
446
+ if (!result.token) {
447
+ _context8.next = 10;
448
+ break;
449
+ }
495
450
 
496
- _context8.next = 7;
497
- return this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(result.token)));
451
+ _context8.next = 7;
452
+ return _regeneratorRuntime.awrap(this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(result.token))));
498
453
 
499
- case 7:
500
- signature = _context8.sent;
501
- multiSig = this.utils.FormatSignature(signature);
502
- result.token = "".concat(result.token, ".").concat(this.utils.B64(multiSig));
454
+ case 7:
455
+ signature = _context8.sent;
456
+ multiSig = this.utils.FormatSignature(signature);
457
+ result.token = "".concat(result.token, ".").concat(this.utils.B64(multiSig));
503
458
 
504
- case 10:
505
- return _context8.abrupt("return", result);
459
+ case 10:
460
+ return _context8.abrupt("return", result);
506
461
 
507
- case 11:
508
- case "end":
509
- return _context8.stop();
510
- }
462
+ case 11:
463
+ case "end":
464
+ return _context8.stop();
511
465
  }
512
- }, _callee8, this);
513
- }));
514
-
515
- return function (_x8) {
516
- return _ref16.apply(this, arguments);
517
- };
518
- }();
466
+ }
467
+ }, null, this);
468
+ };
519
469
  /**
520
470
  * Redeem the specified ticket/code to authorize the client. Must provide either issuer or tenantId and ntpId
521
471
  *
@@ -532,149 +482,143 @@ exports.IssueSignedNTPCode = /*#__PURE__*/function () {
532
482
  */
533
483
 
534
484
 
535
- exports.RedeemCode = /*#__PURE__*/function () {
536
- var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref17) {
537
- var issuer, tenantId, ntpId, code, email, _ref17$includeNTPId, includeNTPId, wallet, token, response, objectId, libraryId, Hash, codeHash, codeInfo, ak, sites, info, signer;
538
-
539
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
540
- while (1) {
541
- switch (_context9.prev = _context9.next) {
542
- case 0:
543
- issuer = _ref17.issuer, tenantId = _ref17.tenantId, ntpId = _ref17.ntpId, code = _ref17.code, email = _ref17.email, _ref17$includeNTPId = _ref17.includeNTPId, includeNTPId = _ref17$includeNTPId === void 0 ? false : _ref17$includeNTPId;
544
- wallet = this.GenerateWallet();
545
- issuer = issuer || "";
546
-
547
- if (!this.signer) {
548
- this.SetSigner({
549
- signer: wallet.AddAccountFromMnemonic({
550
- mnemonic: wallet.GenerateMnemonic()
551
- })
552
- });
553
- }
554
-
555
- if (!issuer.startsWith("iq__")) {
556
- _context9.next = 8;
557
- break;
558
- }
559
-
560
- ValidateObject(issuer);
561
- _context9.next = 28;
562
- break;
563
-
564
- case 8:
565
- if (!(issuer && !issuer.replace(/^\//, "").startsWith("otp/ntp/iten"))) {
566
- _context9.next = 12;
567
- break;
568
- }
569
-
570
- throw Error("Invalid issuer: " + issuer);
571
-
572
- case 12:
573
- // Ticket API
574
- ValidatePresence("issuer or tenantId", issuer || tenantId);
485
+ exports.RedeemCode = function _callee9(_ref11) {
486
+ var issuer, tenantId, ntpId, code, email, _ref11$includeNTPId, includeNTPId, wallet, token, response, objectId, libraryId, Hash, codeHash, codeInfo, ak, sites, info, signer;
575
487
 
576
- if (!issuer) {
577
- issuer = UrlJoin("/otp", "ntp", tenantId, ntpId || "");
578
- }
488
+ return _regeneratorRuntime.async(function _callee9$(_context9) {
489
+ while (1) {
490
+ switch (_context9.prev = _context9.next) {
491
+ case 0:
492
+ issuer = _ref11.issuer, tenantId = _ref11.tenantId, ntpId = _ref11.ntpId, code = _ref11.code, email = _ref11.email, _ref11$includeNTPId = _ref11.includeNTPId, includeNTPId = _ref11$includeNTPId === void 0 ? false : _ref11$includeNTPId;
493
+ wallet = this.GenerateWallet();
494
+ issuer = issuer || "";
579
495
 
580
- _context9.prev = 14;
581
- _context9.next = 17;
582
- return this.authClient.GenerateChannelContentToken({
583
- issuer: issuer,
584
- code: code,
585
- email: email
586
- });
587
-
588
- case 17:
589
- token = _context9.sent;
590
- this.SetStaticToken({
591
- token: token
592
- });
593
- response = JSON.parse(this.utils.FromB64(token));
594
- return _context9.abrupt("return", includeNTPId ? {
595
- objectId: response.qid,
596
- ntpId: response.oid
597
- } : response.qid);
598
-
599
- case 23:
600
- _context9.prev = 23;
601
- _context9.t0 = _context9["catch"](14);
602
- this.Log("Failed to redeem code:", true);
603
- this.Log(_context9.t0, true);
604
- throw _context9.t0;
605
-
606
- case 28:
607
- // Site selector
608
- objectId = issuer;
609
- _context9.next = 31;
610
- return this.ContentObjectLibraryId({
611
- objectId: objectId
612
- });
613
-
614
- case 31:
615
- libraryId = _context9.sent;
616
-
617
- Hash = function Hash(code) {
618
- var chars = code.split("").map(function (code) {
619
- return code.charCodeAt(0);
620
- });
621
- return chars.reduce(function (sum, _char, i) {
622
- return chars[i + 1] ? sum * 2 + _char * chars[i + 1] * (i + 1) : sum + _char;
623
- }, 0).toString();
624
- };
625
-
626
- codeHash = Hash(code);
627
- _context9.next = 36;
628
- return this.ContentObjectMetadata({
629
- libraryId: libraryId,
630
- objectId: objectId,
631
- metadataSubtree: "public/codes/".concat(codeHash)
632
- });
633
-
634
- case 36:
635
- codeInfo = _context9.sent;
636
-
637
- if (codeInfo) {
638
- _context9.next = 40;
639
- break;
640
- }
641
-
642
- this.Log("Code redemption failed:\n\t".concat(issuer, "\n\t").concat(code));
643
- throw Error("Invalid code: " + code);
644
-
645
- case 40:
646
- ak = codeInfo.ak, sites = codeInfo.sites, info = codeInfo.info;
647
- _context9.next = 43;
648
- return wallet.AddAccountFromEncryptedPK({
649
- encryptedPrivateKey: this.utils.FromB64(ak),
650
- password: code
496
+ if (!this.signer) {
497
+ this.SetSigner({
498
+ signer: wallet.AddAccountFromMnemonic({
499
+ mnemonic: wallet.GenerateMnemonic()
500
+ })
651
501
  });
502
+ }
652
503
 
653
- case 43:
654
- signer = _context9.sent;
655
- this.SetSigner({
656
- signer: signer
657
- }); // Ensure wallet is initialized
504
+ if (!issuer.startsWith("iq__")) {
505
+ _context9.next = 8;
506
+ break;
507
+ }
658
508
 
659
- _context9.next = 47;
660
- return this.userProfileClient.WalletAddress();
509
+ ValidateObject(issuer);
510
+ _context9.next = 28;
511
+ break;
661
512
 
662
- case 47:
663
- return _context9.abrupt("return", {
664
- addr: this.utils.FormatAddress(signer.address),
665
- sites: sites,
666
- info: info || {}
513
+ case 8:
514
+ if (!(issuer && !issuer.replace(/^\//, "").startsWith("otp/ntp/iten"))) {
515
+ _context9.next = 12;
516
+ break;
517
+ }
518
+
519
+ throw Error("Invalid issuer: " + issuer);
520
+
521
+ case 12:
522
+ // Ticket API
523
+ ValidatePresence("issuer or tenantId", issuer || tenantId);
524
+
525
+ if (!issuer) {
526
+ issuer = UrlJoin("/otp", "ntp", tenantId, ntpId || "");
527
+ }
528
+
529
+ _context9.prev = 14;
530
+ _context9.next = 17;
531
+ return _regeneratorRuntime.awrap(this.authClient.GenerateChannelContentToken({
532
+ issuer: issuer,
533
+ code: code,
534
+ email: email
535
+ }));
536
+
537
+ case 17:
538
+ token = _context9.sent;
539
+ this.SetStaticToken({
540
+ token: token
541
+ });
542
+ response = JSON.parse(this.utils.FromB64(token));
543
+ return _context9.abrupt("return", includeNTPId ? {
544
+ objectId: response.qid,
545
+ ntpId: response.oid
546
+ } : response.qid);
547
+
548
+ case 23:
549
+ _context9.prev = 23;
550
+ _context9.t0 = _context9["catch"](14);
551
+ this.Log("Failed to redeem code:", true);
552
+ this.Log(_context9.t0, true);
553
+ throw _context9.t0;
554
+
555
+ case 28:
556
+ // Site selector
557
+ objectId = issuer;
558
+ _context9.next = 31;
559
+ return _regeneratorRuntime.awrap(this.ContentObjectLibraryId({
560
+ objectId: objectId
561
+ }));
562
+
563
+ case 31:
564
+ libraryId = _context9.sent;
565
+
566
+ Hash = function Hash(code) {
567
+ var chars = code.split("").map(function (code) {
568
+ return code.charCodeAt(0);
667
569
  });
668
-
669
- case 48:
670
- case "end":
671
- return _context9.stop();
672
- }
570
+ return chars.reduce(function (sum, _char, i) {
571
+ return chars[i + 1] ? sum * 2 + _char * chars[i + 1] * (i + 1) : sum + _char;
572
+ }, 0).toString();
573
+ };
574
+
575
+ codeHash = Hash(code);
576
+ _context9.next = 36;
577
+ return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
578
+ libraryId: libraryId,
579
+ objectId: objectId,
580
+ metadataSubtree: "public/codes/".concat(codeHash)
581
+ }));
582
+
583
+ case 36:
584
+ codeInfo = _context9.sent;
585
+
586
+ if (codeInfo) {
587
+ _context9.next = 40;
588
+ break;
589
+ }
590
+
591
+ this.Log("Code redemption failed:\n\t".concat(issuer, "\n\t").concat(code));
592
+ throw Error("Invalid code: " + code);
593
+
594
+ case 40:
595
+ ak = codeInfo.ak, sites = codeInfo.sites, info = codeInfo.info;
596
+ _context9.next = 43;
597
+ return _regeneratorRuntime.awrap(wallet.AddAccountFromEncryptedPK({
598
+ encryptedPrivateKey: this.utils.FromB64(ak),
599
+ password: code
600
+ }));
601
+
602
+ case 43:
603
+ signer = _context9.sent;
604
+ this.SetSigner({
605
+ signer: signer
606
+ }); // Ensure wallet is initialized
607
+
608
+ _context9.next = 47;
609
+ return _regeneratorRuntime.awrap(this.userProfileClient.WalletAddress());
610
+
611
+ case 47:
612
+ return _context9.abrupt("return", {
613
+ addr: this.utils.FormatAddress(signer.address),
614
+ sites: sites,
615
+ info: info || {}
616
+ });
617
+
618
+ case 48:
619
+ case "end":
620
+ return _context9.stop();
673
621
  }
674
- }, _callee9, this, [[14, 23]]);
675
- }));
676
-
677
- return function (_x9) {
678
- return _ref18.apply(this, arguments);
679
- };
680
- }();
622
+ }
623
+ }, null, this, [[14, 23]]);
624
+ };