@getpara/core-sdk 2.0.0-alpha.38 → 2.0.0-alpha.40
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 +97 -39
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/types/coreApi.js +2 -1
- package/dist/esm/ParaCore.js +97 -39
- package/dist/esm/constants.js +1 -1
- package/dist/esm/types/coreApi.js +2 -1
- package/dist/types/ParaCore.d.ts +9 -2
- package/dist/types/types/coreApi.d.ts +6 -2
- package/dist/types/types/methods.d.ts +14 -2
- package/package.json +3 -3
package/dist/cjs/ParaCore.js
CHANGED
|
@@ -99,7 +99,7 @@ var import_recovery = require("./shares/recovery.js");
|
|
|
99
99
|
var import_utils2 = require("./utils/index.js");
|
|
100
100
|
var import_errors = require("./errors.js");
|
|
101
101
|
var constants = __toESM(require("./constants.js"));
|
|
102
|
-
var _authInfo,
|
|
102
|
+
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;
|
|
103
103
|
if (typeof global !== "undefined") {
|
|
104
104
|
global.Buffer = global.Buffer || import_buffer.Buffer;
|
|
105
105
|
} else if (typeof window !== "undefined") {
|
|
@@ -123,7 +123,6 @@ const _ParaCore = class _ParaCore {
|
|
|
123
123
|
__privateAdd(this, _authInfo);
|
|
124
124
|
this.isNativePasskey = false;
|
|
125
125
|
this.isReady = false;
|
|
126
|
-
__privateAdd(this, _partner);
|
|
127
126
|
this.accountLinkInProgress = void 0;
|
|
128
127
|
this.isAwaitingAccountCreation = false;
|
|
129
128
|
this.isAwaitingLogin = false;
|
|
@@ -465,11 +464,19 @@ const _ParaCore = class _ParaCore {
|
|
|
465
464
|
}
|
|
466
465
|
get partnerId() {
|
|
467
466
|
var _a;
|
|
468
|
-
return (_a =
|
|
467
|
+
return (_a = this.partner) == null ? void 0 : _a.id;
|
|
468
|
+
}
|
|
469
|
+
get partnerName() {
|
|
470
|
+
var _a;
|
|
471
|
+
return (_a = this.partner) == null ? void 0 : _a.displayName;
|
|
472
|
+
}
|
|
473
|
+
get partnerLogo() {
|
|
474
|
+
var _a;
|
|
475
|
+
return (_a = this.partner) == null ? void 0 : _a.logoUrl;
|
|
469
476
|
}
|
|
470
477
|
get currentWalletIdsArray() {
|
|
471
478
|
var _a, _b;
|
|
472
|
-
return ((_b = (_a =
|
|
479
|
+
return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
473
480
|
(acc, { type }) => {
|
|
474
481
|
var _a2;
|
|
475
482
|
return [
|
|
@@ -509,23 +516,23 @@ const _ParaCore = class _ParaCore {
|
|
|
509
516
|
}
|
|
510
517
|
get isNoWalletConfig() {
|
|
511
518
|
var _a;
|
|
512
|
-
return !!((_a =
|
|
519
|
+
return !!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) && this.partner.supportedWalletTypes.length === 0;
|
|
513
520
|
}
|
|
514
521
|
get supportedWalletTypes() {
|
|
515
522
|
var _a, _b;
|
|
516
|
-
return (_b = (_a =
|
|
523
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
517
524
|
}
|
|
518
525
|
get cosmosPrefix() {
|
|
519
526
|
var _a;
|
|
520
|
-
return (_a =
|
|
527
|
+
return (_a = this.partner) == null ? void 0 : _a.cosmosPrefix;
|
|
521
528
|
}
|
|
522
529
|
get supportedAccountLinks() {
|
|
523
530
|
var _a, _b;
|
|
524
|
-
return (_b = (_a =
|
|
531
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...import_user_management_client.LINKED_ACCOUNT_TYPES];
|
|
525
532
|
}
|
|
526
533
|
get isWalletTypeEnabled() {
|
|
527
534
|
var _a;
|
|
528
|
-
return (((_a =
|
|
535
|
+
return (((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
529
536
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
530
537
|
}, {});
|
|
531
538
|
}
|
|
@@ -574,7 +581,7 @@ const _ParaCore = class _ParaCore {
|
|
|
574
581
|
}
|
|
575
582
|
isWalletSupported(wallet) {
|
|
576
583
|
var _a, _b;
|
|
577
|
-
return !((_a =
|
|
584
|
+
return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || (0, import_utils2.isWalletSupported)((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
578
585
|
}
|
|
579
586
|
isWalletOwned(wallet) {
|
|
580
587
|
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;
|
|
@@ -605,7 +612,7 @@ const _ParaCore = class _ParaCore {
|
|
|
605
612
|
} else if (!isOwned && !isUnclaimed) {
|
|
606
613
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
607
614
|
} else if (!this.isWalletSupported(wallet)) {
|
|
608
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b =
|
|
615
|
+
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(", ")}`;
|
|
609
616
|
} else if (types && (!(0, import_utils2.getEquivalentTypes)(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
610
617
|
var _a2, _b2;
|
|
611
618
|
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
@@ -636,7 +643,7 @@ const _ParaCore = class _ParaCore {
|
|
|
636
643
|
if (this.externalWallets[walletId]) {
|
|
637
644
|
const wallet2 = this.externalWallets[walletId];
|
|
638
645
|
return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, {
|
|
639
|
-
prefix: (_a =
|
|
646
|
+
prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
|
|
640
647
|
targetLength: options.targetLength
|
|
641
648
|
}) : wallet2.address;
|
|
642
649
|
}
|
|
@@ -648,7 +655,7 @@ const _ParaCore = class _ParaCore {
|
|
|
648
655
|
let prefix;
|
|
649
656
|
switch (wallet.type) {
|
|
650
657
|
case "COSMOS":
|
|
651
|
-
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b =
|
|
658
|
+
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
652
659
|
str = (0, import_utils2.getCosmosAddress)(wallet.publicKey, prefix);
|
|
653
660
|
break;
|
|
654
661
|
default:
|
|
@@ -683,8 +690,8 @@ const _ParaCore = class _ParaCore {
|
|
|
683
690
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
684
691
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
685
692
|
const [isCreate, isLogin, isOnRamp] = [
|
|
686
|
-
["createAuth", "createPassword"].includes(type),
|
|
687
|
-
["loginAuth", "loginPassword"].includes(type),
|
|
693
|
+
["createAuth", "createPassword", "createPIN"].includes(type),
|
|
694
|
+
["loginAuth", "loginPassword", "loginPIN"].includes(type),
|
|
688
695
|
type === "onRamp"
|
|
689
696
|
];
|
|
690
697
|
if (isCreate || isLogin) {
|
|
@@ -705,6 +712,10 @@ const _ParaCore = class _ParaCore {
|
|
|
705
712
|
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
706
713
|
break;
|
|
707
714
|
}
|
|
715
|
+
case "createPIN": {
|
|
716
|
+
path = `/web/users/${this.userId}/pin/${opts.pathId}`;
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
708
719
|
case "createAuth": {
|
|
709
720
|
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
710
721
|
break;
|
|
@@ -717,6 +728,10 @@ const _ParaCore = class _ParaCore {
|
|
|
717
728
|
path = "/web/biometrics/login";
|
|
718
729
|
break;
|
|
719
730
|
}
|
|
731
|
+
case "loginPIN": {
|
|
732
|
+
path = "/web/pin/login";
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
720
735
|
case "txReview": {
|
|
721
736
|
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
722
737
|
break;
|
|
@@ -791,7 +806,7 @@ const _ParaCore = class _ParaCore {
|
|
|
791
806
|
yield this.ready();
|
|
792
807
|
}
|
|
793
808
|
const session = yield this.ctx.client.touchSession(regenerate);
|
|
794
|
-
if (!
|
|
809
|
+
if (!this.partner || ((_a = this.partner) == null ? void 0 : _a.id) !== session.partnerId || !(0, import_utils2.supportedWalletTypesEq)(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = this.partner) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
|
|
795
810
|
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
796
811
|
}
|
|
797
812
|
return session;
|
|
@@ -1522,6 +1537,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1522
1537
|
let type, linkedAccountId;
|
|
1523
1538
|
switch (reason) {
|
|
1524
1539
|
case "SIGNUP":
|
|
1540
|
+
case "LOGIN":
|
|
1525
1541
|
{
|
|
1526
1542
|
const authInfo = this.assertIsAuthSet(["email", "phone"]);
|
|
1527
1543
|
type = authInfo.authType.toUpperCase();
|
|
@@ -1592,10 +1608,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1592
1608
|
return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
|
|
1593
1609
|
({ userId, partnerId }) => {
|
|
1594
1610
|
var _a;
|
|
1595
|
-
return partnerId === ((_a =
|
|
1611
|
+
return partnerId === ((_a = this.partner) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
|
|
1596
1612
|
}
|
|
1597
1613
|
);
|
|
1598
1614
|
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Get the auth methods available to an existing user
|
|
1617
|
+
*/
|
|
1599
1618
|
supportedAuthMethods(auth) {
|
|
1600
1619
|
return __async(this, null, function* () {
|
|
1601
1620
|
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
@@ -2845,6 +2864,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2845
2864
|
**/
|
|
2846
2865
|
logout() {
|
|
2847
2866
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
2867
|
+
const shouldDispatchLogoutEvent = yield this.isSessionActive();
|
|
2848
2868
|
yield this.ctx.client.logout();
|
|
2849
2869
|
yield this.clearStorage();
|
|
2850
2870
|
if (!clearPregenWallets) {
|
|
@@ -2864,7 +2884,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2864
2884
|
this.accountLinkInProgress = void 0;
|
|
2865
2885
|
this.userId = void 0;
|
|
2866
2886
|
this.sessionCookie = void 0;
|
|
2867
|
-
(
|
|
2887
|
+
if (shouldDispatchLogoutEvent) {
|
|
2888
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
|
|
2889
|
+
}
|
|
2868
2890
|
});
|
|
2869
2891
|
}
|
|
2870
2892
|
get toStringAdditions() {
|
|
@@ -2894,9 +2916,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2894
2916
|
{}
|
|
2895
2917
|
);
|
|
2896
2918
|
const obj = __spreadProps(__spreadValues({
|
|
2897
|
-
partnerId: (_a =
|
|
2898
|
-
supportedWalletTypes: (_b =
|
|
2899
|
-
cosmosPrefix: (_c =
|
|
2919
|
+
partnerId: (_a = this.partner) == null ? void 0 : _a.id,
|
|
2920
|
+
supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
|
|
2921
|
+
cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
|
|
2900
2922
|
authInfo: __privateGet(this, _authInfo),
|
|
2901
2923
|
isGuestMode: this.isGuestMode,
|
|
2902
2924
|
userId: this.userId,
|
|
@@ -2953,6 +2975,14 @@ const _ParaCore = class _ParaCore {
|
|
|
2953
2975
|
}));
|
|
2954
2976
|
urlType = "createPassword";
|
|
2955
2977
|
break;
|
|
2978
|
+
case "PIN":
|
|
2979
|
+
({
|
|
2980
|
+
data: { id: credentialId }
|
|
2981
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
2982
|
+
status: import_user_management_client.PasswordStatus.PENDING
|
|
2983
|
+
}));
|
|
2984
|
+
urlType = "createPIN";
|
|
2985
|
+
break;
|
|
2956
2986
|
}
|
|
2957
2987
|
const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
|
|
2958
2988
|
isForNewDevice,
|
|
@@ -2964,7 +2994,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2964
2994
|
});
|
|
2965
2995
|
}
|
|
2966
2996
|
/**
|
|
2967
|
-
* Returns a Para Portal URL for logging in with a WebAuth passkey or
|
|
2997
|
+
* Returns a Para Portal URL for logging in with a WebAuth passkey, password or PIN.
|
|
2968
2998
|
* @param {Object} opts the options object
|
|
2969
2999
|
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
2970
3000
|
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
@@ -2990,6 +3020,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2990
3020
|
case "PASSWORD":
|
|
2991
3021
|
urlType = "loginPassword";
|
|
2992
3022
|
break;
|
|
3023
|
+
case "PIN":
|
|
3024
|
+
urlType = "loginPIN";
|
|
3025
|
+
break;
|
|
2993
3026
|
default:
|
|
2994
3027
|
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
2995
3028
|
}
|
|
@@ -3033,9 +3066,12 @@ const _ParaCore = class _ParaCore {
|
|
|
3033
3066
|
]);
|
|
3034
3067
|
this.assertIsAuthSet(["email", "phone"]);
|
|
3035
3068
|
const userId = this.assertUserId({ allowGuestMode: true });
|
|
3036
|
-
const serverAuthState = yield this.ctx.client.
|
|
3069
|
+
const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
|
|
3037
3070
|
verificationCode
|
|
3038
3071
|
});
|
|
3072
|
+
if (serverAuthState.stage === "login") {
|
|
3073
|
+
throw new Error("Account already exists.");
|
|
3074
|
+
}
|
|
3039
3075
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3040
3076
|
});
|
|
3041
3077
|
}
|
|
@@ -3154,31 +3190,36 @@ const _ParaCore = class _ParaCore {
|
|
|
3154
3190
|
return accounts;
|
|
3155
3191
|
});
|
|
3156
3192
|
}
|
|
3193
|
+
sendLoginCode() {
|
|
3194
|
+
return __async(this, null, function* () {
|
|
3195
|
+
const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
|
|
3196
|
+
this.setUserId(userId);
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3157
3199
|
};
|
|
3158
3200
|
_authInfo = new WeakMap();
|
|
3159
|
-
_partner = new WeakMap();
|
|
3160
3201
|
_ParaCore_instances = new WeakSet();
|
|
3161
3202
|
assertPartner_fn = function() {
|
|
3162
3203
|
return __async(this, null, function* () {
|
|
3163
3204
|
var _a, _b;
|
|
3164
|
-
if (!
|
|
3205
|
+
if (!this.partner) {
|
|
3165
3206
|
yield this.touchSession();
|
|
3166
3207
|
}
|
|
3167
|
-
if (((_a =
|
|
3168
|
-
this.ctx.cosmosPrefix = (_b =
|
|
3208
|
+
if (((_a = this.partner) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== this.partner.cosmosPrefix) {
|
|
3209
|
+
this.ctx.cosmosPrefix = (_b = this.partner) == null ? void 0 : _b.cosmosPrefix;
|
|
3169
3210
|
}
|
|
3170
|
-
return
|
|
3211
|
+
return this.partner;
|
|
3171
3212
|
});
|
|
3172
3213
|
};
|
|
3173
3214
|
guestWalletIds_get = function() {
|
|
3174
3215
|
var _a, _b, _c;
|
|
3175
|
-
if (!((_a =
|
|
3216
|
+
if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
3176
3217
|
return {};
|
|
3177
3218
|
}
|
|
3178
3219
|
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
3179
3220
|
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
3180
3221
|
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
3181
|
-
return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) =>
|
|
3222
|
+
return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
3182
3223
|
var _a2;
|
|
3183
3224
|
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
3184
3225
|
}, {}));
|
|
@@ -3239,8 +3280,8 @@ getPartner_fn = function(partnerId) {
|
|
|
3239
3280
|
return void 0;
|
|
3240
3281
|
}
|
|
3241
3282
|
const res = yield this.ctx.client.getPartner(partnerId);
|
|
3242
|
-
|
|
3243
|
-
return
|
|
3283
|
+
this.partner = res.data.partner;
|
|
3284
|
+
return this.partner;
|
|
3244
3285
|
});
|
|
3245
3286
|
};
|
|
3246
3287
|
assertIsLinkingAccount_fn = function(types) {
|
|
@@ -3387,9 +3428,9 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3387
3428
|
portalTheme,
|
|
3388
3429
|
sessionLookupId
|
|
3389
3430
|
}) {
|
|
3390
|
-
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
3391
|
-
const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD);
|
|
3392
|
-
return __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
3431
|
+
const _a = loginState, { loginAuthMethods, hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
|
|
3432
|
+
const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) && hasPasswordWithoutPIN, isPINPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PIN);
|
|
3433
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
3393
3434
|
isPasskeySupported
|
|
3394
3435
|
}), isPasskeyPossible ? {
|
|
3395
3436
|
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
@@ -3409,6 +3450,13 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3409
3450
|
portalTheme,
|
|
3410
3451
|
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
3411
3452
|
})
|
|
3453
|
+
} : {}), isPINPossible ? {
|
|
3454
|
+
pinUrl: yield this.constructPortalUrl("loginPIN", {
|
|
3455
|
+
sessionId: sessionLookupId,
|
|
3456
|
+
shorten,
|
|
3457
|
+
portalTheme,
|
|
3458
|
+
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
3459
|
+
})
|
|
3412
3460
|
} : {});
|
|
3413
3461
|
});
|
|
3414
3462
|
};
|
|
@@ -3416,13 +3464,14 @@ prepareSignUpState_fn = function(_0, _1) {
|
|
|
3416
3464
|
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
3417
3465
|
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
3418
3466
|
const isPasskeySupported = yield this.isPasskeySupported();
|
|
3419
|
-
const [isPasskey, isPassword] = [
|
|
3467
|
+
const [isPasskey, isPassword, isPIN] = [
|
|
3420
3468
|
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY),
|
|
3421
|
-
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) || !isPasskeySupported
|
|
3469
|
+
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) || !isPasskeySupported,
|
|
3470
|
+
signupAuthMethods.includes(import_user_management_client.AuthMethod.PIN)
|
|
3422
3471
|
];
|
|
3423
|
-
if (!isPasskey && !isPassword) {
|
|
3472
|
+
if (!isPasskey && !isPassword && !isPIN) {
|
|
3424
3473
|
throw new Error(
|
|
3425
|
-
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or
|
|
3474
|
+
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
|
|
3426
3475
|
);
|
|
3427
3476
|
}
|
|
3428
3477
|
const signupState = __spreadProps(__spreadValues({}, authState), { isPasskeySupported });
|
|
@@ -3443,6 +3492,15 @@ prepareSignUpState_fn = function(_0, _1) {
|
|
|
3443
3492
|
signupState.passwordUrl = passwordUrl;
|
|
3444
3493
|
signupState.passwordId = passwordId;
|
|
3445
3494
|
}
|
|
3495
|
+
if (isPIN) {
|
|
3496
|
+
const { url: pinUrl, credentialId: pinId } = yield this.getNewCredentialAndUrl({
|
|
3497
|
+
authMethod: "PIN",
|
|
3498
|
+
portalTheme,
|
|
3499
|
+
shorten
|
|
3500
|
+
});
|
|
3501
|
+
signupState.pinUrl = pinUrl;
|
|
3502
|
+
signupState.pinId = pinId;
|
|
3503
|
+
}
|
|
3446
3504
|
return signupState;
|
|
3447
3505
|
});
|
|
3448
3506
|
};
|
package/dist/cjs/constants.js
CHANGED
|
@@ -40,7 +40,7 @@ __export(constants_exports, {
|
|
|
40
40
|
SHORT_POLLING_INTERVAL_MS: () => SHORT_POLLING_INTERVAL_MS
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(constants_exports);
|
|
43
|
-
const PARA_CORE_VERSION = "2.0.0-alpha.
|
|
43
|
+
const PARA_CORE_VERSION = "2.0.0-alpha.40";
|
|
44
44
|
const PREFIX = "@CAPSULE/";
|
|
45
45
|
const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
46
46
|
const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
@@ -81,7 +81,8 @@ const PARA_INTERNAL_METHODS = [
|
|
|
81
81
|
"verifyTelegramLink",
|
|
82
82
|
"verifyExternalWalletLink",
|
|
83
83
|
"accountLinkInProgress",
|
|
84
|
-
"prepareLogin"
|
|
84
|
+
"prepareLogin",
|
|
85
|
+
"sendLoginCode"
|
|
85
86
|
];
|
|
86
87
|
// Annotate the CommonJS export names for ESM import in node:
|
|
87
88
|
0 && (module.exports = {
|
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;
|
|
@@ -88,7 +88,6 @@ const _ParaCore = class _ParaCore {
|
|
|
88
88
|
__privateAdd(this, _authInfo);
|
|
89
89
|
this.isNativePasskey = false;
|
|
90
90
|
this.isReady = false;
|
|
91
|
-
__privateAdd(this, _partner);
|
|
92
91
|
this.accountLinkInProgress = void 0;
|
|
93
92
|
this.isAwaitingAccountCreation = false;
|
|
94
93
|
this.isAwaitingLogin = false;
|
|
@@ -430,11 +429,19 @@ const _ParaCore = class _ParaCore {
|
|
|
430
429
|
}
|
|
431
430
|
get partnerId() {
|
|
432
431
|
var _a;
|
|
433
|
-
return (_a =
|
|
432
|
+
return (_a = this.partner) == null ? void 0 : _a.id;
|
|
433
|
+
}
|
|
434
|
+
get partnerName() {
|
|
435
|
+
var _a;
|
|
436
|
+
return (_a = this.partner) == null ? void 0 : _a.displayName;
|
|
437
|
+
}
|
|
438
|
+
get partnerLogo() {
|
|
439
|
+
var _a;
|
|
440
|
+
return (_a = this.partner) == null ? void 0 : _a.logoUrl;
|
|
434
441
|
}
|
|
435
442
|
get currentWalletIdsArray() {
|
|
436
443
|
var _a, _b;
|
|
437
|
-
return ((_b = (_a =
|
|
444
|
+
return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
438
445
|
(acc, { type }) => {
|
|
439
446
|
var _a2;
|
|
440
447
|
return [
|
|
@@ -474,23 +481,23 @@ const _ParaCore = class _ParaCore {
|
|
|
474
481
|
}
|
|
475
482
|
get isNoWalletConfig() {
|
|
476
483
|
var _a;
|
|
477
|
-
return !!((_a =
|
|
484
|
+
return !!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) && this.partner.supportedWalletTypes.length === 0;
|
|
478
485
|
}
|
|
479
486
|
get supportedWalletTypes() {
|
|
480
487
|
var _a, _b;
|
|
481
|
-
return (_b = (_a =
|
|
488
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
482
489
|
}
|
|
483
490
|
get cosmosPrefix() {
|
|
484
491
|
var _a;
|
|
485
|
-
return (_a =
|
|
492
|
+
return (_a = this.partner) == null ? void 0 : _a.cosmosPrefix;
|
|
486
493
|
}
|
|
487
494
|
get supportedAccountLinks() {
|
|
488
495
|
var _a, _b;
|
|
489
|
-
return (_b = (_a =
|
|
496
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...LINKED_ACCOUNT_TYPES];
|
|
490
497
|
}
|
|
491
498
|
get isWalletTypeEnabled() {
|
|
492
499
|
var _a;
|
|
493
|
-
return (((_a =
|
|
500
|
+
return (((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
494
501
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
495
502
|
}, {});
|
|
496
503
|
}
|
|
@@ -539,7 +546,7 @@ const _ParaCore = class _ParaCore {
|
|
|
539
546
|
}
|
|
540
547
|
isWalletSupported(wallet) {
|
|
541
548
|
var _a, _b;
|
|
542
|
-
return !((_a =
|
|
549
|
+
return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
543
550
|
}
|
|
544
551
|
isWalletOwned(wallet) {
|
|
545
552
|
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;
|
|
@@ -570,7 +577,7 @@ const _ParaCore = class _ParaCore {
|
|
|
570
577
|
} else if (!isOwned && !isUnclaimed) {
|
|
571
578
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
572
579
|
} else if (!this.isWalletSupported(wallet)) {
|
|
573
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b =
|
|
580
|
+
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(", ")}`;
|
|
574
581
|
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
575
582
|
var _a2, _b2;
|
|
576
583
|
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
@@ -601,7 +608,7 @@ const _ParaCore = class _ParaCore {
|
|
|
601
608
|
if (this.externalWallets[walletId]) {
|
|
602
609
|
const wallet2 = this.externalWallets[walletId];
|
|
603
610
|
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, {
|
|
604
|
-
prefix: (_a =
|
|
611
|
+
prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
|
|
605
612
|
targetLength: options.targetLength
|
|
606
613
|
}) : wallet2.address;
|
|
607
614
|
}
|
|
@@ -613,7 +620,7 @@ const _ParaCore = class _ParaCore {
|
|
|
613
620
|
let prefix;
|
|
614
621
|
switch (wallet.type) {
|
|
615
622
|
case "COSMOS":
|
|
616
|
-
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b =
|
|
623
|
+
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
617
624
|
str = getCosmosAddress(wallet.publicKey, prefix);
|
|
618
625
|
break;
|
|
619
626
|
default:
|
|
@@ -648,8 +655,8 @@ const _ParaCore = class _ParaCore {
|
|
|
648
655
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
649
656
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
650
657
|
const [isCreate, isLogin, isOnRamp] = [
|
|
651
|
-
["createAuth", "createPassword"].includes(type),
|
|
652
|
-
["loginAuth", "loginPassword"].includes(type),
|
|
658
|
+
["createAuth", "createPassword", "createPIN"].includes(type),
|
|
659
|
+
["loginAuth", "loginPassword", "loginPIN"].includes(type),
|
|
653
660
|
type === "onRamp"
|
|
654
661
|
];
|
|
655
662
|
if (isCreate || isLogin) {
|
|
@@ -670,6 +677,10 @@ const _ParaCore = class _ParaCore {
|
|
|
670
677
|
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
671
678
|
break;
|
|
672
679
|
}
|
|
680
|
+
case "createPIN": {
|
|
681
|
+
path = `/web/users/${this.userId}/pin/${opts.pathId}`;
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
673
684
|
case "createAuth": {
|
|
674
685
|
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
675
686
|
break;
|
|
@@ -682,6 +693,10 @@ const _ParaCore = class _ParaCore {
|
|
|
682
693
|
path = "/web/biometrics/login";
|
|
683
694
|
break;
|
|
684
695
|
}
|
|
696
|
+
case "loginPIN": {
|
|
697
|
+
path = "/web/pin/login";
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
685
700
|
case "txReview": {
|
|
686
701
|
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
687
702
|
break;
|
|
@@ -756,7 +771,7 @@ const _ParaCore = class _ParaCore {
|
|
|
756
771
|
yield this.ready();
|
|
757
772
|
}
|
|
758
773
|
const session = yield this.ctx.client.touchSession(regenerate);
|
|
759
|
-
if (!
|
|
774
|
+
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) {
|
|
760
775
|
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
761
776
|
}
|
|
762
777
|
return session;
|
|
@@ -1487,6 +1502,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1487
1502
|
let type, linkedAccountId;
|
|
1488
1503
|
switch (reason) {
|
|
1489
1504
|
case "SIGNUP":
|
|
1505
|
+
case "LOGIN":
|
|
1490
1506
|
{
|
|
1491
1507
|
const authInfo = this.assertIsAuthSet(["email", "phone"]);
|
|
1492
1508
|
type = authInfo.authType.toUpperCase();
|
|
@@ -1557,10 +1573,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1557
1573
|
return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
|
|
1558
1574
|
({ userId, partnerId }) => {
|
|
1559
1575
|
var _a;
|
|
1560
|
-
return partnerId === ((_a =
|
|
1576
|
+
return partnerId === ((_a = this.partner) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
|
|
1561
1577
|
}
|
|
1562
1578
|
);
|
|
1563
1579
|
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Get the auth methods available to an existing user
|
|
1582
|
+
*/
|
|
1564
1583
|
supportedAuthMethods(auth) {
|
|
1565
1584
|
return __async(this, null, function* () {
|
|
1566
1585
|
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
@@ -2810,6 +2829,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2810
2829
|
**/
|
|
2811
2830
|
logout() {
|
|
2812
2831
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
2832
|
+
const shouldDispatchLogoutEvent = yield this.isSessionActive();
|
|
2813
2833
|
yield this.ctx.client.logout();
|
|
2814
2834
|
yield this.clearStorage();
|
|
2815
2835
|
if (!clearPregenWallets) {
|
|
@@ -2829,7 +2849,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2829
2849
|
this.accountLinkInProgress = void 0;
|
|
2830
2850
|
this.userId = void 0;
|
|
2831
2851
|
this.sessionCookie = void 0;
|
|
2832
|
-
|
|
2852
|
+
if (shouldDispatchLogoutEvent) {
|
|
2853
|
+
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
2854
|
+
}
|
|
2833
2855
|
});
|
|
2834
2856
|
}
|
|
2835
2857
|
get toStringAdditions() {
|
|
@@ -2859,9 +2881,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2859
2881
|
{}
|
|
2860
2882
|
);
|
|
2861
2883
|
const obj = __spreadProps(__spreadValues({
|
|
2862
|
-
partnerId: (_a =
|
|
2863
|
-
supportedWalletTypes: (_b =
|
|
2864
|
-
cosmosPrefix: (_c =
|
|
2884
|
+
partnerId: (_a = this.partner) == null ? void 0 : _a.id,
|
|
2885
|
+
supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
|
|
2886
|
+
cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
|
|
2865
2887
|
authInfo: __privateGet(this, _authInfo),
|
|
2866
2888
|
isGuestMode: this.isGuestMode,
|
|
2867
2889
|
userId: this.userId,
|
|
@@ -2918,6 +2940,14 @@ const _ParaCore = class _ParaCore {
|
|
|
2918
2940
|
}));
|
|
2919
2941
|
urlType = "createPassword";
|
|
2920
2942
|
break;
|
|
2943
|
+
case "PIN":
|
|
2944
|
+
({
|
|
2945
|
+
data: { id: credentialId }
|
|
2946
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
2947
|
+
status: PasswordStatus.PENDING
|
|
2948
|
+
}));
|
|
2949
|
+
urlType = "createPIN";
|
|
2950
|
+
break;
|
|
2921
2951
|
}
|
|
2922
2952
|
const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
|
|
2923
2953
|
isForNewDevice,
|
|
@@ -2929,7 +2959,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2929
2959
|
});
|
|
2930
2960
|
}
|
|
2931
2961
|
/**
|
|
2932
|
-
* Returns a Para Portal URL for logging in with a WebAuth passkey or
|
|
2962
|
+
* Returns a Para Portal URL for logging in with a WebAuth passkey, password or PIN.
|
|
2933
2963
|
* @param {Object} opts the options object
|
|
2934
2964
|
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
2935
2965
|
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
@@ -2955,6 +2985,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2955
2985
|
case "PASSWORD":
|
|
2956
2986
|
urlType = "loginPassword";
|
|
2957
2987
|
break;
|
|
2988
|
+
case "PIN":
|
|
2989
|
+
urlType = "loginPIN";
|
|
2990
|
+
break;
|
|
2958
2991
|
default:
|
|
2959
2992
|
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
2960
2993
|
}
|
|
@@ -2998,9 +3031,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2998
3031
|
]);
|
|
2999
3032
|
this.assertIsAuthSet(["email", "phone"]);
|
|
3000
3033
|
const userId = this.assertUserId({ allowGuestMode: true });
|
|
3001
|
-
const serverAuthState = yield this.ctx.client.
|
|
3034
|
+
const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
|
|
3002
3035
|
verificationCode
|
|
3003
3036
|
});
|
|
3037
|
+
if (serverAuthState.stage === "login") {
|
|
3038
|
+
throw new Error("Account already exists.");
|
|
3039
|
+
}
|
|
3004
3040
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3005
3041
|
});
|
|
3006
3042
|
}
|
|
@@ -3119,31 +3155,36 @@ const _ParaCore = class _ParaCore {
|
|
|
3119
3155
|
return accounts;
|
|
3120
3156
|
});
|
|
3121
3157
|
}
|
|
3158
|
+
sendLoginCode() {
|
|
3159
|
+
return __async(this, null, function* () {
|
|
3160
|
+
const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
|
|
3161
|
+
this.setUserId(userId);
|
|
3162
|
+
});
|
|
3163
|
+
}
|
|
3122
3164
|
};
|
|
3123
3165
|
_authInfo = new WeakMap();
|
|
3124
|
-
_partner = new WeakMap();
|
|
3125
3166
|
_ParaCore_instances = new WeakSet();
|
|
3126
3167
|
assertPartner_fn = function() {
|
|
3127
3168
|
return __async(this, null, function* () {
|
|
3128
3169
|
var _a, _b;
|
|
3129
|
-
if (!
|
|
3170
|
+
if (!this.partner) {
|
|
3130
3171
|
yield this.touchSession();
|
|
3131
3172
|
}
|
|
3132
|
-
if (((_a =
|
|
3133
|
-
this.ctx.cosmosPrefix = (_b =
|
|
3173
|
+
if (((_a = this.partner) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== this.partner.cosmosPrefix) {
|
|
3174
|
+
this.ctx.cosmosPrefix = (_b = this.partner) == null ? void 0 : _b.cosmosPrefix;
|
|
3134
3175
|
}
|
|
3135
|
-
return
|
|
3176
|
+
return this.partner;
|
|
3136
3177
|
});
|
|
3137
3178
|
};
|
|
3138
3179
|
guestWalletIds_get = function() {
|
|
3139
3180
|
var _a, _b, _c;
|
|
3140
|
-
if (!((_a =
|
|
3181
|
+
if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
3141
3182
|
return {};
|
|
3142
3183
|
}
|
|
3143
3184
|
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
3144
3185
|
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
3145
3186
|
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
3146
|
-
return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) =>
|
|
3187
|
+
return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
3147
3188
|
var _a2;
|
|
3148
3189
|
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
3149
3190
|
}, {}));
|
|
@@ -3204,8 +3245,8 @@ getPartner_fn = function(partnerId) {
|
|
|
3204
3245
|
return void 0;
|
|
3205
3246
|
}
|
|
3206
3247
|
const res = yield this.ctx.client.getPartner(partnerId);
|
|
3207
|
-
|
|
3208
|
-
return
|
|
3248
|
+
this.partner = res.data.partner;
|
|
3249
|
+
return this.partner;
|
|
3209
3250
|
});
|
|
3210
3251
|
};
|
|
3211
3252
|
assertIsLinkingAccount_fn = function(types) {
|
|
@@ -3352,9 +3393,9 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3352
3393
|
portalTheme,
|
|
3353
3394
|
sessionLookupId
|
|
3354
3395
|
}) {
|
|
3355
|
-
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
3356
|
-
const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(AuthMethod.PASSWORD);
|
|
3357
|
-
return __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
3396
|
+
const _a = loginState, { loginAuthMethods, hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
|
|
3397
|
+
const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(AuthMethod.PASSWORD) && hasPasswordWithoutPIN, isPINPossible = loginAuthMethods.includes(AuthMethod.PIN);
|
|
3398
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
3358
3399
|
isPasskeySupported
|
|
3359
3400
|
}), isPasskeyPossible ? {
|
|
3360
3401
|
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
@@ -3374,6 +3415,13 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3374
3415
|
portalTheme,
|
|
3375
3416
|
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
3376
3417
|
})
|
|
3418
|
+
} : {}), isPINPossible ? {
|
|
3419
|
+
pinUrl: yield this.constructPortalUrl("loginPIN", {
|
|
3420
|
+
sessionId: sessionLookupId,
|
|
3421
|
+
shorten,
|
|
3422
|
+
portalTheme,
|
|
3423
|
+
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
3424
|
+
})
|
|
3377
3425
|
} : {});
|
|
3378
3426
|
});
|
|
3379
3427
|
};
|
|
@@ -3381,13 +3429,14 @@ prepareSignUpState_fn = function(_0, _1) {
|
|
|
3381
3429
|
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
3382
3430
|
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
3383
3431
|
const isPasskeySupported = yield this.isPasskeySupported();
|
|
3384
|
-
const [isPasskey, isPassword] = [
|
|
3432
|
+
const [isPasskey, isPassword, isPIN] = [
|
|
3385
3433
|
signupAuthMethods.includes(AuthMethod.PASSKEY),
|
|
3386
|
-
signupAuthMethods.includes(AuthMethod.PASSWORD) || !isPasskeySupported
|
|
3434
|
+
signupAuthMethods.includes(AuthMethod.PASSWORD) || !isPasskeySupported,
|
|
3435
|
+
signupAuthMethods.includes(AuthMethod.PIN)
|
|
3387
3436
|
];
|
|
3388
|
-
if (!isPasskey && !isPassword) {
|
|
3437
|
+
if (!isPasskey && !isPassword && !isPIN) {
|
|
3389
3438
|
throw new Error(
|
|
3390
|
-
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or
|
|
3439
|
+
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
|
|
3391
3440
|
);
|
|
3392
3441
|
}
|
|
3393
3442
|
const signupState = __spreadProps(__spreadValues({}, authState), { isPasskeySupported });
|
|
@@ -3408,6 +3457,15 @@ prepareSignUpState_fn = function(_0, _1) {
|
|
|
3408
3457
|
signupState.passwordUrl = passwordUrl;
|
|
3409
3458
|
signupState.passwordId = passwordId;
|
|
3410
3459
|
}
|
|
3460
|
+
if (isPIN) {
|
|
3461
|
+
const { url: pinUrl, credentialId: pinId } = yield this.getNewCredentialAndUrl({
|
|
3462
|
+
authMethod: "PIN",
|
|
3463
|
+
portalTheme,
|
|
3464
|
+
shorten
|
|
3465
|
+
});
|
|
3466
|
+
signupState.pinUrl = pinUrl;
|
|
3467
|
+
signupState.pinId = pinId;
|
|
3468
|
+
}
|
|
3411
3469
|
return signupState;
|
|
3412
3470
|
});
|
|
3413
3471
|
};
|
package/dist/esm/constants.js
CHANGED
package/dist/types/ParaCore.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthMethod, AuthExtras, CurrentWalletIds, EmailTheme, TWalletType, PregenIds, BiometricLocationHint, Auth, SupportedWalletTypes, AuthIdentifier, AuthType, ExternalWalletInfo, PrimaryAuthInfo, SessionInfo, PrimaryAuth, PrimaryAuthType, AccountMetadata, LinkedAccounts, VerifyLinkParams, VerifyExternalWalletParams, SupportedAccountLinks, OnRampPurchase } from '@getpara/user-management-client';
|
|
1
|
+
import { AuthMethod, AuthExtras, CurrentWalletIds, EmailTheme, PartnerEntity, TWalletType, PregenIds, BiometricLocationHint, Auth, SupportedWalletTypes, AuthIdentifier, AuthType, ExternalWalletInfo, PrimaryAuthInfo, SessionInfo, PrimaryAuth, PrimaryAuthType, AccountMetadata, LinkedAccounts, VerifyLinkParams, VerifyExternalWalletParams, SupportedAccountLinks, OnRampPurchase } from '@getpara/user-management-client';
|
|
2
2
|
import type { pki as pkiType } from 'node-forge';
|
|
3
3
|
import { Ctx, Environment, Theme, WalletFilters, Wallet, PortalUrlOptions, ConstructorOpts, CoreAuthInfo, PortalUrlType, CoreMethodParams, CoreMethodResponse, NewCredentialUrlParams, LoginUrlParams, CoreInterface, ExternalWalletConnectionType, AccountLinkInProgress, InternalMethodParams, InternalMethodResponse } from './types/index.js';
|
|
4
4
|
import { PlatformUtils } from './PlatformUtils.js';
|
|
@@ -16,6 +16,7 @@ export declare abstract class ParaCore implements CoreInterface {
|
|
|
16
16
|
get telegramUserId(): AuthIdentifier<'telegram'> | undefined;
|
|
17
17
|
get externalWalletWithParaAuth(): Wallet | undefined;
|
|
18
18
|
get externalWalletConnectionType(): ExternalWalletConnectionType;
|
|
19
|
+
protected partner?: PartnerEntity;
|
|
19
20
|
userId?: string;
|
|
20
21
|
accountLinkInProgress: AccountLinkInProgress | undefined;
|
|
21
22
|
private sessionCookie?;
|
|
@@ -31,6 +32,8 @@ export declare abstract class ParaCore implements CoreInterface {
|
|
|
31
32
|
get isExternalWalletAuth(): boolean;
|
|
32
33
|
get isExternalWalletWithVerification(): boolean;
|
|
33
34
|
get partnerId(): string | undefined;
|
|
35
|
+
protected get partnerName(): string | undefined;
|
|
36
|
+
protected get partnerLogo(): string | undefined;
|
|
34
37
|
/**
|
|
35
38
|
* 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.
|
|
36
39
|
*/
|
|
@@ -408,6 +411,9 @@ export declare abstract class ParaCore implements CoreInterface {
|
|
|
408
411
|
**/
|
|
409
412
|
isFullyLoggedIn(): CoreMethodResponse<'isFullyLoggedIn'>;
|
|
410
413
|
get isGuestMode(): boolean;
|
|
414
|
+
/**
|
|
415
|
+
* Get the auth methods available to an existing user
|
|
416
|
+
*/
|
|
411
417
|
protected supportedAuthMethods(auth: Auth<PrimaryAuthType | 'userId'>): Promise<Set<AuthMethod>>;
|
|
412
418
|
/**
|
|
413
419
|
* Get hints associated with the users stored biometrics.
|
|
@@ -682,7 +688,7 @@ export declare abstract class ParaCore implements CoreInterface {
|
|
|
682
688
|
url?: string;
|
|
683
689
|
}>;
|
|
684
690
|
/**
|
|
685
|
-
* Returns a Para Portal URL for logging in with a WebAuth passkey or
|
|
691
|
+
* Returns a Para Portal URL for logging in with a WebAuth passkey, password or PIN.
|
|
686
692
|
* @param {Object} opts the options object
|
|
687
693
|
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
688
694
|
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
@@ -700,4 +706,5 @@ export declare abstract class ParaCore implements CoreInterface {
|
|
|
700
706
|
accountLinkInProgress?: AccountLinkInProgress;
|
|
701
707
|
} & Partial<Pick<VerifyLinkParams, 'verificationCode' | 'telegramAuthResponse'> & VerifyExternalWalletParams>): Promise<LinkedAccounts>;
|
|
702
708
|
protected verifyEmailOrPhoneLink({ verificationCode, }: InternalMethodParams<'verifyEmailOrPhoneLink'>): InternalMethodResponse<'verifyEmailOrPhoneLink'>;
|
|
709
|
+
protected sendLoginCode(): Promise<void>;
|
|
703
710
|
}
|
|
@@ -4,7 +4,7 @@ import { ParaCore } from '../ParaCore.js';
|
|
|
4
4
|
import { FullSignatureRes, Wallet } from './wallet.js';
|
|
5
5
|
import { AccountLinkInProgress } from './auth.js';
|
|
6
6
|
export declare const PARA_CORE_METHODS: readonly ["getAuthInfo", "signUpOrLogIn", "verifyNewAccount", "waitForLogin", "waitForSignup", "waitForWalletCreation", "getOAuthUrl", "verifyOAuth", "getFarcasterConnectUri", "verifyFarcaster", "verifyTelegram", "resendVerificationCode", "loginExternalWallet", "verifyExternalWallet", "setup2fa", "enable2fa", "verify2fa", "logout", "clearStorage", "isSessionActive", "isFullyLoggedIn", "refreshSession", "keepSessionAlive", "exportSession", "importSession", "getVerificationToken", "getWallets", "getWalletsByType", "fetchWallets", "createWallet", "createWalletPerType", "getPregenWallets", "hasPregenWallet", "updatePregenWalletIdentifier", "createPregenWallet", "createPregenWalletPerType", "claimPregenWallets", "createGuestWallets", "distributeNewWalletShare", "getUserShare", "setUserShare", "refreshShare", "signMessage", "signTransaction", "initiateOnRampTransaction", "getWalletBalance", "issueJwt", "getLinkedAccounts", "accountLinkInProgress"];
|
|
7
|
-
export declare const PARA_INTERNAL_METHODS: readonly ["linkAccount", "unlinkAccount", "verifyEmailOrPhoneLink", "verifyOAuthLink", "verifyFarcasterLink", "verifyTelegramLink", "verifyExternalWalletLink", "accountLinkInProgress", "prepareLogin"];
|
|
7
|
+
export declare const PARA_INTERNAL_METHODS: readonly ["linkAccount", "unlinkAccount", "verifyEmailOrPhoneLink", "verifyOAuthLink", "verifyFarcasterLink", "verifyTelegramLink", "verifyExternalWalletLink", "accountLinkInProgress", "prepareLogin", "sendLoginCode"];
|
|
8
8
|
export type CoreMethodName = (typeof PARA_CORE_METHODS)[number];
|
|
9
9
|
export type CoreMethodParams<method extends CoreMethodName & keyof CoreMethods> = CoreMethods[method] extends {
|
|
10
10
|
params: infer P;
|
|
@@ -152,7 +152,7 @@ export type CoreMethods = Record<CoreMethodName, {
|
|
|
152
152
|
};
|
|
153
153
|
resendVerificationCode: {
|
|
154
154
|
params: {
|
|
155
|
-
type?: 'SIGNUP' | 'LINK_ACCOUNT';
|
|
155
|
+
type?: 'SIGNUP' | 'LINK_ACCOUNT' | 'LOGIN';
|
|
156
156
|
} | undefined;
|
|
157
157
|
response: void;
|
|
158
158
|
};
|
|
@@ -526,6 +526,10 @@ export type InternalMethods = {
|
|
|
526
526
|
params: void;
|
|
527
527
|
response: string;
|
|
528
528
|
};
|
|
529
|
+
sendLoginCode: {
|
|
530
|
+
params: void;
|
|
531
|
+
response: void;
|
|
532
|
+
};
|
|
529
533
|
};
|
|
530
534
|
export type CoreInterface = {
|
|
531
535
|
[key in keyof CoreMethods]: Partial<CoreMethod<key>>;
|
|
@@ -14,7 +14,7 @@ export type VerifyExternalWalletV1 = {
|
|
|
14
14
|
cosmosPublicKeyHex?: string;
|
|
15
15
|
cosmosSigner?: string;
|
|
16
16
|
};
|
|
17
|
-
export type PortalUrlType = 'createAuth' | 'createPassword' | 'loginAuth' | 'loginPassword' | 'txReview' | 'onRamp' | 'telegramLogin';
|
|
17
|
+
export type PortalUrlType = 'createAuth' | 'createPassword' | 'loginAuth' | 'loginPassword' | 'txReview' | 'onRamp' | 'telegramLogin' | 'createPIN' | 'loginPIN';
|
|
18
18
|
export type PortalUrlOptions = {
|
|
19
19
|
params?: Record<string, string | undefined | null>;
|
|
20
20
|
isForNewDevice?: boolean;
|
|
@@ -28,7 +28,7 @@ export type PortalUrlOptions = {
|
|
|
28
28
|
};
|
|
29
29
|
export type WithAuthMethod = {
|
|
30
30
|
/**
|
|
31
|
-
* Which authorization method to use for the URL, either `'passkey'` or `'
|
|
31
|
+
* Which authorization method to use for the URL, either `'passkey'` or `'password'`.
|
|
32
32
|
*/
|
|
33
33
|
authMethod?: Uppercase<AuthMethod>;
|
|
34
34
|
};
|
|
@@ -137,6 +137,10 @@ export type AuthStateLogin = Omit<ServerAuthStateLogin, 'loginAuthMethods'> & Wi
|
|
|
137
137
|
* A Para Portal URL for logging in via a password.
|
|
138
138
|
*/
|
|
139
139
|
passwordUrl?: string;
|
|
140
|
+
/**
|
|
141
|
+
* A Para Portal URL for logging in via a PIN.
|
|
142
|
+
*/
|
|
143
|
+
pinUrl?: string;
|
|
140
144
|
};
|
|
141
145
|
export type AuthStateSignup = Omit<ServerAuthStateSignup, 'signupAuthMethods'> & WithIsPasskeySupported & {
|
|
142
146
|
/**
|
|
@@ -147,6 +151,10 @@ export type AuthStateSignup = Omit<ServerAuthStateSignup, 'signupAuthMethods'> &
|
|
|
147
151
|
* A Para Portal URL for creating a new user password.
|
|
148
152
|
*/
|
|
149
153
|
passwordUrl?: string;
|
|
154
|
+
/**
|
|
155
|
+
* A Para Portal URL for creating a new user PIN.
|
|
156
|
+
*/
|
|
157
|
+
pinUrl?: string;
|
|
150
158
|
/**
|
|
151
159
|
* The Para system ID for the newly generated passkey.
|
|
152
160
|
*/
|
|
@@ -155,6 +163,10 @@ export type AuthStateSignup = Omit<ServerAuthStateSignup, 'signupAuthMethods'> &
|
|
|
155
163
|
* The Para system ID for the newly generated password.
|
|
156
164
|
*/
|
|
157
165
|
passwordId?: string;
|
|
166
|
+
/**
|
|
167
|
+
* The Para system ID for the newly generated PIN.
|
|
168
|
+
*/
|
|
169
|
+
pinId?: string;
|
|
158
170
|
};
|
|
159
171
|
export type AuthStateVerifyOrLogin = AuthStateVerify | AuthStateLogin;
|
|
160
172
|
export type AuthStateSignupOrLogin = AuthStateSignup | AuthStateLogin;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/core-sdk",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.40",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@celo/utils": "^8.0.2",
|
|
6
6
|
"@cosmjs/encoding": "^0.32.4",
|
|
7
7
|
"@ethereumjs/util": "^9.1.0",
|
|
8
|
-
"@getpara/user-management-client": "2.0.0-alpha.
|
|
8
|
+
"@getpara/user-management-client": "2.0.0-alpha.40",
|
|
9
9
|
"@noble/hashes": "^1.5.0",
|
|
10
10
|
"base64url": "^3.0.1",
|
|
11
11
|
"libphonenumber-js": "^1.11.7",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist",
|
|
28
28
|
"package.json"
|
|
29
29
|
],
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "2506044cd3ed127774fb7d537ae850b43acfe8b7",
|
|
31
31
|
"main": "dist/cjs/index.js",
|
|
32
32
|
"module": "dist/esm/index.js",
|
|
33
33
|
"scripts": {
|