@getpara/core-sdk 2.0.0-dev.6 → 2.0.0-dev.7

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.
@@ -58,7 +58,13 @@ class EnclaveClient {
58
58
  }
59
59
  refreshJwt() {
60
60
  return __async(this, null, function* () {
61
- const encryptedPayload = yield this.encryptForEnclave(JSON.stringify({ refreshJwt: this.retrieveRefreshJwt() }));
61
+ const frontendKeyPair = yield this.generateFrontendKeyPair();
62
+ const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
63
+ const payload = {
64
+ refreshJwt: this.retrieveRefreshJwt(),
65
+ responsePublicKey: responsePublicKeyPEM
66
+ };
67
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
62
68
  const response = yield this.userManagementClient.refreshEnclaveJwt(JSON.stringify(encryptedPayload));
63
69
  const decryptedResponse = yield this.decryptForFrontend(JSON.parse(response.payload));
64
70
  this.persistJwt(decryptedResponse.jwt);
@@ -75,6 +81,21 @@ class EnclaveClient {
75
81
  }
76
82
  });
77
83
  }
84
+ issueEnclaveJwt() {
85
+ return __async(this, null, function* () {
86
+ const frontendKeyPair = yield this.generateFrontendKeyPair();
87
+ const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
88
+ const payload = {
89
+ responsePublicKey: responsePublicKeyPEM
90
+ };
91
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
92
+ const response = yield this.userManagementClient.issueEnclaveJwt(JSON.stringify(encryptedPayload));
93
+ console.log(JSON.parse(response));
94
+ const decryptedResponse = yield this.decryptForFrontend(JSON.parse(response));
95
+ console.log("decryptedResponse", decryptedResponse);
96
+ this.persistJwt(decryptedResponse.jwt);
97
+ });
98
+ }
78
99
  /**
79
100
  * Generate a P-256 keypair for the frontend to receive encrypted responses
80
101
  */
@@ -212,8 +233,7 @@ ${exportedAsBase64}
212
233
  */
213
234
  retrieveShares(query) {
214
235
  return __async(this, null, function* () {
215
- console.log("retrieveShares about to call generateFrontendKeyPair");
216
- console.log("query", query);
236
+ yield this.issueEnclaveJwt();
217
237
  const frontendKeyPair = yield this.generateFrontendKeyPair();
218
238
  const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
219
239
  const fullQuery = query.map((q) => ({
@@ -227,9 +247,7 @@ ${exportedAsBase64}
227
247
  const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
228
248
  const encryptedPayloadStr = JSON.stringify(encryptedPayload);
229
249
  const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
230
- console.log("retrieveShares response", response);
231
250
  const encryptedResponse = JSON.parse(response.payload);
232
- console.log("retrieveShares encryptedResponse", encryptedResponse);
233
251
  const decryptedData = yield this.decryptForFrontend(encryptedResponse);
234
252
  console.log("retrieveShares decryptedData", decryptedData);
235
253
  return decryptedData;
@@ -19,7 +19,13 @@ class EnclaveClient {
19
19
  }
20
20
  refreshJwt() {
21
21
  return __async(this, null, function* () {
22
- const encryptedPayload = yield this.encryptForEnclave(JSON.stringify({ refreshJwt: this.retrieveRefreshJwt() }));
22
+ const frontendKeyPair = yield this.generateFrontendKeyPair();
23
+ const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
24
+ const payload = {
25
+ refreshJwt: this.retrieveRefreshJwt(),
26
+ responsePublicKey: responsePublicKeyPEM
27
+ };
28
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
23
29
  const response = yield this.userManagementClient.refreshEnclaveJwt(JSON.stringify(encryptedPayload));
24
30
  const decryptedResponse = yield this.decryptForFrontend(JSON.parse(response.payload));
25
31
  this.persistJwt(decryptedResponse.jwt);
@@ -36,6 +42,21 @@ class EnclaveClient {
36
42
  }
37
43
  });
38
44
  }
45
+ issueEnclaveJwt() {
46
+ return __async(this, null, function* () {
47
+ const frontendKeyPair = yield this.generateFrontendKeyPair();
48
+ const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
49
+ const payload = {
50
+ responsePublicKey: responsePublicKeyPEM
51
+ };
52
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
53
+ const response = yield this.userManagementClient.issueEnclaveJwt(JSON.stringify(encryptedPayload));
54
+ console.log(JSON.parse(response));
55
+ const decryptedResponse = yield this.decryptForFrontend(JSON.parse(response));
56
+ console.log("decryptedResponse", decryptedResponse);
57
+ this.persistJwt(decryptedResponse.jwt);
58
+ });
59
+ }
39
60
  /**
40
61
  * Generate a P-256 keypair for the frontend to receive encrypted responses
41
62
  */
@@ -173,8 +194,7 @@ ${exportedAsBase64}
173
194
  */
174
195
  retrieveShares(query) {
175
196
  return __async(this, null, function* () {
176
- console.log("retrieveShares about to call generateFrontendKeyPair");
177
- console.log("query", query);
197
+ yield this.issueEnclaveJwt();
178
198
  const frontendKeyPair = yield this.generateFrontendKeyPair();
179
199
  const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
180
200
  const fullQuery = query.map((q) => ({
@@ -188,9 +208,7 @@ ${exportedAsBase64}
188
208
  const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
189
209
  const encryptedPayloadStr = JSON.stringify(encryptedPayload);
190
210
  const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
191
- console.log("retrieveShares response", response);
192
211
  const encryptedResponse = JSON.parse(response.payload);
193
- console.log("retrieveShares encryptedResponse", encryptedResponse);
194
212
  const decryptedData = yield this.decryptForFrontend(encryptedResponse);
195
213
  console.log("retrieveShares decryptedData", decryptedData);
196
214
  return decryptedData;
@@ -41,6 +41,7 @@ export declare class EnclaveClient {
41
41
  });
42
42
  private refreshJwt;
43
43
  private withJwtRefreshRetry;
44
+ private issueEnclaveJwt;
44
45
  /**
45
46
  * Generate a P-256 keypair for the frontend to receive encrypted responses
46
47
  */
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@getpara/core-sdk",
3
- "version": "2.0.0-dev.6",
3
+ "version": "2.0.0-dev.7",
4
4
  "dependencies": {
5
5
  "@celo/utils": "^8.0.2",
6
6
  "@cosmjs/encoding": "^0.32.4",
7
7
  "@ethereumjs/util": "^9.1.0",
8
- "@getpara/user-management-client": "2.0.0-dev.6",
8
+ "@getpara/user-management-client": "2.0.0-dev.7",
9
9
  "@noble/hashes": "^1.5.0",
10
10
  "base64url": "^3.0.1",
11
11
  "libphonenumber-js": "^1.11.7",
@@ -27,7 +27,7 @@
27
27
  "dist",
28
28
  "package.json"
29
29
  ],
30
- "gitHead": "c2125e37c73a19f11978031f5aa2eab39b978c56",
30
+ "gitHead": "225cd3693edaab4dac81df7285956d2616e5717f",
31
31
  "main": "dist/cjs/index.js",
32
32
  "module": "dist/esm/index.js",
33
33
  "scripts": {