@eluvio/elv-client-js 4.0.10 → 4.0.11

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