@getpara/core-sdk 2.0.0-alpha.5 → 2.0.0-alpha.51
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 +764 -204
- package/dist/cjs/constants.js +7 -1
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/types/auth.js +33 -0
- package/dist/cjs/types/coreApi.js +20 -3
- package/dist/cjs/types/index.js +2 -0
- package/dist/cjs/utils/formatting.js +4 -0
- package/dist/cjs/utils/phone.js +14 -2
- package/dist/esm/ParaCore.js +771 -208
- package/dist/esm/constants.js +5 -1
- package/dist/esm/index.js +22 -3
- package/dist/esm/types/auth.js +11 -0
- package/dist/esm/types/coreApi.js +18 -2
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/utils/formatting.js +2 -0
- package/dist/esm/utils/phone.js +12 -1
- package/dist/types/ParaCore.d.ts +87 -49
- package/dist/types/PlatformUtils.d.ts +2 -3
- package/dist/types/constants.d.ts +16 -14
- package/dist/types/index.d.ts +3 -3
- package/dist/types/shares/KeyContainer.d.ts +0 -2
- package/dist/types/types/auth.d.ts +16 -0
- package/dist/types/types/config.d.ts +9 -1
- package/dist/types/types/coreApi.d.ts +100 -36
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/methods.d.ts +63 -7
- package/dist/types/types/wallet.d.ts +4 -1
- package/dist/types/utils/formatting.d.ts +2 -0
- package/dist/types/utils/phone.d.ts +4 -0
- package/package.json +23 -23
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, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_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;
|
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
AuthMethod,
|
|
24
24
|
PublicKeyStatus,
|
|
25
25
|
PublicKeyType,
|
|
26
|
-
extractWalletRef,
|
|
27
26
|
PasswordStatus,
|
|
28
27
|
extractAuthInfo,
|
|
29
28
|
isEmail,
|
|
@@ -33,7 +32,9 @@ import {
|
|
|
33
32
|
toPregenTypeAndId,
|
|
34
33
|
toPregenIds,
|
|
35
34
|
isExternalWallet,
|
|
36
|
-
WALLET_TYPES
|
|
35
|
+
WALLET_TYPES,
|
|
36
|
+
LINKED_ACCOUNT_TYPES,
|
|
37
|
+
isPregenAuth
|
|
37
38
|
} from "@getpara/user-management-client";
|
|
38
39
|
import forge from "node-forge";
|
|
39
40
|
const { pki, jsbn } = forge;
|
|
@@ -44,7 +45,8 @@ import { distributeNewShare } from "./shares/shareDistribution.js";
|
|
|
44
45
|
import {
|
|
45
46
|
Environment,
|
|
46
47
|
PopupType,
|
|
47
|
-
ParaEvent
|
|
48
|
+
ParaEvent,
|
|
49
|
+
AccountLinkError
|
|
48
50
|
} from "./types/index.js";
|
|
49
51
|
import { sendRecoveryForShare } from "./shares/recovery.js";
|
|
50
52
|
import {
|
|
@@ -68,27 +70,23 @@ import {
|
|
|
68
70
|
truncateAddress,
|
|
69
71
|
WalletSchemeTypeMap,
|
|
70
72
|
shortenUrl,
|
|
71
|
-
isServerAuthState
|
|
73
|
+
isServerAuthState,
|
|
74
|
+
splitPhoneNumber
|
|
72
75
|
} from "./utils/index.js";
|
|
73
76
|
import { TransactionReviewDenied, TransactionReviewTimeout } from "./errors.js";
|
|
74
77
|
import * as constants from "./constants.js";
|
|
75
78
|
const _ParaCore = class _ParaCore {
|
|
76
|
-
|
|
77
|
-
* Constructs a new `ParaCore` instance.
|
|
78
|
-
* @param env - `Environment` to use.
|
|
79
|
-
* @param apiKey - API key to use.
|
|
80
|
-
* @param opts - Additional constructor options; see `ConstructorOpts`.
|
|
81
|
-
* @returns - A new ParaCore instance.
|
|
82
|
-
*/
|
|
83
|
-
constructor(env, apiKey, opts) {
|
|
79
|
+
constructor(envOrApiKey, apiKeyOrOpts, opts) {
|
|
84
80
|
__privateAdd(this, _ParaCore_instances);
|
|
85
81
|
__privateAdd(this, _authInfo);
|
|
86
82
|
this.isNativePasskey = false;
|
|
87
|
-
|
|
83
|
+
this.isReady = false;
|
|
84
|
+
this.accountLinkInProgress = void 0;
|
|
88
85
|
this.isAwaitingAccountCreation = false;
|
|
89
86
|
this.isAwaitingLogin = false;
|
|
90
87
|
this.isAwaitingFarcaster = false;
|
|
91
88
|
this.isAwaitingOAuth = false;
|
|
89
|
+
this.isWorkerInitialized = false;
|
|
92
90
|
/**
|
|
93
91
|
* 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.
|
|
94
92
|
*/
|
|
@@ -97,6 +95,7 @@ const _ParaCore = class _ParaCore {
|
|
|
97
95
|
* Wallets associated with the `ParaCore` instance.
|
|
98
96
|
*/
|
|
99
97
|
this.externalWallets = {};
|
|
98
|
+
this.onRampPopup = void 0;
|
|
100
99
|
this.localStorageGetItem = (key) => {
|
|
101
100
|
return this.platformUtils.localStorage.get(key);
|
|
102
101
|
};
|
|
@@ -124,10 +123,17 @@ const _ParaCore = class _ParaCore {
|
|
|
124
123
|
*/
|
|
125
124
|
this.clearStorage = (type = "all") => __async(this, null, function* () {
|
|
126
125
|
const isAll = type === "all";
|
|
127
|
-
(isAll || type === "local")
|
|
128
|
-
|
|
126
|
+
if (isAll || type === "local") {
|
|
127
|
+
this.platformUtils.localStorage.clear(constants.PREFIX);
|
|
128
|
+
this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
|
|
129
|
+
}
|
|
130
|
+
if (isAll || type === "session") {
|
|
131
|
+
this.platformUtils.sessionStorage.clear(constants.PREFIX);
|
|
132
|
+
this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
|
|
133
|
+
}
|
|
129
134
|
if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
|
|
130
135
|
this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
136
|
+
this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
|
|
131
137
|
}
|
|
132
138
|
});
|
|
133
139
|
this.trackError = (methodName, err) => __async(this, null, function* () {
|
|
@@ -248,6 +254,16 @@ const _ParaCore = class _ParaCore {
|
|
|
248
254
|
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
249
255
|
this.setExternalWallets(_externalWallets);
|
|
250
256
|
};
|
|
257
|
+
this.initializeWorker = () => __async(this, null, function* () {
|
|
258
|
+
if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers) {
|
|
259
|
+
try {
|
|
260
|
+
this.isWorkerInitialized = true;
|
|
261
|
+
yield this.platformUtils.initializeWorker(this.ctx);
|
|
262
|
+
} catch (e) {
|
|
263
|
+
this.devLog("error initializing worker:", e);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
251
267
|
/**
|
|
252
268
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
253
269
|
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
@@ -264,8 +280,29 @@ const _ParaCore = class _ParaCore {
|
|
|
264
280
|
}) {
|
|
265
281
|
return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
|
|
266
282
|
});
|
|
267
|
-
|
|
268
|
-
|
|
283
|
+
let env, apiKey;
|
|
284
|
+
const actualArgs = Array.from(arguments).filter((arg) => arg !== void 0);
|
|
285
|
+
const actualArgumentCount = actualArgs.length;
|
|
286
|
+
if (actualArgumentCount === 1) {
|
|
287
|
+
if (Object.values(Environment).includes(envOrApiKey)) {
|
|
288
|
+
throw new Error("A Para API key is required.");
|
|
289
|
+
}
|
|
290
|
+
env = _ParaCore.resolveEnvironment(void 0, actualArgs[0]);
|
|
291
|
+
apiKey = actualArgs[0];
|
|
292
|
+
opts = void 0;
|
|
293
|
+
} else if (actualArgumentCount === 2) {
|
|
294
|
+
if (typeof apiKeyOrOpts === "object" && apiKeyOrOpts !== null) {
|
|
295
|
+
env = _ParaCore.resolveEnvironment(void 0, envOrApiKey);
|
|
296
|
+
apiKey = envOrApiKey;
|
|
297
|
+
opts = apiKeyOrOpts;
|
|
298
|
+
} else {
|
|
299
|
+
env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
|
|
300
|
+
apiKey = apiKeyOrOpts;
|
|
301
|
+
opts = void 0;
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
|
|
305
|
+
apiKey = apiKeyOrOpts;
|
|
269
306
|
}
|
|
270
307
|
if (!opts) opts = {};
|
|
271
308
|
let isE2E = false;
|
|
@@ -288,6 +325,7 @@ const _ParaCore = class _ParaCore {
|
|
|
288
325
|
this.portalTheme = opts.portalTheme;
|
|
289
326
|
this.platformUtils = this.getPlatformUtils();
|
|
290
327
|
this.disableProviderModal = this.platformUtils.disableProviderModal;
|
|
328
|
+
this.fetchPregenWalletsOverride = opts.fetchPregenWalletsOverride;
|
|
291
329
|
if (opts.useStorageOverrides) {
|
|
292
330
|
this.localStorageGetItem = opts.localStorageGetItemOverride;
|
|
293
331
|
this.localStorageSetItem = opts.localStorageSetItemOverride;
|
|
@@ -379,6 +417,8 @@ const _ParaCore = class _ParaCore {
|
|
|
379
417
|
get externalWalletConnectionType() {
|
|
380
418
|
if (this.isExternalWalletAuth) {
|
|
381
419
|
return "AUTHENTICATED";
|
|
420
|
+
} else if (this.isExternalWalletWithVerification) {
|
|
421
|
+
return "VERIFICATION";
|
|
382
422
|
} else if (!!Object.keys(this.externalWallets).length) {
|
|
383
423
|
return "CONNECTION_ONLY";
|
|
384
424
|
}
|
|
@@ -401,16 +441,28 @@ const _ParaCore = class _ParaCore {
|
|
|
401
441
|
return isTelegram((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
402
442
|
}
|
|
403
443
|
get isExternalWalletAuth() {
|
|
404
|
-
var _a;
|
|
405
|
-
return isExternalWallet((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
|
|
444
|
+
var _a, _b, _c;
|
|
445
|
+
return isExternalWallet((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) && !!((_c = (_b = __privateGet(this, _authInfo)) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.withFullParaAuth);
|
|
446
|
+
}
|
|
447
|
+
get isExternalWalletWithVerification() {
|
|
448
|
+
var _a, _b, _c;
|
|
449
|
+
return isExternalWallet((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) && !!((_c = (_b = __privateGet(this, _authInfo)) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.withVerification);
|
|
406
450
|
}
|
|
407
451
|
get partnerId() {
|
|
408
452
|
var _a;
|
|
409
|
-
return (_a =
|
|
453
|
+
return (_a = this.partner) == null ? void 0 : _a.id;
|
|
454
|
+
}
|
|
455
|
+
get partnerName() {
|
|
456
|
+
var _a;
|
|
457
|
+
return (_a = this.partner) == null ? void 0 : _a.displayName;
|
|
458
|
+
}
|
|
459
|
+
get partnerLogo() {
|
|
460
|
+
var _a;
|
|
461
|
+
return (_a = this.partner) == null ? void 0 : _a.logoUrl;
|
|
410
462
|
}
|
|
411
463
|
get currentWalletIdsArray() {
|
|
412
464
|
var _a, _b;
|
|
413
|
-
return ((_b = (_a =
|
|
465
|
+
return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
414
466
|
(acc, { type }) => {
|
|
415
467
|
var _a2;
|
|
416
468
|
return [
|
|
@@ -450,19 +502,23 @@ const _ParaCore = class _ParaCore {
|
|
|
450
502
|
}
|
|
451
503
|
get isNoWalletConfig() {
|
|
452
504
|
var _a;
|
|
453
|
-
return !!((_a =
|
|
505
|
+
return !!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) && this.partner.supportedWalletTypes.length === 0;
|
|
454
506
|
}
|
|
455
507
|
get supportedWalletTypes() {
|
|
456
508
|
var _a, _b;
|
|
457
|
-
return (_b = (_a =
|
|
509
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
458
510
|
}
|
|
459
511
|
get cosmosPrefix() {
|
|
460
512
|
var _a;
|
|
461
|
-
return (_a =
|
|
513
|
+
return (_a = this.partner) == null ? void 0 : _a.cosmosPrefix;
|
|
514
|
+
}
|
|
515
|
+
get supportedAccountLinks() {
|
|
516
|
+
var _a, _b;
|
|
517
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...LINKED_ACCOUNT_TYPES];
|
|
462
518
|
}
|
|
463
519
|
get isWalletTypeEnabled() {
|
|
464
520
|
var _a;
|
|
465
|
-
return (((_a =
|
|
521
|
+
return (((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
466
522
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
467
523
|
}, {});
|
|
468
524
|
}
|
|
@@ -511,7 +567,7 @@ const _ParaCore = class _ParaCore {
|
|
|
511
567
|
}
|
|
512
568
|
isWalletSupported(wallet) {
|
|
513
569
|
var _a, _b;
|
|
514
|
-
return !((_a =
|
|
570
|
+
return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
515
571
|
}
|
|
516
572
|
isWalletOwned(wallet) {
|
|
517
573
|
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;
|
|
@@ -537,12 +593,12 @@ const _ParaCore = class _ParaCore {
|
|
|
537
593
|
} else {
|
|
538
594
|
const wallet = this.wallets[walletId];
|
|
539
595
|
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
540
|
-
if (forbidPregen && isUnclaimed) {
|
|
596
|
+
if (forbidPregen && isUnclaimed && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
541
597
|
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
542
598
|
} else if (!isOwned && !isUnclaimed) {
|
|
543
599
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
544
600
|
} else if (!this.isWalletSupported(wallet)) {
|
|
545
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b =
|
|
601
|
+
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(", ")}`;
|
|
546
602
|
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
547
603
|
var _a2, _b2;
|
|
548
604
|
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
@@ -573,7 +629,7 @@ const _ParaCore = class _ParaCore {
|
|
|
573
629
|
if (this.externalWallets[walletId]) {
|
|
574
630
|
const wallet2 = this.externalWallets[walletId];
|
|
575
631
|
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, {
|
|
576
|
-
prefix: (_a =
|
|
632
|
+
prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
|
|
577
633
|
targetLength: options.targetLength
|
|
578
634
|
}) : wallet2.address;
|
|
579
635
|
}
|
|
@@ -585,7 +641,7 @@ const _ParaCore = class _ParaCore {
|
|
|
585
641
|
let prefix;
|
|
586
642
|
switch (wallet.type) {
|
|
587
643
|
case "COSMOS":
|
|
588
|
-
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b =
|
|
644
|
+
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
589
645
|
str = getCosmosAddress(wallet.publicKey, prefix);
|
|
590
646
|
break;
|
|
591
647
|
default:
|
|
@@ -620,8 +676,8 @@ const _ParaCore = class _ParaCore {
|
|
|
620
676
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
621
677
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
622
678
|
const [isCreate, isLogin, isOnRamp] = [
|
|
623
|
-
["createAuth", "createPassword"].includes(type),
|
|
624
|
-
["loginAuth", "loginPassword"].includes(type),
|
|
679
|
+
["createAuth", "createPassword", "createPIN"].includes(type),
|
|
680
|
+
["loginAuth", "loginPassword", "loginPIN"].includes(type),
|
|
625
681
|
type === "onRamp"
|
|
626
682
|
];
|
|
627
683
|
if (isCreate || isLogin) {
|
|
@@ -635,13 +691,17 @@ const _ParaCore = class _ParaCore {
|
|
|
635
691
|
if (!this.loginEncryptionKeyPair) {
|
|
636
692
|
yield this.setLoginEncryptionKeyPair();
|
|
637
693
|
}
|
|
638
|
-
const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL();
|
|
694
|
+
const base = type === "onRamp" || type === "telegramLogin" ? getPortalBaseURL(this.ctx, type === "telegramLogin") : yield this.getPortalURL();
|
|
639
695
|
let path;
|
|
640
696
|
switch (type) {
|
|
641
697
|
case "createPassword": {
|
|
642
698
|
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
643
699
|
break;
|
|
644
700
|
}
|
|
701
|
+
case "createPIN": {
|
|
702
|
+
path = `/web/users/${this.userId}/pin/${opts.pathId}`;
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
645
705
|
case "createAuth": {
|
|
646
706
|
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
647
707
|
break;
|
|
@@ -654,26 +714,43 @@ const _ParaCore = class _ParaCore {
|
|
|
654
714
|
path = "/web/biometrics/login";
|
|
655
715
|
break;
|
|
656
716
|
}
|
|
717
|
+
case "loginPIN": {
|
|
718
|
+
path = "/web/pin/login";
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
657
721
|
case "txReview": {
|
|
658
722
|
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
659
723
|
break;
|
|
660
724
|
}
|
|
661
725
|
case "onRamp": {
|
|
662
|
-
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
726
|
+
path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
case "telegramLogin": {
|
|
730
|
+
path = `/auth/telegram`;
|
|
663
731
|
break;
|
|
664
732
|
}
|
|
665
733
|
default: {
|
|
666
734
|
throw new Error(`invalid URL type ${type}`);
|
|
667
735
|
}
|
|
668
736
|
}
|
|
669
|
-
|
|
737
|
+
let partner = void 0;
|
|
738
|
+
try {
|
|
739
|
+
partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
740
|
+
} catch (e) {
|
|
741
|
+
if (this.isPartnerOptional) {
|
|
742
|
+
partner = void 0;
|
|
743
|
+
} else {
|
|
744
|
+
throw e;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
670
747
|
const thisDevice = (_a = opts.thisDevice) != null ? _a : {
|
|
671
748
|
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
672
749
|
sessionId
|
|
673
750
|
};
|
|
674
|
-
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
751
|
+
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
675
752
|
apiKey: this.ctx.apiKey,
|
|
676
|
-
partnerId: partner.id,
|
|
753
|
+
partnerId: partner == null ? void 0 : partner.id,
|
|
677
754
|
portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
|
|
678
755
|
portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
|
|
679
756
|
portalThemeMode: ((_f = opts.portalTheme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
|
|
@@ -684,7 +761,12 @@ const _ParaCore = class _ParaCore {
|
|
|
684
761
|
portalTextColor: this.portalTextColor,
|
|
685
762
|
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
686
763
|
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
687
|
-
}, isCreate || isLogin ?
|
|
764
|
+
}, isCreate || isLogin ? __spreadProps(__spreadValues({
|
|
765
|
+
authInfo: JSON.stringify(this.authInfo)
|
|
766
|
+
}, isPhone(this.authInfo.auth) ? splitPhoneNumber(this.authInfo.auth.phone) : this.authInfo.auth), {
|
|
767
|
+
pfpUrl: this.authInfo.pfpUrl,
|
|
768
|
+
displayName: this.authInfo.displayName
|
|
769
|
+
}) : {}), isOnRamp ? { origin: typeof window !== "undefined" ? window.location.origin : void 0, email: this.email } : {}), isLogin ? __spreadProps(__spreadValues({
|
|
688
770
|
sessionId: thisDevice.sessionId,
|
|
689
771
|
encryptionKey: thisDevice.encryptionKey
|
|
690
772
|
}, opts.newDevice ? {
|
|
@@ -692,7 +774,7 @@ const _ParaCore = class _ParaCore {
|
|
|
692
774
|
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
693
775
|
} : {}), {
|
|
694
776
|
pregenIds: JSON.stringify(this.pregenIds)
|
|
695
|
-
}) : {}), opts.params || {});
|
|
777
|
+
}) : {}), type === "telegramLogin" ? { isEmbed: "true" } : {}), opts.params || {});
|
|
696
778
|
const url = constructUrl({ base, path, params });
|
|
697
779
|
if (opts.shorten) {
|
|
698
780
|
return shortenUrl(this.ctx, url);
|
|
@@ -700,12 +782,62 @@ const _ParaCore = class _ParaCore {
|
|
|
700
782
|
return url;
|
|
701
783
|
});
|
|
702
784
|
}
|
|
785
|
+
static resolveEnvironment(env, apiKey) {
|
|
786
|
+
var _a;
|
|
787
|
+
if (!apiKey) {
|
|
788
|
+
throw new Error("A Para API key is required.");
|
|
789
|
+
}
|
|
790
|
+
if (apiKey.includes("_")) {
|
|
791
|
+
const validEnvironmentPrefixes = Object.values(Environment);
|
|
792
|
+
const envPrefix = (_a = apiKey.split("_")[0]) == null ? void 0 : _a.toUpperCase();
|
|
793
|
+
const hasValidPrefix = validEnvironmentPrefixes.some((envValue) => envValue === envPrefix);
|
|
794
|
+
if (!hasValidPrefix) {
|
|
795
|
+
throw new Error(`Invalid API key environment prefix.`);
|
|
796
|
+
}
|
|
797
|
+
return envPrefix;
|
|
798
|
+
}
|
|
799
|
+
if (!env) {
|
|
800
|
+
throw new Error("Environment parameter is required.");
|
|
801
|
+
}
|
|
802
|
+
return env;
|
|
803
|
+
}
|
|
703
804
|
touchSession(regenerate = false) {
|
|
704
805
|
return __async(this, null, function* () {
|
|
705
|
-
var _a, _b, _c;
|
|
806
|
+
var _a, _b, _c, _d;
|
|
807
|
+
if (!this.isWorkerInitialized) {
|
|
808
|
+
this.initializeWorker();
|
|
809
|
+
}
|
|
810
|
+
if (!this.isReady) {
|
|
811
|
+
yield this.ready();
|
|
812
|
+
}
|
|
706
813
|
const session = yield this.ctx.client.touchSession(regenerate);
|
|
707
|
-
if (!
|
|
708
|
-
|
|
814
|
+
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) {
|
|
815
|
+
if (!session.partnerId) {
|
|
816
|
+
console.error(`
|
|
817
|
+
\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
|
|
818
|
+
\u{1F6A8} PARA SDK CONFIGURATION ERROR \u{1F6A8}
|
|
819
|
+
|
|
820
|
+
INVALID API KEY FOR CONFIGURED ENVIRONMENT
|
|
821
|
+
|
|
822
|
+
Your API key does not match the configured environment. This usually means:
|
|
823
|
+
|
|
824
|
+
1. You're using a production API key with a development environment
|
|
825
|
+
2. You're using a development API key with a production environment
|
|
826
|
+
3. Your API key is invalid or has been regenerated
|
|
827
|
+
|
|
828
|
+
SOLUTION:
|
|
829
|
+
\u2022 Verify your API key at: https://developer.getpara.com
|
|
830
|
+
\u2022 If your API key doesn't contain an environment prefix, ensure your API key is the correct key for your target environment
|
|
831
|
+
|
|
832
|
+
Current Environment: ${this.ctx.env}
|
|
833
|
+
API Key Prefix: ${((_d = this.ctx.apiKey) == null ? void 0 : _d.split("_")[0].toUpperCase()) || "None"}
|
|
834
|
+
|
|
835
|
+
Need help? Visit: https://docs.getpara.com or contact support
|
|
836
|
+
\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
|
|
837
|
+
`);
|
|
838
|
+
} else {
|
|
839
|
+
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
840
|
+
}
|
|
709
841
|
}
|
|
710
842
|
return session;
|
|
711
843
|
});
|
|
@@ -804,8 +936,8 @@ const _ParaCore = class _ParaCore {
|
|
|
804
936
|
return __privateGet(this, _authInfo);
|
|
805
937
|
});
|
|
806
938
|
}
|
|
807
|
-
assertUserId() {
|
|
808
|
-
if (!this.userId) {
|
|
939
|
+
assertUserId({ allowGuestMode = false } = {}) {
|
|
940
|
+
if (!this.userId || !allowGuestMode && this.isGuestMode) {
|
|
809
941
|
throw new Error("no userId is set");
|
|
810
942
|
}
|
|
811
943
|
return this.userId;
|
|
@@ -861,19 +993,75 @@ const _ParaCore = class _ParaCore {
|
|
|
861
993
|
* @param externalAddress - External wallet address to set.
|
|
862
994
|
* @param externalType - Type of external wallet to set.
|
|
863
995
|
*/
|
|
864
|
-
setExternalWallet(
|
|
865
|
-
return __async(this,
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
996
|
+
setExternalWallet(externalWallet) {
|
|
997
|
+
return __async(this, null, function* () {
|
|
998
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
999
|
+
this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
|
|
1000
|
+
(acc, {
|
|
1001
|
+
partnerId: wPartnerId,
|
|
1002
|
+
address,
|
|
870
1003
|
type,
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
1004
|
+
provider,
|
|
1005
|
+
providerId,
|
|
1006
|
+
addressBech32,
|
|
1007
|
+
withFullParaAuth,
|
|
1008
|
+
isConnectionOnly,
|
|
1009
|
+
withVerification
|
|
1010
|
+
}) => {
|
|
1011
|
+
if (partnerId === wPartnerId && supportedWalletTypes.some(({ type: supportedType }) => supportedType === type)) {
|
|
1012
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1013
|
+
[address]: {
|
|
1014
|
+
id: address,
|
|
1015
|
+
partnerId,
|
|
1016
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
1017
|
+
type,
|
|
1018
|
+
name: provider,
|
|
1019
|
+
isExternal: true,
|
|
1020
|
+
isExternalWithParaAuth: withFullParaAuth,
|
|
1021
|
+
externalProviderId: providerId,
|
|
1022
|
+
signer: "",
|
|
1023
|
+
isExternalConnectionOnly: isConnectionOnly,
|
|
1024
|
+
isExternalWithVerification: withVerification
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
return acc;
|
|
1029
|
+
},
|
|
1030
|
+
{}
|
|
1031
|
+
), this.setExternalWallets(this.externalWallets);
|
|
1032
|
+
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
addExternalWallets(externalWallets) {
|
|
1036
|
+
return __async(this, null, function* () {
|
|
1037
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1038
|
+
this.externalWallets = __spreadValues(__spreadValues({}, Object.entries(this.externalWallets).reduce((acc, [address, wallet]) => {
|
|
1039
|
+
if (partnerId === wallet.partnerId && supportedWalletTypes.some(({ type }) => type === wallet.type)) {
|
|
1040
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1041
|
+
[address]: wallet
|
|
1042
|
+
});
|
|
875
1043
|
}
|
|
876
|
-
|
|
1044
|
+
return acc;
|
|
1045
|
+
}, {})), externalWallets.reduce(
|
|
1046
|
+
(acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
|
|
1047
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1048
|
+
[address]: {
|
|
1049
|
+
id: address,
|
|
1050
|
+
partnerId,
|
|
1051
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
1052
|
+
type,
|
|
1053
|
+
name: provider,
|
|
1054
|
+
isExternal: true,
|
|
1055
|
+
isExternalWithParaAuth: withFullParaAuth,
|
|
1056
|
+
externalProviderId: providerId,
|
|
1057
|
+
signer: "",
|
|
1058
|
+
isExternalConnectionOnly: isConnectionOnly,
|
|
1059
|
+
isExternalWithVerification: withVerification
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
},
|
|
1063
|
+
{}
|
|
1064
|
+
));
|
|
877
1065
|
this.setExternalWallets(this.externalWallets);
|
|
878
1066
|
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
879
1067
|
});
|
|
@@ -985,6 +1173,7 @@ const _ParaCore = class _ParaCore {
|
|
|
985
1173
|
/**
|
|
986
1174
|
* Fetches the most recent OAuth account metadata for the signed-in user.
|
|
987
1175
|
* If applicable, this will include the user's most recent metadata from their Google, Apple, Facebook, X, Discord, Farcaster, or Telegram account, the last time they signed in to your app.
|
|
1176
|
+
* @deprecated use `para.getLinkedAccounts({ withMetadata: true })` instead.
|
|
988
1177
|
* @returns {Promise<AccountMetadata>} the user's account metadata.
|
|
989
1178
|
*/
|
|
990
1179
|
getAccountMetadata() {
|
|
@@ -1130,8 +1319,15 @@ const _ParaCore = class _ParaCore {
|
|
|
1130
1319
|
}
|
|
1131
1320
|
getPartnerURL() {
|
|
1132
1321
|
return __async(this, null, function* () {
|
|
1133
|
-
|
|
1134
|
-
|
|
1322
|
+
try {
|
|
1323
|
+
const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1324
|
+
return portalUrl;
|
|
1325
|
+
} catch (e) {
|
|
1326
|
+
if (this.isPartnerOptional) {
|
|
1327
|
+
return void 0;
|
|
1328
|
+
}
|
|
1329
|
+
throw e;
|
|
1330
|
+
}
|
|
1135
1331
|
});
|
|
1136
1332
|
}
|
|
1137
1333
|
/**
|
|
@@ -1217,15 +1413,27 @@ const _ParaCore = class _ParaCore {
|
|
|
1217
1413
|
} = _b, urlOptions = __objRest(_b, [
|
|
1218
1414
|
"externalWallet"
|
|
1219
1415
|
]);
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
yield this.
|
|
1416
|
+
const externalWallets = Array.isArray(externalWallet) ? externalWallet : [externalWallet];
|
|
1417
|
+
if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
|
|
1418
|
+
yield this.addExternalWallets(
|
|
1419
|
+
externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
|
|
1420
|
+
withFullParaAuth: false
|
|
1421
|
+
}))
|
|
1422
|
+
);
|
|
1223
1423
|
return Promise.resolve({
|
|
1224
1424
|
userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
|
|
1225
1425
|
});
|
|
1226
1426
|
}
|
|
1427
|
+
if (Array.isArray(externalWallet)) {
|
|
1428
|
+
throw new Error(
|
|
1429
|
+
"Cannot authenticate multiple external wallets at once. To connect multiple wallets at once, use CONNECTION_ONLY mode."
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1227
1432
|
this.requireApiKey();
|
|
1228
1433
|
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
|
|
1434
|
+
if (!externalWallet.withFullParaAuth && externalWallet.withVerification) {
|
|
1435
|
+
yield this.touchSession(true);
|
|
1436
|
+
}
|
|
1229
1437
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1230
1438
|
});
|
|
1231
1439
|
}
|
|
@@ -1242,36 +1450,78 @@ const _ParaCore = class _ParaCore {
|
|
|
1242
1450
|
"cosmosPublicKeyHex",
|
|
1243
1451
|
"cosmosSigner"
|
|
1244
1452
|
]);
|
|
1453
|
+
var _a;
|
|
1245
1454
|
const serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
|
|
1246
1455
|
externalWallet,
|
|
1247
1456
|
signedMessage,
|
|
1248
1457
|
cosmosPublicKeyHex,
|
|
1249
1458
|
cosmosSigner
|
|
1250
1459
|
});
|
|
1460
|
+
if (serverAuthState.stage === "login" && ((_a = serverAuthState.loginAuthMethods) == null ? void 0 : _a.includes(AuthMethod.PIN))) {
|
|
1461
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
1462
|
+
return __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1463
|
+
}
|
|
1251
1464
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1252
1465
|
});
|
|
1253
1466
|
}
|
|
1467
|
+
verifyExternalWalletLink(opts) {
|
|
1468
|
+
return __async(this, null, function* () {
|
|
1469
|
+
const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EXTERNAL_WALLET"]);
|
|
1470
|
+
if (!accountLinkInProgress.externalWallet) {
|
|
1471
|
+
throw new Error("no external wallet account link in progress");
|
|
1472
|
+
}
|
|
1473
|
+
const accounts = yield this.verifyLink(__spreadValues({
|
|
1474
|
+
accountLinkInProgress,
|
|
1475
|
+
externalWallet: accountLinkInProgress.externalWallet
|
|
1476
|
+
}, opts));
|
|
1477
|
+
return accounts;
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1254
1480
|
/**
|
|
1255
1481
|
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
1256
1482
|
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
1257
1483
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1258
1484
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1259
1485
|
*/
|
|
1260
|
-
|
|
1486
|
+
verifyTelegramProcess(_e) {
|
|
1261
1487
|
return __async(this, null, function* () {
|
|
1262
1488
|
var _f = _e, {
|
|
1263
|
-
telegramAuthResponse
|
|
1489
|
+
telegramAuthResponse,
|
|
1490
|
+
isLinkAccount
|
|
1264
1491
|
} = _f, urlOptions = __objRest(_f, [
|
|
1265
|
-
"telegramAuthResponse"
|
|
1492
|
+
"telegramAuthResponse",
|
|
1493
|
+
"isLinkAccount"
|
|
1266
1494
|
]);
|
|
1267
1495
|
try {
|
|
1268
|
-
|
|
1269
|
-
|
|
1496
|
+
switch (isLinkAccount) {
|
|
1497
|
+
case false: {
|
|
1498
|
+
const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
|
|
1499
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1500
|
+
}
|
|
1501
|
+
case true: {
|
|
1502
|
+
const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
|
|
1503
|
+
const accounts = yield this.verifyLink({
|
|
1504
|
+
accountLinkInProgress,
|
|
1505
|
+
telegramAuthResponse
|
|
1506
|
+
});
|
|
1507
|
+
return accounts;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1270
1510
|
} catch (e) {
|
|
1271
1511
|
throw new Error(e.message);
|
|
1272
1512
|
}
|
|
1273
1513
|
});
|
|
1274
1514
|
}
|
|
1515
|
+
verifyTelegram(opts) {
|
|
1516
|
+
return __async(this, null, function* () {
|
|
1517
|
+
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
verifyTelegramLink(opts) {
|
|
1521
|
+
return __async(this, null, function* () {
|
|
1522
|
+
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1275
1525
|
/**
|
|
1276
1526
|
* Performs 2FA verification.
|
|
1277
1527
|
* @param {Object} opts the options object
|
|
@@ -1315,10 +1565,35 @@ const _ParaCore = class _ParaCore {
|
|
|
1315
1565
|
/**
|
|
1316
1566
|
* Resend a verification email for the current user.
|
|
1317
1567
|
*/
|
|
1318
|
-
resendVerificationCode() {
|
|
1319
|
-
return __async(this,
|
|
1568
|
+
resendVerificationCode(_0) {
|
|
1569
|
+
return __async(this, arguments, function* ({
|
|
1570
|
+
type: reason = "SIGNUP"
|
|
1571
|
+
}) {
|
|
1572
|
+
let type, linkedAccountId;
|
|
1573
|
+
switch (reason) {
|
|
1574
|
+
case "SIGNUP":
|
|
1575
|
+
case "LOGIN":
|
|
1576
|
+
{
|
|
1577
|
+
const authInfo = this.assertIsAuthSet(["email", "phone"]);
|
|
1578
|
+
type = authInfo.authType.toUpperCase();
|
|
1579
|
+
}
|
|
1580
|
+
break;
|
|
1581
|
+
case "LINK_ACCOUNT":
|
|
1582
|
+
{
|
|
1583
|
+
const accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]);
|
|
1584
|
+
linkedAccountId = accountLinkInProgress.id;
|
|
1585
|
+
type = accountLinkInProgress.type;
|
|
1586
|
+
}
|
|
1587
|
+
break;
|
|
1588
|
+
}
|
|
1589
|
+
const userId = this.assertUserId({ allowGuestMode: true });
|
|
1590
|
+
if (type !== "EMAIL" && type !== "PHONE") {
|
|
1591
|
+
throw new Error("invalid auth type for verification code");
|
|
1592
|
+
}
|
|
1320
1593
|
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
1321
|
-
userId
|
|
1594
|
+
userId,
|
|
1595
|
+
type,
|
|
1596
|
+
linkedAccountId
|
|
1322
1597
|
}, this.getVerificationEmailProps()));
|
|
1323
1598
|
});
|
|
1324
1599
|
}
|
|
@@ -1331,7 +1606,14 @@ const _ParaCore = class _ParaCore {
|
|
|
1331
1606
|
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1332
1607
|
return true;
|
|
1333
1608
|
}
|
|
1334
|
-
const { isAuthenticated } = yield this.touchSession();
|
|
1609
|
+
const { isAuthenticated, verifiedExternalWalletAddresses } = yield this.touchSession();
|
|
1610
|
+
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1611
|
+
if (!verifiedExternalWalletAddresses) {
|
|
1612
|
+
return false;
|
|
1613
|
+
}
|
|
1614
|
+
const externalAddresses = Object.values(this.externalWallets).map((w) => w.id);
|
|
1615
|
+
return externalAddresses.every((address) => verifiedExternalWalletAddresses.includes(address));
|
|
1616
|
+
}
|
|
1335
1617
|
return !!isAuthenticated;
|
|
1336
1618
|
});
|
|
1337
1619
|
}
|
|
@@ -1342,12 +1624,18 @@ const _ParaCore = class _ParaCore {
|
|
|
1342
1624
|
isFullyLoggedIn() {
|
|
1343
1625
|
return __async(this, null, function* () {
|
|
1344
1626
|
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1627
|
+
if (!this.isReady) {
|
|
1628
|
+
yield this.ready();
|
|
1629
|
+
}
|
|
1345
1630
|
return true;
|
|
1346
1631
|
}
|
|
1347
1632
|
if (this.isGuestMode) {
|
|
1348
1633
|
return true;
|
|
1349
1634
|
}
|
|
1350
1635
|
const isSessionActive = yield this.isSessionActive();
|
|
1636
|
+
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1637
|
+
return isSessionActive;
|
|
1638
|
+
}
|
|
1351
1639
|
return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
|
|
1352
1640
|
});
|
|
1353
1641
|
}
|
|
@@ -1355,10 +1643,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1355
1643
|
return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
|
|
1356
1644
|
({ userId, partnerId }) => {
|
|
1357
1645
|
var _a;
|
|
1358
|
-
return partnerId === ((_a =
|
|
1646
|
+
return partnerId === ((_a = this.partner) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
|
|
1359
1647
|
}
|
|
1360
1648
|
);
|
|
1361
1649
|
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Get the auth methods available to an existing user
|
|
1652
|
+
*/
|
|
1362
1653
|
supportedAuthMethods(auth) {
|
|
1363
1654
|
return __async(this, null, function* () {
|
|
1364
1655
|
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
@@ -1452,15 +1743,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1452
1743
|
});
|
|
1453
1744
|
}
|
|
1454
1745
|
/**
|
|
1455
|
-
* Initiates a Farcaster login attempt and
|
|
1746
|
+
* Initiates a Farcaster login attempt and returns the URL for the user to connect.
|
|
1456
1747
|
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
1457
1748
|
* @return {string} the Farcaster connect URI
|
|
1458
1749
|
*/
|
|
1459
1750
|
getFarcasterConnectUri() {
|
|
1460
|
-
return __async(this,
|
|
1461
|
-
const {
|
|
1462
|
-
data: { connect_uri: connectUri }
|
|
1463
|
-
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
1751
|
+
return __async(this, arguments, function* ({ appScheme } = {}) {
|
|
1752
|
+
const { connect_uri: connectUri } = yield this.ctx.client.initializeFarcasterLogin({ appScheme });
|
|
1464
1753
|
return connectUri;
|
|
1465
1754
|
});
|
|
1466
1755
|
}
|
|
@@ -1469,19 +1758,25 @@ const _ParaCore = class _ParaCore {
|
|
|
1469
1758
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
1470
1759
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
1471
1760
|
*/
|
|
1472
|
-
|
|
1761
|
+
verifyFarcasterProcess(_g) {
|
|
1473
1762
|
return __async(this, null, function* () {
|
|
1474
1763
|
var _h = _g, {
|
|
1475
1764
|
isCanceled = () => false,
|
|
1476
1765
|
onConnectUri,
|
|
1477
1766
|
onCancel,
|
|
1478
|
-
onPoll
|
|
1767
|
+
onPoll,
|
|
1768
|
+
isLinkAccount
|
|
1479
1769
|
} = _h, urlOptions = __objRest(_h, [
|
|
1480
1770
|
"isCanceled",
|
|
1481
1771
|
"onConnectUri",
|
|
1482
1772
|
"onCancel",
|
|
1483
|
-
"onPoll"
|
|
1773
|
+
"onPoll",
|
|
1774
|
+
"isLinkAccount"
|
|
1484
1775
|
]);
|
|
1776
|
+
let accountLinkInProgress;
|
|
1777
|
+
if (isLinkAccount) {
|
|
1778
|
+
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
|
|
1779
|
+
}
|
|
1485
1780
|
if (onConnectUri) {
|
|
1486
1781
|
const connectUri = yield this.getFarcasterConnectUri();
|
|
1487
1782
|
onConnectUri(connectUri);
|
|
@@ -1493,53 +1788,55 @@ const _ParaCore = class _ParaCore {
|
|
|
1493
1788
|
try {
|
|
1494
1789
|
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1495
1790
|
onCancel == null ? void 0 : onCancel();
|
|
1496
|
-
return reject("
|
|
1791
|
+
return reject("CANCELED");
|
|
1497
1792
|
}
|
|
1498
1793
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1794
|
+
switch (isLinkAccount) {
|
|
1795
|
+
case false:
|
|
1796
|
+
{
|
|
1797
|
+
const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
|
|
1798
|
+
if (isServerAuthState(serverAuthState)) {
|
|
1799
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1800
|
+
return resolve(authState);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
break;
|
|
1804
|
+
case true: {
|
|
1805
|
+
const result = yield this.verifyLink({
|
|
1806
|
+
accountLinkInProgress
|
|
1807
|
+
});
|
|
1808
|
+
if ("isConflict" in result) {
|
|
1809
|
+
throw new Error(AccountLinkError.Conflict);
|
|
1810
|
+
}
|
|
1811
|
+
return resolve(result);
|
|
1812
|
+
}
|
|
1503
1813
|
}
|
|
1504
1814
|
onPoll == null ? void 0 : onPoll();
|
|
1505
1815
|
} catch (e) {
|
|
1506
|
-
|
|
1507
|
-
|
|
1816
|
+
if (!isLinkAccount || e.message === AccountLinkError.Conflict) {
|
|
1817
|
+
return reject(e.message);
|
|
1818
|
+
}
|
|
1508
1819
|
}
|
|
1509
1820
|
}
|
|
1510
1821
|
}))();
|
|
1511
1822
|
});
|
|
1512
1823
|
});
|
|
1513
1824
|
}
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1825
|
+
verifyFarcaster(opts) {
|
|
1826
|
+
return __async(this, null, function* () {
|
|
1827
|
+
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
verifyFarcasterLink(opts) {
|
|
1831
|
+
return __async(this, null, function* () {
|
|
1832
|
+
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
getOAuthUrl(opts) {
|
|
1523
1836
|
return __async(this, null, function* () {
|
|
1524
|
-
var _j = _i, { method, deeplinkUrl } = _j, params = __objRest(_j, ["method", "deeplinkUrl"]);
|
|
1525
1837
|
var _a;
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
new URL(deeplinkUrl);
|
|
1529
|
-
} catch (e) {
|
|
1530
|
-
throw new Error("Invalid deeplink URL");
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
1534
|
-
return constructUrl({
|
|
1535
|
-
base: getBaseOAuthUrl(this.ctx.env),
|
|
1536
|
-
path: `/auth/${method}`,
|
|
1537
|
-
params: {
|
|
1538
|
-
apiKey: this.ctx.apiKey,
|
|
1539
|
-
sessionLookupId,
|
|
1540
|
-
deeplinkUrl
|
|
1541
|
-
}
|
|
1542
|
-
});
|
|
1838
|
+
const sessionLookupId = (_a = opts.sessionLookupId) != null ? _a : yield this.prepareLogin();
|
|
1839
|
+
return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
|
|
1543
1840
|
});
|
|
1544
1841
|
}
|
|
1545
1842
|
/**
|
|
@@ -1550,28 +1847,55 @@ const _ParaCore = class _ParaCore {
|
|
|
1550
1847
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1551
1848
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1552
1849
|
*/
|
|
1553
|
-
|
|
1850
|
+
verifyOAuthProcess(_i) {
|
|
1554
1851
|
return __async(this, null, function* () {
|
|
1555
|
-
var
|
|
1852
|
+
var _j = _i, {
|
|
1556
1853
|
method,
|
|
1557
|
-
|
|
1854
|
+
appScheme,
|
|
1558
1855
|
isCanceled = () => false,
|
|
1559
1856
|
onCancel,
|
|
1560
1857
|
onPoll,
|
|
1561
|
-
onOAuthUrl
|
|
1562
|
-
|
|
1858
|
+
onOAuthUrl,
|
|
1859
|
+
onOAuthPopup,
|
|
1860
|
+
isLinkAccount
|
|
1861
|
+
} = _j, urlOptions = __objRest(_j, [
|
|
1563
1862
|
"method",
|
|
1564
|
-
"
|
|
1863
|
+
"appScheme",
|
|
1565
1864
|
"isCanceled",
|
|
1566
1865
|
"onCancel",
|
|
1567
1866
|
"onPoll",
|
|
1568
|
-
"onOAuthUrl"
|
|
1867
|
+
"onOAuthUrl",
|
|
1868
|
+
"onOAuthPopup",
|
|
1869
|
+
"isLinkAccount"
|
|
1569
1870
|
]);
|
|
1570
|
-
let
|
|
1571
|
-
if (
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1871
|
+
let popupWindow;
|
|
1872
|
+
if (onOAuthPopup) {
|
|
1873
|
+
try {
|
|
1874
|
+
popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.OAUTH });
|
|
1875
|
+
} catch (error) {
|
|
1876
|
+
throw new Error(`Failed to open OAuth popup: ${error}`);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
let sessionLookupId, accountLinkInProgress;
|
|
1880
|
+
if (onOAuthUrl || onOAuthPopup) {
|
|
1881
|
+
if (isLinkAccount) {
|
|
1882
|
+
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
|
|
1883
|
+
sessionLookupId = (yield this.touchSession()).sessionLookupId;
|
|
1884
|
+
} else {
|
|
1885
|
+
sessionLookupId = yield this.prepareLogin();
|
|
1886
|
+
}
|
|
1887
|
+
const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, appScheme, sessionLookupId, accountLinkInProgress });
|
|
1888
|
+
switch (true) {
|
|
1889
|
+
case !!onOAuthUrl: {
|
|
1890
|
+
onOAuthUrl(oAuthUrl);
|
|
1891
|
+
break;
|
|
1892
|
+
}
|
|
1893
|
+
case (!!onOAuthPopup && !!popupWindow): {
|
|
1894
|
+
popupWindow.location.href = oAuthUrl;
|
|
1895
|
+
onOAuthPopup(popupWindow);
|
|
1896
|
+
break;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1575
1899
|
} else {
|
|
1576
1900
|
({ sessionLookupId } = yield this.touchSession());
|
|
1577
1901
|
}
|
|
@@ -1582,17 +1906,29 @@ const _ParaCore = class _ParaCore {
|
|
|
1582
1906
|
try {
|
|
1583
1907
|
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1584
1908
|
onCancel == null ? void 0 : onCancel();
|
|
1585
|
-
return reject(
|
|
1909
|
+
return reject(AccountLinkError.Canceled);
|
|
1586
1910
|
}
|
|
1587
1911
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1912
|
+
switch (isLinkAccount) {
|
|
1913
|
+
case false:
|
|
1914
|
+
{
|
|
1915
|
+
const serverAuthState = yield this.ctx.client.verifyOAuth();
|
|
1916
|
+
if (isServerAuthState(serverAuthState)) {
|
|
1917
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1918
|
+
return resolve(authState);
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
break;
|
|
1922
|
+
case true: {
|
|
1923
|
+
const accounts = yield this.verifyLink({ accountLinkInProgress });
|
|
1924
|
+
return resolve(accounts);
|
|
1925
|
+
}
|
|
1592
1926
|
}
|
|
1593
1927
|
onPoll == null ? void 0 : onPoll();
|
|
1594
1928
|
} catch (err) {
|
|
1595
|
-
|
|
1929
|
+
if (isLinkAccount && err.message === AccountLinkError.Conflict) {
|
|
1930
|
+
return reject(err.message);
|
|
1931
|
+
}
|
|
1596
1932
|
onPoll == null ? void 0 : onPoll();
|
|
1597
1933
|
}
|
|
1598
1934
|
}
|
|
@@ -1600,6 +1936,16 @@ const _ParaCore = class _ParaCore {
|
|
|
1600
1936
|
});
|
|
1601
1937
|
});
|
|
1602
1938
|
}
|
|
1939
|
+
verifyOAuth(opts) {
|
|
1940
|
+
return __async(this, null, function* () {
|
|
1941
|
+
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
verifyOAuthLink(opts) {
|
|
1945
|
+
return __async(this, null, function* () {
|
|
1946
|
+
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1603
1949
|
/**
|
|
1604
1950
|
* Waits for the session to be active and sets up the user.
|
|
1605
1951
|
*
|
|
@@ -1685,7 +2031,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1685
2031
|
sessionId
|
|
1686
2032
|
});
|
|
1687
2033
|
if (shouldOpenPopup) {
|
|
1688
|
-
this.platformUtils.openPopup(link);
|
|
2034
|
+
yield this.platformUtils.openPopup(link);
|
|
1689
2035
|
}
|
|
1690
2036
|
return link;
|
|
1691
2037
|
});
|
|
@@ -2229,25 +2575,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2229
2575
|
});
|
|
2230
2576
|
});
|
|
2231
2577
|
}
|
|
2232
|
-
getOnRampTransactionUrl(
|
|
2233
|
-
return __async(this,
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
providerKey
|
|
2237
|
-
} = _n, walletParams = __objRest(_n, [
|
|
2238
|
-
"purchaseId",
|
|
2239
|
-
"providerKey"
|
|
2240
|
-
]);
|
|
2241
|
-
const { sessionId } = yield this.touchSession();
|
|
2242
|
-
const [key, identifier] = extractWalletRef(walletParams);
|
|
2578
|
+
getOnRampTransactionUrl(_0) {
|
|
2579
|
+
return __async(this, arguments, function* ({
|
|
2580
|
+
purchaseId
|
|
2581
|
+
}) {
|
|
2243
2582
|
return this.constructPortalUrl("onRamp", {
|
|
2244
|
-
pathId: purchaseId
|
|
2245
|
-
sessionId,
|
|
2246
|
-
params: {
|
|
2247
|
-
[key]: identifier,
|
|
2248
|
-
providerKey,
|
|
2249
|
-
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
2250
|
-
}
|
|
2583
|
+
pathId: purchaseId
|
|
2251
2584
|
});
|
|
2252
2585
|
});
|
|
2253
2586
|
}
|
|
@@ -2281,7 +2614,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2281
2614
|
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2282
2615
|
let timeStart = Date.now();
|
|
2283
2616
|
if (signRes.pendingTransactionId) {
|
|
2284
|
-
this.platformUtils.openPopup(
|
|
2617
|
+
yield this.platformUtils.openPopup(
|
|
2285
2618
|
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2286
2619
|
{ type: cosmosSignDocBase64 ? PopupType.SIGN_TRANSACTION_REVIEW : PopupType.SIGN_MESSAGE_REVIEW }
|
|
2287
2620
|
);
|
|
@@ -2393,7 +2726,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2393
2726
|
);
|
|
2394
2727
|
let timeStart = Date.now();
|
|
2395
2728
|
if (signRes.pendingTransactionId) {
|
|
2396
|
-
this.platformUtils.openPopup(
|
|
2729
|
+
yield this.platformUtils.openPopup(
|
|
2397
2730
|
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2398
2731
|
{ type: PopupType.SIGN_TRANSACTION_REVIEW }
|
|
2399
2732
|
);
|
|
@@ -2469,7 +2802,8 @@ const _ParaCore = class _ParaCore {
|
|
|
2469
2802
|
providerKey: onRampPurchase.providerKey
|
|
2470
2803
|
}, walletParams));
|
|
2471
2804
|
if (shouldOpenPopup) {
|
|
2472
|
-
this.platformUtils.openPopup(portalUrl, { type: PopupType.ON_RAMP_TRANSACTION });
|
|
2805
|
+
const onRampWindow = yield this.platformUtils.openPopup(portalUrl, { type: PopupType.ON_RAMP_TRANSACTION });
|
|
2806
|
+
this.onRampPopup = { window: onRampWindow, onRampPurchase };
|
|
2473
2807
|
}
|
|
2474
2808
|
return { onRampPurchase, portalUrl };
|
|
2475
2809
|
});
|
|
@@ -2552,6 +2886,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2552
2886
|
return sessionLookupId;
|
|
2553
2887
|
});
|
|
2554
2888
|
}
|
|
2889
|
+
issueJwt() {
|
|
2890
|
+
return __async(this, arguments, function* ({ keyIndex = 0 } = {}) {
|
|
2891
|
+
const res = yield this.ctx.client.issueJwt({ keyIndex });
|
|
2892
|
+
return res;
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2555
2895
|
/**
|
|
2556
2896
|
* Logs the user out.
|
|
2557
2897
|
* @param {Object} opts the options object.
|
|
@@ -2559,6 +2899,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2559
2899
|
**/
|
|
2560
2900
|
logout() {
|
|
2561
2901
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
2902
|
+
const shouldDispatchLogoutEvent = yield this.isSessionActive();
|
|
2562
2903
|
yield this.ctx.client.logout();
|
|
2563
2904
|
yield this.clearStorage();
|
|
2564
2905
|
if (!clearPregenWallets) {
|
|
@@ -2575,22 +2916,17 @@ const _ParaCore = class _ParaCore {
|
|
|
2575
2916
|
this.externalWallets = {};
|
|
2576
2917
|
this.loginEncryptionKeyPair = void 0;
|
|
2577
2918
|
__privateSet(this, _authInfo, void 0);
|
|
2919
|
+
this.accountLinkInProgress = void 0;
|
|
2578
2920
|
this.userId = void 0;
|
|
2579
2921
|
this.sessionCookie = void 0;
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
}
|
|
2583
|
-
/** @deprecated */
|
|
2584
|
-
getSupportedCreateAuthMethods() {
|
|
2585
|
-
return __async(this, null, function* () {
|
|
2586
|
-
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2587
|
-
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
2588
|
-
for (const authMethod of partner.supportedAuthMethods) {
|
|
2589
|
-
supportedAuthMethods.add(AuthMethod[authMethod]);
|
|
2922
|
+
if (shouldDispatchLogoutEvent) {
|
|
2923
|
+
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
2590
2924
|
}
|
|
2591
|
-
return supportedAuthMethods;
|
|
2592
2925
|
});
|
|
2593
2926
|
}
|
|
2927
|
+
get toStringAdditions() {
|
|
2928
|
+
return {};
|
|
2929
|
+
}
|
|
2594
2930
|
/**
|
|
2595
2931
|
* Converts to a string, removing sensitive data when logging this class.
|
|
2596
2932
|
*
|
|
@@ -2614,10 +2950,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2614
2950
|
}),
|
|
2615
2951
|
{}
|
|
2616
2952
|
);
|
|
2617
|
-
const obj = {
|
|
2618
|
-
partnerId: (_a =
|
|
2619
|
-
supportedWalletTypes: (_b =
|
|
2620
|
-
cosmosPrefix: (_c =
|
|
2953
|
+
const obj = __spreadProps(__spreadValues({
|
|
2954
|
+
partnerId: (_a = this.partner) == null ? void 0 : _a.id,
|
|
2955
|
+
supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
|
|
2956
|
+
cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
|
|
2621
2957
|
authInfo: __privateGet(this, _authInfo),
|
|
2622
2958
|
isGuestMode: this.isGuestMode,
|
|
2623
2959
|
userId: this.userId,
|
|
@@ -2627,6 +2963,8 @@ const _ParaCore = class _ParaCore {
|
|
|
2627
2963
|
wallets: redactedWallets,
|
|
2628
2964
|
externalWallets: redactedExternalWallets,
|
|
2629
2965
|
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
2966
|
+
isReady: this.isReady
|
|
2967
|
+
}, this.toStringAdditions), {
|
|
2630
2968
|
ctx: {
|
|
2631
2969
|
apiKey: this.ctx.apiKey,
|
|
2632
2970
|
disableWorkers: this.ctx.disableWorkers,
|
|
@@ -2637,9 +2975,14 @@ const _ParaCore = class _ParaCore {
|
|
|
2637
2975
|
useDKLS: this.ctx.useDKLS,
|
|
2638
2976
|
cosmosPrefix: this.ctx.cosmosPrefix
|
|
2639
2977
|
}
|
|
2640
|
-
};
|
|
2978
|
+
});
|
|
2641
2979
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
2642
2980
|
}
|
|
2981
|
+
devLog(...s) {
|
|
2982
|
+
if (this.ctx.env === Environment.DEV || this.ctx.env === Environment.SANDBOX) {
|
|
2983
|
+
console.log(...s);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2643
2986
|
getNewCredentialAndUrl() {
|
|
2644
2987
|
return __async(this, arguments, function* ({
|
|
2645
2988
|
authMethod = "PASSKEY",
|
|
@@ -2667,6 +3010,14 @@ const _ParaCore = class _ParaCore {
|
|
|
2667
3010
|
}));
|
|
2668
3011
|
urlType = "createPassword";
|
|
2669
3012
|
break;
|
|
3013
|
+
case "PIN":
|
|
3014
|
+
({
|
|
3015
|
+
data: { id: credentialId }
|
|
3016
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3017
|
+
status: PasswordStatus.PENDING
|
|
3018
|
+
}));
|
|
3019
|
+
urlType = "createPIN";
|
|
3020
|
+
break;
|
|
2670
3021
|
}
|
|
2671
3022
|
const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
|
|
2672
3023
|
isForNewDevice,
|
|
@@ -2678,7 +3029,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2678
3029
|
});
|
|
2679
3030
|
}
|
|
2680
3031
|
/**
|
|
2681
|
-
* Returns a Para Portal URL for logging in with a WebAuth passkey or
|
|
3032
|
+
* Returns a Para Portal URL for logging in with a WebAuth passkey, password or PIN.
|
|
2682
3033
|
* @param {Object} opts the options object
|
|
2683
3034
|
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
2684
3035
|
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
@@ -2704,6 +3055,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2704
3055
|
case "PASSWORD":
|
|
2705
3056
|
urlType = "loginPassword";
|
|
2706
3057
|
break;
|
|
3058
|
+
case "PIN":
|
|
3059
|
+
urlType = "loginPIN";
|
|
3060
|
+
break;
|
|
2707
3061
|
default:
|
|
2708
3062
|
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
2709
3063
|
}
|
|
@@ -2714,53 +3068,193 @@ const _ParaCore = class _ParaCore {
|
|
|
2714
3068
|
});
|
|
2715
3069
|
});
|
|
2716
3070
|
}
|
|
2717
|
-
|
|
3071
|
+
prepareLogin() {
|
|
3072
|
+
return __async(this, null, function* () {
|
|
3073
|
+
yield this.logout();
|
|
3074
|
+
const { sessionLookupId } = yield this.touchSession(true);
|
|
3075
|
+
if (!this.loginEncryptionKeyPair) {
|
|
3076
|
+
yield this.setLoginEncryptionKeyPair();
|
|
3077
|
+
}
|
|
3078
|
+
return sessionLookupId;
|
|
3079
|
+
});
|
|
3080
|
+
}
|
|
3081
|
+
signUpOrLogIn(_k) {
|
|
2718
3082
|
return __async(this, null, function* () {
|
|
2719
|
-
var
|
|
3083
|
+
var _l = _k, { auth } = _l, urlOptions = __objRest(_l, ["auth"]);
|
|
2720
3084
|
const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
3085
|
+
const authInfo = serverAuthState.auth;
|
|
3086
|
+
if (this.fetchPregenWalletsOverride && isPregenAuth(authInfo)) {
|
|
3087
|
+
const { userShare } = yield this.fetchPregenWalletsOverride({ pregenId: authInfo });
|
|
3088
|
+
if (userShare) {
|
|
3089
|
+
yield this.setUserShare(userShare);
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
2721
3092
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2722
3093
|
});
|
|
2723
3094
|
}
|
|
2724
|
-
verifyNewAccount(
|
|
3095
|
+
verifyNewAccount(_m) {
|
|
2725
3096
|
return __async(this, null, function* () {
|
|
2726
|
-
var
|
|
3097
|
+
var _n = _m, {
|
|
2727
3098
|
verificationCode
|
|
2728
|
-
} =
|
|
3099
|
+
} = _n, urlOptions = __objRest(_n, [
|
|
2729
3100
|
"verificationCode"
|
|
2730
3101
|
]);
|
|
2731
3102
|
this.assertIsAuthSet(["email", "phone"]);
|
|
2732
|
-
const userId = this.assertUserId();
|
|
2733
|
-
const serverAuthState = yield this.ctx.client.
|
|
3103
|
+
const userId = this.assertUserId({ allowGuestMode: true });
|
|
3104
|
+
const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
|
|
2734
3105
|
verificationCode
|
|
2735
3106
|
});
|
|
3107
|
+
if (serverAuthState.stage === "login") {
|
|
3108
|
+
throw new Error("Account already exists.");
|
|
3109
|
+
}
|
|
2736
3110
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2737
3111
|
});
|
|
2738
3112
|
}
|
|
3113
|
+
getLinkedAccounts() {
|
|
3114
|
+
return __async(this, arguments, function* ({
|
|
3115
|
+
withMetadata = false
|
|
3116
|
+
} = {}) {
|
|
3117
|
+
const userId = this.assertUserId();
|
|
3118
|
+
const { accounts } = yield this.ctx.client.getLinkedAccounts({ userId, withMetadata });
|
|
3119
|
+
return __spreadValues({
|
|
3120
|
+
userId
|
|
3121
|
+
}, accounts);
|
|
3122
|
+
});
|
|
3123
|
+
}
|
|
3124
|
+
linkAccount(opts) {
|
|
3125
|
+
return __async(this, null, function* () {
|
|
3126
|
+
const { supportedAccountLinks = [...LINKED_ACCOUNT_TYPES] } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3127
|
+
let type, identifier, externalWallet, isPermitted;
|
|
3128
|
+
switch (true) {
|
|
3129
|
+
case "auth" in opts:
|
|
3130
|
+
{
|
|
3131
|
+
const authInfo = extractAuthInfo(opts.auth, { isRequired: true });
|
|
3132
|
+
if (authInfo.auth === this.authInfo.auth) {
|
|
3133
|
+
throw new Error(AccountLinkError.Conflict);
|
|
3134
|
+
}
|
|
3135
|
+
type = authInfo.authType.toUpperCase();
|
|
3136
|
+
identifier = authInfo.identifier;
|
|
3137
|
+
isPermitted = supportedAccountLinks.includes(type);
|
|
3138
|
+
}
|
|
3139
|
+
break;
|
|
3140
|
+
case "externalWallet" in opts:
|
|
3141
|
+
{
|
|
3142
|
+
externalWallet = opts.externalWallet;
|
|
3143
|
+
type = "EXTERNAL_WALLET";
|
|
3144
|
+
isPermitted = supportedAccountLinks.includes("EXTERNAL_WALLET") || supportedAccountLinks.includes(externalWallet.providerId);
|
|
3145
|
+
}
|
|
3146
|
+
break;
|
|
3147
|
+
case "type" in opts:
|
|
3148
|
+
{
|
|
3149
|
+
type = opts.type;
|
|
3150
|
+
if (type === "X") {
|
|
3151
|
+
type = "TWITTER";
|
|
3152
|
+
}
|
|
3153
|
+
isPermitted = supportedAccountLinks.includes(type);
|
|
3154
|
+
}
|
|
3155
|
+
break;
|
|
3156
|
+
default:
|
|
3157
|
+
throw new Error("Invalid parameters for linking account, must pass `auth` or `type` or `externalWallet");
|
|
3158
|
+
}
|
|
3159
|
+
if (!isPermitted) {
|
|
3160
|
+
throw new Error(`Account linking for type '${type}' is not supported by the current API key configuration`);
|
|
3161
|
+
}
|
|
3162
|
+
const userId = this.assertUserId();
|
|
3163
|
+
const result = yield this.ctx.client.linkAccount(__spreadValues(__spreadValues({
|
|
3164
|
+
userId,
|
|
3165
|
+
type
|
|
3166
|
+
}, identifier ? { identifier } : {}), externalWallet ? { externalWallet } : {}));
|
|
3167
|
+
if ("isConflict" in result) {
|
|
3168
|
+
throw new Error(AccountLinkError.Conflict);
|
|
3169
|
+
}
|
|
3170
|
+
const { linkedAccountId, signatureVerificationMessage } = result;
|
|
3171
|
+
this.accountLinkInProgress = __spreadValues(__spreadValues({
|
|
3172
|
+
id: linkedAccountId,
|
|
3173
|
+
type,
|
|
3174
|
+
isComplete: false
|
|
3175
|
+
}, identifier ? { identifier } : {}), signatureVerificationMessage && externalWallet ? {
|
|
3176
|
+
externalWallet: __spreadProps(__spreadValues({}, externalWallet), {
|
|
3177
|
+
signatureVerificationMessage
|
|
3178
|
+
})
|
|
3179
|
+
} : {});
|
|
3180
|
+
return this.accountLinkInProgress;
|
|
3181
|
+
});
|
|
3182
|
+
}
|
|
3183
|
+
unlinkAccount(_0) {
|
|
3184
|
+
return __async(this, arguments, function* ({
|
|
3185
|
+
linkedAccountId
|
|
3186
|
+
}) {
|
|
3187
|
+
if (!linkedAccountId) {
|
|
3188
|
+
throw new Error("No linked account ID provided");
|
|
3189
|
+
}
|
|
3190
|
+
const userId = this.assertUserId();
|
|
3191
|
+
const accounts = yield this.ctx.client.unlinkAccount({ linkedAccountId, userId });
|
|
3192
|
+
return accounts;
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
verifyLink() {
|
|
3196
|
+
return __async(this, arguments, function* (_o = {}) {
|
|
3197
|
+
var _p = _o, {
|
|
3198
|
+
accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
|
|
3199
|
+
} = _p, opts = __objRest(_p, [
|
|
3200
|
+
"accountLinkInProgress"
|
|
3201
|
+
]);
|
|
3202
|
+
try {
|
|
3203
|
+
const userId = this.assertUserId(), result = yield this.ctx.client.verifyLink(__spreadValues({
|
|
3204
|
+
linkedAccountId: accountLinkInProgress.id,
|
|
3205
|
+
userId
|
|
3206
|
+
}, opts));
|
|
3207
|
+
if ("isConflict" in result) {
|
|
3208
|
+
throw new Error(AccountLinkError.Conflict);
|
|
3209
|
+
}
|
|
3210
|
+
this.accountLinkInProgress = void 0;
|
|
3211
|
+
return result.accounts;
|
|
3212
|
+
} catch (e) {
|
|
3213
|
+
throw new Error(e.message === AccountLinkError.Conflict ? AccountLinkError.Conflict : e.message);
|
|
3214
|
+
}
|
|
3215
|
+
});
|
|
3216
|
+
}
|
|
3217
|
+
verifyEmailOrPhoneLink(_0) {
|
|
3218
|
+
return __async(this, arguments, function* ({
|
|
3219
|
+
verificationCode
|
|
3220
|
+
}) {
|
|
3221
|
+
const accounts = yield this.verifyLink({
|
|
3222
|
+
accountLinkInProgress: __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]),
|
|
3223
|
+
verificationCode
|
|
3224
|
+
});
|
|
3225
|
+
return accounts;
|
|
3226
|
+
});
|
|
3227
|
+
}
|
|
3228
|
+
sendLoginCode() {
|
|
3229
|
+
return __async(this, null, function* () {
|
|
3230
|
+
const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
|
|
3231
|
+
this.setUserId(userId);
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
2739
3234
|
};
|
|
2740
3235
|
_authInfo = new WeakMap();
|
|
2741
|
-
_partner = new WeakMap();
|
|
2742
3236
|
_ParaCore_instances = new WeakSet();
|
|
2743
3237
|
assertPartner_fn = function() {
|
|
2744
3238
|
return __async(this, null, function* () {
|
|
2745
3239
|
var _a, _b;
|
|
2746
|
-
if (!
|
|
3240
|
+
if (!this.partner) {
|
|
2747
3241
|
yield this.touchSession();
|
|
2748
3242
|
}
|
|
2749
|
-
if (((_a =
|
|
2750
|
-
this.ctx.cosmosPrefix = (_b =
|
|
3243
|
+
if (((_a = this.partner) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== this.partner.cosmosPrefix) {
|
|
3244
|
+
this.ctx.cosmosPrefix = (_b = this.partner) == null ? void 0 : _b.cosmosPrefix;
|
|
2751
3245
|
}
|
|
2752
|
-
return
|
|
3246
|
+
return this.partner;
|
|
2753
3247
|
});
|
|
2754
3248
|
};
|
|
2755
3249
|
guestWalletIds_get = function() {
|
|
2756
3250
|
var _a, _b, _c;
|
|
2757
|
-
if (!((_a =
|
|
3251
|
+
if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
2758
3252
|
return {};
|
|
2759
3253
|
}
|
|
2760
3254
|
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
2761
3255
|
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
2762
3256
|
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
2763
|
-
return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) =>
|
|
3257
|
+
return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
2764
3258
|
var _a2;
|
|
2765
3259
|
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
2766
3260
|
}, {}));
|
|
@@ -2817,9 +3311,57 @@ setAuthInfo_fn = function(authInfo) {
|
|
|
2817
3311
|
};
|
|
2818
3312
|
getPartner_fn = function(partnerId) {
|
|
2819
3313
|
return __async(this, null, function* () {
|
|
3314
|
+
if (this.isPartnerOptional && !partnerId) {
|
|
3315
|
+
return void 0;
|
|
3316
|
+
}
|
|
2820
3317
|
const res = yield this.ctx.client.getPartner(partnerId);
|
|
2821
|
-
|
|
2822
|
-
return
|
|
3318
|
+
this.partner = res.data.partner;
|
|
3319
|
+
return this.partner;
|
|
3320
|
+
});
|
|
3321
|
+
};
|
|
3322
|
+
assertIsLinkingAccount_fn = function(types) {
|
|
3323
|
+
if (!this.accountLinkInProgress || this.accountLinkInProgress.isComplete) {
|
|
3324
|
+
throw new Error("no account linking in progress");
|
|
3325
|
+
}
|
|
3326
|
+
if (types && !types.includes(this.accountLinkInProgress.type)) {
|
|
3327
|
+
throw new Error(
|
|
3328
|
+
`account linking in progress for type ${this.accountLinkInProgress.type}, expected one of ${types.join(", ")}`
|
|
3329
|
+
);
|
|
3330
|
+
}
|
|
3331
|
+
return this.accountLinkInProgress;
|
|
3332
|
+
};
|
|
3333
|
+
assertIsLinkingAccountOrStart_fn = function(type) {
|
|
3334
|
+
return __async(this, null, function* () {
|
|
3335
|
+
if (this.accountLinkInProgress && !this.accountLinkInProgress.isComplete) {
|
|
3336
|
+
return __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, [type]);
|
|
3337
|
+
}
|
|
3338
|
+
return yield this.linkAccount({ type });
|
|
3339
|
+
});
|
|
3340
|
+
};
|
|
3341
|
+
/**
|
|
3342
|
+
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
3343
|
+
*
|
|
3344
|
+
* @param {Object} opts the options object
|
|
3345
|
+
* @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
|
|
3346
|
+
* @param {string} [opts.appScheme] the app scheme to redirect to after the OAuth flow. This is for mobile only.
|
|
3347
|
+
* @returns {string} the URL for the user to log in with OAuth.
|
|
3348
|
+
*/
|
|
3349
|
+
getOAuthUrl_fn = function({
|
|
3350
|
+
method,
|
|
3351
|
+
appScheme,
|
|
3352
|
+
accountLinkInProgress,
|
|
3353
|
+
sessionLookupId
|
|
3354
|
+
}) {
|
|
3355
|
+
return constructUrl({
|
|
3356
|
+
base: getBaseOAuthUrl(this.ctx.env),
|
|
3357
|
+
path: `/auth/${method}`,
|
|
3358
|
+
params: __spreadValues({
|
|
3359
|
+
apiKey: this.ctx.apiKey,
|
|
3360
|
+
sessionLookupId,
|
|
3361
|
+
appScheme
|
|
3362
|
+
}, accountLinkInProgress ? {
|
|
3363
|
+
linkedAccountId: this.accountLinkInProgress.id
|
|
3364
|
+
} : {})
|
|
2823
3365
|
});
|
|
2824
3366
|
};
|
|
2825
3367
|
createPregenWallet_fn = function(opts) {
|
|
@@ -2872,8 +3414,9 @@ createPregenWallet_fn = function(opts) {
|
|
|
2872
3414
|
_isCreateGuestWalletsPending = new WeakMap();
|
|
2873
3415
|
prepareAuthState_fn = function(_0) {
|
|
2874
3416
|
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
2875
|
-
|
|
2876
|
-
|
|
3417
|
+
var _a, _b;
|
|
3418
|
+
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))))) {
|
|
3419
|
+
opts.sessionLookupId = yield this.prepareLogin();
|
|
2877
3420
|
}
|
|
2878
3421
|
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
2879
3422
|
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), Object.fromEntries(
|
|
@@ -2887,7 +3430,7 @@ prepareAuthState_fn = function(_0) {
|
|
|
2887
3430
|
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
2888
3431
|
yield this.assertIsAuthSet();
|
|
2889
3432
|
if (!!externalWallet) {
|
|
2890
|
-
yield this.setExternalWallet(externalWallet);
|
|
3433
|
+
yield this.setExternalWallet([externalWallet]);
|
|
2891
3434
|
}
|
|
2892
3435
|
if (!!userId) {
|
|
2893
3436
|
yield this.setUserId(userId);
|
|
@@ -2898,33 +3441,34 @@ prepareAuthState_fn = function(_0) {
|
|
|
2898
3441
|
authState = serverAuthState;
|
|
2899
3442
|
break;
|
|
2900
3443
|
case "login":
|
|
3444
|
+
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
3445
|
+
authState = serverAuthState;
|
|
3446
|
+
break;
|
|
3447
|
+
}
|
|
2901
3448
|
authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
|
|
2902
3449
|
break;
|
|
2903
3450
|
case "signup":
|
|
3451
|
+
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
3452
|
+
authState = serverAuthState;
|
|
3453
|
+
break;
|
|
3454
|
+
}
|
|
2904
3455
|
authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
|
|
2905
3456
|
break;
|
|
2906
3457
|
}
|
|
2907
3458
|
return authState;
|
|
2908
3459
|
});
|
|
2909
3460
|
};
|
|
2910
|
-
prepareLogin_fn = function() {
|
|
2911
|
-
return __async(this, null, function* () {
|
|
2912
|
-
yield this.logout();
|
|
2913
|
-
const { sessionLookupId } = yield this.touchSession(true);
|
|
2914
|
-
if (!this.loginEncryptionKeyPair) {
|
|
2915
|
-
yield this.setLoginEncryptionKeyPair();
|
|
2916
|
-
}
|
|
2917
|
-
return sessionLookupId;
|
|
2918
|
-
});
|
|
2919
|
-
};
|
|
2920
3461
|
prepareLoginState_fn = function(_0, _1) {
|
|
2921
3462
|
return __async(this, arguments, function* (loginState, {
|
|
2922
3463
|
useShortUrls: shorten = false,
|
|
2923
3464
|
portalTheme,
|
|
2924
3465
|
sessionLookupId
|
|
2925
3466
|
}) {
|
|
2926
|
-
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
2927
|
-
|
|
3467
|
+
const _a = loginState, { loginAuthMethods, hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
|
|
3468
|
+
const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(AuthMethod.PASSWORD) && hasPasswordWithoutPIN, isPINPossible = loginAuthMethods.includes(AuthMethod.PIN);
|
|
3469
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
3470
|
+
isPasskeySupported
|
|
3471
|
+
}), isPasskeyPossible ? {
|
|
2928
3472
|
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
2929
3473
|
passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
|
|
2930
3474
|
sessionId: sessionLookupId,
|
|
@@ -2935,11 +3479,19 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
2935
3479
|
shorten,
|
|
2936
3480
|
portalTheme
|
|
2937
3481
|
})
|
|
2938
|
-
} : {}),
|
|
3482
|
+
} : {}), isPasswordPossible ? {
|
|
2939
3483
|
passwordUrl: yield this.constructPortalUrl("loginPassword", {
|
|
2940
3484
|
sessionId: sessionLookupId,
|
|
2941
3485
|
shorten,
|
|
2942
|
-
portalTheme
|
|
3486
|
+
portalTheme,
|
|
3487
|
+
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
3488
|
+
})
|
|
3489
|
+
} : {}), isPINPossible ? {
|
|
3490
|
+
pinUrl: yield this.constructPortalUrl("loginPIN", {
|
|
3491
|
+
sessionId: sessionLookupId,
|
|
3492
|
+
shorten,
|
|
3493
|
+
portalTheme,
|
|
3494
|
+
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
2943
3495
|
})
|
|
2944
3496
|
} : {});
|
|
2945
3497
|
});
|
|
@@ -2947,16 +3499,18 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
2947
3499
|
prepareSignUpState_fn = function(_0, _1) {
|
|
2948
3500
|
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
2949
3501
|
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
2950
|
-
const
|
|
3502
|
+
const isPasskeySupported = yield this.isPasskeySupported();
|
|
3503
|
+
const [isPasskey, isPassword, isPIN] = [
|
|
2951
3504
|
signupAuthMethods.includes(AuthMethod.PASSKEY),
|
|
2952
|
-
signupAuthMethods.includes(AuthMethod.PASSWORD)
|
|
3505
|
+
signupAuthMethods.includes(AuthMethod.PASSWORD) || !isPasskeySupported,
|
|
3506
|
+
signupAuthMethods.includes(AuthMethod.PIN)
|
|
2953
3507
|
];
|
|
2954
|
-
if (!isPasskey && !isPassword) {
|
|
3508
|
+
if (!isPasskey && !isPassword && !isPIN) {
|
|
2955
3509
|
throw new Error(
|
|
2956
|
-
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or
|
|
3510
|
+
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
|
|
2957
3511
|
);
|
|
2958
3512
|
}
|
|
2959
|
-
const signupState = authState;
|
|
3513
|
+
const signupState = __spreadProps(__spreadValues({}, authState), { isPasskeySupported });
|
|
2960
3514
|
if (isPasskey) {
|
|
2961
3515
|
const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
|
|
2962
3516
|
authMethod: "PASSKEY",
|
|
@@ -2974,6 +3528,15 @@ prepareSignUpState_fn = function(_0, _1) {
|
|
|
2974
3528
|
signupState.passwordUrl = passwordUrl;
|
|
2975
3529
|
signupState.passwordId = passwordId;
|
|
2976
3530
|
}
|
|
3531
|
+
if (isPIN) {
|
|
3532
|
+
const { url: pinUrl, credentialId: pinId } = yield this.getNewCredentialAndUrl({
|
|
3533
|
+
authMethod: "PIN",
|
|
3534
|
+
portalTheme,
|
|
3535
|
+
shorten
|
|
3536
|
+
});
|
|
3537
|
+
signupState.pinUrl = pinUrl;
|
|
3538
|
+
signupState.pinId = pinId;
|
|
3539
|
+
}
|
|
2977
3540
|
return signupState;
|
|
2978
3541
|
});
|
|
2979
3542
|
};
|