@eluvio/elv-client-js 3.1.85 → 3.1.87

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.
@@ -218,7 +218,7 @@ function () {
218
218
  break;
219
219
 
220
220
  case 23:
221
- if (!noAuth) {
221
+ if (!(noAuth && this.client.signer && this.client.signer.remoteSigner && this.client.signer.unsignedPublicAuth)) {
222
222
  _context2.next = 25;
223
223
  break;
224
224
  }
@@ -614,24 +614,26 @@ function () {
614
614
  * @param {string=} authToken - Eluvio authorization token previously issued from OAuth ID token
615
615
  * @param {string=} tenantId - If specified, user will be associated with the tenant
616
616
  * @param {Object=} extraData - Additional data to pass to the login API
617
+ * @param {boolean=} unsignedPublicAuth=false - If specified, the client will use an unsigned static token for calls that don't require authorization (reduces remote signature calls)
617
618
  */
618
619
 
619
620
  }, {
620
621
  key: "SetRemoteSigner",
621
622
  value: function SetRemoteSigner(_ref9) {
622
- var idToken, authToken, tenantId, extraData, signer;
623
+ var idToken, authToken, tenantId, extraData, unsignedPublicAuth, signer;
623
624
  return _regeneratorRuntime.async(function SetRemoteSigner$(_context6) {
624
625
  while (1) {
625
626
  switch (_context6.prev = _context6.next) {
626
627
  case 0:
627
- idToken = _ref9.idToken, authToken = _ref9.authToken, tenantId = _ref9.tenantId, extraData = _ref9.extraData;
628
+ idToken = _ref9.idToken, authToken = _ref9.authToken, tenantId = _ref9.tenantId, extraData = _ref9.extraData, unsignedPublicAuth = _ref9.unsignedPublicAuth;
628
629
  signer = new RemoteSigner({
629
630
  rpcUris: this.authServiceURIs,
630
631
  idToken: idToken,
631
632
  authToken: authToken,
632
633
  tenantId: tenantId,
633
634
  provider: this.ethClient.provider,
634
- extraData: extraData
635
+ extraData: extraData,
636
+ unsignedPublicAuth: unsignedPublicAuth
635
637
  });
636
638
  _context6.next = 4;
637
639
  return _regeneratorRuntime.awrap(signer.Initialize());
@@ -34,12 +34,15 @@ function (_Ethers$Signer) {
34
34
  tenantId = _ref.tenantId,
35
35
  provider = _ref.provider,
36
36
  _ref$extraData = _ref.extraData,
37
- extraData = _ref$extraData === void 0 ? {} : _ref$extraData;
37
+ extraData = _ref$extraData === void 0 ? {} : _ref$extraData,
38
+ _ref$unsignedPublicAu = _ref.unsignedPublicAuth,
39
+ unsignedPublicAuth = _ref$unsignedPublicAu === void 0 ? false : _ref$unsignedPublicAu;
38
40
 
39
41
  _classCallCheck(this, RemoteSigner);
40
42
 
41
43
  _this = _possibleConstructorReturn(this, _getPrototypeOf(RemoteSigner).call(this));
42
44
  _this.remoteSigner = true;
45
+ _this.unsignedPublicAuth = unsignedPublicAuth;
43
46
  _this.HttpClient = new HttpClient({
44
47
  uris: rpcUris
45
48
  });
@@ -48,6 +51,7 @@ function (_Ethers$Signer) {
48
51
  _this.authToken = authToken;
49
52
  _this.extraLoginData = extraData || {};
50
53
  _this.provider = provider;
54
+ _this.signatureCache = {};
51
55
  return _this;
52
56
  }
53
57
 
@@ -140,32 +144,55 @@ function (_Ethers$Signer) {
140
144
  }, {
141
145
  key: "signDigest",
142
146
  value: function signDigest(digest) {
143
- var signature;
144
- return _regeneratorRuntime.async(function signDigest$(_context2) {
147
+ var _this2 = this;
148
+
149
+ return _regeneratorRuntime.async(function signDigest$(_context3) {
145
150
  while (1) {
146
- switch (_context2.prev = _context2.next) {
151
+ switch (_context3.prev = _context3.next) {
147
152
  case 0:
148
- _context2.next = 2;
149
- return _regeneratorRuntime.awrap(Utils.ResponseToJson(this.HttpClient.Request({
150
- method: "POST",
151
- path: UrlJoin("as", "wlt", "sign", "eth", this.id),
152
- headers: {
153
- Authorization: "Bearer ".concat(this.authToken)
154
- },
155
- body: {
156
- hash: digest
157
- }
158
- })));
153
+ if (!this.signatureCache[digest]) {
154
+ this.signatureCache[digest] = new Promise(function _callee(resolve) {
155
+ var signature;
156
+ return _regeneratorRuntime.async(function _callee$(_context2) {
157
+ while (1) {
158
+ switch (_context2.prev = _context2.next) {
159
+ case 0:
160
+ _context2.next = 2;
161
+ return _regeneratorRuntime.awrap(Utils.ResponseToJson(_this2.HttpClient.Request({
162
+ method: "POST",
163
+ path: UrlJoin("as", "wlt", "sign", "eth", _this2.id),
164
+ headers: {
165
+ Authorization: "Bearer ".concat(_this2.authToken)
166
+ },
167
+ body: {
168
+ hash: digest
169
+ }
170
+ })));
171
+
172
+ case 2:
173
+ signature = _context2.sent;
174
+ signature.v = parseInt(signature.v, 16);
175
+ signature.recoveryParam = signature.v - 27;
176
+ resolve(signature);
177
+
178
+ case 6:
179
+ case "end":
180
+ return _context2.stop();
181
+ }
182
+ }
183
+ });
184
+ });
185
+ }
159
186
 
160
- case 2:
161
- signature = _context2.sent;
162
- signature.v = parseInt(signature.v, 16);
163
- signature.recoveryParam = signature.v - 27;
164
- return _context2.abrupt("return", signature);
187
+ _context3.next = 3;
188
+ return _regeneratorRuntime.awrap(this.signatureCache[digest]);
165
189
 
166
- case 6:
190
+ case 3:
191
+ return _context3.abrupt("return", _context3.sent);
192
+
193
+ case 4:
167
194
  case "end":
168
- return _context2.stop();
195
+ return _context3.stop();
169
196
  }
170
197
  }
171
198
  }, null, this);
@@ -173,25 +200,25 @@ function (_Ethers$Signer) {
173
200
  }, {
174
201
  key: "signMessage",
175
202
  value: function signMessage(message) {
176
- return _regeneratorRuntime.async(function signMessage$(_context3) {
203
+ return _regeneratorRuntime.async(function signMessage$(_context4) {
177
204
  while (1) {
178
- switch (_context3.prev = _context3.next) {
205
+ switch (_context4.prev = _context4.next) {
179
206
  case 0:
180
- _context3.t0 = Promise;
181
- _context3.t1 = Ethers.utils;
182
- _context3.t2 = "0x";
183
- _context3.next = 5;
207
+ _context4.t0 = Promise;
208
+ _context4.t1 = Ethers.utils;
209
+ _context4.t2 = "0x";
210
+ _context4.next = 5;
184
211
  return _regeneratorRuntime.awrap(this.signDigest(Ethers.utils.hashMessage(message)));
185
212
 
186
213
  case 5:
187
- _context3.t3 = _context3.sent;
188
- _context3.t4 = _context3.t2.concat.call(_context3.t2, _context3.t3);
189
- _context3.t5 = _context3.t1.joinSignature.call(_context3.t1, _context3.t4);
190
- return _context3.abrupt("return", _context3.t0.resolve.call(_context3.t0, _context3.t5));
214
+ _context4.t3 = _context4.sent;
215
+ _context4.t4 = _context4.t2.concat.call(_context4.t2, _context4.t3);
216
+ _context4.t5 = _context4.t1.joinSignature.call(_context4.t1, _context4.t4);
217
+ return _context4.abrupt("return", _context4.t0.resolve.call(_context4.t0, _context4.t5));
191
218
 
192
219
  case 9:
193
220
  case "end":
194
- return _context3.stop();
221
+ return _context4.stop();
195
222
  }
196
223
  }
197
224
  }, null, this);
@@ -200,25 +227,25 @@ function (_Ethers$Signer) {
200
227
  key: "sign",
201
228
  value: function sign(transaction) {
202
229
  var signature;
203
- return _regeneratorRuntime.async(function sign$(_context4) {
230
+ return _regeneratorRuntime.async(function sign$(_context5) {
204
231
  while (1) {
205
- switch (_context4.prev = _context4.next) {
232
+ switch (_context5.prev = _context5.next) {
206
233
  case 0:
207
- _context4.next = 2;
234
+ _context5.next = 2;
208
235
  return _regeneratorRuntime.awrap(Ethers.utils.resolveProperties(transaction));
209
236
 
210
237
  case 2:
211
- transaction = _context4.sent;
212
- _context4.next = 5;
238
+ transaction = _context5.sent;
239
+ _context5.next = 5;
213
240
  return _regeneratorRuntime.awrap(this.signDigest(Ethers.utils.keccak256(Ethers.utils.serializeTransaction(transaction))));
214
241
 
215
242
  case 5:
216
- signature = _context4.sent;
217
- return _context4.abrupt("return", Ethers.utils.serializeTransaction(transaction, signature));
243
+ signature = _context5.sent;
244
+ return _context5.abrupt("return", Ethers.utils.serializeTransaction(transaction, signature));
218
245
 
219
246
  case 7:
220
247
  case "end":
221
- return _context4.stop();
248
+ return _context5.stop();
222
249
  }
223
250
  }
224
251
  }, null, this);
@@ -226,34 +253,34 @@ function (_Ethers$Signer) {
226
253
  }, {
227
254
  key: "sendTransaction",
228
255
  value: function sendTransaction(transaction) {
229
- var _this2 = this;
256
+ var _this3 = this;
230
257
 
231
- return _regeneratorRuntime.async(function sendTransaction$(_context5) {
258
+ return _regeneratorRuntime.async(function sendTransaction$(_context6) {
232
259
  while (1) {
233
- switch (_context5.prev = _context5.next) {
260
+ switch (_context6.prev = _context6.next) {
234
261
  case 0:
235
262
  if (!(transaction.nonce == null)) {
236
- _context5.next = 5;
263
+ _context6.next = 5;
237
264
  break;
238
265
  }
239
266
 
240
267
  transaction = Ethers.utils.shallowCopy(transaction);
241
- _context5.next = 4;
268
+ _context6.next = 4;
242
269
  return _regeneratorRuntime.awrap(this.provider.getTransactionCount(this.address, "pending"));
243
270
 
244
271
  case 4:
245
- transaction.nonce = _context5.sent;
272
+ transaction.nonce = _context6.sent;
246
273
 
247
274
  case 5:
248
- return _context5.abrupt("return", Ethers.utils.populateTransaction(transaction, this.provider, this.address).then(function (tx) {
249
- return _this2.sign(tx).then(function (signedTransaction) {
250
- return _this2.provider.sendTransaction(signedTransaction);
275
+ return _context6.abrupt("return", Ethers.utils.populateTransaction(transaction, this.provider, this.address).then(function (tx) {
276
+ return _this3.sign(tx).then(function (signedTransaction) {
277
+ return _this3.provider.sendTransaction(signedTransaction);
251
278
  });
252
279
  }));
253
280
 
254
281
  case 6:
255
282
  case "end":
256
- return _context5.stop();
283
+ return _context6.stop();
257
284
  }
258
285
  }
259
286
  }, null, this);
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "3.1.85",
3
+ "version": "3.1.87",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "3.1.85",
3
+ "version": "3.1.87",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/ElvClient.js",
6
6
  "author": "Kevin Talmadge",
@@ -160,7 +160,7 @@ class AuthorizationClient {
160
160
  oauthToken
161
161
  });
162
162
  } else {
163
- if(noAuth) {
163
+ if(noAuth && this.client.signer && this.client.signer.remoteSigner && this.client.signer.unsignedPublicAuth) {
164
164
  return this.CreateStaticToken({libraryId});
165
165
  }
166
166
 
package/src/ElvClient.js CHANGED
@@ -598,15 +598,17 @@ class ElvClient {
598
598
  * @param {string=} authToken - Eluvio authorization token previously issued from OAuth ID token
599
599
  * @param {string=} tenantId - If specified, user will be associated with the tenant
600
600
  * @param {Object=} extraData - Additional data to pass to the login API
601
+ * @param {boolean=} unsignedPublicAuth=false - If specified, the client will use an unsigned static token for calls that don't require authorization (reduces remote signature calls)
601
602
  */
602
- async SetRemoteSigner({idToken, authToken, tenantId, extraData}) {
603
+ async SetRemoteSigner({idToken, authToken, tenantId, extraData, unsignedPublicAuth}) {
603
604
  const signer = new RemoteSigner({
604
605
  rpcUris: this.authServiceURIs,
605
606
  idToken,
606
607
  authToken,
607
608
  tenantId,
608
609
  provider: this.ethClient.provider,
609
- extraData
610
+ extraData,
611
+ unsignedPublicAuth
610
612
  });
611
613
 
612
614
  await signer.Initialize();
@@ -10,11 +10,13 @@ class RemoteSigner extends Ethers.Signer {
10
10
  authToken,
11
11
  tenantId,
12
12
  provider,
13
- extraData={}
13
+ extraData={},
14
+ unsignedPublicAuth=false
14
15
  }) {
15
16
  super();
16
17
 
17
18
  this.remoteSigner = true;
19
+ this.unsignedPublicAuth = unsignedPublicAuth;
18
20
 
19
21
  this.HttpClient = new HttpClient({uris: rpcUris});
20
22
  this.idToken = idToken;
@@ -24,6 +26,8 @@ class RemoteSigner extends Ethers.Signer {
24
26
  this.extraLoginData = extraData || {};
25
27
 
26
28
  this.provider = provider;
29
+
30
+ this.signatureCache = {};
27
31
  }
28
32
 
29
33
  async Initialize() {
@@ -80,23 +84,29 @@ class RemoteSigner extends Ethers.Signer {
80
84
  * @returns - the signed message as a hex string
81
85
  */
82
86
  async signDigest(digest) {
83
- let signature = await Utils.ResponseToJson(
84
- this.HttpClient.Request({
85
- method: "POST",
86
- path: UrlJoin("as", "wlt", "sign", "eth", this.id),
87
- headers: {
88
- Authorization: `Bearer ${this.authToken}`
89
- },
90
- body: {
91
- hash: digest
92
- }
93
- })
94
- );
95
-
96
- signature.v = parseInt(signature.v, 16);
97
- signature.recoveryParam = signature.v - 27;
87
+ if(!this.signatureCache[digest]) {
88
+ this.signatureCache[digest] = new Promise(async resolve => {
89
+ let signature = await Utils.ResponseToJson(
90
+ this.HttpClient.Request({
91
+ method: "POST",
92
+ path: UrlJoin("as", "wlt", "sign", "eth", this.id),
93
+ headers: {
94
+ Authorization: `Bearer ${this.authToken}`
95
+ },
96
+ body: {
97
+ hash: digest
98
+ }
99
+ })
100
+ );
101
+
102
+ signature.v = parseInt(signature.v, 16);
103
+ signature.recoveryParam = signature.v - 27;
104
+
105
+ resolve(signature);
106
+ });
107
+ }
98
108
 
99
- return signature;
109
+ return await this.signatureCache[digest];
100
110
  }
101
111
 
102
112
  async signMessage(message) {