@eluvio/elv-client-js 4.0.78 → 4.0.80
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/dist/ElvClient-min.js +13 -14
- package/dist/ElvClient-node-min.js +13 -14
- package/dist/ElvFrameClient-min.js +9 -9
- package/dist/ElvPermissionsClient-min.js +10 -10
- package/dist/ElvWalletClient-min.js +13 -14
- package/dist/ElvWalletClient-node-min.js +13 -14
- package/dist/src/AuthorizationClient.js +5 -4
- package/dist/src/Crypto.js +2 -2
- package/dist/src/ElvClient.js +254 -162
- package/dist/src/EthClient.js +2 -2
- package/dist/src/FrameClient.js +3 -3
- package/dist/src/HttpClient.js +15 -7
- package/dist/src/PermissionsClient.js +2 -2
- package/dist/src/UserProfileClient.js +36 -71
- package/dist/src/Utils.js +2 -2
- package/dist/src/client/ABRPublishing.js +2 -2
- package/dist/src/client/AccessGroups.js +41 -37
- package/dist/src/client/ContentAccess.js +3 -3
- package/dist/src/client/ContentManagement.js +103 -43
- package/dist/src/client/Contracts.js +270 -6
- package/dist/src/client/Files.js +2 -2
- package/dist/src/client/LiveStream.js +239 -210
- package/dist/src/client/NFT.js +2 -2
- package/dist/src/walletClient/ClientMethods.js +283 -189
- package/dist/src/walletClient/Profile.js +2 -2
- package/dist/src/walletClient/Utils.js +2 -2
- package/dist/src/walletClient/index.js +17 -2
- package/package.json +1 -1
- package/src/ElvClient.js +65 -0
- package/src/FrameClient.js +2 -1
- package/src/HttpClient.js +6 -0
- package/src/UserProfileClient.js +9 -38
- package/src/client/AccessGroups.js +19 -24
- package/src/client/ContentAccess.js +1 -1
- package/src/client/ContentManagement.js +44 -22
- package/src/client/Contracts.js +157 -2
- package/src/client/LiveStream.js +146 -128
- package/src/walletClient/ClientMethods.js +48 -0
- package/src/walletClient/index.js +12 -0
- package/testScripts/CreateAndDecodeSignedMessage.js +51 -0
- package/testScripts/TestAddTenantContractId.js +87 -0
- package/utilities/GenerateFabricToken.js +4 -1
|
@@ -2,8 +2,8 @@ var _defineProperty = require("@babel/runtime/helpers/defineProperty");
|
|
|
2
2
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
3
3
|
var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
4
4
|
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
5
|
-
function ownKeys(
|
|
6
|
-
function _objectSpread(
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
7
|
var Utils = require("../Utils");
|
|
8
8
|
var UrlJoin = require("url-join");
|
|
9
9
|
var StateStorePath = function StateStorePath(_ref) {
|
|
@@ -2,8 +2,8 @@ var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
|
2
2
|
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
3
3
|
var _defineProperty = require("@babel/runtime/helpers/defineProperty");
|
|
4
4
|
var _slicedToArray = require("@babel/runtime/helpers/slicedToArray");
|
|
5
|
-
function ownKeys(
|
|
6
|
-
function _objectSpread(
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
7
|
var Utils = require("../Utils");
|
|
8
8
|
var RarityToPercentage = function RarityToPercentage(rarity) {
|
|
9
9
|
if (!rarity) {
|
|
@@ -5,8 +5,8 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
6
6
|
var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
|
|
7
7
|
var _createClass = require("@babel/runtime/helpers/createClass");
|
|
8
|
-
function ownKeys(
|
|
9
|
-
function _objectSpread(
|
|
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
10
|
var _require = require("../ElvClient"),
|
|
11
11
|
ElvClient = _require.ElvClient;
|
|
12
12
|
var Configuration = require("./Configuration");
|
|
@@ -1739,6 +1739,21 @@ var ElvWalletClient = /*#__PURE__*/function () {
|
|
|
1739
1739
|
if (op === "nft-offer-redeem") {
|
|
1740
1740
|
offerId = status.op.split(":")[3];
|
|
1741
1741
|
}
|
|
1742
|
+
if (op === "nft-claim-entitlement") {
|
|
1743
|
+
var _status$op$split3 = status.op.split(":"),
|
|
1744
|
+
_status$op$split4 = _slicedToArray(_status$op$split3, 4),
|
|
1745
|
+
_op = _status$op$split4[0],
|
|
1746
|
+
marketplace = _status$op$split4[1],
|
|
1747
|
+
sku = _status$op$split4[2],
|
|
1748
|
+
purchaseId = _status$op$split4[3];
|
|
1749
|
+
confirmationId = purchaseId;
|
|
1750
|
+
if (status.extra && status.extra["0"]) {
|
|
1751
|
+
address = status.extra["0"].token_addr;
|
|
1752
|
+
tokenId = status.extra["0"].token_id;
|
|
1753
|
+
address = address.startsWith("0x") ? Utils.FormatAddress(address) : address;
|
|
1754
|
+
status.marketplaceId = marketplace;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1742
1757
|
return _objectSpread(_objectSpread({}, status), {}, {
|
|
1743
1758
|
timestamp: new Date(status.ts),
|
|
1744
1759
|
state: status.state && _typeof(status.state) === "object" ? Object.values(status.state) : status.state,
|
package/package.json
CHANGED
package/src/ElvClient.js
CHANGED
|
@@ -975,6 +975,71 @@ class ElvClient {
|
|
|
975
975
|
]))}`;
|
|
976
976
|
}
|
|
977
977
|
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Build a signed message (JSON) using the current signer.
|
|
981
|
+
* Signed messages have a similar format to signed access tokens and they include the message itself
|
|
982
|
+
* such that they can be both verified and decoded by the receiving entity.
|
|
983
|
+
*
|
|
984
|
+
* Messages can be encoded and signed using different methods, and the encoding and signature types
|
|
985
|
+
* are described in the header of the resulting signed message blob.
|
|
986
|
+
*
|
|
987
|
+
* Note this type of message can not be verified and decoded on chain.
|
|
988
|
+
*
|
|
989
|
+
* @methodGroup Authorization
|
|
990
|
+
* @namedParams
|
|
991
|
+
* @param {string} messasge - A JSON object representing the message to sign
|
|
992
|
+
*/
|
|
993
|
+
async CreateSignedMessageJSON({
|
|
994
|
+
message
|
|
995
|
+
}) {
|
|
996
|
+
|
|
997
|
+
// Only one kind of signature supported currently
|
|
998
|
+
const type = "mje_" // JSON message, EIP192 signature
|
|
999
|
+
|
|
1000
|
+
const msg = JSON.stringify(message);
|
|
1001
|
+
const signature = await this.PersonalSign({message: msg, addEthereumPrefix: true});
|
|
1002
|
+
return `${type}${Utils.B58(
|
|
1003
|
+
Buffer.concat([
|
|
1004
|
+
Buffer.from(signature.replace(/^0x/, ""), "hex"),
|
|
1005
|
+
Buffer.from(msg)
|
|
1006
|
+
])
|
|
1007
|
+
)}`;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
/**
|
|
1011
|
+
* Verify and decode a signed message (JSON).
|
|
1012
|
+
*
|
|
1013
|
+
* @methodGroup Authorization
|
|
1014
|
+
* @namedParams
|
|
1015
|
+
* @param {string} signedMessage - a signed message as created by CreateSignedMessageJSON
|
|
1016
|
+
* @returns {Promise<Object>} - The decoded message, signer address, signature and signature type
|
|
1017
|
+
*/
|
|
1018
|
+
async DecodeSignedMessageJSON({
|
|
1019
|
+
signedMessage
|
|
1020
|
+
}) {
|
|
1021
|
+
const type = signedMessage.slice(0,4);
|
|
1022
|
+
switch(type) {
|
|
1023
|
+
case "mje_":
|
|
1024
|
+
const msgBytes = Utils.FromB58(signedMessage.slice(4));
|
|
1025
|
+
const signature = msgBytes.slice(0, 65);
|
|
1026
|
+
const msg = msgBytes.slice(65);
|
|
1027
|
+
const obj = JSON.parse(msg);
|
|
1028
|
+
|
|
1029
|
+
const prefixedMsgHash = Ethers.utils.keccak256(Buffer.from(`\x19Ethereum Signed Message:\n${msg.length}${msg}`, "utf-8"));
|
|
1030
|
+
const signerAddr = Ethers.utils.recoverAddress(prefixedMsgHash, signature);
|
|
1031
|
+
|
|
1032
|
+
return {
|
|
1033
|
+
type: type,
|
|
1034
|
+
message: obj,
|
|
1035
|
+
signerAddress: signerAddr,
|
|
1036
|
+
signature: "0x" + signature.toString("hex")
|
|
1037
|
+
};
|
|
1038
|
+
default:
|
|
1039
|
+
throw new Error(`Bad message type: ${type}`);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
978
1043
|
/**
|
|
979
1044
|
* Get the account address of the current signer
|
|
980
1045
|
*
|
package/src/FrameClient.js
CHANGED
|
@@ -387,6 +387,7 @@ class FrameClient {
|
|
|
387
387
|
"DeleteMetadata",
|
|
388
388
|
"DeleteNTPInstance",
|
|
389
389
|
"DeletePart",
|
|
390
|
+
"DeleteWriteToken",
|
|
390
391
|
"DeployContract",
|
|
391
392
|
"Download",
|
|
392
393
|
"DownloadEncrypted",
|
|
@@ -476,9 +477,9 @@ class FrameClient {
|
|
|
476
477
|
"StartABRMezzanineJobs",
|
|
477
478
|
"StreamConfig",
|
|
478
479
|
"StreamCreate",
|
|
479
|
-
"StreamDeactivate",
|
|
480
480
|
"StreamInitialize",
|
|
481
481
|
"StreamInsertion",
|
|
482
|
+
"StreamListUrls",
|
|
482
483
|
"StreamStatus",
|
|
483
484
|
"StreamStartOrStopOrReset",
|
|
484
485
|
"StreamStopSession",
|
package/src/HttpClient.js
CHANGED
|
@@ -29,6 +29,12 @@ class HttpClient {
|
|
|
29
29
|
this.draftURIs[writeToken] = new URI(nodeUrlStr);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
ClearWriteToken({writeToken}) {
|
|
33
|
+
if(Object.hasOwn(this.draftURIs, writeToken)) {
|
|
34
|
+
delete this.draftURIs[writeToken];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
RequestHeaders(bodyType, headers={}) {
|
|
33
39
|
if(!headers.Accept) {
|
|
34
40
|
headers["Accept"] = "application/json";
|
package/src/UserProfileClient.js
CHANGED
|
@@ -476,9 +476,11 @@ await client.userProfileClient.UserMetadata()
|
|
|
476
476
|
*/
|
|
477
477
|
async TenantContractId() {
|
|
478
478
|
if(!this.tenantContractId) {
|
|
479
|
-
|
|
479
|
+
const {objectId} = await this.UserWalletObjectInfo();
|
|
480
|
+
this.tenantContractId = await this.client.TenantContractId({
|
|
481
|
+
contractAddress: this.client.utils.HashToAddress(objectId)
|
|
482
|
+
});
|
|
480
483
|
}
|
|
481
|
-
|
|
482
484
|
return this.tenantContractId;
|
|
483
485
|
}
|
|
484
486
|
|
|
@@ -489,44 +491,13 @@ await client.userProfileClient.UserMetadata()
|
|
|
489
491
|
*
|
|
490
492
|
* @namedParams
|
|
491
493
|
* @param {string} tenantContractId - The tenant contract ID in hash format
|
|
492
|
-
* @param {string} address - The
|
|
494
|
+
* @param {string} address - The tenant address to use in the hash if id is not provided
|
|
493
495
|
*/
|
|
494
|
-
async SetTenantContractId({tenantContractId
|
|
495
|
-
|
|
496
|
-
throw Error(`Invalid tenant ID: ${tenantContractId}`);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
if(address) {
|
|
500
|
-
if(!Utils.ValidAddress(address)) {
|
|
501
|
-
throw Error(`Invalid address: ${address}`);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
tenantContractId = `iten${Utils.AddressToHash(address)}`;
|
|
505
|
-
}
|
|
496
|
+
async SetTenantContractId({tenantContractId}) {
|
|
497
|
+
const {objectId} = await this.UserWalletObjectInfo();
|
|
506
498
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
if(version !== this.client.authClient.ACCESS_TYPES.TENANT) {
|
|
511
|
-
throw Error("Invalid tenant ID: " + tenantContractId);
|
|
512
|
-
}
|
|
513
|
-
} catch(error) {
|
|
514
|
-
throw Error("Invalid tenant ID: " + tenantContractId);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
const tenantAdminGroupAddress = await this.client.CallContractMethod({
|
|
518
|
-
contractAddress: address || Utils.HashToAddress(tenantContractId),
|
|
519
|
-
methodName: "groupsMapping",
|
|
520
|
-
methodArgs : ["tenant_admin", 0],
|
|
521
|
-
formatArguments: true,
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
await this.MergeUserMetadata({
|
|
525
|
-
metadata: {
|
|
526
|
-
tenantContractId,
|
|
527
|
-
tenantId: !tenantAdminGroupAddress ? undefined : `iten${Utils.AddressToHash(tenantAdminGroupAddress)}`
|
|
528
|
-
}
|
|
529
|
-
});
|
|
499
|
+
const tenantInfo = await this.client.SetTenantContractId({ objectId,tenantContractId });
|
|
500
|
+
this.tenantContractId = tenantInfo.tenantContractId;
|
|
530
501
|
}
|
|
531
502
|
|
|
532
503
|
/**
|
|
@@ -241,9 +241,8 @@ exports.CreateAccessGroup = async function({name, description, metadata={}, visi
|
|
|
241
241
|
this.Log(`Creating access group: ${name || ""} ${description || ""}`);
|
|
242
242
|
let { contractAddress } = await this.authClient.CreateAccessGroup();
|
|
243
243
|
contractAddress = this.utils.FormatAddress(contractAddress);
|
|
244
|
-
|
|
245
244
|
const objectId = this.utils.AddressToObjectId(contractAddress);
|
|
246
|
-
const
|
|
245
|
+
const tenantContractId = await this.userProfileClient.TenantContractId();
|
|
247
246
|
|
|
248
247
|
this.Log(`Access group: ${contractAddress} ${objectId}`);
|
|
249
248
|
|
|
@@ -262,27 +261,6 @@ exports.CreateAccessGroup = async function({name, description, metadata={}, visi
|
|
|
262
261
|
...metadata
|
|
263
262
|
};
|
|
264
263
|
|
|
265
|
-
if(tenantId) {
|
|
266
|
-
let tenantAdminGroupAddress = this.utils.HashToAddress(tenantId);
|
|
267
|
-
|
|
268
|
-
await this.AddContentObjectGroupPermission({
|
|
269
|
-
objectId,
|
|
270
|
-
groupAddress: tenantAdminGroupAddress,
|
|
271
|
-
permission: "manage"
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
await this.ReplaceContractMetadata({
|
|
275
|
-
contractAddress,
|
|
276
|
-
metadataKey: "_tenantId",
|
|
277
|
-
metadata: tenantId
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
groupMetadata["tenantId"] = tenantId;
|
|
281
|
-
} else {
|
|
282
|
-
// eslint-disable-next-line no-console
|
|
283
|
-
console.warn("No tenant ID associated with current tenant.");
|
|
284
|
-
}
|
|
285
|
-
|
|
286
264
|
await this.ReplaceMetadata({
|
|
287
265
|
libraryId: this.contentSpaceLibraryId,
|
|
288
266
|
objectId,
|
|
@@ -303,6 +281,23 @@ exports.CreateAccessGroup = async function({name, description, metadata={}, visi
|
|
|
303
281
|
commitMessage: "Create access group"
|
|
304
282
|
});
|
|
305
283
|
|
|
284
|
+
if(tenantContractId){
|
|
285
|
+
const tenantInfo = await this.SetTenantContractId({contractAddress, tenantContractId});
|
|
286
|
+
|
|
287
|
+
if(tenantInfo.tenantId) {
|
|
288
|
+
let tenantAdminGroupAddress = this.utils.HashToAddress(tenantInfo.tenantId);
|
|
289
|
+
|
|
290
|
+
await this.AddContentObjectGroupPermission({
|
|
291
|
+
objectId,
|
|
292
|
+
groupAddress: tenantAdminGroupAddress,
|
|
293
|
+
permission: "manage"
|
|
294
|
+
});
|
|
295
|
+
} else {
|
|
296
|
+
// eslint-disable-next-line no-console
|
|
297
|
+
console.warn("No tenant ID associated with current tenant.");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
306
301
|
return contractAddress;
|
|
307
302
|
};
|
|
308
303
|
|
|
@@ -946,4 +941,4 @@ exports.UnlinkAccessGroupFromOauth = async function({groupAddress}) {
|
|
|
946
941
|
methodName: "setOAuthEnabled",
|
|
947
942
|
methodArgs: [false]
|
|
948
943
|
});
|
|
949
|
-
};
|
|
944
|
+
};
|
|
@@ -1275,7 +1275,7 @@ exports.PlayoutPathResolution = async function({
|
|
|
1275
1275
|
* Retrieve available playout offerings for the specified content
|
|
1276
1276
|
*
|
|
1277
1277
|
* @methodGroup Media
|
|
1278
|
-
* @param {string=} objectId -
|
|
1278
|
+
* @param {string=} objectId - ID of the content
|
|
1279
1279
|
* @param {string=} versionHash - Version hash of the content
|
|
1280
1280
|
* @param {string=} writeToken - Write token for the content
|
|
1281
1281
|
* @param {string=} linkPath - If playing from a link, the path to the link
|
|
@@ -221,6 +221,12 @@ exports.CreateContentType = async function({name, metadata={}, bitcode}) {
|
|
|
221
221
|
commitMessage: "Create content type"
|
|
222
222
|
});
|
|
223
223
|
|
|
224
|
+
const tenantContractId = await this.userProfileClient.TenantContractId();
|
|
225
|
+
if(tenantContractId){
|
|
226
|
+
await this.SetTenantContractId({contractAddress, tenantContractId});
|
|
227
|
+
this.Log(`tenant_contract_id set for ${objectId}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
224
230
|
return objectId;
|
|
225
231
|
};
|
|
226
232
|
|
|
@@ -255,7 +261,7 @@ exports.CreateContentLibrary = async function({
|
|
|
255
261
|
imageName,
|
|
256
262
|
metadata={},
|
|
257
263
|
kmsId,
|
|
258
|
-
|
|
264
|
+
tenantContractId
|
|
259
265
|
}) {
|
|
260
266
|
if(!kmsId) {
|
|
261
267
|
kmsId = `ikms${this.utils.AddressToHash(await this.DefaultKMSAddress())}`;
|
|
@@ -266,27 +272,6 @@ exports.CreateContentLibrary = async function({
|
|
|
266
272
|
|
|
267
273
|
const { contractAddress } = await this.authClient.CreateContentLibrary({kmsId});
|
|
268
274
|
|
|
269
|
-
|
|
270
|
-
// Set tenant ID on the library if the user is associated with a tenant
|
|
271
|
-
if(!tenantId) {
|
|
272
|
-
tenantId = await this.userProfileClient.TenantId();
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if(tenantId) {
|
|
276
|
-
if(!this.utils.ValidHash(tenantId)) {
|
|
277
|
-
throw Error(`Invalid tenant ID: ${tenantId}`);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
await this.CallContractMethod({
|
|
281
|
-
contractAddress,
|
|
282
|
-
methodName: "putMeta",
|
|
283
|
-
methodArgs: [
|
|
284
|
-
"_tenantId",
|
|
285
|
-
tenantId
|
|
286
|
-
]
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
275
|
metadata = {
|
|
291
276
|
...metadata,
|
|
292
277
|
name,
|
|
@@ -333,6 +318,16 @@ exports.CreateContentLibrary = async function({
|
|
|
333
318
|
});
|
|
334
319
|
}
|
|
335
320
|
|
|
321
|
+
// Set tenant contract ID on the library if the user is associated with a tenant
|
|
322
|
+
if(!tenantContractId) {
|
|
323
|
+
tenantContractId = await this.userProfileClient.TenantContractId();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if(tenantContractId){
|
|
327
|
+
await this.SetTenantContractId({contractAddress, tenantContractId});
|
|
328
|
+
this.Log(`tenant_contract_id set for ${contractAddress}`);
|
|
329
|
+
}
|
|
330
|
+
|
|
336
331
|
this.Log(`Library ${libraryId} created`);
|
|
337
332
|
|
|
338
333
|
return libraryId;
|
|
@@ -1530,3 +1525,30 @@ exports.SetAuthPolicy = async function({objectId, policyId}) {
|
|
|
1530
1525
|
metadata: { "elv:delegation-id": policyId }
|
|
1531
1526
|
});
|
|
1532
1527
|
};
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* Delete the specified write token
|
|
1531
|
+
*
|
|
1532
|
+
* @methodGroup Content Objects
|
|
1533
|
+
*
|
|
1534
|
+
* @namedParams
|
|
1535
|
+
* @param {string} writeToken - Write token to delete
|
|
1536
|
+
* @param {string} libraryId - ID of the library
|
|
1537
|
+
*/
|
|
1538
|
+
exports.DeleteWriteToken = async function({writeToken, libraryId}) {
|
|
1539
|
+
ValidateWriteToken(writeToken);
|
|
1540
|
+
ValidateLibrary(libraryId);
|
|
1541
|
+
|
|
1542
|
+
let path = UrlJoin("qlibs", libraryId, "q", writeToken);
|
|
1543
|
+
|
|
1544
|
+
const authorizationHeader = await this.authClient.AuthorizationHeader({libraryId, update: true});
|
|
1545
|
+
|
|
1546
|
+
await this.HttpClient.Request({
|
|
1547
|
+
headers: authorizationHeader,
|
|
1548
|
+
method: "DELETE",
|
|
1549
|
+
path: path,
|
|
1550
|
+
allowFailover: false
|
|
1551
|
+
});
|
|
1552
|
+
|
|
1553
|
+
await this.HttpClient.ClearWriteToken({writeToken});
|
|
1554
|
+
};
|
package/src/client/Contracts.js
CHANGED
|
@@ -10,8 +10,10 @@ const Ethers = require("ethers");
|
|
|
10
10
|
const {
|
|
11
11
|
ValidateAddress,
|
|
12
12
|
ValidateParameters,
|
|
13
|
-
ValidatePresence
|
|
13
|
+
ValidatePresence,
|
|
14
|
+
ValidateObject, ValidateVersion
|
|
14
15
|
} = require("../Validation");
|
|
16
|
+
const Utils=require("../Utils");
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Return the name of the contract, as specified in the contracts "version" string
|
|
@@ -323,12 +325,16 @@ exports.ReplaceContractMetadata = async function({contractAddress, metadataKey,
|
|
|
323
325
|
ValidatePresence("contractAddress", contractAddress);
|
|
324
326
|
ValidatePresence("metadataKey", metadataKey);
|
|
325
327
|
|
|
328
|
+
if(typeof metadata === "object") {
|
|
329
|
+
metadata = JSON.stringify(metadata);
|
|
330
|
+
}
|
|
331
|
+
|
|
326
332
|
await this.CallContractMethodAndWait({
|
|
327
333
|
contractAddress,
|
|
328
334
|
methodName: "putMeta",
|
|
329
335
|
methodArgs: [
|
|
330
336
|
metadataKey,
|
|
331
|
-
|
|
337
|
+
metadata
|
|
332
338
|
]
|
|
333
339
|
});
|
|
334
340
|
};
|
|
@@ -572,3 +578,152 @@ exports.SendFunds = async function({recipient, ether}) {
|
|
|
572
578
|
|
|
573
579
|
return await transaction.wait();
|
|
574
580
|
};
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Retrieve the ID of the tenant contract for the specified object
|
|
584
|
+
*
|
|
585
|
+
* @methodGroup Tenant
|
|
586
|
+
* @namedParams
|
|
587
|
+
* @param {string=} contractAddress - The address of the object
|
|
588
|
+
* @param {string=} objectId - The ID of the object
|
|
589
|
+
* @param {string=} versionHash - A version hash of the object
|
|
590
|
+
*
|
|
591
|
+
* @returns {Promise<string|undefined>}
|
|
592
|
+
*/
|
|
593
|
+
exports.TenantContractId = async function({contractAddress, objectId, versionHash}) {
|
|
594
|
+
|
|
595
|
+
if(contractAddress){
|
|
596
|
+
ValidateAddress(contractAddress);
|
|
597
|
+
objectId = Utils.AddressToObjectId(contractAddress);
|
|
598
|
+
} else if(versionHash){
|
|
599
|
+
ValidateVersion(versionHash);
|
|
600
|
+
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
601
|
+
contractAddress = Utils.HashToAddress(objectId);
|
|
602
|
+
} else if(objectId){
|
|
603
|
+
ValidateObject(objectId);
|
|
604
|
+
contractAddress=Utils.HashToAddress(objectId);
|
|
605
|
+
} else {
|
|
606
|
+
throw Error("contractAddress or objectId or versionHash not specified");
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const hasGetMetaMethod = await this.authClient.ContractHasMethod({
|
|
610
|
+
contractAddress: contractAddress,
|
|
611
|
+
methodName: "getMeta"
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
if(hasGetMetaMethod) {
|
|
615
|
+
const tenantContractId = await this.ContractMetadata({
|
|
616
|
+
contractAddress:contractAddress,
|
|
617
|
+
metadataKey:"_ELV_TENANT_ID"
|
|
618
|
+
});
|
|
619
|
+
if(tenantContractId !== "") {
|
|
620
|
+
return tenantContractId;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const libraryId = await this.ContentObjectLibraryId({ objectId });
|
|
625
|
+
|
|
626
|
+
return await this.ContentObjectMetadata({
|
|
627
|
+
libraryId,
|
|
628
|
+
objectId,
|
|
629
|
+
metadataSubtree: "tenantContractId",
|
|
630
|
+
});
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Set the tenant contract ID for the specified object
|
|
635
|
+
*
|
|
636
|
+
* @methodGroup Tenant
|
|
637
|
+
* @namedParams
|
|
638
|
+
* @param {string=} contractAddress - The address of the object
|
|
639
|
+
* @param {string=} objectId - The ID of the object
|
|
640
|
+
* @param {string=} versionHash - A version hash of the object
|
|
641
|
+
* @param {string} tenantContractId - The tenant contract ID to set
|
|
642
|
+
*
|
|
643
|
+
* @returns {Promise<{tenantId: (undefined|string), tenantContractId}>}
|
|
644
|
+
*/
|
|
645
|
+
exports.SetTenantContractId = async function({contractAddress, objectId, versionHash, tenantContractId}) {
|
|
646
|
+
|
|
647
|
+
if(contractAddress){
|
|
648
|
+
ValidateAddress(contractAddress);
|
|
649
|
+
objectId = Utils.AddressToObjectId(contractAddress);
|
|
650
|
+
} else if(versionHash){
|
|
651
|
+
ValidateVersion(versionHash);
|
|
652
|
+
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
653
|
+
contractAddress = Utils.HashToAddress(objectId);
|
|
654
|
+
} else if(objectId){
|
|
655
|
+
ValidateObject(objectId);
|
|
656
|
+
contractAddress=Utils.HashToAddress(objectId);
|
|
657
|
+
} else {
|
|
658
|
+
throw Error("contractAddress or objectId or versionHash not specified");
|
|
659
|
+
}
|
|
660
|
+
ValidateObject(tenantContractId);
|
|
661
|
+
|
|
662
|
+
if(tenantContractId && (!tenantContractId.startsWith("iten") || !Utils.ValidHash(tenantContractId))) {
|
|
663
|
+
throw Error(`Invalid tenant ID: ${tenantContractId}`);
|
|
664
|
+
}
|
|
665
|
+
const tenantAddress = Utils.HashToAddress(tenantContractId);
|
|
666
|
+
|
|
667
|
+
const version = await this.authClient.AccessType(tenantContractId);
|
|
668
|
+
if(version !== this.authClient.ACCESS_TYPES.TENANT) {
|
|
669
|
+
throw Error("Invalid tenant ID: " + tenantContractId);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// get tenant admin group
|
|
673
|
+
const tenantAdminGroupAddress = await this.CallContractMethod({
|
|
674
|
+
contractAddress: tenantAddress,
|
|
675
|
+
methodName: "groupsMapping",
|
|
676
|
+
methodArgs: ["tenant_admin", 0],
|
|
677
|
+
formatArguments: true,
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
const hasPutMetaMethod = await this.authClient.ContractHasMethod({
|
|
681
|
+
contractAddress: contractAddress,
|
|
682
|
+
methodName: "putMeta"
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
if(hasPutMetaMethod) {
|
|
686
|
+
|
|
687
|
+
await this.ReplaceContractMetadata({
|
|
688
|
+
contractAddress: contractAddress,
|
|
689
|
+
metadataKey: "_ELV_TENANT_ID",
|
|
690
|
+
metadata: tenantContractId
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
if(tenantAdminGroupAddress){
|
|
694
|
+
await this.ReplaceContractMetadata({
|
|
695
|
+
contractAddress: contractAddress,
|
|
696
|
+
metadataKey: "_tenantId",
|
|
697
|
+
metadata: `iten${Utils.AddressToHash(tenantAdminGroupAddress)}`
|
|
698
|
+
});
|
|
699
|
+
} else {
|
|
700
|
+
// eslint-disable-next-line no-console
|
|
701
|
+
console.warn("No tenant ID associated with current tenant.");
|
|
702
|
+
}
|
|
703
|
+
} else {
|
|
704
|
+
const libraryId = await this.ContentObjectLibraryId({ objectId });
|
|
705
|
+
const editRequest = await this.EditContentObject({libraryId, objectId});
|
|
706
|
+
|
|
707
|
+
await this.MergeMetadata({
|
|
708
|
+
libraryId,
|
|
709
|
+
objectId,
|
|
710
|
+
writeToken: editRequest.write_token,
|
|
711
|
+
metadata: {
|
|
712
|
+
tenantContractId,
|
|
713
|
+
tenantId: !tenantAdminGroupAddress ? undefined : `iten${Utils.AddressToHash(tenantAdminGroupAddress)}`
|
|
714
|
+
},
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
await this.FinalizeContentObject({
|
|
718
|
+
libraryId,
|
|
719
|
+
objectId,
|
|
720
|
+
writeToken: editRequest.write_token,
|
|
721
|
+
commitMessage: "set tenant_contract_id"
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
return {
|
|
726
|
+
tenantContractId: tenantContractId,
|
|
727
|
+
tenantId: !tenantAdminGroupAddress ? undefined : `iten${Utils.AddressToHash(tenantAdminGroupAddress)}`
|
|
728
|
+
};
|
|
729
|
+
};
|