@getpara/core-sdk 1.12.0 → 2.0.0-alpha.10
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 +942 -975
- package/dist/cjs/constants.js +7 -1
- package/dist/cjs/index.js +15 -3
- package/dist/cjs/types/coreApi.js +74 -0
- package/dist/cjs/types/events.js +1 -0
- package/dist/cjs/types/index.js +4 -2
- package/dist/cjs/types/{params.js → methods.js} +2 -2
- package/dist/cjs/utils/autobind.js +41 -0
- package/dist/cjs/utils/formatting.js +0 -12
- package/dist/cjs/utils/index.js +10 -0
- package/dist/cjs/utils/json.js +37 -0
- package/dist/cjs/utils/listeners.js +2 -11
- package/dist/cjs/utils/phone.js +73 -0
- package/dist/cjs/utils/types.js +29 -0
- package/dist/cjs/utils/url.js +34 -2
- package/dist/cjs/utils/wallet.js +30 -17
- package/dist/esm/ParaCore.js +959 -980
- package/dist/esm/constants.js +5 -1
- package/dist/esm/index.js +12 -3
- package/dist/esm/types/coreApi.js +52 -0
- package/dist/esm/types/events.js +1 -0
- package/dist/esm/types/index.js +2 -1
- package/dist/esm/utils/autobind.js +19 -0
- package/dist/esm/utils/formatting.js +0 -10
- package/dist/esm/utils/index.js +5 -0
- package/dist/esm/utils/json.js +15 -0
- package/dist/esm/utils/listeners.js +2 -11
- package/dist/esm/utils/phone.js +39 -0
- package/dist/esm/utils/types.js +7 -0
- package/dist/esm/utils/url.js +15 -2
- package/dist/esm/utils/wallet.js +27 -16
- package/dist/types/ParaCore.d.ts +100 -391
- package/dist/types/PlatformUtils.d.ts +3 -3
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/external/userManagementClient.d.ts +1 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/types/config.d.ts +4 -24
- package/dist/types/types/coreApi.d.ts +475 -0
- package/dist/types/types/events.d.ts +4 -1
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/types/methods.d.ts +148 -0
- package/dist/types/types/onRamps.d.ts +3 -3
- package/dist/types/types/wallet.d.ts +4 -4
- package/dist/types/utils/autobind.d.ts +1 -0
- package/dist/types/utils/formatting.d.ts +2 -4
- package/dist/types/utils/index.d.ts +5 -0
- package/dist/types/utils/json.d.ts +1 -0
- package/dist/types/utils/onRamps.d.ts +3 -3
- package/dist/types/utils/phone.d.ts +11 -0
- package/dist/types/utils/types.d.ts +2 -0
- package/dist/types/utils/url.d.ts +2 -1
- package/dist/types/utils/wallet.d.ts +9 -7
- package/package.json +4 -3
- package/dist/types/types/params.d.ts +0 -73
- /package/dist/esm/types/{params.js → methods.js} +0 -0
package/dist/esm/ParaCore.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
__spreadProps,
|
|
9
9
|
__spreadValues
|
|
10
10
|
} from "./chunk-7B52C2XE.js";
|
|
11
|
-
var
|
|
11
|
+
var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, guestWalletIds_get, guestWalletIdsArray_get, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, createPregenWallet_fn, _isCreateGuestWalletsPending, prepareAuthState_fn, prepareLogin_fn, prepareLoginState_fn, prepareSignUpState_fn;
|
|
12
12
|
import { Buffer as NodeBuffer } from "buffer";
|
|
13
13
|
if (typeof global !== "undefined") {
|
|
14
14
|
global.Buffer = global.Buffer || NodeBuffer;
|
|
@@ -23,12 +23,17 @@ import {
|
|
|
23
23
|
AuthMethod,
|
|
24
24
|
PublicKeyStatus,
|
|
25
25
|
PublicKeyType,
|
|
26
|
-
WalletType,
|
|
27
|
-
WalletScheme,
|
|
28
|
-
OAuthMethod,
|
|
29
26
|
extractWalletRef,
|
|
30
27
|
PasswordStatus,
|
|
31
|
-
extractAuthInfo
|
|
28
|
+
extractAuthInfo,
|
|
29
|
+
isEmail,
|
|
30
|
+
isPhone,
|
|
31
|
+
isFarcaster,
|
|
32
|
+
isTelegram,
|
|
33
|
+
toPregenTypeAndId,
|
|
34
|
+
toPregenIds,
|
|
35
|
+
isExternalWallet,
|
|
36
|
+
WALLET_TYPES
|
|
32
37
|
} from "@getpara/user-management-client";
|
|
33
38
|
import forge from "node-forge";
|
|
34
39
|
const { pki, jsbn } = forge;
|
|
@@ -41,9 +46,10 @@ import {
|
|
|
41
46
|
PopupType,
|
|
42
47
|
ParaEvent
|
|
43
48
|
} from "./types/index.js";
|
|
44
|
-
import * as transmissionUtils from "./transmission/transmissionUtils.js";
|
|
45
49
|
import { sendRecoveryForShare } from "./shares/recovery.js";
|
|
46
50
|
import {
|
|
51
|
+
autoBind,
|
|
52
|
+
formatPhoneNumber,
|
|
47
53
|
constructUrl,
|
|
48
54
|
dispatchEvent,
|
|
49
55
|
entityToWallet,
|
|
@@ -54,15 +60,19 @@ import {
|
|
|
54
60
|
getSchemes,
|
|
55
61
|
isPregenIdentifierMatch,
|
|
56
62
|
isWalletSupported,
|
|
63
|
+
jsonParse,
|
|
57
64
|
migrateWallet,
|
|
58
65
|
newUuid,
|
|
59
|
-
|
|
66
|
+
setupListeners,
|
|
67
|
+
supportedWalletTypesEq,
|
|
60
68
|
truncateAddress,
|
|
61
|
-
WalletSchemeTypeMap
|
|
69
|
+
WalletSchemeTypeMap,
|
|
70
|
+
shortenUrl,
|
|
71
|
+
isServerAuthState,
|
|
72
|
+
splitPhoneNumber
|
|
62
73
|
} from "./utils/index.js";
|
|
63
|
-
import { TransactionReviewDenied,
|
|
74
|
+
import { TransactionReviewDenied, TransactionReviewTimeout } from "./errors.js";
|
|
64
75
|
import * as constants from "./constants.js";
|
|
65
|
-
import { setupListeners } from "./utils/listeners.js";
|
|
66
76
|
const _ParaCore = class _ParaCore {
|
|
67
77
|
/**
|
|
68
78
|
* Constructs a new `ParaCore` instance.
|
|
@@ -73,6 +83,9 @@ const _ParaCore = class _ParaCore {
|
|
|
73
83
|
*/
|
|
74
84
|
constructor(env, apiKey, opts) {
|
|
75
85
|
__privateAdd(this, _ParaCore_instances);
|
|
86
|
+
__privateAdd(this, _authInfo);
|
|
87
|
+
this.isNativePasskey = false;
|
|
88
|
+
__privateAdd(this, _partner);
|
|
76
89
|
this.isAwaitingAccountCreation = false;
|
|
77
90
|
this.isAwaitingLogin = false;
|
|
78
91
|
this.isAwaitingFarcaster = false;
|
|
@@ -81,14 +94,19 @@ const _ParaCore = class _ParaCore {
|
|
|
81
94
|
* 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.
|
|
82
95
|
*/
|
|
83
96
|
this.currentWalletIds = {};
|
|
84
|
-
|
|
85
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Wallets associated with the `ParaCore` instance.
|
|
99
|
+
*/
|
|
100
|
+
this.externalWallets = {};
|
|
86
101
|
this.localStorageGetItem = (key) => {
|
|
87
102
|
return this.platformUtils.localStorage.get(key);
|
|
88
103
|
};
|
|
89
104
|
this.localStorageSetItem = (key, value) => {
|
|
90
105
|
return this.platformUtils.localStorage.set(key, value);
|
|
91
106
|
};
|
|
107
|
+
this.localStorageRemoveItem = (key) => {
|
|
108
|
+
return this.platformUtils.localStorage.removeItem(key);
|
|
109
|
+
};
|
|
92
110
|
this.sessionStorageGetItem = (key) => {
|
|
93
111
|
return this.platformUtils.sessionStorage.get(key);
|
|
94
112
|
};
|
|
@@ -145,38 +163,41 @@ const _ParaCore = class _ParaCore {
|
|
|
145
163
|
}
|
|
146
164
|
};
|
|
147
165
|
this.initializeFromStorage = () => {
|
|
148
|
-
this.
|
|
149
|
-
this.
|
|
150
|
-
this.updatePhoneFromStorage();
|
|
166
|
+
this.updateExternalWalletsFromStorage();
|
|
167
|
+
this.updateAuthInfoFromStorage();
|
|
151
168
|
this.updateUserIdFromStorage();
|
|
152
|
-
this.updateTelegramUserIdFromStorage();
|
|
153
169
|
this.updateWalletsFromStorage();
|
|
154
170
|
this.updateWalletIdsFromStorage();
|
|
155
171
|
this.updateSessionCookieFromStorage();
|
|
156
172
|
this.updateLoginEncryptionKeyPairFromStorage();
|
|
157
|
-
this.updateExternalWalletsFromStorage();
|
|
158
173
|
};
|
|
159
|
-
this.
|
|
160
|
-
|
|
174
|
+
this.updateAuthInfoFromStorage = () => {
|
|
175
|
+
var _a;
|
|
176
|
+
const storageAuthInfo = this.localStorageGetItem(constants.LOCAL_STORAGE_AUTH_INFO) || void 0;
|
|
177
|
+
let authInfo = jsonParse(storageAuthInfo);
|
|
178
|
+
if (!authInfo) {
|
|
179
|
+
const authParams = {
|
|
180
|
+
email: this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL) || void 0,
|
|
181
|
+
phone: this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE) || void 0,
|
|
182
|
+
countryCode: this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE) || void 0,
|
|
183
|
+
farcasterUsername: this.localStorageGetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME) || void 0,
|
|
184
|
+
telegramUserId: this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0,
|
|
185
|
+
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
186
|
+
externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
|
|
187
|
+
};
|
|
188
|
+
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
189
|
+
}
|
|
190
|
+
__privateSet(this, _authInfo, authInfo);
|
|
161
191
|
};
|
|
162
192
|
this.updateUserIdFromStorage = () => {
|
|
163
193
|
this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
164
194
|
};
|
|
165
|
-
this.updatePhoneFromStorage = () => {
|
|
166
|
-
this.phone = this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE) || void 0;
|
|
167
|
-
};
|
|
168
|
-
this.updateCountryCodeFromStorage = () => {
|
|
169
|
-
this.countryCode = this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE) || void 0;
|
|
170
|
-
};
|
|
171
|
-
this.updateEmailFromStorage = () => {
|
|
172
|
-
this.email = this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL) || void 0;
|
|
173
|
-
};
|
|
174
195
|
this.updateWalletsFromStorage = () => __async(this, null, function* () {
|
|
175
196
|
var _a;
|
|
176
197
|
const _currentWalletIds = (_a = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
177
198
|
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
178
199
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
179
|
-
return Array.isArray(fromJson) ?
|
|
200
|
+
return Array.isArray(fromJson) ? WALLET_TYPES.reduce((acc, type) => {
|
|
180
201
|
const wallet = Object.values(this.wallets).find(
|
|
181
202
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
182
203
|
);
|
|
@@ -200,9 +221,9 @@ const _ParaCore = class _ParaCore {
|
|
|
200
221
|
this.updateWalletIdsFromStorage = () => {
|
|
201
222
|
var _a;
|
|
202
223
|
const _currentWalletIds = (_a = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
203
|
-
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
224
|
+
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
204
225
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
205
|
-
return Array.isArray(fromJson) ?
|
|
226
|
+
return Array.isArray(fromJson) ? WALLET_TYPES.reduce((acc, type) => {
|
|
206
227
|
const wallet = Object.values(this.wallets).find(
|
|
207
228
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
208
229
|
);
|
|
@@ -237,12 +258,16 @@ const _ParaCore = class _ParaCore {
|
|
|
237
258
|
* @deprecated alias for `createWalletPerType`
|
|
238
259
|
**/
|
|
239
260
|
this.createWalletPerMissingType = this.createWalletPerType;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
261
|
+
__privateAdd(this, _isCreateGuestWalletsPending, false);
|
|
262
|
+
this.getWalletBalance = (_0) => __async(this, [_0], function* ({
|
|
263
|
+
walletId,
|
|
264
|
+
rpcUrl
|
|
265
|
+
}) {
|
|
266
|
+
return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
|
|
245
267
|
});
|
|
268
|
+
if (!apiKey) {
|
|
269
|
+
throw new Error("A Para API key is required.");
|
|
270
|
+
}
|
|
246
271
|
if (!opts) opts = {};
|
|
247
272
|
let isE2E = false;
|
|
248
273
|
if (env === "E2E") {
|
|
@@ -301,49 +326,27 @@ const _ParaCore = class _ParaCore {
|
|
|
301
326
|
useDKLS: opts.useDKLSForCreation || !opts.offloadMPCComputationURL,
|
|
302
327
|
disableWebSockets: !!opts.disableWebSockets,
|
|
303
328
|
wasmOverride: opts.wasmOverride,
|
|
304
|
-
cosmosPrefix: this.cosmosPrefix,
|
|
305
329
|
isE2E
|
|
306
330
|
};
|
|
307
331
|
if (opts.offloadMPCComputationURL) {
|
|
308
332
|
this.ctx.mpcComputationClient = mpcComputationClient.initClient(opts.offloadMPCComputationURL, opts.disableWorkers);
|
|
309
333
|
}
|
|
310
|
-
try {
|
|
311
|
-
__privateSet(this, _supportedWalletTypes, opts.supportedWalletTypes ? (() => {
|
|
312
|
-
if (Object.values(opts.supportedWalletTypes).every(
|
|
313
|
-
(config) => !!config && typeof config === "object" && config.optional
|
|
314
|
-
)) {
|
|
315
|
-
throw new Error("at least one wallet type must be non-optional");
|
|
316
|
-
}
|
|
317
|
-
if (!Object.keys(opts.supportedWalletTypes).every((type) => Object.values(WalletType).includes(type))) {
|
|
318
|
-
throw new Error("unsupported wallet type");
|
|
319
|
-
}
|
|
320
|
-
__privateSet(this, _supportedWalletTypesOpt, opts.supportedWalletTypes);
|
|
321
|
-
return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
|
|
322
|
-
var _a;
|
|
323
|
-
if (!value) {
|
|
324
|
-
return acc;
|
|
325
|
-
}
|
|
326
|
-
if (key === WalletType.COSMOS && typeof value === "object" && !!value.prefix) {
|
|
327
|
-
this.cosmosPrefix = value.prefix;
|
|
328
|
-
}
|
|
329
|
-
return [...acc, { type: key, optional: value === true ? false : (_a = value.optional) != null ? _a : false }];
|
|
330
|
-
}, []);
|
|
331
|
-
})() : void 0);
|
|
332
|
-
} catch (e) {
|
|
333
|
-
__privateSet(this, _supportedWalletTypes, void 0);
|
|
334
|
-
}
|
|
335
334
|
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
336
335
|
return;
|
|
337
336
|
}
|
|
338
337
|
this.initializeFromStorage();
|
|
339
338
|
setupListeners.bind(this)();
|
|
339
|
+
autoBind(this);
|
|
340
340
|
if (env !== Environment.PROD) {
|
|
341
341
|
this.wrapMethodsWithErrorTracking([
|
|
342
|
-
"
|
|
343
|
-
"
|
|
344
|
-
"
|
|
345
|
-
"
|
|
346
|
-
"
|
|
342
|
+
"signUpOrLogIn",
|
|
343
|
+
"verifyNewAccount",
|
|
344
|
+
"waitForLogin",
|
|
345
|
+
"waitForSignup",
|
|
346
|
+
"waitForWalletCreation",
|
|
347
|
+
"verifyOAuth",
|
|
348
|
+
"verifyTelegram",
|
|
349
|
+
"verifyFarcaster",
|
|
347
350
|
"createPregenWallet",
|
|
348
351
|
"claimPregenWallets",
|
|
349
352
|
"signMessage",
|
|
@@ -351,35 +354,75 @@ const _ParaCore = class _ParaCore {
|
|
|
351
354
|
]);
|
|
352
355
|
}
|
|
353
356
|
}
|
|
354
|
-
get
|
|
355
|
-
return
|
|
357
|
+
get authInfo() {
|
|
358
|
+
return __privateGet(this, _authInfo);
|
|
356
359
|
}
|
|
357
|
-
get
|
|
358
|
-
|
|
360
|
+
get email() {
|
|
361
|
+
var _a;
|
|
362
|
+
return isEmail((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.email : void 0;
|
|
359
363
|
}
|
|
360
|
-
get
|
|
361
|
-
|
|
364
|
+
get phone() {
|
|
365
|
+
var _a;
|
|
366
|
+
return isPhone((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.phone : void 0;
|
|
362
367
|
}
|
|
363
|
-
get
|
|
364
|
-
|
|
368
|
+
get farcasterUsername() {
|
|
369
|
+
var _a;
|
|
370
|
+
return isFarcaster((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.farcasterUsername : void 0;
|
|
371
|
+
}
|
|
372
|
+
get telegramUserId() {
|
|
373
|
+
var _a;
|
|
374
|
+
return isTelegram((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.telegramUserId : void 0;
|
|
365
375
|
}
|
|
366
376
|
get externalWalletWithParaAuth() {
|
|
367
377
|
const externalWallets = Object.values(this.externalWallets);
|
|
368
378
|
return externalWallets.find((w) => w.isExternalWithParaAuth);
|
|
369
379
|
}
|
|
380
|
+
get externalWalletConnectionType() {
|
|
381
|
+
if (this.isExternalWalletAuth) {
|
|
382
|
+
return "AUTHENTICATED";
|
|
383
|
+
} else if (!!Object.keys(this.externalWallets).length) {
|
|
384
|
+
return "CONNECTION_ONLY";
|
|
385
|
+
}
|
|
386
|
+
return "NONE";
|
|
387
|
+
}
|
|
388
|
+
get isEmail() {
|
|
389
|
+
var _a;
|
|
390
|
+
return isEmail((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
391
|
+
}
|
|
392
|
+
get isPhone() {
|
|
393
|
+
var _a;
|
|
394
|
+
return isPhone((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
395
|
+
}
|
|
396
|
+
get isFarcaster() {
|
|
397
|
+
var _a;
|
|
398
|
+
return isFarcaster((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
399
|
+
}
|
|
400
|
+
get isTelegram() {
|
|
401
|
+
var _a;
|
|
402
|
+
return isTelegram((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
403
|
+
}
|
|
370
404
|
get isExternalWalletAuth() {
|
|
371
|
-
|
|
405
|
+
var _a;
|
|
406
|
+
return isExternalWallet((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
|
|
407
|
+
}
|
|
408
|
+
get partnerId() {
|
|
409
|
+
var _a;
|
|
410
|
+
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id;
|
|
372
411
|
}
|
|
373
412
|
get currentWalletIdsArray() {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
413
|
+
var _a, _b;
|
|
414
|
+
return ((_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
415
|
+
(acc, { type }) => {
|
|
416
|
+
var _a2;
|
|
417
|
+
return [
|
|
418
|
+
...acc,
|
|
419
|
+
...((_a2 = this.currentWalletIds[type]) != null ? _a2 : []).map((id) => {
|
|
420
|
+
return [id, type];
|
|
421
|
+
})
|
|
422
|
+
];
|
|
423
|
+
},
|
|
424
|
+
[]
|
|
425
|
+
);
|
|
383
426
|
}
|
|
384
427
|
get currentWalletIdsUnique() {
|
|
385
428
|
return [...new Set(Object.values(this.currentWalletIds).flat())];
|
|
@@ -404,17 +447,23 @@ const _ParaCore = class _ParaCore {
|
|
|
404
447
|
* Whether the instance has multiple wallets connected.
|
|
405
448
|
*/
|
|
406
449
|
get isMultiWallet() {
|
|
407
|
-
return this.currentWalletIdsArray.length > 1;
|
|
450
|
+
return this.currentWalletIdsArray.length > 1 || __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 1;
|
|
408
451
|
}
|
|
409
452
|
get isNoWalletConfig() {
|
|
410
|
-
|
|
453
|
+
var _a;
|
|
454
|
+
return !!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) && __privateGet(this, _partner).supportedWalletTypes.length === 0;
|
|
411
455
|
}
|
|
412
456
|
get supportedWalletTypes() {
|
|
457
|
+
var _a, _b;
|
|
458
|
+
return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
459
|
+
}
|
|
460
|
+
get cosmosPrefix() {
|
|
413
461
|
var _a;
|
|
414
|
-
return (_a = __privateGet(this,
|
|
462
|
+
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
|
|
415
463
|
}
|
|
416
464
|
get isWalletTypeEnabled() {
|
|
417
|
-
|
|
465
|
+
var _a;
|
|
466
|
+
return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
418
467
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
419
468
|
}, {});
|
|
420
469
|
}
|
|
@@ -463,7 +512,7 @@ const _ParaCore = class _ParaCore {
|
|
|
463
512
|
}
|
|
464
513
|
isWalletSupported(wallet) {
|
|
465
514
|
var _a, _b;
|
|
466
|
-
return !
|
|
515
|
+
return !((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = __privateGet(this, _partner).supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
467
516
|
}
|
|
468
517
|
isWalletOwned(wallet) {
|
|
469
518
|
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;
|
|
@@ -479,7 +528,7 @@ const _ParaCore = class _ParaCore {
|
|
|
479
528
|
));
|
|
480
529
|
}
|
|
481
530
|
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
482
|
-
var _a;
|
|
531
|
+
var _a, _b;
|
|
483
532
|
let error;
|
|
484
533
|
if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
|
|
485
534
|
return true;
|
|
@@ -489,15 +538,15 @@ const _ParaCore = class _ParaCore {
|
|
|
489
538
|
} else {
|
|
490
539
|
const wallet = this.wallets[walletId];
|
|
491
540
|
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
492
|
-
if (forbidPregen && isUnclaimed) {
|
|
541
|
+
if (forbidPregen && isUnclaimed && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
493
542
|
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
494
543
|
} else if (!isOwned && !isUnclaimed) {
|
|
495
544
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
496
545
|
} else if (!this.isWalletSupported(wallet)) {
|
|
497
|
-
error = `wallet with id ${wallet
|
|
546
|
+
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || []).map(({ type }) => type).join(", ")}`;
|
|
498
547
|
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
499
|
-
var _a2,
|
|
500
|
-
return (
|
|
548
|
+
var _a2, _b2;
|
|
549
|
+
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
501
550
|
}))) {
|
|
502
551
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
|
|
503
552
|
} else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
|
|
@@ -517,14 +566,17 @@ const _ParaCore = class _ParaCore {
|
|
|
517
566
|
* @param {string} walletId the ID of the wallet address to display.
|
|
518
567
|
* @param {object} options additional options for formatting the address.
|
|
519
568
|
* @param {boolean} options.truncate whether to truncate the address.
|
|
520
|
-
* @param {
|
|
569
|
+
* @param {TWalletType} options.addressType the type of address to display.
|
|
521
570
|
* @returns the formatted address
|
|
522
571
|
*/
|
|
523
572
|
getDisplayAddress(walletId, options = {}) {
|
|
524
|
-
var _a, _b;
|
|
573
|
+
var _a, _b, _c, _d;
|
|
525
574
|
if (this.externalWallets[walletId]) {
|
|
526
575
|
const wallet2 = this.externalWallets[walletId];
|
|
527
|
-
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, {
|
|
576
|
+
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, {
|
|
577
|
+
prefix: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix,
|
|
578
|
+
targetLength: options.targetLength
|
|
579
|
+
}) : wallet2.address;
|
|
528
580
|
}
|
|
529
581
|
const wallet = this.findWallet(walletId, options.addressType);
|
|
530
582
|
if (!wallet) {
|
|
@@ -533,8 +585,8 @@ const _ParaCore = class _ParaCore {
|
|
|
533
585
|
let str;
|
|
534
586
|
let prefix;
|
|
535
587
|
switch (wallet.type) {
|
|
536
|
-
case
|
|
537
|
-
prefix = (
|
|
588
|
+
case "COSMOS":
|
|
589
|
+
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
538
590
|
str = getCosmosAddress(wallet.publicKey, prefix);
|
|
539
591
|
break;
|
|
540
592
|
default:
|
|
@@ -567,8 +619,24 @@ const _ParaCore = class _ParaCore {
|
|
|
567
619
|
}
|
|
568
620
|
constructPortalUrl(_0) {
|
|
569
621
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
570
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
571
|
-
const
|
|
622
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
623
|
+
const [isCreate, isLogin, isOnRamp] = [
|
|
624
|
+
["createAuth", "createPassword"].includes(type),
|
|
625
|
+
["loginAuth", "loginPassword"].includes(type),
|
|
626
|
+
type === "onRamp"
|
|
627
|
+
];
|
|
628
|
+
if (isCreate || isLogin) {
|
|
629
|
+
this.assertIsAuthSet();
|
|
630
|
+
}
|
|
631
|
+
let sessionId = opts.sessionId;
|
|
632
|
+
if ((isLogin || isOnRamp) && !sessionId) {
|
|
633
|
+
const session = yield this.touchSession(true);
|
|
634
|
+
sessionId = session.sessionId;
|
|
635
|
+
}
|
|
636
|
+
if (!this.loginEncryptionKeyPair) {
|
|
637
|
+
yield this.setLoginEncryptionKeyPair();
|
|
638
|
+
}
|
|
639
|
+
const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL();
|
|
572
640
|
let path;
|
|
573
641
|
switch (type) {
|
|
574
642
|
case "createPassword": {
|
|
@@ -599,61 +667,55 @@ const _ParaCore = class _ParaCore {
|
|
|
599
667
|
throw new Error(`invalid URL type ${type}`);
|
|
600
668
|
}
|
|
601
669
|
}
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
const partner = opts.partnerId ? (_a = (yield this.ctx.client.getPartner(opts.partnerId)).data) == null ? void 0 : _a.partner : void 0;
|
|
670
|
+
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
671
|
+
const thisDevice = (_a = opts.thisDevice) != null ? _a : {
|
|
672
|
+
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
673
|
+
sessionId
|
|
674
|
+
};
|
|
608
675
|
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
609
676
|
apiKey: this.ctx.apiKey,
|
|
610
|
-
partnerId:
|
|
611
|
-
portalFont: ((_b = opts.
|
|
612
|
-
portalBorderRadius: ((_d = opts.
|
|
613
|
-
portalThemeMode: ((_f = opts.
|
|
614
|
-
portalAccentColor: ((_h = opts.
|
|
615
|
-
portalForegroundColor: ((_j = opts.
|
|
616
|
-
portalBackgroundColor: ((_l = opts.
|
|
677
|
+
partnerId: partner.id,
|
|
678
|
+
portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
|
|
679
|
+
portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
|
|
680
|
+
portalThemeMode: ((_f = opts.portalTheme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
|
|
681
|
+
portalAccentColor: ((_h = opts.portalTheme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
|
|
682
|
+
portalForegroundColor: ((_j = opts.portalTheme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
|
|
683
|
+
portalBackgroundColor: ((_l = opts.portalTheme) == null ? void 0 : _l.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_m = this.portalTheme) == null ? void 0 : _m.backgroundColor),
|
|
617
684
|
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
618
685
|
portalTextColor: this.portalTextColor,
|
|
619
686
|
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
620
|
-
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
} : {}),
|
|
633
|
-
|
|
687
|
+
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
688
|
+
}, isCreate || isLogin ? __spreadProps(__spreadValues({
|
|
689
|
+
authInfo: JSON.stringify(this.authInfo)
|
|
690
|
+
}, isPhone(this.authInfo.auth) ? splitPhoneNumber(this.authInfo.auth.phone) : this.authInfo.auth), {
|
|
691
|
+
pfpUrl: this.authInfo.pfpUrl,
|
|
692
|
+
displayName: this.authInfo.displayName
|
|
693
|
+
}) : {}), isOnRamp ? { sessionId } : {}), isLogin ? __spreadProps(__spreadValues({
|
|
694
|
+
sessionId: thisDevice.sessionId,
|
|
695
|
+
encryptionKey: thisDevice.encryptionKey
|
|
696
|
+
}, opts.newDevice ? {
|
|
697
|
+
newDeviceSessionLookupId: opts.newDevice.sessionId,
|
|
698
|
+
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
699
|
+
} : {}), {
|
|
700
|
+
pregenIds: JSON.stringify(this.pregenIds)
|
|
701
|
+
}) : {}), opts.params || {});
|
|
702
|
+
const url = constructUrl({ base, path, params });
|
|
703
|
+
if (opts.shorten) {
|
|
704
|
+
return shortenUrl(this.ctx, url);
|
|
705
|
+
}
|
|
706
|
+
return url;
|
|
634
707
|
});
|
|
635
708
|
}
|
|
636
709
|
touchSession(regenerate = false) {
|
|
637
710
|
return __async(this, null, function* () {
|
|
638
|
-
|
|
639
|
-
this.
|
|
640
|
-
|
|
711
|
+
var _a, _b, _c;
|
|
712
|
+
const session = yield this.ctx.client.touchSession(regenerate);
|
|
713
|
+
if (!__privateGet(this, _partner) || ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) !== session.partnerId || !supportedWalletTypesEq(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
|
|
714
|
+
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
715
|
+
}
|
|
716
|
+
return session;
|
|
641
717
|
});
|
|
642
718
|
}
|
|
643
|
-
setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
|
|
644
|
-
if (supportedWalletTypes && !__privateGet(this, _supportedWalletTypes)) {
|
|
645
|
-
__privateSet(this, _supportedWalletTypes, supportedWalletTypes);
|
|
646
|
-
Object.keys(this.currentWalletIds).forEach((type) => {
|
|
647
|
-
var _a;
|
|
648
|
-
if (!((_a = __privateGet(this, _supportedWalletTypes)) == null ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
|
|
649
|
-
delete this.currentWalletIds[type];
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
if (cosmosPrefix && !this.cosmosPrefix) {
|
|
654
|
-
this.cosmosPrefix = cosmosPrefix;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
719
|
getVerificationEmailProps() {
|
|
658
720
|
return {
|
|
659
721
|
brandColor: this.emailPrimaryColor,
|
|
@@ -683,12 +745,26 @@ const _ParaCore = class _ParaCore {
|
|
|
683
745
|
*/
|
|
684
746
|
init() {
|
|
685
747
|
return __async(this, null, function* () {
|
|
686
|
-
var _a;
|
|
687
|
-
this.email = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL)) || void 0;
|
|
688
|
-
this.countryCode = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE)) || void 0;
|
|
689
|
-
this.phone = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE)) || void 0;
|
|
748
|
+
var _a, _b;
|
|
690
749
|
this.userId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID)) || void 0;
|
|
691
|
-
|
|
750
|
+
const storageAuthInfo = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_AUTH_INFO)) || void 0;
|
|
751
|
+
const stringExternalWallets = yield this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
752
|
+
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
753
|
+
yield this.setExternalWallets(_externalWallets);
|
|
754
|
+
let authInfo = jsonParse(storageAuthInfo);
|
|
755
|
+
if (!authInfo) {
|
|
756
|
+
const authParams = {
|
|
757
|
+
email: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL)) || void 0,
|
|
758
|
+
phone: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE)) || void 0,
|
|
759
|
+
countryCode: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE)) || void 0,
|
|
760
|
+
farcasterUsername: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME)) || void 0,
|
|
761
|
+
telegramUserId: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0,
|
|
762
|
+
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
763
|
+
externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
|
|
764
|
+
};
|
|
765
|
+
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
766
|
+
}
|
|
767
|
+
__privateSet(this, _authInfo, authInfo);
|
|
692
768
|
const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_WALLETS);
|
|
693
769
|
const _wallets = JSON.parse(stringWallets || "{}");
|
|
694
770
|
const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_ED25519_WALLETS);
|
|
@@ -701,10 +777,10 @@ const _ParaCore = class _ParaCore {
|
|
|
701
777
|
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
|
|
702
778
|
}, {}));
|
|
703
779
|
yield this.setWallets(wallets);
|
|
704
|
-
const _currentWalletIds = (
|
|
780
|
+
const _currentWalletIds = (_b = yield this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _b : void 0;
|
|
705
781
|
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
706
782
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
707
|
-
return Array.isArray(fromJson) ?
|
|
783
|
+
return Array.isArray(fromJson) ? WALLET_TYPES.reduce((acc, type) => {
|
|
708
784
|
const wallet = Object.values(this.wallets).find(
|
|
709
785
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
710
786
|
);
|
|
@@ -720,21 +796,42 @@ const _ParaCore = class _ParaCore {
|
|
|
720
796
|
if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
|
|
721
797
|
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
722
798
|
}
|
|
723
|
-
const stringExternalWallets = yield this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
724
|
-
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
725
|
-
yield this.setExternalWallets(_externalWallets);
|
|
726
799
|
setupListeners.bind(this)();
|
|
727
800
|
yield this.touchSession();
|
|
728
801
|
});
|
|
729
802
|
}
|
|
803
|
+
setAuth(_0) {
|
|
804
|
+
return __async(this, arguments, function* (auth, { extras = {}, userId } = {}) {
|
|
805
|
+
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), extras || {});
|
|
806
|
+
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
807
|
+
if (!!userId) {
|
|
808
|
+
yield this.setUserId(userId);
|
|
809
|
+
}
|
|
810
|
+
return __privateGet(this, _authInfo);
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
assertUserId() {
|
|
814
|
+
if (!this.userId) {
|
|
815
|
+
throw new Error("no userId is set");
|
|
816
|
+
}
|
|
817
|
+
return this.userId;
|
|
818
|
+
}
|
|
819
|
+
assertIsAuthSet(allowed) {
|
|
820
|
+
if (!__privateGet(this, _authInfo)) {
|
|
821
|
+
throw new Error("auth is not set");
|
|
822
|
+
}
|
|
823
|
+
if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
|
|
824
|
+
throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
|
|
825
|
+
}
|
|
826
|
+
return __privateGet(this, _authInfo);
|
|
827
|
+
}
|
|
730
828
|
/**
|
|
731
829
|
* Sets the email associated with the `ParaCore` instance.
|
|
732
830
|
* @param email - Email to set.
|
|
733
831
|
*/
|
|
734
832
|
setEmail(email) {
|
|
735
833
|
return __async(this, null, function* () {
|
|
736
|
-
this.email
|
|
737
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_EMAIL, email);
|
|
834
|
+
yield this.setAuth({ email });
|
|
738
835
|
});
|
|
739
836
|
}
|
|
740
837
|
/**
|
|
@@ -743,8 +840,7 @@ const _ParaCore = class _ParaCore {
|
|
|
743
840
|
*/
|
|
744
841
|
setTelegramUserId(telegramUserId) {
|
|
745
842
|
return __async(this, null, function* () {
|
|
746
|
-
this.telegramUserId
|
|
747
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
|
|
843
|
+
yield this.setAuth({ telegramUserId });
|
|
748
844
|
});
|
|
749
845
|
}
|
|
750
846
|
/**
|
|
@@ -754,10 +850,7 @@ const _ParaCore = class _ParaCore {
|
|
|
754
850
|
*/
|
|
755
851
|
setPhoneNumber(phone, countryCode) {
|
|
756
852
|
return __async(this, null, function* () {
|
|
757
|
-
this.phone
|
|
758
|
-
this.countryCode = countryCode;
|
|
759
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_PHONE, phone);
|
|
760
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_COUNTRY_CODE, countryCode);
|
|
853
|
+
yield this.setAuth({ phone: formatPhoneNumber(phone, countryCode) });
|
|
761
854
|
});
|
|
762
855
|
}
|
|
763
856
|
/**
|
|
@@ -766,8 +859,7 @@ const _ParaCore = class _ParaCore {
|
|
|
766
859
|
*/
|
|
767
860
|
setFarcasterUsername(farcasterUsername) {
|
|
768
861
|
return __async(this, null, function* () {
|
|
769
|
-
this.farcasterUsername
|
|
770
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
|
|
862
|
+
yield this.setAuth({ farcasterUsername });
|
|
771
863
|
});
|
|
772
864
|
}
|
|
773
865
|
/**
|
|
@@ -852,6 +944,9 @@ const _ParaCore = class _ParaCore {
|
|
|
852
944
|
getUserId() {
|
|
853
945
|
return this.userId;
|
|
854
946
|
}
|
|
947
|
+
getAuthInfo() {
|
|
948
|
+
return this.authInfo;
|
|
949
|
+
}
|
|
855
950
|
/**
|
|
856
951
|
* Gets the email associated with the `ParaCore` instance.
|
|
857
952
|
* @returns - email associated with the `ParaCore` instance.
|
|
@@ -859,22 +954,12 @@ const _ParaCore = class _ParaCore {
|
|
|
859
954
|
getEmail() {
|
|
860
955
|
return this.email;
|
|
861
956
|
}
|
|
862
|
-
/**
|
|
863
|
-
* Gets the phone object associated with the `ParaCore` instance.
|
|
864
|
-
* @returns - phone object with phone number and country code associated with the `ParaCore` instance.
|
|
865
|
-
*/
|
|
866
|
-
getPhone() {
|
|
867
|
-
return { phone: this.phone, countryCode: this.countryCode };
|
|
868
|
-
}
|
|
869
957
|
/**
|
|
870
958
|
* Gets the formatted phone number associated with the `ParaCore` instance.
|
|
871
959
|
* @returns - formatted phone number associated with the `ParaCore` instance.
|
|
872
960
|
*/
|
|
873
961
|
getPhoneNumber() {
|
|
874
|
-
|
|
875
|
-
return void 0;
|
|
876
|
-
}
|
|
877
|
-
return normalizePhoneNumber(this.countryCode, this.phone);
|
|
962
|
+
return this.phone;
|
|
878
963
|
}
|
|
879
964
|
/**
|
|
880
965
|
* Gets the farcaster username associated with the `ParaCore` instance.
|
|
@@ -913,9 +998,7 @@ const _ParaCore = class _ParaCore {
|
|
|
913
998
|
if (!(yield this.isSessionActive()) || !this.userId) {
|
|
914
999
|
throw new Error("no signed-in user");
|
|
915
1000
|
}
|
|
916
|
-
const {
|
|
917
|
-
data: { partnerId }
|
|
918
|
-
} = yield this.touchSession();
|
|
1001
|
+
const { partnerId } = yield this.touchSession();
|
|
919
1002
|
const { accountMetadata } = yield this.ctx.client.getAccountMetadata(this.userId, partnerId);
|
|
920
1003
|
return accountMetadata;
|
|
921
1004
|
});
|
|
@@ -973,8 +1056,10 @@ const _ParaCore = class _ParaCore {
|
|
|
973
1056
|
}
|
|
974
1057
|
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
975
1058
|
var _a, _c, _d;
|
|
976
|
-
if (!this.isExternalWalletAuth
|
|
977
|
-
|
|
1059
|
+
if (!this.isExternalWalletAuth) {
|
|
1060
|
+
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
1061
|
+
return Object.values(this.externalWallets)[0];
|
|
1062
|
+
}
|
|
978
1063
|
}
|
|
979
1064
|
if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
|
|
980
1065
|
return this.externalWallets[idOrAddress];
|
|
@@ -985,7 +1070,7 @@ const _ParaCore = class _ParaCore {
|
|
|
985
1070
|
const _b = this.wallets[walletId], { signer: _signer } = _b, wallet = __objRest(_b, ["signer"]);
|
|
986
1071
|
const type = (_d = overrideType != null ? overrideType : (_c = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _c[1]) != null ? _d : wallet.type;
|
|
987
1072
|
return __spreadProps(__spreadValues({}, wallet), {
|
|
988
|
-
type
|
|
1073
|
+
type
|
|
989
1074
|
});
|
|
990
1075
|
}
|
|
991
1076
|
} catch (e) {
|
|
@@ -995,7 +1080,7 @@ const _ParaCore = class _ParaCore {
|
|
|
995
1080
|
get availableWallets() {
|
|
996
1081
|
var _a;
|
|
997
1082
|
return [
|
|
998
|
-
...this.currentWalletIdsArray.map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1083
|
+
...[...this.currentWalletIdsArray, ...__privateGet(this, _ParaCore_instances, guestWalletIdsArray_get)].map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
999
1084
|
const wallet = this.findWallet(id, type);
|
|
1000
1085
|
if (!wallet) return null;
|
|
1001
1086
|
return {
|
|
@@ -1021,10 +1106,8 @@ const _ParaCore = class _ParaCore {
|
|
|
1021
1106
|
}
|
|
1022
1107
|
assertIsValidWalletType(type, walletTypes) {
|
|
1023
1108
|
return __async(this, null, function* () {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
}
|
|
1027
|
-
if (!type || !Object.values(WalletType).includes(type) || !(walletTypes != null ? walletTypes : this.supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
1109
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1110
|
+
if (!type || !WALLET_TYPES.includes(type) || !(walletTypes != null ? walletTypes : supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
1028
1111
|
throw new Error(`wallet type ${type} is not supported`);
|
|
1029
1112
|
}
|
|
1030
1113
|
return type;
|
|
@@ -1032,33 +1115,29 @@ const _ParaCore = class _ParaCore {
|
|
|
1032
1115
|
}
|
|
1033
1116
|
getMissingTypes() {
|
|
1034
1117
|
return __async(this, null, function* () {
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
}
|
|
1038
|
-
return this.supportedWalletTypes.filter(
|
|
1118
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1119
|
+
return supportedWalletTypes.filter(
|
|
1039
1120
|
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
|
|
1040
1121
|
).map(({ type }) => type);
|
|
1041
1122
|
});
|
|
1042
1123
|
}
|
|
1043
1124
|
getTypesToCreate(types) {
|
|
1044
1125
|
return __async(this, null, function* () {
|
|
1045
|
-
|
|
1046
|
-
yield this.touchSession();
|
|
1047
|
-
}
|
|
1126
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1048
1127
|
return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
1049
1128
|
switch (scheme) {
|
|
1050
|
-
case
|
|
1051
|
-
return
|
|
1129
|
+
case "ED25519":
|
|
1130
|
+
return "SOLANA";
|
|
1052
1131
|
default:
|
|
1053
|
-
return
|
|
1132
|
+
return supportedWalletTypes.some(({ type, optional }) => type === "COSMOS" && !optional) ? "COSMOS" : "EVM";
|
|
1054
1133
|
}
|
|
1055
1134
|
});
|
|
1056
1135
|
});
|
|
1057
1136
|
}
|
|
1058
|
-
getPartnerURL(
|
|
1137
|
+
getPartnerURL() {
|
|
1059
1138
|
return __async(this, null, function* () {
|
|
1060
|
-
const
|
|
1061
|
-
return
|
|
1139
|
+
const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1140
|
+
return portalUrl;
|
|
1062
1141
|
});
|
|
1063
1142
|
}
|
|
1064
1143
|
/**
|
|
@@ -1066,75 +1145,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1066
1145
|
* @param partnerId: string - id of the partner to get the portal URL for
|
|
1067
1146
|
* @returns - portal URL
|
|
1068
1147
|
*/
|
|
1069
|
-
getPortalURL(
|
|
1148
|
+
getPortalURL() {
|
|
1070
1149
|
return __async(this, null, function* () {
|
|
1071
|
-
return
|
|
1072
|
-
});
|
|
1073
|
-
}
|
|
1074
|
-
getWebAuthURLForCreate(_a) {
|
|
1075
|
-
return __async(this, null, function* () {
|
|
1076
|
-
var _b = _a, {
|
|
1077
|
-
webAuthId
|
|
1078
|
-
} = _b, options = __objRest(_b, [
|
|
1079
|
-
"webAuthId"
|
|
1080
|
-
]);
|
|
1081
|
-
return this.constructPortalUrl("createAuth", __spreadProps(__spreadValues({}, options), { pathId: webAuthId }));
|
|
1082
|
-
});
|
|
1083
|
-
}
|
|
1084
|
-
getPasswordURLForCreate(_c) {
|
|
1085
|
-
return __async(this, null, function* () {
|
|
1086
|
-
var _d = _c, {
|
|
1087
|
-
passwordId
|
|
1088
|
-
} = _d, options = __objRest(_d, [
|
|
1089
|
-
"passwordId"
|
|
1090
|
-
]);
|
|
1091
|
-
return this.constructPortalUrl("createPassword", __spreadProps(__spreadValues({}, options), {
|
|
1092
|
-
pathId: passwordId
|
|
1093
|
-
}));
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
|
-
getShortUrl(compressedUrl) {
|
|
1097
|
-
return constructUrl({
|
|
1098
|
-
base: getPortalBaseURL(this.ctx),
|
|
1099
|
-
path: `/short/${compressedUrl}`
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
shortenLoginLink(link) {
|
|
1103
|
-
return __async(this, null, function* () {
|
|
1104
|
-
const url = yield transmissionUtils.upload(link, this.ctx.client);
|
|
1105
|
-
return this.getShortUrl(url);
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
/**
|
|
1109
|
-
* Generates a URL for registering a new WebAuth passkey.
|
|
1110
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1111
|
-
* @returns - the URL for creating a new passkey
|
|
1112
|
-
*/
|
|
1113
|
-
getWebAuthURLForLogin(opts) {
|
|
1114
|
-
return __async(this, null, function* () {
|
|
1115
|
-
return this.constructPortalUrl("loginAuth", opts);
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
/**
|
|
1119
|
-
* Generates a URL for registering a new user password.
|
|
1120
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1121
|
-
* @returns - the URL for creating a new password
|
|
1122
|
-
*/
|
|
1123
|
-
getPasswordURLForLogin(opts) {
|
|
1124
|
-
return __async(this, null, function* () {
|
|
1125
|
-
return this.constructPortalUrl("loginPassword", opts);
|
|
1126
|
-
});
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
1130
|
-
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
1131
|
-
* @returns - web auth url
|
|
1132
|
-
*/
|
|
1133
|
-
getWebAuthURLForLoginForPhone(opts) {
|
|
1134
|
-
return __async(this, null, function* () {
|
|
1135
|
-
return this.constructPortalUrl("loginAuth", __spreadValues({
|
|
1136
|
-
authType: "phone"
|
|
1137
|
-
}, opts));
|
|
1150
|
+
return (yield this.getPartnerURL()) || getPortalBaseURL(this.ctx);
|
|
1138
1151
|
});
|
|
1139
1152
|
}
|
|
1140
1153
|
/**
|
|
@@ -1149,7 +1162,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1149
1162
|
if (!wallet) {
|
|
1150
1163
|
throw new Error("wallet not found");
|
|
1151
1164
|
}
|
|
1152
|
-
if (wallet.scheme !==
|
|
1165
|
+
if (wallet.scheme !== "DKLS") {
|
|
1153
1166
|
throw new Error("invalid wallet scheme");
|
|
1154
1167
|
}
|
|
1155
1168
|
return yield this.platformUtils.getPrivateKey(
|
|
@@ -1196,131 +1209,52 @@ const _ParaCore = class _ParaCore {
|
|
|
1196
1209
|
yield this.setWallets(this.wallets);
|
|
1197
1210
|
});
|
|
1198
1211
|
}
|
|
1199
|
-
/**
|
|
1200
|
-
* Checks if a user exists for an email address.
|
|
1201
|
-
* @param {Object} opts the options object
|
|
1202
|
-
* @param {string} opts.email the email to check.
|
|
1203
|
-
* @returns true if user exists, false otherwise.
|
|
1204
|
-
*/
|
|
1205
|
-
checkIfUserExists(_0) {
|
|
1206
|
-
return __async(this, arguments, function* ({ email }) {
|
|
1207
|
-
const res = yield this.ctx.client.checkUserExists({ email });
|
|
1208
|
-
return res.data.exists;
|
|
1209
|
-
});
|
|
1210
|
-
}
|
|
1211
|
-
/**
|
|
1212
|
-
* Checks if a user exists for a phone number.
|
|
1213
|
-
* @param {Object} opts the options object
|
|
1214
|
-
* @param {string} opts.phone - phone number to check.
|
|
1215
|
-
* @param {string} opts.countryCode - the country code.
|
|
1216
|
-
* @returns true if user exists, false otherwise.
|
|
1217
|
-
*/
|
|
1218
|
-
checkIfUserExistsByPhone(_0) {
|
|
1219
|
-
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
1220
|
-
const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
|
|
1221
|
-
return res.data.exists;
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
/**
|
|
1225
|
-
* Creates a new user.
|
|
1226
|
-
* @param {Object} opts the options object
|
|
1227
|
-
* @param {string} opts.email the email to use.
|
|
1228
|
-
*/
|
|
1229
|
-
createUser(_0) {
|
|
1230
|
-
return __async(this, arguments, function* ({ email }) {
|
|
1231
|
-
this.requireApiKey();
|
|
1232
|
-
yield this.setEmail(email);
|
|
1233
|
-
const { userId } = yield this.ctx.client.createUser(__spreadValues({
|
|
1234
|
-
email: this.email
|
|
1235
|
-
}, this.getVerificationEmailProps()));
|
|
1236
|
-
yield this.setUserId(userId);
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
/**
|
|
1240
|
-
* Creates a new user with a phone number.
|
|
1241
|
-
* @param {Object} opts the options object
|
|
1242
|
-
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
1243
|
-
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
1244
|
-
*/
|
|
1245
|
-
createUserByPhone(_0) {
|
|
1246
|
-
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
1247
|
-
this.requireApiKey();
|
|
1248
|
-
yield this.setPhoneNumber(phone, countryCode);
|
|
1249
|
-
const { userId } = yield this.ctx.client.createUser({
|
|
1250
|
-
phone: this.phone,
|
|
1251
|
-
countryCode: this.countryCode
|
|
1252
|
-
});
|
|
1253
|
-
yield this.setUserId(userId);
|
|
1254
|
-
});
|
|
1255
|
-
}
|
|
1256
1212
|
/**
|
|
1257
1213
|
* Logs in or creates a new user using an external wallet address.
|
|
1258
1214
|
* @param {Object} opts the options object
|
|
1259
1215
|
* @param {string} opts.address the external wallet address to use for identification.
|
|
1260
|
-
* @param {
|
|
1216
|
+
* @param {TWalletType} opts.type type of external wallet to use for identification.
|
|
1261
1217
|
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
1262
1218
|
*/
|
|
1263
|
-
|
|
1219
|
+
loginExternalWallet(_a) {
|
|
1264
1220
|
return __async(this, null, function* () {
|
|
1221
|
+
var _b = _a, {
|
|
1222
|
+
externalWallet
|
|
1223
|
+
} = _b, urlOptions = __objRest(_b, [
|
|
1224
|
+
"externalWallet"
|
|
1225
|
+
]);
|
|
1265
1226
|
if (this.externalWalletConnectionOnly) {
|
|
1266
|
-
|
|
1267
|
-
yield this.setExternalWallet(
|
|
1227
|
+
externalWallet.withFullParaAuth = false;
|
|
1228
|
+
yield this.setExternalWallet(externalWallet);
|
|
1268
1229
|
return Promise.resolve({
|
|
1269
1230
|
userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
|
|
1270
1231
|
});
|
|
1271
1232
|
}
|
|
1272
1233
|
this.requireApiKey();
|
|
1273
|
-
const
|
|
1274
|
-
|
|
1275
|
-
type: wallet.type,
|
|
1276
|
-
externalWalletProvider: wallet.provider,
|
|
1277
|
-
// If the wallet isn't using full Para auth we want to track the login here
|
|
1278
|
-
shouldTrackUser: !wallet.withFullParaAuth
|
|
1279
|
-
});
|
|
1280
|
-
yield this.setExternalWallet(wallet);
|
|
1281
|
-
yield this.setUserId(res.userId);
|
|
1282
|
-
return res;
|
|
1283
|
-
});
|
|
1284
|
-
}
|
|
1285
|
-
/**
|
|
1286
|
-
* Returns whether or not the user is connected with only an external wallet, not an external wallet with Para auth.
|
|
1287
|
-
*/
|
|
1288
|
-
isUsingExternalWallet() {
|
|
1289
|
-
return !this.isExternalWalletAuth && !!Object.keys(this.externalWallets).length;
|
|
1290
|
-
}
|
|
1291
|
-
/**
|
|
1292
|
-
* Passes the email code obtained from the user for verification.
|
|
1293
|
-
* @param {Object} opts the options object
|
|
1294
|
-
* @param {string} verificationCode the six-digit code to check
|
|
1295
|
-
* @returns {string} the web auth url for creating a new credential
|
|
1296
|
-
*/
|
|
1297
|
-
verifyEmail(_0) {
|
|
1298
|
-
return __async(this, arguments, function* ({ verificationCode }) {
|
|
1299
|
-
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
1300
|
-
return this.getSetUpBiometricsURL();
|
|
1234
|
+
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
|
|
1235
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1301
1236
|
});
|
|
1302
1237
|
}
|
|
1303
|
-
verifyExternalWallet(
|
|
1304
|
-
return __async(this,
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
return this.getSetUpBiometricsURLForPhone();
|
|
1238
|
+
verifyExternalWallet(_c) {
|
|
1239
|
+
return __async(this, null, function* () {
|
|
1240
|
+
var _d = _c, {
|
|
1241
|
+
externalWallet,
|
|
1242
|
+
signedMessage,
|
|
1243
|
+
cosmosPublicKeyHex,
|
|
1244
|
+
cosmosSigner
|
|
1245
|
+
} = _d, urlOptions = __objRest(_d, [
|
|
1246
|
+
"externalWallet",
|
|
1247
|
+
"signedMessage",
|
|
1248
|
+
"cosmosPublicKeyHex",
|
|
1249
|
+
"cosmosSigner"
|
|
1250
|
+
]);
|
|
1251
|
+
const serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
|
|
1252
|
+
externalWallet,
|
|
1253
|
+
signedMessage,
|
|
1254
|
+
cosmosPublicKeyHex,
|
|
1255
|
+
cosmosSigner
|
|
1256
|
+
});
|
|
1257
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1324
1258
|
});
|
|
1325
1259
|
}
|
|
1326
1260
|
/**
|
|
@@ -1329,18 +1263,19 @@ const _ParaCore = class _ParaCore {
|
|
|
1329
1263
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1330
1264
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1331
1265
|
*/
|
|
1332
|
-
verifyTelegram(
|
|
1266
|
+
verifyTelegram(_e) {
|
|
1333
1267
|
return __async(this, null, function* () {
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1268
|
+
var _f = _e, {
|
|
1269
|
+
telegramAuthResponse
|
|
1270
|
+
} = _f, urlOptions = __objRest(_f, [
|
|
1271
|
+
"telegramAuthResponse"
|
|
1272
|
+
]);
|
|
1273
|
+
try {
|
|
1274
|
+
const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
|
|
1275
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1276
|
+
} catch (e) {
|
|
1277
|
+
throw new Error(e.message);
|
|
1342
1278
|
}
|
|
1343
|
-
return res;
|
|
1344
1279
|
});
|
|
1345
1280
|
}
|
|
1346
1281
|
/**
|
|
@@ -1350,32 +1285,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1350
1285
|
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
1351
1286
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1352
1287
|
*/
|
|
1353
|
-
|
|
1354
|
-
return __async(this, arguments, function* ({
|
|
1355
|
-
const res = yield this.ctx.client.verify2FA(
|
|
1356
|
-
return {
|
|
1357
|
-
initiatedAt: res.data.initiatedAt,
|
|
1358
|
-
status: res.data.status,
|
|
1359
|
-
userId: res.data.userId,
|
|
1360
|
-
wallets: res.data.wallets
|
|
1361
|
-
};
|
|
1362
|
-
});
|
|
1363
|
-
}
|
|
1364
|
-
/**
|
|
1365
|
-
* Performs 2FA verification.
|
|
1366
|
-
* @param {Object} opts the options object
|
|
1367
|
-
* @param {string} opts.phone the phone number
|
|
1368
|
-
* @param {string} opts.countryCode - the country code
|
|
1369
|
-
* @param {string} opts.verificationCode - verification code to received via 2FA.
|
|
1370
|
-
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1371
|
-
*/
|
|
1372
|
-
verify2FAForPhone(_0) {
|
|
1373
|
-
return __async(this, arguments, function* ({
|
|
1374
|
-
phone,
|
|
1375
|
-
countryCode,
|
|
1376
|
-
verificationCode
|
|
1377
|
-
}) {
|
|
1378
|
-
const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
|
|
1288
|
+
verify2fa(_0) {
|
|
1289
|
+
return __async(this, arguments, function* ({ auth, verificationCode }) {
|
|
1290
|
+
const res = yield this.ctx.client.verify2FA(auth, verificationCode);
|
|
1379
1291
|
return {
|
|
1380
1292
|
initiatedAt: res.data.initiatedAt,
|
|
1381
1293
|
status: res.data.status,
|
|
@@ -1388,12 +1300,11 @@ const _ParaCore = class _ParaCore {
|
|
|
1388
1300
|
* Sets up two-factor authentication for the current user.
|
|
1389
1301
|
* @returns {string} uri - uri to use for setting up 2FA
|
|
1390
1302
|
* */
|
|
1391
|
-
|
|
1303
|
+
setup2fa() {
|
|
1392
1304
|
return __async(this, null, function* () {
|
|
1393
|
-
const
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
};
|
|
1305
|
+
const userId = this.assertUserId();
|
|
1306
|
+
const res = yield this.ctx.client.setup2FA(userId);
|
|
1307
|
+
return res;
|
|
1397
1308
|
});
|
|
1398
1309
|
}
|
|
1399
1310
|
/**
|
|
@@ -1401,24 +1312,10 @@ const _ParaCore = class _ParaCore {
|
|
|
1401
1312
|
* @param {Object} opts the options object
|
|
1402
1313
|
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
1403
1314
|
*/
|
|
1404
|
-
|
|
1315
|
+
enable2fa(_0) {
|
|
1405
1316
|
return __async(this, arguments, function* ({ verificationCode }) {
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
}
|
|
1409
|
-
/**
|
|
1410
|
-
* Determines if 2FA has been set up.
|
|
1411
|
-
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
1412
|
-
*/
|
|
1413
|
-
check2FAStatus() {
|
|
1414
|
-
return __async(this, null, function* () {
|
|
1415
|
-
if (!this.userId) {
|
|
1416
|
-
return { isSetup: false };
|
|
1417
|
-
}
|
|
1418
|
-
const res = yield this.ctx.client.check2FAStatus(this.userId);
|
|
1419
|
-
return {
|
|
1420
|
-
isSetup: res.data.isSetup
|
|
1421
|
-
};
|
|
1317
|
+
const userId = this.assertUserId();
|
|
1318
|
+
yield this.ctx.client.enable2FA(userId, verificationCode);
|
|
1422
1319
|
});
|
|
1423
1320
|
}
|
|
1424
1321
|
/**
|
|
@@ -1431,99 +1328,17 @@ const _ParaCore = class _ParaCore {
|
|
|
1431
1328
|
}, this.getVerificationEmailProps()));
|
|
1432
1329
|
});
|
|
1433
1330
|
}
|
|
1434
|
-
/**
|
|
1435
|
-
* Resend a verification SMS for the current user.
|
|
1436
|
-
*/
|
|
1437
|
-
resendVerificationCodeByPhone() {
|
|
1438
|
-
return __async(this, null, function* () {
|
|
1439
|
-
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
1440
|
-
userId: this.userId
|
|
1441
|
-
});
|
|
1442
|
-
});
|
|
1443
|
-
}
|
|
1444
|
-
/**
|
|
1445
|
-
* Returns a URL for setting up a new WebAuth passkey.
|
|
1446
|
-
* @param {Object} opts the options object
|
|
1447
|
-
* @param {string} opts.authType - the auth type to use
|
|
1448
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1449
|
-
* @returns {string} the URL
|
|
1450
|
-
*/
|
|
1451
|
-
getSetUpBiometricsURL() {
|
|
1452
|
-
return __async(this, arguments, function* ({
|
|
1453
|
-
authType = "email",
|
|
1454
|
-
isForNewDevice = false
|
|
1455
|
-
} = {}) {
|
|
1456
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
1457
|
-
status: PublicKeyStatus.PENDING,
|
|
1458
|
-
type: PublicKeyType.WEB
|
|
1459
|
-
});
|
|
1460
|
-
return this.getWebAuthURLForCreate({
|
|
1461
|
-
authType,
|
|
1462
|
-
isForNewDevice,
|
|
1463
|
-
webAuthId: res.data.id,
|
|
1464
|
-
partnerId: res.data.partnerId
|
|
1465
|
-
});
|
|
1466
|
-
});
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
* Returns a URL for setting up a new WebAuth passkey for a phone number.
|
|
1470
|
-
* @param {Object} opts the options object
|
|
1471
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1472
|
-
* @returns {string} the URL
|
|
1473
|
-
*/
|
|
1474
|
-
getSetUpBiometricsURLForPhone() {
|
|
1475
|
-
return __async(this, arguments, function* ({
|
|
1476
|
-
isForNewDevice = false
|
|
1477
|
-
} = {}) {
|
|
1478
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
1479
|
-
status: PublicKeyStatus.PENDING,
|
|
1480
|
-
type: PublicKeyType.WEB
|
|
1481
|
-
});
|
|
1482
|
-
return this.getWebAuthURLForCreate({
|
|
1483
|
-
authType: "phone",
|
|
1484
|
-
isForNewDevice,
|
|
1485
|
-
webAuthId: res.data.id,
|
|
1486
|
-
partnerId: res.data.partnerId
|
|
1487
|
-
});
|
|
1488
|
-
});
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* Returns a URL for setting up a new password.
|
|
1492
|
-
* @param {Object} opts the options object
|
|
1493
|
-
* @param {string} opts.authType - the auth type to use
|
|
1494
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1495
|
-
* @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
|
|
1496
|
-
* @returns {string} the URL
|
|
1497
|
-
*/
|
|
1498
|
-
getSetupPasswordURL() {
|
|
1499
|
-
return __async(this, arguments, function* ({
|
|
1500
|
-
authType = "email",
|
|
1501
|
-
isForNewDevice = false,
|
|
1502
|
-
theme
|
|
1503
|
-
} = {}) {
|
|
1504
|
-
const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
1505
|
-
status: PasswordStatus.PENDING
|
|
1506
|
-
});
|
|
1507
|
-
return this.getPasswordURLForCreate({
|
|
1508
|
-
authType,
|
|
1509
|
-
isForNewDevice,
|
|
1510
|
-
passwordId: res.data.id,
|
|
1511
|
-
partnerId: res.data.partnerId,
|
|
1512
|
-
theme
|
|
1513
|
-
});
|
|
1514
|
-
});
|
|
1515
|
-
}
|
|
1516
1331
|
/**
|
|
1517
1332
|
* Checks if the current session is active.
|
|
1518
1333
|
* @returns `true` if active, `false` otherwise
|
|
1519
1334
|
*/
|
|
1520
1335
|
isSessionActive() {
|
|
1521
1336
|
return __async(this, null, function* () {
|
|
1522
|
-
if (this.
|
|
1337
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1523
1338
|
return true;
|
|
1524
1339
|
}
|
|
1525
|
-
const
|
|
1526
|
-
return !!
|
|
1340
|
+
const { isAuthenticated } = yield this.touchSession();
|
|
1341
|
+
return !!isAuthenticated;
|
|
1527
1342
|
});
|
|
1528
1343
|
}
|
|
1529
1344
|
/**
|
|
@@ -1532,201 +1347,102 @@ const _ParaCore = class _ParaCore {
|
|
|
1532
1347
|
**/
|
|
1533
1348
|
isFullyLoggedIn() {
|
|
1534
1349
|
return __async(this, null, function* () {
|
|
1535
|
-
if (this.
|
|
1536
|
-
return true;
|
|
1537
|
-
}
|
|
1538
|
-
if (this.isGuestMode) {
|
|
1350
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1539
1351
|
return true;
|
|
1540
1352
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
});
|
|
1544
|
-
}
|
|
1545
|
-
get isGuestMode() {
|
|
1546
|
-
return !this.userId && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.every(([id]) => !!this.wallets[id] && this.wallets[id].pregenIdentifierType === "GUEST_ID");
|
|
1547
|
-
}
|
|
1548
|
-
supportedAuthMethods(auth) {
|
|
1549
|
-
return __async(this, null, function* () {
|
|
1550
|
-
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
1551
|
-
const authMethods = /* @__PURE__ */ new Set();
|
|
1552
|
-
for (const type of supportedAuthMethods) {
|
|
1553
|
-
switch (type) {
|
|
1554
|
-
case "PASSWORD":
|
|
1555
|
-
authMethods.add(AuthMethod.PASSWORD);
|
|
1556
|
-
break;
|
|
1557
|
-
case "BIOMETRIC":
|
|
1558
|
-
authMethods.add(AuthMethod.PASSKEY);
|
|
1559
|
-
break;
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
return authMethods;
|
|
1563
|
-
});
|
|
1564
|
-
}
|
|
1565
|
-
/**
|
|
1566
|
-
* Get hints associated with the users stored biometrics.
|
|
1567
|
-
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
1568
|
-
*/
|
|
1569
|
-
getUserBiometricLocationHints() {
|
|
1570
|
-
return __async(this, null, function* () {
|
|
1571
|
-
var _a;
|
|
1572
|
-
if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId && !this.isExternalWalletAuth) {
|
|
1573
|
-
throw new Error(
|
|
1574
|
-
"one of email, phone, farcaster username, telegram user id or external wallet with Para auth are required to get biometric location hints"
|
|
1575
|
-
);
|
|
1576
|
-
}
|
|
1577
|
-
return yield this.ctx.client.getBiometricLocationHints({
|
|
1578
|
-
email: this.email,
|
|
1579
|
-
phone: this.phone,
|
|
1580
|
-
countryCode: this.countryCode,
|
|
1581
|
-
farcasterUsername: this.farcasterUsername,
|
|
1582
|
-
telegramUserId: this.telegramUserId,
|
|
1583
|
-
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
1584
|
-
externalWalletAddress: (_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id
|
|
1585
|
-
});
|
|
1586
|
-
});
|
|
1587
|
-
}
|
|
1588
|
-
setAuth(auth) {
|
|
1589
|
-
return __async(this, null, function* () {
|
|
1590
|
-
const authInfo = extractAuthInfo(auth);
|
|
1591
|
-
if (!authInfo) {
|
|
1592
|
-
return void 0;
|
|
1593
|
-
}
|
|
1594
|
-
switch (authInfo.authType) {
|
|
1595
|
-
case "email":
|
|
1596
|
-
yield this.setEmail(authInfo.identifier);
|
|
1597
|
-
break;
|
|
1598
|
-
case "phone":
|
|
1599
|
-
yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
|
|
1600
|
-
break;
|
|
1601
|
-
case "farcaster":
|
|
1602
|
-
yield this.setFarcasterUsername(authInfo.identifier);
|
|
1603
|
-
break;
|
|
1604
|
-
case "telegram":
|
|
1605
|
-
yield this.setTelegramUserId(authInfo.identifier);
|
|
1606
|
-
break;
|
|
1607
|
-
}
|
|
1608
|
-
return authInfo;
|
|
1609
|
-
});
|
|
1610
|
-
}
|
|
1611
|
-
/**
|
|
1612
|
-
* Initiates a login.
|
|
1613
|
-
* @param {Object} opts the options object
|
|
1614
|
-
* @param {String} opts.email - the email to login with
|
|
1615
|
-
* @param {boolean} opts.useShortURL - whether to shorten the link
|
|
1616
|
-
* @returns - the WebAuth URL for logging in
|
|
1617
|
-
**/
|
|
1618
|
-
initiateUserLogin(_e) {
|
|
1619
|
-
return __async(this, null, function* () {
|
|
1620
|
-
var _f = _e, { useShortUrl = false } = _f, auth = __objRest(_f, ["useShortUrl"]);
|
|
1621
|
-
const authInfo = yield this.setAuth(auth);
|
|
1622
|
-
if (!authInfo) {
|
|
1623
|
-
return;
|
|
1624
|
-
}
|
|
1625
|
-
const res = yield this.touchSession(true);
|
|
1626
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1627
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1628
|
-
}
|
|
1629
|
-
const webAuthLoginURL = yield this.getWebAuthURLForLogin({
|
|
1630
|
-
authType: authInfo.authType,
|
|
1631
|
-
sessionId: res.data.sessionId,
|
|
1632
|
-
partnerId: res.data.partnerId,
|
|
1633
|
-
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
1634
|
-
});
|
|
1635
|
-
if (!useShortUrl) {
|
|
1636
|
-
return webAuthLoginURL;
|
|
1353
|
+
if (this.isGuestMode) {
|
|
1354
|
+
return true;
|
|
1637
1355
|
}
|
|
1638
|
-
|
|
1356
|
+
const isSessionActive = yield this.isSessionActive();
|
|
1357
|
+
return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
|
|
1639
1358
|
});
|
|
1640
1359
|
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
initiateUserLoginV2(auth) {
|
|
1647
|
-
return __async(this, null, function* () {
|
|
1648
|
-
const authInfo = yield this.setAuth(auth);
|
|
1649
|
-
if (!authInfo) {
|
|
1650
|
-
return;
|
|
1360
|
+
get isGuestMode() {
|
|
1361
|
+
return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
|
|
1362
|
+
({ userId, partnerId }) => {
|
|
1363
|
+
var _a;
|
|
1364
|
+
return partnerId === ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
|
|
1651
1365
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1368
|
+
supportedAuthMethods(auth) {
|
|
1369
|
+
return __async(this, null, function* () {
|
|
1370
|
+
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
1371
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
1372
|
+
for (const type of supportedAuthMethods) {
|
|
1373
|
+
switch (type) {
|
|
1374
|
+
case "PASSWORD":
|
|
1375
|
+
authMethods.add(AuthMethod.PASSWORD);
|
|
1376
|
+
break;
|
|
1377
|
+
case "BIOMETRIC":
|
|
1378
|
+
authMethods.add(AuthMethod.PASSKEY);
|
|
1379
|
+
break;
|
|
1380
|
+
}
|
|
1655
1381
|
}
|
|
1656
|
-
return
|
|
1382
|
+
return authMethods;
|
|
1657
1383
|
});
|
|
1658
1384
|
}
|
|
1659
1385
|
/**
|
|
1660
|
-
*
|
|
1661
|
-
* @
|
|
1662
|
-
* @
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
* @returns - the WebAuth URL for logging in
|
|
1666
|
-
**/
|
|
1667
|
-
initiateUserLoginForPhone(_g) {
|
|
1386
|
+
* Get hints associated with the users stored biometrics.
|
|
1387
|
+
* @deprecated
|
|
1388
|
+
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
1389
|
+
*/
|
|
1390
|
+
getUserBiometricLocationHints() {
|
|
1668
1391
|
return __async(this, null, function* () {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
} = _h, auth = __objRest(_h, [
|
|
1672
|
-
"useShortUrl"
|
|
1673
|
-
]);
|
|
1674
|
-
yield this.setAuth(auth);
|
|
1675
|
-
const res = yield this.touchSession(true);
|
|
1676
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1677
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1678
|
-
}
|
|
1679
|
-
const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
|
|
1680
|
-
sessionId: res.data.sessionId,
|
|
1681
|
-
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
1682
|
-
partnerId: res.data.partnerId
|
|
1683
|
-
});
|
|
1684
|
-
if (!useShortUrl) {
|
|
1685
|
-
return webAuthLoginURL;
|
|
1686
|
-
}
|
|
1687
|
-
return this.shortenLoginLink(webAuthLoginURL);
|
|
1392
|
+
const { auth } = this.assertIsAuthSet();
|
|
1393
|
+
return yield this.ctx.client.getBiometricLocationHints(auth);
|
|
1688
1394
|
});
|
|
1689
1395
|
}
|
|
1690
1396
|
/**
|
|
1691
1397
|
* Waits for the session to be active.
|
|
1692
1398
|
**/
|
|
1693
|
-
|
|
1694
|
-
return __async(this, arguments, function* ({
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
yield
|
|
1703
|
-
if (
|
|
1704
|
-
this.
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1399
|
+
waitForSignup(_0) {
|
|
1400
|
+
return __async(this, arguments, function* ({
|
|
1401
|
+
isCanceled = () => false,
|
|
1402
|
+
onCancel,
|
|
1403
|
+
onPoll
|
|
1404
|
+
}) {
|
|
1405
|
+
const startedAt = Date.now();
|
|
1406
|
+
return new Promise((resolve, reject) => {
|
|
1407
|
+
(() => __async(this, null, function* () {
|
|
1408
|
+
yield this.touchSession();
|
|
1409
|
+
if (!this.isExternalWalletAuth) {
|
|
1410
|
+
this.externalWallets = {};
|
|
1411
|
+
}
|
|
1412
|
+
while (true) {
|
|
1413
|
+
try {
|
|
1414
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1415
|
+
onCancel == null ? void 0 : onCancel();
|
|
1416
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, false, "failed to sign up user");
|
|
1417
|
+
return reject("canceled");
|
|
1418
|
+
}
|
|
1419
|
+
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1420
|
+
if (yield this.isSessionActive()) {
|
|
1421
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
1422
|
+
return resolve(true);
|
|
1423
|
+
}
|
|
1424
|
+
onPoll == null ? void 0 : onPoll();
|
|
1425
|
+
} catch (err) {
|
|
1426
|
+
console.error(err);
|
|
1427
|
+
onPoll == null ? void 0 : onPoll();
|
|
1711
1428
|
}
|
|
1712
1429
|
}
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
return false;
|
|
1430
|
+
}))();
|
|
1431
|
+
});
|
|
1718
1432
|
});
|
|
1719
1433
|
}
|
|
1720
|
-
|
|
1434
|
+
waitForWalletCreation() {
|
|
1721
1435
|
return __async(this, arguments, function* ({
|
|
1722
|
-
|
|
1436
|
+
isCanceled = () => false,
|
|
1437
|
+
onCancel
|
|
1723
1438
|
} = {}) {
|
|
1724
|
-
yield this.
|
|
1439
|
+
yield this.waitForSignup({ isCanceled, onCancel });
|
|
1440
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1725
1441
|
const pregenWallets = yield this.getPregenWallets();
|
|
1726
1442
|
let recoverySecret, walletIds = {};
|
|
1727
1443
|
if (pregenWallets.length > 0) {
|
|
1728
1444
|
recoverySecret = yield this.claimPregenWallets();
|
|
1729
|
-
walletIds =
|
|
1445
|
+
walletIds = supportedWalletTypes.reduce((acc, { type }) => {
|
|
1730
1446
|
var _a;
|
|
1731
1447
|
return __spreadProps(__spreadValues({}, acc), {
|
|
1732
1448
|
[type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
@@ -1746,14 +1462,12 @@ const _ParaCore = class _ParaCore {
|
|
|
1746
1462
|
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
1747
1463
|
* @return {string} the Farcaster connect URI
|
|
1748
1464
|
*/
|
|
1749
|
-
|
|
1465
|
+
getFarcasterConnectUri() {
|
|
1750
1466
|
return __async(this, null, function* () {
|
|
1751
|
-
yield this.logout();
|
|
1752
|
-
yield this.touchSession(true);
|
|
1753
1467
|
const {
|
|
1754
|
-
data: { connect_uri }
|
|
1468
|
+
data: { connect_uri: connectUri }
|
|
1755
1469
|
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
1756
|
-
return
|
|
1470
|
+
return connectUri;
|
|
1757
1471
|
});
|
|
1758
1472
|
}
|
|
1759
1473
|
/**
|
|
@@ -1761,40 +1475,60 @@ const _ParaCore = class _ParaCore {
|
|
|
1761
1475
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
1762
1476
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
1763
1477
|
*/
|
|
1764
|
-
|
|
1478
|
+
verifyFarcaster(_g) {
|
|
1765
1479
|
return __async(this, null, function* () {
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1480
|
+
var _h = _g, {
|
|
1481
|
+
isCanceled = () => false,
|
|
1482
|
+
onConnectUri,
|
|
1483
|
+
onCancel,
|
|
1484
|
+
onPoll
|
|
1485
|
+
} = _h, urlOptions = __objRest(_h, [
|
|
1486
|
+
"isCanceled",
|
|
1487
|
+
"onConnectUri",
|
|
1488
|
+
"onCancel",
|
|
1489
|
+
"onPoll"
|
|
1490
|
+
]);
|
|
1491
|
+
if (onConnectUri) {
|
|
1492
|
+
const connectUri = yield this.getFarcasterConnectUri();
|
|
1493
|
+
onConnectUri(connectUri);
|
|
1494
|
+
}
|
|
1495
|
+
return new Promise((resolve, reject) => {
|
|
1496
|
+
(() => __async(this, null, function* () {
|
|
1497
|
+
const startedAt = Date.now();
|
|
1498
|
+
while (true) {
|
|
1499
|
+
try {
|
|
1500
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1501
|
+
onCancel == null ? void 0 : onCancel();
|
|
1502
|
+
return reject("canceled");
|
|
1503
|
+
}
|
|
1504
|
+
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1505
|
+
const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
|
|
1506
|
+
if (isServerAuthState(serverAuthState)) {
|
|
1507
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1508
|
+
return resolve(authState);
|
|
1509
|
+
}
|
|
1510
|
+
onPoll == null ? void 0 : onPoll();
|
|
1511
|
+
} catch (e) {
|
|
1512
|
+
console.error(e);
|
|
1513
|
+
return reject(e);
|
|
1514
|
+
}
|
|
1780
1515
|
}
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
this.isAwaitingFarcaster = false;
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1516
|
+
}))();
|
|
1517
|
+
});
|
|
1786
1518
|
});
|
|
1787
1519
|
}
|
|
1788
1520
|
/**
|
|
1789
1521
|
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
1790
1522
|
*
|
|
1791
1523
|
* @param {Object} opts the options object
|
|
1792
|
-
* @param {
|
|
1524
|
+
* @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
|
|
1793
1525
|
* @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
|
|
1794
1526
|
* @returns {string} the URL for the user to log in with OAuth.
|
|
1795
1527
|
*/
|
|
1796
|
-
|
|
1797
|
-
return __async(this,
|
|
1528
|
+
getOAuthUrl(_i) {
|
|
1529
|
+
return __async(this, null, function* () {
|
|
1530
|
+
var _j = _i, { method, deeplinkUrl } = _j, params = __objRest(_j, ["method", "deeplinkUrl"]);
|
|
1531
|
+
var _a;
|
|
1798
1532
|
if (deeplinkUrl) {
|
|
1799
1533
|
try {
|
|
1800
1534
|
new URL(deeplinkUrl);
|
|
@@ -1802,14 +1536,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1802
1536
|
throw new Error("Invalid deeplink URL");
|
|
1803
1537
|
}
|
|
1804
1538
|
}
|
|
1805
|
-
yield this.
|
|
1806
|
-
const res = yield this.touchSession(true);
|
|
1539
|
+
const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
1807
1540
|
return constructUrl({
|
|
1808
|
-
base:
|
|
1809
|
-
path: `/auth/${method
|
|
1541
|
+
base: getBaseOAuthUrl(this.ctx.env),
|
|
1542
|
+
path: `/auth/${method}`,
|
|
1810
1543
|
params: {
|
|
1811
1544
|
apiKey: this.ctx.apiKey,
|
|
1812
|
-
sessionLookupId
|
|
1545
|
+
sessionLookupId,
|
|
1813
1546
|
deeplinkUrl
|
|
1814
1547
|
}
|
|
1815
1548
|
});
|
|
@@ -1823,37 +1556,54 @@ const _ParaCore = class _ParaCore {
|
|
|
1823
1556
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1824
1557
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1825
1558
|
*/
|
|
1826
|
-
|
|
1827
|
-
return __async(this,
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1559
|
+
verifyOAuth(_k) {
|
|
1560
|
+
return __async(this, null, function* () {
|
|
1561
|
+
var _l = _k, {
|
|
1562
|
+
method,
|
|
1563
|
+
deeplinkUrl,
|
|
1564
|
+
isCanceled = () => false,
|
|
1565
|
+
onCancel,
|
|
1566
|
+
onPoll,
|
|
1567
|
+
onOAuthUrl
|
|
1568
|
+
} = _l, urlOptions = __objRest(_l, [
|
|
1569
|
+
"method",
|
|
1570
|
+
"deeplinkUrl",
|
|
1571
|
+
"isCanceled",
|
|
1572
|
+
"onCancel",
|
|
1573
|
+
"onPoll",
|
|
1574
|
+
"onOAuthUrl"
|
|
1575
|
+
]);
|
|
1576
|
+
let sessionLookupId;
|
|
1577
|
+
if (onOAuthUrl) {
|
|
1578
|
+
sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
1579
|
+
const oAuthUrl = yield this.getOAuthUrl({ method, deeplinkUrl, sessionLookupId });
|
|
1580
|
+
onOAuthUrl(oAuthUrl);
|
|
1581
|
+
} else {
|
|
1582
|
+
({ sessionLookupId } = yield this.touchSession());
|
|
1583
|
+
}
|
|
1584
|
+
const startedAt = Date.now();
|
|
1585
|
+
return new Promise((resolve, reject) => {
|
|
1586
|
+
(() => __async(this, null, function* () {
|
|
1587
|
+
while (true) {
|
|
1588
|
+
try {
|
|
1589
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1590
|
+
onCancel == null ? void 0 : onCancel();
|
|
1591
|
+
return reject("canceled");
|
|
1841
1592
|
}
|
|
1842
|
-
yield
|
|
1843
|
-
yield this.
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1593
|
+
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1594
|
+
const serverAuthState = yield this.ctx.client.verifyOAuth();
|
|
1595
|
+
if (isServerAuthState(serverAuthState)) {
|
|
1596
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1597
|
+
return resolve(authState);
|
|
1598
|
+
}
|
|
1599
|
+
onPoll == null ? void 0 : onPoll();
|
|
1600
|
+
} catch (err) {
|
|
1601
|
+
console.error(err);
|
|
1602
|
+
onPoll == null ? void 0 : onPoll();
|
|
1850
1603
|
}
|
|
1851
1604
|
}
|
|
1852
|
-
}
|
|
1853
|
-
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
return { userExists: false };
|
|
1605
|
+
}))();
|
|
1606
|
+
});
|
|
1857
1607
|
});
|
|
1858
1608
|
}
|
|
1859
1609
|
/**
|
|
@@ -1864,60 +1614,61 @@ const _ParaCore = class _ParaCore {
|
|
|
1864
1614
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
1865
1615
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
1866
1616
|
**/
|
|
1867
|
-
|
|
1617
|
+
waitForLogin() {
|
|
1868
1618
|
return __async(this, arguments, function* ({
|
|
1869
|
-
|
|
1619
|
+
isCanceled = () => false,
|
|
1620
|
+
onCancel,
|
|
1621
|
+
onPoll,
|
|
1870
1622
|
skipSessionRefresh = false
|
|
1871
1623
|
} = {}) {
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
this
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
try {
|
|
1879
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
1880
|
-
if (!(yield this.isSessionActive())) {
|
|
1881
|
-
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
1882
|
-
const resp2 = { isComplete: false, isError: true };
|
|
1883
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
1884
|
-
return resp2;
|
|
1885
|
-
}
|
|
1886
|
-
continue;
|
|
1624
|
+
const startedAt = Date.now();
|
|
1625
|
+
return new Promise((resolve, reject) => {
|
|
1626
|
+
(() => __async(this, null, function* () {
|
|
1627
|
+
var _a;
|
|
1628
|
+
if (!this.isExternalWalletAuth) {
|
|
1629
|
+
this.externalWallets = {};
|
|
1887
1630
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1631
|
+
while (true) {
|
|
1632
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1633
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
|
|
1634
|
+
onCancel == null ? void 0 : onCancel();
|
|
1635
|
+
return reject("canceled");
|
|
1636
|
+
}
|
|
1637
|
+
yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
|
|
1638
|
+
try {
|
|
1639
|
+
let session = yield this.touchSession();
|
|
1640
|
+
if (!session.isAuthenticated) {
|
|
1641
|
+
onPoll == null ? void 0 : onPoll();
|
|
1897
1642
|
continue;
|
|
1898
1643
|
}
|
|
1644
|
+
session = yield this.userSetupAfterLogin();
|
|
1645
|
+
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
1646
|
+
if (!needsWallet) {
|
|
1647
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
1648
|
+
onPoll == null ? void 0 : onPoll();
|
|
1649
|
+
continue;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
1653
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
1654
|
+
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
1655
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
1656
|
+
yield this.claimPregenWallets();
|
|
1657
|
+
const resp = {
|
|
1658
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
1659
|
+
partnerId: session.partnerId
|
|
1660
|
+
};
|
|
1661
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp);
|
|
1662
|
+
return resolve(resp);
|
|
1663
|
+
}
|
|
1664
|
+
onPoll == null ? void 0 : onPoll();
|
|
1665
|
+
} catch (err) {
|
|
1666
|
+
console.error(err);
|
|
1667
|
+
onPoll == null ? void 0 : onPoll();
|
|
1899
1668
|
}
|
|
1900
1669
|
}
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
1904
|
-
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
1905
|
-
yield this.claimPregenWallets();
|
|
1906
|
-
const resp2 = {
|
|
1907
|
-
isComplete: true,
|
|
1908
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
1909
|
-
partnerId: postLoginData.data.partnerId
|
|
1910
|
-
};
|
|
1911
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
|
|
1912
|
-
return resp2;
|
|
1913
|
-
}
|
|
1914
|
-
} catch (err) {
|
|
1915
|
-
console.error(err);
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
const resp = { isComplete: false };
|
|
1919
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp, "exitted login without setting up user");
|
|
1920
|
-
return resp;
|
|
1670
|
+
}))();
|
|
1671
|
+
});
|
|
1921
1672
|
});
|
|
1922
1673
|
}
|
|
1923
1674
|
/**
|
|
@@ -1929,14 +1680,15 @@ const _ParaCore = class _ParaCore {
|
|
|
1929
1680
|
* @returns a URL for the user to reauthenticate.
|
|
1930
1681
|
**/
|
|
1931
1682
|
refreshSession() {
|
|
1932
|
-
return __async(this, arguments, function* ({
|
|
1933
|
-
|
|
1683
|
+
return __async(this, arguments, function* ({
|
|
1684
|
+
shouldOpenPopup = false
|
|
1685
|
+
} = {}) {
|
|
1686
|
+
const { sessionId } = yield this.touchSession(true);
|
|
1934
1687
|
if (!this.loginEncryptionKeyPair) {
|
|
1935
1688
|
yield this.setLoginEncryptionKeyPair();
|
|
1936
1689
|
}
|
|
1937
|
-
const link = yield this.
|
|
1938
|
-
sessionId
|
|
1939
|
-
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
1690
|
+
const link = yield this.getLoginUrl({
|
|
1691
|
+
sessionId
|
|
1940
1692
|
});
|
|
1941
1693
|
if (shouldOpenPopup) {
|
|
1942
1694
|
this.platformUtils.openPopup(link);
|
|
@@ -1950,13 +1702,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1950
1702
|
**/
|
|
1951
1703
|
userSetupAfterLogin() {
|
|
1952
1704
|
return __async(this, null, function* () {
|
|
1953
|
-
const
|
|
1954
|
-
yield this.setUserId(
|
|
1955
|
-
if (
|
|
1956
|
-
yield this.setCurrentWalletIds(
|
|
1957
|
-
sessionLookupId: this.isPortal() ?
|
|
1705
|
+
const session = yield this.touchSession();
|
|
1706
|
+
yield this.setUserId(session.userId);
|
|
1707
|
+
if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
|
|
1708
|
+
yield this.setCurrentWalletIds(session.currentWalletIds, {
|
|
1709
|
+
sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
|
|
1958
1710
|
});
|
|
1959
|
-
return
|
|
1711
|
+
return session;
|
|
1960
1712
|
});
|
|
1961
1713
|
}
|
|
1962
1714
|
/**
|
|
@@ -1967,8 +1719,8 @@ const _ParaCore = class _ParaCore {
|
|
|
1967
1719
|
**/
|
|
1968
1720
|
getTransmissionKeyShares() {
|
|
1969
1721
|
return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
|
|
1970
|
-
const
|
|
1971
|
-
const sessionLookupId = isForNewDevice ? `${
|
|
1722
|
+
const session = yield this.touchSession();
|
|
1723
|
+
const sessionLookupId = isForNewDevice ? `${session.sessionLookupId}-new-device` : session.sessionLookupId;
|
|
1972
1724
|
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
1973
1725
|
});
|
|
1974
1726
|
}
|
|
@@ -2095,7 +1847,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2095
1847
|
*
|
|
2096
1848
|
* @param {Object} [opts] the options object.
|
|
2097
1849
|
* @param {boolean} [opts.skipDistribute] if `true`, the wallets' recovery share will not be distributed.
|
|
2098
|
-
* @param {
|
|
1850
|
+
* @param {TWalletType[]} [opts.types] the types of wallets to create.
|
|
2099
1851
|
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
2100
1852
|
**/
|
|
2101
1853
|
createWalletPerType() {
|
|
@@ -2166,7 +1918,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2166
1918
|
/**
|
|
2167
1919
|
* Creates a new wallet.
|
|
2168
1920
|
* @param {Object} opts the options object.
|
|
2169
|
-
* @param {
|
|
1921
|
+
* @param {TWalletType} opts.type the type of wallet to create.
|
|
2170
1922
|
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
2171
1923
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2172
1924
|
**/
|
|
@@ -2177,14 +1929,15 @@ const _ParaCore = class _ParaCore {
|
|
|
2177
1929
|
} = {}) {
|
|
2178
1930
|
var _a, _b;
|
|
2179
1931
|
this.requireApiKey();
|
|
1932
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2180
1933
|
const walletType = yield this.assertIsValidWalletType(
|
|
2181
|
-
_type != null ? _type : (_a =
|
|
1934
|
+
_type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
2182
1935
|
);
|
|
2183
1936
|
let signer;
|
|
2184
1937
|
let wallet;
|
|
2185
1938
|
let keygenRes;
|
|
2186
1939
|
switch (walletType) {
|
|
2187
|
-
case
|
|
1940
|
+
case "SOLANA": {
|
|
2188
1941
|
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
2189
1942
|
this.ctx,
|
|
2190
1943
|
this.userId,
|
|
@@ -2210,7 +1963,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2210
1963
|
this.wallets[walletId] = {
|
|
2211
1964
|
id: walletId,
|
|
2212
1965
|
signer,
|
|
2213
|
-
scheme: walletType ===
|
|
1966
|
+
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
2214
1967
|
type: walletType
|
|
2215
1968
|
};
|
|
2216
1969
|
wallet = this.wallets[walletId];
|
|
@@ -2227,7 +1980,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2227
1980
|
});
|
|
2228
1981
|
}
|
|
2229
1982
|
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
2230
|
-
[walletType]: [...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId]
|
|
1983
|
+
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
2231
1984
|
}));
|
|
2232
1985
|
const walletNoSigner = __spreadValues({}, wallet);
|
|
2233
1986
|
delete walletNoSigner.signer;
|
|
@@ -2238,15 +1991,6 @@ const _ParaCore = class _ParaCore {
|
|
|
2238
1991
|
return [wallet, recoveryShare];
|
|
2239
1992
|
});
|
|
2240
1993
|
}
|
|
2241
|
-
/**
|
|
2242
|
-
* Creates a new pregenerated wallet.
|
|
2243
|
-
*
|
|
2244
|
-
* @param {Object} opts the options object.
|
|
2245
|
-
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
2246
|
-
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
2247
|
-
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
2248
|
-
* @returns {Wallet} the created wallet.
|
|
2249
|
-
**/
|
|
2250
1994
|
createPregenWallet(opts) {
|
|
2251
1995
|
return __async(this, null, function* () {
|
|
2252
1996
|
return yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, opts);
|
|
@@ -2259,18 +2003,17 @@ const _ParaCore = class _ParaCore {
|
|
|
2259
2003
|
* @param {Object} opts the options object.
|
|
2260
2004
|
* @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
|
|
2261
2005
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
2262
|
-
* @param {
|
|
2006
|
+
* @param {TWalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
2263
2007
|
* @returns {Wallet[]} an array containing the created wallets.
|
|
2264
2008
|
**/
|
|
2265
2009
|
createPregenWalletPerType(_0) {
|
|
2266
2010
|
return __async(this, arguments, function* ({
|
|
2267
2011
|
types,
|
|
2268
|
-
|
|
2269
|
-
pregenIdentifierType = "EMAIL"
|
|
2012
|
+
pregenId
|
|
2270
2013
|
}) {
|
|
2271
2014
|
const wallets = [];
|
|
2272
2015
|
for (const type of yield this.getTypesToCreate(types)) {
|
|
2273
|
-
const wallet = yield
|
|
2016
|
+
const wallet = yield this.createPregenWallet({ type, pregenId });
|
|
2274
2017
|
wallets.push(wallet);
|
|
2275
2018
|
}
|
|
2276
2019
|
return wallets;
|
|
@@ -2278,7 +2021,6 @@ const _ParaCore = class _ParaCore {
|
|
|
2278
2021
|
}
|
|
2279
2022
|
/**
|
|
2280
2023
|
* Claims a pregenerated wallet.
|
|
2281
|
-
*
|
|
2282
2024
|
* @param {Object} opts the options object.
|
|
2283
2025
|
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
2284
2026
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
@@ -2286,12 +2028,11 @@ const _ParaCore = class _ParaCore {
|
|
|
2286
2028
|
**/
|
|
2287
2029
|
claimPregenWallets() {
|
|
2288
2030
|
return __async(this, arguments, function* ({
|
|
2289
|
-
|
|
2290
|
-
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
2031
|
+
pregenId
|
|
2291
2032
|
} = {}) {
|
|
2292
2033
|
var _a;
|
|
2293
2034
|
this.requireApiKey();
|
|
2294
|
-
const pregenWallets =
|
|
2035
|
+
const pregenWallets = pregenId ? yield this.getPregenWallets({ pregenId }) : yield this.getPregenWallets();
|
|
2295
2036
|
if (pregenWallets.length === 0) {
|
|
2296
2037
|
return void 0;
|
|
2297
2038
|
}
|
|
@@ -2309,7 +2050,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2309
2050
|
for (const walletId of walletIds) {
|
|
2310
2051
|
const wallet = this.wallets[walletId];
|
|
2311
2052
|
let refreshedShare;
|
|
2312
|
-
if (wallet.scheme ===
|
|
2053
|
+
if (wallet.scheme === "ED25519") {
|
|
2313
2054
|
const distributeRes = yield distributeNewShare({
|
|
2314
2055
|
ctx: this.ctx,
|
|
2315
2056
|
userId: this.userId,
|
|
@@ -2360,10 +2101,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2360
2101
|
updatePregenWalletIdentifier(_0) {
|
|
2361
2102
|
return __async(this, arguments, function* ({
|
|
2362
2103
|
walletId,
|
|
2363
|
-
|
|
2364
|
-
newPregenIdentifierType
|
|
2104
|
+
newPregenId
|
|
2365
2105
|
}) {
|
|
2366
2106
|
this.requireApiKey();
|
|
2107
|
+
const [newPregenIdentifierType, newPregenIdentifier] = toPregenTypeAndId(newPregenId);
|
|
2367
2108
|
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
2368
2109
|
pregenIdentifier: newPregenIdentifier,
|
|
2369
2110
|
pregenIdentifierType: newPregenIdentifierType
|
|
@@ -2385,13 +2126,13 @@ const _ParaCore = class _ParaCore {
|
|
|
2385
2126
|
* @returns {boolean} whether the pregen wallet exists
|
|
2386
2127
|
**/
|
|
2387
2128
|
hasPregenWallet(_0) {
|
|
2388
|
-
return __async(this, arguments, function* ({
|
|
2389
|
-
pregenIdentifier,
|
|
2390
|
-
pregenIdentifierType
|
|
2391
|
-
}) {
|
|
2129
|
+
return __async(this, arguments, function* ({ pregenId }) {
|
|
2392
2130
|
this.requireApiKey();
|
|
2393
|
-
const
|
|
2394
|
-
const
|
|
2131
|
+
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
2132
|
+
const wallets = yield this.getPregenWallets({ pregenId });
|
|
2133
|
+
const wallet = wallets.find(
|
|
2134
|
+
(w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType
|
|
2135
|
+
);
|
|
2395
2136
|
if (!wallet) {
|
|
2396
2137
|
return false;
|
|
2397
2138
|
}
|
|
@@ -2406,13 +2147,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2406
2147
|
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
2407
2148
|
**/
|
|
2408
2149
|
getPregenWallets() {
|
|
2409
|
-
return __async(this, arguments, function* ({
|
|
2410
|
-
pregenIdentifier,
|
|
2411
|
-
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
2412
|
-
} = {}) {
|
|
2150
|
+
return __async(this, arguments, function* ({ pregenId } = {}) {
|
|
2413
2151
|
this.requireApiKey();
|
|
2414
2152
|
const res = yield this.ctx.client.getPregenWallets(
|
|
2415
|
-
|
|
2153
|
+
pregenId ? toPregenIds(pregenId) : this.pregenIds,
|
|
2416
2154
|
this.isPortal(),
|
|
2417
2155
|
this.userId
|
|
2418
2156
|
);
|
|
@@ -2420,21 +2158,37 @@ const _ParaCore = class _ParaCore {
|
|
|
2420
2158
|
});
|
|
2421
2159
|
}
|
|
2422
2160
|
createGuestWallets() {
|
|
2423
|
-
return __async(this,
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
wallets
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2161
|
+
return __async(this, null, function* () {
|
|
2162
|
+
let error;
|
|
2163
|
+
if (__privateGet(this, _isCreateGuestWalletsPending)) {
|
|
2164
|
+
error = new Error("Guest wallets creation already in progress");
|
|
2165
|
+
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
|
|
2166
|
+
throw error;
|
|
2167
|
+
}
|
|
2168
|
+
if (this.isGuestMode) {
|
|
2169
|
+
error = new Error("Guest wallets already created");
|
|
2170
|
+
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
|
|
2171
|
+
throw error;
|
|
2172
|
+
}
|
|
2173
|
+
try {
|
|
2174
|
+
__privateSet(this, _isCreateGuestWalletsPending, true);
|
|
2175
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2176
|
+
const wallets = [];
|
|
2177
|
+
const guestId = newUuid();
|
|
2178
|
+
for (const type of yield this.getTypesToCreate(
|
|
2179
|
+
supportedWalletTypes.filter(({ optional }) => !optional).map(({ type: type2 }) => type2)
|
|
2180
|
+
)) {
|
|
2181
|
+
const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenId: { guestId } });
|
|
2182
|
+
wallets.push(wallet);
|
|
2183
|
+
}
|
|
2184
|
+
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, wallets);
|
|
2185
|
+
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2186
|
+
return wallets;
|
|
2187
|
+
} catch (e) {
|
|
2188
|
+
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, null, error == null ? void 0 : error.message);
|
|
2189
|
+
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2190
|
+
throw error;
|
|
2435
2191
|
}
|
|
2436
|
-
yield this.setCurrentWalletIds(currentWalletIds);
|
|
2437
|
-
return wallets;
|
|
2438
2192
|
});
|
|
2439
2193
|
}
|
|
2440
2194
|
encodeWalletBase64(wallet) {
|
|
@@ -2472,9 +2226,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2472
2226
|
}
|
|
2473
2227
|
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
2474
2228
|
return __async(this, null, function* () {
|
|
2475
|
-
const res = yield this.touchSession();
|
|
2476
2229
|
return this.constructPortalUrl("txReview", {
|
|
2477
|
-
partnerId: res.data.partnerId,
|
|
2478
2230
|
pathId: transactionId,
|
|
2479
2231
|
params: {
|
|
2480
2232
|
email: this.email,
|
|
@@ -2483,21 +2235,20 @@ const _ParaCore = class _ParaCore {
|
|
|
2483
2235
|
});
|
|
2484
2236
|
});
|
|
2485
2237
|
}
|
|
2486
|
-
getOnRampTransactionUrl(
|
|
2238
|
+
getOnRampTransactionUrl(_m) {
|
|
2487
2239
|
return __async(this, null, function* () {
|
|
2488
|
-
var
|
|
2240
|
+
var _n = _m, {
|
|
2489
2241
|
purchaseId,
|
|
2490
2242
|
providerKey
|
|
2491
|
-
} =
|
|
2243
|
+
} = _n, walletParams = __objRest(_n, [
|
|
2492
2244
|
"purchaseId",
|
|
2493
2245
|
"providerKey"
|
|
2494
2246
|
]);
|
|
2495
|
-
const
|
|
2247
|
+
const { sessionId } = yield this.touchSession();
|
|
2496
2248
|
const [key, identifier] = extractWalletRef(walletParams);
|
|
2497
2249
|
return this.constructPortalUrl("onRamp", {
|
|
2498
|
-
partnerId: res.data.partnerId,
|
|
2499
2250
|
pathId: purchaseId,
|
|
2500
|
-
sessionId
|
|
2251
|
+
sessionId,
|
|
2501
2252
|
params: {
|
|
2502
2253
|
[key]: identifier,
|
|
2503
2254
|
providerKey,
|
|
@@ -2522,7 +2273,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2522
2273
|
walletId,
|
|
2523
2274
|
messageBase64,
|
|
2524
2275
|
timeoutMs = 3e4,
|
|
2525
|
-
cosmosSignDocBase64
|
|
2276
|
+
cosmosSignDocBase64,
|
|
2277
|
+
isCanceled = () => false,
|
|
2278
|
+
onCancel,
|
|
2279
|
+
onPoll
|
|
2526
2280
|
}) {
|
|
2527
2281
|
this.assertIsValidWalletId(walletId);
|
|
2528
2282
|
const wallet = this.wallets[walletId];
|
|
@@ -2541,11 +2295,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2541
2295
|
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2542
2296
|
return signRes;
|
|
2543
2297
|
}
|
|
2544
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2545
2298
|
while (true) {
|
|
2546
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
2299
|
+
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2300
|
+
onCancel == null ? void 0 : onCancel();
|
|
2547
2301
|
break;
|
|
2548
2302
|
}
|
|
2303
|
+
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2549
2304
|
try {
|
|
2550
2305
|
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2551
2306
|
} catch (err) {
|
|
@@ -2555,7 +2310,8 @@ const _ParaCore = class _ParaCore {
|
|
|
2555
2310
|
}
|
|
2556
2311
|
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2557
2312
|
if (signRes.pendingTransactionId) {
|
|
2558
|
-
|
|
2313
|
+
onPoll == null ? void 0 : onPoll();
|
|
2314
|
+
continue;
|
|
2559
2315
|
} else {
|
|
2560
2316
|
break;
|
|
2561
2317
|
}
|
|
@@ -2581,7 +2337,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2581
2337
|
}) {
|
|
2582
2338
|
let signRes;
|
|
2583
2339
|
switch (wallet.scheme) {
|
|
2584
|
-
case
|
|
2340
|
+
case "ED25519":
|
|
2585
2341
|
signRes = yield this.platformUtils.ed25519Sign(
|
|
2586
2342
|
this.ctx,
|
|
2587
2343
|
signerId,
|
|
@@ -2599,7 +2355,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2599
2355
|
wallet.signer,
|
|
2600
2356
|
messageBase64,
|
|
2601
2357
|
this.retrieveSessionCookie(),
|
|
2602
|
-
wallet.scheme ===
|
|
2358
|
+
wallet.scheme === "DKLS",
|
|
2603
2359
|
cosmosSignDocBase64
|
|
2604
2360
|
);
|
|
2605
2361
|
break;
|
|
@@ -2620,7 +2376,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2620
2376
|
walletId,
|
|
2621
2377
|
rlpEncodedTxBase64,
|
|
2622
2378
|
chainId,
|
|
2623
|
-
timeoutMs = 3e4
|
|
2379
|
+
timeoutMs = 3e4,
|
|
2380
|
+
isCanceled = () => false,
|
|
2381
|
+
onCancel,
|
|
2382
|
+
onPoll
|
|
2624
2383
|
}) {
|
|
2625
2384
|
this.assertIsValidWalletId(walletId);
|
|
2626
2385
|
const wallet = this.wallets[walletId];
|
|
@@ -2636,7 +2395,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2636
2395
|
rlpEncodedTxBase64,
|
|
2637
2396
|
chainId,
|
|
2638
2397
|
this.retrieveSessionCookie(),
|
|
2639
|
-
wallet.scheme ===
|
|
2398
|
+
wallet.scheme === "DKLS"
|
|
2640
2399
|
);
|
|
2641
2400
|
let timeStart = Date.now();
|
|
2642
2401
|
if (signRes.pendingTransactionId) {
|
|
@@ -2648,11 +2407,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2648
2407
|
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2649
2408
|
return signRes;
|
|
2650
2409
|
}
|
|
2651
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2652
2410
|
while (true) {
|
|
2653
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
2411
|
+
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2412
|
+
onCancel == null ? void 0 : onCancel();
|
|
2654
2413
|
break;
|
|
2655
2414
|
}
|
|
2415
|
+
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2656
2416
|
try {
|
|
2657
2417
|
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2658
2418
|
} catch (err) {
|
|
@@ -2668,10 +2428,11 @@ const _ParaCore = class _ParaCore {
|
|
|
2668
2428
|
rlpEncodedTxBase64,
|
|
2669
2429
|
chainId,
|
|
2670
2430
|
this.retrieveSessionCookie(),
|
|
2671
|
-
wallet.scheme ===
|
|
2431
|
+
wallet.scheme === "DKLS"
|
|
2672
2432
|
);
|
|
2673
2433
|
if (signRes.pendingTransactionId) {
|
|
2674
|
-
|
|
2434
|
+
onPoll == null ? void 0 : onPoll();
|
|
2435
|
+
continue;
|
|
2675
2436
|
} else {
|
|
2676
2437
|
break;
|
|
2677
2438
|
}
|
|
@@ -2688,44 +2449,6 @@ const _ParaCore = class _ParaCore {
|
|
|
2688
2449
|
return signRes;
|
|
2689
2450
|
});
|
|
2690
2451
|
}
|
|
2691
|
-
/**
|
|
2692
|
-
* @deprecated
|
|
2693
|
-
* Sends a transaction.
|
|
2694
|
-
* @param walletId - id of the wallet to send the transaction from.
|
|
2695
|
-
* @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
|
|
2696
|
-
* @param chainId - chain id of the chain the transaction is being sent on.
|
|
2697
|
-
**/
|
|
2698
|
-
sendTransaction(_0) {
|
|
2699
|
-
return __async(this, arguments, function* ({
|
|
2700
|
-
walletId,
|
|
2701
|
-
rlpEncodedTxBase64,
|
|
2702
|
-
chainId
|
|
2703
|
-
}) {
|
|
2704
|
-
this.assertIsValidWalletId(walletId);
|
|
2705
|
-
const wallet = this.wallets[walletId];
|
|
2706
|
-
const signRes = yield this.platformUtils.sendTransaction(
|
|
2707
|
-
this.ctx,
|
|
2708
|
-
this.userId,
|
|
2709
|
-
walletId,
|
|
2710
|
-
this.wallets[walletId].signer,
|
|
2711
|
-
rlpEncodedTxBase64,
|
|
2712
|
-
chainId,
|
|
2713
|
-
this.retrieveSessionCookie(),
|
|
2714
|
-
wallet.scheme === WalletScheme.DKLS
|
|
2715
|
-
);
|
|
2716
|
-
if (signRes.pendingTransactionId) {
|
|
2717
|
-
this.platformUtils.openPopup(
|
|
2718
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
2719
|
-
{ type: PopupType.SIGN_TRANSACTION_REVIEW }
|
|
2720
|
-
);
|
|
2721
|
-
const error = new TransactionReviewError(
|
|
2722
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId)
|
|
2723
|
-
);
|
|
2724
|
-
throw error;
|
|
2725
|
-
}
|
|
2726
|
-
return signRes;
|
|
2727
|
-
});
|
|
2728
|
-
}
|
|
2729
2452
|
isProviderModalDisabled() {
|
|
2730
2453
|
return !!this.disableProviderModal;
|
|
2731
2454
|
}
|
|
@@ -2775,17 +2498,13 @@ const _ParaCore = class _ParaCore {
|
|
|
2775
2498
|
* @param {boolean} excludeSigners - whether or not to exclude the signer from the exported wallets.
|
|
2776
2499
|
* @returns {string} the serialized session
|
|
2777
2500
|
*/
|
|
2778
|
-
exportSession({ excludeSigners } = {}) {
|
|
2501
|
+
exportSession({ excludeSigners = false } = {}) {
|
|
2779
2502
|
const sessionInfo = {
|
|
2780
|
-
|
|
2503
|
+
authInfo: __privateGet(this, _authInfo),
|
|
2781
2504
|
userId: this.userId,
|
|
2782
2505
|
wallets: structuredClone(this.wallets),
|
|
2783
2506
|
currentWalletIds: this.currentWalletIds,
|
|
2784
|
-
sessionCookie: this.
|
|
2785
|
-
phone: this.phone,
|
|
2786
|
-
countryCode: this.countryCode,
|
|
2787
|
-
telegramUserId: this.telegramUserId,
|
|
2788
|
-
farcasterUsername: this.farcasterUsername,
|
|
2507
|
+
sessionCookie: this.retrieveSessionCookie(),
|
|
2789
2508
|
externalWallets: this.externalWallets
|
|
2790
2509
|
};
|
|
2791
2510
|
if (excludeSigners) {
|
|
@@ -2801,12 +2520,11 @@ const _ParaCore = class _ParaCore {
|
|
|
2801
2520
|
*/
|
|
2802
2521
|
importSession(serializedInstanceBase64) {
|
|
2803
2522
|
return __async(this, null, function* () {
|
|
2804
|
-
var _a;
|
|
2523
|
+
var _a, _b;
|
|
2805
2524
|
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
2806
|
-
const sessionInfo =
|
|
2807
|
-
|
|
2808
|
-
yield this.
|
|
2809
|
-
yield this.setFarcasterUsername(sessionInfo.farcasterUsername);
|
|
2525
|
+
const sessionInfo = jsonParse(serializedInstance);
|
|
2526
|
+
const authInfo = (_a = sessionInfo.authInfo) != null ? _a : __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, sessionInfo);
|
|
2527
|
+
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
2810
2528
|
yield this.setUserId(sessionInfo.userId);
|
|
2811
2529
|
yield this.setWallets(sessionInfo.wallets);
|
|
2812
2530
|
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
@@ -2821,42 +2539,23 @@ const _ParaCore = class _ParaCore {
|
|
|
2821
2539
|
const currentWalletIds = {};
|
|
2822
2540
|
for (const walletId of Object.keys(sessionInfo.wallets)) {
|
|
2823
2541
|
currentWalletIds[sessionInfo.wallets[walletId].type] = [
|
|
2824
|
-
...(
|
|
2542
|
+
...(_b = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _b : [],
|
|
2825
2543
|
walletId
|
|
2826
2544
|
];
|
|
2827
2545
|
}
|
|
2828
2546
|
yield this.setCurrentWalletIds(currentWalletIds);
|
|
2829
2547
|
}
|
|
2830
2548
|
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
2831
|
-
yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
2832
2549
|
});
|
|
2833
2550
|
}
|
|
2834
|
-
exitAccountCreation() {
|
|
2835
|
-
this.isAwaitingAccountCreation = false;
|
|
2836
|
-
}
|
|
2837
|
-
exitLogin() {
|
|
2838
|
-
this.isAwaitingLogin = false;
|
|
2839
|
-
}
|
|
2840
|
-
exitFarcaster() {
|
|
2841
|
-
this.isAwaitingFarcaster = false;
|
|
2842
|
-
}
|
|
2843
|
-
exitOAuth() {
|
|
2844
|
-
this.isAwaitingOAuth = false;
|
|
2845
|
-
}
|
|
2846
|
-
exitLoops() {
|
|
2847
|
-
this.exitAccountCreation();
|
|
2848
|
-
this.exitLogin();
|
|
2849
|
-
this.exitFarcaster();
|
|
2850
|
-
this.exitOAuth();
|
|
2851
|
-
}
|
|
2852
2551
|
/**
|
|
2853
2552
|
* Retrieves a token to verify the current session.
|
|
2854
2553
|
* @returns {Promise<string>} the ID
|
|
2855
2554
|
**/
|
|
2856
2555
|
getVerificationToken() {
|
|
2857
2556
|
return __async(this, null, function* () {
|
|
2858
|
-
const {
|
|
2859
|
-
return
|
|
2557
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
2558
|
+
return sessionLookupId;
|
|
2860
2559
|
});
|
|
2861
2560
|
}
|
|
2862
2561
|
/**
|
|
@@ -2881,22 +2580,18 @@ const _ParaCore = class _ParaCore {
|
|
|
2881
2580
|
this.currentWalletIds = {};
|
|
2882
2581
|
this.externalWallets = {};
|
|
2883
2582
|
this.loginEncryptionKeyPair = void 0;
|
|
2884
|
-
this
|
|
2885
|
-
this.telegramUserId = void 0;
|
|
2886
|
-
this.phone = void 0;
|
|
2887
|
-
this.countryCode = void 0;
|
|
2583
|
+
__privateSet(this, _authInfo, void 0);
|
|
2888
2584
|
this.userId = void 0;
|
|
2889
2585
|
this.sessionCookie = void 0;
|
|
2890
2586
|
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
2891
2587
|
});
|
|
2892
2588
|
}
|
|
2589
|
+
/** @deprecated */
|
|
2893
2590
|
getSupportedCreateAuthMethods() {
|
|
2894
2591
|
return __async(this, null, function* () {
|
|
2895
|
-
const
|
|
2896
|
-
const partnerId = res.data.partnerId;
|
|
2897
|
-
const partnerRes = yield this.ctx.client.getPartner(partnerId);
|
|
2592
|
+
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2898
2593
|
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
2899
|
-
for (const authMethod of
|
|
2594
|
+
for (const authMethod of partner.supportedAuthMethods) {
|
|
2900
2595
|
supportedAuthMethods.add(AuthMethod[authMethod]);
|
|
2901
2596
|
}
|
|
2902
2597
|
return supportedAuthMethods;
|
|
@@ -2908,6 +2603,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2908
2603
|
* Doesn't work for all types of logging.
|
|
2909
2604
|
**/
|
|
2910
2605
|
toString() {
|
|
2606
|
+
var _a, _b, _c;
|
|
2911
2607
|
const redactedWallets = Object.keys(this.wallets).reduce(
|
|
2912
2608
|
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
2913
2609
|
[walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
@@ -2925,16 +2621,15 @@ const _ParaCore = class _ParaCore {
|
|
|
2925
2621
|
{}
|
|
2926
2622
|
);
|
|
2927
2623
|
const obj = {
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
telegramUserId: this.telegramUserId,
|
|
2934
|
-
farcasterUsername: this.farcasterUsername,
|
|
2624
|
+
partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
|
|
2625
|
+
supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
|
|
2626
|
+
cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
|
|
2627
|
+
authInfo: __privateGet(this, _authInfo),
|
|
2628
|
+
isGuestMode: this.isGuestMode,
|
|
2935
2629
|
userId: this.userId,
|
|
2936
2630
|
pregenIds: this.pregenIds,
|
|
2937
2631
|
currentWalletIds: this.currentWalletIds,
|
|
2632
|
+
guestWalletIds: __privateGet(this, _ParaCore_instances, guestWalletIds_get),
|
|
2938
2633
|
wallets: redactedWallets,
|
|
2939
2634
|
externalWallets: redactedExternalWallets,
|
|
2940
2635
|
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
@@ -2951,25 +2646,201 @@ const _ParaCore = class _ParaCore {
|
|
|
2951
2646
|
};
|
|
2952
2647
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
2953
2648
|
}
|
|
2649
|
+
getNewCredentialAndUrl() {
|
|
2650
|
+
return __async(this, arguments, function* ({
|
|
2651
|
+
authMethod = "PASSKEY",
|
|
2652
|
+
isForNewDevice = false,
|
|
2653
|
+
portalTheme,
|
|
2654
|
+
shorten = false
|
|
2655
|
+
} = {}) {
|
|
2656
|
+
this.assertIsAuthSet();
|
|
2657
|
+
let credentialId, urlType;
|
|
2658
|
+
switch (authMethod) {
|
|
2659
|
+
case "PASSKEY":
|
|
2660
|
+
({
|
|
2661
|
+
data: { id: credentialId }
|
|
2662
|
+
} = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2663
|
+
status: PublicKeyStatus.PENDING,
|
|
2664
|
+
type: PublicKeyType.WEB
|
|
2665
|
+
}));
|
|
2666
|
+
urlType = "createAuth";
|
|
2667
|
+
break;
|
|
2668
|
+
case "PASSWORD":
|
|
2669
|
+
({
|
|
2670
|
+
data: { id: credentialId }
|
|
2671
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
2672
|
+
status: PasswordStatus.PENDING
|
|
2673
|
+
}));
|
|
2674
|
+
urlType = "createPassword";
|
|
2675
|
+
break;
|
|
2676
|
+
}
|
|
2677
|
+
const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
|
|
2678
|
+
isForNewDevice,
|
|
2679
|
+
pathId: credentialId,
|
|
2680
|
+
portalTheme,
|
|
2681
|
+
shorten
|
|
2682
|
+
});
|
|
2683
|
+
return __spreadValues({ credentialId }, url ? { url } : {});
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* Returns a Para Portal URL for logging in with a WebAuth passkey or a password.
|
|
2688
|
+
* @param {Object} opts the options object
|
|
2689
|
+
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
2690
|
+
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
2691
|
+
* @param {Theme} opts.portalTheme the Para Portal theme to apply to the password creation URL, if other than the default theme
|
|
2692
|
+
* @returns {SignUpOrLogInResponse} an object in the form of either: `{ stage: 'verify' }` or `{ stage: 'login'; passkeyUrl?: string; passwordUrl?: string; biometricHints?: BiometricLocationHint[] }`
|
|
2693
|
+
*/
|
|
2694
|
+
getLoginUrl(_0) {
|
|
2695
|
+
return __async(this, arguments, function* ({
|
|
2696
|
+
authMethod = "PASSKEY",
|
|
2697
|
+
shorten = false,
|
|
2698
|
+
portalTheme,
|
|
2699
|
+
sessionId
|
|
2700
|
+
}) {
|
|
2701
|
+
if (!sessionId) {
|
|
2702
|
+
sessionId = (yield this.touchSession()).sessionLookupId;
|
|
2703
|
+
}
|
|
2704
|
+
this.assertIsAuthSet();
|
|
2705
|
+
let urlType;
|
|
2706
|
+
switch (authMethod) {
|
|
2707
|
+
case "PASSKEY":
|
|
2708
|
+
urlType = "loginAuth";
|
|
2709
|
+
break;
|
|
2710
|
+
case "PASSWORD":
|
|
2711
|
+
urlType = "loginPassword";
|
|
2712
|
+
break;
|
|
2713
|
+
default:
|
|
2714
|
+
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
2715
|
+
}
|
|
2716
|
+
return this.constructPortalUrl(urlType, {
|
|
2717
|
+
sessionId,
|
|
2718
|
+
shorten,
|
|
2719
|
+
portalTheme
|
|
2720
|
+
});
|
|
2721
|
+
});
|
|
2722
|
+
}
|
|
2723
|
+
signUpOrLogIn(_o) {
|
|
2724
|
+
return __async(this, null, function* () {
|
|
2725
|
+
var _p = _o, { auth } = _p, urlOptions = __objRest(_p, ["auth"]);
|
|
2726
|
+
const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
2727
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
verifyNewAccount(_q) {
|
|
2731
|
+
return __async(this, null, function* () {
|
|
2732
|
+
var _r = _q, {
|
|
2733
|
+
verificationCode
|
|
2734
|
+
} = _r, urlOptions = __objRest(_r, [
|
|
2735
|
+
"verificationCode"
|
|
2736
|
+
]);
|
|
2737
|
+
this.assertIsAuthSet(["email", "phone"]);
|
|
2738
|
+
const userId = this.assertUserId();
|
|
2739
|
+
const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
|
|
2740
|
+
verificationCode
|
|
2741
|
+
});
|
|
2742
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2743
|
+
});
|
|
2744
|
+
}
|
|
2954
2745
|
};
|
|
2955
|
-
|
|
2956
|
-
|
|
2746
|
+
_authInfo = new WeakMap();
|
|
2747
|
+
_partner = new WeakMap();
|
|
2957
2748
|
_ParaCore_instances = new WeakSet();
|
|
2749
|
+
assertPartner_fn = function() {
|
|
2750
|
+
return __async(this, null, function* () {
|
|
2751
|
+
var _a, _b;
|
|
2752
|
+
if (!__privateGet(this, _partner)) {
|
|
2753
|
+
yield this.touchSession();
|
|
2754
|
+
}
|
|
2755
|
+
if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
|
|
2756
|
+
this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
|
|
2757
|
+
}
|
|
2758
|
+
return __privateGet(this, _partner);
|
|
2759
|
+
});
|
|
2760
|
+
};
|
|
2761
|
+
guestWalletIds_get = function() {
|
|
2762
|
+
var _a, _b, _c;
|
|
2763
|
+
if (!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
2764
|
+
return {};
|
|
2765
|
+
}
|
|
2766
|
+
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
2767
|
+
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
2768
|
+
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
2769
|
+
return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) => __privateGet(this, _partner).supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
2770
|
+
var _a2;
|
|
2771
|
+
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
2772
|
+
}, {}));
|
|
2773
|
+
}
|
|
2774
|
+
return acc;
|
|
2775
|
+
}, {}) : {};
|
|
2776
|
+
};
|
|
2777
|
+
guestWalletIdsArray_get = function() {
|
|
2778
|
+
return Object.entries(__privateGet(this, _ParaCore_instances, guestWalletIds_get)).reduce((acc, [type, ids]) => {
|
|
2779
|
+
return [...acc, ...ids.map((id) => [id, type])];
|
|
2780
|
+
}, []);
|
|
2781
|
+
};
|
|
2782
|
+
toAuthInfo_fn = function({
|
|
2783
|
+
email,
|
|
2784
|
+
phone,
|
|
2785
|
+
countryCode,
|
|
2786
|
+
farcasterUsername,
|
|
2787
|
+
telegramUserId,
|
|
2788
|
+
externalWalletAddress
|
|
2789
|
+
}) {
|
|
2790
|
+
let auth;
|
|
2791
|
+
switch (true) {
|
|
2792
|
+
case !!email:
|
|
2793
|
+
auth = { email };
|
|
2794
|
+
break;
|
|
2795
|
+
case !!phone:
|
|
2796
|
+
{
|
|
2797
|
+
const validPhone = formatPhoneNumber(phone, countryCode);
|
|
2798
|
+
if (validPhone) auth = { phone: formatPhoneNumber(phone, countryCode) };
|
|
2799
|
+
}
|
|
2800
|
+
break;
|
|
2801
|
+
case !!farcasterUsername:
|
|
2802
|
+
auth = { farcasterUsername };
|
|
2803
|
+
break;
|
|
2804
|
+
case !!telegramUserId:
|
|
2805
|
+
auth = { telegramUserId };
|
|
2806
|
+
break;
|
|
2807
|
+
case !!externalWalletAddress:
|
|
2808
|
+
auth = { externalWalletAddress };
|
|
2809
|
+
break;
|
|
2810
|
+
}
|
|
2811
|
+
return extractAuthInfo(auth);
|
|
2812
|
+
};
|
|
2813
|
+
setAuthInfo_fn = function(authInfo) {
|
|
2814
|
+
return __async(this, null, function* () {
|
|
2815
|
+
__privateSet(this, _authInfo, authInfo);
|
|
2816
|
+
yield this.localStorageSetItem(constants.LOCAL_STORAGE_AUTH_INFO, JSON.stringify(authInfo));
|
|
2817
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_EMAIL);
|
|
2818
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_PHONE);
|
|
2819
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_COUNTRY_CODE);
|
|
2820
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME);
|
|
2821
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID);
|
|
2822
|
+
});
|
|
2823
|
+
};
|
|
2824
|
+
getPartner_fn = function(partnerId) {
|
|
2825
|
+
return __async(this, null, function* () {
|
|
2826
|
+
const res = yield this.ctx.client.getPartner(partnerId);
|
|
2827
|
+
__privateSet(this, _partner, res.data.partner);
|
|
2828
|
+
return __privateGet(this, _partner);
|
|
2829
|
+
});
|
|
2830
|
+
};
|
|
2958
2831
|
createPregenWallet_fn = function(opts) {
|
|
2959
2832
|
return __async(this, null, function* () {
|
|
2960
2833
|
var _a, _b;
|
|
2961
|
-
const {
|
|
2962
|
-
|
|
2963
|
-
pregenIdentifier,
|
|
2964
|
-
pregenIdentifierType = "EMAIL"
|
|
2965
|
-
} = opts;
|
|
2834
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2835
|
+
const { type: _type = (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type, pregenId } = opts;
|
|
2966
2836
|
this.requireApiKey();
|
|
2967
2837
|
const walletType = yield this.assertIsValidWalletType(
|
|
2968
|
-
_type != null ? _type : (_b =
|
|
2838
|
+
_type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
2969
2839
|
);
|
|
2840
|
+
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
2970
2841
|
let keygenRes;
|
|
2971
2842
|
switch (walletType) {
|
|
2972
|
-
case
|
|
2843
|
+
case "SOLANA":
|
|
2973
2844
|
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
2974
2845
|
this.ctx,
|
|
2975
2846
|
pregenIdentifier,
|
|
@@ -2993,7 +2864,7 @@ createPregenWallet_fn = function(opts) {
|
|
|
2993
2864
|
this.wallets[walletId] = {
|
|
2994
2865
|
id: walletId,
|
|
2995
2866
|
signer,
|
|
2996
|
-
scheme: walletType ===
|
|
2867
|
+
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
2997
2868
|
type: walletType,
|
|
2998
2869
|
isPregen: true,
|
|
2999
2870
|
pregenIdentifier,
|
|
@@ -3004,6 +2875,114 @@ createPregenWallet_fn = function(opts) {
|
|
|
3004
2875
|
return this.wallets[walletId];
|
|
3005
2876
|
});
|
|
3006
2877
|
};
|
|
2878
|
+
_isCreateGuestWalletsPending = new WeakMap();
|
|
2879
|
+
prepareAuthState_fn = function(_0) {
|
|
2880
|
+
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
2881
|
+
if (!opts.sessionLookupId && serverAuthState.stage === "login") {
|
|
2882
|
+
opts.sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
2883
|
+
}
|
|
2884
|
+
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
2885
|
+
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), Object.fromEntries(
|
|
2886
|
+
Object.entries({
|
|
2887
|
+
displayName,
|
|
2888
|
+
pfpUrl,
|
|
2889
|
+
username,
|
|
2890
|
+
externalWallet
|
|
2891
|
+
}).filter(([_, v]) => !!v)
|
|
2892
|
+
));
|
|
2893
|
+
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
2894
|
+
yield this.assertIsAuthSet();
|
|
2895
|
+
if (!!externalWallet) {
|
|
2896
|
+
yield this.setExternalWallet(externalWallet);
|
|
2897
|
+
}
|
|
2898
|
+
if (!!userId) {
|
|
2899
|
+
yield this.setUserId(userId);
|
|
2900
|
+
}
|
|
2901
|
+
let authState;
|
|
2902
|
+
switch (serverAuthState.stage) {
|
|
2903
|
+
case "verify":
|
|
2904
|
+
authState = serverAuthState;
|
|
2905
|
+
break;
|
|
2906
|
+
case "login":
|
|
2907
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
|
|
2908
|
+
break;
|
|
2909
|
+
case "signup":
|
|
2910
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
|
|
2911
|
+
break;
|
|
2912
|
+
}
|
|
2913
|
+
return authState;
|
|
2914
|
+
});
|
|
2915
|
+
};
|
|
2916
|
+
prepareLogin_fn = function() {
|
|
2917
|
+
return __async(this, null, function* () {
|
|
2918
|
+
yield this.logout();
|
|
2919
|
+
const { sessionLookupId } = yield this.touchSession(true);
|
|
2920
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2921
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2922
|
+
}
|
|
2923
|
+
return sessionLookupId;
|
|
2924
|
+
});
|
|
2925
|
+
};
|
|
2926
|
+
prepareLoginState_fn = function(_0, _1) {
|
|
2927
|
+
return __async(this, arguments, function* (loginState, {
|
|
2928
|
+
useShortUrls: shorten = false,
|
|
2929
|
+
portalTheme,
|
|
2930
|
+
sessionLookupId
|
|
2931
|
+
}) {
|
|
2932
|
+
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
2933
|
+
return __spreadValues(__spreadValues(__spreadValues({}, authState), !this.isNativePasskey && loginAuthMethods.includes(AuthMethod.PASSKEY) ? {
|
|
2934
|
+
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
2935
|
+
passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
|
|
2936
|
+
sessionId: sessionLookupId,
|
|
2937
|
+
newDevice: {
|
|
2938
|
+
sessionId: sessionLookupId,
|
|
2939
|
+
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
2940
|
+
},
|
|
2941
|
+
shorten,
|
|
2942
|
+
portalTheme
|
|
2943
|
+
})
|
|
2944
|
+
} : {}), loginAuthMethods.includes(AuthMethod.PASSWORD) ? {
|
|
2945
|
+
passwordUrl: yield this.constructPortalUrl("loginPassword", {
|
|
2946
|
+
sessionId: sessionLookupId,
|
|
2947
|
+
shorten,
|
|
2948
|
+
portalTheme
|
|
2949
|
+
})
|
|
2950
|
+
} : {});
|
|
2951
|
+
});
|
|
2952
|
+
};
|
|
2953
|
+
prepareSignUpState_fn = function(_0, _1) {
|
|
2954
|
+
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
2955
|
+
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
2956
|
+
const [isPasskey, isPassword] = [
|
|
2957
|
+
signupAuthMethods.includes(AuthMethod.PASSKEY),
|
|
2958
|
+
signupAuthMethods.includes(AuthMethod.PASSWORD)
|
|
2959
|
+
];
|
|
2960
|
+
if (!isPasskey && !isPassword) {
|
|
2961
|
+
throw new Error(
|
|
2962
|
+
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or passwords in your Developer Portal settings."
|
|
2963
|
+
);
|
|
2964
|
+
}
|
|
2965
|
+
const signupState = authState;
|
|
2966
|
+
if (isPasskey) {
|
|
2967
|
+
const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
|
|
2968
|
+
authMethod: "PASSKEY",
|
|
2969
|
+
shorten
|
|
2970
|
+
});
|
|
2971
|
+
if (passkeyUrl) signupState.passkeyUrl = passkeyUrl;
|
|
2972
|
+
signupState.passkeyId = passkeyId;
|
|
2973
|
+
}
|
|
2974
|
+
if (isPassword) {
|
|
2975
|
+
const { url: passwordUrl, credentialId: passwordId } = yield this.getNewCredentialAndUrl({
|
|
2976
|
+
authMethod: "PASSWORD",
|
|
2977
|
+
portalTheme,
|
|
2978
|
+
shorten
|
|
2979
|
+
});
|
|
2980
|
+
signupState.passwordUrl = passwordUrl;
|
|
2981
|
+
signupState.passwordId = passwordId;
|
|
2982
|
+
}
|
|
2983
|
+
return signupState;
|
|
2984
|
+
});
|
|
2985
|
+
};
|
|
3007
2986
|
_ParaCore.version = constants.PARA_CORE_VERSION;
|
|
3008
2987
|
let ParaCore = _ParaCore;
|
|
3009
2988
|
export {
|