@eluvio/elv-client-js 4.0.112 → 4.0.113

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 (124) hide show
  1. package/package.json +1 -1
  2. package/dist/ElvClient-min.js +0 -67
  3. package/dist/ElvClient-node-min.js +0 -66
  4. package/dist/ElvFrameClient-min.js +0 -60
  5. package/dist/ElvPermissionsClient-min.js +0 -60
  6. package/dist/ElvWalletClient-min.js +0 -67
  7. package/dist/ElvWalletClient-node-min.js +0 -66
  8. package/dist/src/AuthorizationClient.js +0 -2157
  9. package/dist/src/ContentObjectAudit.js +0 -175
  10. package/dist/src/ContentObjectVerification.js +0 -281
  11. package/dist/src/Crypto.js +0 -412
  12. package/dist/src/ElvClient.js +0 -2022
  13. package/dist/src/ElvWallet.js +0 -245
  14. package/dist/src/EthClient.js +0 -1154
  15. package/dist/src/FrameClient.js +0 -485
  16. package/dist/src/HttpClient.js +0 -315
  17. package/dist/src/Id.js +0 -21
  18. package/dist/src/LogMessage.js +0 -25
  19. package/dist/src/PermissionsClient.js +0 -1544
  20. package/dist/src/RemoteSigner.js +0 -385
  21. package/dist/src/UserProfileClient.js +0 -1450
  22. package/dist/src/Utils.js +0 -894
  23. package/dist/src/Validation.js +0 -121
  24. package/dist/src/abr_profiles/abr_profile_live_drm.js +0 -1661
  25. package/dist/src/abr_profiles/abr_profile_live_to_vod.js +0 -1606
  26. package/dist/src/client/ABRPublishing.js +0 -1018
  27. package/dist/src/client/AccessGroups.js +0 -1503
  28. package/dist/src/client/ContentAccess.js +0 -5173
  29. package/dist/src/client/ContentManagement.js +0 -2680
  30. package/dist/src/client/Contracts.js +0 -1520
  31. package/dist/src/client/Files.js +0 -2181
  32. package/dist/src/client/LiveConf.js +0 -567
  33. package/dist/src/client/LiveStream.js +0 -2638
  34. package/dist/src/client/NFT.js +0 -162
  35. package/dist/src/client/NTP.js +0 -581
  36. package/dist/src/contracts/v2/AccessIndexor.js +0 -831
  37. package/dist/src/contracts/v2/Accessible.js +0 -31
  38. package/dist/src/contracts/v2/BaseAccessControlGroup.js +0 -1263
  39. package/dist/src/contracts/v2/BaseAccessWallet.js +0 -1609
  40. package/dist/src/contracts/v2/BaseAccessWalletFactory.js +0 -93
  41. package/dist/src/contracts/v2/BaseContent.js +0 -1076
  42. package/dist/src/contracts/v2/BaseContentFactory.js +0 -219
  43. package/dist/src/contracts/v2/BaseContentSpace.js +0 -1352
  44. package/dist/src/contracts/v2/BaseContentType.js +0 -364
  45. package/dist/src/contracts/v2/BaseFactory.js +0 -107
  46. package/dist/src/contracts/v2/BaseGroupFactory.js +0 -93
  47. package/dist/src/contracts/v2/BaseLibrary.js +0 -1041
  48. package/dist/src/contracts/v2/BaseLibraryFactory.js +0 -96
  49. package/dist/src/contracts/v2/Certifyer.js +0 -86
  50. package/dist/src/contracts/v2/Container.js +0 -540
  51. package/dist/src/contracts/v2/Content.js +0 -443
  52. package/dist/src/contracts/v2/Editable.js +0 -306
  53. package/dist/src/contracts/v2/ExternalUserWallet.js +0 -379
  54. package/dist/src/contracts/v2/IFactorySpace.js +0 -57
  55. package/dist/src/contracts/v2/IKmsSpace.js +0 -52
  56. package/dist/src/contracts/v2/INodeSpace.js +0 -18
  57. package/dist/src/contracts/v2/IUserSpace.js +0 -18
  58. package/dist/src/contracts/v2/LvRecordableStream.js +0 -1037
  59. package/dist/src/contracts/v2/LvRecording.js +0 -627
  60. package/dist/src/contracts/v2/LvStreamRightsHolder.js +0 -562
  61. package/dist/src/contracts/v2/MetaObject.js +0 -119
  62. package/dist/src/contracts/v2/Node.js +0 -167
  63. package/dist/src/contracts/v2/NodeSpace.js +0 -273
  64. package/dist/src/contracts/v2/Ownable.js +0 -87
  65. package/dist/src/contracts/v2/PaymentService.js +0 -627
  66. package/dist/src/contracts/v2/Precompile.js +0 -15
  67. package/dist/src/contracts/v2/Transactable.js +0 -82
  68. package/dist/src/contracts/v2/UserSpace.js +0 -29
  69. package/dist/src/contracts/v2/Utils.js +0 -18
  70. package/dist/src/contracts/v2/Verifier.js +0 -53
  71. package/dist/src/contracts/v2/strings.js +0 -4
  72. package/dist/src/contracts/v3/AccessIndexor.js +0 -774
  73. package/dist/src/contracts/v3/Accessible.js +0 -232
  74. package/dist/src/contracts/v3/Adminable.js +0 -107
  75. package/dist/src/contracts/v3/AvailsDelivery.js +0 -586
  76. package/dist/src/contracts/v3/BaseAccessControlGroup.js +0 -1603
  77. package/dist/src/contracts/v3/BaseAccessWallet.js +0 -1628
  78. package/dist/src/contracts/v3/BaseAccessWalletFactory.js +0 -112
  79. package/dist/src/contracts/v3/BaseContent.js +0 -1312
  80. package/dist/src/contracts/v3/BaseContentFactory.js +0 -183
  81. package/dist/src/contracts/v3/BaseContentFactoryExt.js +0 -175
  82. package/dist/src/contracts/v3/BaseContentSpace.js +0 -1515
  83. package/dist/src/contracts/v3/BaseContentType.js +0 -527
  84. package/dist/src/contracts/v3/BaseFactory.js +0 -126
  85. package/dist/src/contracts/v3/BaseGroupFactory.js +0 -112
  86. package/dist/src/contracts/v3/BaseLibrary.js +0 -1204
  87. package/dist/src/contracts/v3/BaseLibraryFactory.js +0 -115
  88. package/dist/src/contracts/v3/BaseTenantSpace.js +0 -1587
  89. package/dist/src/contracts/v3/Certifyer.js +0 -86
  90. package/dist/src/contracts/v3/Container.js +0 -739
  91. package/dist/src/contracts/v3/Content.js +0 -438
  92. package/dist/src/contracts/v3/CounterObject.js +0 -243
  93. package/dist/src/contracts/v3/Editable.js +0 -519
  94. package/dist/src/contracts/v3/EncToken.js +0 -4
  95. package/dist/src/contracts/v3/ExternalUserWallet.js +0 -587
  96. package/dist/src/contracts/v3/IAdmin.js +0 -18
  97. package/dist/src/contracts/v3/IFactorySpace.js +0 -57
  98. package/dist/src/contracts/v3/IKmsSpace.js +0 -52
  99. package/dist/src/contracts/v3/INodeSpace.js +0 -18
  100. package/dist/src/contracts/v3/IUserSpace.js +0 -32
  101. package/dist/src/contracts/v3/LvRecordableStream.js +0 -1032
  102. package/dist/src/contracts/v3/LvRecording.js +0 -650
  103. package/dist/src/contracts/v3/LvStreamRightsHolder.js +0 -557
  104. package/dist/src/contracts/v3/MetaObject.js +0 -144
  105. package/dist/src/contracts/v3/Node.js +0 -178
  106. package/dist/src/contracts/v3/NodeSpace.js +0 -284
  107. package/dist/src/contracts/v3/Ownable.js +0 -98
  108. package/dist/src/contracts/v3/PaymentService.js +0 -622
  109. package/dist/src/contracts/v3/Precompile.js +0 -26
  110. package/dist/src/contracts/v3/TenantFuncsBase.js +0 -351
  111. package/dist/src/contracts/v3/Transactable.js +0 -82
  112. package/dist/src/contracts/v3/UserSpace.js +0 -43
  113. package/dist/src/contracts/v3/Utils.js +0 -18
  114. package/dist/src/contracts/v3/Verifier.js +0 -53
  115. package/dist/src/contracts/v3/strings.js +0 -4
  116. package/dist/src/contracts/v3b/BaseAccessControlGroup.js +0 -1704
  117. package/dist/src/events/Topics.js +0 -1793
  118. package/dist/src/index.js +0 -8
  119. package/dist/src/walletClient/ClientMethods.js +0 -3102
  120. package/dist/src/walletClient/Configuration.js +0 -38
  121. package/dist/src/walletClient/Notifications.js +0 -168
  122. package/dist/src/walletClient/Profile.js +0 -332
  123. package/dist/src/walletClient/Utils.js +0 -281
  124. package/dist/src/walletClient/index.js +0 -2106
@@ -1,2022 +0,0 @@
1
- var _toConsumableArray = require("@babel/runtime/helpers/toConsumableArray");
2
- var _typeof = require("@babel/runtime/helpers/typeof");
3
- var _defineProperty = require("@babel/runtime/helpers/defineProperty");
4
- var _regeneratorRuntime = require("@babel/runtime/regenerator");
5
- var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
6
- var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
7
- var _createClass = require("@babel/runtime/helpers/createClass");
8
- 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; }
9
- 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; }
10
- if (typeof globalThis.Buffer === "undefined") {
11
- globalThis.Buffer = require("buffer/").Buffer;
12
- }
13
- var URI = require("urijs");
14
- var Ethers = require("ethers");
15
- var AuthorizationClient = require("./AuthorizationClient");
16
- var ElvWallet = require("./ElvWallet");
17
- var EthClient = require("./EthClient");
18
- var UserProfileClient = require("./UserProfileClient");
19
- var HttpClient = require("./HttpClient");
20
- var RemoteSigner = require("./RemoteSigner");
21
- var Utils = require("./Utils");
22
- var Crypto = require("./Crypto");
23
- var _require = require("./LogMessage"),
24
- LogMessage = _require.LogMessage;
25
- var Pako = require("pako");
26
- var _require2 = require("./Validation"),
27
- ValidatePresence = _require2.ValidatePresence;
28
- var UrlJoin = require("url-join");
29
- var networks = {
30
- "main": "https://main.net955305.contentfabric.io",
31
- "demo": "https://demov3.net955210.contentfabric.io",
32
- "demov3": "https://demov3.net955210.contentfabric.io",
33
- "local": "http://127.0.0.1:8008/config?qspace=dev&self",
34
- "test": "https://test.net955203.contentfabric.io"
35
- };
36
- if (Utils.Platform() === Utils.PLATFORM_NODE) {
37
- // Define Response in node
38
- // eslint-disable-next-line no-global-assign
39
- globalThis.Response = require("node-fetch").Response;
40
- }
41
-
42
- /**
43
- * See the Modules section on the sidebar for details about methods related to interacting with the Fabric.
44
- *
45
- * <br/>
46
- *
47
- * For information about the Eluvio Wallet Client, go <a href="wallet-client/index.html">here</a>.
48
- */
49
- var ElvClient = /*#__PURE__*/function () {
50
- "use strict";
51
-
52
- /**
53
- * Create a new ElvClient
54
- *
55
- * NOTE: It is highly recommended to use the <a href="#.FromConfigurationUrl">FromConfigurationUrl</a> or <a href="#.FromNetworkName">FromNetworkName</a> method
56
- * automatically import the client settings from the fabric
57
- *
58
- * @constructor
59
- *
60
- * @namedParams
61
- * @param {string} contentSpaceId - ID of the content space
62
- * @param {string} networkId - ID of the blockchain network
63
- * @param {string} networkName - Name of the blockchain network
64
- * @param {number} fabricVersion - The version of the target content fabric
65
- * @param {Array<string>} fabricURIs - A list of full URIs to content fabric nodes
66
- * @param {Array<string>} ethereumURIs - A list of full URIs to ethereum nodes
67
- * @param {Array<string>} authServiceURIs - A list of full URIs to auth service endpoints
68
- * @param {Array<string>} fileServiceURIs - A list of full URIs to file service endpoints
69
- * @param {Array<string>=} searchURIs - A list of full URIs to search service endpoints
70
- * @param {number=} ethereumContractTimeout=10 - Number of seconds to wait for contract calls
71
- * @param {string=} trustAuthorityId - (OAuth) The ID of the trust authority to use for OAuth authentication
72
- * @param {string=} staticToken - Static token that will be used for all authorization in place of normal auth. Also known as an anonymous token containing the space
73
- * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached
74
- * @param {boolean=} noAuth=false - If enabled, blockchain authorization will not be performed
75
- * @param {boolean=} assumeV3=false - If enabled, V3 fabric will be assumed
76
- * @param {string=} service=default - The mode that determines how HttpClient will be initialized.
77
- * If 'default' is set, HttpClient uris will use fabricUris. If 'search' is used, searchUris will be used
78
- *
79
- * @return {ElvClient} - New ElvClient connected to the specified content fabric and blockchain
80
- */
81
- function ElvClient(_ref) {
82
- var contentSpaceId = _ref.contentSpaceId,
83
- networkId = _ref.networkId,
84
- networkName = _ref.networkName,
85
- fabricVersion = _ref.fabricVersion,
86
- fabricURIs = _ref.fabricURIs,
87
- ethereumURIs = _ref.ethereumURIs,
88
- authServiceURIs = _ref.authServiceURIs,
89
- fileServiceURIs = _ref.fileServiceURIs,
90
- searchURIs = _ref.searchURIs,
91
- _ref$ethereumContract = _ref.ethereumContractTimeout,
92
- ethereumContractTimeout = _ref$ethereumContract === void 0 ? 10 : _ref$ethereumContract,
93
- trustAuthorityId = _ref.trustAuthorityId,
94
- staticToken = _ref.staticToken,
95
- _ref$noCache = _ref.noCache,
96
- noCache = _ref$noCache === void 0 ? false : _ref$noCache,
97
- _ref$noAuth = _ref.noAuth,
98
- noAuth = _ref$noAuth === void 0 ? false : _ref$noAuth,
99
- _ref$assumeV = _ref.assumeV3,
100
- assumeV3 = _ref$assumeV === void 0 ? false : _ref$assumeV,
101
- _ref$service = _ref.service,
102
- service = _ref$service === void 0 ? "default" : _ref$service;
103
- _classCallCheck(this, ElvClient);
104
- this.Configuration = ElvClient.Configuration;
105
- this.utils = Utils;
106
- this.contentSpaceId = contentSpaceId;
107
- this.contentSpaceAddress = this.utils.HashToAddress(contentSpaceId);
108
- this.contentSpaceLibraryId = this.utils.AddressToLibraryId(this.contentSpaceAddress);
109
- this.contentSpaceObjectId = this.utils.AddressToObjectId(this.contentSpaceAddress);
110
- this.networkId = networkId;
111
- this.networkName = networkName;
112
- this.fabricVersion = fabricVersion;
113
- this.fabricURIs = fabricURIs;
114
- this.authServiceURIs = authServiceURIs;
115
- this.fileServiceURIs = fileServiceURIs || fabricURIs;
116
- this.ethereumURIs = ethereumURIs;
117
- this.searchURIs = searchURIs;
118
- this.ethereumContractTimeout = ethereumContractTimeout;
119
- this.trustAuthorityId = trustAuthorityId;
120
- this.noCache = noCache;
121
- this.noAuth = noAuth;
122
- this.assumeV3 = assumeV3;
123
- if (!["search", "default"].includes(service)) {
124
- throw Error("Invalid service: ".concat(service));
125
- }
126
- this.service = service;
127
- this.debug = false;
128
- this.InitializeClients({
129
- staticToken: staticToken
130
- });
131
- }
132
-
133
- /**
134
- * Retrieve content space info and preferred fabric and blockchain URLs from the fabric
135
- *
136
- * @methodGroup Constructor
137
- * @namedParams
138
- * @param {string} configUrl - Full URL to the config endpoint
139
- * @param {Array<string>} kmsUrls - List of KMS urls to use for OAuth authentication
140
- * @param {string=} region - Preferred region - the fabric will auto-detect the best region if not specified
141
- * - Available regions: as-east, au-east, eu-east-north, eu-west-north, na-east-north, na-east-south, na-west-north, na-west-south, eu-east-south, eu-west-south
142
- * @param {string=} clientIP - IP address to use in determining the region to use
143
- * @return {Promise<Object>} - Object containing content space ID and fabric and ethereum URLs
144
- */
145
- _createClass(ElvClient, [{
146
- key: "Log",
147
- value: function Log(message) {
148
- var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
149
- LogMessage(this, message, error);
150
- }
151
-
152
- /**
153
- * Enable or disable verbose logging
154
- *
155
- * @methodGroup Miscellaneous
156
- *
157
- * @param {boolean} enable - Set logging
158
- * @param {Object=} options - Additional options for customizing logging
159
- * - log: custom log() function
160
- * - error: custom error() function
161
- * - (custom functions must accept same arguments as console.log/console.error)
162
- */
163
- }, {
164
- key: "ToggleLogging",
165
- value: function ToggleLogging(enable) {
166
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
167
- // define func with closure to pass to forEach
168
- var setDebug = function setDebug(reporter) {
169
- if (reporter) {
170
- reporter.debug = enable;
171
- reporter.debugOptions = options;
172
- }
173
- };
174
- [this, this.authClient, this.ethClient, this.HttpClient, this.AuthHttpClient, this.FileServiceHttpClient, this.SearchHttpClient, this.userProfileClient].forEach(setDebug);
175
- if (enable) {
176
- 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]\n Auth Service URLs: [\\n\\t\\t").concat(this.authServiceURIs.join(", \n\t\t"), "\\n\\t]\n File Service URLs: [\\n\\t\\t").concat(this.fileServiceURIs.join(", \n\t\t"), "\\n\\t]\n "));
177
- }
178
- }
179
- }, {
180
- key: "EnableMethodLogging",
181
- value: function EnableMethodLogging() {
182
- var MethodLogger = function MethodLogger(klass) {
183
- Object.getOwnPropertyNames(Object.getPrototypeOf(klass)).filter(function (method) {
184
- return typeof klass[method] === "function";
185
- }).forEach(function (methodName) {
186
- var originalMethod = klass[methodName].bind(klass);
187
- if (originalMethod.constructor.name === "AsyncFunction") {
188
- klass[methodName] = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
189
- var start,
190
- _len,
191
- args,
192
- _key,
193
- result,
194
- _args = arguments;
195
- return _regeneratorRuntime.wrap(function _callee$(_context) {
196
- while (1) switch (_context.prev = _context.next) {
197
- case 0:
198
- start = Date.now();
199
- for (_len = _args.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
200
- args[_key] = _args[_key];
201
- }
202
- _context.next = 4;
203
- return originalMethod.apply(void 0, args);
204
- case 4:
205
- result = _context.sent;
206
- // eslint-disable-next-line no-console
207
- console.log(methodName, Date.now() - start, "ms", JSON.stringify(args));
208
- return _context.abrupt("return", result);
209
- case 7:
210
- case "end":
211
- return _context.stop();
212
- }
213
- }, _callee);
214
- }));
215
- } else {
216
- klass[methodName] = function () {
217
- var start = Date.now();
218
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
219
- args[_key2] = arguments[_key2];
220
- }
221
- var result = originalMethod.apply(void 0, args);
222
- // eslint-disable-next-line no-console
223
- console.log(methodName, Date.now() - start, "ms", JSON.stringify(args));
224
- return result;
225
- };
226
- }
227
- });
228
- };
229
- MethodLogger(this);
230
- }
231
- }, {
232
- key: "InitializeClients",
233
- value: function () {
234
- var _InitializeClients = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
235
- var _ref3,
236
- staticToken,
237
- uris,
238
- wallet,
239
- signer,
240
- _args2 = arguments;
241
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
242
- while (1) switch (_context2.prev = _context2.next) {
243
- case 0:
244
- _ref3 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, staticToken = _ref3.staticToken;
245
- // Cached info
246
- this.contentTypes = {};
247
- this.encryptionConks = {};
248
- this.stateChannelAccess = {};
249
- this.objectTenantIds = {};
250
- this.objectLibraryIds = {};
251
- this.objectImageUrls = {};
252
- this.visibilityInfo = {};
253
- this.inaccessibleLibraries = {};
254
- uris = this.service === "search" ? this.searchURIs : this.fabricURIs;
255
- this.HttpClient = new HttpClient({
256
- uris: uris,
257
- debug: this.debug
258
- });
259
- this.AuthHttpClient = new HttpClient({
260
- uris: this.authServiceURIs,
261
- debug: this.debug
262
- });
263
- this.FileServiceHttpClient = new HttpClient({
264
- uris: this.fileServiceURIs,
265
- debug: this.debug
266
- });
267
- this.SearchHttpClient = new HttpClient({
268
- uris: this.searchURIs || [],
269
- debug: this.debug
270
- });
271
- this.ethClient = new EthClient({
272
- client: this,
273
- uris: this.ethereumURIs,
274
- networkId: this.networkId,
275
- debug: this.debug,
276
- timeout: this.ethereumContractTimeout
277
- });
278
- if (!this.signer) {
279
- wallet = this.GenerateWallet();
280
- signer = wallet.AddAccountFromMnemonic({
281
- mnemonic: wallet.GenerateMnemonic()
282
- });
283
- this.SetSigner({
284
- signer: signer,
285
- reset: false
286
- });
287
- this.SetStaticToken({
288
- token: staticToken
289
- });
290
- }
291
- this.authClient = new AuthorizationClient({
292
- client: this,
293
- contentSpaceId: this.contentSpaceId,
294
- signer: this.signer,
295
- noCache: this.noCache,
296
- noAuth: this.noAuth,
297
- debug: this.debug
298
- });
299
- this.userProfileClient = new UserProfileClient({
300
- client: this,
301
- debug: this.debug
302
- });
303
-
304
- // Initialize crypto wasm
305
- this.Crypto = Crypto;
306
- this.Crypto.ElvCrypto();
307
- case 20:
308
- case "end":
309
- return _context2.stop();
310
- }
311
- }, _callee2, this);
312
- }));
313
- function InitializeClients() {
314
- return _InitializeClients.apply(this, arguments);
315
- }
316
- return InitializeClients;
317
- }()
318
- }, {
319
- key: "ConfigUrl",
320
- value: function ConfigUrl() {
321
- return this.configUrl;
322
- }
323
- }, {
324
- key: "SetAuth",
325
- value: function SetAuth(auth) {
326
- this.noAuth = !auth;
327
- this.authClient.noAuth = !auth;
328
- }
329
-
330
- /**
331
- * Update fabric URLs to prefer the specified region.
332
- *
333
- * Note: Client must have been initialized with FromConfigurationUrl or FromNetworkName
334
- *
335
- * @methodGroup Nodes
336
- * @namedParams
337
- * @param {string} region - Preferred region - the fabric will auto-detect the best region if not specified
338
- * - Available regions: as-east, au-east, eu-east-north, eu-west-north, na-east-north, na-east-south, na-west-north, na-west-south, eu-east-south, eu-west-south
339
- *
340
- * @return {Promise<Object>} - An object containing the updated fabric, ethereum, auth service, and search URLs in order of preference
341
- */
342
- }, {
343
- key: "UseRegion",
344
- value: function () {
345
- var _UseRegion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref4) {
346
- var region, _yield$ElvClient$Conf, fabricURIs, ethereumURIs, authServiceURIs, fileServiceURIs, searchURIs;
347
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
348
- while (1) switch (_context3.prev = _context3.next) {
349
- case 0:
350
- region = _ref4.region;
351
- if (this.configUrl) {
352
- _context3.next = 3;
353
- break;
354
- }
355
- throw Error("Unable to change region: Configuration URL not set");
356
- case 3:
357
- _context3.next = 5;
358
- return ElvClient.Configuration({
359
- configUrl: this.configUrl,
360
- region: region
361
- });
362
- case 5:
363
- _yield$ElvClient$Conf = _context3.sent;
364
- fabricURIs = _yield$ElvClient$Conf.fabricURIs;
365
- ethereumURIs = _yield$ElvClient$Conf.ethereumURIs;
366
- authServiceURIs = _yield$ElvClient$Conf.authServiceURIs;
367
- fileServiceURIs = _yield$ElvClient$Conf.fileServiceURIs;
368
- searchURIs = _yield$ElvClient$Conf.searchURIs;
369
- this.region = region;
370
- this.SetNodes({
371
- fabricURIs: fabricURIs,
372
- ethereumURIs: ethereumURIs,
373
- authServiceURIs: authServiceURIs,
374
- fileServiceURIs: fileServiceURIs,
375
- searchURIs: searchURIs
376
- });
377
- return _context3.abrupt("return", {
378
- fabricURIs: fabricURIs,
379
- ethereumURIs: ethereumURIs,
380
- fileServiceURIs: fileServiceURIs,
381
- authServiceURIs: authServiceURIs,
382
- searchURIs: searchURIs
383
- });
384
- case 14:
385
- case "end":
386
- return _context3.stop();
387
- }
388
- }, _callee3, this);
389
- }));
390
- function UseRegion(_x) {
391
- return _UseRegion.apply(this, arguments);
392
- }
393
- return UseRegion;
394
- }()
395
- /**
396
- * Reset fabric URLs to prefer the best region auto-detected by the fabric.
397
- *
398
- * Note: Client must have been initialized with FromConfigurationUrl or FromNetworkName
399
- *
400
- * @methodGroup Nodes
401
- *
402
- * @return {Promise<Object>} - An object containing the updated fabric and ethereum URLs in order of preference
403
- */
404
- }, {
405
- key: "ResetRegion",
406
- value: function () {
407
- var _ResetRegion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
408
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
409
- while (1) switch (_context4.prev = _context4.next) {
410
- case 0:
411
- if (this.configUrl) {
412
- _context4.next = 2;
413
- break;
414
- }
415
- throw Error("Unable to change region: Configuration URL not set");
416
- case 2:
417
- _context4.next = 4;
418
- return this.UseRegion({
419
- region: ""
420
- });
421
- case 4:
422
- return _context4.abrupt("return", _context4.sent);
423
- case 5:
424
- case "end":
425
- return _context4.stop();
426
- }
427
- }, _callee4, this);
428
- }));
429
- function ResetRegion() {
430
- return _ResetRegion.apply(this, arguments);
431
- }
432
- return ResetRegion;
433
- }()
434
- /**
435
- * Retrieve the node ID reported by the fabric for the specified region
436
- *
437
- * Note: Client must have been initialized with FromConfigurationUrl or FromNetworkName
438
- *
439
- * @methodGroup Nodes
440
- *
441
- * @namedParams
442
- * @param {string} region - Region from which to retrieve the node ID
443
- *
444
- * @return {Promise<string>} - The node ID reported by the fabric
445
- */
446
- }, {
447
- key: "NodeId",
448
- value: function () {
449
- var _NodeId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref5) {
450
- var region, _yield$ElvClient$Conf2, nodeId;
451
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
452
- while (1) switch (_context5.prev = _context5.next) {
453
- case 0:
454
- region = _ref5.region;
455
- _context5.next = 3;
456
- return ElvClient.Configuration({
457
- configUrl: this.configUrl,
458
- region: region
459
- });
460
- case 3:
461
- _yield$ElvClient$Conf2 = _context5.sent;
462
- nodeId = _yield$ElvClient$Conf2.nodeId;
463
- return _context5.abrupt("return", nodeId);
464
- case 6:
465
- case "end":
466
- return _context5.stop();
467
- }
468
- }, _callee5, this);
469
- }));
470
- function NodeId(_x2) {
471
- return _NodeId.apply(this, arguments);
472
- }
473
- return NodeId;
474
- }()
475
- /**
476
- * Retrieve the fabric, ethereum, auth service, and search nodes currently used by the client, in preference order
477
- *
478
- * @methodGroup Nodes
479
- *
480
- * @return {Promise<Object>} - An object containing the lists of fabric, ethereum, auth service, and search urls in use by the client
481
- */
482
- }, {
483
- key: "Nodes",
484
- value: function Nodes() {
485
- return {
486
- fabricURIs: this.fabricURIs,
487
- ethereumURIs: this.ethereumURIs,
488
- authServiceURIs: this.authServiceURIs,
489
- fileServiceURIs: this.fileServiceURIs,
490
- searchURIs: this.searchURIs
491
- };
492
- }
493
-
494
- /**
495
- * Set the client to use the specified fabric, ethereum, auth service, and search nodes, in preference order
496
- *
497
- * @namedParams
498
- * @param {Array<string>=} fabricURIs - A list of URLs for the fabric, in preference order
499
- * @param {Array<string>=} ethereumURIs - A list of URLs for the blockchain, in preference order
500
- * @param {Array<string>=} authServiceURIs - A list of URLs for the auth service, in preference order
501
- * @param {Array<string>=} fileServiceURIs - A list of URLs for file service jobs, in preference order
502
- * @param {Array<string>=} searchURIs - A list of URLs for the search nodes, in preference order
503
- *
504
- * @methodGroup Nodes
505
- */
506
- }, {
507
- key: "SetNodes",
508
- value: function SetNodes(_ref6) {
509
- var fabricURIs = _ref6.fabricURIs,
510
- ethereumURIs = _ref6.ethereumURIs,
511
- authServiceURIs = _ref6.authServiceURIs,
512
- fileServiceURIs = _ref6.fileServiceURIs,
513
- searchURIs = _ref6.searchURIs;
514
- if (fabricURIs) {
515
- this.fabricURIs = fabricURIs;
516
- this.HttpClient.uris = fabricURIs;
517
- this.HttpClient.uriIndex = 0;
518
- }
519
- if (ethereumURIs) {
520
- this.ethereumURIs = ethereumURIs;
521
- this.ethClient.ethereumURIs = ethereumURIs;
522
- this.ethClient.ethereumURIIndex = 0;
523
- }
524
- if (authServiceURIs) {
525
- this.authServiceURIs = authServiceURIs;
526
- this.AuthHttpClient.uris = authServiceURIs;
527
- this.AuthHttpClient.uriIndex = 0;
528
- }
529
- if (fileServiceURIs) {
530
- this.fileServiceURIs = fileServiceURIs;
531
- this.FileServiceHttpClient.uris = fileServiceURIs;
532
- this.FileServiceHttpClient.uriIndex = 0;
533
- }
534
- if (searchURIs) {
535
- this.searchURIs = searchURIs;
536
- this.SearchHttpClient.uris = searchURIs;
537
- this.SearchHttpClient.uriIndex = 0;
538
- }
539
- }
540
-
541
- /**
542
- * Return a list of nodes in the content space, optionally filtered by node ID or endpoint.
543
- *
544
- * @methodGroup Nodes
545
- * @namedParams
546
- * @param {string=} matchEndpoint - Return node(s) matching the specified endpoint
547
- * @param {string=} matchNodeId - Return node(s) matching the specified node ID
548
- *
549
- * @return {Promise<Array<Object>>} - A list of nodes in the space matching the parameters
550
- */
551
- }, {
552
- key: "SpaceNodes",
553
- value: function () {
554
- var _SpaceNodes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
555
- var _this = this;
556
- var _ref7,
557
- matchEndpoint,
558
- matchNodeId,
559
- nodes,
560
- _yield$this$utils$Res,
561
- node,
562
- _args6 = arguments;
563
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
564
- while (1) switch (_context6.prev = _context6.next) {
565
- case 0:
566
- _ref7 = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {}, matchEndpoint = _ref7.matchEndpoint, matchNodeId = _ref7.matchNodeId;
567
- this.SetStaticToken();
568
- if (!matchEndpoint) {
569
- _context6.next = 12;
570
- break;
571
- }
572
- _context6.next = 5;
573
- return this.utils.ResponseToJson(this.HttpClient.Request({
574
- path: UrlJoin("nodes"),
575
- method: "GET",
576
- headers: {
577
- Authorization: "Bearer ".concat(this.staticToken)
578
- }
579
- }));
580
- case 5:
581
- _yield$this$utils$Res = _context6.sent;
582
- nodes = _yield$this$utils$Res.nodes;
583
- if (!(!nodes || !Array.isArray(nodes) || nodes.length === 0)) {
584
- _context6.next = 9;
585
- break;
586
- }
587
- return _context6.abrupt("return", []);
588
- case 9:
589
- return _context6.abrupt("return", nodes.filter(function (node) {
590
- var match = false;
591
- if (node.services && node.services.fabric_api && node.services.fabric_api.urls) {
592
- var results = (node.services.fabric_api.urls || []).find(function (url) {
593
- return url.includes(matchEndpoint);
594
- });
595
- if (results) {
596
- match = true;
597
- }
598
- }
599
- if (matchNodeId && node.id === matchNodeId) {
600
- match = true;
601
- }
602
- _this.ClearStaticToken();
603
- return match;
604
- }));
605
- case 12:
606
- if (!matchNodeId) {
607
- _context6.next = 19;
608
- break;
609
- }
610
- this.SetStaticToken();
611
- _context6.next = 16;
612
- return this.utils.ResponseToJson(this.HttpClient.Request({
613
- path: UrlJoin("nodes", matchNodeId),
614
- method: "GET",
615
- headers: {
616
- Authorization: "Bearer ".concat(this.staticToken)
617
- }
618
- }));
619
- case 16:
620
- node = _context6.sent;
621
- this.ClearStaticToken();
622
- return _context6.abrupt("return", [node]);
623
- case 19:
624
- case "end":
625
- return _context6.stop();
626
- }
627
- }, _callee6, this);
628
- }));
629
- function SpaceNodes() {
630
- return _SpaceNodes.apply(this, arguments);
631
- }
632
- return SpaceNodes;
633
- }()
634
- /**
635
- * Return information about how the client was connected to the network
636
- *
637
- * @methodGroup Nodes
638
- * @returns {Object} - The name, ID and configuration URL of the network
639
- */
640
- }, {
641
- key: "NetworkInfo",
642
- value: function NetworkInfo() {
643
- return {
644
- name: this.networkName,
645
- id: this.networkId,
646
- configUrl: this.configUrl
647
- };
648
- }
649
- }, {
650
- key: "WriteTokenNodeUrl",
651
- value: function WriteTokenNodeUrl(_ref8) {
652
- var writeToken = _ref8.writeToken;
653
- var nodeUrl = this.HttpClient.draftURIs[writeToken];
654
- return nodeUrl ? nodeUrl.toString() : undefined;
655
- }
656
- }, {
657
- key: "RecordWriteToken",
658
- value: function RecordWriteToken(_ref9) {
659
- var writeToken = _ref9.writeToken,
660
- fabricNodeUrl = _ref9.fabricNodeUrl;
661
- this.HttpClient.RecordWriteToken(writeToken, fabricNodeUrl);
662
- }
663
-
664
- /* Wallet and signers */
665
-
666
- /**
667
- * Generate a new ElvWallet that is connected to the client's provider
668
- *
669
- * @methodGroup Signers
670
- * @returns {ElvWallet} - ElvWallet instance with this client's provider
671
- */
672
- }, {
673
- key: "GenerateWallet",
674
- value: function GenerateWallet() {
675
- return new ElvWallet(this.ethClient.Provider());
676
- }
677
-
678
- /**
679
- * Remove the signer from this client
680
- *
681
- * @methodGroup Signers
682
- */
683
- }, {
684
- key: "ClearSigner",
685
- value: function ClearSigner() {
686
- this.signer = undefined;
687
- this.InitializeClients();
688
- }
689
-
690
- /**
691
- * Clear saved access and state channel tokens
692
- *
693
- * @methodGroup Access Requests
694
- */
695
- }, {
696
- key: "ClearCache",
697
- value: function ClearCache() {
698
- this.authClient.ClearCache();
699
- }
700
-
701
- /**
702
- * Set the signer for this client to use for blockchain transactions
703
- *
704
- * @methodGroup Signers
705
- * @namedParams
706
- * @param {object} signer - The ethers.js signer object
707
- */
708
- }, {
709
- key: "SetSigner",
710
- value: function SetSigner(_ref10) {
711
- var signer = _ref10.signer,
712
- _ref10$reset = _ref10.reset,
713
- reset = _ref10$reset === void 0 ? true : _ref10$reset;
714
- this.staticToken = undefined;
715
- signer.connect(this.ethClient.Provider());
716
- signer.provider.pollingInterval = 500;
717
- this.signer = signer;
718
- if (reset) {
719
- this.InitializeClients();
720
- }
721
- }
722
-
723
- /**
724
- * Set signer using OAuth ID token
725
- *
726
- * @methodGroup Signers
727
- * @namedParams
728
- * @param {string=} idToken - OAuth ID token
729
- * @param {string=} authToken - Eluvio authorization token previously issued from OAuth ID token
730
- * @param {string=} tenantId - If specified, user will be associated with the tenant
731
- * @param {Object=} extraData - Additional data to pass to the login API
732
- * @param {Array<string>=} signerURIs - (Only if using custom OAuth) - URIs corresponding to the key server(s) to use
733
- * @param {boolean=} unsignedPublicAuth=false - If specified, the client will use an unsigned static token for calls that don't require authorization (reduces remote signature calls)
734
- */
735
- }, {
736
- key: "SetRemoteSigner",
737
- value: function () {
738
- var _SetRemoteSigner = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref11) {
739
- var idToken, authToken, tenantId, extraData, signerURIs, unsignedPublicAuth, signer;
740
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
741
- while (1) switch (_context7.prev = _context7.next) {
742
- case 0:
743
- idToken = _ref11.idToken, authToken = _ref11.authToken, tenantId = _ref11.tenantId, extraData = _ref11.extraData, signerURIs = _ref11.signerURIs, unsignedPublicAuth = _ref11.unsignedPublicAuth;
744
- _context7.t0 = RemoteSigner;
745
- _context7.t1 = signerURIs || this.authServiceURIs;
746
- _context7.t2 = idToken;
747
- _context7.t3 = authToken;
748
- _context7.t4 = tenantId;
749
- _context7.next = 8;
750
- return this.ethClient.Provider();
751
- case 8:
752
- _context7.t5 = _context7.sent;
753
- _context7.t6 = extraData;
754
- _context7.t7 = unsignedPublicAuth;
755
- _context7.t8 = {
756
- signerURIs: _context7.t1,
757
- idToken: _context7.t2,
758
- authToken: _context7.t3,
759
- tenantId: _context7.t4,
760
- provider: _context7.t5,
761
- extraData: _context7.t6,
762
- unsignedPublicAuth: _context7.t7
763
- };
764
- signer = new _context7.t0(_context7.t8);
765
- _context7.next = 15;
766
- return signer.Initialize();
767
- case 15:
768
- this.SetSigner({
769
- signer: signer
770
- });
771
- case 16:
772
- case "end":
773
- return _context7.stop();
774
- }
775
- }, _callee7, this);
776
- }));
777
- function SetRemoteSigner(_x3) {
778
- return _SetRemoteSigner.apply(this, arguments);
779
- }
780
- return SetRemoteSigner;
781
- }()
782
- /**
783
- * Set the signer for this client to use for blockchain transactions from an existing web3 provider.
784
- * Useful for integrating with MetaMask
785
- *
786
- * @see https://github.com/ethers-io/ethers.js/issues/59#issuecomment-358224800
787
- *
788
- * @methodGroup Signers
789
- * @namedParams
790
- * @param {object} provider - The web3 provider object
791
- */
792
- }, {
793
- key: "SetSignerFromWeb3Provider",
794
- value: function () {
795
- var _SetSignerFromWeb3Provider = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref12) {
796
- var provider, ethProvider;
797
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
798
- while (1) switch (_context8.prev = _context8.next) {
799
- case 0:
800
- provider = _ref12.provider;
801
- this.staticToken = undefined;
802
- ethProvider = new Ethers.providers.Web3Provider(provider);
803
- ethProvider.pollingInterval = 250;
804
- this.signer = ethProvider.getSigner();
805
- _context8.next = 7;
806
- return this.signer.getAddress();
807
- case 7:
808
- this.signer.address = _context8.sent;
809
- _context8.next = 10;
810
- return this.InitializeClients();
811
- case 10:
812
- case "end":
813
- return _context8.stop();
814
- }
815
- }, _callee8, this);
816
- }));
817
- function SetSignerFromWeb3Provider(_x4) {
818
- return _SetSignerFromWeb3Provider.apply(this, arguments);
819
- }
820
- return SetSignerFromWeb3Provider;
821
- }()
822
- /**
823
- * Initialize a new account using the provided funding and group tokens.
824
- *
825
- * This method will redeem the tokens for the current account (or create a new one if not set) in order to
826
- * retrieve funds and optionally have the user added to appropriate access groups.
827
- *
828
- * @methodGroup Signers
829
- * @namedParams
830
- * @param {string} tenantId - The ID of the tenant
831
- * @param {string} fundingToken - A token permitting the user to retrieve funds
832
- * @param {number=} funds=0.5 - The amount to fund this user. The maximum amount is limited by the token issuer.
833
- * @param {string=} groupToken - A token permitting the user to be added to access groups
834
- *
835
- * @return {string} - The address of the user
836
- */
837
- }, {
838
- key: "CreateAccount",
839
- value: function () {
840
- var _CreateAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref13) {
841
- var tenantId, fundingToken, _ref13$funds, funds, groupToken, wallet, signer;
842
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
843
- while (1) switch (_context9.prev = _context9.next) {
844
- case 0:
845
- tenantId = _ref13.tenantId, fundingToken = _ref13.fundingToken, _ref13$funds = _ref13.funds, funds = _ref13$funds === void 0 ? 0.5 : _ref13$funds, groupToken = _ref13.groupToken;
846
- if (!this.signer) {
847
- wallet = this.GenerateWallet();
848
- signer = wallet.AddAccountFromMnemonic({
849
- mnemonic: wallet.GenerateMnemonic()
850
- });
851
- this.SetSigner({
852
- signer: signer
853
- });
854
- }
855
- _context9.next = 4;
856
- return this.authClient.MakeKMSRequest({
857
- method: "POST",
858
- path: "/ks/otp/fnd/".concat(tenantId),
859
- body: {
860
- toAddr: this.signer.address,
861
- amtStr: this.utils.EtherToWei(funds)
862
- },
863
- headers: {
864
- Authorization: "Bearer ".concat(fundingToken)
865
- }
866
- });
867
- case 4:
868
- _context9.next = 6;
869
- return this.userProfileClient.CreateWallet();
870
- case 6:
871
- _context9.next = 8;
872
- return this.userProfileClient.ReplaceUserMetadata({
873
- metadataSubtree: "tenantContractId",
874
- metadata: tenantId
875
- });
876
- case 8:
877
- if (!groupToken) {
878
- _context9.next = 11;
879
- break;
880
- }
881
- _context9.next = 11;
882
- return this.authClient.MakeKMSRequest({
883
- method: "POST",
884
- path: "/ks/otp/grp/".concat(tenantId),
885
- body: {
886
- addAddr: this.signer.address
887
- },
888
- headers: {
889
- Authorization: "Bearer ".concat(groupToken)
890
- }
891
- });
892
- case 11:
893
- return _context9.abrupt("return", this.utils.FormatAddress(this.signer.address));
894
- case 12:
895
- case "end":
896
- return _context9.stop();
897
- }
898
- }, _callee9, this);
899
- }));
900
- function CreateAccount(_x5) {
901
- return _CreateAccount.apply(this, arguments);
902
- }
903
- return CreateAccount;
904
- }()
905
- /*
906
- TOKEN 211b PREFIX + BODY | aplsjcJf1HYcDDUuCdXcSZtU86nYK162YmYJeuqwMczEBJVkD5D5EvsBvVwYDRsf4hzDvBWMoe9piBpqx...
907
- PREFIX 6b aplsjc | apl=plain s=ES256K jc=json-compressed
908
- BODY 205b base58(SIGNATURE + PAYLOAD)
909
- SIGNATURE + PAYLOAD 151b 151b * 138 / 100 + 1 = 209b (>= 205b)
910
- SIGNATURE 66b ES256K_Di9Lu83mz4wMoehCEeQhKpJJ7ApmDZLumAa2Cge48F6EHYnbn8msATGGpjucScwimei1TWGd7aeyQY45AdXd5tT1Z
911
- PAYLOAD 85b json-compressed
912
- json 79b {"adr":"VVf4DQU357tDnZGYQeDrntRJ5rs=","spc":"ispc3ANoVSzNA3P6t7abLR69ho5YPPZU"}
913
- */
914
- }, {
915
- key: "PersonalSign",
916
- value: function () {
917
- var _PersonalSign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref14) {
918
- var _this2 = this;
919
- var message, addEthereumPrefix, Sign;
920
- return _regeneratorRuntime.wrap(function _callee11$(_context11) {
921
- while (1) switch (_context11.prev = _context11.next) {
922
- case 0:
923
- message = _ref14.message, addEthereumPrefix = _ref14.addEthereumPrefix, Sign = _ref14.Sign;
924
- if (!Sign) {
925
- // Same as authClient.Sign, but authClient may not yet be initialized
926
- Sign = /*#__PURE__*/function () {
927
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(message) {
928
- return _regeneratorRuntime.wrap(function _callee10$(_context10) {
929
- while (1) switch (_context10.prev = _context10.next) {
930
- case 0:
931
- _context10.t0 = Ethers.utils;
932
- if (!_this2.signer.signDigest) {
933
- _context10.next = 7;
934
- break;
935
- }
936
- _context10.next = 4;
937
- return _this2.signer.signDigest(message);
938
- case 4:
939
- _context10.t1 = _context10.sent;
940
- _context10.next = 10;
941
- break;
942
- case 7:
943
- _context10.next = 9;
944
- return _this2.signer._signingKey().signDigest(message);
945
- case 9:
946
- _context10.t1 = _context10.sent;
947
- case 10:
948
- _context10.t2 = _context10.t1;
949
- return _context10.abrupt("return", _context10.t0.joinSignature.call(_context10.t0, _context10.t2));
950
- case 12:
951
- case "end":
952
- return _context10.stop();
953
- }
954
- }, _callee10);
955
- }));
956
- return function Sign(_x7) {
957
- return _ref15.apply(this, arguments);
958
- };
959
- }();
960
- }
961
- if (addEthereumPrefix) {
962
- message = Ethers.utils.keccak256(Buffer.from("\x19Ethereum Signed Message:\n".concat(message.length).concat(message), "utf-8"));
963
- }
964
- _context11.next = 5;
965
- return Sign(message);
966
- case 5:
967
- return _context11.abrupt("return", _context11.sent);
968
- case 6:
969
- case "end":
970
- return _context11.stop();
971
- }
972
- }, _callee11);
973
- }));
974
- function PersonalSign(_x6) {
975
- return _PersonalSign.apply(this, arguments);
976
- }
977
- return PersonalSign;
978
- }()
979
- /**
980
- * Create a signed authorization token that can be used to authorize against the fabric
981
- *
982
- * @methodGroup Authorization
983
- * @namedParams
984
- * @param {number} duration=86400000 - Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000). Default is 24 hours.
985
- * @param {Object=} spec - Additional attributes for this token
986
- * @param {string=} address - Address of the signing account - if not specified, the current signer address will be used.
987
- * @param {function=} Sign - If specified, this function will be used to produce the signature instead of the client's current signer
988
- * @param {boolean=} addEthereumPrefix=true - If specified, the 'Ethereum Signed Message' prefixed hash format will be performed. Disable this if the provided Sign method already does this (e.g. Metamask)
989
- */
990
- }, {
991
- key: "CreateFabricToken",
992
- value: function () {
993
- var _CreateFabricToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
994
- var _ref16,
995
- _ref16$duration,
996
- duration,
997
- _ref16$spec,
998
- spec,
999
- address,
1000
- Sign,
1001
- _ref16$addEthereumPre,
1002
- addEthereumPrefix,
1003
- _ref16$context,
1004
- context,
1005
- token,
1006
- message,
1007
- signature,
1008
- compressedToken,
1009
- _args12 = arguments;
1010
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
1011
- while (1) switch (_context12.prev = _context12.next) {
1012
- case 0:
1013
- _ref16 = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {}, _ref16$duration = _ref16.duration, duration = _ref16$duration === void 0 ? 24 * 60 * 60 * 1000 : _ref16$duration, _ref16$spec = _ref16.spec, spec = _ref16$spec === void 0 ? {} : _ref16$spec, address = _ref16.address, Sign = _ref16.Sign, _ref16$addEthereumPre = _ref16.addEthereumPrefix, addEthereumPrefix = _ref16$addEthereumPre === void 0 ? true : _ref16$addEthereumPre, _ref16$context = _ref16.context, context = _ref16$context === void 0 ? {} : _ref16$context;
1014
- address = address || this.CurrentAccountAddress();
1015
- _context12.t0 = _objectSpread;
1016
- _context12.t1 = _objectSpread({}, spec);
1017
- _context12.t2 = {};
1018
- _context12.t3 = "iusr".concat(Utils.AddressToHash(address));
1019
- _context12.t4 = Buffer.from(address.replace(/^0x/, ""), "hex").toString("base64");
1020
- _context12.next = 9;
1021
- return this.ContentSpaceId();
1022
- case 9:
1023
- _context12.t5 = _context12.sent;
1024
- _context12.t6 = Date.now();
1025
- _context12.t7 = Date.now() + duration;
1026
- _context12.t8 = context;
1027
- _context12.t9 = {
1028
- sub: _context12.t3,
1029
- adr: _context12.t4,
1030
- spc: _context12.t5,
1031
- iat: _context12.t6,
1032
- exp: _context12.t7,
1033
- ctx: _context12.t8
1034
- };
1035
- token = (0, _context12.t0)(_context12.t1, _context12.t2, _context12.t9);
1036
- message = "Eluvio Content Fabric Access Token 1.0\n".concat(JSON.stringify(token));
1037
- _context12.next = 18;
1038
- return this.PersonalSign({
1039
- message: message,
1040
- addEthereumPrefix: addEthereumPrefix,
1041
- Sign: Sign
1042
- });
1043
- case 18:
1044
- signature = _context12.sent;
1045
- compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
1046
- return _context12.abrupt("return", "acspjc".concat(this.utils.B58(Buffer.concat([Buffer.from(signature.replace(/^0x/, ""), "hex"), Buffer.from(compressedToken)]))));
1047
- case 21:
1048
- case "end":
1049
- return _context12.stop();
1050
- }
1051
- }, _callee12, this);
1052
- }));
1053
- function CreateFabricToken() {
1054
- return _CreateFabricToken.apply(this, arguments);
1055
- }
1056
- return CreateFabricToken;
1057
- }()
1058
- /**
1059
- * Issue a self-signed authorization token
1060
- *
1061
- * @methodGroup Authorization
1062
- * @namedParams
1063
- * @param {string=} libraryId - Library ID to authorize
1064
- * @param {string=} objectId - Object ID to authorize
1065
- * @param {string=} versionHash - Version hash to authorize
1066
- * @param {string=} policyId - The object ID of the policy for this token
1067
- * @param {string=} subject - The subject of the token
1068
- * @param {string} grantType=read - Permissions to grant for this token. Options: "access", "read", "create", "update", "read-crypt"
1069
- * @param {number} duration - Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000)
1070
- * @param {boolean} allowDecryption=false - If specified, the re-encryption key will be included in the token,
1071
- * enabling the user of this token to download encrypted content from the specified object
1072
- * @param {Object=} context - Additional JSON context
1073
- */
1074
- }, {
1075
- key: "CreateSignedToken",
1076
- value: function () {
1077
- var _CreateSignedToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref17) {
1078
- var libraryId, objectId, versionHash, policyId, subject, _ref17$grantType, grantType, _ref17$allowDecryptio, allowDecryption, duration, _ref17$context, context, token, cap, compressedToken, signature;
1079
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
1080
- while (1) switch (_context13.prev = _context13.next) {
1081
- case 0:
1082
- libraryId = _ref17.libraryId, objectId = _ref17.objectId, versionHash = _ref17.versionHash, policyId = _ref17.policyId, subject = _ref17.subject, _ref17$grantType = _ref17.grantType, grantType = _ref17$grantType === void 0 ? "read" : _ref17$grantType, _ref17$allowDecryptio = _ref17.allowDecryption, allowDecryption = _ref17$allowDecryptio === void 0 ? false : _ref17$allowDecryptio, duration = _ref17.duration, _ref17$context = _ref17.context, context = _ref17$context === void 0 ? {} : _ref17$context;
1083
- if (subject) {
1084
- _context13.next = 9;
1085
- break;
1086
- }
1087
- _context13.t0 = "iusr";
1088
- _context13.t1 = this.utils;
1089
- _context13.next = 6;
1090
- return this.CurrentAccountAddress();
1091
- case 6:
1092
- _context13.t2 = _context13.sent;
1093
- _context13.t3 = _context13.t1.AddressToHash.call(_context13.t1, _context13.t2);
1094
- subject = _context13.t0.concat.call(_context13.t0, _context13.t3);
1095
- case 9:
1096
- if (policyId) {
1097
- context["elv:delegation-id"] = policyId;
1098
- }
1099
- _context13.t4 = Buffer;
1100
- _context13.next = 13;
1101
- return this.CurrentAccountAddress().replace(/^0x/, "");
1102
- case 13:
1103
- _context13.t5 = _context13.sent;
1104
- _context13.t6 = _context13.t4.from.call(_context13.t4, _context13.t5, "hex").toString("base64");
1105
- _context13.t7 = subject;
1106
- _context13.next = 18;
1107
- return this.ContentSpaceId();
1108
- case 18:
1109
- _context13.t8 = _context13.sent;
1110
- _context13.t9 = Date.now();
1111
- _context13.t10 = Date.now() + duration;
1112
- _context13.t11 = grantType;
1113
- _context13.t12 = context;
1114
- token = {
1115
- adr: _context13.t6,
1116
- sub: _context13.t7,
1117
- spc: _context13.t8,
1118
- iat: _context13.t9,
1119
- exp: _context13.t10,
1120
- gra: _context13.t11,
1121
- ctx: _context13.t12
1122
- };
1123
- if (versionHash) {
1124
- objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1125
- }
1126
- if (!objectId) {
1127
- _context13.next = 31;
1128
- break;
1129
- }
1130
- token.qid = objectId;
1131
- if (libraryId) {
1132
- _context13.next = 31;
1133
- break;
1134
- }
1135
- _context13.next = 30;
1136
- return this.ContentObjectLibraryId({
1137
- objectId: objectId
1138
- });
1139
- case 30:
1140
- libraryId = _context13.sent;
1141
- case 31:
1142
- if (libraryId) {
1143
- token.lib = libraryId;
1144
- }
1145
- if (!allowDecryption) {
1146
- _context13.next = 37;
1147
- break;
1148
- }
1149
- _context13.next = 35;
1150
- return this.authClient.ReEncryptionConk({
1151
- libraryId: libraryId,
1152
- objectId: objectId
1153
- });
1154
- case 35:
1155
- cap = _context13.sent;
1156
- token.apk = cap.public_key;
1157
- case 37:
1158
- compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
1159
- _context13.next = 40;
1160
- return this.authClient.Sign(Ethers.utils.keccak256(compressedToken));
1161
- case 40:
1162
- signature = _context13.sent;
1163
- return _context13.abrupt("return", "aessjc".concat(this.utils.B58(Buffer.concat([Buffer.from(signature.replace(/^0x/, ""), "hex"), Buffer.from(compressedToken)]))));
1164
- case 42:
1165
- case "end":
1166
- return _context13.stop();
1167
- }
1168
- }, _callee13, this);
1169
- }));
1170
- function CreateSignedToken(_x8) {
1171
- return _CreateSignedToken.apply(this, arguments);
1172
- }
1173
- return CreateSignedToken;
1174
- }()
1175
- /**
1176
- * Build a signed message (JSON) using the current signer.
1177
- * Signed messages have a similar format to signed access tokens and they include the message itself
1178
- * such that they can be both verified and decoded by the receiving entity.
1179
- *
1180
- * Messages can be encoded and signed using different methods, and the encoding and signature types
1181
- * are described in the header of the resulting signed message blob.
1182
- *
1183
- * Note this type of message can not be verified and decoded on chain.
1184
- *
1185
- * @methodGroup Authorization
1186
- * @namedParams
1187
- * @param {string} messasge - A JSON object representing the message to sign
1188
- */
1189
- }, {
1190
- key: "CreateSignedMessageJSON",
1191
- value: function () {
1192
- var _CreateSignedMessageJSON = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref18) {
1193
- var message, type, msg, signature;
1194
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
1195
- while (1) switch (_context14.prev = _context14.next) {
1196
- case 0:
1197
- message = _ref18.message;
1198
- // Only one kind of signature supported currently
1199
- type = "mje_"; // JSON message, EIP192 signature
1200
- msg = JSON.stringify(message);
1201
- _context14.next = 5;
1202
- return this.PersonalSign({
1203
- message: msg,
1204
- addEthereumPrefix: true
1205
- });
1206
- case 5:
1207
- signature = _context14.sent;
1208
- return _context14.abrupt("return", "".concat(type).concat(Utils.B58(Buffer.concat([Buffer.from(signature.replace(/^0x/, ""), "hex"), Buffer.from(msg)]))));
1209
- case 7:
1210
- case "end":
1211
- return _context14.stop();
1212
- }
1213
- }, _callee14, this);
1214
- }));
1215
- function CreateSignedMessageJSON(_x9) {
1216
- return _CreateSignedMessageJSON.apply(this, arguments);
1217
- }
1218
- return CreateSignedMessageJSON;
1219
- }()
1220
- /**
1221
- * Verify and decode a signed message (JSON).
1222
- *
1223
- * @methodGroup Authorization
1224
- * @namedParams
1225
- * @param {string} signedMessage - a signed message as created by CreateSignedMessageJSON
1226
- * @returns {Promise<Object>} - The decoded message, signer address, signature and signature type
1227
- */
1228
- }, {
1229
- key: "DecodeSignedMessageJSON",
1230
- value: function () {
1231
- var _DecodeSignedMessageJSON = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref19) {
1232
- var signedMessage, type, msgBytes, signature, msg, obj, prefixedMsgHash, signerAddr;
1233
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1234
- while (1) switch (_context15.prev = _context15.next) {
1235
- case 0:
1236
- signedMessage = _ref19.signedMessage;
1237
- type = signedMessage.slice(0, 4);
1238
- _context15.t0 = type;
1239
- _context15.next = _context15.t0 === "mje_" ? 5 : 12;
1240
- break;
1241
- case 5:
1242
- msgBytes = Utils.FromB58(signedMessage.slice(4));
1243
- signature = msgBytes.slice(0, 65);
1244
- msg = msgBytes.slice(65);
1245
- obj = JSON.parse(msg);
1246
- prefixedMsgHash = Ethers.utils.keccak256(Buffer.from("\x19Ethereum Signed Message:\n".concat(msg.length).concat(msg), "utf-8"));
1247
- signerAddr = Ethers.utils.recoverAddress(prefixedMsgHash, signature);
1248
- return _context15.abrupt("return", {
1249
- type: type,
1250
- message: obj,
1251
- signerAddress: signerAddr,
1252
- signature: "0x" + signature.toString("hex")
1253
- });
1254
- case 12:
1255
- throw new Error("Bad message type: ".concat(type));
1256
- case 13:
1257
- case "end":
1258
- return _context15.stop();
1259
- }
1260
- }, _callee15);
1261
- }));
1262
- function DecodeSignedMessageJSON(_x10) {
1263
- return _DecodeSignedMessageJSON.apply(this, arguments);
1264
- }
1265
- return DecodeSignedMessageJSON;
1266
- }()
1267
- /**
1268
- * Get the account address of the current signer
1269
- *
1270
- * @methodGroup Signers
1271
- * @returns {string} - The address of the current signer
1272
- */
1273
- }, {
1274
- key: "CurrentAccountAddress",
1275
- value: function CurrentAccountAddress() {
1276
- return this.signer ? this.utils.FormatAddress(this.signer.address) : "";
1277
- }
1278
-
1279
- /**
1280
- * Set the OAuth token for use in state channel calls
1281
- *
1282
- * @methodGroup Authorization
1283
- * @namedParams
1284
- * @param {string} token - The OAuth ID token
1285
- */
1286
- }, {
1287
- key: "SetOauthToken",
1288
- value: function () {
1289
- var _SetOauthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref20) {
1290
- var token, wallet, signer;
1291
- return _regeneratorRuntime.wrap(function _callee16$(_context16) {
1292
- while (1) switch (_context16.prev = _context16.next) {
1293
- case 0:
1294
- token = _ref20.token;
1295
- this.oauthToken = token;
1296
- wallet = this.GenerateWallet();
1297
- signer = wallet.AddAccountFromMnemonic({
1298
- mnemonic: wallet.GenerateMnemonic()
1299
- });
1300
- this.SetSigner({
1301
- signer: signer
1302
- });
1303
- case 5:
1304
- case "end":
1305
- return _context16.stop();
1306
- }
1307
- }, _callee16, this);
1308
- }));
1309
- function SetOauthToken(_x11) {
1310
- return _SetOauthToken.apply(this, arguments);
1311
- }
1312
- return SetOauthToken;
1313
- }()
1314
- /**
1315
- * Set the signer for this client via OAuth token. The client will exchange the given token
1316
- * for the user's private key using the KMS specified in the configuration.
1317
- *
1318
- * NOTE: The KMS URL(s) must be set in the initial configuration of the client (FromConfigurationUrl or FromNetworkName)
1319
- *
1320
- * @methodGroup Authorization
1321
- * @namedParams
1322
- * @param {string} token - The OAuth ID
1323
- */
1324
- }, {
1325
- key: "SetSignerFromOauthToken",
1326
- value: function () {
1327
- var _SetSignerFromOauthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref21) {
1328
- var token, wallet, client, _yield$client$authCli, urls, path, httpClient, response, privateKey;
1329
- return _regeneratorRuntime.wrap(function _callee17$(_context17) {
1330
- while (1) switch (_context17.prev = _context17.next) {
1331
- case 0:
1332
- token = _ref21.token;
1333
- if (this.trustAuthorityId) {
1334
- _context17.next = 3;
1335
- break;
1336
- }
1337
- throw Error("Unable to authorize with OAuth token: No trust authority ID set");
1338
- case 3:
1339
- wallet = this.GenerateWallet();
1340
- _context17.prev = 4;
1341
- if (this.kmsURIs) {
1342
- _context17.next = 17;
1343
- break;
1344
- }
1345
- _context17.next = 8;
1346
- return ElvClient.FromConfigurationUrl({
1347
- configUrl: this.configUrl
1348
- });
1349
- case 8:
1350
- client = _context17.sent;
1351
- client.SetSigner({
1352
- signer: wallet.AddAccountFromMnemonic({
1353
- mnemonic: wallet.GenerateMnemonic()
1354
- })
1355
- });
1356
- _context17.next = 12;
1357
- return client.authClient.KMSInfo({
1358
- kmsId: this.trustAuthorityId
1359
- });
1360
- case 12:
1361
- _yield$client$authCli = _context17.sent;
1362
- urls = _yield$client$authCli.urls;
1363
- if (!(!urls || urls.length === 0)) {
1364
- _context17.next = 16;
1365
- break;
1366
- }
1367
- throw Error("Unable to authorize with OAuth token: No KMS URLs set");
1368
- case 16:
1369
- this.kmsURIs = urls;
1370
- case 17:
1371
- this.oauthToken = token;
1372
- path = "/ks/jwt/wlt";
1373
- httpClient = new HttpClient({
1374
- uris: this.kmsURIs,
1375
- debug: this.debug
1376
- });
1377
- _context17.next = 22;
1378
- return this.utils.ResponseToJson(httpClient.Request({
1379
- headers: {
1380
- Authorization: "Bearer ".concat(token)
1381
- },
1382
- method: "PUT",
1383
- path: path,
1384
- forceFailover: true
1385
- }));
1386
- case 22:
1387
- response = _context17.sent;
1388
- privateKey = response["UserSKHex"];
1389
- this.SetSigner({
1390
- signer: wallet.AddAccount({
1391
- privateKey: privateKey
1392
- })
1393
- });
1394
-
1395
- // Ensure wallet is initialized
1396
- _context17.next = 27;
1397
- return this.userProfileClient.WalletAddress();
1398
- case 27:
1399
- _context17.next = 36;
1400
- break;
1401
- case 29:
1402
- _context17.prev = 29;
1403
- _context17.t0 = _context17["catch"](4);
1404
- this.Log("Failed to set signer from OAuth token:", true);
1405
- this.Log(_context17.t0, true);
1406
- _context17.next = 35;
1407
- return this.ClearSigner();
1408
- case 35:
1409
- throw _context17.t0;
1410
- case 36:
1411
- case "end":
1412
- return _context17.stop();
1413
- }
1414
- }, _callee17, this, [[4, 29]]);
1415
- }));
1416
- function SetSignerFromOauthToken(_x12) {
1417
- return _SetSignerFromOauthToken.apply(this, arguments);
1418
- }
1419
- return SetSignerFromOauthToken;
1420
- }()
1421
- /**
1422
- * Set a static token for the client to use for all authorization
1423
- *
1424
- * @methodGroup Authorization
1425
- * @namedParams
1426
- * @param {string=} token - The static token to use. If not provided, the default static token will be set.
1427
- */
1428
- }, {
1429
- key: "SetStaticToken",
1430
- value: function SetStaticToken() {
1431
- var _ref22 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1432
- token = _ref22.token;
1433
- if (token) {
1434
- this.staticToken = token;
1435
- } else {
1436
- this.staticToken = this.utils.B64(JSON.stringify({
1437
- qspace_id: this.contentSpaceId
1438
- }));
1439
- }
1440
- }
1441
-
1442
- /**
1443
- * Clear the set static token for the client
1444
- */
1445
- }, {
1446
- key: "ClearStaticToken",
1447
- value: function ClearStaticToken() {
1448
- this.staticToken = undefined;
1449
- }
1450
-
1451
- /**
1452
- * Authorize the client against the specified policy.
1453
- *
1454
- * NOTE: After authorizing, the client will only be able to access content allowed by the policy
1455
- *
1456
- * @methodGroup Authorization
1457
- * @namedParams
1458
- * @param {string} objectId - The ID of the policy object
1459
- */
1460
- }, {
1461
- key: "SetPolicyAuthorization",
1462
- value: function () {
1463
- var _SetPolicyAuthorization = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref23) {
1464
- var objectId;
1465
- return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1466
- while (1) switch (_context18.prev = _context18.next) {
1467
- case 0:
1468
- objectId = _ref23.objectId;
1469
- _context18.t0 = this;
1470
- _context18.next = 4;
1471
- return this.GenerateStateChannelToken({
1472
- objectId: objectId
1473
- });
1474
- case 4:
1475
- _context18.t1 = _context18.sent;
1476
- _context18.t2 = {
1477
- token: _context18.t1
1478
- };
1479
- _context18.t0.SetStaticToken.call(_context18.t0, _context18.t2);
1480
- case 7:
1481
- case "end":
1482
- return _context18.stop();
1483
- }
1484
- }, _callee18, this);
1485
- }));
1486
- function SetPolicyAuthorization(_x13) {
1487
- return _SetPolicyAuthorization.apply(this, arguments);
1488
- }
1489
- return SetPolicyAuthorization;
1490
- }()
1491
- /**
1492
- * Create a signature for the specified string
1493
- *
1494
- * @param {string} string - The string to sign
1495
- * @return {Promise<string>} - The signed string
1496
- */
1497
- }, {
1498
- key: "Sign",
1499
- value: function () {
1500
- var _Sign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(string) {
1501
- var signature;
1502
- return _regeneratorRuntime.wrap(function _callee19$(_context19) {
1503
- while (1) switch (_context19.prev = _context19.next) {
1504
- case 0:
1505
- _context19.next = 2;
1506
- return this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(string)));
1507
- case 2:
1508
- signature = _context19.sent;
1509
- return _context19.abrupt("return", this.utils.FormatSignature(signature));
1510
- case 4:
1511
- case "end":
1512
- return _context19.stop();
1513
- }
1514
- }, _callee19, this);
1515
- }));
1516
- function Sign(_x14) {
1517
- return _Sign.apply(this, arguments);
1518
- }
1519
- return Sign;
1520
- }()
1521
- /**
1522
- * Encrypt the given string or object with the current signer's public key
1523
- *
1524
- * @namedParams
1525
- * @param {string | Object} message - The string or object to encrypt
1526
- * @param {string=} publicKey - If specified, message will be encrypted with this public key instead of the current user's
1527
- *
1528
- * @return {Promise<string>} - The encrypted message
1529
- */
1530
- }, {
1531
- key: "EncryptECIES",
1532
- value: function () {
1533
- var _EncryptECIES = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(_ref24) {
1534
- var message, publicKey;
1535
- return _regeneratorRuntime.wrap(function _callee20$(_context20) {
1536
- while (1) switch (_context20.prev = _context20.next) {
1537
- case 0:
1538
- message = _ref24.message, publicKey = _ref24.publicKey;
1539
- if (this.signer) {
1540
- _context20.next = 3;
1541
- break;
1542
- }
1543
- throw "Signer not set";
1544
- case 3:
1545
- ValidatePresence("message", message);
1546
- _context20.next = 6;
1547
- return this.Crypto.EncryptConk(message, publicKey || this.signer._signingKey().publicKey);
1548
- case 6:
1549
- return _context20.abrupt("return", _context20.sent);
1550
- case 7:
1551
- case "end":
1552
- return _context20.stop();
1553
- }
1554
- }, _callee20, this);
1555
- }));
1556
- function EncryptECIES(_x15) {
1557
- return _EncryptECIES.apply(this, arguments);
1558
- }
1559
- return EncryptECIES;
1560
- }()
1561
- /**
1562
- * Decrypt the given encrypted message with the current signer's private key
1563
- *
1564
- * @namedParams
1565
- * @param {string} message - The message to decrypt
1566
- *
1567
- * @return {Promise<string | Object>} - The decrypted string or object
1568
- */
1569
- }, {
1570
- key: "DecryptECIES",
1571
- value: function () {
1572
- var _DecryptECIES = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(_ref25) {
1573
- var message;
1574
- return _regeneratorRuntime.wrap(function _callee21$(_context21) {
1575
- while (1) switch (_context21.prev = _context21.next) {
1576
- case 0:
1577
- message = _ref25.message;
1578
- if (this.signer) {
1579
- _context21.next = 3;
1580
- break;
1581
- }
1582
- throw "Signer not set";
1583
- case 3:
1584
- ValidatePresence("message", message);
1585
- _context21.next = 6;
1586
- return this.Crypto.DecryptCap(message, this.signer._signingKey().privateKey);
1587
- case 6:
1588
- return _context21.abrupt("return", _context21.sent);
1589
- case 7:
1590
- case "end":
1591
- return _context21.stop();
1592
- }
1593
- }, _callee21, this);
1594
- }));
1595
- function DecryptECIES(_x16) {
1596
- return _DecryptECIES.apply(this, arguments);
1597
- }
1598
- return DecryptECIES;
1599
- }()
1600
- /**
1601
- * Request the specified URL with the given method and body, and return the result in the specified format
1602
- *
1603
- * @param {string} url - URL to request
1604
- * @param {string=} format="json" - Format of response
1605
- * @param {string=} method="GET" - Request method
1606
- * @param {object=} body - Request body
1607
- * @param {object=} headers - Request headers
1608
- *
1609
- * @return {Promise<*>} - Response in the specified format
1610
- */
1611
- }, {
1612
- key: "Request",
1613
- value: function () {
1614
- var _Request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref26) {
1615
- var url, _ref26$format, format, _ref26$method, method, _ref26$headers, headers, body;
1616
- return _regeneratorRuntime.wrap(function _callee22$(_context22) {
1617
- while (1) switch (_context22.prev = _context22.next) {
1618
- case 0:
1619
- url = _ref26.url, _ref26$format = _ref26.format, format = _ref26$format === void 0 ? "json" : _ref26$format, _ref26$method = _ref26.method, method = _ref26$method === void 0 ? "GET" : _ref26$method, _ref26$headers = _ref26.headers, headers = _ref26$headers === void 0 ? {} : _ref26$headers, body = _ref26.body;
1620
- return _context22.abrupt("return", this.utils.ResponseToFormat(format, HttpClient.Fetch(url, {
1621
- method: method,
1622
- headers: headers,
1623
- body: body
1624
- })));
1625
- case 2:
1626
- case "end":
1627
- return _context22.stop();
1628
- }
1629
- }, _callee22, this);
1630
- }));
1631
- function Request(_x17) {
1632
- return _Request.apply(this, arguments);
1633
- }
1634
- return Request;
1635
- }()
1636
- }, {
1637
- key: "MakeAuthServiceRequest",
1638
- value: function () {
1639
- var _MakeAuthServiceRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23(_ref27) {
1640
- var kmsId, objectId, versionHash, _ref27$method, method, path, bodyType, _ref27$body, body, _ref27$queryParams, queryParams, headers;
1641
- return _regeneratorRuntime.wrap(function _callee23$(_context23) {
1642
- while (1) switch (_context23.prev = _context23.next) {
1643
- case 0:
1644
- kmsId = _ref27.kmsId, objectId = _ref27.objectId, versionHash = _ref27.versionHash, _ref27$method = _ref27.method, method = _ref27$method === void 0 ? "GET" : _ref27$method, path = _ref27.path, bodyType = _ref27.bodyType, _ref27$body = _ref27.body, body = _ref27$body === void 0 ? {} : _ref27$body, _ref27$queryParams = _ref27.queryParams, queryParams = _ref27$queryParams === void 0 ? {} : _ref27$queryParams, headers = _ref27.headers;
1645
- return _context23.abrupt("return", this.authClient.MakeAuthServiceRequest({
1646
- kmsId: kmsId,
1647
- objectId: objectId,
1648
- versionHash: versionHash,
1649
- method: method,
1650
- path: path,
1651
- bodyType: bodyType,
1652
- body: body,
1653
- queryParams: queryParams,
1654
- headers: headers
1655
- }));
1656
- case 2:
1657
- case "end":
1658
- return _context23.stop();
1659
- }
1660
- }, _callee23, this);
1661
- }));
1662
- function MakeAuthServiceRequest(_x18) {
1663
- return _MakeAuthServiceRequest.apply(this, arguments);
1664
- }
1665
- return MakeAuthServiceRequest;
1666
- }()
1667
- /* FrameClient related */
1668
- // Whitelist of methods allowed to be called using the frame API
1669
- }, {
1670
- key: "FrameAllowedMethods",
1671
- value: function FrameAllowedMethods() {
1672
- var _this3 = this;
1673
- var forbiddenMethods = ["constructor", "AccessGroupMembershipMethod", "CallFromFrameMessage", "ClearSigner", "CreateAccount", "EnableMethodLogging", "FormatBlockNumbers", "FrameAllowedMethods", "FromConfigurationUrl", "GenerateWallet", "InitializeClients", "Log", "PersonalSign", "SetRemoteSigner", "SetSigner", "SetSignerFromWeb3Provider", "Sign", "ToggleLogging"];
1674
- return Object.getOwnPropertyNames(Object.getPrototypeOf(this)).filter(function (method) {
1675
- return typeof _this3[method] === "function" && !forbiddenMethods.includes(method);
1676
- });
1677
- }
1678
-
1679
- // Call a method specified in a message from a frame
1680
- }, {
1681
- key: "CallFromFrameMessage",
1682
- value: function () {
1683
- var _CallFromFrameMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24(message, Respond) {
1684
- var _this4 = this;
1685
- var callback, method, methodResults, responseError;
1686
- return _regeneratorRuntime.wrap(function _callee24$(_context24) {
1687
- while (1) switch (_context24.prev = _context24.next) {
1688
- case 0:
1689
- if (!(message.type !== "ElvFrameRequest")) {
1690
- _context24.next = 2;
1691
- break;
1692
- }
1693
- return _context24.abrupt("return");
1694
- case 2:
1695
- if (message.callbackId) {
1696
- callback = function callback(result) {
1697
- Respond(_this4.utils.MakeClonable({
1698
- type: "ElvFrameResponse",
1699
- requestId: message.callbackId,
1700
- response: result
1701
- }));
1702
- };
1703
- message.args.callback = callback;
1704
- }
1705
- _context24.prev = 3;
1706
- method = message.calledMethod;
1707
- if (!(message.module === "walletClient")) {
1708
- _context24.next = 15;
1709
- break;
1710
- }
1711
- if (this.walletClient) {
1712
- _context24.next = 8;
1713
- break;
1714
- }
1715
- throw Error("Wallet client not set");
1716
- case 8:
1717
- if (!this.walletClient.ForbiddenMethods().includes(method)) {
1718
- _context24.next = 10;
1719
- break;
1720
- }
1721
- throw Error("Invalid user profile method: " + method);
1722
- case 10:
1723
- _context24.next = 12;
1724
- return this.walletClient[method](message.args);
1725
- case 12:
1726
- methodResults = _context24.sent;
1727
- _context24.next = 28;
1728
- break;
1729
- case 15:
1730
- if (!(message.module === "userProfileClient")) {
1731
- _context24.next = 23;
1732
- break;
1733
- }
1734
- if (this.userProfileClient.FrameAllowedMethods().includes(method)) {
1735
- _context24.next = 18;
1736
- break;
1737
- }
1738
- throw Error("Invalid user profile method: " + method);
1739
- case 18:
1740
- _context24.next = 20;
1741
- return this.userProfileClient[method](message.args);
1742
- case 20:
1743
- methodResults = _context24.sent;
1744
- _context24.next = 28;
1745
- break;
1746
- case 23:
1747
- if (this.FrameAllowedMethods().includes(method)) {
1748
- _context24.next = 25;
1749
- break;
1750
- }
1751
- throw Error("Invalid method: " + method);
1752
- case 25:
1753
- _context24.next = 27;
1754
- return this[method](message.args);
1755
- case 27:
1756
- methodResults = _context24.sent;
1757
- case 28:
1758
- Respond(this.utils.MakeClonable({
1759
- type: "ElvFrameResponse",
1760
- requestId: message.requestId,
1761
- response: methodResults
1762
- }));
1763
- _context24.next = 37;
1764
- break;
1765
- case 31:
1766
- _context24.prev = 31;
1767
- _context24.t0 = _context24["catch"](3);
1768
- // eslint-disable-next-line no-console
1769
- this.Log("Frame Message Error:\n Method: ".concat(message.calledMethod, "\n Arguments: ").concat(JSON.stringify(message.args, null, 2), "\n Error: ").concat(_typeof(_context24.t0) === "object" ? JSON.stringify(_context24.t0, null, 2) : _context24.t0), true);
1770
-
1771
- // eslint-disable-next-line no-console
1772
- console.error(_context24.t0);
1773
- responseError = _context24.t0 instanceof Error ? _context24.t0.message : _context24.t0;
1774
- Respond(this.utils.MakeClonable({
1775
- type: "ElvFrameResponse",
1776
- requestId: message.requestId,
1777
- error: responseError
1778
- }));
1779
- case 37:
1780
- case "end":
1781
- return _context24.stop();
1782
- }
1783
- }, _callee24, this, [[3, 31]]);
1784
- }));
1785
- function CallFromFrameMessage(_x19, _x20) {
1786
- return _CallFromFrameMessage.apply(this, arguments);
1787
- }
1788
- return CallFromFrameMessage;
1789
- }()
1790
- }], [{
1791
- key: "Configuration",
1792
- value: function () {
1793
- var _Configuration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25(_ref28) {
1794
- var configUrl, _ref28$kmsUrls, kmsUrls, region, clientIP, uri, fabricInfo, filterHTTPS, fabricURIs, ethereumURIs, authServiceURIs, fileServiceURIs, searchURIs, fabricVersion;
1795
- return _regeneratorRuntime.wrap(function _callee25$(_context25) {
1796
- while (1) switch (_context25.prev = _context25.next) {
1797
- case 0:
1798
- configUrl = _ref28.configUrl, _ref28$kmsUrls = _ref28.kmsUrls, kmsUrls = _ref28$kmsUrls === void 0 ? [] : _ref28$kmsUrls, region = _ref28.region, clientIP = _ref28.clientIP;
1799
- _context25.prev = 1;
1800
- uri = new URI(configUrl);
1801
- uri.pathname("/config");
1802
- if (region) {
1803
- uri.addSearch("elvgeo", region);
1804
- }
1805
- if (clientIP) {
1806
- uri.addSearch("client_ip", clientIP);
1807
- }
1808
- _context25.next = 8;
1809
- return Utils.ResponseToJson(HttpClient.Fetch(uri.toString()));
1810
- case 8:
1811
- fabricInfo = _context25.sent;
1812
- // If any HTTPS urls present, throw away HTTP urls so only HTTPS will be used
1813
- filterHTTPS = function filterHTTPS(uri) {
1814
- return uri.toLowerCase().startsWith("https");
1815
- };
1816
- fabricURIs = fabricInfo.network.services.fabric_api;
1817
- if (fabricURIs.find(filterHTTPS)) {
1818
- fabricURIs = fabricURIs.filter(filterHTTPS);
1819
- }
1820
- ethereumURIs = fabricInfo.network.services.ethereum_api;
1821
- if (ethereumURIs.find(filterHTTPS)) {
1822
- ethereumURIs = ethereumURIs.filter(filterHTTPS);
1823
- }
1824
- authServiceURIs = fabricInfo.network.services.authority_service || [];
1825
- if (authServiceURIs.find(filterHTTPS)) {
1826
- authServiceURIs = authServiceURIs.filter(filterHTTPS);
1827
- }
1828
- fileServiceURIs = fabricInfo.network.services.file_service || fabricURIs;
1829
- if (fileServiceURIs.find(filterHTTPS)) {
1830
- fileServiceURIs = fileServiceURIs.filter(filterHTTPS);
1831
- }
1832
- searchURIs = fabricInfo.network.services.search || [];
1833
- fabricVersion = Math.max.apply(Math, _toConsumableArray(fabricInfo.network.api_versions || [2]));
1834
- return _context25.abrupt("return", {
1835
- nodeId: fabricInfo.node_id,
1836
- contentSpaceId: fabricInfo.qspace.id,
1837
- networkId: (fabricInfo.qspace.ethereum || {}).network_id,
1838
- networkName: ((fabricInfo.qspace || {}).names || [])[0],
1839
- fabricURIs: fabricURIs,
1840
- ethereumURIs: ethereumURIs,
1841
- authServiceURIs: authServiceURIs,
1842
- fileServiceURIs: fileServiceURIs,
1843
- kmsURIs: kmsUrls,
1844
- searchURIs: searchURIs,
1845
- fabricVersion: fabricVersion
1846
- });
1847
- case 23:
1848
- _context25.prev = 23;
1849
- _context25.t0 = _context25["catch"](1);
1850
- // eslint-disable-next-line no-console
1851
- console.error("Error retrieving fabric configuration:");
1852
- // eslint-disable-next-line no-console
1853
- console.error(_context25.t0);
1854
- throw _context25.t0;
1855
- case 28:
1856
- case "end":
1857
- return _context25.stop();
1858
- }
1859
- }, _callee25, null, [[1, 23]]);
1860
- }));
1861
- function Configuration(_x21) {
1862
- return _Configuration.apply(this, arguments);
1863
- }
1864
- return Configuration;
1865
- }()
1866
- /**
1867
- * Return a list of valid Eluvio Content Fabric network names and their associated configuration URLs
1868
- *
1869
- * @methodGroup Miscellaneous
1870
- *
1871
- * @return {Object} - An object using network names as keys and configuration URLs as values.
1872
- */
1873
- }, {
1874
- key: "Networks",
1875
- value: function Networks() {
1876
- return Object.assign({}, networks);
1877
- }
1878
-
1879
- /**
1880
- * Create a new ElvClient for the specified network
1881
- *
1882
- * @methodGroup Constructor
1883
- * @namedParams
1884
- * @param {string} networkName - Name of the network to connect to ("main", "demo", "test)
1885
- * @param {string=} region - Preferred region - the fabric will auto-detect the best region if not specified
1886
- * - Available regions: as-east, au-east, eu-east-north, eu-west-north, na-east-north, na-east-south, na-west-north, na-west-south, eu-east-south, eu-west-south
1887
- * @param {string=} clientIP - IP address to use in determining the region to use
1888
- * @param {string=} trustAuthorityId - (OAuth) The ID of the trust authority to use for OAuth authentication * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached
1889
- * @param {string=} staticToken - Static token that will be used for all authorization in place of normal auth
1890
- * @param {number=} ethereumContractTimeout=10 - Number of seconds to wait for contract calls
1891
- * @param {boolean=} noAuth=false - If enabled, blockchain authorization will not be performed
1892
- *
1893
- * @return {Promise<ElvClient>} - New ElvClient connected to the specified content fabric and blockchain
1894
- */
1895
- }, {
1896
- key: "FromNetworkName",
1897
- value: function () {
1898
- var _FromNetworkName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26(_ref29) {
1899
- var networkName, region, clientIP, trustAuthorityId, staticToken, _ref29$ethereumContra, ethereumContractTimeout, _ref29$noCache, noCache, _ref29$noAuth, noAuth, assumeV3, configUrl;
1900
- return _regeneratorRuntime.wrap(function _callee26$(_context26) {
1901
- while (1) switch (_context26.prev = _context26.next) {
1902
- case 0:
1903
- networkName = _ref29.networkName, region = _ref29.region, clientIP = _ref29.clientIP, trustAuthorityId = _ref29.trustAuthorityId, staticToken = _ref29.staticToken, _ref29$ethereumContra = _ref29.ethereumContractTimeout, ethereumContractTimeout = _ref29$ethereumContra === void 0 ? 10 : _ref29$ethereumContra, _ref29$noCache = _ref29.noCache, noCache = _ref29$noCache === void 0 ? false : _ref29$noCache, _ref29$noAuth = _ref29.noAuth, noAuth = _ref29$noAuth === void 0 ? false : _ref29$noAuth, assumeV3 = _ref29.assumeV3;
1904
- configUrl = networks[networkName];
1905
- if (configUrl) {
1906
- _context26.next = 4;
1907
- break;
1908
- }
1909
- throw Error("Invalid network name: " + networkName);
1910
- case 4:
1911
- _context26.next = 6;
1912
- return this.FromConfigurationUrl({
1913
- configUrl: configUrl,
1914
- region: region,
1915
- clientIP: clientIP,
1916
- trustAuthorityId: trustAuthorityId,
1917
- staticToken: staticToken,
1918
- ethereumContractTimeout: ethereumContractTimeout,
1919
- noCache: noCache,
1920
- noAuth: noAuth,
1921
- assumeV3: assumeV3
1922
- });
1923
- case 6:
1924
- return _context26.abrupt("return", _context26.sent);
1925
- case 7:
1926
- case "end":
1927
- return _context26.stop();
1928
- }
1929
- }, _callee26, this);
1930
- }));
1931
- function FromNetworkName(_x22) {
1932
- return _FromNetworkName.apply(this, arguments);
1933
- }
1934
- return FromNetworkName;
1935
- }()
1936
- /**
1937
- * Create a new ElvClient from the specified configuration URL
1938
- *
1939
- * @methodGroup Constructor
1940
- * @namedParams
1941
- * @param {string} configUrl - Full URL to the config endpoint
1942
- * @param {string=} region - Preferred region - the fabric will auto-detect the best region if not specified
1943
- * - Available regions: as-east, au-east, eu-east-north, eu-west-north, na-east-north, na-east-south, na-west-north, na-west-south, eu-east-south, eu-west-south
1944
- * @param {string=} clientIP - IP address to use in determining the region to use
1945
- * @param {string=} trustAuthorityId - (OAuth) The ID of the trust authority to use for OAuth authentication * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached
1946
- * @param {string=} staticToken - Static token that will be used for all authorization in place of normal auth
1947
- * @param {number=} ethereumContractTimeout=10 - Number of seconds to wait for contract calls
1948
- * @param {boolean=} noAuth=false - If enabled, blockchain authorization will not be performed
1949
- *
1950
- * @return {Promise<ElvClient>} - New ElvClient connected to the specified content fabric and blockchain
1951
- */
1952
- }, {
1953
- key: "FromConfigurationUrl",
1954
- value: function () {
1955
- var _FromConfigurationUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee27(_ref30) {
1956
- var configUrl, region, clientIP, trustAuthorityId, staticToken, _ref30$ethereumContra, ethereumContractTimeout, _ref30$noCache, noCache, _ref30$noAuth, noAuth, _ref30$assumeV, assumeV3, _yield$ElvClient$Conf3, contentSpaceId, networkId, networkName, fabricURIs, ethereumURIs, authServiceURIs, fileServiceURIs, searchURIs, fabricVersion, client;
1957
- return _regeneratorRuntime.wrap(function _callee27$(_context27) {
1958
- while (1) switch (_context27.prev = _context27.next) {
1959
- case 0:
1960
- configUrl = _ref30.configUrl, region = _ref30.region, clientIP = _ref30.clientIP, trustAuthorityId = _ref30.trustAuthorityId, staticToken = _ref30.staticToken, _ref30$ethereumContra = _ref30.ethereumContractTimeout, ethereumContractTimeout = _ref30$ethereumContra === void 0 ? 10 : _ref30$ethereumContra, _ref30$noCache = _ref30.noCache, noCache = _ref30$noCache === void 0 ? false : _ref30$noCache, _ref30$noAuth = _ref30.noAuth, noAuth = _ref30$noAuth === void 0 ? false : _ref30$noAuth, _ref30$assumeV = _ref30.assumeV3, assumeV3 = _ref30$assumeV === void 0 ? false : _ref30$assumeV;
1961
- _context27.next = 3;
1962
- return ElvClient.Configuration({
1963
- configUrl: configUrl,
1964
- clientIP: clientIP,
1965
- region: region
1966
- });
1967
- case 3:
1968
- _yield$ElvClient$Conf3 = _context27.sent;
1969
- contentSpaceId = _yield$ElvClient$Conf3.contentSpaceId;
1970
- networkId = _yield$ElvClient$Conf3.networkId;
1971
- networkName = _yield$ElvClient$Conf3.networkName;
1972
- fabricURIs = _yield$ElvClient$Conf3.fabricURIs;
1973
- ethereumURIs = _yield$ElvClient$Conf3.ethereumURIs;
1974
- authServiceURIs = _yield$ElvClient$Conf3.authServiceURIs;
1975
- fileServiceURIs = _yield$ElvClient$Conf3.fileServiceURIs;
1976
- searchURIs = _yield$ElvClient$Conf3.searchURIs;
1977
- fabricVersion = _yield$ElvClient$Conf3.fabricVersion;
1978
- client = new ElvClient({
1979
- contentSpaceId: contentSpaceId,
1980
- networkId: networkId,
1981
- networkName: networkName,
1982
- fabricVersion: fabricVersion,
1983
- fabricURIs: fabricURIs,
1984
- ethereumURIs: ethereumURIs,
1985
- authServiceURIs: authServiceURIs,
1986
- fileServiceURIs: fileServiceURIs,
1987
- searchURIs: searchURIs,
1988
- ethereumContractTimeout: ethereumContractTimeout,
1989
- trustAuthorityId: trustAuthorityId,
1990
- staticToken: staticToken,
1991
- noCache: noCache,
1992
- noAuth: noAuth,
1993
- assumeV3: assumeV3
1994
- });
1995
- client.configUrl = configUrl;
1996
- client.region = region;
1997
- client.clientIP = clientIP;
1998
- return _context27.abrupt("return", client);
1999
- case 18:
2000
- case "end":
2001
- return _context27.stop();
2002
- }
2003
- }, _callee27);
2004
- }));
2005
- function FromConfigurationUrl(_x23) {
2006
- return _FromConfigurationUrl.apply(this, arguments);
2007
- }
2008
- return FromConfigurationUrl;
2009
- }()
2010
- }]);
2011
- return ElvClient;
2012
- }();
2013
- Object.assign(ElvClient.prototype, require("./client/AccessGroups"));
2014
- Object.assign(ElvClient.prototype, require("./client/ContentAccess"));
2015
- Object.assign(ElvClient.prototype, require("./client/Contracts"));
2016
- Object.assign(ElvClient.prototype, require("./client/Files"));
2017
- Object.assign(ElvClient.prototype, require("./client/ABRPublishing"));
2018
- Object.assign(ElvClient.prototype, require("./client/LiveStream"));
2019
- Object.assign(ElvClient.prototype, require("./client/ContentManagement"));
2020
- Object.assign(ElvClient.prototype, require("./client/NTP"));
2021
- Object.assign(ElvClient.prototype, require("./client/NFT"));
2022
- exports.ElvClient = ElvClient;