@eluvio/elv-client-js 4.0.10 → 4.0.11

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.
Files changed (40) hide show
  1. package/dist/ElvClient-min.js +10 -11
  2. package/dist/ElvClient-node-min.js +10 -11
  3. package/dist/ElvFrameClient-min.js +10 -11
  4. package/dist/ElvPermissionsClient-min.js +9 -10
  5. package/dist/ElvWalletClient-min.js +9 -10
  6. package/dist/ElvWalletClient-node-min.js +9 -10
  7. package/dist/src/AuthorizationClient.js +2070 -1550
  8. package/dist/src/ContentObjectVerification.js +185 -134
  9. package/dist/src/Crypto.js +319 -224
  10. package/dist/src/ElvClient.js +1114 -822
  11. package/dist/src/ElvWallet.js +106 -64
  12. package/dist/src/EthClient.js +974 -719
  13. package/dist/src/FrameClient.js +318 -222
  14. package/dist/src/HttpClient.js +154 -112
  15. package/dist/src/Id.js +6 -1
  16. package/dist/src/LogMessage.js +8 -4
  17. package/dist/src/PermissionsClient.js +1271 -973
  18. package/dist/src/RemoteSigner.js +232 -161
  19. package/dist/src/UserProfileClient.js +1038 -781
  20. package/dist/src/Utils.js +299 -159
  21. package/dist/src/Validation.js +17 -2
  22. package/dist/src/client/ABRPublishing.js +942 -772
  23. package/dist/src/client/AccessGroups.js +1095 -849
  24. package/dist/src/client/ContentAccess.js +4196 -3323
  25. package/dist/src/client/ContentManagement.js +2288 -1814
  26. package/dist/src/client/Contracts.js +614 -468
  27. package/dist/src/client/Files.js +1831 -1490
  28. package/dist/src/client/NFT.js +116 -94
  29. package/dist/src/client/NTP.js +425 -326
  30. package/dist/src/index.js +5 -2
  31. package/dist/src/walletClient/ClientMethods.js +1763 -1368
  32. package/dist/src/walletClient/Configuration.js +2 -4
  33. package/dist/src/walletClient/Notifications.js +127 -98
  34. package/dist/src/walletClient/Profile.js +246 -184
  35. package/dist/src/walletClient/Utils.js +122 -76
  36. package/dist/src/walletClient/index.js +1496 -1171
  37. package/package.json +1 -1
  38. package/src/AuthorizationClient.js +5 -5
  39. package/src/client/Files.js +1 -1
  40. package/testScripts/CreateMezMonolithic.js +0 -779
@@ -1,18 +1,22 @@
1
1
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
+
2
3
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
+
3
5
  /**
4
6
  * Methods for creating and managing NTP instances and tickets
5
7
  *
6
8
  * @module ElvClient/NTP
7
9
  */
8
-
9
10
  var UrlJoin = require("url-join");
11
+
10
12
  var Ethers = require("ethers");
13
+
11
14
  var _require = require("../Validation"),
12
- ValidateAddress = _require.ValidateAddress,
13
- ValidateDate = _require.ValidateDate,
14
- ValidateObject = _require.ValidateObject,
15
- ValidatePresence = _require.ValidatePresence;
15
+ ValidateAddress = _require.ValidateAddress,
16
+ ValidateDate = _require.ValidateDate,
17
+ ValidateObject = _require.ValidateObject,
18
+ ValidatePresence = _require.ValidatePresence;
19
+
16
20
  var FormatNTPInfo = function FormatNTPInfo(info) {
17
21
  var params = info.pm || {};
18
22
  var response = {
@@ -28,12 +32,13 @@ var FormatNTPInfo = function FormatNTPInfo(info) {
28
32
  maxRedemptions: params.ntp,
29
33
  maxTickets: info.mx
30
34
  };
35
+
31
36
  if (typeof info.cnt !== "undefined") {
32
37
  response.issuedTickets = info.cnt;
33
38
  }
39
+
34
40
  return response;
35
41
  };
36
-
37
42
  /**
38
43
  * Issue an n-time-password (NTP) instance. This instance contains a specification for the tickets (AKA codes) to be issued, including
39
44
  * the target(s) to be authorized, how many tickets can be issued, and when and how many times tickets can be redeemed.
@@ -57,61 +62,76 @@ var FormatNTPInfo = function FormatNTPInfo(info) {
57
62
  *
58
63
  * @return {Promise<string>} - The ID of the NTP instance. This ID can be used when issuing tickets (See IssueNTPCode)
59
64
  */
65
+
66
+
60
67
  exports.CreateNTPInstance = /*#__PURE__*/function () {
61
68
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
62
69
  var _this = this;
70
+
63
71
  var tenantId, objectId, groupAddresses, _ref$ntpClass, ntpClass, _ref$maxTickets, maxTickets, _ref$maxRedemptions, maxRedemptions, startTime, endTime, _ref$ticketLength, ticketLength, paramsJSON, groupIds;
72
+
64
73
  return _regeneratorRuntime.wrap(function _callee$(_context) {
65
- while (1) switch (_context.prev = _context.next) {
66
- case 0:
67
- 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;
68
- ValidatePresence("tenantId", tenantId);
69
- ValidatePresence("objectId or groupAddresses", objectId || groupAddresses);
70
- if (objectId) {
71
- ValidateObject(objectId);
72
- }
73
- if (groupAddresses) {
74
- groupAddresses.forEach(function (address) {
75
- return ValidateAddress(address);
76
- });
77
- }
78
- startTime = ValidateDate(startTime);
79
- endTime = ValidateDate(endTime);
80
- paramsJSON = ["ntp:".concat(parseInt(maxRedemptions)), "sen:".concat(parseInt(ticketLength))];
81
- if (objectId) {
82
- paramsJSON.push("qid:".concat(objectId));
83
- } else if (groupAddresses) {
84
- groupIds = groupAddresses.map(function (address) {
85
- return "igrp".concat(_this.utils.AddressToHash(address));
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"]
86
118
  });
87
- paramsJSON.push("gid:".concat(groupIds.join(",")));
88
- }
89
- if (startTime) {
90
- paramsJSON.push("vat:".concat(startTime));
91
- }
92
- if (endTime) {
93
- paramsJSON.push("exp:".concat(endTime));
94
- }
95
- _context.next = 13;
96
- return this.authClient.MakeKMSCall({
97
- tenantId: tenantId,
98
- methodName: "elv_createOTPInstance",
99
- params: [tenantId, ntpClass, JSON.stringify(paramsJSON), parseInt(maxTickets), Date.now()],
100
- paramTypes: ["string", "int", "string", "int", "int"]
101
- });
102
- case 13:
103
- return _context.abrupt("return", _context.sent);
104
- case 14:
105
- case "end":
106
- return _context.stop();
119
+
120
+ case 13:
121
+ return _context.abrupt("return", _context.sent);
122
+
123
+ case 14:
124
+ case "end":
125
+ return _context.stop();
126
+ }
107
127
  }
108
128
  }, _callee, this);
109
129
  }));
130
+
110
131
  return function (_x) {
111
132
  return _ref2.apply(this, arguments);
112
133
  };
113
134
  }();
114
-
115
135
  /**
116
136
  * Update the attributes of the specified NTP instance. Only the specified attributes will be updated ; others will be unchanged.
117
137
  *
@@ -126,52 +146,64 @@ exports.CreateNTPInstance = /*#__PURE__*/function () {
126
146
  *
127
147
  * @return {Object} - Info about the NTP Instance
128
148
  */
149
+
150
+
129
151
  exports.UpdateNTPInstance = /*#__PURE__*/function () {
130
152
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
131
153
  var tenantId, ntpId, _ref3$maxTickets, maxTickets, _ref3$maxRedemptions, maxRedemptions, startTime, endTime, paramsJSON, _yield$this$authClien, Ret;
154
+
132
155
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
133
- while (1) switch (_context2.prev = _context2.next) {
134
- case 0:
135
- 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;
136
- ValidatePresence("tenantId", tenantId);
137
- ValidatePresence("ntpId", ntpId);
138
- startTime = ValidateDate(startTime);
139
- endTime = ValidateDate(endTime);
140
- paramsJSON = [];
141
- if (maxRedemptions) {
142
- paramsJSON.push("ntp:".concat(parseInt(maxRedemptions)));
143
- }
144
- if (startTime) {
145
- paramsJSON.push("vat:".concat(startTime));
146
- }
147
- if (endTime) {
148
- paramsJSON.push("exp:".concat(endTime));
149
- }
150
- if (maxTickets) {
151
- paramsJSON.push("max:".concat(parseInt(maxTickets)));
152
- }
153
- _context2.next = 12;
154
- return this.authClient.MakeKMSCall({
155
- tenantId: tenantId,
156
- methodName: "elv_updateOTPInstance",
157
- params: [tenantId, ntpId, "update", JSON.stringify(paramsJSON), Date.now()],
158
- paramTypes: ["string", "string", "string", "string", "int"]
159
- });
160
- case 12:
161
- _yield$this$authClien = _context2.sent;
162
- Ret = _yield$this$authClien.Ret;
163
- return _context2.abrupt("return", FormatNTPInfo(JSON.parse(Ret)));
164
- case 15:
165
- case "end":
166
- return _context2.stop();
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
+ }
167
199
  }
168
200
  }, _callee2, this);
169
201
  }));
202
+
170
203
  return function (_x2) {
171
204
  return _ref4.apply(this, arguments);
172
205
  };
173
206
  }();
174
-
175
207
  /**
176
208
  * Suspend the specified NTP instance. All tickets issued for this instance will be considered expired.
177
209
  *
@@ -182,33 +214,38 @@ exports.UpdateNTPInstance = /*#__PURE__*/function () {
182
214
  * @param {string} tenantId - The ID of the tenant in which this NTP instance was created
183
215
  * @param {string} ntpId - The ID of the NTP instance
184
216
  */
217
+
218
+
185
219
  exports.SuspendNTPInstance = /*#__PURE__*/function () {
186
220
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
187
221
  var tenantId, ntpId;
188
222
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
189
- while (1) switch (_context3.prev = _context3.next) {
190
- case 0:
191
- tenantId = _ref5.tenantId, ntpId = _ref5.ntpId;
192
- ValidatePresence("tenantId", tenantId);
193
- ValidatePresence("ntpId", ntpId);
194
- _context3.next = 5;
195
- return this.authClient.MakeKMSCall({
196
- tenantId: tenantId,
197
- methodName: "elv_updateOTPInstance",
198
- params: [tenantId, ntpId, "cancel", "[]", Date.now()],
199
- paramTypes: ["string", "string", "string", "string", "int"]
200
- });
201
- case 5:
202
- case "end":
203
- return _context3.stop();
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
+ }
204
241
  }
205
242
  }, _callee3, this);
206
243
  }));
244
+
207
245
  return function (_x3) {
208
246
  return _ref6.apply(this, arguments);
209
247
  };
210
248
  }();
211
-
212
249
  /**
213
250
  * Delete the specified NTP instance. This action cannot be undone.
214
251
  *
@@ -217,33 +254,38 @@ exports.SuspendNTPInstance = /*#__PURE__*/function () {
217
254
  * @param {string} tenantId - The ID of the tenant in which this NTP instance was created
218
255
  * @param {string} ntpId - The ID of the NTP instance
219
256
  */
257
+
258
+
220
259
  exports.DeleteNTPInstance = /*#__PURE__*/function () {
221
260
  var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
222
261
  var tenantId, ntpId;
223
262
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
224
- while (1) switch (_context4.prev = _context4.next) {
225
- case 0:
226
- tenantId = _ref7.tenantId, ntpId = _ref7.ntpId;
227
- ValidatePresence("tenantId", tenantId);
228
- ValidatePresence("ntpId", ntpId);
229
- _context4.next = 5;
230
- return this.authClient.MakeKMSCall({
231
- tenantId: tenantId,
232
- methodName: "elv_updateOTPInstance",
233
- params: [tenantId, ntpId, "delete", "[]", Date.now()],
234
- paramTypes: ["string", "string", "string", "string", "int"]
235
- });
236
- case 5:
237
- case "end":
238
- return _context4.stop();
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
281
  }
240
282
  }, _callee4, this);
241
283
  }));
284
+
242
285
  return function (_x4) {
243
286
  return _ref8.apply(this, arguments);
244
287
  };
245
288
  }();
246
-
247
289
  /**
248
290
  * Retrieve info for NTP instances in the specified tenant
249
291
  *
@@ -255,43 +297,50 @@ exports.DeleteNTPInstance = /*#__PURE__*/function () {
255
297
  *
256
298
  * @return {Object} - List of NTP instances along with pagination information
257
299
  */
300
+
301
+
258
302
  exports.ListNTPInstances = /*#__PURE__*/function () {
259
303
  var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref9) {
260
304
  var tenantId, _ref9$count, count, _ref9$offset, offset, _yield$this$authClien2, Defs, Total;
305
+
261
306
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
262
- while (1) switch (_context5.prev = _context5.next) {
263
- case 0:
264
- 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;
265
- ValidatePresence("tenantId", tenantId);
266
- _context5.next = 4;
267
- return this.authClient.MakeKMSCall({
268
- tenantId: tenantId,
269
- methodName: "elv_listOTPInfo",
270
- params: [tenantId, offset, count],
271
- paramTypes: ["string", "int", "int"],
272
- signature: false
273
- });
274
- case 4:
275
- _yield$this$authClien2 = _context5.sent;
276
- Defs = _yield$this$authClien2.Defs;
277
- Total = _yield$this$authClien2.Total;
278
- return _context5.abrupt("return", {
279
- ntpInstances: Object.values(Defs || {}).map(FormatNTPInfo),
280
- start: offset,
281
- end: Math.min(Total, offset + count),
282
- total: Total
283
- });
284
- case 8:
285
- case "end":
286
- return _context5.stop();
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
+ }
287
336
  }
288
337
  }, _callee5, this);
289
338
  }));
339
+
290
340
  return function (_x5) {
291
341
  return _ref10.apply(this, arguments);
292
342
  };
293
343
  }();
294
-
295
344
  /**
296
345
  * Retrieve a info about the specified NTP instance
297
346
  *
@@ -302,38 +351,44 @@ exports.ListNTPInstances = /*#__PURE__*/function () {
302
351
  *
303
352
  * @return {Object} - Info about the NTP instance
304
353
  */
354
+
355
+
305
356
  exports.NTPInstance = /*#__PURE__*/function () {
306
357
  var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref11) {
307
358
  var tenantId, ntpId;
308
359
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
309
- while (1) switch (_context6.prev = _context6.next) {
310
- case 0:
311
- tenantId = _ref11.tenantId, ntpId = _ref11.ntpId;
312
- ValidatePresence("tenantId", tenantId);
313
- ValidatePresence("ntpId", ntpId);
314
- _context6.t0 = FormatNTPInfo;
315
- _context6.next = 6;
316
- return this.authClient.MakeKMSCall({
317
- tenantId: tenantId,
318
- methodName: "elv_getOTPInfo",
319
- params: [tenantId, ntpId],
320
- paramTypes: ["string", "string"],
321
- signature: false
322
- });
323
- case 6:
324
- _context6.t1 = _context6.sent;
325
- return _context6.abrupt("return", (0, _context6.t0)(_context6.t1));
326
- case 8:
327
- case "end":
328
- return _context6.stop();
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
+ }
329
384
  }
330
385
  }, _callee6, this);
331
386
  }));
387
+
332
388
  return function (_x6) {
333
389
  return _ref12.apply(this, arguments);
334
390
  };
335
391
  }();
336
-
337
392
  /**
338
393
  * Issue a ticket from the specified NTP ID
339
394
  *
@@ -350,43 +405,52 @@ exports.NTPInstance = /*#__PURE__*/function () {
350
405
  *
351
406
  * @return {Promise<Object>} - The generated ticket code and additional information about the ticket.
352
407
  */
408
+
409
+
353
410
  exports.IssueNTPCode = /*#__PURE__*/function () {
354
411
  var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref13) {
355
412
  var tenantId, ntpId, email, maxRedemptions, options, params, paramTypes;
356
413
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
357
- while (1) switch (_context7.prev = _context7.next) {
358
- case 0:
359
- tenantId = _ref13.tenantId, ntpId = _ref13.ntpId, email = _ref13.email, maxRedemptions = _ref13.maxRedemptions;
360
- ValidatePresence("tenantId", tenantId);
361
- ValidatePresence("ntpId", ntpId);
362
- options = [];
363
- if (email) {
364
- options.push("eml:".concat(email));
365
- }
366
- if (maxRedemptions) {
367
- options.push("cnt:".concat(parseInt(maxRedemptions)));
368
- }
369
- params = [tenantId, ntpId, JSON.stringify(options), Date.now()];
370
- paramTypes = ["string", "string", "string", "uint"];
371
- _context7.next = 10;
372
- return this.authClient.MakeKMSCall({
373
- methodName: "elv_issueOTPCode",
374
- params: params,
375
- paramTypes: paramTypes
376
- });
377
- case 10:
378
- return _context7.abrupt("return", _context7.sent);
379
- case 11:
380
- case "end":
381
- return _context7.stop();
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
+ }
382
446
  }
383
447
  }, _callee7, this);
384
448
  }));
449
+
385
450
  return function (_x7) {
386
451
  return _ref14.apply(this, arguments);
387
452
  };
388
453
  }();
389
-
390
454
  /**
391
455
  * Identical to IssueNTPCode, but the token is also signed by the current user.
392
456
  *
@@ -403,45 +467,55 @@ exports.IssueNTPCode = /*#__PURE__*/function () {
403
467
  *
404
468
  * @return {Promise<Object>} - The generated signed ticket code and additional information about the ticket.
405
469
  */
470
+
471
+
406
472
  exports.IssueSignedNTPCode = /*#__PURE__*/function () {
407
473
  var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref15) {
408
474
  var tenantId, ntpId, email, maxRedemptions, result, signature, multiSig;
409
475
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
410
- while (1) switch (_context8.prev = _context8.next) {
411
- case 0:
412
- tenantId = _ref15.tenantId, ntpId = _ref15.ntpId, email = _ref15.email, maxRedemptions = _ref15.maxRedemptions;
413
- _context8.next = 3;
414
- return this.IssueNTPCode({
415
- tenantId: tenantId,
416
- ntpId: ntpId,
417
- email: email,
418
- maxRedemptions: maxRedemptions
419
- });
420
- case 3:
421
- result = _context8.sent;
422
- if (!result.token) {
423
- _context8.next = 10;
424
- break;
425
- }
426
- _context8.next = 7;
427
- return this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(result.token)));
428
- case 7:
429
- signature = _context8.sent;
430
- multiSig = this.utils.FormatSignature(signature);
431
- result.token = "".concat(result.token, ".").concat(this.utils.B64(multiSig));
432
- case 10:
433
- return _context8.abrupt("return", result);
434
- case 11:
435
- case "end":
436
- return _context8.stop();
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
+ }
495
+
496
+ _context8.next = 7;
497
+ return this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(result.token)));
498
+
499
+ case 7:
500
+ signature = _context8.sent;
501
+ multiSig = this.utils.FormatSignature(signature);
502
+ result.token = "".concat(result.token, ".").concat(this.utils.B64(multiSig));
503
+
504
+ case 10:
505
+ return _context8.abrupt("return", result);
506
+
507
+ case 11:
508
+ case "end":
509
+ return _context8.stop();
510
+ }
437
511
  }
438
512
  }, _callee8, this);
439
513
  }));
514
+
440
515
  return function (_x8) {
441
516
  return _ref16.apply(this, arguments);
442
517
  };
443
518
  }();
444
-
445
519
  /**
446
520
  * Redeem the specified ticket/code to authorize the client. Must provide either issuer or tenantId and ntpId
447
521
  *
@@ -456,125 +530,150 @@ exports.IssueSignedNTPCode = /*#__PURE__*/function () {
456
530
  *
457
531
  * @return {Promise<string|Object>} - The object ID which the ticket is authorized to, or an object containing the object ID and NTP ID if `includeNTPId` is specified
458
532
  */
533
+
534
+
459
535
  exports.RedeemCode = /*#__PURE__*/function () {
460
536
  var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref17) {
461
537
  var issuer, tenantId, ntpId, code, email, _ref17$includeNTPId, includeNTPId, wallet, token, response, objectId, libraryId, Hash, codeHash, codeInfo, ak, sites, info, signer;
538
+
462
539
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
463
- while (1) switch (_context9.prev = _context9.next) {
464
- case 0:
465
- 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;
466
- wallet = this.GenerateWallet();
467
- issuer = issuer || "";
468
- if (!this.signer) {
469
- this.SetSigner({
470
- signer: wallet.AddAccountFromMnemonic({
471
- mnemonic: wallet.GenerateMnemonic()
472
- })
473
- });
474
- }
475
- if (!issuer.startsWith("iq__")) {
476
- _context9.next = 8;
477
- break;
478
- }
479
- ValidateObject(issuer);
480
- _context9.next = 28;
481
- break;
482
- case 8:
483
- if (!(issuer && !issuer.replace(/^\//, "").startsWith("otp/ntp/iten"))) {
484
- _context9.next = 12;
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;
485
562
  break;
486
- }
487
- throw Error("Invalid issuer: " + issuer);
488
- case 12:
489
- // Ticket API
490
-
491
- ValidatePresence("issuer or tenantId", issuer || tenantId);
492
- if (!issuer) {
493
- issuer = UrlJoin("/otp", "ntp", tenantId, ntpId || "");
494
- }
495
- _context9.prev = 14;
496
- _context9.next = 17;
497
- return this.authClient.GenerateChannelContentToken({
498
- issuer: issuer,
499
- code: code,
500
- email: email
501
- });
502
- case 17:
503
- token = _context9.sent;
504
- this.SetStaticToken({
505
- token: token
506
- });
507
- response = JSON.parse(this.utils.FromB64(token));
508
- return _context9.abrupt("return", includeNTPId ? {
509
- objectId: response.qid,
510
- ntpId: response.oid
511
- } : response.qid);
512
- case 23:
513
- _context9.prev = 23;
514
- _context9.t0 = _context9["catch"](14);
515
- this.Log("Failed to redeem code:", true);
516
- this.Log(_context9.t0, true);
517
- throw _context9.t0;
518
- case 28:
519
- // Site selector
520
- objectId = issuer;
521
- _context9.next = 31;
522
- return this.ContentObjectLibraryId({
523
- objectId: objectId
524
- });
525
- case 31:
526
- libraryId = _context9.sent;
527
- Hash = function Hash(code) {
528
- var chars = code.split("").map(function (code) {
529
- return code.charCodeAt(0);
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);
575
+
576
+ if (!issuer) {
577
+ issuer = UrlJoin("/otp", "ntp", tenantId, ntpId || "");
578
+ }
579
+
580
+ _context9.prev = 14;
581
+ _context9.next = 17;
582
+ return this.authClient.GenerateChannelContentToken({
583
+ issuer: issuer,
584
+ code: code,
585
+ email: email
530
586
  });
531
- return chars.reduce(function (sum, _char, i) {
532
- return chars[i + 1] ? sum * 2 + _char * chars[i + 1] * (i + 1) : sum + _char;
533
- }, 0).toString();
534
- };
535
- codeHash = Hash(code);
536
- _context9.next = 36;
537
- return this.ContentObjectMetadata({
538
- libraryId: libraryId,
539
- objectId: objectId,
540
- metadataSubtree: "public/codes/".concat(codeHash)
541
- });
542
- case 36:
543
- codeInfo = _context9.sent;
544
- if (codeInfo) {
545
- _context9.next = 40;
546
- break;
547
- }
548
- this.Log("Code redemption failed:\n\t".concat(issuer, "\n\t").concat(code));
549
- throw Error("Invalid code: " + code);
550
- case 40:
551
- ak = codeInfo.ak, sites = codeInfo.sites, info = codeInfo.info;
552
- _context9.next = 43;
553
- return wallet.AddAccountFromEncryptedPK({
554
- encryptedPrivateKey: this.utils.FromB64(ak),
555
- password: code
556
- });
557
- case 43:
558
- signer = _context9.sent;
559
- this.SetSigner({
560
- signer: signer
561
- });
562
-
563
- // Ensure wallet is initialized
564
- _context9.next = 47;
565
- return this.userProfileClient.WalletAddress();
566
- case 47:
567
- return _context9.abrupt("return", {
568
- addr: this.utils.FormatAddress(signer.address),
569
- sites: sites,
570
- info: info || {}
571
- });
572
- case 48:
573
- case "end":
574
- return _context9.stop();
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
651
+ });
652
+
653
+ case 43:
654
+ signer = _context9.sent;
655
+ this.SetSigner({
656
+ signer: signer
657
+ }); // Ensure wallet is initialized
658
+
659
+ _context9.next = 47;
660
+ return this.userProfileClient.WalletAddress();
661
+
662
+ case 47:
663
+ return _context9.abrupt("return", {
664
+ addr: this.utils.FormatAddress(signer.address),
665
+ sites: sites,
666
+ info: info || {}
667
+ });
668
+
669
+ case 48:
670
+ case "end":
671
+ return _context9.stop();
672
+ }
575
673
  }
576
674
  }, _callee9, this, [[14, 23]]);
577
675
  }));
676
+
578
677
  return function (_x9) {
579
678
  return _ref18.apply(this, arguments);
580
679
  };