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

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.
@@ -1,6 +1,7 @@
1
1
  import "./chunk-7B52C2XE.js";
2
- const PARA_CORE_VERSION = "2.0.0-dev.0";
2
+ const PARA_CORE_VERSION = "2.0.0-alpha.50";
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
@@ -33,7 +33,7 @@ export * from "./types/coreApi.js";
33
33
  export * from "./types/events.js";
34
34
  export * from "./types/config.js";
35
35
  import { getPortalDomain, entityToWallet, constructUrl, shortenUrl } from "./utils/index.js";
36
- import { PREFIX } from "./constants.js";
36
+ import { PREFIX, PARA_PREFIX } from "./constants.js";
37
37
  import { distributeNewShare } from "./shares/shareDistribution.js";
38
38
  import { KeyContainer } from "./shares/KeyContainer.js";
39
39
  import { getBaseUrl, initClient } from "./external/userManagementClient.js";
@@ -85,6 +85,7 @@ export {
85
85
  OnRampProvider,
86
86
  OnRampPurchaseStatus,
87
87
  OnRampPurchaseType,
88
+ PARA_PREFIX as PARA_STORAGE_PREFIX,
88
89
  PREGEN_IDENTIFIER_TYPES,
89
90
  PopupType,
90
91
  PregenIdentifierType,
@@ -0,0 +1,216 @@
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 encryptedPayload = yield this.encryptForEnclave(JSON.stringify({ refreshJwt: this.retrieveRefreshJwt() }));
23
+ const response = yield this.userManagementClient.refreshEnclaveJwt(JSON.stringify(encryptedPayload));
24
+ const decryptedResponse = yield this.decryptForFrontend(JSON.parse(response.payload));
25
+ this.persistJwt(decryptedResponse.jwt);
26
+ this.persistRefreshJwt(decryptedResponse.refreshJwt);
27
+ });
28
+ }
29
+ withJwtRefreshRetry(fn) {
30
+ return __async(this, null, function* () {
31
+ try {
32
+ return yield fn();
33
+ } catch (error) {
34
+ yield this.refreshJwt();
35
+ return yield fn();
36
+ }
37
+ });
38
+ }
39
+ /**
40
+ * Generate a P-256 keypair for the frontend to receive encrypted responses
41
+ */
42
+ generateFrontendKeyPair() {
43
+ return __async(this, null, function* () {
44
+ if (this.frontendKeyPair) {
45
+ return this.frontendKeyPair;
46
+ }
47
+ this.frontendKeyPair = yield crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, ["deriveBits"]);
48
+ return this.frontendKeyPair;
49
+ });
50
+ }
51
+ /**
52
+ * Get the enclave's public key from the user-management service
53
+ */
54
+ getEnclavePublicKey() {
55
+ return __async(this, null, function* () {
56
+ if (this.enclavePublicKey) {
57
+ return this.enclavePublicKey;
58
+ }
59
+ const response = yield this.userManagementClient.getEnclavePublicKey();
60
+ this.enclavePublicKey = response.publicKey;
61
+ return this.enclavePublicKey;
62
+ });
63
+ }
64
+ /**
65
+ * Import a PEM-formatted public key for use with Web Crypto API
66
+ */
67
+ importPublicKeyFromPEM(pemString) {
68
+ return __async(this, null, function* () {
69
+ const pemContents = pemString.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replace(/\s/g, "");
70
+ const keyData = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
71
+ return yield crypto.subtle.importKey("spki", keyData, { name: "ECDH", namedCurve: "P-256" }, false, []);
72
+ });
73
+ }
74
+ /**
75
+ * Export a public key to PEM format
76
+ */
77
+ exportPublicKeyToPEM(publicKey) {
78
+ return __async(this, null, function* () {
79
+ const exported = yield crypto.subtle.exportKey("spki", publicKey);
80
+ const exportedAsBase64 = btoa(String.fromCharCode(...new Uint8Array(exported)));
81
+ return `-----BEGIN PUBLIC KEY-----
82
+ ${exportedAsBase64}
83
+ -----END PUBLIC KEY-----`;
84
+ });
85
+ }
86
+ /**
87
+ * Encrypt data using P-256 ECIES for the enclave
88
+ */
89
+ encryptForEnclave(plaintext) {
90
+ return __async(this, null, function* () {
91
+ const enclavePublicKeyPEM = yield this.getEnclavePublicKey();
92
+ const enclavePublicKey = yield this.importPublicKeyFromPEM(enclavePublicKeyPEM);
93
+ const ephemeralKeyPair = yield crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, ["deriveBits"]);
94
+ const sharedSecretBits = yield crypto.subtle.deriveBits(
95
+ { name: "ECDH", public: enclavePublicKey },
96
+ ephemeralKeyPair.privateKey,
97
+ 256
98
+ // 32 bytes = 256 bits
99
+ );
100
+ const encryptionKeyBuffer = yield crypto.subtle.digest("SHA-256", sharedSecretBits);
101
+ const encryptionKey = yield crypto.subtle.importKey("raw", encryptionKeyBuffer, { name: "AES-GCM" }, false, ["encrypt"]);
102
+ const iv = crypto.getRandomValues(new Uint8Array(12));
103
+ const encrypted = yield crypto.subtle.encrypt(
104
+ { name: "AES-GCM", iv },
105
+ encryptionKey,
106
+ new TextEncoder().encode(plaintext)
107
+ );
108
+ const encryptedArray = new Uint8Array(encrypted);
109
+ const combined = new Uint8Array(iv.length + encryptedArray.length);
110
+ combined.set(iv);
111
+ combined.set(encryptedArray, iv.length);
112
+ const ephemeralPublicKeyBuffer = yield crypto.subtle.exportKey("spki", ephemeralKeyPair.publicKey);
113
+ return {
114
+ encryptedData: btoa(String.fromCharCode(...combined)),
115
+ keyId: "",
116
+ // Will be set by the enclave
117
+ algorithm: "ECIES-P256-AES256-SHA256",
118
+ ephemeral: btoa(String.fromCharCode(...new Uint8Array(ephemeralPublicKeyBuffer)))
119
+ };
120
+ });
121
+ }
122
+ /**
123
+ * Decrypt response encrypted for the frontend
124
+ */
125
+ decryptForFrontend(encryptedPayload) {
126
+ return __async(this, null, function* () {
127
+ if (!this.frontendKeyPair) {
128
+ throw new Error("Frontend keypair not available");
129
+ }
130
+ const encryptedData = Uint8Array.from(atob(encryptedPayload.encryptedData), (c) => c.charCodeAt(0));
131
+ const ephemeralPublicKeyData = Uint8Array.from(atob(encryptedPayload.ephemeral), (c) => c.charCodeAt(0));
132
+ const ephemeralPublicKey = yield crypto.subtle.importKey(
133
+ "spki",
134
+ ephemeralPublicKeyData,
135
+ { name: "ECDH", namedCurve: "P-256" },
136
+ false,
137
+ []
138
+ );
139
+ const sharedSecretBits = yield crypto.subtle.deriveBits(
140
+ { name: "ECDH", public: ephemeralPublicKey },
141
+ this.frontendKeyPair.privateKey,
142
+ 256
143
+ );
144
+ const encryptionKeyBuffer = yield crypto.subtle.digest("SHA-256", sharedSecretBits);
145
+ const encryptionKey = yield crypto.subtle.importKey("raw", encryptionKeyBuffer, { name: "AES-GCM" }, false, ["decrypt"]);
146
+ const iv = encryptedData.slice(0, 12);
147
+ const ciphertext = encryptedData.slice(12);
148
+ const decrypted = yield crypto.subtle.decrypt({ name: "AES-GCM", iv }, encryptionKey, ciphertext);
149
+ console.log("decryptForFrontend decrypted", decrypted);
150
+ return JSON.parse(new TextDecoder().decode(decrypted));
151
+ });
152
+ }
153
+ /**
154
+ * Persist key shares to the enclave
155
+ * @param shares Array of share data to persist
156
+ */
157
+ persistShares(shares) {
158
+ return __async(this, null, function* () {
159
+ console.log("persistShares about to call encryptForEnclave");
160
+ console.log("shares", shares);
161
+ const payload = {
162
+ shares,
163
+ jwt: this.retrieveJwt()
164
+ };
165
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
166
+ const encryptedPayloadStr = JSON.stringify(encryptedPayload);
167
+ return yield this.userManagementClient.persistEnclaveShares(encryptedPayloadStr);
168
+ });
169
+ }
170
+ /**
171
+ * Retrieve key shares from the enclave
172
+ * @param query Query parameters for finding shares (single query or array of queries)
173
+ */
174
+ retrieveShares(query) {
175
+ return __async(this, null, function* () {
176
+ console.log("retrieveShares about to call generateFrontendKeyPair");
177
+ console.log("query", query);
178
+ const frontendKeyPair = yield this.generateFrontendKeyPair();
179
+ const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
180
+ const fullQuery = query.map((q) => ({
181
+ userId: q.userId
182
+ }));
183
+ const payload = {
184
+ query: fullQuery,
185
+ responsePublicKey: responsePublicKeyPEM,
186
+ jwt: this.retrieveJwt()
187
+ };
188
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
189
+ const encryptedPayloadStr = JSON.stringify(encryptedPayload);
190
+ const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
191
+ console.log("retrieveShares response", response);
192
+ const encryptedResponse = JSON.parse(response.payload);
193
+ console.log("retrieveShares encryptedResponse", encryptedResponse);
194
+ const decryptedData = yield this.decryptForFrontend(encryptedResponse);
195
+ console.log("retrieveShares decryptedData", decryptedData);
196
+ return decryptedData;
197
+ });
198
+ }
199
+ retrieveSharesWithRetry(query) {
200
+ return __async(this, null, function* () {
201
+ return yield this.withJwtRefreshRetry(() => __async(this, null, function* () {
202
+ return this.retrieveShares(query);
203
+ }));
204
+ });
205
+ }
206
+ persistSharesWithRetry(shares) {
207
+ return __async(this, null, function* () {
208
+ return yield this.withJwtRefreshRetry(() => __async(this, null, function* () {
209
+ return this.persistShares(shares);
210
+ }));
211
+ });
212
+ }
213
+ }
214
+ export {
215
+ EnclaveClient
216
+ };
@@ -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) {
@@ -58,7 +58,9 @@ const PARA_INTERNAL_METHODS = [
58
58
  "verifyFarcasterLink",
59
59
  "verifyTelegramLink",
60
60
  "verifyExternalWalletLink",
61
- "accountLinkInProgress"
61
+ "accountLinkInProgress",
62
+ "prepareLogin",
63
+ "sendLoginCode"
62
64
  ];
63
65
  export {
64
66
  PARA_CORE_METHODS,
@@ -1,9 +1,10 @@
1
- import { AuthMethod, AuthExtras, CurrentWalletIds, EmailTheme, TWalletType, PregenIds, BiometricLocationHint, Auth, SupportedWalletTypes, AuthIdentifier, AuthType, ExternalWalletInfo, PrimaryAuthInfo, SessionInfo, PrimaryAuth, PrimaryAuthType, AccountMetadata, LinkedAccounts, VerifyLinkParams, VerifyExternalWalletParams, SupportedAccountLinks } 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 } from '@getpara/user-management-client';
2
2
  import type { pki as pkiType } from 'node-forge';
3
3
  import { Ctx, Environment, Theme, 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;
@@ -16,13 +17,18 @@ export declare abstract class ParaCore implements CoreInterface {
16
17
  get telegramUserId(): AuthIdentifier<'telegram'> | undefined;
17
18
  get externalWalletWithParaAuth(): Wallet | undefined;
18
19
  get externalWalletConnectionType(): ExternalWalletConnectionType;
20
+ protected partner?: PartnerEntity;
19
21
  userId?: string;
20
22
  accountLinkInProgress: AccountLinkInProgress | undefined;
21
23
  private sessionCookie?;
24
+ isEnclaveUser: boolean;
25
+ private enclaveJwt?;
26
+ private enclaveRefreshJwt?;
22
27
  private isAwaitingAccountCreation;
23
28
  private isAwaitingLogin;
24
29
  private isAwaitingFarcaster;
25
30
  private isAwaitingOAuth;
31
+ private isWorkerInitialized;
26
32
  get isEmail(): boolean;
27
33
  get isPhone(): boolean;
28
34
  get isFarcaster(): boolean;
@@ -30,6 +36,8 @@ export declare abstract class ParaCore implements CoreInterface {
30
36
  get isExternalWalletAuth(): boolean;
31
37
  get isExternalWalletWithVerification(): boolean;
32
38
  get partnerId(): string | undefined;
39
+ protected get partnerName(): string | undefined;
40
+ protected get partnerLogo(): string | undefined;
33
41
  /**
34
42
  * The IDs of the currently active wallets, for each supported wallet type. Any signer integrations will default to the first viable wallet ID in this dictionary.
35
43
  */
@@ -129,7 +137,11 @@ export declare abstract class ParaCore implements CoreInterface {
129
137
  get cosmosPrefix(): string | undefined;
130
138
  get supportedAccountLinks(): SupportedAccountLinks;
131
139
  get isWalletTypeEnabled(): Partial<Record<TWalletType, boolean>>;
132
- private platformUtils;
140
+ protected onRampPopup: {
141
+ window: Window;
142
+ onRampPurchase: OnRampPurchase;
143
+ } | undefined;
144
+ protected platformUtils: PlatformUtils;
133
145
  private localStorageGetItem;
134
146
  private localStorageSetItem;
135
147
  private localStorageRemoveItem;
@@ -138,6 +150,10 @@ export declare abstract class ParaCore implements CoreInterface {
138
150
  private sessionStorageRemoveItem;
139
151
  retrieveSessionCookie: () => string | undefined;
140
152
  persistSessionCookie: (cookie: string) => void;
153
+ retrieveEnclaveJwt: () => string;
154
+ persistEnclaveJwt: (jwt: string) => void;
155
+ retrieveEnclaveRefreshJwt: () => string;
156
+ persistEnclaveRefreshJwt: (jwt: string) => void;
141
157
  /**
142
158
  * Remove all local storage and prefixed session storage.
143
159
  * @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
@@ -145,7 +161,7 @@ export declare abstract class ParaCore implements CoreInterface {
145
161
  clearStorage: (type?: CoreMethodParams<"clearStorage">) => CoreMethodResponse<"clearStorage">;
146
162
  private convertBigInt;
147
163
  private convertEncryptionKeyPair;
148
- private isPortal;
164
+ protected isPortal(envOverride?: Environment): boolean;
149
165
  private isParaConnect;
150
166
  private requireApiKey;
151
167
  private isWalletSupported;
@@ -179,24 +195,28 @@ export declare abstract class ParaCore implements CoreInterface {
179
195
  protected abstract getPlatformUtils(): PlatformUtils;
180
196
  abstract isPasskeySupported(): Promise<boolean>;
181
197
  protected constructPortalUrl(type: PortalUrlType, opts?: PortalUrlOptions): Promise<string>;
198
+ static resolveEnvironment(env: Environment | undefined, apiKey: string | undefined): Environment;
182
199
  /**
183
200
  * Constructs a new `ParaCore` instance.
184
- * @param env - `Environment` to use.
201
+ * @param env - `Environment` to use. Optional if the apiKey contains an environment prefix (e.g., "prod_your_api_key"). Updated API keys can be found at https://developer.getpara.com.
185
202
  * @param apiKey - API key to use.
186
203
  * @param opts - Additional constructor options; see `ConstructorOpts`.
187
204
  * @returns - A new ParaCore instance.
188
205
  */
189
- constructor(env: Environment, apiKey: string, opts?: ConstructorOpts);
206
+ constructor(env: Environment | undefined, apiKey: string, opts?: ConstructorOpts);
207
+ constructor(apiKey: string, opts?: ConstructorOpts);
190
208
  private trackError;
191
209
  private wrapMethodsWithErrorTracking;
192
210
  private initializeFromStorage;
193
211
  private updateAuthInfoFromStorage;
212
+ private updateEnclaveJwtFromStorage;
194
213
  private updateUserIdFromStorage;
195
214
  private updateWalletsFromStorage;
196
215
  private updateWalletIdsFromStorage;
197
216
  private updateSessionCookieFromStorage;
198
217
  private updateLoginEncryptionKeyPairFromStorage;
199
218
  private updateExternalWalletsFromStorage;
219
+ protected initializeWorker: () => Promise<void>;
200
220
  touchSession(regenerate?: boolean): Promise<SessionInfo>;
201
221
  private getVerificationEmailProps;
202
222
  private getBackupKitEmailProps;
@@ -206,12 +226,19 @@ export declare abstract class ParaCore implements CoreInterface {
206
226
  * Init only needs to be called for storage that is async.
207
227
  */
208
228
  init(): Promise<void>;
209
- protected abstract ready(): Promise<void>;
229
+ /**
230
+ * Call this method to perform initial setup for the `ParaCore` instance.
231
+ *
232
+ * This method will be called automatically if you use the React `ParaProvider` or when you call any methods that request an updated session.
233
+ */
234
+ abstract ready(): Promise<void>;
210
235
  protected setAuth(auth: PrimaryAuth, { extras, userId }?: {
211
236
  extras?: AuthExtras;
212
237
  userId?: string;
213
238
  }): Promise<typeof this.authInfo>;
214
- protected assertUserId(): string;
239
+ protected assertUserId({ allowGuestMode }?: {
240
+ allowGuestMode?: boolean;
241
+ }): string;
215
242
  protected assertIsAuthSet(allowed?: AuthType[]): PrimaryAuthInfo;
216
243
  /**
217
244
  * Sets the email associated with the `ParaCore` instance.
@@ -240,6 +267,7 @@ export declare abstract class ParaCore implements CoreInterface {
240
267
  * @param externalType - Type of external wallet to set.
241
268
  */
242
269
  setExternalWallet(externalWallet: ExternalWalletInfo[] | ExternalWalletInfo): Promise<void>;
270
+ protected addExternalWallets(externalWallets: ExternalWalletInfo[]): Promise<void>;
243
271
  /**
244
272
  * Sets the user id associated with the `ParaCore` instance.
245
273
  * @param userId - User id to set.
@@ -394,6 +422,9 @@ export declare abstract class ParaCore implements CoreInterface {
394
422
  **/
395
423
  isFullyLoggedIn(): CoreMethodResponse<'isFullyLoggedIn'>;
396
424
  get isGuestMode(): boolean;
425
+ /**
426
+ * Get the auth methods available to an existing user
427
+ */
397
428
  protected supportedAuthMethods(auth: Auth<PrimaryAuthType | 'userId'>): Promise<Set<AuthMethod>>;
398
429
  /**
399
430
  * Get hints associated with the users stored biometrics.
@@ -668,7 +699,7 @@ export declare abstract class ParaCore implements CoreInterface {
668
699
  url?: string;
669
700
  }>;
670
701
  /**
671
- * Returns a Para Portal URL for logging in with a WebAuth passkey or a password.
702
+ * Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
672
703
  * @param {Object} opts the options object
673
704
  * @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
674
705
  * @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
@@ -676,6 +707,7 @@ export declare abstract class ParaCore implements CoreInterface {
676
707
  * @returns {SignUpOrLogInResponse} an object in the form of either: `{ stage: 'verify' }` or `{ stage: 'login'; passkeyUrl?: string; passwordUrl?: string; biometricHints?: BiometricLocationHint[] }`
677
708
  */
678
709
  protected getLoginUrl({ authMethod, shorten, portalTheme, sessionId, }: LoginUrlParams): Promise<string>;
710
+ protected prepareLogin(): InternalMethodResponse<'prepareLogin'>;
679
711
  signUpOrLogIn({ auth, ...urlOptions }: CoreMethodParams<'signUpOrLogIn'>): CoreMethodResponse<'signUpOrLogIn'>;
680
712
  verifyNewAccount({ verificationCode, ...urlOptions }: CoreMethodParams<'verifyNewAccount'>): CoreMethodResponse<'verifyNewAccount'>;
681
713
  getLinkedAccounts({ withMetadata, }?: CoreMethodParams<'getLinkedAccounts'>): CoreMethodResponse<'getLinkedAccounts'>;
@@ -685,4 +717,5 @@ export declare abstract class ParaCore implements CoreInterface {
685
717
  accountLinkInProgress?: AccountLinkInProgress;
686
718
  } & Partial<Pick<VerifyLinkParams, 'verificationCode' | 'telegramAuthResponse'> & VerifyExternalWalletParams>): Promise<LinkedAccounts>;
687
719
  protected verifyEmailOrPhoneLink({ verificationCode, }: InternalMethodParams<'verifyEmailOrPhoneLink'>): InternalMethodResponse<'verifyEmailOrPhoneLink'>;
720
+ protected sendLoginCode(): Promise<void>;
688
721
  }
@@ -42,5 +42,6 @@ export interface PlatformUtils {
42
42
  disableProviderModal?: boolean;
43
43
  openPopup(popupUrl: string, opts?: {
44
44
  type: PopupType;
45
- }): Window;
45
+ }): Promise<Window>;
46
+ initializeWorker(ctx: Ctx): Promise<void>;
46
47
  }
@@ -1,5 +1,6 @@
1
1
  export declare const PARA_CORE_VERSION: string;
2
2
  export declare const PREFIX = "@CAPSULE/";
3
+ export declare const PARA_PREFIX = "@PARA/";
3
4
  export declare const LOCAL_STORAGE_AUTH_INFO = "@CAPSULE/authInfo";
4
5
  export declare const LOCAL_STORAGE_EMAIL = "@CAPSULE/e-mail";
5
6
  export declare const LOCAL_STORAGE_PHONE = "@CAPSULE/phone";
@@ -13,6 +14,8 @@ export declare const LOCAL_STORAGE_WALLETS = "@CAPSULE/wallets";
13
14
  export declare const LOCAL_STORAGE_EXTERNAL_WALLETS = "@CAPSULE/externalWallets";
14
15
  export declare const LOCAL_STORAGE_CURRENT_WALLET_IDS = "@CAPSULE/currentWalletIds";
15
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";
16
19
  export declare const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = "@CAPSULE/loginEncryptionKeyPair";
17
20
  export declare const POLLING_INTERVAL_MS = 2000;
18
21
  export declare const SHORT_POLLING_INTERVAL_MS = 1000;
@@ -5,7 +5,7 @@ export * from './types/coreApi.js';
5
5
  export * from './types/events.js';
6
6
  export * from './types/config.js';
7
7
  export { getPortalDomain, entityToWallet, constructUrl, shortenUrl } from './utils/index.js';
8
- export { PREFIX as STORAGE_PREFIX } from './constants.js';
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';
11
11
  export type { PlatformUtils } from './PlatformUtils.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,80 @@
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
+ /**
45
+ * Generate a P-256 keypair for the frontend to receive encrypted responses
46
+ */
47
+ private generateFrontendKeyPair;
48
+ /**
49
+ * Get the enclave's public key from the user-management service
50
+ */
51
+ private getEnclavePublicKey;
52
+ /**
53
+ * Import a PEM-formatted public key for use with Web Crypto API
54
+ */
55
+ private importPublicKeyFromPEM;
56
+ /**
57
+ * Export a public key to PEM format
58
+ */
59
+ private exportPublicKeyToPEM;
60
+ /**
61
+ * Encrypt data using P-256 ECIES for the enclave
62
+ */
63
+ private encryptForEnclave;
64
+ /**
65
+ * Decrypt response encrypted for the frontend
66
+ */
67
+ private decryptForFrontend;
68
+ /**
69
+ * Persist key shares to the enclave
70
+ * @param shares Array of share data to persist
71
+ */
72
+ private persistShares;
73
+ /**
74
+ * Retrieve key shares from the enclave
75
+ * @param query Query parameters for finding shares (single query or array of queries)
76
+ */
77
+ private retrieveShares;
78
+ retrieveSharesWithRetry(query: ShareQuery[]): Promise<ShareData[]>;
79
+ persistSharesWithRetry(shares: ShareData[]): Promise<any>;
80
+ }
@@ -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>;
@@ -1,6 +1,7 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
  import Client, { EmailTheme, Network, OnRampAsset, OnRampProvider, PregenAuth, TWalletScheme, TWalletType } from '@getpara/user-management-client';
3
3
  import { Theme } from './theme.js';
4
+ import { EnclaveClient } from '../shares/enclave.js';
4
5
  export declare enum Environment {
5
6
  DEV = "DEV",
6
7
  SANDBOX = "SANDBOX",
@@ -13,6 +14,7 @@ export interface Ctx {
13
14
  env: Environment;
14
15
  apiKey: string;
15
16
  client: Client;
17
+ enclaveClient?: EnclaveClient;
16
18
  disableWorkers?: boolean;
17
19
  offloadMPCComputationURL?: string;
18
20
  mpcComputationClient?: AxiosInstance;
@@ -4,7 +4,7 @@ import { ParaCore } from '../ParaCore.js';
4
4
  import { FullSignatureRes, Wallet } from './wallet.js';
5
5
  import { AccountLinkInProgress } from './auth.js';
6
6
  export declare const PARA_CORE_METHODS: readonly ["getAuthInfo", "signUpOrLogIn", "verifyNewAccount", "waitForLogin", "waitForSignup", "waitForWalletCreation", "getOAuthUrl", "verifyOAuth", "getFarcasterConnectUri", "verifyFarcaster", "verifyTelegram", "resendVerificationCode", "loginExternalWallet", "verifyExternalWallet", "setup2fa", "enable2fa", "verify2fa", "logout", "clearStorage", "isSessionActive", "isFullyLoggedIn", "refreshSession", "keepSessionAlive", "exportSession", "importSession", "getVerificationToken", "getWallets", "getWalletsByType", "fetchWallets", "createWallet", "createWalletPerType", "getPregenWallets", "hasPregenWallet", "updatePregenWalletIdentifier", "createPregenWallet", "createPregenWalletPerType", "claimPregenWallets", "createGuestWallets", "distributeNewWalletShare", "getUserShare", "setUserShare", "refreshShare", "signMessage", "signTransaction", "initiateOnRampTransaction", "getWalletBalance", "issueJwt", "getLinkedAccounts", "accountLinkInProgress"];
7
- export declare const PARA_INTERNAL_METHODS: readonly ["linkAccount", "unlinkAccount", "verifyEmailOrPhoneLink", "verifyOAuthLink", "verifyFarcasterLink", "verifyTelegramLink", "verifyExternalWalletLink", "accountLinkInProgress"];
7
+ export declare const PARA_INTERNAL_METHODS: readonly ["linkAccount", "unlinkAccount", "verifyEmailOrPhoneLink", "verifyOAuthLink", "verifyFarcasterLink", "verifyTelegramLink", "verifyExternalWalletLink", "accountLinkInProgress", "prepareLogin", "sendLoginCode"];
8
8
  export type CoreMethodName = (typeof PARA_CORE_METHODS)[number];
9
9
  export type CoreMethodParams<method extends CoreMethodName & keyof CoreMethods> = CoreMethods[method] extends {
10
10
  params: infer P;
@@ -118,6 +118,7 @@ export type CoreMethods = Record<CoreMethodName, {
118
118
  getOAuthUrl: {
119
119
  params: OAuthUrlParams & {
120
120
  sessionLookupId?: string;
121
+ encryptionKey?: string;
121
122
  };
122
123
  response: string;
123
124
  };
@@ -148,11 +149,11 @@ export type CoreMethods = Record<CoreMethodName, {
148
149
  };
149
150
  verifyExternalWallet: {
150
151
  params: AuthStateBaseParams & VerifyExternalWalletParams;
151
- response: AuthStateSignup;
152
+ response: AuthStateSignup | AuthStateLogin;
152
153
  };
153
154
  resendVerificationCode: {
154
155
  params: {
155
- type?: 'SIGNUP' | 'LINK_ACCOUNT';
156
+ type?: 'SIGNUP' | 'LINK_ACCOUNT' | 'LOGIN';
156
157
  } | undefined;
157
158
  response: void;
158
159
  };
@@ -522,6 +523,14 @@ export type InternalMethods = {
522
523
  params: Omit<VerifyExternalWalletParams, 'externalWallet'>;
523
524
  response: LinkedAccounts;
524
525
  };
526
+ prepareLogin: {
527
+ params: void;
528
+ response: string;
529
+ };
530
+ sendLoginCode: {
531
+ params: void;
532
+ response: void;
533
+ };
525
534
  };
526
535
  export type CoreInterface = {
527
536
  [key in keyof CoreMethods]: Partial<CoreMethod<key>>;