@eluvio/elv-client-js 4.0.137 → 4.0.139
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/AuthorizationClient.js +2 -1
- package/src/ElvClient.js +2 -0
- package/src/EthClient.js +1 -1
- package/src/client/ABRPublishing.js +1 -1
- package/src/client/ContentAccess.js +30 -71
- package/src/walletClient/index.js +15 -12
package/package.json
CHANGED
|
@@ -122,6 +122,7 @@ class AuthorizationClient {
|
|
|
122
122
|
const isWalletRequest =
|
|
123
123
|
objectId &&
|
|
124
124
|
this.client.signer &&
|
|
125
|
+
!this.client.signer.anonymous &&
|
|
125
126
|
this.client.utils.EqualAddress(
|
|
126
127
|
await this.client.userProfileClient.WalletAddress(false),
|
|
127
128
|
this.client.utils.HashToAddress(objectId)
|
|
@@ -958,7 +959,7 @@ class AuthorizationClient {
|
|
|
958
959
|
|
|
959
960
|
const kmsUrl = KMSUrls[i];
|
|
960
961
|
if(!this.providers[kmsUrl]) {
|
|
961
|
-
this.providers[kmsUrl] = new Ethers.providers.
|
|
962
|
+
this.providers[kmsUrl] = new Ethers.providers.StaticJsonRpcProvider(kmsUrl, this.client.networkId);
|
|
962
963
|
}
|
|
963
964
|
|
|
964
965
|
return await this.providers[kmsUrl].send(methodName, params);
|
package/src/ElvClient.js
CHANGED
|
@@ -434,6 +434,7 @@ class ElvClient {
|
|
|
434
434
|
if(!this.signer) {
|
|
435
435
|
const wallet = this.GenerateWallet();
|
|
436
436
|
const signer = wallet.AddAccountFromMnemonic({mnemonic: wallet.GenerateMnemonic()});
|
|
437
|
+
signer.anonymous = true;
|
|
437
438
|
|
|
438
439
|
this.SetSigner({signer, reset: false});
|
|
439
440
|
this.SetStaticToken({token: staticToken});
|
|
@@ -739,6 +740,7 @@ class ElvClient {
|
|
|
739
740
|
);
|
|
740
741
|
|
|
741
742
|
if(!nodeUrl) {
|
|
743
|
+
// eslint-disable-next-line no-console
|
|
742
744
|
console.error(`No node url found for write token: ${writeToken}`);
|
|
743
745
|
|
|
744
746
|
return "";
|
package/src/EthClient.js
CHANGED
|
@@ -50,7 +50,7 @@ class EthClient {
|
|
|
50
50
|
|
|
51
51
|
Provider() {
|
|
52
52
|
if(!this.provider) {
|
|
53
|
-
this.provider = new Ethers.providers.
|
|
53
|
+
this.provider = new Ethers.providers.StaticJsonRpcProvider(this.ethereumURIs[this.ethereumURIIndex], this.networkId);
|
|
54
54
|
|
|
55
55
|
// Ethers.js uses eth_getCode to ensure a contract is deployed and nothing else - this pulls a large chunk of pointless
|
|
56
56
|
// data every time a contract is initialized in the client (often). Ethers.js just checks that the code isn't == "0x", so
|
|
@@ -832,7 +832,7 @@ exports.FinalizeABRMezzanine = async function({libraryId, objectId, preFinalizeF
|
|
|
832
832
|
}
|
|
833
833
|
|
|
834
834
|
const finalizeResponse = {};
|
|
835
|
-
if
|
|
835
|
+
if(!writeToken) {
|
|
836
836
|
finalizeResponse = await this.FinalizeContentObject({
|
|
837
837
|
libraryId,
|
|
838
838
|
objectId: objectId,
|
|
@@ -584,17 +584,21 @@ exports.ContentObjects = async function({libraryId, filterOptions={}}) {
|
|
|
584
584
|
*
|
|
585
585
|
* @returns {Promise<Object>} - Description of content object
|
|
586
586
|
*/
|
|
587
|
-
exports.ContentObject = async function({
|
|
588
|
-
|
|
587
|
+
exports.ContentObject = async function({objectId, versionHash, writeToken}) {
|
|
588
|
+
this.Log(`Retrieving content object: ${writeToken || versionHash || objectId}`);
|
|
589
589
|
|
|
590
|
-
|
|
590
|
+
if(writeToken) {
|
|
591
|
+
objectId = this.utils.DecodeWriteToken(writeToken).objectId;
|
|
592
|
+
} else if(versionHash) {
|
|
593
|
+
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
594
|
+
}
|
|
591
595
|
|
|
592
|
-
|
|
596
|
+
ValidateObject(objectId);
|
|
593
597
|
|
|
594
598
|
let path = UrlJoin("q", writeToken || versionHash || objectId);
|
|
595
599
|
|
|
596
600
|
return await this.HttpClient.RequestJsonBody({
|
|
597
|
-
headers: await this.authClient.AuthorizationHeader({
|
|
601
|
+
headers: await this.authClient.AuthorizationHeader({objectId, versionHash}),
|
|
598
602
|
method: "GET",
|
|
599
603
|
path: path
|
|
600
604
|
});
|
|
@@ -664,6 +668,24 @@ exports.ContentObjectTenantId = async function({objectId, versionHash}) {
|
|
|
664
668
|
* @returns {Promise<string>} - Library ID of the object
|
|
665
669
|
*/
|
|
666
670
|
exports.ContentObjectLibraryId = async function({objectId, versionHash}) {
|
|
671
|
+
if(versionHash) {
|
|
672
|
+
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Cache results because they will never change
|
|
676
|
+
if(!this.objectLibraryIds[objectId]) {
|
|
677
|
+
try {
|
|
678
|
+
this.objectLibraryIds[objectId] = (await this.ContentObject({objectId, versionHash})).qlib_id;
|
|
679
|
+
} catch(error) {
|
|
680
|
+
error.message = `Unable to determine latest library for ${versionHash || objectId}`;
|
|
681
|
+
throw error;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
return this.objectLibraryIds[objectId];
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
exports.ContentObjectLibraryId2 = async function({objectId, versionHash}) {
|
|
667
689
|
versionHash ? ValidateVersion(versionHash) : ValidateObject(objectId);
|
|
668
690
|
|
|
669
691
|
if(versionHash) { objectId = this.utils.DecodeVersionHash(versionHash).objectId; }
|
|
@@ -1065,57 +1087,8 @@ exports.ContentObjectVersions = async function({libraryId, objectId}) {
|
|
|
1065
1087
|
});
|
|
1066
1088
|
};
|
|
1067
1089
|
|
|
1068
|
-
/**
|
|
1069
|
-
* Retrieve the version hash of the latest version of the specified object from chain
|
|
1070
|
-
*
|
|
1071
|
-
* @methodGroup Content Objects
|
|
1072
|
-
* @namedParams
|
|
1073
|
-
* @param {string=} objectId - ID of the object
|
|
1074
|
-
* @param {string=} versionHash - Version hash of the object
|
|
1075
|
-
*
|
|
1076
|
-
* @returns {Promise<string>} - The latest version hash of the object
|
|
1077
|
-
*/
|
|
1078
|
-
exports.LatestVersionHash = async function({objectId, versionHash}) {
|
|
1079
|
-
if(versionHash) { objectId = this.utils.DecodeVersionHash(versionHash).objectId; }
|
|
1080
|
-
|
|
1081
|
-
ValidateObject(objectId);
|
|
1082
|
-
|
|
1083
|
-
let latestHash;
|
|
1084
|
-
try {
|
|
1085
|
-
latestHash = await this.CallContractMethod({
|
|
1086
|
-
contractAddress: this.utils.HashToAddress(objectId),
|
|
1087
|
-
methodName: "objectHash"
|
|
1088
|
-
});
|
|
1089
|
-
// eslint-disable-next-line no-empty
|
|
1090
|
-
} catch(error) {}
|
|
1091
|
-
|
|
1092
|
-
if(!latestHash) {
|
|
1093
|
-
let versionCount;
|
|
1094
|
-
try {
|
|
1095
|
-
versionCount = await this.CallContractMethod({
|
|
1096
|
-
contractAddress: this.utils.HashToAddress(objectId),
|
|
1097
|
-
methodName: "countVersionHashes"
|
|
1098
|
-
});
|
|
1099
|
-
// eslint-disable-next-line no-empty
|
|
1100
|
-
} catch(error) {}
|
|
1101
|
-
|
|
1102
|
-
if(!versionCount || !versionCount.toNumber()) {
|
|
1103
|
-
throw Error(`Unable to determine latest version hash for ${versionHash || objectId} - Item deleted?`);
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
latestHash = await this.CallContractMethod({
|
|
1107
|
-
contractAddress: this.utils.HashToAddress(objectId),
|
|
1108
|
-
methodName: "versionHashes",
|
|
1109
|
-
methodArgs: [versionCount - 1]
|
|
1110
|
-
});
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
return latestHash;
|
|
1114
|
-
};
|
|
1115
|
-
|
|
1116
1090
|
/**
|
|
1117
1091
|
* Retrieve the version hash of the latest version of the specified object via fabric API.
|
|
1118
|
-
* Requires authorization.
|
|
1119
1092
|
*
|
|
1120
1093
|
* @methodGroup Content Objects
|
|
1121
1094
|
* @namedParams
|
|
@@ -1124,27 +1097,13 @@ exports.LatestVersionHash = async function({objectId, versionHash}) {
|
|
|
1124
1097
|
*
|
|
1125
1098
|
* @returns {Promise<string>} - The latest version hash of the object
|
|
1126
1099
|
*/
|
|
1127
|
-
exports.
|
|
1128
|
-
if(versionHash) { objectId = this.utils.DecodeVersionHash(versionHash).objectId; }
|
|
1129
|
-
|
|
1130
|
-
ValidateObject(objectId);
|
|
1131
|
-
|
|
1132
|
-
let latestHash;
|
|
1100
|
+
exports.LatestVersionHash = async function({objectId, versionHash}) {
|
|
1133
1101
|
try {
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
let q = await this.HttpClient.RequestJsonBody({
|
|
1137
|
-
headers: await this.authClient.AuthorizationHeader({objectId}),
|
|
1138
|
-
method: "GET",
|
|
1139
|
-
path: path
|
|
1140
|
-
});
|
|
1141
|
-
latestHash = q.hash;
|
|
1142
|
-
|
|
1102
|
+
return (await this.ContentObject({objectId, versionHash})).hash;
|
|
1143
1103
|
} catch(error) {
|
|
1144
1104
|
error.message = `Unable to determine latest version hash for ${versionHash || objectId}`;
|
|
1145
1105
|
throw error;
|
|
1146
1106
|
}
|
|
1147
|
-
return latestHash;
|
|
1148
1107
|
};
|
|
1149
1108
|
|
|
1150
1109
|
/* URL Methods */
|
|
@@ -1946,7 +1905,7 @@ exports.MakeFileServiceRequest = async function({
|
|
|
1946
1905
|
]
|
|
1947
1906
|
.flat()
|
|
1948
1907
|
.filter(token => token);
|
|
1949
|
-
|
|
1908
|
+
|
|
1950
1909
|
return this.utils.ResponseToFormat(
|
|
1951
1910
|
format,
|
|
1952
1911
|
await this.FileServiceHttpClient.Request({
|
|
@@ -186,19 +186,22 @@ class ElvWalletClient {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
try {
|
|
189
|
-
walletClient.topLevelInfoPromise =
|
|
190
|
-
client.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
189
|
+
walletClient.topLevelInfoPromise = new Promise(resolve =>
|
|
190
|
+
client.utils.ResponseToJson(
|
|
191
|
+
client.MakeAuthServiceRequest({
|
|
192
|
+
path: "/as/mw/toplevel",
|
|
193
|
+
queryParams: {env: mode}
|
|
194
|
+
})
|
|
195
|
+
)
|
|
196
|
+
.then(info => {
|
|
197
|
+
walletClient.topLevelInfo = info;
|
|
198
|
+
resolve();
|
|
197
199
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
if(!skipMarketplaceLoad) {
|
|
201
|
+
walletClient.LoadAvailableMarketplaces();
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
);
|
|
202
205
|
} catch(error) {
|
|
203
206
|
// eslint-disable-next-line no-console
|
|
204
207
|
console.error("Unable to load top level info:");
|