@tdxvolt/volt-client-grpc 0.14.134 → 0.15.1

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.
@@ -36,7 +36,7 @@ export class VoltCredential {
36
36
  // Need to unencrypt the private key.
37
37
  const decrypted = pki.decryptRsaPrivateKey(
38
38
  this._cryptoCache.key,
39
- config.p,
39
+ config.p
40
40
  );
41
41
  if (!decrypted) {
42
42
  throw new Error("failed to decrypt key - check passphrase");
@@ -56,7 +56,7 @@ export class VoltCredential {
56
56
  // Extract Volt public key (used for encrypting Relay payloads).
57
57
  this._voltPublicKey = forge.pki.publicKeyToPem(voltCert.publicKey);
58
58
  this._voltFingerprint = voltUtils.createPublicKeyFingerprint(
59
- this._voltPublicKey,
59
+ this._voltPublicKey
60
60
  );
61
61
  }
62
62
  }
@@ -101,19 +101,17 @@ export class VoltCredential {
101
101
  return Promise.resolve(this.getKey());
102
102
  } else {
103
103
  log("creating key");
104
- return new Promise((resolve, reject) => {
105
- pki.rsa.generateKeyPair({ bits: 2048, workers: -1 }, (err, keypair) => {
106
- if (err) {
107
- log("failure creating key [%s]", err.message);
108
- reject(err);
109
- } else {
110
- log("successfully created key");
111
- const pem = pki.privateKeyToPem(keypair.privateKey);
112
- this._cryptoCache.key = pem;
113
- resolve(keypair);
114
- }
104
+ return voltUtils
105
+ .createRSAKey()
106
+ .then((keyInfo) => {
107
+ log("successfully created key");
108
+ this._cryptoCache.key = keyInfo.pem;
109
+ return keyInfo.keypair;
110
+ })
111
+ .catch((err) => {
112
+ log("failure creating key [%s]", err.message);
113
+ return Promise.reject(err);
115
114
  });
116
- });
117
115
  }
118
116
  }
119
117
 
@@ -161,7 +159,7 @@ export class VoltCredential {
161
159
  aud: audience,
162
160
  iat: Math.floor(Date.now() / 1000) - ttl,
163
161
  exp: Math.floor(Date.now() / 1000) + ttl,
164
- sub: this._cryptoCache.client_id,
162
+ sub: this._cryptoCache.client_id
165
163
  };
166
164
 
167
165
  let sharedKey;
@@ -177,13 +175,13 @@ export class VoltCredential {
177
175
  // Sign synchronously.
178
176
  const token = jwt.sign(payload, this._cryptoCache.key, {
179
177
  algorithm: rs256Algorithm,
180
- keyid: base58Key,
178
+ keyid: base58Key
181
179
  });
182
180
 
183
181
  // Return the token along with any encryption key details.
184
182
  return {
185
183
  token,
186
- sharedKey,
184
+ sharedKey
187
185
  };
188
186
  }
189
187
 
@@ -201,7 +199,7 @@ export class VoltCredential {
201
199
  audience || this._voltConfig.id,
202
200
  publicKey,
203
201
  tunnelling,
204
- ttl,
202
+ ttl
205
203
  );
206
204
  const metadata = new grpc.Metadata();
207
205
  metadata.add(constants.authTokenName, identityToken.token);
@@ -216,7 +214,7 @@ export class VoltCredential {
216
214
  const privateKey = pki.privateKeyFromPem(this._cryptoCache.key);
217
215
  clone.credential.key = pki.encryptRsaPrivateKey(
218
216
  privateKey,
219
- this._config.p,
217
+ this._config.p
220
218
  );
221
219
  }
222
220
  fs.writeFileSync(this._configPath, JSON.stringify(clone, null, 2));