@eluvio/elv-client-js 4.0.109 → 4.0.110

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/src/ElvClient.js CHANGED
@@ -435,7 +435,7 @@ class ElvClient {
435
435
  const signer = wallet.AddAccountFromMnemonic({mnemonic: wallet.GenerateMnemonic()});
436
436
 
437
437
  this.SetSigner({signer, reset: false});
438
- this.SetStaticToken({token: staticToken});
438
+ await this.SetStaticToken({token: staticToken});
439
439
  }
440
440
 
441
441
  this.authClient = new AuthorizationClient({
@@ -623,7 +623,7 @@ class ElvClient {
623
623
  */
624
624
  async SpaceNodes({matchEndpoint, matchNodeId}={}) {
625
625
  let nodes;
626
- this.SetStaticToken();
626
+ await this.SetStaticToken();
627
627
 
628
628
  if(matchEndpoint) {
629
629
  ({nodes} = await this.utils.ResponseToJson(
@@ -664,7 +664,7 @@ class ElvClient {
664
664
  return match;
665
665
  });
666
666
  } else if(matchNodeId) {
667
- this.SetStaticToken();
667
+ await this.SetStaticToken();
668
668
  let node = await this.utils.ResponseToJson(
669
669
  this.HttpClient.Request({
670
670
  path: UrlJoin("nodes", matchNodeId),
@@ -877,7 +877,13 @@ class ElvClient {
877
877
  Sign
878
878
  }) {
879
879
  if(!Sign) {
880
- Sign = async message => this.authClient.Sign(message);
880
+ // Same as authClient.Sign, but authClient may not yet be initialized
881
+ Sign = async message =>
882
+ Ethers.utils.joinSignature(
883
+ this.signer.signDigest ?
884
+ await this.signer.signDigest(message) :
885
+ await this.signer._signingKey().signDigest(message)
886
+ );
881
887
  }
882
888
 
883
889
  if(addEthereumPrefix) {
@@ -1171,12 +1177,13 @@ class ElvClient {
1171
1177
  * @namedParams
1172
1178
  * @param {string=} token - The static token to use. If not provided, the default static token will be set.
1173
1179
  */
1174
- SetStaticToken({token}={}) {
1175
- if(!token) {
1176
- token = this.utils.B64(JSON.stringify({qspace_id: this.contentSpaceId}));
1180
+ async SetStaticToken({token}={}) {
1181
+ if(token) {
1182
+ this.staticToken = token;
1183
+ } else {
1184
+ this.CreateFabricToken({duration: 7 * 24 * 60 * 60 * 1000})
1185
+ .then(token => this.staticToken = token);
1177
1186
  }
1178
-
1179
- this.staticToken = token;
1180
1187
  }
1181
1188
 
1182
1189
  /**
@@ -1196,7 +1203,7 @@ class ElvClient {
1196
1203
  * @param {string} objectId - The ID of the policy object
1197
1204
  */
1198
1205
  async SetPolicyAuthorization({objectId}) {
1199
- this.SetStaticToken({
1206
+ await this.SetStaticToken({
1200
1207
  token: await this.GenerateStateChannelToken({objectId})
1201
1208
  });
1202
1209
  }