@eluvio/elv-client-js 4.0.8 → 4.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/ElvClient-min.js +10 -11
  2. package/dist/ElvClient-node-min.js +10 -11
  3. package/dist/ElvFrameClient-min.js +10 -11
  4. package/dist/ElvPermissionsClient-min.js +9 -10
  5. package/dist/ElvWalletClient-min.js +10 -11
  6. package/dist/ElvWalletClient-node-min.js +9 -10
  7. package/dist/src/AuthorizationClient.js +2069 -1548
  8. package/dist/src/ContentObjectVerification.js +185 -134
  9. package/dist/src/Crypto.js +323 -226
  10. package/dist/src/ElvClient.js +1118 -824
  11. package/dist/src/ElvWallet.js +106 -64
  12. package/dist/src/EthClient.js +974 -719
  13. package/dist/src/FrameClient.js +318 -222
  14. package/dist/src/HttpClient.js +154 -112
  15. package/dist/src/Id.js +6 -1
  16. package/dist/src/LogMessage.js +8 -4
  17. package/dist/src/PermissionsClient.js +1271 -973
  18. package/dist/src/RemoteSigner.js +232 -161
  19. package/dist/src/UserProfileClient.js +1038 -781
  20. package/dist/src/Utils.js +302 -160
  21. package/dist/src/Validation.js +17 -2
  22. package/dist/src/client/ABRPublishing.js +942 -772
  23. package/dist/src/client/AccessGroups.js +1095 -849
  24. package/dist/src/client/ContentAccess.js +4198 -3272
  25. package/dist/src/client/ContentManagement.js +2284 -1812
  26. package/dist/src/client/Contracts.js +614 -468
  27. package/dist/src/client/Files.js +1831 -1491
  28. package/dist/src/client/NFT.js +116 -94
  29. package/dist/src/client/NTP.js +425 -326
  30. package/dist/src/index.js +5 -2
  31. package/dist/src/walletClient/ClientMethods.js +1766 -1350
  32. package/dist/src/walletClient/Configuration.js +2 -4
  33. package/dist/src/walletClient/Notifications.js +127 -98
  34. package/dist/src/walletClient/Profile.js +246 -184
  35. package/dist/src/walletClient/Utils.js +124 -78
  36. package/dist/src/walletClient/index.js +1498 -1169
  37. package/package.json +1 -1
  38. package/src/client/ContentAccess.js +27 -10
  39. package/src/walletClient/ClientMethods.js +18 -10
  40. package/src/walletClient/index.js +7 -2
@@ -1,18 +1,29 @@
1
1
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
+
2
3
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
+
3
5
  var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
6
+
4
7
  var _createClass = require("@babel/runtime/helpers/createClass");
8
+
5
9
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
10
+
6
11
  var _v, _v2;
12
+
7
13
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14
+
8
15
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
+
9
17
  var HttpClient = require("./HttpClient");
18
+
10
19
  var Ethers = require("ethers");
20
+
11
21
  var Utils = require("./Utils");
22
+
12
23
  var UrlJoin = require("url-join");
13
- var _require = require("./LogMessage"),
14
- LogMessage = _require.LogMessage;
15
24
 
25
+ var _require = require("./LogMessage"),
26
+ LogMessage = _require.LogMessage;
16
27
  /*
17
28
  // -- Contract javascript files built using build/BuildContracts.js
18
29
  const SpaceContract = require("./contracts/BaseContentSpace");
@@ -25,6 +36,7 @@ const AccessibleContract = require("./contracts/Accessible");
25
36
  const EditableContract = require("./contracts/Editable");
26
37
  */
27
38
 
39
+
28
40
  var ACCESS_TYPES = {
29
41
  SPACE: "space",
30
42
  LIBRARY: "library",
@@ -41,19 +53,22 @@ var CONTRACTS = {
41
53
  v2: (_v = {}, _defineProperty(_v, ACCESS_TYPES.SPACE, require("./contracts/v2/BaseContentSpace")), _defineProperty(_v, ACCESS_TYPES.LIBRARY, require("./contracts/v2/BaseLibrary")), _defineProperty(_v, ACCESS_TYPES.TYPE, require("./contracts/v2/BaseContentType")), _defineProperty(_v, ACCESS_TYPES.OBJECT, require("./contracts/v2/BaseContent")), _defineProperty(_v, ACCESS_TYPES.WALLET, require("./contracts/v2/BaseAccessWallet")), _defineProperty(_v, ACCESS_TYPES.GROUP, require("./contracts/v2/BaseAccessControlGroup")), _defineProperty(_v, ACCESS_TYPES.ACCESSIBLE, require("./contracts/v2/Accessible")), _defineProperty(_v, ACCESS_TYPES.EDITABLE, require("./contracts/v2/Editable")), _v),
42
54
  v3: (_v2 = {}, _defineProperty(_v2, ACCESS_TYPES.SPACE, require("./contracts/v3/BaseContentSpace")), _defineProperty(_v2, ACCESS_TYPES.LIBRARY, require("./contracts/v3/BaseLibrary")), _defineProperty(_v2, ACCESS_TYPES.TYPE, require("./contracts/v3/BaseContentType")), _defineProperty(_v2, ACCESS_TYPES.OBJECT, require("./contracts/v3/BaseContent")), _defineProperty(_v2, ACCESS_TYPES.WALLET, require("./contracts/v3/BaseAccessWallet")), _defineProperty(_v2, ACCESS_TYPES.GROUP, require("./contracts/v3/BaseAccessControlGroup")), _defineProperty(_v2, ACCESS_TYPES.ACCESSIBLE, require("./contracts/v3/Accessible")), _defineProperty(_v2, ACCESS_TYPES.EDITABLE, require("./contracts/v3/Editable")), _defineProperty(_v2, ACCESS_TYPES.TENANT, require("./contracts/v3/BaseTenantSpace")), _v2)
43
55
  };
56
+
44
57
  var AuthorizationClient = /*#__PURE__*/function () {
45
58
  "use strict";
46
59
 
47
60
  function AuthorizationClient(_ref) {
48
61
  var client = _ref.client,
49
- contentSpaceId = _ref.contentSpaceId,
50
- _ref$debug = _ref.debug,
51
- debug = _ref$debug === void 0 ? false : _ref$debug,
52
- _ref$noCache = _ref.noCache,
53
- noCache = _ref$noCache === void 0 ? false : _ref$noCache,
54
- _ref$noAuth = _ref.noAuth,
55
- noAuth = _ref$noAuth === void 0 ? false : _ref$noAuth;
62
+ contentSpaceId = _ref.contentSpaceId,
63
+ _ref$debug = _ref.debug,
64
+ debug = _ref$debug === void 0 ? false : _ref$debug,
65
+ _ref$noCache = _ref.noCache,
66
+ noCache = _ref$noCache === void 0 ? false : _ref$noCache,
67
+ _ref$noAuth = _ref.noAuth,
68
+ noAuth = _ref$noAuth === void 0 ? false : _ref$noAuth;
69
+
56
70
  _classCallCheck(this, AuthorizationClient);
71
+
57
72
  this.ACCESS_TYPES = ACCESS_TYPES;
58
73
  this.CONTRACTS = CONTRACTS;
59
74
  this.client = client;
@@ -73,6 +88,7 @@ var AuthorizationClient = /*#__PURE__*/function () {
73
88
  this.requestIds = {};
74
89
  this.providers = {};
75
90
  }
91
+
76
92
  _createClass(AuthorizationClient, [{
77
93
  key: "Log",
78
94
  value: function Log(message) {
@@ -86,41 +102,50 @@ var AuthorizationClient = /*#__PURE__*/function () {
86
102
  var token = {
87
103
  qspace_id: this.client.contentSpaceId
88
104
  };
105
+
89
106
  if (libraryId) {
90
107
  token.qlib_id = libraryId;
91
108
  }
109
+
92
110
  return Utils.B64(JSON.stringify(token));
93
- }
111
+ } // Return authorization token in appropriate headers
94
112
 
95
- // Return authorization token in appropriate headers
96
113
  }, {
97
114
  key: "AuthorizationHeader",
98
115
  value: function () {
99
116
  var _AuthorizationHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
100
117
  var authorizationToken, headers;
101
118
  return _regeneratorRuntime.wrap(function _callee$(_context) {
102
- while (1) switch (_context.prev = _context.next) {
103
- case 0:
104
- _context.next = 2;
105
- return this.AuthorizationToken(params);
106
- case 2:
107
- authorizationToken = _context.sent;
108
- headers = {
109
- Authorization: "Bearer " + authorizationToken
110
- };
111
- if (params.encryption && params.encryption !== "none") {
112
- headers["X-Content-Fabric-Encryption-Scheme"] = params.encryption;
113
- }
114
- return _context.abrupt("return", headers);
115
- case 6:
116
- case "end":
117
- return _context.stop();
119
+ while (1) {
120
+ switch (_context.prev = _context.next) {
121
+ case 0:
122
+ _context.next = 2;
123
+ return this.AuthorizationToken(params);
124
+
125
+ case 2:
126
+ authorizationToken = _context.sent;
127
+ headers = {
128
+ Authorization: "Bearer " + authorizationToken
129
+ };
130
+
131
+ if (params.encryption && params.encryption !== "none") {
132
+ headers["X-Content-Fabric-Encryption-Scheme"] = params.encryption;
133
+ }
134
+
135
+ return _context.abrupt("return", headers);
136
+
137
+ case 6:
138
+ case "end":
139
+ return _context.stop();
140
+ }
118
141
  }
119
142
  }, _callee, this);
120
143
  }));
144
+
121
145
  function AuthorizationHeader(_x) {
122
146
  return _AuthorizationHeader.apply(this, arguments);
123
147
  }
148
+
124
149
  return AuthorizationHeader;
125
150
  }()
126
151
  }, {
@@ -128,100 +153,127 @@ var AuthorizationClient = /*#__PURE__*/function () {
128
153
  value: function () {
129
154
  var _AuthorizationToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
130
155
  var libraryId, objectId, versionHash, partHash, encryption, audienceData, context, _ref3$update, update, _ref3$channelAuth, channelAuth, oauthToken, _ref3$noCache, noCache, _ref3$noAuth, noAuth, isWalletRequest, initialNoCache, authorizationToken;
156
+
131
157
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
132
- while (1) switch (_context2.prev = _context2.next) {
133
- case 0:
134
- libraryId = _ref3.libraryId, objectId = _ref3.objectId, versionHash = _ref3.versionHash, partHash = _ref3.partHash, encryption = _ref3.encryption, audienceData = _ref3.audienceData, context = _ref3.context, _ref3$update = _ref3.update, update = _ref3$update === void 0 ? false : _ref3$update, _ref3$channelAuth = _ref3.channelAuth, channelAuth = _ref3$channelAuth === void 0 ? false : _ref3$channelAuth, oauthToken = _ref3.oauthToken, _ref3$noCache = _ref3.noCache, noCache = _ref3$noCache === void 0 ? false : _ref3$noCache, _ref3$noAuth = _ref3.noAuth, noAuth = _ref3$noAuth === void 0 ? false : _ref3$noAuth;
135
- if (versionHash) {
136
- objectId = this.client.utils.DecodeVersionHash(versionHash).objectId;
137
- }
138
- _context2.t0 = objectId && this.client.signer;
139
- if (!_context2.t0) {
140
- _context2.next = 10;
141
- break;
142
- }
143
- _context2.t1 = this.client.utils;
144
- _context2.next = 7;
145
- return this.client.userProfileClient.WalletAddress(false);
146
- case 7:
147
- _context2.t2 = _context2.sent;
148
- _context2.t3 = this.client.utils.HashToAddress(objectId);
149
- _context2.t0 = _context2.t1.EqualAddress.call(_context2.t1, _context2.t2, _context2.t3);
150
- case 10:
151
- isWalletRequest = _context2.t0;
152
- if (!(this.client.staticToken && !isWalletRequest)) {
153
- _context2.next = 13;
154
- break;
155
- }
156
- return _context2.abrupt("return", this.client.staticToken);
157
- case 13:
158
- initialNoCache = this.noCache;
159
- _context2.prev = 14;
160
- // noCache enabled for this call
161
- if (noCache && !this.noCache) {
162
- this.noCache = true;
163
- }
164
- if (channelAuth && this.client.signer && this.client.signer.remoteSigner) {
165
- // Channel auth not supported for remote signer, use a self-signed no-auth token instead
166
- noAuth = true;
167
- channelAuth = false;
168
- }
169
- if (!channelAuth) {
170
- _context2.next = 23;
171
- break;
172
- }
173
- _context2.next = 20;
174
- return this.GenerateChannelContentToken({
175
- objectId: objectId,
176
- versionHash: versionHash,
177
- audienceData: audienceData,
178
- context: context,
179
- oauthToken: oauthToken
180
- });
181
- case 20:
182
- authorizationToken = _context2.sent;
183
- _context2.next = 28;
184
- break;
185
- case 23:
186
- if (!(noAuth && this.client.signer && this.client.signer.remoteSigner && this.client.signer.unsignedPublicAuth)) {
187
- _context2.next = 25;
158
+ while (1) {
159
+ switch (_context2.prev = _context2.next) {
160
+ case 0:
161
+ libraryId = _ref3.libraryId, objectId = _ref3.objectId, versionHash = _ref3.versionHash, partHash = _ref3.partHash, encryption = _ref3.encryption, audienceData = _ref3.audienceData, context = _ref3.context, _ref3$update = _ref3.update, update = _ref3$update === void 0 ? false : _ref3$update, _ref3$channelAuth = _ref3.channelAuth, channelAuth = _ref3$channelAuth === void 0 ? false : _ref3$channelAuth, oauthToken = _ref3.oauthToken, _ref3$noCache = _ref3.noCache, noCache = _ref3$noCache === void 0 ? false : _ref3$noCache, _ref3$noAuth = _ref3.noAuth, noAuth = _ref3$noAuth === void 0 ? false : _ref3$noAuth;
162
+
163
+ if (versionHash) {
164
+ objectId = this.client.utils.DecodeVersionHash(versionHash).objectId;
165
+ }
166
+
167
+ _context2.t0 = objectId && this.client.signer;
168
+
169
+ if (!_context2.t0) {
170
+ _context2.next = 10;
171
+ break;
172
+ }
173
+
174
+ _context2.t1 = this.client.utils;
175
+ _context2.next = 7;
176
+ return this.client.userProfileClient.WalletAddress(false);
177
+
178
+ case 7:
179
+ _context2.t2 = _context2.sent;
180
+ _context2.t3 = this.client.utils.HashToAddress(objectId);
181
+ _context2.t0 = _context2.t1.EqualAddress.call(_context2.t1, _context2.t2, _context2.t3);
182
+
183
+ case 10:
184
+ isWalletRequest = _context2.t0;
185
+
186
+ if (!(this.client.staticToken && !isWalletRequest)) {
187
+ _context2.next = 13;
188
+ break;
189
+ }
190
+
191
+ return _context2.abrupt("return", this.client.staticToken);
192
+
193
+ case 13:
194
+ initialNoCache = this.noCache;
195
+ _context2.prev = 14;
196
+
197
+ // noCache enabled for this call
198
+ if (noCache && !this.noCache) {
199
+ this.noCache = true;
200
+ }
201
+
202
+ if (channelAuth && this.client.signer && this.client.signer.remoteSigner) {
203
+ // Channel auth not supported for remote signer, use a self-signed no-auth token instead
204
+ noAuth = true;
205
+ channelAuth = false;
206
+ }
207
+
208
+ if (!channelAuth) {
209
+ _context2.next = 23;
210
+ break;
211
+ }
212
+
213
+ _context2.next = 20;
214
+ return this.GenerateChannelContentToken({
215
+ objectId: objectId,
216
+ versionHash: versionHash,
217
+ audienceData: audienceData,
218
+ context: context,
219
+ oauthToken: oauthToken
220
+ });
221
+
222
+ case 20:
223
+ authorizationToken = _context2.sent;
224
+ _context2.next = 28;
188
225
  break;
189
- }
190
- return _context2.abrupt("return", this.CreateStaticToken({
191
- libraryId: libraryId
192
- }));
193
- case 25:
194
- _context2.next = 27;
195
- return this.GenerateAuthorizationToken({
196
- libraryId: libraryId,
197
- objectId: objectId,
198
- versionHash: versionHash,
199
- partHash: partHash,
200
- encryption: encryption,
201
- update: update,
202
- noAuth: noAuth
203
- });
204
- case 27:
205
- authorizationToken = _context2.sent;
206
- case 28:
207
- return _context2.abrupt("return", authorizationToken);
208
- case 31:
209
- _context2.prev = 31;
210
- _context2.t4 = _context2["catch"](14);
211
- throw _context2.t4;
212
- case 34:
213
- _context2.prev = 34;
214
- this.noCache = initialNoCache;
215
- return _context2.finish(34);
216
- case 37:
217
- case "end":
218
- return _context2.stop();
226
+
227
+ case 23:
228
+ if (!(noAuth && this.client.signer && this.client.signer.remoteSigner && this.client.signer.unsignedPublicAuth)) {
229
+ _context2.next = 25;
230
+ break;
231
+ }
232
+
233
+ return _context2.abrupt("return", this.CreateStaticToken({
234
+ libraryId: libraryId
235
+ }));
236
+
237
+ case 25:
238
+ _context2.next = 27;
239
+ return this.GenerateAuthorizationToken({
240
+ libraryId: libraryId,
241
+ objectId: objectId,
242
+ versionHash: versionHash,
243
+ partHash: partHash,
244
+ encryption: encryption,
245
+ update: update,
246
+ noAuth: noAuth
247
+ });
248
+
249
+ case 27:
250
+ authorizationToken = _context2.sent;
251
+
252
+ case 28:
253
+ return _context2.abrupt("return", authorizationToken);
254
+
255
+ case 31:
256
+ _context2.prev = 31;
257
+ _context2.t4 = _context2["catch"](14);
258
+ throw _context2.t4;
259
+
260
+ case 34:
261
+ _context2.prev = 34;
262
+ this.noCache = initialNoCache;
263
+ return _context2.finish(34);
264
+
265
+ case 37:
266
+ case "end":
267
+ return _context2.stop();
268
+ }
219
269
  }
220
270
  }, _callee2, this, [[14, 31, 34, 37]]);
221
271
  }));
272
+
222
273
  function AuthorizationToken(_x2) {
223
274
  return _AuthorizationToken.apply(this, arguments);
224
275
  }
276
+
225
277
  return AuthorizationToken;
226
278
  }()
227
279
  }, {
@@ -229,109 +281,136 @@ var AuthorizationClient = /*#__PURE__*/function () {
229
281
  value: function () {
230
282
  var _GenerateAuthorizationToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref4) {
231
283
  var libraryId, objectId, versionHash, partHash, encryption, _ref4$update, update, _ref4$noAuth, noAuth, publicKey, owner, ownerCapKey, ownerCap, cap, token, _yield$this$MakeAcces, transactionHash, signature, multiSig;
284
+
232
285
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
233
- while (1) switch (_context3.prev = _context3.next) {
234
- case 0:
235
- libraryId = _ref4.libraryId, objectId = _ref4.objectId, versionHash = _ref4.versionHash, partHash = _ref4.partHash, encryption = _ref4.encryption, _ref4$update = _ref4.update, update = _ref4$update === void 0 ? false : _ref4$update, _ref4$noAuth = _ref4.noAuth, noAuth = _ref4$noAuth === void 0 ? false : _ref4$noAuth;
236
- if (versionHash) {
237
- objectId = Utils.DecodeVersionHash(versionHash).objectId;
238
- }
239
-
240
- // Generate AFGH public key if encryption is specified
241
- _context3.t0 = encryption && encryption !== "none" && objectId;
242
- if (!_context3.t0) {
243
- _context3.next = 9;
244
- break;
245
- }
246
- _context3.next = 6;
247
- return this.AccessType(objectId);
248
- case 6:
249
- _context3.t1 = _context3.sent;
250
- _context3.t2 = ACCESS_TYPES.OBJECT;
251
- _context3.t0 = _context3.t1 === _context3.t2;
252
- case 9:
253
- if (!_context3.t0) {
254
- _context3.next = 22;
255
- break;
256
- }
257
- _context3.next = 12;
258
- return this.Owner({
259
- id: objectId
260
- });
261
- case 12:
262
- owner = _context3.sent;
263
- ownerCapKey = "eluv.caps.iusr".concat(Utils.AddressToHash(this.client.signer.address));
264
- _context3.next = 16;
265
- return this.client.ContentObjectMetadata({
266
- libraryId: libraryId,
267
- objectId: objectId,
268
- metadataSubtree: ownerCapKey
269
- });
270
- case 16:
271
- ownerCap = _context3.sent;
272
- if (!(!Utils.EqualAddress(owner, this.client.signer.address) && !ownerCap)) {
273
- _context3.next = 22;
274
- break;
275
- }
276
- _context3.next = 20;
277
- return this.ReEncryptionConk({
278
- libraryId: libraryId,
279
- objectId: objectId
280
- });
281
- case 20:
282
- cap = _context3.sent;
283
- publicKey = cap.public_key;
284
- case 22:
285
- token = {
286
- qspace_id: this.contentSpaceId,
287
- addr: Utils.FormatAddress(this.client.signer && this.client.signer.address || "")
288
- };
289
- if (!update) {
290
- _context3.next = 29;
291
- break;
292
- }
293
- _context3.next = 26;
294
- return this.MakeAccessRequest({
295
- libraryId: libraryId,
296
- objectId: objectId,
297
- versionHash: versionHash,
298
- update: update,
299
- publicKey: publicKey,
300
- noCache: this.noCache,
301
- noAuth: this.noAuth || noAuth
302
- });
303
- case 26:
304
- _yield$this$MakeAcces = _context3.sent;
305
- transactionHash = _yield$this$MakeAcces.transactionHash;
306
- if (transactionHash) {
307
- token.tx_id = transactionHash;
308
- }
309
- case 29:
310
- if (libraryId) {
311
- token.qlib_id = libraryId;
312
- }
313
- if (partHash) {
314
- token.qphash = partHash;
315
- }
316
- if (publicKey) {
317
- token.afgh_pk = publicKey;
318
- }
319
- token = Utils.B64(JSON.stringify(token));
320
- _context3.next = 35;
321
- return this.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(token)));
322
- case 35:
323
- signature = _context3.sent;
324
- multiSig = Utils.FormatSignature(signature);
325
- return _context3.abrupt("return", "".concat(token, ".").concat(Utils.B64(multiSig)));
326
- case 38:
327
- case "end":
328
- return _context3.stop();
286
+ while (1) {
287
+ switch (_context3.prev = _context3.next) {
288
+ case 0:
289
+ libraryId = _ref4.libraryId, objectId = _ref4.objectId, versionHash = _ref4.versionHash, partHash = _ref4.partHash, encryption = _ref4.encryption, _ref4$update = _ref4.update, update = _ref4$update === void 0 ? false : _ref4$update, _ref4$noAuth = _ref4.noAuth, noAuth = _ref4$noAuth === void 0 ? false : _ref4$noAuth;
290
+
291
+ if (versionHash) {
292
+ objectId = Utils.DecodeVersionHash(versionHash).objectId;
293
+ } // Generate AFGH public key if encryption is specified
294
+
295
+
296
+ _context3.t0 = encryption && encryption !== "none" && objectId;
297
+
298
+ if (!_context3.t0) {
299
+ _context3.next = 9;
300
+ break;
301
+ }
302
+
303
+ _context3.next = 6;
304
+ return this.AccessType(objectId);
305
+
306
+ case 6:
307
+ _context3.t1 = _context3.sent;
308
+ _context3.t2 = ACCESS_TYPES.OBJECT;
309
+ _context3.t0 = _context3.t1 === _context3.t2;
310
+
311
+ case 9:
312
+ if (!_context3.t0) {
313
+ _context3.next = 22;
314
+ break;
315
+ }
316
+
317
+ _context3.next = 12;
318
+ return this.Owner({
319
+ id: objectId
320
+ });
321
+
322
+ case 12:
323
+ owner = _context3.sent;
324
+ ownerCapKey = "eluv.caps.iusr".concat(Utils.AddressToHash(this.client.signer.address));
325
+ _context3.next = 16;
326
+ return this.client.ContentObjectMetadata({
327
+ libraryId: libraryId,
328
+ objectId: objectId,
329
+ metadataSubtree: ownerCapKey
330
+ });
331
+
332
+ case 16:
333
+ ownerCap = _context3.sent;
334
+
335
+ if (!(!Utils.EqualAddress(owner, this.client.signer.address) && !ownerCap)) {
336
+ _context3.next = 22;
337
+ break;
338
+ }
339
+
340
+ _context3.next = 20;
341
+ return this.ReEncryptionConk({
342
+ libraryId: libraryId,
343
+ objectId: objectId
344
+ });
345
+
346
+ case 20:
347
+ cap = _context3.sent;
348
+ publicKey = cap.public_key;
349
+
350
+ case 22:
351
+ token = {
352
+ qspace_id: this.contentSpaceId,
353
+ addr: Utils.FormatAddress(this.client.signer && this.client.signer.address || "")
354
+ };
355
+
356
+ if (!update) {
357
+ _context3.next = 29;
358
+ break;
359
+ }
360
+
361
+ _context3.next = 26;
362
+ return this.MakeAccessRequest({
363
+ libraryId: libraryId,
364
+ objectId: objectId,
365
+ versionHash: versionHash,
366
+ update: update,
367
+ publicKey: publicKey,
368
+ noCache: this.noCache,
369
+ noAuth: this.noAuth || noAuth
370
+ });
371
+
372
+ case 26:
373
+ _yield$this$MakeAcces = _context3.sent;
374
+ transactionHash = _yield$this$MakeAcces.transactionHash;
375
+
376
+ if (transactionHash) {
377
+ token.tx_id = transactionHash;
378
+ }
379
+
380
+ case 29:
381
+ if (libraryId) {
382
+ token.qlib_id = libraryId;
383
+ }
384
+
385
+ if (partHash) {
386
+ token.qphash = partHash;
387
+ }
388
+
389
+ if (publicKey) {
390
+ token.afgh_pk = publicKey;
391
+ }
392
+
393
+ token = Utils.B64(JSON.stringify(token));
394
+ _context3.next = 35;
395
+ return this.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(token)));
396
+
397
+ case 35:
398
+ signature = _context3.sent;
399
+ multiSig = Utils.FormatSignature(signature);
400
+ return _context3.abrupt("return", "".concat(token, ".").concat(Utils.B64(multiSig)));
401
+
402
+ case 38:
403
+ case "end":
404
+ return _context3.stop();
405
+ }
329
406
  }
330
407
  }, _callee3, this);
331
408
  }));
409
+
332
410
  function GenerateAuthorizationToken(_x3) {
333
411
  return _GenerateAuthorizationToken.apply(this, arguments);
334
412
  }
413
+
335
414
  return GenerateAuthorizationToken;
336
415
  }()
337
416
  }, {
@@ -339,180 +418,226 @@ var AuthorizationClient = /*#__PURE__*/function () {
339
418
  value: function () {
340
419
  var _MakeAccessRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref5) {
341
420
  var _this = this;
421
+
342
422
  var libraryId, objectId, versionHash, _ref5$args, args, _ref5$publicKey, publicKey, _ref5$update, update, _ref5$skipCache, skipCache, _ref5$noCache, noCache, cacheOnly, walletContractAddress, walletCreated, id, _yield$this$ContractI, isV3, accessType, abi, _yield$this$AccessInf, accessArgs, checkAccessCharge, address, elapsed, _cache, accessRequest, cache;
423
+
343
424
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
344
- while (1) switch (_context4.prev = _context4.next) {
345
- case 0:
346
- libraryId = _ref5.libraryId, objectId = _ref5.objectId, versionHash = _ref5.versionHash, _ref5$args = _ref5.args, args = _ref5$args === void 0 ? [] : _ref5$args, _ref5$publicKey = _ref5.publicKey, publicKey = _ref5$publicKey === void 0 ? "" : _ref5$publicKey, _ref5$update = _ref5.update, update = _ref5$update === void 0 ? false : _ref5$update, _ref5$skipCache = _ref5.skipCache, skipCache = _ref5$skipCache === void 0 ? false : _ref5$skipCache, _ref5$noCache = _ref5.noCache, noCache = _ref5$noCache === void 0 ? false : _ref5$noCache, cacheOnly = _ref5.cacheOnly;
347
- if (this.client.signer) {
348
- _context4.next = 3;
349
- break;
350
- }
351
- return _context4.abrupt("return", {
352
- transactionHash: ""
353
- });
354
- case 3:
355
- _context4.next = 5;
356
- return this.client.userProfileClient.UserWalletAddress({
357
- address: this.client.signer.address
358
- });
359
- case 5:
360
- walletContractAddress = _context4.sent;
361
- if (walletContractAddress) {
362
- _context4.next = 12;
363
- break;
364
- }
365
- _context4.next = 9;
366
- return this.client.userProfileClient.WalletAddress();
367
- case 9:
368
- walletCreated = _context4.sent;
369
- if (walletCreated) {
370
- _context4.next = 12;
371
- break;
372
- }
373
- throw Error("User wallet contract is required to make access requests");
374
- case 12:
375
- if (versionHash) {
376
- objectId = Utils.DecodeVersionHash(versionHash).objectId;
377
- }
378
- id = objectId || libraryId || this.contentSpaceId;
379
- _context4.next = 16;
380
- return this.ContractInfo({
381
- id: id
382
- });
383
- case 16:
384
- _yield$this$ContractI = _context4.sent;
385
- isV3 = _yield$this$ContractI.isV3;
386
- accessType = _yield$this$ContractI.accessType;
387
- abi = _yield$this$ContractI.abi;
388
- if (!(typeof accessType === "undefined")) {
389
- _context4.next = 22;
390
- break;
391
- }
392
- throw Error("Unable to determine contract info for ".concat(id, " (").concat(this.client.utils.HashToAddress(id), ") - Wrong network?"));
393
- case 22:
394
- _context4.next = 24;
395
- return this.AccessInfo({
396
- accessType: accessType,
397
- publicKey: publicKey,
398
- update: update,
399
- args: args,
400
- isV3: isV3
401
- });
402
- case 24:
403
- _yield$this$AccessInf = _context4.sent;
404
- accessArgs = _yield$this$AccessInf.accessArgs;
405
- checkAccessCharge = _yield$this$AccessInf.checkAccessCharge;
406
- address = Utils.HashToAddress(id);
407
- elapsed = 0;
408
- case 29:
409
- if (!this.transactionLocks[id]) {
410
- _context4.next = 36;
411
- break;
412
- }
413
- _context4.next = 32;
414
- return new Promise(function (resolve) {
415
- return setTimeout(resolve, 100);
416
- });
417
- case 32:
418
- elapsed += 100;
419
- if (elapsed > 15000) {
420
- this.Log("Lock never released for ".concat(id, " - releasing lock"));
421
- delete this.transactionLocks[id];
422
- }
423
- _context4.next = 29;
424
- break;
425
- case 36:
426
- _context4.prev = 36;
427
- this.transactionLocks[id] = true;
428
-
429
- // Check cache for existing transaction
430
- if (!(!noCache && !skipCache)) {
431
- _context4.next = 46;
432
- break;
433
- }
434
- _cache = update ? this.modifyTransactions : this.accessTransactions;
435
- if (!_cache[address]) {
436
- _context4.next = 46;
437
- break;
438
- }
439
- if (!(_cache[address].issuedAt > Date.now() - 12 * 60 * 60 * 1000)) {
440
- _context4.next = 45;
441
- break;
442
- }
443
- return _context4.abrupt("return", _cache[address]);
444
- case 45:
445
- // Token expired
446
- delete _cache[address];
447
- case 46:
448
- if (!cacheOnly) {
449
- _context4.next = 48;
425
+ while (1) {
426
+ switch (_context4.prev = _context4.next) {
427
+ case 0:
428
+ libraryId = _ref5.libraryId, objectId = _ref5.objectId, versionHash = _ref5.versionHash, _ref5$args = _ref5.args, args = _ref5$args === void 0 ? [] : _ref5$args, _ref5$publicKey = _ref5.publicKey, publicKey = _ref5$publicKey === void 0 ? "" : _ref5$publicKey, _ref5$update = _ref5.update, update = _ref5$update === void 0 ? false : _ref5$update, _ref5$skipCache = _ref5.skipCache, skipCache = _ref5$skipCache === void 0 ? false : _ref5$skipCache, _ref5$noCache = _ref5.noCache, noCache = _ref5$noCache === void 0 ? false : _ref5$noCache, cacheOnly = _ref5.cacheOnly;
429
+
430
+ if (this.client.signer) {
431
+ _context4.next = 3;
432
+ break;
433
+ }
434
+
435
+ return _context4.abrupt("return", {
436
+ transactionHash: ""
437
+ });
438
+
439
+ case 3:
440
+ _context4.next = 5;
441
+ return this.client.userProfileClient.UserWalletAddress({
442
+ address: this.client.signer.address
443
+ });
444
+
445
+ case 5:
446
+ walletContractAddress = _context4.sent;
447
+
448
+ if (walletContractAddress) {
449
+ _context4.next = 12;
450
+ break;
451
+ }
452
+
453
+ _context4.next = 9;
454
+ return this.client.userProfileClient.WalletAddress();
455
+
456
+ case 9:
457
+ walletCreated = _context4.sent;
458
+
459
+ if (walletCreated) {
460
+ _context4.next = 12;
461
+ break;
462
+ }
463
+
464
+ throw Error("User wallet contract is required to make access requests");
465
+
466
+ case 12:
467
+ if (versionHash) {
468
+ objectId = Utils.DecodeVersionHash(versionHash).objectId;
469
+ }
470
+
471
+ id = objectId || libraryId || this.contentSpaceId;
472
+ _context4.next = 16;
473
+ return this.ContractInfo({
474
+ id: id
475
+ });
476
+
477
+ case 16:
478
+ _yield$this$ContractI = _context4.sent;
479
+ isV3 = _yield$this$ContractI.isV3;
480
+ accessType = _yield$this$ContractI.accessType;
481
+ abi = _yield$this$ContractI.abi;
482
+
483
+ if (!(typeof accessType === "undefined")) {
484
+ _context4.next = 22;
485
+ break;
486
+ }
487
+
488
+ throw Error("Unable to determine contract info for ".concat(id, " (").concat(this.client.utils.HashToAddress(id), ") - Wrong network?"));
489
+
490
+ case 22:
491
+ _context4.next = 24;
492
+ return this.AccessInfo({
493
+ accessType: accessType,
494
+ publicKey: publicKey,
495
+ update: update,
496
+ args: args,
497
+ isV3: isV3
498
+ });
499
+
500
+ case 24:
501
+ _yield$this$AccessInf = _context4.sent;
502
+ accessArgs = _yield$this$AccessInf.accessArgs;
503
+ checkAccessCharge = _yield$this$AccessInf.checkAccessCharge;
504
+ address = Utils.HashToAddress(id);
505
+ elapsed = 0;
506
+
507
+ case 29:
508
+ if (!this.transactionLocks[id]) {
509
+ _context4.next = 36;
510
+ break;
511
+ }
512
+
513
+ _context4.next = 32;
514
+ return new Promise(function (resolve) {
515
+ return setTimeout(resolve, 100);
516
+ });
517
+
518
+ case 32:
519
+ elapsed += 100;
520
+
521
+ if (elapsed > 15000) {
522
+ this.Log("Lock never released for ".concat(id, " - releasing lock"));
523
+ delete this.transactionLocks[id];
524
+ }
525
+
526
+ _context4.next = 29;
450
527
  break;
451
- }
452
- return _context4.abrupt("return");
453
- case 48:
454
- if (!update) {
455
- _context4.next = 55;
528
+
529
+ case 36:
530
+ _context4.prev = 36;
531
+ this.transactionLocks[id] = true; // Check cache for existing transaction
532
+
533
+ if (!(!noCache && !skipCache)) {
534
+ _context4.next = 46;
535
+ break;
536
+ }
537
+
538
+ _cache = update ? this.modifyTransactions : this.accessTransactions;
539
+
540
+ if (!_cache[address]) {
541
+ _context4.next = 46;
542
+ break;
543
+ }
544
+
545
+ if (!(_cache[address].issuedAt > Date.now() - 12 * 60 * 60 * 1000)) {
546
+ _context4.next = 45;
547
+ break;
548
+ }
549
+
550
+ return _context4.abrupt("return", _cache[address]);
551
+
552
+ case 45:
553
+ // Token expired
554
+ delete _cache[address];
555
+
556
+ case 46:
557
+ if (!cacheOnly) {
558
+ _context4.next = 48;
559
+ break;
560
+ }
561
+
562
+ return _context4.abrupt("return");
563
+
564
+ case 48:
565
+ if (!update) {
566
+ _context4.next = 55;
567
+ break;
568
+ }
569
+
570
+ this.Log("Making update request on ".concat(accessType, " ").concat(id));
571
+ _context4.next = 52;
572
+ return this.UpdateRequest({
573
+ id: id,
574
+ abi: abi
575
+ });
576
+
577
+ case 52:
578
+ accessRequest = _context4.sent;
579
+ _context4.next = 59;
456
580
  break;
457
- }
458
- this.Log("Making update request on ".concat(accessType, " ").concat(id));
459
- _context4.next = 52;
460
- return this.UpdateRequest({
461
- id: id,
462
- abi: abi
463
- });
464
- case 52:
465
- accessRequest = _context4.sent;
466
- _context4.next = 59;
467
- break;
468
- case 55:
469
- this.Log("Making access request on ".concat(accessType, " ").concat(id));
470
- _context4.next = 58;
471
- return this.AccessRequest({
472
- id: id,
473
- args: accessArgs,
474
- checkAccessCharge: checkAccessCharge
475
- });
476
- case 58:
477
- accessRequest = _context4.sent;
478
- case 59:
479
- cache = update ? this.modifyTransactions : this.accessTransactions;
480
- _context4.prev = 60;
481
- if (!noCache) {
482
- cache[address] = {
483
- issuedAt: Date.now(),
484
- transactionHash: accessRequest.transactionHash
485
- };
486
581
 
487
- // Save request ID if present
488
- accessRequest.logs.some(function (log) {
489
- if (log.args && (log.args.requestID || log.args.requestNonce)) {
490
- _this.requestIds[address] = (log.args.requestID || log.args.requestNonce || "").toString().replace(/^0x/, "");
491
- return true;
492
- }
582
+ case 55:
583
+ this.Log("Making access request on ".concat(accessType, " ").concat(id));
584
+ _context4.next = 58;
585
+ return this.AccessRequest({
586
+ id: id,
587
+ args: accessArgs,
588
+ checkAccessCharge: checkAccessCharge
493
589
  });
494
- }
495
- return _context4.abrupt("return", accessRequest);
496
- case 65:
497
- _context4.prev = 65;
498
- _context4.t0 = _context4["catch"](60);
499
- if (!noCache) {
500
- delete cache[address];
501
- }
502
- throw _context4.t0;
503
- case 69:
504
- _context4.prev = 69;
505
- delete this.transactionLocks[id];
506
- return _context4.finish(69);
507
- case 72:
508
- case "end":
509
- return _context4.stop();
590
+
591
+ case 58:
592
+ accessRequest = _context4.sent;
593
+
594
+ case 59:
595
+ cache = update ? this.modifyTransactions : this.accessTransactions;
596
+ _context4.prev = 60;
597
+
598
+ if (!noCache) {
599
+ cache[address] = {
600
+ issuedAt: Date.now(),
601
+ transactionHash: accessRequest.transactionHash
602
+ }; // Save request ID if present
603
+
604
+ accessRequest.logs.some(function (log) {
605
+ if (log.args && (log.args.requestID || log.args.requestNonce)) {
606
+ _this.requestIds[address] = (log.args.requestID || log.args.requestNonce || "").toString().replace(/^0x/, "");
607
+ return true;
608
+ }
609
+ });
610
+ }
611
+
612
+ return _context4.abrupt("return", accessRequest);
613
+
614
+ case 65:
615
+ _context4.prev = 65;
616
+ _context4.t0 = _context4["catch"](60);
617
+
618
+ if (!noCache) {
619
+ delete cache[address];
620
+ }
621
+
622
+ throw _context4.t0;
623
+
624
+ case 69:
625
+ _context4.prev = 69;
626
+ delete this.transactionLocks[id];
627
+ return _context4.finish(69);
628
+
629
+ case 72:
630
+ case "end":
631
+ return _context4.stop();
632
+ }
510
633
  }
511
634
  }, _callee4, this, [[36,, 69, 72], [60, 65]]);
512
635
  }));
636
+
513
637
  function MakeAccessRequest(_x4) {
514
638
  return _MakeAccessRequest.apply(this, arguments);
515
639
  }
640
+
516
641
  return MakeAccessRequest;
517
642
  }()
518
643
  }, {
@@ -520,108 +645,134 @@ var AuthorizationClient = /*#__PURE__*/function () {
520
645
  value: function () {
521
646
  var _AccessRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref6) {
522
647
  var id, _ref6$args, args, _ref6$checkAccessChar, checkAccessCharge, _yield$this$ContractI2, isV3, accessType, abi, accessCharge, owner, accessChargeArgs, event, methodName, contractAddress;
648
+
523
649
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
524
- while (1) switch (_context5.prev = _context5.next) {
525
- case 0:
526
- id = _ref6.id, _ref6$args = _ref6.args, args = _ref6$args === void 0 ? [] : _ref6$args, _ref6$checkAccessChar = _ref6.checkAccessCharge, checkAccessCharge = _ref6$checkAccessChar === void 0 ? false : _ref6$checkAccessChar;
527
- _context5.next = 3;
528
- return this.ContractInfo({
529
- id: id
530
- });
531
- case 3:
532
- _yield$this$ContractI2 = _context5.sent;
533
- isV3 = _yield$this$ContractI2.isV3;
534
- accessType = _yield$this$ContractI2.accessType;
535
- abi = _yield$this$ContractI2.abi;
536
- // Send some bux if access charge is required
537
- accessCharge = 0;
538
- if (!(checkAccessCharge && accessType === ACCESS_TYPES.OBJECT)) {
539
- _context5.next = 26;
540
- break;
541
- }
542
- _context5.next = 11;
543
- return this.Owner({
544
- id: id,
545
- abi: abi
546
- });
547
- case 11:
548
- owner = _context5.sent;
549
- if (Utils.EqualAddress(this.client.signer.address, owner)) {
650
+ while (1) {
651
+ switch (_context5.prev = _context5.next) {
652
+ case 0:
653
+ id = _ref6.id, _ref6$args = _ref6.args, args = _ref6$args === void 0 ? [] : _ref6$args, _ref6$checkAccessChar = _ref6.checkAccessCharge, checkAccessCharge = _ref6$checkAccessChar === void 0 ? false : _ref6$checkAccessChar;
654
+ _context5.next = 3;
655
+ return this.ContractInfo({
656
+ id: id
657
+ });
658
+
659
+ case 3:
660
+ _yield$this$ContractI2 = _context5.sent;
661
+ isV3 = _yield$this$ContractI2.isV3;
662
+ accessType = _yield$this$ContractI2.accessType;
663
+ abi = _yield$this$ContractI2.abi;
664
+ // Send some bux if access charge is required
665
+ accessCharge = 0;
666
+
667
+ if (!(checkAccessCharge && accessType === ACCESS_TYPES.OBJECT)) {
668
+ _context5.next = 26;
669
+ break;
670
+ }
671
+
672
+ _context5.next = 11;
673
+ return this.Owner({
674
+ id: id,
675
+ abi: abi
676
+ });
677
+
678
+ case 11:
679
+ owner = _context5.sent;
680
+
681
+ if (Utils.EqualAddress(this.client.signer.address, owner)) {
682
+ _context5.next = 26;
683
+ break;
684
+ }
685
+
686
+ _context5.prev = 13;
687
+ // Extract level, custom values and stakeholders from accessRequest arguments
688
+ accessChargeArgs = isV3 ? [0, [], []] : [args[0], args[3], args[4]]; // Access charge is in wei, but methods take ether - convert to charge to ether
689
+
690
+ _context5.t0 = Utils;
691
+ _context5.next = 18;
692
+ return this.GetAccessCharge({
693
+ objectId: id,
694
+ args: accessChargeArgs
695
+ });
696
+
697
+ case 18:
698
+ _context5.t1 = _context5.sent;
699
+ accessCharge = _context5.t0.WeiToEther.call(_context5.t0, _context5.t1);
550
700
  _context5.next = 26;
551
701
  break;
552
- }
553
- _context5.prev = 13;
554
- // Extract level, custom values and stakeholders from accessRequest arguments
555
- accessChargeArgs = isV3 ? [0, [], []] : [args[0], args[3], args[4]]; // Access charge is in wei, but methods take ether - convert to charge to ether
556
- _context5.t0 = Utils;
557
- _context5.next = 18;
558
- return this.GetAccessCharge({
559
- objectId: id,
560
- args: accessChargeArgs
561
- });
562
- case 18:
563
- _context5.t1 = _context5.sent;
564
- accessCharge = _context5.t0.WeiToEther.call(_context5.t0, _context5.t1);
565
- _context5.next = 26;
566
- break;
567
- case 22:
568
- _context5.prev = 22;
569
- _context5.t2 = _context5["catch"](13);
570
- this.Log("Failed to get access charge for", id);
571
- this.Log(_context5.t2);
572
- case 26:
573
- if (accessCharge > 0) {
574
- this.Log("Access charge: ".concat(accessCharge));
575
- }
576
- contractAddress = Utils.HashToAddress(id);
577
- if (isV3) {
578
- methodName = "accessRequestV3";
579
- } else {
580
- methodName = "accessRequest";
581
- }
582
- _context5.next = 31;
583
- return this.ContractHasMethod({
584
- contractAddress: contractAddress,
585
- abi: abi,
586
- methodName: methodName
587
- });
588
- case 31:
589
- if (_context5.sent) {
590
- _context5.next = 34;
591
- break;
592
- }
593
- this.Log("".concat(accessType, " ").concat(id, " has no ").concat(methodName, " method. Skipping"));
594
- return _context5.abrupt("return", {
595
- transactionHash: "",
596
- logs: []
597
- });
598
- case 34:
599
- _context5.next = 36;
600
- return this.client.CallContractMethodAndWait({
601
- contractAddress: contractAddress,
602
- abi: abi,
603
- methodName: methodName,
604
- methodArgs: args,
605
- value: accessCharge
606
- });
607
- case 36:
608
- event = _context5.sent;
609
- if (!(event.logs.length === 0)) {
610
- _context5.next = 39;
611
- break;
612
- }
613
- throw Error("Access denied (".concat(id, ")"));
614
- case 39:
615
- return _context5.abrupt("return", event);
616
- case 40:
617
- case "end":
618
- return _context5.stop();
702
+
703
+ case 22:
704
+ _context5.prev = 22;
705
+ _context5.t2 = _context5["catch"](13);
706
+ this.Log("Failed to get access charge for", id);
707
+ this.Log(_context5.t2);
708
+
709
+ case 26:
710
+ if (accessCharge > 0) {
711
+ this.Log("Access charge: ".concat(accessCharge));
712
+ }
713
+
714
+ contractAddress = Utils.HashToAddress(id);
715
+
716
+ if (isV3) {
717
+ methodName = "accessRequestV3";
718
+ } else {
719
+ methodName = "accessRequest";
720
+ }
721
+
722
+ _context5.next = 31;
723
+ return this.ContractHasMethod({
724
+ contractAddress: contractAddress,
725
+ abi: abi,
726
+ methodName: methodName
727
+ });
728
+
729
+ case 31:
730
+ if (_context5.sent) {
731
+ _context5.next = 34;
732
+ break;
733
+ }
734
+
735
+ this.Log("".concat(accessType, " ").concat(id, " has no ").concat(methodName, " method. Skipping"));
736
+ return _context5.abrupt("return", {
737
+ transactionHash: "",
738
+ logs: []
739
+ });
740
+
741
+ case 34:
742
+ _context5.next = 36;
743
+ return this.client.CallContractMethodAndWait({
744
+ contractAddress: contractAddress,
745
+ abi: abi,
746
+ methodName: methodName,
747
+ methodArgs: args,
748
+ value: accessCharge
749
+ });
750
+
751
+ case 36:
752
+ event = _context5.sent;
753
+
754
+ if (!(event.logs.length === 0)) {
755
+ _context5.next = 39;
756
+ break;
757
+ }
758
+
759
+ throw Error("Access denied (".concat(id, ")"));
760
+
761
+ case 39:
762
+ return _context5.abrupt("return", event);
763
+
764
+ case 40:
765
+ case "end":
766
+ return _context5.stop();
767
+ }
619
768
  }
620
769
  }, _callee5, this, [[13, 22]]);
621
770
  }));
771
+
622
772
  function AccessRequest(_x5) {
623
773
  return _AccessRequest.apply(this, arguments);
624
774
  }
775
+
625
776
  return AccessRequest;
626
777
  }()
627
778
  }, {
@@ -630,58 +781,69 @@ var AuthorizationClient = /*#__PURE__*/function () {
630
781
  var _UpdateRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref7) {
631
782
  var id, abi, event, updateRequestEvent;
632
783
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
633
- while (1) switch (_context6.prev = _context6.next) {
634
- case 0:
635
- id = _ref7.id, abi = _ref7.abi;
636
- _context6.next = 3;
637
- return this.client.CallContractMethodAndWait({
638
- contractAddress: Utils.HashToAddress(id),
639
- abi: abi,
640
- methodName: "updateRequest",
641
- methodArgs: []
642
- });
643
- case 3:
644
- event = _context6.sent;
645
- updateRequestEvent = this.client.ExtractEventFromLogs({
646
- abi: abi,
647
- event: event,
648
- eventName: "UpdateRequest"
649
- });
650
- if (!(event.logs.length === 0 || !updateRequestEvent)) {
651
- _context6.next = 7;
652
- break;
653
- }
654
- throw Error("Update request denied for ".concat(id));
655
- case 7:
656
- return _context6.abrupt("return", event);
657
- case 8:
658
- case "end":
659
- return _context6.stop();
784
+ while (1) {
785
+ switch (_context6.prev = _context6.next) {
786
+ case 0:
787
+ id = _ref7.id, abi = _ref7.abi;
788
+ _context6.next = 3;
789
+ return this.client.CallContractMethodAndWait({
790
+ contractAddress: Utils.HashToAddress(id),
791
+ abi: abi,
792
+ methodName: "updateRequest",
793
+ methodArgs: []
794
+ });
795
+
796
+ case 3:
797
+ event = _context6.sent;
798
+ updateRequestEvent = this.client.ExtractEventFromLogs({
799
+ abi: abi,
800
+ event: event,
801
+ eventName: "UpdateRequest"
802
+ });
803
+
804
+ if (!(event.logs.length === 0 || !updateRequestEvent)) {
805
+ _context6.next = 7;
806
+ break;
807
+ }
808
+
809
+ throw Error("Update request denied for ".concat(id));
810
+
811
+ case 7:
812
+ return _context6.abrupt("return", event);
813
+
814
+ case 8:
815
+ case "end":
816
+ return _context6.stop();
817
+ }
660
818
  }
661
819
  }, _callee6, this);
662
820
  }));
821
+
663
822
  function UpdateRequest(_x6) {
664
823
  return _UpdateRequest.apply(this, arguments);
665
824
  }
825
+
666
826
  return UpdateRequest;
667
827
  }()
668
828
  }, {
669
829
  key: "AudienceData",
670
830
  value: function AudienceData(_ref8) {
671
831
  var objectId = _ref8.objectId,
672
- versionHash = _ref8.versionHash,
673
- _ref8$protocols = _ref8.protocols,
674
- protocols = _ref8$protocols === void 0 ? [] : _ref8$protocols,
675
- _ref8$drms = _ref8.drms,
676
- drms = _ref8$drms === void 0 ? [] : _ref8$drms,
677
- context = _ref8.context;
832
+ versionHash = _ref8.versionHash,
833
+ _ref8$protocols = _ref8.protocols,
834
+ protocols = _ref8$protocols === void 0 ? [] : _ref8$protocols,
835
+ _ref8$drms = _ref8.drms,
836
+ drms = _ref8$drms === void 0 ? [] : _ref8$drms,
837
+ context = _ref8.context;
678
838
  this.Log("Retrieving audience data: ".concat(objectId));
679
839
  context = context || this.client.authContext || {};
840
+
680
841
  if (Object.values(context).find(function (value) {
681
842
  return typeof value !== "string";
682
843
  })) {
683
844
  throw Error("Context must be a map of string->string");
684
845
  }
846
+
685
847
  var data = _objectSpread({
686
848
  user_address: Utils.FormatAddress(this.client.signer.address),
687
849
  content_id: objectId || Utils.DecodeVersionHash(versionHash).id,
@@ -691,10 +853,12 @@ var AuthorizationClient = /*#__PURE__*/function () {
691
853
  format: protocols.join(","),
692
854
  drm: drms.join(",")
693
855
  }, context);
856
+
694
857
  if (typeof window !== "undefined" && window.navigator) {
695
858
  data.user_string = window.navigator.userAgent;
696
859
  data.language = window.navigator.language;
697
860
  }
861
+
698
862
  this.Log(data);
699
863
  return data;
700
864
  }
@@ -703,147 +867,180 @@ var AuthorizationClient = /*#__PURE__*/function () {
703
867
  value: function () {
704
868
  var _GenerateChannelContentToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref9) {
705
869
  var objectId, versionHash, issuer, code, email, audienceData, context, oauthToken, _ref9$value, value, token, tenantId, kmsAddress, stateChannelApi, additionalParams, payload, signature, multiSig;
870
+
706
871
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
707
- while (1) switch (_context7.prev = _context7.next) {
708
- case 0:
709
- objectId = _ref9.objectId, versionHash = _ref9.versionHash, issuer = _ref9.issuer, code = _ref9.code, email = _ref9.email, audienceData = _ref9.audienceData, context = _ref9.context, oauthToken = _ref9.oauthToken, _ref9$value = _ref9.value, value = _ref9$value === void 0 ? 0 : _ref9$value;
710
- if (!oauthToken) {
711
- _context7.next = 5;
712
- break;
713
- }
714
- _context7.next = 4;
715
- return this.GenerateOauthChannelToken({
716
- objectId: objectId,
717
- token: oauthToken
718
- });
719
- case 4:
720
- return _context7.abrupt("return", _context7.sent);
721
- case 5:
722
- if (!(!this.noCache && this.channelContentTokens[objectId])) {
723
- _context7.next = 11;
724
- break;
725
- }
726
- if (!(this.channelContentTokens[objectId].issuedAt > Date.now() - 12 * 60 * 60 * 1000)) {
727
- _context7.next = 10;
872
+ while (1) {
873
+ switch (_context7.prev = _context7.next) {
874
+ case 0:
875
+ objectId = _ref9.objectId, versionHash = _ref9.versionHash, issuer = _ref9.issuer, code = _ref9.code, email = _ref9.email, audienceData = _ref9.audienceData, context = _ref9.context, oauthToken = _ref9.oauthToken, _ref9$value = _ref9.value, value = _ref9$value === void 0 ? 0 : _ref9$value;
876
+
877
+ if (!oauthToken) {
878
+ _context7.next = 5;
879
+ break;
880
+ }
881
+
882
+ _context7.next = 4;
883
+ return this.GenerateOauthChannelToken({
884
+ objectId: objectId,
885
+ token: oauthToken
886
+ });
887
+
888
+ case 4:
889
+ return _context7.abrupt("return", _context7.sent);
890
+
891
+ case 5:
892
+ if (!(!this.noCache && this.channelContentTokens[objectId])) {
893
+ _context7.next = 11;
894
+ break;
895
+ }
896
+
897
+ if (!(this.channelContentTokens[objectId].issuedAt > Date.now() - 12 * 60 * 60 * 1000)) {
898
+ _context7.next = 10;
899
+ break;
900
+ }
901
+
902
+ return _context7.abrupt("return", this.channelContentTokens[objectId].token);
903
+
904
+ case 10:
905
+ // Token expired
906
+ delete this.channelContentTokens[objectId];
907
+
908
+ case 11:
909
+ this.Log("Making state channel access request: ".concat(objectId));
910
+
911
+ if (!issuer) {
912
+ _context7.next = 43;
913
+ break;
914
+ }
915
+
916
+ // Ticket API
917
+ tenantId = issuer.replace(/^\//, "").split("/")[2];
918
+ _context7.prev = 14;
919
+ _context7.next = 17;
920
+ return this.client.CallContractMethod({
921
+ contractAddress: Utils.HashToAddress(tenantId),
922
+ methodName: "addressKMS"
923
+ });
924
+
925
+ case 17:
926
+ kmsAddress = _context7.sent;
927
+
928
+ if (kmsAddress) {
929
+ _context7.next = 20;
930
+ break;
931
+ }
932
+
933
+ throw "";
934
+
935
+ case 20:
936
+ _context7.next = 27;
728
937
  break;
729
- }
730
- return _context7.abrupt("return", this.channelContentTokens[objectId].token);
731
- case 10:
732
- // Token expired
733
- delete this.channelContentTokens[objectId];
734
- case 11:
735
- this.Log("Making state channel access request: ".concat(objectId));
736
- if (!issuer) {
737
- _context7.next = 43;
938
+
939
+ case 22:
940
+ _context7.prev = 22;
941
+ _context7.t0 = _context7["catch"](14);
942
+ _context7.next = 26;
943
+ return this.client.DefaultKMSAddress();
944
+
945
+ case 26:
946
+ kmsAddress = _context7.sent;
947
+
948
+ case 27:
949
+ _context7.prev = 27;
950
+ _context7.next = 30;
951
+ return Utils.ResponseToFormat("text", this.MakeAuthServiceRequest({
952
+ kmsId: "ikms" + Utils.AddressToHash(kmsAddress),
953
+ method: "POST",
954
+ path: UrlJoin("as", issuer),
955
+ body: {
956
+ "_PASSWORD": code,
957
+ "_EMAIL": email
958
+ }
959
+ }));
960
+
961
+ case 30:
962
+ token = _context7.sent;
963
+ _context7.next = 40;
738
964
  break;
739
- }
740
- // Ticket API
741
- tenantId = issuer.replace(/^\//, "").split("/")[2];
742
- _context7.prev = 14;
743
- _context7.next = 17;
744
- return this.client.CallContractMethod({
745
- contractAddress: Utils.HashToAddress(tenantId),
746
- methodName: "addressKMS"
747
- });
748
- case 17:
749
- kmsAddress = _context7.sent;
750
- if (kmsAddress) {
751
- _context7.next = 20;
965
+
966
+ case 33:
967
+ _context7.prev = 33;
968
+ _context7.t1 = _context7["catch"](27);
969
+ this.Log("/as token redemption failed:", true);
970
+ this.Log(_context7.t1, true);
971
+ _context7.next = 39;
972
+ return Utils.ResponseToFormat("text", this.MakeKMSRequest({
973
+ kmsId: "ikms" + Utils.AddressToHash(kmsAddress),
974
+ method: "POST",
975
+ path: UrlJoin("ks", issuer),
976
+ body: {
977
+ "_PASSWORD": code,
978
+ "_EMAIL": email
979
+ }
980
+ }));
981
+
982
+ case 39:
983
+ token = _context7.sent;
984
+
985
+ case 40:
986
+ // Pull target object from token so token can be cached
987
+ objectId = JSON.parse(Utils.FromB64(token)).qid;
988
+ _context7.next = 54;
752
989
  break;
753
- }
754
- throw "";
755
- case 20:
756
- _context7.next = 27;
757
- break;
758
- case 22:
759
- _context7.prev = 22;
760
- _context7.t0 = _context7["catch"](14);
761
- _context7.next = 26;
762
- return this.client.DefaultKMSAddress();
763
- case 26:
764
- kmsAddress = _context7.sent;
765
- case 27:
766
- _context7.prev = 27;
767
- _context7.next = 30;
768
- return Utils.ResponseToFormat("text", this.MakeAuthServiceRequest({
769
- kmsId: "ikms" + Utils.AddressToHash(kmsAddress),
770
- method: "POST",
771
- path: UrlJoin("as", issuer),
772
- body: {
773
- "_PASSWORD": code,
774
- "_EMAIL": email
775
- }
776
- }));
777
- case 30:
778
- token = _context7.sent;
779
- _context7.next = 40;
780
- break;
781
- case 33:
782
- _context7.prev = 33;
783
- _context7.t1 = _context7["catch"](27);
784
- this.Log("/as token redemption failed:", true);
785
- this.Log(_context7.t1, true);
786
- _context7.next = 39;
787
- return Utils.ResponseToFormat("text", this.MakeKMSRequest({
788
- kmsId: "ikms" + Utils.AddressToHash(kmsAddress),
789
- method: "POST",
790
- path: UrlJoin("ks", issuer),
791
- body: {
792
- "_PASSWORD": code,
793
- "_EMAIL": email
794
- }
795
- }));
796
- case 39:
797
- token = _context7.sent;
798
- case 40:
799
- // Pull target object from token so token can be cached
800
- objectId = JSON.parse(Utils.FromB64(token)).qid;
801
- _context7.next = 54;
802
- break;
803
- case 43:
804
- // State channel API
805
- if (!audienceData) {
806
- audienceData = this.AudienceData({
990
+
991
+ case 43:
992
+ // State channel API
993
+ if (!audienceData) {
994
+ audienceData = this.AudienceData({
995
+ objectId: objectId,
996
+ versionHash: versionHash,
997
+ context: context
998
+ });
999
+ }
1000
+
1001
+ stateChannelApi = "elv_channelContentRequestContext";
1002
+ additionalParams = [JSON.stringify(audienceData)];
1003
+ _context7.next = 48;
1004
+ return this.MakeKMSCall({
807
1005
  objectId: objectId,
808
- versionHash: versionHash,
809
- context: context
810
- });
811
- }
812
- stateChannelApi = "elv_channelContentRequestContext";
813
- additionalParams = [JSON.stringify(audienceData)];
814
- _context7.next = 48;
815
- return this.MakeKMSCall({
816
- objectId: objectId,
817
- methodName: stateChannelApi,
818
- paramTypes: ["address", "address", "uint", "uint"],
819
- params: [this.client.signer.address, Utils.HashToAddress(objectId), value, Date.now()],
820
- additionalParams: additionalParams
821
- });
822
- case 48:
823
- payload = _context7.sent;
824
- _context7.next = 51;
825
- return this.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(payload)));
826
- case 51:
827
- signature = _context7.sent;
828
- multiSig = Utils.FormatSignature(signature);
829
- token = "".concat(payload, ".").concat(Utils.B64(multiSig));
830
- case 54:
831
- if (!this.noCache) {
832
- this.channelContentTokens[objectId] = {
833
- token: token,
834
- issuedAt: Date.now()
835
- };
836
- }
837
- return _context7.abrupt("return", token);
838
- case 56:
839
- case "end":
840
- return _context7.stop();
1006
+ methodName: stateChannelApi,
1007
+ paramTypes: ["address", "address", "uint", "uint"],
1008
+ params: [this.client.signer.address, Utils.HashToAddress(objectId), value, Date.now()],
1009
+ additionalParams: additionalParams
1010
+ });
1011
+
1012
+ case 48:
1013
+ payload = _context7.sent;
1014
+ _context7.next = 51;
1015
+ return this.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(payload)));
1016
+
1017
+ case 51:
1018
+ signature = _context7.sent;
1019
+ multiSig = Utils.FormatSignature(signature);
1020
+ token = "".concat(payload, ".").concat(Utils.B64(multiSig));
1021
+
1022
+ case 54:
1023
+ if (!this.noCache) {
1024
+ this.channelContentTokens[objectId] = {
1025
+ token: token,
1026
+ issuedAt: Date.now()
1027
+ };
1028
+ }
1029
+
1030
+ return _context7.abrupt("return", token);
1031
+
1032
+ case 56:
1033
+ case "end":
1034
+ return _context7.stop();
1035
+ }
841
1036
  }
842
1037
  }, _callee7, this, [[14, 22], [27, 33]]);
843
1038
  }));
1039
+
844
1040
  function GenerateChannelContentToken(_x7) {
845
1041
  return _GenerateChannelContentToken.apply(this, arguments);
846
1042
  }
1043
+
847
1044
  return GenerateChannelContentToken;
848
1045
  }()
849
1046
  }, {
@@ -851,35 +1048,42 @@ var AuthorizationClient = /*#__PURE__*/function () {
851
1048
  value: function () {
852
1049
  var _ChannelContentFinalize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref10) {
853
1050
  var objectId, versionHash, _ref10$percent, percent, result;
1051
+
854
1052
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
855
- while (1) switch (_context8.prev = _context8.next) {
856
- case 0:
857
- objectId = _ref10.objectId, versionHash = _ref10.versionHash, _ref10$percent = _ref10.percent, percent = _ref10$percent === void 0 ? 0 : _ref10$percent;
858
- this.Log("Making state channel finalize request: ".concat(objectId));
859
- _context8.next = 4;
860
- return this.MakeKMSCall({
861
- objectId: objectId,
862
- methodName: "elv_channelContentFinalizeContext",
863
- paramTypes: ["address", "address", "uint", "uint"],
864
- params: [this.client.signer.address, Utils.HashToAddress(objectId), percent, Date.now()],
865
- additionalParams: [JSON.stringify(this.AudienceData({
1053
+ while (1) {
1054
+ switch (_context8.prev = _context8.next) {
1055
+ case 0:
1056
+ objectId = _ref10.objectId, versionHash = _ref10.versionHash, _ref10$percent = _ref10.percent, percent = _ref10$percent === void 0 ? 0 : _ref10$percent;
1057
+ this.Log("Making state channel finalize request: ".concat(objectId));
1058
+ _context8.next = 4;
1059
+ return this.MakeKMSCall({
866
1060
  objectId: objectId,
867
- versionHash: versionHash
868
- }))]
869
- });
870
- case 4:
871
- result = _context8.sent;
872
- this.channelContentTokens[objectId] = undefined;
873
- return _context8.abrupt("return", result);
874
- case 7:
875
- case "end":
876
- return _context8.stop();
1061
+ methodName: "elv_channelContentFinalizeContext",
1062
+ paramTypes: ["address", "address", "uint", "uint"],
1063
+ params: [this.client.signer.address, Utils.HashToAddress(objectId), percent, Date.now()],
1064
+ additionalParams: [JSON.stringify(this.AudienceData({
1065
+ objectId: objectId,
1066
+ versionHash: versionHash
1067
+ }))]
1068
+ });
1069
+
1070
+ case 4:
1071
+ result = _context8.sent;
1072
+ this.channelContentTokens[objectId] = undefined;
1073
+ return _context8.abrupt("return", result);
1074
+
1075
+ case 7:
1076
+ case "end":
1077
+ return _context8.stop();
1078
+ }
877
1079
  }
878
1080
  }, _callee8, this);
879
1081
  }));
1082
+
880
1083
  function ChannelContentFinalize(_x8) {
881
1084
  return _ChannelContentFinalize.apply(this, arguments);
882
1085
  }
1086
+
883
1087
  return ChannelContentFinalize;
884
1088
  }()
885
1089
  }, {
@@ -888,57 +1092,72 @@ var AuthorizationClient = /*#__PURE__*/function () {
888
1092
  var _GenerateOauthChannelToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref11) {
889
1093
  var objectId, versionHash, token, fabricToken;
890
1094
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
891
- while (1) switch (_context9.prev = _context9.next) {
892
- case 0:
893
- objectId = _ref11.objectId, versionHash = _ref11.versionHash, token = _ref11.token;
894
- if (versionHash) {
895
- objectId = Utils.DecodeVersionHash(versionHash).objectId;
896
- }
897
- if (!(!this.noCache && this.channelContentTokens[objectId])) {
898
- _context9.next = 6;
899
- break;
900
- }
901
- if (!(this.channelContentTokens[objectId].issuedAt > Date.now() - 12 * 60 * 60 * 1000)) {
902
- _context9.next = 5;
903
- break;
904
- }
905
- return _context9.abrupt("return", this.channelContentTokens[objectId].token);
906
- case 5:
907
- // Token expired
908
- this.channelContentTokens[objectId] = undefined;
909
- case 6:
910
- _context9.next = 8;
911
- return this.MakeKMSRequest({
912
- objectId: objectId,
913
- versionHash: versionHash,
914
- method: "GET",
915
- path: UrlJoin("ks", "jwt", "q", objectId),
916
- bodyType: "NONE",
917
- headers: {
918
- Authorization: "Bearer ".concat(token)
919
- }
920
- });
921
- case 8:
922
- _context9.next = 10;
923
- return _context9.sent.text();
924
- case 10:
925
- fabricToken = _context9.sent;
926
- if (!this.noCache) {
927
- this.channelContentTokens[objectId] = {
928
- token: fabricToken,
929
- issuedAt: Date.now()
930
- };
931
- }
932
- return _context9.abrupt("return", fabricToken);
933
- case 13:
934
- case "end":
935
- return _context9.stop();
1095
+ while (1) {
1096
+ switch (_context9.prev = _context9.next) {
1097
+ case 0:
1098
+ objectId = _ref11.objectId, versionHash = _ref11.versionHash, token = _ref11.token;
1099
+
1100
+ if (versionHash) {
1101
+ objectId = Utils.DecodeVersionHash(versionHash).objectId;
1102
+ }
1103
+
1104
+ if (!(!this.noCache && this.channelContentTokens[objectId])) {
1105
+ _context9.next = 6;
1106
+ break;
1107
+ }
1108
+
1109
+ if (!(this.channelContentTokens[objectId].issuedAt > Date.now() - 12 * 60 * 60 * 1000)) {
1110
+ _context9.next = 5;
1111
+ break;
1112
+ }
1113
+
1114
+ return _context9.abrupt("return", this.channelContentTokens[objectId].token);
1115
+
1116
+ case 5:
1117
+ // Token expired
1118
+ this.channelContentTokens[objectId] = undefined;
1119
+
1120
+ case 6:
1121
+ _context9.next = 8;
1122
+ return this.MakeKMSRequest({
1123
+ objectId: objectId,
1124
+ versionHash: versionHash,
1125
+ method: "GET",
1126
+ path: UrlJoin("ks", "jwt", "q", objectId),
1127
+ bodyType: "NONE",
1128
+ headers: {
1129
+ Authorization: "Bearer ".concat(token)
1130
+ }
1131
+ });
1132
+
1133
+ case 8:
1134
+ _context9.next = 10;
1135
+ return _context9.sent.text();
1136
+
1137
+ case 10:
1138
+ fabricToken = _context9.sent;
1139
+
1140
+ if (!this.noCache) {
1141
+ this.channelContentTokens[objectId] = {
1142
+ token: fabricToken,
1143
+ issuedAt: Date.now()
1144
+ };
1145
+ }
1146
+
1147
+ return _context9.abrupt("return", fabricToken);
1148
+
1149
+ case 13:
1150
+ case "end":
1151
+ return _context9.stop();
1152
+ }
936
1153
  }
937
1154
  }, _callee9, this);
938
1155
  }));
1156
+
939
1157
  function GenerateOauthChannelToken(_x9) {
940
1158
  return _GenerateOauthChannelToken.apply(this, arguments);
941
1159
  }
1160
+
942
1161
  return GenerateOauthChannelToken;
943
1162
  }()
944
1163
  }, {
@@ -947,39 +1166,51 @@ var AuthorizationClient = /*#__PURE__*/function () {
947
1166
  var _IsV = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref12) {
948
1167
  var id, contractName;
949
1168
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
950
- while (1) switch (_context10.prev = _context10.next) {
951
- case 0:
952
- id = _ref12.id;
953
- if (!this.client.assumeV3) {
954
- _context10.next = 3;
955
- break;
956
- }
957
- return _context10.abrupt("return", true);
958
- case 3:
959
- _context10.next = 5;
960
- return this.client.ethClient.ContractName(Utils.HashToAddress(id), true);
961
- case 5:
962
- contractName = _context10.sent;
963
- if (!this.accessVersions[contractName]) {
964
- this.accessVersions[contractName] = this.ContractHasMethod({
965
- contractAddress: this.client.utils.HashToAddress(id),
966
- abi: this.CONTRACTS.v3[this.ACCESS_TYPES.ACCESSIBLE].abi,
967
- methodName: "accessRequestV3"
968
- });
969
- }
970
- _context10.next = 9;
971
- return this.accessVersions[contractName];
972
- case 9:
973
- return _context10.abrupt("return", _context10.sent);
974
- case 10:
975
- case "end":
976
- return _context10.stop();
1169
+ while (1) {
1170
+ switch (_context10.prev = _context10.next) {
1171
+ case 0:
1172
+ id = _ref12.id;
1173
+
1174
+ if (!this.client.assumeV3) {
1175
+ _context10.next = 3;
1176
+ break;
1177
+ }
1178
+
1179
+ return _context10.abrupt("return", true);
1180
+
1181
+ case 3:
1182
+ _context10.next = 5;
1183
+ return this.client.ethClient.ContractName(Utils.HashToAddress(id), true);
1184
+
1185
+ case 5:
1186
+ contractName = _context10.sent;
1187
+
1188
+ if (!this.accessVersions[contractName]) {
1189
+ this.accessVersions[contractName] = this.ContractHasMethod({
1190
+ contractAddress: this.client.utils.HashToAddress(id),
1191
+ abi: this.CONTRACTS.v3[this.ACCESS_TYPES.ACCESSIBLE].abi,
1192
+ methodName: "accessRequestV3"
1193
+ });
1194
+ }
1195
+
1196
+ _context10.next = 9;
1197
+ return this.accessVersions[contractName];
1198
+
1199
+ case 9:
1200
+ return _context10.abrupt("return", _context10.sent);
1201
+
1202
+ case 10:
1203
+ case "end":
1204
+ return _context10.stop();
1205
+ }
977
1206
  }
978
1207
  }, _callee10, this);
979
1208
  }));
1209
+
980
1210
  function IsV3(_x10) {
981
1211
  return _IsV.apply(this, arguments);
982
1212
  }
1213
+
983
1214
  return IsV3;
984
1215
  }()
985
1216
  }, {
@@ -988,108 +1219,130 @@ var AuthorizationClient = /*#__PURE__*/function () {
988
1219
  var _AccessInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref13) {
989
1220
  var accessType, publicKey, args, isV3, checkAccessCharge;
990
1221
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
991
- while (1) switch (_context11.prev = _context11.next) {
992
- case 0:
993
- accessType = _ref13.accessType, publicKey = _ref13.publicKey, args = _ref13.args, isV3 = _ref13.isV3;
994
- checkAccessCharge = false;
995
- if (accessType === ACCESS_TYPES.OBJECT) {
996
- checkAccessCharge = true;
997
- if (!isV3) {
998
- if (args && args.length > 0) {
999
- // Inject public key of requester
1000
- args[1] = this.client.signer._signingKey ? this.client.signer._signingKey().publicKey : "";
1001
- } else {
1002
- // Set default args
1003
- args = [0,
1004
- // Access level
1005
- this.client.signer._signingKey ? this.client.signer._signingKey().publicKey : "",
1006
- // Public key of requester
1007
- publicKey,
1008
- //cap.public_key,
1009
- [],
1010
- // Custom values
1011
- [] // Stakeholders
1012
- ];
1222
+ while (1) {
1223
+ switch (_context11.prev = _context11.next) {
1224
+ case 0:
1225
+ accessType = _ref13.accessType, publicKey = _ref13.publicKey, args = _ref13.args, isV3 = _ref13.isV3;
1226
+ checkAccessCharge = false;
1227
+
1228
+ if (accessType === ACCESS_TYPES.OBJECT) {
1229
+ checkAccessCharge = true;
1230
+
1231
+ if (!isV3) {
1232
+ if (args && args.length > 0) {
1233
+ // Inject public key of requester
1234
+ args[1] = this.client.signer._signingKey ? this.client.signer._signingKey().publicKey : "";
1235
+ } else {
1236
+ // Set default args
1237
+ args = [0, // Access level
1238
+ this.client.signer._signingKey ? this.client.signer._signingKey().publicKey : "", // Public key of requester
1239
+ publicKey, //cap.public_key,
1240
+ [], // Custom values
1241
+ [] // Stakeholders
1242
+ ];
1243
+ }
1013
1244
  }
1014
1245
  }
1015
- }
1016
-
1017
- if (isV3 && (!args || args.length === 0)) {
1018
- args = [[],
1019
- // customValues
1020
- [] // stakeholders
1021
- ];
1022
- }
1023
- return _context11.abrupt("return", {
1024
- accessArgs: args,
1025
- checkAccessCharge: checkAccessCharge
1026
- });
1027
- case 5:
1028
- case "end":
1029
- return _context11.stop();
1246
+
1247
+ if (isV3 && (!args || args.length === 0)) {
1248
+ args = [[], // customValues
1249
+ [] // stakeholders
1250
+ ];
1251
+ }
1252
+
1253
+ return _context11.abrupt("return", {
1254
+ accessArgs: args,
1255
+ checkAccessCharge: checkAccessCharge
1256
+ });
1257
+
1258
+ case 5:
1259
+ case "end":
1260
+ return _context11.stop();
1261
+ }
1030
1262
  }
1031
1263
  }, _callee11, this);
1032
1264
  }));
1265
+
1033
1266
  function AccessInfo(_x11) {
1034
1267
  return _AccessInfo.apply(this, arguments);
1035
1268
  }
1269
+
1036
1270
  return AccessInfo;
1037
1271
  }() // Determine type of ID based on contract version string
1272
+
1038
1273
  }, {
1039
1274
  key: "AccessType",
1040
1275
  value: function () {
1041
1276
  var _AccessType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(id) {
1042
1277
  var contractName, accessType;
1043
1278
  return _regeneratorRuntime.wrap(function _callee12$(_context12) {
1044
- while (1) switch (_context12.prev = _context12.next) {
1045
- case 0:
1046
- _context12.next = 2;
1047
- return this.client.ethClient.ContractName(Utils.HashToAddress(id));
1048
- case 2:
1049
- contractName = _context12.sent;
1050
- if (this.accessTypes[id]) {
1051
- _context12.next = 23;
1279
+ while (1) {
1280
+ switch (_context12.prev = _context12.next) {
1281
+ case 0:
1282
+ _context12.next = 2;
1283
+ return this.client.ethClient.ContractName(Utils.HashToAddress(id));
1284
+
1285
+ case 2:
1286
+ contractName = _context12.sent;
1287
+
1288
+ if (this.accessTypes[id]) {
1289
+ _context12.next = 23;
1290
+ break;
1291
+ }
1292
+
1293
+ _context12.t0 = contractName;
1294
+ _context12.next = _context12.t0 === "BaseContentSpace" ? 7 : _context12.t0 === "BaseLibrary" ? 9 : _context12.t0 === "BaseContentType" ? 11 : _context12.t0 === "BsAccessWallet" ? 13 : _context12.t0 === "BsAccessCtrlGrp" ? 15 : _context12.t0 === "BaseContent" ? 17 : _context12.t0 === "BaseTenantSpace" ? 19 : 21;
1052
1295
  break;
1053
- }
1054
- _context12.t0 = contractName;
1055
- _context12.next = _context12.t0 === "BaseContentSpace" ? 7 : _context12.t0 === "BaseLibrary" ? 9 : _context12.t0 === "BaseContentType" ? 11 : _context12.t0 === "BsAccessWallet" ? 13 : _context12.t0 === "BsAccessCtrlGrp" ? 15 : _context12.t0 === "BaseContent" ? 17 : _context12.t0 === "BaseTenantSpace" ? 19 : 21;
1056
- break;
1057
- case 7:
1058
- accessType = ACCESS_TYPES.SPACE;
1059
- return _context12.abrupt("break", 22);
1060
- case 9:
1061
- accessType = ACCESS_TYPES.LIBRARY;
1062
- return _context12.abrupt("break", 22);
1063
- case 11:
1064
- accessType = ACCESS_TYPES.TYPE;
1065
- return _context12.abrupt("break", 22);
1066
- case 13:
1067
- accessType = ACCESS_TYPES.WALLET;
1068
- return _context12.abrupt("break", 22);
1069
- case 15:
1070
- accessType = ACCESS_TYPES.GROUP;
1071
- return _context12.abrupt("break", 22);
1072
- case 17:
1073
- accessType = ACCESS_TYPES.OBJECT;
1074
- return _context12.abrupt("break", 22);
1075
- case 19:
1076
- accessType = ACCESS_TYPES.TENANT;
1077
- return _context12.abrupt("break", 22);
1078
- case 21:
1079
- accessType = ACCESS_TYPES.OTHER;
1080
- case 22:
1081
- this.accessTypes[id] = accessType;
1082
- case 23:
1083
- return _context12.abrupt("return", this.accessTypes[id]);
1084
- case 24:
1085
- case "end":
1086
- return _context12.stop();
1296
+
1297
+ case 7:
1298
+ accessType = ACCESS_TYPES.SPACE;
1299
+ return _context12.abrupt("break", 22);
1300
+
1301
+ case 9:
1302
+ accessType = ACCESS_TYPES.LIBRARY;
1303
+ return _context12.abrupt("break", 22);
1304
+
1305
+ case 11:
1306
+ accessType = ACCESS_TYPES.TYPE;
1307
+ return _context12.abrupt("break", 22);
1308
+
1309
+ case 13:
1310
+ accessType = ACCESS_TYPES.WALLET;
1311
+ return _context12.abrupt("break", 22);
1312
+
1313
+ case 15:
1314
+ accessType = ACCESS_TYPES.GROUP;
1315
+ return _context12.abrupt("break", 22);
1316
+
1317
+ case 17:
1318
+ accessType = ACCESS_TYPES.OBJECT;
1319
+ return _context12.abrupt("break", 22);
1320
+
1321
+ case 19:
1322
+ accessType = ACCESS_TYPES.TENANT;
1323
+ return _context12.abrupt("break", 22);
1324
+
1325
+ case 21:
1326
+ accessType = ACCESS_TYPES.OTHER;
1327
+
1328
+ case 22:
1329
+ this.accessTypes[id] = accessType;
1330
+
1331
+ case 23:
1332
+ return _context12.abrupt("return", this.accessTypes[id]);
1333
+
1334
+ case 24:
1335
+ case "end":
1336
+ return _context12.stop();
1337
+ }
1087
1338
  }
1088
1339
  }, _callee12, this);
1089
1340
  }));
1341
+
1090
1342
  function AccessType(_x12) {
1091
1343
  return _AccessType.apply(this, arguments);
1092
1344
  }
1345
+
1093
1346
  return AccessType;
1094
1347
  }()
1095
1348
  }, {
@@ -1097,113 +1350,143 @@ var AuthorizationClient = /*#__PURE__*/function () {
1097
1350
  value: function () {
1098
1351
  var _AccessComplete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref14) {
1099
1352
  var id, score, _yield$this$ContractI3, abi, isV3, address, requestId, event;
1353
+
1100
1354
  return _regeneratorRuntime.wrap(function _callee13$(_context13) {
1101
- while (1) switch (_context13.prev = _context13.next) {
1102
- case 0:
1103
- id = _ref14.id, score = _ref14.score;
1104
- this.Log("Calling access complete on ".concat(id, " with score ").concat(score));
1105
- _context13.next = 4;
1106
- return this.ContractInfo({
1107
- id: id
1108
- });
1109
- case 4:
1110
- _yield$this$ContractI3 = _context13.sent;
1111
- abi = _yield$this$ContractI3.abi;
1112
- isV3 = _yield$this$ContractI3.isV3;
1113
- address = Utils.HashToAddress(id);
1114
- requestId = this.requestIds[address];
1115
- if (requestId) {
1116
- _context13.next = 11;
1117
- break;
1118
- }
1119
- throw Error("Unknown request ID for " + id);
1120
- case 11:
1121
- if (!isV3) {
1122
- _context13.next = 17;
1355
+ while (1) {
1356
+ switch (_context13.prev = _context13.next) {
1357
+ case 0:
1358
+ id = _ref14.id, score = _ref14.score;
1359
+ this.Log("Calling access complete on ".concat(id, " with score ").concat(score));
1360
+ _context13.next = 4;
1361
+ return this.ContractInfo({
1362
+ id: id
1363
+ });
1364
+
1365
+ case 4:
1366
+ _yield$this$ContractI3 = _context13.sent;
1367
+ abi = _yield$this$ContractI3.abi;
1368
+ isV3 = _yield$this$ContractI3.isV3;
1369
+ address = Utils.HashToAddress(id);
1370
+ requestId = this.requestIds[address];
1371
+
1372
+ if (requestId) {
1373
+ _context13.next = 11;
1374
+ break;
1375
+ }
1376
+
1377
+ throw Error("Unknown request ID for " + id);
1378
+
1379
+ case 11:
1380
+ if (!isV3) {
1381
+ _context13.next = 17;
1382
+ break;
1383
+ }
1384
+
1385
+ _context13.next = 14;
1386
+ return this.client.CallContractMethodAndWait({
1387
+ contractAddress: address,
1388
+ abi: abi,
1389
+ methodName: "accessCompleteV3",
1390
+ methodArgs: [requestId, [], []]
1391
+ });
1392
+
1393
+ case 14:
1394
+ event = _context13.sent;
1395
+ _context13.next = 20;
1123
1396
  break;
1124
- }
1125
- _context13.next = 14;
1126
- return this.client.CallContractMethodAndWait({
1127
- contractAddress: address,
1128
- abi: abi,
1129
- methodName: "accessCompleteV3",
1130
- methodArgs: [requestId, [], []]
1131
- });
1132
- case 14:
1133
- event = _context13.sent;
1134
- _context13.next = 20;
1135
- break;
1136
- case 17:
1137
- _context13.next = 19;
1138
- return this.client.CallContractMethodAndWait({
1139
- contractAddress: address,
1140
- abi: abi,
1141
- methodName: isV3 ? "accessCompleteV3" : "accessComplete",
1142
- methodArgs: [requestId, score, ""]
1143
- });
1144
- case 19:
1145
- event = _context13.sent;
1146
- case 20:
1147
- delete this.requestIds[address];
1148
- delete this.accessTransactions[address];
1149
- return _context13.abrupt("return", event);
1150
- case 23:
1151
- case "end":
1152
- return _context13.stop();
1397
+
1398
+ case 17:
1399
+ _context13.next = 19;
1400
+ return this.client.CallContractMethodAndWait({
1401
+ contractAddress: address,
1402
+ abi: abi,
1403
+ methodName: isV3 ? "accessCompleteV3" : "accessComplete",
1404
+ methodArgs: [requestId, score, ""]
1405
+ });
1406
+
1407
+ case 19:
1408
+ event = _context13.sent;
1409
+
1410
+ case 20:
1411
+ delete this.requestIds[address];
1412
+ delete this.accessTransactions[address];
1413
+ return _context13.abrupt("return", event);
1414
+
1415
+ case 23:
1416
+ case "end":
1417
+ return _context13.stop();
1418
+ }
1153
1419
  }
1154
1420
  }, _callee13, this);
1155
1421
  }));
1422
+
1156
1423
  function AccessComplete(_x13) {
1157
1424
  return _AccessComplete.apply(this, arguments);
1158
1425
  }
1426
+
1159
1427
  return AccessComplete;
1160
- }() /* Utility methods */
1428
+ }()
1429
+ /* Utility methods */
1430
+
1161
1431
  }, {
1162
1432
  key: "ContractInfo",
1163
1433
  value: function () {
1164
1434
  var _ContractInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref15) {
1165
1435
  var id, address, isV3, version, accessType;
1166
1436
  return _regeneratorRuntime.wrap(function _callee14$(_context14) {
1167
- while (1) switch (_context14.prev = _context14.next) {
1168
- case 0:
1169
- id = _ref15.id, address = _ref15.address;
1170
- if (!address) {
1171
- address = Utils.HashToAddress(id);
1172
- }
1173
- if (!id) {
1174
- id = Utils.AddressToObjectId(address);
1175
- }
1176
- _context14.next = 5;
1177
- return this.IsV3({
1178
- id: id
1179
- });
1180
- case 5:
1181
- isV3 = _context14.sent;
1182
- version = isV3 ? "v3" : "v2";
1183
- _context14.next = 9;
1184
- return this.AccessType(id);
1185
- case 9:
1186
- accessType = _context14.sent;
1187
- if (!(accessType === this.ACCESS_TYPES.OTHER)) {
1188
- _context14.next = 12;
1189
- break;
1190
- }
1191
- return _context14.abrupt("return", {});
1192
- case 12:
1193
- return _context14.abrupt("return", {
1194
- isV3: isV3,
1195
- accessType: accessType,
1196
- abi: this.CONTRACTS[version][accessType].abi
1197
- });
1198
- case 13:
1199
- case "end":
1200
- return _context14.stop();
1437
+ while (1) {
1438
+ switch (_context14.prev = _context14.next) {
1439
+ case 0:
1440
+ id = _ref15.id, address = _ref15.address;
1441
+
1442
+ if (!address) {
1443
+ address = Utils.HashToAddress(id);
1444
+ }
1445
+
1446
+ if (!id) {
1447
+ id = Utils.AddressToObjectId(address);
1448
+ }
1449
+
1450
+ _context14.next = 5;
1451
+ return this.IsV3({
1452
+ id: id
1453
+ });
1454
+
1455
+ case 5:
1456
+ isV3 = _context14.sent;
1457
+ version = isV3 ? "v3" : "v2";
1458
+ _context14.next = 9;
1459
+ return this.AccessType(id);
1460
+
1461
+ case 9:
1462
+ accessType = _context14.sent;
1463
+
1464
+ if (!(accessType === this.ACCESS_TYPES.OTHER)) {
1465
+ _context14.next = 12;
1466
+ break;
1467
+ }
1468
+
1469
+ return _context14.abrupt("return", {});
1470
+
1471
+ case 12:
1472
+ return _context14.abrupt("return", {
1473
+ isV3: isV3,
1474
+ accessType: accessType,
1475
+ abi: this.CONTRACTS[version][accessType].abi
1476
+ });
1477
+
1478
+ case 13:
1479
+ case "end":
1480
+ return _context14.stop();
1481
+ }
1201
1482
  }
1202
1483
  }, _callee14, this);
1203
1484
  }));
1485
+
1204
1486
  function ContractInfo(_x14) {
1205
1487
  return _ContractInfo.apply(this, arguments);
1206
1488
  }
1489
+
1207
1490
  return ContractInfo;
1208
1491
  }()
1209
1492
  }, {
@@ -1211,36 +1494,44 @@ var AuthorizationClient = /*#__PURE__*/function () {
1211
1494
  value: function () {
1212
1495
  var _GetAccessCharge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref16) {
1213
1496
  var objectId, args, _yield$this$ContractI4, abi, info;
1497
+
1214
1498
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1215
- while (1) switch (_context15.prev = _context15.next) {
1216
- case 0:
1217
- objectId = _ref16.objectId, args = _ref16.args;
1218
- _context15.next = 3;
1219
- return this.ContractInfo({
1220
- id: objectId
1221
- });
1222
- case 3:
1223
- _yield$this$ContractI4 = _context15.sent;
1224
- abi = _yield$this$ContractI4.abi;
1225
- _context15.next = 7;
1226
- return this.client.CallContractMethod({
1227
- contractAddress: Utils.HashToAddress(objectId),
1228
- abi: abi,
1229
- methodName: "getAccessInfo",
1230
- methodArgs: args
1231
- });
1232
- case 7:
1233
- info = _context15.sent;
1234
- return _context15.abrupt("return", info[1] === 0 ? 0 : info[2]);
1235
- case 9:
1236
- case "end":
1237
- return _context15.stop();
1499
+ while (1) {
1500
+ switch (_context15.prev = _context15.next) {
1501
+ case 0:
1502
+ objectId = _ref16.objectId, args = _ref16.args;
1503
+ _context15.next = 3;
1504
+ return this.ContractInfo({
1505
+ id: objectId
1506
+ });
1507
+
1508
+ case 3:
1509
+ _yield$this$ContractI4 = _context15.sent;
1510
+ abi = _yield$this$ContractI4.abi;
1511
+ _context15.next = 7;
1512
+ return this.client.CallContractMethod({
1513
+ contractAddress: Utils.HashToAddress(objectId),
1514
+ abi: abi,
1515
+ methodName: "getAccessInfo",
1516
+ methodArgs: args
1517
+ });
1518
+
1519
+ case 7:
1520
+ info = _context15.sent;
1521
+ return _context15.abrupt("return", info[1] === 0 ? 0 : info[2]);
1522
+
1523
+ case 9:
1524
+ case "end":
1525
+ return _context15.stop();
1526
+ }
1238
1527
  }
1239
1528
  }, _callee15, this);
1240
1529
  }));
1530
+
1241
1531
  function GetAccessCharge(_x15) {
1242
1532
  return _GetAccessCharge.apply(this, arguments);
1243
1533
  }
1534
+
1244
1535
  return GetAccessCharge;
1245
1536
  }()
1246
1537
  }, {
@@ -1249,36 +1540,46 @@ var AuthorizationClient = /*#__PURE__*/function () {
1249
1540
  var _Owner = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref17) {
1250
1541
  var id, address, ownerAddress;
1251
1542
  return _regeneratorRuntime.wrap(function _callee16$(_context16) {
1252
- while (1) switch (_context16.prev = _context16.next) {
1253
- case 0:
1254
- id = _ref17.id, address = _ref17.address;
1255
- if (this.client.signer) {
1256
- _context16.next = 3;
1257
- break;
1258
- }
1259
- return _context16.abrupt("return", false);
1260
- case 3:
1261
- if (id) {
1262
- address = Utils.HashToAddress(id);
1263
- }
1264
- _context16.next = 6;
1265
- return this.client.CallContractMethod({
1266
- contractAddress: address,
1267
- methodName: "owner",
1268
- methodArgs: []
1269
- });
1270
- case 6:
1271
- ownerAddress = _context16.sent;
1272
- return _context16.abrupt("return", Utils.FormatAddress(ownerAddress));
1273
- case 8:
1274
- case "end":
1275
- return _context16.stop();
1543
+ while (1) {
1544
+ switch (_context16.prev = _context16.next) {
1545
+ case 0:
1546
+ id = _ref17.id, address = _ref17.address;
1547
+
1548
+ if (this.client.signer) {
1549
+ _context16.next = 3;
1550
+ break;
1551
+ }
1552
+
1553
+ return _context16.abrupt("return", false);
1554
+
1555
+ case 3:
1556
+ if (id) {
1557
+ address = Utils.HashToAddress(id);
1558
+ }
1559
+
1560
+ _context16.next = 6;
1561
+ return this.client.CallContractMethod({
1562
+ contractAddress: address,
1563
+ methodName: "owner",
1564
+ methodArgs: []
1565
+ });
1566
+
1567
+ case 6:
1568
+ ownerAddress = _context16.sent;
1569
+ return _context16.abrupt("return", Utils.FormatAddress(ownerAddress));
1570
+
1571
+ case 8:
1572
+ case "end":
1573
+ return _context16.stop();
1574
+ }
1276
1575
  }
1277
1576
  }, _callee16, this);
1278
1577
  }));
1578
+
1279
1579
  function Owner(_x16) {
1280
1580
  return _Owner.apply(this, arguments);
1281
1581
  }
1582
+
1282
1583
  return Owner;
1283
1584
  }()
1284
1585
  }, {
@@ -1286,39 +1587,51 @@ var AuthorizationClient = /*#__PURE__*/function () {
1286
1587
  value: function () {
1287
1588
  var _Sign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(message) {
1288
1589
  return _regeneratorRuntime.wrap(function _callee17$(_context17) {
1289
- while (1) switch (_context17.prev = _context17.next) {
1290
- case 0:
1291
- _context17.t0 = Ethers.utils;
1292
- if (!this.client.signer.signDigest) {
1293
- _context17.next = 7;
1590
+ while (1) {
1591
+ switch (_context17.prev = _context17.next) {
1592
+ case 0:
1593
+ _context17.t0 = Ethers.utils;
1594
+
1595
+ if (!this.client.signer.signDigest) {
1596
+ _context17.next = 7;
1597
+ break;
1598
+ }
1599
+
1600
+ _context17.next = 4;
1601
+ return this.client.signer.signDigest(message);
1602
+
1603
+ case 4:
1604
+ _context17.t1 = _context17.sent;
1605
+ _context17.next = 10;
1294
1606
  break;
1295
- }
1296
- _context17.next = 4;
1297
- return this.client.signer.signDigest(message);
1298
- case 4:
1299
- _context17.t1 = _context17.sent;
1300
- _context17.next = 10;
1301
- break;
1302
- case 7:
1303
- _context17.next = 9;
1304
- return this.client.signer._signingKey().signDigest(message);
1305
- case 9:
1306
- _context17.t1 = _context17.sent;
1307
- case 10:
1308
- _context17.t2 = _context17.t1;
1309
- _context17.next = 13;
1310
- return _context17.t0.joinSignature.call(_context17.t0, _context17.t2);
1311
- case 13:
1312
- return _context17.abrupt("return", _context17.sent);
1313
- case 14:
1314
- case "end":
1315
- return _context17.stop();
1607
+
1608
+ case 7:
1609
+ _context17.next = 9;
1610
+ return this.client.signer._signingKey().signDigest(message);
1611
+
1612
+ case 9:
1613
+ _context17.t1 = _context17.sent;
1614
+
1615
+ case 10:
1616
+ _context17.t2 = _context17.t1;
1617
+ _context17.next = 13;
1618
+ return _context17.t0.joinSignature.call(_context17.t0, _context17.t2);
1619
+
1620
+ case 13:
1621
+ return _context17.abrupt("return", _context17.sent);
1622
+
1623
+ case 14:
1624
+ case "end":
1625
+ return _context17.stop();
1626
+ }
1316
1627
  }
1317
1628
  }, _callee17, this);
1318
1629
  }));
1630
+
1319
1631
  function Sign(_x17) {
1320
1632
  return _Sign.apply(this, arguments);
1321
1633
  }
1634
+
1322
1635
  return Sign;
1323
1636
  }()
1324
1637
  }, {
@@ -1326,43 +1639,56 @@ var AuthorizationClient = /*#__PURE__*/function () {
1326
1639
  value: function () {
1327
1640
  var _KMSAddress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref18) {
1328
1641
  var objectId, versionHash, _yield$this$ContractI5, abi;
1642
+
1329
1643
  return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1330
- while (1) switch (_context18.prev = _context18.next) {
1331
- case 0:
1332
- objectId = _ref18.objectId, versionHash = _ref18.versionHash;
1333
- if (versionHash) {
1334
- objectId = Utils.DecodeVersionHash(versionHash).objectId;
1335
- }
1336
- _context18.next = 4;
1337
- return this.ContractInfo({
1338
- id: objectId
1339
- });
1340
- case 4:
1341
- _yield$this$ContractI5 = _context18.sent;
1342
- abi = _yield$this$ContractI5.abi;
1343
- if (abi) {
1344
- _context18.next = 8;
1345
- break;
1346
- }
1347
- throw Error("Unable to determine contract info for ".concat(objectId, " - wrong network?"));
1348
- case 8:
1349
- _context18.next = 10;
1350
- return this.client.CallContractMethod({
1351
- contractAddress: Utils.HashToAddress(objectId),
1352
- abi: abi,
1353
- methodName: "addressKMS"
1354
- });
1355
- case 10:
1356
- return _context18.abrupt("return", _context18.sent);
1357
- case 11:
1358
- case "end":
1359
- return _context18.stop();
1644
+ while (1) {
1645
+ switch (_context18.prev = _context18.next) {
1646
+ case 0:
1647
+ objectId = _ref18.objectId, versionHash = _ref18.versionHash;
1648
+
1649
+ if (versionHash) {
1650
+ objectId = Utils.DecodeVersionHash(versionHash).objectId;
1651
+ }
1652
+
1653
+ _context18.next = 4;
1654
+ return this.ContractInfo({
1655
+ id: objectId
1656
+ });
1657
+
1658
+ case 4:
1659
+ _yield$this$ContractI5 = _context18.sent;
1660
+ abi = _yield$this$ContractI5.abi;
1661
+
1662
+ if (abi) {
1663
+ _context18.next = 8;
1664
+ break;
1665
+ }
1666
+
1667
+ throw Error("Unable to determine contract info for ".concat(objectId, " - wrong network?"));
1668
+
1669
+ case 8:
1670
+ _context18.next = 10;
1671
+ return this.client.CallContractMethod({
1672
+ contractAddress: Utils.HashToAddress(objectId),
1673
+ abi: abi,
1674
+ methodName: "addressKMS"
1675
+ });
1676
+
1677
+ case 10:
1678
+ return _context18.abrupt("return", _context18.sent);
1679
+
1680
+ case 11:
1681
+ case "end":
1682
+ return _context18.stop();
1683
+ }
1360
1684
  }
1361
1685
  }, _callee18, this);
1362
1686
  }));
1687
+
1363
1688
  function KMSAddress(_x18) {
1364
1689
  return _KMSAddress.apply(this, arguments);
1365
1690
  }
1691
+
1366
1692
  return KMSAddress;
1367
1693
  }()
1368
1694
  }, {
@@ -1370,397 +1696,497 @@ var AuthorizationClient = /*#__PURE__*/function () {
1370
1696
  value: function () {
1371
1697
  var _KMSInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(_ref19) {
1372
1698
  var objectId, versionHash, kmsId, KMSInfo, _yield$this$ContractI6, abi, _yield$this$ContractI7, _abi, publicKey;
1699
+
1373
1700
  return _regeneratorRuntime.wrap(function _callee19$(_context19) {
1374
- while (1) switch (_context19.prev = _context19.next) {
1375
- case 0:
1376
- objectId = _ref19.objectId, versionHash = _ref19.versionHash, kmsId = _ref19.kmsId;
1377
- if (!kmsId) {
1378
- _context19.next = 11;
1701
+ while (1) {
1702
+ switch (_context19.prev = _context19.next) {
1703
+ case 0:
1704
+ objectId = _ref19.objectId, versionHash = _ref19.versionHash, kmsId = _ref19.kmsId;
1705
+
1706
+ if (!kmsId) {
1707
+ _context19.next = 11;
1708
+ break;
1709
+ }
1710
+
1711
+ _context19.next = 4;
1712
+ return this.ContractInfo({
1713
+ address: this.client.contentSpaceAddress
1714
+ });
1715
+
1716
+ case 4:
1717
+ _yield$this$ContractI6 = _context19.sent;
1718
+ abi = _yield$this$ContractI6.abi;
1719
+ _context19.next = 8;
1720
+ return this.client.CallContractMethod({
1721
+ contractAddress: this.client.contentSpaceAddress,
1722
+ abi: abi,
1723
+ methodName: "getKMSInfo",
1724
+ methodArgs: [kmsId, []],
1725
+ formatArguments: false
1726
+ });
1727
+
1728
+ case 8:
1729
+ KMSInfo = _context19.sent;
1730
+ _context19.next = 19;
1379
1731
  break;
1380
- }
1381
- _context19.next = 4;
1382
- return this.ContractInfo({
1383
- address: this.client.contentSpaceAddress
1384
- });
1385
- case 4:
1386
- _yield$this$ContractI6 = _context19.sent;
1387
- abi = _yield$this$ContractI6.abi;
1388
- _context19.next = 8;
1389
- return this.client.CallContractMethod({
1390
- contractAddress: this.client.contentSpaceAddress,
1391
- abi: abi,
1392
- methodName: "getKMSInfo",
1393
- methodArgs: [kmsId, []],
1394
- formatArguments: false
1395
- });
1396
- case 8:
1397
- KMSInfo = _context19.sent;
1398
- _context19.next = 19;
1399
- break;
1400
- case 11:
1401
- if (versionHash) {
1402
- objectId = Utils.DecodeVersionHash(versionHash).objectId;
1403
- }
1404
- _context19.next = 14;
1405
- return this.ContractInfo({
1406
- id: objectId
1407
- });
1408
- case 14:
1409
- _yield$this$ContractI7 = _context19.sent;
1410
- _abi = _yield$this$ContractI7.abi;
1411
- _context19.next = 18;
1412
- return this.client.CallContractMethod({
1413
- contractAddress: Utils.HashToAddress(objectId),
1414
- abi: _abi,
1415
- methodName: "getKMSInfo",
1416
- methodArgs: [[]],
1417
- formatArguments: false
1418
- });
1419
- case 18:
1420
- KMSInfo = _context19.sent;
1421
- case 19:
1422
- // Public key is compressed and hashed
1423
- publicKey = Ethers.utils.computePublicKey(Utils.HashToAddress(KMSInfo[1]), false);
1424
- return _context19.abrupt("return", {
1425
- urls: KMSInfo[0].split(","),
1426
- publicKey: publicKey
1427
- });
1428
- case 21:
1429
- case "end":
1430
- return _context19.stop();
1732
+
1733
+ case 11:
1734
+ if (versionHash) {
1735
+ objectId = Utils.DecodeVersionHash(versionHash).objectId;
1736
+ }
1737
+
1738
+ _context19.next = 14;
1739
+ return this.ContractInfo({
1740
+ id: objectId
1741
+ });
1742
+
1743
+ case 14:
1744
+ _yield$this$ContractI7 = _context19.sent;
1745
+ _abi = _yield$this$ContractI7.abi;
1746
+ _context19.next = 18;
1747
+ return this.client.CallContractMethod({
1748
+ contractAddress: Utils.HashToAddress(objectId),
1749
+ abi: _abi,
1750
+ methodName: "getKMSInfo",
1751
+ methodArgs: [[]],
1752
+ formatArguments: false
1753
+ });
1754
+
1755
+ case 18:
1756
+ KMSInfo = _context19.sent;
1757
+
1758
+ case 19:
1759
+ // Public key is compressed and hashed
1760
+ publicKey = Ethers.utils.computePublicKey(Utils.HashToAddress(KMSInfo[1]), false);
1761
+ return _context19.abrupt("return", {
1762
+ urls: KMSInfo[0].split(","),
1763
+ publicKey: publicKey
1764
+ });
1765
+
1766
+ case 21:
1767
+ case "end":
1768
+ return _context19.stop();
1769
+ }
1431
1770
  }
1432
1771
  }, _callee19, this);
1433
1772
  }));
1773
+
1434
1774
  function KMSInfo(_x19) {
1435
1775
  return _KMSInfo.apply(this, arguments);
1436
1776
  }
1777
+
1437
1778
  return KMSInfo;
1438
1779
  }() // Retrieve symmetric key for object
1780
+
1439
1781
  }, {
1440
1782
  key: "RetrieveConk",
1441
1783
  value: function () {
1442
1784
  var _RetrieveConk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(_ref20) {
1443
1785
  var libraryId, objectId, kmsAddress, kmsCapId, kmsCap, cap;
1444
1786
  return _regeneratorRuntime.wrap(function _callee20$(_context20) {
1445
- while (1) switch (_context20.prev = _context20.next) {
1446
- case 0:
1447
- libraryId = _ref20.libraryId, objectId = _ref20.objectId;
1448
- if (libraryId) {
1449
- _context20.next = 5;
1450
- break;
1451
- }
1452
- _context20.next = 4;
1453
- return this.client.ContentObjectLibraryId({
1454
- objectId: objectId
1455
- });
1456
- case 4:
1457
- libraryId = _context20.sent;
1458
- case 5:
1459
- _context20.next = 7;
1460
- return this.KMSAddress({
1461
- objectId: objectId
1462
- });
1463
- case 7:
1464
- kmsAddress = _context20.sent;
1465
- kmsCapId = "eluv.caps.ikms".concat(Utils.AddressToHash(kmsAddress));
1466
- _context20.next = 11;
1467
- return this.client.ContentObjectMetadata({
1468
- libraryId: libraryId,
1469
- objectId: objectId,
1470
- metadataSubtree: kmsCapId
1471
- });
1472
- case 11:
1473
- kmsCap = _context20.sent;
1474
- if (kmsCap) {
1475
- _context20.next = 14;
1476
- break;
1477
- }
1478
- throw Error("No KMS key set for this object");
1479
- case 14:
1480
- _context20.next = 16;
1481
- return this.MakeKMSCall({
1482
- objectId: objectId,
1483
- methodName: "elv_getEncryptionKey",
1484
- paramTypes: ["string", "string", "string", "string", "string"],
1485
- params: [this.client.contentSpaceId, libraryId, objectId, kmsCap || "", ""]
1486
- });
1487
- case 16:
1488
- cap = _context20.sent;
1489
- return _context20.abrupt("return", JSON.parse(Utils.FromB58(cap.replace(/^kp__/, "")).toString("utf-8")));
1490
- case 18:
1491
- case "end":
1492
- return _context20.stop();
1787
+ while (1) {
1788
+ switch (_context20.prev = _context20.next) {
1789
+ case 0:
1790
+ libraryId = _ref20.libraryId, objectId = _ref20.objectId;
1791
+
1792
+ if (libraryId) {
1793
+ _context20.next = 5;
1794
+ break;
1795
+ }
1796
+
1797
+ _context20.next = 4;
1798
+ return this.client.ContentObjectLibraryId({
1799
+ objectId: objectId
1800
+ });
1801
+
1802
+ case 4:
1803
+ libraryId = _context20.sent;
1804
+
1805
+ case 5:
1806
+ _context20.next = 7;
1807
+ return this.KMSAddress({
1808
+ objectId: objectId
1809
+ });
1810
+
1811
+ case 7:
1812
+ kmsAddress = _context20.sent;
1813
+ kmsCapId = "eluv.caps.ikms".concat(Utils.AddressToHash(kmsAddress));
1814
+ _context20.next = 11;
1815
+ return this.client.ContentObjectMetadata({
1816
+ libraryId: libraryId,
1817
+ objectId: objectId,
1818
+ metadataSubtree: kmsCapId
1819
+ });
1820
+
1821
+ case 11:
1822
+ kmsCap = _context20.sent;
1823
+
1824
+ if (kmsCap) {
1825
+ _context20.next = 14;
1826
+ break;
1827
+ }
1828
+
1829
+ throw Error("No KMS key set for this object");
1830
+
1831
+ case 14:
1832
+ _context20.next = 16;
1833
+ return this.MakeKMSCall({
1834
+ objectId: objectId,
1835
+ methodName: "elv_getEncryptionKey",
1836
+ paramTypes: ["string", "string", "string", "string", "string"],
1837
+ params: [this.client.contentSpaceId, libraryId, objectId, kmsCap || "", ""]
1838
+ });
1839
+
1840
+ case 16:
1841
+ cap = _context20.sent;
1842
+ return _context20.abrupt("return", JSON.parse(Utils.FromB58(cap.replace(/^kp__/, "")).toString("utf-8")));
1843
+
1844
+ case 18:
1845
+ case "end":
1846
+ return _context20.stop();
1847
+ }
1493
1848
  }
1494
1849
  }, _callee20, this);
1495
1850
  }));
1851
+
1496
1852
  function RetrieveConk(_x20) {
1497
1853
  return _RetrieveConk.apply(this, arguments);
1498
1854
  }
1855
+
1499
1856
  return RetrieveConk;
1500
1857
  }() // Retrieve symmetric key for object
1858
+
1501
1859
  }, {
1502
1860
  key: "RetrieveReencryptionSymmetricKey",
1503
1861
  value: function () {
1504
1862
  var _RetrieveReencryptionSymmetricKey = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(_ref21) {
1505
1863
  var libraryId, objectId, kmsAddress, kmsCapId, kmsCap;
1506
1864
  return _regeneratorRuntime.wrap(function _callee21$(_context21) {
1507
- while (1) switch (_context21.prev = _context21.next) {
1508
- case 0:
1509
- libraryId = _ref21.libraryId, objectId = _ref21.objectId;
1510
- if (libraryId) {
1511
- _context21.next = 5;
1512
- break;
1513
- }
1514
- _context21.next = 4;
1515
- return this.client.ContentObjectLibraryId({
1516
- objectId: objectId
1517
- });
1518
- case 4:
1519
- libraryId = _context21.sent;
1520
- case 5:
1521
- _context21.next = 7;
1522
- return this.KMSAddress({
1523
- objectId: objectId
1524
- });
1525
- case 7:
1526
- kmsAddress = _context21.sent;
1527
- kmsCapId = "eluv.caps.ikms".concat(Utils.AddressToHash(kmsAddress));
1528
- _context21.next = 11;
1529
- return this.client.ContentObjectMetadata({
1530
- libraryId: libraryId,
1531
- objectId: objectId,
1532
- metadataSubtree: kmsCapId
1533
- });
1534
- case 11:
1535
- kmsCap = _context21.sent;
1536
- if (kmsCap) {
1537
- _context21.next = 14;
1538
- break;
1539
- }
1540
- throw Error("No KMS key set for this object");
1541
- case 14:
1542
- _context21.next = 16;
1543
- return this.MakeKMSCall({
1544
- objectId: objectId,
1545
- methodName: "elv_getSymmetricKeyAuth",
1546
- paramTypes: ["string", "string", "string", "string", "string"],
1547
- params: [this.client.contentSpaceId, libraryId, objectId, kmsCap || "", ""]
1548
- });
1549
- case 16:
1550
- return _context21.abrupt("return", _context21.sent);
1551
- case 17:
1552
- case "end":
1553
- return _context21.stop();
1865
+ while (1) {
1866
+ switch (_context21.prev = _context21.next) {
1867
+ case 0:
1868
+ libraryId = _ref21.libraryId, objectId = _ref21.objectId;
1869
+
1870
+ if (libraryId) {
1871
+ _context21.next = 5;
1872
+ break;
1873
+ }
1874
+
1875
+ _context21.next = 4;
1876
+ return this.client.ContentObjectLibraryId({
1877
+ objectId: objectId
1878
+ });
1879
+
1880
+ case 4:
1881
+ libraryId = _context21.sent;
1882
+
1883
+ case 5:
1884
+ _context21.next = 7;
1885
+ return this.KMSAddress({
1886
+ objectId: objectId
1887
+ });
1888
+
1889
+ case 7:
1890
+ kmsAddress = _context21.sent;
1891
+ kmsCapId = "eluv.caps.ikms".concat(Utils.AddressToHash(kmsAddress));
1892
+ _context21.next = 11;
1893
+ return this.client.ContentObjectMetadata({
1894
+ libraryId: libraryId,
1895
+ objectId: objectId,
1896
+ metadataSubtree: kmsCapId
1897
+ });
1898
+
1899
+ case 11:
1900
+ kmsCap = _context21.sent;
1901
+
1902
+ if (kmsCap) {
1903
+ _context21.next = 14;
1904
+ break;
1905
+ }
1906
+
1907
+ throw Error("No KMS key set for this object");
1908
+
1909
+ case 14:
1910
+ _context21.next = 16;
1911
+ return this.MakeKMSCall({
1912
+ objectId: objectId,
1913
+ methodName: "elv_getSymmetricKeyAuth",
1914
+ paramTypes: ["string", "string", "string", "string", "string"],
1915
+ params: [this.client.contentSpaceId, libraryId, objectId, kmsCap || "", ""]
1916
+ });
1917
+
1918
+ case 16:
1919
+ return _context21.abrupt("return", _context21.sent);
1920
+
1921
+ case 17:
1922
+ case "end":
1923
+ return _context21.stop();
1924
+ }
1554
1925
  }
1555
1926
  }, _callee21, this);
1556
1927
  }));
1928
+
1557
1929
  function RetrieveReencryptionSymmetricKey(_x21) {
1558
1930
  return _RetrieveReencryptionSymmetricKey.apply(this, arguments);
1559
1931
  }
1932
+
1560
1933
  return RetrieveReencryptionSymmetricKey;
1561
1934
  }() // Make an RPC call to the KMS with signed parameters
1935
+
1562
1936
  }, {
1563
1937
  key: "MakeKMSCall",
1564
1938
  value: function () {
1565
1939
  var _MakeKMSCall = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref22) {
1566
1940
  var kmsId, tenantId, objectId, versionHash, methodName, params, paramTypes, _ref22$additionalPara, additionalParams, _ref22$signature, signature, packedHash, KMSUrls, i, kmsUrl;
1941
+
1567
1942
  return _regeneratorRuntime.wrap(function _callee22$(_context22) {
1568
- while (1) switch (_context22.prev = _context22.next) {
1569
- case 0:
1570
- kmsId = _ref22.kmsId, tenantId = _ref22.tenantId, objectId = _ref22.objectId, versionHash = _ref22.versionHash, methodName = _ref22.methodName, params = _ref22.params, paramTypes = _ref22.paramTypes, _ref22$additionalPara = _ref22.additionalParams, additionalParams = _ref22$additionalPara === void 0 ? [] : _ref22$additionalPara, _ref22$signature = _ref22.signature, signature = _ref22$signature === void 0 ? true : _ref22$signature;
1571
- if (versionHash) {
1572
- objectId = Utils.DecodeVersionHash(versionHash).objectId;
1573
- }
1574
- if (objectId) {
1575
- _context22.next = 10;
1576
- break;
1577
- }
1578
- _context22.t0 = "ikms";
1579
- _context22.t1 = Utils;
1580
- _context22.next = 7;
1581
- return this.client.DefaultKMSAddress({
1582
- tenantId: tenantId
1583
- });
1584
- case 7:
1585
- _context22.t2 = _context22.sent;
1586
- _context22.t3 = _context22.t1.AddressToHash.call(_context22.t1, _context22.t2);
1587
- kmsId = _context22.t0.concat.call(_context22.t0, _context22.t3);
1588
- case 10:
1589
- if (!signature) {
1590
- _context22.next = 17;
1591
- break;
1592
- }
1593
- packedHash = Ethers.utils.solidityKeccak256(paramTypes, params);
1594
- _context22.t4 = params;
1595
- _context22.next = 15;
1596
- return this.Sign(packedHash);
1597
- case 15:
1598
- _context22.t5 = _context22.sent;
1599
- _context22.t4.push.call(_context22.t4, _context22.t5);
1600
- case 17:
1601
- params = params.concat(additionalParams);
1602
- _context22.next = 20;
1603
- return this.KMSInfo({
1604
- kmsId: kmsId,
1605
- objectId: objectId,
1606
- versionHash: versionHash
1607
- });
1608
- case 20:
1609
- KMSUrls = _context22.sent.urls;
1610
- i = 0;
1611
- case 22:
1612
- if (!(i < KMSUrls.length)) {
1613
- _context22.next = 40;
1614
- break;
1615
- }
1616
- _context22.prev = 23;
1617
- this.Log("Making KMS request:\n URL: ".concat(KMSUrls[i], "\n Method: ").concat(methodName, "\n Params: ").concat(params.join(", ")));
1618
- kmsUrl = KMSUrls[i];
1619
- if (!this.providers[kmsUrl]) {
1620
- this.providers[kmsUrl] = new Ethers.providers.JsonRpcProvider(kmsUrl, this.client.networkId);
1621
- }
1622
- _context22.next = 29;
1623
- return this.providers[kmsUrl].send(methodName, params);
1624
- case 29:
1625
- return _context22.abrupt("return", _context22.sent);
1626
- case 32:
1627
- _context22.prev = 32;
1628
- _context22.t6 = _context22["catch"](23);
1629
- this.Log("KMS Call Error: ".concat(_context22.t6), true);
1630
-
1631
- // If the request has been attempted on all KMS urls, throw the error
1632
- if (!(i === KMSUrls.length - 1)) {
1633
- _context22.next = 37;
1943
+ while (1) {
1944
+ switch (_context22.prev = _context22.next) {
1945
+ case 0:
1946
+ kmsId = _ref22.kmsId, tenantId = _ref22.tenantId, objectId = _ref22.objectId, versionHash = _ref22.versionHash, methodName = _ref22.methodName, params = _ref22.params, paramTypes = _ref22.paramTypes, _ref22$additionalPara = _ref22.additionalParams, additionalParams = _ref22$additionalPara === void 0 ? [] : _ref22$additionalPara, _ref22$signature = _ref22.signature, signature = _ref22$signature === void 0 ? true : _ref22$signature;
1947
+
1948
+ if (versionHash) {
1949
+ objectId = Utils.DecodeVersionHash(versionHash).objectId;
1950
+ }
1951
+
1952
+ if (objectId) {
1953
+ _context22.next = 10;
1954
+ break;
1955
+ }
1956
+
1957
+ _context22.t0 = "ikms";
1958
+ _context22.t1 = Utils;
1959
+ _context22.next = 7;
1960
+ return this.client.DefaultKMSAddress({
1961
+ tenantId: tenantId
1962
+ });
1963
+
1964
+ case 7:
1965
+ _context22.t2 = _context22.sent;
1966
+ _context22.t3 = _context22.t1.AddressToHash.call(_context22.t1, _context22.t2);
1967
+ kmsId = _context22.t0.concat.call(_context22.t0, _context22.t3);
1968
+
1969
+ case 10:
1970
+ if (!signature) {
1971
+ _context22.next = 17;
1972
+ break;
1973
+ }
1974
+
1975
+ packedHash = Ethers.utils.solidityKeccak256(paramTypes, params);
1976
+ _context22.t4 = params;
1977
+ _context22.next = 15;
1978
+ return this.Sign(packedHash);
1979
+
1980
+ case 15:
1981
+ _context22.t5 = _context22.sent;
1982
+
1983
+ _context22.t4.push.call(_context22.t4, _context22.t5);
1984
+
1985
+ case 17:
1986
+ params = params.concat(additionalParams);
1987
+ _context22.next = 20;
1988
+ return this.KMSInfo({
1989
+ kmsId: kmsId,
1990
+ objectId: objectId,
1991
+ versionHash: versionHash
1992
+ });
1993
+
1994
+ case 20:
1995
+ KMSUrls = _context22.sent.urls;
1996
+ i = 0;
1997
+
1998
+ case 22:
1999
+ if (!(i < KMSUrls.length)) {
2000
+ _context22.next = 40;
2001
+ break;
2002
+ }
2003
+
2004
+ _context22.prev = 23;
2005
+ this.Log("Making KMS request:\n URL: ".concat(KMSUrls[i], "\n Method: ").concat(methodName, "\n Params: ").concat(params.join(", ")));
2006
+ kmsUrl = KMSUrls[i];
2007
+
2008
+ if (!this.providers[kmsUrl]) {
2009
+ this.providers[kmsUrl] = new Ethers.providers.JsonRpcProvider(kmsUrl, this.client.networkId);
2010
+ }
2011
+
2012
+ _context22.next = 29;
2013
+ return this.providers[kmsUrl].send(methodName, params);
2014
+
2015
+ case 29:
2016
+ return _context22.abrupt("return", _context22.sent);
2017
+
2018
+ case 32:
2019
+ _context22.prev = 32;
2020
+ _context22.t6 = _context22["catch"](23);
2021
+ this.Log("KMS Call Error: ".concat(_context22.t6), true); // If the request has been attempted on all KMS urls, throw the error
2022
+
2023
+ if (!(i === KMSUrls.length - 1)) {
2024
+ _context22.next = 37;
2025
+ break;
2026
+ }
2027
+
2028
+ throw _context22.t6;
2029
+
2030
+ case 37:
2031
+ i++;
2032
+ _context22.next = 22;
1634
2033
  break;
1635
- }
1636
- throw _context22.t6;
1637
- case 37:
1638
- i++;
1639
- _context22.next = 22;
1640
- break;
1641
- case 40:
1642
- case "end":
1643
- return _context22.stop();
2034
+
2035
+ case 40:
2036
+ case "end":
2037
+ return _context22.stop();
2038
+ }
1644
2039
  }
1645
2040
  }, _callee22, this, [[23, 32]]);
1646
2041
  }));
2042
+
1647
2043
  function MakeKMSCall(_x22) {
1648
2044
  return _MakeKMSCall.apply(this, arguments);
1649
2045
  }
2046
+
1650
2047
  return MakeKMSCall;
1651
2048
  }() // Make an arbitrary HTTP call to an authority server
2049
+
1652
2050
  }, {
1653
2051
  key: "MakeAuthServiceRequest",
1654
2052
  value: function () {
1655
2053
  var _MakeAuthServiceRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23(_ref23) {
1656
2054
  var kmsId, objectId, versionHash, _ref23$method, method, path, bodyType, _ref23$body, body, _ref23$queryParams, queryParams, headers;
2055
+
1657
2056
  return _regeneratorRuntime.wrap(function _callee23$(_context23) {
1658
- while (1) switch (_context23.prev = _context23.next) {
1659
- case 0:
1660
- kmsId = _ref23.kmsId, objectId = _ref23.objectId, versionHash = _ref23.versionHash, _ref23$method = _ref23.method, method = _ref23$method === void 0 ? "GET" : _ref23$method, path = _ref23.path, bodyType = _ref23.bodyType, _ref23$body = _ref23.body, body = _ref23$body === void 0 ? {} : _ref23$body, _ref23$queryParams = _ref23.queryParams, queryParams = _ref23$queryParams === void 0 ? {} : _ref23$queryParams, headers = _ref23.headers;
1661
- if (!(this.client.authServiceURIs.length === 0)) {
1662
- _context23.next = 5;
1663
- break;
1664
- }
1665
- _context23.next = 4;
1666
- return this.MakeKMSRequest({
1667
- kmsId: kmsId,
1668
- objectId: objectId,
1669
- versionHash: versionHash,
1670
- method: method,
1671
- path: path,
1672
- bodyType: bodyType,
1673
- body: body,
1674
- queryParams: queryParams,
1675
- headers: headers
1676
- });
1677
- case 4:
1678
- return _context23.abrupt("return", _context23.sent);
1679
- case 5:
1680
- _context23.next = 7;
1681
- return this.client.AuthHttpClient.Request({
1682
- method: method,
1683
- path: path,
1684
- bodyType: bodyType,
1685
- body: body,
1686
- headers: headers,
1687
- queryParams: queryParams
1688
- });
1689
- case 7:
1690
- return _context23.abrupt("return", _context23.sent);
1691
- case 8:
1692
- case "end":
1693
- return _context23.stop();
2057
+ while (1) {
2058
+ switch (_context23.prev = _context23.next) {
2059
+ case 0:
2060
+ kmsId = _ref23.kmsId, objectId = _ref23.objectId, versionHash = _ref23.versionHash, _ref23$method = _ref23.method, method = _ref23$method === void 0 ? "GET" : _ref23$method, path = _ref23.path, bodyType = _ref23.bodyType, _ref23$body = _ref23.body, body = _ref23$body === void 0 ? {} : _ref23$body, _ref23$queryParams = _ref23.queryParams, queryParams = _ref23$queryParams === void 0 ? {} : _ref23$queryParams, headers = _ref23.headers;
2061
+
2062
+ if (!(this.client.authServiceURIs.length === 0)) {
2063
+ _context23.next = 5;
2064
+ break;
2065
+ }
2066
+
2067
+ _context23.next = 4;
2068
+ return this.MakeKMSRequest({
2069
+ kmsId: kmsId,
2070
+ objectId: objectId,
2071
+ versionHash: versionHash,
2072
+ method: method,
2073
+ path: path,
2074
+ bodyType: bodyType,
2075
+ body: body,
2076
+ queryParams: queryParams,
2077
+ headers: headers
2078
+ });
2079
+
2080
+ case 4:
2081
+ return _context23.abrupt("return", _context23.sent);
2082
+
2083
+ case 5:
2084
+ _context23.next = 7;
2085
+ return this.client.AuthHttpClient.Request({
2086
+ method: method,
2087
+ path: path,
2088
+ bodyType: bodyType,
2089
+ body: body,
2090
+ headers: headers,
2091
+ queryParams: queryParams
2092
+ });
2093
+
2094
+ case 7:
2095
+ return _context23.abrupt("return", _context23.sent);
2096
+
2097
+ case 8:
2098
+ case "end":
2099
+ return _context23.stop();
2100
+ }
1694
2101
  }
1695
2102
  }, _callee23, this);
1696
2103
  }));
2104
+
1697
2105
  function MakeAuthServiceRequest(_x23) {
1698
2106
  return _MakeAuthServiceRequest.apply(this, arguments);
1699
2107
  }
2108
+
1700
2109
  return MakeAuthServiceRequest;
1701
2110
  }() // Make an arbitrary HTTP call to the KMS
2111
+
1702
2112
  }, {
1703
2113
  key: "MakeKMSRequest",
1704
2114
  value: function () {
1705
2115
  var _MakeKMSRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24(_ref24) {
1706
2116
  var kmsId, objectId, versionHash, _ref24$method, method, path, bodyType, _ref24$body, body, _ref24$queryParams, queryParams, headers, kmsUrls, kmsHttpClient;
2117
+
1707
2118
  return _regeneratorRuntime.wrap(function _callee24$(_context24) {
1708
- while (1) switch (_context24.prev = _context24.next) {
1709
- case 0:
1710
- kmsId = _ref24.kmsId, objectId = _ref24.objectId, versionHash = _ref24.versionHash, _ref24$method = _ref24.method, method = _ref24$method === void 0 ? "GET" : _ref24$method, path = _ref24.path, bodyType = _ref24.bodyType, _ref24$body = _ref24.body, body = _ref24$body === void 0 ? {} : _ref24$body, _ref24$queryParams = _ref24.queryParams, queryParams = _ref24$queryParams === void 0 ? {} : _ref24$queryParams, headers = _ref24.headers;
1711
- if (versionHash) {
1712
- objectId = Utils.DecodeVersionHash(versionHash).objectId;
1713
- }
1714
- if (!(!objectId && !kmsId)) {
1715
- _context24.next = 10;
1716
- break;
1717
- }
1718
- _context24.t0 = "ikms";
1719
- _context24.t1 = Utils;
1720
- _context24.next = 7;
1721
- return this.client.DefaultKMSAddress();
1722
- case 7:
1723
- _context24.t2 = _context24.sent;
1724
- _context24.t3 = _context24.t1.AddressToHash.call(_context24.t1, _context24.t2);
1725
- kmsId = _context24.t0.concat.call(_context24.t0, _context24.t3);
1726
- case 10:
1727
- _context24.next = 12;
1728
- return this.KMSInfo({
1729
- kmsId: kmsId,
1730
- objectId: objectId,
1731
- versionHash: versionHash
1732
- });
1733
- case 12:
1734
- kmsUrls = _context24.sent.urls;
1735
- if (!(!kmsUrls || !kmsUrls[0])) {
1736
- _context24.next = 15;
1737
- break;
1738
- }
1739
- throw Error("No KMS info set for ".concat(versionHash || objectId || "default KMS"));
1740
- case 15:
1741
- kmsHttpClient = new HttpClient({
1742
- uris: kmsUrls
1743
- });
1744
- _context24.next = 18;
1745
- return kmsHttpClient.Request({
1746
- method: method,
1747
- path: path,
1748
- bodyType: bodyType,
1749
- body: body,
1750
- headers: headers,
1751
- queryParams: queryParams
1752
- });
1753
- case 18:
1754
- return _context24.abrupt("return", _context24.sent);
1755
- case 19:
1756
- case "end":
1757
- return _context24.stop();
2119
+ while (1) {
2120
+ switch (_context24.prev = _context24.next) {
2121
+ case 0:
2122
+ kmsId = _ref24.kmsId, objectId = _ref24.objectId, versionHash = _ref24.versionHash, _ref24$method = _ref24.method, method = _ref24$method === void 0 ? "GET" : _ref24$method, path = _ref24.path, bodyType = _ref24.bodyType, _ref24$body = _ref24.body, body = _ref24$body === void 0 ? {} : _ref24$body, _ref24$queryParams = _ref24.queryParams, queryParams = _ref24$queryParams === void 0 ? {} : _ref24$queryParams, headers = _ref24.headers;
2123
+
2124
+ if (versionHash) {
2125
+ objectId = Utils.DecodeVersionHash(versionHash).objectId;
2126
+ }
2127
+
2128
+ if (!(!objectId && !kmsId)) {
2129
+ _context24.next = 10;
2130
+ break;
2131
+ }
2132
+
2133
+ _context24.t0 = "ikms";
2134
+ _context24.t1 = Utils;
2135
+ _context24.next = 7;
2136
+ return this.client.DefaultKMSAddress();
2137
+
2138
+ case 7:
2139
+ _context24.t2 = _context24.sent;
2140
+ _context24.t3 = _context24.t1.AddressToHash.call(_context24.t1, _context24.t2);
2141
+ kmsId = _context24.t0.concat.call(_context24.t0, _context24.t3);
2142
+
2143
+ case 10:
2144
+ _context24.next = 12;
2145
+ return this.KMSInfo({
2146
+ kmsId: kmsId,
2147
+ objectId: objectId,
2148
+ versionHash: versionHash
2149
+ });
2150
+
2151
+ case 12:
2152
+ kmsUrls = _context24.sent.urls;
2153
+
2154
+ if (!(!kmsUrls || !kmsUrls[0])) {
2155
+ _context24.next = 15;
2156
+ break;
2157
+ }
2158
+
2159
+ throw Error("No KMS info set for ".concat(versionHash || objectId || "default KMS"));
2160
+
2161
+ case 15:
2162
+ kmsHttpClient = new HttpClient({
2163
+ uris: kmsUrls
2164
+ });
2165
+ _context24.next = 18;
2166
+ return kmsHttpClient.Request({
2167
+ method: method,
2168
+ path: path,
2169
+ bodyType: bodyType,
2170
+ body: body,
2171
+ headers: headers,
2172
+ queryParams: queryParams
2173
+ });
2174
+
2175
+ case 18:
2176
+ return _context24.abrupt("return", _context24.sent);
2177
+
2178
+ case 19:
2179
+ case "end":
2180
+ return _context24.stop();
2181
+ }
1758
2182
  }
1759
2183
  }, _callee24, this);
1760
2184
  }));
2185
+
1761
2186
  function MakeKMSRequest(_x24) {
1762
2187
  return _MakeKMSRequest.apply(this, arguments);
1763
2188
  }
2189
+
1764
2190
  return MakeKMSRequest;
1765
2191
  }()
1766
2192
  }, {
@@ -1769,64 +2195,82 @@ var AuthorizationClient = /*#__PURE__*/function () {
1769
2195
  var _ContractHasMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25(_ref25) {
1770
2196
  var contractAddress, abi, methodName, key, method, methodSignature, methodId;
1771
2197
  return _regeneratorRuntime.wrap(function _callee25$(_context25) {
1772
- while (1) switch (_context25.prev = _context25.next) {
1773
- case 0:
1774
- contractAddress = _ref25.contractAddress, abi = _ref25.abi, methodName = _ref25.methodName;
1775
- contractAddress = Utils.FormatAddress(contractAddress);
1776
- key = "".concat(contractAddress, "-").concat(methodName);
1777
- if (!(this.methodAvailability[key] === undefined)) {
1778
- _context25.next = 19;
1779
- break;
1780
- }
1781
- this.Log("Checking method availability: ".concat(contractAddress, " ").concat(methodName));
1782
- if (abi) {
1783
- _context25.next = 9;
1784
- break;
1785
- }
1786
- _context25.next = 8;
1787
- return this.ContractInfo({
1788
- address: contractAddress
1789
- });
1790
- case 8:
1791
- abi = _context25.sent.abi;
1792
- case 9:
1793
- if (abi) {
1794
- _context25.next = 11;
1795
- break;
1796
- }
1797
- throw Error("No ABI for contract ".concat(contractAddress, " - Wrong network or deleted item?"));
1798
- case 11:
1799
- method = abi.find(function (method) {
1800
- return method.name === methodName;
1801
- });
1802
- if (method) {
1803
- _context25.next = 14;
1804
- break;
1805
- }
1806
- return _context25.abrupt("return", false);
1807
- case 14:
1808
- methodSignature = "".concat(method.name, "(").concat(method.inputs.map(function (i) {
1809
- return i.type;
1810
- }).join(","), ")");
1811
- methodId = Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(methodSignature)).replace("0x", "").slice(0, 8);
1812
- _context25.next = 18;
1813
- return this.MakeElvMasterCall({
1814
- methodName: "elv_deployedContractHasMethod",
1815
- params: [contractAddress, methodId]
1816
- });
1817
- case 18:
1818
- this.methodAvailability[key] = _context25.sent;
1819
- case 19:
1820
- return _context25.abrupt("return", this.methodAvailability[key]);
1821
- case 20:
1822
- case "end":
1823
- return _context25.stop();
2198
+ while (1) {
2199
+ switch (_context25.prev = _context25.next) {
2200
+ case 0:
2201
+ contractAddress = _ref25.contractAddress, abi = _ref25.abi, methodName = _ref25.methodName;
2202
+ contractAddress = Utils.FormatAddress(contractAddress);
2203
+ key = "".concat(contractAddress, "-").concat(methodName);
2204
+
2205
+ if (!(this.methodAvailability[key] === undefined)) {
2206
+ _context25.next = 19;
2207
+ break;
2208
+ }
2209
+
2210
+ this.Log("Checking method availability: ".concat(contractAddress, " ").concat(methodName));
2211
+
2212
+ if (abi) {
2213
+ _context25.next = 9;
2214
+ break;
2215
+ }
2216
+
2217
+ _context25.next = 8;
2218
+ return this.ContractInfo({
2219
+ address: contractAddress
2220
+ });
2221
+
2222
+ case 8:
2223
+ abi = _context25.sent.abi;
2224
+
2225
+ case 9:
2226
+ if (abi) {
2227
+ _context25.next = 11;
2228
+ break;
2229
+ }
2230
+
2231
+ throw Error("No ABI for contract ".concat(contractAddress, " - Wrong network or deleted item?"));
2232
+
2233
+ case 11:
2234
+ method = abi.find(function (method) {
2235
+ return method.name === methodName;
2236
+ });
2237
+
2238
+ if (method) {
2239
+ _context25.next = 14;
2240
+ break;
2241
+ }
2242
+
2243
+ return _context25.abrupt("return", false);
2244
+
2245
+ case 14:
2246
+ methodSignature = "".concat(method.name, "(").concat(method.inputs.map(function (i) {
2247
+ return i.type;
2248
+ }).join(","), ")");
2249
+ methodId = Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(methodSignature)).replace("0x", "").slice(0, 8);
2250
+ _context25.next = 18;
2251
+ return this.MakeElvMasterCall({
2252
+ methodName: "elv_deployedContractHasMethod",
2253
+ params: [contractAddress, methodId]
2254
+ });
2255
+
2256
+ case 18:
2257
+ this.methodAvailability[key] = _context25.sent;
2258
+
2259
+ case 19:
2260
+ return _context25.abrupt("return", this.methodAvailability[key]);
2261
+
2262
+ case 20:
2263
+ case "end":
2264
+ return _context25.stop();
2265
+ }
1824
2266
  }
1825
2267
  }, _callee25, this);
1826
2268
  }));
2269
+
1827
2270
  function ContractHasMethod(_x25) {
1828
2271
  return _ContractHasMethod.apply(this, arguments);
1829
2272
  }
2273
+
1830
2274
  return ContractHasMethod;
1831
2275
  }()
1832
2276
  }, {
@@ -1835,25 +2279,31 @@ var AuthorizationClient = /*#__PURE__*/function () {
1835
2279
  var _MakeElvMasterCall = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26(_ref26) {
1836
2280
  var methodName, params;
1837
2281
  return _regeneratorRuntime.wrap(function _callee26$(_context26) {
1838
- while (1) switch (_context26.prev = _context26.next) {
1839
- case 0:
1840
- methodName = _ref26.methodName, params = _ref26.params;
1841
- _context26.next = 3;
1842
- return this.client.ethClient.MakeProviderCall({
1843
- methodName: "send",
1844
- args: [methodName, params]
1845
- });
1846
- case 3:
1847
- return _context26.abrupt("return", _context26.sent);
1848
- case 4:
1849
- case "end":
1850
- return _context26.stop();
2282
+ while (1) {
2283
+ switch (_context26.prev = _context26.next) {
2284
+ case 0:
2285
+ methodName = _ref26.methodName, params = _ref26.params;
2286
+ _context26.next = 3;
2287
+ return this.client.ethClient.MakeProviderCall({
2288
+ methodName: "send",
2289
+ args: [methodName, params]
2290
+ });
2291
+
2292
+ case 3:
2293
+ return _context26.abrupt("return", _context26.sent);
2294
+
2295
+ case 4:
2296
+ case "end":
2297
+ return _context26.stop();
2298
+ }
1851
2299
  }
1852
2300
  }, _callee26, this);
1853
2301
  }));
2302
+
1854
2303
  function MakeElvMasterCall(_x26) {
1855
2304
  return _MakeElvMasterCall.apply(this, arguments);
1856
2305
  }
2306
+
1857
2307
  return MakeElvMasterCall;
1858
2308
  }()
1859
2309
  }, {
@@ -1862,39 +2312,50 @@ var AuthorizationClient = /*#__PURE__*/function () {
1862
2312
  var _ReEncryptionConk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee27(_ref27) {
1863
2313
  var libraryId, objectId, versionHash, cap;
1864
2314
  return _regeneratorRuntime.wrap(function _callee27$(_context27) {
1865
- while (1) switch (_context27.prev = _context27.next) {
1866
- case 0:
1867
- libraryId = _ref27.libraryId, objectId = _ref27.objectId, versionHash = _ref27.versionHash;
1868
- if (versionHash) {
1869
- objectId = Utils.DecodeVersionHash(versionHash).objectId;
1870
- }
1871
- if (this.reencryptionKeys[objectId]) {
1872
- _context27.next = 10;
1873
- break;
1874
- }
1875
- _context27.next = 5;
1876
- return this.client.Crypto.GenerateTargetConk();
1877
- case 5:
1878
- cap = _context27.sent;
1879
- _context27.next = 8;
1880
- return this.RetrieveReencryptionSymmetricKey({
1881
- libraryId: libraryId,
1882
- objectId: objectId
1883
- });
1884
- case 8:
1885
- cap.symm_key = _context27.sent;
1886
- this.reencryptionKeys[objectId] = cap;
1887
- case 10:
1888
- return _context27.abrupt("return", this.reencryptionKeys[objectId]);
1889
- case 11:
1890
- case "end":
1891
- return _context27.stop();
2315
+ while (1) {
2316
+ switch (_context27.prev = _context27.next) {
2317
+ case 0:
2318
+ libraryId = _ref27.libraryId, objectId = _ref27.objectId, versionHash = _ref27.versionHash;
2319
+
2320
+ if (versionHash) {
2321
+ objectId = Utils.DecodeVersionHash(versionHash).objectId;
2322
+ }
2323
+
2324
+ if (this.reencryptionKeys[objectId]) {
2325
+ _context27.next = 10;
2326
+ break;
2327
+ }
2328
+
2329
+ _context27.next = 5;
2330
+ return this.client.Crypto.GenerateTargetConk();
2331
+
2332
+ case 5:
2333
+ cap = _context27.sent;
2334
+ _context27.next = 8;
2335
+ return this.RetrieveReencryptionSymmetricKey({
2336
+ libraryId: libraryId,
2337
+ objectId: objectId
2338
+ });
2339
+
2340
+ case 8:
2341
+ cap.symm_key = _context27.sent;
2342
+ this.reencryptionKeys[objectId] = cap;
2343
+
2344
+ case 10:
2345
+ return _context27.abrupt("return", this.reencryptionKeys[objectId]);
2346
+
2347
+ case 11:
2348
+ case "end":
2349
+ return _context27.stop();
2350
+ }
1892
2351
  }
1893
2352
  }, _callee27, this);
1894
2353
  }));
2354
+
1895
2355
  function ReEncryptionConk(_x27) {
1896
2356
  return _ReEncryptionConk.apply(this, arguments);
1897
2357
  }
2358
+
1898
2359
  return ReEncryptionConk;
1899
2360
  }()
1900
2361
  }, {
@@ -1902,57 +2363,71 @@ var AuthorizationClient = /*#__PURE__*/function () {
1902
2363
  value: function () {
1903
2364
  var _EncryptionConk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee28(_ref28) {
1904
2365
  var libraryId, objectId, versionHash, conk, _yield$this$client$Cr, secret_key;
2366
+
1905
2367
  return _regeneratorRuntime.wrap(function _callee28$(_context28) {
1906
- while (1) switch (_context28.prev = _context28.next) {
1907
- case 0:
1908
- libraryId = _ref28.libraryId, objectId = _ref28.objectId, versionHash = _ref28.versionHash;
1909
- if (versionHash) {
1910
- objectId = Utils.DecodeVersionHash(versionHash).objectId;
1911
- }
1912
- if (libraryId) {
1913
- _context28.next = 6;
1914
- break;
1915
- }
1916
- _context28.next = 5;
1917
- return this.client.ContentObjectLibraryId({
1918
- objectId: objectId
1919
- });
1920
- case 5:
1921
- libraryId = _context28.sent;
1922
- case 6:
1923
- if (this.encryptionKeys[objectId]) {
1924
- _context28.next = 16;
1925
- break;
1926
- }
1927
- _context28.next = 9;
1928
- return this.RetrieveConk({
1929
- libraryId: libraryId,
1930
- objectId: objectId
1931
- });
1932
- case 9:
1933
- conk = _context28.sent;
1934
- _context28.next = 12;
1935
- return this.client.Crypto.GeneratePrimaryConk({
1936
- objectId: objectId
1937
- });
1938
- case 12:
1939
- _yield$this$client$Cr = _context28.sent;
1940
- secret_key = _yield$this$client$Cr.secret_key;
1941
- conk.secret_key = secret_key;
1942
-
1943
- // { secret_key, public_key, symm_key, block_size }
1944
- this.encryptionKeys[objectId] = conk;
1945
- case 16:
1946
- return _context28.abrupt("return", this.encryptionKeys[objectId]);
1947
- case 17:
1948
- case "end":
1949
- return _context28.stop();
2368
+ while (1) {
2369
+ switch (_context28.prev = _context28.next) {
2370
+ case 0:
2371
+ libraryId = _ref28.libraryId, objectId = _ref28.objectId, versionHash = _ref28.versionHash;
2372
+
2373
+ if (versionHash) {
2374
+ objectId = Utils.DecodeVersionHash(versionHash).objectId;
2375
+ }
2376
+
2377
+ if (libraryId) {
2378
+ _context28.next = 6;
2379
+ break;
2380
+ }
2381
+
2382
+ _context28.next = 5;
2383
+ return this.client.ContentObjectLibraryId({
2384
+ objectId: objectId
2385
+ });
2386
+
2387
+ case 5:
2388
+ libraryId = _context28.sent;
2389
+
2390
+ case 6:
2391
+ if (this.encryptionKeys[objectId]) {
2392
+ _context28.next = 16;
2393
+ break;
2394
+ }
2395
+
2396
+ _context28.next = 9;
2397
+ return this.RetrieveConk({
2398
+ libraryId: libraryId,
2399
+ objectId: objectId
2400
+ });
2401
+
2402
+ case 9:
2403
+ conk = _context28.sent;
2404
+ _context28.next = 12;
2405
+ return this.client.Crypto.GeneratePrimaryConk({
2406
+ objectId: objectId
2407
+ });
2408
+
2409
+ case 12:
2410
+ _yield$this$client$Cr = _context28.sent;
2411
+ secret_key = _yield$this$client$Cr.secret_key;
2412
+ conk.secret_key = secret_key; // { secret_key, public_key, symm_key, block_size }
2413
+
2414
+ this.encryptionKeys[objectId] = conk;
2415
+
2416
+ case 16:
2417
+ return _context28.abrupt("return", this.encryptionKeys[objectId]);
2418
+
2419
+ case 17:
2420
+ case "end":
2421
+ return _context28.stop();
2422
+ }
1950
2423
  }
1951
2424
  }, _callee28, this);
1952
2425
  }));
2426
+
1953
2427
  function EncryptionConk(_x28) {
1954
2428
  return _EncryptionConk.apply(this, arguments);
1955
2429
  }
2430
+
1956
2431
  return EncryptionConk;
1957
2432
  }()
1958
2433
  }, {
@@ -1960,81 +2435,103 @@ var AuthorizationClient = /*#__PURE__*/function () {
1960
2435
  value: function () {
1961
2436
  var _RecordTags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee29(_ref29) {
1962
2437
  var accessType, libraryId, objectId, versionHash, _yield$this$ContractI8, abi, owner;
2438
+
1963
2439
  return _regeneratorRuntime.wrap(function _callee29$(_context29) {
1964
- while (1) switch (_context29.prev = _context29.next) {
1965
- case 0:
1966
- accessType = _ref29.accessType, libraryId = _ref29.libraryId, objectId = _ref29.objectId, versionHash = _ref29.versionHash;
1967
- if (!(accessType !== ACCESS_TYPES.OBJECT)) {
1968
- _context29.next = 3;
1969
- break;
1970
- }
1971
- return _context29.abrupt("return");
1972
- case 3:
1973
- _context29.next = 5;
1974
- return this.ContractInfo({
1975
- id: objectId
1976
- });
1977
- case 5:
1978
- _yield$this$ContractI8 = _context29.sent;
1979
- abi = _yield$this$ContractI8.abi;
1980
- _context29.next = 9;
1981
- return this.Owner({
1982
- id: objectId,
1983
- abi: abi
1984
- });
1985
- case 9:
1986
- owner = _context29.sent;
1987
- if (Utils.EqualAddress(owner, this.client.signer.address)) {
2440
+ while (1) {
2441
+ switch (_context29.prev = _context29.next) {
2442
+ case 0:
2443
+ accessType = _ref29.accessType, libraryId = _ref29.libraryId, objectId = _ref29.objectId, versionHash = _ref29.versionHash;
2444
+
2445
+ if (!(accessType !== ACCESS_TYPES.OBJECT)) {
2446
+ _context29.next = 3;
2447
+ break;
2448
+ }
2449
+
2450
+ return _context29.abrupt("return");
2451
+
2452
+ case 3:
2453
+ _context29.next = 5;
2454
+ return this.ContractInfo({
2455
+ id: objectId
2456
+ });
2457
+
2458
+ case 5:
2459
+ _yield$this$ContractI8 = _context29.sent;
2460
+ abi = _yield$this$ContractI8.abi;
2461
+ _context29.next = 9;
2462
+ return this.Owner({
2463
+ id: objectId,
2464
+ abi: abi
2465
+ });
2466
+
2467
+ case 9:
2468
+ owner = _context29.sent;
2469
+
2470
+ if (Utils.EqualAddress(owner, this.client.signer.address)) {
2471
+ _context29.next = 13;
2472
+ break;
2473
+ }
2474
+
1988
2475
  _context29.next = 13;
1989
- break;
1990
- }
1991
- _context29.next = 13;
1992
- return this.client.userProfileClient.RecordTags({
1993
- libraryId: libraryId,
1994
- objectId: objectId,
1995
- versionHash: versionHash
1996
- });
1997
- case 13:
1998
- case "end":
1999
- return _context29.stop();
2476
+ return this.client.userProfileClient.RecordTags({
2477
+ libraryId: libraryId,
2478
+ objectId: objectId,
2479
+ versionHash: versionHash
2480
+ });
2481
+
2482
+ case 13:
2483
+ case "end":
2484
+ return _context29.stop();
2485
+ }
2000
2486
  }
2001
2487
  }, _callee29, this);
2002
2488
  }));
2489
+
2003
2490
  function RecordTags(_x29) {
2004
2491
  return _RecordTags.apply(this, arguments);
2005
2492
  }
2493
+
2006
2494
  return RecordTags;
2007
- }() /* Creation methods */
2495
+ }()
2496
+ /* Creation methods */
2497
+
2008
2498
  }, {
2009
2499
  key: "CreateAccessGroup",
2010
2500
  value: function () {
2011
2501
  var _CreateAccessGroup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee30() {
2012
2502
  var _yield$this$client$et, contractAddress, transactionHash;
2503
+
2013
2504
  return _regeneratorRuntime.wrap(function _callee30$(_context30) {
2014
- while (1) switch (_context30.prev = _context30.next) {
2015
- case 0:
2016
- _context30.next = 2;
2017
- return this.client.ethClient.DeployAccessGroupContract({
2018
- contentSpaceAddress: Utils.HashToAddress(this.contentSpaceId),
2019
- signer: this.client.signer
2020
- });
2021
- case 2:
2022
- _yield$this$client$et = _context30.sent;
2023
- contractAddress = _yield$this$client$et.contractAddress;
2024
- transactionHash = _yield$this$client$et.transactionHash;
2025
- return _context30.abrupt("return", {
2026
- contractAddress: contractAddress,
2027
- transactionHash: transactionHash
2028
- });
2029
- case 6:
2030
- case "end":
2031
- return _context30.stop();
2505
+ while (1) {
2506
+ switch (_context30.prev = _context30.next) {
2507
+ case 0:
2508
+ _context30.next = 2;
2509
+ return this.client.ethClient.DeployAccessGroupContract({
2510
+ contentSpaceAddress: Utils.HashToAddress(this.contentSpaceId),
2511
+ signer: this.client.signer
2512
+ });
2513
+
2514
+ case 2:
2515
+ _yield$this$client$et = _context30.sent;
2516
+ contractAddress = _yield$this$client$et.contractAddress;
2517
+ transactionHash = _yield$this$client$et.transactionHash;
2518
+ return _context30.abrupt("return", {
2519
+ contractAddress: contractAddress,
2520
+ transactionHash: transactionHash
2521
+ });
2522
+
2523
+ case 6:
2524
+ case "end":
2525
+ return _context30.stop();
2526
+ }
2032
2527
  }
2033
2528
  }, _callee30, this);
2034
2529
  }));
2530
+
2035
2531
  function CreateAccessGroup() {
2036
2532
  return _CreateAccessGroup.apply(this, arguments);
2037
2533
  }
2534
+
2038
2535
  return CreateAccessGroup;
2039
2536
  }()
2040
2537
  }, {
@@ -2042,31 +2539,38 @@ var AuthorizationClient = /*#__PURE__*/function () {
2042
2539
  value: function () {
2043
2540
  var _CreateContentType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee31() {
2044
2541
  var _yield$this$client$et2, contractAddress, transactionHash;
2542
+
2045
2543
  return _regeneratorRuntime.wrap(function _callee31$(_context31) {
2046
- while (1) switch (_context31.prev = _context31.next) {
2047
- case 0:
2048
- _context31.next = 2;
2049
- return this.client.ethClient.DeployTypeContract({
2050
- contentSpaceAddress: Utils.HashToAddress(this.contentSpaceId),
2051
- signer: this.client.signer
2052
- });
2053
- case 2:
2054
- _yield$this$client$et2 = _context31.sent;
2055
- contractAddress = _yield$this$client$et2.contractAddress;
2056
- transactionHash = _yield$this$client$et2.transactionHash;
2057
- return _context31.abrupt("return", {
2058
- contractAddress: contractAddress,
2059
- transactionHash: transactionHash
2060
- });
2061
- case 6:
2062
- case "end":
2063
- return _context31.stop();
2544
+ while (1) {
2545
+ switch (_context31.prev = _context31.next) {
2546
+ case 0:
2547
+ _context31.next = 2;
2548
+ return this.client.ethClient.DeployTypeContract({
2549
+ contentSpaceAddress: Utils.HashToAddress(this.contentSpaceId),
2550
+ signer: this.client.signer
2551
+ });
2552
+
2553
+ case 2:
2554
+ _yield$this$client$et2 = _context31.sent;
2555
+ contractAddress = _yield$this$client$et2.contractAddress;
2556
+ transactionHash = _yield$this$client$et2.transactionHash;
2557
+ return _context31.abrupt("return", {
2558
+ contractAddress: contractAddress,
2559
+ transactionHash: transactionHash
2560
+ });
2561
+
2562
+ case 6:
2563
+ case "end":
2564
+ return _context31.stop();
2565
+ }
2064
2566
  }
2065
2567
  }, _callee31, this);
2066
2568
  }));
2569
+
2067
2570
  function CreateContentType() {
2068
2571
  return _CreateContentType.apply(this, arguments);
2069
2572
  }
2573
+
2070
2574
  return CreateContentType;
2071
2575
  }()
2072
2576
  }, {
@@ -2074,33 +2578,40 @@ var AuthorizationClient = /*#__PURE__*/function () {
2074
2578
  value: function () {
2075
2579
  var _CreateContentLibrary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee32(_ref30) {
2076
2580
  var kmsId, _yield$this$client$et3, contractAddress, transactionHash;
2581
+
2077
2582
  return _regeneratorRuntime.wrap(function _callee32$(_context32) {
2078
- while (1) switch (_context32.prev = _context32.next) {
2079
- case 0:
2080
- kmsId = _ref30.kmsId;
2081
- _context32.next = 3;
2082
- return this.client.ethClient.DeployLibraryContract({
2083
- contentSpaceAddress: Utils.HashToAddress(this.contentSpaceId),
2084
- kmsId: kmsId,
2085
- signer: this.client.signer
2086
- });
2087
- case 3:
2088
- _yield$this$client$et3 = _context32.sent;
2089
- contractAddress = _yield$this$client$et3.contractAddress;
2090
- transactionHash = _yield$this$client$et3.transactionHash;
2091
- return _context32.abrupt("return", {
2092
- contractAddress: contractAddress,
2093
- transactionHash: transactionHash
2094
- });
2095
- case 7:
2096
- case "end":
2097
- return _context32.stop();
2583
+ while (1) {
2584
+ switch (_context32.prev = _context32.next) {
2585
+ case 0:
2586
+ kmsId = _ref30.kmsId;
2587
+ _context32.next = 3;
2588
+ return this.client.ethClient.DeployLibraryContract({
2589
+ contentSpaceAddress: Utils.HashToAddress(this.contentSpaceId),
2590
+ kmsId: kmsId,
2591
+ signer: this.client.signer
2592
+ });
2593
+
2594
+ case 3:
2595
+ _yield$this$client$et3 = _context32.sent;
2596
+ contractAddress = _yield$this$client$et3.contractAddress;
2597
+ transactionHash = _yield$this$client$et3.transactionHash;
2598
+ return _context32.abrupt("return", {
2599
+ contractAddress: contractAddress,
2600
+ transactionHash: transactionHash
2601
+ });
2602
+
2603
+ case 7:
2604
+ case "end":
2605
+ return _context32.stop();
2606
+ }
2098
2607
  }
2099
2608
  }, _callee32, this);
2100
2609
  }));
2610
+
2101
2611
  function CreateContentLibrary(_x30) {
2102
2612
  return _CreateContentLibrary.apply(this, arguments);
2103
2613
  }
2614
+
2104
2615
  return CreateContentLibrary;
2105
2616
  }()
2106
2617
  }, {
@@ -2108,35 +2619,43 @@ var AuthorizationClient = /*#__PURE__*/function () {
2108
2619
  value: function () {
2109
2620
  var _CreateContentObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee33(_ref31) {
2110
2621
  var libraryId, typeId, _yield$this$client$et4, contractAddress, transactionHash;
2622
+
2111
2623
  return _regeneratorRuntime.wrap(function _callee33$(_context33) {
2112
- while (1) switch (_context33.prev = _context33.next) {
2113
- case 0:
2114
- libraryId = _ref31.libraryId, typeId = _ref31.typeId;
2115
- _context33.next = 3;
2116
- return this.client.ethClient.DeployContentContract({
2117
- contentLibraryAddress: Utils.HashToAddress(libraryId),
2118
- typeAddress: typeId ? Utils.HashToAddress(typeId) : Utils.nullAddress,
2119
- signer: this.client.signer
2120
- });
2121
- case 3:
2122
- _yield$this$client$et4 = _context33.sent;
2123
- contractAddress = _yield$this$client$et4.contractAddress;
2124
- transactionHash = _yield$this$client$et4.transactionHash;
2125
- return _context33.abrupt("return", {
2126
- contractAddress: contractAddress,
2127
- transactionHash: transactionHash
2128
- });
2129
- case 7:
2130
- case "end":
2131
- return _context33.stop();
2624
+ while (1) {
2625
+ switch (_context33.prev = _context33.next) {
2626
+ case 0:
2627
+ libraryId = _ref31.libraryId, typeId = _ref31.typeId;
2628
+ _context33.next = 3;
2629
+ return this.client.ethClient.DeployContentContract({
2630
+ contentLibraryAddress: Utils.HashToAddress(libraryId),
2631
+ typeAddress: typeId ? Utils.HashToAddress(typeId) : Utils.nullAddress,
2632
+ signer: this.client.signer
2633
+ });
2634
+
2635
+ case 3:
2636
+ _yield$this$client$et4 = _context33.sent;
2637
+ contractAddress = _yield$this$client$et4.contractAddress;
2638
+ transactionHash = _yield$this$client$et4.transactionHash;
2639
+ return _context33.abrupt("return", {
2640
+ contractAddress: contractAddress,
2641
+ transactionHash: transactionHash
2642
+ });
2643
+
2644
+ case 7:
2645
+ case "end":
2646
+ return _context33.stop();
2647
+ }
2132
2648
  }
2133
2649
  }, _callee33, this);
2134
2650
  }));
2651
+
2135
2652
  function CreateContentObject(_x31) {
2136
2653
  return _CreateContentObject.apply(this, arguments);
2137
2654
  }
2655
+
2138
2656
  return CreateContentObject;
2139
2657
  }() // Clear cached access transaction IDs and state channel tokens
2658
+
2140
2659
  }, {
2141
2660
  key: "ClearCache",
2142
2661
  value: function ClearCache() {
@@ -2145,6 +2664,8 @@ var AuthorizationClient = /*#__PURE__*/function () {
2145
2664
  this.channelContentTokens = {};
2146
2665
  }
2147
2666
  }]);
2667
+
2148
2668
  return AuthorizationClient;
2149
2669
  }();
2670
+
2150
2671
  module.exports = AuthorizationClient;