@getpara/core-sdk 2.0.0-alpha.7 → 2.0.0-alpha.70
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 +1516 -382
- package/dist/cjs/constants.js +13 -1
- package/dist/cjs/index.js +35 -3
- package/dist/cjs/shares/KeyContainer.js +3 -3
- package/dist/cjs/shares/enclave.js +266 -0
- package/dist/cjs/shares/shareDistribution.js +16 -1
- package/dist/cjs/transmission/transmissionUtils.js +4 -3
- package/dist/cjs/types/{theme.js → assets.js} +2 -2
- package/dist/cjs/types/{onRamps.js → auth.js} +12 -12
- package/dist/cjs/types/coreApi.js +23 -3
- package/dist/cjs/types/events.js +2 -0
- package/dist/cjs/types/index.js +2 -21
- package/dist/cjs/types/popup.js +1 -0
- package/dist/cjs/utils/config.js +108 -0
- package/dist/cjs/utils/formatting.js +4 -0
- package/dist/cjs/utils/index.js +5 -1
- package/dist/cjs/utils/onRamps.js +2 -3
- package/dist/cjs/utils/wallet.js +18 -0
- package/dist/cjs/{types/recovery.js → utils/window.js} +17 -13
- package/dist/esm/ParaCore.js +1525 -388
- package/dist/esm/constants.js +9 -1
- package/dist/esm/index.js +36 -5
- package/dist/esm/shares/KeyContainer.js +3 -3
- package/dist/esm/shares/enclave.js +226 -0
- package/dist/esm/shares/shareDistribution.js +16 -1
- package/dist/esm/transmission/transmissionUtils.js +4 -3
- package/dist/esm/types/auth.js +11 -0
- package/dist/esm/types/coreApi.js +21 -2
- package/dist/esm/types/events.js +2 -0
- package/dist/esm/types/index.js +1 -16
- package/dist/esm/types/popup.js +1 -0
- package/dist/esm/utils/config.js +86 -0
- package/dist/esm/utils/formatting.js +2 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/onRamps.js +2 -3
- package/dist/esm/utils/wallet.js +17 -0
- package/dist/esm/utils/window.js +16 -0
- package/dist/types/ParaCore.d.ts +142 -57
- package/dist/types/PlatformUtils.d.ts +2 -3
- package/dist/types/constants.d.ts +18 -14
- package/dist/types/index.d.ts +6 -4
- package/dist/types/shares/KeyContainer.d.ts +0 -2
- package/dist/types/shares/enclave.d.ts +81 -0
- package/dist/types/shares/shareDistribution.d.ts +4 -2
- package/dist/types/types/assets.d.ts +14 -0
- package/dist/types/types/auth.d.ts +16 -0
- package/dist/types/types/config.d.ts +11 -2
- package/dist/types/types/coreApi.d.ts +133 -37
- package/dist/types/types/events.d.ts +7 -2
- package/dist/types/types/index.d.ts +1 -4
- package/dist/types/types/methods.d.ts +94 -15
- package/dist/types/types/popup.d.ts +2 -1
- package/dist/types/types/wallet.d.ts +11 -4
- package/dist/types/utils/config.d.ts +7 -0
- package/dist/types/utils/formatting.d.ts +2 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/onRamps.d.ts +9 -10
- package/dist/types/utils/wallet.d.ts +1 -0
- package/dist/types/utils/window.d.ts +2 -0
- package/package.json +23 -23
- package/dist/esm/types/onRamps.js +0 -11
- package/dist/esm/types/recovery.js +0 -12
- package/dist/types/types/onRamps.d.ts +0 -10
- package/dist/types/types/recovery.d.ts +0 -7
- package/dist/types/types/theme.d.ts +0 -12
- /package/dist/esm/types/{theme.js → assets.js} +0 -0
package/dist/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, waitForLoginProcess_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,22 +112,20 @@ 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);
|
|
119
|
+
this.isSwitchingWallets = false;
|
|
124
120
|
this.isNativePasskey = false;
|
|
125
|
-
|
|
121
|
+
this.isReady = false;
|
|
122
|
+
this.accountLinkInProgress = void 0;
|
|
123
|
+
this.isEnclaveUser = false;
|
|
126
124
|
this.isAwaitingAccountCreation = false;
|
|
127
125
|
this.isAwaitingLogin = false;
|
|
128
126
|
this.isAwaitingFarcaster = false;
|
|
129
127
|
this.isAwaitingOAuth = false;
|
|
128
|
+
this.isWorkerInitialized = false;
|
|
130
129
|
/**
|
|
131
130
|
* 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.
|
|
132
131
|
*/
|
|
@@ -135,20 +134,34 @@ const _ParaCore = class _ParaCore {
|
|
|
135
134
|
* Wallets associated with the `ParaCore` instance.
|
|
136
135
|
*/
|
|
137
136
|
this.externalWallets = {};
|
|
137
|
+
this.onRampPopup = void 0;
|
|
138
|
+
this.nonPersistedStorageKeys = [];
|
|
138
139
|
this.localStorageGetItem = (key) => {
|
|
139
|
-
|
|
140
|
+
var _a;
|
|
141
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
142
|
+
return this.platformUtils.localStorage.get(key);
|
|
143
|
+
}
|
|
140
144
|
};
|
|
141
145
|
this.localStorageSetItem = (key, value) => {
|
|
142
|
-
|
|
146
|
+
var _a;
|
|
147
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
148
|
+
return this.platformUtils.localStorage.set(key, value);
|
|
149
|
+
}
|
|
143
150
|
};
|
|
144
151
|
this.localStorageRemoveItem = (key) => {
|
|
145
152
|
return this.platformUtils.localStorage.removeItem(key);
|
|
146
153
|
};
|
|
147
154
|
this.sessionStorageGetItem = (key) => {
|
|
148
|
-
|
|
155
|
+
var _a;
|
|
156
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
157
|
+
return this.platformUtils.sessionStorage.get(key);
|
|
158
|
+
}
|
|
149
159
|
};
|
|
150
160
|
this.sessionStorageSetItem = (key, value) => {
|
|
151
|
-
|
|
161
|
+
var _a;
|
|
162
|
+
if (!((_a = this.nonPersistedStorageKeys) != null ? _a : []).includes(key)) {
|
|
163
|
+
return this.platformUtils.sessionStorage.set(key, value);
|
|
164
|
+
}
|
|
152
165
|
};
|
|
153
166
|
this.sessionStorageRemoveItem = (key) => {
|
|
154
167
|
return this.platformUtils.sessionStorage.removeItem(key);
|
|
@@ -156,16 +169,29 @@ const _ParaCore = class _ParaCore {
|
|
|
156
169
|
this.retrieveSessionCookie = () => {
|
|
157
170
|
return this.sessionCookie;
|
|
158
171
|
};
|
|
172
|
+
this.retrieveEnclaveJwt = () => {
|
|
173
|
+
return this.enclaveJwt;
|
|
174
|
+
};
|
|
175
|
+
this.retrieveEnclaveRefreshJwt = () => {
|
|
176
|
+
return this.enclaveRefreshJwt;
|
|
177
|
+
};
|
|
159
178
|
/**
|
|
160
179
|
* Remove all local storage and prefixed session storage.
|
|
161
180
|
* @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
|
|
162
181
|
*/
|
|
163
182
|
this.clearStorage = (type = "all") => __async(this, null, function* () {
|
|
164
183
|
const isAll = type === "all";
|
|
165
|
-
(isAll || type === "local")
|
|
166
|
-
|
|
184
|
+
if (isAll || type === "local") {
|
|
185
|
+
this.platformUtils.localStorage.clear(constants.PREFIX);
|
|
186
|
+
this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
|
|
187
|
+
}
|
|
188
|
+
if (isAll || type === "session") {
|
|
189
|
+
this.platformUtils.sessionStorage.clear(constants.PREFIX);
|
|
190
|
+
this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
|
|
191
|
+
}
|
|
167
192
|
if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
|
|
168
193
|
this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
194
|
+
this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
|
|
169
195
|
}
|
|
170
196
|
});
|
|
171
197
|
this.trackError = (methodName, err) => __async(this, null, function* () {
|
|
@@ -207,6 +233,7 @@ const _ParaCore = class _ParaCore {
|
|
|
207
233
|
this.updateWalletIdsFromStorage();
|
|
208
234
|
this.updateSessionCookieFromStorage();
|
|
209
235
|
this.updateLoginEncryptionKeyPairFromStorage();
|
|
236
|
+
this.updateEnclaveJwtFromStorage();
|
|
210
237
|
};
|
|
211
238
|
this.updateAuthInfoFromStorage = () => {
|
|
212
239
|
var _a;
|
|
@@ -226,6 +253,10 @@ const _ParaCore = class _ParaCore {
|
|
|
226
253
|
}
|
|
227
254
|
__privateSet(this, _authInfo, authInfo);
|
|
228
255
|
};
|
|
256
|
+
this.updateEnclaveJwtFromStorage = () => {
|
|
257
|
+
this.enclaveJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || void 0;
|
|
258
|
+
this.enclaveRefreshJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT) || void 0;
|
|
259
|
+
};
|
|
229
260
|
this.updateUserIdFromStorage = () => {
|
|
230
261
|
this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
231
262
|
};
|
|
@@ -286,6 +317,16 @@ const _ParaCore = class _ParaCore {
|
|
|
286
317
|
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
287
318
|
this.setExternalWallets(_externalWallets);
|
|
288
319
|
};
|
|
320
|
+
this.initializeWorker = () => __async(this, null, function* () {
|
|
321
|
+
if (!this.isWorkerInitialized && !this.ctx.disableWebSockets && !this.ctx.disableWorkers && !this.isPortal()) {
|
|
322
|
+
try {
|
|
323
|
+
this.isWorkerInitialized = true;
|
|
324
|
+
yield this.platformUtils.initializeWorker(this.ctx);
|
|
325
|
+
} catch (e) {
|
|
326
|
+
this.devLog("error initializing worker:", e);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
});
|
|
289
330
|
/**
|
|
290
331
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
291
332
|
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
@@ -302,8 +343,29 @@ const _ParaCore = class _ParaCore {
|
|
|
302
343
|
}) {
|
|
303
344
|
return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
|
|
304
345
|
});
|
|
305
|
-
|
|
306
|
-
|
|
346
|
+
let env, apiKey;
|
|
347
|
+
const actualArgs = Array.from(arguments).filter((arg) => arg !== void 0);
|
|
348
|
+
const actualArgumentCount = actualArgs.length;
|
|
349
|
+
if (actualArgumentCount === 1) {
|
|
350
|
+
if (Object.values(import_types.Environment).includes(envOrApiKey)) {
|
|
351
|
+
throw new Error("A Para API key is required.");
|
|
352
|
+
}
|
|
353
|
+
env = _ParaCore.resolveEnvironment(void 0, actualArgs[0]);
|
|
354
|
+
apiKey = actualArgs[0];
|
|
355
|
+
opts = void 0;
|
|
356
|
+
} else if (actualArgumentCount === 2) {
|
|
357
|
+
if (typeof apiKeyOrOpts === "object" && apiKeyOrOpts !== null) {
|
|
358
|
+
env = _ParaCore.resolveEnvironment(void 0, envOrApiKey);
|
|
359
|
+
apiKey = envOrApiKey;
|
|
360
|
+
opts = apiKeyOrOpts;
|
|
361
|
+
} else {
|
|
362
|
+
env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
|
|
363
|
+
apiKey = apiKeyOrOpts;
|
|
364
|
+
opts = void 0;
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
env = _ParaCore.resolveEnvironment(envOrApiKey, apiKeyOrOpts);
|
|
368
|
+
apiKey = apiKeyOrOpts;
|
|
307
369
|
}
|
|
308
370
|
if (!opts) opts = {};
|
|
309
371
|
let isE2E = false;
|
|
@@ -326,6 +388,7 @@ const _ParaCore = class _ParaCore {
|
|
|
326
388
|
this.portalTheme = opts.portalTheme;
|
|
327
389
|
this.platformUtils = this.getPlatformUtils();
|
|
328
390
|
this.disableProviderModal = this.platformUtils.disableProviderModal;
|
|
391
|
+
this.fetchPregenWalletsOverride = opts.fetchPregenWalletsOverride;
|
|
329
392
|
if (opts.useStorageOverrides) {
|
|
330
393
|
this.localStorageGetItem = opts.localStorageGetItemOverride;
|
|
331
394
|
this.localStorageSetItem = opts.localStorageSetItemOverride;
|
|
@@ -345,18 +408,41 @@ const _ParaCore = class _ParaCore {
|
|
|
345
408
|
cookie
|
|
346
409
|
);
|
|
347
410
|
};
|
|
411
|
+
this.persistEnclaveJwt = (jwt) => {
|
|
412
|
+
this.enclaveJwt = jwt;
|
|
413
|
+
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
|
|
414
|
+
constants.LOCAL_STORAGE_ENCLAVE_JWT,
|
|
415
|
+
jwt
|
|
416
|
+
);
|
|
417
|
+
};
|
|
418
|
+
this.persistEnclaveRefreshJwt = (refreshJwt) => {
|
|
419
|
+
this.enclaveRefreshJwt = refreshJwt;
|
|
420
|
+
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
|
|
421
|
+
constants.LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
|
|
422
|
+
refreshJwt
|
|
423
|
+
);
|
|
424
|
+
};
|
|
425
|
+
const client = (0, import_userManagementClient.initClient)({
|
|
426
|
+
env,
|
|
427
|
+
version: _ParaCore.version,
|
|
428
|
+
apiKey,
|
|
429
|
+
partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
|
|
430
|
+
useFetchAdapter: !!opts.disableWorkers,
|
|
431
|
+
retrieveSessionCookie: this.retrieveSessionCookie,
|
|
432
|
+
persistSessionCookie: this.persistSessionCookie
|
|
433
|
+
});
|
|
434
|
+
const enclaveClient = new import_enclave.EnclaveClient({
|
|
435
|
+
userManagementClient: client,
|
|
436
|
+
retrieveJwt: this.retrieveEnclaveJwt,
|
|
437
|
+
persistJwt: this.persistEnclaveJwt,
|
|
438
|
+
retrieveRefreshJwt: this.retrieveEnclaveRefreshJwt,
|
|
439
|
+
persistRefreshJwt: this.persistEnclaveRefreshJwt
|
|
440
|
+
});
|
|
348
441
|
this.ctx = {
|
|
349
442
|
env,
|
|
350
443
|
apiKey,
|
|
351
|
-
client
|
|
352
|
-
|
|
353
|
-
version: _ParaCore.version,
|
|
354
|
-
apiKey,
|
|
355
|
-
partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
|
|
356
|
-
useFetchAdapter: !!opts.disableWorkers,
|
|
357
|
-
retrieveSessionCookie: this.retrieveSessionCookie,
|
|
358
|
-
persistSessionCookie: this.persistSessionCookie
|
|
359
|
-
}),
|
|
444
|
+
client,
|
|
445
|
+
enclaveClient,
|
|
360
446
|
disableWorkers: opts.disableWorkers,
|
|
361
447
|
offloadMPCComputationURL: opts.offloadMPCComputationURL,
|
|
362
448
|
useLocalFiles: opts.useLocalFiles,
|
|
@@ -391,6 +477,9 @@ const _ParaCore = class _ParaCore {
|
|
|
391
477
|
]);
|
|
392
478
|
}
|
|
393
479
|
}
|
|
480
|
+
setModalError(_error) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
394
483
|
get authInfo() {
|
|
395
484
|
return __privateGet(this, _authInfo);
|
|
396
485
|
}
|
|
@@ -417,8 +506,15 @@ const _ParaCore = class _ParaCore {
|
|
|
417
506
|
get externalWalletConnectionType() {
|
|
418
507
|
if (this.isExternalWalletAuth) {
|
|
419
508
|
return "AUTHENTICATED";
|
|
509
|
+
} else if (this.isExternalWalletWithVerification) {
|
|
510
|
+
return "VERIFICATION";
|
|
420
511
|
} else if (!!Object.keys(this.externalWallets).length) {
|
|
421
|
-
|
|
512
|
+
const hasEmbeddedWallets = Object.keys(this.wallets).some((id) => !this.wallets[id].isExternal);
|
|
513
|
+
if (hasEmbeddedWallets) {
|
|
514
|
+
return "NONE";
|
|
515
|
+
} else {
|
|
516
|
+
return "CONNECTION_ONLY";
|
|
517
|
+
}
|
|
422
518
|
}
|
|
423
519
|
return "NONE";
|
|
424
520
|
}
|
|
@@ -439,16 +535,28 @@ const _ParaCore = class _ParaCore {
|
|
|
439
535
|
return (0, import_user_management_client.isTelegram)((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
440
536
|
}
|
|
441
537
|
get isExternalWalletAuth() {
|
|
442
|
-
var _a;
|
|
443
|
-
return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
|
|
538
|
+
var _a, _b, _c;
|
|
539
|
+
return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) && !!((_c = (_b = __privateGet(this, _authInfo)) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.withFullParaAuth);
|
|
540
|
+
}
|
|
541
|
+
get isExternalWalletWithVerification() {
|
|
542
|
+
var _a, _b, _c;
|
|
543
|
+
return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) && !!((_c = (_b = __privateGet(this, _authInfo)) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.withVerification);
|
|
444
544
|
}
|
|
445
545
|
get partnerId() {
|
|
446
546
|
var _a;
|
|
447
|
-
return (_a =
|
|
547
|
+
return (_a = this.partner) == null ? void 0 : _a.id;
|
|
548
|
+
}
|
|
549
|
+
get partnerName() {
|
|
550
|
+
var _a;
|
|
551
|
+
return (_a = this.partner) == null ? void 0 : _a.displayName;
|
|
552
|
+
}
|
|
553
|
+
get partnerLogo() {
|
|
554
|
+
var _a;
|
|
555
|
+
return (_a = this.partner) == null ? void 0 : _a.logoUrl;
|
|
448
556
|
}
|
|
449
557
|
get currentWalletIdsArray() {
|
|
450
558
|
var _a, _b;
|
|
451
|
-
return ((_b = (_a =
|
|
559
|
+
return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
452
560
|
(acc, { type }) => {
|
|
453
561
|
var _a2;
|
|
454
562
|
return [
|
|
@@ -488,19 +596,23 @@ const _ParaCore = class _ParaCore {
|
|
|
488
596
|
}
|
|
489
597
|
get isNoWalletConfig() {
|
|
490
598
|
var _a;
|
|
491
|
-
return !!((_a =
|
|
599
|
+
return !!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) && this.partner.supportedWalletTypes.length === 0;
|
|
492
600
|
}
|
|
493
601
|
get supportedWalletTypes() {
|
|
494
602
|
var _a, _b;
|
|
495
|
-
return (_b = (_a =
|
|
603
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
496
604
|
}
|
|
497
605
|
get cosmosPrefix() {
|
|
498
606
|
var _a;
|
|
499
|
-
return (_a =
|
|
607
|
+
return (_a = this.partner) == null ? void 0 : _a.cosmosPrefix;
|
|
608
|
+
}
|
|
609
|
+
get supportedAccountLinks() {
|
|
610
|
+
var _a, _b;
|
|
611
|
+
return (_b = (_a = this.partner) == null ? void 0 : _a.supportedAccountLinks) != null ? _b : [...import_user_management_client.LINKED_ACCOUNT_TYPES];
|
|
500
612
|
}
|
|
501
613
|
get isWalletTypeEnabled() {
|
|
502
614
|
var _a;
|
|
503
|
-
return (((_a =
|
|
615
|
+
return (((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
504
616
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
505
617
|
}, {});
|
|
506
618
|
}
|
|
@@ -530,9 +642,7 @@ const _ParaCore = class _ParaCore {
|
|
|
530
642
|
};
|
|
531
643
|
}
|
|
532
644
|
isPortal(envOverride) {
|
|
533
|
-
|
|
534
|
-
if (typeof window === "undefined") return false;
|
|
535
|
-
return !!((_a = window.location) == null ? void 0 : _a.host) && (0, import_utils2.getPortalBaseURL)(envOverride ? { env: envOverride } : this.ctx).includes(window.location.host);
|
|
645
|
+
return (0, import_utils2.isPortal)(this.ctx, envOverride);
|
|
536
646
|
}
|
|
537
647
|
isParaConnect() {
|
|
538
648
|
var _a;
|
|
@@ -549,7 +659,7 @@ const _ParaCore = class _ParaCore {
|
|
|
549
659
|
}
|
|
550
660
|
isWalletSupported(wallet) {
|
|
551
661
|
var _a, _b;
|
|
552
|
-
return !((_a =
|
|
662
|
+
return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || (0, import_utils2.isWalletSupported)((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
553
663
|
}
|
|
554
664
|
isWalletOwned(wallet) {
|
|
555
665
|
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;
|
|
@@ -575,12 +685,12 @@ const _ParaCore = class _ParaCore {
|
|
|
575
685
|
} else {
|
|
576
686
|
const wallet = this.wallets[walletId];
|
|
577
687
|
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
578
|
-
if (forbidPregen && isUnclaimed) {
|
|
688
|
+
if (forbidPregen && isUnclaimed && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
579
689
|
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
580
690
|
} else if (!isOwned && !isUnclaimed) {
|
|
581
691
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
582
692
|
} else if (!this.isWalletSupported(wallet)) {
|
|
583
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b =
|
|
693
|
+
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(", ")}`;
|
|
584
694
|
} else if (types && (!(0, import_utils2.getEquivalentTypes)(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
585
695
|
var _a2, _b2;
|
|
586
696
|
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
@@ -598,6 +708,9 @@ const _ParaCore = class _ParaCore {
|
|
|
598
708
|
}
|
|
599
709
|
return true;
|
|
600
710
|
}
|
|
711
|
+
truncateAddress(...args) {
|
|
712
|
+
return (0, import_utils2.truncateAddress)(args[0], args[1], __spreadValues({ prefix: this.cosmosPrefix }, args[2] || {}));
|
|
713
|
+
}
|
|
601
714
|
/**
|
|
602
715
|
* Returns the formatted address for the desired wallet ID, depending on your app settings.
|
|
603
716
|
* @param {string} walletId the ID of the wallet address to display.
|
|
@@ -611,7 +724,7 @@ const _ParaCore = class _ParaCore {
|
|
|
611
724
|
if (this.externalWallets[walletId]) {
|
|
612
725
|
const wallet2 = this.externalWallets[walletId];
|
|
613
726
|
return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, {
|
|
614
|
-
prefix: (_a =
|
|
727
|
+
prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
|
|
615
728
|
targetLength: options.targetLength
|
|
616
729
|
}) : wallet2.address;
|
|
617
730
|
}
|
|
@@ -623,7 +736,7 @@ const _ParaCore = class _ParaCore {
|
|
|
623
736
|
let prefix;
|
|
624
737
|
switch (wallet.type) {
|
|
625
738
|
case "COSMOS":
|
|
626
|
-
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b =
|
|
739
|
+
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
627
740
|
str = (0, import_utils2.getCosmosAddress)(wallet.publicKey, prefix);
|
|
628
741
|
break;
|
|
629
742
|
default:
|
|
@@ -656,30 +769,55 @@ const _ParaCore = class _ParaCore {
|
|
|
656
769
|
}
|
|
657
770
|
constructPortalUrl(_0) {
|
|
658
771
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
659
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
660
|
-
const [
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
772
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
773
|
+
const [
|
|
774
|
+
isCreate,
|
|
775
|
+
isLogin,
|
|
776
|
+
isOnRamp,
|
|
777
|
+
isOAuth,
|
|
778
|
+
isOAuthCallback,
|
|
779
|
+
isTelegramLogin,
|
|
780
|
+
isFarcasterLogin,
|
|
781
|
+
isAddNewCredential,
|
|
782
|
+
isSwitchWallets,
|
|
783
|
+
isExportPrivateKey
|
|
784
|
+
] = [
|
|
785
|
+
["createAuth", "createPassword", "createPIN"].includes(type),
|
|
786
|
+
["loginAuth", "loginPassword", "loginPIN", "loginOTP", "switchWallets", "loginExternalWallet"].includes(type),
|
|
787
|
+
type === "onRamp",
|
|
788
|
+
type === "oAuth",
|
|
789
|
+
type === "oAuthCallback",
|
|
790
|
+
["telegramLogin", "telegramLoginVerify"].includes(type),
|
|
791
|
+
type === "loginFarcaster",
|
|
792
|
+
type === "addNewCredential",
|
|
793
|
+
type === "switchWallets",
|
|
794
|
+
type === "exportPrivateKey"
|
|
664
795
|
];
|
|
796
|
+
if (isOAuth && !opts.oAuthMethod) {
|
|
797
|
+
throw new Error("oAuthMethod is required for oAuth portal URLs");
|
|
798
|
+
}
|
|
665
799
|
if (isCreate || isLogin) {
|
|
666
800
|
this.assertIsAuthSet();
|
|
667
801
|
}
|
|
668
802
|
let sessionId = opts.sessionId;
|
|
669
|
-
if ((isLogin || isOnRamp) && !sessionId) {
|
|
803
|
+
if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin || isExportPrivateKey) && !sessionId) {
|
|
670
804
|
const session = yield this.touchSession(true);
|
|
671
805
|
sessionId = session.sessionId;
|
|
672
806
|
}
|
|
673
807
|
if (!this.loginEncryptionKeyPair) {
|
|
674
808
|
yield this.setLoginEncryptionKeyPair();
|
|
675
809
|
}
|
|
676
|
-
const base = type === "onRamp" ? (0, import_utils2.getPortalBaseURL)(this.ctx) : yield this.getPortalURL();
|
|
810
|
+
const base = type === "onRamp" || isTelegramLogin ? (0, import_utils2.getPortalBaseURL)(this.ctx, isTelegramLogin) : yield this.getPortalURL();
|
|
677
811
|
let path;
|
|
678
812
|
switch (type) {
|
|
679
813
|
case "createPassword": {
|
|
680
814
|
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
681
815
|
break;
|
|
682
816
|
}
|
|
817
|
+
case "createPIN": {
|
|
818
|
+
path = `/web/users/${this.userId}/pin/${opts.pathId}`;
|
|
819
|
+
break;
|
|
820
|
+
}
|
|
683
821
|
case "createAuth": {
|
|
684
822
|
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
685
823
|
break;
|
|
@@ -692,42 +830,102 @@ const _ParaCore = class _ParaCore {
|
|
|
692
830
|
path = "/web/biometrics/login";
|
|
693
831
|
break;
|
|
694
832
|
}
|
|
833
|
+
case "loginPIN": {
|
|
834
|
+
path = "/web/pin/login";
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
695
837
|
case "txReview": {
|
|
696
838
|
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
697
839
|
break;
|
|
698
840
|
}
|
|
699
841
|
case "onRamp": {
|
|
700
|
-
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
842
|
+
path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
case "telegramLoginVerify": {
|
|
846
|
+
path = `/auth/telegram/verify`;
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
case "telegramLogin": {
|
|
850
|
+
path = `/auth/telegram`;
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
853
|
+
case "oAuth": {
|
|
854
|
+
path = `/auth/${opts.oAuthMethod.toLowerCase()}`;
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
case "oAuthCallback": {
|
|
858
|
+
path = `/auth/${opts.oAuthMethod.toLowerCase()}/callback`;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
case "loginOTP": {
|
|
862
|
+
path = "/auth/otp";
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
case "loginFarcaster": {
|
|
866
|
+
path = "/auth/farcaster";
|
|
867
|
+
break;
|
|
868
|
+
}
|
|
869
|
+
case "switchWallets": {
|
|
870
|
+
path = `/auth/wallets`;
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
case "addNewCredential": {
|
|
874
|
+
path = "/auth/add-new-credential";
|
|
875
|
+
break;
|
|
876
|
+
}
|
|
877
|
+
case "exportPrivateKey": {
|
|
878
|
+
path = `/web/users/${this.userId}/private-key/${opts.pathId}`;
|
|
879
|
+
break;
|
|
880
|
+
}
|
|
881
|
+
case "loginExternalWallet": {
|
|
882
|
+
path = "/auth/external-wallet";
|
|
883
|
+
break;
|
|
884
|
+
}
|
|
885
|
+
case "connectExternalWallet": {
|
|
886
|
+
path = "/auth/connect-external-wallet";
|
|
701
887
|
break;
|
|
702
888
|
}
|
|
703
889
|
default: {
|
|
704
890
|
throw new Error(`invalid URL type ${type}`);
|
|
705
891
|
}
|
|
706
892
|
}
|
|
707
|
-
|
|
893
|
+
let partner = void 0;
|
|
894
|
+
try {
|
|
895
|
+
partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
896
|
+
} catch (e) {
|
|
897
|
+
if (this.isPartnerOptional) {
|
|
898
|
+
partner = void 0;
|
|
899
|
+
} else {
|
|
900
|
+
throw e;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
708
903
|
const thisDevice = (_a = opts.thisDevice) != null ? _a : {
|
|
709
904
|
encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
|
|
710
905
|
sessionId
|
|
711
906
|
};
|
|
712
|
-
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
907
|
+
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({
|
|
713
908
|
apiKey: this.ctx.apiKey,
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
909
|
+
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
910
|
+
partnerId: partner == null ? void 0 : partner.id
|
|
911
|
+
}, typeof window !== "undefined" && ((_b = window.location) == null ? void 0 : _b.origin) ? { origin: window.location.origin } : {}), {
|
|
912
|
+
portalFont: ((_c = opts.portalTheme) == null ? void 0 : _c.font) || ((_d = this.portalTheme) == null ? void 0 : _d.font) || (partner == null ? void 0 : partner.font),
|
|
913
|
+
portalBorderRadius: ((_e = opts.portalTheme) == null ? void 0 : _e.borderRadius) || ((_f = this.portalTheme) == null ? void 0 : _f.borderRadius),
|
|
914
|
+
portalThemeMode: ((_g = opts.portalTheme) == null ? void 0 : _g.mode) || ((_h = this.portalTheme) == null ? void 0 : _h.mode) || (partner == null ? void 0 : partner.themeMode),
|
|
915
|
+
portalAccentColor: ((_i = opts.portalTheme) == null ? void 0 : _i.accentColor) || ((_j = this.portalTheme) == null ? void 0 : _j.accentColor) || (partner == null ? void 0 : partner.accentColor),
|
|
916
|
+
portalForegroundColor: ((_k = opts.portalTheme) == null ? void 0 : _k.foregroundColor) || ((_l = this.portalTheme) == null ? void 0 : _l.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor),
|
|
917
|
+
portalBackgroundColor: ((_m = opts.portalTheme) == null ? void 0 : _m.backgroundColor) || ((_n = this.portalTheme) == null ? void 0 : _n.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor,
|
|
721
918
|
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
722
919
|
portalTextColor: this.portalTextColor,
|
|
723
920
|
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
724
921
|
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
725
|
-
}, isCreate || isLogin ? __spreadProps(__spreadValues({
|
|
922
|
+
}), this.authInfo && (isCreate || isLogin || isAddNewCredential || isOAuthCallback || isSwitchWallets || isExportPrivateKey) ? __spreadProps(__spreadValues({
|
|
726
923
|
authInfo: JSON.stringify(this.authInfo)
|
|
727
924
|
}, (0, import_user_management_client.isPhone)(this.authInfo.auth) ? (0, import_utils2.splitPhoneNumber)(this.authInfo.auth.phone) : this.authInfo.auth), {
|
|
728
925
|
pfpUrl: this.authInfo.pfpUrl,
|
|
729
|
-
displayName: this.authInfo.displayName
|
|
730
|
-
|
|
926
|
+
displayName: this.authInfo.displayName,
|
|
927
|
+
userId: this.userId
|
|
928
|
+
}) : {}), isOnRamp ? { email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin || isAddNewCredential ? __spreadProps(__spreadValues({
|
|
731
929
|
sessionId: thisDevice.sessionId,
|
|
732
930
|
encryptionKey: thisDevice.encryptionKey
|
|
733
931
|
}, opts.newDevice ? {
|
|
@@ -735,7 +933,17 @@ const _ParaCore = class _ParaCore {
|
|
|
735
933
|
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
736
934
|
} : {}), {
|
|
737
935
|
pregenIds: JSON.stringify(this.pregenIds)
|
|
738
|
-
}) : {}),
|
|
936
|
+
}) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
|
|
937
|
+
appScheme: opts.appScheme
|
|
938
|
+
} : {}), isTelegramLogin ? { isEmbed: "true" } : {}), isSwitchWallets ? __spreadValues(__spreadValues({}, this.currentWalletIds ? { currentWalletIds: JSON.stringify(this.currentWalletIds) } : {}), this.userId ? { userId: this.userId } : {}) : {}), opts.params || {}), isAddNewCredential ? __spreadProps(__spreadValues({}, opts.addNewCredentialType && { addNewCredentialType: opts.addNewCredentialType.toString() }), {
|
|
939
|
+
addNewCredentialPasskeyId: opts.addNewCredentialPasskeyId,
|
|
940
|
+
addNewCredentialPasswordId: opts.addNewCredentialPasswordId
|
|
941
|
+
}) : {}), isLogin && {
|
|
942
|
+
// Prior versions won't have this param which will skip the upgrade prompt
|
|
943
|
+
isBasicLoginUpgradeVersion: "true"
|
|
944
|
+
}), isExportPrivateKey ? {
|
|
945
|
+
sessionId: thisDevice.sessionId
|
|
946
|
+
} : {});
|
|
739
947
|
const url = (0, import_utils2.constructUrl)({ base, path, params });
|
|
740
948
|
if (opts.shorten) {
|
|
741
949
|
return (0, import_utils2.shortenUrl)(this.ctx, url);
|
|
@@ -743,12 +951,75 @@ const _ParaCore = class _ParaCore {
|
|
|
743
951
|
return url;
|
|
744
952
|
});
|
|
745
953
|
}
|
|
954
|
+
static resolveEnvironment(env, apiKey) {
|
|
955
|
+
var _a;
|
|
956
|
+
if (!apiKey) {
|
|
957
|
+
throw new Error("A Para API key is required.");
|
|
958
|
+
}
|
|
959
|
+
if (apiKey.includes("_")) {
|
|
960
|
+
const validEnvironmentPrefixes = Object.values(import_types.Environment);
|
|
961
|
+
const envPrefix = (_a = apiKey.split("_")[0]) == null ? void 0 : _a.toUpperCase();
|
|
962
|
+
const hasValidPrefix = validEnvironmentPrefixes.some((envValue) => envValue === envPrefix);
|
|
963
|
+
if (!hasValidPrefix) {
|
|
964
|
+
throw new Error(`Invalid API key environment prefix.`);
|
|
965
|
+
}
|
|
966
|
+
return envPrefix;
|
|
967
|
+
}
|
|
968
|
+
if (!env) {
|
|
969
|
+
throw new Error("Environment parameter is required.");
|
|
970
|
+
}
|
|
971
|
+
return env;
|
|
972
|
+
}
|
|
746
973
|
touchSession(regenerate = false) {
|
|
747
974
|
return __async(this, null, function* () {
|
|
748
|
-
var _a, _b, _c;
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
975
|
+
var _a, _b, _c, _d, _e;
|
|
976
|
+
if (!this.isWorkerInitialized) {
|
|
977
|
+
this.initializeWorker();
|
|
978
|
+
}
|
|
979
|
+
if (!this.isReady) {
|
|
980
|
+
yield this.ready();
|
|
981
|
+
}
|
|
982
|
+
let session;
|
|
983
|
+
try {
|
|
984
|
+
session = yield this.ctx.client.touchSession(regenerate);
|
|
985
|
+
} catch (error) {
|
|
986
|
+
this.handleTouchSessionError(error);
|
|
987
|
+
throw error;
|
|
988
|
+
}
|
|
989
|
+
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) {
|
|
990
|
+
if (!session.partnerId && !this.isPortal()) {
|
|
991
|
+
this.displayModalError(
|
|
992
|
+
`Invalid API Key. Please ensure you have a valid API key for the current environment: ${(_d = this.ctx.env) == null ? void 0 : _d.toUpperCase()}.`
|
|
993
|
+
);
|
|
994
|
+
console.error(`
|
|
995
|
+
\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
996
|
+
\u{1F6A8} PARA SDK CONFIGURATION ERROR \u{1F6A8}
|
|
997
|
+
|
|
998
|
+
INVALID API KEY FOR CONFIGURED ENVIRONMENT
|
|
999
|
+
|
|
1000
|
+
Your API key does not match the configured environment. This usually means:
|
|
1001
|
+
|
|
1002
|
+
1. You're using a production API key with a development environment
|
|
1003
|
+
2. You're using a development API key with a production environment
|
|
1004
|
+
3. Your API key is invalid or has been regenerated
|
|
1005
|
+
|
|
1006
|
+
SOLUTION:
|
|
1007
|
+
\u2022 Verify your API key at: https://developer.getpara.com
|
|
1008
|
+
\u2022 If your API key doesn't contain an environment prefix, ensure your API key is the correct key for your target environment
|
|
1009
|
+
|
|
1010
|
+
Current Environment: ${this.ctx.env}
|
|
1011
|
+
API Key Prefix: ${((_e = this.ctx.apiKey) == null ? void 0 : _e.split("_")[0].toUpperCase()) || "None"}
|
|
1012
|
+
|
|
1013
|
+
Need help? Visit: https://docs.getpara.com or contact support
|
|
1014
|
+
\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
1015
|
+
`);
|
|
1016
|
+
throw new Error("Invalid API Key.");
|
|
1017
|
+
} else {
|
|
1018
|
+
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (session.currentWalletIds && !(0, import_utils2.currentWalletIdsEq)(session.currentWalletIds, this.currentWalletIds)) {
|
|
1022
|
+
yield this.setCurrentWalletIds(session.currentWalletIds);
|
|
752
1023
|
}
|
|
753
1024
|
return session;
|
|
754
1025
|
});
|
|
@@ -847,8 +1118,35 @@ const _ParaCore = class _ParaCore {
|
|
|
847
1118
|
return __privateGet(this, _authInfo);
|
|
848
1119
|
});
|
|
849
1120
|
}
|
|
850
|
-
|
|
851
|
-
|
|
1121
|
+
/**
|
|
1122
|
+
* Display an error message in the modal (if available)
|
|
1123
|
+
* @internal
|
|
1124
|
+
*/
|
|
1125
|
+
displayModalError(error) {
|
|
1126
|
+
if (this.ctx.env !== import_types.Environment.PROD) {
|
|
1127
|
+
this.setModalError(error);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Handle specific touchSession errors with user-friendly messages
|
|
1132
|
+
* @private
|
|
1133
|
+
*/
|
|
1134
|
+
handleTouchSessionError(error) {
|
|
1135
|
+
const errorStr = String(error);
|
|
1136
|
+
const errorMessage = error instanceof Error ? error.message : "";
|
|
1137
|
+
if (errorStr.includes("blocked by CORS policy") && errorStr.includes("Access-Control-Allow-Origin")) {
|
|
1138
|
+
this.displayModalError("Request rate limit reached. Please wait a couple of minutes and try again.");
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
if (error.status === 403 && errorMessage.includes("origin not authorized")) {
|
|
1142
|
+
this.displayModalError(
|
|
1143
|
+
"The current origin is not allowed. Update your allowed origins in the Para developer portal to allow the current origin."
|
|
1144
|
+
);
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
assertUserId({ allowGuestMode = false } = {}) {
|
|
1149
|
+
if (!this.userId || !allowGuestMode && this.isGuestMode) {
|
|
852
1150
|
throw new Error("no userId is set");
|
|
853
1151
|
}
|
|
854
1152
|
return this.userId;
|
|
@@ -904,19 +1202,75 @@ const _ParaCore = class _ParaCore {
|
|
|
904
1202
|
* @param externalAddress - External wallet address to set.
|
|
905
1203
|
* @param externalType - Type of external wallet to set.
|
|
906
1204
|
*/
|
|
907
|
-
setExternalWallet(
|
|
908
|
-
return __async(this,
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
1205
|
+
setExternalWallet(externalWallet) {
|
|
1206
|
+
return __async(this, null, function* () {
|
|
1207
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1208
|
+
this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
|
|
1209
|
+
(acc, {
|
|
1210
|
+
partnerId: wPartnerId,
|
|
1211
|
+
address,
|
|
913
1212
|
type,
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1213
|
+
provider,
|
|
1214
|
+
providerId,
|
|
1215
|
+
addressBech32,
|
|
1216
|
+
withFullParaAuth,
|
|
1217
|
+
isConnectionOnly,
|
|
1218
|
+
withVerification
|
|
1219
|
+
}) => {
|
|
1220
|
+
if (partnerId === wPartnerId && supportedWalletTypes.some(({ type: supportedType }) => supportedType === type)) {
|
|
1221
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1222
|
+
[address]: {
|
|
1223
|
+
id: address,
|
|
1224
|
+
partnerId,
|
|
1225
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
1226
|
+
type,
|
|
1227
|
+
name: provider,
|
|
1228
|
+
isExternal: true,
|
|
1229
|
+
isExternalWithParaAuth: withFullParaAuth,
|
|
1230
|
+
externalProviderId: providerId,
|
|
1231
|
+
signer: "",
|
|
1232
|
+
isExternalConnectionOnly: isConnectionOnly,
|
|
1233
|
+
isExternalWithVerification: withVerification
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
return acc;
|
|
1238
|
+
},
|
|
1239
|
+
{}
|
|
1240
|
+
), this.setExternalWallets(this.externalWallets);
|
|
1241
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
addExternalWallets(externalWallets) {
|
|
1245
|
+
return __async(this, null, function* () {
|
|
1246
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1247
|
+
this.externalWallets = __spreadValues(__spreadValues({}, Object.entries(this.externalWallets).reduce((acc, [address, wallet]) => {
|
|
1248
|
+
if (partnerId === wallet.partnerId && supportedWalletTypes.some(({ type }) => type === wallet.type)) {
|
|
1249
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1250
|
+
[address]: wallet
|
|
1251
|
+
});
|
|
918
1252
|
}
|
|
919
|
-
|
|
1253
|
+
return acc;
|
|
1254
|
+
}, {})), externalWallets.reduce(
|
|
1255
|
+
(acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
|
|
1256
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1257
|
+
[address]: {
|
|
1258
|
+
id: address,
|
|
1259
|
+
partnerId,
|
|
1260
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
1261
|
+
type,
|
|
1262
|
+
name: provider,
|
|
1263
|
+
isExternal: true,
|
|
1264
|
+
isExternalWithParaAuth: withFullParaAuth,
|
|
1265
|
+
externalProviderId: providerId,
|
|
1266
|
+
signer: "",
|
|
1267
|
+
isExternalConnectionOnly: isConnectionOnly,
|
|
1268
|
+
isExternalWithVerification: withVerification
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1271
|
+
},
|
|
1272
|
+
{}
|
|
1273
|
+
));
|
|
920
1274
|
this.setExternalWallets(this.externalWallets);
|
|
921
1275
|
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
922
1276
|
});
|
|
@@ -947,12 +1301,16 @@ const _ParaCore = class _ParaCore {
|
|
|
947
1301
|
}
|
|
948
1302
|
/**
|
|
949
1303
|
* Sets the external wallets associated with the `ParaCore` instance.
|
|
950
|
-
* @param externalWallets - External wallets to set.
|
|
1304
|
+
* @param externalWallets - External wallets to set, or a function that modifies the current wallets.
|
|
951
1305
|
*/
|
|
952
1306
|
setExternalWallets(externalWallets) {
|
|
953
1307
|
return __async(this, null, function* () {
|
|
954
|
-
|
|
955
|
-
|
|
1308
|
+
if (typeof externalWallets === "function") {
|
|
1309
|
+
this.externalWallets = externalWallets(this.externalWallets);
|
|
1310
|
+
} else {
|
|
1311
|
+
this.externalWallets = externalWallets;
|
|
1312
|
+
}
|
|
1313
|
+
yield this.localStorageSetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS, JSON.stringify(this.externalWallets));
|
|
956
1314
|
});
|
|
957
1315
|
}
|
|
958
1316
|
/**
|
|
@@ -1028,6 +1386,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1028
1386
|
/**
|
|
1029
1387
|
* Fetches the most recent OAuth account metadata for the signed-in user.
|
|
1030
1388
|
* If applicable, this will include the user's most recent metadata from their Google, Apple, Facebook, X, Discord, Farcaster, or Telegram account, the last time they signed in to your app.
|
|
1389
|
+
* @deprecated use `para.getLinkedAccounts({ withMetadata: true })` instead.
|
|
1031
1390
|
* @returns {Promise<AccountMetadata>} the user's account metadata.
|
|
1032
1391
|
*/
|
|
1033
1392
|
getAccountMetadata() {
|
|
@@ -1120,14 +1479,27 @@ const _ParaCore = class _ParaCore {
|
|
|
1120
1479
|
...[...this.currentWalletIdsArray, ...__privateGet(this, _ParaCore_instances, guestWalletIdsArray_get)].map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1121
1480
|
const wallet = this.findWallet(id, type);
|
|
1122
1481
|
if (!wallet) return null;
|
|
1482
|
+
const name = wallet.name;
|
|
1483
|
+
const address = this.getDisplayAddress(id, { addressType: type });
|
|
1484
|
+
const addressShort = this.getDisplayAddress(id, { addressType: type, truncate: true });
|
|
1123
1485
|
return {
|
|
1124
1486
|
id: wallet.id,
|
|
1487
|
+
partner: wallet.partner,
|
|
1125
1488
|
type,
|
|
1126
|
-
address
|
|
1127
|
-
name
|
|
1489
|
+
address,
|
|
1490
|
+
name,
|
|
1491
|
+
addressShort,
|
|
1492
|
+
displayName: name != null ? name : addressShort,
|
|
1493
|
+
ensName: wallet.ensName,
|
|
1494
|
+
ensAvatar: wallet.ensAvatar
|
|
1128
1495
|
};
|
|
1129
1496
|
}).filter((obj) => obj !== null),
|
|
1130
|
-
...Object.values((_a = this.externalWallets) != null ? _a : {})
|
|
1497
|
+
...Object.values((_a = this.externalWallets) != null ? _a : {}).map((wallet) => {
|
|
1498
|
+
return __spreadProps(__spreadValues({}, wallet), {
|
|
1499
|
+
addressShort: (0, import_utils2.truncateAddress)(wallet.address, wallet.type, { prefix: this.cosmosPrefix }),
|
|
1500
|
+
displayName: wallet.externalProviderId
|
|
1501
|
+
});
|
|
1502
|
+
})
|
|
1131
1503
|
];
|
|
1132
1504
|
}
|
|
1133
1505
|
/**
|
|
@@ -1173,8 +1545,15 @@ const _ParaCore = class _ParaCore {
|
|
|
1173
1545
|
}
|
|
1174
1546
|
getPartnerURL() {
|
|
1175
1547
|
return __async(this, null, function* () {
|
|
1176
|
-
|
|
1177
|
-
|
|
1548
|
+
try {
|
|
1549
|
+
const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1550
|
+
return portalUrl;
|
|
1551
|
+
} catch (e) {
|
|
1552
|
+
if (this.isPartnerOptional) {
|
|
1553
|
+
return void 0;
|
|
1554
|
+
}
|
|
1555
|
+
throw e;
|
|
1556
|
+
}
|
|
1178
1557
|
});
|
|
1179
1558
|
}
|
|
1180
1559
|
/**
|
|
@@ -1219,13 +1598,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1219
1598
|
return __async(this, null, function* () {
|
|
1220
1599
|
const res = yield this.isPortal() || this.isParaConnect() ? this.ctx.client.getAllWallets(this.userId) : this.ctx.client.getWallets(this.userId, true);
|
|
1221
1600
|
return res.data.wallets.filter(
|
|
1222
|
-
(wallet) => !!wallet.address && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported((0, import_utils2.entityToWallet)(wallet)))
|
|
1601
|
+
(wallet) => !!wallet.address && wallet.sharesPersisted && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported((0, import_utils2.entityToWallet)(wallet)))
|
|
1223
1602
|
);
|
|
1224
1603
|
});
|
|
1225
1604
|
}
|
|
1226
1605
|
populateWalletAddresses() {
|
|
1227
1606
|
return __async(this, null, function* () {
|
|
1228
|
-
const res = yield this.ctx.client.getWallets(this.userId, true);
|
|
1607
|
+
const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId, true);
|
|
1229
1608
|
const wallets = res.data.wallets;
|
|
1230
1609
|
wallets.forEach((entity) => {
|
|
1231
1610
|
if (this.wallets[entity.id]) {
|
|
@@ -1256,65 +1635,143 @@ const _ParaCore = class _ParaCore {
|
|
|
1256
1635
|
loginExternalWallet(_a) {
|
|
1257
1636
|
return __async(this, null, function* () {
|
|
1258
1637
|
var _b = _a, {
|
|
1259
|
-
externalWallet
|
|
1638
|
+
externalWallet,
|
|
1639
|
+
chainId,
|
|
1640
|
+
uri
|
|
1260
1641
|
} = _b, urlOptions = __objRest(_b, [
|
|
1261
|
-
"externalWallet"
|
|
1642
|
+
"externalWallet",
|
|
1643
|
+
"chainId",
|
|
1644
|
+
"uri"
|
|
1262
1645
|
]);
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
yield this.
|
|
1646
|
+
const externalWallets = Array.isArray(externalWallet) ? externalWallet : [externalWallet];
|
|
1647
|
+
if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
|
|
1648
|
+
yield this.addExternalWallets(
|
|
1649
|
+
externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
|
|
1650
|
+
withFullParaAuth: false
|
|
1651
|
+
}))
|
|
1652
|
+
);
|
|
1266
1653
|
return Promise.resolve({
|
|
1267
1654
|
userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
|
|
1268
1655
|
});
|
|
1269
1656
|
}
|
|
1657
|
+
if (Array.isArray(externalWallet)) {
|
|
1658
|
+
throw new Error(
|
|
1659
|
+
"Cannot authenticate multiple external wallets at once. To connect multiple wallets at once, use CONNECTION_ONLY mode."
|
|
1660
|
+
);
|
|
1661
|
+
}
|
|
1270
1662
|
this.requireApiKey();
|
|
1271
|
-
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
|
|
1663
|
+
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet, chainId, uri });
|
|
1664
|
+
if (!externalWallet.withFullParaAuth && externalWallet.withVerification) {
|
|
1665
|
+
yield this.touchSession(true);
|
|
1666
|
+
}
|
|
1667
|
+
if (externalWallet.withFullParaAuth) {
|
|
1668
|
+
yield this.ctx.client.sessionAddPortalVerification();
|
|
1669
|
+
}
|
|
1272
1670
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1273
1671
|
});
|
|
1274
1672
|
}
|
|
1275
|
-
verifyExternalWallet(
|
|
1673
|
+
verifyExternalWallet(params) {
|
|
1276
1674
|
return __async(this, null, function* () {
|
|
1277
|
-
var
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
"cosmosPublicKeyHex",
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1675
|
+
var _c;
|
|
1676
|
+
let serverAuthState;
|
|
1677
|
+
let urlOptions;
|
|
1678
|
+
if ("serverAuthState" in params && params.serverAuthState !== void 0) {
|
|
1679
|
+
const _a = params, { serverAuthState: optsServerAuthState } = _a, rest = __objRest(_a, ["serverAuthState"]);
|
|
1680
|
+
serverAuthState = optsServerAuthState;
|
|
1681
|
+
urlOptions = rest;
|
|
1682
|
+
} else if ("externalWallet" in params) {
|
|
1683
|
+
const _b = params, { externalWallet, signedMessage, cosmosPublicKeyHex, cosmosSigner } = _b, rest = __objRest(_b, ["externalWallet", "signedMessage", "cosmosPublicKeyHex", "cosmosSigner"]);
|
|
1684
|
+
const _serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
|
|
1685
|
+
externalWallet,
|
|
1686
|
+
signedMessage,
|
|
1687
|
+
cosmosPublicKeyHex,
|
|
1688
|
+
cosmosSigner
|
|
1689
|
+
});
|
|
1690
|
+
serverAuthState = _serverAuthState;
|
|
1691
|
+
urlOptions = rest;
|
|
1692
|
+
}
|
|
1693
|
+
if (serverAuthState.stage === "login" && ((_c = serverAuthState.loginAuthMethods) == null ? void 0 : _c.includes(import_user_management_client.AuthMethod.PIN))) {
|
|
1694
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
1695
|
+
return yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1696
|
+
}
|
|
1697
|
+
let state;
|
|
1698
|
+
try {
|
|
1699
|
+
state = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1700
|
+
} catch (err) {
|
|
1701
|
+
console.error("Error prepping state:", err);
|
|
1702
|
+
}
|
|
1703
|
+
return state;
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
verifyExternalWalletLink(opts) {
|
|
1707
|
+
return __async(this, null, function* () {
|
|
1708
|
+
const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EXTERNAL_WALLET"]);
|
|
1709
|
+
if (!accountLinkInProgress.externalWallet) {
|
|
1710
|
+
throw new Error("no external wallet account link in progress");
|
|
1711
|
+
}
|
|
1712
|
+
const accounts = yield this.verifyLink(__spreadValues({
|
|
1713
|
+
accountLinkInProgress,
|
|
1714
|
+
externalWallet: accountLinkInProgress.externalWallet
|
|
1715
|
+
}, opts));
|
|
1716
|
+
return accounts;
|
|
1295
1717
|
});
|
|
1296
1718
|
}
|
|
1719
|
+
// TELEGRAM
|
|
1297
1720
|
/**
|
|
1298
1721
|
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
1299
1722
|
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
1300
1723
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1301
1724
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1302
1725
|
*/
|
|
1303
|
-
|
|
1726
|
+
verifyTelegramProcess(_c) {
|
|
1304
1727
|
return __async(this, null, function* () {
|
|
1305
|
-
var
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1728
|
+
var _d = _c, {
|
|
1729
|
+
serverAuthState: optsServerAuthState,
|
|
1730
|
+
telegramAuthResponse,
|
|
1731
|
+
isLinkAccount
|
|
1732
|
+
} = _d, urlOptions = __objRest(_d, [
|
|
1733
|
+
"serverAuthState",
|
|
1734
|
+
"telegramAuthResponse",
|
|
1735
|
+
"isLinkAccount"
|
|
1309
1736
|
]);
|
|
1310
1737
|
try {
|
|
1311
|
-
|
|
1312
|
-
|
|
1738
|
+
switch (isLinkAccount) {
|
|
1739
|
+
case false: {
|
|
1740
|
+
if (!optsServerAuthState && !telegramAuthResponse) {
|
|
1741
|
+
throw new Error("one of serverAuthState or telegramAuthResponse are required for verifying telegram");
|
|
1742
|
+
}
|
|
1743
|
+
const serverAuthState = optsServerAuthState != null ? optsServerAuthState : yield this.ctx.client.verifyTelegram({ authObject: telegramAuthResponse });
|
|
1744
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
1745
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1746
|
+
}
|
|
1747
|
+
case true: {
|
|
1748
|
+
if (!telegramAuthResponse) {
|
|
1749
|
+
throw new Error("telegramAuthResponse is required for verifying telegram link");
|
|
1750
|
+
}
|
|
1751
|
+
const accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "TELEGRAM");
|
|
1752
|
+
const accounts = yield this.verifyLink({
|
|
1753
|
+
accountLinkInProgress,
|
|
1754
|
+
telegramAuthResponse
|
|
1755
|
+
});
|
|
1756
|
+
return accounts;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1313
1759
|
} catch (e) {
|
|
1314
|
-
|
|
1760
|
+
const errorMessage = e instanceof Error ? e.message : e ? String(e) : "Unknown error occurred";
|
|
1761
|
+
throw new Error(errorMessage);
|
|
1315
1762
|
}
|
|
1316
1763
|
});
|
|
1317
1764
|
}
|
|
1765
|
+
verifyTelegram(opts) {
|
|
1766
|
+
return __async(this, null, function* () {
|
|
1767
|
+
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
verifyTelegramLink(opts) {
|
|
1771
|
+
return __async(this, null, function* () {
|
|
1772
|
+
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1318
1775
|
/**
|
|
1319
1776
|
* Performs 2FA verification.
|
|
1320
1777
|
* @param {Object} opts the options object
|
|
@@ -1358,10 +1815,35 @@ const _ParaCore = class _ParaCore {
|
|
|
1358
1815
|
/**
|
|
1359
1816
|
* Resend a verification email for the current user.
|
|
1360
1817
|
*/
|
|
1361
|
-
resendVerificationCode() {
|
|
1362
|
-
return __async(this,
|
|
1818
|
+
resendVerificationCode(_0) {
|
|
1819
|
+
return __async(this, arguments, function* ({
|
|
1820
|
+
type: reason = "SIGNUP"
|
|
1821
|
+
}) {
|
|
1822
|
+
let type, linkedAccountId;
|
|
1823
|
+
switch (reason) {
|
|
1824
|
+
case "SIGNUP":
|
|
1825
|
+
case "LOGIN":
|
|
1826
|
+
{
|
|
1827
|
+
const authInfo = this.assertIsAuthSet(["email", "phone"]);
|
|
1828
|
+
type = authInfo.authType.toUpperCase();
|
|
1829
|
+
}
|
|
1830
|
+
break;
|
|
1831
|
+
case "LINK_ACCOUNT":
|
|
1832
|
+
{
|
|
1833
|
+
const accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]);
|
|
1834
|
+
linkedAccountId = accountLinkInProgress.id;
|
|
1835
|
+
type = accountLinkInProgress.type;
|
|
1836
|
+
}
|
|
1837
|
+
break;
|
|
1838
|
+
}
|
|
1839
|
+
const userId = this.assertUserId({ allowGuestMode: true });
|
|
1840
|
+
if (type !== "EMAIL" && type !== "PHONE") {
|
|
1841
|
+
throw new Error("invalid auth type for verification code");
|
|
1842
|
+
}
|
|
1363
1843
|
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
1364
|
-
userId
|
|
1844
|
+
userId,
|
|
1845
|
+
type,
|
|
1846
|
+
linkedAccountId
|
|
1365
1847
|
}, this.getVerificationEmailProps()));
|
|
1366
1848
|
});
|
|
1367
1849
|
}
|
|
@@ -1374,7 +1856,14 @@ const _ParaCore = class _ParaCore {
|
|
|
1374
1856
|
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1375
1857
|
return true;
|
|
1376
1858
|
}
|
|
1377
|
-
const { isAuthenticated } = yield this.touchSession();
|
|
1859
|
+
const { isAuthenticated, verifiedExternalWalletAddresses } = yield this.touchSession();
|
|
1860
|
+
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1861
|
+
if (!verifiedExternalWalletAddresses) {
|
|
1862
|
+
return false;
|
|
1863
|
+
}
|
|
1864
|
+
const externalAddresses = Object.values(this.externalWallets).map((w) => w.id);
|
|
1865
|
+
return externalAddresses.every((address) => verifiedExternalWalletAddresses.includes(address));
|
|
1866
|
+
}
|
|
1378
1867
|
return !!isAuthenticated;
|
|
1379
1868
|
});
|
|
1380
1869
|
}
|
|
@@ -1385,23 +1874,57 @@ const _ParaCore = class _ParaCore {
|
|
|
1385
1874
|
isFullyLoggedIn() {
|
|
1386
1875
|
return __async(this, null, function* () {
|
|
1387
1876
|
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1877
|
+
if (!this.isReady) {
|
|
1878
|
+
yield this.ready();
|
|
1879
|
+
}
|
|
1388
1880
|
return true;
|
|
1389
1881
|
}
|
|
1390
1882
|
if (this.isGuestMode) {
|
|
1391
1883
|
return true;
|
|
1392
1884
|
}
|
|
1393
1885
|
const isSessionActive = yield this.isSessionActive();
|
|
1394
|
-
|
|
1886
|
+
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1887
|
+
return isSessionActive;
|
|
1888
|
+
}
|
|
1889
|
+
if (this.isSwitchingWallets) {
|
|
1890
|
+
return isSessionActive;
|
|
1891
|
+
}
|
|
1892
|
+
if (!isSessionActive) {
|
|
1893
|
+
return false;
|
|
1894
|
+
}
|
|
1895
|
+
if (this.isNoWalletConfig) {
|
|
1896
|
+
return true;
|
|
1897
|
+
}
|
|
1898
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1899
|
+
const requiredWalletTypes = supportedWalletTypes.filter(({ optional }) => !optional);
|
|
1900
|
+
for (const { type } of requiredWalletTypes) {
|
|
1901
|
+
const hasWalletForType = this.currentWalletIdsArray.some(([walletId, walletType]) => {
|
|
1902
|
+
try {
|
|
1903
|
+
const wallet = this.wallets[walletId];
|
|
1904
|
+
return wallet && walletType === type && typeof wallet.address === "string";
|
|
1905
|
+
} catch (e) {
|
|
1906
|
+
return false;
|
|
1907
|
+
}
|
|
1908
|
+
});
|
|
1909
|
+
if (!hasWalletForType) {
|
|
1910
|
+
return false;
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
return true;
|
|
1395
1914
|
});
|
|
1396
1915
|
}
|
|
1397
1916
|
get isGuestMode() {
|
|
1398
1917
|
return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
|
|
1399
1918
|
({ userId, partnerId }) => {
|
|
1400
1919
|
var _a;
|
|
1401
|
-
return partnerId === ((_a =
|
|
1920
|
+
return partnerId === ((_a = this.partner) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
|
|
1402
1921
|
}
|
|
1403
1922
|
);
|
|
1404
1923
|
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Get the auth methods available to an existing user
|
|
1926
|
+
* @deprecated Use supportedUserAuthMethods instead
|
|
1927
|
+
*/
|
|
1405
1928
|
supportedAuthMethods(auth) {
|
|
1406
1929
|
return __async(this, null, function* () {
|
|
1407
1930
|
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
@@ -1419,6 +1942,37 @@ const _ParaCore = class _ParaCore {
|
|
|
1419
1942
|
return authMethods;
|
|
1420
1943
|
});
|
|
1421
1944
|
}
|
|
1945
|
+
/**
|
|
1946
|
+
* Get the auth methods available to an existing user
|
|
1947
|
+
*/
|
|
1948
|
+
supportedUserAuthMethods() {
|
|
1949
|
+
return __async(this, null, function* () {
|
|
1950
|
+
yield this.assertIsAuthSet();
|
|
1951
|
+
const { supportedAuthMethods, hasPasswordWithoutPIN } = yield this.ctx.client.getSupportedAuthMethodsV2(
|
|
1952
|
+
this.authInfo.auth
|
|
1953
|
+
);
|
|
1954
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
1955
|
+
for (const type of supportedAuthMethods) {
|
|
1956
|
+
switch (type) {
|
|
1957
|
+
case "PASSWORD":
|
|
1958
|
+
if (hasPasswordWithoutPIN) {
|
|
1959
|
+
authMethods.add(import_user_management_client.AuthMethod.PASSWORD);
|
|
1960
|
+
}
|
|
1961
|
+
break;
|
|
1962
|
+
case "PASSKEY":
|
|
1963
|
+
authMethods.add(import_user_management_client.AuthMethod.PASSKEY);
|
|
1964
|
+
break;
|
|
1965
|
+
case "PIN":
|
|
1966
|
+
authMethods.add(import_user_management_client.AuthMethod.PIN);
|
|
1967
|
+
break;
|
|
1968
|
+
case "BASIC_LOGIN":
|
|
1969
|
+
authMethods.add(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
1970
|
+
break;
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
return authMethods;
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1422
1976
|
/**
|
|
1423
1977
|
* Get hints associated with the users stored biometrics.
|
|
1424
1978
|
* @deprecated
|
|
@@ -1495,36 +2049,47 @@ const _ParaCore = class _ParaCore {
|
|
|
1495
2049
|
});
|
|
1496
2050
|
}
|
|
1497
2051
|
/**
|
|
1498
|
-
* Initiates a Farcaster login attempt and
|
|
2052
|
+
* Initiates a Farcaster login attempt and returns the URL for the user to connect.
|
|
1499
2053
|
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
1500
2054
|
* @return {string} the Farcaster connect URI
|
|
1501
2055
|
*/
|
|
1502
2056
|
getFarcasterConnectUri() {
|
|
1503
|
-
return __async(this,
|
|
1504
|
-
const {
|
|
1505
|
-
data: { connect_uri: connectUri }
|
|
1506
|
-
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
2057
|
+
return __async(this, arguments, function* ({ appScheme } = {}) {
|
|
2058
|
+
const { connect_uri: connectUri } = yield this.ctx.client.initializeFarcasterLogin({ appScheme });
|
|
1507
2059
|
return connectUri;
|
|
1508
2060
|
});
|
|
1509
2061
|
}
|
|
2062
|
+
// FARCASTER
|
|
1510
2063
|
/**
|
|
1511
2064
|
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
1512
2065
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
1513
2066
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
1514
2067
|
*/
|
|
1515
|
-
|
|
2068
|
+
verifyFarcasterProcess(_e) {
|
|
1516
2069
|
return __async(this, null, function* () {
|
|
1517
|
-
var
|
|
2070
|
+
var _f = _e, {
|
|
1518
2071
|
isCanceled = () => false,
|
|
1519
2072
|
onConnectUri,
|
|
1520
2073
|
onCancel,
|
|
1521
|
-
onPoll
|
|
1522
|
-
|
|
2074
|
+
onPoll,
|
|
2075
|
+
isLinkAccount,
|
|
2076
|
+
serverAuthState: optsServerAuthState
|
|
2077
|
+
} = _f, urlOptions = __objRest(_f, [
|
|
1523
2078
|
"isCanceled",
|
|
1524
2079
|
"onConnectUri",
|
|
1525
2080
|
"onCancel",
|
|
1526
|
-
"onPoll"
|
|
2081
|
+
"onPoll",
|
|
2082
|
+
"isLinkAccount",
|
|
2083
|
+
"serverAuthState"
|
|
1527
2084
|
]);
|
|
2085
|
+
if (optsServerAuthState) {
|
|
2086
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, optsServerAuthState, urlOptions);
|
|
2087
|
+
return authState;
|
|
2088
|
+
}
|
|
2089
|
+
let accountLinkInProgress;
|
|
2090
|
+
if (isLinkAccount) {
|
|
2091
|
+
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
|
|
2092
|
+
}
|
|
1528
2093
|
if (onConnectUri) {
|
|
1529
2094
|
const connectUri = yield this.getFarcasterConnectUri();
|
|
1530
2095
|
onConnectUri(connectUri);
|
|
@@ -1536,85 +2101,113 @@ const _ParaCore = class _ParaCore {
|
|
|
1536
2101
|
try {
|
|
1537
2102
|
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1538
2103
|
onCancel == null ? void 0 : onCancel();
|
|
1539
|
-
return reject("
|
|
2104
|
+
return reject("CANCELED");
|
|
1540
2105
|
}
|
|
1541
2106
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
2107
|
+
switch (isLinkAccount) {
|
|
2108
|
+
case false:
|
|
2109
|
+
{
|
|
2110
|
+
const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
|
|
2111
|
+
if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
|
|
2112
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2113
|
+
return resolve(authState);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
break;
|
|
2117
|
+
case true: {
|
|
2118
|
+
const result = yield this.verifyLink({
|
|
2119
|
+
accountLinkInProgress
|
|
2120
|
+
});
|
|
2121
|
+
if ("isConflict" in result) {
|
|
2122
|
+
throw new Error(import_types.AccountLinkError.Conflict);
|
|
2123
|
+
}
|
|
2124
|
+
return resolve(result);
|
|
2125
|
+
}
|
|
1546
2126
|
}
|
|
1547
2127
|
onPoll == null ? void 0 : onPoll();
|
|
1548
2128
|
} catch (e) {
|
|
1549
|
-
|
|
1550
|
-
|
|
2129
|
+
if (!isLinkAccount || e.message === import_types.AccountLinkError.Conflict) {
|
|
2130
|
+
return reject(e.message);
|
|
2131
|
+
}
|
|
1551
2132
|
}
|
|
1552
2133
|
}
|
|
1553
2134
|
}))();
|
|
1554
2135
|
});
|
|
1555
2136
|
});
|
|
1556
2137
|
}
|
|
1557
|
-
|
|
1558
|
-
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
1559
|
-
*
|
|
1560
|
-
* @param {Object} opts the options object
|
|
1561
|
-
* @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
|
|
1562
|
-
* @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
|
|
1563
|
-
* @returns {string} the URL for the user to log in with OAuth.
|
|
1564
|
-
*/
|
|
1565
|
-
getOAuthUrl(_i) {
|
|
2138
|
+
verifyFarcaster(opts) {
|
|
1566
2139
|
return __async(this, null, function* () {
|
|
1567
|
-
|
|
1568
|
-
var _a;
|
|
1569
|
-
if (deeplinkUrl) {
|
|
1570
|
-
try {
|
|
1571
|
-
new URL(deeplinkUrl);
|
|
1572
|
-
} catch (e) {
|
|
1573
|
-
throw new Error("Invalid deeplink URL");
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
1577
|
-
return (0, import_utils2.constructUrl)({
|
|
1578
|
-
base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
|
|
1579
|
-
path: `/auth/${method}`,
|
|
1580
|
-
params: {
|
|
1581
|
-
apiKey: this.ctx.apiKey,
|
|
1582
|
-
sessionLookupId,
|
|
1583
|
-
deeplinkUrl
|
|
1584
|
-
}
|
|
1585
|
-
});
|
|
2140
|
+
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
|
|
1586
2141
|
});
|
|
1587
2142
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
2143
|
+
verifyFarcasterLink(opts) {
|
|
2144
|
+
return __async(this, null, function* () {
|
|
2145
|
+
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
getOAuthUrl(opts) {
|
|
2149
|
+
return __async(this, null, function* () {
|
|
2150
|
+
var _a;
|
|
2151
|
+
const sessionLookupId = (_a = opts.sessionLookupId) != null ? _a : yield this.prepareLogin();
|
|
2152
|
+
return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* Awaits the response from a user's attempt to log in with OAuth.
|
|
1590
2157
|
* If successful, this returns the user's email address and indicates whether the user already exists.
|
|
1591
2158
|
*
|
|
1592
2159
|
* @param {Object} opts the options object.
|
|
1593
2160
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1594
2161
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1595
2162
|
*/
|
|
1596
|
-
|
|
2163
|
+
verifyOAuthProcess(_g) {
|
|
1597
2164
|
return __async(this, null, function* () {
|
|
1598
|
-
var
|
|
2165
|
+
var _h = _g, {
|
|
1599
2166
|
method,
|
|
1600
|
-
|
|
2167
|
+
appScheme,
|
|
1601
2168
|
isCanceled = () => false,
|
|
1602
2169
|
onCancel,
|
|
1603
2170
|
onPoll,
|
|
1604
|
-
onOAuthUrl
|
|
1605
|
-
|
|
2171
|
+
onOAuthUrl,
|
|
2172
|
+
onOAuthPopup,
|
|
2173
|
+
isLinkAccount
|
|
2174
|
+
} = _h, urlOptions = __objRest(_h, [
|
|
1606
2175
|
"method",
|
|
1607
|
-
"
|
|
2176
|
+
"appScheme",
|
|
1608
2177
|
"isCanceled",
|
|
1609
2178
|
"onCancel",
|
|
1610
2179
|
"onPoll",
|
|
1611
|
-
"onOAuthUrl"
|
|
2180
|
+
"onOAuthUrl",
|
|
2181
|
+
"onOAuthPopup",
|
|
2182
|
+
"isLinkAccount"
|
|
1612
2183
|
]);
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
2184
|
+
if (onOAuthPopup) {
|
|
2185
|
+
try {
|
|
2186
|
+
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.OAUTH });
|
|
2187
|
+
} catch (error) {
|
|
2188
|
+
throw new Error(`Failed to open OAuth popup: ${error}`);
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
let sessionLookupId, accountLinkInProgress;
|
|
2192
|
+
if (onOAuthUrl || onOAuthPopup) {
|
|
2193
|
+
if (isLinkAccount) {
|
|
2194
|
+
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
|
|
2195
|
+
sessionLookupId = (yield this.touchSession()).sessionLookupId;
|
|
2196
|
+
} else {
|
|
2197
|
+
sessionLookupId = yield this.prepareLogin();
|
|
2198
|
+
}
|
|
2199
|
+
const oAuthUrl = yield __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, { method, appScheme, sessionLookupId, accountLinkInProgress });
|
|
2200
|
+
switch (true) {
|
|
2201
|
+
case !!onOAuthUrl: {
|
|
2202
|
+
onOAuthUrl(oAuthUrl);
|
|
2203
|
+
break;
|
|
2204
|
+
}
|
|
2205
|
+
case (!!onOAuthPopup && !!this.popupWindow): {
|
|
2206
|
+
this.popupWindow.location.href = oAuthUrl;
|
|
2207
|
+
onOAuthPopup(this.popupWindow);
|
|
2208
|
+
break;
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
1618
2211
|
} else {
|
|
1619
2212
|
({ sessionLookupId } = yield this.touchSession());
|
|
1620
2213
|
}
|
|
@@ -1625,17 +2218,29 @@ const _ParaCore = class _ParaCore {
|
|
|
1625
2218
|
try {
|
|
1626
2219
|
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1627
2220
|
onCancel == null ? void 0 : onCancel();
|
|
1628
|
-
return reject(
|
|
2221
|
+
return reject(import_types.AccountLinkError.Canceled);
|
|
1629
2222
|
}
|
|
1630
2223
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
2224
|
+
switch (isLinkAccount) {
|
|
2225
|
+
case false:
|
|
2226
|
+
{
|
|
2227
|
+
const serverAuthState = yield this.ctx.client.verifyOAuth();
|
|
2228
|
+
if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
|
|
2229
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
2230
|
+
return resolve(authState);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
break;
|
|
2234
|
+
case true: {
|
|
2235
|
+
const accounts = yield this.verifyLink({ accountLinkInProgress });
|
|
2236
|
+
return resolve(accounts);
|
|
2237
|
+
}
|
|
1635
2238
|
}
|
|
1636
2239
|
onPoll == null ? void 0 : onPoll();
|
|
1637
2240
|
} catch (err) {
|
|
1638
|
-
|
|
2241
|
+
if (isLinkAccount && err.message === import_types.AccountLinkError.Conflict) {
|
|
2242
|
+
return reject(err.message);
|
|
2243
|
+
}
|
|
1639
2244
|
onPoll == null ? void 0 : onPoll();
|
|
1640
2245
|
}
|
|
1641
2246
|
}
|
|
@@ -1643,6 +2248,16 @@ const _ParaCore = class _ParaCore {
|
|
|
1643
2248
|
});
|
|
1644
2249
|
});
|
|
1645
2250
|
}
|
|
2251
|
+
verifyOAuth(opts) {
|
|
2252
|
+
return __async(this, null, function* () {
|
|
2253
|
+
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: false }));
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
verifyOAuthLink(opts) {
|
|
2257
|
+
return __async(this, null, function* () {
|
|
2258
|
+
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
1646
2261
|
/**
|
|
1647
2262
|
* Waits for the session to be active and sets up the user.
|
|
1648
2263
|
*
|
|
@@ -1651,61 +2266,26 @@ const _ParaCore = class _ParaCore {
|
|
|
1651
2266
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
1652
2267
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
1653
2268
|
**/
|
|
1654
|
-
waitForLogin() {
|
|
1655
|
-
return __async(this,
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
|
|
1675
|
-
try {
|
|
1676
|
-
let session = yield this.touchSession();
|
|
1677
|
-
if (!session.isAuthenticated) {
|
|
1678
|
-
onPoll == null ? void 0 : onPoll();
|
|
1679
|
-
continue;
|
|
1680
|
-
}
|
|
1681
|
-
session = yield this.userSetupAfterLogin();
|
|
1682
|
-
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
1683
|
-
if (!needsWallet) {
|
|
1684
|
-
if (this.currentWalletIdsArray.length === 0) {
|
|
1685
|
-
onPoll == null ? void 0 : onPoll();
|
|
1686
|
-
continue;
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
const fetchedWallets = yield this.fetchWallets();
|
|
1690
|
-
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
1691
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
1692
|
-
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
1693
|
-
yield this.claimPregenWallets();
|
|
1694
|
-
const resp = {
|
|
1695
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
1696
|
-
partnerId: session.partnerId
|
|
1697
|
-
};
|
|
1698
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp);
|
|
1699
|
-
return resolve(resp);
|
|
1700
|
-
}
|
|
1701
|
-
onPoll == null ? void 0 : onPoll();
|
|
1702
|
-
} catch (err) {
|
|
1703
|
-
console.error(err);
|
|
1704
|
-
onPoll == null ? void 0 : onPoll();
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
}))();
|
|
1708
|
-
});
|
|
2269
|
+
waitForLogin(args) {
|
|
2270
|
+
return __async(this, null, function* () {
|
|
2271
|
+
return yield __privateMethod(this, _ParaCore_instances, waitForLoginProcess_fn).call(this, args);
|
|
2272
|
+
});
|
|
2273
|
+
}
|
|
2274
|
+
waitForWalletSwitching(args) {
|
|
2275
|
+
return __async(this, null, function* () {
|
|
2276
|
+
return yield __privateMethod(this, _ParaCore_instances, waitForLoginProcess_fn).call(this, __spreadProps(__spreadValues({}, args), { isSwitchingWallets: true }));
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
/**
|
|
2280
|
+
* Gets the switch wallets URL for wallet selection.
|
|
2281
|
+
* The authMethod is automatically included in the URL if available.
|
|
2282
|
+
*
|
|
2283
|
+
* @returns {Promise<{ url: string; authMethod: TAuthMethod }>} The switch wallets URL and authMethod
|
|
2284
|
+
*/
|
|
2285
|
+
getSwitchWalletsUrl() {
|
|
2286
|
+
return __async(this, null, function* () {
|
|
2287
|
+
const url = yield this.constructPortalUrl("switchWallets");
|
|
2288
|
+
return url;
|
|
1709
2289
|
});
|
|
1710
2290
|
}
|
|
1711
2291
|
/**
|
|
@@ -1728,7 +2308,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1728
2308
|
sessionId
|
|
1729
2309
|
});
|
|
1730
2310
|
if (shouldOpenPopup) {
|
|
1731
|
-
this.platformUtils.openPopup(link);
|
|
2311
|
+
yield this.platformUtils.openPopup(link);
|
|
1732
2312
|
}
|
|
1733
2313
|
return link;
|
|
1734
2314
|
});
|
|
@@ -1819,7 +2399,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1819
2399
|
userId: this.userId,
|
|
1820
2400
|
walletId,
|
|
1821
2401
|
userShare: userSigner,
|
|
1822
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2402
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
2403
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2404
|
+
walletScheme: this.wallets[walletId].scheme
|
|
1823
2405
|
});
|
|
1824
2406
|
return recoveryShare;
|
|
1825
2407
|
});
|
|
@@ -1833,7 +2415,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1833
2415
|
break;
|
|
1834
2416
|
}
|
|
1835
2417
|
++maxPolls;
|
|
1836
|
-
const res = yield this.ctx.client.getWallets(this.userId);
|
|
2418
|
+
const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId);
|
|
1837
2419
|
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
1838
2420
|
if (wallet && wallet.address) {
|
|
1839
2421
|
return;
|
|
@@ -1947,7 +2529,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1947
2529
|
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
1948
2530
|
emailProps: this.getBackupKitEmailProps(),
|
|
1949
2531
|
partnerId: newPartnerId,
|
|
1950
|
-
protocolId
|
|
2532
|
+
protocolId,
|
|
2533
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2534
|
+
walletScheme: this.wallets[walletId].scheme
|
|
1951
2535
|
});
|
|
1952
2536
|
return { signer, recoverySecret, protocolId };
|
|
1953
2537
|
});
|
|
@@ -1996,26 +2580,29 @@ const _ParaCore = class _ParaCore {
|
|
|
1996
2580
|
}
|
|
1997
2581
|
}
|
|
1998
2582
|
const walletId = keygenRes.walletId;
|
|
2583
|
+
const walletScheme = walletType === "SOLANA" ? "ED25519" : "DKLS";
|
|
1999
2584
|
signer = keygenRes.signer;
|
|
2000
|
-
this.
|
|
2001
|
-
id: walletId,
|
|
2002
|
-
signer,
|
|
2003
|
-
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
2004
|
-
type: walletType
|
|
2005
|
-
};
|
|
2006
|
-
wallet = this.wallets[walletId];
|
|
2007
|
-
yield this.waitForWalletAddress(wallet.id);
|
|
2008
|
-
yield this.populateWalletAddresses();
|
|
2585
|
+
yield this.waitForWalletAddress(walletId);
|
|
2009
2586
|
let recoveryShare = null;
|
|
2010
2587
|
if (!skipDistribute) {
|
|
2011
2588
|
recoveryShare = yield (0, import_shareDistribution.distributeNewShare)({
|
|
2012
2589
|
ctx: this.ctx,
|
|
2013
2590
|
userId: this.userId,
|
|
2014
|
-
walletId
|
|
2591
|
+
walletId,
|
|
2015
2592
|
userShare: signer,
|
|
2016
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2593
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
2594
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2595
|
+
walletScheme
|
|
2017
2596
|
});
|
|
2018
2597
|
}
|
|
2598
|
+
this.wallets[walletId] = {
|
|
2599
|
+
id: walletId,
|
|
2600
|
+
signer,
|
|
2601
|
+
scheme: walletScheme,
|
|
2602
|
+
type: walletType
|
|
2603
|
+
};
|
|
2604
|
+
wallet = this.wallets[walletId];
|
|
2605
|
+
yield this.populateWalletAddresses();
|
|
2019
2606
|
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
2020
2607
|
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
2021
2608
|
}));
|
|
@@ -2094,7 +2681,9 @@ const _ParaCore = class _ParaCore {
|
|
|
2094
2681
|
walletId: wallet.id,
|
|
2095
2682
|
userShare: this.wallets[wallet.id].signer,
|
|
2096
2683
|
emailProps: this.getBackupKitEmailProps(),
|
|
2097
|
-
partnerId: wallet.partnerId
|
|
2684
|
+
partnerId: wallet.partnerId,
|
|
2685
|
+
isEnclaveUser: this.isEnclaveUser,
|
|
2686
|
+
walletScheme: wallet.scheme
|
|
2098
2687
|
});
|
|
2099
2688
|
if (distributeRes.length > 0) {
|
|
2100
2689
|
newRecoverySecret = distributeRes;
|
|
@@ -2221,10 +2810,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2221
2810
|
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, wallets);
|
|
2222
2811
|
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2223
2812
|
return wallets;
|
|
2224
|
-
} catch (
|
|
2225
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null,
|
|
2813
|
+
} catch (error2) {
|
|
2814
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error2 == null ? void 0 : error2.message);
|
|
2226
2815
|
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2227
|
-
throw
|
|
2816
|
+
throw error2;
|
|
2228
2817
|
}
|
|
2229
2818
|
});
|
|
2230
2819
|
}
|
|
@@ -2272,25 +2861,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2272
2861
|
});
|
|
2273
2862
|
});
|
|
2274
2863
|
}
|
|
2275
|
-
getOnRampTransactionUrl(
|
|
2276
|
-
return __async(this,
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
providerKey
|
|
2280
|
-
} = _n, walletParams = __objRest(_n, [
|
|
2281
|
-
"purchaseId",
|
|
2282
|
-
"providerKey"
|
|
2283
|
-
]);
|
|
2284
|
-
const { sessionId } = yield this.touchSession();
|
|
2285
|
-
const [key, identifier] = (0, import_user_management_client.extractWalletRef)(walletParams);
|
|
2864
|
+
getOnRampTransactionUrl(_0) {
|
|
2865
|
+
return __async(this, arguments, function* ({
|
|
2866
|
+
purchaseId
|
|
2867
|
+
}) {
|
|
2286
2868
|
return this.constructPortalUrl("onRamp", {
|
|
2287
|
-
pathId: purchaseId
|
|
2288
|
-
sessionId,
|
|
2289
|
-
params: {
|
|
2290
|
-
[key]: identifier,
|
|
2291
|
-
providerKey,
|
|
2292
|
-
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
2293
|
-
}
|
|
2869
|
+
pathId: purchaseId
|
|
2294
2870
|
});
|
|
2295
2871
|
});
|
|
2296
2872
|
}
|
|
@@ -2315,6 +2891,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2315
2891
|
onCancel,
|
|
2316
2892
|
onPoll
|
|
2317
2893
|
}) {
|
|
2894
|
+
var _a;
|
|
2318
2895
|
this.assertIsValidWalletId(walletId);
|
|
2319
2896
|
const wallet = this.wallets[walletId];
|
|
2320
2897
|
let signerId = this.userId;
|
|
@@ -2324,7 +2901,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2324
2901
|
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2325
2902
|
let timeStart = Date.now();
|
|
2326
2903
|
if (signRes.pendingTransactionId) {
|
|
2327
|
-
this.platformUtils.openPopup(
|
|
2904
|
+
yield this.platformUtils.openPopup(
|
|
2328
2905
|
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2329
2906
|
{ type: cosmosSignDocBase64 ? import_types.PopupType.SIGN_TRANSACTION_REVIEW : import_types.PopupType.SIGN_MESSAGE_REVIEW }
|
|
2330
2907
|
);
|
|
@@ -2338,18 +2915,19 @@ const _ParaCore = class _ParaCore {
|
|
|
2338
2915
|
break;
|
|
2339
2916
|
}
|
|
2340
2917
|
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2918
|
+
let pendingTransaction;
|
|
2341
2919
|
try {
|
|
2342
|
-
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2343
|
-
} catch (
|
|
2920
|
+
pendingTransaction = (_a = (yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId)).data) == null ? void 0 : _a.pendingTransaction;
|
|
2921
|
+
} catch (e) {
|
|
2344
2922
|
const error = new import_errors.TransactionReviewDenied();
|
|
2345
2923
|
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2346
2924
|
throw error;
|
|
2347
2925
|
}
|
|
2348
|
-
|
|
2349
|
-
if (signRes.pendingTransactionId) {
|
|
2926
|
+
if (!(pendingTransaction == null ? void 0 : pendingTransaction.approvedAt)) {
|
|
2350
2927
|
onPoll == null ? void 0 : onPoll();
|
|
2351
2928
|
continue;
|
|
2352
2929
|
} else {
|
|
2930
|
+
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2353
2931
|
break;
|
|
2354
2932
|
}
|
|
2355
2933
|
}
|
|
@@ -2418,6 +2996,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2418
2996
|
onCancel,
|
|
2419
2997
|
onPoll
|
|
2420
2998
|
}) {
|
|
2999
|
+
var _a;
|
|
2421
3000
|
this.assertIsValidWalletId(walletId);
|
|
2422
3001
|
const wallet = this.wallets[walletId];
|
|
2423
3002
|
let signerId = this.userId;
|
|
@@ -2436,7 +3015,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2436
3015
|
);
|
|
2437
3016
|
let timeStart = Date.now();
|
|
2438
3017
|
if (signRes.pendingTransactionId) {
|
|
2439
|
-
this.platformUtils.openPopup(
|
|
3018
|
+
yield this.platformUtils.openPopup(
|
|
2440
3019
|
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2441
3020
|
{ type: import_types.PopupType.SIGN_TRANSACTION_REVIEW }
|
|
2442
3021
|
);
|
|
@@ -2450,27 +3029,28 @@ const _ParaCore = class _ParaCore {
|
|
|
2450
3029
|
break;
|
|
2451
3030
|
}
|
|
2452
3031
|
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
3032
|
+
let pendingTransaction;
|
|
2453
3033
|
try {
|
|
2454
|
-
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2455
|
-
} catch (
|
|
3034
|
+
pendingTransaction = (_a = (yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId)).data) == null ? void 0 : _a.pendingTransaction;
|
|
3035
|
+
} catch (e) {
|
|
2456
3036
|
const error = new import_errors.TransactionReviewDenied();
|
|
2457
3037
|
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
2458
3038
|
throw error;
|
|
2459
3039
|
}
|
|
2460
|
-
|
|
2461
|
-
this.ctx,
|
|
2462
|
-
signerId,
|
|
2463
|
-
walletId,
|
|
2464
|
-
this.wallets[walletId].signer,
|
|
2465
|
-
rlpEncodedTxBase64,
|
|
2466
|
-
chainId,
|
|
2467
|
-
this.retrieveSessionCookie(),
|
|
2468
|
-
wallet.scheme === "DKLS"
|
|
2469
|
-
);
|
|
2470
|
-
if (signRes.pendingTransactionId) {
|
|
3040
|
+
if (!(pendingTransaction == null ? void 0 : pendingTransaction.approvedAt)) {
|
|
2471
3041
|
onPoll == null ? void 0 : onPoll();
|
|
2472
3042
|
continue;
|
|
2473
3043
|
} else {
|
|
3044
|
+
signRes = yield this.platformUtils.signTransaction(
|
|
3045
|
+
this.ctx,
|
|
3046
|
+
signerId,
|
|
3047
|
+
walletId,
|
|
3048
|
+
this.wallets[walletId].signer,
|
|
3049
|
+
rlpEncodedTxBase64,
|
|
3050
|
+
chainId,
|
|
3051
|
+
this.retrieveSessionCookie(),
|
|
3052
|
+
wallet.scheme === "DKLS"
|
|
3053
|
+
);
|
|
2474
3054
|
break;
|
|
2475
3055
|
}
|
|
2476
3056
|
}
|
|
@@ -2512,7 +3092,8 @@ const _ParaCore = class _ParaCore {
|
|
|
2512
3092
|
providerKey: onRampPurchase.providerKey
|
|
2513
3093
|
}, walletParams));
|
|
2514
3094
|
if (shouldOpenPopup) {
|
|
2515
|
-
this.platformUtils.openPopup(portalUrl, { type: import_types.PopupType.ON_RAMP_TRANSACTION });
|
|
3095
|
+
const onRampWindow = yield this.platformUtils.openPopup(portalUrl, { type: import_types.PopupType.ON_RAMP_TRANSACTION });
|
|
3096
|
+
this.onRampPopup = { window: onRampWindow, onRampPurchase };
|
|
2516
3097
|
}
|
|
2517
3098
|
return { onRampPurchase, portalUrl };
|
|
2518
3099
|
});
|
|
@@ -2525,7 +3106,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2525
3106
|
try {
|
|
2526
3107
|
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
2527
3108
|
return true;
|
|
2528
|
-
} catch (
|
|
3109
|
+
} catch (e) {
|
|
2529
3110
|
return false;
|
|
2530
3111
|
}
|
|
2531
3112
|
});
|
|
@@ -2595,6 +3176,20 @@ const _ParaCore = class _ParaCore {
|
|
|
2595
3176
|
return sessionLookupId;
|
|
2596
3177
|
});
|
|
2597
3178
|
}
|
|
3179
|
+
issueJwt() {
|
|
3180
|
+
return __async(this, arguments, function* ({ keyIndex = 0 } = {}) {
|
|
3181
|
+
try {
|
|
3182
|
+
return yield this.ctx.client.issueJwt({ keyIndex });
|
|
3183
|
+
} catch (error) {
|
|
3184
|
+
if (error.status === 403 || error.status === 401) {
|
|
3185
|
+
const errorMessage = "The user needs to be logged in to issue a JWT. Please log in and try again.";
|
|
3186
|
+
this.displayModalError(errorMessage);
|
|
3187
|
+
console.warn(errorMessage);
|
|
3188
|
+
}
|
|
3189
|
+
throw error;
|
|
3190
|
+
}
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
2598
3193
|
/**
|
|
2599
3194
|
* Logs the user out.
|
|
2600
3195
|
* @param {Object} opts the options object.
|
|
@@ -2602,6 +3197,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2602
3197
|
**/
|
|
2603
3198
|
logout() {
|
|
2604
3199
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3200
|
+
const shouldDispatchLogoutEvent = yield this.isSessionActive();
|
|
2605
3201
|
yield this.ctx.client.logout();
|
|
2606
3202
|
yield this.clearStorage();
|
|
2607
3203
|
if (!clearPregenWallets) {
|
|
@@ -2618,22 +3214,17 @@ const _ParaCore = class _ParaCore {
|
|
|
2618
3214
|
this.externalWallets = {};
|
|
2619
3215
|
this.loginEncryptionKeyPair = void 0;
|
|
2620
3216
|
__privateSet(this, _authInfo, void 0);
|
|
3217
|
+
this.accountLinkInProgress = void 0;
|
|
2621
3218
|
this.userId = void 0;
|
|
2622
3219
|
this.sessionCookie = void 0;
|
|
2623
|
-
(
|
|
2624
|
-
|
|
2625
|
-
}
|
|
2626
|
-
/** @deprecated */
|
|
2627
|
-
getSupportedCreateAuthMethods() {
|
|
2628
|
-
return __async(this, null, function* () {
|
|
2629
|
-
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2630
|
-
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
2631
|
-
for (const authMethod of partner.supportedAuthMethods) {
|
|
2632
|
-
supportedAuthMethods.add(import_user_management_client.AuthMethod[authMethod]);
|
|
3220
|
+
if (shouldDispatchLogoutEvent) {
|
|
3221
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
|
|
2633
3222
|
}
|
|
2634
|
-
return supportedAuthMethods;
|
|
2635
3223
|
});
|
|
2636
3224
|
}
|
|
3225
|
+
get toStringAdditions() {
|
|
3226
|
+
return {};
|
|
3227
|
+
}
|
|
2637
3228
|
/**
|
|
2638
3229
|
* Converts to a string, removing sensitive data when logging this class.
|
|
2639
3230
|
*
|
|
@@ -2657,10 +3248,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2657
3248
|
}),
|
|
2658
3249
|
{}
|
|
2659
3250
|
);
|
|
2660
|
-
const obj = {
|
|
2661
|
-
partnerId: (_a =
|
|
2662
|
-
supportedWalletTypes: (_b =
|
|
2663
|
-
cosmosPrefix: (_c =
|
|
3251
|
+
const obj = __spreadProps(__spreadValues({
|
|
3252
|
+
partnerId: (_a = this.partner) == null ? void 0 : _a.id,
|
|
3253
|
+
supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
|
|
3254
|
+
cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
|
|
2664
3255
|
authInfo: __privateGet(this, _authInfo),
|
|
2665
3256
|
isGuestMode: this.isGuestMode,
|
|
2666
3257
|
userId: this.userId,
|
|
@@ -2670,6 +3261,8 @@ const _ParaCore = class _ParaCore {
|
|
|
2670
3261
|
wallets: redactedWallets,
|
|
2671
3262
|
externalWallets: redactedExternalWallets,
|
|
2672
3263
|
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
3264
|
+
isReady: this.isReady
|
|
3265
|
+
}, this.toStringAdditions), {
|
|
2673
3266
|
ctx: {
|
|
2674
3267
|
apiKey: this.ctx.apiKey,
|
|
2675
3268
|
disableWorkers: this.ctx.disableWorkers,
|
|
@@ -2680,48 +3273,98 @@ const _ParaCore = class _ParaCore {
|
|
|
2680
3273
|
useDKLS: this.ctx.useDKLS,
|
|
2681
3274
|
cosmosPrefix: this.ctx.cosmosPrefix
|
|
2682
3275
|
}
|
|
2683
|
-
};
|
|
3276
|
+
});
|
|
2684
3277
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
2685
3278
|
}
|
|
3279
|
+
devLog(...s) {
|
|
3280
|
+
if (this.ctx.env === import_types.Environment.DEV || this.ctx.env === import_types.Environment.SANDBOX) {
|
|
3281
|
+
console.log(...s);
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
2686
3284
|
getNewCredentialAndUrl() {
|
|
2687
3285
|
return __async(this, arguments, function* ({
|
|
2688
|
-
authMethod
|
|
3286
|
+
authMethod: optsAuthMethod,
|
|
2689
3287
|
isForNewDevice = false,
|
|
2690
3288
|
portalTheme,
|
|
2691
3289
|
shorten = false
|
|
2692
3290
|
} = {}) {
|
|
3291
|
+
const userAuthMethods = yield this.supportedUserAuthMethods();
|
|
3292
|
+
const isEnclaveUser = userAuthMethods.has(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
3293
|
+
const isAddingBasicLogin = optsAuthMethod === "BASIC_LOGIN";
|
|
3294
|
+
if (isEnclaveUser && isAddingBasicLogin) {
|
|
3295
|
+
throw new Error("That user is already using basic login");
|
|
3296
|
+
}
|
|
3297
|
+
if (isEnclaveUser || isAddingBasicLogin) {
|
|
3298
|
+
isForNewDevice = true;
|
|
3299
|
+
}
|
|
3300
|
+
const authMethods = optsAuthMethod ? [optsAuthMethod] : isForNewDevice ? ["PASSKEY", "PIN", "PASSWORD"] : ["PASSKEY"];
|
|
2693
3301
|
this.assertIsAuthSet();
|
|
2694
|
-
let
|
|
2695
|
-
|
|
2696
|
-
|
|
3302
|
+
let passkeyId, passwordId, urlType, credentialId;
|
|
3303
|
+
if (!isAddingBasicLogin) {
|
|
3304
|
+
const canAddPasswordOrPIN = !userAuthMethods.has(import_user_management_client.AuthMethod.PASSWORD) && !userAuthMethods.has(import_user_management_client.AuthMethod.PIN);
|
|
3305
|
+
if (authMethods.includes("PASSKEY") && (yield this.isPasskeySupported())) {
|
|
2697
3306
|
({
|
|
2698
|
-
data: { id:
|
|
3307
|
+
data: { id: passkeyId }
|
|
2699
3308
|
} = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2700
|
-
status: import_user_management_client.
|
|
3309
|
+
status: import_user_management_client.AuthMethodStatus.PENDING,
|
|
2701
3310
|
type: import_user_management_client.PublicKeyType.WEB
|
|
2702
3311
|
}));
|
|
2703
3312
|
urlType = "createAuth";
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
({
|
|
2707
|
-
|
|
2708
|
-
}
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
3313
|
+
}
|
|
3314
|
+
if (authMethods.includes("PASSWORD")) {
|
|
3315
|
+
if (!canAddPasswordOrPIN) {
|
|
3316
|
+
if (optsAuthMethod === "PASSWORD") throw new Error("A user cannot have more than one password or PIN.");
|
|
3317
|
+
} else {
|
|
3318
|
+
({
|
|
3319
|
+
data: { id: passwordId }
|
|
3320
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3321
|
+
status: import_user_management_client.AuthMethodStatus.PENDING
|
|
3322
|
+
}));
|
|
3323
|
+
urlType = "createPassword";
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
if (authMethods.includes("PIN")) {
|
|
3327
|
+
if (!canAddPasswordOrPIN) {
|
|
3328
|
+
if (optsAuthMethod === "PIN") throw new Error("A user cannot have more than one password or PIN.");
|
|
3329
|
+
} else {
|
|
3330
|
+
({
|
|
3331
|
+
data: { id: passwordId }
|
|
3332
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3333
|
+
status: import_user_management_client.AuthMethodStatus.PENDING
|
|
3334
|
+
}));
|
|
3335
|
+
urlType = "createPIN";
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
credentialId = passkeyId != null ? passkeyId : passwordId;
|
|
3339
|
+
if (this.isNativePasskey && authMethods.includes("PASSKEY")) {
|
|
3340
|
+
return { credentialId };
|
|
3341
|
+
}
|
|
2713
3342
|
}
|
|
2714
|
-
const
|
|
3343
|
+
const { sessionId } = yield this.touchSession();
|
|
3344
|
+
const url = (isForNewDevice || urlType) && (yield this.constructPortalUrl(isForNewDevice ? "addNewCredential" : urlType, {
|
|
2715
3345
|
isForNewDevice,
|
|
2716
3346
|
pathId: credentialId,
|
|
2717
3347
|
portalTheme,
|
|
2718
|
-
shorten
|
|
2719
|
-
|
|
3348
|
+
shorten,
|
|
3349
|
+
sessionId: isForNewDevice ? sessionId : void 0,
|
|
3350
|
+
addNewCredentialType: optsAuthMethod,
|
|
3351
|
+
addNewCredentialPasskeyId: passkeyId,
|
|
3352
|
+
addNewCredentialPasswordId: passwordId
|
|
3353
|
+
}));
|
|
2720
3354
|
return __spreadValues({ credentialId }, url ? { url } : {});
|
|
2721
3355
|
});
|
|
2722
3356
|
}
|
|
3357
|
+
addCredential(_0) {
|
|
3358
|
+
return __async(this, arguments, function* ({ authMethod }) {
|
|
3359
|
+
if (authMethod === "PASSKEY" && !(yield this.isPasskeySupported())) {
|
|
3360
|
+
throw new Error("Passkeys are not supported.");
|
|
3361
|
+
}
|
|
3362
|
+
const { url } = yield this.getNewCredentialAndUrl({ isForNewDevice: true, authMethod });
|
|
3363
|
+
return url;
|
|
3364
|
+
});
|
|
3365
|
+
}
|
|
2723
3366
|
/**
|
|
2724
|
-
* Returns a Para Portal URL for logging in with a WebAuth passkey or
|
|
3367
|
+
* Returns a Para Portal URL for logging in with a WebAuth passkey, password, PIN or OTP.
|
|
2725
3368
|
* @param {Object} opts the options object
|
|
2726
3369
|
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
2727
3370
|
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
@@ -2747,6 +3390,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2747
3390
|
case "PASSWORD":
|
|
2748
3391
|
urlType = "loginPassword";
|
|
2749
3392
|
break;
|
|
3393
|
+
case "PIN":
|
|
3394
|
+
urlType = "loginPIN";
|
|
3395
|
+
break;
|
|
3396
|
+
case "BASIC_LOGIN":
|
|
3397
|
+
urlType = this.authInfo.authType === "externalWallet" ? "loginExternalWallet" : "loginOTP";
|
|
3398
|
+
break;
|
|
2750
3399
|
default:
|
|
2751
3400
|
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
2752
3401
|
}
|
|
@@ -2757,53 +3406,248 @@ const _ParaCore = class _ParaCore {
|
|
|
2757
3406
|
});
|
|
2758
3407
|
});
|
|
2759
3408
|
}
|
|
2760
|
-
|
|
3409
|
+
prepareLogin() {
|
|
2761
3410
|
return __async(this, null, function* () {
|
|
2762
|
-
|
|
2763
|
-
const
|
|
2764
|
-
|
|
3411
|
+
yield this.logout();
|
|
3412
|
+
const { sessionLookupId } = yield this.touchSession(true);
|
|
3413
|
+
if (!this.loginEncryptionKeyPair) {
|
|
3414
|
+
yield this.setLoginEncryptionKeyPair();
|
|
3415
|
+
}
|
|
3416
|
+
return sessionLookupId;
|
|
3417
|
+
});
|
|
3418
|
+
}
|
|
3419
|
+
signUpOrLogIn(_i) {
|
|
3420
|
+
return __async(this, null, function* () {
|
|
3421
|
+
var _j = _i, { auth } = _j, urlOptions = __objRest(_j, ["auth"]);
|
|
3422
|
+
let serverAuthState;
|
|
3423
|
+
try {
|
|
3424
|
+
serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
3425
|
+
} catch (error) {
|
|
3426
|
+
if (error.message.includes("max beta users reached")) {
|
|
3427
|
+
this.displayModalError(
|
|
3428
|
+
`50 user limit reached. [Go to Production.](https://docs.getpara.com/v2/general/checklist#go-live-checklist)`
|
|
3429
|
+
);
|
|
3430
|
+
}
|
|
3431
|
+
throw error;
|
|
3432
|
+
}
|
|
3433
|
+
const authInfo = serverAuthState.auth;
|
|
3434
|
+
if (this.fetchPregenWalletsOverride && (0, import_user_management_client.isPregenAuth)(authInfo)) {
|
|
3435
|
+
const { userShare } = yield this.fetchPregenWalletsOverride({ pregenId: authInfo });
|
|
3436
|
+
if (userShare) {
|
|
3437
|
+
yield this.setUserShare(userShare);
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadValues({}, urlOptions));
|
|
2765
3441
|
});
|
|
2766
3442
|
}
|
|
2767
|
-
verifyNewAccount(
|
|
3443
|
+
verifyNewAccount(_k) {
|
|
2768
3444
|
return __async(this, null, function* () {
|
|
2769
|
-
var
|
|
3445
|
+
var _l = _k, {
|
|
2770
3446
|
verificationCode
|
|
2771
|
-
} =
|
|
3447
|
+
} = _l, urlOptions = __objRest(_l, [
|
|
2772
3448
|
"verificationCode"
|
|
2773
3449
|
]);
|
|
2774
3450
|
this.assertIsAuthSet(["email", "phone"]);
|
|
2775
|
-
const userId = this.assertUserId();
|
|
2776
|
-
const serverAuthState = yield this.ctx.client.
|
|
3451
|
+
const userId = this.assertUserId({ allowGuestMode: true });
|
|
3452
|
+
const serverAuthState = yield this.ctx.client.verifyAccount(userId, {
|
|
2777
3453
|
verificationCode
|
|
2778
3454
|
});
|
|
3455
|
+
if (serverAuthState.stage === "login" || serverAuthState.stage === "done") {
|
|
3456
|
+
throw new Error("Account already exists.");
|
|
3457
|
+
}
|
|
3458
|
+
yield this.touchSession(true);
|
|
2779
3459
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2780
3460
|
});
|
|
2781
3461
|
}
|
|
3462
|
+
getLinkedAccounts() {
|
|
3463
|
+
return __async(this, arguments, function* ({
|
|
3464
|
+
withMetadata = false
|
|
3465
|
+
} = {}) {
|
|
3466
|
+
const userId = this.assertUserId();
|
|
3467
|
+
const { accounts } = yield this.ctx.client.getLinkedAccounts({ userId, withMetadata });
|
|
3468
|
+
return __spreadValues({
|
|
3469
|
+
userId
|
|
3470
|
+
}, accounts);
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
linkAccount(opts) {
|
|
3474
|
+
return __async(this, null, function* () {
|
|
3475
|
+
const { supportedAccountLinks = [...import_user_management_client.LINKED_ACCOUNT_TYPES] } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3476
|
+
let type, identifier, externalWallet, isPermitted;
|
|
3477
|
+
switch (true) {
|
|
3478
|
+
case "auth" in opts:
|
|
3479
|
+
{
|
|
3480
|
+
const authInfo = (0, import_user_management_client.extractAuthInfo)(opts.auth, { isRequired: true });
|
|
3481
|
+
if (authInfo.auth === this.authInfo.auth) {
|
|
3482
|
+
throw new Error(import_types.AccountLinkError.Conflict);
|
|
3483
|
+
}
|
|
3484
|
+
type = authInfo.authType.toUpperCase();
|
|
3485
|
+
identifier = authInfo.identifier;
|
|
3486
|
+
isPermitted = supportedAccountLinks.includes(type);
|
|
3487
|
+
}
|
|
3488
|
+
break;
|
|
3489
|
+
case "externalWallet" in opts:
|
|
3490
|
+
{
|
|
3491
|
+
externalWallet = opts.externalWallet;
|
|
3492
|
+
type = "EXTERNAL_WALLET";
|
|
3493
|
+
isPermitted = supportedAccountLinks.includes("EXTERNAL_WALLET") || supportedAccountLinks.includes(externalWallet.providerId);
|
|
3494
|
+
}
|
|
3495
|
+
break;
|
|
3496
|
+
case "type" in opts:
|
|
3497
|
+
{
|
|
3498
|
+
type = opts.type;
|
|
3499
|
+
if (type === "X") {
|
|
3500
|
+
type = "TWITTER";
|
|
3501
|
+
}
|
|
3502
|
+
isPermitted = supportedAccountLinks.includes(type);
|
|
3503
|
+
}
|
|
3504
|
+
break;
|
|
3505
|
+
default:
|
|
3506
|
+
throw new Error("Invalid parameters for linking account, must pass `auth` or `type` or `externalWallet`");
|
|
3507
|
+
}
|
|
3508
|
+
if (!isPermitted) {
|
|
3509
|
+
throw new Error(`Account linking for type '${type}' is not supported by the current API key configuration`);
|
|
3510
|
+
}
|
|
3511
|
+
const userId = this.assertUserId();
|
|
3512
|
+
const result = yield this.ctx.client.linkAccount(__spreadValues(__spreadValues({
|
|
3513
|
+
userId,
|
|
3514
|
+
type
|
|
3515
|
+
}, identifier ? { identifier } : {}), externalWallet ? { externalWallet } : {}));
|
|
3516
|
+
if ("isConflict" in result) {
|
|
3517
|
+
throw new Error(import_types.AccountLinkError.Conflict);
|
|
3518
|
+
}
|
|
3519
|
+
const { linkedAccountId, signatureVerificationMessage } = result;
|
|
3520
|
+
this.accountLinkInProgress = __spreadValues(__spreadValues({
|
|
3521
|
+
id: linkedAccountId,
|
|
3522
|
+
type,
|
|
3523
|
+
isComplete: false
|
|
3524
|
+
}, identifier ? { identifier } : {}), signatureVerificationMessage && externalWallet ? {
|
|
3525
|
+
externalWallet: __spreadProps(__spreadValues({}, externalWallet), {
|
|
3526
|
+
signatureVerificationMessage
|
|
3527
|
+
})
|
|
3528
|
+
} : {});
|
|
3529
|
+
return this.accountLinkInProgress;
|
|
3530
|
+
});
|
|
3531
|
+
}
|
|
3532
|
+
unlinkAccount(_0) {
|
|
3533
|
+
return __async(this, arguments, function* ({
|
|
3534
|
+
linkedAccountId
|
|
3535
|
+
}) {
|
|
3536
|
+
if (!linkedAccountId) {
|
|
3537
|
+
throw new Error("No linked account ID provided");
|
|
3538
|
+
}
|
|
3539
|
+
const userId = this.assertUserId();
|
|
3540
|
+
const accounts = yield this.ctx.client.unlinkAccount({ linkedAccountId, userId });
|
|
3541
|
+
return accounts;
|
|
3542
|
+
});
|
|
3543
|
+
}
|
|
3544
|
+
verifyLink() {
|
|
3545
|
+
return __async(this, arguments, function* (_m = {}) {
|
|
3546
|
+
var _n = _m, {
|
|
3547
|
+
accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
|
|
3548
|
+
} = _n, opts = __objRest(_n, [
|
|
3549
|
+
"accountLinkInProgress"
|
|
3550
|
+
]);
|
|
3551
|
+
try {
|
|
3552
|
+
const userId = this.assertUserId(), result = yield this.ctx.client.verifyLink(__spreadValues({
|
|
3553
|
+
linkedAccountId: accountLinkInProgress.id,
|
|
3554
|
+
userId
|
|
3555
|
+
}, opts));
|
|
3556
|
+
if ("isConflict" in result) {
|
|
3557
|
+
throw new Error(import_types.AccountLinkError.Conflict);
|
|
3558
|
+
}
|
|
3559
|
+
this.accountLinkInProgress = void 0;
|
|
3560
|
+
return result.accounts;
|
|
3561
|
+
} catch (e) {
|
|
3562
|
+
throw new Error(e.message === import_types.AccountLinkError.Conflict ? import_types.AccountLinkError.Conflict : e.message);
|
|
3563
|
+
}
|
|
3564
|
+
});
|
|
3565
|
+
}
|
|
3566
|
+
verifyEmailOrPhoneLink(_0) {
|
|
3567
|
+
return __async(this, arguments, function* ({
|
|
3568
|
+
verificationCode
|
|
3569
|
+
}) {
|
|
3570
|
+
const accounts = yield this.verifyLink({
|
|
3571
|
+
accountLinkInProgress: __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]),
|
|
3572
|
+
verificationCode
|
|
3573
|
+
});
|
|
3574
|
+
return accounts;
|
|
3575
|
+
});
|
|
3576
|
+
}
|
|
3577
|
+
getProfileBalance() {
|
|
3578
|
+
return __async(this, arguments, function* ({ config, refetch = false } = {}) {
|
|
3579
|
+
const { balance } = yield this.ctx.client.getProfileBalance({
|
|
3580
|
+
config,
|
|
3581
|
+
wallets: this.availableWallets.map(({ type, address }) => ({ type, address })),
|
|
3582
|
+
refetch
|
|
3583
|
+
});
|
|
3584
|
+
return balance;
|
|
3585
|
+
});
|
|
3586
|
+
}
|
|
3587
|
+
sendLoginCode() {
|
|
3588
|
+
return __async(this, null, function* () {
|
|
3589
|
+
const { userId } = yield this.ctx.client.sendLoginVerificationCode(this.authInfo);
|
|
3590
|
+
this.setUserId(userId);
|
|
3591
|
+
});
|
|
3592
|
+
}
|
|
3593
|
+
exportPrivateKey() {
|
|
3594
|
+
return __async(this, arguments, function* (args = {}) {
|
|
3595
|
+
let walletId = args == null ? void 0 : args.walletId;
|
|
3596
|
+
if (!(args == null ? void 0 : args.walletId)) {
|
|
3597
|
+
walletId = this.findWalletId(void 0, { forbidPregen: true, scheme: ["DKLS"] });
|
|
3598
|
+
}
|
|
3599
|
+
const wallet = this.wallets[walletId];
|
|
3600
|
+
if (this.externalWallets[walletId]) {
|
|
3601
|
+
throw new Error("Cannot export private key for an external wallet");
|
|
3602
|
+
}
|
|
3603
|
+
if (!wallet || !wallet.signer) {
|
|
3604
|
+
throw new Error("Wallet not found with id: " + walletId);
|
|
3605
|
+
}
|
|
3606
|
+
if (wallet.scheme !== "DKLS") {
|
|
3607
|
+
throw new Error("Cannot export private key for a Solana wallet");
|
|
3608
|
+
}
|
|
3609
|
+
if (wallet.isPregen && !!wallet.pregenIdentifier && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
3610
|
+
throw new Error("Cannot export private key for a pregenerated wallet");
|
|
3611
|
+
}
|
|
3612
|
+
if (args.shouldOpenPopup) {
|
|
3613
|
+
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.EXPORT_PRIVATE_KEY });
|
|
3614
|
+
}
|
|
3615
|
+
const exportPrivateKeyUrl = yield this.constructPortalUrl("exportPrivateKey", {
|
|
3616
|
+
pathId: walletId
|
|
3617
|
+
});
|
|
3618
|
+
if (args.shouldOpenPopup) {
|
|
3619
|
+
this.popupWindow.location.href = exportPrivateKeyUrl;
|
|
3620
|
+
}
|
|
3621
|
+
return {
|
|
3622
|
+
url: exportPrivateKeyUrl,
|
|
3623
|
+
popupWindow: this.popupWindow
|
|
3624
|
+
};
|
|
3625
|
+
});
|
|
3626
|
+
}
|
|
2782
3627
|
};
|
|
2783
3628
|
_authInfo = new WeakMap();
|
|
2784
|
-
_partner = new WeakMap();
|
|
2785
3629
|
_ParaCore_instances = new WeakSet();
|
|
2786
3630
|
assertPartner_fn = function() {
|
|
2787
3631
|
return __async(this, null, function* () {
|
|
2788
3632
|
var _a, _b;
|
|
2789
|
-
if (!
|
|
3633
|
+
if (!this.partner) {
|
|
2790
3634
|
yield this.touchSession();
|
|
2791
3635
|
}
|
|
2792
|
-
if (((_a =
|
|
2793
|
-
this.ctx.cosmosPrefix = (_b =
|
|
3636
|
+
if (((_a = this.partner) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== this.partner.cosmosPrefix) {
|
|
3637
|
+
this.ctx.cosmosPrefix = (_b = this.partner) == null ? void 0 : _b.cosmosPrefix;
|
|
2794
3638
|
}
|
|
2795
|
-
return
|
|
3639
|
+
return this.partner;
|
|
2796
3640
|
});
|
|
2797
3641
|
};
|
|
2798
3642
|
guestWalletIds_get = function() {
|
|
2799
3643
|
var _a, _b, _c;
|
|
2800
|
-
if (!((_a =
|
|
3644
|
+
if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
2801
3645
|
return {};
|
|
2802
3646
|
}
|
|
2803
3647
|
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
2804
3648
|
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
2805
3649
|
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
2806
|
-
return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) =>
|
|
3650
|
+
return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
2807
3651
|
var _a2;
|
|
2808
3652
|
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
2809
3653
|
}, {}));
|
|
@@ -2860,9 +3704,236 @@ setAuthInfo_fn = function(authInfo) {
|
|
|
2860
3704
|
};
|
|
2861
3705
|
getPartner_fn = function(partnerId) {
|
|
2862
3706
|
return __async(this, null, function* () {
|
|
3707
|
+
if (this.isPartnerOptional && !partnerId) {
|
|
3708
|
+
return void 0;
|
|
3709
|
+
}
|
|
2863
3710
|
const res = yield this.ctx.client.getPartner(partnerId);
|
|
2864
|
-
|
|
2865
|
-
return
|
|
3711
|
+
this.partner = res.data.partner;
|
|
3712
|
+
return this.partner;
|
|
3713
|
+
});
|
|
3714
|
+
};
|
|
3715
|
+
assertIsLinkingAccount_fn = function(types) {
|
|
3716
|
+
if (!this.accountLinkInProgress || this.accountLinkInProgress.isComplete) {
|
|
3717
|
+
throw new Error("no account linking in progress");
|
|
3718
|
+
}
|
|
3719
|
+
if (types && !types.includes(this.accountLinkInProgress.type)) {
|
|
3720
|
+
throw new Error(
|
|
3721
|
+
`account linking in progress for type ${this.accountLinkInProgress.type}, expected one of ${types.join(", ")}`
|
|
3722
|
+
);
|
|
3723
|
+
}
|
|
3724
|
+
return this.accountLinkInProgress;
|
|
3725
|
+
};
|
|
3726
|
+
assertIsLinkingAccountOrStart_fn = function(type) {
|
|
3727
|
+
return __async(this, null, function* () {
|
|
3728
|
+
if (this.accountLinkInProgress && !this.accountLinkInProgress.isComplete) {
|
|
3729
|
+
return __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, [type]);
|
|
3730
|
+
}
|
|
3731
|
+
return yield this.linkAccount({ type });
|
|
3732
|
+
});
|
|
3733
|
+
};
|
|
3734
|
+
getOAuthUrl_fn = function(_0) {
|
|
3735
|
+
return __async(this, arguments, function* ({
|
|
3736
|
+
method,
|
|
3737
|
+
appScheme,
|
|
3738
|
+
accountLinkInProgress,
|
|
3739
|
+
sessionLookupId,
|
|
3740
|
+
encryptionKey,
|
|
3741
|
+
portalCallbackParams
|
|
3742
|
+
}) {
|
|
3743
|
+
if (!accountLinkInProgress && !this.isPortal()) {
|
|
3744
|
+
return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
|
|
3745
|
+
}
|
|
3746
|
+
let portalSessionLookupId;
|
|
3747
|
+
if (this.isPortal()) {
|
|
3748
|
+
portalSessionLookupId = (yield this.touchSession(true)).sessionLookupId;
|
|
3749
|
+
}
|
|
3750
|
+
return (0, import_utils2.constructUrl)({
|
|
3751
|
+
base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
|
|
3752
|
+
path: `/auth/${method.toLowerCase()}`,
|
|
3753
|
+
params: __spreadProps(__spreadValues({
|
|
3754
|
+
apiKey: this.ctx.apiKey,
|
|
3755
|
+
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
3756
|
+
sessionLookupId,
|
|
3757
|
+
portalSessionLookupId,
|
|
3758
|
+
appScheme
|
|
3759
|
+
}, accountLinkInProgress ? {
|
|
3760
|
+
linkedAccountId: this.accountLinkInProgress.id
|
|
3761
|
+
} : {}), {
|
|
3762
|
+
callback: !accountLinkInProgress && (yield this.constructPortalUrl("oAuthCallback", __spreadValues({
|
|
3763
|
+
sessionId: sessionLookupId,
|
|
3764
|
+
oAuthMethod: method,
|
|
3765
|
+
appScheme,
|
|
3766
|
+
thisDevice: {
|
|
3767
|
+
sessionId: sessionLookupId,
|
|
3768
|
+
encryptionKey
|
|
3769
|
+
}
|
|
3770
|
+
}, this.isPortal() && { params: portalCallbackParams })))
|
|
3771
|
+
})
|
|
3772
|
+
});
|
|
3773
|
+
});
|
|
3774
|
+
};
|
|
3775
|
+
waitForLoginProcess_fn = function() {
|
|
3776
|
+
return __async(this, arguments, function* ({
|
|
3777
|
+
isCanceled = () => false,
|
|
3778
|
+
onCancel,
|
|
3779
|
+
onPoll,
|
|
3780
|
+
skipSessionRefresh = false,
|
|
3781
|
+
isSwitchingWallets = false
|
|
3782
|
+
} = {}) {
|
|
3783
|
+
this.devLog("[waitForLoginProcess] Starting", {
|
|
3784
|
+
isSwitchingWallets,
|
|
3785
|
+
skipSessionRefresh,
|
|
3786
|
+
isExternalWalletAuth: this.isExternalWalletAuth
|
|
3787
|
+
});
|
|
3788
|
+
const startedAt = Date.now();
|
|
3789
|
+
let originalCurrentWalletIdsHash;
|
|
3790
|
+
if (isSwitchingWallets) {
|
|
3791
|
+
this.devLog("[waitForLoginProcess] Wallet switching mode enabled");
|
|
3792
|
+
this.isSwitchingWallets = true;
|
|
3793
|
+
const session = yield this.touchSession();
|
|
3794
|
+
originalCurrentWalletIdsHash = session.currentWalletIdsHash;
|
|
3795
|
+
this.devLog("[waitForLoginProcess] Original wallet IDs hash", { originalCurrentWalletIdsHash });
|
|
3796
|
+
}
|
|
3797
|
+
return new Promise((resolve, reject) => {
|
|
3798
|
+
(() => __async(this, null, function* () {
|
|
3799
|
+
var _a;
|
|
3800
|
+
if (!this.isExternalWalletAuth && !isSwitchingWallets) {
|
|
3801
|
+
this.devLog("[waitForLoginProcess] Clearing external wallets");
|
|
3802
|
+
this.externalWallets = {};
|
|
3803
|
+
}
|
|
3804
|
+
let pollCount = 0;
|
|
3805
|
+
while (true) {
|
|
3806
|
+
pollCount++;
|
|
3807
|
+
this.devLog("[waitForLoginProcess] Poll iteration", {
|
|
3808
|
+
pollCount,
|
|
3809
|
+
elapsedMs: Date.now() - startedAt
|
|
3810
|
+
});
|
|
3811
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
3812
|
+
this.devLog("[waitForLoginProcess] Canceled or timed out", {
|
|
3813
|
+
wasCanceled: isCanceled(),
|
|
3814
|
+
timedOut: Date.now() - startedAt > constants.POLLING_TIMEOUT_MS,
|
|
3815
|
+
elapsedMs: Date.now() - startedAt
|
|
3816
|
+
});
|
|
3817
|
+
if (isSwitchingWallets) {
|
|
3818
|
+
this.isSwitchingWallets = false;
|
|
3819
|
+
} else {
|
|
3820
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
|
|
3821
|
+
}
|
|
3822
|
+
onCancel == null ? void 0 : onCancel();
|
|
3823
|
+
return reject("canceled");
|
|
3824
|
+
}
|
|
3825
|
+
yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
|
|
3826
|
+
try {
|
|
3827
|
+
this.devLog("[waitForLoginProcess] Touching session");
|
|
3828
|
+
let session = yield this.touchSession();
|
|
3829
|
+
this.devLog("[waitForLoginProcess] Session state", {
|
|
3830
|
+
isAuthenticated: session.isAuthenticated,
|
|
3831
|
+
currentWalletIdsHash: session.currentWalletIdsHash,
|
|
3832
|
+
needsWallet: session.needsWallet
|
|
3833
|
+
});
|
|
3834
|
+
const shouldContinuePolling = isSwitchingWallets ? originalCurrentWalletIdsHash === session.currentWalletIdsHash : !session.isAuthenticated;
|
|
3835
|
+
this.devLog("[waitForLoginProcess] Should continue polling", {
|
|
3836
|
+
shouldContinuePolling,
|
|
3837
|
+
isSwitchingWallets,
|
|
3838
|
+
originalCurrentWalletIdsHash,
|
|
3839
|
+
sessionCurrentWalletIdsHash: session.currentWalletIdsHash,
|
|
3840
|
+
isAuthenticated: session.isAuthenticated
|
|
3841
|
+
});
|
|
3842
|
+
if (shouldContinuePolling) {
|
|
3843
|
+
onPoll == null ? void 0 : onPoll();
|
|
3844
|
+
continue;
|
|
3845
|
+
}
|
|
3846
|
+
this.devLog("[waitForLoginProcess] Authentication check passed, setting up user");
|
|
3847
|
+
session = yield this.userSetupAfterLogin();
|
|
3848
|
+
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
3849
|
+
this.devLog("[waitForLoginProcess] User setup complete", { needsWallet });
|
|
3850
|
+
if (isSwitchingWallets) {
|
|
3851
|
+
const isWalletSwitchingComplete = originalCurrentWalletIdsHash !== session.currentWalletIdsHash;
|
|
3852
|
+
this.devLog("[waitForLoginProcess] Wallet switching check", {
|
|
3853
|
+
isWalletSwitchingComplete,
|
|
3854
|
+
originalHash: originalCurrentWalletIdsHash,
|
|
3855
|
+
sessionHash: session.currentWalletIdsHash
|
|
3856
|
+
});
|
|
3857
|
+
if (!isWalletSwitchingComplete) {
|
|
3858
|
+
onPoll == null ? void 0 : onPoll();
|
|
3859
|
+
continue;
|
|
3860
|
+
}
|
|
3861
|
+
} else if (!needsWallet) {
|
|
3862
|
+
this.devLog("[waitForLoginProcess] Checking wallet IDs", {
|
|
3863
|
+
currentWalletIdsArrayLength: this.currentWalletIdsArray.length
|
|
3864
|
+
});
|
|
3865
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
3866
|
+
this.devLog("[waitForLoginProcess] No wallet IDs yet, continuing to poll");
|
|
3867
|
+
onPoll == null ? void 0 : onPoll();
|
|
3868
|
+
continue;
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
this.devLog("[waitForLoginProcess] Getting transmission key shares");
|
|
3872
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
3873
|
+
this.devLog("[waitForLoginProcess] Transmission shares received", {
|
|
3874
|
+
shareCount: tempSharesRes.data.temporaryShares.length,
|
|
3875
|
+
shares: tempSharesRes.data.temporaryShares.map((s) => ({
|
|
3876
|
+
walletId: s.walletId,
|
|
3877
|
+
walletScheme: s.walletScheme
|
|
3878
|
+
}))
|
|
3879
|
+
});
|
|
3880
|
+
let hasSharesForCurrentWallets;
|
|
3881
|
+
if (!isSwitchingWallets && !this.isPortal()) {
|
|
3882
|
+
this.devLog("[waitForLoginProcess] Fetching wallets");
|
|
3883
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
3884
|
+
this.devLog("[waitForLoginProcess] Wallets fetched", {
|
|
3885
|
+
walletCount: fetchedWallets.length,
|
|
3886
|
+
wallets: fetchedWallets.map((w) => ({ id: w.id, type: w.type, scheme: w.scheme }))
|
|
3887
|
+
});
|
|
3888
|
+
hasSharesForCurrentWallets = tempSharesRes.data.temporaryShares.length === fetchedWallets.length;
|
|
3889
|
+
} else {
|
|
3890
|
+
hasSharesForCurrentWallets = this.currentWalletIdsArray.every(([walletId]) => {
|
|
3891
|
+
return tempSharesRes.data.temporaryShares.some((share) => share.walletId === walletId);
|
|
3892
|
+
});
|
|
3893
|
+
}
|
|
3894
|
+
this.devLog("[waitForLoginProcess] Checking shares for current wallets", {
|
|
3895
|
+
hasSharesForCurrentWallets,
|
|
3896
|
+
currentWalletIdsArray: this.currentWalletIdsArray,
|
|
3897
|
+
shares: tempSharesRes.data.temporaryShares.map((s) => ({
|
|
3898
|
+
walletId: s.walletId,
|
|
3899
|
+
walletScheme: s.walletScheme
|
|
3900
|
+
}))
|
|
3901
|
+
});
|
|
3902
|
+
if (hasSharesForCurrentWallets) {
|
|
3903
|
+
this.devLog("[waitForLoginProcess] Setting up after login");
|
|
3904
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
3905
|
+
this.devLog("[waitForLoginProcess] Setup after login complete");
|
|
3906
|
+
this.devLog("[waitForLoginProcess] Claiming pregen wallets");
|
|
3907
|
+
yield this.claimPregenWallets();
|
|
3908
|
+
this.devLog("[waitForLoginProcess] Pregen wallets claimed");
|
|
3909
|
+
const resp = {
|
|
3910
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
3911
|
+
partnerId: session.partnerId
|
|
3912
|
+
};
|
|
3913
|
+
this.devLog("[waitForLoginProcess] Login process complete", {
|
|
3914
|
+
needsWallet: resp.needsWallet,
|
|
3915
|
+
partnerId: resp.partnerId,
|
|
3916
|
+
walletCount: Object.values(this.wallets).length,
|
|
3917
|
+
isSwitchingWallets
|
|
3918
|
+
});
|
|
3919
|
+
if (isSwitchingWallets) {
|
|
3920
|
+
this.devLog("[waitForLoginProcess] Clearing wallet switching state");
|
|
3921
|
+
this.isSwitchingWallets = false;
|
|
3922
|
+
} else {
|
|
3923
|
+
this.devLog("[waitForLoginProcess] Dispatching LOGIN_EVENT");
|
|
3924
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp);
|
|
3925
|
+
}
|
|
3926
|
+
return resolve(resp);
|
|
3927
|
+
}
|
|
3928
|
+
this.devLog("[waitForLoginProcess] Not all shares available yet, continuing to poll");
|
|
3929
|
+
onPoll == null ? void 0 : onPoll();
|
|
3930
|
+
} catch (err) {
|
|
3931
|
+
console.error("[waitForLoginProcess] Error during polling iteration", err);
|
|
3932
|
+
onPoll == null ? void 0 : onPoll();
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
}))();
|
|
3936
|
+
});
|
|
2866
3937
|
});
|
|
2867
3938
|
};
|
|
2868
3939
|
createPregenWallet_fn = function(opts) {
|
|
@@ -2915,8 +3986,9 @@ createPregenWallet_fn = function(opts) {
|
|
|
2915
3986
|
_isCreateGuestWalletsPending = new WeakMap();
|
|
2916
3987
|
prepareAuthState_fn = function(_0) {
|
|
2917
3988
|
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
2918
|
-
|
|
2919
|
-
|
|
3989
|
+
var _a, _b;
|
|
3990
|
+
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))))) {
|
|
3991
|
+
opts.sessionLookupId = yield this.prepareLogin();
|
|
2920
3992
|
}
|
|
2921
3993
|
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
2922
3994
|
const authInfo = __spreadValues(__spreadValues({}, (0, import_user_management_client.extractAuthInfo)(auth, { isRequired: true })), Object.fromEntries(
|
|
@@ -2930,34 +4002,70 @@ prepareAuthState_fn = function(_0) {
|
|
|
2930
4002
|
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
2931
4003
|
yield this.assertIsAuthSet();
|
|
2932
4004
|
if (!!externalWallet) {
|
|
2933
|
-
yield this.setExternalWallet(externalWallet);
|
|
4005
|
+
yield this.setExternalWallet([externalWallet]);
|
|
2934
4006
|
}
|
|
2935
4007
|
if (!!userId) {
|
|
2936
4008
|
yield this.setUserId(userId);
|
|
2937
4009
|
}
|
|
2938
4010
|
let authState;
|
|
2939
4011
|
switch (serverAuthState.stage) {
|
|
4012
|
+
case "done": {
|
|
4013
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareDoneState_fn).call(this, serverAuthState);
|
|
4014
|
+
break;
|
|
4015
|
+
}
|
|
2940
4016
|
case "verify":
|
|
2941
|
-
authState = serverAuthState
|
|
4017
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareVerificationState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), {
|
|
4018
|
+
sessionLookupId: opts.sessionLookupId
|
|
4019
|
+
}));
|
|
2942
4020
|
break;
|
|
2943
4021
|
case "login":
|
|
4022
|
+
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
4023
|
+
authState = serverAuthState;
|
|
4024
|
+
break;
|
|
4025
|
+
}
|
|
2944
4026
|
authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
|
|
2945
4027
|
break;
|
|
2946
4028
|
case "signup":
|
|
4029
|
+
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
4030
|
+
authState = serverAuthState;
|
|
4031
|
+
break;
|
|
4032
|
+
}
|
|
2947
4033
|
authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
|
|
2948
4034
|
break;
|
|
2949
4035
|
}
|
|
2950
4036
|
return authState;
|
|
2951
4037
|
});
|
|
2952
4038
|
};
|
|
2953
|
-
|
|
4039
|
+
prepareDoneState_fn = function(doneState) {
|
|
2954
4040
|
return __async(this, null, function* () {
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
4041
|
+
let isSLOPossible = doneState.authMethods.includes(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
4042
|
+
this.isEnclaveUser = isSLOPossible;
|
|
4043
|
+
return doneState;
|
|
4044
|
+
});
|
|
4045
|
+
};
|
|
4046
|
+
prepareVerificationState_fn = function(_0, _1) {
|
|
4047
|
+
return __async(this, arguments, function* (verifyState, {
|
|
4048
|
+
useShortUrls: shorten = false,
|
|
4049
|
+
portalTheme,
|
|
4050
|
+
sessionLookupId
|
|
4051
|
+
}) {
|
|
4052
|
+
var _a;
|
|
4053
|
+
let isSLOPossible = false;
|
|
4054
|
+
if (verifyState.nextStage === "login") {
|
|
4055
|
+
isSLOPossible = verifyState.loginAuthMethods.includes(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
4056
|
+
} else if (verifyState.nextStage === "signup") {
|
|
4057
|
+
isSLOPossible = verifyState.signupAuthMethods.includes(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
2959
4058
|
}
|
|
2960
|
-
|
|
4059
|
+
this.isEnclaveUser = isSLOPossible;
|
|
4060
|
+
const isExternalWalletFullAuth = (_a = verifyState.externalWallet) == null ? void 0 : _a.withFullParaAuth;
|
|
4061
|
+
return __spreadValues(__spreadValues({}, verifyState), isSLOPossible || isExternalWalletFullAuth ? {
|
|
4062
|
+
loginUrl: yield this.getLoginUrl({
|
|
4063
|
+
authMethod: import_user_management_client.AuthMethod.BASIC_LOGIN,
|
|
4064
|
+
sessionId: sessionLookupId,
|
|
4065
|
+
shorten,
|
|
4066
|
+
portalTheme
|
|
4067
|
+
})
|
|
4068
|
+
} : {});
|
|
2961
4069
|
});
|
|
2962
4070
|
};
|
|
2963
4071
|
prepareLoginState_fn = function(_0, _1) {
|
|
@@ -2966,8 +4074,12 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
2966
4074
|
portalTheme,
|
|
2967
4075
|
sessionLookupId
|
|
2968
4076
|
}) {
|
|
2969
|
-
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
2970
|
-
|
|
4077
|
+
const _a = loginState, { loginAuthMethods = [], hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
|
|
4078
|
+
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);
|
|
4079
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
4080
|
+
isPasskeySupported,
|
|
4081
|
+
loginAuthMethods
|
|
4082
|
+
}), isPasskeyPossible ? {
|
|
2971
4083
|
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
2972
4084
|
passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
|
|
2973
4085
|
sessionId: sessionLookupId,
|
|
@@ -2978,28 +4090,41 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
2978
4090
|
shorten,
|
|
2979
4091
|
portalTheme
|
|
2980
4092
|
})
|
|
2981
|
-
} : {}),
|
|
4093
|
+
} : {}), isPasswordPossible ? {
|
|
2982
4094
|
passwordUrl: yield this.constructPortalUrl("loginPassword", {
|
|
2983
4095
|
sessionId: sessionLookupId,
|
|
2984
4096
|
shorten,
|
|
2985
|
-
portalTheme
|
|
4097
|
+
portalTheme,
|
|
4098
|
+
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
4099
|
+
})
|
|
4100
|
+
} : {}), isPINPossible ? {
|
|
4101
|
+
pinUrl: yield this.constructPortalUrl("loginPIN", {
|
|
4102
|
+
sessionId: sessionLookupId,
|
|
4103
|
+
shorten,
|
|
4104
|
+
portalTheme,
|
|
4105
|
+
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
2986
4106
|
})
|
|
2987
4107
|
} : {});
|
|
2988
4108
|
});
|
|
2989
4109
|
};
|
|
2990
4110
|
prepareSignUpState_fn = function(_0, _1) {
|
|
2991
4111
|
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
2992
|
-
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
2993
|
-
const
|
|
4112
|
+
const _a = serverSignupState, { signupAuthMethods = [] } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
4113
|
+
const isPasskeySupported = yield this.isPasskeySupported();
|
|
4114
|
+
const [isPasskey, isPassword, isPIN] = [
|
|
2994
4115
|
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY),
|
|
2995
|
-
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD)
|
|
4116
|
+
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) || !isPasskeySupported,
|
|
4117
|
+
signupAuthMethods.includes(import_user_management_client.AuthMethod.PIN)
|
|
2996
4118
|
];
|
|
2997
|
-
if (!isPasskey && !isPassword) {
|
|
4119
|
+
if (!isPasskey && !isPassword && !isPIN) {
|
|
2998
4120
|
throw new Error(
|
|
2999
|
-
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or
|
|
4121
|
+
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
|
|
3000
4122
|
);
|
|
3001
4123
|
}
|
|
3002
|
-
const signupState = authState
|
|
4124
|
+
const signupState = __spreadProps(__spreadValues({}, authState), {
|
|
4125
|
+
isPasskeySupported,
|
|
4126
|
+
signupAuthMethods
|
|
4127
|
+
});
|
|
3003
4128
|
if (isPasskey) {
|
|
3004
4129
|
const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
|
|
3005
4130
|
authMethod: "PASSKEY",
|
|
@@ -3017,6 +4142,15 @@ prepareSignUpState_fn = function(_0, _1) {
|
|
|
3017
4142
|
signupState.passwordUrl = passwordUrl;
|
|
3018
4143
|
signupState.passwordId = passwordId;
|
|
3019
4144
|
}
|
|
4145
|
+
if (isPIN) {
|
|
4146
|
+
const { url: pinUrl, credentialId: pinId } = yield this.getNewCredentialAndUrl({
|
|
4147
|
+
authMethod: "PIN",
|
|
4148
|
+
portalTheme,
|
|
4149
|
+
shorten
|
|
4150
|
+
});
|
|
4151
|
+
signupState.pinUrl = pinUrl;
|
|
4152
|
+
signupState.pinId = pinId;
|
|
4153
|
+
}
|
|
3020
4154
|
return signupState;
|
|
3021
4155
|
});
|
|
3022
4156
|
};
|