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