@getpara/core-sdk 2.0.0-fc.2 → 2.0.0

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.
Files changed (60) hide show
  1. package/dist/cjs/ParaCore.js +1111 -316
  2. package/dist/cjs/constants.js +10 -1
  3. package/dist/cjs/index.js +23 -3
  4. package/dist/cjs/shares/KeyContainer.js +3 -3
  5. package/dist/cjs/shares/enclave.js +287 -0
  6. package/dist/cjs/shares/shareDistribution.js +16 -1
  7. package/dist/cjs/transmission/transmissionUtils.js +4 -3
  8. package/dist/cjs/types/{theme.js → assets.js} +2 -2
  9. package/dist/cjs/types/coreApi.js +7 -2
  10. package/dist/cjs/types/events.js +2 -0
  11. package/dist/cjs/types/index.js +0 -21
  12. package/dist/cjs/types/popup.js +1 -0
  13. package/dist/cjs/utils/config.js +108 -0
  14. package/dist/cjs/utils/index.js +5 -1
  15. package/dist/cjs/utils/onRamps.js +2 -3
  16. package/dist/cjs/utils/wallet.js +18 -0
  17. package/dist/cjs/{types/onRamps.js → utils/window.js} +17 -12
  18. package/dist/esm/ParaCore.js +1115 -320
  19. package/dist/esm/constants.js +7 -1
  20. package/dist/esm/index.js +24 -5
  21. package/dist/esm/shares/KeyContainer.js +3 -3
  22. package/dist/esm/shares/enclave.js +247 -0
  23. package/dist/esm/shares/shareDistribution.js +16 -1
  24. package/dist/esm/transmission/transmissionUtils.js +4 -3
  25. package/dist/esm/types/coreApi.js +7 -2
  26. package/dist/esm/types/events.js +2 -0
  27. package/dist/esm/types/index.js +0 -16
  28. package/dist/esm/types/popup.js +1 -0
  29. package/dist/esm/utils/config.js +86 -0
  30. package/dist/esm/utils/index.js +2 -0
  31. package/dist/esm/utils/onRamps.js +2 -3
  32. package/dist/esm/utils/wallet.js +17 -0
  33. package/dist/esm/utils/window.js +16 -0
  34. package/dist/types/ParaCore.d.ts +90 -19
  35. package/dist/types/PlatformUtils.d.ts +2 -1
  36. package/dist/types/constants.d.ts +3 -0
  37. package/dist/types/index.d.ts +6 -4
  38. package/dist/types/shares/enclave.d.ts +83 -0
  39. package/dist/types/shares/shareDistribution.d.ts +4 -2
  40. package/dist/types/types/assets.d.ts +14 -0
  41. package/dist/types/types/config.d.ts +3 -2
  42. package/dist/types/types/coreApi.d.ts +47 -7
  43. package/dist/types/types/events.d.ts +7 -2
  44. package/dist/types/types/index.d.ts +0 -4
  45. package/dist/types/types/methods.d.ts +56 -12
  46. package/dist/types/types/popup.d.ts +2 -1
  47. package/dist/types/types/wallet.d.ts +8 -4
  48. package/dist/types/utils/config.d.ts +7 -0
  49. package/dist/types/utils/index.d.ts +2 -0
  50. package/dist/types/utils/onRamps.d.ts +9 -10
  51. package/dist/types/utils/wallet.d.ts +1 -0
  52. package/dist/types/utils/window.d.ts +2 -0
  53. package/package.json +3 -3
  54. package/dist/cjs/types/recovery.js +0 -34
  55. package/dist/esm/types/onRamps.js +0 -11
  56. package/dist/esm/types/recovery.js +0 -12
  57. package/dist/types/types/onRamps.d.ts +0 -10
  58. package/dist/types/types/recovery.d.ts +0 -7
  59. package/dist/types/types/theme.d.ts +0 -12
  60. /package/dist/esm/types/{theme.js → assets.js} +0 -0
@@ -1,6 +1,7 @@
1
1
  import "./chunk-7B52C2XE.js";
2
- const PARA_CORE_VERSION = "2.0.0-fc.1";
2
+ const PARA_CORE_VERSION = "2.0.0";
3
3
  const PREFIX = "@CAPSULE/";
4
+ const PARA_PREFIX = "@PARA/";
4
5
  const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
5
6
  const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
6
7
  const LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
@@ -14,6 +15,8 @@ const LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
14
15
  const LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
15
16
  const LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
16
17
  const LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
18
+ const LOCAL_STORAGE_ENCLAVE_JWT = `${PREFIX}enclaveJwt`;
19
+ const LOCAL_STORAGE_ENCLAVE_REFRESH_JWT = `${PREFIX}enclaveRefreshJwt`;
17
20
  const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
18
21
  const POLLING_INTERVAL_MS = 2e3;
19
22
  const SHORT_POLLING_INTERVAL_MS = 1e3;
@@ -28,6 +31,8 @@ export {
28
31
  LOCAL_STORAGE_CURRENT_WALLET_IDS,
29
32
  LOCAL_STORAGE_ED25519_WALLETS,
30
33
  LOCAL_STORAGE_EMAIL,
34
+ LOCAL_STORAGE_ENCLAVE_JWT,
35
+ LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
31
36
  LOCAL_STORAGE_EXTERNAL_WALLETS,
32
37
  LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID,
33
38
  LOCAL_STORAGE_FARCASTER_USERNAME,
@@ -37,6 +42,7 @@ export {
37
42
  LOCAL_STORAGE_USER_ID,
38
43
  LOCAL_STORAGE_WALLETS,
39
44
  PARA_CORE_VERSION,
45
+ PARA_PREFIX,
40
46
  POLLING_INTERVAL_MS,
41
47
  POLLING_TIMEOUT_MS,
42
48
  PREFIX,
package/dist/esm/index.js CHANGED
@@ -2,6 +2,7 @@ import "./chunk-7B52C2XE.js";
2
2
  import { ParaCore } from "./ParaCore.js";
3
3
  import {
4
4
  AuthMethod,
5
+ AuthMethodStatus,
5
6
  EmailTheme,
6
7
  Network,
7
8
  WalletType,
@@ -10,7 +11,10 @@ import {
10
11
  OnRampPurchaseType,
11
12
  OnRampProvider,
12
13
  OnRampPurchaseStatus,
14
+ OnRampMethod,
13
15
  OAuthMethod,
16
+ RecoveryStatus,
17
+ ThemeMode,
14
18
  NON_ED25519,
15
19
  PREGEN_IDENTIFIER_TYPES,
16
20
  WALLET_TYPES,
@@ -20,20 +24,25 @@ import {
20
24
  EXTERNAL_WALLET_TYPES,
21
25
  EVM_WALLETS,
22
26
  SOLANA_WALLETS,
23
- COSMOS_WALLETS
27
+ COSMOS_WALLETS,
28
+ formatAssetQuantity,
29
+ formatCurrency
24
30
  } from "@getpara/user-management-client";
25
31
  import {
26
- OnRampMethod,
27
32
  PopupType,
28
33
  PregenIdentifierType,
29
- RecoveryStatus,
30
34
  AccountLinkError
31
35
  } from "./types/index.js";
32
36
  export * from "./types/coreApi.js";
33
37
  export * from "./types/events.js";
34
38
  export * from "./types/config.js";
35
- import { getPortalDomain, entityToWallet, constructUrl, shortenUrl } from "./utils/index.js";
36
- import { PREFIX } from "./constants.js";
39
+ import { getPortalDomain, dispatchEvent, entityToWallet, constructUrl, shortenUrl, isPortal } from "./utils/index.js";
40
+ import {
41
+ PREFIX,
42
+ PARA_PREFIX,
43
+ LOCAL_STORAGE_CURRENT_WALLET_IDS,
44
+ LOCAL_STORAGE_WALLETS
45
+ } from "./constants.js";
37
46
  import { distributeNewShare } from "./shares/shareDistribution.js";
38
47
  import { KeyContainer } from "./shares/KeyContainer.js";
39
48
  import { getBaseUrl, initClient } from "./external/userManagementClient.js";
@@ -61,6 +70,7 @@ export * from "./errors.js";
61
70
  export * from "./utils/formatting.js";
62
71
  export * from "./utils/polling.js";
63
72
  export * from "./utils/phone.js";
73
+ export * from "./utils/config.js";
64
74
  import { isWalletSupported } from "./utils/wallet.js";
65
75
  import { getNetworkPrefix, getOnRampAssets, getOnRampNetworks, toAssetInfoArray } from "./utils/onRamps.js";
66
76
  import { getPortalBaseURL } from "./utils/url.js";
@@ -70,12 +80,15 @@ var src_default = ParaCore;
70
80
  export {
71
81
  AccountLinkError,
72
82
  AuthMethod,
83
+ AuthMethodStatus,
73
84
  COSMOS_WALLETS,
74
85
  EVM_WALLETS,
75
86
  EXTERNAL_WALLET_TYPES,
76
87
  EmailTheme,
77
88
  KeyContainer,
78
89
  LINKED_ACCOUNT_TYPES,
90
+ LOCAL_STORAGE_CURRENT_WALLET_IDS,
91
+ LOCAL_STORAGE_WALLETS,
79
92
  NON_ED25519,
80
93
  Network,
81
94
  OAUTH_METHODS,
@@ -85,12 +98,14 @@ export {
85
98
  OnRampProvider,
86
99
  OnRampPurchaseStatus,
87
100
  OnRampPurchaseType,
101
+ PARA_PREFIX as PARA_STORAGE_PREFIX,
88
102
  PREGEN_IDENTIFIER_TYPES,
89
103
  PopupType,
90
104
  PregenIdentifierType,
91
105
  RecoveryStatus,
92
106
  SOLANA_WALLETS,
93
107
  PREFIX as STORAGE_PREFIX,
108
+ ThemeMode,
94
109
  WALLET_SCHEMES,
95
110
  WALLET_TYPES,
96
111
  WalletScheme,
@@ -102,12 +117,15 @@ export {
102
117
  decryptWithKeyPair,
103
118
  decryptWithPrivateKey,
104
119
  src_default as default,
120
+ dispatchEvent,
105
121
  distributeNewShare,
106
122
  encodePrivateKeyToPemHex,
107
123
  encryptPrivateKey,
108
124
  encryptPrivateKeyWithPassword,
109
125
  encryptWithDerivedPublicKey,
110
126
  entityToWallet,
127
+ formatAssetQuantity,
128
+ formatCurrency,
111
129
  getAsymmetricKeyPair,
112
130
  getBaseUrl,
113
131
  getDerivedPrivateKeyAndDecrypt,
@@ -121,6 +139,7 @@ export {
121
139
  getSHA256HashHex,
122
140
  hashPasswordWithSalt,
123
141
  initClient,
142
+ isPortal,
124
143
  isWalletSupported,
125
144
  mpcComputationClient,
126
145
  paraVersion,
@@ -30,7 +30,7 @@ class KeyContainer {
30
30
  const pubkey = this.getPublicEncryptionKey();
31
31
  const data = ECIESEncrypt(pubkey, Buffer.from(backup, "ucs2")).toString("base64");
32
32
  return data;
33
- } catch (error) {
33
+ } catch (e) {
34
34
  throw Error("Error encrypting backup");
35
35
  }
36
36
  }
@@ -38,7 +38,7 @@ class KeyContainer {
38
38
  try {
39
39
  const data = ECIESEncrypt(publicKey, Buffer.from(backup, "ucs2")).toString("base64");
40
40
  return data;
41
- } catch (error) {
41
+ } catch (e) {
42
42
  throw Error("Error encrypting backup");
43
43
  }
44
44
  }
@@ -47,7 +47,7 @@ class KeyContainer {
47
47
  const buf = Buffer.from(encryptedBackup, "base64");
48
48
  const data = ECIESDecrypt(Buffer.from(this.backupDecryptionKey, "hex"), buf);
49
49
  return Buffer.from(data.buffer).toString("ucs2");
50
- } catch (error) {
50
+ } catch (e) {
51
51
  throw Error("Error decrypting backup");
52
52
  }
53
53
  }
@@ -0,0 +1,247 @@
1
+ import {
2
+ __async
3
+ } from "../chunk-7B52C2XE.js";
4
+ class EnclaveClient {
5
+ constructor({
6
+ userManagementClient,
7
+ retrieveJwt,
8
+ persistJwt,
9
+ retrieveRefreshJwt,
10
+ persistRefreshJwt
11
+ }) {
12
+ this.enclavePublicKey = null;
13
+ this.frontendKeyPair = null;
14
+ this.userManagementClient = userManagementClient;
15
+ this.retrieveJwt = retrieveJwt;
16
+ this.persistJwt = persistJwt;
17
+ this.retrieveRefreshJwt = retrieveRefreshJwt;
18
+ this.persistRefreshJwt = persistRefreshJwt;
19
+ }
20
+ refreshJwt() {
21
+ return __async(this, null, function* () {
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));
29
+ const response = yield this.userManagementClient.refreshEnclaveJwt(JSON.stringify(encryptedPayload));
30
+ const decryptedResponse = yield this.decryptForFrontend(JSON.parse(response.payload));
31
+ this.persistJwt(decryptedResponse.jwt);
32
+ this.persistRefreshJwt(decryptedResponse.refreshJwt);
33
+ });
34
+ }
35
+ withJwtRefreshRetry(fn) {
36
+ return __async(this, null, function* () {
37
+ try {
38
+ return yield fn();
39
+ } catch (e) {
40
+ yield this.refreshJwt();
41
+ return yield fn();
42
+ }
43
+ });
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
+ const decryptedResponse = yield this.decryptForFrontend(JSON.parse(response));
55
+ this.persistJwt(decryptedResponse.jwt);
56
+ });
57
+ }
58
+ /**
59
+ * Generate a P-256 keypair for the frontend to receive encrypted responses
60
+ */
61
+ generateFrontendKeyPair() {
62
+ return __async(this, null, function* () {
63
+ if (this.frontendKeyPair) {
64
+ return this.frontendKeyPair;
65
+ }
66
+ this.frontendKeyPair = yield crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, ["deriveBits"]);
67
+ return this.frontendKeyPair;
68
+ });
69
+ }
70
+ /**
71
+ * Get the enclave's public key from the user-management service
72
+ */
73
+ getEnclavePublicKey() {
74
+ return __async(this, null, function* () {
75
+ if (this.enclavePublicKey) {
76
+ return this.enclavePublicKey;
77
+ }
78
+ const response = yield this.userManagementClient.getEnclavePublicKey();
79
+ this.enclavePublicKey = response.publicKey;
80
+ return this.enclavePublicKey;
81
+ });
82
+ }
83
+ /**
84
+ * Import a PEM-formatted public key for use with Web Crypto API
85
+ */
86
+ importPublicKeyFromPEM(pemString) {
87
+ return __async(this, null, function* () {
88
+ const pemContents = pemString.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replace(/\s/g, "");
89
+ const keyData = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
90
+ return yield crypto.subtle.importKey("spki", keyData, { name: "ECDH", namedCurve: "P-256" }, false, []);
91
+ });
92
+ }
93
+ /**
94
+ * Export a public key to PEM format
95
+ */
96
+ exportPublicKeyToPEM(publicKey) {
97
+ return __async(this, null, function* () {
98
+ const exported = yield crypto.subtle.exportKey("spki", publicKey);
99
+ const exportedAsBase64 = btoa(String.fromCharCode(...new Uint8Array(exported)));
100
+ return `-----BEGIN PUBLIC KEY-----
101
+ ${exportedAsBase64}
102
+ -----END PUBLIC KEY-----`;
103
+ });
104
+ }
105
+ /**
106
+ * Encrypt data using P-256 ECIES for the enclave
107
+ */
108
+ encryptForEnclave(plaintext) {
109
+ return __async(this, null, function* () {
110
+ const enclavePublicKeyPEM = yield this.getEnclavePublicKey();
111
+ const enclavePublicKey = yield this.importPublicKeyFromPEM(enclavePublicKeyPEM);
112
+ const ephemeralKeyPair = yield crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, ["deriveBits"]);
113
+ const sharedSecretBits = yield crypto.subtle.deriveBits(
114
+ { name: "ECDH", public: enclavePublicKey },
115
+ ephemeralKeyPair.privateKey,
116
+ 256
117
+ // 32 bytes = 256 bits
118
+ );
119
+ const encryptionKeyBuffer = yield crypto.subtle.digest("SHA-256", sharedSecretBits);
120
+ const encryptionKey = yield crypto.subtle.importKey("raw", encryptionKeyBuffer, { name: "AES-GCM" }, false, ["encrypt"]);
121
+ const iv = crypto.getRandomValues(new Uint8Array(12));
122
+ const encrypted = yield crypto.subtle.encrypt(
123
+ { name: "AES-GCM", iv },
124
+ encryptionKey,
125
+ new TextEncoder().encode(plaintext)
126
+ );
127
+ const encryptedArray = new Uint8Array(encrypted);
128
+ const combined = new Uint8Array(iv.length + encryptedArray.length);
129
+ combined.set(iv);
130
+ combined.set(encryptedArray, iv.length);
131
+ const ephemeralPublicKeyBuffer = yield crypto.subtle.exportKey("spki", ephemeralKeyPair.publicKey);
132
+ return {
133
+ encryptedData: btoa(String.fromCharCode(...combined)),
134
+ keyId: "",
135
+ // Will be set by the enclave
136
+ algorithm: "ECIES-P256-AES256-SHA256",
137
+ ephemeral: btoa(String.fromCharCode(...new Uint8Array(ephemeralPublicKeyBuffer)))
138
+ };
139
+ });
140
+ }
141
+ /**
142
+ * Decrypt response encrypted for the frontend
143
+ */
144
+ decryptForFrontend(encryptedPayload) {
145
+ return __async(this, null, function* () {
146
+ if (!this.frontendKeyPair) {
147
+ throw new Error("Frontend keypair not available");
148
+ }
149
+ const encryptedData = Uint8Array.from(atob(encryptedPayload.encryptedData), (c) => c.charCodeAt(0));
150
+ const ephemeralPublicKeyData = Uint8Array.from(atob(encryptedPayload.ephemeral), (c) => c.charCodeAt(0));
151
+ const ephemeralPublicKey = yield crypto.subtle.importKey(
152
+ "spki",
153
+ ephemeralPublicKeyData,
154
+ { name: "ECDH", namedCurve: "P-256" },
155
+ false,
156
+ []
157
+ );
158
+ const sharedSecretBits = yield crypto.subtle.deriveBits(
159
+ { name: "ECDH", public: ephemeralPublicKey },
160
+ this.frontendKeyPair.privateKey,
161
+ 256
162
+ );
163
+ const encryptionKeyBuffer = yield crypto.subtle.digest("SHA-256", sharedSecretBits);
164
+ const encryptionKey = yield crypto.subtle.importKey("raw", encryptionKeyBuffer, { name: "AES-GCM" }, false, ["decrypt"]);
165
+ const iv = encryptedData.slice(0, 12);
166
+ const ciphertext = encryptedData.slice(12);
167
+ const decrypted = yield crypto.subtle.decrypt({ name: "AES-GCM", iv }, encryptionKey, ciphertext);
168
+ return JSON.parse(new TextDecoder().decode(decrypted));
169
+ });
170
+ }
171
+ /**
172
+ * Persist key shares to the enclave
173
+ * @param shares Array of share data to persist
174
+ */
175
+ persistShares(shares) {
176
+ return __async(this, null, function* () {
177
+ const payload = {
178
+ shares,
179
+ jwt: this.retrieveJwt()
180
+ };
181
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
182
+ const encryptedPayloadStr = JSON.stringify(encryptedPayload);
183
+ return yield this.userManagementClient.persistEnclaveShares({ encryptedPayload: encryptedPayloadStr });
184
+ });
185
+ }
186
+ /**
187
+ * Retrieve key shares from the enclave
188
+ * @param query Query parameters for finding shares (single query or array of queries)
189
+ */
190
+ retrieveShares(query) {
191
+ return __async(this, null, function* () {
192
+ yield this.issueEnclaveJwt();
193
+ const frontendKeyPair = yield this.generateFrontendKeyPair();
194
+ const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
195
+ const fullQuery = query.map((q) => ({
196
+ userId: q.userId
197
+ }));
198
+ const payload = {
199
+ query: fullQuery,
200
+ responsePublicKey: responsePublicKeyPEM,
201
+ jwt: this.retrieveJwt()
202
+ };
203
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
204
+ const encryptedPayloadStr = JSON.stringify(encryptedPayload);
205
+ const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
206
+ const encryptedResponse = JSON.parse(response.payload);
207
+ const decryptedData = yield this.decryptForFrontend(encryptedResponse);
208
+ return decryptedData.shares;
209
+ });
210
+ }
211
+ deleteShares() {
212
+ return __async(this, null, function* () {
213
+ yield this.issueEnclaveJwt();
214
+ const frontendKeyPair = yield this.generateFrontendKeyPair();
215
+ const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
216
+ const payload = {
217
+ responsePublicKey: responsePublicKeyPEM,
218
+ jwt: this.retrieveJwt()
219
+ };
220
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
221
+ const encryptedPayloadStr = JSON.stringify(encryptedPayload);
222
+ yield this.userManagementClient.deleteEnclaveShares(encryptedPayloadStr);
223
+ });
224
+ }
225
+ retrieveSharesWithRetry(query) {
226
+ return __async(this, null, function* () {
227
+ return yield this.withJwtRefreshRetry(() => __async(this, null, function* () {
228
+ return this.retrieveShares(query);
229
+ }));
230
+ });
231
+ }
232
+ persistSharesWithRetry(shares) {
233
+ return __async(this, null, function* () {
234
+ return yield this.persistShares(shares);
235
+ });
236
+ }
237
+ deleteSharesWithRetry() {
238
+ return __async(this, null, function* () {
239
+ return yield this.withJwtRefreshRetry(() => __async(this, null, function* () {
240
+ return this.deleteShares();
241
+ }));
242
+ });
243
+ }
244
+ }
245
+ export {
246
+ EnclaveClient
247
+ };
@@ -13,8 +13,23 @@ function distributeNewShare(_0) {
13
13
  ignoreRedistributingBackupEncryptedShare = false,
14
14
  emailProps = {},
15
15
  partnerId,
16
- protocolId
16
+ protocolId,
17
+ isEnclaveUser,
18
+ walletScheme
17
19
  }) {
20
+ if (isEnclaveUser) {
21
+ yield ctx.enclaveClient.persistSharesWithRetry([
22
+ {
23
+ userId,
24
+ walletId,
25
+ walletScheme,
26
+ signer: userShare,
27
+ partnerId,
28
+ protocolId
29
+ }
30
+ ]);
31
+ return "";
32
+ }
18
33
  const publicKeysRes = yield ctx.client.getSessionPublicKeys(userId);
19
34
  const biometricEncryptedShares = publicKeysRes.data.keys.map((key) => {
20
35
  if (!key.publicKey) {
@@ -4,15 +4,16 @@ import {
4
4
  import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from "@celo/utils/lib/ecies.js";
5
5
  import { Buffer } from "buffer";
6
6
  import * as eutil from "@ethereumjs/util";
7
- import { randomBytes } from "crypto";
8
7
  function upload(message, userManagementClient) {
9
8
  return __async(this, null, function* () {
10
9
  let secret;
11
10
  let publicKeyUint8Array;
12
11
  while (true) {
13
12
  try {
14
- secret = randomBytes(32).toString("hex");
15
- publicKeyUint8Array = eutil.privateToPublic(Buffer.from(secret, "hex"));
13
+ const privateKeyUint8Array = new Uint8Array(32);
14
+ crypto.getRandomValues(privateKeyUint8Array);
15
+ secret = Buffer.from(privateKeyUint8Array).toString("hex");
16
+ publicKeyUint8Array = eutil.privateToPublic(privateKeyUint8Array);
16
17
  break;
17
18
  } catch (e) {
18
19
  continue;
@@ -48,7 +48,9 @@ const PARA_CORE_METHODS = [
48
48
  "getWalletBalance",
49
49
  "issueJwt",
50
50
  "getLinkedAccounts",
51
- "accountLinkInProgress"
51
+ "accountLinkInProgress",
52
+ "addCredential",
53
+ "exportPrivateKey"
52
54
  ];
53
55
  const PARA_INTERNAL_METHODS = [
54
56
  "linkAccount",
@@ -58,7 +60,10 @@ const PARA_INTERNAL_METHODS = [
58
60
  "verifyFarcasterLink",
59
61
  "verifyTelegramLink",
60
62
  "verifyExternalWalletLink",
61
- "accountLinkInProgress"
63
+ "accountLinkInProgress",
64
+ "prepareLogin",
65
+ "sendLoginCode",
66
+ "supportedUserAuthMethods"
62
67
  ];
63
68
  export {
64
69
  PARA_CORE_METHODS,
@@ -12,6 +12,8 @@ var ParaEvent = ((ParaEvent2) => {
12
12
  ParaEvent2["WALLET_CREATED"] = `${EVENT_PREFIX}WalletCreated`;
13
13
  ParaEvent2["PREGEN_WALLET_CLAIMED"] = `${EVENT_PREFIX}PregenWalletClaimed`;
14
14
  ParaEvent2["GUEST_WALLETS_CREATED"] = `${EVENT_PREFIX}GuestWalletsCreated`;
15
+ ParaEvent2["ASSET_TRANSFERRED"] = `${EVENT_PREFIX}AssetTransferred`;
16
+ ParaEvent2["ONRAMP_TRANSACTION_COMPLETE"] = `${EVENT_PREFIX}OnRampTransactionComplete`;
15
17
  return ParaEvent2;
16
18
  })(ParaEvent || {});
17
19
  export {
@@ -1,23 +1,7 @@
1
- import "../chunk-7B52C2XE.js";
2
1
  export * from "./auth.js";
3
2
  export * from "./config.js";
4
3
  export * from "./coreApi.js";
5
4
  export * from "./wallet.js";
6
5
  export * from "./methods.js";
7
- export * from "./theme.js";
8
- export * from "./onRamps.js";
9
6
  export * from "./popup.js";
10
- export * from "./recovery.js";
11
7
  export * from "./events.js";
12
- import {
13
- Network,
14
- OnRampAsset,
15
- OnRampProvider,
16
- OnRampPurchaseStatus
17
- } from "@getpara/user-management-client";
18
- export {
19
- Network,
20
- OnRampAsset,
21
- OnRampProvider,
22
- OnRampPurchaseStatus
23
- };
@@ -6,6 +6,7 @@ var PopupType = /* @__PURE__ */ ((PopupType2) => {
6
6
  PopupType2["CREATE_PASSKEY"] = "CREATE_PASSKEY";
7
7
  PopupType2["OAUTH"] = "OAUTH";
8
8
  PopupType2["ON_RAMP_TRANSACTION"] = "ON_RAMP_TRANSACTION";
9
+ PopupType2["EXPORT_PRIVATE_KEY"] = "EXPORT_PRIVATE_KEY";
9
10
  return PopupType2;
10
11
  })(PopupType || {});
11
12
  export {
@@ -0,0 +1,86 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ import { NETWORKS } from "@getpara/user-management-client";
3
+ function validateBalancesConfig(obj) {
4
+ if (!obj || typeof obj !== "object") {
5
+ return false;
6
+ }
7
+ if (!obj.displayType || obj.displayType !== "AGGREGATED" && obj.displayType !== "CUSTOM_ASSET") {
8
+ return false;
9
+ }
10
+ if (obj.displayType === "AGGREGATED") {
11
+ if (obj.excludeStandardAssets !== void 0 && typeof obj.excludeStandardAssets !== "boolean") {
12
+ return false;
13
+ }
14
+ if (obj.additionalAssets !== void 0) {
15
+ if (!Array.isArray(obj.additionalAssets)) {
16
+ return false;
17
+ }
18
+ for (const asset of obj.additionalAssets) {
19
+ if (!validateCustomAsset(asset)) {
20
+ return false;
21
+ }
22
+ const hasPriceUrl = typeof asset.priceUrl === "string" && asset.priceUrl.trim();
23
+ const hasPrice = asset.price && typeof asset.price === "object" && typeof asset.price.value === "number" && asset.price.value > 0 && typeof asset.price.currency === "string" && asset.price.currency.trim();
24
+ if (!hasPriceUrl && !hasPrice) {
25
+ return false;
26
+ }
27
+ if (hasPriceUrl && hasPrice) {
28
+ return false;
29
+ }
30
+ }
31
+ }
32
+ return true;
33
+ }
34
+ if (obj.displayType === "CUSTOM_ASSET") {
35
+ if (!obj.asset) {
36
+ return false;
37
+ }
38
+ if (!validateCustomAsset(obj.asset)) {
39
+ return false;
40
+ }
41
+ const hasPriceUrl = typeof obj.asset.priceUrl === "string" && obj.asset.priceUrl.trim();
42
+ const hasPrice = obj.asset.price && typeof obj.asset.price === "object" && typeof obj.asset.price.value === "number" && obj.asset.price.value > 0 && typeof obj.asset.price.currency === "string" && obj.asset.price.currency.trim();
43
+ if (hasPriceUrl && hasPrice) {
44
+ return false;
45
+ }
46
+ return true;
47
+ }
48
+ return false;
49
+ }
50
+ function validateCustomAsset(obj) {
51
+ if (!obj || typeof obj !== "object") {
52
+ return false;
53
+ }
54
+ if (typeof obj.name !== "string" || !obj.name.trim() || typeof obj.symbol !== "string" || !obj.symbol.trim()) {
55
+ return false;
56
+ }
57
+ if (!Array.isArray(obj.implementations) || obj.implementations.length === 0) {
58
+ return false;
59
+ }
60
+ for (const network of obj.implementations) {
61
+ if (!network || typeof network !== "object") {
62
+ return false;
63
+ }
64
+ if (typeof network.network === "string") {
65
+ if (!NETWORKS.includes(network.network)) {
66
+ return false;
67
+ }
68
+ if (typeof network.contractAddress !== "string" || !network.contractAddress.trim()) {
69
+ return false;
70
+ }
71
+ } else if (typeof network.network === "object") {
72
+ if (typeof network.network.name !== "string" || !network.network.name.trim() || typeof network.network.rpcUrl !== "string" || !network.network.rpcUrl.trim() || typeof network.network.evmChainId !== "string" || !network.network.evmChainId.trim()) {
73
+ return false;
74
+ }
75
+ if (network.contractAddress !== void 0 && (typeof network.contractAddress !== "string" || !network.contractAddress.trim())) {
76
+ return false;
77
+ }
78
+ } else {
79
+ return false;
80
+ }
81
+ }
82
+ return true;
83
+ }
84
+ export {
85
+ validateBalancesConfig
86
+ };
@@ -1,4 +1,5 @@
1
1
  export * from "./autobind.js";
2
+ export * from "./config.js";
2
3
  export * from "./events.js";
3
4
  export * from "./formatting.js";
4
5
  export * from "./json.js";
@@ -9,3 +10,4 @@ export * from "./polling.js";
9
10
  export * from "./types.js";
10
11
  export * from "./url.js";
11
12
  export * from "./wallet.js";
13
+ export * from "./window.js";
@@ -1,5 +1,4 @@
1
1
  import "../chunk-7B52C2XE.js";
2
- import { Network } from "@getpara/user-management-client";
3
2
  function toAssetInfoArray(data) {
4
3
  const result = [];
5
4
  Object.keys(data).forEach((walletType) => {
@@ -51,8 +50,8 @@ function getOnRampAssets(data, {
51
50
  ];
52
51
  }
53
52
  const NETWORK_PREFIXES = {
54
- [Network.COSMOS]: "cosmos",
55
- [Network.NOBLE]: "noble"
53
+ COSMOS: "cosmos",
54
+ NOBLE: "noble"
56
55
  };
57
56
  function getNetworkPrefix(network) {
58
57
  return NETWORK_PREFIXES[network];
@@ -59,7 +59,10 @@ function getEquivalentTypes(types) {
59
59
  return getWalletTypes(getSchemes(Array.isArray(types) ? types : [types]));
60
60
  }
61
61
  function entityToWallet(w) {
62
+ var _a;
62
63
  return __spreadProps(__spreadValues({}, w), {
64
+ createdAt: typeof w.createdAt === "string" ? w.createdAt : w.createdAt.toISOString(),
65
+ lastUsedAt: typeof w.lastUsedAt === "string" ? w.lastUsedAt : (_a = w.lastUsedAt) == null ? void 0 : _a.toISOString(),
63
66
  scheme: w.scheme,
64
67
  type: w.type,
65
68
  pregenIdentifierType: w.pregenIdentifierType
@@ -88,8 +91,22 @@ function mergeCurrentWalletIds(original, additional) {
88
91
  function newUuid() {
89
92
  return uuid.v4();
90
93
  }
94
+ function currentWalletIdsEq(a, b) {
95
+ if (!a && !b) return true;
96
+ if (!a || !b) return false;
97
+ const aKeys = Object.keys(a);
98
+ const bKeys = Object.keys(b);
99
+ if (aKeys.length !== bKeys.length) return false;
100
+ return aKeys.every((key) => {
101
+ var _a, _b;
102
+ const aIds = ((_a = a[key]) == null ? void 0 : _a.sort()) || [];
103
+ const bIds = ((_b = b[key]) == null ? void 0 : _b.sort()) || [];
104
+ return aIds.length === bIds.length && aIds.every((id, index) => id === bIds[index]);
105
+ });
106
+ }
91
107
  export {
92
108
  WalletSchemeTypeMap,
109
+ currentWalletIdsEq,
93
110
  entityToWallet,
94
111
  getEquivalentTypes,
95
112
  getSchemes,