@getpara/core-sdk 2.0.0-dev.3 → 2.0.0-dev.7
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 +493 -146
- package/dist/cjs/constants.js +10 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/shares/enclave.js +274 -0
- package/dist/cjs/shares/shareDistribution.js +16 -1
- package/dist/cjs/types/coreApi.js +3 -1
- package/dist/esm/ParaCore.js +493 -147
- package/dist/esm/constants.js +7 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/shares/enclave.js +234 -0
- package/dist/esm/shares/shareDistribution.js +16 -1
- package/dist/esm/types/coreApi.js +3 -1
- package/dist/types/ParaCore.d.ts +41 -8
- package/dist/types/PlatformUtils.d.ts +2 -1
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/shares/enclave.d.ts +81 -0
- package/dist/types/shares/shareDistribution.d.ts +4 -2
- package/dist/types/types/config.d.ts +2 -0
- package/dist/types/types/coreApi.d.ts +12 -3
- package/dist/types/types/methods.d.ts +37 -8
- package/dist/types/types/wallet.d.ts +2 -2
- package/package.json +3 -3
package/dist/cjs/ParaCore.js
CHANGED
|
@@ -99,7 +99,8 @@ 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
|
|
102
|
+
var import_enclave = require("./shares/enclave.js");
|
|
103
|
+
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, prepareDoneState_fn, prepareVerificationState_fn, prepareLoginState_fn, prepareSignUpState_fn;
|
|
103
104
|
if (typeof global !== "undefined") {
|
|
104
105
|
global.Buffer = global.Buffer || import_buffer.Buffer;
|
|
105
106
|
} else if (typeof window !== "undefined") {
|
|
@@ -111,24 +112,19 @@ if (typeof global !== "undefined") {
|
|
|
111
112
|
}
|
|
112
113
|
const { pki, jsbn } = import_node_forge.default;
|
|
113
114
|
const _ParaCore = class _ParaCore {
|
|
114
|
-
|
|
115
|
-
* Constructs a new `ParaCore` instance.
|
|
116
|
-
* @param env - `Environment` to use.
|
|
117
|
-
* @param apiKey - API key to use.
|
|
118
|
-
* @param opts - Additional constructor options; see `ConstructorOpts`.
|
|
119
|
-
* @returns - A new ParaCore instance.
|
|
120
|
-
*/
|
|
121
|
-
constructor(env, apiKey, opts) {
|
|
115
|
+
constructor(envOrApiKey, apiKeyOrOpts, opts) {
|
|
122
116
|
__privateAdd(this, _ParaCore_instances);
|
|
117
|
+
this.popupWindow = null;
|
|
123
118
|
__privateAdd(this, _authInfo);
|
|
124
119
|
this.isNativePasskey = false;
|
|
125
120
|
this.isReady = false;
|
|
126
|
-
__privateAdd(this, _partner);
|
|
127
121
|
this.accountLinkInProgress = void 0;
|
|
122
|
+
this.isEnclaveUser = false;
|
|
128
123
|
this.isAwaitingAccountCreation = false;
|
|
129
124
|
this.isAwaitingLogin = false;
|
|
130
125
|
this.isAwaitingFarcaster = false;
|
|
131
126
|
this.isAwaitingOAuth = false;
|
|
127
|
+
this.isWorkerInitialized = false;
|
|
132
128
|
/**
|
|
133
129
|
* 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.
|
|
134
130
|
*/
|
|
@@ -137,6 +133,7 @@ const _ParaCore = class _ParaCore {
|
|
|
137
133
|
* Wallets associated with the `ParaCore` instance.
|
|
138
134
|
*/
|
|
139
135
|
this.externalWallets = {};
|
|
136
|
+
this.onRampPopup = void 0;
|
|
140
137
|
this.localStorageGetItem = (key) => {
|
|
141
138
|
return this.platformUtils.localStorage.get(key);
|
|
142
139
|
};
|
|
@@ -158,16 +155,29 @@ const _ParaCore = class _ParaCore {
|
|
|
158
155
|
this.retrieveSessionCookie = () => {
|
|
159
156
|
return this.sessionCookie;
|
|
160
157
|
};
|
|
158
|
+
this.retrieveEnclaveJwt = () => {
|
|
159
|
+
return this.enclaveJwt;
|
|
160
|
+
};
|
|
161
|
+
this.retrieveEnclaveRefreshJwt = () => {
|
|
162
|
+
return this.enclaveRefreshJwt;
|
|
163
|
+
};
|
|
161
164
|
/**
|
|
162
165
|
* Remove all local storage and prefixed session storage.
|
|
163
166
|
* @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
|
|
164
167
|
*/
|
|
165
168
|
this.clearStorage = (type = "all") => __async(this, null, function* () {
|
|
166
169
|
const isAll = type === "all";
|
|
167
|
-
(isAll || type === "local")
|
|
168
|
-
|
|
170
|
+
if (isAll || type === "local") {
|
|
171
|
+
this.platformUtils.localStorage.clear(constants.PREFIX);
|
|
172
|
+
this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
|
|
173
|
+
}
|
|
174
|
+
if (isAll || type === "session") {
|
|
175
|
+
this.platformUtils.sessionStorage.clear(constants.PREFIX);
|
|
176
|
+
this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
|
|
177
|
+
}
|
|
169
178
|
if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
|
|
170
179
|
this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
180
|
+
this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
|
|
171
181
|
}
|
|
172
182
|
});
|
|
173
183
|
this.trackError = (methodName, err) => __async(this, null, function* () {
|
|
@@ -209,6 +219,7 @@ const _ParaCore = class _ParaCore {
|
|
|
209
219
|
this.updateWalletIdsFromStorage();
|
|
210
220
|
this.updateSessionCookieFromStorage();
|
|
211
221
|
this.updateLoginEncryptionKeyPairFromStorage();
|
|
222
|
+
this.updateEnclaveJwtFromStorage();
|
|
212
223
|
};
|
|
213
224
|
this.updateAuthInfoFromStorage = () => {
|
|
214
225
|
var _a;
|
|
@@ -228,6 +239,10 @@ const _ParaCore = class _ParaCore {
|
|
|
228
239
|
}
|
|
229
240
|
__privateSet(this, _authInfo, authInfo);
|
|
230
241
|
};
|
|
242
|
+
this.updateEnclaveJwtFromStorage = () => {
|
|
243
|
+
this.enclaveJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || void 0;
|
|
244
|
+
this.enclaveRefreshJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || void 0;
|
|
245
|
+
};
|
|
231
246
|
this.updateUserIdFromStorage = () => {
|
|
232
247
|
this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
233
248
|
};
|
|
@@ -288,6 +303,16 @@ const _ParaCore = class _ParaCore {
|
|
|
288
303
|
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
289
304
|
this.setExternalWallets(_externalWallets);
|
|
290
305
|
};
|
|
306
|
+
this.initializeWorker = () => __async(this, null, function* () {
|
|
307
|
+
if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers) {
|
|
308
|
+
try {
|
|
309
|
+
this.isWorkerInitialized = true;
|
|
310
|
+
yield this.platformUtils.initializeWorker(this.ctx);
|
|
311
|
+
} catch (e) {
|
|
312
|
+
this.devLog("error initializing worker:", e);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
});
|
|
291
316
|
/**
|
|
292
317
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
293
318
|
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
@@ -304,8 +329,29 @@ const _ParaCore = class _ParaCore {
|
|
|
304
329
|
}) {
|
|
305
330
|
return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
|
|
306
331
|
});
|
|
307
|
-
|
|
308
|
-
|
|
332
|
+
let env, apiKey;
|
|
333
|
+
const actualArgs = Array.from(arguments).filter((arg) => arg !== void 0);
|
|
334
|
+
const actualArgumentCount = actualArgs.length;
|
|
335
|
+
if (actualArgumentCount === 1) {
|
|
336
|
+
if (Object.values(import_types.Environment).includes(envOrApiKey)) {
|
|
337
|
+
throw new Error("A Para API key is required.");
|
|
338
|
+
}
|
|
339
|
+
env = _ParaCore.resolveEnvironment(void 0, actualArgs[0]);
|
|
340
|
+
apiKey = actualArgs[0];
|
|
341
|
+
opts = void 0;
|
|
342
|
+
} else if (actualArgumentCount === 2) {
|
|
343
|
+
if (typeof apiKeyOrOpts === "object" && apiKeyOrOpts !== null) {
|
|
344
|
+
env = _ParaCore.resolveEnvironment(void 0, envOrApiKey);
|
|
345
|
+
apiKey = envOrApiKey;
|
|
346
|
+
opts = apiKeyOrOpts;
|
|
347
|
+
} else {
|
|
348
|
+
env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
|
|
349
|
+
apiKey = apiKeyOrOpts;
|
|
350
|
+
opts = void 0;
|
|
351
|
+
}
|
|
352
|
+
} else {
|
|
353
|
+
env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
|
|
354
|
+
apiKey = apiKeyOrOpts;
|
|
309
355
|
}
|
|
310
356
|
if (!opts) opts = {};
|
|
311
357
|
let isE2E = false;
|
|
@@ -348,18 +394,41 @@ const _ParaCore = class _ParaCore {
|
|
|
348
394
|
cookie
|
|
349
395
|
);
|
|
350
396
|
};
|
|
397
|
+
this.persistEnclaveJwt = (jwt) => {
|
|
398
|
+
this.enclaveJwt = jwt;
|
|
399
|
+
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
|
|
400
|
+
constants.LOCAL_STORAGE_ENCLAVE_JWT,
|
|
401
|
+
jwt
|
|
402
|
+
);
|
|
403
|
+
};
|
|
404
|
+
this.persistEnclaveRefreshJwt = (refreshJwt) => {
|
|
405
|
+
this.enclaveRefreshJwt = refreshJwt;
|
|
406
|
+
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
|
|
407
|
+
constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
|
|
408
|
+
refreshJwt
|
|
409
|
+
);
|
|
410
|
+
};
|
|
411
|
+
const client = (0, import_userManagementClient.initClient)({
|
|
412
|
+
env,
|
|
413
|
+
version: _ParaCore.version,
|
|
414
|
+
apiKey,
|
|
415
|
+
partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
|
|
416
|
+
useFetchAdapter: !!opts.disableWorkers,
|
|
417
|
+
retrieveSessionCookie: this.retrieveSessionCookie,
|
|
418
|
+
persistSessionCookie: this.persistSessionCookie
|
|
419
|
+
});
|
|
420
|
+
const enclaveClient = new import_enclave.EnclaveClient({
|
|
421
|
+
userManagementClient: client,
|
|
422
|
+
retrieveJwt: this.retrieveEnclaveJwt,
|
|
423
|
+
persistJwt: this.persistEnclaveJwt,
|
|
424
|
+
retrieveRefreshJwt: this.retrieveEnclaveRefreshJwt,
|
|
425
|
+
persistRefreshJwt: this.persistEnclaveRefreshJwt
|
|
426
|
+
});
|
|
351
427
|
this.ctx = {
|
|
352
428
|
env,
|
|
353
429
|
apiKey,
|
|
354
|
-
client
|
|
355
|
-
|
|
356
|
-
version: _ParaCore.version,
|
|
357
|
-
apiKey,
|
|
358
|
-
partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
|
|
359
|
-
useFetchAdapter: !!opts.disableWorkers,
|
|
360
|
-
retrieveSessionCookie: this.retrieveSessionCookie,
|
|
361
|
-
persistSessionCookie: this.persistSessionCookie
|
|
362
|
-
}),
|
|
430
|
+
client,
|
|
431
|
+
enclaveClient,
|
|
363
432
|
disableWorkers: opts.disableWorkers,
|
|
364
433
|
offloadMPCComputationURL: opts.offloadMPCComputationURL,
|
|
365
434
|
useLocalFiles: opts.useLocalFiles,
|
|
@@ -453,11 +522,19 @@ const _ParaCore = class _ParaCore {
|
|
|
453
522
|
}
|
|
454
523
|
get partnerId() {
|
|
455
524
|
var _a;
|
|
456
|
-
return (_a =
|
|
525
|
+
return (_a = this.partner) == null ? void 0 : _a.id;
|
|
526
|
+
}
|
|
527
|
+
get partnerName() {
|
|
528
|
+
var _a;
|
|
529
|
+
return (_a = this.partner) == null ? void 0 : _a.displayName;
|
|
530
|
+
}
|
|
531
|
+
get partnerLogo() {
|
|
532
|
+
var _a;
|
|
533
|
+
return (_a = this.partner) == null ? void 0 : _a.logoUrl;
|
|
457
534
|
}
|
|
458
535
|
get currentWalletIdsArray() {
|
|
459
536
|
var _a, _b;
|
|
460
|
-
return ((_b = (_a =
|
|
537
|
+
return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
461
538
|
(acc, { type }) => {
|
|
462
539
|
var _a2;
|
|
463
540
|
return [
|
|
@@ -497,23 +574,23 @@ const _ParaCore = class _ParaCore {
|
|
|
497
574
|
}
|
|
498
575
|
get isNoWalletConfig() {
|
|
499
576
|
var _a;
|
|
500
|
-
return !!((_a =
|
|
577
|
+
return !!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) && this.partner.supportedWalletTypes.length === 0;
|
|
501
578
|
}
|
|
502
579
|
get supportedWalletTypes() {
|
|
503
580
|
var _a, _b;
|
|
504
|
-
return (_b = (_a =
|
|
581
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
505
582
|
}
|
|
506
583
|
get cosmosPrefix() {
|
|
507
584
|
var _a;
|
|
508
|
-
return (_a =
|
|
585
|
+
return (_a = this.partner) == null ? void 0 : _a.cosmosPrefix;
|
|
509
586
|
}
|
|
510
587
|
get supportedAccountLinks() {
|
|
511
588
|
var _a, _b;
|
|
512
|
-
return (_b = (_a =
|
|
589
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...import_user_management_client.LINKED_ACCOUNT_TYPES];
|
|
513
590
|
}
|
|
514
591
|
get isWalletTypeEnabled() {
|
|
515
592
|
var _a;
|
|
516
|
-
return (((_a =
|
|
593
|
+
return (((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
517
594
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
518
595
|
}, {});
|
|
519
596
|
}
|
|
@@ -562,7 +639,7 @@ const _ParaCore = class _ParaCore {
|
|
|
562
639
|
}
|
|
563
640
|
isWalletSupported(wallet) {
|
|
564
641
|
var _a, _b;
|
|
565
|
-
return !((_a =
|
|
642
|
+
return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || (0, import_utils2.isWalletSupported)((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
566
643
|
}
|
|
567
644
|
isWalletOwned(wallet) {
|
|
568
645
|
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;
|
|
@@ -593,7 +670,7 @@ const _ParaCore = class _ParaCore {
|
|
|
593
670
|
} else if (!isOwned && !isUnclaimed) {
|
|
594
671
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
595
672
|
} else if (!this.isWalletSupported(wallet)) {
|
|
596
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b =
|
|
673
|
+
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(", ")}`;
|
|
597
674
|
} else if (types && (!(0, import_utils2.getEquivalentTypes)(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
598
675
|
var _a2, _b2;
|
|
599
676
|
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
@@ -624,7 +701,7 @@ const _ParaCore = class _ParaCore {
|
|
|
624
701
|
if (this.externalWallets[walletId]) {
|
|
625
702
|
const wallet2 = this.externalWallets[walletId];
|
|
626
703
|
return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, {
|
|
627
|
-
prefix: (_a =
|
|
704
|
+
prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
|
|
628
705
|
targetLength: options.targetLength
|
|
629
706
|
}) : wallet2.address;
|
|
630
707
|
}
|
|
@@ -636,7 +713,7 @@ const _ParaCore = class _ParaCore {
|
|
|
636
713
|
let prefix;
|
|
637
714
|
switch (wallet.type) {
|
|
638
715
|
case "COSMOS":
|
|
639
|
-
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b =
|
|
716
|
+
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
640
717
|
str = (0, import_utils2.getCosmosAddress)(wallet.publicKey, prefix);
|
|
641
718
|
break;
|
|
642
719
|
default:
|
|
@@ -670,29 +747,40 @@ const _ParaCore = class _ParaCore {
|
|
|
670
747
|
constructPortalUrl(_0) {
|
|
671
748
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
672
749
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
673
|
-
const [isCreate, isLogin, isOnRamp] = [
|
|
674
|
-
["createAuth", "createPassword"].includes(type),
|
|
675
|
-
["loginAuth", "loginPassword"].includes(type),
|
|
676
|
-
type === "onRamp"
|
|
750
|
+
const [isCreate, isLogin, isOnRamp, isOAuth, isOAuthCallback, isTelegramLogin, isFarcasterLogin] = [
|
|
751
|
+
["createAuth", "createPassword", "createPIN"].includes(type),
|
|
752
|
+
["loginAuth", "loginPassword", "loginPIN", "loginOTP"].includes(type),
|
|
753
|
+
type === "onRamp",
|
|
754
|
+
type === "oAuth",
|
|
755
|
+
type === "oAuthCallback",
|
|
756
|
+
["telegramLogin", "telegramLoginVerify"].includes(type),
|
|
757
|
+
type === "loginFarcaster"
|
|
677
758
|
];
|
|
759
|
+
if (isOAuth && !opts.oAuthMethod) {
|
|
760
|
+
throw new Error("oAuthMethod is required for oAuth portal URLs");
|
|
761
|
+
}
|
|
678
762
|
if (isCreate || isLogin) {
|
|
679
763
|
this.assertIsAuthSet();
|
|
680
764
|
}
|
|
681
765
|
let sessionId = opts.sessionId;
|
|
682
|
-
if ((isLogin || isOnRamp) && !sessionId) {
|
|
766
|
+
if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin) && !sessionId) {
|
|
683
767
|
const session = yield this.touchSession(true);
|
|
684
768
|
sessionId = session.sessionId;
|
|
685
769
|
}
|
|
686
770
|
if (!this.loginEncryptionKeyPair) {
|
|
687
771
|
yield this.setLoginEncryptionKeyPair();
|
|
688
772
|
}
|
|
689
|
-
const base = type === "onRamp" ||
|
|
773
|
+
const base = type === "onRamp" || isTelegramLogin ? (0, import_utils2.getPortalBaseURL)(this.ctx, isTelegramLogin) : yield this.getPortalURL();
|
|
690
774
|
let path;
|
|
691
775
|
switch (type) {
|
|
692
776
|
case "createPassword": {
|
|
693
777
|
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
694
778
|
break;
|
|
695
779
|
}
|
|
780
|
+
case "createPIN": {
|
|
781
|
+
path = `/web/users/${this.userId}/pin/${opts.pathId}`;
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
696
784
|
case "createAuth": {
|
|
697
785
|
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
698
786
|
break;
|
|
@@ -705,18 +793,42 @@ const _ParaCore = class _ParaCore {
|
|
|
705
793
|
path = "/web/biometrics/login";
|
|
706
794
|
break;
|
|
707
795
|
}
|
|
796
|
+
case "loginPIN": {
|
|
797
|
+
path = "/web/pin/login";
|
|
798
|
+
break;
|
|
799
|
+
}
|
|
708
800
|
case "txReview": {
|
|
709
801
|
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
710
802
|
break;
|
|
711
803
|
}
|
|
712
804
|
case "onRamp": {
|
|
713
|
-
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
805
|
+
path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
case "telegramLoginVerify": {
|
|
809
|
+
path = `/auth/telegram/verify`;
|
|
714
810
|
break;
|
|
715
811
|
}
|
|
716
812
|
case "telegramLogin": {
|
|
717
813
|
path = `/auth/telegram`;
|
|
718
814
|
break;
|
|
719
815
|
}
|
|
816
|
+
case "oAuth": {
|
|
817
|
+
path = `/auth/${opts.oAuthMethod.toLowerCase()}`;
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
case "oAuthCallback": {
|
|
821
|
+
path = `/auth/${opts.oAuthMethod.toLowerCase()}/callback`;
|
|
822
|
+
break;
|
|
823
|
+
}
|
|
824
|
+
case "loginOTP": {
|
|
825
|
+
path = "/auth/otp";
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
case "loginFarcaster": {
|
|
829
|
+
path = "/auth/farcaster";
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
720
832
|
default: {
|
|
721
833
|
throw new Error(`invalid URL type ${type}`);
|
|
722
834
|
}
|
|
@@ -735,7 +847,7 @@ const _ParaCore = class _ParaCore {
|
|
|
735
847
|
encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
|
|
736
848
|
sessionId
|
|
737
849
|
};
|
|
738
|
-
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
850
|
+
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
739
851
|
apiKey: this.ctx.apiKey,
|
|
740
852
|
partnerId: partner == null ? void 0 : partner.id,
|
|
741
853
|
portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
|
|
@@ -753,7 +865,7 @@ const _ParaCore = class _ParaCore {
|
|
|
753
865
|
}, (0, import_user_management_client.isPhone)(this.authInfo.auth) ? (0, import_utils2.splitPhoneNumber)(this.authInfo.auth.phone) : this.authInfo.auth), {
|
|
754
866
|
pfpUrl: this.authInfo.pfpUrl,
|
|
755
867
|
displayName: this.authInfo.displayName
|
|
756
|
-
}) : {}), isOnRamp ? {
|
|
868
|
+
}) : {}), isOnRamp ? { origin: typeof window !== "undefined" ? window.location.origin : void 0, email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin ? __spreadProps(__spreadValues({
|
|
757
869
|
sessionId: thisDevice.sessionId,
|
|
758
870
|
encryptionKey: thisDevice.encryptionKey
|
|
759
871
|
}, opts.newDevice ? {
|
|
@@ -761,7 +873,9 @@ const _ParaCore = class _ParaCore {
|
|
|
761
873
|
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
762
874
|
} : {}), {
|
|
763
875
|
pregenIds: JSON.stringify(this.pregenIds)
|
|
764
|
-
}) : {}),
|
|
876
|
+
}) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
|
|
877
|
+
appScheme: opts.appScheme
|
|
878
|
+
} : {}), isTelegramLogin ? { isEmbed: "true" } : {}), opts.params || {});
|
|
765
879
|
const url = (0, import_utils2.constructUrl)({ base, path, params });
|
|
766
880
|
if (opts.shorten) {
|
|
767
881
|
return (0, import_utils2.shortenUrl)(this.ctx, url);
|
|
@@ -769,15 +883,62 @@ const _ParaCore = class _ParaCore {
|
|
|
769
883
|
return url;
|
|
770
884
|
});
|
|
771
885
|
}
|
|
886
|
+
static resolveEnvironment(env, apiKey) {
|
|
887
|
+
var _a;
|
|
888
|
+
if (!apiKey) {
|
|
889
|
+
throw new Error("A Para API key is required.");
|
|
890
|
+
}
|
|
891
|
+
if (apiKey.includes("_")) {
|
|
892
|
+
const validEnvironmentPrefixes = Object.values(import_types.Environment);
|
|
893
|
+
const envPrefix = (_a = apiKey.split("_")[0]) == null ? void 0 : _a.toUpperCase();
|
|
894
|
+
const hasValidPrefix = validEnvironmentPrefixes.some((envValue) => envValue === envPrefix);
|
|
895
|
+
if (!hasValidPrefix) {
|
|
896
|
+
throw new Error(`Invalid API key environment prefix.`);
|
|
897
|
+
}
|
|
898
|
+
return envPrefix;
|
|
899
|
+
}
|
|
900
|
+
if (!env) {
|
|
901
|
+
throw new Error("Environment parameter is required.");
|
|
902
|
+
}
|
|
903
|
+
return env;
|
|
904
|
+
}
|
|
772
905
|
touchSession(regenerate = false) {
|
|
773
906
|
return __async(this, null, function* () {
|
|
774
|
-
var _a, _b, _c;
|
|
907
|
+
var _a, _b, _c, _d;
|
|
908
|
+
if (!this.isWorkerInitialized) {
|
|
909
|
+
this.initializeWorker();
|
|
910
|
+
}
|
|
775
911
|
if (!this.isReady) {
|
|
776
912
|
yield this.ready();
|
|
777
913
|
}
|
|
778
914
|
const session = yield this.ctx.client.touchSession(regenerate);
|
|
779
|
-
if (!
|
|
780
|
-
|
|
915
|
+
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) {
|
|
916
|
+
if (!session.partnerId) {
|
|
917
|
+
console.error(`
|
|
918
|
+
\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
919
|
+
\u{1F6A8} PARA SDK CONFIGURATION ERROR \u{1F6A8}
|
|
920
|
+
|
|
921
|
+
INVALID API KEY FOR CONFIGURED ENVIRONMENT
|
|
922
|
+
|
|
923
|
+
Your API key does not match the configured environment. This usually means:
|
|
924
|
+
|
|
925
|
+
1. You're using a production API key with a development environment
|
|
926
|
+
2. You're using a development API key with a production environment
|
|
927
|
+
3. Your API key is invalid or has been regenerated
|
|
928
|
+
|
|
929
|
+
SOLUTION:
|
|
930
|
+
\u2022 Verify your API key at: https://developer.getpara.com
|
|
931
|
+
\u2022 If your API key doesn't contain an environment prefix, ensure your API key is the correct key for your target environment
|
|
932
|
+
|
|
933
|
+
Current Environment: ${this.ctx.env}
|
|
934
|
+
API Key Prefix: ${((_d = this.ctx.apiKey) == null ? void 0 : _d.split("_")[0].toUpperCase()) || "None"}
|
|
935
|
+
|
|
936
|
+
Need help? Visit: https://docs.getpara.com or contact support
|
|
937
|
+
\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
938
|
+
`);
|
|
939
|
+
} else {
|
|
940
|
+
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
941
|
+
}
|
|
781
942
|
}
|
|
782
943
|
return session;
|
|
783
944
|
});
|
|
@@ -876,8 +1037,8 @@ const _ParaCore = class _ParaCore {
|
|
|
876
1037
|
return __privateGet(this, _authInfo);
|
|
877
1038
|
});
|
|
878
1039
|
}
|
|
879
|
-
assertUserId() {
|
|
880
|
-
if (!this.userId || this.isGuestMode) {
|
|
1040
|
+
assertUserId({ allowGuestMode = false } = {}) {
|
|
1041
|
+
if (!this.userId || !allowGuestMode && this.isGuestMode) {
|
|
881
1042
|
throw new Error("no userId is set");
|
|
882
1043
|
}
|
|
883
1044
|
return this.userId;
|
|
@@ -935,11 +1096,59 @@ const _ParaCore = class _ParaCore {
|
|
|
935
1096
|
*/
|
|
936
1097
|
setExternalWallet(externalWallet) {
|
|
937
1098
|
return __async(this, null, function* () {
|
|
1099
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
938
1100
|
this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
|
|
1101
|
+
(acc, {
|
|
1102
|
+
partnerId: wPartnerId,
|
|
1103
|
+
address,
|
|
1104
|
+
type,
|
|
1105
|
+
provider,
|
|
1106
|
+
providerId,
|
|
1107
|
+
addressBech32,
|
|
1108
|
+
withFullParaAuth,
|
|
1109
|
+
isConnectionOnly,
|
|
1110
|
+
withVerification
|
|
1111
|
+
}) => {
|
|
1112
|
+
if (partnerId === wPartnerId && supportedWalletTypes.some(({ type: supportedType }) => supportedType === type)) {
|
|
1113
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1114
|
+
[address]: {
|
|
1115
|
+
id: address,
|
|
1116
|
+
partnerId,
|
|
1117
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
1118
|
+
type,
|
|
1119
|
+
name: provider,
|
|
1120
|
+
isExternal: true,
|
|
1121
|
+
isExternalWithParaAuth: withFullParaAuth,
|
|
1122
|
+
externalProviderId: providerId,
|
|
1123
|
+
signer: "",
|
|
1124
|
+
isExternalConnectionOnly: isConnectionOnly,
|
|
1125
|
+
isExternalWithVerification: withVerification
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
return acc;
|
|
1130
|
+
},
|
|
1131
|
+
{}
|
|
1132
|
+
), this.setExternalWallets(this.externalWallets);
|
|
1133
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
addExternalWallets(externalWallets) {
|
|
1137
|
+
return __async(this, null, function* () {
|
|
1138
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1139
|
+
this.externalWallets = __spreadValues(__spreadValues({}, Object.entries(this.externalWallets).reduce((acc, [address, wallet]) => {
|
|
1140
|
+
if (partnerId === wallet.partnerId && supportedWalletTypes.some(({ type }) => type === wallet.type)) {
|
|
1141
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1142
|
+
[address]: wallet
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
return acc;
|
|
1146
|
+
}, {})), externalWallets.reduce(
|
|
939
1147
|
(acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
|
|
940
1148
|
return __spreadProps(__spreadValues({}, acc), {
|
|
941
1149
|
[address]: {
|
|
942
1150
|
id: address,
|
|
1151
|
+
partnerId,
|
|
943
1152
|
address: addressBech32 != null ? addressBech32 : address,
|
|
944
1153
|
type,
|
|
945
1154
|
name: provider,
|
|
@@ -953,7 +1162,7 @@ const _ParaCore = class _ParaCore {
|
|
|
953
1162
|
});
|
|
954
1163
|
},
|
|
955
1164
|
{}
|
|
956
|
-
);
|
|
1165
|
+
));
|
|
957
1166
|
this.setExternalWallets(this.externalWallets);
|
|
958
1167
|
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
959
1168
|
});
|
|
@@ -1307,7 +1516,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1307
1516
|
]);
|
|
1308
1517
|
const externalWallets = Array.isArray(externalWallet) ? externalWallet : [externalWallet];
|
|
1309
1518
|
if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
|
|
1310
|
-
yield this.
|
|
1519
|
+
yield this.addExternalWallets(
|
|
1311
1520
|
externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
|
|
1312
1521
|
withFullParaAuth: false
|
|
1313
1522
|
}))
|
|
@@ -1342,12 +1551,17 @@ const _ParaCore = class _ParaCore {
|
|
|
1342
1551
|
"cosmosPublicKeyHex",
|
|
1343
1552
|
"cosmosSigner"
|
|
1344
1553
|
]);
|
|
1554
|
+
var _a;
|
|
1345
1555
|
const serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
|
|
1346
1556
|
externalWallet,
|
|
1347
1557
|
signedMessage,
|
|
1348
1558
|
cosmosPublicKeyHex,
|
|
1349
1559
|
cosmosSigner
|
|
1350
1560
|
});
|
|
1561
|
+
if (serverAuthState.stage === "login" && ((_a = serverAuthState.loginAuthMethods) == null ? void 0 : _a.includes(import_user_management_client.AuthMethod.PIN))) {
|
|
1562
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
1563
|
+
return __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1564
|
+
}
|
|
1351
1565
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1352
1566
|
});
|
|
1353
1567
|
}
|
|
@@ -1364,6 +1578,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1364
1578
|
return accounts;
|
|
1365
1579
|
});
|
|
1366
1580
|
}
|
|
1581
|
+
// TELEGRAM
|
|
1367
1582
|
/**
|
|
1368
1583
|
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
1369
1584
|
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
@@ -1373,19 +1588,28 @@ const _ParaCore = class _ParaCore {
|
|
|
1373
1588
|
verifyTelegramProcess(_e) {
|
|
1374
1589
|
return __async(this, null, function* () {
|
|
1375
1590
|
var _f = _e, {
|
|
1591
|
+
serverAuthState: optsServerAuthState,
|
|
1376
1592
|
telegramAuthResponse,
|
|
1377
1593
|
isLinkAccount
|
|
1378
1594
|
} = _f, urlOptions = __objRest(_f, [
|
|
1595
|
+
"serverAuthState",
|
|
1379
1596
|
"telegramAuthResponse",
|
|
1380
1597
|
"isLinkAccount"
|
|
1381
1598
|
]);
|
|
1382
1599
|
try {
|
|
1383
1600
|
switch (isLinkAccount) {
|
|
1384
1601
|
case false: {
|
|
1385
|
-
|
|
1386
|
-
|
|
1602
|
+
if (!optsServerAuthState && !telegramAuthResponse) {
|
|
1603
|
+
throw new Error("one of serverAuthState or telegramAuthResponse are required for verifying telegram");
|
|
1604
|
+
}
|
|
1605
|
+
const serverAuthState = optsServerAuthState != null ? optsServerAuthState : yield this.ctx.client.verifyTelegram({ authObject: telegramAuthResponse });
|
|
1606
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
1607
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1387
1608
|
}
|
|
1388
1609
|
case true: {
|
|
1610
|
+
if (!telegramAuthResponse) {
|
|
1611
|
+
throw new Error("telegramAuthResponse is required for verifying telegram link");
|
|
1612
|
+
}
|
|
1389
1613
|
const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
|
|
1390
1614
|
const accounts = yield this.verifyLink({
|
|
1391
1615
|
accountLinkInProgress,
|
|
@@ -1459,6 +1683,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1459
1683
|
let type, linkedAccountId;
|
|
1460
1684
|
switch (reason) {
|
|
1461
1685
|
case "SIGNUP":
|
|
1686
|
+
case "LOGIN":
|
|
1462
1687
|
{
|
|
1463
1688
|
const authInfo = this.assertIsAuthSet(["email", "phone"]);
|
|
1464
1689
|
type = authInfo.authType.toUpperCase();
|
|
@@ -1472,7 +1697,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1472
1697
|
}
|
|
1473
1698
|
break;
|
|
1474
1699
|
}
|
|
1475
|
-
const userId = this.assertUserId();
|
|
1700
|
+
const userId = this.assertUserId({ allowGuestMode: true });
|
|
1476
1701
|
if (type !== "EMAIL" && type !== "PHONE") {
|
|
1477
1702
|
throw new Error("invalid auth type for verification code");
|
|
1478
1703
|
}
|
|
@@ -1510,6 +1735,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1510
1735
|
isFullyLoggedIn() {
|
|
1511
1736
|
return __async(this, null, function* () {
|
|
1512
1737
|
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1738
|
+
if (!this.isReady) {
|
|
1739
|
+
yield this.ready();
|
|
1740
|
+
}
|
|
1513
1741
|
return true;
|
|
1514
1742
|
}
|
|
1515
1743
|
if (this.isGuestMode) {
|
|
@@ -1526,10 +1754,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1526
1754
|
return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
|
|
1527
1755
|
({ userId, partnerId }) => {
|
|
1528
1756
|
var _a;
|
|
1529
|
-
return partnerId === ((_a =
|
|
1757
|
+
return partnerId === ((_a = this.partner) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
|
|
1530
1758
|
}
|
|
1531
1759
|
);
|
|
1532
1760
|
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Get the auth methods available to an existing user
|
|
1763
|
+
*/
|
|
1533
1764
|
supportedAuthMethods(auth) {
|
|
1534
1765
|
return __async(this, null, function* () {
|
|
1535
1766
|
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
@@ -1633,6 +1864,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1633
1864
|
return connectUri;
|
|
1634
1865
|
});
|
|
1635
1866
|
}
|
|
1867
|
+
// FARCASTER
|
|
1636
1868
|
/**
|
|
1637
1869
|
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
1638
1870
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
@@ -1645,14 +1877,20 @@ const _ParaCore = class _ParaCore {
|
|
|
1645
1877
|
onConnectUri,
|
|
1646
1878
|
onCancel,
|
|
1647
1879
|
onPoll,
|
|
1648
|
-
isLinkAccount
|
|
1880
|
+
isLinkAccount,
|
|
1881
|
+
serverAuthState: optsServerAuthState
|
|
1649
1882
|
} = _h, urlOptions = __objRest(_h, [
|
|
1650
1883
|
"isCanceled",
|
|
1651
1884
|
"onConnectUri",
|
|
1652
1885
|
"onCancel",
|
|
1653
1886
|
"onPoll",
|
|
1654
|
-
"isLinkAccount"
|
|
1887
|
+
"isLinkAccount",
|
|
1888
|
+
"serverAuthState"
|
|
1655
1889
|
]);
|
|
1890
|
+
if (optsServerAuthState) {
|
|
1891
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, optsServerAuthState, urlOptions);
|
|
1892
|
+
return authState;
|
|
1893
|
+
}
|
|
1656
1894
|
let accountLinkInProgress;
|
|
1657
1895
|
if (isLinkAccount) {
|
|
1658
1896
|
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
|
|
@@ -1714,7 +1952,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1714
1952
|
}
|
|
1715
1953
|
getOAuthUrl(opts) {
|
|
1716
1954
|
return __async(this, null, function* () {
|
|
1717
|
-
|
|
1955
|
+
var _a;
|
|
1956
|
+
const sessionLookupId = (_a = opts.sessionLookupId) != null ? _a : yield this.prepareLogin();
|
|
1957
|
+
return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
|
|
1718
1958
|
});
|
|
1719
1959
|
}
|
|
1720
1960
|
/**
|
|
@@ -1725,35 +1965,54 @@ const _ParaCore = class _ParaCore {
|
|
|
1725
1965
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1726
1966
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1727
1967
|
*/
|
|
1728
|
-
verifyOAuthProcess(
|
|
1968
|
+
verifyOAuthProcess(_i) {
|
|
1729
1969
|
return __async(this, null, function* () {
|
|
1730
|
-
var
|
|
1970
|
+
var _j = _i, {
|
|
1731
1971
|
method,
|
|
1732
1972
|
appScheme,
|
|
1733
1973
|
isCanceled = () => false,
|
|
1734
1974
|
onCancel,
|
|
1735
1975
|
onPoll,
|
|
1736
1976
|
onOAuthUrl,
|
|
1977
|
+
onOAuthPopup,
|
|
1737
1978
|
isLinkAccount
|
|
1738
|
-
} =
|
|
1979
|
+
} = _j, urlOptions = __objRest(_j, [
|
|
1739
1980
|
"method",
|
|
1740
1981
|
"appScheme",
|
|
1741
1982
|
"isCanceled",
|
|
1742
1983
|
"onCancel",
|
|
1743
1984
|
"onPoll",
|
|
1744
1985
|
"onOAuthUrl",
|
|
1986
|
+
"onOAuthPopup",
|
|
1745
1987
|
"isLinkAccount"
|
|
1746
1988
|
]);
|
|
1989
|
+
if (onOAuthPopup) {
|
|
1990
|
+
try {
|
|
1991
|
+
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.OAUTH });
|
|
1992
|
+
} catch (error) {
|
|
1993
|
+
throw new Error(`Failed to open OAuth popup: ${error}`);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1747
1996
|
let sessionLookupId, accountLinkInProgress;
|
|
1748
|
-
if (onOAuthUrl) {
|
|
1997
|
+
if (onOAuthUrl || onOAuthPopup) {
|
|
1749
1998
|
if (isLinkAccount) {
|
|
1750
1999
|
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
|
|
1751
2000
|
sessionLookupId = (yield this.touchSession()).sessionLookupId;
|
|
1752
2001
|
} else {
|
|
1753
|
-
sessionLookupId = yield
|
|
2002
|
+
sessionLookupId = yield this.prepareLogin();
|
|
1754
2003
|
}
|
|
1755
2004
|
const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, appScheme, sessionLookupId, accountLinkInProgress });
|
|
1756
|
-
|
|
2005
|
+
switch (true) {
|
|
2006
|
+
case !!onOAuthUrl: {
|
|
2007
|
+
onOAuthUrl(oAuthUrl);
|
|
2008
|
+
break;
|
|
2009
|
+
}
|
|
2010
|
+
case (!!onOAuthPopup && !!this.popupWindow): {
|
|
2011
|
+
this.popupWindow.location.href = oAuthUrl;
|
|
2012
|
+
onOAuthPopup(this.popupWindow);
|
|
2013
|
+
break;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
1757
2016
|
} else {
|
|
1758
2017
|
({ sessionLookupId } = yield this.touchSession());
|
|
1759
2018
|
}
|
|
@@ -1889,7 +2148,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1889
2148
|
sessionId
|
|
1890
2149
|
});
|
|
1891
2150
|
if (shouldOpenPopup) {
|
|
1892
|
-
this.platformUtils.openPopup(link);
|
|
2151
|
+
yield this.platformUtils.openPopup(link);
|
|
1893
2152
|
}
|
|
1894
2153
|
return link;
|
|
1895
2154
|
});
|
|
@@ -1980,7 +2239,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1980
2239
|
userId: this.userId,
|
|
1981
2240
|
walletId,
|
|
1982
2241
|
userShare: userSigner,
|
|
1983
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2242
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
2243
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2244
|
+
walletScheme: this.wallets[walletId].scheme
|
|
1984
2245
|
});
|
|
1985
2246
|
return recoveryShare;
|
|
1986
2247
|
});
|
|
@@ -2108,7 +2369,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2108
2369
|
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
2109
2370
|
emailProps: this.getBackupKitEmailProps(),
|
|
2110
2371
|
partnerId: newPartnerId,
|
|
2111
|
-
protocolId
|
|
2372
|
+
protocolId,
|
|
2373
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2374
|
+
walletScheme: this.wallets[walletId].scheme
|
|
2112
2375
|
});
|
|
2113
2376
|
return { signer, recoverySecret, protocolId };
|
|
2114
2377
|
});
|
|
@@ -2174,7 +2437,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2174
2437
|
userId: this.userId,
|
|
2175
2438
|
walletId: wallet.id,
|
|
2176
2439
|
userShare: signer,
|
|
2177
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2440
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
2441
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2442
|
+
walletScheme: wallet.scheme
|
|
2178
2443
|
});
|
|
2179
2444
|
}
|
|
2180
2445
|
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
@@ -2255,7 +2520,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2255
2520
|
walletId: wallet.id,
|
|
2256
2521
|
userShare: this.wallets[wallet.id].signer,
|
|
2257
2522
|
emailProps: this.getBackupKitEmailProps(),
|
|
2258
|
-
partnerId: wallet.partnerId
|
|
2523
|
+
partnerId: wallet.partnerId,
|
|
2524
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2525
|
+
walletScheme: wallet.scheme
|
|
2259
2526
|
});
|
|
2260
2527
|
if (distributeRes.length > 0) {
|
|
2261
2528
|
newRecoverySecret = distributeRes;
|
|
@@ -2433,25 +2700,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2433
2700
|
});
|
|
2434
2701
|
});
|
|
2435
2702
|
}
|
|
2436
|
-
getOnRampTransactionUrl(
|
|
2437
|
-
return __async(this,
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
providerKey
|
|
2441
|
-
} = _n, walletParams = __objRest(_n, [
|
|
2442
|
-
"purchaseId",
|
|
2443
|
-
"providerKey"
|
|
2444
|
-
]);
|
|
2445
|
-
const { sessionId } = yield this.touchSession();
|
|
2446
|
-
const [key, identifier] = (0, import_user_management_client.extractWalletRef)(walletParams);
|
|
2703
|
+
getOnRampTransactionUrl(_0) {
|
|
2704
|
+
return __async(this, arguments, function* ({
|
|
2705
|
+
purchaseId
|
|
2706
|
+
}) {
|
|
2447
2707
|
return this.constructPortalUrl("onRamp", {
|
|
2448
|
-
pathId: purchaseId
|
|
2449
|
-
sessionId,
|
|
2450
|
-
params: {
|
|
2451
|
-
[key]: identifier,
|
|
2452
|
-
providerKey,
|
|
2453
|
-
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
2454
|
-
}
|
|
2708
|
+
pathId: purchaseId
|
|
2455
2709
|
});
|
|
2456
2710
|
});
|
|
2457
2711
|
}
|
|
@@ -2485,7 +2739,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2485
2739
|
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2486
2740
|
let timeStart = Date.now();
|
|
2487
2741
|
if (signRes.pendingTransactionId) {
|
|
2488
|
-
this.platformUtils.openPopup(
|
|
2742
|
+
yield this.platformUtils.openPopup(
|
|
2489
2743
|
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2490
2744
|
{ type: cosmosSignDocBase64 ? import_types.PopupType.SIGN_TRANSACTION_REVIEW : import_types.PopupType.SIGN_MESSAGE_REVIEW }
|
|
2491
2745
|
);
|
|
@@ -2597,7 +2851,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2597
2851
|
);
|
|
2598
2852
|
let timeStart = Date.now();
|
|
2599
2853
|
if (signRes.pendingTransactionId) {
|
|
2600
|
-
this.platformUtils.openPopup(
|
|
2854
|
+
yield this.platformUtils.openPopup(
|
|
2601
2855
|
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2602
2856
|
{ type: import_types.PopupType.SIGN_TRANSACTION_REVIEW }
|
|
2603
2857
|
);
|
|
@@ -2673,7 +2927,8 @@ const _ParaCore = class _ParaCore {
|
|
|
2673
2927
|
providerKey: onRampPurchase.providerKey
|
|
2674
2928
|
}, walletParams));
|
|
2675
2929
|
if (shouldOpenPopup) {
|
|
2676
|
-
this.platformUtils.openPopup(portalUrl, { type: import_types.PopupType.ON_RAMP_TRANSACTION });
|
|
2930
|
+
const onRampWindow = yield this.platformUtils.openPopup(portalUrl, { type: import_types.PopupType.ON_RAMP_TRANSACTION });
|
|
2931
|
+
this.onRampPopup = { window: onRampWindow, onRampPurchase };
|
|
2677
2932
|
}
|
|
2678
2933
|
return { onRampPurchase, portalUrl };
|
|
2679
2934
|
});
|
|
@@ -2769,6 +3024,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2769
3024
|
**/
|
|
2770
3025
|
logout() {
|
|
2771
3026
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3027
|
+
const shouldDispatchLogoutEvent = yield this.isSessionActive();
|
|
2772
3028
|
yield this.ctx.client.logout();
|
|
2773
3029
|
yield this.clearStorage();
|
|
2774
3030
|
if (!clearPregenWallets) {
|
|
@@ -2788,7 +3044,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2788
3044
|
this.accountLinkInProgress = void 0;
|
|
2789
3045
|
this.userId = void 0;
|
|
2790
3046
|
this.sessionCookie = void 0;
|
|
2791
|
-
(
|
|
3047
|
+
if (shouldDispatchLogoutEvent) {
|
|
3048
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
|
|
3049
|
+
}
|
|
2792
3050
|
});
|
|
2793
3051
|
}
|
|
2794
3052
|
get toStringAdditions() {
|
|
@@ -2818,9 +3076,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2818
3076
|
{}
|
|
2819
3077
|
);
|
|
2820
3078
|
const obj = __spreadProps(__spreadValues({
|
|
2821
|
-
partnerId: (_a =
|
|
2822
|
-
supportedWalletTypes: (_b =
|
|
2823
|
-
cosmosPrefix: (_c =
|
|
3079
|
+
partnerId: (_a = this.partner) == null ? void 0 : _a.id,
|
|
3080
|
+
supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
|
|
3081
|
+
cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
|
|
2824
3082
|
authInfo: __privateGet(this, _authInfo),
|
|
2825
3083
|
isGuestMode: this.isGuestMode,
|
|
2826
3084
|
userId: this.userId,
|
|
@@ -2877,6 +3135,14 @@ const _ParaCore = class _ParaCore {
|
|
|
2877
3135
|
}));
|
|
2878
3136
|
urlType = "createPassword";
|
|
2879
3137
|
break;
|
|
3138
|
+
case "PIN":
|
|
3139
|
+
({
|
|
3140
|
+
data: { id: credentialId }
|
|
3141
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3142
|
+
status: import_user_management_client.PasswordStatus.PENDING
|
|
3143
|
+
}));
|
|
3144
|
+
urlType = "createPIN";
|
|
3145
|
+
break;
|
|
2880
3146
|
}
|
|
2881
3147
|
const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
|
|
2882
3148
|
isForNewDevice,
|
|
@@ -2888,7 +3154,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2888
3154
|
});
|
|
2889
3155
|
}
|
|
2890
3156
|
/**
|
|
2891
|
-
* Returns a Para Portal URL for logging in with a WebAuth passkey or
|
|
3157
|
+
* Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
|
|
2892
3158
|
* @param {Object} opts the options object
|
|
2893
3159
|
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
2894
3160
|
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
@@ -2914,6 +3180,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2914
3180
|
case "PASSWORD":
|
|
2915
3181
|
urlType = "loginPassword";
|
|
2916
3182
|
break;
|
|
3183
|
+
case "PIN":
|
|
3184
|
+
urlType = "loginPIN";
|
|
3185
|
+
break;
|
|
3186
|
+
case "SLO":
|
|
3187
|
+
urlType = "loginOTP";
|
|
3188
|
+
break;
|
|
2917
3189
|
default:
|
|
2918
3190
|
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
2919
3191
|
}
|
|
@@ -2924,9 +3196,19 @@ const _ParaCore = class _ParaCore {
|
|
|
2924
3196
|
});
|
|
2925
3197
|
});
|
|
2926
3198
|
}
|
|
2927
|
-
|
|
3199
|
+
prepareLogin() {
|
|
2928
3200
|
return __async(this, null, function* () {
|
|
2929
|
-
|
|
3201
|
+
yield this.logout();
|
|
3202
|
+
const { sessionLookupId } = yield this.touchSession(true);
|
|
3203
|
+
if (!this.loginEncryptionKeyPair) {
|
|
3204
|
+
yield this.setLoginEncryptionKeyPair();
|
|
3205
|
+
}
|
|
3206
|
+
return sessionLookupId;
|
|
3207
|
+
});
|
|
3208
|
+
}
|
|
3209
|
+
signUpOrLogIn(_k) {
|
|
3210
|
+
return __async(this, null, function* () {
|
|
3211
|
+
var _l = _k, { auth } = _l, urlOptions = __objRest(_l, ["auth"]);
|
|
2930
3212
|
const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
2931
3213
|
const authInfo = serverAuthState.auth;
|
|
2932
3214
|
if (this.fetchPregenWalletsOverride && (0, import_user_management_client.isPregenAuth)(authInfo)) {
|
|
@@ -2935,21 +3217,24 @@ const _ParaCore = class _ParaCore {
|
|
|
2935
3217
|
yield this.setUserShare(userShare);
|
|
2936
3218
|
}
|
|
2937
3219
|
}
|
|
2938
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3220
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadValues({}, urlOptions));
|
|
2939
3221
|
});
|
|
2940
3222
|
}
|
|
2941
|
-
verifyNewAccount(
|
|
3223
|
+
verifyNewAccount(_m) {
|
|
2942
3224
|
return __async(this, null, function* () {
|
|
2943
|
-
var
|
|
3225
|
+
var _n = _m, {
|
|
2944
3226
|
verificationCode
|
|
2945
|
-
} =
|
|
3227
|
+
} = _n, urlOptions = __objRest(_n, [
|
|
2946
3228
|
"verificationCode"
|
|
2947
3229
|
]);
|
|
2948
3230
|
this.assertIsAuthSet(["email", "phone"]);
|
|
2949
|
-
const userId = this.assertUserId();
|
|
2950
|
-
const serverAuthState = yield this.ctx.client.
|
|
3231
|
+
const userId = this.assertUserId({ allowGuestMode: true });
|
|
3232
|
+
const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
|
|
2951
3233
|
verificationCode
|
|
2952
3234
|
});
|
|
3235
|
+
if (serverAuthState.stage === "login" || serverAuthState.stage === "done") {
|
|
3236
|
+
throw new Error("Account already exists.");
|
|
3237
|
+
}
|
|
2953
3238
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2954
3239
|
});
|
|
2955
3240
|
}
|
|
@@ -3036,10 +3321,10 @@ const _ParaCore = class _ParaCore {
|
|
|
3036
3321
|
});
|
|
3037
3322
|
}
|
|
3038
3323
|
verifyLink() {
|
|
3039
|
-
return __async(this, arguments, function* (
|
|
3040
|
-
var
|
|
3324
|
+
return __async(this, arguments, function* (_o = {}) {
|
|
3325
|
+
var _p = _o, {
|
|
3041
3326
|
accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
|
|
3042
|
-
} =
|
|
3327
|
+
} = _p, opts = __objRest(_p, [
|
|
3043
3328
|
"accountLinkInProgress"
|
|
3044
3329
|
]);
|
|
3045
3330
|
try {
|
|
@@ -3068,31 +3353,36 @@ const _ParaCore = class _ParaCore {
|
|
|
3068
3353
|
return accounts;
|
|
3069
3354
|
});
|
|
3070
3355
|
}
|
|
3356
|
+
sendLoginCode() {
|
|
3357
|
+
return __async(this, null, function* () {
|
|
3358
|
+
const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
|
|
3359
|
+
this.setUserId(userId);
|
|
3360
|
+
});
|
|
3361
|
+
}
|
|
3071
3362
|
};
|
|
3072
3363
|
_authInfo = new WeakMap();
|
|
3073
|
-
_partner = new WeakMap();
|
|
3074
3364
|
_ParaCore_instances = new WeakSet();
|
|
3075
3365
|
assertPartner_fn = function() {
|
|
3076
3366
|
return __async(this, null, function* () {
|
|
3077
3367
|
var _a, _b;
|
|
3078
|
-
if (!
|
|
3368
|
+
if (!this.partner) {
|
|
3079
3369
|
yield this.touchSession();
|
|
3080
3370
|
}
|
|
3081
|
-
if (((_a =
|
|
3082
|
-
this.ctx.cosmosPrefix = (_b =
|
|
3371
|
+
if (((_a = this.partner) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== this.partner.cosmosPrefix) {
|
|
3372
|
+
this.ctx.cosmosPrefix = (_b = this.partner) == null ? void 0 : _b.cosmosPrefix;
|
|
3083
3373
|
}
|
|
3084
|
-
return
|
|
3374
|
+
return this.partner;
|
|
3085
3375
|
});
|
|
3086
3376
|
};
|
|
3087
3377
|
guestWalletIds_get = function() {
|
|
3088
3378
|
var _a, _b, _c;
|
|
3089
|
-
if (!((_a =
|
|
3379
|
+
if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
3090
3380
|
return {};
|
|
3091
3381
|
}
|
|
3092
3382
|
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
3093
3383
|
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
3094
3384
|
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
3095
|
-
return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) =>
|
|
3385
|
+
return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
3096
3386
|
var _a2;
|
|
3097
3387
|
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
3098
3388
|
}, {}));
|
|
@@ -3153,8 +3443,8 @@ getPartner_fn = function(partnerId) {
|
|
|
3153
3443
|
return void 0;
|
|
3154
3444
|
}
|
|
3155
3445
|
const res = yield this.ctx.client.getPartner(partnerId);
|
|
3156
|
-
|
|
3157
|
-
return
|
|
3446
|
+
this.partner = res.data.partner;
|
|
3447
|
+
return this.partner;
|
|
3158
3448
|
});
|
|
3159
3449
|
};
|
|
3160
3450
|
assertIsLinkingAccount_fn = function(types) {
|
|
@@ -3176,29 +3466,42 @@ assertIsLinkingAccountOrStart_fn = function(type) {
|
|
|
3176
3466
|
return yield this.linkAccount({ type });
|
|
3177
3467
|
});
|
|
3178
3468
|
};
|
|
3179
|
-
getOAuthUrl_fn = function(
|
|
3180
|
-
return __async(this,
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
"
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3469
|
+
getOAuthUrl_fn = function(_0) {
|
|
3470
|
+
return __async(this, arguments, function* ({
|
|
3471
|
+
method,
|
|
3472
|
+
appScheme,
|
|
3473
|
+
accountLinkInProgress,
|
|
3474
|
+
sessionLookupId,
|
|
3475
|
+
encryptionKey
|
|
3476
|
+
}) {
|
|
3477
|
+
if (!accountLinkInProgress && !this.isPortal()) {
|
|
3478
|
+
return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
|
|
3479
|
+
}
|
|
3480
|
+
let portalSessionLookupId;
|
|
3481
|
+
if (this.isPortal()) {
|
|
3482
|
+
portalSessionLookupId = (yield this.touchSession(true)).sessionLookupId;
|
|
3483
|
+
}
|
|
3192
3484
|
return (0, import_utils2.constructUrl)({
|
|
3193
3485
|
base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
|
|
3194
3486
|
path: `/auth/${method}`,
|
|
3195
|
-
params: __spreadValues({
|
|
3487
|
+
params: __spreadProps(__spreadValues({
|
|
3196
3488
|
apiKey: this.ctx.apiKey,
|
|
3197
3489
|
sessionLookupId,
|
|
3490
|
+
portalSessionLookupId,
|
|
3198
3491
|
appScheme
|
|
3199
3492
|
}, accountLinkInProgress ? {
|
|
3200
3493
|
linkedAccountId: this.accountLinkInProgress.id
|
|
3201
|
-
} : {})
|
|
3494
|
+
} : {}), {
|
|
3495
|
+
callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", {
|
|
3496
|
+
sessionId: sessionLookupId,
|
|
3497
|
+
oAuthMethod: method,
|
|
3498
|
+
appScheme,
|
|
3499
|
+
thisDevice: {
|
|
3500
|
+
sessionId: sessionLookupId,
|
|
3501
|
+
encryptionKey
|
|
3502
|
+
}
|
|
3503
|
+
}))
|
|
3504
|
+
})
|
|
3202
3505
|
});
|
|
3203
3506
|
});
|
|
3204
3507
|
};
|
|
@@ -3252,8 +3555,9 @@ createPregenWallet_fn = function(opts) {
|
|
|
3252
3555
|
_isCreateGuestWalletsPending = new WeakMap();
|
|
3253
3556
|
prepareAuthState_fn = function(_0) {
|
|
3254
3557
|
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
3255
|
-
|
|
3256
|
-
|
|
3558
|
+
var _a, _b;
|
|
3559
|
+
if (!opts.sessionLookupId && serverAuthState.stage === "login" && (!serverAuthState.externalWallet || !(((_a = serverAuthState.externalWallet) == null ? void 0 : _a.withFullParaAuth) && ((_b = serverAuthState.loginAuthMethods) == null ? void 0 : _b.includes(import_user_management_client.AuthMethod.PIN))))) {
|
|
3560
|
+
opts.sessionLookupId = yield this.prepareLogin();
|
|
3257
3561
|
}
|
|
3258
3562
|
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
3259
3563
|
const authInfo = __spreadValues(__spreadValues({}, (0, import_user_management_client.extractAuthInfo)(auth, { isRequired: true })), Object.fromEntries(
|
|
@@ -3274,8 +3578,14 @@ prepareAuthState_fn = function(_0) {
|
|
|
3274
3578
|
}
|
|
3275
3579
|
let authState;
|
|
3276
3580
|
switch (serverAuthState.stage) {
|
|
3581
|
+
case "done": {
|
|
3582
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareDoneState_fn).call(this, serverAuthState);
|
|
3583
|
+
break;
|
|
3584
|
+
}
|
|
3277
3585
|
case "verify":
|
|
3278
|
-
authState = serverAuthState
|
|
3586
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareVerificationState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), {
|
|
3587
|
+
sessionLookupId: opts.sessionLookupId
|
|
3588
|
+
}));
|
|
3279
3589
|
break;
|
|
3280
3590
|
case "login":
|
|
3281
3591
|
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
@@ -3295,14 +3605,34 @@ prepareAuthState_fn = function(_0) {
|
|
|
3295
3605
|
return authState;
|
|
3296
3606
|
});
|
|
3297
3607
|
};
|
|
3298
|
-
|
|
3608
|
+
prepareDoneState_fn = function(doneState) {
|
|
3299
3609
|
return __async(this, null, function* () {
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3610
|
+
let isSLOPossible = doneState.authMethods.includes(import_user_management_client.AuthMethod.SLO);
|
|
3611
|
+
this.isEnclaveUser = isSLOPossible;
|
|
3612
|
+
return doneState;
|
|
3613
|
+
});
|
|
3614
|
+
};
|
|
3615
|
+
prepareVerificationState_fn = function(_0, _1) {
|
|
3616
|
+
return __async(this, arguments, function* (verifyState, {
|
|
3617
|
+
useShortUrls: shorten = false,
|
|
3618
|
+
portalTheme,
|
|
3619
|
+
sessionLookupId
|
|
3620
|
+
}) {
|
|
3621
|
+
let isSLOPossible = false;
|
|
3622
|
+
if (verifyState.nextStage === "login") {
|
|
3623
|
+
isSLOPossible = verifyState.loginAuthMethods.includes(import_user_management_client.AuthMethod.SLO);
|
|
3624
|
+
} else if (verifyState.nextStage === "signup") {
|
|
3625
|
+
isSLOPossible = verifyState.signupAuthMethods.includes(import_user_management_client.AuthMethod.SLO);
|
|
3304
3626
|
}
|
|
3305
|
-
|
|
3627
|
+
this.isEnclaveUser = isSLOPossible;
|
|
3628
|
+
return __spreadValues(__spreadValues({}, verifyState), isSLOPossible ? {
|
|
3629
|
+
loginUrl: yield this.getLoginUrl({
|
|
3630
|
+
authMethod: import_user_management_client.AuthMethod.SLO,
|
|
3631
|
+
sessionId: sessionLookupId,
|
|
3632
|
+
shorten,
|
|
3633
|
+
portalTheme
|
|
3634
|
+
})
|
|
3635
|
+
} : {});
|
|
3306
3636
|
});
|
|
3307
3637
|
};
|
|
3308
3638
|
prepareLoginState_fn = function(_0, _1) {
|
|
@@ -3311,9 +3641,9 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3311
3641
|
portalTheme,
|
|
3312
3642
|
sessionLookupId
|
|
3313
3643
|
}) {
|
|
3314
|
-
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
3315
|
-
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);
|
|
3316
|
-
return __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
3644
|
+
const _a = loginState, { loginAuthMethods, hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
|
|
3645
|
+
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);
|
|
3646
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
3317
3647
|
isPasskeySupported
|
|
3318
3648
|
}), isPasskeyPossible ? {
|
|
3319
3649
|
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
@@ -3333,6 +3663,13 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3333
3663
|
portalTheme,
|
|
3334
3664
|
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
3335
3665
|
})
|
|
3666
|
+
} : {}), isPINPossible ? {
|
|
3667
|
+
pinUrl: yield this.constructPortalUrl("loginPIN", {
|
|
3668
|
+
sessionId: sessionLookupId,
|
|
3669
|
+
shorten,
|
|
3670
|
+
portalTheme,
|
|
3671
|
+
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
3672
|
+
})
|
|
3336
3673
|
} : {});
|
|
3337
3674
|
});
|
|
3338
3675
|
};
|
|
@@ -3340,13 +3677,14 @@ prepareSignUpState_fn = function(_0, _1) {
|
|
|
3340
3677
|
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
3341
3678
|
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
3342
3679
|
const isPasskeySupported = yield this.isPasskeySupported();
|
|
3343
|
-
const [isPasskey, isPassword] = [
|
|
3680
|
+
const [isPasskey, isPassword, isPIN] = [
|
|
3344
3681
|
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY),
|
|
3345
|
-
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) || !isPasskeySupported
|
|
3682
|
+
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) || !isPasskeySupported,
|
|
3683
|
+
signupAuthMethods.includes(import_user_management_client.AuthMethod.PIN)
|
|
3346
3684
|
];
|
|
3347
|
-
if (!isPasskey && !isPassword) {
|
|
3685
|
+
if (!isPasskey && !isPassword && !isPIN) {
|
|
3348
3686
|
throw new Error(
|
|
3349
|
-
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or
|
|
3687
|
+
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
|
|
3350
3688
|
);
|
|
3351
3689
|
}
|
|
3352
3690
|
const signupState = __spreadProps(__spreadValues({}, authState), { isPasskeySupported });
|
|
@@ -3367,6 +3705,15 @@ prepareSignUpState_fn = function(_0, _1) {
|
|
|
3367
3705
|
signupState.passwordUrl = passwordUrl;
|
|
3368
3706
|
signupState.passwordId = passwordId;
|
|
3369
3707
|
}
|
|
3708
|
+
if (isPIN) {
|
|
3709
|
+
const { url: pinUrl, credentialId: pinId } = yield this.getNewCredentialAndUrl({
|
|
3710
|
+
authMethod: "PIN",
|
|
3711
|
+
portalTheme,
|
|
3712
|
+
shorten
|
|
3713
|
+
});
|
|
3714
|
+
signupState.pinUrl = pinUrl;
|
|
3715
|
+
signupState.pinId = pinId;
|
|
3716
|
+
}
|
|
3370
3717
|
return signupState;
|
|
3371
3718
|
});
|
|
3372
3719
|
};
|