@eluvio/elv-client-js 4.0.4 → 4.0.6
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.
- package/dist/ElvClient-min.js +12 -11
- package/dist/ElvClient-node-min.js +12 -17
- package/dist/ElvFrameClient-min.js +12 -11
- package/dist/ElvPermissionsClient-min.js +10 -9
- package/dist/ElvWalletClient-min.js +11 -10
- package/dist/ElvWalletClient-node-min.js +12 -17
- package/dist/src/AuthorizationClient.js +1556 -2077
- package/dist/src/ContentObjectVerification.js +134 -185
- package/dist/src/Crypto.js +225 -322
- package/dist/src/ElvClient.js +823 -1117
- package/dist/src/ElvWallet.js +64 -106
- package/dist/src/EthClient.js +719 -974
- package/dist/src/FrameClient.js +222 -318
- package/dist/src/HttpClient.js +112 -154
- package/dist/src/Id.js +1 -6
- package/dist/src/LogMessage.js +4 -8
- package/dist/src/PermissionsClient.js +973 -1271
- package/dist/src/RemoteSigner.js +161 -232
- package/dist/src/UserProfileClient.js +781 -1038
- package/dist/src/Utils.js +160 -302
- package/dist/src/Validation.js +2 -17
- package/dist/src/client/ABRPublishing.js +772 -942
- package/dist/src/client/AccessGroups.js +849 -1095
- package/dist/src/client/ContentAccess.js +3263 -4132
- package/dist/src/client/ContentManagement.js +1811 -2283
- package/dist/src/client/Contracts.js +468 -614
- package/dist/src/client/Files.js +1505 -1845
- package/dist/src/client/NFT.js +94 -116
- package/dist/src/client/NTP.js +326 -425
- package/dist/src/index.js +2 -5
- package/dist/src/walletClient/ClientMethods.js +1412 -1551
- package/dist/src/walletClient/Configuration.js +4 -2
- package/dist/src/walletClient/Notifications.js +98 -127
- package/dist/src/walletClient/Profile.js +184 -246
- package/dist/src/walletClient/Utils.js +76 -122
- package/dist/src/walletClient/index.js +1169 -1493
- package/package.json +3 -2
- package/src/Crypto.js +1 -1
- package/src/ElvClient.js +1 -3
- package/src/Utils.js +1 -1
- package/src/walletClient/ClientMethods.js +133 -11
- package/src/walletClient/index.js +1 -0
- package/testScripts/Test.js +0 -1
- package/utilities/NFTIngest.js +527 -0
- package/utilities/lib/concerns/LocalFile.js +2 -1
package/dist/src/client/NTP.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
2
|
-
|
|
3
2
|
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Methods for creating and managing NTP instances and tickets
|
|
7
5
|
*
|
|
8
6
|
* @module ElvClient/NTP
|
|
9
7
|
*/
|
|
10
|
-
var UrlJoin = require("url-join");
|
|
11
8
|
|
|
9
|
+
var UrlJoin = require("url-join");
|
|
12
10
|
var Ethers = require("ethers");
|
|
13
|
-
|
|
14
11
|
var _require = require("../Validation"),
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
ValidateAddress = _require.ValidateAddress,
|
|
13
|
+
ValidateDate = _require.ValidateDate,
|
|
14
|
+
ValidateObject = _require.ValidateObject,
|
|
15
|
+
ValidatePresence = _require.ValidatePresence;
|
|
20
16
|
var FormatNTPInfo = function FormatNTPInfo(info) {
|
|
21
17
|
var params = info.pm || {};
|
|
22
18
|
var response = {
|
|
@@ -32,13 +28,12 @@ var FormatNTPInfo = function FormatNTPInfo(info) {
|
|
|
32
28
|
maxRedemptions: params.ntp,
|
|
33
29
|
maxTickets: info.mx
|
|
34
30
|
};
|
|
35
|
-
|
|
36
31
|
if (typeof info.cnt !== "undefined") {
|
|
37
32
|
response.issuedTickets = info.cnt;
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
return response;
|
|
41
35
|
};
|
|
36
|
+
|
|
42
37
|
/**
|
|
43
38
|
* Issue an n-time-password (NTP) instance. This instance contains a specification for the tickets (AKA codes) to be issued, including
|
|
44
39
|
* the target(s) to be authorized, how many tickets can be issued, and when and how many times tickets can be redeemed.
|
|
@@ -62,76 +57,61 @@ var FormatNTPInfo = function FormatNTPInfo(info) {
|
|
|
62
57
|
*
|
|
63
58
|
* @return {Promise<string>} - The ID of the NTP instance. This ID can be used when issuing tickets (See IssueNTPCode)
|
|
64
59
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
60
|
exports.CreateNTPInstance = /*#__PURE__*/function () {
|
|
68
61
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
69
62
|
var _this = this;
|
|
70
|
-
|
|
71
63
|
var tenantId, objectId, groupAddresses, _ref$ntpClass, ntpClass, _ref$maxTickets, maxTickets, _ref$maxRedemptions, maxRedemptions, startTime, endTime, _ref$ticketLength, ticketLength, paramsJSON, groupIds;
|
|
72
|
-
|
|
73
64
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
74
|
-
while (1) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
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);
|
|
118
76
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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));
|
|
86
|
+
});
|
|
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();
|
|
127
107
|
}
|
|
128
108
|
}, _callee, this);
|
|
129
109
|
}));
|
|
130
|
-
|
|
131
110
|
return function (_x) {
|
|
132
111
|
return _ref2.apply(this, arguments);
|
|
133
112
|
};
|
|
134
113
|
}();
|
|
114
|
+
|
|
135
115
|
/**
|
|
136
116
|
* Update the attributes of the specified NTP instance. Only the specified attributes will be updated ; others will be unchanged.
|
|
137
117
|
*
|
|
@@ -146,64 +126,52 @@ exports.CreateNTPInstance = /*#__PURE__*/function () {
|
|
|
146
126
|
*
|
|
147
127
|
* @return {Object} - Info about the NTP Instance
|
|
148
128
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
129
|
exports.UpdateNTPInstance = /*#__PURE__*/function () {
|
|
152
130
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
|
|
153
131
|
var tenantId, ntpId, _ref3$maxTickets, maxTickets, _ref3$maxRedemptions, maxRedemptions, startTime, endTime, paramsJSON, _yield$this$authClien, Ret;
|
|
154
|
-
|
|
155
132
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
156
|
-
while (1) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
}
|
|
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();
|
|
199
167
|
}
|
|
200
168
|
}, _callee2, this);
|
|
201
169
|
}));
|
|
202
|
-
|
|
203
170
|
return function (_x2) {
|
|
204
171
|
return _ref4.apply(this, arguments);
|
|
205
172
|
};
|
|
206
173
|
}();
|
|
174
|
+
|
|
207
175
|
/**
|
|
208
176
|
* Suspend the specified NTP instance. All tickets issued for this instance will be considered expired.
|
|
209
177
|
*
|
|
@@ -214,38 +182,33 @@ exports.UpdateNTPInstance = /*#__PURE__*/function () {
|
|
|
214
182
|
* @param {string} tenantId - The ID of the tenant in which this NTP instance was created
|
|
215
183
|
* @param {string} ntpId - The ID of the NTP instance
|
|
216
184
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
185
|
exports.SuspendNTPInstance = /*#__PURE__*/function () {
|
|
220
186
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
|
|
221
187
|
var tenantId, ntpId;
|
|
222
188
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
223
|
-
while (1) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
case "end":
|
|
239
|
-
return _context3.stop();
|
|
240
|
-
}
|
|
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();
|
|
241
204
|
}
|
|
242
205
|
}, _callee3, this);
|
|
243
206
|
}));
|
|
244
|
-
|
|
245
207
|
return function (_x3) {
|
|
246
208
|
return _ref6.apply(this, arguments);
|
|
247
209
|
};
|
|
248
210
|
}();
|
|
211
|
+
|
|
249
212
|
/**
|
|
250
213
|
* Delete the specified NTP instance. This action cannot be undone.
|
|
251
214
|
*
|
|
@@ -254,38 +217,33 @@ exports.SuspendNTPInstance = /*#__PURE__*/function () {
|
|
|
254
217
|
* @param {string} tenantId - The ID of the tenant in which this NTP instance was created
|
|
255
218
|
* @param {string} ntpId - The ID of the NTP instance
|
|
256
219
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
259
220
|
exports.DeleteNTPInstance = /*#__PURE__*/function () {
|
|
260
221
|
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
|
|
261
222
|
var tenantId, ntpId;
|
|
262
223
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
263
|
-
while (1) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
case "end":
|
|
279
|
-
return _context4.stop();
|
|
280
|
-
}
|
|
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();
|
|
281
239
|
}
|
|
282
240
|
}, _callee4, this);
|
|
283
241
|
}));
|
|
284
|
-
|
|
285
242
|
return function (_x4) {
|
|
286
243
|
return _ref8.apply(this, arguments);
|
|
287
244
|
};
|
|
288
245
|
}();
|
|
246
|
+
|
|
289
247
|
/**
|
|
290
248
|
* Retrieve info for NTP instances in the specified tenant
|
|
291
249
|
*
|
|
@@ -297,50 +255,43 @@ exports.DeleteNTPInstance = /*#__PURE__*/function () {
|
|
|
297
255
|
*
|
|
298
256
|
* @return {Object} - List of NTP instances along with pagination information
|
|
299
257
|
*/
|
|
300
|
-
|
|
301
|
-
|
|
302
258
|
exports.ListNTPInstances = /*#__PURE__*/function () {
|
|
303
259
|
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref9) {
|
|
304
260
|
var tenantId, _ref9$count, count, _ref9$offset, offset, _yield$this$authClien2, Defs, Total;
|
|
305
|
-
|
|
306
261
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
307
|
-
while (1) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
case 8:
|
|
333
|
-
case "end":
|
|
334
|
-
return _context5.stop();
|
|
335
|
-
}
|
|
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();
|
|
336
287
|
}
|
|
337
288
|
}, _callee5, this);
|
|
338
289
|
}));
|
|
339
|
-
|
|
340
290
|
return function (_x5) {
|
|
341
291
|
return _ref10.apply(this, arguments);
|
|
342
292
|
};
|
|
343
293
|
}();
|
|
294
|
+
|
|
344
295
|
/**
|
|
345
296
|
* Retrieve a info about the specified NTP instance
|
|
346
297
|
*
|
|
@@ -351,44 +302,38 @@ exports.ListNTPInstances = /*#__PURE__*/function () {
|
|
|
351
302
|
*
|
|
352
303
|
* @return {Object} - Info about the NTP instance
|
|
353
304
|
*/
|
|
354
|
-
|
|
355
|
-
|
|
356
305
|
exports.NTPInstance = /*#__PURE__*/function () {
|
|
357
306
|
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref11) {
|
|
358
307
|
var tenantId, ntpId;
|
|
359
308
|
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
360
|
-
while (1) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
case 8:
|
|
381
|
-
case "end":
|
|
382
|
-
return _context6.stop();
|
|
383
|
-
}
|
|
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();
|
|
384
329
|
}
|
|
385
330
|
}, _callee6, this);
|
|
386
331
|
}));
|
|
387
|
-
|
|
388
332
|
return function (_x6) {
|
|
389
333
|
return _ref12.apply(this, arguments);
|
|
390
334
|
};
|
|
391
335
|
}();
|
|
336
|
+
|
|
392
337
|
/**
|
|
393
338
|
* Issue a ticket from the specified NTP ID
|
|
394
339
|
*
|
|
@@ -405,52 +350,43 @@ exports.NTPInstance = /*#__PURE__*/function () {
|
|
|
405
350
|
*
|
|
406
351
|
* @return {Promise<Object>} - The generated ticket code and additional information about the ticket.
|
|
407
352
|
*/
|
|
408
|
-
|
|
409
|
-
|
|
410
353
|
exports.IssueNTPCode = /*#__PURE__*/function () {
|
|
411
354
|
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref13) {
|
|
412
355
|
var tenantId, ntpId, email, maxRedemptions, options, params, paramTypes;
|
|
413
356
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
414
|
-
while (1) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
case 10:
|
|
440
|
-
return _context7.abrupt("return", _context7.sent);
|
|
441
|
-
|
|
442
|
-
case 11:
|
|
443
|
-
case "end":
|
|
444
|
-
return _context7.stop();
|
|
445
|
-
}
|
|
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();
|
|
446
382
|
}
|
|
447
383
|
}, _callee7, this);
|
|
448
384
|
}));
|
|
449
|
-
|
|
450
385
|
return function (_x7) {
|
|
451
386
|
return _ref14.apply(this, arguments);
|
|
452
387
|
};
|
|
453
388
|
}();
|
|
389
|
+
|
|
454
390
|
/**
|
|
455
391
|
* Identical to IssueNTPCode, but the token is also signed by the current user.
|
|
456
392
|
*
|
|
@@ -467,55 +403,45 @@ exports.IssueNTPCode = /*#__PURE__*/function () {
|
|
|
467
403
|
*
|
|
468
404
|
* @return {Promise<Object>} - The generated signed ticket code and additional information about the ticket.
|
|
469
405
|
*/
|
|
470
|
-
|
|
471
|
-
|
|
472
406
|
exports.IssueSignedNTPCode = /*#__PURE__*/function () {
|
|
473
407
|
var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref15) {
|
|
474
408
|
var tenantId, ntpId, email, maxRedemptions, result, signature, multiSig;
|
|
475
409
|
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
476
|
-
while (1) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
case 10:
|
|
505
|
-
return _context8.abrupt("return", result);
|
|
506
|
-
|
|
507
|
-
case 11:
|
|
508
|
-
case "end":
|
|
509
|
-
return _context8.stop();
|
|
510
|
-
}
|
|
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();
|
|
511
437
|
}
|
|
512
438
|
}, _callee8, this);
|
|
513
439
|
}));
|
|
514
|
-
|
|
515
440
|
return function (_x8) {
|
|
516
441
|
return _ref16.apply(this, arguments);
|
|
517
442
|
};
|
|
518
443
|
}();
|
|
444
|
+
|
|
519
445
|
/**
|
|
520
446
|
* Redeem the specified ticket/code to authorize the client. Must provide either issuer or tenantId and ntpId
|
|
521
447
|
*
|
|
@@ -530,150 +456,125 @@ exports.IssueSignedNTPCode = /*#__PURE__*/function () {
|
|
|
530
456
|
*
|
|
531
457
|
* @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
|
|
532
458
|
*/
|
|
533
|
-
|
|
534
|
-
|
|
535
459
|
exports.RedeemCode = /*#__PURE__*/function () {
|
|
536
460
|
var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref17) {
|
|
537
461
|
var issuer, tenantId, ntpId, code, email, _ref17$includeNTPId, includeNTPId, wallet, token, response, objectId, libraryId, Hash, codeHash, codeInfo, ak, sites, info, signer;
|
|
538
|
-
|
|
539
462
|
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
540
|
-
while (1) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
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);
|
|
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
|
|
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
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
case 43:
|
|
654
|
-
signer = _context9.sent;
|
|
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) {
|
|
655
469
|
this.SetSigner({
|
|
656
|
-
signer:
|
|
657
|
-
|
|
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 || {}
|
|
470
|
+
signer: wallet.AddAccountFromMnemonic({
|
|
471
|
+
mnemonic: wallet.GenerateMnemonic()
|
|
472
|
+
})
|
|
667
473
|
});
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
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;
|
|
485
|
+
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);
|
|
530
|
+
});
|
|
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();
|
|
673
575
|
}
|
|
674
576
|
}, _callee9, this, [[14, 23]]);
|
|
675
577
|
}));
|
|
676
|
-
|
|
677
578
|
return function (_x9) {
|
|
678
579
|
return _ref18.apply(this, arguments);
|
|
679
580
|
};
|