@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/cjs/ParaCore.js
CHANGED
|
@@ -95,13 +95,11 @@ var import_userManagementClient = require("./external/userManagementClient.js");
|
|
|
95
95
|
var mpcComputationClient = __toESM(require("./external/mpcComputationClient.js"));
|
|
96
96
|
var import_shareDistribution = require("./shares/shareDistribution.js");
|
|
97
97
|
var import_types = require("./types/index.js");
|
|
98
|
-
var transmissionUtils = __toESM(require("./transmission/transmissionUtils.js"));
|
|
99
98
|
var import_recovery = require("./shares/recovery.js");
|
|
100
99
|
var import_utils2 = require("./utils/index.js");
|
|
101
100
|
var import_errors = require("./errors.js");
|
|
102
101
|
var constants = __toESM(require("./constants.js"));
|
|
103
|
-
var
|
|
104
|
-
var _supportedWalletTypes, _supportedWalletTypesOpt, _ParaCore_instances, createPregenWallet_fn;
|
|
102
|
+
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;
|
|
105
103
|
if (typeof global !== "undefined") {
|
|
106
104
|
global.Buffer = global.Buffer || import_buffer.Buffer;
|
|
107
105
|
} else if (typeof window !== "undefined") {
|
|
@@ -122,6 +120,9 @@ const _ParaCore = class _ParaCore {
|
|
|
122
120
|
*/
|
|
123
121
|
constructor(env, apiKey, opts) {
|
|
124
122
|
__privateAdd(this, _ParaCore_instances);
|
|
123
|
+
__privateAdd(this, _authInfo);
|
|
124
|
+
this.isNativePasskey = false;
|
|
125
|
+
__privateAdd(this, _partner);
|
|
125
126
|
this.isAwaitingAccountCreation = false;
|
|
126
127
|
this.isAwaitingLogin = false;
|
|
127
128
|
this.isAwaitingFarcaster = false;
|
|
@@ -130,14 +131,19 @@ const _ParaCore = class _ParaCore {
|
|
|
130
131
|
* 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.
|
|
131
132
|
*/
|
|
132
133
|
this.currentWalletIds = {};
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Wallets associated with the `ParaCore` instance.
|
|
136
|
+
*/
|
|
137
|
+
this.externalWallets = {};
|
|
135
138
|
this.localStorageGetItem = (key) => {
|
|
136
139
|
return this.platformUtils.localStorage.get(key);
|
|
137
140
|
};
|
|
138
141
|
this.localStorageSetItem = (key, value) => {
|
|
139
142
|
return this.platformUtils.localStorage.set(key, value);
|
|
140
143
|
};
|
|
144
|
+
this.localStorageRemoveItem = (key) => {
|
|
145
|
+
return this.platformUtils.localStorage.removeItem(key);
|
|
146
|
+
};
|
|
141
147
|
this.sessionStorageGetItem = (key) => {
|
|
142
148
|
return this.platformUtils.sessionStorage.get(key);
|
|
143
149
|
};
|
|
@@ -162,39 +168,73 @@ const _ParaCore = class _ParaCore {
|
|
|
162
168
|
this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
163
169
|
}
|
|
164
170
|
});
|
|
171
|
+
this.trackError = (methodName, err) => __async(this, null, function* () {
|
|
172
|
+
try {
|
|
173
|
+
yield this.ctx.client.trackError({
|
|
174
|
+
methodName,
|
|
175
|
+
sdkType: this.platformUtils.sdkType,
|
|
176
|
+
userId: this.userId,
|
|
177
|
+
error: {
|
|
178
|
+
name: err.name,
|
|
179
|
+
message: err.message
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
} catch (e) {
|
|
183
|
+
console.error("error tracking error:", e);
|
|
184
|
+
}
|
|
185
|
+
throw err;
|
|
186
|
+
});
|
|
187
|
+
this.wrapMethodsWithErrorTracking = (methodNames) => {
|
|
188
|
+
for (const methodName of methodNames) {
|
|
189
|
+
const original = this[methodName];
|
|
190
|
+
if (typeof original === "function") {
|
|
191
|
+
this[methodName] = (...args) => {
|
|
192
|
+
try {
|
|
193
|
+
const result = original.apply(this, args);
|
|
194
|
+
return result instanceof Promise ? result.catch((err) => this.trackError(methodName, err)) : result;
|
|
195
|
+
} catch (err) {
|
|
196
|
+
return this.trackError(methodName, err);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
165
202
|
this.initializeFromStorage = () => {
|
|
166
|
-
this.
|
|
167
|
-
this.
|
|
168
|
-
this.updatePhoneFromStorage();
|
|
203
|
+
this.updateExternalWalletsFromStorage();
|
|
204
|
+
this.updateAuthInfoFromStorage();
|
|
169
205
|
this.updateUserIdFromStorage();
|
|
170
|
-
this.updateTelegramUserIdFromStorage();
|
|
171
206
|
this.updateWalletsFromStorage();
|
|
172
207
|
this.updateWalletIdsFromStorage();
|
|
173
208
|
this.updateSessionCookieFromStorage();
|
|
174
209
|
this.updateLoginEncryptionKeyPairFromStorage();
|
|
175
|
-
this.updateExternalWalletsFromStorage();
|
|
176
210
|
};
|
|
177
|
-
this.
|
|
178
|
-
|
|
211
|
+
this.updateAuthInfoFromStorage = () => {
|
|
212
|
+
var _a;
|
|
213
|
+
const storageAuthInfo = this.localStorageGetItem(constants.LOCAL_STORAGE_AUTH_INFO) || void 0;
|
|
214
|
+
let authInfo = (0, import_utils2.jsonParse)(storageAuthInfo);
|
|
215
|
+
if (!authInfo) {
|
|
216
|
+
const authParams = {
|
|
217
|
+
email: this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL) || void 0,
|
|
218
|
+
phone: this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE) || void 0,
|
|
219
|
+
countryCode: this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE) || void 0,
|
|
220
|
+
farcasterUsername: this.localStorageGetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME) || void 0,
|
|
221
|
+
telegramUserId: this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0,
|
|
222
|
+
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
223
|
+
externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
|
|
224
|
+
};
|
|
225
|
+
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
226
|
+
}
|
|
227
|
+
__privateSet(this, _authInfo, authInfo);
|
|
179
228
|
};
|
|
180
229
|
this.updateUserIdFromStorage = () => {
|
|
181
230
|
this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
182
231
|
};
|
|
183
|
-
this.updatePhoneFromStorage = () => {
|
|
184
|
-
this.phone = this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE) || void 0;
|
|
185
|
-
};
|
|
186
|
-
this.updateCountryCodeFromStorage = () => {
|
|
187
|
-
this.countryCode = this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE) || void 0;
|
|
188
|
-
};
|
|
189
|
-
this.updateEmailFromStorage = () => {
|
|
190
|
-
this.email = this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL) || void 0;
|
|
191
|
-
};
|
|
192
232
|
this.updateWalletsFromStorage = () => __async(this, null, function* () {
|
|
193
233
|
var _a;
|
|
194
234
|
const _currentWalletIds = (_a = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
195
235
|
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
196
236
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
197
|
-
return Array.isArray(fromJson) ?
|
|
237
|
+
return Array.isArray(fromJson) ? import_user_management_client.WALLET_TYPES.reduce((acc, type) => {
|
|
198
238
|
const wallet = Object.values(this.wallets).find(
|
|
199
239
|
(w) => fromJson.includes(w.id) && import_utils2.WalletSchemeTypeMap[w.scheme][type]
|
|
200
240
|
);
|
|
@@ -218,9 +258,9 @@ const _ParaCore = class _ParaCore {
|
|
|
218
258
|
this.updateWalletIdsFromStorage = () => {
|
|
219
259
|
var _a;
|
|
220
260
|
const _currentWalletIds = (_a = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
221
|
-
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
261
|
+
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
222
262
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
223
|
-
return Array.isArray(fromJson) ?
|
|
263
|
+
return Array.isArray(fromJson) ? import_user_management_client.WALLET_TYPES.reduce((acc, type) => {
|
|
224
264
|
const wallet = Object.values(this.wallets).find(
|
|
225
265
|
(w) => fromJson.includes(w.id) && import_utils2.WalletSchemeTypeMap[w.scheme][type]
|
|
226
266
|
);
|
|
@@ -255,18 +295,23 @@ const _ParaCore = class _ParaCore {
|
|
|
255
295
|
* @deprecated alias for `createWalletPerType`
|
|
256
296
|
**/
|
|
257
297
|
this.createWalletPerMissingType = this.createWalletPerType;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
298
|
+
__privateAdd(this, _isCreateGuestWalletsPending, false);
|
|
299
|
+
this.getWalletBalance = (_0) => __async(this, [_0], function* ({
|
|
300
|
+
walletId,
|
|
301
|
+
rpcUrl
|
|
302
|
+
}) {
|
|
303
|
+
return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
|
|
263
304
|
});
|
|
305
|
+
if (!apiKey) {
|
|
306
|
+
throw new Error("A Para API key is required.");
|
|
307
|
+
}
|
|
264
308
|
if (!opts) opts = {};
|
|
265
309
|
let isE2E = false;
|
|
266
310
|
if (env === "E2E") {
|
|
267
311
|
isE2E = true;
|
|
268
312
|
env = import_types.Environment.SANDBOX;
|
|
269
313
|
}
|
|
314
|
+
this.externalWalletConnectionOnly = opts.externalWalletConnectionOnly;
|
|
270
315
|
this.emailPrimaryColor = opts.emailPrimaryColor;
|
|
271
316
|
this.emailTheme = opts.emailTheme;
|
|
272
317
|
this.homepageUrl = opts.homepageUrl;
|
|
@@ -318,72 +363,103 @@ const _ParaCore = class _ParaCore {
|
|
|
318
363
|
useDKLS: opts.useDKLSForCreation || !opts.offloadMPCComputationURL,
|
|
319
364
|
disableWebSockets: !!opts.disableWebSockets,
|
|
320
365
|
wasmOverride: opts.wasmOverride,
|
|
321
|
-
cosmosPrefix: this.cosmosPrefix,
|
|
322
366
|
isE2E
|
|
323
367
|
};
|
|
324
368
|
if (opts.offloadMPCComputationURL) {
|
|
325
369
|
this.ctx.mpcComputationClient = mpcComputationClient.initClient(opts.offloadMPCComputationURL, opts.disableWorkers);
|
|
326
370
|
}
|
|
327
|
-
try {
|
|
328
|
-
__privateSet(this, _supportedWalletTypes, opts.supportedWalletTypes ? (() => {
|
|
329
|
-
if (Object.values(opts.supportedWalletTypes).every(
|
|
330
|
-
(config) => !!config && typeof config === "object" && config.optional
|
|
331
|
-
)) {
|
|
332
|
-
throw new Error("at least one wallet type must be non-optional");
|
|
333
|
-
}
|
|
334
|
-
if (!Object.keys(opts.supportedWalletTypes).every((type) => Object.values(import_user_management_client.WalletType).includes(type))) {
|
|
335
|
-
throw new Error("unsupported wallet type");
|
|
336
|
-
}
|
|
337
|
-
__privateSet(this, _supportedWalletTypesOpt, opts.supportedWalletTypes);
|
|
338
|
-
return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
|
|
339
|
-
var _a;
|
|
340
|
-
if (!value) {
|
|
341
|
-
return acc;
|
|
342
|
-
}
|
|
343
|
-
if (key === import_user_management_client.WalletType.COSMOS && typeof value === "object" && !!value.prefix) {
|
|
344
|
-
this.cosmosPrefix = value.prefix;
|
|
345
|
-
}
|
|
346
|
-
return [...acc, { type: key, optional: value === true ? false : (_a = value.optional) != null ? _a : false }];
|
|
347
|
-
}, []);
|
|
348
|
-
})() : void 0);
|
|
349
|
-
} catch (e) {
|
|
350
|
-
__privateSet(this, _supportedWalletTypes, void 0);
|
|
351
|
-
}
|
|
352
371
|
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
353
372
|
return;
|
|
354
373
|
}
|
|
355
374
|
this.initializeFromStorage();
|
|
356
|
-
|
|
375
|
+
import_utils2.setupListeners.bind(this)();
|
|
376
|
+
(0, import_utils2.autoBind)(this);
|
|
377
|
+
if (env !== import_types.Environment.PROD) {
|
|
378
|
+
this.wrapMethodsWithErrorTracking([
|
|
379
|
+
"signUpOrLogIn",
|
|
380
|
+
"verifyNewAccount",
|
|
381
|
+
"waitForLogin",
|
|
382
|
+
"waitForSignup",
|
|
383
|
+
"waitForWalletCreation",
|
|
384
|
+
"verifyOAuth",
|
|
385
|
+
"verifyTelegram",
|
|
386
|
+
"verifyFarcaster",
|
|
387
|
+
"createPregenWallet",
|
|
388
|
+
"claimPregenWallets",
|
|
389
|
+
"signMessage",
|
|
390
|
+
"signTransaction"
|
|
391
|
+
]);
|
|
392
|
+
}
|
|
357
393
|
}
|
|
358
|
-
get
|
|
359
|
-
return
|
|
394
|
+
get authInfo() {
|
|
395
|
+
return __privateGet(this, _authInfo);
|
|
360
396
|
}
|
|
361
|
-
get
|
|
362
|
-
|
|
397
|
+
get email() {
|
|
398
|
+
var _a;
|
|
399
|
+
return (0, import_user_management_client.isEmail)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.email : void 0;
|
|
363
400
|
}
|
|
364
|
-
get
|
|
365
|
-
|
|
401
|
+
get phone() {
|
|
402
|
+
var _a;
|
|
403
|
+
return (0, import_user_management_client.isPhone)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.phone : void 0;
|
|
366
404
|
}
|
|
367
|
-
get
|
|
368
|
-
|
|
405
|
+
get farcasterUsername() {
|
|
406
|
+
var _a;
|
|
407
|
+
return (0, import_user_management_client.isFarcaster)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.farcasterUsername : void 0;
|
|
408
|
+
}
|
|
409
|
+
get telegramUserId() {
|
|
410
|
+
var _a;
|
|
411
|
+
return (0, import_user_management_client.isTelegram)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.telegramUserId : void 0;
|
|
369
412
|
}
|
|
370
413
|
get externalWalletWithParaAuth() {
|
|
371
414
|
const externalWallets = Object.values(this.externalWallets);
|
|
372
415
|
return externalWallets.find((w) => w.isExternalWithParaAuth);
|
|
373
416
|
}
|
|
417
|
+
get externalWalletConnectionType() {
|
|
418
|
+
if (this.isExternalWalletAuth) {
|
|
419
|
+
return "AUTHENTICATED";
|
|
420
|
+
} else if (!!Object.keys(this.externalWallets).length) {
|
|
421
|
+
return "CONNECTION_ONLY";
|
|
422
|
+
}
|
|
423
|
+
return "NONE";
|
|
424
|
+
}
|
|
425
|
+
get isEmail() {
|
|
426
|
+
var _a;
|
|
427
|
+
return (0, import_user_management_client.isEmail)((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
428
|
+
}
|
|
429
|
+
get isPhone() {
|
|
430
|
+
var _a;
|
|
431
|
+
return (0, import_user_management_client.isPhone)((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
432
|
+
}
|
|
433
|
+
get isFarcaster() {
|
|
434
|
+
var _a;
|
|
435
|
+
return (0, import_user_management_client.isFarcaster)((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
436
|
+
}
|
|
437
|
+
get isTelegram() {
|
|
438
|
+
var _a;
|
|
439
|
+
return (0, import_user_management_client.isTelegram)((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
440
|
+
}
|
|
374
441
|
get isExternalWalletAuth() {
|
|
375
|
-
|
|
442
|
+
var _a;
|
|
443
|
+
return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
|
|
444
|
+
}
|
|
445
|
+
get partnerId() {
|
|
446
|
+
var _a;
|
|
447
|
+
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id;
|
|
376
448
|
}
|
|
377
449
|
get currentWalletIdsArray() {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
450
|
+
var _a, _b;
|
|
451
|
+
return ((_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
452
|
+
(acc, { type }) => {
|
|
453
|
+
var _a2;
|
|
454
|
+
return [
|
|
455
|
+
...acc,
|
|
456
|
+
...((_a2 = this.currentWalletIds[type]) != null ? _a2 : []).map((id) => {
|
|
457
|
+
return [id, type];
|
|
458
|
+
})
|
|
459
|
+
];
|
|
460
|
+
},
|
|
461
|
+
[]
|
|
462
|
+
);
|
|
387
463
|
}
|
|
388
464
|
get currentWalletIdsUnique() {
|
|
389
465
|
return [...new Set(Object.values(this.currentWalletIds).flat())];
|
|
@@ -408,17 +484,23 @@ const _ParaCore = class _ParaCore {
|
|
|
408
484
|
* Whether the instance has multiple wallets connected.
|
|
409
485
|
*/
|
|
410
486
|
get isMultiWallet() {
|
|
411
|
-
return this.currentWalletIdsArray.length > 1;
|
|
487
|
+
return this.currentWalletIdsArray.length > 1 || __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 1;
|
|
412
488
|
}
|
|
413
489
|
get isNoWalletConfig() {
|
|
414
|
-
|
|
490
|
+
var _a;
|
|
491
|
+
return !!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) && __privateGet(this, _partner).supportedWalletTypes.length === 0;
|
|
415
492
|
}
|
|
416
493
|
get supportedWalletTypes() {
|
|
494
|
+
var _a, _b;
|
|
495
|
+
return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
496
|
+
}
|
|
497
|
+
get cosmosPrefix() {
|
|
417
498
|
var _a;
|
|
418
|
-
return (_a = __privateGet(this,
|
|
499
|
+
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
|
|
419
500
|
}
|
|
420
501
|
get isWalletTypeEnabled() {
|
|
421
|
-
|
|
502
|
+
var _a;
|
|
503
|
+
return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
422
504
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
423
505
|
}, {});
|
|
424
506
|
}
|
|
@@ -467,7 +549,7 @@ const _ParaCore = class _ParaCore {
|
|
|
467
549
|
}
|
|
468
550
|
isWalletSupported(wallet) {
|
|
469
551
|
var _a, _b;
|
|
470
|
-
return !__privateGet(this,
|
|
552
|
+
return !((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || (0, import_utils2.isWalletSupported)((_b = __privateGet(this, _partner).supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
471
553
|
}
|
|
472
554
|
isWalletOwned(wallet) {
|
|
473
555
|
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;
|
|
@@ -483,7 +565,7 @@ const _ParaCore = class _ParaCore {
|
|
|
483
565
|
));
|
|
484
566
|
}
|
|
485
567
|
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
486
|
-
var _a;
|
|
568
|
+
var _a, _b;
|
|
487
569
|
let error;
|
|
488
570
|
if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
|
|
489
571
|
return true;
|
|
@@ -493,15 +575,15 @@ const _ParaCore = class _ParaCore {
|
|
|
493
575
|
} else {
|
|
494
576
|
const wallet = this.wallets[walletId];
|
|
495
577
|
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
496
|
-
if (forbidPregen && isUnclaimed) {
|
|
578
|
+
if (forbidPregen && isUnclaimed && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
497
579
|
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
498
580
|
} else if (!isOwned && !isUnclaimed) {
|
|
499
581
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
500
582
|
} else if (!this.isWalletSupported(wallet)) {
|
|
501
|
-
error = `wallet with id ${wallet
|
|
583
|
+
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(", ")}`;
|
|
502
584
|
} else if (types && (!(0, import_utils2.getEquivalentTypes)(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
503
|
-
var _a2,
|
|
504
|
-
return (
|
|
585
|
+
var _a2, _b2;
|
|
586
|
+
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
505
587
|
}))) {
|
|
506
588
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
|
|
507
589
|
} else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
|
|
@@ -521,14 +603,17 @@ const _ParaCore = class _ParaCore {
|
|
|
521
603
|
* @param {string} walletId the ID of the wallet address to display.
|
|
522
604
|
* @param {object} options additional options for formatting the address.
|
|
523
605
|
* @param {boolean} options.truncate whether to truncate the address.
|
|
524
|
-
* @param {
|
|
606
|
+
* @param {TWalletType} options.addressType the type of address to display.
|
|
525
607
|
* @returns the formatted address
|
|
526
608
|
*/
|
|
527
609
|
getDisplayAddress(walletId, options = {}) {
|
|
528
|
-
var _a, _b;
|
|
610
|
+
var _a, _b, _c, _d;
|
|
529
611
|
if (this.externalWallets[walletId]) {
|
|
530
612
|
const wallet2 = this.externalWallets[walletId];
|
|
531
|
-
return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, {
|
|
613
|
+
return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, {
|
|
614
|
+
prefix: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix,
|
|
615
|
+
targetLength: options.targetLength
|
|
616
|
+
}) : wallet2.address;
|
|
532
617
|
}
|
|
533
618
|
const wallet = this.findWallet(walletId, options.addressType);
|
|
534
619
|
if (!wallet) {
|
|
@@ -537,8 +622,8 @@ const _ParaCore = class _ParaCore {
|
|
|
537
622
|
let str;
|
|
538
623
|
let prefix;
|
|
539
624
|
switch (wallet.type) {
|
|
540
|
-
case
|
|
541
|
-
prefix = (
|
|
625
|
+
case "COSMOS":
|
|
626
|
+
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
542
627
|
str = (0, import_utils2.getCosmosAddress)(wallet.publicKey, prefix);
|
|
543
628
|
break;
|
|
544
629
|
default:
|
|
@@ -571,8 +656,24 @@ const _ParaCore = class _ParaCore {
|
|
|
571
656
|
}
|
|
572
657
|
constructPortalUrl(_0) {
|
|
573
658
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
574
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
575
|
-
const
|
|
659
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
660
|
+
const [isCreate, isLogin, isOnRamp] = [
|
|
661
|
+
["createAuth", "createPassword"].includes(type),
|
|
662
|
+
["loginAuth", "loginPassword"].includes(type),
|
|
663
|
+
type === "onRamp"
|
|
664
|
+
];
|
|
665
|
+
if (isCreate || isLogin) {
|
|
666
|
+
this.assertIsAuthSet();
|
|
667
|
+
}
|
|
668
|
+
let sessionId = opts.sessionId;
|
|
669
|
+
if ((isLogin || isOnRamp) && !sessionId) {
|
|
670
|
+
const session = yield this.touchSession(true);
|
|
671
|
+
sessionId = session.sessionId;
|
|
672
|
+
}
|
|
673
|
+
if (!this.loginEncryptionKeyPair) {
|
|
674
|
+
yield this.setLoginEncryptionKeyPair();
|
|
675
|
+
}
|
|
676
|
+
const base = type === "onRamp" ? (0, import_utils2.getPortalBaseURL)(this.ctx) : yield this.getPortalURL();
|
|
576
677
|
let path;
|
|
577
678
|
switch (type) {
|
|
578
679
|
case "createPassword": {
|
|
@@ -603,61 +704,55 @@ const _ParaCore = class _ParaCore {
|
|
|
603
704
|
throw new Error(`invalid URL type ${type}`);
|
|
604
705
|
}
|
|
605
706
|
}
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
const partner = opts.partnerId ? (_a = (yield this.ctx.client.getPartner(opts.partnerId)).data) == null ? void 0 : _a.partner : void 0;
|
|
707
|
+
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
708
|
+
const thisDevice = (_a = opts.thisDevice) != null ? _a : {
|
|
709
|
+
encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
|
|
710
|
+
sessionId
|
|
711
|
+
};
|
|
612
712
|
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
613
713
|
apiKey: this.ctx.apiKey,
|
|
614
|
-
partnerId:
|
|
615
|
-
portalFont: ((_b = opts.
|
|
616
|
-
portalBorderRadius: ((_d = opts.
|
|
617
|
-
portalThemeMode: ((_f = opts.
|
|
618
|
-
portalAccentColor: ((_h = opts.
|
|
619
|
-
portalForegroundColor: ((_j = opts.
|
|
620
|
-
portalBackgroundColor: ((_l = opts.
|
|
714
|
+
partnerId: partner.id,
|
|
715
|
+
portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
|
|
716
|
+
portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
|
|
717
|
+
portalThemeMode: ((_f = opts.portalTheme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
|
|
718
|
+
portalAccentColor: ((_h = opts.portalTheme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
|
|
719
|
+
portalForegroundColor: ((_j = opts.portalTheme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
|
|
720
|
+
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),
|
|
621
721
|
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
622
722
|
portalTextColor: this.portalTextColor,
|
|
623
723
|
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
624
|
-
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
} : {}),
|
|
637
|
-
|
|
724
|
+
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
725
|
+
}, isCreate || isLogin ? __spreadProps(__spreadValues({
|
|
726
|
+
authInfo: JSON.stringify(this.authInfo)
|
|
727
|
+
}, (0, import_user_management_client.isPhone)(this.authInfo.auth) ? (0, import_utils2.splitPhoneNumber)(this.authInfo.auth.phone) : this.authInfo.auth), {
|
|
728
|
+
pfpUrl: this.authInfo.pfpUrl,
|
|
729
|
+
displayName: this.authInfo.displayName
|
|
730
|
+
}) : {}), isOnRamp ? { sessionId } : {}), isLogin ? __spreadProps(__spreadValues({
|
|
731
|
+
sessionId: thisDevice.sessionId,
|
|
732
|
+
encryptionKey: thisDevice.encryptionKey
|
|
733
|
+
}, opts.newDevice ? {
|
|
734
|
+
newDeviceSessionLookupId: opts.newDevice.sessionId,
|
|
735
|
+
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
736
|
+
} : {}), {
|
|
737
|
+
pregenIds: JSON.stringify(this.pregenIds)
|
|
738
|
+
}) : {}), opts.params || {});
|
|
739
|
+
const url = (0, import_utils2.constructUrl)({ base, path, params });
|
|
740
|
+
if (opts.shorten) {
|
|
741
|
+
return (0, import_utils2.shortenUrl)(this.ctx, url);
|
|
742
|
+
}
|
|
743
|
+
return url;
|
|
638
744
|
});
|
|
639
745
|
}
|
|
640
746
|
touchSession(regenerate = false) {
|
|
641
747
|
return __async(this, null, function* () {
|
|
642
|
-
|
|
643
|
-
this.
|
|
644
|
-
|
|
748
|
+
var _a, _b, _c;
|
|
749
|
+
const session = yield this.ctx.client.touchSession(regenerate);
|
|
750
|
+
if (!__privateGet(this, _partner) || ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) !== session.partnerId || !(0, import_utils2.supportedWalletTypesEq)(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
|
|
751
|
+
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
752
|
+
}
|
|
753
|
+
return session;
|
|
645
754
|
});
|
|
646
755
|
}
|
|
647
|
-
setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
|
|
648
|
-
if (supportedWalletTypes && !__privateGet(this, _supportedWalletTypes)) {
|
|
649
|
-
__privateSet(this, _supportedWalletTypes, supportedWalletTypes);
|
|
650
|
-
Object.keys(this.currentWalletIds).forEach((type) => {
|
|
651
|
-
var _a;
|
|
652
|
-
if (!((_a = __privateGet(this, _supportedWalletTypes)) == null ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
|
|
653
|
-
delete this.currentWalletIds[type];
|
|
654
|
-
}
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
if (cosmosPrefix && !this.cosmosPrefix) {
|
|
658
|
-
this.cosmosPrefix = cosmosPrefix;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
756
|
getVerificationEmailProps() {
|
|
662
757
|
return {
|
|
663
758
|
brandColor: this.emailPrimaryColor,
|
|
@@ -687,12 +782,26 @@ const _ParaCore = class _ParaCore {
|
|
|
687
782
|
*/
|
|
688
783
|
init() {
|
|
689
784
|
return __async(this, null, function* () {
|
|
690
|
-
var _a;
|
|
691
|
-
this.email = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL)) || void 0;
|
|
692
|
-
this.countryCode = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE)) || void 0;
|
|
693
|
-
this.phone = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE)) || void 0;
|
|
785
|
+
var _a, _b;
|
|
694
786
|
this.userId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID)) || void 0;
|
|
695
|
-
|
|
787
|
+
const storageAuthInfo = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_AUTH_INFO)) || void 0;
|
|
788
|
+
const stringExternalWallets = yield this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
789
|
+
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
790
|
+
yield this.setExternalWallets(_externalWallets);
|
|
791
|
+
let authInfo = (0, import_utils2.jsonParse)(storageAuthInfo);
|
|
792
|
+
if (!authInfo) {
|
|
793
|
+
const authParams = {
|
|
794
|
+
email: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL)) || void 0,
|
|
795
|
+
phone: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE)) || void 0,
|
|
796
|
+
countryCode: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE)) || void 0,
|
|
797
|
+
farcasterUsername: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME)) || void 0,
|
|
798
|
+
telegramUserId: (yield this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0,
|
|
799
|
+
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
800
|
+
externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
|
|
801
|
+
};
|
|
802
|
+
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
803
|
+
}
|
|
804
|
+
__privateSet(this, _authInfo, authInfo);
|
|
696
805
|
const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_WALLETS);
|
|
697
806
|
const _wallets = JSON.parse(stringWallets || "{}");
|
|
698
807
|
const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_ED25519_WALLETS);
|
|
@@ -705,10 +814,10 @@ const _ParaCore = class _ParaCore {
|
|
|
705
814
|
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: (0, import_utils2.migrateWallet)(_ed25519Wallets[key]) } : {});
|
|
706
815
|
}, {}));
|
|
707
816
|
yield this.setWallets(wallets);
|
|
708
|
-
const _currentWalletIds = (
|
|
817
|
+
const _currentWalletIds = (_b = yield this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _b : void 0;
|
|
709
818
|
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
710
819
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
711
|
-
return Array.isArray(fromJson) ?
|
|
820
|
+
return Array.isArray(fromJson) ? import_user_management_client.WALLET_TYPES.reduce((acc, type) => {
|
|
712
821
|
const wallet = Object.values(this.wallets).find(
|
|
713
822
|
(w) => fromJson.includes(w.id) && import_utils2.WalletSchemeTypeMap[w.scheme][type]
|
|
714
823
|
);
|
|
@@ -724,21 +833,42 @@ const _ParaCore = class _ParaCore {
|
|
|
724
833
|
if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
|
|
725
834
|
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
726
835
|
}
|
|
727
|
-
|
|
728
|
-
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
729
|
-
yield this.setExternalWallets(_externalWallets);
|
|
730
|
-
import_listeners.setupListeners.bind(this)();
|
|
836
|
+
import_utils2.setupListeners.bind(this)();
|
|
731
837
|
yield this.touchSession();
|
|
732
838
|
});
|
|
733
839
|
}
|
|
840
|
+
setAuth(_0) {
|
|
841
|
+
return __async(this, arguments, function* (auth, { extras = {}, userId } = {}) {
|
|
842
|
+
const authInfo = __spreadValues(__spreadValues({}, (0, import_user_management_client.extractAuthInfo)(auth, { isRequired: true })), extras || {});
|
|
843
|
+
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
844
|
+
if (!!userId) {
|
|
845
|
+
yield this.setUserId(userId);
|
|
846
|
+
}
|
|
847
|
+
return __privateGet(this, _authInfo);
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
assertUserId() {
|
|
851
|
+
if (!this.userId) {
|
|
852
|
+
throw new Error("no userId is set");
|
|
853
|
+
}
|
|
854
|
+
return this.userId;
|
|
855
|
+
}
|
|
856
|
+
assertIsAuthSet(allowed) {
|
|
857
|
+
if (!__privateGet(this, _authInfo)) {
|
|
858
|
+
throw new Error("auth is not set");
|
|
859
|
+
}
|
|
860
|
+
if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
|
|
861
|
+
throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
|
|
862
|
+
}
|
|
863
|
+
return __privateGet(this, _authInfo);
|
|
864
|
+
}
|
|
734
865
|
/**
|
|
735
866
|
* Sets the email associated with the `ParaCore` instance.
|
|
736
867
|
* @param email - Email to set.
|
|
737
868
|
*/
|
|
738
869
|
setEmail(email) {
|
|
739
870
|
return __async(this, null, function* () {
|
|
740
|
-
this.email
|
|
741
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_EMAIL, email);
|
|
871
|
+
yield this.setAuth({ email });
|
|
742
872
|
});
|
|
743
873
|
}
|
|
744
874
|
/**
|
|
@@ -747,8 +877,7 @@ const _ParaCore = class _ParaCore {
|
|
|
747
877
|
*/
|
|
748
878
|
setTelegramUserId(telegramUserId) {
|
|
749
879
|
return __async(this, null, function* () {
|
|
750
|
-
this.telegramUserId
|
|
751
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
|
|
880
|
+
yield this.setAuth({ telegramUserId });
|
|
752
881
|
});
|
|
753
882
|
}
|
|
754
883
|
/**
|
|
@@ -758,10 +887,7 @@ const _ParaCore = class _ParaCore {
|
|
|
758
887
|
*/
|
|
759
888
|
setPhoneNumber(phone, countryCode) {
|
|
760
889
|
return __async(this, null, function* () {
|
|
761
|
-
this.phone
|
|
762
|
-
this.countryCode = countryCode;
|
|
763
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_PHONE, phone);
|
|
764
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_COUNTRY_CODE, countryCode);
|
|
890
|
+
yield this.setAuth({ phone: (0, import_utils2.formatPhoneNumber)(phone, countryCode) });
|
|
765
891
|
});
|
|
766
892
|
}
|
|
767
893
|
/**
|
|
@@ -770,8 +896,7 @@ const _ParaCore = class _ParaCore {
|
|
|
770
896
|
*/
|
|
771
897
|
setFarcasterUsername(farcasterUsername) {
|
|
772
898
|
return __async(this, null, function* () {
|
|
773
|
-
this.farcasterUsername
|
|
774
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
|
|
899
|
+
yield this.setAuth({ farcasterUsername });
|
|
775
900
|
});
|
|
776
901
|
}
|
|
777
902
|
/**
|
|
@@ -856,6 +981,9 @@ const _ParaCore = class _ParaCore {
|
|
|
856
981
|
getUserId() {
|
|
857
982
|
return this.userId;
|
|
858
983
|
}
|
|
984
|
+
getAuthInfo() {
|
|
985
|
+
return this.authInfo;
|
|
986
|
+
}
|
|
859
987
|
/**
|
|
860
988
|
* Gets the email associated with the `ParaCore` instance.
|
|
861
989
|
* @returns - email associated with the `ParaCore` instance.
|
|
@@ -863,22 +991,12 @@ const _ParaCore = class _ParaCore {
|
|
|
863
991
|
getEmail() {
|
|
864
992
|
return this.email;
|
|
865
993
|
}
|
|
866
|
-
/**
|
|
867
|
-
* Gets the phone object associated with the `ParaCore` instance.
|
|
868
|
-
* @returns - phone object with phone number and country code associated with the `ParaCore` instance.
|
|
869
|
-
*/
|
|
870
|
-
getPhone() {
|
|
871
|
-
return { phone: this.phone, countryCode: this.countryCode };
|
|
872
|
-
}
|
|
873
994
|
/**
|
|
874
995
|
* Gets the formatted phone number associated with the `ParaCore` instance.
|
|
875
996
|
* @returns - formatted phone number associated with the `ParaCore` instance.
|
|
876
997
|
*/
|
|
877
998
|
getPhoneNumber() {
|
|
878
|
-
|
|
879
|
-
return void 0;
|
|
880
|
-
}
|
|
881
|
-
return (0, import_utils2.normalizePhoneNumber)(this.countryCode, this.phone);
|
|
999
|
+
return this.phone;
|
|
882
1000
|
}
|
|
883
1001
|
/**
|
|
884
1002
|
* Gets the farcaster username associated with the `ParaCore` instance.
|
|
@@ -917,9 +1035,7 @@ const _ParaCore = class _ParaCore {
|
|
|
917
1035
|
if (!(yield this.isSessionActive()) || !this.userId) {
|
|
918
1036
|
throw new Error("no signed-in user");
|
|
919
1037
|
}
|
|
920
|
-
const {
|
|
921
|
-
data: { partnerId }
|
|
922
|
-
} = yield this.touchSession();
|
|
1038
|
+
const { partnerId } = yield this.touchSession();
|
|
923
1039
|
const { accountMetadata } = yield this.ctx.client.getAccountMetadata(this.userId, partnerId);
|
|
924
1040
|
return accountMetadata;
|
|
925
1041
|
});
|
|
@@ -977,8 +1093,10 @@ const _ParaCore = class _ParaCore {
|
|
|
977
1093
|
}
|
|
978
1094
|
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
979
1095
|
var _a, _c, _d;
|
|
980
|
-
if (!this.isExternalWalletAuth
|
|
981
|
-
|
|
1096
|
+
if (!this.isExternalWalletAuth) {
|
|
1097
|
+
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
1098
|
+
return Object.values(this.externalWallets)[0];
|
|
1099
|
+
}
|
|
982
1100
|
}
|
|
983
1101
|
if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
|
|
984
1102
|
return this.externalWallets[idOrAddress];
|
|
@@ -989,7 +1107,7 @@ const _ParaCore = class _ParaCore {
|
|
|
989
1107
|
const _b = this.wallets[walletId], { signer: _signer } = _b, wallet = __objRest(_b, ["signer"]);
|
|
990
1108
|
const type = (_d = overrideType != null ? overrideType : (_c = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _c[1]) != null ? _d : wallet.type;
|
|
991
1109
|
return __spreadProps(__spreadValues({}, wallet), {
|
|
992
|
-
type
|
|
1110
|
+
type
|
|
993
1111
|
});
|
|
994
1112
|
}
|
|
995
1113
|
} catch (e) {
|
|
@@ -999,7 +1117,7 @@ const _ParaCore = class _ParaCore {
|
|
|
999
1117
|
get availableWallets() {
|
|
1000
1118
|
var _a;
|
|
1001
1119
|
return [
|
|
1002
|
-
...this.currentWalletIdsArray.map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1120
|
+
...[...this.currentWalletIdsArray, ...__privateGet(this, _ParaCore_instances, guestWalletIdsArray_get)].map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1003
1121
|
const wallet = this.findWallet(id, type);
|
|
1004
1122
|
if (!wallet) return null;
|
|
1005
1123
|
return {
|
|
@@ -1025,10 +1143,8 @@ const _ParaCore = class _ParaCore {
|
|
|
1025
1143
|
}
|
|
1026
1144
|
assertIsValidWalletType(type, walletTypes) {
|
|
1027
1145
|
return __async(this, null, function* () {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
}
|
|
1031
|
-
if (!type || !Object.values(import_user_management_client.WalletType).includes(type) || !(walletTypes != null ? walletTypes : this.supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
1146
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1147
|
+
if (!type || !import_user_management_client.WALLET_TYPES.includes(type) || !(walletTypes != null ? walletTypes : supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
1032
1148
|
throw new Error(`wallet type ${type} is not supported`);
|
|
1033
1149
|
}
|
|
1034
1150
|
return type;
|
|
@@ -1036,33 +1152,29 @@ const _ParaCore = class _ParaCore {
|
|
|
1036
1152
|
}
|
|
1037
1153
|
getMissingTypes() {
|
|
1038
1154
|
return __async(this, null, function* () {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
}
|
|
1042
|
-
return this.supportedWalletTypes.filter(
|
|
1155
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1156
|
+
return supportedWalletTypes.filter(
|
|
1043
1157
|
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !import_utils2.WalletSchemeTypeMap[w.scheme][t])
|
|
1044
1158
|
).map(({ type }) => type);
|
|
1045
1159
|
});
|
|
1046
1160
|
}
|
|
1047
1161
|
getTypesToCreate(types) {
|
|
1048
1162
|
return __async(this, null, function* () {
|
|
1049
|
-
|
|
1050
|
-
yield this.touchSession();
|
|
1051
|
-
}
|
|
1163
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1052
1164
|
return (0, import_utils2.getSchemes)(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
1053
1165
|
switch (scheme) {
|
|
1054
|
-
case
|
|
1055
|
-
return
|
|
1166
|
+
case "ED25519":
|
|
1167
|
+
return "SOLANA";
|
|
1056
1168
|
default:
|
|
1057
|
-
return
|
|
1169
|
+
return supportedWalletTypes.some(({ type, optional }) => type === "COSMOS" && !optional) ? "COSMOS" : "EVM";
|
|
1058
1170
|
}
|
|
1059
1171
|
});
|
|
1060
1172
|
});
|
|
1061
1173
|
}
|
|
1062
|
-
getPartnerURL(
|
|
1174
|
+
getPartnerURL() {
|
|
1063
1175
|
return __async(this, null, function* () {
|
|
1064
|
-
const
|
|
1065
|
-
return
|
|
1176
|
+
const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1177
|
+
return portalUrl;
|
|
1066
1178
|
});
|
|
1067
1179
|
}
|
|
1068
1180
|
/**
|
|
@@ -1070,75 +1182,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1070
1182
|
* @param partnerId: string - id of the partner to get the portal URL for
|
|
1071
1183
|
* @returns - portal URL
|
|
1072
1184
|
*/
|
|
1073
|
-
getPortalURL(
|
|
1074
|
-
return __async(this, null, function* () {
|
|
1075
|
-
return partnerId && (yield this.getPartnerURL(partnerId)) || (0, import_utils2.getPortalBaseURL)(this.ctx);
|
|
1076
|
-
});
|
|
1077
|
-
}
|
|
1078
|
-
getWebAuthURLForCreate(_a) {
|
|
1079
|
-
return __async(this, null, function* () {
|
|
1080
|
-
var _b = _a, {
|
|
1081
|
-
webAuthId
|
|
1082
|
-
} = _b, options = __objRest(_b, [
|
|
1083
|
-
"webAuthId"
|
|
1084
|
-
]);
|
|
1085
|
-
return this.constructPortalUrl("createAuth", __spreadProps(__spreadValues({}, options), { pathId: webAuthId }));
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
getPasswordURLForCreate(_c) {
|
|
1089
|
-
return __async(this, null, function* () {
|
|
1090
|
-
var _d = _c, {
|
|
1091
|
-
passwordId
|
|
1092
|
-
} = _d, options = __objRest(_d, [
|
|
1093
|
-
"passwordId"
|
|
1094
|
-
]);
|
|
1095
|
-
return this.constructPortalUrl("createPassword", __spreadProps(__spreadValues({}, options), {
|
|
1096
|
-
pathId: passwordId
|
|
1097
|
-
}));
|
|
1098
|
-
});
|
|
1099
|
-
}
|
|
1100
|
-
getShortUrl(compressedUrl) {
|
|
1101
|
-
return (0, import_utils2.constructUrl)({
|
|
1102
|
-
base: (0, import_utils2.getPortalBaseURL)(this.ctx),
|
|
1103
|
-
path: `/short/${compressedUrl}`
|
|
1104
|
-
});
|
|
1105
|
-
}
|
|
1106
|
-
shortenLoginLink(link) {
|
|
1107
|
-
return __async(this, null, function* () {
|
|
1108
|
-
const url = yield transmissionUtils.upload(link, this.ctx.client);
|
|
1109
|
-
return this.getShortUrl(url);
|
|
1110
|
-
});
|
|
1111
|
-
}
|
|
1112
|
-
/**
|
|
1113
|
-
* Generates a URL for registering a new WebAuth passkey.
|
|
1114
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1115
|
-
* @returns - the URL for creating a new passkey
|
|
1116
|
-
*/
|
|
1117
|
-
getWebAuthURLForLogin(opts) {
|
|
1185
|
+
getPortalURL() {
|
|
1118
1186
|
return __async(this, null, function* () {
|
|
1119
|
-
return this.
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
/**
|
|
1123
|
-
* Generates a URL for registering a new user password.
|
|
1124
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1125
|
-
* @returns - the URL for creating a new password
|
|
1126
|
-
*/
|
|
1127
|
-
getPasswordURLForLogin(opts) {
|
|
1128
|
-
return __async(this, null, function* () {
|
|
1129
|
-
return this.constructPortalUrl("loginPassword", opts);
|
|
1130
|
-
});
|
|
1131
|
-
}
|
|
1132
|
-
/**
|
|
1133
|
-
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
1134
|
-
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
1135
|
-
* @returns - web auth url
|
|
1136
|
-
*/
|
|
1137
|
-
getWebAuthURLForLoginForPhone(opts) {
|
|
1138
|
-
return __async(this, null, function* () {
|
|
1139
|
-
return this.constructPortalUrl("loginAuth", __spreadValues({
|
|
1140
|
-
authType: "phone"
|
|
1141
|
-
}, opts));
|
|
1187
|
+
return (yield this.getPartnerURL()) || (0, import_utils2.getPortalBaseURL)(this.ctx);
|
|
1142
1188
|
});
|
|
1143
1189
|
}
|
|
1144
1190
|
/**
|
|
@@ -1153,7 +1199,7 @@ const _ParaCore = class _ParaCore {
|
|
|
1153
1199
|
if (!wallet) {
|
|
1154
1200
|
throw new Error("wallet not found");
|
|
1155
1201
|
}
|
|
1156
|
-
if (wallet.scheme !==
|
|
1202
|
+
if (wallet.scheme !== "DKLS") {
|
|
1157
1203
|
throw new Error("invalid wallet scheme");
|
|
1158
1204
|
}
|
|
1159
1205
|
return yield this.platformUtils.getPrivateKey(
|
|
@@ -1200,124 +1246,52 @@ const _ParaCore = class _ParaCore {
|
|
|
1200
1246
|
yield this.setWallets(this.wallets);
|
|
1201
1247
|
});
|
|
1202
1248
|
}
|
|
1203
|
-
/**
|
|
1204
|
-
* Checks if a user exists for an email address.
|
|
1205
|
-
* @param {Object} opts the options object
|
|
1206
|
-
* @param {string} opts.email the email to check.
|
|
1207
|
-
* @returns true if user exists, false otherwise.
|
|
1208
|
-
*/
|
|
1209
|
-
checkIfUserExists(_0) {
|
|
1210
|
-
return __async(this, arguments, function* ({ email }) {
|
|
1211
|
-
const res = yield this.ctx.client.checkUserExists({ email });
|
|
1212
|
-
return res.data.exists;
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
/**
|
|
1216
|
-
* Checks if a user exists for a phone number.
|
|
1217
|
-
* @param {Object} opts the options object
|
|
1218
|
-
* @param {string} opts.phone - phone number to check.
|
|
1219
|
-
* @param {string} opts.countryCode - the country code.
|
|
1220
|
-
* @returns true if user exists, false otherwise.
|
|
1221
|
-
*/
|
|
1222
|
-
checkIfUserExistsByPhone(_0) {
|
|
1223
|
-
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
1224
|
-
const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
|
|
1225
|
-
return res.data.exists;
|
|
1226
|
-
});
|
|
1227
|
-
}
|
|
1228
|
-
/**
|
|
1229
|
-
* Creates a new user.
|
|
1230
|
-
* @param {Object} opts the options object
|
|
1231
|
-
* @param {string} opts.email the email to use.
|
|
1232
|
-
*/
|
|
1233
|
-
createUser(_0) {
|
|
1234
|
-
return __async(this, arguments, function* ({ email }) {
|
|
1235
|
-
this.requireApiKey();
|
|
1236
|
-
yield this.setEmail(email);
|
|
1237
|
-
const { userId } = yield this.ctx.client.createUser(__spreadValues({
|
|
1238
|
-
email: this.email
|
|
1239
|
-
}, this.getVerificationEmailProps()));
|
|
1240
|
-
yield this.setUserId(userId);
|
|
1241
|
-
});
|
|
1242
|
-
}
|
|
1243
|
-
/**
|
|
1244
|
-
* Creates a new user with a phone number.
|
|
1245
|
-
* @param {Object} opts the options object
|
|
1246
|
-
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
1247
|
-
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
1248
|
-
*/
|
|
1249
|
-
createUserByPhone(_0) {
|
|
1250
|
-
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
1251
|
-
this.requireApiKey();
|
|
1252
|
-
yield this.setPhoneNumber(phone, countryCode);
|
|
1253
|
-
const { userId } = yield this.ctx.client.createUser({
|
|
1254
|
-
phone: this.phone,
|
|
1255
|
-
countryCode: this.countryCode
|
|
1256
|
-
});
|
|
1257
|
-
yield this.setUserId(userId);
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
1249
|
/**
|
|
1261
1250
|
* Logs in or creates a new user using an external wallet address.
|
|
1262
1251
|
* @param {Object} opts the options object
|
|
1263
1252
|
* @param {string} opts.address the external wallet address to use for identification.
|
|
1264
|
-
* @param {
|
|
1253
|
+
* @param {TWalletType} opts.type type of external wallet to use for identification.
|
|
1265
1254
|
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
1266
1255
|
*/
|
|
1267
|
-
|
|
1256
|
+
loginExternalWallet(_a) {
|
|
1268
1257
|
return __async(this, null, function* () {
|
|
1258
|
+
var _b = _a, {
|
|
1259
|
+
externalWallet
|
|
1260
|
+
} = _b, urlOptions = __objRest(_b, [
|
|
1261
|
+
"externalWallet"
|
|
1262
|
+
]);
|
|
1263
|
+
if (this.externalWalletConnectionOnly) {
|
|
1264
|
+
externalWallet.withFullParaAuth = false;
|
|
1265
|
+
yield this.setExternalWallet(externalWallet);
|
|
1266
|
+
return Promise.resolve({
|
|
1267
|
+
userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1269
1270
|
this.requireApiKey();
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1272
|
-
type: wallet.type,
|
|
1273
|
-
externalWalletProvider: wallet.provider,
|
|
1274
|
-
// If the wallet isn't using full Para auth we want to track the login here
|
|
1275
|
-
shouldTrackUser: !wallet.withFullParaAuth
|
|
1276
|
-
});
|
|
1277
|
-
yield this.setExternalWallet(wallet);
|
|
1278
|
-
yield this.setUserId(res.userId);
|
|
1279
|
-
return res;
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
/**
|
|
1283
|
-
* Returns whether or not the user is connected with only an external wallet, not an external wallet with Para auth.
|
|
1284
|
-
*/
|
|
1285
|
-
isUsingExternalWallet() {
|
|
1286
|
-
return !this.isExternalWalletAuth && !!Object.keys(this.externalWallets).length;
|
|
1287
|
-
}
|
|
1288
|
-
/**
|
|
1289
|
-
* Passes the email code obtained from the user for verification.
|
|
1290
|
-
* @param {Object} opts the options object
|
|
1291
|
-
* @param {string} verificationCode the six-digit code to check
|
|
1292
|
-
* @returns {string} the web auth url for creating a new credential
|
|
1293
|
-
*/
|
|
1294
|
-
verifyEmail(_0) {
|
|
1295
|
-
return __async(this, arguments, function* ({ verificationCode }) {
|
|
1296
|
-
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
1297
|
-
return this.getSetUpBiometricsURL();
|
|
1271
|
+
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
|
|
1272
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1298
1273
|
});
|
|
1299
1274
|
}
|
|
1300
|
-
verifyExternalWallet(
|
|
1301
|
-
return __async(this,
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
return this.getSetUpBiometricsURLForPhone();
|
|
1275
|
+
verifyExternalWallet(_c) {
|
|
1276
|
+
return __async(this, null, function* () {
|
|
1277
|
+
var _d = _c, {
|
|
1278
|
+
externalWallet,
|
|
1279
|
+
signedMessage,
|
|
1280
|
+
cosmosPublicKeyHex,
|
|
1281
|
+
cosmosSigner
|
|
1282
|
+
} = _d, urlOptions = __objRest(_d, [
|
|
1283
|
+
"externalWallet",
|
|
1284
|
+
"signedMessage",
|
|
1285
|
+
"cosmosPublicKeyHex",
|
|
1286
|
+
"cosmosSigner"
|
|
1287
|
+
]);
|
|
1288
|
+
const serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
|
|
1289
|
+
externalWallet,
|
|
1290
|
+
signedMessage,
|
|
1291
|
+
cosmosPublicKeyHex,
|
|
1292
|
+
cosmosSigner
|
|
1293
|
+
});
|
|
1294
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1321
1295
|
});
|
|
1322
1296
|
}
|
|
1323
1297
|
/**
|
|
@@ -1326,18 +1300,19 @@ const _ParaCore = class _ParaCore {
|
|
|
1326
1300
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1327
1301
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1328
1302
|
*/
|
|
1329
|
-
verifyTelegram(
|
|
1303
|
+
verifyTelegram(_e) {
|
|
1330
1304
|
return __async(this, null, function* () {
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1305
|
+
var _f = _e, {
|
|
1306
|
+
telegramAuthResponse
|
|
1307
|
+
} = _f, urlOptions = __objRest(_f, [
|
|
1308
|
+
"telegramAuthResponse"
|
|
1309
|
+
]);
|
|
1310
|
+
try {
|
|
1311
|
+
const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
|
|
1312
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1313
|
+
} catch (e) {
|
|
1314
|
+
throw new Error(e.message);
|
|
1339
1315
|
}
|
|
1340
|
-
return res;
|
|
1341
1316
|
});
|
|
1342
1317
|
}
|
|
1343
1318
|
/**
|
|
@@ -1347,32 +1322,9 @@ const _ParaCore = class _ParaCore {
|
|
|
1347
1322
|
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
1348
1323
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1349
1324
|
*/
|
|
1350
|
-
|
|
1351
|
-
return __async(this, arguments, function* ({
|
|
1352
|
-
const res = yield this.ctx.client.verify2FA(
|
|
1353
|
-
return {
|
|
1354
|
-
initiatedAt: res.data.initiatedAt,
|
|
1355
|
-
status: res.data.status,
|
|
1356
|
-
userId: res.data.userId,
|
|
1357
|
-
wallets: res.data.wallets
|
|
1358
|
-
};
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
/**
|
|
1362
|
-
* Performs 2FA verification.
|
|
1363
|
-
* @param {Object} opts the options object
|
|
1364
|
-
* @param {string} opts.phone the phone number
|
|
1365
|
-
* @param {string} opts.countryCode - the country code
|
|
1366
|
-
* @param {string} opts.verificationCode - verification code to received via 2FA.
|
|
1367
|
-
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1368
|
-
*/
|
|
1369
|
-
verify2FAForPhone(_0) {
|
|
1370
|
-
return __async(this, arguments, function* ({
|
|
1371
|
-
phone,
|
|
1372
|
-
countryCode,
|
|
1373
|
-
verificationCode
|
|
1374
|
-
}) {
|
|
1375
|
-
const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
|
|
1325
|
+
verify2fa(_0) {
|
|
1326
|
+
return __async(this, arguments, function* ({ auth, verificationCode }) {
|
|
1327
|
+
const res = yield this.ctx.client.verify2FA(auth, verificationCode);
|
|
1376
1328
|
return {
|
|
1377
1329
|
initiatedAt: res.data.initiatedAt,
|
|
1378
1330
|
status: res.data.status,
|
|
@@ -1385,12 +1337,11 @@ const _ParaCore = class _ParaCore {
|
|
|
1385
1337
|
* Sets up two-factor authentication for the current user.
|
|
1386
1338
|
* @returns {string} uri - uri to use for setting up 2FA
|
|
1387
1339
|
* */
|
|
1388
|
-
|
|
1340
|
+
setup2fa() {
|
|
1389
1341
|
return __async(this, null, function* () {
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
};
|
|
1342
|
+
const userId = this.assertUserId();
|
|
1343
|
+
const res = yield this.ctx.client.setup2FA(userId);
|
|
1344
|
+
return res;
|
|
1394
1345
|
});
|
|
1395
1346
|
}
|
|
1396
1347
|
/**
|
|
@@ -1398,24 +1349,10 @@ const _ParaCore = class _ParaCore {
|
|
|
1398
1349
|
* @param {Object} opts the options object
|
|
1399
1350
|
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
1400
1351
|
*/
|
|
1401
|
-
|
|
1352
|
+
enable2fa(_0) {
|
|
1402
1353
|
return __async(this, arguments, function* ({ verificationCode }) {
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
}
|
|
1406
|
-
/**
|
|
1407
|
-
* Determines if 2FA has been set up.
|
|
1408
|
-
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
1409
|
-
*/
|
|
1410
|
-
check2FAStatus() {
|
|
1411
|
-
return __async(this, null, function* () {
|
|
1412
|
-
if (!this.userId) {
|
|
1413
|
-
return { isSetup: false };
|
|
1414
|
-
}
|
|
1415
|
-
const res = yield this.ctx.client.check2FAStatus(this.userId);
|
|
1416
|
-
return {
|
|
1417
|
-
isSetup: res.data.isSetup
|
|
1418
|
-
};
|
|
1354
|
+
const userId = this.assertUserId();
|
|
1355
|
+
yield this.ctx.client.enable2FA(userId, verificationCode);
|
|
1419
1356
|
});
|
|
1420
1357
|
}
|
|
1421
1358
|
/**
|
|
@@ -1428,302 +1365,121 @@ const _ParaCore = class _ParaCore {
|
|
|
1428
1365
|
}, this.getVerificationEmailProps()));
|
|
1429
1366
|
});
|
|
1430
1367
|
}
|
|
1431
|
-
/**
|
|
1432
|
-
* Resend a verification SMS for the current user.
|
|
1433
|
-
*/
|
|
1434
|
-
resendVerificationCodeByPhone() {
|
|
1435
|
-
return __async(this, null, function* () {
|
|
1436
|
-
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
1437
|
-
userId: this.userId
|
|
1438
|
-
});
|
|
1439
|
-
});
|
|
1440
|
-
}
|
|
1441
|
-
/**
|
|
1442
|
-
* Returns a URL for setting up a new WebAuth passkey.
|
|
1443
|
-
* @param {Object} opts the options object
|
|
1444
|
-
* @param {string} opts.authType - the auth type to use
|
|
1445
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1446
|
-
* @returns {string} the URL
|
|
1447
|
-
*/
|
|
1448
|
-
getSetUpBiometricsURL() {
|
|
1449
|
-
return __async(this, arguments, function* ({
|
|
1450
|
-
authType = "email",
|
|
1451
|
-
isForNewDevice = false
|
|
1452
|
-
} = {}) {
|
|
1453
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
1454
|
-
status: import_user_management_client.PublicKeyStatus.PENDING,
|
|
1455
|
-
type: import_user_management_client.PublicKeyType.WEB
|
|
1456
|
-
});
|
|
1457
|
-
return this.getWebAuthURLForCreate({
|
|
1458
|
-
authType,
|
|
1459
|
-
isForNewDevice,
|
|
1460
|
-
webAuthId: res.data.id,
|
|
1461
|
-
partnerId: res.data.partnerId
|
|
1462
|
-
});
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
|
-
/**
|
|
1466
|
-
* Returns a URL for setting up a new WebAuth passkey for a phone number.
|
|
1467
|
-
* @param {Object} opts the options object
|
|
1468
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1469
|
-
* @returns {string} the URL
|
|
1470
|
-
*/
|
|
1471
|
-
getSetUpBiometricsURLForPhone() {
|
|
1472
|
-
return __async(this, arguments, function* ({
|
|
1473
|
-
isForNewDevice = false
|
|
1474
|
-
} = {}) {
|
|
1475
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
1476
|
-
status: import_user_management_client.PublicKeyStatus.PENDING,
|
|
1477
|
-
type: import_user_management_client.PublicKeyType.WEB
|
|
1478
|
-
});
|
|
1479
|
-
return this.getWebAuthURLForCreate({
|
|
1480
|
-
authType: "phone",
|
|
1481
|
-
isForNewDevice,
|
|
1482
|
-
webAuthId: res.data.id,
|
|
1483
|
-
partnerId: res.data.partnerId
|
|
1484
|
-
});
|
|
1485
|
-
});
|
|
1486
|
-
}
|
|
1487
|
-
/**
|
|
1488
|
-
* Returns a URL for setting up a new password.
|
|
1489
|
-
* @param {Object} opts the options object
|
|
1490
|
-
* @param {string} opts.authType - the auth type to use
|
|
1491
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1492
|
-
* @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
|
|
1493
|
-
* @returns {string} the URL
|
|
1494
|
-
*/
|
|
1495
|
-
getSetupPasswordURL() {
|
|
1496
|
-
return __async(this, arguments, function* ({
|
|
1497
|
-
authType = "email",
|
|
1498
|
-
isForNewDevice = false,
|
|
1499
|
-
theme
|
|
1500
|
-
} = {}) {
|
|
1501
|
-
const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
1502
|
-
status: import_user_management_client.PasswordStatus.PENDING
|
|
1503
|
-
});
|
|
1504
|
-
return this.getPasswordURLForCreate({
|
|
1505
|
-
authType,
|
|
1506
|
-
isForNewDevice,
|
|
1507
|
-
passwordId: res.data.id,
|
|
1508
|
-
partnerId: res.data.partnerId,
|
|
1509
|
-
theme
|
|
1510
|
-
});
|
|
1511
|
-
});
|
|
1512
|
-
}
|
|
1513
1368
|
/**
|
|
1514
1369
|
* Checks if the current session is active.
|
|
1515
1370
|
* @returns `true` if active, `false` otherwise
|
|
1516
1371
|
*/
|
|
1517
|
-
isSessionActive() {
|
|
1518
|
-
return __async(this, null, function* () {
|
|
1519
|
-
if (this.
|
|
1520
|
-
return true;
|
|
1521
|
-
}
|
|
1522
|
-
const res = yield this.touchSession();
|
|
1523
|
-
return !!res.data.isAuthenticated;
|
|
1524
|
-
});
|
|
1525
|
-
}
|
|
1526
|
-
/**
|
|
1527
|
-
* Checks if a session is active and a wallet exists.
|
|
1528
|
-
* @returns `true` if active, `false` otherwise
|
|
1529
|
-
**/
|
|
1530
|
-
isFullyLoggedIn() {
|
|
1531
|
-
return __async(this, null, function* () {
|
|
1532
|
-
if (this.isUsingExternalWallet()) {
|
|
1533
|
-
return true;
|
|
1534
|
-
}
|
|
1535
|
-
if (this.isGuestMode) {
|
|
1536
|
-
return true;
|
|
1537
|
-
}
|
|
1538
|
-
const isSessionActive = yield this.isSessionActive();
|
|
1539
|
-
return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
|
|
1540
|
-
});
|
|
1541
|
-
}
|
|
1542
|
-
get isGuestMode() {
|
|
1543
|
-
return !this.userId && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.every(([id]) => !!this.wallets[id] && this.wallets[id].pregenIdentifierType === "GUEST_ID");
|
|
1544
|
-
}
|
|
1545
|
-
supportedAuthMethods(auth) {
|
|
1546
|
-
return __async(this, null, function* () {
|
|
1547
|
-
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
1548
|
-
const authMethods = /* @__PURE__ */ new Set();
|
|
1549
|
-
for (const type of supportedAuthMethods) {
|
|
1550
|
-
switch (type) {
|
|
1551
|
-
case "PASSWORD":
|
|
1552
|
-
authMethods.add(import_user_management_client.AuthMethod.PASSWORD);
|
|
1553
|
-
break;
|
|
1554
|
-
case "BIOMETRIC":
|
|
1555
|
-
authMethods.add(import_user_management_client.AuthMethod.PASSKEY);
|
|
1556
|
-
break;
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
return authMethods;
|
|
1560
|
-
});
|
|
1561
|
-
}
|
|
1562
|
-
/**
|
|
1563
|
-
* Get hints associated with the users stored biometrics.
|
|
1564
|
-
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
1565
|
-
*/
|
|
1566
|
-
getUserBiometricLocationHints() {
|
|
1567
|
-
return __async(this, null, function* () {
|
|
1568
|
-
var _a;
|
|
1569
|
-
if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId && !this.isExternalWalletAuth) {
|
|
1570
|
-
throw new Error(
|
|
1571
|
-
"one of email, phone, farcaster username, telegram user id or external wallet with Para auth are required to get biometric location hints"
|
|
1572
|
-
);
|
|
1573
|
-
}
|
|
1574
|
-
return yield this.ctx.client.getBiometricLocationHints({
|
|
1575
|
-
email: this.email,
|
|
1576
|
-
phone: this.phone,
|
|
1577
|
-
countryCode: this.countryCode,
|
|
1578
|
-
farcasterUsername: this.farcasterUsername,
|
|
1579
|
-
telegramUserId: this.telegramUserId,
|
|
1580
|
-
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
1581
|
-
externalWalletAddress: (_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id
|
|
1582
|
-
});
|
|
1583
|
-
});
|
|
1584
|
-
}
|
|
1585
|
-
setAuth(auth) {
|
|
1586
|
-
return __async(this, null, function* () {
|
|
1587
|
-
const authInfo = (0, import_user_management_client.extractAuthInfo)(auth);
|
|
1588
|
-
if (!authInfo) {
|
|
1589
|
-
return void 0;
|
|
1590
|
-
}
|
|
1591
|
-
switch (authInfo.authType) {
|
|
1592
|
-
case "email":
|
|
1593
|
-
yield this.setEmail(authInfo.identifier);
|
|
1594
|
-
break;
|
|
1595
|
-
case "phone":
|
|
1596
|
-
yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
|
|
1597
|
-
break;
|
|
1598
|
-
case "farcaster":
|
|
1599
|
-
yield this.setFarcasterUsername(authInfo.identifier);
|
|
1600
|
-
break;
|
|
1601
|
-
case "telegram":
|
|
1602
|
-
yield this.setTelegramUserId(authInfo.identifier);
|
|
1603
|
-
break;
|
|
1604
|
-
}
|
|
1605
|
-
return authInfo;
|
|
1606
|
-
});
|
|
1607
|
-
}
|
|
1608
|
-
/**
|
|
1609
|
-
* Initiates a login.
|
|
1610
|
-
* @param {Object} opts the options object
|
|
1611
|
-
* @param {String} opts.email - the email to login with
|
|
1612
|
-
* @param {boolean} opts.useShortURL - whether to shorten the link
|
|
1613
|
-
* @returns - the WebAuth URL for logging in
|
|
1614
|
-
**/
|
|
1615
|
-
initiateUserLogin(_e) {
|
|
1616
|
-
return __async(this, null, function* () {
|
|
1617
|
-
var _f = _e, { useShortUrl = false } = _f, auth = __objRest(_f, ["useShortUrl"]);
|
|
1618
|
-
const authInfo = yield this.setAuth(auth);
|
|
1619
|
-
if (!authInfo) {
|
|
1620
|
-
return;
|
|
1621
|
-
}
|
|
1622
|
-
const res = yield this.touchSession(true);
|
|
1623
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1624
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1625
|
-
}
|
|
1626
|
-
const webAuthLoginURL = yield this.getWebAuthURLForLogin({
|
|
1627
|
-
authType: authInfo.authType,
|
|
1628
|
-
sessionId: res.data.sessionId,
|
|
1629
|
-
partnerId: res.data.partnerId,
|
|
1630
|
-
loginEncryptionPublicKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair)
|
|
1631
|
-
});
|
|
1632
|
-
if (!useShortUrl) {
|
|
1633
|
-
return webAuthLoginURL;
|
|
1372
|
+
isSessionActive() {
|
|
1373
|
+
return __async(this, null, function* () {
|
|
1374
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1375
|
+
return true;
|
|
1634
1376
|
}
|
|
1635
|
-
|
|
1377
|
+
const { isAuthenticated } = yield this.touchSession();
|
|
1378
|
+
return !!isAuthenticated;
|
|
1636
1379
|
});
|
|
1637
1380
|
}
|
|
1638
1381
|
/**
|
|
1639
|
-
*
|
|
1640
|
-
* @
|
|
1641
|
-
* @returns - a set of supported auth methods for the user
|
|
1382
|
+
* Checks if a session is active and a wallet exists.
|
|
1383
|
+
* @returns `true` if active, `false` otherwise
|
|
1642
1384
|
**/
|
|
1643
|
-
|
|
1385
|
+
isFullyLoggedIn() {
|
|
1644
1386
|
return __async(this, null, function* () {
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
return;
|
|
1387
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
1388
|
+
return true;
|
|
1648
1389
|
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1390
|
+
if (this.isGuestMode) {
|
|
1391
|
+
return true;
|
|
1652
1392
|
}
|
|
1653
|
-
|
|
1393
|
+
const isSessionActive = yield this.isSessionActive();
|
|
1394
|
+
return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
|
|
1654
1395
|
});
|
|
1655
1396
|
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
* @param opts.useShortURL - whether to shorten the link
|
|
1662
|
-
* @returns - the WebAuth URL for logging in
|
|
1663
|
-
**/
|
|
1664
|
-
initiateUserLoginForPhone(_g) {
|
|
1665
|
-
return __async(this, null, function* () {
|
|
1666
|
-
var _h = _g, {
|
|
1667
|
-
useShortUrl = false
|
|
1668
|
-
} = _h, auth = __objRest(_h, [
|
|
1669
|
-
"useShortUrl"
|
|
1670
|
-
]);
|
|
1671
|
-
yield this.setAuth(auth);
|
|
1672
|
-
const res = yield this.touchSession(true);
|
|
1673
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1674
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1397
|
+
get isGuestMode() {
|
|
1398
|
+
return __privateGet(this, _ParaCore_instances, guestWalletIdsArray_get).length > 0 && Object.values(this.wallets).every(
|
|
1399
|
+
({ userId, partnerId }) => {
|
|
1400
|
+
var _a;
|
|
1401
|
+
return partnerId === ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) && (!userId || userId !== this.userId);
|
|
1675
1402
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
});
|
|
1681
|
-
|
|
1682
|
-
|
|
1403
|
+
);
|
|
1404
|
+
}
|
|
1405
|
+
supportedAuthMethods(auth) {
|
|
1406
|
+
return __async(this, null, function* () {
|
|
1407
|
+
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
1408
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
1409
|
+
for (const type of supportedAuthMethods) {
|
|
1410
|
+
switch (type) {
|
|
1411
|
+
case "PASSWORD":
|
|
1412
|
+
authMethods.add(import_user_management_client.AuthMethod.PASSWORD);
|
|
1413
|
+
break;
|
|
1414
|
+
case "BIOMETRIC":
|
|
1415
|
+
authMethods.add(import_user_management_client.AuthMethod.PASSKEY);
|
|
1416
|
+
break;
|
|
1417
|
+
}
|
|
1683
1418
|
}
|
|
1684
|
-
return
|
|
1419
|
+
return authMethods;
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* Get hints associated with the users stored biometrics.
|
|
1424
|
+
* @deprecated
|
|
1425
|
+
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
1426
|
+
*/
|
|
1427
|
+
getUserBiometricLocationHints() {
|
|
1428
|
+
return __async(this, null, function* () {
|
|
1429
|
+
const { auth } = this.assertIsAuthSet();
|
|
1430
|
+
return yield this.ctx.client.getBiometricLocationHints(auth);
|
|
1685
1431
|
});
|
|
1686
1432
|
}
|
|
1687
1433
|
/**
|
|
1688
1434
|
* Waits for the session to be active.
|
|
1689
1435
|
**/
|
|
1690
|
-
|
|
1691
|
-
return __async(this, arguments, function* ({
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
yield
|
|
1700
|
-
if (
|
|
1701
|
-
this.
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1436
|
+
waitForSignup(_0) {
|
|
1437
|
+
return __async(this, arguments, function* ({
|
|
1438
|
+
isCanceled = () => false,
|
|
1439
|
+
onCancel,
|
|
1440
|
+
onPoll
|
|
1441
|
+
}) {
|
|
1442
|
+
const startedAt = Date.now();
|
|
1443
|
+
return new Promise((resolve, reject) => {
|
|
1444
|
+
(() => __async(this, null, function* () {
|
|
1445
|
+
yield this.touchSession();
|
|
1446
|
+
if (!this.isExternalWalletAuth) {
|
|
1447
|
+
this.externalWallets = {};
|
|
1448
|
+
}
|
|
1449
|
+
while (true) {
|
|
1450
|
+
try {
|
|
1451
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1452
|
+
onCancel == null ? void 0 : onCancel();
|
|
1453
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.ACCOUNT_CREATION_EVENT, false, "failed to sign up user");
|
|
1454
|
+
return reject("canceled");
|
|
1455
|
+
}
|
|
1456
|
+
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1457
|
+
if (yield this.isSessionActive()) {
|
|
1458
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
1459
|
+
return resolve(true);
|
|
1460
|
+
}
|
|
1461
|
+
onPoll == null ? void 0 : onPoll();
|
|
1462
|
+
} catch (err) {
|
|
1463
|
+
console.error(err);
|
|
1464
|
+
onPoll == null ? void 0 : onPoll();
|
|
1708
1465
|
}
|
|
1709
1466
|
}
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
return false;
|
|
1467
|
+
}))();
|
|
1468
|
+
});
|
|
1715
1469
|
});
|
|
1716
1470
|
}
|
|
1717
|
-
|
|
1471
|
+
waitForWalletCreation() {
|
|
1718
1472
|
return __async(this, arguments, function* ({
|
|
1719
|
-
|
|
1473
|
+
isCanceled = () => false,
|
|
1474
|
+
onCancel
|
|
1720
1475
|
} = {}) {
|
|
1721
|
-
yield this.
|
|
1476
|
+
yield this.waitForSignup({ isCanceled, onCancel });
|
|
1477
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1722
1478
|
const pregenWallets = yield this.getPregenWallets();
|
|
1723
1479
|
let recoverySecret, walletIds = {};
|
|
1724
1480
|
if (pregenWallets.length > 0) {
|
|
1725
1481
|
recoverySecret = yield this.claimPregenWallets();
|
|
1726
|
-
walletIds =
|
|
1482
|
+
walletIds = supportedWalletTypes.reduce((acc, { type }) => {
|
|
1727
1483
|
var _a;
|
|
1728
1484
|
return __spreadProps(__spreadValues({}, acc), {
|
|
1729
1485
|
[type]: [(_a = pregenWallets.find((w) => !!import_utils2.WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
@@ -1743,14 +1499,12 @@ const _ParaCore = class _ParaCore {
|
|
|
1743
1499
|
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
1744
1500
|
* @return {string} the Farcaster connect URI
|
|
1745
1501
|
*/
|
|
1746
|
-
|
|
1502
|
+
getFarcasterConnectUri() {
|
|
1747
1503
|
return __async(this, null, function* () {
|
|
1748
|
-
yield this.logout();
|
|
1749
|
-
yield this.touchSession(true);
|
|
1750
1504
|
const {
|
|
1751
|
-
data: { connect_uri }
|
|
1505
|
+
data: { connect_uri: connectUri }
|
|
1752
1506
|
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
1753
|
-
return
|
|
1507
|
+
return connectUri;
|
|
1754
1508
|
});
|
|
1755
1509
|
}
|
|
1756
1510
|
/**
|
|
@@ -1758,40 +1512,60 @@ const _ParaCore = class _ParaCore {
|
|
|
1758
1512
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
1759
1513
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
1760
1514
|
*/
|
|
1761
|
-
|
|
1515
|
+
verifyFarcaster(_g) {
|
|
1762
1516
|
return __async(this, null, function* () {
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1517
|
+
var _h = _g, {
|
|
1518
|
+
isCanceled = () => false,
|
|
1519
|
+
onConnectUri,
|
|
1520
|
+
onCancel,
|
|
1521
|
+
onPoll
|
|
1522
|
+
} = _h, urlOptions = __objRest(_h, [
|
|
1523
|
+
"isCanceled",
|
|
1524
|
+
"onConnectUri",
|
|
1525
|
+
"onCancel",
|
|
1526
|
+
"onPoll"
|
|
1527
|
+
]);
|
|
1528
|
+
if (onConnectUri) {
|
|
1529
|
+
const connectUri = yield this.getFarcasterConnectUri();
|
|
1530
|
+
onConnectUri(connectUri);
|
|
1531
|
+
}
|
|
1532
|
+
return new Promise((resolve, reject) => {
|
|
1533
|
+
(() => __async(this, null, function* () {
|
|
1534
|
+
const startedAt = Date.now();
|
|
1535
|
+
while (true) {
|
|
1536
|
+
try {
|
|
1537
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1538
|
+
onCancel == null ? void 0 : onCancel();
|
|
1539
|
+
return reject("canceled");
|
|
1540
|
+
}
|
|
1541
|
+
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1542
|
+
const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
|
|
1543
|
+
if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
|
|
1544
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1545
|
+
return resolve(authState);
|
|
1546
|
+
}
|
|
1547
|
+
onPoll == null ? void 0 : onPoll();
|
|
1548
|
+
} catch (e) {
|
|
1549
|
+
console.error(e);
|
|
1550
|
+
return reject(e);
|
|
1551
|
+
}
|
|
1777
1552
|
}
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
this.isAwaitingFarcaster = false;
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1553
|
+
}))();
|
|
1554
|
+
});
|
|
1783
1555
|
});
|
|
1784
1556
|
}
|
|
1785
1557
|
/**
|
|
1786
1558
|
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
1787
1559
|
*
|
|
1788
1560
|
* @param {Object} opts the options object
|
|
1789
|
-
* @param {
|
|
1561
|
+
* @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
|
|
1790
1562
|
* @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
|
|
1791
1563
|
* @returns {string} the URL for the user to log in with OAuth.
|
|
1792
1564
|
*/
|
|
1793
|
-
|
|
1794
|
-
return __async(this,
|
|
1565
|
+
getOAuthUrl(_i) {
|
|
1566
|
+
return __async(this, null, function* () {
|
|
1567
|
+
var _j = _i, { method, deeplinkUrl } = _j, params = __objRest(_j, ["method", "deeplinkUrl"]);
|
|
1568
|
+
var _a;
|
|
1795
1569
|
if (deeplinkUrl) {
|
|
1796
1570
|
try {
|
|
1797
1571
|
new URL(deeplinkUrl);
|
|
@@ -1799,14 +1573,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1799
1573
|
throw new Error("Invalid deeplink URL");
|
|
1800
1574
|
}
|
|
1801
1575
|
}
|
|
1802
|
-
yield this.
|
|
1803
|
-
const res = yield this.touchSession(true);
|
|
1576
|
+
const sessionLookupId = (_a = params.sessionLookupId) != null ? _a : yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
1804
1577
|
return (0, import_utils2.constructUrl)({
|
|
1805
|
-
base:
|
|
1806
|
-
path: `/auth/${method
|
|
1578
|
+
base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
|
|
1579
|
+
path: `/auth/${method}`,
|
|
1807
1580
|
params: {
|
|
1808
1581
|
apiKey: this.ctx.apiKey,
|
|
1809
|
-
sessionLookupId
|
|
1582
|
+
sessionLookupId,
|
|
1810
1583
|
deeplinkUrl
|
|
1811
1584
|
}
|
|
1812
1585
|
});
|
|
@@ -1820,37 +1593,54 @@ const _ParaCore = class _ParaCore {
|
|
|
1820
1593
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1821
1594
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1822
1595
|
*/
|
|
1823
|
-
|
|
1824
|
-
return __async(this,
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1596
|
+
verifyOAuth(_k) {
|
|
1597
|
+
return __async(this, null, function* () {
|
|
1598
|
+
var _l = _k, {
|
|
1599
|
+
method,
|
|
1600
|
+
deeplinkUrl,
|
|
1601
|
+
isCanceled = () => false,
|
|
1602
|
+
onCancel,
|
|
1603
|
+
onPoll,
|
|
1604
|
+
onOAuthUrl
|
|
1605
|
+
} = _l, urlOptions = __objRest(_l, [
|
|
1606
|
+
"method",
|
|
1607
|
+
"deeplinkUrl",
|
|
1608
|
+
"isCanceled",
|
|
1609
|
+
"onCancel",
|
|
1610
|
+
"onPoll",
|
|
1611
|
+
"onOAuthUrl"
|
|
1612
|
+
]);
|
|
1613
|
+
let sessionLookupId;
|
|
1614
|
+
if (onOAuthUrl) {
|
|
1615
|
+
sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
1616
|
+
const oAuthUrl = yield this.getOAuthUrl({ method, deeplinkUrl, sessionLookupId });
|
|
1617
|
+
onOAuthUrl(oAuthUrl);
|
|
1618
|
+
} else {
|
|
1619
|
+
({ sessionLookupId } = yield this.touchSession());
|
|
1620
|
+
}
|
|
1621
|
+
const startedAt = Date.now();
|
|
1622
|
+
return new Promise((resolve, reject) => {
|
|
1623
|
+
(() => __async(this, null, function* () {
|
|
1624
|
+
while (true) {
|
|
1625
|
+
try {
|
|
1626
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1627
|
+
onCancel == null ? void 0 : onCancel();
|
|
1628
|
+
return reject("canceled");
|
|
1629
|
+
}
|
|
1630
|
+
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
1631
|
+
const serverAuthState = yield this.ctx.client.verifyOAuth();
|
|
1632
|
+
if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
|
|
1633
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1634
|
+
return resolve(authState);
|
|
1838
1635
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
return {
|
|
1844
|
-
userExists,
|
|
1845
|
-
email
|
|
1846
|
-
};
|
|
1636
|
+
onPoll == null ? void 0 : onPoll();
|
|
1637
|
+
} catch (err) {
|
|
1638
|
+
console.error(err);
|
|
1639
|
+
onPoll == null ? void 0 : onPoll();
|
|
1847
1640
|
}
|
|
1848
1641
|
}
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
return { userExists: false };
|
|
1642
|
+
}))();
|
|
1643
|
+
});
|
|
1854
1644
|
});
|
|
1855
1645
|
}
|
|
1856
1646
|
/**
|
|
@@ -1861,60 +1651,61 @@ const _ParaCore = class _ParaCore {
|
|
|
1861
1651
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
1862
1652
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
1863
1653
|
**/
|
|
1864
|
-
|
|
1654
|
+
waitForLogin() {
|
|
1865
1655
|
return __async(this, arguments, function* ({
|
|
1866
|
-
|
|
1656
|
+
isCanceled = () => false,
|
|
1657
|
+
onCancel,
|
|
1658
|
+
onPoll,
|
|
1867
1659
|
skipSessionRefresh = false
|
|
1868
1660
|
} = {}) {
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
this
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
try {
|
|
1876
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
1877
|
-
if (!(yield this.isSessionActive())) {
|
|
1878
|
-
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
1879
|
-
const resp2 = { isComplete: false, isError: true };
|
|
1880
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
1881
|
-
return resp2;
|
|
1882
|
-
}
|
|
1883
|
-
continue;
|
|
1661
|
+
const startedAt = Date.now();
|
|
1662
|
+
return new Promise((resolve, reject) => {
|
|
1663
|
+
(() => __async(this, null, function* () {
|
|
1664
|
+
var _a;
|
|
1665
|
+
if (!this.isExternalWalletAuth) {
|
|
1666
|
+
this.externalWallets = {};
|
|
1884
1667
|
}
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1668
|
+
while (true) {
|
|
1669
|
+
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
1670
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
|
|
1671
|
+
onCancel == null ? void 0 : onCancel();
|
|
1672
|
+
return reject("canceled");
|
|
1673
|
+
}
|
|
1674
|
+
yield new Promise((resolve2) => setTimeout(resolve2, constants.POLLING_INTERVAL_MS));
|
|
1675
|
+
try {
|
|
1676
|
+
let session = yield this.touchSession();
|
|
1677
|
+
if (!session.isAuthenticated) {
|
|
1678
|
+
onPoll == null ? void 0 : onPoll();
|
|
1894
1679
|
continue;
|
|
1895
1680
|
}
|
|
1681
|
+
session = yield this.userSetupAfterLogin();
|
|
1682
|
+
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
1683
|
+
if (!needsWallet) {
|
|
1684
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
1685
|
+
onPoll == null ? void 0 : onPoll();
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
1690
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
1691
|
+
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
1692
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
1693
|
+
yield this.claimPregenWallets();
|
|
1694
|
+
const resp = {
|
|
1695
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
1696
|
+
partnerId: session.partnerId
|
|
1697
|
+
};
|
|
1698
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp);
|
|
1699
|
+
return resolve(resp);
|
|
1700
|
+
}
|
|
1701
|
+
onPoll == null ? void 0 : onPoll();
|
|
1702
|
+
} catch (err) {
|
|
1703
|
+
console.error(err);
|
|
1704
|
+
onPoll == null ? void 0 : onPoll();
|
|
1896
1705
|
}
|
|
1897
1706
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
1901
|
-
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
1902
|
-
yield this.claimPregenWallets();
|
|
1903
|
-
const resp2 = {
|
|
1904
|
-
isComplete: true,
|
|
1905
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
1906
|
-
partnerId: postLoginData.data.partnerId
|
|
1907
|
-
};
|
|
1908
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp2);
|
|
1909
|
-
return resp2;
|
|
1910
|
-
}
|
|
1911
|
-
} catch (err) {
|
|
1912
|
-
console.error(err);
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
const resp = { isComplete: false };
|
|
1916
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGIN_EVENT, resp, "exitted login without setting up user");
|
|
1917
|
-
return resp;
|
|
1707
|
+
}))();
|
|
1708
|
+
});
|
|
1918
1709
|
});
|
|
1919
1710
|
}
|
|
1920
1711
|
/**
|
|
@@ -1926,14 +1717,15 @@ const _ParaCore = class _ParaCore {
|
|
|
1926
1717
|
* @returns a URL for the user to reauthenticate.
|
|
1927
1718
|
**/
|
|
1928
1719
|
refreshSession() {
|
|
1929
|
-
return __async(this, arguments, function* ({
|
|
1930
|
-
|
|
1720
|
+
return __async(this, arguments, function* ({
|
|
1721
|
+
shouldOpenPopup = false
|
|
1722
|
+
} = {}) {
|
|
1723
|
+
const { sessionId } = yield this.touchSession(true);
|
|
1931
1724
|
if (!this.loginEncryptionKeyPair) {
|
|
1932
1725
|
yield this.setLoginEncryptionKeyPair();
|
|
1933
1726
|
}
|
|
1934
|
-
const link = yield this.
|
|
1935
|
-
sessionId
|
|
1936
|
-
loginEncryptionPublicKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair)
|
|
1727
|
+
const link = yield this.getLoginUrl({
|
|
1728
|
+
sessionId
|
|
1937
1729
|
});
|
|
1938
1730
|
if (shouldOpenPopup) {
|
|
1939
1731
|
this.platformUtils.openPopup(link);
|
|
@@ -1947,13 +1739,13 @@ const _ParaCore = class _ParaCore {
|
|
|
1947
1739
|
**/
|
|
1948
1740
|
userSetupAfterLogin() {
|
|
1949
1741
|
return __async(this, null, function* () {
|
|
1950
|
-
const
|
|
1951
|
-
yield this.setUserId(
|
|
1952
|
-
if (
|
|
1953
|
-
yield this.setCurrentWalletIds(
|
|
1954
|
-
sessionLookupId: this.isPortal() ?
|
|
1742
|
+
const session = yield this.touchSession();
|
|
1743
|
+
yield this.setUserId(session.userId);
|
|
1744
|
+
if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
|
|
1745
|
+
yield this.setCurrentWalletIds(session.currentWalletIds, {
|
|
1746
|
+
sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
|
|
1955
1747
|
});
|
|
1956
|
-
return
|
|
1748
|
+
return session;
|
|
1957
1749
|
});
|
|
1958
1750
|
}
|
|
1959
1751
|
/**
|
|
@@ -1964,8 +1756,8 @@ const _ParaCore = class _ParaCore {
|
|
|
1964
1756
|
**/
|
|
1965
1757
|
getTransmissionKeyShares() {
|
|
1966
1758
|
return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
|
|
1967
|
-
const
|
|
1968
|
-
const sessionLookupId = isForNewDevice ? `${
|
|
1759
|
+
const session = yield this.touchSession();
|
|
1760
|
+
const sessionLookupId = isForNewDevice ? `${session.sessionLookupId}-new-device` : session.sessionLookupId;
|
|
1969
1761
|
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
1970
1762
|
});
|
|
1971
1763
|
}
|
|
@@ -2092,7 +1884,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2092
1884
|
*
|
|
2093
1885
|
* @param {Object} [opts] the options object.
|
|
2094
1886
|
* @param {boolean} [opts.skipDistribute] if `true`, the wallets' recovery share will not be distributed.
|
|
2095
|
-
* @param {
|
|
1887
|
+
* @param {TWalletType[]} [opts.types] the types of wallets to create.
|
|
2096
1888
|
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
2097
1889
|
**/
|
|
2098
1890
|
createWalletPerType() {
|
|
@@ -2163,7 +1955,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2163
1955
|
/**
|
|
2164
1956
|
* Creates a new wallet.
|
|
2165
1957
|
* @param {Object} opts the options object.
|
|
2166
|
-
* @param {
|
|
1958
|
+
* @param {TWalletType} opts.type the type of wallet to create.
|
|
2167
1959
|
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
2168
1960
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2169
1961
|
**/
|
|
@@ -2174,14 +1966,15 @@ const _ParaCore = class _ParaCore {
|
|
|
2174
1966
|
} = {}) {
|
|
2175
1967
|
var _a, _b;
|
|
2176
1968
|
this.requireApiKey();
|
|
1969
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2177
1970
|
const walletType = yield this.assertIsValidWalletType(
|
|
2178
|
-
_type != null ? _type : (_a =
|
|
1971
|
+
_type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
2179
1972
|
);
|
|
2180
1973
|
let signer;
|
|
2181
1974
|
let wallet;
|
|
2182
1975
|
let keygenRes;
|
|
2183
1976
|
switch (walletType) {
|
|
2184
|
-
case
|
|
1977
|
+
case "SOLANA": {
|
|
2185
1978
|
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
2186
1979
|
this.ctx,
|
|
2187
1980
|
this.userId,
|
|
@@ -2207,7 +2000,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2207
2000
|
this.wallets[walletId] = {
|
|
2208
2001
|
id: walletId,
|
|
2209
2002
|
signer,
|
|
2210
|
-
scheme: walletType ===
|
|
2003
|
+
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
2211
2004
|
type: walletType
|
|
2212
2005
|
};
|
|
2213
2006
|
wallet = this.wallets[walletId];
|
|
@@ -2224,7 +2017,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2224
2017
|
});
|
|
2225
2018
|
}
|
|
2226
2019
|
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
2227
|
-
[walletType]: [...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId]
|
|
2020
|
+
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
2228
2021
|
}));
|
|
2229
2022
|
const walletNoSigner = __spreadValues({}, wallet);
|
|
2230
2023
|
delete walletNoSigner.signer;
|
|
@@ -2235,15 +2028,6 @@ const _ParaCore = class _ParaCore {
|
|
|
2235
2028
|
return [wallet, recoveryShare];
|
|
2236
2029
|
});
|
|
2237
2030
|
}
|
|
2238
|
-
/**
|
|
2239
|
-
* Creates a new pregenerated wallet.
|
|
2240
|
-
*
|
|
2241
|
-
* @param {Object} opts the options object.
|
|
2242
|
-
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
2243
|
-
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
2244
|
-
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
2245
|
-
* @returns {Wallet} the created wallet.
|
|
2246
|
-
**/
|
|
2247
2031
|
createPregenWallet(opts) {
|
|
2248
2032
|
return __async(this, null, function* () {
|
|
2249
2033
|
return yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, opts);
|
|
@@ -2256,18 +2040,17 @@ const _ParaCore = class _ParaCore {
|
|
|
2256
2040
|
* @param {Object} opts the options object.
|
|
2257
2041
|
* @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
|
|
2258
2042
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
2259
|
-
* @param {
|
|
2043
|
+
* @param {TWalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
2260
2044
|
* @returns {Wallet[]} an array containing the created wallets.
|
|
2261
2045
|
**/
|
|
2262
2046
|
createPregenWalletPerType(_0) {
|
|
2263
2047
|
return __async(this, arguments, function* ({
|
|
2264
2048
|
types,
|
|
2265
|
-
|
|
2266
|
-
pregenIdentifierType = "EMAIL"
|
|
2049
|
+
pregenId
|
|
2267
2050
|
}) {
|
|
2268
2051
|
const wallets = [];
|
|
2269
2052
|
for (const type of yield this.getTypesToCreate(types)) {
|
|
2270
|
-
const wallet = yield
|
|
2053
|
+
const wallet = yield this.createPregenWallet({ type, pregenId });
|
|
2271
2054
|
wallets.push(wallet);
|
|
2272
2055
|
}
|
|
2273
2056
|
return wallets;
|
|
@@ -2275,7 +2058,6 @@ const _ParaCore = class _ParaCore {
|
|
|
2275
2058
|
}
|
|
2276
2059
|
/**
|
|
2277
2060
|
* Claims a pregenerated wallet.
|
|
2278
|
-
*
|
|
2279
2061
|
* @param {Object} opts the options object.
|
|
2280
2062
|
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
2281
2063
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
@@ -2283,12 +2065,11 @@ const _ParaCore = class _ParaCore {
|
|
|
2283
2065
|
**/
|
|
2284
2066
|
claimPregenWallets() {
|
|
2285
2067
|
return __async(this, arguments, function* ({
|
|
2286
|
-
|
|
2287
|
-
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
2068
|
+
pregenId
|
|
2288
2069
|
} = {}) {
|
|
2289
2070
|
var _a;
|
|
2290
2071
|
this.requireApiKey();
|
|
2291
|
-
const pregenWallets =
|
|
2072
|
+
const pregenWallets = pregenId ? yield this.getPregenWallets({ pregenId }) : yield this.getPregenWallets();
|
|
2292
2073
|
if (pregenWallets.length === 0) {
|
|
2293
2074
|
return void 0;
|
|
2294
2075
|
}
|
|
@@ -2306,7 +2087,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2306
2087
|
for (const walletId of walletIds) {
|
|
2307
2088
|
const wallet = this.wallets[walletId];
|
|
2308
2089
|
let refreshedShare;
|
|
2309
|
-
if (wallet.scheme ===
|
|
2090
|
+
if (wallet.scheme === "ED25519") {
|
|
2310
2091
|
const distributeRes = yield (0, import_shareDistribution.distributeNewShare)({
|
|
2311
2092
|
ctx: this.ctx,
|
|
2312
2093
|
userId: this.userId,
|
|
@@ -2357,10 +2138,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2357
2138
|
updatePregenWalletIdentifier(_0) {
|
|
2358
2139
|
return __async(this, arguments, function* ({
|
|
2359
2140
|
walletId,
|
|
2360
|
-
|
|
2361
|
-
newPregenIdentifierType
|
|
2141
|
+
newPregenId
|
|
2362
2142
|
}) {
|
|
2363
2143
|
this.requireApiKey();
|
|
2144
|
+
const [newPregenIdentifierType, newPregenIdentifier] = (0, import_user_management_client.toPregenTypeAndId)(newPregenId);
|
|
2364
2145
|
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
2365
2146
|
pregenIdentifier: newPregenIdentifier,
|
|
2366
2147
|
pregenIdentifierType: newPregenIdentifierType
|
|
@@ -2382,13 +2163,13 @@ const _ParaCore = class _ParaCore {
|
|
|
2382
2163
|
* @returns {boolean} whether the pregen wallet exists
|
|
2383
2164
|
**/
|
|
2384
2165
|
hasPregenWallet(_0) {
|
|
2385
|
-
return __async(this, arguments, function* ({
|
|
2386
|
-
pregenIdentifier,
|
|
2387
|
-
pregenIdentifierType
|
|
2388
|
-
}) {
|
|
2166
|
+
return __async(this, arguments, function* ({ pregenId }) {
|
|
2389
2167
|
this.requireApiKey();
|
|
2390
|
-
const
|
|
2391
|
-
const
|
|
2168
|
+
const [pregenIdentifierType, pregenIdentifier] = (0, import_user_management_client.toPregenTypeAndId)(pregenId);
|
|
2169
|
+
const wallets = yield this.getPregenWallets({ pregenId });
|
|
2170
|
+
const wallet = wallets.find(
|
|
2171
|
+
(w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType
|
|
2172
|
+
);
|
|
2392
2173
|
if (!wallet) {
|
|
2393
2174
|
return false;
|
|
2394
2175
|
}
|
|
@@ -2403,13 +2184,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2403
2184
|
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
2404
2185
|
**/
|
|
2405
2186
|
getPregenWallets() {
|
|
2406
|
-
return __async(this, arguments, function* ({
|
|
2407
|
-
pregenIdentifier,
|
|
2408
|
-
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
2409
|
-
} = {}) {
|
|
2187
|
+
return __async(this, arguments, function* ({ pregenId } = {}) {
|
|
2410
2188
|
this.requireApiKey();
|
|
2411
2189
|
const res = yield this.ctx.client.getPregenWallets(
|
|
2412
|
-
|
|
2190
|
+
pregenId ? (0, import_user_management_client.toPregenIds)(pregenId) : this.pregenIds,
|
|
2413
2191
|
this.isPortal(),
|
|
2414
2192
|
this.userId
|
|
2415
2193
|
);
|
|
@@ -2417,21 +2195,37 @@ const _ParaCore = class _ParaCore {
|
|
|
2417
2195
|
});
|
|
2418
2196
|
}
|
|
2419
2197
|
createGuestWallets() {
|
|
2420
|
-
return __async(this,
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
wallets
|
|
2429
|
-
(0, import_utils2.
|
|
2430
|
-
|
|
2431
|
-
|
|
2198
|
+
return __async(this, null, function* () {
|
|
2199
|
+
let error;
|
|
2200
|
+
if (__privateGet(this, _isCreateGuestWalletsPending)) {
|
|
2201
|
+
error = new Error("Guest wallets creation already in progress");
|
|
2202
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
|
|
2203
|
+
throw error;
|
|
2204
|
+
}
|
|
2205
|
+
if (this.isGuestMode) {
|
|
2206
|
+
error = new Error("Guest wallets already created");
|
|
2207
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
|
|
2208
|
+
throw error;
|
|
2209
|
+
}
|
|
2210
|
+
try {
|
|
2211
|
+
__privateSet(this, _isCreateGuestWalletsPending, true);
|
|
2212
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2213
|
+
const wallets = [];
|
|
2214
|
+
const guestId = (0, import_utils2.newUuid)();
|
|
2215
|
+
for (const type of yield this.getTypesToCreate(
|
|
2216
|
+
supportedWalletTypes.filter(({ optional }) => !optional).map(({ type: type2 }) => type2)
|
|
2217
|
+
)) {
|
|
2218
|
+
const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenId: { guestId } });
|
|
2219
|
+
wallets.push(wallet);
|
|
2220
|
+
}
|
|
2221
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, wallets);
|
|
2222
|
+
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2223
|
+
return wallets;
|
|
2224
|
+
} catch (e) {
|
|
2225
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error == null ? void 0 : error.message);
|
|
2226
|
+
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2227
|
+
throw error;
|
|
2432
2228
|
}
|
|
2433
|
-
yield this.setCurrentWalletIds(currentWalletIds);
|
|
2434
|
-
return wallets;
|
|
2435
2229
|
});
|
|
2436
2230
|
}
|
|
2437
2231
|
encodeWalletBase64(wallet) {
|
|
@@ -2469,9 +2263,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2469
2263
|
}
|
|
2470
2264
|
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
2471
2265
|
return __async(this, null, function* () {
|
|
2472
|
-
const res = yield this.touchSession();
|
|
2473
2266
|
return this.constructPortalUrl("txReview", {
|
|
2474
|
-
partnerId: res.data.partnerId,
|
|
2475
2267
|
pathId: transactionId,
|
|
2476
2268
|
params: {
|
|
2477
2269
|
email: this.email,
|
|
@@ -2480,21 +2272,20 @@ const _ParaCore = class _ParaCore {
|
|
|
2480
2272
|
});
|
|
2481
2273
|
});
|
|
2482
2274
|
}
|
|
2483
|
-
getOnRampTransactionUrl(
|
|
2275
|
+
getOnRampTransactionUrl(_m) {
|
|
2484
2276
|
return __async(this, null, function* () {
|
|
2485
|
-
var
|
|
2277
|
+
var _n = _m, {
|
|
2486
2278
|
purchaseId,
|
|
2487
2279
|
providerKey
|
|
2488
|
-
} =
|
|
2280
|
+
} = _n, walletParams = __objRest(_n, [
|
|
2489
2281
|
"purchaseId",
|
|
2490
2282
|
"providerKey"
|
|
2491
2283
|
]);
|
|
2492
|
-
const
|
|
2284
|
+
const { sessionId } = yield this.touchSession();
|
|
2493
2285
|
const [key, identifier] = (0, import_user_management_client.extractWalletRef)(walletParams);
|
|
2494
2286
|
return this.constructPortalUrl("onRamp", {
|
|
2495
|
-
partnerId: res.data.partnerId,
|
|
2496
2287
|
pathId: purchaseId,
|
|
2497
|
-
sessionId
|
|
2288
|
+
sessionId,
|
|
2498
2289
|
params: {
|
|
2499
2290
|
[key]: identifier,
|
|
2500
2291
|
providerKey,
|
|
@@ -2519,7 +2310,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2519
2310
|
walletId,
|
|
2520
2311
|
messageBase64,
|
|
2521
2312
|
timeoutMs = 3e4,
|
|
2522
|
-
cosmosSignDocBase64
|
|
2313
|
+
cosmosSignDocBase64,
|
|
2314
|
+
isCanceled = () => false,
|
|
2315
|
+
onCancel,
|
|
2316
|
+
onPoll
|
|
2523
2317
|
}) {
|
|
2524
2318
|
this.assertIsValidWalletId(walletId);
|
|
2525
2319
|
const wallet = this.wallets[walletId];
|
|
@@ -2538,11 +2332,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2538
2332
|
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2539
2333
|
return signRes;
|
|
2540
2334
|
}
|
|
2541
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2542
2335
|
while (true) {
|
|
2543
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
2336
|
+
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2337
|
+
onCancel == null ? void 0 : onCancel();
|
|
2544
2338
|
break;
|
|
2545
2339
|
}
|
|
2340
|
+
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2546
2341
|
try {
|
|
2547
2342
|
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2548
2343
|
} catch (err) {
|
|
@@ -2552,7 +2347,8 @@ const _ParaCore = class _ParaCore {
|
|
|
2552
2347
|
}
|
|
2553
2348
|
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2554
2349
|
if (signRes.pendingTransactionId) {
|
|
2555
|
-
|
|
2350
|
+
onPoll == null ? void 0 : onPoll();
|
|
2351
|
+
continue;
|
|
2556
2352
|
} else {
|
|
2557
2353
|
break;
|
|
2558
2354
|
}
|
|
@@ -2578,7 +2374,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2578
2374
|
}) {
|
|
2579
2375
|
let signRes;
|
|
2580
2376
|
switch (wallet.scheme) {
|
|
2581
|
-
case
|
|
2377
|
+
case "ED25519":
|
|
2582
2378
|
signRes = yield this.platformUtils.ed25519Sign(
|
|
2583
2379
|
this.ctx,
|
|
2584
2380
|
signerId,
|
|
@@ -2596,7 +2392,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2596
2392
|
wallet.signer,
|
|
2597
2393
|
messageBase64,
|
|
2598
2394
|
this.retrieveSessionCookie(),
|
|
2599
|
-
wallet.scheme ===
|
|
2395
|
+
wallet.scheme === "DKLS",
|
|
2600
2396
|
cosmosSignDocBase64
|
|
2601
2397
|
);
|
|
2602
2398
|
break;
|
|
@@ -2617,7 +2413,10 @@ const _ParaCore = class _ParaCore {
|
|
|
2617
2413
|
walletId,
|
|
2618
2414
|
rlpEncodedTxBase64,
|
|
2619
2415
|
chainId,
|
|
2620
|
-
timeoutMs = 3e4
|
|
2416
|
+
timeoutMs = 3e4,
|
|
2417
|
+
isCanceled = () => false,
|
|
2418
|
+
onCancel,
|
|
2419
|
+
onPoll
|
|
2621
2420
|
}) {
|
|
2622
2421
|
this.assertIsValidWalletId(walletId);
|
|
2623
2422
|
const wallet = this.wallets[walletId];
|
|
@@ -2633,7 +2432,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2633
2432
|
rlpEncodedTxBase64,
|
|
2634
2433
|
chainId,
|
|
2635
2434
|
this.retrieveSessionCookie(),
|
|
2636
|
-
wallet.scheme ===
|
|
2435
|
+
wallet.scheme === "DKLS"
|
|
2637
2436
|
);
|
|
2638
2437
|
let timeStart = Date.now();
|
|
2639
2438
|
if (signRes.pendingTransactionId) {
|
|
@@ -2645,11 +2444,12 @@ const _ParaCore = class _ParaCore {
|
|
|
2645
2444
|
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2646
2445
|
return signRes;
|
|
2647
2446
|
}
|
|
2648
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2649
2447
|
while (true) {
|
|
2650
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
2448
|
+
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2449
|
+
onCancel == null ? void 0 : onCancel();
|
|
2651
2450
|
break;
|
|
2652
2451
|
}
|
|
2452
|
+
yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2653
2453
|
try {
|
|
2654
2454
|
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2655
2455
|
} catch (err) {
|
|
@@ -2665,10 +2465,11 @@ const _ParaCore = class _ParaCore {
|
|
|
2665
2465
|
rlpEncodedTxBase64,
|
|
2666
2466
|
chainId,
|
|
2667
2467
|
this.retrieveSessionCookie(),
|
|
2668
|
-
wallet.scheme ===
|
|
2468
|
+
wallet.scheme === "DKLS"
|
|
2669
2469
|
);
|
|
2670
2470
|
if (signRes.pendingTransactionId) {
|
|
2671
|
-
|
|
2471
|
+
onPoll == null ? void 0 : onPoll();
|
|
2472
|
+
continue;
|
|
2672
2473
|
} else {
|
|
2673
2474
|
break;
|
|
2674
2475
|
}
|
|
@@ -2685,44 +2486,6 @@ const _ParaCore = class _ParaCore {
|
|
|
2685
2486
|
return signRes;
|
|
2686
2487
|
});
|
|
2687
2488
|
}
|
|
2688
|
-
/**
|
|
2689
|
-
* @deprecated
|
|
2690
|
-
* Sends a transaction.
|
|
2691
|
-
* @param walletId - id of the wallet to send the transaction from.
|
|
2692
|
-
* @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
|
|
2693
|
-
* @param chainId - chain id of the chain the transaction is being sent on.
|
|
2694
|
-
**/
|
|
2695
|
-
sendTransaction(_0) {
|
|
2696
|
-
return __async(this, arguments, function* ({
|
|
2697
|
-
walletId,
|
|
2698
|
-
rlpEncodedTxBase64,
|
|
2699
|
-
chainId
|
|
2700
|
-
}) {
|
|
2701
|
-
this.assertIsValidWalletId(walletId);
|
|
2702
|
-
const wallet = this.wallets[walletId];
|
|
2703
|
-
const signRes = yield this.platformUtils.sendTransaction(
|
|
2704
|
-
this.ctx,
|
|
2705
|
-
this.userId,
|
|
2706
|
-
walletId,
|
|
2707
|
-
this.wallets[walletId].signer,
|
|
2708
|
-
rlpEncodedTxBase64,
|
|
2709
|
-
chainId,
|
|
2710
|
-
this.retrieveSessionCookie(),
|
|
2711
|
-
wallet.scheme === import_user_management_client.WalletScheme.DKLS
|
|
2712
|
-
);
|
|
2713
|
-
if (signRes.pendingTransactionId) {
|
|
2714
|
-
this.platformUtils.openPopup(
|
|
2715
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
2716
|
-
{ type: import_types.PopupType.SIGN_TRANSACTION_REVIEW }
|
|
2717
|
-
);
|
|
2718
|
-
const error = new import_errors.TransactionReviewError(
|
|
2719
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId)
|
|
2720
|
-
);
|
|
2721
|
-
throw error;
|
|
2722
|
-
}
|
|
2723
|
-
return signRes;
|
|
2724
|
-
});
|
|
2725
|
-
}
|
|
2726
2489
|
isProviderModalDisabled() {
|
|
2727
2490
|
return !!this.disableProviderModal;
|
|
2728
2491
|
}
|
|
@@ -2772,17 +2535,13 @@ const _ParaCore = class _ParaCore {
|
|
|
2772
2535
|
* @param {boolean} excludeSigners - whether or not to exclude the signer from the exported wallets.
|
|
2773
2536
|
* @returns {string} the serialized session
|
|
2774
2537
|
*/
|
|
2775
|
-
exportSession({ excludeSigners } = {}) {
|
|
2538
|
+
exportSession({ excludeSigners = false } = {}) {
|
|
2776
2539
|
const sessionInfo = {
|
|
2777
|
-
|
|
2540
|
+
authInfo: __privateGet(this, _authInfo),
|
|
2778
2541
|
userId: this.userId,
|
|
2779
2542
|
wallets: structuredClone(this.wallets),
|
|
2780
2543
|
currentWalletIds: this.currentWalletIds,
|
|
2781
|
-
sessionCookie: this.
|
|
2782
|
-
phone: this.phone,
|
|
2783
|
-
countryCode: this.countryCode,
|
|
2784
|
-
telegramUserId: this.telegramUserId,
|
|
2785
|
-
farcasterUsername: this.farcasterUsername,
|
|
2544
|
+
sessionCookie: this.retrieveSessionCookie(),
|
|
2786
2545
|
externalWallets: this.externalWallets
|
|
2787
2546
|
};
|
|
2788
2547
|
if (excludeSigners) {
|
|
@@ -2798,12 +2557,11 @@ const _ParaCore = class _ParaCore {
|
|
|
2798
2557
|
*/
|
|
2799
2558
|
importSession(serializedInstanceBase64) {
|
|
2800
2559
|
return __async(this, null, function* () {
|
|
2801
|
-
var _a;
|
|
2560
|
+
var _a, _b;
|
|
2802
2561
|
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
2803
|
-
const sessionInfo =
|
|
2804
|
-
|
|
2805
|
-
yield this.
|
|
2806
|
-
yield this.setFarcasterUsername(sessionInfo.farcasterUsername);
|
|
2562
|
+
const sessionInfo = (0, import_utils2.jsonParse)(serializedInstance);
|
|
2563
|
+
const authInfo = (_a = sessionInfo.authInfo) != null ? _a : __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, sessionInfo);
|
|
2564
|
+
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
2807
2565
|
yield this.setUserId(sessionInfo.userId);
|
|
2808
2566
|
yield this.setWallets(sessionInfo.wallets);
|
|
2809
2567
|
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
@@ -2818,42 +2576,23 @@ const _ParaCore = class _ParaCore {
|
|
|
2818
2576
|
const currentWalletIds = {};
|
|
2819
2577
|
for (const walletId of Object.keys(sessionInfo.wallets)) {
|
|
2820
2578
|
currentWalletIds[sessionInfo.wallets[walletId].type] = [
|
|
2821
|
-
...(
|
|
2579
|
+
...(_b = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _b : [],
|
|
2822
2580
|
walletId
|
|
2823
2581
|
];
|
|
2824
2582
|
}
|
|
2825
2583
|
yield this.setCurrentWalletIds(currentWalletIds);
|
|
2826
2584
|
}
|
|
2827
2585
|
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
2828
|
-
yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
2829
2586
|
});
|
|
2830
2587
|
}
|
|
2831
|
-
exitAccountCreation() {
|
|
2832
|
-
this.isAwaitingAccountCreation = false;
|
|
2833
|
-
}
|
|
2834
|
-
exitLogin() {
|
|
2835
|
-
this.isAwaitingLogin = false;
|
|
2836
|
-
}
|
|
2837
|
-
exitFarcaster() {
|
|
2838
|
-
this.isAwaitingFarcaster = false;
|
|
2839
|
-
}
|
|
2840
|
-
exitOAuth() {
|
|
2841
|
-
this.isAwaitingOAuth = false;
|
|
2842
|
-
}
|
|
2843
|
-
exitLoops() {
|
|
2844
|
-
this.exitAccountCreation();
|
|
2845
|
-
this.exitLogin();
|
|
2846
|
-
this.exitFarcaster();
|
|
2847
|
-
this.exitOAuth();
|
|
2848
|
-
}
|
|
2849
2588
|
/**
|
|
2850
2589
|
* Retrieves a token to verify the current session.
|
|
2851
2590
|
* @returns {Promise<string>} the ID
|
|
2852
2591
|
**/
|
|
2853
2592
|
getVerificationToken() {
|
|
2854
2593
|
return __async(this, null, function* () {
|
|
2855
|
-
const {
|
|
2856
|
-
return
|
|
2594
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
2595
|
+
return sessionLookupId;
|
|
2857
2596
|
});
|
|
2858
2597
|
}
|
|
2859
2598
|
/**
|
|
@@ -2878,22 +2617,18 @@ const _ParaCore = class _ParaCore {
|
|
|
2878
2617
|
this.currentWalletIds = {};
|
|
2879
2618
|
this.externalWallets = {};
|
|
2880
2619
|
this.loginEncryptionKeyPair = void 0;
|
|
2881
|
-
this
|
|
2882
|
-
this.telegramUserId = void 0;
|
|
2883
|
-
this.phone = void 0;
|
|
2884
|
-
this.countryCode = void 0;
|
|
2620
|
+
__privateSet(this, _authInfo, void 0);
|
|
2885
2621
|
this.userId = void 0;
|
|
2886
2622
|
this.sessionCookie = void 0;
|
|
2887
2623
|
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
|
|
2888
2624
|
});
|
|
2889
2625
|
}
|
|
2626
|
+
/** @deprecated */
|
|
2890
2627
|
getSupportedCreateAuthMethods() {
|
|
2891
2628
|
return __async(this, null, function* () {
|
|
2892
|
-
const
|
|
2893
|
-
const partnerId = res.data.partnerId;
|
|
2894
|
-
const partnerRes = yield this.ctx.client.getPartner(partnerId);
|
|
2629
|
+
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2895
2630
|
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
2896
|
-
for (const authMethod of
|
|
2631
|
+
for (const authMethod of partner.supportedAuthMethods) {
|
|
2897
2632
|
supportedAuthMethods.add(import_user_management_client.AuthMethod[authMethod]);
|
|
2898
2633
|
}
|
|
2899
2634
|
return supportedAuthMethods;
|
|
@@ -2905,6 +2640,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2905
2640
|
* Doesn't work for all types of logging.
|
|
2906
2641
|
**/
|
|
2907
2642
|
toString() {
|
|
2643
|
+
var _a, _b, _c;
|
|
2908
2644
|
const redactedWallets = Object.keys(this.wallets).reduce(
|
|
2909
2645
|
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
2910
2646
|
[walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
@@ -2922,16 +2658,15 @@ const _ParaCore = class _ParaCore {
|
|
|
2922
2658
|
{}
|
|
2923
2659
|
);
|
|
2924
2660
|
const obj = {
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
telegramUserId: this.telegramUserId,
|
|
2931
|
-
farcasterUsername: this.farcasterUsername,
|
|
2661
|
+
partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
|
|
2662
|
+
supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
|
|
2663
|
+
cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
|
|
2664
|
+
authInfo: __privateGet(this, _authInfo),
|
|
2665
|
+
isGuestMode: this.isGuestMode,
|
|
2932
2666
|
userId: this.userId,
|
|
2933
2667
|
pregenIds: this.pregenIds,
|
|
2934
2668
|
currentWalletIds: this.currentWalletIds,
|
|
2669
|
+
guestWalletIds: __privateGet(this, _ParaCore_instances, guestWalletIds_get),
|
|
2935
2670
|
wallets: redactedWallets,
|
|
2936
2671
|
externalWallets: redactedExternalWallets,
|
|
2937
2672
|
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
@@ -2948,25 +2683,201 @@ const _ParaCore = class _ParaCore {
|
|
|
2948
2683
|
};
|
|
2949
2684
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
2950
2685
|
}
|
|
2686
|
+
getNewCredentialAndUrl() {
|
|
2687
|
+
return __async(this, arguments, function* ({
|
|
2688
|
+
authMethod = "PASSKEY",
|
|
2689
|
+
isForNewDevice = false,
|
|
2690
|
+
portalTheme,
|
|
2691
|
+
shorten = false
|
|
2692
|
+
} = {}) {
|
|
2693
|
+
this.assertIsAuthSet();
|
|
2694
|
+
let credentialId, urlType;
|
|
2695
|
+
switch (authMethod) {
|
|
2696
|
+
case "PASSKEY":
|
|
2697
|
+
({
|
|
2698
|
+
data: { id: credentialId }
|
|
2699
|
+
} = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2700
|
+
status: import_user_management_client.PublicKeyStatus.PENDING,
|
|
2701
|
+
type: import_user_management_client.PublicKeyType.WEB
|
|
2702
|
+
}));
|
|
2703
|
+
urlType = "createAuth";
|
|
2704
|
+
break;
|
|
2705
|
+
case "PASSWORD":
|
|
2706
|
+
({
|
|
2707
|
+
data: { id: credentialId }
|
|
2708
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
2709
|
+
status: import_user_management_client.PasswordStatus.PENDING
|
|
2710
|
+
}));
|
|
2711
|
+
urlType = "createPassword";
|
|
2712
|
+
break;
|
|
2713
|
+
}
|
|
2714
|
+
const url = this.isNativePasskey && urlType === "createAuth" ? void 0 : yield this.constructPortalUrl(urlType, {
|
|
2715
|
+
isForNewDevice,
|
|
2716
|
+
pathId: credentialId,
|
|
2717
|
+
portalTheme,
|
|
2718
|
+
shorten
|
|
2719
|
+
});
|
|
2720
|
+
return __spreadValues({ credentialId }, url ? { url } : {});
|
|
2721
|
+
});
|
|
2722
|
+
}
|
|
2723
|
+
/**
|
|
2724
|
+
* Returns a Para Portal URL for logging in with a WebAuth passkey or a password.
|
|
2725
|
+
* @param {Object} opts the options object
|
|
2726
|
+
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
2727
|
+
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
2728
|
+
* @param {Theme} opts.portalTheme the Para Portal theme to apply to the password creation URL, if other than the default theme
|
|
2729
|
+
* @returns {SignUpOrLogInResponse} an object in the form of either: `{ stage: 'verify' }` or `{ stage: 'login'; passkeyUrl?: string; passwordUrl?: string; biometricHints?: BiometricLocationHint[] }`
|
|
2730
|
+
*/
|
|
2731
|
+
getLoginUrl(_0) {
|
|
2732
|
+
return __async(this, arguments, function* ({
|
|
2733
|
+
authMethod = "PASSKEY",
|
|
2734
|
+
shorten = false,
|
|
2735
|
+
portalTheme,
|
|
2736
|
+
sessionId
|
|
2737
|
+
}) {
|
|
2738
|
+
if (!sessionId) {
|
|
2739
|
+
sessionId = (yield this.touchSession()).sessionLookupId;
|
|
2740
|
+
}
|
|
2741
|
+
this.assertIsAuthSet();
|
|
2742
|
+
let urlType;
|
|
2743
|
+
switch (authMethod) {
|
|
2744
|
+
case "PASSKEY":
|
|
2745
|
+
urlType = "loginAuth";
|
|
2746
|
+
break;
|
|
2747
|
+
case "PASSWORD":
|
|
2748
|
+
urlType = "loginPassword";
|
|
2749
|
+
break;
|
|
2750
|
+
default:
|
|
2751
|
+
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
2752
|
+
}
|
|
2753
|
+
return this.constructPortalUrl(urlType, {
|
|
2754
|
+
sessionId,
|
|
2755
|
+
shorten,
|
|
2756
|
+
portalTheme
|
|
2757
|
+
});
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2760
|
+
signUpOrLogIn(_o) {
|
|
2761
|
+
return __async(this, null, function* () {
|
|
2762
|
+
var _p = _o, { auth } = _p, urlOptions = __objRest(_p, ["auth"]);
|
|
2763
|
+
const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
2764
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
verifyNewAccount(_q) {
|
|
2768
|
+
return __async(this, null, function* () {
|
|
2769
|
+
var _r = _q, {
|
|
2770
|
+
verificationCode
|
|
2771
|
+
} = _r, urlOptions = __objRest(_r, [
|
|
2772
|
+
"verificationCode"
|
|
2773
|
+
]);
|
|
2774
|
+
this.assertIsAuthSet(["email", "phone"]);
|
|
2775
|
+
const userId = this.assertUserId();
|
|
2776
|
+
const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
|
|
2777
|
+
verificationCode
|
|
2778
|
+
});
|
|
2779
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2780
|
+
});
|
|
2781
|
+
}
|
|
2951
2782
|
};
|
|
2952
|
-
|
|
2953
|
-
|
|
2783
|
+
_authInfo = new WeakMap();
|
|
2784
|
+
_partner = new WeakMap();
|
|
2954
2785
|
_ParaCore_instances = new WeakSet();
|
|
2786
|
+
assertPartner_fn = function() {
|
|
2787
|
+
return __async(this, null, function* () {
|
|
2788
|
+
var _a, _b;
|
|
2789
|
+
if (!__privateGet(this, _partner)) {
|
|
2790
|
+
yield this.touchSession();
|
|
2791
|
+
}
|
|
2792
|
+
if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
|
|
2793
|
+
this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
|
|
2794
|
+
}
|
|
2795
|
+
return __privateGet(this, _partner);
|
|
2796
|
+
});
|
|
2797
|
+
};
|
|
2798
|
+
guestWalletIds_get = function() {
|
|
2799
|
+
var _a, _b, _c;
|
|
2800
|
+
if (!((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
2801
|
+
return {};
|
|
2802
|
+
}
|
|
2803
|
+
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
2804
|
+
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
2805
|
+
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
2806
|
+
return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) => __privateGet(this, _partner).supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
2807
|
+
var _a2;
|
|
2808
|
+
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
2809
|
+
}, {}));
|
|
2810
|
+
}
|
|
2811
|
+
return acc;
|
|
2812
|
+
}, {}) : {};
|
|
2813
|
+
};
|
|
2814
|
+
guestWalletIdsArray_get = function() {
|
|
2815
|
+
return Object.entries(__privateGet(this, _ParaCore_instances, guestWalletIds_get)).reduce((acc, [type, ids]) => {
|
|
2816
|
+
return [...acc, ...ids.map((id) => [id, type])];
|
|
2817
|
+
}, []);
|
|
2818
|
+
};
|
|
2819
|
+
toAuthInfo_fn = function({
|
|
2820
|
+
email,
|
|
2821
|
+
phone,
|
|
2822
|
+
countryCode,
|
|
2823
|
+
farcasterUsername,
|
|
2824
|
+
telegramUserId,
|
|
2825
|
+
externalWalletAddress
|
|
2826
|
+
}) {
|
|
2827
|
+
let auth;
|
|
2828
|
+
switch (true) {
|
|
2829
|
+
case !!email:
|
|
2830
|
+
auth = { email };
|
|
2831
|
+
break;
|
|
2832
|
+
case !!phone:
|
|
2833
|
+
{
|
|
2834
|
+
const validPhone = (0, import_utils2.formatPhoneNumber)(phone, countryCode);
|
|
2835
|
+
if (validPhone) auth = { phone: (0, import_utils2.formatPhoneNumber)(phone, countryCode) };
|
|
2836
|
+
}
|
|
2837
|
+
break;
|
|
2838
|
+
case !!farcasterUsername:
|
|
2839
|
+
auth = { farcasterUsername };
|
|
2840
|
+
break;
|
|
2841
|
+
case !!telegramUserId:
|
|
2842
|
+
auth = { telegramUserId };
|
|
2843
|
+
break;
|
|
2844
|
+
case !!externalWalletAddress:
|
|
2845
|
+
auth = { externalWalletAddress };
|
|
2846
|
+
break;
|
|
2847
|
+
}
|
|
2848
|
+
return (0, import_user_management_client.extractAuthInfo)(auth);
|
|
2849
|
+
};
|
|
2850
|
+
setAuthInfo_fn = function(authInfo) {
|
|
2851
|
+
return __async(this, null, function* () {
|
|
2852
|
+
__privateSet(this, _authInfo, authInfo);
|
|
2853
|
+
yield this.localStorageSetItem(constants.LOCAL_STORAGE_AUTH_INFO, JSON.stringify(authInfo));
|
|
2854
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_EMAIL);
|
|
2855
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_PHONE);
|
|
2856
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_COUNTRY_CODE);
|
|
2857
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME);
|
|
2858
|
+
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID);
|
|
2859
|
+
});
|
|
2860
|
+
};
|
|
2861
|
+
getPartner_fn = function(partnerId) {
|
|
2862
|
+
return __async(this, null, function* () {
|
|
2863
|
+
const res = yield this.ctx.client.getPartner(partnerId);
|
|
2864
|
+
__privateSet(this, _partner, res.data.partner);
|
|
2865
|
+
return __privateGet(this, _partner);
|
|
2866
|
+
});
|
|
2867
|
+
};
|
|
2955
2868
|
createPregenWallet_fn = function(opts) {
|
|
2956
2869
|
return __async(this, null, function* () {
|
|
2957
2870
|
var _a, _b;
|
|
2958
|
-
const {
|
|
2959
|
-
|
|
2960
|
-
pregenIdentifier,
|
|
2961
|
-
pregenIdentifierType = "EMAIL"
|
|
2962
|
-
} = opts;
|
|
2871
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2872
|
+
const { type: _type = (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type, pregenId } = opts;
|
|
2963
2873
|
this.requireApiKey();
|
|
2964
2874
|
const walletType = yield this.assertIsValidWalletType(
|
|
2965
|
-
_type != null ? _type : (_b =
|
|
2875
|
+
_type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
2966
2876
|
);
|
|
2877
|
+
const [pregenIdentifierType, pregenIdentifier] = (0, import_user_management_client.toPregenTypeAndId)(pregenId);
|
|
2967
2878
|
let keygenRes;
|
|
2968
2879
|
switch (walletType) {
|
|
2969
|
-
case
|
|
2880
|
+
case "SOLANA":
|
|
2970
2881
|
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
2971
2882
|
this.ctx,
|
|
2972
2883
|
pregenIdentifier,
|
|
@@ -2990,7 +2901,7 @@ createPregenWallet_fn = function(opts) {
|
|
|
2990
2901
|
this.wallets[walletId] = {
|
|
2991
2902
|
id: walletId,
|
|
2992
2903
|
signer,
|
|
2993
|
-
scheme: walletType ===
|
|
2904
|
+
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
2994
2905
|
type: walletType,
|
|
2995
2906
|
isPregen: true,
|
|
2996
2907
|
pregenIdentifier,
|
|
@@ -3001,6 +2912,114 @@ createPregenWallet_fn = function(opts) {
|
|
|
3001
2912
|
return this.wallets[walletId];
|
|
3002
2913
|
});
|
|
3003
2914
|
};
|
|
2915
|
+
_isCreateGuestWalletsPending = new WeakMap();
|
|
2916
|
+
prepareAuthState_fn = function(_0) {
|
|
2917
|
+
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
2918
|
+
if (!opts.sessionLookupId && serverAuthState.stage === "login") {
|
|
2919
|
+
opts.sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
2920
|
+
}
|
|
2921
|
+
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
2922
|
+
const authInfo = __spreadValues(__spreadValues({}, (0, import_user_management_client.extractAuthInfo)(auth, { isRequired: true })), Object.fromEntries(
|
|
2923
|
+
Object.entries({
|
|
2924
|
+
displayName,
|
|
2925
|
+
pfpUrl,
|
|
2926
|
+
username,
|
|
2927
|
+
externalWallet
|
|
2928
|
+
}).filter(([_, v]) => !!v)
|
|
2929
|
+
));
|
|
2930
|
+
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
2931
|
+
yield this.assertIsAuthSet();
|
|
2932
|
+
if (!!externalWallet) {
|
|
2933
|
+
yield this.setExternalWallet(externalWallet);
|
|
2934
|
+
}
|
|
2935
|
+
if (!!userId) {
|
|
2936
|
+
yield this.setUserId(userId);
|
|
2937
|
+
}
|
|
2938
|
+
let authState;
|
|
2939
|
+
switch (serverAuthState.stage) {
|
|
2940
|
+
case "verify":
|
|
2941
|
+
authState = serverAuthState;
|
|
2942
|
+
break;
|
|
2943
|
+
case "login":
|
|
2944
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
|
|
2945
|
+
break;
|
|
2946
|
+
case "signup":
|
|
2947
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
|
|
2948
|
+
break;
|
|
2949
|
+
}
|
|
2950
|
+
return authState;
|
|
2951
|
+
});
|
|
2952
|
+
};
|
|
2953
|
+
prepareLogin_fn = function() {
|
|
2954
|
+
return __async(this, null, function* () {
|
|
2955
|
+
yield this.logout();
|
|
2956
|
+
const { sessionLookupId } = yield this.touchSession(true);
|
|
2957
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2958
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2959
|
+
}
|
|
2960
|
+
return sessionLookupId;
|
|
2961
|
+
});
|
|
2962
|
+
};
|
|
2963
|
+
prepareLoginState_fn = function(_0, _1) {
|
|
2964
|
+
return __async(this, arguments, function* (loginState, {
|
|
2965
|
+
useShortUrls: shorten = false,
|
|
2966
|
+
portalTheme,
|
|
2967
|
+
sessionLookupId
|
|
2968
|
+
}) {
|
|
2969
|
+
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
2970
|
+
return __spreadValues(__spreadValues(__spreadValues({}, authState), !this.isNativePasskey && loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY) ? {
|
|
2971
|
+
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
2972
|
+
passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
|
|
2973
|
+
sessionId: sessionLookupId,
|
|
2974
|
+
newDevice: {
|
|
2975
|
+
sessionId: sessionLookupId,
|
|
2976
|
+
encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair)
|
|
2977
|
+
},
|
|
2978
|
+
shorten,
|
|
2979
|
+
portalTheme
|
|
2980
|
+
})
|
|
2981
|
+
} : {}), loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) ? {
|
|
2982
|
+
passwordUrl: yield this.constructPortalUrl("loginPassword", {
|
|
2983
|
+
sessionId: sessionLookupId,
|
|
2984
|
+
shorten,
|
|
2985
|
+
portalTheme
|
|
2986
|
+
})
|
|
2987
|
+
} : {});
|
|
2988
|
+
});
|
|
2989
|
+
};
|
|
2990
|
+
prepareSignUpState_fn = function(_0, _1) {
|
|
2991
|
+
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
2992
|
+
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
2993
|
+
const [isPasskey, isPassword] = [
|
|
2994
|
+
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY),
|
|
2995
|
+
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD)
|
|
2996
|
+
];
|
|
2997
|
+
if (!isPasskey && !isPassword) {
|
|
2998
|
+
throw new Error(
|
|
2999
|
+
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or passwords in your Developer Portal settings."
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
const signupState = authState;
|
|
3003
|
+
if (isPasskey) {
|
|
3004
|
+
const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
|
|
3005
|
+
authMethod: "PASSKEY",
|
|
3006
|
+
shorten
|
|
3007
|
+
});
|
|
3008
|
+
if (passkeyUrl) signupState.passkeyUrl = passkeyUrl;
|
|
3009
|
+
signupState.passkeyId = passkeyId;
|
|
3010
|
+
}
|
|
3011
|
+
if (isPassword) {
|
|
3012
|
+
const { url: passwordUrl, credentialId: passwordId } = yield this.getNewCredentialAndUrl({
|
|
3013
|
+
authMethod: "PASSWORD",
|
|
3014
|
+
portalTheme,
|
|
3015
|
+
shorten
|
|
3016
|
+
});
|
|
3017
|
+
signupState.passwordUrl = passwordUrl;
|
|
3018
|
+
signupState.passwordId = passwordId;
|
|
3019
|
+
}
|
|
3020
|
+
return signupState;
|
|
3021
|
+
});
|
|
3022
|
+
};
|
|
3004
3023
|
_ParaCore.version = constants.PARA_CORE_VERSION;
|
|
3005
3024
|
let ParaCore = _ParaCore;
|
|
3006
3025
|
// Annotate the CommonJS export names for ESM import in node:
|