@getpara/core-sdk 2.0.0-alpha.53 → 2.0.0-alpha.54

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 (51) hide show
  1. package/dist/cjs/ParaCore.js +213 -60
  2. package/dist/cjs/constants.js +7 -1
  3. package/dist/cjs/index.js +2 -0
  4. package/dist/cjs/shares/enclave.js +266 -0
  5. package/dist/cjs/shares/shareDistribution.js +16 -1
  6. package/dist/cjs/types/assets.js +15 -0
  7. package/dist/cjs/types/events.js +2 -0
  8. package/dist/cjs/utils/formatting.js +41 -0
  9. package/dist/esm/ParaCore.js +214 -61
  10. package/dist/esm/{chunk-7B52C2XE.js → chunk-W5CT3TVS.js} +2 -0
  11. package/dist/esm/constants.js +6 -2
  12. package/dist/esm/cryptography/utils.js +1 -1
  13. package/dist/esm/errors.js +1 -1
  14. package/dist/esm/external/mpcComputationClient.js +1 -1
  15. package/dist/esm/external/userManagementClient.js +1 -1
  16. package/dist/esm/index.js +3 -2
  17. package/dist/esm/shares/KeyContainer.js +1 -1
  18. package/dist/esm/shares/enclave.js +226 -0
  19. package/dist/esm/shares/recovery.js +1 -1
  20. package/dist/esm/shares/shareDistribution.js +17 -2
  21. package/dist/esm/transmission/transmissionUtils.js +1 -1
  22. package/dist/esm/types/assets.js +0 -0
  23. package/dist/esm/types/auth.js +1 -1
  24. package/dist/esm/types/config.js +1 -1
  25. package/dist/esm/types/coreApi.js +1 -1
  26. package/dist/esm/types/events.js +3 -1
  27. package/dist/esm/types/popup.js +1 -1
  28. package/dist/esm/types/wallet.js +1 -1
  29. package/dist/esm/utils/autobind.js +1 -1
  30. package/dist/esm/utils/events.js +1 -1
  31. package/dist/esm/utils/formatting.js +41 -1
  32. package/dist/esm/utils/json.js +1 -1
  33. package/dist/esm/utils/listeners.js +1 -1
  34. package/dist/esm/utils/onRamps.js +1 -1
  35. package/dist/esm/utils/phone.js +1 -1
  36. package/dist/esm/utils/polling.js +1 -1
  37. package/dist/esm/utils/types.js +1 -1
  38. package/dist/esm/utils/url.js +1 -1
  39. package/dist/esm/utils/wallet.js +1 -1
  40. package/dist/types/ParaCore.d.ts +15 -2
  41. package/dist/types/constants.d.ts +2 -0
  42. package/dist/types/index.d.ts +3 -2
  43. package/dist/types/shares/enclave.d.ts +81 -0
  44. package/dist/types/shares/shareDistribution.d.ts +4 -2
  45. package/dist/types/types/assets.d.ts +14 -0
  46. package/dist/types/types/config.d.ts +2 -0
  47. package/dist/types/types/coreApi.d.ts +1 -0
  48. package/dist/types/types/events.d.ts +7 -2
  49. package/dist/types/types/methods.d.ts +15 -7
  50. package/dist/types/utils/formatting.d.ts +10 -1
  51. package/package.json +3 -3
@@ -0,0 +1,226 @@
1
+ import {
2
+ __async
3
+ } from "../chunk-W5CT3TVS.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 (error) {
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(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
+ retrieveSharesWithRetry(query) {
212
+ return __async(this, null, function* () {
213
+ return yield this.withJwtRefreshRetry(() => __async(this, null, function* () {
214
+ return this.retrieveShares(query);
215
+ }));
216
+ });
217
+ }
218
+ persistSharesWithRetry(shares) {
219
+ return __async(this, null, function* () {
220
+ return yield this.persistShares(shares);
221
+ });
222
+ }
223
+ }
224
+ export {
225
+ EnclaveClient
226
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __async,
3
3
  __spreadValues
4
- } from "../chunk-7B52C2XE.js";
4
+ } from "../chunk-W5CT3TVS.js";
5
5
  import { EncryptorType, KeyShareType } from "@getpara/user-management-client";
6
6
  import { KeyContainer } from "./KeyContainer.js";
7
7
  function sendRecoveryForShare(_0) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-7B52C2XE.js";
3
+ } from "../chunk-W5CT3TVS.js";
4
4
  import { EncryptorType, KeyShareType } from "@getpara/user-management-client";
5
5
  import { encryptWithDerivedPublicKey } from "../cryptography/utils.js";
6
6
  import { sendRecoveryForShare } from "./recovery.js";
@@ -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) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-7B52C2XE.js";
3
+ } from "../chunk-W5CT3TVS.js";
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";
File without changes
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  var AccountLinkError = /* @__PURE__ */ ((AccountLinkError2) => {
3
3
  AccountLinkError2["NotAuthenticated"] = "No user is currently authenticated";
4
4
  AccountLinkError2["Conflict"] = "Account already linked";
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  var Environment = /* @__PURE__ */ ((Environment2) => {
3
3
  Environment2["DEV"] = "DEV";
4
4
  Environment2["SANDBOX"] = "SANDBOX";
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  const PARA_CORE_METHODS = [
3
3
  "getAuthInfo",
4
4
  "signUpOrLogIn",
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  const EVENT_PREFIX = "para";
3
3
  var ParaEvent = ((ParaEvent2) => {
4
4
  ParaEvent2["LOGIN_EVENT"] = `${EVENT_PREFIX}Login`;
@@ -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,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  var PopupType = /* @__PURE__ */ ((PopupType2) => {
3
3
  PopupType2["SIGN_TRANSACTION_REVIEW"] = "SIGN_TRANSACTION_REVIEW";
4
4
  PopupType2["SIGN_MESSAGE_REVIEW"] = "SIGN_MESSAGE_REVIEW";
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  var PregenIdentifierType = /* @__PURE__ */ ((PregenIdentifierType2) => {
3
3
  PregenIdentifierType2["EMAIL"] = "EMAIL";
4
4
  PregenIdentifierType2["PHONE"] = "PHONE";
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  function autoBind(instance) {
3
3
  let proto = instance;
4
4
  while (proto && proto !== Object.prototype) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __spreadValues
3
- } from "../chunk-7B52C2XE.js";
3
+ } from "../chunk-W5CT3TVS.js";
4
4
  function dispatchEvent(type, data, error) {
5
5
  typeof window !== "undefined" && !!window.dispatchEvent && window.dispatchEvent(
6
6
  new CustomEvent(type, { detail: __spreadValues({ data }, error && { error: new Error(error) }) })
@@ -1,4 +1,6 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import {
2
+ __pow
3
+ } from "../chunk-W5CT3TVS.js";
2
4
  import { toBech32 } from "@cosmjs/encoding";
3
5
  import { sha256 } from "@noble/hashes/sha256";
4
6
  import { ripemd160 } from "@noble/hashes/ripemd160";
@@ -63,9 +65,47 @@ function truncateAddress(str, addressType, {
63
65
  const margin = targetLength !== void 0 ? (targetLength - minimum) / 2 : 4;
64
66
  return `${str.slice(0, minimum + margin)}...${str.slice(-1 * margin)}`;
65
67
  }
68
+ function formatCurrency(value, { fallback = "" } = {}) {
69
+ if (!value) {
70
+ return fallback;
71
+ }
72
+ const formatter = new Intl.NumberFormat("en-US", {
73
+ style: "currency",
74
+ currency: value.currency
75
+ });
76
+ const zeroFormatter = new Intl.NumberFormat("en-US", {
77
+ style: "currency",
78
+ currency: value.currency,
79
+ maximumFractionDigits: 0
80
+ });
81
+ return Math.abs(value.value) < 0.01 ? zeroFormatter.format(0) : formatter.format(value.value);
82
+ }
83
+ const zeroAssetFormatter = new Intl.NumberFormat("en-US", {
84
+ style: "decimal",
85
+ maximumFractionDigits: 0,
86
+ minimumFractionDigits: 0
87
+ });
88
+ function formatAssetQuantity({
89
+ quantity,
90
+ symbol = "",
91
+ decimals,
92
+ fallback = ""
93
+ }) {
94
+ if (!quantity) {
95
+ return fallback;
96
+ }
97
+ const formatter = new Intl.NumberFormat("en-US", {
98
+ style: "decimal",
99
+ maximumFractionDigits: decimals != null ? decimals : Math.abs(quantity) < 1e-3 ? 6 : 3,
100
+ minimumFractionDigits: decimals != null ? decimals : 3
101
+ });
102
+ return `${Math.abs(quantity) < __pow(10, -1 * (decimals != null ? decimals : 6)) ? zeroAssetFormatter.format(0) : formatter.format(quantity)}${symbol && symbol.length > 0 ? ` ${symbol}` : ""}`;
103
+ }
66
104
  export {
67
105
  compressPubkey,
68
106
  decimalToHex,
107
+ formatAssetQuantity,
108
+ formatCurrency,
69
109
  getCosmosAddress,
70
110
  hexStringToBase64,
71
111
  hexToDecimal,
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  function jsonParse(data, validate) {
3
3
  try {
4
4
  const res = JSON.parse(data);
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  import * as constants from "../constants.js";
3
3
  function storageListener(e) {
4
4
  if (!e.url.includes(window.location.origin)) {
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  function toAssetInfoArray(data) {
3
3
  const result = [];
4
4
  Object.keys(data).forEach((walletType) => {
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  import parsePhoneNumberFromString from "libphonenumber-js";
3
3
  function formatPhoneNumber(phone, countryCode, { forDisplay = false } = {}) {
4
4
  phone = phone.toString();
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-7B52C2XE.js";
3
+ } from "../chunk-W5CT3TVS.js";
4
4
  function waitUntilTrue(condition, timeoutMs, intervalMs) {
5
5
  return __async(this, null, function* () {
6
6
  const start = Date.now();
@@ -1,4 +1,4 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import "../chunk-W5CT3TVS.js";
2
2
  function isServerAuthState(obj) {
3
3
  return "stage" in obj;
4
4
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-7B52C2XE.js";
3
+ } from "../chunk-W5CT3TVS.js";
4
4
  import { upload } from "../transmission/transmissionUtils.js";
5
5
  import { Environment } from "../types/index.js";
6
6
  function getPortalDomain(env, isE2E) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __spreadProps,
3
3
  __spreadValues
4
- } from "../chunk-7B52C2XE.js";
4
+ } from "../chunk-W5CT3TVS.js";
5
5
  import * as uuid from "uuid";
6
6
  import { formatPhoneNumber } from "./phone.js";
7
7
  const WalletSchemeTypeMap = {
@@ -1,9 +1,10 @@
1
- import { AuthMethod, AuthExtras, CurrentWalletIds, EmailTheme, PartnerEntity, TWalletType, PregenIds, BiometricLocationHint, Auth, SupportedWalletTypes, AuthIdentifier, AuthType, ExternalWalletInfo, PrimaryAuthInfo, SessionInfo, PrimaryAuth, PrimaryAuthType, AccountMetadata, LinkedAccounts, VerifyLinkParams, VerifyExternalWalletParams, SupportedAccountLinks, OnRampPurchase, Theme } from '@getpara/user-management-client';
1
+ import { AuthMethod, AuthExtras, CurrentWalletIds, EmailTheme, PartnerEntity, TWalletType, PregenIds, BiometricLocationHint, Auth, SupportedWalletTypes, AuthIdentifier, AuthType, ExternalWalletInfo, PrimaryAuthInfo, SessionInfo, PrimaryAuth, PrimaryAuthType, AccountMetadata, LinkedAccounts, VerifyLinkParams, VerifyExternalWalletParams, SupportedAccountLinks, OnRampPurchase, BalancesConfig, Theme } from '@getpara/user-management-client';
2
2
  import type { pki as pkiType } from 'node-forge';
3
3
  import { Ctx, Environment, WalletFilters, Wallet, PortalUrlOptions, ConstructorOpts, CoreAuthInfo, PortalUrlType, CoreMethodParams, CoreMethodResponse, NewCredentialUrlParams, LoginUrlParams, CoreInterface, ExternalWalletConnectionType, AccountLinkInProgress, InternalMethodParams, InternalMethodResponse } from './types/index.js';
4
4
  import { PlatformUtils } from './PlatformUtils.js';
5
5
  export declare abstract class ParaCore implements CoreInterface {
6
6
  #private;
7
+ popupWindow: Window | null;
7
8
  static version?: string;
8
9
  ctx: Ctx;
9
10
  protected isNativePasskey: boolean;
@@ -21,6 +22,9 @@ export declare abstract class ParaCore implements CoreInterface {
21
22
  userId?: string;
22
23
  accountLinkInProgress: AccountLinkInProgress | undefined;
23
24
  private sessionCookie?;
25
+ isEnclaveUser: boolean;
26
+ private enclaveJwt?;
27
+ private enclaveRefreshJwt?;
24
28
  private isAwaitingAccountCreation;
25
29
  private isAwaitingLogin;
26
30
  private isAwaitingFarcaster;
@@ -147,6 +151,10 @@ export declare abstract class ParaCore implements CoreInterface {
147
151
  private sessionStorageRemoveItem;
148
152
  retrieveSessionCookie: () => string | undefined;
149
153
  persistSessionCookie: (cookie: string) => void;
154
+ retrieveEnclaveJwt: () => string;
155
+ persistEnclaveJwt: (jwt: string) => void;
156
+ retrieveEnclaveRefreshJwt: () => string;
157
+ persistEnclaveRefreshJwt: (jwt: string) => void;
150
158
  /**
151
159
  * Remove all local storage and prefixed session storage.
152
160
  * @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
@@ -202,6 +210,7 @@ export declare abstract class ParaCore implements CoreInterface {
202
210
  private wrapMethodsWithErrorTracking;
203
211
  private initializeFromStorage;
204
212
  private updateAuthInfoFromStorage;
213
+ private updateEnclaveJwtFromStorage;
205
214
  private updateUserIdFromStorage;
206
215
  private updateWalletsFromStorage;
207
216
  private updateWalletIdsFromStorage;
@@ -701,7 +710,7 @@ export declare abstract class ParaCore implements CoreInterface {
701
710
  url?: string;
702
711
  }>;
703
712
  /**
704
- * Returns a Para Portal URL for logging in with a WebAuth passkey, password or PIN.
713
+ * Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
705
714
  * @param {Object} opts the options object
706
715
  * @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
707
716
  * @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
@@ -719,5 +728,9 @@ export declare abstract class ParaCore implements CoreInterface {
719
728
  accountLinkInProgress?: AccountLinkInProgress;
720
729
  } & Partial<Pick<VerifyLinkParams, 'verificationCode' | 'telegramAuthResponse'> & VerifyExternalWalletParams>): Promise<LinkedAccounts>;
721
730
  protected verifyEmailOrPhoneLink({ verificationCode, }: InternalMethodParams<'verifyEmailOrPhoneLink'>): InternalMethodResponse<'verifyEmailOrPhoneLink'>;
731
+ protected getProfileBalance({ config, refetch }?: {
732
+ config?: BalancesConfig;
733
+ refetch?: boolean;
734
+ }): Promise<import("@getpara/user-management-client").ProfileBalance>;
722
735
  protected sendLoginCode(): Promise<void>;
723
736
  }
@@ -14,6 +14,8 @@ export declare const LOCAL_STORAGE_WALLETS = "@CAPSULE/wallets";
14
14
  export declare const LOCAL_STORAGE_EXTERNAL_WALLETS = "@CAPSULE/externalWallets";
15
15
  export declare const LOCAL_STORAGE_CURRENT_WALLET_IDS = "@CAPSULE/currentWalletIds";
16
16
  export declare const LOCAL_STORAGE_SESSION_COOKIE = "@CAPSULE/sessionCookie";
17
+ export declare const LOCAL_STORAGE_ENCLAVE_JWT = "@CAPSULE/enclaveJwt";
18
+ export declare const LOCAL_STORAGE_ENCLAVE_REFRESH_JWT = "@CAPSULE/enclaveRefreshJwt";
17
19
  export declare const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = "@CAPSULE/loginEncryptionKeyPair";
18
20
  export declare const POLLING_INTERVAL_MS = 2000;
19
21
  export declare const SHORT_POLLING_INTERVAL_MS = 1000;
@@ -1,10 +1,10 @@
1
1
  import { ParaCore } from './ParaCore.js';
2
- export { type Auth, type AuthInfo, type PrimaryAuthInfo, type VerifiedAuthInfo, type VerifiedAuth, AuthMethod, AuthMethodStatus, type AuthExtras, type CurrentWalletIds, EmailTheme, type PartnerEntity, type WalletEntity, Network, type TNetwork, WalletType, type TWalletType, WalletScheme, type TWalletScheme, OnRampAsset, type TOnRampAsset, OnRampPurchaseType, OnRampProvider, OnRampPurchaseStatus, type OnRampConfig, type OnRampAssets, type OnRampPurchase, type OnRampAssetInfo, type ProviderAssetInfo, OnRampMethod, type Theme, OAuthMethod, type TOAuthMethod, type TLinkedAccountType, type SupportedAccountLinks, type SupportedWalletTypes, type TPregenIdentifierType, type PregenIds, type LinkedAccount, type LinkedAccounts, type TExternalWallet, type ExternalWalletInfo, type PregenAuth, type Setup2faResponse, type TelegramAuthResponse, type VerifyExternalWalletParams, RecoveryStatus, ThemeMode, NON_ED25519, PREGEN_IDENTIFIER_TYPES, WALLET_TYPES, WALLET_SCHEMES, OAUTH_METHODS, LINKED_ACCOUNT_TYPES, EXTERNAL_WALLET_TYPES, EVM_WALLETS, SOLANA_WALLETS, COSMOS_WALLETS, } from '@getpara/user-management-client';
2
+ export { type Auth, type AuthInfo, type PrimaryAuthInfo, type VerifiedAuthInfo, type VerifiedAuth, AuthMethod, AuthMethodStatus, type AuthExtras, type CurrentWalletIds, EmailTheme, type PartnerEntity, type WalletEntity, Network, type TNetwork, WalletType, type TWalletType, WalletScheme, type TWalletScheme, OnRampAsset, type TOnRampAsset, OnRampPurchaseType, OnRampProvider, OnRampPurchaseStatus, type OnRampConfig, type OnRampAssets, type OnRampPurchase, type OnRampAssetInfo, type ProviderAssetInfo, OnRampMethod, type Theme, OAuthMethod, type TOAuthMethod, type TLinkedAccountType, type SupportedAccountLinks, type SupportedWalletTypes, type TPregenIdentifierType, type PregenIds, type LinkedAccount, type LinkedAccounts, type TExternalWallet, type ExternalWalletInfo, type PregenAuth, type Setup2faResponse, type TelegramAuthResponse, type VerifyExternalWalletParams, type AssetMetadata, type AssetMetadataIndexed, type AssetValue, type BalancesConfig, type WalletBalance, type ProfileBalance, type OfframpDepositRequest, RecoveryStatus, ThemeMode, NON_ED25519, PREGEN_IDENTIFIER_TYPES, WALLET_TYPES, WALLET_SCHEMES, OAUTH_METHODS, LINKED_ACCOUNT_TYPES, EXTERNAL_WALLET_TYPES, EVM_WALLETS, SOLANA_WALLETS, COSMOS_WALLETS, } from '@getpara/user-management-client';
3
3
  export { PopupType, PregenIdentifierType, type AuthStateSignup, type AuthStateVerify, type AuthStateLogin, type AuthState, type OAuthResponse, type CoreAuthInfo, type SignatureRes, type FullSignatureRes, type SuccessfulSignatureRes, type DeniedSignatureRes, type DeniedSignatureResWithUrl, type Wallet, type GetWalletBalanceParams, type AccountLinkInProgress, AccountLinkError, type InternalInterface, } from './types/index.js';
4
4
  export * from './types/coreApi.js';
5
5
  export * from './types/events.js';
6
6
  export * from './types/config.js';
7
- export { getPortalDomain, entityToWallet, constructUrl, shortenUrl } from './utils/index.js';
7
+ export { getPortalDomain, dispatchEvent, entityToWallet, constructUrl, shortenUrl } from './utils/index.js';
8
8
  export { PREFIX as STORAGE_PREFIX, PARA_PREFIX as PARA_STORAGE_PREFIX } from './constants.js';
9
9
  export { distributeNewShare } from './shares/shareDistribution.js';
10
10
  export { KeyContainer } from './shares/KeyContainer.js';
@@ -22,5 +22,6 @@ export { isWalletSupported } from './utils/wallet.js';
22
22
  export { getNetworkPrefix, getOnRampAssets, getOnRampNetworks, toAssetInfoArray } from './utils/onRamps.js';
23
23
  export { getPortalBaseURL } from './utils/url.js';
24
24
  export { retrieve as transmissionUtilsRetrieve } from './transmission/transmissionUtils.js';
25
+ export type { ShareData } from './shares/enclave.js';
25
26
  export declare const paraVersion: string;
26
27
  export default ParaCore;
@@ -0,0 +1,81 @@
1
+ import UserManagementClient from '@getpara/user-management-client';
2
+ export interface ShareData {
3
+ userId: string;
4
+ walletId: string;
5
+ walletScheme: string;
6
+ partnerId?: string;
7
+ protocolId?: string;
8
+ signer: string;
9
+ createdAt?: string;
10
+ updatedAt?: string;
11
+ }
12
+ export interface ShareQuery {
13
+ userId: string;
14
+ walletId?: string;
15
+ partnerId?: string;
16
+ }
17
+ export interface EncryptedPayload {
18
+ encryptedData: string;
19
+ keyId: string;
20
+ algorithm: string;
21
+ ephemeral: string;
22
+ }
23
+ /**
24
+ * Enclave client for secure key share operations
25
+ * Handles encryption/decryption and communication with the enclave service
26
+ */
27
+ export declare class EnclaveClient {
28
+ private userManagementClient;
29
+ private enclavePublicKey;
30
+ private frontendKeyPair;
31
+ private retrieveJwt;
32
+ private persistJwt;
33
+ private retrieveRefreshJwt;
34
+ private persistRefreshJwt;
35
+ constructor({ userManagementClient, retrieveJwt, persistJwt, retrieveRefreshJwt, persistRefreshJwt, }: {
36
+ userManagementClient: UserManagementClient;
37
+ retrieveJwt: () => string;
38
+ persistJwt: (jwt: string) => void;
39
+ retrieveRefreshJwt: () => string;
40
+ persistRefreshJwt: (refreshJwt: string) => void;
41
+ });
42
+ private refreshJwt;
43
+ private withJwtRefreshRetry;
44
+ private issueEnclaveJwt;
45
+ /**
46
+ * Generate a P-256 keypair for the frontend to receive encrypted responses
47
+ */
48
+ private generateFrontendKeyPair;
49
+ /**
50
+ * Get the enclave's public key from the user-management service
51
+ */
52
+ private getEnclavePublicKey;
53
+ /**
54
+ * Import a PEM-formatted public key for use with Web Crypto API
55
+ */
56
+ private importPublicKeyFromPEM;
57
+ /**
58
+ * Export a public key to PEM format
59
+ */
60
+ private exportPublicKeyToPEM;
61
+ /**
62
+ * Encrypt data using P-256 ECIES for the enclave
63
+ */
64
+ private encryptForEnclave;
65
+ /**
66
+ * Decrypt response encrypted for the frontend
67
+ */
68
+ private decryptForFrontend;
69
+ /**
70
+ * Persist key shares to the enclave
71
+ * @param shares Array of share data to persist
72
+ */
73
+ private persistShares;
74
+ /**
75
+ * Retrieve key shares from the enclave
76
+ * @param query Query parameters for finding shares (single query or array of queries)
77
+ */
78
+ private retrieveShares;
79
+ retrieveSharesWithRetry(query: ShareQuery[]): Promise<ShareData[]>;
80
+ persistSharesWithRetry(shares: ShareData[]): Promise<any>;
81
+ }
@@ -1,6 +1,6 @@
1
- import { BackupKitEmailProps } from '@getpara/user-management-client';
1
+ import { BackupKitEmailProps, TWalletScheme } from '@getpara/user-management-client';
2
2
  import { Ctx } from '../types/index.js';
3
- export declare function distributeNewShare({ ctx, userId, walletId, userShare, ignoreRedistributingBackupEncryptedShare, emailProps, partnerId, protocolId, }: {
3
+ export declare function distributeNewShare({ ctx, userId, walletId, userShare, ignoreRedistributingBackupEncryptedShare, emailProps, partnerId, protocolId, isEnclaveUser, walletScheme, }: {
4
4
  ctx: Ctx;
5
5
  userId: string;
6
6
  walletId: string;
@@ -9,4 +9,6 @@ export declare function distributeNewShare({ ctx, userId, walletId, userShare, i
9
9
  emailProps?: BackupKitEmailProps;
10
10
  partnerId?: string;
11
11
  protocolId?: string;
12
+ isEnclaveUser: boolean;
13
+ walletScheme: TWalletScheme;
12
14
  }): Promise<string>;