@eluvio/elv-client-js 3.2.4 → 3.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/ElvClient-min.js +15 -11
  2. package/dist/ElvClient-node-min.js +17 -13
  3. package/dist/ElvFrameClient-min.js +12 -8
  4. package/dist/ElvPermissionsClient-min.js +13 -9
  5. package/dist/ElvWalletClient-min.js +58 -0
  6. package/dist/ElvWalletClient-node-min.js +78 -0
  7. package/dist/src/AuthorizationClient.js +2248 -1990
  8. package/dist/src/ContentObjectVerification.js +164 -173
  9. package/dist/src/Crypto.js +376 -324
  10. package/dist/src/ElvClient.js +1198 -1019
  11. package/dist/src/ElvWallet.js +119 -95
  12. package/dist/src/EthClient.js +1040 -896
  13. package/dist/src/FrameClient.js +331 -300
  14. package/dist/src/HttpClient.js +153 -147
  15. package/dist/src/Id.js +1 -3
  16. package/dist/src/PermissionsClient.js +1294 -1168
  17. package/dist/src/RemoteSigner.js +263 -211
  18. package/dist/src/UserProfileClient.js +1164 -1023
  19. package/dist/src/Utils.js +229 -184
  20. package/dist/src/client/ABRPublishing.js +895 -858
  21. package/dist/src/client/AccessGroups.js +1102 -959
  22. package/dist/src/client/ContentAccess.js +3724 -3431
  23. package/dist/src/client/ContentManagement.js +2252 -2068
  24. package/dist/src/client/Contracts.js +647 -563
  25. package/dist/src/client/Files.js +1886 -1757
  26. package/dist/src/client/NFT.js +126 -112
  27. package/dist/src/client/NTP.js +478 -422
  28. package/dist/src/index.js +11 -0
  29. package/dist/src/marketplaceClient/ClientMethods.js +1918 -0
  30. package/dist/src/marketplaceClient/Configuration.js +29 -0
  31. package/dist/src/marketplaceClient/Utils.js +304 -0
  32. package/dist/src/marketplaceClient/index.js +1553 -0
  33. package/dist/src/walletClient/ClientMethods.js +2080 -0
  34. package/dist/src/walletClient/Configuration.js +29 -0
  35. package/dist/src/walletClient/Utils.js +304 -0
  36. package/dist/src/walletClient/index.js +1770 -0
  37. package/package.json +8 -4
  38. package/src/ElvClient.js +5 -2
  39. package/src/Utils.js +22 -4
  40. package/src/index.js +7 -0
  41. package/src/walletClient/ClientMethods.js +1111 -0
  42. package/src/walletClient/Configuration.js +40 -0
  43. package/src/walletClient/README.md +191 -0
  44. package/src/walletClient/Utils.js +234 -0
  45. package/src/walletClient/index.js +977 -0
  46. package/testScripts/TestMarketplaceClient.js +25 -0
@@ -0,0 +1,1770 @@
1
+ var _slicedToArray = require("@babel/runtime/helpers/slicedToArray");
2
+
3
+ var _defineProperty = require("@babel/runtime/helpers/defineProperty");
4
+
5
+ var _regeneratorRuntime = require("@babel/runtime/regenerator");
6
+
7
+ var _typeof = require("@babel/runtime/helpers/typeof");
8
+
9
+ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
10
+
11
+ var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
12
+
13
+ var _createClass = require("@babel/runtime/helpers/createClass");
14
+
15
+ 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; }
16
+
17
+ 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; }
18
+
19
+ var _require = require("../ElvClient"),
20
+ ElvClient = _require.ElvClient;
21
+
22
+ var Configuration = require("./Configuration");
23
+
24
+ var _require2 = require("./Utils"),
25
+ LinkTargetHash = _require2.LinkTargetHash,
26
+ FormatNFT = _require2.FormatNFT,
27
+ ActionPopup = _require2.ActionPopup;
28
+
29
+ var UrlJoin = require("url-join");
30
+
31
+ var Utils = require("../Utils");
32
+
33
+ var Ethers = require("ethers");
34
+ /**
35
+ * Use the <a href="#.Initialize">Initialize</a> method to initialize a new client.
36
+ *
37
+ *
38
+ * See the Modules section on the sidebar for all client methods unrelated to login and authorization
39
+ */
40
+
41
+
42
+ var ElvWalletClient = /*#__PURE__*/function () {
43
+ "use strict";
44
+
45
+ function ElvWalletClient(_ref) {
46
+ var client = _ref.client,
47
+ network = _ref.network,
48
+ mode = _ref.mode,
49
+ marketplaceInfo = _ref.marketplaceInfo,
50
+ storeAuthToken = _ref.storeAuthToken;
51
+
52
+ _classCallCheck(this, ElvWalletClient);
53
+
54
+ this.client = client;
55
+ this.loggedIn = false;
56
+ this.network = network;
57
+ this.mode = mode;
58
+ this.purchaseMode = Configuration[network][mode].purchaseMode;
59
+ this.mainSiteId = Configuration[network][mode].siteId;
60
+ this.appUrl = Configuration[network][mode].appUrl;
61
+ this.publicStaticToken = client.staticToken;
62
+ this.storeAuthToken = storeAuthToken;
63
+ this.selectedMarketplaceInfo = marketplaceInfo;
64
+ this.availableMarketplaces = {};
65
+ this.availableMarketplacesById = {};
66
+ this.marketplaceHashes = {}; // Caches
67
+
68
+ this.cachedMarketplaces = {};
69
+ this.cachedCSS = {};
70
+ this.utils = client.utils;
71
+ }
72
+
73
+ _createClass(ElvWalletClient, [{
74
+ key: "Log",
75
+ value: function Log(message) {
76
+ var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
77
+
78
+ if (error) {
79
+ // eslint-disable-next-line no-console
80
+ console.error("Eluvio Wallet Client:", message);
81
+ } else {
82
+ // eslint-disable-next-line no-console
83
+ console.log("Eluvio Wallet Client:", message);
84
+ }
85
+ }
86
+ /**
87
+ * Initialize the wallet client.
88
+ *
89
+ * Specify tenantSlug and marketplaceSlug to automatically associate this tenant with a particular marketplace.
90
+ *
91
+ * @methodGroup Initialization
92
+ * @namedParams
93
+ * @param {string} network=main - Name of the Fabric network to use (`main`, `demo`)
94
+ * @param {string} mode=production - Environment to use (`production`, `staging`)
95
+ * @param {Object=} marketplaceParams - Marketplace parameters
96
+ * @param {boolean=} storeAuthToken=true - If specified, auth tokens will be stored in localstorage (if available)
97
+ *
98
+ * @returns {Promise<ElvWalletClient>}
99
+ */
100
+
101
+ }, {
102
+ key: "CanSign",
103
+ value:
104
+ /* Login and authorization */
105
+
106
+ /**
107
+ * Check if this client can sign without opening a popup.
108
+ *
109
+ * Generally, Eluvio custodial wallet users will require a popup prompt, while Metamask and custom OAuth users will not.
110
+ *
111
+ * @methodGroup Signatures
112
+ * @returns {boolean} - Whether or not this client can sign a message without a popup.
113
+ */
114
+ function CanSign() {
115
+ if (!this.loggedIn) {
116
+ return false;
117
+ }
118
+
119
+ return !!this.__authorization.clusterToken || !!(this.UserInfo().walletName.toLowerCase() === "metamask" && window.ethereum && window.ethereum.isMetaMask && window.ethereum.chainId);
120
+ }
121
+ /**
122
+ * <b><i>Requires login</i></b>
123
+ *
124
+ * Request the current user sign the specified message.
125
+ *
126
+ * If this client is not able to perform the signature (Eluvio custodial OAuth users), a popup will be opened and the user will be prompted to sign.
127
+ *
128
+ * To check if the signature can be done without a popup, use the <a href="#CanSign">CanSign</a> method.
129
+ *
130
+ * @methodGroup Signatures
131
+ * @namedParams
132
+ * @param {string} message - The message to sign
133
+ *
134
+ * @throws - If the user rejects the signature or closes the popup, an error will be thrown.
135
+ *
136
+ * @returns {Promise<string>} - The signature of the message
137
+ */
138
+
139
+ }, {
140
+ key: "PersonalSign",
141
+ value: function () {
142
+ var _PersonalSign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref2) {
143
+ var message, parameters, url;
144
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
145
+ while (1) {
146
+ switch (_context3.prev = _context3.next) {
147
+ case 0:
148
+ message = _ref2.message;
149
+
150
+ if (this.loggedIn) {
151
+ _context3.next = 3;
152
+ break;
153
+ }
154
+
155
+ throw Error("ElvWalletClient: Unable to perform signature - Not logged in");
156
+
157
+ case 3:
158
+ if (!this.CanSign()) {
159
+ _context3.next = 17;
160
+ break;
161
+ }
162
+
163
+ if (!this.__authorization.clusterToken) {
164
+ _context3.next = 12;
165
+ break;
166
+ }
167
+
168
+ // Custodial wallet sign
169
+ message = _typeof(message) === "object" ? JSON.stringify(message) : message;
170
+ message = Ethers.utils.keccak256(Buffer.from("\x19Ethereum Signed Message:\n".concat(message.length).concat(message), "utf-8"));
171
+ _context3.next = 9;
172
+ return this.client.authClient.Sign(message);
173
+
174
+ case 9:
175
+ return _context3.abrupt("return", _context3.sent);
176
+
177
+ case 12:
178
+ if (!(this.UserInfo().walletName.toLowerCase() === "metamask")) {
179
+ _context3.next = 16;
180
+ break;
181
+ }
182
+
183
+ return _context3.abrupt("return", this.SignMetamask({
184
+ message: message,
185
+ address: this.UserAddress()
186
+ }));
187
+
188
+ case 16:
189
+ throw Error("ElvWalletClient: Unable to sign");
190
+
191
+ case 17:
192
+ parameters = {
193
+ action: "personal-sign",
194
+ message: message,
195
+ logIn: true
196
+ };
197
+ url = new URL(this.appUrl);
198
+ url.hash = UrlJoin("/action", "sign", Utils.B58(JSON.stringify(parameters)));
199
+ url.searchParams.set("origin", window.location.origin);
200
+ _context3.next = 23;
201
+ return new Promise( /*#__PURE__*/function () {
202
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
203
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
204
+ while (1) {
205
+ switch (_context2.prev = _context2.next) {
206
+ case 0:
207
+ _context2.next = 2;
208
+ return ActionPopup({
209
+ mode: "tab",
210
+ url: url.toString(),
211
+ onCancel: function onCancel() {
212
+ return reject("User cancelled sign");
213
+ },
214
+ onMessage: function () {
215
+ var _onMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event, Close) {
216
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
217
+ while (1) {
218
+ switch (_context.prev = _context.next) {
219
+ case 0:
220
+ if (!(!event || !event.data || event.data.type !== "FlowResponse")) {
221
+ _context.next = 2;
222
+ break;
223
+ }
224
+
225
+ return _context.abrupt("return");
226
+
227
+ case 2:
228
+ try {
229
+ resolve(event.data.response);
230
+ } catch (error) {
231
+ reject(error);
232
+ } finally {
233
+ Close();
234
+ }
235
+
236
+ case 3:
237
+ case "end":
238
+ return _context.stop();
239
+ }
240
+ }
241
+ }, _callee);
242
+ }));
243
+
244
+ function onMessage(_x4, _x5) {
245
+ return _onMessage.apply(this, arguments);
246
+ }
247
+
248
+ return onMessage;
249
+ }()
250
+ });
251
+
252
+ case 2:
253
+ case "end":
254
+ return _context2.stop();
255
+ }
256
+ }
257
+ }, _callee2);
258
+ }));
259
+
260
+ return function (_x2, _x3) {
261
+ return _ref3.apply(this, arguments);
262
+ };
263
+ }());
264
+
265
+ case 23:
266
+ return _context3.abrupt("return", _context3.sent);
267
+
268
+ case 24:
269
+ case "end":
270
+ return _context3.stop();
271
+ }
272
+ }
273
+ }, _callee3, this);
274
+ }));
275
+
276
+ function PersonalSign(_x) {
277
+ return _PersonalSign.apply(this, arguments);
278
+ }
279
+
280
+ return PersonalSign;
281
+ }()
282
+ /**
283
+ * Direct the user to the Eluvio Media Wallet login page.
284
+ *
285
+ * <b>NOTE:</b> The domain of the opening window (popup flow) or domain of the `callbackUrl` (redirect flow) MUST be allowed in the metadata of the specified marketplace.
286
+ *
287
+ * @methodGroup Login
288
+ * @namedParams
289
+ * @param {string=} method=redirect - How to present the login page.
290
+ * - `redirect` - Redirect to the wallet login page. Upon login, the page will be redirected back to the specified `redirectUrl` with the authorization token.
291
+ * - `popup` - Open the wallet login page in a new tab. Upon login, authorization information will be sent back to the client via message and the tab will be closed.
292
+ * @param {string=} provider - If logging in via a specific method, specify the provider and mode. Options: `oauth`, `metamask`
293
+ * @param {string=} mode - If logging in via a specific method, specify the mode. Options `login` (Log In), `create` (Sign Up)
294
+ * @param {string=} callbackUrl - If using the redirect flow, the URL to redirect back to after login.
295
+ * @param {Object=} marketplaceParams - Parameters of a marketplace to associate the login with. If not specified, the marketplace parameters used upon client initialization will be used. A marketplace is required when using the redirect flow.
296
+ * @param {boolean=} clearLogin=false - If specified, the user will be prompted to log in anew even if they are already logged in on the Eluvio Media Wallet app
297
+ *
298
+ * @throws - If using the popup flow and the user closes the popup, this method will throw an error.
299
+ */
300
+
301
+ }, {
302
+ key: "LogIn",
303
+ value: function () {
304
+ var _LogIn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref4) {
305
+ var _this = this;
306
+
307
+ var _ref4$method, method, provider, _ref4$mode, mode, callbackUrl, marketplaceParams, _ref4$clearLogin, clearLogin, callback, loginUrl;
308
+
309
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
310
+ while (1) {
311
+ switch (_context6.prev = _context6.next) {
312
+ case 0:
313
+ _ref4$method = _ref4.method, method = _ref4$method === void 0 ? "redirect" : _ref4$method, provider = _ref4.provider, _ref4$mode = _ref4.mode, mode = _ref4$mode === void 0 ? "login" : _ref4$mode, callbackUrl = _ref4.callbackUrl, marketplaceParams = _ref4.marketplaceParams, _ref4$clearLogin = _ref4.clearLogin, clearLogin = _ref4$clearLogin === void 0 ? false : _ref4$clearLogin, callback = _ref4.callback;
314
+ loginUrl = new URL(this.appUrl);
315
+ loginUrl.hash = "/login";
316
+ loginUrl.searchParams.set("origin", window.location.origin);
317
+ loginUrl.searchParams.set("action", "login");
318
+
319
+ if (provider) {
320
+ loginUrl.searchParams.set("provider", provider);
321
+ }
322
+
323
+ if (mode) {
324
+ loginUrl.searchParams.set("mode", mode);
325
+ }
326
+
327
+ if (!marketplaceParams) {
328
+ _context6.next = 15;
329
+ break;
330
+ }
331
+
332
+ _context6.t0 = loginUrl.searchParams;
333
+ _context6.next = 11;
334
+ return this.MarketplaceInfo({
335
+ marketplaceParams: marketplaceParams
336
+ });
337
+
338
+ case 11:
339
+ _context6.t1 = _context6.sent.marketplaceHash;
340
+
341
+ _context6.t0.set.call(_context6.t0, "mid", _context6.t1);
342
+
343
+ _context6.next = 16;
344
+ break;
345
+
346
+ case 15:
347
+ if ((this.selectedMarketplaceInfo || {}).marketplaceHash) {
348
+ loginUrl.searchParams.set("mid", this.selectedMarketplaceInfo.marketplaceHash);
349
+ }
350
+
351
+ case 16:
352
+ if (clearLogin) {
353
+ loginUrl.searchParams.set("clear", "");
354
+ }
355
+
356
+ if (!(method === "redirect")) {
357
+ _context6.next = 24;
358
+ break;
359
+ }
360
+
361
+ loginUrl.searchParams.set("response", "redirect");
362
+ loginUrl.searchParams.set("source", "origin");
363
+ loginUrl.searchParams.set("redirect", callbackUrl);
364
+ window.location = loginUrl;
365
+ _context6.next = 28;
366
+ break;
367
+
368
+ case 24:
369
+ loginUrl.searchParams.set("response", "message");
370
+ loginUrl.searchParams.set("source", "parent");
371
+ _context6.next = 28;
372
+ return new Promise( /*#__PURE__*/function () {
373
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resolve, reject) {
374
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
375
+ while (1) {
376
+ switch (_context5.prev = _context5.next) {
377
+ case 0:
378
+ _context5.next = 2;
379
+ return ActionPopup({
380
+ mode: "tab",
381
+ url: loginUrl.toString(),
382
+ onCancel: function onCancel() {
383
+ return reject("User cancelled login");
384
+ },
385
+ onMessage: function () {
386
+ var _onMessage2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(event, Close) {
387
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
388
+ while (1) {
389
+ switch (_context4.prev = _context4.next) {
390
+ case 0:
391
+ if (!(!event || !event.data || event.data.type !== "LoginResponse")) {
392
+ _context4.next = 2;
393
+ break;
394
+ }
395
+
396
+ return _context4.abrupt("return");
397
+
398
+ case 2:
399
+ _context4.prev = 2;
400
+
401
+ if (!callback) {
402
+ _context4.next = 8;
403
+ break;
404
+ }
405
+
406
+ _context4.next = 6;
407
+ return callback(event.data.params);
408
+
409
+ case 6:
410
+ _context4.next = 10;
411
+ break;
412
+
413
+ case 8:
414
+ _context4.next = 10;
415
+ return _this.Authenticate({
416
+ token: event.data.params.clientSigningToken || event.data.params.clientAuthToken
417
+ });
418
+
419
+ case 10:
420
+ resolve();
421
+ _context4.next = 16;
422
+ break;
423
+
424
+ case 13:
425
+ _context4.prev = 13;
426
+ _context4.t0 = _context4["catch"](2);
427
+ reject(_context4.t0);
428
+
429
+ case 16:
430
+ _context4.prev = 16;
431
+ Close();
432
+ return _context4.finish(16);
433
+
434
+ case 19:
435
+ case "end":
436
+ return _context4.stop();
437
+ }
438
+ }
439
+ }, _callee4, null, [[2, 13, 16, 19]]);
440
+ }));
441
+
442
+ function onMessage(_x9, _x10) {
443
+ return _onMessage2.apply(this, arguments);
444
+ }
445
+
446
+ return onMessage;
447
+ }()
448
+ });
449
+
450
+ case 2:
451
+ case "end":
452
+ return _context5.stop();
453
+ }
454
+ }
455
+ }, _callee5);
456
+ }));
457
+
458
+ return function (_x7, _x8) {
459
+ return _ref5.apply(this, arguments);
460
+ };
461
+ }());
462
+
463
+ case 28:
464
+ case "end":
465
+ return _context6.stop();
466
+ }
467
+ }
468
+ }, _callee6, this);
469
+ }));
470
+
471
+ function LogIn(_x6) {
472
+ return _LogIn.apply(this, arguments);
473
+ }
474
+
475
+ return LogIn;
476
+ }()
477
+ /**
478
+ * Remove authorization for the current user.
479
+ *
480
+ * @methodGroup Login
481
+ */
482
+
483
+ }, {
484
+ key: "LogOut",
485
+ value: function LogOut() {
486
+ this.__authorization = {};
487
+ this.loggedIn = false;
488
+ this.cachedMarketplaces = {}; // Delete saved auth token
489
+
490
+ if (typeof localStorage !== "undefined") {
491
+ try {
492
+ localStorage.removeItem("__elv-token-".concat(this.network)); // eslint-disable-next-line no-empty
493
+ } catch (error) {}
494
+ }
495
+ }
496
+ /**
497
+ * Authenticate with an ElvWalletClient authorization token
498
+ *
499
+ * @methodGroup Authorization
500
+ * @namedParams
501
+ * @param {string} token - A previously generated ElvWalletClient authorization token;
502
+ */
503
+
504
+ }, {
505
+ key: "Authenticate",
506
+ value: function () {
507
+ var _Authenticate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref6) {
508
+ var token, decodedToken;
509
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
510
+ while (1) {
511
+ switch (_context7.prev = _context7.next) {
512
+ case 0:
513
+ token = _ref6.token;
514
+ _context7.prev = 1;
515
+ decodedToken = JSON.parse(this.utils.FromB58ToStr(token)) || {};
516
+ _context7.next = 8;
517
+ break;
518
+
519
+ case 5:
520
+ _context7.prev = 5;
521
+ _context7.t0 = _context7["catch"](1);
522
+ throw new Error("Invalid authorization token " + token);
523
+
524
+ case 8:
525
+ if (!(!decodedToken.expiresAt || Date.now() > decodedToken.expiresAt)) {
526
+ _context7.next = 10;
527
+ break;
528
+ }
529
+
530
+ throw Error("ElvWalletClient: Provided authorization token has expired");
531
+
532
+ case 10:
533
+ if (!decodedToken.clusterToken) {
534
+ _context7.next = 13;
535
+ break;
536
+ }
537
+
538
+ _context7.next = 13;
539
+ return this.client.SetRemoteSigner({
540
+ authToken: decodedToken.clusterToken
541
+ });
542
+
543
+ case 13:
544
+ this.client.SetStaticToken({
545
+ token: decodedToken.fabricToken
546
+ });
547
+ return _context7.abrupt("return", this.SetAuthorization(decodedToken));
548
+
549
+ case 15:
550
+ case "end":
551
+ return _context7.stop();
552
+ }
553
+ }
554
+ }, _callee7, this, [[1, 5]]);
555
+ }));
556
+
557
+ function Authenticate(_x11) {
558
+ return _Authenticate.apply(this, arguments);
559
+ }
560
+
561
+ return Authenticate;
562
+ }()
563
+ /**
564
+ * Authenticate with an OAuth ID token
565
+ *
566
+ * @methodGroup Authorization
567
+ * @namedParams
568
+ * @param {string} idToken - An OAuth ID token
569
+ * @param {string=} tenantId - ID of tenant with which to associate the user. If marketplace info was set upon initialization, this will be determined automatically.
570
+ * @param {string=} email - Email address of the user. If not specified, this method will attempt to extract the email from the ID token.
571
+ * @param {boolean=} shareEmail=false - Whether or not the user consents to sharing their email
572
+ * @param {number=} tokenDuration=24 - Number of hours the generated authorization token will last before expiring
573
+ *
574
+ * @returns {Promise<Object>} - Returns an authorization tokens that can be used to initialize the client using <a href="#Authenticate">Authenticate</a>.
575
+ * Save this token to avoid having to reauthenticate with OAuth. This token expires after 24 hours.
576
+ *
577
+ * The result includes two tokens:
578
+ * - token - Standard client auth token used to access content and perform actions on behalf of the user.
579
+ * - signingToken - Identical to `authToken`, but also includes the ability to perform arbitrary signatures with the custodial wallet. This token should be protected and should not be
580
+ * shared with third parties.
581
+ */
582
+
583
+ }, {
584
+ key: "AuthenticateOAuth",
585
+ value: function () {
586
+ var _AuthenticateOAuth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref7) {
587
+ var idToken, tenantId, email, _ref7$shareEmail, shareEmail, _ref7$tokenDuration, tokenDuration, expiresAt, fabricToken, address, decodedToken;
588
+
589
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
590
+ while (1) {
591
+ switch (_context8.prev = _context8.next) {
592
+ case 0:
593
+ idToken = _ref7.idToken, tenantId = _ref7.tenantId, email = _ref7.email, _ref7$shareEmail = _ref7.shareEmail, shareEmail = _ref7$shareEmail === void 0 ? false : _ref7$shareEmail, _ref7$tokenDuration = _ref7.tokenDuration, tokenDuration = _ref7$tokenDuration === void 0 ? 24 : _ref7$tokenDuration;
594
+
595
+ if (!(!tenantId && this.selectedMarketplaceInfo)) {
596
+ _context8.next = 5;
597
+ break;
598
+ }
599
+
600
+ _context8.next = 4;
601
+ return this.AvailableMarketplaces();
602
+
603
+ case 4:
604
+ tenantId = this.selectedMarketplaceInfo.tenantId;
605
+
606
+ case 5:
607
+ _context8.next = 7;
608
+ return this.client.SetRemoteSigner({
609
+ idToken: idToken,
610
+ tenantId: tenantId,
611
+ extraData: {
612
+ share_email: shareEmail
613
+ },
614
+ unsignedPublicAuth: true
615
+ });
616
+
617
+ case 7:
618
+ expiresAt = Date.now() + tokenDuration * 60 * 60 * 1000;
619
+ _context8.next = 10;
620
+ return this.client.CreateFabricToken({
621
+ duration: tokenDuration * 60 * 60 * 1000
622
+ });
623
+
624
+ case 10:
625
+ fabricToken = _context8.sent;
626
+ address = this.client.utils.FormatAddress(this.client.CurrentAccountAddress());
627
+
628
+ if (email) {
629
+ _context8.next = 21;
630
+ break;
631
+ }
632
+
633
+ _context8.prev = 13;
634
+ decodedToken = JSON.parse(this.utils.FromB64URL(idToken.split(".")[1]));
635
+ email = decodedToken.email;
636
+ _context8.next = 21;
637
+ break;
638
+
639
+ case 18:
640
+ _context8.prev = 18;
641
+ _context8.t0 = _context8["catch"](13);
642
+ throw Error("Failed to decode ID token");
643
+
644
+ case 21:
645
+ this.client.SetStaticToken({
646
+ token: fabricToken
647
+ });
648
+ return _context8.abrupt("return", {
649
+ authToken: this.SetAuthorization({
650
+ fabricToken: fabricToken,
651
+ tenantId: tenantId,
652
+ address: address,
653
+ email: email,
654
+ expiresAt: expiresAt,
655
+ walletType: "Custodial",
656
+ walletName: "Eluvio"
657
+ }),
658
+ signingToken: this.SetAuthorization({
659
+ clusterToken: this.client.signer.authToken,
660
+ fabricToken: fabricToken,
661
+ tenantId: tenantId,
662
+ address: address,
663
+ email: email,
664
+ expiresAt: expiresAt,
665
+ walletType: "Custodial",
666
+ walletName: "Eluvio"
667
+ })
668
+ });
669
+
670
+ case 23:
671
+ case "end":
672
+ return _context8.stop();
673
+ }
674
+ }
675
+ }, _callee8, this, [[13, 18]]);
676
+ }));
677
+
678
+ function AuthenticateOAuth(_x12) {
679
+ return _AuthenticateOAuth.apply(this, arguments);
680
+ }
681
+
682
+ return AuthenticateOAuth;
683
+ }()
684
+ /**
685
+ * Authenticate with an external Ethereum compatible wallet, like Metamask.
686
+ *
687
+ * @methodGroup Authorization
688
+ * @namedParams
689
+ * @param {string} address - The address of the wallet
690
+ * @param {number=} tokenDuration=24 - Number of hours the generated authorization token will last before expiring
691
+ * @param {string=} walletName=Metamask - Name of the external wallet
692
+ * @param {function=} Sign - The method used for signing by the wallet. If not specified, will attempt to sign with Metamask.
693
+ *
694
+ * @returns {Promise<string>} - Returns an authorization token that can be used to initialize the client using <a href="#Authenticate">Authenticate</a>.
695
+ * Save this token to avoid having to reauthenticate. This token expires after 24 hours.
696
+ */
697
+
698
+ }, {
699
+ key: "AuthenticateExternalWallet",
700
+ value: function () {
701
+ var _AuthenticateExternalWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref8) {
702
+ var _this2 = this;
703
+
704
+ var address, _ref8$tokenDuration, tokenDuration, _ref8$walletName, walletName, Sign, expiresAt, fabricToken;
705
+
706
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
707
+ while (1) {
708
+ switch (_context10.prev = _context10.next) {
709
+ case 0:
710
+ address = _ref8.address, _ref8$tokenDuration = _ref8.tokenDuration, tokenDuration = _ref8$tokenDuration === void 0 ? 24 : _ref8$tokenDuration, _ref8$walletName = _ref8.walletName, walletName = _ref8$walletName === void 0 ? "Metamask" : _ref8$walletName, Sign = _ref8.Sign;
711
+
712
+ if (!address) {
713
+ address = window.ethereum.selectedAddress;
714
+ }
715
+
716
+ address = this.utils.FormatAddress(address);
717
+
718
+ if (!Sign) {
719
+ Sign = /*#__PURE__*/function () {
720
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(message) {
721
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
722
+ while (1) {
723
+ switch (_context9.prev = _context9.next) {
724
+ case 0:
725
+ return _context9.abrupt("return", _this2.SignMetamask({
726
+ message: message,
727
+ address: address
728
+ }));
729
+
730
+ case 1:
731
+ case "end":
732
+ return _context9.stop();
733
+ }
734
+ }
735
+ }, _callee9);
736
+ }));
737
+
738
+ return function Sign(_x14) {
739
+ return _ref9.apply(this, arguments);
740
+ };
741
+ }();
742
+ }
743
+
744
+ expiresAt = Date.now() + tokenDuration * 60 * 60 * 1000;
745
+ _context10.next = 7;
746
+ return this.client.CreateFabricToken({
747
+ address: address,
748
+ duration: tokenDuration * 60 * 60 * 1000,
749
+ Sign: Sign,
750
+ addEthereumPrefix: false
751
+ });
752
+
753
+ case 7:
754
+ fabricToken = _context10.sent;
755
+ return _context10.abrupt("return", this.SetAuthorization({
756
+ fabricToken: fabricToken,
757
+ address: address,
758
+ expiresAt: expiresAt,
759
+ walletType: "External",
760
+ walletName: walletName
761
+ }));
762
+
763
+ case 9:
764
+ case "end":
765
+ return _context10.stop();
766
+ }
767
+ }
768
+ }, _callee10, this);
769
+ }));
770
+
771
+ function AuthenticateExternalWallet(_x13) {
772
+ return _AuthenticateExternalWallet.apply(this, arguments);
773
+ }
774
+
775
+ return AuthenticateExternalWallet;
776
+ }()
777
+ /**
778
+ * <b><i>Requires login</i></b>
779
+ *
780
+ * Retrieve the current client auth token
781
+ *
782
+ * @returns {string} - The client auth token
783
+ */
784
+
785
+ }, {
786
+ key: "ClientAuthToken",
787
+ value: function ClientAuthToken() {
788
+ if (!this.loggedIn) {
789
+ return "";
790
+ }
791
+
792
+ return this.utils.B58(JSON.stringify(this.__authorization));
793
+ }
794
+ }, {
795
+ key: "AuthToken",
796
+ value: function AuthToken() {
797
+ if (!this.loggedIn) {
798
+ return this.publicStaticToken;
799
+ }
800
+
801
+ return this.__authorization.fabricToken;
802
+ }
803
+ }, {
804
+ key: "SetAuthorization",
805
+ value: function SetAuthorization(_ref10) {
806
+ var clusterToken = _ref10.clusterToken,
807
+ fabricToken = _ref10.fabricToken,
808
+ tenantId = _ref10.tenantId,
809
+ address = _ref10.address,
810
+ email = _ref10.email,
811
+ expiresAt = _ref10.expiresAt,
812
+ walletType = _ref10.walletType,
813
+ walletName = _ref10.walletName;
814
+ address = this.client.utils.FormatAddress(address);
815
+ this.__authorization = {
816
+ fabricToken: fabricToken,
817
+ tenantId: tenantId,
818
+ address: address,
819
+ email: email,
820
+ expiresAt: expiresAt,
821
+ walletType: walletType,
822
+ walletName: walletName
823
+ };
824
+
825
+ if (clusterToken) {
826
+ this.__authorization.clusterToken = clusterToken;
827
+ }
828
+
829
+ this.loggedIn = true;
830
+ this.cachedMarketplaces = {};
831
+ var token = this.ClientAuthToken();
832
+
833
+ if (this.storeAuthToken && typeof localStorage !== "undefined") {
834
+ try {
835
+ localStorage.setItem("__elv-token-".concat(this.network), token); // eslint-disable-next-line no-empty
836
+ } catch (error) {}
837
+ }
838
+
839
+ return token;
840
+ }
841
+ }, {
842
+ key: "SignMetamask",
843
+ value: function () {
844
+ var _SignMetamask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref11) {
845
+ var message, address, accounts;
846
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
847
+ while (1) {
848
+ switch (_context11.prev = _context11.next) {
849
+ case 0:
850
+ message = _ref11.message, address = _ref11.address;
851
+
852
+ if (window.ethereum) {
853
+ _context11.next = 3;
854
+ break;
855
+ }
856
+
857
+ throw Error("ElvWalletClient: Unable to initialize - Metamask not available");
858
+
859
+ case 3:
860
+ address = address || this.UserAddress();
861
+ _context11.next = 6;
862
+ return window.ethereum.request({
863
+ method: "eth_requestAccounts"
864
+ });
865
+
866
+ case 6:
867
+ accounts = _context11.sent;
868
+
869
+ if (!(address && !Utils.EqualAddress(accounts[0], address))) {
870
+ _context11.next = 9;
871
+ break;
872
+ }
873
+
874
+ throw Error("ElvWalletClient: Incorrect MetaMask account selected. Expected ".concat(address, ", got ").concat(accounts[0]));
875
+
876
+ case 9:
877
+ _context11.next = 11;
878
+ return window.ethereum.request({
879
+ method: "personal_sign",
880
+ params: [message, address, ""]
881
+ });
882
+
883
+ case 11:
884
+ return _context11.abrupt("return", _context11.sent);
885
+
886
+ case 12:
887
+ case "end":
888
+ return _context11.stop();
889
+ }
890
+ }
891
+ }, _callee11, this);
892
+ }));
893
+
894
+ function SignMetamask(_x15) {
895
+ return _SignMetamask.apply(this, arguments);
896
+ }
897
+
898
+ return SignMetamask;
899
+ }() // Internal loading methods
900
+ // If marketplace slug is specified, load only that marketplace. Otherwise load all
901
+
902
+ }, {
903
+ key: "LoadAvailableMarketplaces",
904
+ value: function () {
905
+ var _LoadAvailableMarketplaces = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
906
+ var _this3 = this;
907
+
908
+ var forceReload,
909
+ mainSiteHash,
910
+ metadata,
911
+ availableMarketplaces,
912
+ availableMarketplacesById,
913
+ _args12 = arguments;
914
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
915
+ while (1) {
916
+ switch (_context12.prev = _context12.next) {
917
+ case 0:
918
+ forceReload = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : false;
919
+
920
+ if (!(!forceReload && Object.keys(this.availableMarketplaces) > 0)) {
921
+ _context12.next = 3;
922
+ break;
923
+ }
924
+
925
+ return _context12.abrupt("return");
926
+
927
+ case 3:
928
+ _context12.next = 5;
929
+ return this.client.LatestVersionHash({
930
+ objectId: this.mainSiteId
931
+ });
932
+
933
+ case 5:
934
+ mainSiteHash = _context12.sent;
935
+ _context12.next = 8;
936
+ return this.client.ContentObjectMetadata({
937
+ versionHash: mainSiteHash,
938
+ metadataSubtree: "public/asset_metadata/tenants",
939
+ resolveLinks: true,
940
+ linkDepthLimit: 2,
941
+ resolveIncludeSource: true,
942
+ resolveIgnoreErrors: true,
943
+ produceLinkUrls: true,
944
+ authorizationToken: this.publicStaticToken,
945
+ noAuth: true,
946
+ select: ["*/.", "*/marketplaces/*/.", "*/marketplaces/*/info/tenant_id", "*/marketplaces/*/info/tenant_name", "*/marketplaces/*/info/branding"],
947
+ remove: ["*/marketplaces/*/info/branding/custom_css"]
948
+ });
949
+
950
+ case 8:
951
+ metadata = _context12.sent;
952
+ availableMarketplaces = _objectSpread({}, this.availableMarketplaces || {});
953
+ availableMarketplacesById = _objectSpread({}, this.availableMarketplacesById || {});
954
+ Object.keys(metadata || {}).forEach(function (tenantSlug) {
955
+ try {
956
+ availableMarketplaces[tenantSlug] = {
957
+ versionHash: metadata[tenantSlug]["."].source
958
+ };
959
+ Object.keys(metadata[tenantSlug].marketplaces || {}).forEach(function (marketplaceSlug) {
960
+ try {
961
+ var versionHash = metadata[tenantSlug].marketplaces[marketplaceSlug]["."].source;
962
+
963
+ var objectId = _this3.utils.DecodeVersionHash(versionHash).objectId;
964
+
965
+ availableMarketplaces[tenantSlug][marketplaceSlug] = _objectSpread(_objectSpread({}, metadata[tenantSlug].marketplaces[marketplaceSlug].info || {}), {}, {
966
+ tenantName: metadata[tenantSlug].marketplaces[marketplaceSlug].info.tenant_name,
967
+ tenantId: metadata[tenantSlug].marketplaces[marketplaceSlug].info.tenant_id,
968
+ tenantSlug: tenantSlug,
969
+ marketplaceSlug: marketplaceSlug,
970
+ marketplaceId: objectId,
971
+ marketplaceHash: versionHash,
972
+ order: Configuration.__MARKETPLACE_ORDER.findIndex(function (slug) {
973
+ return slug === marketplaceSlug;
974
+ })
975
+ });
976
+ availableMarketplacesById[objectId] = availableMarketplaces[tenantSlug][marketplaceSlug];
977
+ _this3.marketplaceHashes[objectId] = versionHash; // Fill out selected marketplace info
978
+
979
+ if (_this3.selectedMarketplaceInfo) {
980
+ if (_this3.selectedMarketplaceInfo.tenantSlug === tenantSlug && _this3.selectedMarketplaceInfo.marketplaceSlug === marketplaceSlug || _this3.selectedMarketplaceInfo.marketplaceId === objectId) {
981
+ _this3.selectedMarketplaceInfo = availableMarketplaces[tenantSlug][marketplaceSlug];
982
+ }
983
+ }
984
+ } catch (error) {
985
+ _this3.Log("Eluvio Wallet Client: Unable to load info for marketplace ".concat(tenantSlug, "/").concat(marketplaceSlug), true);
986
+ }
987
+ });
988
+ } catch (error) {
989
+ _this3.Log("Eluvio Wallet Client: Failed to load tenant info ".concat(tenantSlug), true);
990
+
991
+ _this3.Log(error, true);
992
+ }
993
+ });
994
+ this.availableMarketplaces = availableMarketplaces;
995
+ this.availableMarketplacesById = availableMarketplacesById;
996
+
997
+ case 14:
998
+ case "end":
999
+ return _context12.stop();
1000
+ }
1001
+ }
1002
+ }, _callee12, this);
1003
+ }));
1004
+
1005
+ function LoadAvailableMarketplaces() {
1006
+ return _LoadAvailableMarketplaces.apply(this, arguments);
1007
+ }
1008
+
1009
+ return LoadAvailableMarketplaces;
1010
+ }() // Get the hash of the currently linked marketplace
1011
+
1012
+ }, {
1013
+ key: "LatestMarketplaceHash",
1014
+ value: function () {
1015
+ var _LatestMarketplaceHash = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref12) {
1016
+ var tenantSlug, marketplaceSlug, mainSiteHash, marketplaceLink;
1017
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
1018
+ while (1) {
1019
+ switch (_context13.prev = _context13.next) {
1020
+ case 0:
1021
+ tenantSlug = _ref12.tenantSlug, marketplaceSlug = _ref12.marketplaceSlug;
1022
+ _context13.next = 3;
1023
+ return this.client.LatestVersionHash({
1024
+ objectId: this.mainSiteId
1025
+ });
1026
+
1027
+ case 3:
1028
+ mainSiteHash = _context13.sent;
1029
+ _context13.next = 6;
1030
+ return this.client.ContentObjectMetadata({
1031
+ versionHash: mainSiteHash,
1032
+ metadataSubtree: UrlJoin("/public", "asset_metadata", "tenants", tenantSlug, "marketplaces", marketplaceSlug),
1033
+ resolveLinks: false
1034
+ });
1035
+
1036
+ case 6:
1037
+ marketplaceLink = _context13.sent;
1038
+ return _context13.abrupt("return", LinkTargetHash(marketplaceLink));
1039
+
1040
+ case 8:
1041
+ case "end":
1042
+ return _context13.stop();
1043
+ }
1044
+ }
1045
+ }, _callee13, this);
1046
+ }));
1047
+
1048
+ function LatestMarketplaceHash(_x16) {
1049
+ return _LatestMarketplaceHash.apply(this, arguments);
1050
+ }
1051
+
1052
+ return LatestMarketplaceHash;
1053
+ }()
1054
+ }, {
1055
+ key: "LoadMarketplace",
1056
+ value: function () {
1057
+ var _LoadMarketplace = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(marketplaceParams) {
1058
+ var _this4 = this;
1059
+
1060
+ var marketplaceInfo, marketplaceId, marketplaceHash, marketplace;
1061
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1062
+ while (1) {
1063
+ switch (_context15.prev = _context15.next) {
1064
+ case 0:
1065
+ marketplaceInfo = this.MarketplaceInfo({
1066
+ marketplaceParams: marketplaceParams
1067
+ });
1068
+ marketplaceId = marketplaceInfo.marketplaceId;
1069
+ _context15.next = 4;
1070
+ return this.LatestMarketplaceHash({
1071
+ tenantSlug: marketplaceInfo.tenantSlug,
1072
+ marketplaceSlug: marketplaceInfo.marketplaceSlug
1073
+ });
1074
+
1075
+ case 4:
1076
+ marketplaceHash = _context15.sent;
1077
+
1078
+ if (this.cachedMarketplaces[marketplaceId] && this.cachedMarketplaces[marketplaceId].versionHash !== marketplaceHash) {
1079
+ delete this.cachedMarketplaces[marketplaceId];
1080
+ }
1081
+
1082
+ if (this.cachedMarketplaces[marketplaceId]) {
1083
+ _context15.next = 19;
1084
+ break;
1085
+ }
1086
+
1087
+ _context15.next = 9;
1088
+ return this.client.ContentObjectMetadata({
1089
+ versionHash: marketplaceHash,
1090
+ metadataSubtree: "public/asset_metadata/info",
1091
+ linkDepthLimit: 2,
1092
+ resolveLinks: true,
1093
+ resolveIgnoreErrors: true,
1094
+ resolveIncludeSource: true,
1095
+ produceLinkUrls: true,
1096
+ authorizationToken: this.publicStaticToken
1097
+ });
1098
+
1099
+ case 9:
1100
+ marketplace = _context15.sent;
1101
+ _context15.next = 12;
1102
+ return Promise.all(marketplace.items.map( /*#__PURE__*/function () {
1103
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(item, index) {
1104
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
1105
+ while (1) {
1106
+ switch (_context14.prev = _context14.next) {
1107
+ case 0:
1108
+ if (!item.requires_permissions) {
1109
+ _context14.next = 14;
1110
+ break;
1111
+ }
1112
+
1113
+ if (_this4.loggedIn) {
1114
+ _context14.next = 5;
1115
+ break;
1116
+ }
1117
+
1118
+ item.authorized = false;
1119
+ _context14.next = 14;
1120
+ break;
1121
+
1122
+ case 5:
1123
+ _context14.prev = 5;
1124
+ _context14.next = 8;
1125
+ return _this4.client.ContentObjectMetadata({
1126
+ versionHash: LinkTargetHash(item.nft_template),
1127
+ metadataSubtree: "permissioned"
1128
+ });
1129
+
1130
+ case 8:
1131
+ item.authorized = true;
1132
+ _context14.next = 14;
1133
+ break;
1134
+
1135
+ case 11:
1136
+ _context14.prev = 11;
1137
+ _context14.t0 = _context14["catch"](5);
1138
+ item.authorized = false;
1139
+
1140
+ case 14:
1141
+ item.nftTemplateMetadata = (item.nft_template || {}).nft || {};
1142
+ item.itemIndex = index;
1143
+ return _context14.abrupt("return", item);
1144
+
1145
+ case 17:
1146
+ case "end":
1147
+ return _context14.stop();
1148
+ }
1149
+ }
1150
+ }, _callee14, null, [[5, 11]]);
1151
+ }));
1152
+
1153
+ return function (_x18, _x19) {
1154
+ return _ref13.apply(this, arguments);
1155
+ };
1156
+ }()));
1157
+
1158
+ case 12:
1159
+ marketplace.items = _context15.sent;
1160
+ marketplace.collections = (marketplace.collections || []).map(function (collection, collectionIndex) {
1161
+ return _objectSpread(_objectSpread({}, collection), {}, {
1162
+ collectionIndex: collectionIndex
1163
+ });
1164
+ });
1165
+ marketplace.retrievedAt = Date.now();
1166
+ marketplace.marketplaceId = marketplaceId;
1167
+ marketplace.versionHash = marketplaceHash; // Generate embed URLs for pack opening animations
1168
+
1169
+ ["purchase_animation", "purchase_animation__mobile", "reveal_animation", "reveal_animation_mobile"].forEach(function (key) {
1170
+ try {
1171
+ if (marketplace.storefront[key]) {
1172
+ var embedUrl = new URL("https://embed.v3.contentfabric.io");
1173
+ var targetHash = LinkTargetHash(marketplace.storefront[key]);
1174
+ embedUrl.searchParams.set("p", "");
1175
+ embedUrl.searchParams.set("net", _this4.network === "main" ? "main" : "demo");
1176
+ embedUrl.searchParams.set("ath", (_this4.__authorization || {}).authToken || _this4.publicStaticToken);
1177
+ embedUrl.searchParams.set("vid", targetHash);
1178
+ embedUrl.searchParams.set("ap", "");
1179
+
1180
+ if (!key.startsWith("reveal")) {
1181
+ embedUrl.searchParams.set("m", "");
1182
+ embedUrl.searchParams.set("lp", "");
1183
+ }
1184
+
1185
+ marketplace.storefront["".concat(key, "_embed_url")] = embedUrl.toString();
1186
+ } // eslint-disable-next-line no-empty
1187
+
1188
+ } catch (error) {}
1189
+ });
1190
+ this.cachedMarketplaces[marketplaceId] = marketplace;
1191
+
1192
+ case 19:
1193
+ return _context15.abrupt("return", this.cachedMarketplaces[marketplaceId]);
1194
+
1195
+ case 20:
1196
+ case "end":
1197
+ return _context15.stop();
1198
+ }
1199
+ }
1200
+ }, _callee15, this);
1201
+ }));
1202
+
1203
+ function LoadMarketplace(_x17) {
1204
+ return _LoadMarketplace.apply(this, arguments);
1205
+ }
1206
+
1207
+ return LoadMarketplace;
1208
+ }()
1209
+ }, {
1210
+ key: "FilteredQuery",
1211
+ value: function () {
1212
+ var _FilteredQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
1213
+ var _ref14,
1214
+ _ref14$mode,
1215
+ mode,
1216
+ _ref14$sortBy,
1217
+ sortBy,
1218
+ _ref14$sortDesc,
1219
+ sortDesc,
1220
+ filter,
1221
+ editionFilter,
1222
+ attributeFilters,
1223
+ contractAddress,
1224
+ tokenId,
1225
+ currency,
1226
+ marketplaceParams,
1227
+ tenantId,
1228
+ _ref14$collectionInde,
1229
+ collectionIndex,
1230
+ sellerAddress,
1231
+ _ref14$lastNDays,
1232
+ lastNDays,
1233
+ _ref14$start,
1234
+ start,
1235
+ _ref14$limit,
1236
+ limit,
1237
+ params,
1238
+ marketplaceInfo,
1239
+ marketplace,
1240
+ filters,
1241
+ collection,
1242
+ path,
1243
+ _ref16,
1244
+ contents,
1245
+ paging,
1246
+ _args16 = arguments;
1247
+
1248
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
1249
+ while (1) {
1250
+ switch (_context16.prev = _context16.next) {
1251
+ case 0:
1252
+ _ref14 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, _ref14$mode = _ref14.mode, mode = _ref14$mode === void 0 ? "listings" : _ref14$mode, _ref14$sortBy = _ref14.sortBy, sortBy = _ref14$sortBy === void 0 ? "created" : _ref14$sortBy, _ref14$sortDesc = _ref14.sortDesc, sortDesc = _ref14$sortDesc === void 0 ? false : _ref14$sortDesc, filter = _ref14.filter, editionFilter = _ref14.editionFilter, attributeFilters = _ref14.attributeFilters, contractAddress = _ref14.contractAddress, tokenId = _ref14.tokenId, currency = _ref14.currency, marketplaceParams = _ref14.marketplaceParams, tenantId = _ref14.tenantId, _ref14$collectionInde = _ref14.collectionIndex, collectionIndex = _ref14$collectionInde === void 0 ? -1 : _ref14$collectionInde, sellerAddress = _ref14.sellerAddress, _ref14$lastNDays = _ref14.lastNDays, lastNDays = _ref14$lastNDays === void 0 ? -1 : _ref14$lastNDays, _ref14$start = _ref14.start, start = _ref14$start === void 0 ? 0 : _ref14$start, _ref14$limit = _ref14.limit, limit = _ref14$limit === void 0 ? 50 : _ref14$limit;
1253
+ collectionIndex = parseInt(collectionIndex);
1254
+ params = {
1255
+ sort_by: sortBy,
1256
+ sort_descending: sortDesc,
1257
+ start: start,
1258
+ limit: limit
1259
+ };
1260
+
1261
+ if (!marketplaceParams) {
1262
+ _context16.next = 11;
1263
+ break;
1264
+ }
1265
+
1266
+ _context16.next = 6;
1267
+ return this.MarketplaceInfo({
1268
+ marketplaceParams: marketplaceParams
1269
+ });
1270
+
1271
+ case 6:
1272
+ marketplaceInfo = _context16.sent;
1273
+
1274
+ if (!(collectionIndex >= 0)) {
1275
+ _context16.next = 11;
1276
+ break;
1277
+ }
1278
+
1279
+ _context16.next = 10;
1280
+ return this.Marketplace({
1281
+ marketplaceParams: marketplaceParams
1282
+ });
1283
+
1284
+ case 10:
1285
+ marketplace = _context16.sent;
1286
+
1287
+ case 11:
1288
+ _context16.prev = 11;
1289
+ filters = [];
1290
+
1291
+ if (sellerAddress) {
1292
+ filters.push("seller:eq:".concat(this.client.utils.FormatAddress(sellerAddress)));
1293
+ }
1294
+
1295
+ if (!(marketplace && collectionIndex >= 0)) {
1296
+ _context16.next = 25;
1297
+ break;
1298
+ }
1299
+
1300
+ collection = marketplace.collections[collectionIndex];
1301
+ collection.items.forEach(function (sku) {
1302
+ if (!sku) {
1303
+ return;
1304
+ }
1305
+
1306
+ var item = marketplace.items.find(function (item) {
1307
+ return item.sku === sku;
1308
+ });
1309
+
1310
+ if (!item) {
1311
+ return;
1312
+ }
1313
+
1314
+ var address = Utils.SafeTraverse(item, "nft_template", "nft", "address");
1315
+
1316
+ if (address) {
1317
+ filters.push("".concat(mode === "owned" ? "contract_addr" : "contract", ":eq:").concat(Utils.FormatAddress(address)));
1318
+ }
1319
+ }); // No valid items, so there must not be anything relevant in the collection
1320
+
1321
+ if (!(filters.length === 0)) {
1322
+ _context16.next = 23;
1323
+ break;
1324
+ }
1325
+
1326
+ if (!mode.includes("stats")) {
1327
+ _context16.next = 22;
1328
+ break;
1329
+ }
1330
+
1331
+ return _context16.abrupt("return", {});
1332
+
1333
+ case 22:
1334
+ return _context16.abrupt("return", {
1335
+ paging: {
1336
+ start: params.start,
1337
+ limit: params.limit,
1338
+ total: 0,
1339
+ more: false
1340
+ },
1341
+ results: []
1342
+ });
1343
+
1344
+ case 23:
1345
+ _context16.next = 26;
1346
+ break;
1347
+
1348
+ case 25:
1349
+ if (mode !== "owned" && marketplaceInfo || tenantId) {
1350
+ filters.push("tenant:eq:".concat(marketplaceInfo ? marketplaceInfo.tenantId : tenantId));
1351
+ }
1352
+
1353
+ case 26:
1354
+ if (contractAddress) {
1355
+ if (mode === "owned") {
1356
+ filters.push("contract_addr:eq:".concat(Utils.FormatAddress(contractAddress)));
1357
+ } else {
1358
+ filters.push("contract:eq:".concat(Utils.FormatAddress(contractAddress)));
1359
+ }
1360
+
1361
+ if (tokenId) {
1362
+ filters.push("token:eq:".concat(tokenId));
1363
+ }
1364
+ } else if (filter) {
1365
+ if (mode.includes("listing")) {
1366
+ filters.push("nft/display_name:eq:".concat(filter));
1367
+ } else if (mode === "owned") {
1368
+ filters.push("meta:@>:{\"display_name\":\"".concat(filter, "\"}"));
1369
+ params.exact = false;
1370
+ } else {
1371
+ filters.push("name:eq:".concat(filter));
1372
+ }
1373
+ }
1374
+
1375
+ if (editionFilter) {
1376
+ if (mode.includes("listing")) {
1377
+ filters.push("nft/edition_name:eq:".concat(editionFilter));
1378
+ } else if (mode === "owned") {
1379
+ filters.push("meta:@>:{\"edition_name\":\"".concat(editionFilter, "\"}"));
1380
+ params.exact = false;
1381
+ } else {
1382
+ filters.push("edition:eq:".concat(editionFilter));
1383
+ }
1384
+ }
1385
+
1386
+ if (attributeFilters) {
1387
+ attributeFilters.map(function (_ref15) {
1388
+ var name = _ref15.name,
1389
+ value = _ref15.value;
1390
+
1391
+ if (!name || !value) {
1392
+ return;
1393
+ }
1394
+
1395
+ filters.push("nft/attributes/".concat(name, ":eq:").concat(value));
1396
+ });
1397
+ }
1398
+
1399
+ if (currency) {
1400
+ filters.push("link_type:eq:sol");
1401
+ }
1402
+
1403
+ if (lastNDays && lastNDays > 0) {
1404
+ filters.push("created:gt:".concat((Date.now() / 1000 - lastNDays * 24 * 60 * 60).toFixed(0)));
1405
+ }
1406
+
1407
+ _context16.t0 = mode;
1408
+ _context16.next = _context16.t0 === "owned" ? 34 : _context16.t0 === "listings" ? 37 : _context16.t0 === "transfers" ? 39 : _context16.t0 === "sales" ? 41 : _context16.t0 === "listing-stats" ? 44 : _context16.t0 === "sales-stats" ? 46 : 48;
1409
+ break;
1410
+
1411
+ case 34:
1412
+ path = UrlJoin("as", "wlt", "nfts");
1413
+
1414
+ if (marketplaceInfo) {
1415
+ path = UrlJoin("as", "wlt", "nfts", marketplaceInfo.tenantId);
1416
+ }
1417
+
1418
+ return _context16.abrupt("break", 48);
1419
+
1420
+ case 37:
1421
+ path = UrlJoin("as", "mkt", "f");
1422
+ return _context16.abrupt("break", 48);
1423
+
1424
+ case 39:
1425
+ path = UrlJoin("as", "mkt", "hst", "f");
1426
+ return _context16.abrupt("break", 48);
1427
+
1428
+ case 41:
1429
+ path = UrlJoin("as", "mkt", "hst", "f");
1430
+ filters.push("action:eq:SOLD");
1431
+ return _context16.abrupt("break", 48);
1432
+
1433
+ case 44:
1434
+ path = UrlJoin("as", "mkt", "stats", "listed");
1435
+ return _context16.abrupt("break", 48);
1436
+
1437
+ case 46:
1438
+ path = UrlJoin("as", "mkt", "stats", "sold");
1439
+ return _context16.abrupt("break", 48);
1440
+
1441
+ case 48:
1442
+ if (filters.length > 0) {
1443
+ params.filter = filters;
1444
+ }
1445
+
1446
+ if (!mode.includes("stats")) {
1447
+ _context16.next = 53;
1448
+ break;
1449
+ }
1450
+
1451
+ _context16.next = 52;
1452
+ return Utils.ResponseToJson(this.client.authClient.MakeAuthServiceRequest({
1453
+ path: path,
1454
+ method: "GET",
1455
+ queryParams: params
1456
+ }));
1457
+
1458
+ case 52:
1459
+ return _context16.abrupt("return", _context16.sent);
1460
+
1461
+ case 53:
1462
+ _context16.t2 = Utils;
1463
+ _context16.next = 56;
1464
+ return this.client.authClient.MakeAuthServiceRequest({
1465
+ path: path,
1466
+ method: "GET",
1467
+ queryParams: params,
1468
+ headers: mode === "owned" ? {
1469
+ Authorization: "Bearer ".concat(this.AuthToken())
1470
+ } : {}
1471
+ });
1472
+
1473
+ case 56:
1474
+ _context16.t3 = _context16.sent;
1475
+ _context16.next = 59;
1476
+ return _context16.t2.ResponseToJson.call(_context16.t2, _context16.t3);
1477
+
1478
+ case 59:
1479
+ _context16.t1 = _context16.sent;
1480
+
1481
+ if (_context16.t1) {
1482
+ _context16.next = 62;
1483
+ break;
1484
+ }
1485
+
1486
+ _context16.t1 = [];
1487
+
1488
+ case 62:
1489
+ _ref16 = _context16.t1;
1490
+ contents = _ref16.contents;
1491
+ paging = _ref16.paging;
1492
+ return _context16.abrupt("return", {
1493
+ paging: {
1494
+ start: params.start,
1495
+ limit: params.limit,
1496
+ total: paging.total,
1497
+ more: paging.total > start + limit
1498
+ },
1499
+ results: (contents || []).map(function (item) {
1500
+ return ["owned", "listings"].includes(mode) ? FormatNFT(item) : item;
1501
+ })
1502
+ });
1503
+
1504
+ case 68:
1505
+ _context16.prev = 68;
1506
+ _context16.t4 = _context16["catch"](11);
1507
+
1508
+ if (!(_context16.t4.status && _context16.t4.status.toString() === "404")) {
1509
+ _context16.next = 72;
1510
+ break;
1511
+ }
1512
+
1513
+ return _context16.abrupt("return", {
1514
+ paging: {
1515
+ start: params.start,
1516
+ limit: params.limit,
1517
+ total: 0,
1518
+ more: false
1519
+ },
1520
+ results: []
1521
+ });
1522
+
1523
+ case 72:
1524
+ throw _context16.t4;
1525
+
1526
+ case 73:
1527
+ case "end":
1528
+ return _context16.stop();
1529
+ }
1530
+ }
1531
+ }, _callee16, this, [[11, 68]]);
1532
+ }));
1533
+
1534
+ function FilteredQuery() {
1535
+ return _FilteredQuery.apply(this, arguments);
1536
+ }
1537
+
1538
+ return FilteredQuery;
1539
+ }()
1540
+ }, {
1541
+ key: "MintingStatus",
1542
+ value: function () {
1543
+ var _MintingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref17) {
1544
+ var marketplaceParams, tenantId, marketplaceInfo, response;
1545
+ return _regeneratorRuntime.wrap(function _callee17$(_context17) {
1546
+ while (1) {
1547
+ switch (_context17.prev = _context17.next) {
1548
+ case 0:
1549
+ marketplaceParams = _ref17.marketplaceParams, tenantId = _ref17.tenantId;
1550
+
1551
+ if (tenantId) {
1552
+ _context17.next = 6;
1553
+ break;
1554
+ }
1555
+
1556
+ _context17.next = 4;
1557
+ return this.MarketplaceInfo({
1558
+ marketplaceParams: marketplaceParams || this.selectedMarketplaceInfo
1559
+ });
1560
+
1561
+ case 4:
1562
+ marketplaceInfo = _context17.sent;
1563
+ tenantId = marketplaceInfo.tenantId;
1564
+
1565
+ case 6:
1566
+ _context17.prev = 6;
1567
+ _context17.next = 9;
1568
+ return Utils.ResponseToJson(this.client.authClient.MakeAuthServiceRequest({
1569
+ path: UrlJoin("as", "wlt", "status", "act", tenantId),
1570
+ method: "GET",
1571
+ headers: {
1572
+ Authorization: "Bearer ".concat(this.AuthToken())
1573
+ }
1574
+ }));
1575
+
1576
+ case 9:
1577
+ response = _context17.sent;
1578
+ return _context17.abrupt("return", response.map(function (status) {
1579
+ var _status$op$split = status.op.split(":"),
1580
+ _status$op$split2 = _slicedToArray(_status$op$split, 3),
1581
+ op = _status$op$split2[0],
1582
+ address = _status$op$split2[1],
1583
+ id = _status$op$split2[2];
1584
+
1585
+ address = address.startsWith("0x") ? Utils.FormatAddress(address) : address;
1586
+ var confirmationId, tokenId;
1587
+
1588
+ if (op === "nft-buy") {
1589
+ confirmationId = id;
1590
+ } else if (op === "nft-claim") {
1591
+ confirmationId = id;
1592
+ status.marketplaceId = address;
1593
+
1594
+ if (status.extra && status.extra["0"]) {
1595
+ address = status.extra.token_addr;
1596
+ tokenId = status.extra.token_id_str;
1597
+ }
1598
+ } else if (op === "nft-redeem") {
1599
+ confirmationId = status.op.split(":").slice(-1)[0];
1600
+ } else {
1601
+ tokenId = id;
1602
+ }
1603
+
1604
+ if (op === "nft-transfer") {
1605
+ confirmationId = status.extra && status.extra.trans_id;
1606
+ }
1607
+
1608
+ return _objectSpread(_objectSpread({}, status), {}, {
1609
+ timestamp: new Date(status.ts),
1610
+ state: status.state && _typeof(status.state) === "object" ? Object.values(status.state) : status.state,
1611
+ extra: status.extra && _typeof(status.extra) === "object" ? Object.values(status.extra) : status.extra,
1612
+ confirmationId: confirmationId,
1613
+ op: op,
1614
+ address: address,
1615
+ tokenId: tokenId
1616
+ });
1617
+ }).sort(function (a, b) {
1618
+ return a.ts < b.ts ? 1 : -1;
1619
+ }));
1620
+
1621
+ case 13:
1622
+ _context17.prev = 13;
1623
+ _context17.t0 = _context17["catch"](6);
1624
+ this.Log("Failed to retrieve minting status", true);
1625
+ this.Log(_context17.t0);
1626
+ return _context17.abrupt("return", []);
1627
+
1628
+ case 18:
1629
+ case "end":
1630
+ return _context17.stop();
1631
+ }
1632
+ }
1633
+ }, _callee17, this, [[6, 13]]);
1634
+ }));
1635
+
1636
+ function MintingStatus(_x20) {
1637
+ return _MintingStatus.apply(this, arguments);
1638
+ }
1639
+
1640
+ return MintingStatus;
1641
+ }()
1642
+ }], [{
1643
+ key: "Initialize",
1644
+ value: function () {
1645
+ var _Initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref18) {
1646
+ var _ref18$network, network, _ref18$mode, mode, marketplaceParams, _ref18$storeAuthToken, storeAuthToken, _ref19, tenantSlug, marketplaceSlug, marketplaceId, marketplaceHash, client, walletClient, url, savedToken;
1647
+
1648
+ return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1649
+ while (1) {
1650
+ switch (_context18.prev = _context18.next) {
1651
+ case 0:
1652
+ _ref18$network = _ref18.network, network = _ref18$network === void 0 ? "main" : _ref18$network, _ref18$mode = _ref18.mode, mode = _ref18$mode === void 0 ? "production" : _ref18$mode, marketplaceParams = _ref18.marketplaceParams, _ref18$storeAuthToken = _ref18.storeAuthToken, storeAuthToken = _ref18$storeAuthToken === void 0 ? true : _ref18$storeAuthToken;
1653
+ _ref19 = marketplaceParams || {}, tenantSlug = _ref19.tenantSlug, marketplaceSlug = _ref19.marketplaceSlug, marketplaceId = _ref19.marketplaceId, marketplaceHash = _ref19.marketplaceHash;
1654
+
1655
+ if (Configuration[network]) {
1656
+ _context18.next = 6;
1657
+ break;
1658
+ }
1659
+
1660
+ throw Error("ElvWalletClient: Invalid network ".concat(network));
1661
+
1662
+ case 6:
1663
+ if (Configuration[network][mode]) {
1664
+ _context18.next = 8;
1665
+ break;
1666
+ }
1667
+
1668
+ throw Error("ElvWalletClient: Invalid mode ".concat(mode));
1669
+
1670
+ case 8:
1671
+ _context18.next = 10;
1672
+ return ElvClient.FromNetworkName({
1673
+ networkName: network,
1674
+ assumeV3: true
1675
+ });
1676
+
1677
+ case 10:
1678
+ client = _context18.sent;
1679
+ walletClient = new ElvWalletClient({
1680
+ client: client,
1681
+ network: network,
1682
+ mode: mode,
1683
+ marketplaceInfo: {
1684
+ tenantSlug: tenantSlug,
1685
+ marketplaceSlug: marketplaceSlug,
1686
+ marketplaceId: marketplaceHash ? client.utils.DecodeVersionHash(marketplaceHash).objectId : marketplaceId,
1687
+ marketplaceHash: marketplaceHash
1688
+ },
1689
+ storeAuthToken: storeAuthToken
1690
+ });
1691
+
1692
+ if (!(window && window.location && window.location.href)) {
1693
+ _context18.next = 31;
1694
+ break;
1695
+ }
1696
+
1697
+ url = new URL(window.location.href);
1698
+
1699
+ if (!url.searchParams.get("elvToken")) {
1700
+ _context18.next = 21;
1701
+ break;
1702
+ }
1703
+
1704
+ _context18.next = 17;
1705
+ return walletClient.Authenticate({
1706
+ token: url.searchParams.get("elvToken")
1707
+ });
1708
+
1709
+ case 17:
1710
+ url.searchParams["delete"]("elvToken");
1711
+ window.history.replaceState("", "", url);
1712
+ _context18.next = 31;
1713
+ break;
1714
+
1715
+ case 21:
1716
+ if (!(storeAuthToken && typeof localStorage !== "undefined")) {
1717
+ _context18.next = 31;
1718
+ break;
1719
+ }
1720
+
1721
+ _context18.prev = 22;
1722
+ // Load saved auth token
1723
+ savedToken = localStorage.getItem("__elv-token-".concat(network));
1724
+
1725
+ if (!savedToken) {
1726
+ _context18.next = 27;
1727
+ break;
1728
+ }
1729
+
1730
+ _context18.next = 27;
1731
+ return walletClient.Authenticate({
1732
+ token: savedToken
1733
+ });
1734
+
1735
+ case 27:
1736
+ _context18.next = 31;
1737
+ break;
1738
+
1739
+ case 29:
1740
+ _context18.prev = 29;
1741
+ _context18.t0 = _context18["catch"](22);
1742
+
1743
+ case 31:
1744
+ _context18.next = 33;
1745
+ return walletClient.LoadAvailableMarketplaces();
1746
+
1747
+ case 33:
1748
+ return _context18.abrupt("return", walletClient);
1749
+
1750
+ case 34:
1751
+ case "end":
1752
+ return _context18.stop();
1753
+ }
1754
+ }
1755
+ }, _callee18, null, [[22, 29]]);
1756
+ }));
1757
+
1758
+ function Initialize(_x21) {
1759
+ return _Initialize.apply(this, arguments);
1760
+ }
1761
+
1762
+ return Initialize;
1763
+ }()
1764
+ }]);
1765
+
1766
+ return ElvWalletClient;
1767
+ }();
1768
+
1769
+ Object.assign(ElvWalletClient.prototype, require("./ClientMethods"));
1770
+ exports.ElvWalletClient = ElvWalletClient;