@eluvio/elv-client-js 4.0.11 → 4.0.13

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 (111) hide show
  1. package/dist/.keep +0 -0
  2. package/dist/ElvClient-min.js +11 -10
  3. package/dist/ElvClient-node-min.js +11 -10
  4. package/dist/ElvFrameClient-min.js +11 -10
  5. package/dist/ElvPermissionsClient-min.js +10 -9
  6. package/dist/ElvWalletClient-min.js +10 -9
  7. package/dist/ElvWalletClient-node-min.js +10 -9
  8. package/dist/src/AuthorizationClient.js +1555 -2076
  9. package/dist/src/ContentObjectVerification.js +134 -185
  10. package/dist/src/Crypto.js +224 -319
  11. package/dist/src/ElvClient.js +822 -1114
  12. package/dist/src/ElvWallet.js +64 -106
  13. package/dist/src/EthClient.js +719 -974
  14. package/dist/src/FrameClient.js +223 -319
  15. package/dist/src/HttpClient.js +117 -156
  16. package/dist/src/Id.js +1 -6
  17. package/dist/src/LogMessage.js +4 -8
  18. package/dist/src/PermissionsClient.js +973 -1271
  19. package/dist/src/RemoteSigner.js +161 -232
  20. package/dist/src/UserProfileClient.js +781 -1038
  21. package/dist/src/Utils.js +159 -299
  22. package/dist/src/Validation.js +2 -17
  23. package/dist/src/client/ABRPublishing.js +828 -958
  24. package/dist/src/client/AccessGroups.js +849 -1095
  25. package/dist/src/client/ContentAccess.js +3323 -4195
  26. package/dist/src/client/ContentManagement.js +1818 -2290
  27. package/dist/src/client/Contracts.js +468 -614
  28. package/dist/src/client/Files.js +1506 -1846
  29. package/dist/src/client/NFT.js +94 -116
  30. package/dist/src/client/NTP.js +326 -425
  31. package/dist/src/index.js +2 -5
  32. package/dist/src/walletClient/ClientMethods.js +1368 -1763
  33. package/dist/src/walletClient/Configuration.js +5 -3
  34. package/dist/src/walletClient/Notifications.js +98 -127
  35. package/dist/src/walletClient/Profile.js +184 -246
  36. package/dist/src/walletClient/Utils.js +76 -122
  37. package/dist/src/walletClient/index.js +1171 -1496
  38. package/package.json +4 -21
  39. package/src/FrameClient.js +1 -0
  40. package/src/HttpClient.js +4 -2
  41. package/src/client/ABRPublishing.js +126 -105
  42. package/src/client/ContentAccess.js +1 -0
  43. package/src/client/ContentManagement.js +4 -2
  44. package/src/walletClient/Configuration.js +3 -2
  45. package/dist/AccessClient-min.js +0 -54
  46. package/dist/AccessClient-node-min.js +0 -74
  47. package/dist/src/AccessClient.js +0 -798
  48. package/dist/src/LimitedMap.js +0 -120
  49. package/dist/src/client/Access.js +0 -1
  50. package/dist/src/client/Management.js +0 -1606
  51. package/dist/src/contracts/AccessIndexor.js +0 -831
  52. package/dist/src/contracts/Accessible.js +0 -31
  53. package/dist/src/contracts/AdmgrAdvertisement.js +0 -695
  54. package/dist/src/contracts/AdmgrCampaign.js +0 -648
  55. package/dist/src/contracts/AdmgrCampaignManager.js +0 -493
  56. package/dist/src/contracts/AdmgrCommercialOffering.js +0 -622
  57. package/dist/src/contracts/AdmgrCommercialOfferingManager.js +0 -413
  58. package/dist/src/contracts/AdmgrMarketPlace.js +0 -413
  59. package/dist/src/contracts/AvailsDelivery.js +0 -535
  60. package/dist/src/contracts/BaseAccessControlGroup.js +0 -1221
  61. package/dist/src/contracts/BaseAccessWallet.js +0 -1575
  62. package/dist/src/contracts/BaseAccessWalletFactory.js +0 -93
  63. package/dist/src/contracts/BaseContent.js +0 -1104
  64. package/dist/src/contracts/BaseContentFactory.js +0 -99
  65. package/dist/src/contracts/BaseContentFactoryExt.js +0 -219
  66. package/dist/src/contracts/BaseContentSpace.js +0 -1346
  67. package/dist/src/contracts/BaseContentType.js +0 -353
  68. package/dist/src/contracts/BaseFactory.js +0 -107
  69. package/dist/src/contracts/BaseGroupFactory.js +0 -93
  70. package/dist/src/contracts/BaseLibrary.js +0 -1035
  71. package/dist/src/contracts/BaseLibraryFactory.js +0 -96
  72. package/dist/src/contracts/Certifyer.js +0 -87
  73. package/dist/src/contracts/Container.js +0 -543
  74. package/dist/src/contracts/Content.js +0 -432
  75. package/dist/src/contracts/Editable.js +0 -295
  76. package/dist/src/contracts/FactorySpace.js +0 -57
  77. package/dist/src/contracts/KmsSpace.js +0 -52
  78. package/dist/src/contracts/LvProvider.js +0 -512
  79. package/dist/src/contracts/LvRecordableStream.js +0 -1026
  80. package/dist/src/contracts/LvRecording.js +0 -627
  81. package/dist/src/contracts/LvStreamRightsHolder.js +0 -551
  82. package/dist/src/contracts/MetaObject.js +0 -110
  83. package/dist/src/contracts/Node.js +0 -167
  84. package/dist/src/contracts/NodeSpace.js +0 -18
  85. package/dist/src/contracts/NodeSpaceImpl.js +0 -273
  86. package/dist/src/contracts/Ownable.js +0 -87
  87. package/dist/src/contracts/PaymentService.js +0 -616
  88. package/dist/src/contracts/Precompile.js +0 -15
  89. package/dist/src/contracts/SampleContentAdMarketplace.js +0 -564
  90. package/dist/src/contracts/SampleContentAdvertising.js +0 -444
  91. package/dist/src/contracts/SampleContentHelloWorld.js +0 -459
  92. package/dist/src/contracts/SampleContentLicensing.js +0 -618
  93. package/dist/src/contracts/SampleContentSigned.js +0 -447
  94. package/dist/src/contracts/SampleInstance.js +0 -438
  95. package/dist/src/contracts/SampleInstanceFactory.js +0 -451
  96. package/dist/src/contracts/Transactable.js +0 -82
  97. package/dist/src/contracts/UserSpace.js +0 -18
  98. package/dist/src/contracts/UserSpaceImpl.js +0 -43
  99. package/dist/src/contracts/Utils.js +0 -18
  100. package/dist/src/contracts/Verifier.js +0 -53
  101. package/dist/src/contracts/strings.js +0 -4
  102. package/dist/src/contracts/v2/BaseContentFactoryExt.js +0 -219
  103. package/dist/src/contracts/v2/FactorySpace.js +0 -57
  104. package/dist/src/contracts/v2/KmsSpace.js +0 -52
  105. package/dist/src/contracts/v2/NodeSpaceImpl.js +0 -273
  106. package/dist/src/contracts/v2/UserSpaceImpl.js +0 -43
  107. package/dist/src/marketplaceClient/ClientMethods.js +0 -1918
  108. package/dist/src/marketplaceClient/Configuration.js +0 -29
  109. package/dist/src/marketplaceClient/Utils.js +0 -304
  110. package/dist/src/marketplaceClient/index.js +0 -1553
  111. package/utilities/ListAccessGroups.js +0 -34
@@ -1,798 +0,0 @@
1
- var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
-
3
- var _typeof = require("@babel/runtime/helpers/typeof");
4
-
5
- var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
6
-
7
- var _createClass = require("@babel/runtime/helpers/createClass");
8
-
9
- if (typeof Buffer === "undefined") {
10
- Buffer = require("buffer/").Buffer;
11
- }
12
-
13
- var URI = require("urijs");
14
-
15
- var Ethers = require("ethers");
16
-
17
- var AuthorizationClient = require("./AuthorizationClient");
18
-
19
- var ElvWallet = require("./ElvWallet");
20
-
21
- var EthClient = require("./EthClient");
22
-
23
- var UserProfileClient = require("./UserProfileClient");
24
-
25
- var HttpClient = require("./HttpClient"); // const ContentObjectVerification = require("./ContentObjectVerification");
26
-
27
-
28
- var Utils = require("./Utils");
29
-
30
- if (Utils.Platform() === Utils.PLATFORM_NODE) {
31
- // Define Response in node
32
- // eslint-disable-next-line no-global-assign
33
- global.Response = require("node-fetch").Response;
34
- } else if (Utils.Platform() === Utils.PLATFORM_REACT_NATIVE) {
35
- // React native polyfill
36
- require("unorm");
37
- }
38
- /**
39
- * See the Modules section on the sidebar for details about methods related to interacting with the Fabric.
40
- *
41
- */
42
-
43
-
44
- var ElvClient =
45
- /*#__PURE__*/
46
- function () {
47
- "use strict";
48
-
49
- _createClass(ElvClient, [{
50
- key: "Log",
51
- value: function Log(message) {
52
- var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
53
-
54
- if (!this.debug) {
55
- return;
56
- }
57
-
58
- if (_typeof(message) === "object") {
59
- message = JSON.stringify(message);
60
- }
61
-
62
- error ? // eslint-disable-next-line no-console
63
- console.error("\n(elv-client-js#ElvClient) ".concat(message, "\n")) : // eslint-disable-next-line no-console
64
- console.log("\n(elv-client-js#ElvClient) ".concat(message, "\n"));
65
- }
66
- /**
67
- * Enable or disable verbose logging
68
- *
69
- * @methodGroup Miscellaneous
70
- *
71
- * @param {boolean} enable - Set logging
72
- */
73
-
74
- }, {
75
- key: "ToggleLogging",
76
- value: function ToggleLogging(enable) {
77
- this.debug = enable;
78
- this.authClient ? this.authClient.debug = enable : undefined;
79
- this.ethClient ? this.ethClient.debug = enable : undefined;
80
- this.HttpClient ? this.HttpClient.debug = enable : undefined;
81
- this.userProfileClient ? this.userProfileClient.debug = enable : undefined;
82
-
83
- if (enable) {
84
- this.Log("Debug Logging Enabled:\n Content Space: ".concat(this.contentSpaceId, "\n Fabric URLs: [\n\t\t").concat(this.fabricURIs.join(", \n\t\t"), "\n\t]\n Ethereum URLs: [\n\t\t").concat(this.ethereumURIs.join(", \n\t\t"), "\n\t]"));
85
- }
86
- }
87
- /**
88
- * Create a new ElvClient
89
- *
90
- * NOTE: It is highly recommended to use ElvClient.FromConfiguration to
91
- * automatically import the client settings from the fabric
92
- *
93
- * @constructor
94
- *
95
- * @namedParams
96
- * @param {string} contentSpaceId - ID of the content space
97
- * @param {Array<string>} fabricURIs - A list of full URIs to content fabric nodes
98
- * @param {Array<string>} ethereumURIs - A list of full URIs to ethereum nodes
99
- * @param {Array<string>} kmsURIs - List of KMS urls to use for OAuth authentication
100
- * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached
101
- * @param {boolean=} noAuth=false - If enabled, blockchain authorization will not be performed
102
- *
103
- * @return {ElvClient} - New ElvClient connected to the specified content fabric and blockchain
104
- */
105
-
106
- }]);
107
-
108
- function ElvClient(_ref) {
109
- var contentSpaceId = _ref.contentSpaceId,
110
- fabricURIs = _ref.fabricURIs,
111
- ethereumURIs = _ref.ethereumURIs,
112
- _ref$kmsURIs = _ref.kmsURIs,
113
- kmsURIs = _ref$kmsURIs === void 0 ? [] : _ref$kmsURIs,
114
- _ref$noCache = _ref.noCache,
115
- noCache = _ref$noCache === void 0 ? false : _ref$noCache,
116
- _ref$noAuth = _ref.noAuth,
117
- noAuth = _ref$noAuth === void 0 ? false : _ref$noAuth;
118
-
119
- _classCallCheck(this, ElvClient);
120
-
121
- this.utils = Utils;
122
- this.contentSpaceId = contentSpaceId;
123
- this.contentSpaceAddress = this.utils.HashToAddress(contentSpaceId);
124
- this.contentSpaceLibraryId = this.utils.AddressToLibraryId(this.contentSpaceAddress);
125
- this.contentSpaceObjectId = this.utils.AddressToObjectId(this.contentSpaceAddress);
126
- this.fabricURIs = fabricURIs;
127
- this.ethereumURIs = ethereumURIs;
128
- this.kmsURIs = kmsURIs;
129
- this.noCache = noCache;
130
- this.noAuth = noAuth;
131
- this.debug = false;
132
- this.InitializeClients();
133
- }
134
- /**
135
- * Retrieve content space info and preferred fabric and blockchain URLs from the fabric
136
- *
137
- * @methodGroup Constructor
138
- * @namedParams
139
- * @param {string} configUrl - Full URL to the config endpoint
140
- * @param {Array<string>} kmsUrls - List of KMS urls to use for OAuth authentication
141
- * @param {string=} region - Preferred region - the fabric will auto-detect the best region if not specified
142
- * - Available regions: na-west-north na-west-south na-east eu-west
143
- *
144
- * @return {Promise<Object>} - Object containing content space ID and fabric and ethereum URLs
145
- */
146
-
147
-
148
- _createClass(ElvClient, [{
149
- key: "InitializeClients",
150
- value: function InitializeClients() {
151
- this.contentTypes = {};
152
- this.encryptionConks = {};
153
- this.reencryptionConks = {};
154
- this.stateChannelAccess = {};
155
- this.objectLibraryIds = {};
156
- this.HttpClient = new HttpClient({
157
- uris: this.fabricURIs,
158
- debug: this.debug
159
- });
160
- this.ethClient = new EthClient({
161
- uris: this.ethereumURIs,
162
- debug: this.debug
163
- });
164
- this.authClient = new AuthorizationClient({
165
- client: this,
166
- contentSpaceId: this.contentSpaceId,
167
- signer: this.signer,
168
- noCache: this.noCache,
169
- noAuth: this.noAuth,
170
- debug: this.debug
171
- });
172
- this.userProfileClient = new UserProfileClient({
173
- client: this,
174
- debug: this.debug
175
- });
176
- }
177
- }, {
178
- key: "SetAuth",
179
- value: function SetAuth(auth) {
180
- this.noAuth = !auth;
181
- this.authClient.noAuth = !auth;
182
- }
183
- /**
184
- * Update fabric URLs to prefer the specified region.
185
- *
186
- * Note: Client must have been initialized with FromConfiguration
187
- *
188
- * @methodGroup Nodes
189
- * @namedParams
190
- * @param {string} region - Preferred region - the fabric will auto-detect the best region if not specified
191
- * - Available regions: na-west-north na-west-south na-east eu-west
192
- *
193
- * @return {Promise<Object>} - An object containing the updated fabric and ethereum URLs in order of preference
194
- */
195
-
196
- }, {
197
- key: "UseRegion",
198
- value: function UseRegion(_ref2) {
199
- var region, _ref3, fabricURIs, ethereumURIs;
200
-
201
- return _regeneratorRuntime.async(function UseRegion$(_context) {
202
- while (1) {
203
- switch (_context.prev = _context.next) {
204
- case 0:
205
- region = _ref2.region;
206
-
207
- if (this.configUrl) {
208
- _context.next = 3;
209
- break;
210
- }
211
-
212
- throw Error("Unable to change region: Configuration URL not set");
213
-
214
- case 3:
215
- _context.next = 5;
216
- return _regeneratorRuntime.awrap(ElvClient.Configuration({
217
- configUrl: this.configUrl,
218
- region: region
219
- }));
220
-
221
- case 5:
222
- _ref3 = _context.sent;
223
- fabricURIs = _ref3.fabricURIs;
224
- ethereumURIs = _ref3.ethereumURIs;
225
- this.fabricURIs = fabricURIs;
226
- this.ethereumURIs = ethereumURIs;
227
- this.HttpClient.uris = fabricURIs;
228
- this.HttpClient.uriIndex = 0;
229
- this.ethClient.ethereumURIs = ethereumURIs;
230
- this.ethClient.ethereumURIIndex = 0;
231
- return _context.abrupt("return", {
232
- fabricURIs: fabricURIs,
233
- ethereumURIs: ethereumURIs
234
- });
235
-
236
- case 15:
237
- case "end":
238
- return _context.stop();
239
- }
240
- }
241
- }, null, this);
242
- }
243
- /**
244
- * Reset fabric URLs to prefer the best region auto-detected by the fabric.
245
- *
246
- * Note: Client must have been initialized with FromConfiguration
247
- *
248
- * @methodGroup Nodes
249
- *
250
- * @return {Promise<Object>} - An object containing the updated fabric and ethereum URLs in order of preference
251
- */
252
-
253
- }, {
254
- key: "ResetRegion",
255
- value: function ResetRegion() {
256
- return _regeneratorRuntime.async(function ResetRegion$(_context2) {
257
- while (1) {
258
- switch (_context2.prev = _context2.next) {
259
- case 0:
260
- if (this.configUrl) {
261
- _context2.next = 2;
262
- break;
263
- }
264
-
265
- throw Error("Unable to change region: Configuration URL not set");
266
-
267
- case 2:
268
- _context2.next = 4;
269
- return _regeneratorRuntime.awrap(this.UseRegion({
270
- region: ""
271
- }));
272
-
273
- case 4:
274
- return _context2.abrupt("return", _context2.sent);
275
-
276
- case 5:
277
- case "end":
278
- return _context2.stop();
279
- }
280
- }
281
- }, null, this);
282
- }
283
- /**
284
- * Retrieve the node ID reported by the fabric for the specified region
285
- *
286
- * Note: Client must have been initialized with FromConfiguration
287
- *
288
- * @methodGroup Nodes
289
- *
290
- * @namedParams
291
- * @param {string} region - Region from which to retrieve the node ID
292
- *
293
- * @return {Promise<string>} - The node ID reported by the fabric
294
- */
295
-
296
- }, {
297
- key: "NodeId",
298
- value: function NodeId(_ref4) {
299
- var region, _ref5, nodeId;
300
-
301
- return _regeneratorRuntime.async(function NodeId$(_context3) {
302
- while (1) {
303
- switch (_context3.prev = _context3.next) {
304
- case 0:
305
- region = _ref4.region;
306
- _context3.next = 3;
307
- return _regeneratorRuntime.awrap(ElvClient.Configuration({
308
- configUrl: this.configUrl,
309
- region: region
310
- }));
311
-
312
- case 3:
313
- _ref5 = _context3.sent;
314
- nodeId = _ref5.nodeId;
315
- return _context3.abrupt("return", nodeId);
316
-
317
- case 6:
318
- case "end":
319
- return _context3.stop();
320
- }
321
- }
322
- }, null, this);
323
- }
324
- /**
325
- * Retrieve the fabric and ethereum nodes currently used by the client, in preference order
326
- *
327
- * @methodGroup Nodes
328
- *
329
- * @return {Promise<Object>} - An object containing the lists of fabric and ethereum urls in use by the client
330
- */
331
-
332
- }, {
333
- key: "Nodes",
334
- value: function Nodes() {
335
- return {
336
- fabricURIs: this.fabricURIs,
337
- ethereumURIs: this.ethereumURIs
338
- };
339
- }
340
- /**
341
- * Set the client to use the specified fabric and ethereum nodes, in preference order
342
- *
343
- * @namedParams
344
- * @param {Array<string>=} fabricURIs - A list of URLs for the fabric, in preference order
345
- * @param {Array<string>=} ethereumURIs - A list of URLs for the blockchain, in preference order
346
- *
347
- * @methodGroup Nodes
348
- */
349
-
350
- }, {
351
- key: "SetNodes",
352
- value: function SetNodes(_ref6) {
353
- var fabricURIs = _ref6.fabricURIs,
354
- ethereumURIs = _ref6.ethereumURIs;
355
-
356
- if (fabricURIs) {
357
- this.fabricURIs = fabricURIs;
358
- this.HttpClient.uris = fabricURIs;
359
- this.HttpClient.uriIndex = 0;
360
- }
361
-
362
- if (ethereumURIs) {
363
- this.ethereumURIs = ethereumURIs;
364
- this.ethClient.ethereumURIs = ethereumURIs;
365
- this.ethClient.ethereumURIIndex = 0;
366
- }
367
- }
368
- /* Wallet and signers */
369
-
370
- /**
371
- * Generate a new ElvWallet that is connected to the client's provider
372
- *
373
- * @methodGroup Signers
374
- * @returns {ElvWallet} - ElvWallet instance with this client's provider
375
- */
376
-
377
- }, {
378
- key: "GenerateWallet",
379
- value: function GenerateWallet() {
380
- return new ElvWallet(this.ethClient.Provider());
381
- }
382
- /**
383
- * Remove the signer from this client
384
- *
385
- * @methodGroup Signers
386
- */
387
-
388
- }, {
389
- key: "ClearSigner",
390
- value: function ClearSigner() {
391
- this.signer = undefined;
392
- this.InitializeClients();
393
- }
394
- /**
395
- * Clear saved access and state channel tokens
396
- *
397
- * @methodGroup Access Requests
398
- */
399
-
400
- }, {
401
- key: "ClearCache",
402
- value: function ClearCache() {
403
- this.authClient.ClearCache();
404
- }
405
- /**
406
- * Set the signer for this client to use for blockchain transactions
407
- *
408
- * @methodGroup Signers
409
- * @namedParams
410
- * @param {object} signer - The ethers.js signer object
411
- */
412
-
413
- }, {
414
- key: "SetSigner",
415
- value: function SetSigner(_ref7) {
416
- var signer = _ref7.signer;
417
- signer.connect(this.ethClient.Provider());
418
- signer.provider.pollingInterval = 250;
419
- this.signer = signer;
420
- this.InitializeClients();
421
- }
422
- /**
423
- * Set the signer for this client to use for blockchain transactions from an existing web3 provider.
424
- * Useful for integrating with MetaMask
425
- *
426
- * @see https://github.com/ethers-io/ethers.js/issues/59#issuecomment-358224800
427
- *
428
- * @methodGroup Signers
429
- * @namedParams
430
- * @param {object} provider - The web3 provider object
431
- */
432
-
433
- }, {
434
- key: "SetSignerFromWeb3Provider",
435
- value: function SetSignerFromWeb3Provider(_ref8) {
436
- var provider, ethProvider;
437
- return _regeneratorRuntime.async(function SetSignerFromWeb3Provider$(_context4) {
438
- while (1) {
439
- switch (_context4.prev = _context4.next) {
440
- case 0:
441
- provider = _ref8.provider;
442
- ethProvider = new Ethers.providers.Web3Provider(provider);
443
- ethProvider.pollingInterval = 250;
444
- this.signer = ethProvider.getSigner();
445
- _context4.next = 6;
446
- return _regeneratorRuntime.awrap(this.signer.getAddress());
447
-
448
- case 6:
449
- this.signer.address = _context4.sent;
450
- _context4.next = 9;
451
- return _regeneratorRuntime.awrap(this.InitializeClients());
452
-
453
- case 9:
454
- case "end":
455
- return _context4.stop();
456
- }
457
- }
458
- }, null, this);
459
- }
460
- /**
461
- * Get the account address of the current signer
462
- *
463
- * @methodGroup Signers
464
- * @returns {string} - The address of the current signer
465
- */
466
-
467
- }, {
468
- key: "CurrentAccountAddress",
469
- value: function CurrentAccountAddress() {
470
- return this.signer ? this.utils.FormatAddress(this.signer.address) : "";
471
- }
472
- /**
473
- * Set the OAuth token for use in state channel calls
474
- *
475
- * @param {string} token - The OAuth ID token
476
- */
477
-
478
- }, {
479
- key: "SetOauthToken",
480
- value: function SetOauthToken(_ref9) {
481
- var token, wallet, signer;
482
- return _regeneratorRuntime.async(function SetOauthToken$(_context5) {
483
- while (1) {
484
- switch (_context5.prev = _context5.next) {
485
- case 0:
486
- token = _ref9.token;
487
- this.oauthToken = token;
488
- wallet = this.GenerateWallet();
489
- signer = wallet.AddAccountFromMnemonic({
490
- mnemonic: wallet.GenerateMnemonic()
491
- });
492
- this.SetSigner({
493
- signer: signer
494
- });
495
-
496
- case 5:
497
- case "end":
498
- return _context5.stop();
499
- }
500
- }
501
- }, null, this);
502
- }
503
- /**
504
- * Set the signer for this client via OAuth token. The client will exchange the given token
505
- * for the user's private key using the KMS specified in the configuration.
506
- *
507
- * NOTE: The KMS URL(s) must be set in the initial configuration of the client (FromConfigurationUrl)
508
- *
509
- * @param {string} token - The OAuth ID
510
- */
511
-
512
- }, {
513
- key: "SetSignerFromOauthToken",
514
- value: function SetSignerFromOauthToken(_ref10) {
515
- var token, path, httpClient, response, privateKey, wallet, signer;
516
- return _regeneratorRuntime.async(function SetSignerFromOauthToken$(_context6) {
517
- while (1) {
518
- switch (_context6.prev = _context6.next) {
519
- case 0:
520
- token = _ref10.token;
521
-
522
- if (!(!this.kmsURIs || this.kmsURIs.length === 0)) {
523
- _context6.next = 3;
524
- break;
525
- }
526
-
527
- throw Error("Unable to authorize with OAuth token: No KMS URLs set");
528
-
529
- case 3:
530
- this.oauthToken = token;
531
- path = "/ks/jwt/wlt";
532
- httpClient = new HttpClient({
533
- uris: this.kmsURIs
534
- });
535
- _context6.next = 8;
536
- return _regeneratorRuntime.awrap(this.utils.ResponseToJson(httpClient.Request({
537
- headers: {
538
- Authorization: "Bearer ".concat(token)
539
- },
540
- method: "PUT",
541
- path: path
542
- })));
543
-
544
- case 8:
545
- response = _context6.sent;
546
- privateKey = response["UserSKHex"];
547
- wallet = this.GenerateWallet();
548
- signer = wallet.AddAccount({
549
- privateKey: privateKey
550
- });
551
- this.SetSigner({
552
- signer: signer
553
- });
554
-
555
- case 13:
556
- case "end":
557
- return _context6.stop();
558
- }
559
- }
560
- }, null, this);
561
- }
562
- /* FrameClient related */
563
- // Whitelist of methods allowed to be called using the frame API
564
-
565
- }, {
566
- key: "FrameAllowedMethods",
567
- value: function FrameAllowedMethods() {
568
- var forbiddenMethods = ["constructor", "AccessGroupMembershipMethod", "CallFromFrameMessage", "ClearSigner", "FormatBlockNumbers", "FrameAllowedMethods", "FromConfigurationUrl", "GenerateWallet", "InitializeClients", "Log", "SetSigner", "SetSignerFromWeb3Provider", "ToggleLogging"];
569
- return Object.getOwnPropertyNames(Object.getPrototypeOf(this)).filter(function (method) {
570
- return !forbiddenMethods.includes(method);
571
- });
572
- } // Call a method specified in a message from a frame
573
-
574
- }, {
575
- key: "CallFromFrameMessage",
576
- value: function CallFromFrameMessage(message, Respond) {
577
- var _this = this;
578
-
579
- var callback, method, methodResults, responseError;
580
- return _regeneratorRuntime.async(function CallFromFrameMessage$(_context7) {
581
- while (1) {
582
- switch (_context7.prev = _context7.next) {
583
- case 0:
584
- if (!(message.type !== "ElvFrameRequest")) {
585
- _context7.next = 2;
586
- break;
587
- }
588
-
589
- return _context7.abrupt("return");
590
-
591
- case 2:
592
- if (message.callbackId) {
593
- callback = function callback(result) {
594
- Respond(_this.utils.MakeClonable({
595
- type: "ElvFrameResponse",
596
- requestId: message.callbackId,
597
- response: result
598
- }));
599
- };
600
-
601
- message.args.callback = callback;
602
- }
603
-
604
- _context7.prev = 3;
605
- method = message.calledMethod;
606
-
607
- if (!(message.module === "userProfileClient")) {
608
- _context7.next = 13;
609
- break;
610
- }
611
-
612
- if (this.userProfileClient.FrameAllowedMethods().includes(method)) {
613
- _context7.next = 8;
614
- break;
615
- }
616
-
617
- throw Error("Invalid user profile method: " + method);
618
-
619
- case 8:
620
- _context7.next = 10;
621
- return _regeneratorRuntime.awrap(this.userProfileClient[method](message.args));
622
-
623
- case 10:
624
- methodResults = _context7.sent;
625
- _context7.next = 18;
626
- break;
627
-
628
- case 13:
629
- if (this.FrameAllowedMethods().includes(method)) {
630
- _context7.next = 15;
631
- break;
632
- }
633
-
634
- throw Error("Invalid method: " + method);
635
-
636
- case 15:
637
- _context7.next = 17;
638
- return _regeneratorRuntime.awrap(this[method](message.args));
639
-
640
- case 17:
641
- methodResults = _context7.sent;
642
-
643
- case 18:
644
- Respond(this.utils.MakeClonable({
645
- type: "ElvFrameResponse",
646
- requestId: message.requestId,
647
- response: methodResults
648
- }));
649
- _context7.next = 27;
650
- break;
651
-
652
- case 21:
653
- _context7.prev = 21;
654
- _context7.t0 = _context7["catch"](3);
655
- // eslint-disable-next-line no-console
656
- this.Log("Frame Message Error:\n Method: ".concat(message.calledMethod, "\n Arguments: ").concat(JSON.stringify(message.args, null, 2), "\n Error: ").concat(_typeof(_context7.t0) === "object" ? JSON.stringify(_context7.t0, null, 2) : _context7.t0), true); // eslint-disable-next-line no-console
657
-
658
- console.error(_context7.t0);
659
- responseError = _context7.t0 instanceof Error ? _context7.t0.message : _context7.t0;
660
- Respond(this.utils.MakeClonable({
661
- type: "ElvFrameResponse",
662
- requestId: message.requestId,
663
- error: responseError
664
- }));
665
-
666
- case 27:
667
- case "end":
668
- return _context7.stop();
669
- }
670
- }
671
- }, null, this, [[3, 21]]);
672
- }
673
- }], [{
674
- key: "Configuration",
675
- value: function Configuration(_ref11) {
676
- var configUrl, _ref11$kmsUrls, kmsUrls, region, uri, fabricInfo, filterHTTPS, fabricURIs, ethereumURIs;
677
-
678
- return _regeneratorRuntime.async(function Configuration$(_context8) {
679
- while (1) {
680
- switch (_context8.prev = _context8.next) {
681
- case 0:
682
- configUrl = _ref11.configUrl, _ref11$kmsUrls = _ref11.kmsUrls, kmsUrls = _ref11$kmsUrls === void 0 ? [] : _ref11$kmsUrls, region = _ref11.region;
683
- _context8.prev = 1;
684
- uri = new URI(configUrl);
685
-
686
- if (region) {
687
- uri.addSearch("elvgeo", region);
688
- }
689
-
690
- _context8.next = 6;
691
- return _regeneratorRuntime.awrap(Utils.ResponseToJson(HttpClient.Fetch(uri.toString())));
692
-
693
- case 6:
694
- fabricInfo = _context8.sent;
695
-
696
- // If any HTTPS urls present, throw away HTTP urls so only HTTPS will be used
697
- filterHTTPS = function filterHTTPS(uri) {
698
- return uri.toLowerCase().startsWith("https");
699
- };
700
-
701
- fabricURIs = fabricInfo.network.seed_nodes.fabric_api;
702
-
703
- if (fabricURIs.find(filterHTTPS)) {
704
- fabricURIs = fabricURIs.filter(filterHTTPS);
705
- }
706
-
707
- ethereumURIs = fabricInfo.network.seed_nodes.ethereum_api;
708
-
709
- if (ethereumURIs.find(filterHTTPS)) {
710
- ethereumURIs = ethereumURIs.filter(filterHTTPS);
711
- }
712
-
713
- return _context8.abrupt("return", {
714
- nodeId: fabricInfo.node_id,
715
- contentSpaceId: fabricInfo.qspace.id,
716
- fabricURIs: fabricURIs,
717
- ethereumURIs: ethereumURIs,
718
- kmsURIs: kmsUrls
719
- });
720
-
721
- case 15:
722
- _context8.prev = 15;
723
- _context8.t0 = _context8["catch"](1);
724
- // eslint-disable-next-line no-console
725
- console.error("Error retrieving fabric configuration:"); // eslint-disable-next-line no-console
726
-
727
- console.error(_context8.t0);
728
- throw _context8.t0;
729
-
730
- case 20:
731
- case "end":
732
- return _context8.stop();
733
- }
734
- }
735
- }, null, null, [[1, 15]]);
736
- }
737
- /**
738
- * Create a new ElvClient from the specified configuration URL
739
- *
740
- * @methodGroup Constructor
741
- * @namedParams
742
- * @param {string} configUrl - Full URL to the config endpoint
743
- * @param {string=} region - Preferred region - the fabric will auto-detect the best region if not specified
744
- * - Available regions: na-west-north na-west-south na-east eu-west
745
- * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached
746
- * @param {boolean=} noAuth=false - If enabled, blockchain authorization will not be performed
747
- *
748
- * @return {Promise<ElvClient>} - New ElvClient connected to the specified content fabric and blockchain
749
- */
750
-
751
- }, {
752
- key: "FromConfigurationUrl",
753
- value: function FromConfigurationUrl(_ref12) {
754
- var configUrl, region, _ref12$noCache, noCache, _ref12$noAuth, noAuth, _ref13, contentSpaceId, fabricURIs, ethereumURIs, client;
755
-
756
- return _regeneratorRuntime.async(function FromConfigurationUrl$(_context9) {
757
- while (1) {
758
- switch (_context9.prev = _context9.next) {
759
- case 0:
760
- configUrl = _ref12.configUrl, region = _ref12.region, _ref12$noCache = _ref12.noCache, noCache = _ref12$noCache === void 0 ? false : _ref12$noCache, _ref12$noAuth = _ref12.noAuth, noAuth = _ref12$noAuth === void 0 ? false : _ref12$noAuth;
761
- _context9.next = 3;
762
- return _regeneratorRuntime.awrap(ElvClient.Configuration({
763
- configUrl: configUrl,
764
- region: region
765
- }));
766
-
767
- case 3:
768
- _ref13 = _context9.sent;
769
- contentSpaceId = _ref13.contentSpaceId;
770
- fabricURIs = _ref13.fabricURIs;
771
- ethereumURIs = _ref13.ethereumURIs;
772
- client = new ElvClient({
773
- contentSpaceId: contentSpaceId,
774
- fabricURIs: fabricURIs,
775
- ethereumURIs: ethereumURIs,
776
- noCache: noCache,
777
- noAuth: noAuth
778
- });
779
- client.configUrl = configUrl;
780
- return _context9.abrupt("return", client);
781
-
782
- case 10:
783
- case "end":
784
- return _context9.stop();
785
- }
786
- }
787
- });
788
- }
789
- }]);
790
-
791
- return ElvClient;
792
- }();
793
-
794
- Object.assign(ElvClient.prototype, require("./client/AccessGroups").access);
795
- Object.assign(ElvClient.prototype, require("./client/ContentAccess"));
796
- Object.assign(ElvClient.prototype, require("./client/Contracts"));
797
- Object.assign(ElvClient.prototype, require("./client/Files").access);
798
- exports.AccessClient = ElvClient;