@getpara/core-sdk 1.11.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 +998 -979
- package/dist/cjs/constants.js +10 -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 +1016 -985
- package/dist/esm/constants.js +7 -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 +106 -391
- package/dist/types/PlatformUtils.d.ts +4 -3
- package/dist/types/constants.d.ts +3 -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 +5 -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 +6 -5
- 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
|
};
|
|
@@ -113,39 +131,73 @@ const _ParaCore = class _ParaCore {
|
|
|
113
131
|
this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
114
132
|
}
|
|
115
133
|
});
|
|
134
|
+
this.trackError = (methodName, err) => __async(this, null, function* () {
|
|
135
|
+
try {
|
|
136
|
+
yield this.ctx.client.trackError({
|
|
137
|
+
methodName,
|
|
138
|
+
sdkType: this.platformUtils.sdkType,
|
|
139
|
+
userId: this.userId,
|
|
140
|
+
error: {
|
|
141
|
+
name: err.name,
|
|
142
|
+
message: err.message
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.error("error tracking error:", e);
|
|
147
|
+
}
|
|
148
|
+
throw err;
|
|
149
|
+
});
|
|
150
|
+
this.wrapMethodsWithErrorTracking = (methodNames) => {
|
|
151
|
+
for (const methodName of methodNames) {
|
|
152
|
+
const original = this[methodName];
|
|
153
|
+
if (typeof original === "function") {
|
|
154
|
+
this[methodName] = (...args) => {
|
|
155
|
+
try {
|
|
156
|
+
const result = original.apply(this, args);
|
|
157
|
+
return result instanceof Promise ? result.catch((err) => this.trackError(methodName, err)) : result;
|
|
158
|
+
} catch (err) {
|
|
159
|
+
return this.trackError(methodName, err);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
116
165
|
this.initializeFromStorage = () => {
|
|
117
|
-
this.
|
|
118
|
-
this.
|
|
119
|
-
this.updatePhoneFromStorage();
|
|
166
|
+
this.updateExternalWalletsFromStorage();
|
|
167
|
+
this.updateAuthInfoFromStorage();
|
|
120
168
|
this.updateUserIdFromStorage();
|
|
121
|
-
this.updateTelegramUserIdFromStorage();
|
|
122
169
|
this.updateWalletsFromStorage();
|
|
123
170
|
this.updateWalletIdsFromStorage();
|
|
124
171
|
this.updateSessionCookieFromStorage();
|
|
125
172
|
this.updateLoginEncryptionKeyPairFromStorage();
|
|
126
|
-
this.updateExternalWalletsFromStorage();
|
|
127
173
|
};
|
|
128
|
-
this.
|
|
129
|
-
|
|
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);
|
|
130
191
|
};
|
|
131
192
|
this.updateUserIdFromStorage = () => {
|
|
132
193
|
this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
133
194
|
};
|
|
134
|
-
this.updatePhoneFromStorage = () => {
|
|
135
|
-
this.phone = this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE) || void 0;
|
|
136
|
-
};
|
|
137
|
-
this.updateCountryCodeFromStorage = () => {
|
|
138
|
-
this.countryCode = this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE) || void 0;
|
|
139
|
-
};
|
|
140
|
-
this.updateEmailFromStorage = () => {
|
|
141
|
-
this.email = this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL) || void 0;
|
|
142
|
-
};
|
|
143
195
|
this.updateWalletsFromStorage = () => __async(this, null, function* () {
|
|
144
196
|
var _a;
|
|
145
197
|
const _currentWalletIds = (_a = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
146
198
|
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
147
199
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
148
|
-
return Array.isArray(fromJson) ?
|
|
200
|
+
return Array.isArray(fromJson) ? WALLET_TYPES.reduce((acc, type) => {
|
|
149
201
|
const wallet = Object.values(this.wallets).find(
|
|
150
202
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
151
203
|
);
|
|
@@ -169,9 +221,9 @@ const _ParaCore = class _ParaCore {
|
|
|
169
221
|
this.updateWalletIdsFromStorage = () => {
|
|
170
222
|
var _a;
|
|
171
223
|
const _currentWalletIds = (_a = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
172
|
-
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
224
|
+
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
173
225
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
174
|
-
return Array.isArray(fromJson) ?
|
|
226
|
+
return Array.isArray(fromJson) ? WALLET_TYPES.reduce((acc, type) => {
|
|
175
227
|
const wallet = Object.values(this.wallets).find(
|
|
176
228
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
177
229
|
);
|
|
@@ -206,18 +258,23 @@ const _ParaCore = class _ParaCore {
|
|
|
206
258
|
* @deprecated alias for `createWalletPerType`
|
|
207
259
|
**/
|
|
208
260
|
this.createWalletPerMissingType = this.createWalletPerType;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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;
|
|
214
267
|
});
|
|
268
|
+
if (!apiKey) {
|
|
269
|
+
throw new Error("A Para API key is required.");
|
|
270
|
+
}
|
|
215
271
|
if (!opts) opts = {};
|
|
216
272
|
let isE2E = false;
|
|
217
273
|
if (env === "E2E") {
|
|
218
274
|
isE2E = true;
|
|
219
275
|
env = Environment.SANDBOX;
|
|
220
276
|
}
|
|
277
|
+
this.externalWalletConnectionOnly = opts.externalWalletConnectionOnly;
|
|
221
278
|
this.emailPrimaryColor = opts.emailPrimaryColor;
|
|
222
279
|
this.emailTheme = opts.emailTheme;
|
|
223
280
|
this.homepageUrl = opts.homepageUrl;
|
|
@@ -269,72 +326,103 @@ const _ParaCore = class _ParaCore {
|
|
|
269
326
|
useDKLS: opts.useDKLSForCreation || !opts.offloadMPCComputationURL,
|
|
270
327
|
disableWebSockets: !!opts.disableWebSockets,
|
|
271
328
|
wasmOverride: opts.wasmOverride,
|
|
272
|
-
cosmosPrefix: this.cosmosPrefix,
|
|
273
329
|
isE2E
|
|
274
330
|
};
|
|
275
331
|
if (opts.offloadMPCComputationURL) {
|
|
276
332
|
this.ctx.mpcComputationClient = mpcComputationClient.initClient(opts.offloadMPCComputationURL, opts.disableWorkers);
|
|
277
333
|
}
|
|
278
|
-
try {
|
|
279
|
-
__privateSet(this, _supportedWalletTypes, opts.supportedWalletTypes ? (() => {
|
|
280
|
-
if (Object.values(opts.supportedWalletTypes).every(
|
|
281
|
-
(config) => !!config && typeof config === "object" && config.optional
|
|
282
|
-
)) {
|
|
283
|
-
throw new Error("at least one wallet type must be non-optional");
|
|
284
|
-
}
|
|
285
|
-
if (!Object.keys(opts.supportedWalletTypes).every((type) => Object.values(WalletType).includes(type))) {
|
|
286
|
-
throw new Error("unsupported wallet type");
|
|
287
|
-
}
|
|
288
|
-
__privateSet(this, _supportedWalletTypesOpt, opts.supportedWalletTypes);
|
|
289
|
-
return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
|
|
290
|
-
var _a;
|
|
291
|
-
if (!value) {
|
|
292
|
-
return acc;
|
|
293
|
-
}
|
|
294
|
-
if (key === WalletType.COSMOS && typeof value === "object" && !!value.prefix) {
|
|
295
|
-
this.cosmosPrefix = value.prefix;
|
|
296
|
-
}
|
|
297
|
-
return [...acc, { type: key, optional: value === true ? false : (_a = value.optional) != null ? _a : false }];
|
|
298
|
-
}, []);
|
|
299
|
-
})() : void 0);
|
|
300
|
-
} catch (e) {
|
|
301
|
-
__privateSet(this, _supportedWalletTypes, void 0);
|
|
302
|
-
}
|
|
303
334
|
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
304
335
|
return;
|
|
305
336
|
}
|
|
306
337
|
this.initializeFromStorage();
|
|
307
338
|
setupListeners.bind(this)();
|
|
339
|
+
autoBind(this);
|
|
340
|
+
if (env !== Environment.PROD) {
|
|
341
|
+
this.wrapMethodsWithErrorTracking([
|
|
342
|
+
"signUpOrLogIn",
|
|
343
|
+
"verifyNewAccount",
|
|
344
|
+
"waitForLogin",
|
|
345
|
+
"waitForSignup",
|
|
346
|
+
"waitForWalletCreation",
|
|
347
|
+
"verifyOAuth",
|
|
348
|
+
"verifyTelegram",
|
|
349
|
+
"verifyFarcaster",
|
|
350
|
+
"createPregenWallet",
|
|
351
|
+
"claimPregenWallets",
|
|
352
|
+
"signMessage",
|
|
353
|
+
"signTransaction"
|
|
354
|
+
]);
|
|
355
|
+
}
|
|
308
356
|
}
|
|
309
|
-
get
|
|
310
|
-
return
|
|
357
|
+
get authInfo() {
|
|
358
|
+
return __privateGet(this, _authInfo);
|
|
311
359
|
}
|
|
312
|
-
get
|
|
313
|
-
|
|
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;
|
|
314
363
|
}
|
|
315
|
-
get
|
|
316
|
-
|
|
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;
|
|
317
367
|
}
|
|
318
|
-
get
|
|
319
|
-
|
|
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;
|
|
320
375
|
}
|
|
321
376
|
get externalWalletWithParaAuth() {
|
|
322
377
|
const externalWallets = Object.values(this.externalWallets);
|
|
323
378
|
return externalWallets.find((w) => w.isExternalWithParaAuth);
|
|
324
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
|
+
}
|
|
325
404
|
get isExternalWalletAuth() {
|
|
326
|
-
|
|
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;
|
|
327
411
|
}
|
|
328
412
|
get currentWalletIdsArray() {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
+
);
|
|
338
426
|
}
|
|
339
427
|
get currentWalletIdsUnique() {
|
|
340
428
|
return [...new Set(Object.values(this.currentWalletIds).flat())];
|
|
@@ -359,17 +447,23 @@ const _ParaCore = class _ParaCore {
|
|
|
359
447
|
* Whether the instance has multiple wallets connected.
|
|
360
448
|
*/
|
|
361
449
|
get isMultiWallet() {
|
|
362
|
-
return this.currentWalletIdsArray.length > 1;
|
|
450
|
+
return this.currentWalletIdsArray.length > 1 || __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 1;
|
|
363
451
|
}
|
|
364
452
|
get isNoWalletConfig() {
|
|
365
|
-
|
|
453
|
+
var _a;
|
|
454
|
+
return !!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) && __privateGet(this, _partner).supportedWalletTypes.length === 0;
|
|
366
455
|
}
|
|
367
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() {
|
|
368
461
|
var _a;
|
|
369
|
-
return (_a = __privateGet(this,
|
|
462
|
+
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
|
|
370
463
|
}
|
|
371
464
|
get isWalletTypeEnabled() {
|
|
372
|
-
|
|
465
|
+
var _a;
|
|
466
|
+
return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
373
467
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
374
468
|
}, {});
|
|
375
469
|
}
|
|
@@ -418,7 +512,7 @@ const _ParaCore = class _ParaCore {
|
|
|
418
512
|
}
|
|
419
513
|
isWalletSupported(wallet) {
|
|
420
514
|
var _a, _b;
|
|
421
|
-
return !
|
|
515
|
+
return !((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = __privateGet(this, _partner).supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
422
516
|
}
|
|
423
517
|
isWalletOwned(wallet) {
|
|
424
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;
|
|
@@ -434,7 +528,7 @@ const _ParaCore = class _ParaCore {
|
|
|
434
528
|
));
|
|
435
529
|
}
|
|
436
530
|
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
437
|
-
var _a;
|
|
531
|
+
var _a, _b;
|
|
438
532
|
let error;
|
|
439
533
|
if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
|
|
440
534
|
return true;
|
|
@@ -444,15 +538,15 @@ const _ParaCore = class _ParaCore {
|
|
|
444
538
|
} else {
|
|
445
539
|
const wallet = this.wallets[walletId];
|
|
446
540
|
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
447
|
-
if (forbidPregen && isUnclaimed) {
|
|
541
|
+
if (forbidPregen && isUnclaimed && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
448
542
|
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
449
543
|
} else if (!isOwned && !isUnclaimed) {
|
|
450
544
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
451
545
|
} else if (!this.isWalletSupported(wallet)) {
|
|
452
|
-
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(", ")}`;
|
|
453
547
|
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
454
|
-
var _a2,
|
|
455
|
-
return (
|
|
548
|
+
var _a2, _b2;
|
|
549
|
+
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
456
550
|
}))) {
|
|
457
551
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
|
|
458
552
|
} else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
|
|
@@ -472,14 +566,17 @@ const _ParaCore = class _ParaCore {
|
|
|
472
566
|
* @param {string} walletId the ID of the wallet address to display.
|
|
473
567
|
* @param {object} options additional options for formatting the address.
|
|
474
568
|
* @param {boolean} options.truncate whether to truncate the address.
|
|
475
|
-
* @param {
|
|
569
|
+
* @param {TWalletType} options.addressType the type of address to display.
|
|
476
570
|
* @returns the formatted address
|
|
477
571
|
*/
|
|
478
572
|
getDisplayAddress(walletId, options = {}) {
|
|
479
|
-
var _a, _b;
|
|
573
|
+
var _a, _b, _c, _d;
|
|
480
574
|
if (this.externalWallets[walletId]) {
|
|
481
575
|
const wallet2 = this.externalWallets[walletId];
|
|
482
|
-
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;
|
|
483
580
|
}
|
|
484
581
|
const wallet = this.findWallet(walletId, options.addressType);
|
|
485
582
|
if (!wallet) {
|
|
@@ -488,8 +585,8 @@ const _ParaCore = class _ParaCore {
|
|
|
488
585
|
let str;
|
|
489
586
|
let prefix;
|
|
490
587
|
switch (wallet.type) {
|
|
491
|
-
case
|
|
492
|
-
prefix = (
|
|
588
|
+
case "COSMOS":
|
|
589
|
+
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
493
590
|
str = getCosmosAddress(wallet.publicKey, prefix);
|
|
494
591
|
break;
|
|
495
592
|
default:
|
|
@@ -522,8 +619,24 @@ const _ParaCore = class _ParaCore {
|
|
|
522
619
|
}
|
|
523
620
|
constructPortalUrl(_0) {
|
|
524
621
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
525
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
526
|
-
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();
|
|
527
640
|
let path;
|
|
528
641
|
switch (type) {
|
|
529
642
|
case "createPassword": {
|
|
@@ -554,61 +667,55 @@ const _ParaCore = class _ParaCore {
|
|
|
554
667
|
throw new Error(`invalid URL type ${type}`);
|
|
555
668
|
}
|
|
556
669
|
}
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
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
|
+
};
|
|
563
675
|
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
564
676
|
apiKey: this.ctx.apiKey,
|
|
565
|
-
partnerId:
|
|
566
|
-
portalFont: ((_b = opts.
|
|
567
|
-
portalBorderRadius: ((_d = opts.
|
|
568
|
-
portalThemeMode: ((_f = opts.
|
|
569
|
-
portalAccentColor: ((_h = opts.
|
|
570
|
-
portalForegroundColor: ((_j = opts.
|
|
571
|
-
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),
|
|
572
684
|
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
573
685
|
portalTextColor: this.portalTextColor,
|
|
574
686
|
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
575
|
-
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
} : {}),
|
|
588
|
-
|
|
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;
|
|
589
707
|
});
|
|
590
708
|
}
|
|
591
709
|
touchSession(regenerate = false) {
|
|
592
710
|
return __async(this, null, function* () {
|
|
593
|
-
|
|
594
|
-
this.
|
|
595
|
-
|
|
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;
|
|
596
717
|
});
|
|
597
718
|
}
|
|
598
|
-
setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
|
|
599
|
-
if (supportedWalletTypes && !__privateGet(this, _supportedWalletTypes)) {
|
|
600
|
-
__privateSet(this, _supportedWalletTypes, supportedWalletTypes);
|
|
601
|
-
Object.keys(this.currentWalletIds).forEach((type) => {
|
|
602
|
-
var _a;
|
|
603
|
-
if (!((_a = __privateGet(this, _supportedWalletTypes)) == null ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
|
|
604
|
-
delete this.currentWalletIds[type];
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
if (cosmosPrefix && !this.cosmosPrefix) {
|
|
609
|
-
this.cosmosPrefix = cosmosPrefix;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
719
|
getVerificationEmailProps() {
|
|
613
720
|
return {
|
|
614
721
|
brandColor: this.emailPrimaryColor,
|
|
@@ -638,12 +745,26 @@ const _ParaCore = class _ParaCore {
|
|
|
638
745
|
*/
|
|
639
746
|
init() {
|
|
640
747
|
return __async(this, null, function* () {
|
|
641
|
-
var _a;
|
|
642
|
-
this.email = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL)) || void 0;
|
|
643
|
-
this.countryCode = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE)) || void 0;
|
|
644
|
-
this.phone = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE)) || void 0;
|
|
748
|
+
var _a, _b;
|
|
645
749
|
this.userId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID)) || void 0;
|
|
646
|
-
|
|
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);
|
|
647
768
|
const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_WALLETS);
|
|
648
769
|
const _wallets = JSON.parse(stringWallets || "{}");
|
|
649
770
|
const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_ED25519_WALLETS);
|
|
@@ -656,10 +777,10 @@ const _ParaCore = class _ParaCore {
|
|
|
656
777
|
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
|
|
657
778
|
}, {}));
|
|
658
779
|
yield this.setWallets(wallets);
|
|
659
|
-
const _currentWalletIds = (
|
|
780
|
+
const _currentWalletIds = (_b = yield this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _b : void 0;
|
|
660
781
|
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
661
782
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
662
|
-
return Array.isArray(fromJson) ?
|
|
783
|
+
return Array.isArray(fromJson) ? WALLET_TYPES.reduce((acc, type) => {
|
|
663
784
|
const wallet = Object.values(this.wallets).find(
|
|
664
785
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
665
786
|
);
|
|
@@ -675,21 +796,42 @@ const _ParaCore = class _ParaCore {
|
|
|
675
796
|
if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
|
|
676
797
|
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
677
798
|
}
|
|
678
|
-
const stringExternalWallets = yield this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
679
|
-
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
680
|
-
yield this.setExternalWallets(_externalWallets);
|
|
681
799
|
setupListeners.bind(this)();
|
|
682
800
|
yield this.touchSession();
|
|
683
801
|
});
|
|
684
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
|
+
}
|
|
685
828
|
/**
|
|
686
829
|
* Sets the email associated with the `ParaCore` instance.
|
|
687
830
|
* @param email - Email to set.
|
|
688
831
|
*/
|
|
689
832
|
setEmail(email) {
|
|
690
833
|
return __async(this, null, function* () {
|
|
691
|
-
this.email
|
|
692
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_EMAIL, email);
|
|
834
|
+
yield this.setAuth({ email });
|
|
693
835
|
});
|
|
694
836
|
}
|
|
695
837
|
/**
|
|
@@ -698,8 +840,7 @@ const _ParaCore = class _ParaCore {
|
|
|
698
840
|
*/
|
|
699
841
|
setTelegramUserId(telegramUserId) {
|
|
700
842
|
return __async(this, null, function* () {
|
|
701
|
-
this.telegramUserId
|
|
702
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
|
|
843
|
+
yield this.setAuth({ telegramUserId });
|
|
703
844
|
});
|
|
704
845
|
}
|
|
705
846
|
/**
|
|
@@ -709,10 +850,7 @@ const _ParaCore = class _ParaCore {
|
|
|
709
850
|
*/
|
|
710
851
|
setPhoneNumber(phone, countryCode) {
|
|
711
852
|
return __async(this, null, function* () {
|
|
712
|
-
this.phone
|
|
713
|
-
this.countryCode = countryCode;
|
|
714
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_PHONE, phone);
|
|
715
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_COUNTRY_CODE, countryCode);
|
|
853
|
+
yield this.setAuth({ phone: formatPhoneNumber(phone, countryCode) });
|
|
716
854
|
});
|
|
717
855
|
}
|
|
718
856
|
/**
|
|
@@ -721,8 +859,7 @@ const _ParaCore = class _ParaCore {
|
|
|
721
859
|
*/
|
|
722
860
|
setFarcasterUsername(farcasterUsername) {
|
|
723
861
|
return __async(this, null, function* () {
|
|
724
|
-
this.farcasterUsername
|
|
725
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
|
|
862
|
+
yield this.setAuth({ farcasterUsername });
|
|
726
863
|
});
|
|
727
864
|
}
|
|
728
865
|
/**
|
|
@@ -807,6 +944,9 @@ const _ParaCore = class _ParaCore {
|
|
|
807
944
|
getUserId() {
|
|
808
945
|
return this.userId;
|
|
809
946
|
}
|
|
947
|
+
getAuthInfo() {
|
|
948
|
+
return this.authInfo;
|
|
949
|
+
}
|
|
810
950
|
/**
|
|
811
951
|
* Gets the email associated with the `ParaCore` instance.
|
|
812
952
|
* @returns - email associated with the `ParaCore` instance.
|
|
@@ -814,22 +954,12 @@ const _ParaCore = class _ParaCore {
|
|
|
814
954
|
getEmail() {
|
|
815
955
|
return this.email;
|
|
816
956
|
}
|
|
817
|
-
/**
|
|
818
|
-
* Gets the phone object associated with the `ParaCore` instance.
|
|
819
|
-
* @returns - phone object with phone number and country code associated with the `ParaCore` instance.
|
|
820
|
-
*/
|
|
821
|
-
getPhone() {
|
|
822
|
-
return { phone: this.phone, countryCode: this.countryCode };
|
|
823
|
-
}
|
|
824
957
|
/**
|
|
825
958
|
* Gets the formatted phone number associated with the `ParaCore` instance.
|
|
826
959
|
* @returns - formatted phone number associated with the `ParaCore` instance.
|
|
827
960
|
*/
|
|
828
961
|
getPhoneNumber() {
|
|
829
|
-
|
|
830
|
-
return void 0;
|
|
831
|
-
}
|
|
832
|
-
return normalizePhoneNumber(this.countryCode, this.phone);
|
|
962
|
+
return this.phone;
|
|
833
963
|
}
|
|
834
964
|
/**
|
|
835
965
|
* Gets the farcaster username associated with the `ParaCore` instance.
|
|
@@ -868,9 +998,7 @@ const _ParaCore = class _ParaCore {
|
|
|
868
998
|
if (!(yield this.isSessionActive()) || !this.userId) {
|
|
869
999
|
throw new Error("no signed-in user");
|
|
870
1000
|
}
|
|
871
|
-
const {
|
|
872
|
-
data: { partnerId }
|
|
873
|
-
} = yield this.touchSession();
|
|
1001
|
+
const { partnerId } = yield this.touchSession();
|
|
874
1002
|
const { accountMetadata } = yield this.ctx.client.getAccountMetadata(this.userId, partnerId);
|
|
875
1003
|
return accountMetadata;
|
|
876
1004
|
});
|
|
@@ -928,8 +1056,10 @@ const _ParaCore = class _ParaCore {
|
|
|
928
1056
|
}
|
|
929
1057
|
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
930
1058
|
var _a, _c, _d;
|
|
931
|
-
if (!this.isExternalWalletAuth
|
|
932
|
-
|
|
1059
|
+
if (!this.isExternalWalletAuth) {
|
|
1060
|
+
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
1061
|
+
return Object.values(this.externalWallets)[0];
|
|
1062
|
+
}
|
|
933
1063
|
}
|
|
934
1064
|
if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
|
|
935
1065
|
return this.externalWallets[idOrAddress];
|
|
@@ -940,7 +1070,7 @@ const _ParaCore = class _ParaCore {
|
|
|
940
1070
|
const _b = this.wallets[walletId], { signer: _signer } = _b, wallet = __objRest(_b, ["signer"]);
|
|
941
1071
|
const type = (_d = overrideType != null ? overrideType : (_c = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _c[1]) != null ? _d : wallet.type;
|
|
942
1072
|
return __spreadProps(__spreadValues({}, wallet), {
|
|
943
|
-
type
|
|
1073
|
+
type
|
|
944
1074
|
});
|
|
945
1075
|
}
|
|
946
1076
|
} catch (e) {
|
|
@@ -950,7 +1080,7 @@ const _ParaCore = class _ParaCore {
|
|
|
950
1080
|
get availableWallets() {
|
|
951
1081
|
var _a;
|
|
952
1082
|
return [
|
|
953
|
-
...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]) => {
|
|
954
1084
|
const wallet = this.findWallet(id, type);
|
|
955
1085
|
if (!wallet) return null;
|
|
956
1086
|
return {
|
|
@@ -976,10 +1106,8 @@ const _ParaCore = class _ParaCore {
|
|
|
976
1106
|
}
|
|
977
1107
|
assertIsValidWalletType(type, walletTypes) {
|
|
978
1108
|
return __async(this, null, function* () {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
}
|
|
982
|
-
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)) {
|
|
983
1111
|
throw new Error(`wallet type ${type} is not supported`);
|
|
984
1112
|
}
|
|
985
1113
|
return type;
|
|
@@ -987,33 +1115,29 @@ const _ParaCore = class _ParaCore {
|
|
|
987
1115
|
}
|
|
988
1116
|
getMissingTypes() {
|
|
989
1117
|
return __async(this, null, function* () {
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
}
|
|
993
|
-
return this.supportedWalletTypes.filter(
|
|
1118
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1119
|
+
return supportedWalletTypes.filter(
|
|
994
1120
|
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
|
|
995
1121
|
).map(({ type }) => type);
|
|
996
1122
|
});
|
|
997
1123
|
}
|
|
998
1124
|
getTypesToCreate(types) {
|
|
999
1125
|
return __async(this, null, function* () {
|
|
1000
|
-
|
|
1001
|
-
yield this.touchSession();
|
|
1002
|
-
}
|
|
1126
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1003
1127
|
return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
1004
1128
|
switch (scheme) {
|
|
1005
|
-
case
|
|
1006
|
-
return
|
|
1129
|
+
case "ED25519":
|
|
1130
|
+
return "SOLANA";
|
|
1007
1131
|
default:
|
|
1008
|
-
return
|
|
1132
|
+
return supportedWalletTypes.some(({ type, optional }) => type === "COSMOS" && !optional) ? "COSMOS" : "EVM";
|
|
1009
1133
|
}
|
|
1010
1134
|
});
|
|
1011
1135
|
});
|
|
1012
1136
|
}
|
|
1013
|
-
getPartnerURL(
|
|
1137
|
+
getPartnerURL() {
|
|
1014
1138
|
return __async(this, null, function* () {
|
|
1015
|
-
const
|
|
1016
|
-
return
|
|
1139
|
+
const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1140
|
+
return portalUrl;
|
|
1017
1141
|
});
|
|
1018
1142
|
}
|
|
1019
1143
|
/**
|
|
@@ -1021,75 +1145,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1021
1145
|
* @param partnerId: string - id of the partner to get the portal URL for
|
|
1022
1146
|
* @returns - portal URL
|
|
1023
1147
|
*/
|
|
1024
|
-
getPortalURL(
|
|
1148
|
+
getPortalURL() {
|
|
1025
1149
|
return __async(this, null, function* () {
|
|
1026
|
-
return
|
|
1027
|
-
});
|
|
1028
|
-
}
|
|
1029
|
-
getWebAuthURLForCreate(_a) {
|
|
1030
|
-
return __async(this, null, function* () {
|
|
1031
|
-
var _b = _a, {
|
|
1032
|
-
webAuthId
|
|
1033
|
-
} = _b, options = __objRest(_b, [
|
|
1034
|
-
"webAuthId"
|
|
1035
|
-
]);
|
|
1036
|
-
return this.constructPortalUrl("createAuth", __spreadProps(__spreadValues({}, options), { pathId: webAuthId }));
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
getPasswordURLForCreate(_c) {
|
|
1040
|
-
return __async(this, null, function* () {
|
|
1041
|
-
var _d = _c, {
|
|
1042
|
-
passwordId
|
|
1043
|
-
} = _d, options = __objRest(_d, [
|
|
1044
|
-
"passwordId"
|
|
1045
|
-
]);
|
|
1046
|
-
return this.constructPortalUrl("createPassword", __spreadProps(__spreadValues({}, options), {
|
|
1047
|
-
pathId: passwordId
|
|
1048
|
-
}));
|
|
1049
|
-
});
|
|
1050
|
-
}
|
|
1051
|
-
getShortUrl(compressedUrl) {
|
|
1052
|
-
return constructUrl({
|
|
1053
|
-
base: getPortalBaseURL(this.ctx),
|
|
1054
|
-
path: `/short/${compressedUrl}`
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
shortenLoginLink(link) {
|
|
1058
|
-
return __async(this, null, function* () {
|
|
1059
|
-
const url = yield transmissionUtils.upload(link, this.ctx.client);
|
|
1060
|
-
return this.getShortUrl(url);
|
|
1061
|
-
});
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* Generates a URL for registering a new WebAuth passkey.
|
|
1065
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1066
|
-
* @returns - the URL for creating a new passkey
|
|
1067
|
-
*/
|
|
1068
|
-
getWebAuthURLForLogin(opts) {
|
|
1069
|
-
return __async(this, null, function* () {
|
|
1070
|
-
return this.constructPortalUrl("loginAuth", opts);
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
/**
|
|
1074
|
-
* Generates a URL for registering a new user password.
|
|
1075
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1076
|
-
* @returns - the URL for creating a new password
|
|
1077
|
-
*/
|
|
1078
|
-
getPasswordURLForLogin(opts) {
|
|
1079
|
-
return __async(this, null, function* () {
|
|
1080
|
-
return this.constructPortalUrl("loginPassword", opts);
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
/**
|
|
1084
|
-
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
1085
|
-
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
1086
|
-
* @returns - web auth url
|
|
1087
|
-
*/
|
|
1088
|
-
getWebAuthURLForLoginForPhone(opts) {
|
|
1089
|
-
return __async(this, null, function* () {
|
|
1090
|
-
return this.constructPortalUrl("loginAuth", __spreadValues({
|
|
1091
|
-
authType: "phone"
|
|
1092
|
-
}, opts));
|
|
1150
|
+
return (yield this.getPartnerURL()) || getPortalBaseURL(this.ctx);
|
|
1093
1151
|
});
|
|
1094
1152
|
}
|
|
1095
1153
|
/**
|
|
@@ -1104,7 +1162,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1104
1162
|
if (!wallet) {
|
|
1105
1163
|
throw new Error("wallet not found");
|
|
1106
1164
|
}
|
|
1107
|
-
if (wallet.scheme !==
|
|
1165
|
+
if (wallet.scheme !== "DKLS") {
|
|
1108
1166
|
throw new Error("invalid wallet scheme");
|
|
1109
1167
|
}
|
|
1110
1168
|
return yield this.platformUtils.getPrivateKey(
|
|
@@ -1151,124 +1209,52 @@ const _ParaCore = class _ParaCore {
|
|
|
1151
1209
|
yield this.setWallets(this.wallets);
|
|
1152
1210
|
});
|
|
1153
1211
|
}
|
|
1154
|
-
/**
|
|
1155
|
-
* Checks if a user exists for an email address.
|
|
1156
|
-
* @param {Object} opts the options object
|
|
1157
|
-
* @param {string} opts.email the email to check.
|
|
1158
|
-
* @returns true if user exists, false otherwise.
|
|
1159
|
-
*/
|
|
1160
|
-
checkIfUserExists(_0) {
|
|
1161
|
-
return __async(this, arguments, function* ({ email }) {
|
|
1162
|
-
const res = yield this.ctx.client.checkUserExists({ email });
|
|
1163
|
-
return res.data.exists;
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
/**
|
|
1167
|
-
* Checks if a user exists for a phone number.
|
|
1168
|
-
* @param {Object} opts the options object
|
|
1169
|
-
* @param {string} opts.phone - phone number to check.
|
|
1170
|
-
* @param {string} opts.countryCode - the country code.
|
|
1171
|
-
* @returns true if user exists, false otherwise.
|
|
1172
|
-
*/
|
|
1173
|
-
checkIfUserExistsByPhone(_0) {
|
|
1174
|
-
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
1175
|
-
const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
|
|
1176
|
-
return res.data.exists;
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
* Creates a new user.
|
|
1181
|
-
* @param {Object} opts the options object
|
|
1182
|
-
* @param {string} opts.email the email to use.
|
|
1183
|
-
*/
|
|
1184
|
-
createUser(_0) {
|
|
1185
|
-
return __async(this, arguments, function* ({ email }) {
|
|
1186
|
-
this.requireApiKey();
|
|
1187
|
-
yield this.setEmail(email);
|
|
1188
|
-
const { userId } = yield this.ctx.client.createUser(__spreadValues({
|
|
1189
|
-
email: this.email
|
|
1190
|
-
}, this.getVerificationEmailProps()));
|
|
1191
|
-
yield this.setUserId(userId);
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Creates a new user with a phone number.
|
|
1196
|
-
* @param {Object} opts the options object
|
|
1197
|
-
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
1198
|
-
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
1199
|
-
*/
|
|
1200
|
-
createUserByPhone(_0) {
|
|
1201
|
-
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
1202
|
-
this.requireApiKey();
|
|
1203
|
-
yield this.setPhoneNumber(phone, countryCode);
|
|
1204
|
-
const { userId } = yield this.ctx.client.createUser({
|
|
1205
|
-
phone: this.phone,
|
|
1206
|
-
countryCode: this.countryCode
|
|
1207
|
-
});
|
|
1208
|
-
yield this.setUserId(userId);
|
|
1209
|
-
});
|
|
1210
|
-
}
|
|
1211
1212
|
/**
|
|
1212
1213
|
* Logs in or creates a new user using an external wallet address.
|
|
1213
1214
|
* @param {Object} opts the options object
|
|
1214
1215
|
* @param {string} opts.address the external wallet address to use for identification.
|
|
1215
|
-
* @param {
|
|
1216
|
+
* @param {TWalletType} opts.type type of external wallet to use for identification.
|
|
1216
1217
|
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
1217
1218
|
*/
|
|
1218
|
-
|
|
1219
|
+
loginExternalWallet(_a) {
|
|
1219
1220
|
return __async(this, null, function* () {
|
|
1221
|
+
var _b = _a, {
|
|
1222
|
+
externalWallet
|
|
1223
|
+
} = _b, urlOptions = __objRest(_b, [
|
|
1224
|
+
"externalWallet"
|
|
1225
|
+
]);
|
|
1226
|
+
if (this.externalWalletConnectionOnly) {
|
|
1227
|
+
externalWallet.withFullParaAuth = false;
|
|
1228
|
+
yield this.setExternalWallet(externalWallet);
|
|
1229
|
+
return Promise.resolve({
|
|
1230
|
+
userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1220
1233
|
this.requireApiKey();
|
|
1221
|
-
const
|
|
1222
|
-
|
|
1223
|
-
type: wallet.type,
|
|
1224
|
-
externalWalletProvider: wallet.provider,
|
|
1225
|
-
// If the wallet isn't using full Para auth we want to track the login here
|
|
1226
|
-
shouldTrackUser: !wallet.withFullParaAuth
|
|
1227
|
-
});
|
|
1228
|
-
yield this.setExternalWallet(wallet);
|
|
1229
|
-
yield this.setUserId(res.userId);
|
|
1230
|
-
return res;
|
|
1231
|
-
});
|
|
1232
|
-
}
|
|
1233
|
-
/**
|
|
1234
|
-
* Returns whether or not the user is connected with only an external wallet, not an external wallet with Para auth.
|
|
1235
|
-
*/
|
|
1236
|
-
isUsingExternalWallet() {
|
|
1237
|
-
return !this.isExternalWalletAuth && !!Object.keys(this.externalWallets).length;
|
|
1238
|
-
}
|
|
1239
|
-
/**
|
|
1240
|
-
* Passes the email code obtained from the user for verification.
|
|
1241
|
-
* @param {Object} opts the options object
|
|
1242
|
-
* @param {string} verificationCode the six-digit code to check
|
|
1243
|
-
* @returns {string} the web auth url for creating a new credential
|
|
1244
|
-
*/
|
|
1245
|
-
verifyEmail(_0) {
|
|
1246
|
-
return __async(this, arguments, function* ({ verificationCode }) {
|
|
1247
|
-
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
1248
|
-
return this.getSetUpBiometricsURL();
|
|
1234
|
+
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
|
|
1235
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1249
1236
|
});
|
|
1250
1237
|
}
|
|
1251
|
-
verifyExternalWallet(
|
|
1252
|
-
return __async(this,
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
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);
|
|
1272
1258
|
});
|
|
1273
1259
|
}
|
|
1274
1260
|
/**
|
|
@@ -1277,18 +1263,19 @@ const _ParaCore = class _ParaCore {
|
|
|
1277
1263
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1278
1264
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1279
1265
|
*/
|
|
1280
|
-
verifyTelegram(
|
|
1266
|
+
verifyTelegram(_e) {
|
|
1281
1267
|
return __async(this, null, function* () {
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
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);
|
|
1290
1278
|
}
|
|
1291
|
-
return res;
|
|
1292
1279
|
});
|
|
1293
1280
|
}
|
|
1294
1281
|
/**
|
|
@@ -1298,32 +1285,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1298
1285
|
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
1299
1286
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1300
1287
|
*/
|
|
1301
|
-
|
|
1302
|
-
return __async(this, arguments, function* ({
|
|
1303
|
-
const res = yield this.ctx.client.verify2FA(
|
|
1304
|
-
return {
|
|
1305
|
-
initiatedAt: res.data.initiatedAt,
|
|
1306
|
-
status: res.data.status,
|
|
1307
|
-
userId: res.data.userId,
|
|
1308
|
-
wallets: res.data.wallets
|
|
1309
|
-
};
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Performs 2FA verification.
|
|
1314
|
-
* @param {Object} opts the options object
|
|
1315
|
-
* @param {string} opts.phone the phone number
|
|
1316
|
-
* @param {string} opts.countryCode - the country code
|
|
1317
|
-
* @param {string} opts.verificationCode - verification code to received via 2FA.
|
|
1318
|
-
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1319
|
-
*/
|
|
1320
|
-
verify2FAForPhone(_0) {
|
|
1321
|
-
return __async(this, arguments, function* ({
|
|
1322
|
-
phone,
|
|
1323
|
-
countryCode,
|
|
1324
|
-
verificationCode
|
|
1325
|
-
}) {
|
|
1326
|
-
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);
|
|
1327
1291
|
return {
|
|
1328
1292
|
initiatedAt: res.data.initiatedAt,
|
|
1329
1293
|
status: res.data.status,
|
|
@@ -1336,12 +1300,11 @@ const _ParaCore = class _ParaCore {
|
|
|
1336
1300
|
* Sets up two-factor authentication for the current user.
|
|
1337
1301
|
* @returns {string} uri - uri to use for setting up 2FA
|
|
1338
1302
|
* */
|
|
1339
|
-
|
|
1303
|
+
setup2fa() {
|
|
1340
1304
|
return __async(this, null, function* () {
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
};
|
|
1305
|
+
const userId = this.assertUserId();
|
|
1306
|
+
const res = yield this.ctx.client.setup2FA(userId);
|
|
1307
|
+
return res;
|
|
1345
1308
|
});
|
|
1346
1309
|
}
|
|
1347
1310
|
/**
|
|
@@ -1349,24 +1312,10 @@ const _ParaCore = class _ParaCore {
|
|
|
1349
1312
|
* @param {Object} opts the options object
|
|
1350
1313
|
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
1351
1314
|
*/
|
|
1352
|
-
|
|
1315
|
+
enable2fa(_0) {
|
|
1353
1316
|
return __async(this, arguments, function* ({ verificationCode }) {
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
}
|
|
1357
|
-
/**
|
|
1358
|
-
* Determines if 2FA has been set up.
|
|
1359
|
-
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
1360
|
-
*/
|
|
1361
|
-
check2FAStatus() {
|
|
1362
|
-
return __async(this, null, function* () {
|
|
1363
|
-
if (!this.userId) {
|
|
1364
|
-
return { isSetup: false };
|
|
1365
|
-
}
|
|
1366
|
-
const res = yield this.ctx.client.check2FAStatus(this.userId);
|
|
1367
|
-
return {
|
|
1368
|
-
isSetup: res.data.isSetup
|
|
1369
|
-
};
|
|
1317
|
+
const userId = this.assertUserId();
|
|
1318
|
+
yield this.ctx.client.enable2FA(userId, verificationCode);
|
|
1370
1319
|
});
|
|
1371
1320
|
}
|
|
1372
1321
|
/**
|
|
@@ -1379,302 +1328,121 @@ const _ParaCore = class _ParaCore {
|
|
|
1379
1328
|
}, this.getVerificationEmailProps()));
|
|
1380
1329
|
});
|
|
1381
1330
|
}
|
|
1382
|
-
/**
|
|
1383
|
-
* Resend a verification SMS for the current user.
|
|
1384
|
-
*/
|
|
1385
|
-
resendVerificationCodeByPhone() {
|
|
1386
|
-
return __async(this, null, function* () {
|
|
1387
|
-
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
1388
|
-
userId: this.userId
|
|
1389
|
-
});
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
/**
|
|
1393
|
-
* Returns a URL for setting up a new WebAuth passkey.
|
|
1394
|
-
* @param {Object} opts the options object
|
|
1395
|
-
* @param {string} opts.authType - the auth type to use
|
|
1396
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1397
|
-
* @returns {string} the URL
|
|
1398
|
-
*/
|
|
1399
|
-
getSetUpBiometricsURL() {
|
|
1400
|
-
return __async(this, arguments, function* ({
|
|
1401
|
-
authType = "email",
|
|
1402
|
-
isForNewDevice = false
|
|
1403
|
-
} = {}) {
|
|
1404
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
1405
|
-
status: PublicKeyStatus.PENDING,
|
|
1406
|
-
type: PublicKeyType.WEB
|
|
1407
|
-
});
|
|
1408
|
-
return this.getWebAuthURLForCreate({
|
|
1409
|
-
authType,
|
|
1410
|
-
isForNewDevice,
|
|
1411
|
-
webAuthId: res.data.id,
|
|
1412
|
-
partnerId: res.data.partnerId
|
|
1413
|
-
});
|
|
1414
|
-
});
|
|
1415
|
-
}
|
|
1416
|
-
/**
|
|
1417
|
-
* Returns a URL for setting up a new WebAuth passkey for a phone number.
|
|
1418
|
-
* @param {Object} opts the options object
|
|
1419
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1420
|
-
* @returns {string} the URL
|
|
1421
|
-
*/
|
|
1422
|
-
getSetUpBiometricsURLForPhone() {
|
|
1423
|
-
return __async(this, arguments, function* ({
|
|
1424
|
-
isForNewDevice = false
|
|
1425
|
-
} = {}) {
|
|
1426
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
1427
|
-
status: PublicKeyStatus.PENDING,
|
|
1428
|
-
type: PublicKeyType.WEB
|
|
1429
|
-
});
|
|
1430
|
-
return this.getWebAuthURLForCreate({
|
|
1431
|
-
authType: "phone",
|
|
1432
|
-
isForNewDevice,
|
|
1433
|
-
webAuthId: res.data.id,
|
|
1434
|
-
partnerId: res.data.partnerId
|
|
1435
|
-
});
|
|
1436
|
-
});
|
|
1437
|
-
}
|
|
1438
|
-
/**
|
|
1439
|
-
* Returns a URL for setting up a new password.
|
|
1440
|
-
* @param {Object} opts the options object
|
|
1441
|
-
* @param {string} opts.authType - the auth type to use
|
|
1442
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1443
|
-
* @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
|
|
1444
|
-
* @returns {string} the URL
|
|
1445
|
-
*/
|
|
1446
|
-
getSetupPasswordURL() {
|
|
1447
|
-
return __async(this, arguments, function* ({
|
|
1448
|
-
authType = "email",
|
|
1449
|
-
isForNewDevice = false,
|
|
1450
|
-
theme
|
|
1451
|
-
} = {}) {
|
|
1452
|
-
const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
1453
|
-
status: PasswordStatus.PENDING
|
|
1454
|
-
});
|
|
1455
|
-
return this.getPasswordURLForCreate({
|
|
1456
|
-
authType,
|
|
1457
|
-
isForNewDevice,
|
|
1458
|
-
passwordId: res.data.id,
|
|
1459
|
-
partnerId: res.data.partnerId,
|
|
1460
|
-
theme
|
|
1461
|
-
});
|
|
1462
|
-
});
|
|
1463
|
-
}
|
|
1464
1331
|
/**
|
|
1465
1332
|
* Checks if the current session is active.
|
|
1466
1333
|
* @returns `true` if active, `false` otherwise
|
|
1467
|
-
*/
|
|
1468
|
-
isSessionActive() {
|
|
1469
|
-
return __async(this, null, function* () {
|
|
1470
|
-
if (this.
|
|
1471
|
-
return true;
|
|
1472
|
-
}
|
|
1473
|
-
const res = yield this.touchSession();
|
|
1474
|
-
return !!res.data.isAuthenticated;
|
|
1475
|
-
});
|
|
1476
|
-
}
|
|
1477
|
-
/**
|
|
1478
|
-
* Checks if a session is active and a wallet exists.
|
|
1479
|
-
* @returns `true` if active, `false` otherwise
|
|
1480
|
-
**/
|
|
1481
|
-
isFullyLoggedIn() {
|
|
1482
|
-
return __async(this, null, function* () {
|
|
1483
|
-
if (this.isUsingExternalWallet()) {
|
|
1484
|
-
return true;
|
|
1485
|
-
}
|
|
1486
|
-
if (this.isGuestMode) {
|
|
1487
|
-
return true;
|
|
1488
|
-
}
|
|
1489
|
-
const isSessionActive = yield this.isSessionActive();
|
|
1490
|
-
return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
|
|
1491
|
-
});
|
|
1492
|
-
}
|
|
1493
|
-
get isGuestMode() {
|
|
1494
|
-
return !this.userId && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.every(([id]) => !!this.wallets[id] && this.wallets[id].pregenIdentifierType === "GUEST_ID");
|
|
1495
|
-
}
|
|
1496
|
-
supportedAuthMethods(auth) {
|
|
1497
|
-
return __async(this, null, function* () {
|
|
1498
|
-
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
1499
|
-
const authMethods = /* @__PURE__ */ new Set();
|
|
1500
|
-
for (const type of supportedAuthMethods) {
|
|
1501
|
-
switch (type) {
|
|
1502
|
-
case "PASSWORD":
|
|
1503
|
-
authMethods.add(AuthMethod.PASSWORD);
|
|
1504
|
-
break;
|
|
1505
|
-
case "BIOMETRIC":
|
|
1506
|
-
authMethods.add(AuthMethod.PASSKEY);
|
|
1507
|
-
break;
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
return authMethods;
|
|
1511
|
-
});
|
|
1512
|
-
}
|
|
1513
|
-
/**
|
|
1514
|
-
* Get hints associated with the users stored biometrics.
|
|
1515
|
-
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
1516
|
-
*/
|
|
1517
|
-
getUserBiometricLocationHints() {
|
|
1518
|
-
return __async(this, null, function* () {
|
|
1519
|
-
var _a;
|
|
1520
|
-
if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId && !this.isExternalWalletAuth) {
|
|
1521
|
-
throw new Error(
|
|
1522
|
-
"one of email, phone, farcaster username, telegram user id or external wallet with Para auth are required to get biometric location hints"
|
|
1523
|
-
);
|
|
1524
|
-
}
|
|
1525
|
-
return yield this.ctx.client.getBiometricLocationHints({
|
|
1526
|
-
email: this.email,
|
|
1527
|
-
phone: this.phone,
|
|
1528
|
-
countryCode: this.countryCode,
|
|
1529
|
-
farcasterUsername: this.farcasterUsername,
|
|
1530
|
-
telegramUserId: this.telegramUserId,
|
|
1531
|
-
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
1532
|
-
externalWalletAddress: (_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id
|
|
1533
|
-
});
|
|
1534
|
-
});
|
|
1535
|
-
}
|
|
1536
|
-
setAuth(auth) {
|
|
1537
|
-
return __async(this, null, function* () {
|
|
1538
|
-
const authInfo = extractAuthInfo(auth);
|
|
1539
|
-
if (!authInfo) {
|
|
1540
|
-
return void 0;
|
|
1541
|
-
}
|
|
1542
|
-
switch (authInfo.authType) {
|
|
1543
|
-
case "email":
|
|
1544
|
-
yield this.setEmail(authInfo.identifier);
|
|
1545
|
-
break;
|
|
1546
|
-
case "phone":
|
|
1547
|
-
yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
|
|
1548
|
-
break;
|
|
1549
|
-
case "farcaster":
|
|
1550
|
-
yield this.setFarcasterUsername(authInfo.identifier);
|
|
1551
|
-
break;
|
|
1552
|
-
case "telegram":
|
|
1553
|
-
yield this.setTelegramUserId(authInfo.identifier);
|
|
1554
|
-
break;
|
|
1555
|
-
}
|
|
1556
|
-
return authInfo;
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
|
-
/**
|
|
1560
|
-
* Initiates a login.
|
|
1561
|
-
* @param {Object} opts the options object
|
|
1562
|
-
* @param {String} opts.email - the email to login with
|
|
1563
|
-
* @param {boolean} opts.useShortURL - whether to shorten the link
|
|
1564
|
-
* @returns - the WebAuth URL for logging in
|
|
1565
|
-
**/
|
|
1566
|
-
initiateUserLogin(_e) {
|
|
1567
|
-
return __async(this, null, function* () {
|
|
1568
|
-
var _f = _e, { useShortUrl = false } = _f, auth = __objRest(_f, ["useShortUrl"]);
|
|
1569
|
-
const authInfo = yield this.setAuth(auth);
|
|
1570
|
-
if (!authInfo) {
|
|
1571
|
-
return;
|
|
1572
|
-
}
|
|
1573
|
-
const res = yield this.touchSession(true);
|
|
1574
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1575
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1576
|
-
}
|
|
1577
|
-
const webAuthLoginURL = yield this.getWebAuthURLForLogin({
|
|
1578
|
-
authType: authInfo.authType,
|
|
1579
|
-
sessionId: res.data.sessionId,
|
|
1580
|
-
partnerId: res.data.partnerId,
|
|
1581
|
-
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
1582
|
-
});
|
|
1583
|
-
if (!useShortUrl) {
|
|
1584
|
-
return webAuthLoginURL;
|
|
1334
|
+
*/
|
|
1335
|
+
isSessionActive() {
|
|
1336
|
+
return __async(this, null, function* () {
|
|
1337
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1338
|
+
return true;
|
|
1585
1339
|
}
|
|
1586
|
-
|
|
1340
|
+
const { isAuthenticated } = yield this.touchSession();
|
|
1341
|
+
return !!isAuthenticated;
|
|
1587
1342
|
});
|
|
1588
1343
|
}
|
|
1589
1344
|
/**
|
|
1590
|
-
*
|
|
1591
|
-
* @
|
|
1592
|
-
* @returns - a set of supported auth methods for the user
|
|
1345
|
+
* Checks if a session is active and a wallet exists.
|
|
1346
|
+
* @returns `true` if active, `false` otherwise
|
|
1593
1347
|
**/
|
|
1594
|
-
|
|
1348
|
+
isFullyLoggedIn() {
|
|
1595
1349
|
return __async(this, null, function* () {
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
return;
|
|
1350
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1351
|
+
return true;
|
|
1599
1352
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1353
|
+
if (this.isGuestMode) {
|
|
1354
|
+
return true;
|
|
1603
1355
|
}
|
|
1604
|
-
|
|
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));
|
|
1605
1358
|
});
|
|
1606
1359
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
* @param opts.useShortURL - whether to shorten the link
|
|
1613
|
-
* @returns - the WebAuth URL for logging in
|
|
1614
|
-
**/
|
|
1615
|
-
initiateUserLoginForPhone(_g) {
|
|
1616
|
-
return __async(this, null, function* () {
|
|
1617
|
-
var _h = _g, {
|
|
1618
|
-
useShortUrl = false
|
|
1619
|
-
} = _h, auth = __objRest(_h, [
|
|
1620
|
-
"useShortUrl"
|
|
1621
|
-
]);
|
|
1622
|
-
yield this.setAuth(auth);
|
|
1623
|
-
const res = yield this.touchSession(true);
|
|
1624
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1625
|
-
yield this.setLoginEncryptionKeyPair();
|
|
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);
|
|
1626
1365
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
});
|
|
1632
|
-
|
|
1633
|
-
|
|
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
|
+
}
|
|
1634
1381
|
}
|
|
1635
|
-
return
|
|
1382
|
+
return authMethods;
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* Get hints associated with the users stored biometrics.
|
|
1387
|
+
* @deprecated
|
|
1388
|
+
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
1389
|
+
*/
|
|
1390
|
+
getUserBiometricLocationHints() {
|
|
1391
|
+
return __async(this, null, function* () {
|
|
1392
|
+
const { auth } = this.assertIsAuthSet();
|
|
1393
|
+
return yield this.ctx.client.getBiometricLocationHints(auth);
|
|
1636
1394
|
});
|
|
1637
1395
|
}
|
|
1638
1396
|
/**
|
|
1639
1397
|
* Waits for the session to be active.
|
|
1640
1398
|
**/
|
|
1641
|
-
|
|
1642
|
-
return __async(this, arguments, function* ({
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
yield
|
|
1651
|
-
if (
|
|
1652
|
-
this.
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
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();
|
|
1659
1428
|
}
|
|
1660
1429
|
}
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
return false;
|
|
1430
|
+
}))();
|
|
1431
|
+
});
|
|
1666
1432
|
});
|
|
1667
1433
|
}
|
|
1668
|
-
|
|
1434
|
+
waitForWalletCreation() {
|
|
1669
1435
|
return __async(this, arguments, function* ({
|
|
1670
|
-
|
|
1436
|
+
isCanceled = () => false,
|
|
1437
|
+
onCancel
|
|
1671
1438
|
} = {}) {
|
|
1672
|
-
yield this.
|
|
1439
|
+
yield this.waitForSignup({ isCanceled, onCancel });
|
|
1440
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1673
1441
|
const pregenWallets = yield this.getPregenWallets();
|
|
1674
1442
|
let recoverySecret, walletIds = {};
|
|
1675
1443
|
if (pregenWallets.length > 0) {
|
|
1676
1444
|
recoverySecret = yield this.claimPregenWallets();
|
|
1677
|
-
walletIds =
|
|
1445
|
+
walletIds = supportedWalletTypes.reduce((acc, { type }) => {
|
|
1678
1446
|
var _a;
|
|
1679
1447
|
return __spreadProps(__spreadValues({}, acc), {
|
|
1680
1448
|
[type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
@@ -1694,14 +1462,12 @@ const _ParaCore = class _ParaCore {
|
|
|
1694
1462
|
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
1695
1463
|
* @return {string} the Farcaster connect URI
|
|
1696
1464
|
*/
|
|
1697
|
-
|
|
1465
|
+
getFarcasterConnectUri() {
|
|
1698
1466
|
return __async(this, null, function* () {
|
|
1699
|
-
yield this.logout();
|
|
1700
|
-
yield this.touchSession(true);
|
|
1701
1467
|
const {
|
|
1702
|
-
data: { connect_uri }
|
|
1468
|
+
data: { connect_uri: connectUri }
|
|
1703
1469
|
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
1704
|
-
return
|
|
1470
|
+
return connectUri;
|
|
1705
1471
|
});
|
|
1706
1472
|
}
|
|
1707
1473
|
/**
|
|
@@ -1709,40 +1475,60 @@ const _ParaCore = class _ParaCore {
|
|
|
1709
1475
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
1710
1476
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
1711
1477
|
*/
|
|
1712
|
-
|
|
1478
|
+
verifyFarcaster(_g) {
|
|
1713
1479
|
return __async(this, null, function* () {
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
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
|
+
}
|
|
1728
1515
|
}
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
this.isAwaitingFarcaster = false;
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1516
|
+
}))();
|
|
1517
|
+
});
|
|
1734
1518
|
});
|
|
1735
1519
|
}
|
|
1736
1520
|
/**
|
|
1737
1521
|
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
1738
1522
|
*
|
|
1739
1523
|
* @param {Object} opts the options object
|
|
1740
|
-
* @param {
|
|
1524
|
+
* @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
|
|
1741
1525
|
* @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
|
|
1742
1526
|
* @returns {string} the URL for the user to log in with OAuth.
|
|
1743
1527
|
*/
|
|
1744
|
-
|
|
1745
|
-
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;
|
|
1746
1532
|
if (deeplinkUrl) {
|
|
1747
1533
|
try {
|
|
1748
1534
|
new URL(deeplinkUrl);
|
|
@@ -1750,14 +1536,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1750
1536
|
throw new Error("Invalid deeplink URL");
|
|
1751
1537
|
}
|
|
1752
1538
|
}
|
|
1753
|
-
yield this.
|
|
1754
|
-
const res = yield this.touchSession(true);
|
|
1539
|
+
const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
1755
1540
|
return constructUrl({
|
|
1756
|
-
base:
|
|
1757
|
-
path: `/auth/${method
|
|
1541
|
+
base: getBaseOAuthUrl(this.ctx.env),
|
|
1542
|
+
path: `/auth/${method}`,
|
|
1758
1543
|
params: {
|
|
1759
1544
|
apiKey: this.ctx.apiKey,
|
|
1760
|
-
sessionLookupId
|
|
1545
|
+
sessionLookupId,
|
|
1761
1546
|
deeplinkUrl
|
|
1762
1547
|
}
|
|
1763
1548
|
});
|
|
@@ -1771,37 +1556,54 @@ const _ParaCore = class _ParaCore {
|
|
|
1771
1556
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1772
1557
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1773
1558
|
*/
|
|
1774
|
-
|
|
1775
|
-
return __async(this,
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
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");
|
|
1789
1592
|
}
|
|
1790
|
-
yield
|
|
1791
|
-
yield this.
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
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();
|
|
1798
1603
|
}
|
|
1799
1604
|
}
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
return { userExists: false };
|
|
1605
|
+
}))();
|
|
1606
|
+
});
|
|
1805
1607
|
});
|
|
1806
1608
|
}
|
|
1807
1609
|
/**
|
|
@@ -1812,60 +1614,61 @@ const _ParaCore = class _ParaCore {
|
|
|
1812
1614
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
1813
1615
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
1814
1616
|
**/
|
|
1815
|
-
|
|
1617
|
+
waitForLogin() {
|
|
1816
1618
|
return __async(this, arguments, function* ({
|
|
1817
|
-
|
|
1619
|
+
isCanceled = () => false,
|
|
1620
|
+
onCancel,
|
|
1621
|
+
onPoll,
|
|
1818
1622
|
skipSessionRefresh = false
|
|
1819
1623
|
} = {}) {
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
this
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
try {
|
|
1827
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
1828
|
-
if (!(yield this.isSessionActive())) {
|
|
1829
|
-
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
1830
|
-
const resp2 = { isComplete: false, isError: true };
|
|
1831
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
1832
|
-
return resp2;
|
|
1833
|
-
}
|
|
1834
|
-
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 = {};
|
|
1835
1630
|
}
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
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();
|
|
1845
1642
|
continue;
|
|
1846
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();
|
|
1847
1668
|
}
|
|
1848
1669
|
}
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
1852
|
-
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
1853
|
-
yield this.claimPregenWallets();
|
|
1854
|
-
const resp2 = {
|
|
1855
|
-
isComplete: true,
|
|
1856
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
1857
|
-
partnerId: postLoginData.data.partnerId
|
|
1858
|
-
};
|
|
1859
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
|
|
1860
|
-
return resp2;
|
|
1861
|
-
}
|
|
1862
|
-
} catch (err) {
|
|
1863
|
-
console.error(err);
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
const resp = { isComplete: false };
|
|
1867
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp, "exitted login without setting up user");
|
|
1868
|
-
return resp;
|
|
1670
|
+
}))();
|
|
1671
|
+
});
|
|
1869
1672
|
});
|
|
1870
1673
|
}
|
|
1871
1674
|
/**
|
|
@@ -1877,14 +1680,15 @@ const _ParaCore = class _ParaCore {
|
|
|
1877
1680
|
* @returns a URL for the user to reauthenticate.
|
|
1878
1681
|
**/
|
|
1879
1682
|
refreshSession() {
|
|
1880
|
-
return __async(this, arguments, function* ({
|
|
1881
|
-
|
|
1683
|
+
return __async(this, arguments, function* ({
|
|
1684
|
+
shouldOpenPopup = false
|
|
1685
|
+
} = {}) {
|
|
1686
|
+
const { sessionId } = yield this.touchSession(true);
|
|
1882
1687
|
if (!this.loginEncryptionKeyPair) {
|
|
1883
1688
|
yield this.setLoginEncryptionKeyPair();
|
|
1884
1689
|
}
|
|
1885
|
-
const link = yield this.
|
|
1886
|
-
sessionId
|
|
1887
|
-
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
1690
|
+
const link = yield this.getLoginUrl({
|
|
1691
|
+
sessionId
|
|
1888
1692
|
});
|
|
1889
1693
|
if (shouldOpenPopup) {
|
|
1890
1694
|
this.platformUtils.openPopup(link);
|
|
@@ -1898,13 +1702,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1898
1702
|
**/
|
|
1899
1703
|
userSetupAfterLogin() {
|
|
1900
1704
|
return __async(this, null, function* () {
|
|
1901
|
-
const
|
|
1902
|
-
yield this.setUserId(
|
|
1903
|
-
if (
|
|
1904
|
-
yield this.setCurrentWalletIds(
|
|
1905
|
-
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
|
|
1906
1710
|
});
|
|
1907
|
-
return
|
|
1711
|
+
return session;
|
|
1908
1712
|
});
|
|
1909
1713
|
}
|
|
1910
1714
|
/**
|
|
@@ -1915,8 +1719,8 @@ const _ParaCore = class _ParaCore {
|
|
|
1915
1719
|
**/
|
|
1916
1720
|
getTransmissionKeyShares() {
|
|
1917
1721
|
return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
|
|
1918
|
-
const
|
|
1919
|
-
const sessionLookupId = isForNewDevice ? `${
|
|
1722
|
+
const session = yield this.touchSession();
|
|
1723
|
+
const sessionLookupId = isForNewDevice ? `${session.sessionLookupId}-new-device` : session.sessionLookupId;
|
|
1920
1724
|
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
1921
1725
|
});
|
|
1922
1726
|
}
|
|
@@ -2043,7 +1847,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2043
1847
|
*
|
|
2044
1848
|
* @param {Object} [opts] the options object.
|
|
2045
1849
|
* @param {boolean} [opts.skipDistribute] if `true`, the wallets' recovery share will not be distributed.
|
|
2046
|
-
* @param {
|
|
1850
|
+
* @param {TWalletType[]} [opts.types] the types of wallets to create.
|
|
2047
1851
|
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
2048
1852
|
**/
|
|
2049
1853
|
createWalletPerType() {
|
|
@@ -2114,7 +1918,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2114
1918
|
/**
|
|
2115
1919
|
* Creates a new wallet.
|
|
2116
1920
|
* @param {Object} opts the options object.
|
|
2117
|
-
* @param {
|
|
1921
|
+
* @param {TWalletType} opts.type the type of wallet to create.
|
|
2118
1922
|
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
2119
1923
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2120
1924
|
**/
|
|
@@ -2125,14 +1929,15 @@ const _ParaCore = class _ParaCore {
|
|
|
2125
1929
|
} = {}) {
|
|
2126
1930
|
var _a, _b;
|
|
2127
1931
|
this.requireApiKey();
|
|
1932
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2128
1933
|
const walletType = yield this.assertIsValidWalletType(
|
|
2129
|
-
_type != null ? _type : (_a =
|
|
1934
|
+
_type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
2130
1935
|
);
|
|
2131
1936
|
let signer;
|
|
2132
1937
|
let wallet;
|
|
2133
1938
|
let keygenRes;
|
|
2134
1939
|
switch (walletType) {
|
|
2135
|
-
case
|
|
1940
|
+
case "SOLANA": {
|
|
2136
1941
|
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
2137
1942
|
this.ctx,
|
|
2138
1943
|
this.userId,
|
|
@@ -2158,7 +1963,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2158
1963
|
this.wallets[walletId] = {
|
|
2159
1964
|
id: walletId,
|
|
2160
1965
|
signer,
|
|
2161
|
-
scheme: walletType ===
|
|
1966
|
+
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
2162
1967
|
type: walletType
|
|
2163
1968
|
};
|
|
2164
1969
|
wallet = this.wallets[walletId];
|
|
@@ -2175,7 +1980,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2175
1980
|
});
|
|
2176
1981
|
}
|
|
2177
1982
|
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
2178
|
-
[walletType]: [...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId]
|
|
1983
|
+
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
2179
1984
|
}));
|
|
2180
1985
|
const walletNoSigner = __spreadValues({}, wallet);
|
|
2181
1986
|
delete walletNoSigner.signer;
|
|
@@ -2186,15 +1991,6 @@ const _ParaCore = class _ParaCore {
|
|
|
2186
1991
|
return [wallet, recoveryShare];
|
|
2187
1992
|
});
|
|
2188
1993
|
}
|
|
2189
|
-
/**
|
|
2190
|
-
* Creates a new pregenerated wallet.
|
|
2191
|
-
*
|
|
2192
|
-
* @param {Object} opts the options object.
|
|
2193
|
-
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
2194
|
-
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
2195
|
-
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
2196
|
-
* @returns {Wallet} the created wallet.
|
|
2197
|
-
**/
|
|
2198
1994
|
createPregenWallet(opts) {
|
|
2199
1995
|
return __async(this, null, function* () {
|
|
2200
1996
|
return yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, opts);
|
|
@@ -2207,18 +2003,17 @@ const _ParaCore = class _ParaCore {
|
|
|
2207
2003
|
* @param {Object} opts the options object.
|
|
2208
2004
|
* @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
|
|
2209
2005
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
2210
|
-
* @param {
|
|
2006
|
+
* @param {TWalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
2211
2007
|
* @returns {Wallet[]} an array containing the created wallets.
|
|
2212
2008
|
**/
|
|
2213
2009
|
createPregenWalletPerType(_0) {
|
|
2214
2010
|
return __async(this, arguments, function* ({
|
|
2215
2011
|
types,
|
|
2216
|
-
|
|
2217
|
-
pregenIdentifierType = "EMAIL"
|
|
2012
|
+
pregenId
|
|
2218
2013
|
}) {
|
|
2219
2014
|
const wallets = [];
|
|
2220
2015
|
for (const type of yield this.getTypesToCreate(types)) {
|
|
2221
|
-
const wallet = yield
|
|
2016
|
+
const wallet = yield this.createPregenWallet({ type, pregenId });
|
|
2222
2017
|
wallets.push(wallet);
|
|
2223
2018
|
}
|
|
2224
2019
|
return wallets;
|
|
@@ -2226,7 +2021,6 @@ const _ParaCore = class _ParaCore {
|
|
|
2226
2021
|
}
|
|
2227
2022
|
/**
|
|
2228
2023
|
* Claims a pregenerated wallet.
|
|
2229
|
-
*
|
|
2230
2024
|
* @param {Object} opts the options object.
|
|
2231
2025
|
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
2232
2026
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
@@ -2234,12 +2028,11 @@ const _ParaCore = class _ParaCore {
|
|
|
2234
2028
|
**/
|
|
2235
2029
|
claimPregenWallets() {
|
|
2236
2030
|
return __async(this, arguments, function* ({
|
|
2237
|
-
|
|
2238
|
-
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
2031
|
+
pregenId
|
|
2239
2032
|
} = {}) {
|
|
2240
2033
|
var _a;
|
|
2241
2034
|
this.requireApiKey();
|
|
2242
|
-
const pregenWallets =
|
|
2035
|
+
const pregenWallets = pregenId ? yield this.getPregenWallets({ pregenId }) : yield this.getPregenWallets();
|
|
2243
2036
|
if (pregenWallets.length === 0) {
|
|
2244
2037
|
return void 0;
|
|
2245
2038
|
}
|
|
@@ -2257,7 +2050,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2257
2050
|
for (const walletId of walletIds) {
|
|
2258
2051
|
const wallet = this.wallets[walletId];
|
|
2259
2052
|
let refreshedShare;
|
|
2260
|
-
if (wallet.scheme ===
|
|
2053
|
+
if (wallet.scheme === "ED25519") {
|
|
2261
2054
|
const distributeRes = yield distributeNewShare({
|
|
2262
2055
|
ctx: this.ctx,
|
|
2263
2056
|
userId: this.userId,
|
|
@@ -2308,10 +2101,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2308
2101
|
updatePregenWalletIdentifier(_0) {
|
|
2309
2102
|
return __async(this, arguments, function* ({
|
|
2310
2103
|
walletId,
|
|
2311
|
-
|
|
2312
|
-
newPregenIdentifierType
|
|
2104
|
+
newPregenId
|
|
2313
2105
|
}) {
|
|
2314
2106
|
this.requireApiKey();
|
|
2107
|
+
const [newPregenIdentifierType, newPregenIdentifier] = toPregenTypeAndId(newPregenId);
|
|
2315
2108
|
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
2316
2109
|
pregenIdentifier: newPregenIdentifier,
|
|
2317
2110
|
pregenIdentifierType: newPregenIdentifierType
|
|
@@ -2333,13 +2126,13 @@ const _ParaCore = class _ParaCore {
|
|
|
2333
2126
|
* @returns {boolean} whether the pregen wallet exists
|
|
2334
2127
|
**/
|
|
2335
2128
|
hasPregenWallet(_0) {
|
|
2336
|
-
return __async(this, arguments, function* ({
|
|
2337
|
-
pregenIdentifier,
|
|
2338
|
-
pregenIdentifierType
|
|
2339
|
-
}) {
|
|
2129
|
+
return __async(this, arguments, function* ({ pregenId }) {
|
|
2340
2130
|
this.requireApiKey();
|
|
2341
|
-
const
|
|
2342
|
-
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
|
+
);
|
|
2343
2136
|
if (!wallet) {
|
|
2344
2137
|
return false;
|
|
2345
2138
|
}
|
|
@@ -2354,13 +2147,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2354
2147
|
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
2355
2148
|
**/
|
|
2356
2149
|
getPregenWallets() {
|
|
2357
|
-
return __async(this, arguments, function* ({
|
|
2358
|
-
pregenIdentifier,
|
|
2359
|
-
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
2360
|
-
} = {}) {
|
|
2150
|
+
return __async(this, arguments, function* ({ pregenId } = {}) {
|
|
2361
2151
|
this.requireApiKey();
|
|
2362
2152
|
const res = yield this.ctx.client.getPregenWallets(
|
|
2363
|
-
|
|
2153
|
+
pregenId ? toPregenIds(pregenId) : this.pregenIds,
|
|
2364
2154
|
this.isPortal(),
|
|
2365
2155
|
this.userId
|
|
2366
2156
|
);
|
|
@@ -2368,21 +2158,37 @@ const _ParaCore = class _ParaCore {
|
|
|
2368
2158
|
});
|
|
2369
2159
|
}
|
|
2370
2160
|
createGuestWallets() {
|
|
2371
|
-
return __async(this,
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
wallets
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
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;
|
|
2383
2191
|
}
|
|
2384
|
-
yield this.setCurrentWalletIds(currentWalletIds);
|
|
2385
|
-
return wallets;
|
|
2386
2192
|
});
|
|
2387
2193
|
}
|
|
2388
2194
|
encodeWalletBase64(wallet) {
|
|
@@ -2420,9 +2226,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2420
2226
|
}
|
|
2421
2227
|
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
2422
2228
|
return __async(this, null, function* () {
|
|
2423
|
-
const res = yield this.touchSession();
|
|
2424
2229
|
return this.constructPortalUrl("txReview", {
|
|
2425
|
-
partnerId: res.data.partnerId,
|
|
2426
2230
|
pathId: transactionId,
|
|
2427
2231
|
params: {
|
|
2428
2232
|
email: this.email,
|
|
@@ -2431,21 +2235,20 @@ const _ParaCore = class _ParaCore {
|
|
|
2431
2235
|
});
|
|
2432
2236
|
});
|
|
2433
2237
|
}
|
|
2434
|
-
getOnRampTransactionUrl(
|
|
2238
|
+
getOnRampTransactionUrl(_m) {
|
|
2435
2239
|
return __async(this, null, function* () {
|
|
2436
|
-
var
|
|
2240
|
+
var _n = _m, {
|
|
2437
2241
|
purchaseId,
|
|
2438
2242
|
providerKey
|
|
2439
|
-
} =
|
|
2243
|
+
} = _n, walletParams = __objRest(_n, [
|
|
2440
2244
|
"purchaseId",
|
|
2441
2245
|
"providerKey"
|
|
2442
2246
|
]);
|
|
2443
|
-
const
|
|
2247
|
+
const { sessionId } = yield this.touchSession();
|
|
2444
2248
|
const [key, identifier] = extractWalletRef(walletParams);
|
|
2445
2249
|
return this.constructPortalUrl("onRamp", {
|
|
2446
|
-
partnerId: res.data.partnerId,
|
|
2447
2250
|
pathId: purchaseId,
|
|
2448
|
-
sessionId
|
|
2251
|
+
sessionId,
|
|
2449
2252
|
params: {
|
|
2450
2253
|
[key]: identifier,
|
|
2451
2254
|
providerKey,
|
|
@@ -2470,7 +2273,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2470
2273
|
walletId,
|
|
2471
2274
|
messageBase64,
|
|
2472
2275
|
timeoutMs = 3e4,
|
|
2473
|
-
cosmosSignDocBase64
|
|
2276
|
+
cosmosSignDocBase64,
|
|
2277
|
+
isCanceled = () => false,
|
|
2278
|
+
onCancel,
|
|
2279
|
+
onPoll
|
|
2474
2280
|
}) {
|
|
2475
2281
|
this.assertIsValidWalletId(walletId);
|
|
2476
2282
|
const wallet = this.wallets[walletId];
|
|
@@ -2489,11 +2295,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2489
2295
|
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2490
2296
|
return signRes;
|
|
2491
2297
|
}
|
|
2492
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2493
2298
|
while (true) {
|
|
2494
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
2299
|
+
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2300
|
+
onCancel == null ? void 0 : onCancel();
|
|
2495
2301
|
break;
|
|
2496
2302
|
}
|
|
2303
|
+
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2497
2304
|
try {
|
|
2498
2305
|
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2499
2306
|
} catch (err) {
|
|
@@ -2503,7 +2310,8 @@ const _ParaCore = class _ParaCore {
|
|
|
2503
2310
|
}
|
|
2504
2311
|
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2505
2312
|
if (signRes.pendingTransactionId) {
|
|
2506
|
-
|
|
2313
|
+
onPoll == null ? void 0 : onPoll();
|
|
2314
|
+
continue;
|
|
2507
2315
|
} else {
|
|
2508
2316
|
break;
|
|
2509
2317
|
}
|
|
@@ -2529,7 +2337,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2529
2337
|
}) {
|
|
2530
2338
|
let signRes;
|
|
2531
2339
|
switch (wallet.scheme) {
|
|
2532
|
-
case
|
|
2340
|
+
case "ED25519":
|
|
2533
2341
|
signRes = yield this.platformUtils.ed25519Sign(
|
|
2534
2342
|
this.ctx,
|
|
2535
2343
|
signerId,
|
|
@@ -2547,7 +2355,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2547
2355
|
wallet.signer,
|
|
2548
2356
|
messageBase64,
|
|
2549
2357
|
this.retrieveSessionCookie(),
|
|
2550
|
-
wallet.scheme ===
|
|
2358
|
+
wallet.scheme === "DKLS",
|
|
2551
2359
|
cosmosSignDocBase64
|
|
2552
2360
|
);
|
|
2553
2361
|
break;
|
|
@@ -2568,7 +2376,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2568
2376
|
walletId,
|
|
2569
2377
|
rlpEncodedTxBase64,
|
|
2570
2378
|
chainId,
|
|
2571
|
-
timeoutMs = 3e4
|
|
2379
|
+
timeoutMs = 3e4,
|
|
2380
|
+
isCanceled = () => false,
|
|
2381
|
+
onCancel,
|
|
2382
|
+
onPoll
|
|
2572
2383
|
}) {
|
|
2573
2384
|
this.assertIsValidWalletId(walletId);
|
|
2574
2385
|
const wallet = this.wallets[walletId];
|
|
@@ -2584,7 +2395,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2584
2395
|
rlpEncodedTxBase64,
|
|
2585
2396
|
chainId,
|
|
2586
2397
|
this.retrieveSessionCookie(),
|
|
2587
|
-
wallet.scheme ===
|
|
2398
|
+
wallet.scheme === "DKLS"
|
|
2588
2399
|
);
|
|
2589
2400
|
let timeStart = Date.now();
|
|
2590
2401
|
if (signRes.pendingTransactionId) {
|
|
@@ -2596,11 +2407,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2596
2407
|
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2597
2408
|
return signRes;
|
|
2598
2409
|
}
|
|
2599
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2600
2410
|
while (true) {
|
|
2601
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
2411
|
+
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2412
|
+
onCancel == null ? void 0 : onCancel();
|
|
2602
2413
|
break;
|
|
2603
2414
|
}
|
|
2415
|
+
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2604
2416
|
try {
|
|
2605
2417
|
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2606
2418
|
} catch (err) {
|
|
@@ -2616,10 +2428,11 @@ const _ParaCore = class _ParaCore {
|
|
|
2616
2428
|
rlpEncodedTxBase64,
|
|
2617
2429
|
chainId,
|
|
2618
2430
|
this.retrieveSessionCookie(),
|
|
2619
|
-
wallet.scheme ===
|
|
2431
|
+
wallet.scheme === "DKLS"
|
|
2620
2432
|
);
|
|
2621
2433
|
if (signRes.pendingTransactionId) {
|
|
2622
|
-
|
|
2434
|
+
onPoll == null ? void 0 : onPoll();
|
|
2435
|
+
continue;
|
|
2623
2436
|
} else {
|
|
2624
2437
|
break;
|
|
2625
2438
|
}
|
|
@@ -2636,44 +2449,6 @@ const _ParaCore = class _ParaCore {
|
|
|
2636
2449
|
return signRes;
|
|
2637
2450
|
});
|
|
2638
2451
|
}
|
|
2639
|
-
/**
|
|
2640
|
-
* @deprecated
|
|
2641
|
-
* Sends a transaction.
|
|
2642
|
-
* @param walletId - id of the wallet to send the transaction from.
|
|
2643
|
-
* @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
|
|
2644
|
-
* @param chainId - chain id of the chain the transaction is being sent on.
|
|
2645
|
-
**/
|
|
2646
|
-
sendTransaction(_0) {
|
|
2647
|
-
return __async(this, arguments, function* ({
|
|
2648
|
-
walletId,
|
|
2649
|
-
rlpEncodedTxBase64,
|
|
2650
|
-
chainId
|
|
2651
|
-
}) {
|
|
2652
|
-
this.assertIsValidWalletId(walletId);
|
|
2653
|
-
const wallet = this.wallets[walletId];
|
|
2654
|
-
const signRes = yield this.platformUtils.sendTransaction(
|
|
2655
|
-
this.ctx,
|
|
2656
|
-
this.userId,
|
|
2657
|
-
walletId,
|
|
2658
|
-
this.wallets[walletId].signer,
|
|
2659
|
-
rlpEncodedTxBase64,
|
|
2660
|
-
chainId,
|
|
2661
|
-
this.retrieveSessionCookie(),
|
|
2662
|
-
wallet.scheme === WalletScheme.DKLS
|
|
2663
|
-
);
|
|
2664
|
-
if (signRes.pendingTransactionId) {
|
|
2665
|
-
this.platformUtils.openPopup(
|
|
2666
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
2667
|
-
{ type: PopupType.SIGN_TRANSACTION_REVIEW }
|
|
2668
|
-
);
|
|
2669
|
-
const error = new TransactionReviewError(
|
|
2670
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId)
|
|
2671
|
-
);
|
|
2672
|
-
throw error;
|
|
2673
|
-
}
|
|
2674
|
-
return signRes;
|
|
2675
|
-
});
|
|
2676
|
-
}
|
|
2677
2452
|
isProviderModalDisabled() {
|
|
2678
2453
|
return !!this.disableProviderModal;
|
|
2679
2454
|
}
|
|
@@ -2723,17 +2498,13 @@ const _ParaCore = class _ParaCore {
|
|
|
2723
2498
|
* @param {boolean} excludeSigners - whether or not to exclude the signer from the exported wallets.
|
|
2724
2499
|
* @returns {string} the serialized session
|
|
2725
2500
|
*/
|
|
2726
|
-
exportSession({ excludeSigners } = {}) {
|
|
2501
|
+
exportSession({ excludeSigners = false } = {}) {
|
|
2727
2502
|
const sessionInfo = {
|
|
2728
|
-
|
|
2503
|
+
authInfo: __privateGet(this, _authInfo),
|
|
2729
2504
|
userId: this.userId,
|
|
2730
2505
|
wallets: structuredClone(this.wallets),
|
|
2731
2506
|
currentWalletIds: this.currentWalletIds,
|
|
2732
|
-
sessionCookie: this.
|
|
2733
|
-
phone: this.phone,
|
|
2734
|
-
countryCode: this.countryCode,
|
|
2735
|
-
telegramUserId: this.telegramUserId,
|
|
2736
|
-
farcasterUsername: this.farcasterUsername,
|
|
2507
|
+
sessionCookie: this.retrieveSessionCookie(),
|
|
2737
2508
|
externalWallets: this.externalWallets
|
|
2738
2509
|
};
|
|
2739
2510
|
if (excludeSigners) {
|
|
@@ -2749,12 +2520,11 @@ const _ParaCore = class _ParaCore {
|
|
|
2749
2520
|
*/
|
|
2750
2521
|
importSession(serializedInstanceBase64) {
|
|
2751
2522
|
return __async(this, null, function* () {
|
|
2752
|
-
var _a;
|
|
2523
|
+
var _a, _b;
|
|
2753
2524
|
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
2754
|
-
const sessionInfo =
|
|
2755
|
-
|
|
2756
|
-
yield this.
|
|
2757
|
-
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);
|
|
2758
2528
|
yield this.setUserId(sessionInfo.userId);
|
|
2759
2529
|
yield this.setWallets(sessionInfo.wallets);
|
|
2760
2530
|
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
@@ -2769,42 +2539,23 @@ const _ParaCore = class _ParaCore {
|
|
|
2769
2539
|
const currentWalletIds = {};
|
|
2770
2540
|
for (const walletId of Object.keys(sessionInfo.wallets)) {
|
|
2771
2541
|
currentWalletIds[sessionInfo.wallets[walletId].type] = [
|
|
2772
|
-
...(
|
|
2542
|
+
...(_b = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _b : [],
|
|
2773
2543
|
walletId
|
|
2774
2544
|
];
|
|
2775
2545
|
}
|
|
2776
2546
|
yield this.setCurrentWalletIds(currentWalletIds);
|
|
2777
2547
|
}
|
|
2778
2548
|
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
2779
|
-
yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
2780
2549
|
});
|
|
2781
2550
|
}
|
|
2782
|
-
exitAccountCreation() {
|
|
2783
|
-
this.isAwaitingAccountCreation = false;
|
|
2784
|
-
}
|
|
2785
|
-
exitLogin() {
|
|
2786
|
-
this.isAwaitingLogin = false;
|
|
2787
|
-
}
|
|
2788
|
-
exitFarcaster() {
|
|
2789
|
-
this.isAwaitingFarcaster = false;
|
|
2790
|
-
}
|
|
2791
|
-
exitOAuth() {
|
|
2792
|
-
this.isAwaitingOAuth = false;
|
|
2793
|
-
}
|
|
2794
|
-
exitLoops() {
|
|
2795
|
-
this.exitAccountCreation();
|
|
2796
|
-
this.exitLogin();
|
|
2797
|
-
this.exitFarcaster();
|
|
2798
|
-
this.exitOAuth();
|
|
2799
|
-
}
|
|
2800
2551
|
/**
|
|
2801
2552
|
* Retrieves a token to verify the current session.
|
|
2802
2553
|
* @returns {Promise<string>} the ID
|
|
2803
2554
|
**/
|
|
2804
2555
|
getVerificationToken() {
|
|
2805
2556
|
return __async(this, null, function* () {
|
|
2806
|
-
const {
|
|
2807
|
-
return
|
|
2557
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
2558
|
+
return sessionLookupId;
|
|
2808
2559
|
});
|
|
2809
2560
|
}
|
|
2810
2561
|
/**
|
|
@@ -2829,22 +2580,18 @@ const _ParaCore = class _ParaCore {
|
|
|
2829
2580
|
this.currentWalletIds = {};
|
|
2830
2581
|
this.externalWallets = {};
|
|
2831
2582
|
this.loginEncryptionKeyPair = void 0;
|
|
2832
|
-
this
|
|
2833
|
-
this.telegramUserId = void 0;
|
|
2834
|
-
this.phone = void 0;
|
|
2835
|
-
this.countryCode = void 0;
|
|
2583
|
+
__privateSet(this, _authInfo, void 0);
|
|
2836
2584
|
this.userId = void 0;
|
|
2837
2585
|
this.sessionCookie = void 0;
|
|
2838
2586
|
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
2839
2587
|
});
|
|
2840
2588
|
}
|
|
2589
|
+
/** @deprecated */
|
|
2841
2590
|
getSupportedCreateAuthMethods() {
|
|
2842
2591
|
return __async(this, null, function* () {
|
|
2843
|
-
const
|
|
2844
|
-
const partnerId = res.data.partnerId;
|
|
2845
|
-
const partnerRes = yield this.ctx.client.getPartner(partnerId);
|
|
2592
|
+
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2846
2593
|
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
2847
|
-
for (const authMethod of
|
|
2594
|
+
for (const authMethod of partner.supportedAuthMethods) {
|
|
2848
2595
|
supportedAuthMethods.add(AuthMethod[authMethod]);
|
|
2849
2596
|
}
|
|
2850
2597
|
return supportedAuthMethods;
|
|
@@ -2856,6 +2603,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2856
2603
|
* Doesn't work for all types of logging.
|
|
2857
2604
|
**/
|
|
2858
2605
|
toString() {
|
|
2606
|
+
var _a, _b, _c;
|
|
2859
2607
|
const redactedWallets = Object.keys(this.wallets).reduce(
|
|
2860
2608
|
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
2861
2609
|
[walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
@@ -2873,16 +2621,15 @@ const _ParaCore = class _ParaCore {
|
|
|
2873
2621
|
{}
|
|
2874
2622
|
);
|
|
2875
2623
|
const obj = {
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
telegramUserId: this.telegramUserId,
|
|
2882
|
-
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,
|
|
2883
2629
|
userId: this.userId,
|
|
2884
2630
|
pregenIds: this.pregenIds,
|
|
2885
2631
|
currentWalletIds: this.currentWalletIds,
|
|
2632
|
+
guestWalletIds: __privateGet(this, _ParaCore_instances, guestWalletIds_get),
|
|
2886
2633
|
wallets: redactedWallets,
|
|
2887
2634
|
externalWallets: redactedExternalWallets,
|
|
2888
2635
|
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
@@ -2899,25 +2646,201 @@ const _ParaCore = class _ParaCore {
|
|
|
2899
2646
|
};
|
|
2900
2647
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
2901
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
|
+
}
|
|
2902
2745
|
};
|
|
2903
|
-
|
|
2904
|
-
|
|
2746
|
+
_authInfo = new WeakMap();
|
|
2747
|
+
_partner = new WeakMap();
|
|
2905
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
|
+
};
|
|
2906
2831
|
createPregenWallet_fn = function(opts) {
|
|
2907
2832
|
return __async(this, null, function* () {
|
|
2908
2833
|
var _a, _b;
|
|
2909
|
-
const {
|
|
2910
|
-
|
|
2911
|
-
pregenIdentifier,
|
|
2912
|
-
pregenIdentifierType = "EMAIL"
|
|
2913
|
-
} = 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;
|
|
2914
2836
|
this.requireApiKey();
|
|
2915
2837
|
const walletType = yield this.assertIsValidWalletType(
|
|
2916
|
-
_type != null ? _type : (_b =
|
|
2838
|
+
_type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
2917
2839
|
);
|
|
2840
|
+
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
2918
2841
|
let keygenRes;
|
|
2919
2842
|
switch (walletType) {
|
|
2920
|
-
case
|
|
2843
|
+
case "SOLANA":
|
|
2921
2844
|
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
2922
2845
|
this.ctx,
|
|
2923
2846
|
pregenIdentifier,
|
|
@@ -2941,7 +2864,7 @@ createPregenWallet_fn = function(opts) {
|
|
|
2941
2864
|
this.wallets[walletId] = {
|
|
2942
2865
|
id: walletId,
|
|
2943
2866
|
signer,
|
|
2944
|
-
scheme: walletType ===
|
|
2867
|
+
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
2945
2868
|
type: walletType,
|
|
2946
2869
|
isPregen: true,
|
|
2947
2870
|
pregenIdentifier,
|
|
@@ -2952,6 +2875,114 @@ createPregenWallet_fn = function(opts) {
|
|
|
2952
2875
|
return this.wallets[walletId];
|
|
2953
2876
|
});
|
|
2954
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
|
+
};
|
|
2955
2986
|
_ParaCore.version = constants.PARA_CORE_VERSION;
|
|
2956
2987
|
let ParaCore = _ParaCore;
|
|
2957
2988
|
export {
|