@eluvio/elv-client-js 4.0.139 → 4.0.141

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.139",
3
+ "version": "4.0.141",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
package/src/ElvClient.js CHANGED
@@ -202,6 +202,10 @@ class ElvClient {
202
202
 
203
203
  this.debug = false;
204
204
 
205
+ // Use a default key when client is unauthed. This key should not be used for any other purpose.
206
+ // Break it up to avoid automatic private key detection warnings
207
+ this.defaultKey = "0x" + "5d52d808f10f64f0dffff8c73edff" + "3f7b467411216e2350940f869e6ac5a7db6";
208
+
205
209
  this.InitializeClients({staticToken});
206
210
  }
207
211
 
@@ -433,7 +437,7 @@ class ElvClient {
433
437
 
434
438
  if(!this.signer) {
435
439
  const wallet = this.GenerateWallet();
436
- const signer = wallet.AddAccountFromMnemonic({mnemonic: wallet.GenerateMnemonic()});
440
+ const signer = wallet.AddAccount({privateKey: this.defaultKey});
437
441
  signer.anonymous = true;
438
442
 
439
443
  this.SetSigner({signer, reset: false});
@@ -1201,7 +1205,7 @@ class ElvClient {
1201
1205
  // Make dummy client with dummy account to allow calling of contracts
1202
1206
  const client = await ElvClient.FromConfigurationUrl({configUrl: this.configUrl});
1203
1207
  client.SetSigner({
1204
- signer: wallet.AddAccountFromMnemonic({mnemonic: wallet.GenerateMnemonic()})
1208
+ signer: wallet.AddAccount({privateKey: this.defaultKey})
1205
1209
  });
1206
1210
 
1207
1211
  const {urls} = await client.authClient.KMSInfo({
@@ -185,28 +185,8 @@ class ElvWalletClient {
185
185
  }
186
186
  }
187
187
 
188
- try {
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();
199
-
200
- if(!skipMarketplaceLoad) {
201
- walletClient.LoadAvailableMarketplaces();
202
- }
203
- })
204
- );
205
- } catch(error) {
206
- // eslint-disable-next-line no-console
207
- console.error("Unable to load top level info:");
208
- // eslint-disable-next-line no-console
209
- console.error(error);
188
+ if(!skipMarketplaceLoad) {
189
+ walletClient.LoadAvailableMarketplaces();
210
190
  }
211
191
 
212
192
  return walletClient;
@@ -774,39 +754,57 @@ class ElvWalletClient {
774
754
 
775
755
  // Internal loading methods
776
756
 
777
- async LoadAvailableMarketplaces(forceReload=false) {
778
- if(!forceReload && Object.keys(this.availableMarketplaces) > 0) {
779
- return;
757
+ async TopLevelInfo(forceReload=false) {
758
+ if(!this.topLevelInfoPromise || forceReload) {
759
+ this.topLevelInfoPromise = this.client.utils.ResponseToJson(
760
+ this.client.MakeAuthServiceRequest({
761
+ path: "/as/mw/toplevel",
762
+ queryParams: {env: this.mode}
763
+ })
764
+ );
780
765
  }
781
766
 
782
- const marketplaces = this.topLevelInfo.marketplaces;
783
-
784
- let availableMarketplaces = { ...(this.availableMarketplaces || {}) };
785
- let availableMarketplacesById = { ...(this.availableMarketplacesById || {}) };
767
+ return await this.topLevelInfoPromise;
768
+ }
786
769
 
787
- marketplaces.map(marketplaceInfo => {
788
- const marketplaceId = Utils.DecodeVersionHash(marketplaceInfo.source_hash).objectId;
789
- const marketplaceSlug = marketplaceInfo.slug || marketplaceInfo.name;
770
+ async LoadAvailableMarketplaces(forceReload=false) {
771
+ if(!this.availableMarketplacesPromise || forceReload) {
772
+ this.availableMarketplacesPromise = new Promise(async resolve => {
773
+ const topLevelInfo = await this.TopLevelInfo();
774
+ const marketplaces = topLevelInfo.marketplaces;
775
+
776
+ let availableMarketplaces = {...(this.availableMarketplaces || {})};
777
+ let availableMarketplacesById = {...(this.availableMarketplacesById || {})};
778
+
779
+ marketplaces.map(marketplaceInfo => {
780
+ const marketplaceId = Utils.DecodeVersionHash(marketplaceInfo.source_hash).objectId;
781
+ const marketplaceSlug = marketplaceInfo.slug || marketplaceInfo.name;
782
+
783
+ availableMarketplaces[marketplaceInfo.tenant_slug] = availableMarketplaces[marketplaceInfo.tenant_slug] || {};
784
+
785
+ availableMarketplaces[marketplaceInfo.tenant_slug][marketplaceSlug] = {
786
+ ...marketplaceInfo,
787
+ tenantName: marketplaceInfo.tenant_slug,
788
+ tenantSlug: marketplaceInfo.tenant_slug,
789
+ tenantId: marketplaceInfo.tenant_id,
790
+ marketplaceSlug: marketplaceSlug,
791
+ marketplaceId,
792
+ marketplaceHash: marketplaceInfo.source_hash
793
+ };
790
794
 
791
- availableMarketplaces[marketplaceInfo.tenant_slug] = availableMarketplaces[marketplaceInfo.tenant_slug] || {};
795
+ availableMarketplacesById[marketplaceId] = availableMarketplaces[marketplaceInfo.tenant_slug][marketplaceSlug];
792
796
 
793
- availableMarketplaces[marketplaceInfo.tenant_slug][marketplaceSlug] = {
794
- ...marketplaceInfo,
795
- tenantName: marketplaceInfo.tenant_slug,
796
- tenantSlug: marketplaceInfo.tenant_slug,
797
- tenantId: marketplaceInfo.tenant_id,
798
- marketplaceSlug: marketplaceSlug,
799
- marketplaceId,
800
- marketplaceHash: marketplaceInfo.source_hash
801
- };
797
+ this.marketplaceHashes[marketplaceId] = marketplaceInfo.source_hash;
798
+ });
802
799
 
803
- availableMarketplacesById[marketplaceId] = availableMarketplaces[marketplaceInfo.tenant_slug][marketplaceSlug];
800
+ this.availableMarketplaces = availableMarketplaces;
801
+ this.availableMarketplacesById = availableMarketplacesById;
804
802
 
805
- this.marketplaceHashes[marketplaceId] = marketplaceInfo.source_hash;
806
- });
803
+ resolve();
804
+ });
805
+ }
807
806
 
808
- this.availableMarketplaces = availableMarketplaces;
809
- this.availableMarketplacesById = availableMarketplacesById;
807
+ await this.availableMarketplacesPromise;
810
808
  }
811
809
 
812
810
  // Get the hash of the currently linked marketplace
@@ -829,7 +827,8 @@ class ElvWalletClient {
829
827
  }
830
828
 
831
829
  async LoadMarketplace(marketplaceParams) {
832
- await this.topLevelInfoPromise;
830
+ await this.LoadAvailableMarketplaces();
831
+
833
832
  const marketplaceInfo = this.MarketplaceInfo({marketplaceParams});
834
833
 
835
834
  const marketplaceId = marketplaceInfo.marketplaceId;