@eluvio/elv-client-js 4.0.114 → 4.0.115
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 +67 -0
- package/dist/ElvClient-node-min.js +66 -0
- package/dist/ElvFrameClient-min.js +60 -0
- package/dist/ElvPermissionsClient-min.js +60 -0
- package/dist/ElvWalletClient-min.js +67 -0
- package/dist/ElvWalletClient-node-min.js +66 -0
- package/dist/src/AuthorizationClient.js +2169 -0
- package/dist/src/ContentObjectAudit.js +175 -0
- package/dist/src/ContentObjectVerification.js +281 -0
- package/dist/src/Crypto.js +412 -0
- package/dist/src/ElvClient.js +2044 -0
- package/dist/src/ElvWallet.js +245 -0
- package/dist/src/EthClient.js +1154 -0
- package/dist/src/FrameClient.js +485 -0
- package/dist/src/HttpClient.js +315 -0
- package/dist/src/Id.js +21 -0
- package/dist/src/LogMessage.js +25 -0
- package/dist/src/PermissionsClient.js +1544 -0
- package/dist/src/RemoteSigner.js +385 -0
- package/dist/src/UserProfileClient.js +1450 -0
- package/dist/src/Utils.js +894 -0
- package/dist/src/Validation.js +121 -0
- package/dist/src/abr_profiles/abr_profile_live_drm.js +1661 -0
- package/dist/src/abr_profiles/abr_profile_live_to_vod.js +1606 -0
- package/dist/src/client/ABRPublishing.js +1018 -0
- package/dist/src/client/AccessGroups.js +1503 -0
- package/dist/src/client/ContentAccess.js +5195 -0
- package/dist/src/client/ContentManagement.js +2680 -0
- package/dist/src/client/Contracts.js +1520 -0
- package/dist/src/client/Files.js +2181 -0
- package/dist/src/client/LiveConf.js +569 -0
- package/dist/src/client/LiveStream.js +2640 -0
- package/dist/src/client/NFT.js +162 -0
- package/dist/src/client/NTP.js +581 -0
- package/dist/src/contracts/v2/AccessIndexor.js +831 -0
- package/dist/src/contracts/v2/Accessible.js +31 -0
- package/dist/src/contracts/v2/BaseAccessControlGroup.js +1263 -0
- package/dist/src/contracts/v2/BaseAccessWallet.js +1609 -0
- package/dist/src/contracts/v2/BaseAccessWalletFactory.js +93 -0
- package/dist/src/contracts/v2/BaseContent.js +1076 -0
- package/dist/src/contracts/v2/BaseContentFactory.js +219 -0
- package/dist/src/contracts/v2/BaseContentSpace.js +1352 -0
- package/dist/src/contracts/v2/BaseContentType.js +364 -0
- package/dist/src/contracts/v2/BaseFactory.js +107 -0
- package/dist/src/contracts/v2/BaseGroupFactory.js +93 -0
- package/dist/src/contracts/v2/BaseLibrary.js +1041 -0
- package/dist/src/contracts/v2/BaseLibraryFactory.js +96 -0
- package/dist/src/contracts/v2/Certifyer.js +86 -0
- package/dist/src/contracts/v2/Container.js +540 -0
- package/dist/src/contracts/v2/Content.js +443 -0
- package/dist/src/contracts/v2/Editable.js +306 -0
- package/dist/src/contracts/v2/ExternalUserWallet.js +379 -0
- package/dist/src/contracts/v2/IFactorySpace.js +57 -0
- package/dist/src/contracts/v2/IKmsSpace.js +52 -0
- package/dist/src/contracts/v2/INodeSpace.js +18 -0
- package/dist/src/contracts/v2/IUserSpace.js +18 -0
- package/dist/src/contracts/v2/LvRecordableStream.js +1037 -0
- package/dist/src/contracts/v2/LvRecording.js +627 -0
- package/dist/src/contracts/v2/LvStreamRightsHolder.js +562 -0
- package/dist/src/contracts/v2/MetaObject.js +119 -0
- package/dist/src/contracts/v2/Node.js +167 -0
- package/dist/src/contracts/v2/NodeSpace.js +273 -0
- package/dist/src/contracts/v2/Ownable.js +87 -0
- package/dist/src/contracts/v2/PaymentService.js +627 -0
- package/dist/src/contracts/v2/Precompile.js +15 -0
- package/dist/src/contracts/v2/Transactable.js +82 -0
- package/dist/src/contracts/v2/UserSpace.js +29 -0
- package/dist/src/contracts/v2/Utils.js +18 -0
- package/dist/src/contracts/v2/Verifier.js +53 -0
- package/dist/src/contracts/v2/strings.js +4 -0
- package/dist/src/contracts/v3/AccessIndexor.js +774 -0
- package/dist/src/contracts/v3/Accessible.js +232 -0
- package/dist/src/contracts/v3/Adminable.js +107 -0
- package/dist/src/contracts/v3/AvailsDelivery.js +586 -0
- package/dist/src/contracts/v3/BaseAccessControlGroup.js +1603 -0
- package/dist/src/contracts/v3/BaseAccessWallet.js +1628 -0
- package/dist/src/contracts/v3/BaseAccessWalletFactory.js +112 -0
- package/dist/src/contracts/v3/BaseContent.js +1312 -0
- package/dist/src/contracts/v3/BaseContentFactory.js +183 -0
- package/dist/src/contracts/v3/BaseContentFactoryExt.js +175 -0
- package/dist/src/contracts/v3/BaseContentSpace.js +1515 -0
- package/dist/src/contracts/v3/BaseContentType.js +527 -0
- package/dist/src/contracts/v3/BaseFactory.js +126 -0
- package/dist/src/contracts/v3/BaseGroupFactory.js +112 -0
- package/dist/src/contracts/v3/BaseLibrary.js +1204 -0
- package/dist/src/contracts/v3/BaseLibraryFactory.js +115 -0
- package/dist/src/contracts/v3/BaseTenantSpace.js +1587 -0
- package/dist/src/contracts/v3/Certifyer.js +86 -0
- package/dist/src/contracts/v3/Container.js +739 -0
- package/dist/src/contracts/v3/Content.js +438 -0
- package/dist/src/contracts/v3/CounterObject.js +243 -0
- package/dist/src/contracts/v3/Editable.js +519 -0
- package/dist/src/contracts/v3/EncToken.js +4 -0
- package/dist/src/contracts/v3/ExternalUserWallet.js +587 -0
- package/dist/src/contracts/v3/IAdmin.js +18 -0
- package/dist/src/contracts/v3/IFactorySpace.js +57 -0
- package/dist/src/contracts/v3/IKmsSpace.js +52 -0
- package/dist/src/contracts/v3/INodeSpace.js +18 -0
- package/dist/src/contracts/v3/IUserSpace.js +32 -0
- package/dist/src/contracts/v3/LvRecordableStream.js +1032 -0
- package/dist/src/contracts/v3/LvRecording.js +650 -0
- package/dist/src/contracts/v3/LvStreamRightsHolder.js +557 -0
- package/dist/src/contracts/v3/MetaObject.js +144 -0
- package/dist/src/contracts/v3/Node.js +178 -0
- package/dist/src/contracts/v3/NodeSpace.js +284 -0
- package/dist/src/contracts/v3/Ownable.js +98 -0
- package/dist/src/contracts/v3/PaymentService.js +622 -0
- package/dist/src/contracts/v3/Precompile.js +26 -0
- package/dist/src/contracts/v3/TenantFuncsBase.js +351 -0
- package/dist/src/contracts/v3/Transactable.js +82 -0
- package/dist/src/contracts/v3/UserSpace.js +43 -0
- package/dist/src/contracts/v3/Utils.js +18 -0
- package/dist/src/contracts/v3/Verifier.js +53 -0
- package/dist/src/contracts/v3/strings.js +4 -0
- package/dist/src/contracts/v3b/BaseAccessControlGroup.js +1704 -0
- package/dist/src/events/Topics.js +1793 -0
- package/dist/src/index.js +8 -0
- package/dist/src/walletClient/ClientMethods.js +3102 -0
- package/dist/src/walletClient/Configuration.js +38 -0
- package/dist/src/walletClient/Notifications.js +168 -0
- package/dist/src/walletClient/Profile.js +332 -0
- package/dist/src/walletClient/Utils.js +281 -0
- package/dist/src/walletClient/index.js +2106 -0
- package/package.json +1 -1
- package/src/AuthorizationClient.js +24 -16
- package/src/ElvClient.js +19 -0
- package/src/client/ContentAccess.js +10 -1
- package/src/client/LiveConf.js +10 -8
- package/src/client/LiveStream.js +6 -4
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
2
|
+
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
3
|
+
/**
|
|
4
|
+
* Methods for creating and managing NTP instances and tickets
|
|
5
|
+
*
|
|
6
|
+
* @module ElvClient/NTP
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var UrlJoin = require("url-join");
|
|
10
|
+
var Ethers = require("ethers");
|
|
11
|
+
var _require = require("../Validation"),
|
|
12
|
+
ValidateAddress = _require.ValidateAddress,
|
|
13
|
+
ValidateDate = _require.ValidateDate,
|
|
14
|
+
ValidateObject = _require.ValidateObject,
|
|
15
|
+
ValidatePresence = _require.ValidatePresence;
|
|
16
|
+
var FormatNTPInfo = function FormatNTPInfo(info) {
|
|
17
|
+
var params = info.pm || {};
|
|
18
|
+
var response = {
|
|
19
|
+
ntpId: info.id,
|
|
20
|
+
ntpClass: "Class ".concat(info.de),
|
|
21
|
+
tenantId: info.ti,
|
|
22
|
+
kmsId: info.ki,
|
|
23
|
+
objectId: params.qid,
|
|
24
|
+
updatedAt: parseInt(info.ts),
|
|
25
|
+
startTime: parseInt(params.vat),
|
|
26
|
+
endTime: parseInt(params.exp),
|
|
27
|
+
ticketLength: params.sen,
|
|
28
|
+
maxRedemptions: params.ntp,
|
|
29
|
+
maxTickets: info.mx
|
|
30
|
+
};
|
|
31
|
+
if (typeof info.cnt !== "undefined") {
|
|
32
|
+
response.issuedTickets = info.cnt;
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Issue an n-time-password (NTP) instance. This instance contains a specification for the tickets (AKA codes) to be issued, including
|
|
39
|
+
* the target(s) to be authorized, how many tickets can be issued, and when and how many times tickets can be redeemed.
|
|
40
|
+
*
|
|
41
|
+
* Note: For date types (startTime/endTime), you may specify the date in any format parsable by JavaScript's `new Date()` constructor,
|
|
42
|
+
* including Unix epoch timestamps and ISO strings
|
|
43
|
+
*
|
|
44
|
+
* @see <a href="#IssueNTPCode">IssueNTPCode</a>
|
|
45
|
+
*
|
|
46
|
+
* @methodGroup NTP Instances
|
|
47
|
+
* @namedParams
|
|
48
|
+
* @param {string} tenantId - The ID of the tenant in which to create the NTP instance
|
|
49
|
+
* @param {string} objectId - ID of the object for the tickets to be authorized to
|
|
50
|
+
* @param {Array<string>=} groupAddresses - List of group addresses for the tickets to inherit permissions from
|
|
51
|
+
* @param {number=} ntpClass=4 - Class of NTP instance to create
|
|
52
|
+
* @param {number=} maxTickets=0 - The maximum number of tickets that may be issued for this instance (if 0, no limit)
|
|
53
|
+
* @param {number=} maxRedemptions=100 - The maximum number of times each ticket may be redeemed
|
|
54
|
+
* @param {string|number=} startTime - The time when issued tickets can be redeemed
|
|
55
|
+
* @param {string|number=} endTime - The time when issued tickets can no longer be redeemed
|
|
56
|
+
* @param {number=} ticketLength=6 - The number of characters in each ticket code
|
|
57
|
+
*
|
|
58
|
+
* @return {Promise<string>} - The ID of the NTP instance. This ID can be used when issuing tickets (See IssueNTPCode)
|
|
59
|
+
*/
|
|
60
|
+
exports.CreateNTPInstance = /*#__PURE__*/function () {
|
|
61
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
62
|
+
var _this = this;
|
|
63
|
+
var tenantId, objectId, groupAddresses, _ref$ntpClass, ntpClass, _ref$maxTickets, maxTickets, _ref$maxRedemptions, maxRedemptions, startTime, endTime, _ref$ticketLength, ticketLength, paramsJSON, groupIds;
|
|
64
|
+
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));
|
|
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();
|
|
107
|
+
}
|
|
108
|
+
}, _callee, this);
|
|
109
|
+
}));
|
|
110
|
+
return function (_x) {
|
|
111
|
+
return _ref2.apply(this, arguments);
|
|
112
|
+
};
|
|
113
|
+
}();
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Update the attributes of the specified NTP instance. Only the specified attributes will be updated ; others will be unchanged.
|
|
117
|
+
*
|
|
118
|
+
* @methodGroup NTP Instances
|
|
119
|
+
* @namedParams
|
|
120
|
+
* @param {string} tenantId - The ID of the tenant in which this NTP instance was created
|
|
121
|
+
* @param {string} ntpId - The ID of the NTP instance to update
|
|
122
|
+
* @param {number=} maxTickets=0 - The maximum number of tickets that may be issued for this instance (if 0, no limit)
|
|
123
|
+
* @param {number=} maxRedemptions=100 - The maximum number of times each ticket may be redeemed
|
|
124
|
+
* @param {string|number=} startTime - The time when issued tickets can be redeemed
|
|
125
|
+
* @param {string|number=} endTime - The time when issued tickets can no longer be redeemed
|
|
126
|
+
*
|
|
127
|
+
* @return {Object} - Info about the NTP Instance
|
|
128
|
+
*/
|
|
129
|
+
exports.UpdateNTPInstance = /*#__PURE__*/function () {
|
|
130
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
|
|
131
|
+
var tenantId, ntpId, _ref3$maxTickets, maxTickets, _ref3$maxRedemptions, maxRedemptions, startTime, endTime, paramsJSON, _yield$this$authClien, Ret;
|
|
132
|
+
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();
|
|
167
|
+
}
|
|
168
|
+
}, _callee2, this);
|
|
169
|
+
}));
|
|
170
|
+
return function (_x2) {
|
|
171
|
+
return _ref4.apply(this, arguments);
|
|
172
|
+
};
|
|
173
|
+
}();
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Suspend the specified NTP instance. All tickets issued for this instance will be considered expired.
|
|
177
|
+
*
|
|
178
|
+
* To reactivate the NTP instance, reset the expiration date using `UpdateNTPInstance`
|
|
179
|
+
*
|
|
180
|
+
* @methodGroup NTP Instances
|
|
181
|
+
* @namedParams
|
|
182
|
+
* @param {string} tenantId - The ID of the tenant in which this NTP instance was created
|
|
183
|
+
* @param {string} ntpId - The ID of the NTP instance
|
|
184
|
+
*/
|
|
185
|
+
exports.SuspendNTPInstance = /*#__PURE__*/function () {
|
|
186
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
|
|
187
|
+
var tenantId, ntpId;
|
|
188
|
+
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();
|
|
204
|
+
}
|
|
205
|
+
}, _callee3, this);
|
|
206
|
+
}));
|
|
207
|
+
return function (_x3) {
|
|
208
|
+
return _ref6.apply(this, arguments);
|
|
209
|
+
};
|
|
210
|
+
}();
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Delete the specified NTP instance. This action cannot be undone.
|
|
214
|
+
*
|
|
215
|
+
* @methodGroup NTP Instances
|
|
216
|
+
* @namedParams
|
|
217
|
+
* @param {string} tenantId - The ID of the tenant in which this NTP instance was created
|
|
218
|
+
* @param {string} ntpId - The ID of the NTP instance
|
|
219
|
+
*/
|
|
220
|
+
exports.DeleteNTPInstance = /*#__PURE__*/function () {
|
|
221
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
|
|
222
|
+
var tenantId, ntpId;
|
|
223
|
+
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();
|
|
239
|
+
}
|
|
240
|
+
}, _callee4, this);
|
|
241
|
+
}));
|
|
242
|
+
return function (_x4) {
|
|
243
|
+
return _ref8.apply(this, arguments);
|
|
244
|
+
};
|
|
245
|
+
}();
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Retrieve info for NTP instances in the specified tenant
|
|
249
|
+
*
|
|
250
|
+
* @methodGroup NTP Instances
|
|
251
|
+
* @namedParams
|
|
252
|
+
* @param {string} tenantId - The ID of the tenant
|
|
253
|
+
* @param {number=} count=10 - Maximum number of results to return
|
|
254
|
+
* @param {number=} offset=0 - Offset from which to return results
|
|
255
|
+
*
|
|
256
|
+
* @return {Object} - List of NTP instances along with pagination information
|
|
257
|
+
*/
|
|
258
|
+
exports.ListNTPInstances = /*#__PURE__*/function () {
|
|
259
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref9) {
|
|
260
|
+
var tenantId, _ref9$count, count, _ref9$offset, offset, _yield$this$authClien2, Defs, Total;
|
|
261
|
+
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();
|
|
287
|
+
}
|
|
288
|
+
}, _callee5, this);
|
|
289
|
+
}));
|
|
290
|
+
return function (_x5) {
|
|
291
|
+
return _ref10.apply(this, arguments);
|
|
292
|
+
};
|
|
293
|
+
}();
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Retrieve a info about the specified NTP instance
|
|
297
|
+
*
|
|
298
|
+
* @methodGroup NTP Instances
|
|
299
|
+
* @namedParams
|
|
300
|
+
* @param {string} tenantId - The ID of the tenant
|
|
301
|
+
* @param {string} ntpId - The ID of the NTP instance
|
|
302
|
+
*
|
|
303
|
+
* @return {Object} - Info about the NTP instance
|
|
304
|
+
*/
|
|
305
|
+
exports.NTPInstance = /*#__PURE__*/function () {
|
|
306
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref11) {
|
|
307
|
+
var tenantId, ntpId;
|
|
308
|
+
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();
|
|
329
|
+
}
|
|
330
|
+
}, _callee6, this);
|
|
331
|
+
}));
|
|
332
|
+
return function (_x6) {
|
|
333
|
+
return _ref12.apply(this, arguments);
|
|
334
|
+
};
|
|
335
|
+
}();
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Issue a ticket from the specified NTP ID
|
|
339
|
+
*
|
|
340
|
+
* @see <a href="#CreateNTPInstance">CreateNTPInstance</a>
|
|
341
|
+
*
|
|
342
|
+
* @methodGroup Tickets
|
|
343
|
+
* @namedParams
|
|
344
|
+
* @param {string} tenantId - The ID of the tenant in the NTP instance was created
|
|
345
|
+
* @param {string} ntpId - The ID of the NTP instance from which to issue a ticket
|
|
346
|
+
* @param {string=} email - The email address associated with this ticket. If specified, the email address will have to
|
|
347
|
+
* be provided along with the ticket code in order to redeem the ticket.
|
|
348
|
+
* @param {number=} maxRedemptions - Maximum number of times this ticket may be redeemed. If less than the max redemptions
|
|
349
|
+
* of the NTP instance, the lower limit will be used.
|
|
350
|
+
*
|
|
351
|
+
* @return {Promise<Object>} - The generated ticket code and additional information about the ticket.
|
|
352
|
+
*/
|
|
353
|
+
exports.IssueNTPCode = /*#__PURE__*/function () {
|
|
354
|
+
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref13) {
|
|
355
|
+
var tenantId, ntpId, email, maxRedemptions, options, params, paramTypes;
|
|
356
|
+
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();
|
|
382
|
+
}
|
|
383
|
+
}, _callee7, this);
|
|
384
|
+
}));
|
|
385
|
+
return function (_x7) {
|
|
386
|
+
return _ref14.apply(this, arguments);
|
|
387
|
+
};
|
|
388
|
+
}();
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Identical to IssueNTPCode, but the token is also signed by the current user.
|
|
392
|
+
*
|
|
393
|
+
* @see <a href="#IssueNTPCode">IssueNTPCode</a>
|
|
394
|
+
*
|
|
395
|
+
* @methodGroup Tickets
|
|
396
|
+
* @namedParams
|
|
397
|
+
* @param {string} tenantId - The ID of the tenant in the NTP instance was created
|
|
398
|
+
* @param {string} ntpId - The ID of the NTP instance from which to issue a ticket
|
|
399
|
+
* @param {string=} email - The email address associated with this ticket. If specified, the email address will have to
|
|
400
|
+
* be provided along with the ticket code in order to redeem the ticket.
|
|
401
|
+
* @param {number=} maxRedemptions - Maximum number of times this ticket may be redeemed. If less than the max redemptions
|
|
402
|
+
* of the NTP instance, the lower limit will be used.
|
|
403
|
+
*
|
|
404
|
+
* @return {Promise<Object>} - The generated signed ticket code and additional information about the ticket.
|
|
405
|
+
*/
|
|
406
|
+
exports.IssueSignedNTPCode = /*#__PURE__*/function () {
|
|
407
|
+
var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref15) {
|
|
408
|
+
var tenantId, ntpId, email, maxRedemptions, result, signature, multiSig;
|
|
409
|
+
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();
|
|
437
|
+
}
|
|
438
|
+
}, _callee8, this);
|
|
439
|
+
}));
|
|
440
|
+
return function (_x8) {
|
|
441
|
+
return _ref16.apply(this, arguments);
|
|
442
|
+
};
|
|
443
|
+
}();
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Redeem the specified ticket/code to authorize the client. Must provide either issuer or tenantId and ntpId
|
|
447
|
+
*
|
|
448
|
+
* @methodGroup Tickets
|
|
449
|
+
* @namedParams
|
|
450
|
+
* @param {string=} issuer - Issuer to authorize against
|
|
451
|
+
* @param {string=} tenantId - The ID of the tenant from which the ticket was issued
|
|
452
|
+
* @param {string=} ntpId - The ID of the NTP instance from which the ticket was issued
|
|
453
|
+
* @param {string} code - Access code
|
|
454
|
+
* @param {string=} email - Email address associated with the code
|
|
455
|
+
* @param {boolean=} includeNTPId - If specified, the response will include both the target object ID as well as the NTP ID associated with the ticket
|
|
456
|
+
*
|
|
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
|
|
458
|
+
*/
|
|
459
|
+
exports.RedeemCode = /*#__PURE__*/function () {
|
|
460
|
+
var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref17) {
|
|
461
|
+
var issuer, tenantId, ntpId, code, email, _ref17$includeNTPId, includeNTPId, wallet, token, response, objectId, libraryId, Hash, codeHash, codeInfo, ak, sites, info, signer;
|
|
462
|
+
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;
|
|
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();
|
|
575
|
+
}
|
|
576
|
+
}, _callee9, this, [[14, 23]]);
|
|
577
|
+
}));
|
|
578
|
+
return function (_x9) {
|
|
579
|
+
return _ref18.apply(this, arguments);
|
|
580
|
+
};
|
|
581
|
+
}();
|