@eluvio/elv-client-js 3.2.4 → 3.2.7
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 +15 -11
- package/dist/ElvClient-node-min.js +17 -13
- package/dist/ElvFrameClient-min.js +12 -8
- package/dist/ElvPermissionsClient-min.js +13 -9
- package/dist/ElvWalletClient-min.js +58 -0
- package/dist/ElvWalletClient-node-min.js +78 -0
- package/dist/src/AuthorizationClient.js +2248 -1990
- package/dist/src/ContentObjectVerification.js +164 -173
- package/dist/src/Crypto.js +376 -324
- package/dist/src/ElvClient.js +1198 -1019
- package/dist/src/ElvWallet.js +119 -95
- package/dist/src/EthClient.js +1040 -896
- package/dist/src/FrameClient.js +331 -300
- package/dist/src/HttpClient.js +153 -147
- package/dist/src/Id.js +1 -3
- package/dist/src/PermissionsClient.js +1294 -1168
- package/dist/src/RemoteSigner.js +263 -211
- package/dist/src/UserProfileClient.js +1164 -1023
- package/dist/src/Utils.js +229 -184
- package/dist/src/client/ABRPublishing.js +895 -858
- package/dist/src/client/AccessGroups.js +1102 -959
- package/dist/src/client/ContentAccess.js +3724 -3431
- package/dist/src/client/ContentManagement.js +2252 -2068
- package/dist/src/client/Contracts.js +647 -563
- package/dist/src/client/Files.js +1886 -1757
- package/dist/src/client/NFT.js +126 -112
- package/dist/src/client/NTP.js +478 -422
- package/dist/src/index.js +11 -0
- package/dist/src/marketplaceClient/ClientMethods.js +1918 -0
- package/dist/src/marketplaceClient/Configuration.js +29 -0
- package/dist/src/marketplaceClient/Utils.js +304 -0
- package/dist/src/marketplaceClient/index.js +1553 -0
- package/dist/src/walletClient/ClientMethods.js +2080 -0
- package/dist/src/walletClient/Configuration.js +29 -0
- package/dist/src/walletClient/Utils.js +304 -0
- package/dist/src/walletClient/index.js +1770 -0
- package/package.json +8 -4
- package/src/ElvClient.js +5 -2
- package/src/Utils.js +22 -4
- package/src/index.js +7 -0
- package/src/walletClient/ClientMethods.js +1111 -0
- package/src/walletClient/Configuration.js +40 -0
- package/src/walletClient/README.md +191 -0
- package/src/walletClient/Utils.js +234 -0
- package/src/walletClient/index.js +977 -0
- package/testScripts/TestMarketplaceClient.js +25 -0
package/dist/src/client/NTP.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
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
|
*
|
|
@@ -62,68 +64,74 @@ var FormatNTPInfo = function FormatNTPInfo(info) {
|
|
|
62
64
|
*/
|
|
63
65
|
|
|
64
66
|
|
|
65
|
-
exports.CreateNTPInstance = function
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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"]
|
|
85
118
|
});
|
|
86
|
-
}
|
|
87
119
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
paramsJSON = ["ntp:".concat(parseInt(maxRedemptions)), "sen:".concat(parseInt(ticketLength))];
|
|
120
|
+
case 13:
|
|
121
|
+
return _context.abrupt("return", _context.sent);
|
|
91
122
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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();
|
|
123
|
+
case 14:
|
|
124
|
+
case "end":
|
|
125
|
+
return _context.stop();
|
|
126
|
+
}
|
|
123
127
|
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
128
|
+
}, _callee, this);
|
|
129
|
+
}));
|
|
130
|
+
|
|
131
|
+
return function (_x) {
|
|
132
|
+
return _ref2.apply(this, arguments);
|
|
133
|
+
};
|
|
134
|
+
}();
|
|
127
135
|
/**
|
|
128
136
|
* Update the attributes of the specified NTP instance. Only the specified attributes will be updated ; others will be unchanged.
|
|
129
137
|
*
|
|
@@ -140,56 +148,62 @@ exports.CreateNTPInstance = function _callee(_ref) {
|
|
|
140
148
|
*/
|
|
141
149
|
|
|
142
150
|
|
|
143
|
-
exports.UpdateNTPInstance = function
|
|
144
|
-
var
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
189
199
|
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
200
|
+
}, _callee2, this);
|
|
201
|
+
}));
|
|
202
|
+
|
|
203
|
+
return function (_x2) {
|
|
204
|
+
return _ref4.apply(this, arguments);
|
|
205
|
+
};
|
|
206
|
+
}();
|
|
193
207
|
/**
|
|
194
208
|
* Suspend the specified NTP instance. All tickets issued for this instance will be considered expired.
|
|
195
209
|
*
|
|
@@ -202,30 +216,36 @@ exports.UpdateNTPInstance = function _callee2(_ref2) {
|
|
|
202
216
|
*/
|
|
203
217
|
|
|
204
218
|
|
|
205
|
-
exports.SuspendNTPInstance = function
|
|
206
|
-
var
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
+
}
|
|
225
241
|
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
242
|
+
}, _callee3, this);
|
|
243
|
+
}));
|
|
244
|
+
|
|
245
|
+
return function (_x3) {
|
|
246
|
+
return _ref6.apply(this, arguments);
|
|
247
|
+
};
|
|
248
|
+
}();
|
|
229
249
|
/**
|
|
230
250
|
* Delete the specified NTP instance. This action cannot be undone.
|
|
231
251
|
*
|
|
@@ -236,30 +256,36 @@ exports.SuspendNTPInstance = function _callee3(_ref4) {
|
|
|
236
256
|
*/
|
|
237
257
|
|
|
238
258
|
|
|
239
|
-
exports.DeleteNTPInstance = function
|
|
240
|
-
var
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
+
}
|
|
259
281
|
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
282
|
+
}, _callee4, this);
|
|
283
|
+
}));
|
|
284
|
+
|
|
285
|
+
return function (_x4) {
|
|
286
|
+
return _ref8.apply(this, arguments);
|
|
287
|
+
};
|
|
288
|
+
}();
|
|
263
289
|
/**
|
|
264
290
|
* Retrieve info for NTP instances in the specified tenant
|
|
265
291
|
*
|
|
@@ -273,42 +299,48 @@ exports.DeleteNTPInstance = function _callee4(_ref5) {
|
|
|
273
299
|
*/
|
|
274
300
|
|
|
275
301
|
|
|
276
|
-
exports.ListNTPInstances = function
|
|
277
|
-
var
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
+
}
|
|
308
336
|
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
337
|
+
}, _callee5, this);
|
|
338
|
+
}));
|
|
339
|
+
|
|
340
|
+
return function (_x5) {
|
|
341
|
+
return _ref10.apply(this, arguments);
|
|
342
|
+
};
|
|
343
|
+
}();
|
|
312
344
|
/**
|
|
313
345
|
* Retrieve a info about the specified NTP instance
|
|
314
346
|
*
|
|
@@ -321,36 +353,42 @@ exports.ListNTPInstances = function _callee5(_ref6) {
|
|
|
321
353
|
*/
|
|
322
354
|
|
|
323
355
|
|
|
324
|
-
exports.NTPInstance = function
|
|
325
|
-
var
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
+
}
|
|
350
384
|
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
385
|
+
}, _callee6, this);
|
|
386
|
+
}));
|
|
387
|
+
|
|
388
|
+
return function (_x6) {
|
|
389
|
+
return _ref12.apply(this, arguments);
|
|
390
|
+
};
|
|
391
|
+
}();
|
|
354
392
|
/**
|
|
355
393
|
* Issue a ticket from the specified NTP ID
|
|
356
394
|
*
|
|
@@ -369,44 +407,50 @@ exports.NTPInstance = function _callee6(_ref8) {
|
|
|
369
407
|
*/
|
|
370
408
|
|
|
371
409
|
|
|
372
|
-
exports.IssueNTPCode = function
|
|
373
|
-
var
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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
|
+
}
|
|
406
446
|
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
447
|
+
}, _callee7, this);
|
|
448
|
+
}));
|
|
449
|
+
|
|
450
|
+
return function (_x7) {
|
|
451
|
+
return _ref14.apply(this, arguments);
|
|
452
|
+
};
|
|
453
|
+
}();
|
|
410
454
|
/**
|
|
411
455
|
* Identical to IssueNTPCode, but the token is also signed by the current user.
|
|
412
456
|
*
|
|
@@ -425,47 +469,53 @@ exports.IssueNTPCode = function _callee7(_ref9) {
|
|
|
425
469
|
*/
|
|
426
470
|
|
|
427
471
|
|
|
428
|
-
exports.IssueSignedNTPCode = function
|
|
429
|
-
var
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
case 3:
|
|
444
|
-
result = _context8.sent;
|
|
445
|
-
|
|
446
|
-
if (!result.token) {
|
|
447
|
-
_context8.next = 10;
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
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
|
+
});
|
|
450
487
|
|
|
451
|
-
|
|
452
|
-
|
|
488
|
+
case 3:
|
|
489
|
+
result = _context8.sent;
|
|
453
490
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
491
|
+
if (!result.token) {
|
|
492
|
+
_context8.next = 10;
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
458
495
|
|
|
459
|
-
|
|
460
|
-
|
|
496
|
+
_context8.next = 7;
|
|
497
|
+
return this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(result.token)));
|
|
461
498
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
+
}
|
|
465
511
|
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
512
|
+
}, _callee8, this);
|
|
513
|
+
}));
|
|
514
|
+
|
|
515
|
+
return function (_x8) {
|
|
516
|
+
return _ref16.apply(this, arguments);
|
|
517
|
+
};
|
|
518
|
+
}();
|
|
469
519
|
/**
|
|
470
520
|
* Redeem the specified ticket/code to authorize the client. Must provide either issuer or tenantId and ntpId
|
|
471
521
|
*
|
|
@@ -482,143 +532,149 @@ exports.IssueSignedNTPCode = function _callee8(_ref10) {
|
|
|
482
532
|
*/
|
|
483
533
|
|
|
484
534
|
|
|
485
|
-
exports.RedeemCode = function
|
|
486
|
-
var
|
|
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;
|
|
487
563
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
wallet = this.GenerateWallet();
|
|
494
|
-
issuer = issuer || "";
|
|
564
|
+
case 8:
|
|
565
|
+
if (!(issuer && !issuer.replace(/^\//, "").startsWith("otp/ntp/iten"))) {
|
|
566
|
+
_context9.next = 12;
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
495
569
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
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
|
|
501
586
|
});
|
|
502
|
-
}
|
|
503
587
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
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
|
+
});
|
|
508
613
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
+
});
|
|
512
633
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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);
|
|
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
|
|
569
651
|
});
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
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();
|
|
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
|
+
}
|
|
621
673
|
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
|
|
674
|
+
}, _callee9, this, [[14, 23]]);
|
|
675
|
+
}));
|
|
676
|
+
|
|
677
|
+
return function (_x9) {
|
|
678
|
+
return _ref18.apply(this, arguments);
|
|
679
|
+
};
|
|
680
|
+
}();
|