@eluvio/elv-client-js 4.2.8 → 4.2.9

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.2.8",
3
+ "version": "4.2.9",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
@@ -73,15 +73,18 @@ class RemoteSigner extends Ethers.Signer {
73
73
  this.signer = this.provider.getSigner(this.address);
74
74
  }
75
75
 
76
- async RetrieveCSAT({email, nonce, tenantId, force=false, duration=24}) {
77
- nonce = nonce || Utils.B58(UUID.parse(UUID.v4()));
76
+ async RetrieveCSAT({email, nonce, installId, tenantId, force=false, duration=24}) {
77
+ if(nonce && !installId) {
78
+ const buf = await crypto.subtle.digest("SHA-512", new TextEncoder("utf-8").encode(nonce));
79
+ installId = Array.prototype.map.call(new Uint8Array(buf), x=>(("00"+x.toString(16)).slice(-2))).join("");
80
+ }
78
81
 
79
82
  let response = await Utils.ResponseToJson(
80
83
  this.HttpClient.Request({
81
84
  method: "POST",
82
85
  body: {
83
86
  email,
84
- nonce,
87
+ install_id: installId,
85
88
  force,
86
89
  tid: tenantId,
87
90
  exp: parseInt(duration * 60 * 60)
@@ -94,6 +97,7 @@ class RemoteSigner extends Ethers.Signer {
94
97
  );
95
98
 
96
99
  response.nonce = nonce;
100
+ response.installId = installId;
97
101
 
98
102
  return response;
99
103
  }
@@ -128,6 +132,23 @@ class RemoteSigner extends Ethers.Signer {
128
132
  );
129
133
  }
130
134
 
135
+ async RefreshCSAT({accessToken, refreshToken, nonce}) {
136
+ return await Utils.ResponseToJson(
137
+ this.HttpClient.Request({
138
+ method: "POST",
139
+ path: UrlJoin("as", "wlt", "refresh", "csat"),
140
+ body: {
141
+ last_csat: accessToken,
142
+ refresh_token: refreshToken,
143
+ nonce
144
+ },
145
+ headers: {
146
+ Authorization: `Bearer ${accessToken}`
147
+ },
148
+ })
149
+ );
150
+ }
151
+
131
152
  // Overrides
132
153
 
133
154
  getAddress() {
@@ -396,7 +396,7 @@ class ElvWalletClient {
396
396
  * @methodGroup Login
397
397
  */
398
398
  async LogOut() {
399
- if(this.__authorization && this.__authorization.nonce) {
399
+ if(this.__authorization && (this.__authorization.nonce || this.__authorization.installId)) {
400
400
  try {
401
401
  await this.client.signer.ReleaseCSAT({accessToken: this.AuthToken()});
402
402
  } catch(error) {
@@ -419,7 +419,7 @@ class ElvWalletClient {
419
419
  }
420
420
 
421
421
  async TokenStatus() {
422
- if(!this.__authorization || !this.__authorization.nonce) {
422
+ if(!this.__authorization || !(this.__authorization.nonce || this.__authorization.installId)) {
423
423
  return true;
424
424
  }
425
425
 
@@ -482,6 +482,7 @@ class ElvWalletClient {
482
482
  shareEmail=false,
483
483
  extraData={},
484
484
  nonce,
485
+ installId,
485
486
  createRemoteToken=true,
486
487
  force=false,
487
488
  tokenDuration=24
@@ -497,9 +498,10 @@ class ElvWalletClient {
497
498
  let fabricToken, refreshToken, expiresAt;
498
499
  if(createRemoteToken && this.client.signer.remoteSigner) {
499
500
  expiresAt = Date.now() + tokenDuration * 60 * 60 * 1000;
500
- const tokenResponse = await this.client.signer.RetrieveCSAT({email, nonce, tenantId, force, duration: tokenDuration});
501
+ const tokenResponse = await this.client.signer.RetrieveCSAT({email, nonce, installId, tenantId, force, duration: tokenDuration});
501
502
  fabricToken = tokenResponse.token;
502
- nonce = tokenResponse.nonce;
503
+ nonce = tokenResponse.nonce || nonce;
504
+ installId = tokenResponse.installId || installId;
503
505
  refreshToken = tokenResponse.refresh_token;
504
506
  } else {
505
507
  expiresAt = Date.now() + tokenDuration * 60 * 60 * 1000;
@@ -533,7 +535,8 @@ class ElvWalletClient {
533
535
  walletType: "Custodial",
534
536
  walletName: "Eluvio",
535
537
  register: true,
536
- nonce
538
+ nonce,
539
+ installId
537
540
  }),
538
541
  signingToken: this.SetAuthorization({
539
542
  clusterToken: this.client.signer.authToken,
@@ -546,7 +549,8 @@ class ElvWalletClient {
546
549
  signerURIs,
547
550
  walletType: "Custodial",
548
551
  walletName: "Eluvio",
549
- nonce
552
+ nonce,
553
+ installId
550
554
  })
551
555
  };
552
556
  }
@@ -607,7 +611,7 @@ class ElvWalletClient {
607
611
  return this.__authorization.fabricToken;
608
612
  }
609
613
 
610
- SetAuthorization({clusterToken, fabricToken, refreshToken, tenantId, address, email, expiresAt, signerURIs, walletType, walletName, nonce, register=false}) {
614
+ SetAuthorization({clusterToken, fabricToken, refreshToken, tenantId, address, email, expiresAt, signerURIs, walletType, walletName, nonce, installId, register=false}) {
611
615
  address = this.client.utils.FormatAddress(address);
612
616
 
613
617
  this.__authorization = {
@@ -619,7 +623,8 @@ class ElvWalletClient {
619
623
  expiresAt,
620
624
  walletType,
621
625
  walletName,
622
- nonce
626
+ nonce,
627
+ installId
623
628
  };
624
629
 
625
630
  if(clusterToken) {