@eluvio/elv-client-js 3.1.87 → 3.1.88
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-lock.json +1 -1
- package/package.json +1 -1
- package/src/UserProfileClient.js +7 -2
- package/src/Utils.js +30 -1
- package/src/client/ContentManagement.js +4 -0
package/package-lock.json
CHANGED
package/package.json
CHANGED
package/src/UserProfileClient.js
CHANGED
|
@@ -438,14 +438,19 @@ await client.userProfileClient.UserMetadata()
|
|
|
438
438
|
* Note: This method is not accessible to applications. Eluvio core will drop the request.
|
|
439
439
|
*
|
|
440
440
|
* @namedParams
|
|
441
|
-
* @param
|
|
441
|
+
* @param {string} id - The tenant ID in hash format
|
|
442
|
+
* @param {string} address - The group address to use in the hash if id is not provided
|
|
442
443
|
*/
|
|
443
444
|
async SetTenantId({id, address}) {
|
|
444
|
-
if(id && !id.startsWith("iten")) {
|
|
445
|
+
if(id && (!id.startsWith("iten") || !Utils.ValidHash(id))) {
|
|
445
446
|
throw Error(`Invalid tenant ID: ${id}`);
|
|
446
447
|
}
|
|
447
448
|
|
|
448
449
|
if(address) {
|
|
450
|
+
if(!Utils.ValidAddress(address)) {
|
|
451
|
+
throw Error(`Invalid address: ${address}`);
|
|
452
|
+
}
|
|
453
|
+
|
|
449
454
|
id = `iten${Utils.AddressToHash(address)}`;
|
|
450
455
|
}
|
|
451
456
|
|
package/src/Utils.js
CHANGED
|
@@ -6,7 +6,8 @@ const VarInt = require("varint");
|
|
|
6
6
|
const URI = require("urijs");
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
|
-
keccak256
|
|
9
|
+
keccak256,
|
|
10
|
+
getAddress
|
|
10
11
|
} = require("ethers").utils;
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -245,6 +246,34 @@ const Utils = {
|
|
|
245
246
|
return (Utils.HashToAddress(firstHash) === Utils.HashToAddress(secondHash));
|
|
246
247
|
},
|
|
247
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Determine whether the address is valid
|
|
251
|
+
*
|
|
252
|
+
* @param {string} address - Address to validate
|
|
253
|
+
*
|
|
254
|
+
* @returns {boolean} - Whether or not the address is valid
|
|
255
|
+
*/
|
|
256
|
+
ValidAddress: (address) => {
|
|
257
|
+
try {
|
|
258
|
+
getAddress(address);
|
|
259
|
+
return true;
|
|
260
|
+
} catch(error) {
|
|
261
|
+
this.Log(error);
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Determine whether the hash is valid
|
|
268
|
+
*
|
|
269
|
+
* @param {string} hash - Hash to validate
|
|
270
|
+
*
|
|
271
|
+
* @returns {boolean} - Whether or not the hash is valid
|
|
272
|
+
*/
|
|
273
|
+
ValidHash: (hash) => {
|
|
274
|
+
return Utils.ValidAddress(Utils.HashToAddress(hash));
|
|
275
|
+
},
|
|
276
|
+
|
|
248
277
|
/**
|
|
249
278
|
* Convert the specified string to a bytes32 string
|
|
250
279
|
*
|
|
@@ -271,6 +271,10 @@ exports.CreateContentLibrary = async function({
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
if(tenantId) {
|
|
274
|
+
if(!this.utils.ValidHash(tenantId)) {
|
|
275
|
+
throw Error(`Invalid tenant ID: ${tenantId}`);
|
|
276
|
+
}
|
|
277
|
+
|
|
274
278
|
await this.CallContractMethod({
|
|
275
279
|
contractAddress,
|
|
276
280
|
methodName: "putMeta",
|