@getpara/core-sdk 2.0.0-fc.3 → 2.1.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.
- package/dist/cjs/ParaCore.js +1119 -319
- package/dist/cjs/constants.js +10 -1
- package/dist/cjs/index.js +23 -3
- package/dist/cjs/shares/KeyContainer.js +3 -3
- package/dist/cjs/shares/enclave.js +287 -0
- package/dist/cjs/shares/shareDistribution.js +16 -1
- package/dist/cjs/transmission/transmissionUtils.js +4 -3
- package/dist/cjs/types/{theme.js → assets.js} +2 -2
- package/dist/cjs/types/coreApi.js +7 -2
- package/dist/cjs/types/events.js +2 -0
- package/dist/cjs/types/index.js +0 -21
- package/dist/cjs/types/popup.js +1 -0
- package/dist/cjs/utils/config.js +108 -0
- package/dist/cjs/utils/index.js +5 -1
- package/dist/cjs/utils/onRamps.js +2 -3
- package/dist/cjs/utils/url.js +10 -9
- package/dist/cjs/utils/wallet.js +18 -0
- package/dist/cjs/{types/onRamps.js → utils/window.js} +17 -12
- package/dist/esm/ParaCore.js +1123 -323
- package/dist/esm/constants.js +7 -1
- package/dist/esm/index.js +24 -5
- package/dist/esm/shares/KeyContainer.js +3 -3
- package/dist/esm/shares/enclave.js +247 -0
- package/dist/esm/shares/shareDistribution.js +16 -1
- package/dist/esm/transmission/transmissionUtils.js +4 -3
- package/dist/esm/types/coreApi.js +7 -2
- package/dist/esm/types/events.js +2 -0
- package/dist/esm/types/index.js +0 -16
- package/dist/esm/types/popup.js +1 -0
- package/dist/esm/utils/config.js +86 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/onRamps.js +2 -3
- package/dist/esm/utils/url.js +10 -9
- package/dist/esm/utils/wallet.js +17 -0
- package/dist/esm/utils/window.js +16 -0
- package/dist/types/ParaCore.d.ts +91 -20
- package/dist/types/PlatformUtils.d.ts +2 -1
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/index.d.ts +6 -4
- package/dist/types/shares/enclave.d.ts +83 -0
- package/dist/types/shares/shareDistribution.d.ts +4 -2
- package/dist/types/types/assets.d.ts +14 -0
- package/dist/types/types/config.d.ts +3 -2
- package/dist/types/types/coreApi.d.ts +47 -7
- package/dist/types/types/events.d.ts +7 -2
- package/dist/types/types/index.d.ts +0 -4
- package/dist/types/types/methods.d.ts +57 -12
- package/dist/types/types/popup.d.ts +2 -1
- package/dist/types/types/wallet.d.ts +8 -4
- package/dist/types/utils/config.d.ts +7 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/onRamps.d.ts +9 -10
- package/dist/types/utils/url.d.ts +3 -3
- package/dist/types/utils/wallet.d.ts +1 -0
- package/dist/types/utils/window.d.ts +2 -0
- package/package.json +3 -3
- package/dist/cjs/types/recovery.js +0 -34
- package/dist/esm/types/onRamps.js +0 -11
- package/dist/esm/types/recovery.js +0 -12
- package/dist/types/types/onRamps.d.ts +0 -10
- package/dist/types/types/recovery.d.ts +0 -7
- package/dist/types/types/theme.d.ts +0 -12
- /package/dist/esm/types/{theme.js → assets.js} +0 -0
package/dist/esm/ParaCore.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
__spreadProps,
|
|
9
9
|
__spreadValues
|
|
10
10
|
} from "./chunk-7B52C2XE.js";
|
|
11
|
-
var _authInfo,
|
|
11
|
+
var _authInfo, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, getOAuthUrl_fn, waitForLoginProcess_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareDoneState_fn, prepareVerificationState_fn, prepareLoginState_fn, prepareSignUpState_fn;
|
|
12
12
|
import { Buffer as NodeBuffer } from "buffer";
|
|
13
13
|
if (typeof global !== "undefined") {
|
|
14
14
|
global.Buffer = global.Buffer || NodeBuffer;
|
|
@@ -21,10 +21,8 @@ if (typeof global !== "undefined") {
|
|
|
21
21
|
}
|
|
22
22
|
import {
|
|
23
23
|
AuthMethod,
|
|
24
|
-
|
|
24
|
+
AuthMethodStatus,
|
|
25
25
|
PublicKeyType,
|
|
26
|
-
extractWalletRef,
|
|
27
|
-
PasswordStatus,
|
|
28
26
|
extractAuthInfo,
|
|
29
27
|
isEmail,
|
|
30
28
|
isPhone,
|
|
@@ -72,29 +70,28 @@ import {
|
|
|
72
70
|
WalletSchemeTypeMap,
|
|
73
71
|
shortenUrl,
|
|
74
72
|
isServerAuthState,
|
|
75
|
-
splitPhoneNumber
|
|
73
|
+
splitPhoneNumber,
|
|
74
|
+
currentWalletIdsEq,
|
|
75
|
+
isPortal
|
|
76
76
|
} from "./utils/index.js";
|
|
77
77
|
import { TransactionReviewDenied, TransactionReviewTimeout } from "./errors.js";
|
|
78
78
|
import * as constants from "./constants.js";
|
|
79
|
+
import { EnclaveClient } from "./shares/enclave.js";
|
|
79
80
|
const _ParaCore = class _ParaCore {
|
|
80
|
-
|
|
81
|
-
* Constructs a new `ParaCore` instance.
|
|
82
|
-
* @param env - `Environment` to use.
|
|
83
|
-
* @param apiKey - API key to use.
|
|
84
|
-
* @param opts - Additional constructor options; see `ConstructorOpts`.
|
|
85
|
-
* @returns - A new ParaCore instance.
|
|
86
|
-
*/
|
|
87
|
-
constructor(env, apiKey, opts) {
|
|
81
|
+
constructor(envOrApiKey, apiKeyOrOpts, opts) {
|
|
88
82
|
__privateAdd(this, _ParaCore_instances);
|
|
83
|
+
this.popupWindow = null;
|
|
89
84
|
__privateAdd(this, _authInfo);
|
|
85
|
+
this.isSwitchingWallets = false;
|
|
90
86
|
this.isNativePasskey = false;
|
|
91
87
|
this.isReady = false;
|
|
92
|
-
__privateAdd(this, _partner);
|
|
93
88
|
this.accountLinkInProgress = void 0;
|
|
89
|
+
this.isEnclaveUser = false;
|
|
94
90
|
this.isAwaitingAccountCreation = false;
|
|
95
91
|
this.isAwaitingLogin = false;
|
|
96
92
|
this.isAwaitingFarcaster = false;
|
|
97
93
|
this.isAwaitingOAuth = false;
|
|
94
|
+
this.isWorkerInitialized = false;
|
|
98
95
|
/**
|
|
99
96
|
* 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.
|
|
100
97
|
*/
|
|
@@ -103,20 +100,34 @@ const _ParaCore = class _ParaCore {
|
|
|
103
100
|
* Wallets associated with the `ParaCore` instance.
|
|
104
101
|
*/
|
|
105
102
|
this.externalWallets = {};
|
|
103
|
+
this.onRampPopup = void 0;
|
|
104
|
+
this.nonPersistedStorageKeys = [];
|
|
106
105
|
this.localStorageGetItem = (key) => {
|
|
107
|
-
|
|
106
|
+
var _a;
|
|
107
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
108
|
+
return this.platformUtils.localStorage.get(key);
|
|
109
|
+
}
|
|
108
110
|
};
|
|
109
111
|
this.localStorageSetItem = (key, value) => {
|
|
110
|
-
|
|
112
|
+
var _a;
|
|
113
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
114
|
+
return this.platformUtils.localStorage.set(key, value);
|
|
115
|
+
}
|
|
111
116
|
};
|
|
112
117
|
this.localStorageRemoveItem = (key) => {
|
|
113
118
|
return this.platformUtils.localStorage.removeItem(key);
|
|
114
119
|
};
|
|
115
120
|
this.sessionStorageGetItem = (key) => {
|
|
116
|
-
|
|
121
|
+
var _a;
|
|
122
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
123
|
+
return this.platformUtils.sessionStorage.get(key);
|
|
124
|
+
}
|
|
117
125
|
};
|
|
118
126
|
this.sessionStorageSetItem = (key, value) => {
|
|
119
|
-
|
|
127
|
+
var _a;
|
|
128
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
129
|
+
return this.platformUtils.sessionStorage.set(key, value);
|
|
130
|
+
}
|
|
120
131
|
};
|
|
121
132
|
this.sessionStorageRemoveItem = (key) => {
|
|
122
133
|
return this.platformUtils.sessionStorage.removeItem(key);
|
|
@@ -124,16 +135,29 @@ const _ParaCore = class _ParaCore {
|
|
|
124
135
|
this.retrieveSessionCookie = () => {
|
|
125
136
|
return this.sessionCookie;
|
|
126
137
|
};
|
|
138
|
+
this.retrieveEnclaveJwt = () => {
|
|
139
|
+
return this.enclaveJwt;
|
|
140
|
+
};
|
|
141
|
+
this.retrieveEnclaveRefreshJwt = () => {
|
|
142
|
+
return this.enclaveRefreshJwt;
|
|
143
|
+
};
|
|
127
144
|
/**
|
|
128
145
|
* Remove all local storage and prefixed session storage.
|
|
129
146
|
* @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
|
|
130
147
|
*/
|
|
131
148
|
this.clearStorage = (type = "all") => __async(this, null, function* () {
|
|
132
149
|
const isAll = type === "all";
|
|
133
|
-
(isAll || type === "local")
|
|
134
|
-
|
|
150
|
+
if (isAll || type === "local") {
|
|
151
|
+
this.platformUtils.localStorage.clear(constants.PREFIX);
|
|
152
|
+
this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
|
|
153
|
+
}
|
|
154
|
+
if (isAll || type === "session") {
|
|
155
|
+
this.platformUtils.sessionStorage.clear(constants.PREFIX);
|
|
156
|
+
this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
|
|
157
|
+
}
|
|
135
158
|
if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
|
|
136
159
|
this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
160
|
+
this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
|
|
137
161
|
}
|
|
138
162
|
});
|
|
139
163
|
this.trackError = (methodName, err) => __async(this, null, function* () {
|
|
@@ -175,6 +199,7 @@ const _ParaCore = class _ParaCore {
|
|
|
175
199
|
this.updateWalletIdsFromStorage();
|
|
176
200
|
this.updateSessionCookieFromStorage();
|
|
177
201
|
this.updateLoginEncryptionKeyPairFromStorage();
|
|
202
|
+
this.updateEnclaveJwtFromStorage();
|
|
178
203
|
};
|
|
179
204
|
this.updateAuthInfoFromStorage = () => {
|
|
180
205
|
var _a;
|
|
@@ -194,6 +219,10 @@ const _ParaCore = class _ParaCore {
|
|
|
194
219
|
}
|
|
195
220
|
__privateSet(this, _authInfo, authInfo);
|
|
196
221
|
};
|
|
222
|
+
this.updateEnclaveJwtFromStorage = () => {
|
|
223
|
+
this.enclaveJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || void 0;
|
|
224
|
+
this.enclaveRefreshJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || void 0;
|
|
225
|
+
};
|
|
197
226
|
this.updateUserIdFromStorage = () => {
|
|
198
227
|
this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
199
228
|
};
|
|
@@ -254,6 +283,16 @@ const _ParaCore = class _ParaCore {
|
|
|
254
283
|
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
255
284
|
this.setExternalWallets(_externalWallets);
|
|
256
285
|
};
|
|
286
|
+
this.initializeWorker = () => __async(this, null, function* () {
|
|
287
|
+
if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers && !this.isPortal()) {
|
|
288
|
+
try {
|
|
289
|
+
this.isWorkerInitialized = true;
|
|
290
|
+
yield this.platformUtils.initializeWorker(this.ctx);
|
|
291
|
+
} catch (e) {
|
|
292
|
+
this.devLog("error initializing worker:", e);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
257
296
|
/**
|
|
258
297
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
259
298
|
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
@@ -270,8 +309,29 @@ const _ParaCore = class _ParaCore {
|
|
|
270
309
|
}) {
|
|
271
310
|
return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
|
|
272
311
|
});
|
|
273
|
-
|
|
274
|
-
|
|
312
|
+
let env, apiKey;
|
|
313
|
+
const actualArgs = Array.from(arguments).filter((arg) => arg !== void 0);
|
|
314
|
+
const actualArgumentCount = actualArgs.length;
|
|
315
|
+
if (actualArgumentCount === 1) {
|
|
316
|
+
if (Object.values(Environment).includes(envOrApiKey)) {
|
|
317
|
+
throw new Error("A Para API key is required.");
|
|
318
|
+
}
|
|
319
|
+
env = _ParaCore.resolveEnvironment(void 0, actualArgs[0]);
|
|
320
|
+
apiKey = actualArgs[0];
|
|
321
|
+
opts = void 0;
|
|
322
|
+
} else if (actualArgumentCount === 2) {
|
|
323
|
+
if (typeof apiKeyOrOpts === "object" && apiKeyOrOpts !== null) {
|
|
324
|
+
env = _ParaCore.resolveEnvironment(void 0, envOrApiKey);
|
|
325
|
+
apiKey = envOrApiKey;
|
|
326
|
+
opts = apiKeyOrOpts;
|
|
327
|
+
} else {
|
|
328
|
+
env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
|
|
329
|
+
apiKey = apiKeyOrOpts;
|
|
330
|
+
opts = void 0;
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
|
|
334
|
+
apiKey = apiKeyOrOpts;
|
|
275
335
|
}
|
|
276
336
|
if (!opts) opts = {};
|
|
277
337
|
let isE2E = false;
|
|
@@ -314,18 +374,41 @@ const _ParaCore = class _ParaCore {
|
|
|
314
374
|
cookie
|
|
315
375
|
);
|
|
316
376
|
};
|
|
377
|
+
this.persistEnclaveJwt = (jwt) => {
|
|
378
|
+
this.enclaveJwt = jwt;
|
|
379
|
+
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
|
|
380
|
+
constants.LOCAL_STORAGE_ENCLAVE_JWT,
|
|
381
|
+
jwt
|
|
382
|
+
);
|
|
383
|
+
};
|
|
384
|
+
this.persistEnclaveRefreshJwt = (refreshJwt) => {
|
|
385
|
+
this.enclaveRefreshJwt = refreshJwt;
|
|
386
|
+
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
|
|
387
|
+
constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
|
|
388
|
+
refreshJwt
|
|
389
|
+
);
|
|
390
|
+
};
|
|
391
|
+
const client = initClient({
|
|
392
|
+
env,
|
|
393
|
+
version: _ParaCore.version,
|
|
394
|
+
apiKey,
|
|
395
|
+
partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
|
|
396
|
+
useFetchAdapter: !!opts.disableWorkers,
|
|
397
|
+
retrieveSessionCookie: this.retrieveSessionCookie,
|
|
398
|
+
persistSessionCookie: this.persistSessionCookie
|
|
399
|
+
});
|
|
400
|
+
const enclaveClient = new EnclaveClient({
|
|
401
|
+
userManagementClient: client,
|
|
402
|
+
retrieveJwt: this.retrieveEnclaveJwt,
|
|
403
|
+
persistJwt: this.persistEnclaveJwt,
|
|
404
|
+
retrieveRefreshJwt: this.retrieveEnclaveRefreshJwt,
|
|
405
|
+
persistRefreshJwt: this.persistEnclaveRefreshJwt
|
|
406
|
+
});
|
|
317
407
|
this.ctx = {
|
|
318
408
|
env,
|
|
319
409
|
apiKey,
|
|
320
|
-
client
|
|
321
|
-
|
|
322
|
-
version: _ParaCore.version,
|
|
323
|
-
apiKey,
|
|
324
|
-
partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
|
|
325
|
-
useFetchAdapter: !!opts.disableWorkers,
|
|
326
|
-
retrieveSessionCookie: this.retrieveSessionCookie,
|
|
327
|
-
persistSessionCookie: this.persistSessionCookie
|
|
328
|
-
}),
|
|
410
|
+
client,
|
|
411
|
+
enclaveClient,
|
|
329
412
|
disableWorkers: opts.disableWorkers,
|
|
330
413
|
offloadMPCComputationURL: opts.offloadMPCComputationURL,
|
|
331
414
|
useLocalFiles: opts.useLocalFiles,
|
|
@@ -360,6 +443,9 @@ const _ParaCore = class _ParaCore {
|
|
|
360
443
|
]);
|
|
361
444
|
}
|
|
362
445
|
}
|
|
446
|
+
setModalError(_error) {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
363
449
|
get authInfo() {
|
|
364
450
|
return __privateGet(this, _authInfo);
|
|
365
451
|
}
|
|
@@ -389,7 +475,12 @@ const _ParaCore = class _ParaCore {
|
|
|
389
475
|
} else if (this.isExternalWalletWithVerification) {
|
|
390
476
|
return "VERIFICATION";
|
|
391
477
|
} else if (!!Object.keys(this.externalWallets).length) {
|
|
392
|
-
|
|
478
|
+
const hasEmbeddedWallets = Object.keys(this.wallets).some((id) => !this.wallets[id].isExternal);
|
|
479
|
+
if (hasEmbeddedWallets) {
|
|
480
|
+
return "NONE";
|
|
481
|
+
} else {
|
|
482
|
+
return "CONNECTION_ONLY";
|
|
483
|
+
}
|
|
393
484
|
}
|
|
394
485
|
return "NONE";
|
|
395
486
|
}
|
|
@@ -419,11 +510,19 @@ const _ParaCore = class _ParaCore {
|
|
|
419
510
|
}
|
|
420
511
|
get partnerId() {
|
|
421
512
|
var _a;
|
|
422
|
-
return (_a =
|
|
513
|
+
return (_a = this.partner) == null ? void 0 : _a.id;
|
|
514
|
+
}
|
|
515
|
+
get partnerName() {
|
|
516
|
+
var _a;
|
|
517
|
+
return (_a = this.partner) == null ? void 0 : _a.displayName;
|
|
518
|
+
}
|
|
519
|
+
get partnerLogo() {
|
|
520
|
+
var _a;
|
|
521
|
+
return (_a = this.partner) == null ? void 0 : _a.logoUrl;
|
|
423
522
|
}
|
|
424
523
|
get currentWalletIdsArray() {
|
|
425
524
|
var _a, _b;
|
|
426
|
-
return ((_b = (_a =
|
|
525
|
+
return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
427
526
|
(acc, { type }) => {
|
|
428
527
|
var _a2;
|
|
429
528
|
return [
|
|
@@ -463,23 +562,23 @@ const _ParaCore = class _ParaCore {
|
|
|
463
562
|
}
|
|
464
563
|
get isNoWalletConfig() {
|
|
465
564
|
var _a;
|
|
466
|
-
return !!((_a =
|
|
565
|
+
return !!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) && this.partner.supportedWalletTypes.length === 0;
|
|
467
566
|
}
|
|
468
567
|
get supportedWalletTypes() {
|
|
469
568
|
var _a, _b;
|
|
470
|
-
return (_b = (_a =
|
|
569
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
471
570
|
}
|
|
472
571
|
get cosmosPrefix() {
|
|
473
572
|
var _a;
|
|
474
|
-
return (_a =
|
|
573
|
+
return (_a = this.partner) == null ? void 0 : _a.cosmosPrefix;
|
|
475
574
|
}
|
|
476
575
|
get supportedAccountLinks() {
|
|
477
576
|
var _a, _b;
|
|
478
|
-
return (_b = (_a =
|
|
577
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...LINKED_ACCOUNT_TYPES];
|
|
479
578
|
}
|
|
480
579
|
get isWalletTypeEnabled() {
|
|
481
580
|
var _a;
|
|
482
|
-
return (((_a =
|
|
581
|
+
return (((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
483
582
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
484
583
|
}, {});
|
|
485
584
|
}
|
|
@@ -509,9 +608,7 @@ const _ParaCore = class _ParaCore {
|
|
|
509
608
|
};
|
|
510
609
|
}
|
|
511
610
|
isPortal(envOverride) {
|
|
512
|
-
|
|
513
|
-
if (typeof window === "undefined") return false;
|
|
514
|
-
return !!((_a = window.location) == null ? void 0 : _a.host) && getPortalBaseURL(envOverride ? { env: envOverride } : this.ctx).includes(window.location.host);
|
|
611
|
+
return isPortal(this.ctx, envOverride);
|
|
515
612
|
}
|
|
516
613
|
isParaConnect() {
|
|
517
614
|
var _a;
|
|
@@ -528,7 +625,7 @@ const _ParaCore = class _ParaCore {
|
|
|
528
625
|
}
|
|
529
626
|
isWalletSupported(wallet) {
|
|
530
627
|
var _a, _b;
|
|
531
|
-
return !((_a =
|
|
628
|
+
return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
532
629
|
}
|
|
533
630
|
isWalletOwned(wallet) {
|
|
534
631
|
return this.isWalletSupported(wallet) && !(wallet == null ? void 0 : wallet.pregenIdentifier) && !(wallet == null ? void 0 : wallet.pregenIdentifierType) && !!this.userId && (wallet == null ? void 0 : wallet.userId) === this.userId;
|
|
@@ -559,7 +656,7 @@ const _ParaCore = class _ParaCore {
|
|
|
559
656
|
} else if (!isOwned && !isUnclaimed) {
|
|
560
657
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
561
658
|
} else if (!this.isWalletSupported(wallet)) {
|
|
562
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b =
|
|
659
|
+
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || []).map(({ type }) => type).join(", ")}`;
|
|
563
660
|
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
564
661
|
var _a2, _b2;
|
|
565
662
|
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
@@ -577,6 +674,9 @@ const _ParaCore = class _ParaCore {
|
|
|
577
674
|
}
|
|
578
675
|
return true;
|
|
579
676
|
}
|
|
677
|
+
truncateAddress(...args) {
|
|
678
|
+
return truncateAddress(args[0], args[1], __spreadValues({ prefix: this.cosmosPrefix }, args[2] || {}));
|
|
679
|
+
}
|
|
580
680
|
/**
|
|
581
681
|
* Returns the formatted address for the desired wallet ID, depending on your app settings.
|
|
582
682
|
* @param {string} walletId the ID of the wallet address to display.
|
|
@@ -590,7 +690,7 @@ const _ParaCore = class _ParaCore {
|
|
|
590
690
|
if (this.externalWallets[walletId]) {
|
|
591
691
|
const wallet2 = this.externalWallets[walletId];
|
|
592
692
|
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, {
|
|
593
|
-
prefix: (_a =
|
|
693
|
+
prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
|
|
594
694
|
targetLength: options.targetLength
|
|
595
695
|
}) : wallet2.address;
|
|
596
696
|
}
|
|
@@ -602,7 +702,7 @@ const _ParaCore = class _ParaCore {
|
|
|
602
702
|
let prefix;
|
|
603
703
|
switch (wallet.type) {
|
|
604
704
|
case "COSMOS":
|
|
605
|
-
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b =
|
|
705
|
+
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
606
706
|
str = getCosmosAddress(wallet.publicKey, prefix);
|
|
607
707
|
break;
|
|
608
708
|
default:
|
|
@@ -635,30 +735,56 @@ const _ParaCore = class _ParaCore {
|
|
|
635
735
|
}
|
|
636
736
|
constructPortalUrl(_0) {
|
|
637
737
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
638
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
639
|
-
const [
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
738
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
739
|
+
const [
|
|
740
|
+
isCreate,
|
|
741
|
+
isLogin,
|
|
742
|
+
isOnRamp,
|
|
743
|
+
isOAuth,
|
|
744
|
+
isOAuthCallback,
|
|
745
|
+
isTelegramLogin,
|
|
746
|
+
isFarcasterLogin,
|
|
747
|
+
isAddNewCredential,
|
|
748
|
+
isSwitchWallets,
|
|
749
|
+
isExportPrivateKey
|
|
750
|
+
] = [
|
|
751
|
+
["createAuth", "createPassword", "createPIN"].includes(type),
|
|
752
|
+
["loginAuth", "loginPassword", "loginPIN", "loginOTP", "switchWallets", "loginExternalWallet"].includes(type),
|
|
753
|
+
type === "onRamp",
|
|
754
|
+
type === "oAuth",
|
|
755
|
+
type === "oAuthCallback",
|
|
756
|
+
["telegramLogin", "telegramLoginVerify"].includes(type),
|
|
757
|
+
type === "loginFarcaster",
|
|
758
|
+
type === "addNewCredential",
|
|
759
|
+
type === "switchWallets",
|
|
760
|
+
type === "exportPrivateKey"
|
|
643
761
|
];
|
|
762
|
+
if (isOAuth && !opts.oAuthMethod) {
|
|
763
|
+
throw new Error("oAuthMethod is required for oAuth portal URLs");
|
|
764
|
+
}
|
|
644
765
|
if (isCreate || isLogin) {
|
|
645
766
|
this.assertIsAuthSet();
|
|
646
767
|
}
|
|
647
768
|
let sessionId = opts.sessionId;
|
|
648
|
-
if ((isLogin || isOnRamp) && !sessionId) {
|
|
769
|
+
if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin || isExportPrivateKey) && !sessionId) {
|
|
649
770
|
const session = yield this.touchSession(true);
|
|
650
771
|
sessionId = session.sessionId;
|
|
651
772
|
}
|
|
652
773
|
if (!this.loginEncryptionKeyPair) {
|
|
653
774
|
yield this.setLoginEncryptionKeyPair();
|
|
654
775
|
}
|
|
655
|
-
const
|
|
776
|
+
const shouldUseLegacyPortalUrl = opts.useLegacyUrl || !!opts.addNewCredentialPasskeyId || type === "loginAuth";
|
|
777
|
+
const base = type === "onRamp" || isTelegramLogin ? getPortalBaseURL(this.ctx, isTelegramLogin, false, shouldUseLegacyPortalUrl) : yield this.getPortalURL(shouldUseLegacyPortalUrl);
|
|
656
778
|
let path;
|
|
657
779
|
switch (type) {
|
|
658
780
|
case "createPassword": {
|
|
659
781
|
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
660
782
|
break;
|
|
661
783
|
}
|
|
784
|
+
case "createPIN": {
|
|
785
|
+
path = `/web/users/${this.userId}/pin/${opts.pathId}`;
|
|
786
|
+
break;
|
|
787
|
+
}
|
|
662
788
|
case "createAuth": {
|
|
663
789
|
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
664
790
|
break;
|
|
@@ -671,18 +797,62 @@ const _ParaCore = class _ParaCore {
|
|
|
671
797
|
path = "/web/biometrics/login";
|
|
672
798
|
break;
|
|
673
799
|
}
|
|
800
|
+
case "loginPIN": {
|
|
801
|
+
path = "/web/pin/login";
|
|
802
|
+
break;
|
|
803
|
+
}
|
|
674
804
|
case "txReview": {
|
|
675
805
|
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
676
806
|
break;
|
|
677
807
|
}
|
|
678
808
|
case "onRamp": {
|
|
679
|
-
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
809
|
+
path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
case "telegramLoginVerify": {
|
|
813
|
+
path = `/auth/telegram/verify`;
|
|
680
814
|
break;
|
|
681
815
|
}
|
|
682
816
|
case "telegramLogin": {
|
|
683
817
|
path = `/auth/telegram`;
|
|
684
818
|
break;
|
|
685
819
|
}
|
|
820
|
+
case "oAuth": {
|
|
821
|
+
path = `/auth/${opts.oAuthMethod.toLowerCase()}`;
|
|
822
|
+
break;
|
|
823
|
+
}
|
|
824
|
+
case "oAuthCallback": {
|
|
825
|
+
path = `/auth/${opts.oAuthMethod.toLowerCase()}/callback`;
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
case "loginOTP": {
|
|
829
|
+
path = "/auth/otp";
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
case "loginFarcaster": {
|
|
833
|
+
path = "/auth/farcaster";
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
836
|
+
case "switchWallets": {
|
|
837
|
+
path = `/auth/wallets`;
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
case "addNewCredential": {
|
|
841
|
+
path = "/auth/add-new-credential";
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
case "exportPrivateKey": {
|
|
845
|
+
path = `/web/users/${this.userId}/private-key/${opts.pathId}`;
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
case "loginExternalWallet": {
|
|
849
|
+
path = "/auth/external-wallet";
|
|
850
|
+
break;
|
|
851
|
+
}
|
|
852
|
+
case "connectExternalWallet": {
|
|
853
|
+
path = "/auth/connect-external-wallet";
|
|
854
|
+
break;
|
|
855
|
+
}
|
|
686
856
|
default: {
|
|
687
857
|
throw new Error(`invalid URL type ${type}`);
|
|
688
858
|
}
|
|
@@ -701,25 +871,28 @@ const _ParaCore = class _ParaCore {
|
|
|
701
871
|
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
702
872
|
sessionId
|
|
703
873
|
};
|
|
704
|
-
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
874
|
+
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({
|
|
705
875
|
apiKey: this.ctx.apiKey,
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
876
|
+
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
877
|
+
partnerId: partner == null ? void 0 : partner.id
|
|
878
|
+
}, typeof window !== "undefined" && ((_b = window.location) == null ? void 0 : _b.origin) ? { origin: window.location.origin } : {}), {
|
|
879
|
+
portalFont: ((_c = opts.portalTheme) == null ? void 0 : _c.font) || ((_d = this.portalTheme) == null ? void 0 : _d.font) || (partner == null ? void 0 : partner.font),
|
|
880
|
+
portalBorderRadius: ((_e = opts.portalTheme) == null ? void 0 : _e.borderRadius) || ((_f = this.portalTheme) == null ? void 0 : _f.borderRadius),
|
|
881
|
+
portalThemeMode: ((_g = opts.portalTheme) == null ? void 0 : _g.mode) || ((_h = this.portalTheme) == null ? void 0 : _h.mode) || (partner == null ? void 0 : partner.themeMode),
|
|
882
|
+
portalAccentColor: ((_i = opts.portalTheme) == null ? void 0 : _i.accentColor) || ((_j = this.portalTheme) == null ? void 0 : _j.accentColor) || (partner == null ? void 0 : partner.accentColor),
|
|
883
|
+
portalForegroundColor: ((_k = opts.portalTheme) == null ? void 0 : _k.foregroundColor) || ((_l = this.portalTheme) == null ? void 0 : _l.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor),
|
|
884
|
+
portalBackgroundColor: ((_m = opts.portalTheme) == null ? void 0 : _m.backgroundColor) || ((_n = this.portalTheme) == null ? void 0 : _n.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor,
|
|
713
885
|
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
714
886
|
portalTextColor: this.portalTextColor,
|
|
715
887
|
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
716
888
|
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
717
|
-
}, isCreate || isLogin ? __spreadProps(__spreadValues({
|
|
889
|
+
}), this.authInfo && (isCreate || isLogin || isAddNewCredential || isOAuthCallback || isSwitchWallets || isExportPrivateKey) ? __spreadProps(__spreadValues({
|
|
718
890
|
authInfo: JSON.stringify(this.authInfo)
|
|
719
891
|
}, isPhone(this.authInfo.auth) ? splitPhoneNumber(this.authInfo.auth.phone) : this.authInfo.auth), {
|
|
720
892
|
pfpUrl: this.authInfo.pfpUrl,
|
|
721
|
-
displayName: this.authInfo.displayName
|
|
722
|
-
|
|
893
|
+
displayName: this.authInfo.displayName,
|
|
894
|
+
userId: this.userId
|
|
895
|
+
}) : {}), isOnRamp ? { email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin || isAddNewCredential ? __spreadProps(__spreadValues({
|
|
723
896
|
sessionId: thisDevice.sessionId,
|
|
724
897
|
encryptionKey: thisDevice.encryptionKey
|
|
725
898
|
}, opts.newDevice ? {
|
|
@@ -727,23 +900,93 @@ const _ParaCore = class _ParaCore {
|
|
|
727
900
|
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
728
901
|
} : {}), {
|
|
729
902
|
pregenIds: JSON.stringify(this.pregenIds)
|
|
730
|
-
}) : {}),
|
|
903
|
+
}) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
|
|
904
|
+
appScheme: opts.appScheme
|
|
905
|
+
} : {}), isTelegramLogin ? { isEmbed: "true" } : {}), isSwitchWallets ? __spreadValues(__spreadValues({}, this.currentWalletIds ? { currentWalletIds: JSON.stringify(this.currentWalletIds) } : {}), this.userId ? { userId: this.userId } : {}) : {}), opts.params || {}), isAddNewCredential ? __spreadProps(__spreadValues({}, opts.addNewCredentialType && { addNewCredentialType: opts.addNewCredentialType.toString() }), {
|
|
906
|
+
addNewCredentialPasskeyId: opts.addNewCredentialPasskeyId,
|
|
907
|
+
addNewCredentialPasswordId: opts.addNewCredentialPasswordId
|
|
908
|
+
}) : {}), isLogin && {
|
|
909
|
+
// Prior versions won't have this param which will skip the upgrade prompt
|
|
910
|
+
isBasicLoginUpgradeVersion: "true"
|
|
911
|
+
}), isExportPrivateKey ? {
|
|
912
|
+
sessionId: thisDevice.sessionId
|
|
913
|
+
} : {});
|
|
731
914
|
const url = constructUrl({ base, path, params });
|
|
732
915
|
if (opts.shorten) {
|
|
733
|
-
return shortenUrl(this.ctx, url);
|
|
916
|
+
return yield shortenUrl(this.ctx, url, shouldUseLegacyPortalUrl);
|
|
734
917
|
}
|
|
735
918
|
return url;
|
|
736
919
|
});
|
|
737
920
|
}
|
|
921
|
+
static resolveEnvironment(env, apiKey) {
|
|
922
|
+
var _a;
|
|
923
|
+
if (!apiKey) {
|
|
924
|
+
throw new Error("A Para API key is required.");
|
|
925
|
+
}
|
|
926
|
+
if (apiKey.includes("_")) {
|
|
927
|
+
const validEnvironmentPrefixes = Object.values(Environment);
|
|
928
|
+
const envPrefix = (_a = apiKey.split("_")[0]) == null ? void 0 : _a.toUpperCase();
|
|
929
|
+
const hasValidPrefix = validEnvironmentPrefixes.some((envValue) => envValue === envPrefix);
|
|
930
|
+
if (!hasValidPrefix) {
|
|
931
|
+
throw new Error(`Invalid API key environment prefix.`);
|
|
932
|
+
}
|
|
933
|
+
return envPrefix;
|
|
934
|
+
}
|
|
935
|
+
if (!env) {
|
|
936
|
+
throw new Error("Environment parameter is required.");
|
|
937
|
+
}
|
|
938
|
+
return env;
|
|
939
|
+
}
|
|
738
940
|
touchSession(regenerate = false) {
|
|
739
941
|
return __async(this, null, function* () {
|
|
740
|
-
var _a, _b, _c;
|
|
942
|
+
var _a, _b, _c, _d, _e;
|
|
943
|
+
if (!this.isWorkerInitialized) {
|
|
944
|
+
this.initializeWorker();
|
|
945
|
+
}
|
|
741
946
|
if (!this.isReady) {
|
|
742
947
|
yield this.ready();
|
|
743
948
|
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
yield
|
|
949
|
+
let session;
|
|
950
|
+
try {
|
|
951
|
+
session = yield this.ctx.client.touchSession(regenerate);
|
|
952
|
+
} catch (error) {
|
|
953
|
+
this.handleTouchSessionError(error);
|
|
954
|
+
throw error;
|
|
955
|
+
}
|
|
956
|
+
if (!this.partner || ((_a = this.partner) == null ? void 0 : _a.id) !== session.partnerId || !supportedWalletTypesEq(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = this.partner) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
|
|
957
|
+
if (!session.partnerId && !this.isPortal()) {
|
|
958
|
+
this.displayModalError(
|
|
959
|
+
`Invalid API Key. Please ensure you have a valid API key for the current environment: ${(_d = this.ctx.env) == null ? void 0 : _d.toUpperCase()}.`
|
|
960
|
+
);
|
|
961
|
+
console.error(`
|
|
962
|
+
\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
963
|
+
\u{1F6A8} PARA SDK CONFIGURATION ERROR \u{1F6A8}
|
|
964
|
+
|
|
965
|
+
INVALID API KEY FOR CONFIGURED ENVIRONMENT
|
|
966
|
+
|
|
967
|
+
Your API key does not match the configured environment. This usually means:
|
|
968
|
+
|
|
969
|
+
1. You're using a production API key with a development environment
|
|
970
|
+
2. You're using a development API key with a production environment
|
|
971
|
+
3. Your API key is invalid or has been regenerated
|
|
972
|
+
|
|
973
|
+
SOLUTION:
|
|
974
|
+
\u2022 Verify your API key at: https://developer.getpara.com
|
|
975
|
+
\u2022 If your API key doesn't contain an environment prefix, ensure your API key is the correct key for your target environment
|
|
976
|
+
|
|
977
|
+
Current Environment: ${this.ctx.env}
|
|
978
|
+
API Key Prefix: ${((_e = this.ctx.apiKey) == null ? void 0 : _e.split("_")[0].toUpperCase()) || "None"}
|
|
979
|
+
|
|
980
|
+
Need help? Visit: https://docs.getpara.com or contact support
|
|
981
|
+
\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
982
|
+
`);
|
|
983
|
+
throw new Error("Invalid API Key.");
|
|
984
|
+
} else {
|
|
985
|
+
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
if (session.currentWalletIds && !currentWalletIdsEq(session.currentWalletIds, this.currentWalletIds)) {
|
|
989
|
+
yield this.setCurrentWalletIds(session.currentWalletIds);
|
|
747
990
|
}
|
|
748
991
|
return session;
|
|
749
992
|
});
|
|
@@ -842,8 +1085,35 @@ const _ParaCore = class _ParaCore {
|
|
|
842
1085
|
return __privateGet(this, _authInfo);
|
|
843
1086
|
});
|
|
844
1087
|
}
|
|
845
|
-
|
|
846
|
-
|
|
1088
|
+
/**
|
|
1089
|
+
* Display an error message in the modal (if available)
|
|
1090
|
+
* @internal
|
|
1091
|
+
*/
|
|
1092
|
+
displayModalError(error) {
|
|
1093
|
+
if (this.ctx.env !== Environment.PROD) {
|
|
1094
|
+
this.setModalError(error);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Handle specific touchSession errors with user-friendly messages
|
|
1099
|
+
* @private
|
|
1100
|
+
*/
|
|
1101
|
+
handleTouchSessionError(error) {
|
|
1102
|
+
const errorStr = String(error);
|
|
1103
|
+
const errorMessage = error instanceof Error ? error.message : "";
|
|
1104
|
+
if (errorStr.includes("blocked by CORS policy") && errorStr.includes("Access-Control-Allow-Origin")) {
|
|
1105
|
+
this.displayModalError("Request rate limit reached. Please wait a couple of minutes and try again.");
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
if (error.status === 403 && errorMessage.includes("origin not authorized")) {
|
|
1109
|
+
this.displayModalError(
|
|
1110
|
+
"The current origin is not allowed. Update your allowed origins in the Para developer portal to allow the current origin."
|
|
1111
|
+
);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
assertUserId({ allowGuestMode = false } = {}) {
|
|
1116
|
+
if (!this.userId || !allowGuestMode && this.isGuestMode) {
|
|
847
1117
|
throw new Error("no userId is set");
|
|
848
1118
|
}
|
|
849
1119
|
return this.userId;
|
|
@@ -901,11 +1171,59 @@ const _ParaCore = class _ParaCore {
|
|
|
901
1171
|
*/
|
|
902
1172
|
setExternalWallet(externalWallet) {
|
|
903
1173
|
return __async(this, null, function* () {
|
|
1174
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
904
1175
|
this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
|
|
1176
|
+
(acc, {
|
|
1177
|
+
partnerId: wPartnerId,
|
|
1178
|
+
address,
|
|
1179
|
+
type,
|
|
1180
|
+
provider,
|
|
1181
|
+
providerId,
|
|
1182
|
+
addressBech32,
|
|
1183
|
+
withFullParaAuth,
|
|
1184
|
+
isConnectionOnly,
|
|
1185
|
+
withVerification
|
|
1186
|
+
}) => {
|
|
1187
|
+
if (partnerId === wPartnerId && supportedWalletTypes.some(({ type: supportedType }) => supportedType === type)) {
|
|
1188
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1189
|
+
[address]: {
|
|
1190
|
+
id: address,
|
|
1191
|
+
partnerId,
|
|
1192
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
1193
|
+
type,
|
|
1194
|
+
name: provider,
|
|
1195
|
+
isExternal: true,
|
|
1196
|
+
isExternalWithParaAuth: withFullParaAuth,
|
|
1197
|
+
externalProviderId: providerId,
|
|
1198
|
+
signer: "",
|
|
1199
|
+
isExternalConnectionOnly: isConnectionOnly,
|
|
1200
|
+
isExternalWithVerification: withVerification
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
return acc;
|
|
1205
|
+
},
|
|
1206
|
+
{}
|
|
1207
|
+
), this.setExternalWallets(this.externalWallets);
|
|
1208
|
+
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
addExternalWallets(externalWallets) {
|
|
1212
|
+
return __async(this, null, function* () {
|
|
1213
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1214
|
+
this.externalWallets = __spreadValues(__spreadValues({}, Object.entries(this.externalWallets).reduce((acc, [address, wallet]) => {
|
|
1215
|
+
if (partnerId === wallet.partnerId && supportedWalletTypes.some(({ type }) => type === wallet.type)) {
|
|
1216
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1217
|
+
[address]: wallet
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
return acc;
|
|
1221
|
+
}, {})), externalWallets.reduce(
|
|
905
1222
|
(acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
|
|
906
1223
|
return __spreadProps(__spreadValues({}, acc), {
|
|
907
1224
|
[address]: {
|
|
908
1225
|
id: address,
|
|
1226
|
+
partnerId,
|
|
909
1227
|
address: addressBech32 != null ? addressBech32 : address,
|
|
910
1228
|
type,
|
|
911
1229
|
name: provider,
|
|
@@ -919,7 +1237,7 @@ const _ParaCore = class _ParaCore {
|
|
|
919
1237
|
});
|
|
920
1238
|
},
|
|
921
1239
|
{}
|
|
922
|
-
);
|
|
1240
|
+
));
|
|
923
1241
|
this.setExternalWallets(this.externalWallets);
|
|
924
1242
|
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
925
1243
|
});
|
|
@@ -950,12 +1268,16 @@ const _ParaCore = class _ParaCore {
|
|
|
950
1268
|
}
|
|
951
1269
|
/**
|
|
952
1270
|
* Sets the external wallets associated with the `ParaCore` instance.
|
|
953
|
-
* @param externalWallets - External wallets to set.
|
|
1271
|
+
* @param externalWallets - External wallets to set, or a function that modifies the current wallets.
|
|
954
1272
|
*/
|
|
955
1273
|
setExternalWallets(externalWallets) {
|
|
956
1274
|
return __async(this, null, function* () {
|
|
957
|
-
|
|
958
|
-
|
|
1275
|
+
if (typeof externalWallets === "function") {
|
|
1276
|
+
this.externalWallets = externalWallets(this.externalWallets);
|
|
1277
|
+
} else {
|
|
1278
|
+
this.externalWallets = externalWallets;
|
|
1279
|
+
}
|
|
1280
|
+
yield this.localStorageSetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS, JSON.stringify(this.externalWallets));
|
|
959
1281
|
});
|
|
960
1282
|
}
|
|
961
1283
|
/**
|
|
@@ -1124,14 +1446,27 @@ const _ParaCore = class _ParaCore {
|
|
|
1124
1446
|
...[...this.currentWalletIdsArray, ...__privateGet(this, _ParaCore_instances, guestWalletIdsArray_get)].map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1125
1447
|
const wallet = this.findWallet(id, type);
|
|
1126
1448
|
if (!wallet) return null;
|
|
1449
|
+
const name = wallet.name;
|
|
1450
|
+
const address = this.getDisplayAddress(id, { addressType: type });
|
|
1451
|
+
const addressShort = this.getDisplayAddress(id, { addressType: type, truncate: true });
|
|
1127
1452
|
return {
|
|
1128
1453
|
id: wallet.id,
|
|
1454
|
+
partner: wallet.partner,
|
|
1129
1455
|
type,
|
|
1130
|
-
address
|
|
1131
|
-
name
|
|
1456
|
+
address,
|
|
1457
|
+
name,
|
|
1458
|
+
addressShort,
|
|
1459
|
+
displayName: name != null ? name : addressShort,
|
|
1460
|
+
ensName: wallet.ensName,
|
|
1461
|
+
ensAvatar: wallet.ensAvatar
|
|
1132
1462
|
};
|
|
1133
1463
|
}).filter((obj) => obj !== null),
|
|
1134
|
-
...Object.values((_a = this.externalWallets) != null ? _a : {})
|
|
1464
|
+
...Object.values((_a = this.externalWallets) != null ? _a : {}).map((wallet) => {
|
|
1465
|
+
return __spreadProps(__spreadValues({}, wallet), {
|
|
1466
|
+
addressShort: truncateAddress(wallet.address, wallet.type, { prefix: this.cosmosPrefix }),
|
|
1467
|
+
displayName: wallet.externalProviderId
|
|
1468
|
+
});
|
|
1469
|
+
})
|
|
1135
1470
|
];
|
|
1136
1471
|
}
|
|
1137
1472
|
/**
|
|
@@ -1193,9 +1528,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1193
1528
|
* @param partnerId: string - id of the partner to get the portal URL for
|
|
1194
1529
|
* @returns - portal URL
|
|
1195
1530
|
*/
|
|
1196
|
-
getPortalURL() {
|
|
1531
|
+
getPortalURL(isLegacy) {
|
|
1197
1532
|
return __async(this, null, function* () {
|
|
1198
|
-
return (yield this.getPartnerURL()) || getPortalBaseURL(this.ctx);
|
|
1533
|
+
return (yield this.getPartnerURL()) || getPortalBaseURL(this.ctx, false, false, isLegacy);
|
|
1199
1534
|
});
|
|
1200
1535
|
}
|
|
1201
1536
|
/**
|
|
@@ -1230,13 +1565,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1230
1565
|
return __async(this, null, function* () {
|
|
1231
1566
|
const res = yield this.isPortal() || this.isParaConnect() ? this.ctx.client.getAllWallets(this.userId) : this.ctx.client.getWallets(this.userId, true);
|
|
1232
1567
|
return res.data.wallets.filter(
|
|
1233
|
-
(wallet) => !!wallet.address && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported(entityToWallet(wallet)))
|
|
1568
|
+
(wallet) => !!wallet.address && wallet.sharesPersisted && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported(entityToWallet(wallet)))
|
|
1234
1569
|
);
|
|
1235
1570
|
});
|
|
1236
1571
|
}
|
|
1237
1572
|
populateWalletAddresses() {
|
|
1238
1573
|
return __async(this, null, function* () {
|
|
1239
|
-
const res = yield this.ctx.client.getWallets(this.userId, true);
|
|
1574
|
+
const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId, true);
|
|
1240
1575
|
const wallets = res.data.wallets;
|
|
1241
1576
|
wallets.forEach((entity) => {
|
|
1242
1577
|
if (this.wallets[entity.id]) {
|
|
@@ -1267,13 +1602,28 @@ const _ParaCore = class _ParaCore {
|
|
|
1267
1602
|
loginExternalWallet(_a) {
|
|
1268
1603
|
return __async(this, null, function* () {
|
|
1269
1604
|
var _b = _a, {
|
|
1270
|
-
externalWallet
|
|
1605
|
+
externalWallet,
|
|
1606
|
+
chainId,
|
|
1607
|
+
uri
|
|
1271
1608
|
} = _b, urlOptions = __objRest(_b, [
|
|
1272
|
-
"externalWallet"
|
|
1609
|
+
"externalWallet",
|
|
1610
|
+
"chainId",
|
|
1611
|
+
"uri"
|
|
1273
1612
|
]);
|
|
1274
1613
|
const externalWallets = Array.isArray(externalWallet) ? externalWallet : [externalWallet];
|
|
1614
|
+
try {
|
|
1615
|
+
yield this.ctx.client.trackExternalWalletConnections({
|
|
1616
|
+
wallets: externalWallets.map((wallet) => ({
|
|
1617
|
+
address: wallet.address,
|
|
1618
|
+
type: wallet.type,
|
|
1619
|
+
provider: wallet.provider
|
|
1620
|
+
}))
|
|
1621
|
+
});
|
|
1622
|
+
} catch (err) {
|
|
1623
|
+
console.error("Error tracking external wallet connections:", err);
|
|
1624
|
+
}
|
|
1275
1625
|
if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
|
|
1276
|
-
yield this.
|
|
1626
|
+
yield this.addExternalWallets(
|
|
1277
1627
|
externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
|
|
1278
1628
|
withFullParaAuth: false
|
|
1279
1629
|
}))
|
|
@@ -1288,33 +1638,47 @@ const _ParaCore = class _ParaCore {
|
|
|
1288
1638
|
);
|
|
1289
1639
|
}
|
|
1290
1640
|
this.requireApiKey();
|
|
1291
|
-
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
|
|
1641
|
+
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet, chainId, uri });
|
|
1292
1642
|
if (!externalWallet.withFullParaAuth && externalWallet.withVerification) {
|
|
1293
1643
|
yield this.touchSession(true);
|
|
1294
1644
|
}
|
|
1645
|
+
if (externalWallet.withFullParaAuth) {
|
|
1646
|
+
yield this.ctx.client.sessionAddPortalVerification();
|
|
1647
|
+
}
|
|
1295
1648
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1296
1649
|
});
|
|
1297
1650
|
}
|
|
1298
|
-
verifyExternalWallet(
|
|
1651
|
+
verifyExternalWallet(params) {
|
|
1299
1652
|
return __async(this, null, function* () {
|
|
1300
|
-
var
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
"cosmosPublicKeyHex",
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1653
|
+
var _c;
|
|
1654
|
+
let serverAuthState;
|
|
1655
|
+
let urlOptions;
|
|
1656
|
+
if ("serverAuthState" in params && params.serverAuthState !== void 0) {
|
|
1657
|
+
const _a = params, { serverAuthState: optsServerAuthState } = _a, rest = __objRest(_a, ["serverAuthState"]);
|
|
1658
|
+
serverAuthState = optsServerAuthState;
|
|
1659
|
+
urlOptions = rest;
|
|
1660
|
+
} else if ("externalWallet" in params) {
|
|
1661
|
+
const _b = params, { externalWallet, signedMessage, cosmosPublicKeyHex, cosmosSigner } = _b, rest = __objRest(_b, ["externalWallet", "signedMessage", "cosmosPublicKeyHex", "cosmosSigner"]);
|
|
1662
|
+
const _serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
|
|
1663
|
+
externalWallet,
|
|
1664
|
+
signedMessage,
|
|
1665
|
+
cosmosPublicKeyHex,
|
|
1666
|
+
cosmosSigner
|
|
1667
|
+
});
|
|
1668
|
+
serverAuthState = _serverAuthState;
|
|
1669
|
+
urlOptions = rest;
|
|
1670
|
+
}
|
|
1671
|
+
if (serverAuthState.stage === "login" && ((_c = serverAuthState.loginAuthMethods) == null ? void 0 : _c.includes(AuthMethod.PIN))) {
|
|
1672
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
1673
|
+
return yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1674
|
+
}
|
|
1675
|
+
let state;
|
|
1676
|
+
try {
|
|
1677
|
+
state = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1678
|
+
} catch (err) {
|
|
1679
|
+
console.error("Error prepping state:", err);
|
|
1680
|
+
}
|
|
1681
|
+
return state;
|
|
1318
1682
|
});
|
|
1319
1683
|
}
|
|
1320
1684
|
verifyExternalWalletLink(opts) {
|
|
@@ -1330,28 +1694,38 @@ const _ParaCore = class _ParaCore {
|
|
|
1330
1694
|
return accounts;
|
|
1331
1695
|
});
|
|
1332
1696
|
}
|
|
1697
|
+
// TELEGRAM
|
|
1333
1698
|
/**
|
|
1334
1699
|
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
1335
1700
|
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
1336
1701
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1337
1702
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1338
1703
|
*/
|
|
1339
|
-
verifyTelegramProcess(
|
|
1704
|
+
verifyTelegramProcess(_c) {
|
|
1340
1705
|
return __async(this, null, function* () {
|
|
1341
|
-
var
|
|
1706
|
+
var _d = _c, {
|
|
1707
|
+
serverAuthState: optsServerAuthState,
|
|
1342
1708
|
telegramAuthResponse,
|
|
1343
1709
|
isLinkAccount
|
|
1344
|
-
} =
|
|
1710
|
+
} = _d, urlOptions = __objRest(_d, [
|
|
1711
|
+
"serverAuthState",
|
|
1345
1712
|
"telegramAuthResponse",
|
|
1346
1713
|
"isLinkAccount"
|
|
1347
1714
|
]);
|
|
1348
1715
|
try {
|
|
1349
1716
|
switch (isLinkAccount) {
|
|
1350
1717
|
case false: {
|
|
1351
|
-
|
|
1352
|
-
|
|
1718
|
+
if (!optsServerAuthState && !telegramAuthResponse) {
|
|
1719
|
+
throw new Error("one of serverAuthState or telegramAuthResponse are required for verifying telegram");
|
|
1720
|
+
}
|
|
1721
|
+
const serverAuthState = optsServerAuthState != null ? optsServerAuthState : yield this.ctx.client.verifyTelegram({ authObject: telegramAuthResponse });
|
|
1722
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
1723
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1353
1724
|
}
|
|
1354
1725
|
case true: {
|
|
1726
|
+
if (!telegramAuthResponse) {
|
|
1727
|
+
throw new Error("telegramAuthResponse is required for verifying telegram link");
|
|
1728
|
+
}
|
|
1355
1729
|
const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
|
|
1356
1730
|
const accounts = yield this.verifyLink({
|
|
1357
1731
|
accountLinkInProgress,
|
|
@@ -1361,7 +1735,8 @@ const _ParaCore = class _ParaCore {
|
|
|
1361
1735
|
}
|
|
1362
1736
|
}
|
|
1363
1737
|
} catch (e) {
|
|
1364
|
-
|
|
1738
|
+
const errorMessage = e instanceof Error ? e.message : e ? String(e) : "Unknown error occurred";
|
|
1739
|
+
throw new Error(errorMessage);
|
|
1365
1740
|
}
|
|
1366
1741
|
});
|
|
1367
1742
|
}
|
|
@@ -1425,6 +1800,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1425
1800
|
let type, linkedAccountId;
|
|
1426
1801
|
switch (reason) {
|
|
1427
1802
|
case "SIGNUP":
|
|
1803
|
+
case "LOGIN":
|
|
1428
1804
|
{
|
|
1429
1805
|
const authInfo = this.assertIsAuthSet(["email", "phone"]);
|
|
1430
1806
|
type = authInfo.authType.toUpperCase();
|
|
@@ -1438,7 +1814,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1438
1814
|
}
|
|
1439
1815
|
break;
|
|
1440
1816
|
}
|
|
1441
|
-
const userId = this.assertUserId();
|
|
1817
|
+
const userId = this.assertUserId({ allowGuestMode: true });
|
|
1442
1818
|
if (type !== "EMAIL" && type !== "PHONE") {
|
|
1443
1819
|
throw new Error("invalid auth type for verification code");
|
|
1444
1820
|
}
|
|
@@ -1476,6 +1852,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1476
1852
|
isFullyLoggedIn() {
|
|
1477
1853
|
return __async(this, null, function* () {
|
|
1478
1854
|
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1855
|
+
if (!this.isReady) {
|
|
1856
|
+
yield this.ready();
|
|
1857
|
+
}
|
|
1479
1858
|
return true;
|
|
1480
1859
|
}
|
|
1481
1860
|
if (this.isGuestMode) {
|
|
@@ -1485,17 +1864,45 @@ const _ParaCore = class _ParaCore {
|
|
|
1485
1864
|
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1486
1865
|
return isSessionActive;
|
|
1487
1866
|
}
|
|
1488
|
-
|
|
1867
|
+
if (this.isSwitchingWallets) {
|
|
1868
|
+
return isSessionActive;
|
|
1869
|
+
}
|
|
1870
|
+
if (!isSessionActive) {
|
|
1871
|
+
return false;
|
|
1872
|
+
}
|
|
1873
|
+
if (this.isNoWalletConfig) {
|
|
1874
|
+
return true;
|
|
1875
|
+
}
|
|
1876
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1877
|
+
const requiredWalletTypes = supportedWalletTypes.filter(({ optional }) => !optional);
|
|
1878
|
+
for (const { type } of requiredWalletTypes) {
|
|
1879
|
+
const hasWalletForType = this.currentWalletIdsArray.some(([walletId, walletType]) => {
|
|
1880
|
+
try {
|
|
1881
|
+
const wallet = this.wallets[walletId];
|
|
1882
|
+
return wallet && walletType === type && typeof wallet.address === "string";
|
|
1883
|
+
} catch (e) {
|
|
1884
|
+
return false;
|
|
1885
|
+
}
|
|
1886
|
+
});
|
|
1887
|
+
if (!hasWalletForType) {
|
|
1888
|
+
return false;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
return true;
|
|
1489
1892
|
});
|
|
1490
1893
|
}
|
|
1491
1894
|
get isGuestMode() {
|
|
1492
1895
|
return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
|
|
1493
1896
|
({ userId, partnerId }) => {
|
|
1494
1897
|
var _a;
|
|
1495
|
-
return partnerId === ((_a =
|
|
1898
|
+
return partnerId === ((_a = this.partner) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
|
|
1496
1899
|
}
|
|
1497
1900
|
);
|
|
1498
1901
|
}
|
|
1902
|
+
/**
|
|
1903
|
+
* Get the auth methods available to an existing user
|
|
1904
|
+
* @deprecated Use supportedUserAuthMethods instead
|
|
1905
|
+
*/
|
|
1499
1906
|
supportedAuthMethods(auth) {
|
|
1500
1907
|
return __async(this, null, function* () {
|
|
1501
1908
|
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
@@ -1513,6 +1920,37 @@ const _ParaCore = class _ParaCore {
|
|
|
1513
1920
|
return authMethods;
|
|
1514
1921
|
});
|
|
1515
1922
|
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Get the auth methods available to an existing user
|
|
1925
|
+
*/
|
|
1926
|
+
supportedUserAuthMethods() {
|
|
1927
|
+
return __async(this, null, function* () {
|
|
1928
|
+
yield this.assertIsAuthSet();
|
|
1929
|
+
const { supportedAuthMethods, hasPasswordWithoutPIN } = yield this.ctx.client.getSupportedAuthMethodsV2(
|
|
1930
|
+
this.authInfo.auth
|
|
1931
|
+
);
|
|
1932
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
1933
|
+
for (const type of supportedAuthMethods) {
|
|
1934
|
+
switch (type) {
|
|
1935
|
+
case "PASSWORD":
|
|
1936
|
+
if (hasPasswordWithoutPIN) {
|
|
1937
|
+
authMethods.add(AuthMethod.PASSWORD);
|
|
1938
|
+
}
|
|
1939
|
+
break;
|
|
1940
|
+
case "PASSKEY":
|
|
1941
|
+
authMethods.add(AuthMethod.PASSKEY);
|
|
1942
|
+
break;
|
|
1943
|
+
case "PIN":
|
|
1944
|
+
authMethods.add(AuthMethod.PIN);
|
|
1945
|
+
break;
|
|
1946
|
+
case "BASIC_LOGIN":
|
|
1947
|
+
authMethods.add(AuthMethod.BASIC_LOGIN);
|
|
1948
|
+
break;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
return authMethods;
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1516
1954
|
/**
|
|
1517
1955
|
* Get hints associated with the users stored biometrics.
|
|
1518
1956
|
* @deprecated
|
|
@@ -1599,26 +2037,33 @@ const _ParaCore = class _ParaCore {
|
|
|
1599
2037
|
return connectUri;
|
|
1600
2038
|
});
|
|
1601
2039
|
}
|
|
2040
|
+
// FARCASTER
|
|
1602
2041
|
/**
|
|
1603
2042
|
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
1604
2043
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
1605
2044
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
1606
2045
|
*/
|
|
1607
|
-
verifyFarcasterProcess(
|
|
2046
|
+
verifyFarcasterProcess(_e) {
|
|
1608
2047
|
return __async(this, null, function* () {
|
|
1609
|
-
var
|
|
2048
|
+
var _f = _e, {
|
|
1610
2049
|
isCanceled = () => false,
|
|
1611
2050
|
onConnectUri,
|
|
1612
2051
|
onCancel,
|
|
1613
2052
|
onPoll,
|
|
1614
|
-
isLinkAccount
|
|
1615
|
-
|
|
2053
|
+
isLinkAccount,
|
|
2054
|
+
serverAuthState: optsServerAuthState
|
|
2055
|
+
} = _f, urlOptions = __objRest(_f, [
|
|
1616
2056
|
"isCanceled",
|
|
1617
2057
|
"onConnectUri",
|
|
1618
2058
|
"onCancel",
|
|
1619
2059
|
"onPoll",
|
|
1620
|
-
"isLinkAccount"
|
|
2060
|
+
"isLinkAccount",
|
|
2061
|
+
"serverAuthState"
|
|
1621
2062
|
]);
|
|
2063
|
+
if (optsServerAuthState) {
|
|
2064
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, optsServerAuthState, urlOptions);
|
|
2065
|
+
return authState;
|
|
2066
|
+
}
|
|
1622
2067
|
let accountLinkInProgress;
|
|
1623
2068
|
if (isLinkAccount) {
|
|
1624
2069
|
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
|
|
@@ -1680,7 +2125,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1680
2125
|
}
|
|
1681
2126
|
getOAuthUrl(opts) {
|
|
1682
2127
|
return __async(this, null, function* () {
|
|
1683
|
-
|
|
2128
|
+
var _a;
|
|
2129
|
+
const sessionLookupId = (_a = opts.sessionLookupId) != null ? _a : yield this.prepareLogin();
|
|
2130
|
+
return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
|
|
1684
2131
|
});
|
|
1685
2132
|
}
|
|
1686
2133
|
/**
|
|
@@ -1691,35 +2138,54 @@ const _ParaCore = class _ParaCore {
|
|
|
1691
2138
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1692
2139
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1693
2140
|
*/
|
|
1694
|
-
verifyOAuthProcess(
|
|
2141
|
+
verifyOAuthProcess(_g) {
|
|
1695
2142
|
return __async(this, null, function* () {
|
|
1696
|
-
var
|
|
2143
|
+
var _h = _g, {
|
|
1697
2144
|
method,
|
|
1698
2145
|
appScheme,
|
|
1699
2146
|
isCanceled = () => false,
|
|
1700
2147
|
onCancel,
|
|
1701
2148
|
onPoll,
|
|
1702
2149
|
onOAuthUrl,
|
|
2150
|
+
onOAuthPopup,
|
|
1703
2151
|
isLinkAccount
|
|
1704
|
-
} =
|
|
2152
|
+
} = _h, urlOptions = __objRest(_h, [
|
|
1705
2153
|
"method",
|
|
1706
2154
|
"appScheme",
|
|
1707
2155
|
"isCanceled",
|
|
1708
2156
|
"onCancel",
|
|
1709
2157
|
"onPoll",
|
|
1710
2158
|
"onOAuthUrl",
|
|
2159
|
+
"onOAuthPopup",
|
|
1711
2160
|
"isLinkAccount"
|
|
1712
2161
|
]);
|
|
2162
|
+
if (onOAuthPopup) {
|
|
2163
|
+
try {
|
|
2164
|
+
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.OAUTH });
|
|
2165
|
+
} catch (error) {
|
|
2166
|
+
throw new Error(`Failed to open OAuth popup: ${error}`);
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
1713
2169
|
let sessionLookupId, accountLinkInProgress;
|
|
1714
|
-
if (onOAuthUrl) {
|
|
2170
|
+
if (onOAuthUrl || onOAuthPopup) {
|
|
1715
2171
|
if (isLinkAccount) {
|
|
1716
2172
|
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
|
|
1717
2173
|
sessionLookupId = (yield this.touchSession()).sessionLookupId;
|
|
1718
2174
|
} else {
|
|
1719
|
-
sessionLookupId = yield
|
|
2175
|
+
sessionLookupId = yield this.prepareLogin();
|
|
1720
2176
|
}
|
|
1721
2177
|
const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, appScheme, sessionLookupId, accountLinkInProgress });
|
|
1722
|
-
|
|
2178
|
+
switch (true) {
|
|
2179
|
+
case !!onOAuthUrl: {
|
|
2180
|
+
onOAuthUrl(oAuthUrl);
|
|
2181
|
+
break;
|
|
2182
|
+
}
|
|
2183
|
+
case (!!onOAuthPopup && !!this.popupWindow): {
|
|
2184
|
+
this.popupWindow.location.href = oAuthUrl;
|
|
2185
|
+
onOAuthPopup(this.popupWindow);
|
|
2186
|
+
break;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
1723
2189
|
} else {
|
|
1724
2190
|
({ sessionLookupId } = yield this.touchSession());
|
|
1725
2191
|
}
|
|
@@ -1778,61 +2244,26 @@ const _ParaCore = class _ParaCore {
|
|
|
1778
2244
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
1779
2245
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
1780
2246
|
**/
|
|
1781
|
-
waitForLogin() {
|
|
1782
|
-
return __async(this,
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
|
|
1802
|
-
try {
|
|
1803
|
-
let session = yield this.touchSession();
|
|
1804
|
-
if (!session.isAuthenticated) {
|
|
1805
|
-
onPoll == null ? void 0 : onPoll();
|
|
1806
|
-
continue;
|
|
1807
|
-
}
|
|
1808
|
-
session = yield this.userSetupAfterLogin();
|
|
1809
|
-
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
1810
|
-
if (!needsWallet) {
|
|
1811
|
-
if (this.currentWalletIdsArray.length === 0) {
|
|
1812
|
-
onPoll == null ? void 0 : onPoll();
|
|
1813
|
-
continue;
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
const fetchedWallets = yield this.fetchWallets();
|
|
1817
|
-
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
1818
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
1819
|
-
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
1820
|
-
yield this.claimPregenWallets();
|
|
1821
|
-
const resp = {
|
|
1822
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
1823
|
-
partnerId: session.partnerId
|
|
1824
|
-
};
|
|
1825
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp);
|
|
1826
|
-
return resolve(resp);
|
|
1827
|
-
}
|
|
1828
|
-
onPoll == null ? void 0 : onPoll();
|
|
1829
|
-
} catch (err) {
|
|
1830
|
-
console.error(err);
|
|
1831
|
-
onPoll == null ? void 0 : onPoll();
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
}))();
|
|
1835
|
-
});
|
|
2247
|
+
waitForLogin(args) {
|
|
2248
|
+
return __async(this, null, function* () {
|
|
2249
|
+
return yield __privateMethod(this, _ParaCore_instances, waitForLoginProcess_fn).call(this, args);
|
|
2250
|
+
});
|
|
2251
|
+
}
|
|
2252
|
+
waitForWalletSwitching(args) {
|
|
2253
|
+
return __async(this, null, function* () {
|
|
2254
|
+
return yield __privateMethod(this, _ParaCore_instances, waitForLoginProcess_fn).call(this, __spreadProps(__spreadValues({}, args), { isSwitchingWallets: true }));
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
/**
|
|
2258
|
+
* Gets the switch wallets URL for wallet selection.
|
|
2259
|
+
* The authMethod is automatically included in the URL if available.
|
|
2260
|
+
*
|
|
2261
|
+
* @returns {Promise<{ url: string; authMethod: TAuthMethod }>} The switch wallets URL and authMethod
|
|
2262
|
+
*/
|
|
2263
|
+
getSwitchWalletsUrl() {
|
|
2264
|
+
return __async(this, null, function* () {
|
|
2265
|
+
const url = yield this.constructPortalUrl("switchWallets");
|
|
2266
|
+
return url;
|
|
1836
2267
|
});
|
|
1837
2268
|
}
|
|
1838
2269
|
/**
|
|
@@ -1855,7 +2286,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1855
2286
|
sessionId
|
|
1856
2287
|
});
|
|
1857
2288
|
if (shouldOpenPopup) {
|
|
1858
|
-
this.platformUtils.openPopup(link);
|
|
2289
|
+
yield this.platformUtils.openPopup(link);
|
|
1859
2290
|
}
|
|
1860
2291
|
return link;
|
|
1861
2292
|
});
|
|
@@ -1946,7 +2377,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1946
2377
|
userId: this.userId,
|
|
1947
2378
|
walletId,
|
|
1948
2379
|
userShare: userSigner,
|
|
1949
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2380
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
2381
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2382
|
+
walletScheme: this.wallets[walletId].scheme
|
|
1950
2383
|
});
|
|
1951
2384
|
return recoveryShare;
|
|
1952
2385
|
});
|
|
@@ -1960,7 +2393,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1960
2393
|
break;
|
|
1961
2394
|
}
|
|
1962
2395
|
++maxPolls;
|
|
1963
|
-
const res = yield this.ctx.client.getWallets(this.userId);
|
|
2396
|
+
const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId);
|
|
1964
2397
|
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
1965
2398
|
if (wallet && wallet.address) {
|
|
1966
2399
|
return;
|
|
@@ -2074,7 +2507,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2074
2507
|
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
2075
2508
|
emailProps: this.getBackupKitEmailProps(),
|
|
2076
2509
|
partnerId: newPartnerId,
|
|
2077
|
-
protocolId
|
|
2510
|
+
protocolId,
|
|
2511
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2512
|
+
walletScheme: this.wallets[walletId].scheme
|
|
2078
2513
|
});
|
|
2079
2514
|
return { signer, recoverySecret, protocolId };
|
|
2080
2515
|
});
|
|
@@ -2123,26 +2558,29 @@ const _ParaCore = class _ParaCore {
|
|
|
2123
2558
|
}
|
|
2124
2559
|
}
|
|
2125
2560
|
const walletId = keygenRes.walletId;
|
|
2561
|
+
const walletScheme = walletType === "SOLANA" ? "ED25519" : "DKLS";
|
|
2126
2562
|
signer = keygenRes.signer;
|
|
2127
|
-
this.
|
|
2128
|
-
id: walletId,
|
|
2129
|
-
signer,
|
|
2130
|
-
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
2131
|
-
type: walletType
|
|
2132
|
-
};
|
|
2133
|
-
wallet = this.wallets[walletId];
|
|
2134
|
-
yield this.waitForWalletAddress(wallet.id);
|
|
2135
|
-
yield this.populateWalletAddresses();
|
|
2563
|
+
yield this.waitForWalletAddress(walletId);
|
|
2136
2564
|
let recoveryShare = null;
|
|
2137
2565
|
if (!skipDistribute) {
|
|
2138
2566
|
recoveryShare = yield distributeNewShare({
|
|
2139
2567
|
ctx: this.ctx,
|
|
2140
2568
|
userId: this.userId,
|
|
2141
|
-
walletId
|
|
2569
|
+
walletId,
|
|
2142
2570
|
userShare: signer,
|
|
2143
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2571
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
2572
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2573
|
+
walletScheme
|
|
2144
2574
|
});
|
|
2145
2575
|
}
|
|
2576
|
+
this.wallets[walletId] = {
|
|
2577
|
+
id: walletId,
|
|
2578
|
+
signer,
|
|
2579
|
+
scheme: walletScheme,
|
|
2580
|
+
type: walletType
|
|
2581
|
+
};
|
|
2582
|
+
wallet = this.wallets[walletId];
|
|
2583
|
+
yield this.populateWalletAddresses();
|
|
2146
2584
|
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
2147
2585
|
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
2148
2586
|
}));
|
|
@@ -2221,7 +2659,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2221
2659
|
walletId: wallet.id,
|
|
2222
2660
|
userShare: this.wallets[wallet.id].signer,
|
|
2223
2661
|
emailProps: this.getBackupKitEmailProps(),
|
|
2224
|
-
partnerId: wallet.partnerId
|
|
2662
|
+
partnerId: wallet.partnerId,
|
|
2663
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2664
|
+
walletScheme: wallet.scheme
|
|
2225
2665
|
});
|
|
2226
2666
|
if (distributeRes.length > 0) {
|
|
2227
2667
|
newRecoverySecret = distributeRes;
|
|
@@ -2348,10 +2788,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2348
2788
|
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, wallets);
|
|
2349
2789
|
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2350
2790
|
return wallets;
|
|
2351
|
-
} catch (
|
|
2352
|
-
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, null,
|
|
2791
|
+
} catch (error2) {
|
|
2792
|
+
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, null, error2 == null ? void 0 : error2.message);
|
|
2353
2793
|
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2354
|
-
throw
|
|
2794
|
+
throw error2;
|
|
2355
2795
|
}
|
|
2356
2796
|
});
|
|
2357
2797
|
}
|
|
@@ -2399,25 +2839,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2399
2839
|
});
|
|
2400
2840
|
});
|
|
2401
2841
|
}
|
|
2402
|
-
getOnRampTransactionUrl(
|
|
2403
|
-
return __async(this,
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
providerKey
|
|
2407
|
-
} = _n, walletParams = __objRest(_n, [
|
|
2408
|
-
"purchaseId",
|
|
2409
|
-
"providerKey"
|
|
2410
|
-
]);
|
|
2411
|
-
const { sessionId } = yield this.touchSession();
|
|
2412
|
-
const [key, identifier] = extractWalletRef(walletParams);
|
|
2842
|
+
getOnRampTransactionUrl(_0) {
|
|
2843
|
+
return __async(this, arguments, function* ({
|
|
2844
|
+
purchaseId
|
|
2845
|
+
}) {
|
|
2413
2846
|
return this.constructPortalUrl("onRamp", {
|
|
2414
|
-
pathId: purchaseId
|
|
2415
|
-
sessionId,
|
|
2416
|
-
params: {
|
|
2417
|
-
[key]: identifier,
|
|
2418
|
-
providerKey,
|
|
2419
|
-
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
2420
|
-
}
|
|
2847
|
+
pathId: purchaseId
|
|
2421
2848
|
});
|
|
2422
2849
|
});
|
|
2423
2850
|
}
|
|
@@ -2442,6 +2869,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2442
2869
|
onCancel,
|
|
2443
2870
|
onPoll
|
|
2444
2871
|
}) {
|
|
2872
|
+
var _a;
|
|
2445
2873
|
this.assertIsValidWalletId(walletId);
|
|
2446
2874
|
const wallet = this.wallets[walletId];
|
|
2447
2875
|
let signerId = this.userId;
|
|
@@ -2451,7 +2879,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2451
2879
|
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2452
2880
|
let timeStart = Date.now();
|
|
2453
2881
|
if (signRes.pendingTransactionId) {
|
|
2454
|
-
this.platformUtils.openPopup(
|
|
2882
|
+
yield this.platformUtils.openPopup(
|
|
2455
2883
|
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2456
2884
|
{ type: cosmosSignDocBase64 ? PopupType.SIGN_TRANSACTION_REVIEW : PopupType.SIGN_MESSAGE_REVIEW }
|
|
2457
2885
|
);
|
|
@@ -2465,18 +2893,19 @@ const _ParaCore = class _ParaCore {
|
|
|
2465
2893
|
break;
|
|
2466
2894
|
}
|
|
2467
2895
|
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2896
|
+
let pendingTransaction;
|
|
2468
2897
|
try {
|
|
2469
|
-
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2470
|
-
} catch (
|
|
2898
|
+
pendingTransaction = (_a = (yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId)).data) == null ? void 0 : _a.pendingTransaction;
|
|
2899
|
+
} catch (e) {
|
|
2471
2900
|
const error = new TransactionReviewDenied();
|
|
2472
2901
|
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2473
2902
|
throw error;
|
|
2474
2903
|
}
|
|
2475
|
-
|
|
2476
|
-
if (signRes.pendingTransactionId) {
|
|
2904
|
+
if (!(pendingTransaction == null ? void 0 : pendingTransaction.approvedAt)) {
|
|
2477
2905
|
onPoll == null ? void 0 : onPoll();
|
|
2478
2906
|
continue;
|
|
2479
2907
|
} else {
|
|
2908
|
+
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2480
2909
|
break;
|
|
2481
2910
|
}
|
|
2482
2911
|
}
|
|
@@ -2545,6 +2974,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2545
2974
|
onCancel,
|
|
2546
2975
|
onPoll
|
|
2547
2976
|
}) {
|
|
2977
|
+
var _a;
|
|
2548
2978
|
this.assertIsValidWalletId(walletId);
|
|
2549
2979
|
const wallet = this.wallets[walletId];
|
|
2550
2980
|
let signerId = this.userId;
|
|
@@ -2563,7 +2993,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2563
2993
|
);
|
|
2564
2994
|
let timeStart = Date.now();
|
|
2565
2995
|
if (signRes.pendingTransactionId) {
|
|
2566
|
-
this.platformUtils.openPopup(
|
|
2996
|
+
yield this.platformUtils.openPopup(
|
|
2567
2997
|
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2568
2998
|
{ type: PopupType.SIGN_TRANSACTION_REVIEW }
|
|
2569
2999
|
);
|
|
@@ -2577,27 +3007,28 @@ const _ParaCore = class _ParaCore {
|
|
|
2577
3007
|
break;
|
|
2578
3008
|
}
|
|
2579
3009
|
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
3010
|
+
let pendingTransaction;
|
|
2580
3011
|
try {
|
|
2581
|
-
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2582
|
-
} catch (
|
|
3012
|
+
pendingTransaction = (_a = (yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId)).data) == null ? void 0 : _a.pendingTransaction;
|
|
3013
|
+
} catch (e) {
|
|
2583
3014
|
const error = new TransactionReviewDenied();
|
|
2584
3015
|
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
2585
3016
|
throw error;
|
|
2586
3017
|
}
|
|
2587
|
-
|
|
2588
|
-
this.ctx,
|
|
2589
|
-
signerId,
|
|
2590
|
-
walletId,
|
|
2591
|
-
this.wallets[walletId].signer,
|
|
2592
|
-
rlpEncodedTxBase64,
|
|
2593
|
-
chainId,
|
|
2594
|
-
this.retrieveSessionCookie(),
|
|
2595
|
-
wallet.scheme === "DKLS"
|
|
2596
|
-
);
|
|
2597
|
-
if (signRes.pendingTransactionId) {
|
|
3018
|
+
if (!(pendingTransaction == null ? void 0 : pendingTransaction.approvedAt)) {
|
|
2598
3019
|
onPoll == null ? void 0 : onPoll();
|
|
2599
3020
|
continue;
|
|
2600
3021
|
} else {
|
|
3022
|
+
signRes = yield this.platformUtils.signTransaction(
|
|
3023
|
+
this.ctx,
|
|
3024
|
+
signerId,
|
|
3025
|
+
walletId,
|
|
3026
|
+
this.wallets[walletId].signer,
|
|
3027
|
+
rlpEncodedTxBase64,
|
|
3028
|
+
chainId,
|
|
3029
|
+
this.retrieveSessionCookie(),
|
|
3030
|
+
wallet.scheme === "DKLS"
|
|
3031
|
+
);
|
|
2601
3032
|
break;
|
|
2602
3033
|
}
|
|
2603
3034
|
}
|
|
@@ -2639,7 +3070,8 @@ const _ParaCore = class _ParaCore {
|
|
|
2639
3070
|
providerKey: onRampPurchase.providerKey
|
|
2640
3071
|
}, walletParams));
|
|
2641
3072
|
if (shouldOpenPopup) {
|
|
2642
|
-
this.platformUtils.openPopup(portalUrl, { type: PopupType.ON_RAMP_TRANSACTION });
|
|
3073
|
+
const onRampWindow = yield this.platformUtils.openPopup(portalUrl, { type: PopupType.ON_RAMP_TRANSACTION });
|
|
3074
|
+
this.onRampPopup = { window: onRampWindow, onRampPurchase };
|
|
2643
3075
|
}
|
|
2644
3076
|
return { onRampPurchase, portalUrl };
|
|
2645
3077
|
});
|
|
@@ -2652,7 +3084,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2652
3084
|
try {
|
|
2653
3085
|
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
2654
3086
|
return true;
|
|
2655
|
-
} catch (
|
|
3087
|
+
} catch (e) {
|
|
2656
3088
|
return false;
|
|
2657
3089
|
}
|
|
2658
3090
|
});
|
|
@@ -2724,8 +3156,16 @@ const _ParaCore = class _ParaCore {
|
|
|
2724
3156
|
}
|
|
2725
3157
|
issueJwt() {
|
|
2726
3158
|
return __async(this, arguments, function* ({ keyIndex = 0 } = {}) {
|
|
2727
|
-
|
|
2728
|
-
|
|
3159
|
+
try {
|
|
3160
|
+
return yield this.ctx.client.issueJwt({ keyIndex });
|
|
3161
|
+
} catch (error) {
|
|
3162
|
+
if (error.status === 403 || error.status === 401) {
|
|
3163
|
+
const errorMessage = "The user needs to be logged in to issue a JWT. Please log in and try again.";
|
|
3164
|
+
this.displayModalError(errorMessage);
|
|
3165
|
+
console.warn(errorMessage);
|
|
3166
|
+
}
|
|
3167
|
+
throw error;
|
|
3168
|
+
}
|
|
2729
3169
|
});
|
|
2730
3170
|
}
|
|
2731
3171
|
/**
|
|
@@ -2735,6 +3175,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2735
3175
|
**/
|
|
2736
3176
|
logout() {
|
|
2737
3177
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3178
|
+
const shouldDispatchLogoutEvent = yield this.isSessionActive();
|
|
2738
3179
|
yield this.ctx.client.logout();
|
|
2739
3180
|
yield this.clearStorage();
|
|
2740
3181
|
if (!clearPregenWallets) {
|
|
@@ -2754,7 +3195,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2754
3195
|
this.accountLinkInProgress = void 0;
|
|
2755
3196
|
this.userId = void 0;
|
|
2756
3197
|
this.sessionCookie = void 0;
|
|
2757
|
-
|
|
3198
|
+
if (shouldDispatchLogoutEvent) {
|
|
3199
|
+
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
3200
|
+
}
|
|
2758
3201
|
});
|
|
2759
3202
|
}
|
|
2760
3203
|
get toStringAdditions() {
|
|
@@ -2784,9 +3227,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2784
3227
|
{}
|
|
2785
3228
|
);
|
|
2786
3229
|
const obj = __spreadProps(__spreadValues({
|
|
2787
|
-
partnerId: (_a =
|
|
2788
|
-
supportedWalletTypes: (_b =
|
|
2789
|
-
cosmosPrefix: (_c =
|
|
3230
|
+
partnerId: (_a = this.partner) == null ? void 0 : _a.id,
|
|
3231
|
+
supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
|
|
3232
|
+
cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
|
|
2790
3233
|
authInfo: __privateGet(this, _authInfo),
|
|
2791
3234
|
isGuestMode: this.isGuestMode,
|
|
2792
3235
|
userId: this.userId,
|
|
@@ -2818,43 +3261,88 @@ const _ParaCore = class _ParaCore {
|
|
|
2818
3261
|
}
|
|
2819
3262
|
getNewCredentialAndUrl() {
|
|
2820
3263
|
return __async(this, arguments, function* ({
|
|
2821
|
-
authMethod
|
|
3264
|
+
authMethod: optsAuthMethod,
|
|
2822
3265
|
isForNewDevice = false,
|
|
2823
3266
|
portalTheme,
|
|
2824
3267
|
shorten = false
|
|
2825
3268
|
} = {}) {
|
|
3269
|
+
const userAuthMethods = yield this.supportedUserAuthMethods();
|
|
3270
|
+
const isEnclaveUser = userAuthMethods.has(AuthMethod.BASIC_LOGIN);
|
|
3271
|
+
const isAddingBasicLogin = optsAuthMethod === "BASIC_LOGIN";
|
|
3272
|
+
if (isEnclaveUser && isAddingBasicLogin) {
|
|
3273
|
+
throw new Error("That user is already using basic login");
|
|
3274
|
+
}
|
|
3275
|
+
if (isEnclaveUser || isAddingBasicLogin) {
|
|
3276
|
+
isForNewDevice = true;
|
|
3277
|
+
}
|
|
3278
|
+
const authMethods = optsAuthMethod ? [optsAuthMethod] : isForNewDevice ? ["PASSKEY", "PIN", "PASSWORD"] : ["PASSKEY"];
|
|
2826
3279
|
this.assertIsAuthSet();
|
|
2827
|
-
let
|
|
2828
|
-
|
|
2829
|
-
|
|
3280
|
+
let passkeyId, passwordId, urlType, credentialId;
|
|
3281
|
+
if (!isAddingBasicLogin) {
|
|
3282
|
+
const canAddPasswordOrPIN = !userAuthMethods.has(AuthMethod.PASSWORD) && !userAuthMethods.has(AuthMethod.PIN);
|
|
3283
|
+
if (authMethods.includes("PASSKEY") && (yield this.isPasskeySupported())) {
|
|
2830
3284
|
({
|
|
2831
|
-
data: { id:
|
|
3285
|
+
data: { id: passkeyId }
|
|
2832
3286
|
} = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2833
|
-
status:
|
|
3287
|
+
status: AuthMethodStatus.PENDING,
|
|
2834
3288
|
type: PublicKeyType.WEB
|
|
2835
3289
|
}));
|
|
2836
3290
|
urlType = "createAuth";
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
({
|
|
2840
|
-
|
|
2841
|
-
}
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
3291
|
+
}
|
|
3292
|
+
if (authMethods.includes("PASSWORD")) {
|
|
3293
|
+
if (!canAddPasswordOrPIN) {
|
|
3294
|
+
if (optsAuthMethod === "PASSWORD") throw new Error("A user cannot have more than one password or PIN.");
|
|
3295
|
+
} else {
|
|
3296
|
+
({
|
|
3297
|
+
data: { id: passwordId }
|
|
3298
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3299
|
+
status: AuthMethodStatus.PENDING
|
|
3300
|
+
}));
|
|
3301
|
+
urlType = "createPassword";
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
if (authMethods.includes("PIN")) {
|
|
3305
|
+
if (!canAddPasswordOrPIN) {
|
|
3306
|
+
if (optsAuthMethod === "PIN") throw new Error("A user cannot have more than one password or PIN.");
|
|
3307
|
+
} else {
|
|
3308
|
+
({
|
|
3309
|
+
data: { id: passwordId }
|
|
3310
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3311
|
+
status: AuthMethodStatus.PENDING
|
|
3312
|
+
}));
|
|
3313
|
+
urlType = "createPIN";
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
credentialId = passkeyId != null ? passkeyId : passwordId;
|
|
3317
|
+
if (this.isNativePasskey && authMethods.includes("PASSKEY")) {
|
|
3318
|
+
return { credentialId };
|
|
3319
|
+
}
|
|
2846
3320
|
}
|
|
2847
|
-
const
|
|
3321
|
+
const { sessionId } = yield this.touchSession();
|
|
3322
|
+
const url = (isForNewDevice || urlType) && (yield this.constructPortalUrl(isForNewDevice ? "addNewCredential" : urlType, {
|
|
2848
3323
|
isForNewDevice,
|
|
2849
3324
|
pathId: credentialId,
|
|
2850
3325
|
portalTheme,
|
|
2851
|
-
shorten
|
|
2852
|
-
|
|
3326
|
+
shorten,
|
|
3327
|
+
sessionId: isForNewDevice ? sessionId : void 0,
|
|
3328
|
+
addNewCredentialType: optsAuthMethod,
|
|
3329
|
+
addNewCredentialPasskeyId: passkeyId,
|
|
3330
|
+
addNewCredentialPasswordId: passwordId
|
|
3331
|
+
}));
|
|
2853
3332
|
return __spreadValues({ credentialId }, url ? { url } : {});
|
|
2854
3333
|
});
|
|
2855
3334
|
}
|
|
3335
|
+
addCredential(_0) {
|
|
3336
|
+
return __async(this, arguments, function* ({ authMethod }) {
|
|
3337
|
+
if (authMethod === "PASSKEY" && !(yield this.isPasskeySupported())) {
|
|
3338
|
+
throw new Error("Passkeys are not supported.");
|
|
3339
|
+
}
|
|
3340
|
+
const { url } = yield this.getNewCredentialAndUrl({ isForNewDevice: true, authMethod });
|
|
3341
|
+
return url;
|
|
3342
|
+
});
|
|
3343
|
+
}
|
|
2856
3344
|
/**
|
|
2857
|
-
* Returns a Para Portal URL for logging in with a WebAuth passkey or
|
|
3345
|
+
* Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
|
|
2858
3346
|
* @param {Object} opts the options object
|
|
2859
3347
|
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
2860
3348
|
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
@@ -2880,6 +3368,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2880
3368
|
case "PASSWORD":
|
|
2881
3369
|
urlType = "loginPassword";
|
|
2882
3370
|
break;
|
|
3371
|
+
case "PIN":
|
|
3372
|
+
urlType = "loginPIN";
|
|
3373
|
+
break;
|
|
3374
|
+
case "BASIC_LOGIN":
|
|
3375
|
+
urlType = this.authInfo.authType === "externalWallet" ? "loginExternalWallet" : "loginOTP";
|
|
3376
|
+
break;
|
|
2883
3377
|
default:
|
|
2884
3378
|
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
2885
3379
|
}
|
|
@@ -2890,10 +3384,30 @@ const _ParaCore = class _ParaCore {
|
|
|
2890
3384
|
});
|
|
2891
3385
|
});
|
|
2892
3386
|
}
|
|
2893
|
-
|
|
3387
|
+
prepareLogin() {
|
|
3388
|
+
return __async(this, null, function* () {
|
|
3389
|
+
yield this.logout();
|
|
3390
|
+
const { sessionLookupId } = yield this.touchSession(true);
|
|
3391
|
+
if (!this.loginEncryptionKeyPair) {
|
|
3392
|
+
yield this.setLoginEncryptionKeyPair();
|
|
3393
|
+
}
|
|
3394
|
+
return sessionLookupId;
|
|
3395
|
+
});
|
|
3396
|
+
}
|
|
3397
|
+
signUpOrLogIn(_i) {
|
|
2894
3398
|
return __async(this, null, function* () {
|
|
2895
|
-
var
|
|
2896
|
-
|
|
3399
|
+
var _j = _i, { auth } = _j, urlOptions = __objRest(_j, ["auth"]);
|
|
3400
|
+
let serverAuthState;
|
|
3401
|
+
try {
|
|
3402
|
+
serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
3403
|
+
} catch (error) {
|
|
3404
|
+
if (error.message.includes("max beta users reached")) {
|
|
3405
|
+
this.displayModalError(
|
|
3406
|
+
`50 user limit reached. [Go to Production.](https://docs.getpara.com/v2/general/checklist#go-live-checklist)`
|
|
3407
|
+
);
|
|
3408
|
+
}
|
|
3409
|
+
throw error;
|
|
3410
|
+
}
|
|
2897
3411
|
const authInfo = serverAuthState.auth;
|
|
2898
3412
|
if (this.fetchPregenWalletsOverride && isPregenAuth(authInfo)) {
|
|
2899
3413
|
const { userShare } = yield this.fetchPregenWalletsOverride({ pregenId: authInfo });
|
|
@@ -2901,21 +3415,25 @@ const _ParaCore = class _ParaCore {
|
|
|
2901
3415
|
yield this.setUserShare(userShare);
|
|
2902
3416
|
}
|
|
2903
3417
|
}
|
|
2904
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3418
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadValues({}, urlOptions));
|
|
2905
3419
|
});
|
|
2906
3420
|
}
|
|
2907
|
-
verifyNewAccount(
|
|
3421
|
+
verifyNewAccount(_k) {
|
|
2908
3422
|
return __async(this, null, function* () {
|
|
2909
|
-
var
|
|
3423
|
+
var _l = _k, {
|
|
2910
3424
|
verificationCode
|
|
2911
|
-
} =
|
|
3425
|
+
} = _l, urlOptions = __objRest(_l, [
|
|
2912
3426
|
"verificationCode"
|
|
2913
3427
|
]);
|
|
2914
3428
|
this.assertIsAuthSet(["email", "phone"]);
|
|
2915
|
-
const userId = this.assertUserId();
|
|
2916
|
-
const serverAuthState = yield this.ctx.client.
|
|
3429
|
+
const userId = this.assertUserId({ allowGuestMode: true });
|
|
3430
|
+
const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
|
|
2917
3431
|
verificationCode
|
|
2918
3432
|
});
|
|
3433
|
+
if (serverAuthState.stage === "login" || serverAuthState.stage === "done") {
|
|
3434
|
+
throw new Error("Account already exists.");
|
|
3435
|
+
}
|
|
3436
|
+
yield this.touchSession(true);
|
|
2919
3437
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2920
3438
|
});
|
|
2921
3439
|
}
|
|
@@ -2963,7 +3481,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2963
3481
|
}
|
|
2964
3482
|
break;
|
|
2965
3483
|
default:
|
|
2966
|
-
throw new Error("Invalid parameters for linking account, must pass `auth` or `type` or `externalWallet");
|
|
3484
|
+
throw new Error("Invalid parameters for linking account, must pass `auth` or `type` or `externalWallet`");
|
|
2967
3485
|
}
|
|
2968
3486
|
if (!isPermitted) {
|
|
2969
3487
|
throw new Error(`Account linking for type '${type}' is not supported by the current API key configuration`);
|
|
@@ -3002,10 +3520,10 @@ const _ParaCore = class _ParaCore {
|
|
|
3002
3520
|
});
|
|
3003
3521
|
}
|
|
3004
3522
|
verifyLink() {
|
|
3005
|
-
return __async(this, arguments, function* (
|
|
3006
|
-
var
|
|
3523
|
+
return __async(this, arguments, function* (_m = {}) {
|
|
3524
|
+
var _n = _m, {
|
|
3007
3525
|
accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
|
|
3008
|
-
} =
|
|
3526
|
+
} = _n, opts = __objRest(_n, [
|
|
3009
3527
|
"accountLinkInProgress"
|
|
3010
3528
|
]);
|
|
3011
3529
|
try {
|
|
@@ -3034,31 +3552,80 @@ const _ParaCore = class _ParaCore {
|
|
|
3034
3552
|
return accounts;
|
|
3035
3553
|
});
|
|
3036
3554
|
}
|
|
3555
|
+
getProfileBalance() {
|
|
3556
|
+
return __async(this, arguments, function* ({ config, refetch = false } = {}) {
|
|
3557
|
+
const { balance } = yield this.ctx.client.getProfileBalance({
|
|
3558
|
+
config,
|
|
3559
|
+
wallets: this.availableWallets.filter(({ type }) => type !== "COSMOS").map(({ type, address }) => ({ type, address })),
|
|
3560
|
+
refetch
|
|
3561
|
+
});
|
|
3562
|
+
return balance;
|
|
3563
|
+
});
|
|
3564
|
+
}
|
|
3565
|
+
sendLoginCode() {
|
|
3566
|
+
return __async(this, null, function* () {
|
|
3567
|
+
const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
|
|
3568
|
+
this.setUserId(userId);
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3571
|
+
exportPrivateKey() {
|
|
3572
|
+
return __async(this, arguments, function* (args = {}) {
|
|
3573
|
+
let walletId = args == null ? void 0 : args.walletId;
|
|
3574
|
+
if (!(args == null ? void 0 : args.walletId)) {
|
|
3575
|
+
walletId = this.findWalletId(void 0, { forbidPregen: true, scheme: ["DKLS"] });
|
|
3576
|
+
}
|
|
3577
|
+
const wallet = this.wallets[walletId];
|
|
3578
|
+
if (this.externalWallets[walletId]) {
|
|
3579
|
+
throw new Error("Cannot export private key for an external wallet");
|
|
3580
|
+
}
|
|
3581
|
+
if (!wallet || !wallet.signer) {
|
|
3582
|
+
throw new Error("Wallet not found with id: " + walletId);
|
|
3583
|
+
}
|
|
3584
|
+
if (wallet.scheme !== "DKLS") {
|
|
3585
|
+
throw new Error("Cannot export private key for a Solana wallet");
|
|
3586
|
+
}
|
|
3587
|
+
if (wallet.isPregen && !!wallet.pregenIdentifier && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
3588
|
+
throw new Error("Cannot export private key for a pregenerated wallet");
|
|
3589
|
+
}
|
|
3590
|
+
if (args.shouldOpenPopup) {
|
|
3591
|
+
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.EXPORT_PRIVATE_KEY });
|
|
3592
|
+
}
|
|
3593
|
+
const exportPrivateKeyUrl = yield this.constructPortalUrl("exportPrivateKey", {
|
|
3594
|
+
pathId: walletId
|
|
3595
|
+
});
|
|
3596
|
+
if (args.shouldOpenPopup) {
|
|
3597
|
+
this.popupWindow.location.href = exportPrivateKeyUrl;
|
|
3598
|
+
}
|
|
3599
|
+
return {
|
|
3600
|
+
url: exportPrivateKeyUrl,
|
|
3601
|
+
popupWindow: this.popupWindow
|
|
3602
|
+
};
|
|
3603
|
+
});
|
|
3604
|
+
}
|
|
3037
3605
|
};
|
|
3038
3606
|
_authInfo = new WeakMap();
|
|
3039
|
-
_partner = new WeakMap();
|
|
3040
3607
|
_ParaCore_instances = new WeakSet();
|
|
3041
3608
|
assertPartner_fn = function() {
|
|
3042
3609
|
return __async(this, null, function* () {
|
|
3043
3610
|
var _a, _b;
|
|
3044
|
-
if (!
|
|
3611
|
+
if (!this.partner) {
|
|
3045
3612
|
yield this.touchSession();
|
|
3046
3613
|
}
|
|
3047
|
-
if (((_a =
|
|
3048
|
-
this.ctx.cosmosPrefix = (_b =
|
|
3614
|
+
if (((_a = this.partner) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== this.partner.cosmosPrefix) {
|
|
3615
|
+
this.ctx.cosmosPrefix = (_b = this.partner) == null ? void 0 : _b.cosmosPrefix;
|
|
3049
3616
|
}
|
|
3050
|
-
return
|
|
3617
|
+
return this.partner;
|
|
3051
3618
|
});
|
|
3052
3619
|
};
|
|
3053
3620
|
guestWalletIds_get = function() {
|
|
3054
3621
|
var _a, _b, _c;
|
|
3055
|
-
if (!((_a =
|
|
3622
|
+
if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
3056
3623
|
return {};
|
|
3057
3624
|
}
|
|
3058
3625
|
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
3059
3626
|
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
3060
3627
|
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
3061
|
-
return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) =>
|
|
3628
|
+
return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
3062
3629
|
var _a2;
|
|
3063
3630
|
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
3064
3631
|
}, {}));
|
|
@@ -3119,8 +3686,8 @@ getPartner_fn = function(partnerId) {
|
|
|
3119
3686
|
return void 0;
|
|
3120
3687
|
}
|
|
3121
3688
|
const res = yield this.ctx.client.getPartner(partnerId);
|
|
3122
|
-
|
|
3123
|
-
return
|
|
3689
|
+
this.partner = res.data.partner;
|
|
3690
|
+
return this.partner;
|
|
3124
3691
|
});
|
|
3125
3692
|
};
|
|
3126
3693
|
assertIsLinkingAccount_fn = function(types) {
|
|
@@ -3142,29 +3709,212 @@ assertIsLinkingAccountOrStart_fn = function(type) {
|
|
|
3142
3709
|
return yield this.linkAccount({ type });
|
|
3143
3710
|
});
|
|
3144
3711
|
};
|
|
3145
|
-
getOAuthUrl_fn = function(
|
|
3146
|
-
return __async(this,
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3712
|
+
getOAuthUrl_fn = function(_0) {
|
|
3713
|
+
return __async(this, arguments, function* ({
|
|
3714
|
+
method,
|
|
3715
|
+
appScheme,
|
|
3716
|
+
accountLinkInProgress,
|
|
3717
|
+
sessionLookupId,
|
|
3718
|
+
encryptionKey,
|
|
3719
|
+
portalCallbackParams
|
|
3720
|
+
}) {
|
|
3721
|
+
if (!accountLinkInProgress && !this.isPortal()) {
|
|
3722
|
+
return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
|
|
3723
|
+
}
|
|
3724
|
+
let portalSessionLookupId;
|
|
3725
|
+
if (this.isPortal()) {
|
|
3726
|
+
portalSessionLookupId = (yield this.touchSession(true)).sessionLookupId;
|
|
3727
|
+
}
|
|
3158
3728
|
return constructUrl({
|
|
3159
3729
|
base: getBaseOAuthUrl(this.ctx.env),
|
|
3160
|
-
path: `/auth/${method}`,
|
|
3161
|
-
params: __spreadValues({
|
|
3730
|
+
path: `/auth/${method.toLowerCase()}`,
|
|
3731
|
+
params: __spreadProps(__spreadValues({
|
|
3162
3732
|
apiKey: this.ctx.apiKey,
|
|
3733
|
+
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
3163
3734
|
sessionLookupId,
|
|
3735
|
+
portalSessionLookupId,
|
|
3164
3736
|
appScheme
|
|
3165
3737
|
}, accountLinkInProgress ? {
|
|
3166
3738
|
linkedAccountId: this.accountLinkInProgress.id
|
|
3167
|
-
} : {})
|
|
3739
|
+
} : {}), {
|
|
3740
|
+
callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", __spreadValues({
|
|
3741
|
+
sessionId: sessionLookupId,
|
|
3742
|
+
oAuthMethod: method,
|
|
3743
|
+
appScheme,
|
|
3744
|
+
thisDevice: {
|
|
3745
|
+
sessionId: sessionLookupId,
|
|
3746
|
+
encryptionKey
|
|
3747
|
+
}
|
|
3748
|
+
}, this.isPortal() && {
|
|
3749
|
+
params: portalCallbackParams,
|
|
3750
|
+
// Build callback for legacy portal if needed
|
|
3751
|
+
useLegacyUrl: typeof window !== "undefined" ? window.location.host.includes("usecapsule") : false
|
|
3752
|
+
})))
|
|
3753
|
+
})
|
|
3754
|
+
});
|
|
3755
|
+
});
|
|
3756
|
+
};
|
|
3757
|
+
waitForLoginProcess_fn = function() {
|
|
3758
|
+
return __async(this, arguments, function* ({
|
|
3759
|
+
isCanceled = () => false,
|
|
3760
|
+
onCancel,
|
|
3761
|
+
onPoll,
|
|
3762
|
+
skipSessionRefresh = false,
|
|
3763
|
+
isSwitchingWallets = false
|
|
3764
|
+
} = {}) {
|
|
3765
|
+
this.devLog("[waitForLoginProcess] Starting", {
|
|
3766
|
+
isSwitchingWallets,
|
|
3767
|
+
skipSessionRefresh,
|
|
3768
|
+
isExternalWalletAuth: this.isExternalWalletAuth
|
|
3769
|
+
});
|
|
3770
|
+
const startedAt = Date.now();
|
|
3771
|
+
let originalCurrentWalletIdsHash;
|
|
3772
|
+
if (isSwitchingWallets) {
|
|
3773
|
+
this.devLog("[waitForLoginProcess] Wallet switching mode enabled");
|
|
3774
|
+
this.isSwitchingWallets = true;
|
|
3775
|
+
const session = yield this.touchSession();
|
|
3776
|
+
originalCurrentWalletIdsHash = session.currentWalletIdsHash;
|
|
3777
|
+
this.devLog("[waitForLoginProcess] Original wallet IDs hash", { originalCurrentWalletIdsHash });
|
|
3778
|
+
}
|
|
3779
|
+
return new Promise((resolve, reject) => {
|
|
3780
|
+
(() => __async(this, null, function* () {
|
|
3781
|
+
var _a;
|
|
3782
|
+
if (!this.isExternalWalletAuth && !isSwitchingWallets) {
|
|
3783
|
+
this.devLog("[waitForLoginProcess] Clearing external wallets");
|
|
3784
|
+
this.externalWallets = {};
|
|
3785
|
+
}
|
|
3786
|
+
let pollCount = 0;
|
|
3787
|
+
while (true) {
|
|
3788
|
+
pollCount++;
|
|
3789
|
+
this.devLog("[waitForLoginProcess] Poll iteration", {
|
|
3790
|
+
pollCount,
|
|
3791
|
+
elapsedMs: Date.now() - startedAt
|
|
3792
|
+
});
|
|
3793
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
3794
|
+
this.devLog("[waitForLoginProcess] Canceled or timed out", {
|
|
3795
|
+
wasCanceled: isCanceled(),
|
|
3796
|
+
timedOut: Date.now() - startedAt > constants.POLLING_TIMEOUT_MS,
|
|
3797
|
+
elapsedMs: Date.now() - startedAt
|
|
3798
|
+
});
|
|
3799
|
+
if (isSwitchingWallets) {
|
|
3800
|
+
this.isSwitchingWallets = false;
|
|
3801
|
+
} else {
|
|
3802
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
|
|
3803
|
+
}
|
|
3804
|
+
onCancel == null ? void 0 : onCancel();
|
|
3805
|
+
return reject("canceled");
|
|
3806
|
+
}
|
|
3807
|
+
yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
|
|
3808
|
+
try {
|
|
3809
|
+
this.devLog("[waitForLoginProcess] Touching session");
|
|
3810
|
+
let session = yield this.touchSession();
|
|
3811
|
+
this.devLog("[waitForLoginProcess] Session state", {
|
|
3812
|
+
isAuthenticated: session.isAuthenticated,
|
|
3813
|
+
currentWalletIdsHash: session.currentWalletIdsHash,
|
|
3814
|
+
needsWallet: session.needsWallet
|
|
3815
|
+
});
|
|
3816
|
+
const shouldContinuePolling = isSwitchingWallets ? originalCurrentWalletIdsHash === session.currentWalletIdsHash : !session.isAuthenticated;
|
|
3817
|
+
this.devLog("[waitForLoginProcess] Should continue polling", {
|
|
3818
|
+
shouldContinuePolling,
|
|
3819
|
+
isSwitchingWallets,
|
|
3820
|
+
originalCurrentWalletIdsHash,
|
|
3821
|
+
sessionCurrentWalletIdsHash: session.currentWalletIdsHash,
|
|
3822
|
+
isAuthenticated: session.isAuthenticated
|
|
3823
|
+
});
|
|
3824
|
+
if (shouldContinuePolling) {
|
|
3825
|
+
onPoll == null ? void 0 : onPoll();
|
|
3826
|
+
continue;
|
|
3827
|
+
}
|
|
3828
|
+
this.devLog("[waitForLoginProcess] Authentication check passed, setting up user");
|
|
3829
|
+
session = yield this.userSetupAfterLogin();
|
|
3830
|
+
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
3831
|
+
this.devLog("[waitForLoginProcess] User setup complete", { needsWallet });
|
|
3832
|
+
if (isSwitchingWallets) {
|
|
3833
|
+
const isWalletSwitchingComplete = originalCurrentWalletIdsHash !== session.currentWalletIdsHash;
|
|
3834
|
+
this.devLog("[waitForLoginProcess] Wallet switching check", {
|
|
3835
|
+
isWalletSwitchingComplete,
|
|
3836
|
+
originalHash: originalCurrentWalletIdsHash,
|
|
3837
|
+
sessionHash: session.currentWalletIdsHash
|
|
3838
|
+
});
|
|
3839
|
+
if (!isWalletSwitchingComplete) {
|
|
3840
|
+
onPoll == null ? void 0 : onPoll();
|
|
3841
|
+
continue;
|
|
3842
|
+
}
|
|
3843
|
+
} else if (!needsWallet) {
|
|
3844
|
+
this.devLog("[waitForLoginProcess] Checking wallet IDs", {
|
|
3845
|
+
currentWalletIdsArrayLength: this.currentWalletIdsArray.length
|
|
3846
|
+
});
|
|
3847
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
3848
|
+
this.devLog("[waitForLoginProcess] No wallet IDs yet, continuing to poll");
|
|
3849
|
+
onPoll == null ? void 0 : onPoll();
|
|
3850
|
+
continue;
|
|
3851
|
+
}
|
|
3852
|
+
}
|
|
3853
|
+
this.devLog("[waitForLoginProcess] Getting transmission key shares");
|
|
3854
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
3855
|
+
this.devLog("[waitForLoginProcess] Transmission shares received", {
|
|
3856
|
+
shareCount: tempSharesRes.data.temporaryShares.length,
|
|
3857
|
+
shares: tempSharesRes.data.temporaryShares.map((s) => ({
|
|
3858
|
+
walletId: s.walletId,
|
|
3859
|
+
walletScheme: s.walletScheme
|
|
3860
|
+
}))
|
|
3861
|
+
});
|
|
3862
|
+
let hasSharesForCurrentWallets;
|
|
3863
|
+
if (!isSwitchingWallets && !this.isPortal()) {
|
|
3864
|
+
this.devLog("[waitForLoginProcess] Fetching wallets");
|
|
3865
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
3866
|
+
this.devLog("[waitForLoginProcess] Wallets fetched", {
|
|
3867
|
+
walletCount: fetchedWallets.length,
|
|
3868
|
+
wallets: fetchedWallets.map((w) => ({ id: w.id, type: w.type, scheme: w.scheme }))
|
|
3869
|
+
});
|
|
3870
|
+
hasSharesForCurrentWallets = tempSharesRes.data.temporaryShares.length === fetchedWallets.length;
|
|
3871
|
+
} else {
|
|
3872
|
+
hasSharesForCurrentWallets = this.currentWalletIdsArray.every(([walletId]) => {
|
|
3873
|
+
return tempSharesRes.data.temporaryShares.some((share) => share.walletId === walletId);
|
|
3874
|
+
});
|
|
3875
|
+
}
|
|
3876
|
+
this.devLog("[waitForLoginProcess] Checking shares for current wallets", {
|
|
3877
|
+
hasSharesForCurrentWallets,
|
|
3878
|
+
currentWalletIdsArray: this.currentWalletIdsArray,
|
|
3879
|
+
shares: tempSharesRes.data.temporaryShares.map((s) => ({
|
|
3880
|
+
walletId: s.walletId,
|
|
3881
|
+
walletScheme: s.walletScheme
|
|
3882
|
+
}))
|
|
3883
|
+
});
|
|
3884
|
+
if (hasSharesForCurrentWallets) {
|
|
3885
|
+
this.devLog("[waitForLoginProcess] Setting up after login");
|
|
3886
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
3887
|
+
this.devLog("[waitForLoginProcess] Setup after login complete");
|
|
3888
|
+
this.devLog("[waitForLoginProcess] Claiming pregen wallets");
|
|
3889
|
+
yield this.claimPregenWallets();
|
|
3890
|
+
this.devLog("[waitForLoginProcess] Pregen wallets claimed");
|
|
3891
|
+
const resp = {
|
|
3892
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
3893
|
+
partnerId: session.partnerId
|
|
3894
|
+
};
|
|
3895
|
+
this.devLog("[waitForLoginProcess] Login process complete", {
|
|
3896
|
+
needsWallet: resp.needsWallet,
|
|
3897
|
+
partnerId: resp.partnerId,
|
|
3898
|
+
walletCount: Object.values(this.wallets).length,
|
|
3899
|
+
isSwitchingWallets
|
|
3900
|
+
});
|
|
3901
|
+
if (isSwitchingWallets) {
|
|
3902
|
+
this.devLog("[waitForLoginProcess] Clearing wallet switching state");
|
|
3903
|
+
this.isSwitchingWallets = false;
|
|
3904
|
+
} else {
|
|
3905
|
+
this.devLog("[waitForLoginProcess] Dispatching LOGIN_EVENT");
|
|
3906
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp);
|
|
3907
|
+
}
|
|
3908
|
+
return resolve(resp);
|
|
3909
|
+
}
|
|
3910
|
+
this.devLog("[waitForLoginProcess] Not all shares available yet, continuing to poll");
|
|
3911
|
+
onPoll == null ? void 0 : onPoll();
|
|
3912
|
+
} catch (err) {
|
|
3913
|
+
console.error("[waitForLoginProcess] Error during polling iteration", err);
|
|
3914
|
+
onPoll == null ? void 0 : onPoll();
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
}))();
|
|
3168
3918
|
});
|
|
3169
3919
|
});
|
|
3170
3920
|
};
|
|
@@ -3218,8 +3968,9 @@ createPregenWallet_fn = function(opts) {
|
|
|
3218
3968
|
_isCreateGuestWalletsPending = new WeakMap();
|
|
3219
3969
|
prepareAuthState_fn = function(_0) {
|
|
3220
3970
|
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
3221
|
-
|
|
3222
|
-
|
|
3971
|
+
var _a, _b;
|
|
3972
|
+
if (!opts.sessionLookupId && serverAuthState.stage === "login" && (!serverAuthState.externalWallet || !(((_a = serverAuthState.externalWallet) == null ? void 0 : _a.withFullParaAuth) && ((_b = serverAuthState.loginAuthMethods) == null ? void 0 : _b.includes(AuthMethod.PIN))))) {
|
|
3973
|
+
opts.sessionLookupId = yield this.prepareLogin();
|
|
3223
3974
|
}
|
|
3224
3975
|
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
3225
3976
|
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), Object.fromEntries(
|
|
@@ -3240,8 +3991,14 @@ prepareAuthState_fn = function(_0) {
|
|
|
3240
3991
|
}
|
|
3241
3992
|
let authState;
|
|
3242
3993
|
switch (serverAuthState.stage) {
|
|
3994
|
+
case "done": {
|
|
3995
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareDoneState_fn).call(this, serverAuthState);
|
|
3996
|
+
break;
|
|
3997
|
+
}
|
|
3243
3998
|
case "verify":
|
|
3244
|
-
authState = serverAuthState
|
|
3999
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareVerificationState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), {
|
|
4000
|
+
sessionLookupId: opts.sessionLookupId
|
|
4001
|
+
}));
|
|
3245
4002
|
break;
|
|
3246
4003
|
case "login":
|
|
3247
4004
|
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
@@ -3261,14 +4018,36 @@ prepareAuthState_fn = function(_0) {
|
|
|
3261
4018
|
return authState;
|
|
3262
4019
|
});
|
|
3263
4020
|
};
|
|
3264
|
-
|
|
4021
|
+
prepareDoneState_fn = function(doneState) {
|
|
3265
4022
|
return __async(this, null, function* () {
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
4023
|
+
let isSLOPossible = doneState.authMethods.includes(AuthMethod.BASIC_LOGIN);
|
|
4024
|
+
this.isEnclaveUser = isSLOPossible;
|
|
4025
|
+
return doneState;
|
|
4026
|
+
});
|
|
4027
|
+
};
|
|
4028
|
+
prepareVerificationState_fn = function(_0, _1) {
|
|
4029
|
+
return __async(this, arguments, function* (verifyState, {
|
|
4030
|
+
useShortUrls: shorten = false,
|
|
4031
|
+
portalTheme,
|
|
4032
|
+
sessionLookupId
|
|
4033
|
+
}) {
|
|
4034
|
+
var _a;
|
|
4035
|
+
let isSLOPossible = false;
|
|
4036
|
+
if (verifyState.nextStage === "login") {
|
|
4037
|
+
isSLOPossible = verifyState.loginAuthMethods.includes(AuthMethod.BASIC_LOGIN);
|
|
4038
|
+
} else if (verifyState.nextStage === "signup") {
|
|
4039
|
+
isSLOPossible = verifyState.signupAuthMethods.includes(AuthMethod.BASIC_LOGIN);
|
|
3270
4040
|
}
|
|
3271
|
-
|
|
4041
|
+
this.isEnclaveUser = isSLOPossible;
|
|
4042
|
+
const isExternalWalletFullAuth = (_a = verifyState.externalWallet) == null ? void 0 : _a.withFullParaAuth;
|
|
4043
|
+
return __spreadValues(__spreadValues({}, verifyState), isSLOPossible || isExternalWalletFullAuth ? {
|
|
4044
|
+
loginUrl: yield this.getLoginUrl({
|
|
4045
|
+
authMethod: AuthMethod.BASIC_LOGIN,
|
|
4046
|
+
sessionId: sessionLookupId,
|
|
4047
|
+
shorten,
|
|
4048
|
+
portalTheme
|
|
4049
|
+
})
|
|
4050
|
+
} : {});
|
|
3272
4051
|
});
|
|
3273
4052
|
};
|
|
3274
4053
|
prepareLoginState_fn = function(_0, _1) {
|
|
@@ -3277,10 +4056,11 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3277
4056
|
portalTheme,
|
|
3278
4057
|
sessionLookupId
|
|
3279
4058
|
}) {
|
|
3280
|
-
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
3281
|
-
const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(AuthMethod.PASSWORD);
|
|
3282
|
-
return __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
3283
|
-
isPasskeySupported
|
|
4059
|
+
const _a = loginState, { loginAuthMethods = [], hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
|
|
4060
|
+
const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(AuthMethod.PASSWORD) && hasPasswordWithoutPIN, isPINPossible = loginAuthMethods.includes(AuthMethod.PIN);
|
|
4061
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
4062
|
+
isPasskeySupported,
|
|
4063
|
+
loginAuthMethods
|
|
3284
4064
|
}), isPasskeyPossible ? {
|
|
3285
4065
|
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
3286
4066
|
passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
|
|
@@ -3299,23 +4079,34 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3299
4079
|
portalTheme,
|
|
3300
4080
|
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
3301
4081
|
})
|
|
4082
|
+
} : {}), isPINPossible ? {
|
|
4083
|
+
pinUrl: yield this.constructPortalUrl("loginPIN", {
|
|
4084
|
+
sessionId: sessionLookupId,
|
|
4085
|
+
shorten,
|
|
4086
|
+
portalTheme,
|
|
4087
|
+
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
4088
|
+
})
|
|
3302
4089
|
} : {});
|
|
3303
4090
|
});
|
|
3304
4091
|
};
|
|
3305
4092
|
prepareSignUpState_fn = function(_0, _1) {
|
|
3306
4093
|
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
3307
|
-
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
4094
|
+
const _a = serverSignupState, { signupAuthMethods = [] } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
3308
4095
|
const isPasskeySupported = yield this.isPasskeySupported();
|
|
3309
|
-
const [isPasskey, isPassword] = [
|
|
4096
|
+
const [isPasskey, isPassword, isPIN] = [
|
|
3310
4097
|
signupAuthMethods.includes(AuthMethod.PASSKEY),
|
|
3311
|
-
signupAuthMethods.includes(AuthMethod.PASSWORD) || !isPasskeySupported
|
|
4098
|
+
signupAuthMethods.includes(AuthMethod.PASSWORD) || !isPasskeySupported,
|
|
4099
|
+
signupAuthMethods.includes(AuthMethod.PIN)
|
|
3312
4100
|
];
|
|
3313
|
-
if (!isPasskey && !isPassword) {
|
|
4101
|
+
if (!isPasskey && !isPassword && !isPIN) {
|
|
3314
4102
|
throw new Error(
|
|
3315
|
-
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or
|
|
4103
|
+
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
|
|
3316
4104
|
);
|
|
3317
4105
|
}
|
|
3318
|
-
const signupState = __spreadProps(__spreadValues({}, authState), {
|
|
4106
|
+
const signupState = __spreadProps(__spreadValues({}, authState), {
|
|
4107
|
+
isPasskeySupported,
|
|
4108
|
+
signupAuthMethods
|
|
4109
|
+
});
|
|
3319
4110
|
if (isPasskey) {
|
|
3320
4111
|
const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
|
|
3321
4112
|
authMethod: "PASSKEY",
|
|
@@ -3333,6 +4124,15 @@ prepareSignUpState_fn = function(_0, _1) {
|
|
|
3333
4124
|
signupState.passwordUrl = passwordUrl;
|
|
3334
4125
|
signupState.passwordId = passwordId;
|
|
3335
4126
|
}
|
|
4127
|
+
if (isPIN) {
|
|
4128
|
+
const { url: pinUrl, credentialId: pinId } = yield this.getNewCredentialAndUrl({
|
|
4129
|
+
authMethod: "PIN",
|
|
4130
|
+
portalTheme,
|
|
4131
|
+
shorten
|
|
4132
|
+
});
|
|
4133
|
+
signupState.pinUrl = pinUrl;
|
|
4134
|
+
signupState.pinId = pinId;
|
|
4135
|
+
}
|
|
3336
4136
|
return signupState;
|
|
3337
4137
|
});
|
|
3338
4138
|
};
|