@getpara/core-sdk 2.0.0-alpha.3 → 2.0.0-dev.1
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/index.js +1465 -420
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +1468 -422
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/types/ParaCore.d.ts +414 -35
- package/dist/types/types/coreApi.d.ts +20 -20
- package/dist/types/types/methods.d.ts +49 -1
- package/package.json +3 -4
package/dist/esm/index.js
CHANGED
|
@@ -70,6 +70,7 @@ import {
|
|
|
70
70
|
PublicKeyType,
|
|
71
71
|
WalletType as WalletType2,
|
|
72
72
|
WalletScheme as WalletScheme2,
|
|
73
|
+
OAuthMethod,
|
|
73
74
|
extractWalletRef,
|
|
74
75
|
PasswordStatus,
|
|
75
76
|
extractAuthInfo,
|
|
@@ -187,7 +188,7 @@ function jsonParse(data, validate) {
|
|
|
187
188
|
}
|
|
188
189
|
|
|
189
190
|
// src/constants.ts
|
|
190
|
-
var PARA_CORE_VERSION = '2.0.0-
|
|
191
|
+
var PARA_CORE_VERSION = '2.0.0-dev.1';
|
|
191
192
|
var PREFIX = "@CAPSULE/";
|
|
192
193
|
var LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
193
194
|
var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
@@ -317,7 +318,7 @@ function waitUntilTrue(condition, timeoutMs, intervalMs) {
|
|
|
317
318
|
|
|
318
319
|
// src/utils/types.ts
|
|
319
320
|
function isServerAuthState(obj) {
|
|
320
|
-
return "stage" in obj
|
|
321
|
+
return "stage" in obj;
|
|
321
322
|
}
|
|
322
323
|
|
|
323
324
|
// src/transmission/transmissionUtils.ts
|
|
@@ -376,20 +377,20 @@ var EnabledFlow = /* @__PURE__ */ ((EnabledFlow2) => {
|
|
|
376
377
|
|
|
377
378
|
// src/types/coreApi.ts
|
|
378
379
|
var PARA_CORE_METHODS = [
|
|
379
|
-
"
|
|
380
|
-
"
|
|
381
|
-
"
|
|
382
|
-
"
|
|
383
|
-
"
|
|
384
|
-
"
|
|
385
|
-
"
|
|
386
|
-
"
|
|
380
|
+
"signUpOrLogInV2",
|
|
381
|
+
"verifyNewAccountV2",
|
|
382
|
+
"waitForLoginV2",
|
|
383
|
+
"waitForSignupV2",
|
|
384
|
+
"waitForWalletCreationV2",
|
|
385
|
+
"verifyOAuthV2",
|
|
386
|
+
"verifyFarcasterV2",
|
|
387
|
+
"verifyTelegramV2",
|
|
387
388
|
"resendVerificationCode",
|
|
388
|
-
"
|
|
389
|
-
"
|
|
390
|
-
"
|
|
391
|
-
"
|
|
392
|
-
"
|
|
389
|
+
"loginExternalWalletV2",
|
|
390
|
+
"verifyExternalWalletV2",
|
|
391
|
+
"setup2faV2",
|
|
392
|
+
"enable2faV2",
|
|
393
|
+
"verify2faV2",
|
|
393
394
|
"logout",
|
|
394
395
|
"clearStorage",
|
|
395
396
|
"isSessionActive",
|
|
@@ -402,12 +403,12 @@ var PARA_CORE_METHODS = [
|
|
|
402
403
|
"fetchWallets",
|
|
403
404
|
"createWallet",
|
|
404
405
|
"createWalletPerType",
|
|
405
|
-
"
|
|
406
|
-
"
|
|
407
|
-
"
|
|
408
|
-
"
|
|
409
|
-
"
|
|
410
|
-
"
|
|
406
|
+
"getPregenWalletsV2",
|
|
407
|
+
"hasPregenWalletV2",
|
|
408
|
+
"updatePregenWalletIdentifierV2",
|
|
409
|
+
"createPregenWalletV2",
|
|
410
|
+
"createPregenWalletPerTypeV2",
|
|
411
|
+
"claimPregenWalletsV2",
|
|
411
412
|
"distributeNewWalletShare",
|
|
412
413
|
"getUserShare",
|
|
413
414
|
"setUserShare",
|
|
@@ -445,13 +446,13 @@ var PopupType = /* @__PURE__ */ ((PopupType2) => {
|
|
|
445
446
|
})(PopupType || {});
|
|
446
447
|
|
|
447
448
|
// src/types/recovery.ts
|
|
448
|
-
var RecoveryStatus = /* @__PURE__ */ ((
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
return
|
|
449
|
+
var RecoveryStatus = /* @__PURE__ */ ((RecoveryStatus3) => {
|
|
450
|
+
RecoveryStatus3["INITIATED"] = "INITIATED";
|
|
451
|
+
RecoveryStatus3["READY"] = "READY";
|
|
452
|
+
RecoveryStatus3["EXPIRED"] = "EXPIRED";
|
|
453
|
+
RecoveryStatus3["FINISHED"] = "FINISHED";
|
|
454
|
+
RecoveryStatus3["CANCELLED"] = "CANCELLED";
|
|
455
|
+
return RecoveryStatus3;
|
|
455
456
|
})(RecoveryStatus || {});
|
|
456
457
|
|
|
457
458
|
// src/types/events.ts
|
|
@@ -942,7 +943,7 @@ function initClient({
|
|
|
942
943
|
}) {
|
|
943
944
|
return new Client({
|
|
944
945
|
userManagementHost: getBaseUrl(env),
|
|
945
|
-
version: ["DEV" /* DEV */, "SANDBOX" /* SANDBOX */].includes(env) ? "dev
|
|
946
|
+
version: ["DEV" /* DEV */, "SANDBOX" /* SANDBOX */].includes(env) ? "dev" : version,
|
|
946
947
|
apiKey,
|
|
947
948
|
partnerId,
|
|
948
949
|
opts: { useFetchAdapter },
|
|
@@ -1682,7 +1683,7 @@ var _ParaCore = class _ParaCore {
|
|
|
1682
1683
|
var _a, _b, _c;
|
|
1683
1684
|
return walletId ? (_a = this.wallets[walletId]) == null ? void 0 : _a.address : (_c = (_b = Object.values(this.wallets)) == null ? void 0 : _b[0]) == null ? void 0 : _c.address;
|
|
1684
1685
|
}
|
|
1685
|
-
|
|
1686
|
+
constructPortalUrlV2(_0) {
|
|
1686
1687
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
1687
1688
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1688
1689
|
const [isCreate, isLogin, isOnRamp] = [
|
|
@@ -1767,6 +1768,77 @@ var _ParaCore = class _ParaCore {
|
|
|
1767
1768
|
return url;
|
|
1768
1769
|
});
|
|
1769
1770
|
}
|
|
1771
|
+
constructPortalUrl(_0) {
|
|
1772
|
+
return __async(this, arguments, function* (type, opts = {}) {
|
|
1773
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1774
|
+
const [isCreate, isLogin, isOnRamp] = [
|
|
1775
|
+
["createAuth", "createPassword"].includes(type),
|
|
1776
|
+
["loginAuth", "loginPassword"].includes(type),
|
|
1777
|
+
type === "onRamp"
|
|
1778
|
+
];
|
|
1779
|
+
let auth;
|
|
1780
|
+
if (isCreate || isLogin) {
|
|
1781
|
+
auth = this.assertIsAuthSet().auth;
|
|
1782
|
+
}
|
|
1783
|
+
if ((isLogin || isOnRamp) && !opts.sessionId) {
|
|
1784
|
+
opts.sessionId = (yield this.touchSession()).sessionLookupId;
|
|
1785
|
+
}
|
|
1786
|
+
const base = isOnRamp ? getPortalBaseURL(this.ctx) : yield this.getPortalURL();
|
|
1787
|
+
let path;
|
|
1788
|
+
switch (type) {
|
|
1789
|
+
case "createPassword": {
|
|
1790
|
+
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
1791
|
+
break;
|
|
1792
|
+
}
|
|
1793
|
+
case "createAuth": {
|
|
1794
|
+
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
1795
|
+
break;
|
|
1796
|
+
}
|
|
1797
|
+
case "loginPassword": {
|
|
1798
|
+
path = "/web/passwords/login";
|
|
1799
|
+
break;
|
|
1800
|
+
}
|
|
1801
|
+
case "loginAuth": {
|
|
1802
|
+
path = "/web/biometrics/login";
|
|
1803
|
+
break;
|
|
1804
|
+
}
|
|
1805
|
+
case "txReview": {
|
|
1806
|
+
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
1807
|
+
break;
|
|
1808
|
+
}
|
|
1809
|
+
case "onRamp": {
|
|
1810
|
+
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
1811
|
+
break;
|
|
1812
|
+
}
|
|
1813
|
+
default: {
|
|
1814
|
+
throw new Error(`invalid URL type ${type}`);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1818
|
+
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
1819
|
+
apiKey: this.ctx.apiKey,
|
|
1820
|
+
partnerId: partner.id,
|
|
1821
|
+
portalFont: ((_a = opts.theme) == null ? void 0 : _a.font) || (partner == null ? void 0 : partner.font) || ((_b = this.portalTheme) == null ? void 0 : _b.font),
|
|
1822
|
+
portalBorderRadius: ((_c = opts.theme) == null ? void 0 : _c.borderRadius) || ((_d = this.portalTheme) == null ? void 0 : _d.borderRadius),
|
|
1823
|
+
portalThemeMode: ((_e = opts.theme) == null ? void 0 : _e.mode) || (partner == null ? void 0 : partner.themeMode) || ((_f = this.portalTheme) == null ? void 0 : _f.mode),
|
|
1824
|
+
portalAccentColor: ((_g = opts.theme) == null ? void 0 : _g.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_h = this.portalTheme) == null ? void 0 : _h.accentColor),
|
|
1825
|
+
portalForegroundColor: ((_i = opts.theme) == null ? void 0 : _i.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_j = this.portalTheme) == null ? void 0 : _j.foregroundColor),
|
|
1826
|
+
portalBackgroundColor: ((_k = opts.theme) == null ? void 0 : _k.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_l = this.portalTheme) == null ? void 0 : _l.backgroundColor),
|
|
1827
|
+
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
1828
|
+
portalTextColor: this.portalTextColor,
|
|
1829
|
+
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
1830
|
+
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
1831
|
+
}, auth && (isCreate || isLogin) ? auth : {}), isCreate || isLogin ? { authInfo: JSON.stringify(this.authInfo) } : {}), isLogin || isOnRamp ? { sessionId: opts.sessionId } : {}), isLogin ? {
|
|
1832
|
+
encryptionKey: opts.loginEncryptionPublicKey,
|
|
1833
|
+
newDeviceSessionLookupId: opts.newDeviceSessionId,
|
|
1834
|
+
newDeviceEncryptionKey: opts.newDeviceEncryptionKey,
|
|
1835
|
+
pregenIds: JSON.stringify(this.pregenIds),
|
|
1836
|
+
displayName: opts.displayName,
|
|
1837
|
+
pfpUrl: opts.pfpUrl
|
|
1838
|
+
} : {}), opts.params || {});
|
|
1839
|
+
return constructUrl({ base, path, params });
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1770
1842
|
touchSession(regenerate = false) {
|
|
1771
1843
|
return __async(this, null, function* () {
|
|
1772
1844
|
var _a, _b, _c;
|
|
@@ -1909,7 +1981,7 @@ var _ParaCore = class _ParaCore {
|
|
|
1909
1981
|
* @param phone - Phone number to set.
|
|
1910
1982
|
* @param countryCode - Country Code to set.
|
|
1911
1983
|
*/
|
|
1912
|
-
|
|
1984
|
+
setPhoneNumber(phone, countryCode) {
|
|
1913
1985
|
return __async(this, null, function* () {
|
|
1914
1986
|
yield this.setAuth({ phone: formatPhoneNumber(phone, countryCode) });
|
|
1915
1987
|
});
|
|
@@ -2193,6 +2265,75 @@ var _ParaCore = class _ParaCore {
|
|
|
2193
2265
|
return (yield this.getPartnerURL()) || getPortalBaseURL(this.ctx);
|
|
2194
2266
|
});
|
|
2195
2267
|
}
|
|
2268
|
+
getWebAuthURLForCreate(_a) {
|
|
2269
|
+
return __async(this, null, function* () {
|
|
2270
|
+
var _b = _a, {
|
|
2271
|
+
webAuthId
|
|
2272
|
+
} = _b, options = __objRest(_b, [
|
|
2273
|
+
"webAuthId"
|
|
2274
|
+
]);
|
|
2275
|
+
return this.constructPortalUrl("createAuth", __spreadProps(__spreadValues({}, options), { pathId: webAuthId }));
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
getPasswordURLForCreate(_c) {
|
|
2279
|
+
return __async(this, null, function* () {
|
|
2280
|
+
var _d = _c, {
|
|
2281
|
+
passwordId
|
|
2282
|
+
} = _d, options = __objRest(_d, [
|
|
2283
|
+
"passwordId"
|
|
2284
|
+
]);
|
|
2285
|
+
return this.constructPortalUrl("createPassword", __spreadProps(__spreadValues({}, options), {
|
|
2286
|
+
pathId: passwordId
|
|
2287
|
+
}));
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
getShortUrl(compressedUrl) {
|
|
2291
|
+
return constructUrl({
|
|
2292
|
+
base: getPortalBaseURL(this.ctx),
|
|
2293
|
+
path: `/short/${compressedUrl}`
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
shortenLoginLink(link) {
|
|
2297
|
+
return __async(this, null, function* () {
|
|
2298
|
+
const url = yield upload(link, this.ctx.client);
|
|
2299
|
+
return this.getShortUrl(url);
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
/**
|
|
2303
|
+
* Generates a URL for registering a new WebAuth passkey.
|
|
2304
|
+
* @deprecated
|
|
2305
|
+
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
2306
|
+
* @returns - the URL for creating a new passkey
|
|
2307
|
+
*/
|
|
2308
|
+
getWebAuthURLForLogin(opts) {
|
|
2309
|
+
return __async(this, null, function* () {
|
|
2310
|
+
return this.constructPortalUrl("loginAuth", opts);
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
/**
|
|
2314
|
+
* Generates a URL for registering a new user password.
|
|
2315
|
+
* @deprecated
|
|
2316
|
+
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
2317
|
+
* @returns - the URL for creating a new password
|
|
2318
|
+
*/
|
|
2319
|
+
getPasswordURLForLogin(opts) {
|
|
2320
|
+
return __async(this, null, function* () {
|
|
2321
|
+
return this.constructPortalUrl("loginPassword", opts);
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
2326
|
+
* @deprecated
|
|
2327
|
+
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
2328
|
+
* @returns - web auth url
|
|
2329
|
+
*/
|
|
2330
|
+
getWebAuthURLForLoginForPhone(opts) {
|
|
2331
|
+
return __async(this, null, function* () {
|
|
2332
|
+
return this.constructPortalUrl("loginAuth", __spreadValues({
|
|
2333
|
+
authType: "phone"
|
|
2334
|
+
}, opts));
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2196
2337
|
/**
|
|
2197
2338
|
* Gets the private key for the given wallet.
|
|
2198
2339
|
* @param {string } [walletId] id of the wallet to get the private key for. Will default to the first wallet if not provided.
|
|
@@ -2243,7 +2384,7 @@ var _ParaCore = class _ParaCore {
|
|
|
2243
2384
|
}
|
|
2244
2385
|
populatePregenWalletAddresses() {
|
|
2245
2386
|
return __async(this, null, function* () {
|
|
2246
|
-
const res = yield this.
|
|
2387
|
+
const res = yield this.getPregenWalletsV2();
|
|
2247
2388
|
res.forEach((entity) => {
|
|
2248
2389
|
if (this.wallets[entity.id]) {
|
|
2249
2390
|
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
@@ -2253,387 +2394,1253 @@ var _ParaCore = class _ParaCore {
|
|
|
2253
2394
|
});
|
|
2254
2395
|
}
|
|
2255
2396
|
/**
|
|
2256
|
-
*
|
|
2397
|
+
* Checks if a user exists for an email address.
|
|
2398
|
+
* @deprecated
|
|
2399
|
+
* @param {Object} opts the options object
|
|
2400
|
+
* @param {string} opts.email the email to check.
|
|
2401
|
+
* @returns true if user exists, false otherwise.
|
|
2257
2402
|
*/
|
|
2258
|
-
|
|
2259
|
-
return __async(this,
|
|
2260
|
-
yield this.ctx.client.
|
|
2261
|
-
|
|
2262
|
-
}, this.getVerificationEmailProps()));
|
|
2403
|
+
checkIfUserExists(_0) {
|
|
2404
|
+
return __async(this, arguments, function* ({ email }) {
|
|
2405
|
+
const res = yield this.ctx.client.checkUserExists({ email });
|
|
2406
|
+
return res.data.exists;
|
|
2263
2407
|
});
|
|
2264
2408
|
}
|
|
2265
2409
|
/**
|
|
2266
|
-
* Checks if
|
|
2267
|
-
* @
|
|
2410
|
+
* Checks if a user exists for a phone number.
|
|
2411
|
+
* @deprecated
|
|
2412
|
+
* @param {Object} opts the options object
|
|
2413
|
+
* @param {string} opts.phone - phone number to check.
|
|
2414
|
+
* @param {string} opts.countryCode - the country code.
|
|
2415
|
+
* @returns true if user exists, false otherwise.
|
|
2268
2416
|
*/
|
|
2269
|
-
|
|
2417
|
+
checkIfUserExistsByPhone(auth) {
|
|
2270
2418
|
return __async(this, null, function* () {
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
}
|
|
2274
|
-
const { isAuthenticated } = yield this.touchSession();
|
|
2275
|
-
return !!isAuthenticated;
|
|
2419
|
+
const res = yield this.ctx.client.checkUserExists(auth);
|
|
2420
|
+
return res.data.exists;
|
|
2276
2421
|
});
|
|
2277
2422
|
}
|
|
2278
2423
|
/**
|
|
2279
|
-
*
|
|
2280
|
-
* @
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2424
|
+
* Creates a new user.
|
|
2425
|
+
* @deprecated
|
|
2426
|
+
* @param {Object} opts the options object
|
|
2427
|
+
* @param {string} opts.email the email to use.
|
|
2428
|
+
*/
|
|
2429
|
+
createUser(_0) {
|
|
2430
|
+
return __async(this, arguments, function* ({ email }) {
|
|
2431
|
+
this.requireApiKey();
|
|
2432
|
+
yield this.setEmail(email);
|
|
2433
|
+
const { userId } = yield this.ctx.client.createUser(__spreadValues({
|
|
2434
|
+
email: this.email
|
|
2435
|
+
}, this.getVerificationEmailProps()));
|
|
2436
|
+
yield this.setUserId(userId);
|
|
2289
2437
|
});
|
|
2290
2438
|
}
|
|
2291
|
-
|
|
2439
|
+
/**
|
|
2440
|
+
* Creates a new user with a phone number.
|
|
2441
|
+
* @deprecated
|
|
2442
|
+
* @param {Object} opts the options object
|
|
2443
|
+
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
2444
|
+
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
2445
|
+
*/
|
|
2446
|
+
createUserByPhone(auth) {
|
|
2292
2447
|
return __async(this, null, function* () {
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
case "PASSWORD":
|
|
2298
|
-
authMethods.add(AuthMethod.PASSWORD);
|
|
2299
|
-
break;
|
|
2300
|
-
case "BIOMETRIC":
|
|
2301
|
-
authMethods.add(AuthMethod.PASSKEY);
|
|
2302
|
-
break;
|
|
2303
|
-
}
|
|
2304
|
-
}
|
|
2305
|
-
return authMethods;
|
|
2448
|
+
this.requireApiKey();
|
|
2449
|
+
yield this.setPhoneNumber(auth.phone);
|
|
2450
|
+
const { userId } = yield this.ctx.client.createUser(auth);
|
|
2451
|
+
yield this.setUserId(userId);
|
|
2306
2452
|
});
|
|
2307
2453
|
}
|
|
2308
2454
|
/**
|
|
2309
|
-
*
|
|
2455
|
+
* Logs in or creates a new user using an external wallet address.
|
|
2310
2456
|
* @deprecated
|
|
2311
|
-
* @
|
|
2457
|
+
* @param {Object} opts the options object
|
|
2458
|
+
* @param {string} opts.address the external wallet address to use for identification.
|
|
2459
|
+
* @param {WalletType} opts.type type of external wallet to use for identification.
|
|
2460
|
+
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
2312
2461
|
*/
|
|
2313
|
-
|
|
2462
|
+
externalWalletLogin(wallet) {
|
|
2314
2463
|
return __async(this, null, function* () {
|
|
2315
|
-
|
|
2316
|
-
|
|
2464
|
+
this.requireApiKey();
|
|
2465
|
+
const res = yield this.ctx.client.externalWalletLogin({
|
|
2466
|
+
externalAddress: wallet.address,
|
|
2467
|
+
type: wallet.type,
|
|
2468
|
+
externalWalletProvider: wallet.provider,
|
|
2469
|
+
// If the wallet isn't using full Para auth we want to track the login here
|
|
2470
|
+
shouldTrackUser: !wallet.withFullParaAuth
|
|
2471
|
+
});
|
|
2472
|
+
yield this.setExternalWallet(wallet);
|
|
2473
|
+
yield this.setUserId(res.userId);
|
|
2474
|
+
return res;
|
|
2317
2475
|
});
|
|
2318
2476
|
}
|
|
2319
2477
|
/**
|
|
2320
|
-
*
|
|
2321
|
-
*
|
|
2322
|
-
*
|
|
2323
|
-
* @param {
|
|
2324
|
-
* @
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2478
|
+
* Passes the email code obtained from the user for verification.
|
|
2479
|
+
* @deprecated
|
|
2480
|
+
* @param {Object} opts the options object
|
|
2481
|
+
* @param {string} verificationCode the six-digit code to check
|
|
2482
|
+
* @returns {string} the web auth url for creating a new credential
|
|
2483
|
+
*/
|
|
2484
|
+
verifyEmail(_0) {
|
|
2485
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2486
|
+
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
2487
|
+
return this.getSetUpBiometricsURL();
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
/** @deprecated */
|
|
2491
|
+
verifyExternalWallet(_0) {
|
|
2328
2492
|
return __async(this, arguments, function* ({
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
sessionId
|
|
2337
|
-
});
|
|
2338
|
-
if (shouldOpenPopup) {
|
|
2339
|
-
this.platformUtils.openPopup(link);
|
|
2340
|
-
}
|
|
2341
|
-
return link;
|
|
2493
|
+
address,
|
|
2494
|
+
signedMessage,
|
|
2495
|
+
cosmosPublicKeyHex,
|
|
2496
|
+
cosmosSigner
|
|
2497
|
+
}) {
|
|
2498
|
+
yield this.ctx.client.verifyExternalWallet(this.userId, { address, signedMessage, cosmosPublicKeyHex, cosmosSigner });
|
|
2499
|
+
return this.getSetUpBiometricsURL();
|
|
2342
2500
|
});
|
|
2343
2501
|
}
|
|
2344
2502
|
/**
|
|
2345
|
-
*
|
|
2346
|
-
*
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
});
|
|
2356
|
-
return session;
|
|
2503
|
+
* Passes the phone code obtained from the user for verification.
|
|
2504
|
+
* @deprecated
|
|
2505
|
+
* @param {Object} opts the options object
|
|
2506
|
+
* @param {string} verificationCode the six-digit code to check
|
|
2507
|
+
* @returns {string} the web auth url for creating a new credential
|
|
2508
|
+
*/
|
|
2509
|
+
verifyPhone(_0) {
|
|
2510
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2511
|
+
yield this.ctx.client.verifyPhone(this.userId, { verificationCode });
|
|
2512
|
+
return this.getSetUpBiometricsURLForPhone();
|
|
2357
2513
|
});
|
|
2358
2514
|
}
|
|
2359
2515
|
/**
|
|
2360
|
-
*
|
|
2361
|
-
*
|
|
2362
|
-
* @
|
|
2363
|
-
* @
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
const
|
|
2369
|
-
|
|
2516
|
+
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
2517
|
+
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
2518
|
+
* @deprecated
|
|
2519
|
+
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
2520
|
+
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
2521
|
+
*/
|
|
2522
|
+
verifyTelegram(authObject) {
|
|
2523
|
+
return __async(this, null, function* () {
|
|
2524
|
+
const res = yield this.ctx.client.verifyTelegram(authObject);
|
|
2525
|
+
if (res.isValid) {
|
|
2526
|
+
const { userId, telegramUserId } = res;
|
|
2527
|
+
const { photo_url: pfpUrl, username, first_name: firstName, last_name: lastName } = authObject;
|
|
2528
|
+
yield this.setAuth(
|
|
2529
|
+
{ telegramUserId },
|
|
2530
|
+
{
|
|
2531
|
+
extras: {
|
|
2532
|
+
pfpUrl,
|
|
2533
|
+
username,
|
|
2534
|
+
displayName: firstName ? `${firstName}${lastName ? ` ${lastName}` : ""}` : username ? `@${username}` : void 0
|
|
2535
|
+
},
|
|
2536
|
+
userId
|
|
2537
|
+
}
|
|
2538
|
+
);
|
|
2539
|
+
yield this.touchSession(true);
|
|
2540
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2541
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
return res;
|
|
2370
2545
|
});
|
|
2371
2546
|
}
|
|
2372
2547
|
/**
|
|
2373
|
-
*
|
|
2374
|
-
* @
|
|
2375
|
-
* @param {
|
|
2376
|
-
* @param {
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
id: share.walletId,
|
|
2390
|
-
signer
|
|
2391
|
-
};
|
|
2392
|
-
});
|
|
2393
|
-
yield this.deleteLoginEncryptionKeyPair();
|
|
2394
|
-
yield this.populateWalletAddresses();
|
|
2395
|
-
yield this.touchSession(!skipSessionRefresh);
|
|
2548
|
+
* Performs 2FA verification.
|
|
2549
|
+
* @deprecated
|
|
2550
|
+
* @param {Object} opts the options object
|
|
2551
|
+
* @param {string} opts.email the email to use for performing a 2FA verification.
|
|
2552
|
+
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
2553
|
+
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
2554
|
+
*/
|
|
2555
|
+
verify2FA(_0) {
|
|
2556
|
+
return __async(this, arguments, function* ({ email, verificationCode }) {
|
|
2557
|
+
const res = yield this.ctx.client.verify2FA(email, verificationCode);
|
|
2558
|
+
return {
|
|
2559
|
+
initiatedAt: res.data.initiatedAt,
|
|
2560
|
+
status: res.data.status,
|
|
2561
|
+
userId: res.data.userId,
|
|
2562
|
+
wallets: res.data.wallets
|
|
2563
|
+
};
|
|
2396
2564
|
});
|
|
2397
2565
|
}
|
|
2398
2566
|
/**
|
|
2399
|
-
*
|
|
2400
|
-
* @
|
|
2401
|
-
* @param {
|
|
2402
|
-
* @param {string} opts.
|
|
2403
|
-
* @param {
|
|
2404
|
-
* @param {
|
|
2405
|
-
* @returns {
|
|
2406
|
-
|
|
2407
|
-
|
|
2567
|
+
* Performs 2FA verification.
|
|
2568
|
+
* @deprecated
|
|
2569
|
+
* @param {Object} opts the options object
|
|
2570
|
+
* @param {string} opts.phone the phone number
|
|
2571
|
+
* @param {string} opts.countryCode - the country code
|
|
2572
|
+
* @param {string} opts.verificationCode - verification code to received via 2FA.
|
|
2573
|
+
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
2574
|
+
*/
|
|
2575
|
+
verify2FAForPhone(_0) {
|
|
2408
2576
|
return __async(this, arguments, function* ({
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
skipBiometricShareCreation = false,
|
|
2412
|
-
forceRefresh = false
|
|
2577
|
+
phone,
|
|
2578
|
+
verificationCode
|
|
2413
2579
|
}) {
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2580
|
+
const res = yield this.ctx.client.verify2FAForPhone(phone, verificationCode);
|
|
2581
|
+
return {
|
|
2582
|
+
initiatedAt: res.data.initiatedAt,
|
|
2583
|
+
status: res.data.status,
|
|
2584
|
+
userId: res.data.userId,
|
|
2585
|
+
wallets: res.data.wallets
|
|
2586
|
+
};
|
|
2587
|
+
});
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Sets up two-factor authentication for the current user.
|
|
2591
|
+
* @deprecated
|
|
2592
|
+
* @returns {string} uri - uri to use for setting up 2FA
|
|
2593
|
+
* */
|
|
2594
|
+
setup2FA() {
|
|
2595
|
+
return __async(this, null, function* () {
|
|
2596
|
+
const res = yield this.ctx.client.setup2FA(this.userId);
|
|
2597
|
+
return {
|
|
2598
|
+
uri: res.data.uri
|
|
2599
|
+
};
|
|
2600
|
+
});
|
|
2601
|
+
}
|
|
2602
|
+
/**
|
|
2603
|
+
* Enables 2FA.
|
|
2604
|
+
* @deprecated
|
|
2605
|
+
* @param {Object} opts the options object
|
|
2606
|
+
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
2607
|
+
*/
|
|
2608
|
+
enable2FA(_0) {
|
|
2609
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2610
|
+
yield this.ctx.client.enable2FA(this.userId, verificationCode);
|
|
2611
|
+
});
|
|
2612
|
+
}
|
|
2613
|
+
/**
|
|
2614
|
+
* Determines if 2FA has been set up.
|
|
2615
|
+
* @deprecated
|
|
2616
|
+
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
2617
|
+
*/
|
|
2618
|
+
check2FAStatus() {
|
|
2619
|
+
return __async(this, null, function* () {
|
|
2620
|
+
if (!this.userId) {
|
|
2621
|
+
return { isSetup: false };
|
|
2417
2622
|
}
|
|
2418
|
-
const
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2623
|
+
const res = yield this.ctx.client.check2FAStatus(this.userId);
|
|
2624
|
+
return {
|
|
2625
|
+
isSetup: res.data.isSetup
|
|
2626
|
+
};
|
|
2627
|
+
});
|
|
2628
|
+
}
|
|
2629
|
+
/**
|
|
2630
|
+
* Resend a verification email for the current user.
|
|
2631
|
+
*/
|
|
2632
|
+
resendVerificationCode() {
|
|
2633
|
+
return __async(this, null, function* () {
|
|
2634
|
+
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
2635
|
+
userId: this.userId
|
|
2636
|
+
}, this.getVerificationEmailProps()));
|
|
2637
|
+
});
|
|
2638
|
+
}
|
|
2639
|
+
/**
|
|
2640
|
+
* Resend a verification SMS for the current user.
|
|
2641
|
+
* @deprecated
|
|
2642
|
+
*/
|
|
2643
|
+
resendVerificationCodeByPhone() {
|
|
2644
|
+
return __async(this, null, function* () {
|
|
2645
|
+
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
2646
|
+
userId: this.userId
|
|
2431
2647
|
});
|
|
2432
|
-
return recoveryShare;
|
|
2433
2648
|
});
|
|
2434
2649
|
}
|
|
2435
|
-
|
|
2650
|
+
/**
|
|
2651
|
+
* Returns a URL for setting up a new WebAuth passkey.
|
|
2652
|
+
* @deprecated
|
|
2653
|
+
* @param {Object} opts the options object
|
|
2654
|
+
* @param {string} opts.authType - the auth type to use
|
|
2655
|
+
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2656
|
+
* @returns {string} the URL
|
|
2657
|
+
*/
|
|
2658
|
+
getSetUpBiometricsURL() {
|
|
2659
|
+
return __async(this, arguments, function* ({
|
|
2660
|
+
authType = "email",
|
|
2661
|
+
isForNewDevice = false
|
|
2662
|
+
} = {}) {
|
|
2663
|
+
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2664
|
+
status: PublicKeyStatus.PENDING,
|
|
2665
|
+
type: PublicKeyType.WEB
|
|
2666
|
+
});
|
|
2667
|
+
return this.getWebAuthURLForCreate({
|
|
2668
|
+
authType,
|
|
2669
|
+
isForNewDevice,
|
|
2670
|
+
webAuthId: res.data.id,
|
|
2671
|
+
partnerId: res.data.partnerId
|
|
2672
|
+
});
|
|
2673
|
+
});
|
|
2674
|
+
}
|
|
2675
|
+
/**
|
|
2676
|
+
* Returns a URL for setting up a new WebAuth passkey for a phone number.
|
|
2677
|
+
* @deprecated
|
|
2678
|
+
* @param {Object} opts the options object
|
|
2679
|
+
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2680
|
+
* @returns {string} the URL
|
|
2681
|
+
*/
|
|
2682
|
+
getSetUpBiometricsURLForPhone() {
|
|
2683
|
+
return __async(this, arguments, function* ({
|
|
2684
|
+
isForNewDevice = false
|
|
2685
|
+
} = {}) {
|
|
2686
|
+
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2687
|
+
status: PublicKeyStatus.PENDING,
|
|
2688
|
+
type: PublicKeyType.WEB
|
|
2689
|
+
});
|
|
2690
|
+
return this.getWebAuthURLForCreate({
|
|
2691
|
+
authType: "phone",
|
|
2692
|
+
isForNewDevice,
|
|
2693
|
+
webAuthId: res.data.id,
|
|
2694
|
+
partnerId: res.data.partnerId
|
|
2695
|
+
});
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
/**
|
|
2699
|
+
* Returns a URL for setting up a new password.
|
|
2700
|
+
* @deprecated
|
|
2701
|
+
* @param {Object} opts the options object
|
|
2702
|
+
* @param {string} opts.authType - the auth type to use
|
|
2703
|
+
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2704
|
+
* @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
|
|
2705
|
+
* @returns {string} the URL
|
|
2706
|
+
*/
|
|
2707
|
+
getSetupPasswordURL() {
|
|
2708
|
+
return __async(this, arguments, function* ({
|
|
2709
|
+
authType = "email",
|
|
2710
|
+
isForNewDevice = false,
|
|
2711
|
+
theme
|
|
2712
|
+
} = {}) {
|
|
2713
|
+
const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
2714
|
+
status: PasswordStatus.PENDING
|
|
2715
|
+
});
|
|
2716
|
+
return this.getPasswordURLForCreate({
|
|
2717
|
+
authType,
|
|
2718
|
+
isForNewDevice,
|
|
2719
|
+
passwordId: res.data.id,
|
|
2720
|
+
partnerId: res.data.partnerId,
|
|
2721
|
+
theme
|
|
2722
|
+
});
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
/**
|
|
2726
|
+
* Checks if the current session is active.
|
|
2727
|
+
* @returns `true` if active, `false` otherwise
|
|
2728
|
+
*/
|
|
2729
|
+
isSessionActive() {
|
|
2436
2730
|
return __async(this, null, function* () {
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2731
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
2732
|
+
return true;
|
|
2733
|
+
}
|
|
2734
|
+
const { isAuthenticated } = yield this.touchSession();
|
|
2735
|
+
return !!isAuthenticated;
|
|
2736
|
+
});
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Checks if a session is active and a wallet exists.
|
|
2740
|
+
* @returns `true` if active, `false` otherwise
|
|
2741
|
+
**/
|
|
2742
|
+
isFullyLoggedIn() {
|
|
2743
|
+
return __async(this, null, function* () {
|
|
2744
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
2745
|
+
return true;
|
|
2746
|
+
}
|
|
2747
|
+
const isSessionActive = yield this.isSessionActive();
|
|
2748
|
+
return isSessionActive && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true);
|
|
2749
|
+
});
|
|
2750
|
+
}
|
|
2751
|
+
/** @deprecated */
|
|
2752
|
+
supportedAuthMethods(auth) {
|
|
2753
|
+
return __async(this, null, function* () {
|
|
2754
|
+
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
2755
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
2756
|
+
for (const type of supportedAuthMethods) {
|
|
2757
|
+
switch (type) {
|
|
2758
|
+
case "PASSWORD":
|
|
2759
|
+
authMethods.add(AuthMethod.PASSWORD);
|
|
2760
|
+
break;
|
|
2761
|
+
case "BIOMETRIC":
|
|
2762
|
+
authMethods.add(AuthMethod.PASSKEY);
|
|
2441
2763
|
break;
|
|
2442
|
-
}
|
|
2443
|
-
++maxPolls;
|
|
2444
|
-
const res = yield this.ctx.client.getWallets(this.userId);
|
|
2445
|
-
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
2446
|
-
if (wallet && wallet.address) {
|
|
2447
|
-
return;
|
|
2448
|
-
}
|
|
2449
|
-
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2450
|
-
} catch (err) {
|
|
2451
|
-
console.error(err);
|
|
2452
2764
|
}
|
|
2453
2765
|
}
|
|
2454
|
-
|
|
2766
|
+
return authMethods;
|
|
2455
2767
|
});
|
|
2456
2768
|
}
|
|
2457
2769
|
/**
|
|
2458
|
-
*
|
|
2459
|
-
*
|
|
2460
|
-
* @
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2770
|
+
* Get hints associated with the users stored biometrics.
|
|
2771
|
+
* @deprecated
|
|
2772
|
+
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
2773
|
+
*/
|
|
2774
|
+
getUserBiometricLocationHints() {
|
|
2775
|
+
return __async(this, null, function* () {
|
|
2776
|
+
const { auth } = this.assertIsAuthSet();
|
|
2777
|
+
return yield this.ctx.client.getBiometricLocationHints(auth);
|
|
2778
|
+
});
|
|
2779
|
+
}
|
|
2780
|
+
/**
|
|
2781
|
+
* Initiates a login.
|
|
2782
|
+
* @deprecated
|
|
2783
|
+
* @param {Object} opts the options object
|
|
2784
|
+
* @param {String} opts.email - the email to login with
|
|
2785
|
+
* @param {boolean} opts.useShortURL - whether to shorten the link
|
|
2786
|
+
* @returns - the WebAuth URL for logging in
|
|
2464
2787
|
**/
|
|
2465
|
-
|
|
2788
|
+
initiateUserLogin(_e) {
|
|
2466
2789
|
return __async(this, null, function* () {
|
|
2467
|
-
|
|
2468
|
-
|
|
2790
|
+
var _f = _e, { useShortUrl = false } = _f, auth = __objRest(_f, ["useShortUrl"]);
|
|
2791
|
+
const authInfo = yield this.setAuth(auth);
|
|
2792
|
+
if (!authInfo) {
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2795
|
+
const { partnerId, sessionId } = yield this.touchSession(true);
|
|
2796
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2797
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2798
|
+
}
|
|
2799
|
+
const webAuthLoginURL = yield this.getWebAuthURLForLogin({
|
|
2800
|
+
authType: authInfo.authType,
|
|
2801
|
+
sessionId,
|
|
2802
|
+
partnerId,
|
|
2803
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
2804
|
+
});
|
|
2805
|
+
if (!useShortUrl) {
|
|
2806
|
+
return webAuthLoginURL;
|
|
2807
|
+
}
|
|
2808
|
+
return this.shortenLoginLink(webAuthLoginURL);
|
|
2809
|
+
});
|
|
2810
|
+
}
|
|
2811
|
+
/**
|
|
2812
|
+
* Initiates a login.
|
|
2813
|
+
* @deprecated
|
|
2814
|
+
* @param email - the email to login with
|
|
2815
|
+
* @returns - a set of supported auth methods for the user
|
|
2816
|
+
**/
|
|
2817
|
+
initiateUserLoginV2(auth) {
|
|
2818
|
+
return __async(this, null, function* () {
|
|
2819
|
+
let authInfo = __privateGet(this, _authInfo);
|
|
2820
|
+
if (!authInfo || JSON.stringify(authInfo.auth) !== JSON.stringify(auth)) {
|
|
2821
|
+
authInfo = yield this.setAuth(auth);
|
|
2822
|
+
}
|
|
2823
|
+
if (!authInfo) {
|
|
2824
|
+
return;
|
|
2825
|
+
}
|
|
2826
|
+
yield this.touchSession(true);
|
|
2827
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2828
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2829
|
+
}
|
|
2830
|
+
return yield this.supportedAuthMethods(authInfo.auth);
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
/**
|
|
2834
|
+
* Initiates a login.
|
|
2835
|
+
* @deprecated
|
|
2836
|
+
* @param opts the options object
|
|
2837
|
+
* @param opts.phone the phone number
|
|
2838
|
+
* @param opts.countryCode the country code
|
|
2839
|
+
* @param opts.useShortURL - whether to shorten the link
|
|
2840
|
+
* @returns - the WebAuth URL for logging in
|
|
2841
|
+
**/
|
|
2842
|
+
initiateUserLoginForPhone(_g) {
|
|
2843
|
+
return __async(this, null, function* () {
|
|
2844
|
+
var _h = _g, {
|
|
2845
|
+
useShortUrl = false
|
|
2846
|
+
} = _h, auth = __objRest(_h, [
|
|
2847
|
+
"useShortUrl"
|
|
2848
|
+
]);
|
|
2849
|
+
yield this.setAuth(auth);
|
|
2850
|
+
const { sessionId, partnerId } = yield this.touchSession(true);
|
|
2851
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2852
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2853
|
+
}
|
|
2854
|
+
const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
|
|
2855
|
+
sessionId,
|
|
2856
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
2857
|
+
partnerId
|
|
2858
|
+
});
|
|
2859
|
+
if (!useShortUrl) {
|
|
2860
|
+
return webAuthLoginURL;
|
|
2861
|
+
}
|
|
2862
|
+
return this.shortenLoginLink(webAuthLoginURL);
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2865
|
+
/**
|
|
2866
|
+
* @deprecated
|
|
2867
|
+
* Waits for the session to be active.
|
|
2868
|
+
**/
|
|
2869
|
+
waitForAccountCreation() {
|
|
2870
|
+
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
2871
|
+
yield this.touchSession();
|
|
2872
|
+
if (!this.isExternalWalletAuth) {
|
|
2873
|
+
this.externalWallets = {};
|
|
2874
|
+
}
|
|
2875
|
+
this.isAwaitingAccountCreation = true;
|
|
2876
|
+
while (this.isAwaitingAccountCreation) {
|
|
2469
2877
|
try {
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2878
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2879
|
+
if (yield this.isSessionActive()) {
|
|
2880
|
+
this.isAwaitingAccountCreation = false;
|
|
2881
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
2882
|
+
return true;
|
|
2883
|
+
} else {
|
|
2884
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2885
|
+
this.isAwaitingAccountCreation = false;
|
|
2886
|
+
return false;
|
|
2887
|
+
}
|
|
2478
2888
|
}
|
|
2479
|
-
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2480
2889
|
} catch (err) {
|
|
2481
2890
|
console.error(err);
|
|
2482
2891
|
}
|
|
2483
2892
|
}
|
|
2484
|
-
|
|
2893
|
+
return false;
|
|
2894
|
+
});
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* @deprecated
|
|
2898
|
+
*/
|
|
2899
|
+
waitForPasskeyAndCreateWallet() {
|
|
2900
|
+
return __async(this, arguments, function* ({
|
|
2901
|
+
popupWindow
|
|
2902
|
+
} = {}) {
|
|
2903
|
+
yield this.waitForAccountCreation({ popupWindow });
|
|
2904
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2905
|
+
const pregenWallets = yield this.getPregenWalletsV2();
|
|
2906
|
+
let recoverySecret, walletIds = {};
|
|
2907
|
+
if (pregenWallets.length > 0) {
|
|
2908
|
+
recoverySecret = yield this.claimPregenWallets();
|
|
2909
|
+
walletIds = supportedWalletTypes.reduce((acc, { type }) => {
|
|
2910
|
+
var _a;
|
|
2911
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
2912
|
+
[type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
2913
|
+
});
|
|
2914
|
+
}, {});
|
|
2915
|
+
}
|
|
2916
|
+
const created = yield this.createWalletPerType();
|
|
2917
|
+
recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
|
|
2918
|
+
walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
|
|
2919
|
+
const resp = { walletIds, recoverySecret };
|
|
2920
|
+
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
2921
|
+
return resp;
|
|
2922
|
+
});
|
|
2923
|
+
}
|
|
2924
|
+
/**
|
|
2925
|
+
* Initiates a Farcaster login attempt and return the URI for the user to connect.
|
|
2926
|
+
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
2927
|
+
* @deprecated
|
|
2928
|
+
* @return {string} the Farcaster connect URI
|
|
2929
|
+
*/
|
|
2930
|
+
getFarcasterConnectURL() {
|
|
2931
|
+
return __async(this, null, function* () {
|
|
2932
|
+
yield this.logout();
|
|
2933
|
+
yield this.touchSession(true);
|
|
2934
|
+
const {
|
|
2935
|
+
data: { connect_uri }
|
|
2936
|
+
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
2937
|
+
return connect_uri;
|
|
2938
|
+
});
|
|
2939
|
+
}
|
|
2940
|
+
/**
|
|
2941
|
+
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
2942
|
+
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
2943
|
+
* @deprecated
|
|
2944
|
+
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
2945
|
+
*/
|
|
2946
|
+
waitForFarcasterStatus() {
|
|
2947
|
+
return __async(this, null, function* () {
|
|
2948
|
+
this.isAwaitingFarcaster = true;
|
|
2949
|
+
while (this.isAwaitingFarcaster) {
|
|
2950
|
+
try {
|
|
2951
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2952
|
+
const res = yield this.ctx.client.getFarcasterAuthStatus();
|
|
2953
|
+
if (res.data.state === "completed") {
|
|
2954
|
+
const { userId, userExists, username, pfpUrl } = res.data;
|
|
2955
|
+
yield this.setAuth(
|
|
2956
|
+
{ farcasterUsername: username },
|
|
2957
|
+
{ extras: { pfpUrl, username, displayName: username }, userId }
|
|
2958
|
+
);
|
|
2959
|
+
return {
|
|
2960
|
+
userId,
|
|
2961
|
+
userExists,
|
|
2962
|
+
username,
|
|
2963
|
+
pfpUrl
|
|
2964
|
+
};
|
|
2965
|
+
}
|
|
2966
|
+
} catch (err) {
|
|
2967
|
+
console.error(err);
|
|
2968
|
+
this.isAwaitingFarcaster = false;
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
});
|
|
2972
|
+
}
|
|
2973
|
+
/**
|
|
2974
|
+
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
2975
|
+
* @deprecated
|
|
2976
|
+
* @param {Object} opts the options object
|
|
2977
|
+
* @param {OAuthMethod} opts.method the third-party service to use for OAuth.
|
|
2978
|
+
* @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
|
|
2979
|
+
* @returns {string} the URL for the user to log in with OAuth.
|
|
2980
|
+
*/
|
|
2981
|
+
getOAuthURL(_0) {
|
|
2982
|
+
return __async(this, arguments, function* ({ method, deeplinkUrl }) {
|
|
2983
|
+
yield this.logout();
|
|
2984
|
+
const { sessionLookupId } = yield this.touchSession(true);
|
|
2985
|
+
return constructUrl({
|
|
2986
|
+
base: method === OAuthMethod.TELEGRAM ? getPortalBaseURL(this.ctx, true) : getBaseOAuthUrl(this.ctx.env),
|
|
2987
|
+
path: `/auth/${method.toLowerCase()}`,
|
|
2988
|
+
params: {
|
|
2989
|
+
apiKey: this.ctx.apiKey,
|
|
2990
|
+
sessionLookupId,
|
|
2991
|
+
deeplinkUrl
|
|
2992
|
+
}
|
|
2993
|
+
});
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2996
|
+
/**
|
|
2997
|
+
* Awaits the response from a user's attempt to log in with OAuth.
|
|
2998
|
+
* If successful, this returns the user's email address and indicates whether the user already exists.
|
|
2999
|
+
* @deprecated
|
|
3000
|
+
* @param {Object} opts the options object.
|
|
3001
|
+
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
3002
|
+
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
3003
|
+
*/
|
|
3004
|
+
waitForOAuth() {
|
|
3005
|
+
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
3006
|
+
this.isAwaitingOAuth = true;
|
|
3007
|
+
while (this.isAwaitingOAuth) {
|
|
3008
|
+
try {
|
|
3009
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
3010
|
+
return { isError: true, userExists: false };
|
|
3011
|
+
}
|
|
3012
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3013
|
+
if (this.isAwaitingOAuth) {
|
|
3014
|
+
const { userId, email } = yield this.touchSession();
|
|
3015
|
+
if (!!userId) {
|
|
3016
|
+
if (!this.loginEncryptionKeyPair) {
|
|
3017
|
+
yield this.setLoginEncryptionKeyPair();
|
|
3018
|
+
}
|
|
3019
|
+
yield this.setUserId(userId);
|
|
3020
|
+
yield this.setEmail(email);
|
|
3021
|
+
this.isAwaitingOAuth = false;
|
|
3022
|
+
return {
|
|
3023
|
+
userExists: true,
|
|
3024
|
+
email
|
|
3025
|
+
};
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
} catch (err) {
|
|
3029
|
+
console.error(err);
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
return { userExists: false };
|
|
3033
|
+
});
|
|
3034
|
+
}
|
|
3035
|
+
/**
|
|
3036
|
+
* Waits for the session to be active and sets up the user.
|
|
3037
|
+
* @deprecated
|
|
3038
|
+
* @param {Object} opts the options object
|
|
3039
|
+
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
3040
|
+
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
3041
|
+
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
3042
|
+
**/
|
|
3043
|
+
waitForLoginAndSetup() {
|
|
3044
|
+
return __async(this, arguments, function* ({
|
|
3045
|
+
popupWindow,
|
|
3046
|
+
skipSessionRefresh = false
|
|
3047
|
+
} = {}) {
|
|
3048
|
+
var _a;
|
|
3049
|
+
if (!this.isExternalWalletAuth) {
|
|
3050
|
+
this.externalWallets = {};
|
|
3051
|
+
}
|
|
3052
|
+
this.isAwaitingLogin = true;
|
|
3053
|
+
while (this.isAwaitingLogin) {
|
|
3054
|
+
let session;
|
|
3055
|
+
try {
|
|
3056
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3057
|
+
session = yield this.touchSession();
|
|
3058
|
+
if (!session.isAuthenticated) {
|
|
3059
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
3060
|
+
const resp2 = { isComplete: false, isError: true };
|
|
3061
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
3062
|
+
return resp2;
|
|
3063
|
+
}
|
|
3064
|
+
continue;
|
|
3065
|
+
}
|
|
3066
|
+
session = yield this.userSetupAfterLogin();
|
|
3067
|
+
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
3068
|
+
if (!needsWallet) {
|
|
3069
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
3070
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
3071
|
+
const resp2 = { isComplete: false, isError: true };
|
|
3072
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
3073
|
+
return resp2;
|
|
3074
|
+
} else {
|
|
3075
|
+
continue;
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
3080
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
3081
|
+
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
3082
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
3083
|
+
yield this.claimPregenWallets();
|
|
3084
|
+
const resp2 = {
|
|
3085
|
+
isComplete: true,
|
|
3086
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
3087
|
+
partnerId: session.partnerId
|
|
3088
|
+
};
|
|
3089
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
|
|
3090
|
+
return resp2;
|
|
3091
|
+
}
|
|
3092
|
+
} catch (err) {
|
|
3093
|
+
console.error(err);
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
const resp = { isComplete: false };
|
|
3097
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp, "exitted login without setting up user");
|
|
3098
|
+
return resp;
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
/**
|
|
3102
|
+
* Updates the session with the user management server, possibly
|
|
3103
|
+
* opening a popup to refresh the session.
|
|
3104
|
+
*
|
|
3105
|
+
* @param {Object} opts the options object.
|
|
3106
|
+
* @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
|
|
3107
|
+
* @returns a URL for the user to reauthenticate.
|
|
3108
|
+
**/
|
|
3109
|
+
refreshSession() {
|
|
3110
|
+
return __async(this, arguments, function* ({
|
|
3111
|
+
shouldOpenPopup = false
|
|
3112
|
+
} = {}) {
|
|
3113
|
+
const { sessionId } = yield this.touchSession(true);
|
|
3114
|
+
if (!this.loginEncryptionKeyPair) {
|
|
3115
|
+
yield this.setLoginEncryptionKeyPair();
|
|
3116
|
+
}
|
|
3117
|
+
const link = yield this.getWebAuthURLForLogin({
|
|
3118
|
+
sessionId,
|
|
3119
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
3120
|
+
});
|
|
3121
|
+
if (shouldOpenPopup) {
|
|
3122
|
+
this.platformUtils.openPopup(link);
|
|
3123
|
+
}
|
|
3124
|
+
return link;
|
|
3125
|
+
});
|
|
3126
|
+
}
|
|
3127
|
+
/**
|
|
3128
|
+
* Call this method after login to ensure that the user ID is set
|
|
3129
|
+
* internally.
|
|
3130
|
+
**/
|
|
3131
|
+
userSetupAfterLogin() {
|
|
3132
|
+
return __async(this, null, function* () {
|
|
3133
|
+
const session = yield this.touchSession();
|
|
3134
|
+
yield this.setUserId(session.userId);
|
|
3135
|
+
if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
|
|
3136
|
+
yield this.setCurrentWalletIds(session.currentWalletIds, {
|
|
3137
|
+
sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
|
|
3138
|
+
});
|
|
3139
|
+
return session;
|
|
3140
|
+
});
|
|
3141
|
+
}
|
|
3142
|
+
/**
|
|
3143
|
+
* Get transmission shares associated with session.
|
|
3144
|
+
* @param {Object} opts the options object.
|
|
3145
|
+
* @param {boolean} opts.isForNewDevice - true if this device is registering.
|
|
3146
|
+
* @returns - transmission keyshares.
|
|
3147
|
+
**/
|
|
3148
|
+
getTransmissionKeyShares() {
|
|
3149
|
+
return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
|
|
3150
|
+
const session = yield this.touchSession();
|
|
3151
|
+
const sessionLookupId = isForNewDevice ? `${session.sessionLookupId}-new-device` : session.sessionLookupId;
|
|
3152
|
+
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
/**
|
|
3156
|
+
* Call this method after login to perform setup.
|
|
3157
|
+
* @param {Object} opts the options object.
|
|
3158
|
+
* @param {any[]} opts.temporaryShares optional temporary shares to use for decryption.
|
|
3159
|
+
* @param {boolean} [opts.skipSessionRefresh] - whether or not to skip refreshing the session.
|
|
3160
|
+
**/
|
|
3161
|
+
setupAfterLogin() {
|
|
3162
|
+
return __async(this, arguments, function* ({
|
|
3163
|
+
temporaryShares,
|
|
3164
|
+
skipSessionRefresh = false
|
|
3165
|
+
} = {}) {
|
|
3166
|
+
if (!temporaryShares) {
|
|
3167
|
+
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
3168
|
+
}
|
|
3169
|
+
temporaryShares.forEach((share) => {
|
|
3170
|
+
const signer = decryptWithPrivateKey(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
3171
|
+
this.wallets[share.walletId] = {
|
|
3172
|
+
id: share.walletId,
|
|
3173
|
+
signer
|
|
3174
|
+
};
|
|
3175
|
+
});
|
|
3176
|
+
yield this.deleteLoginEncryptionKeyPair();
|
|
3177
|
+
yield this.populateWalletAddresses();
|
|
3178
|
+
yield this.touchSession(!skipSessionRefresh);
|
|
3179
|
+
});
|
|
3180
|
+
}
|
|
3181
|
+
/**
|
|
3182
|
+
* Distributes a new wallet recovery share.
|
|
3183
|
+
* @param {Object} opts the options object.
|
|
3184
|
+
* @param {string} opts.walletId the wallet to distribute the recovery share for.
|
|
3185
|
+
* @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
|
|
3186
|
+
* @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
|
|
3187
|
+
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
3188
|
+
* @returns {string} the recovery share.
|
|
3189
|
+
**/
|
|
3190
|
+
distributeNewWalletShare(_0) {
|
|
3191
|
+
return __async(this, arguments, function* ({
|
|
3192
|
+
walletId,
|
|
3193
|
+
userShare,
|
|
3194
|
+
skipBiometricShareCreation = false,
|
|
3195
|
+
forceRefresh = false
|
|
3196
|
+
}) {
|
|
3197
|
+
let userSigner = userShare;
|
|
3198
|
+
if (!userSigner) {
|
|
3199
|
+
userSigner = this.wallets[walletId].signer;
|
|
3200
|
+
}
|
|
3201
|
+
const recoveryShare = skipBiometricShareCreation ? yield sendRecoveryForShare({
|
|
3202
|
+
ctx: this.ctx,
|
|
3203
|
+
userId: this.userId,
|
|
3204
|
+
walletId,
|
|
3205
|
+
userSigner,
|
|
3206
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3207
|
+
forceRefresh
|
|
3208
|
+
}) : yield distributeNewShare({
|
|
3209
|
+
ctx: this.ctx,
|
|
3210
|
+
userId: this.userId,
|
|
3211
|
+
walletId,
|
|
3212
|
+
userShare: userSigner,
|
|
3213
|
+
emailProps: this.getBackupKitEmailProps()
|
|
3214
|
+
});
|
|
3215
|
+
return recoveryShare;
|
|
3216
|
+
});
|
|
3217
|
+
}
|
|
3218
|
+
waitForWalletAddress(walletId) {
|
|
3219
|
+
return __async(this, null, function* () {
|
|
3220
|
+
let maxPolls = 0;
|
|
3221
|
+
while (true) {
|
|
3222
|
+
try {
|
|
3223
|
+
if (maxPolls === 10) {
|
|
3224
|
+
break;
|
|
3225
|
+
}
|
|
3226
|
+
++maxPolls;
|
|
3227
|
+
const res = yield this.ctx.client.getWallets(this.userId);
|
|
3228
|
+
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
3229
|
+
if (wallet && wallet.address) {
|
|
3230
|
+
return;
|
|
3231
|
+
}
|
|
3232
|
+
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
3233
|
+
} catch (err) {
|
|
3234
|
+
console.error(err);
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
throw new Error("timed out waiting for wallet address");
|
|
3238
|
+
});
|
|
3239
|
+
}
|
|
3240
|
+
/**
|
|
3241
|
+
* Waits for a pregen wallet address to be created.
|
|
3242
|
+
*
|
|
3243
|
+
* @param pregenIdentifier - the identifier of the user the pregen wallet is associated with.
|
|
3244
|
+
* @param walletId - the wallet id
|
|
3245
|
+
* @param pregenIdentifierType - the identifier type of the user the pregen wallet is associated with.
|
|
3246
|
+
* @returns - recovery share.
|
|
3247
|
+
**/
|
|
3248
|
+
waitForPregenWalletAddress(walletId) {
|
|
3249
|
+
return __async(this, null, function* () {
|
|
3250
|
+
let maxPolls = 0;
|
|
3251
|
+
while (true) {
|
|
3252
|
+
try {
|
|
3253
|
+
if (maxPolls === 10) {
|
|
3254
|
+
break;
|
|
3255
|
+
}
|
|
3256
|
+
++maxPolls;
|
|
3257
|
+
const res = yield this.getPregenWalletsV2();
|
|
3258
|
+
const wallet = res.find((w) => w.id === walletId);
|
|
3259
|
+
if (wallet && wallet.address) {
|
|
3260
|
+
return;
|
|
3261
|
+
}
|
|
3262
|
+
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
3263
|
+
} catch (err) {
|
|
3264
|
+
console.error(err);
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
throw new Error("timed out waiting for wallet address");
|
|
3268
|
+
});
|
|
3269
|
+
}
|
|
3270
|
+
/**
|
|
3271
|
+
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
3272
|
+
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
3273
|
+
* object that are not already present. This is automatically called upon account creation to ensure that
|
|
3274
|
+
* the user has a wallet of each required type.
|
|
3275
|
+
*
|
|
3276
|
+
* @param {Object} [opts] the options object.
|
|
3277
|
+
* @param {boolean} [opts.skipDistribute] if `true`, the wallets' recovery share will not be distributed.
|
|
3278
|
+
* @param {WalletType[]} [opts.types] the types of wallets to create.
|
|
3279
|
+
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
3280
|
+
**/
|
|
3281
|
+
createWalletPerType() {
|
|
3282
|
+
return __async(this, arguments, function* ({
|
|
3283
|
+
skipDistribute = false,
|
|
3284
|
+
types
|
|
3285
|
+
} = {}) {
|
|
3286
|
+
const wallets = [];
|
|
3287
|
+
const walletIds = {};
|
|
3288
|
+
let recoverySecret;
|
|
3289
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
3290
|
+
const [wallet, recoveryShare] = yield this.createWallet({ type, skipDistribute });
|
|
3291
|
+
wallets.push(wallet);
|
|
3292
|
+
getEquivalentTypes(type).filter((t) => !!this.isWalletTypeEnabled[t]).forEach((t) => {
|
|
3293
|
+
walletIds[t] = [wallet.id];
|
|
3294
|
+
});
|
|
3295
|
+
if (recoveryShare) {
|
|
3296
|
+
recoverySecret = recoveryShare;
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
return { wallets, walletIds, recoverySecret };
|
|
3300
|
+
});
|
|
3301
|
+
}
|
|
3302
|
+
/**
|
|
3303
|
+
* Refresh the current user share for a wallet.
|
|
3304
|
+
*
|
|
3305
|
+
* @param {Object} opts the options object.
|
|
3306
|
+
* @param {string} opts.walletId the wallet id to refresh.
|
|
3307
|
+
* @param {string} opts.share the current user share.
|
|
3308
|
+
* @param {string} [opts.oldPartnerId] the current partner id.
|
|
3309
|
+
* @param {string} [opts.newPartnerId] the new partner id to set, if any.
|
|
3310
|
+
* @param {string} [opts.keyShareProtocolId]
|
|
3311
|
+
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
3312
|
+
* @returns {Object} the new user share and recovery secret.
|
|
3313
|
+
**/
|
|
3314
|
+
refreshShare(_0) {
|
|
3315
|
+
return __async(this, arguments, function* ({
|
|
3316
|
+
walletId,
|
|
3317
|
+
share,
|
|
3318
|
+
oldPartnerId,
|
|
3319
|
+
newPartnerId,
|
|
3320
|
+
keyShareProtocolId,
|
|
3321
|
+
redistributeBackupEncryptedShares
|
|
3322
|
+
}) {
|
|
3323
|
+
const { signer, protocolId } = yield this.platformUtils.refresh(
|
|
3324
|
+
this.ctx,
|
|
3325
|
+
this.retrieveSessionCookie(),
|
|
3326
|
+
this.userId,
|
|
3327
|
+
walletId,
|
|
3328
|
+
share,
|
|
3329
|
+
oldPartnerId,
|
|
3330
|
+
newPartnerId,
|
|
3331
|
+
keyShareProtocolId
|
|
3332
|
+
);
|
|
3333
|
+
const recoverySecret = yield distributeNewShare({
|
|
3334
|
+
ctx: this.ctx,
|
|
3335
|
+
userId: this.userId,
|
|
3336
|
+
walletId,
|
|
3337
|
+
userShare: signer,
|
|
3338
|
+
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
3339
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3340
|
+
partnerId: newPartnerId,
|
|
3341
|
+
protocolId
|
|
3342
|
+
});
|
|
3343
|
+
return { signer, recoverySecret, protocolId };
|
|
3344
|
+
});
|
|
3345
|
+
}
|
|
3346
|
+
/**
|
|
3347
|
+
* Creates a new wallet.
|
|
3348
|
+
* @param {Object} opts the options object.
|
|
3349
|
+
* @param {WalletType} opts.type the type of wallet to create.
|
|
3350
|
+
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
3351
|
+
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3352
|
+
**/
|
|
3353
|
+
createWallet() {
|
|
3354
|
+
return __async(this, arguments, function* ({
|
|
3355
|
+
type: _type,
|
|
3356
|
+
skipDistribute = false
|
|
3357
|
+
} = {}) {
|
|
3358
|
+
var _a, _b;
|
|
3359
|
+
this.requireApiKey();
|
|
3360
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3361
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
3362
|
+
_type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
3363
|
+
);
|
|
3364
|
+
let signer;
|
|
3365
|
+
let wallet;
|
|
3366
|
+
let keygenRes;
|
|
3367
|
+
switch (walletType) {
|
|
3368
|
+
case WalletType2.SOLANA: {
|
|
3369
|
+
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
3370
|
+
this.ctx,
|
|
3371
|
+
this.userId,
|
|
3372
|
+
this.retrieveSessionCookie(),
|
|
3373
|
+
this.getBackupKitEmailProps()
|
|
3374
|
+
);
|
|
3375
|
+
break;
|
|
3376
|
+
}
|
|
3377
|
+
default: {
|
|
3378
|
+
keygenRes = yield this.platformUtils.keygen(
|
|
3379
|
+
this.ctx,
|
|
3380
|
+
this.userId,
|
|
3381
|
+
walletType,
|
|
3382
|
+
null,
|
|
3383
|
+
this.retrieveSessionCookie(),
|
|
3384
|
+
this.getBackupKitEmailProps()
|
|
3385
|
+
);
|
|
3386
|
+
break;
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
const walletId = keygenRes.walletId;
|
|
3390
|
+
signer = keygenRes.signer;
|
|
3391
|
+
this.wallets[walletId] = {
|
|
3392
|
+
id: walletId,
|
|
3393
|
+
signer,
|
|
3394
|
+
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
3395
|
+
type: walletType
|
|
3396
|
+
};
|
|
3397
|
+
wallet = this.wallets[walletId];
|
|
3398
|
+
yield this.waitForWalletAddress(wallet.id);
|
|
3399
|
+
yield this.populateWalletAddresses();
|
|
3400
|
+
let recoveryShare = null;
|
|
3401
|
+
if (!skipDistribute) {
|
|
3402
|
+
recoveryShare = yield distributeNewShare({
|
|
3403
|
+
ctx: this.ctx,
|
|
3404
|
+
userId: this.userId,
|
|
3405
|
+
walletId: wallet.id,
|
|
3406
|
+
userShare: signer,
|
|
3407
|
+
emailProps: this.getBackupKitEmailProps()
|
|
3408
|
+
});
|
|
3409
|
+
}
|
|
3410
|
+
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
3411
|
+
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
3412
|
+
}));
|
|
3413
|
+
const walletNoSigner = __spreadValues({}, wallet);
|
|
3414
|
+
delete walletNoSigner.signer;
|
|
3415
|
+
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
3416
|
+
wallet: walletNoSigner,
|
|
3417
|
+
recoverySecret: recoveryShare
|
|
3418
|
+
});
|
|
3419
|
+
return [wallet, recoveryShare];
|
|
3420
|
+
});
|
|
3421
|
+
}
|
|
3422
|
+
/**
|
|
3423
|
+
* Creates a new pregenerated wallet.
|
|
3424
|
+
* @deprecated
|
|
3425
|
+
* @param {Object} opts the options object.
|
|
3426
|
+
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
3427
|
+
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
3428
|
+
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
3429
|
+
* @returns {Wallet} the created wallet.
|
|
3430
|
+
**/
|
|
3431
|
+
createPregenWallet(opts) {
|
|
3432
|
+
return __async(this, null, function* () {
|
|
3433
|
+
var _a, _b;
|
|
3434
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3435
|
+
const {
|
|
3436
|
+
type: _type = (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
|
|
3437
|
+
pregenIdentifier,
|
|
3438
|
+
pregenIdentifierType = "EMAIL"
|
|
3439
|
+
} = opts;
|
|
3440
|
+
this.requireApiKey();
|
|
3441
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
3442
|
+
_type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
3443
|
+
);
|
|
3444
|
+
let keygenRes;
|
|
3445
|
+
switch (walletType) {
|
|
3446
|
+
case WalletType2.SOLANA:
|
|
3447
|
+
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
3448
|
+
this.ctx,
|
|
3449
|
+
pregenIdentifier,
|
|
3450
|
+
pregenIdentifierType,
|
|
3451
|
+
this.retrieveSessionCookie()
|
|
3452
|
+
);
|
|
3453
|
+
break;
|
|
3454
|
+
default:
|
|
3455
|
+
keygenRes = yield this.platformUtils.preKeygen(
|
|
3456
|
+
this.ctx,
|
|
3457
|
+
void 0,
|
|
3458
|
+
pregenIdentifier,
|
|
3459
|
+
pregenIdentifierType,
|
|
3460
|
+
walletType,
|
|
3461
|
+
null,
|
|
3462
|
+
this.retrieveSessionCookie()
|
|
3463
|
+
);
|
|
3464
|
+
break;
|
|
3465
|
+
}
|
|
3466
|
+
const { signer, walletId } = keygenRes;
|
|
3467
|
+
this.wallets[walletId] = {
|
|
3468
|
+
id: walletId,
|
|
3469
|
+
signer,
|
|
3470
|
+
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
3471
|
+
type: walletType,
|
|
3472
|
+
isPregen: true,
|
|
3473
|
+
pregenIdentifier,
|
|
3474
|
+
pregenIdentifierType
|
|
3475
|
+
};
|
|
3476
|
+
yield this.waitForPregenWalletAddress(walletId);
|
|
3477
|
+
yield this.populatePregenWalletAddresses();
|
|
3478
|
+
return this.wallets[walletId];
|
|
3479
|
+
});
|
|
3480
|
+
}
|
|
3481
|
+
/**
|
|
3482
|
+
* Creates new pregenerated wallets for each desired type.
|
|
3483
|
+
* If no types are provided, this method will create one for each of the non-optional types
|
|
3484
|
+
* specified in the instance's `supportedWalletTypes` array that are not already present.
|
|
3485
|
+
* @deprecated
|
|
3486
|
+
* @param {Object} opts the options object.
|
|
3487
|
+
* @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
|
|
3488
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
3489
|
+
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
3490
|
+
* @returns {Wallet[]} an array containing the created wallets.
|
|
3491
|
+
**/
|
|
3492
|
+
createPregenWalletPerType(_0) {
|
|
3493
|
+
return __async(this, arguments, function* ({
|
|
3494
|
+
types,
|
|
3495
|
+
pregenIdentifier,
|
|
3496
|
+
pregenIdentifierType = "EMAIL"
|
|
3497
|
+
}) {
|
|
3498
|
+
const wallets = [];
|
|
3499
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
3500
|
+
const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
|
|
3501
|
+
wallets.push(wallet);
|
|
3502
|
+
}
|
|
3503
|
+
return wallets;
|
|
3504
|
+
});
|
|
3505
|
+
}
|
|
3506
|
+
/**
|
|
3507
|
+
* Claims a pregenerated wallet.
|
|
3508
|
+
* @deprecated
|
|
3509
|
+
* @param {Object} opts the options object.
|
|
3510
|
+
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
3511
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
3512
|
+
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3513
|
+
**/
|
|
3514
|
+
claimPregenWallets() {
|
|
3515
|
+
return __async(this, arguments, function* ({
|
|
3516
|
+
pregenIdentifier,
|
|
3517
|
+
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
3518
|
+
} = {}) {
|
|
3519
|
+
var _a;
|
|
3520
|
+
this.requireApiKey();
|
|
3521
|
+
const pregenWallets = pregenIdentifier && pregenIdentifierType ? yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType }) : yield this.getPregenWallets();
|
|
3522
|
+
if (pregenWallets.length === 0) {
|
|
3523
|
+
return void 0;
|
|
3524
|
+
}
|
|
3525
|
+
let newRecoverySecret;
|
|
3526
|
+
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
3527
|
+
userId: this.userId,
|
|
3528
|
+
walletIds: pregenWallets.map((w) => w.id)
|
|
3529
|
+
});
|
|
3530
|
+
for (const walletId of walletIds) {
|
|
3531
|
+
const wallet = this.wallets[walletId];
|
|
3532
|
+
let refreshedShare;
|
|
3533
|
+
if (wallet.scheme === WalletScheme2.ED25519) {
|
|
3534
|
+
const distributeRes = yield distributeNewShare({
|
|
3535
|
+
ctx: this.ctx,
|
|
3536
|
+
userId: this.userId,
|
|
3537
|
+
walletId: wallet.id,
|
|
3538
|
+
userShare: this.wallets[wallet.id].signer,
|
|
3539
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3540
|
+
partnerId: wallet.partnerId
|
|
3541
|
+
});
|
|
3542
|
+
if (distributeRes.length > 0) {
|
|
3543
|
+
newRecoverySecret = distributeRes;
|
|
3544
|
+
}
|
|
3545
|
+
} else {
|
|
3546
|
+
refreshedShare = yield this.refreshShare({
|
|
3547
|
+
walletId: wallet.id,
|
|
3548
|
+
share: this.wallets[wallet.id].signer,
|
|
3549
|
+
oldPartnerId: wallet.partnerId,
|
|
3550
|
+
newPartnerId: wallet.partnerId,
|
|
3551
|
+
redistributeBackupEncryptedShares: true
|
|
3552
|
+
});
|
|
3553
|
+
if (refreshedShare.recoverySecret) {
|
|
3554
|
+
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
|
|
3558
|
+
signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
|
|
3559
|
+
userId: this.userId,
|
|
3560
|
+
pregenIdentifier: void 0,
|
|
3561
|
+
pregenIdentifierType: void 0
|
|
3562
|
+
});
|
|
3563
|
+
const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
|
|
3564
|
+
delete walletNoSigner.signer;
|
|
3565
|
+
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
3566
|
+
wallet: walletNoSigner,
|
|
3567
|
+
recoverySecret: newRecoverySecret
|
|
3568
|
+
});
|
|
3569
|
+
}
|
|
3570
|
+
yield this.setWallets(this.wallets);
|
|
3571
|
+
return newRecoverySecret;
|
|
2485
3572
|
});
|
|
2486
3573
|
}
|
|
2487
3574
|
/**
|
|
2488
|
-
*
|
|
2489
|
-
*
|
|
2490
|
-
*
|
|
2491
|
-
*
|
|
2492
|
-
*
|
|
2493
|
-
* @param {
|
|
2494
|
-
* @param {boolean} [opts.skipDistribute] if `true`, the wallets' recovery share will not be distributed.
|
|
2495
|
-
* @param {WalletType[]} [opts.types] the types of wallets to create.
|
|
2496
|
-
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
3575
|
+
* Updates the identifier for a pregen wallet.
|
|
3576
|
+
* @deprecated
|
|
3577
|
+
* @param {Object} opts the options object.
|
|
3578
|
+
* @param {string} opts.walletId the pregen wallet ID
|
|
3579
|
+
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
3580
|
+
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
2497
3581
|
**/
|
|
2498
|
-
|
|
3582
|
+
updatePregenWalletIdentifier(_0) {
|
|
2499
3583
|
return __async(this, arguments, function* ({
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
3584
|
+
walletId,
|
|
3585
|
+
newPregenIdentifier,
|
|
3586
|
+
newPregenIdentifierType
|
|
3587
|
+
}) {
|
|
3588
|
+
this.requireApiKey();
|
|
3589
|
+
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
3590
|
+
pregenIdentifier: newPregenIdentifier,
|
|
3591
|
+
pregenIdentifierType: newPregenIdentifierType
|
|
3592
|
+
});
|
|
3593
|
+
if (!!this.wallets[walletId]) {
|
|
3594
|
+
this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3595
|
+
pregenIdentifier: newPregenIdentifier,
|
|
3596
|
+
pregenIdentifierType: newPregenIdentifierType
|
|
2511
3597
|
});
|
|
2512
|
-
|
|
2513
|
-
recoverySecret = recoveryShare;
|
|
2514
|
-
}
|
|
3598
|
+
yield this.setWallets(this.wallets);
|
|
2515
3599
|
}
|
|
2516
|
-
return { wallets, walletIds, recoverySecret };
|
|
2517
3600
|
});
|
|
2518
3601
|
}
|
|
2519
3602
|
/**
|
|
2520
|
-
*
|
|
2521
|
-
*
|
|
3603
|
+
* Checks if a pregen Wallet exists for the given identifier with the current partner.
|
|
3604
|
+
* @deprecated
|
|
2522
3605
|
* @param {Object} opts the options object.
|
|
2523
|
-
* @param {string} opts.
|
|
2524
|
-
* @param {
|
|
2525
|
-
* @
|
|
2526
|
-
* @param {string} [opts.newPartnerId] the new partner id to set, if any.
|
|
2527
|
-
* @param {string} [opts.keyShareProtocolId]
|
|
2528
|
-
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
2529
|
-
* @returns {Object} the new user share and recovery secret.
|
|
3606
|
+
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
3607
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
3608
|
+
* @returns {boolean} whether the pregen wallet exists
|
|
2530
3609
|
**/
|
|
2531
|
-
|
|
3610
|
+
hasPregenWallet(_0) {
|
|
2532
3611
|
return __async(this, arguments, function* ({
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
oldPartnerId,
|
|
2536
|
-
newPartnerId,
|
|
2537
|
-
keyShareProtocolId,
|
|
2538
|
-
redistributeBackupEncryptedShares
|
|
3612
|
+
pregenIdentifier,
|
|
3613
|
+
pregenIdentifierType
|
|
2539
3614
|
}) {
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
newPartnerId,
|
|
2548
|
-
keyShareProtocolId
|
|
2549
|
-
);
|
|
2550
|
-
const recoverySecret = yield distributeNewShare({
|
|
2551
|
-
ctx: this.ctx,
|
|
2552
|
-
userId: this.userId,
|
|
2553
|
-
walletId,
|
|
2554
|
-
userShare: signer,
|
|
2555
|
-
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
2556
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2557
|
-
partnerId: newPartnerId,
|
|
2558
|
-
protocolId
|
|
2559
|
-
});
|
|
2560
|
-
return { signer, recoverySecret, protocolId };
|
|
3615
|
+
this.requireApiKey();
|
|
3616
|
+
const res = yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType });
|
|
3617
|
+
const wallet = res.find((w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType);
|
|
3618
|
+
if (!wallet) {
|
|
3619
|
+
return false;
|
|
3620
|
+
}
|
|
3621
|
+
return true;
|
|
2561
3622
|
});
|
|
2562
3623
|
}
|
|
2563
3624
|
/**
|
|
2564
|
-
*
|
|
3625
|
+
* Get pregen wallets for the given identifier.
|
|
3626
|
+
* @deprecated
|
|
2565
3627
|
* @param {Object} opts the options object.
|
|
2566
|
-
* @param {
|
|
2567
|
-
* @param {
|
|
2568
|
-
* @returns {[
|
|
3628
|
+
* @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet
|
|
3629
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
3630
|
+
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
2569
3631
|
**/
|
|
2570
|
-
|
|
3632
|
+
getPregenWallets() {
|
|
2571
3633
|
return __async(this, arguments, function* ({
|
|
2572
|
-
|
|
2573
|
-
|
|
3634
|
+
pregenIdentifier,
|
|
3635
|
+
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
2574
3636
|
} = {}) {
|
|
2575
|
-
var _a, _b;
|
|
2576
3637
|
this.requireApiKey();
|
|
2577
|
-
const
|
|
2578
|
-
|
|
2579
|
-
|
|
3638
|
+
const res = yield this.ctx.client.getPregenWallets(
|
|
3639
|
+
pregenIdentifier && pregenIdentifierType ? { [pregenIdentifierType]: [pregenIdentifier] } : this.pregenIds,
|
|
3640
|
+
this.isPortal(),
|
|
3641
|
+
this.userId
|
|
2580
3642
|
);
|
|
2581
|
-
|
|
2582
|
-
let wallet;
|
|
2583
|
-
let keygenRes;
|
|
2584
|
-
switch (walletType) {
|
|
2585
|
-
case WalletType2.SOLANA: {
|
|
2586
|
-
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
2587
|
-
this.ctx,
|
|
2588
|
-
this.userId,
|
|
2589
|
-
this.retrieveSessionCookie(),
|
|
2590
|
-
this.getBackupKitEmailProps()
|
|
2591
|
-
);
|
|
2592
|
-
break;
|
|
2593
|
-
}
|
|
2594
|
-
default: {
|
|
2595
|
-
keygenRes = yield this.platformUtils.keygen(
|
|
2596
|
-
this.ctx,
|
|
2597
|
-
this.userId,
|
|
2598
|
-
walletType,
|
|
2599
|
-
null,
|
|
2600
|
-
this.retrieveSessionCookie(),
|
|
2601
|
-
this.getBackupKitEmailProps()
|
|
2602
|
-
);
|
|
2603
|
-
break;
|
|
2604
|
-
}
|
|
2605
|
-
}
|
|
2606
|
-
const walletId = keygenRes.walletId;
|
|
2607
|
-
signer = keygenRes.signer;
|
|
2608
|
-
this.wallets[walletId] = {
|
|
2609
|
-
id: walletId,
|
|
2610
|
-
signer,
|
|
2611
|
-
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
2612
|
-
type: walletType
|
|
2613
|
-
};
|
|
2614
|
-
wallet = this.wallets[walletId];
|
|
2615
|
-
yield this.waitForWalletAddress(wallet.id);
|
|
2616
|
-
yield this.populateWalletAddresses();
|
|
2617
|
-
let recoveryShare = null;
|
|
2618
|
-
if (!skipDistribute) {
|
|
2619
|
-
recoveryShare = yield distributeNewShare({
|
|
2620
|
-
ctx: this.ctx,
|
|
2621
|
-
userId: this.userId,
|
|
2622
|
-
walletId: wallet.id,
|
|
2623
|
-
userShare: signer,
|
|
2624
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2625
|
-
});
|
|
2626
|
-
}
|
|
2627
|
-
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
2628
|
-
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
2629
|
-
}));
|
|
2630
|
-
const walletNoSigner = __spreadValues({}, wallet);
|
|
2631
|
-
delete walletNoSigner.signer;
|
|
2632
|
-
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
2633
|
-
wallet: walletNoSigner,
|
|
2634
|
-
recoverySecret: recoveryShare
|
|
2635
|
-
});
|
|
2636
|
-
return [wallet, recoveryShare];
|
|
3643
|
+
return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
|
|
2637
3644
|
});
|
|
2638
3645
|
}
|
|
2639
3646
|
encodeWalletBase64(wallet) {
|
|
@@ -2671,7 +3678,9 @@ var _ParaCore = class _ParaCore {
|
|
|
2671
3678
|
}
|
|
2672
3679
|
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
2673
3680
|
return __async(this, null, function* () {
|
|
3681
|
+
const { id: partnerId } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2674
3682
|
return this.constructPortalUrl("txReview", {
|
|
3683
|
+
partnerId,
|
|
2675
3684
|
pathId: transactionId,
|
|
2676
3685
|
params: {
|
|
2677
3686
|
email: this.email,
|
|
@@ -2680,18 +3689,19 @@ var _ParaCore = class _ParaCore {
|
|
|
2680
3689
|
});
|
|
2681
3690
|
});
|
|
2682
3691
|
}
|
|
2683
|
-
getOnRampTransactionUrl(
|
|
3692
|
+
getOnRampTransactionUrl(_i) {
|
|
2684
3693
|
return __async(this, null, function* () {
|
|
2685
|
-
var
|
|
3694
|
+
var _j = _i, {
|
|
2686
3695
|
purchaseId,
|
|
2687
3696
|
providerKey
|
|
2688
|
-
} =
|
|
3697
|
+
} = _j, walletParams = __objRest(_j, [
|
|
2689
3698
|
"purchaseId",
|
|
2690
3699
|
"providerKey"
|
|
2691
3700
|
]);
|
|
2692
|
-
const { sessionId } = yield this.touchSession();
|
|
3701
|
+
const { partnerId, sessionId } = yield this.touchSession();
|
|
2693
3702
|
const [key, identifier] = extractWalletRef(walletParams);
|
|
2694
3703
|
return this.constructPortalUrl("onRamp", {
|
|
3704
|
+
partnerId,
|
|
2695
3705
|
pathId: purchaseId,
|
|
2696
3706
|
sessionId,
|
|
2697
3707
|
params: {
|
|
@@ -2894,6 +3904,44 @@ var _ParaCore = class _ParaCore {
|
|
|
2894
3904
|
return signRes;
|
|
2895
3905
|
});
|
|
2896
3906
|
}
|
|
3907
|
+
/**
|
|
3908
|
+
* @deprecated
|
|
3909
|
+
* Sends a transaction.
|
|
3910
|
+
* @param walletId - id of the wallet to send the transaction from.
|
|
3911
|
+
* @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
|
|
3912
|
+
* @param chainId - chain id of the chain the transaction is being sent on.
|
|
3913
|
+
**/
|
|
3914
|
+
sendTransaction(_0) {
|
|
3915
|
+
return __async(this, arguments, function* ({
|
|
3916
|
+
walletId,
|
|
3917
|
+
rlpEncodedTxBase64,
|
|
3918
|
+
chainId
|
|
3919
|
+
}) {
|
|
3920
|
+
this.assertIsValidWalletId(walletId);
|
|
3921
|
+
const wallet = this.wallets[walletId];
|
|
3922
|
+
const signRes = yield this.platformUtils.sendTransaction(
|
|
3923
|
+
this.ctx,
|
|
3924
|
+
this.userId,
|
|
3925
|
+
walletId,
|
|
3926
|
+
this.wallets[walletId].signer,
|
|
3927
|
+
rlpEncodedTxBase64,
|
|
3928
|
+
chainId,
|
|
3929
|
+
this.retrieveSessionCookie(),
|
|
3930
|
+
wallet.scheme === WalletScheme2.DKLS
|
|
3931
|
+
);
|
|
3932
|
+
if (signRes.pendingTransactionId) {
|
|
3933
|
+
this.platformUtils.openPopup(
|
|
3934
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3935
|
+
{ type: "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ }
|
|
3936
|
+
);
|
|
3937
|
+
const error = new TransactionReviewError(
|
|
3938
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId)
|
|
3939
|
+
);
|
|
3940
|
+
throw error;
|
|
3941
|
+
}
|
|
3942
|
+
return signRes;
|
|
3943
|
+
});
|
|
3944
|
+
}
|
|
2897
3945
|
isProviderModalDisabled() {
|
|
2898
3946
|
return !!this.disableProviderModal;
|
|
2899
3947
|
}
|
|
@@ -2990,36 +4038,36 @@ var _ParaCore = class _ParaCore {
|
|
|
2990
4038
|
/**
|
|
2991
4039
|
* @deprecated
|
|
2992
4040
|
*/
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
4041
|
+
exitAccountCreation() {
|
|
4042
|
+
this.isAwaitingAccountCreation = false;
|
|
4043
|
+
}
|
|
2996
4044
|
/**
|
|
2997
4045
|
* @deprecated
|
|
2998
4046
|
*/
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
4047
|
+
exitLogin() {
|
|
4048
|
+
this.isAwaitingLogin = false;
|
|
4049
|
+
}
|
|
3002
4050
|
/**
|
|
3003
4051
|
* @deprecated
|
|
3004
4052
|
*/
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
4053
|
+
exitFarcaster() {
|
|
4054
|
+
this.isAwaitingFarcaster = false;
|
|
4055
|
+
}
|
|
3008
4056
|
/**
|
|
3009
4057
|
* @deprecated
|
|
3010
4058
|
*/
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
4059
|
+
exitOAuth() {
|
|
4060
|
+
this.isAwaitingOAuth = false;
|
|
4061
|
+
}
|
|
3014
4062
|
/**
|
|
3015
4063
|
* @deprecated
|
|
3016
4064
|
*/
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
4065
|
+
exitLoops() {
|
|
4066
|
+
this.exitAccountCreation();
|
|
4067
|
+
this.exitLogin();
|
|
4068
|
+
this.exitFarcaster();
|
|
4069
|
+
this.exitOAuth();
|
|
4070
|
+
}
|
|
3023
4071
|
/**
|
|
3024
4072
|
* Retrieves a token to verify the current session.
|
|
3025
4073
|
* @returns {Promise<string>} the ID
|
|
@@ -3117,13 +4165,13 @@ var _ParaCore = class _ParaCore {
|
|
|
3117
4165
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
3118
4166
|
}
|
|
3119
4167
|
/** NEW METHODS */
|
|
3120
|
-
getNewCredentialAndUrl() {
|
|
4168
|
+
getNewCredentialAndUrl(_0) {
|
|
3121
4169
|
return __async(this, arguments, function* ({
|
|
3122
4170
|
authMethod = "PASSKEY",
|
|
3123
4171
|
isForNewDevice = false,
|
|
3124
4172
|
portalTheme,
|
|
3125
4173
|
shorten = false
|
|
3126
|
-
}
|
|
4174
|
+
}) {
|
|
3127
4175
|
this.assertIsAuthSet();
|
|
3128
4176
|
let credentialId, urlType;
|
|
3129
4177
|
switch (authMethod) {
|
|
@@ -3145,7 +4193,7 @@ var _ParaCore = class _ParaCore {
|
|
|
3145
4193
|
urlType = "createPassword";
|
|
3146
4194
|
break;
|
|
3147
4195
|
}
|
|
3148
|
-
const url = yield this.
|
|
4196
|
+
const url = yield this.constructPortalUrlV2(urlType, {
|
|
3149
4197
|
isForNewDevice,
|
|
3150
4198
|
pathId: credentialId,
|
|
3151
4199
|
portalTheme,
|
|
@@ -3154,15 +4202,7 @@ var _ParaCore = class _ParaCore {
|
|
|
3154
4202
|
return { credentialId, url };
|
|
3155
4203
|
});
|
|
3156
4204
|
}
|
|
3157
|
-
|
|
3158
|
-
* Returns a Para Portal URL for logging in with a WebAuth passkey or a password.
|
|
3159
|
-
* @param {Object} opts the options object
|
|
3160
|
-
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
3161
|
-
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
3162
|
-
* @param {Theme} opts.portalTheme the Para Portal theme to apply to the password creation URL, if other than the default theme
|
|
3163
|
-
* @returns {SignUpOrLogInResponse} an object in the form of either: `{ stage: 'verify' }` or `{ stage: 'login'; passkeyUrl?: string; passwordUrl?: string; biometricHints?: BiometricLocationHint[] }`
|
|
3164
|
-
*/
|
|
3165
|
-
getLoginUrl(_0) {
|
|
4205
|
+
getLoginUrlV2(_0) {
|
|
3166
4206
|
return __async(this, arguments, function* ({
|
|
3167
4207
|
authMethod = "PASSKEY",
|
|
3168
4208
|
shorten = false,
|
|
@@ -3184,14 +4224,14 @@ var _ParaCore = class _ParaCore {
|
|
|
3184
4224
|
default:
|
|
3185
4225
|
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
3186
4226
|
}
|
|
3187
|
-
return this.
|
|
4227
|
+
return this.constructPortalUrlV2(urlType, {
|
|
3188
4228
|
sessionId,
|
|
3189
4229
|
shorten,
|
|
3190
4230
|
portalTheme
|
|
3191
4231
|
});
|
|
3192
4232
|
});
|
|
3193
4233
|
}
|
|
3194
|
-
|
|
4234
|
+
getOAuthUrlV2(_0) {
|
|
3195
4235
|
return __async(this, arguments, function* ({ method, deeplinkUrl }) {
|
|
3196
4236
|
yield this.logout();
|
|
3197
4237
|
const { sessionLookupId } = yield this.touchSession(true);
|
|
@@ -3206,18 +4246,22 @@ var _ParaCore = class _ParaCore {
|
|
|
3206
4246
|
});
|
|
3207
4247
|
});
|
|
3208
4248
|
}
|
|
3209
|
-
|
|
4249
|
+
signUpOrLogInV2(_k) {
|
|
3210
4250
|
return __async(this, null, function* () {
|
|
3211
|
-
var
|
|
4251
|
+
var _l = _k, {
|
|
4252
|
+
auth
|
|
4253
|
+
} = _l, urlOptions = __objRest(_l, [
|
|
4254
|
+
"auth"
|
|
4255
|
+
]);
|
|
3212
4256
|
const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
3213
4257
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3214
4258
|
});
|
|
3215
4259
|
}
|
|
3216
|
-
|
|
4260
|
+
verifyNewAccountV2(_m) {
|
|
3217
4261
|
return __async(this, null, function* () {
|
|
3218
|
-
var
|
|
4262
|
+
var _n = _m, {
|
|
3219
4263
|
verificationCode
|
|
3220
|
-
} =
|
|
4264
|
+
} = _n, urlOptions = __objRest(_n, [
|
|
3221
4265
|
"verificationCode"
|
|
3222
4266
|
]);
|
|
3223
4267
|
this.assertIsAuthSet(["email", "phone"]);
|
|
@@ -3228,16 +4272,16 @@ var _ParaCore = class _ParaCore {
|
|
|
3228
4272
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3229
4273
|
});
|
|
3230
4274
|
}
|
|
3231
|
-
|
|
4275
|
+
verifyOAuthV2(_o) {
|
|
3232
4276
|
return __async(this, null, function* () {
|
|
3233
|
-
var
|
|
4277
|
+
var _p = _o, {
|
|
3234
4278
|
method,
|
|
3235
4279
|
deeplinkUrl,
|
|
3236
4280
|
isCanceled = () => false,
|
|
3237
4281
|
onCancel,
|
|
3238
4282
|
onPoll,
|
|
3239
4283
|
onOAuthUrl
|
|
3240
|
-
} =
|
|
4284
|
+
} = _p, urlOptions = __objRest(_p, [
|
|
3241
4285
|
"method",
|
|
3242
4286
|
"deeplinkUrl",
|
|
3243
4287
|
"isCanceled",
|
|
@@ -3281,14 +4325,14 @@ var _ParaCore = class _ParaCore {
|
|
|
3281
4325
|
});
|
|
3282
4326
|
});
|
|
3283
4327
|
}
|
|
3284
|
-
|
|
4328
|
+
verifyFarcasterV2(_q) {
|
|
3285
4329
|
return __async(this, null, function* () {
|
|
3286
|
-
var
|
|
4330
|
+
var _r = _q, {
|
|
3287
4331
|
isCanceled = () => false,
|
|
3288
4332
|
onConnectUri,
|
|
3289
4333
|
onCancel,
|
|
3290
4334
|
onPoll
|
|
3291
|
-
} =
|
|
4335
|
+
} = _r, urlOptions = __objRest(_r, [
|
|
3292
4336
|
"isCanceled",
|
|
3293
4337
|
"onConnectUri",
|
|
3294
4338
|
"onCancel",
|
|
@@ -3308,7 +4352,7 @@ var _ParaCore = class _ParaCore {
|
|
|
3308
4352
|
return reject("canceled");
|
|
3309
4353
|
}
|
|
3310
4354
|
yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
|
|
3311
|
-
const serverAuthState = yield this.ctx.client.
|
|
4355
|
+
const serverAuthState = yield this.ctx.client.getFarcasterAuthStatusV2();
|
|
3312
4356
|
if (isServerAuthState(serverAuthState)) {
|
|
3313
4357
|
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3314
4358
|
return resolve(authState);
|
|
@@ -3329,15 +4373,15 @@ var _ParaCore = class _ParaCore {
|
|
|
3329
4373
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
3330
4374
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
3331
4375
|
*/
|
|
3332
|
-
|
|
4376
|
+
verifyTelegramV2(_s) {
|
|
3333
4377
|
return __async(this, null, function* () {
|
|
3334
|
-
var
|
|
4378
|
+
var _t = _s, {
|
|
3335
4379
|
telegramAuthResponse
|
|
3336
|
-
} =
|
|
4380
|
+
} = _t, urlOptions = __objRest(_t, [
|
|
3337
4381
|
"telegramAuthResponse"
|
|
3338
4382
|
]);
|
|
3339
4383
|
try {
|
|
3340
|
-
const serverAuthState = yield this.ctx.client.
|
|
4384
|
+
const serverAuthState = yield this.ctx.client.verifyTelegramV2(telegramAuthResponse);
|
|
3341
4385
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3342
4386
|
} catch (e) {
|
|
3343
4387
|
throw new Error(e.message);
|
|
@@ -3352,7 +4396,7 @@ var _ParaCore = class _ParaCore {
|
|
|
3352
4396
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
3353
4397
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
3354
4398
|
**/
|
|
3355
|
-
|
|
4399
|
+
waitForLoginV2() {
|
|
3356
4400
|
return __async(this, arguments, function* ({
|
|
3357
4401
|
isCanceled = () => false,
|
|
3358
4402
|
onCancel,
|
|
@@ -3391,7 +4435,7 @@ var _ParaCore = class _ParaCore {
|
|
|
3391
4435
|
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
3392
4436
|
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
3393
4437
|
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
3394
|
-
yield this.
|
|
4438
|
+
yield this.claimPregenWalletsV2();
|
|
3395
4439
|
const resp = {
|
|
3396
4440
|
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
3397
4441
|
partnerId: session.partnerId
|
|
@@ -3409,7 +4453,7 @@ var _ParaCore = class _ParaCore {
|
|
|
3409
4453
|
});
|
|
3410
4454
|
});
|
|
3411
4455
|
}
|
|
3412
|
-
|
|
4456
|
+
waitForSignupV2(_0) {
|
|
3413
4457
|
return __async(this, arguments, function* ({
|
|
3414
4458
|
isCanceled = () => false,
|
|
3415
4459
|
onCancel,
|
|
@@ -3444,17 +4488,17 @@ var _ParaCore = class _ParaCore {
|
|
|
3444
4488
|
});
|
|
3445
4489
|
});
|
|
3446
4490
|
}
|
|
3447
|
-
|
|
4491
|
+
waitForWalletCreationV2() {
|
|
3448
4492
|
return __async(this, arguments, function* ({
|
|
3449
4493
|
isCanceled = () => false,
|
|
3450
4494
|
onCancel
|
|
3451
4495
|
} = {}) {
|
|
3452
|
-
yield this.
|
|
4496
|
+
yield this.waitForSignupV2({ isCanceled, onCancel });
|
|
3453
4497
|
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3454
|
-
const pregenWallets = yield this.
|
|
4498
|
+
const pregenWallets = yield this.getPregenWalletsV2();
|
|
3455
4499
|
let recoverySecret, walletIds = {};
|
|
3456
4500
|
if (pregenWallets.length > 0) {
|
|
3457
|
-
recoverySecret = yield this.
|
|
4501
|
+
recoverySecret = yield this.claimPregenWalletsV2();
|
|
3458
4502
|
walletIds = supportedWalletTypes.reduce((acc, { type }) => {
|
|
3459
4503
|
var _a;
|
|
3460
4504
|
return __spreadProps(__spreadValues({}, acc), {
|
|
@@ -3470,32 +4514,32 @@ var _ParaCore = class _ParaCore {
|
|
|
3470
4514
|
return resp;
|
|
3471
4515
|
});
|
|
3472
4516
|
}
|
|
3473
|
-
|
|
4517
|
+
loginExternalWalletV2(_u) {
|
|
3474
4518
|
return __async(this, null, function* () {
|
|
3475
|
-
var
|
|
4519
|
+
var _v = _u, {
|
|
3476
4520
|
externalWallet
|
|
3477
|
-
} =
|
|
4521
|
+
} = _v, urlOptions = __objRest(_v, [
|
|
3478
4522
|
"externalWallet"
|
|
3479
4523
|
]);
|
|
3480
4524
|
this.requireApiKey();
|
|
3481
|
-
const serverAuthState = yield this.ctx.client.
|
|
4525
|
+
const serverAuthState = yield this.ctx.client.loginExternalWalletV2({ externalWallet });
|
|
3482
4526
|
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3483
4527
|
});
|
|
3484
4528
|
}
|
|
3485
|
-
|
|
4529
|
+
verifyExternalWalletV2(_w) {
|
|
3486
4530
|
return __async(this, null, function* () {
|
|
3487
|
-
var
|
|
4531
|
+
var _x = _w, {
|
|
3488
4532
|
externalWallet,
|
|
3489
4533
|
signedMessage,
|
|
3490
4534
|
cosmosPublicKeyHex,
|
|
3491
4535
|
cosmosSigner
|
|
3492
|
-
} =
|
|
4536
|
+
} = _x, urlOptions = __objRest(_x, [
|
|
3493
4537
|
"externalWallet",
|
|
3494
4538
|
"signedMessage",
|
|
3495
4539
|
"cosmosPublicKeyHex",
|
|
3496
4540
|
"cosmosSigner"
|
|
3497
4541
|
]);
|
|
3498
|
-
const serverAuthState = yield this.ctx.client.
|
|
4542
|
+
const serverAuthState = yield this.ctx.client.verifyExternalWalletV2(this.userId, {
|
|
3499
4543
|
externalWallet,
|
|
3500
4544
|
signedMessage,
|
|
3501
4545
|
cosmosPublicKeyHex,
|
|
@@ -3511,9 +4555,9 @@ var _ParaCore = class _ParaCore {
|
|
|
3511
4555
|
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
3512
4556
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
3513
4557
|
*/
|
|
3514
|
-
|
|
4558
|
+
verify2faV2(_0) {
|
|
3515
4559
|
return __async(this, arguments, function* ({ auth, verificationCode }) {
|
|
3516
|
-
const res = yield this.ctx.client.
|
|
4560
|
+
const res = yield this.ctx.client.verify2FAV2(auth, verificationCode);
|
|
3517
4561
|
return {
|
|
3518
4562
|
initiatedAt: res.data.initiatedAt,
|
|
3519
4563
|
status: res.data.status,
|
|
@@ -3526,10 +4570,10 @@ var _ParaCore = class _ParaCore {
|
|
|
3526
4570
|
* Sets up two-factor authentication for the current user.
|
|
3527
4571
|
* @returns {string} uri - uri to use for setting up 2FA
|
|
3528
4572
|
* */
|
|
3529
|
-
|
|
4573
|
+
setup2faV2() {
|
|
3530
4574
|
return __async(this, null, function* () {
|
|
3531
4575
|
const userId = this.assertUserId();
|
|
3532
|
-
const res = yield this.ctx.client.
|
|
4576
|
+
const res = yield this.ctx.client.setup2FAV2(userId);
|
|
3533
4577
|
return res;
|
|
3534
4578
|
});
|
|
3535
4579
|
}
|
|
@@ -3538,7 +4582,7 @@ var _ParaCore = class _ParaCore {
|
|
|
3538
4582
|
* @param {Object} opts the options object
|
|
3539
4583
|
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
3540
4584
|
*/
|
|
3541
|
-
|
|
4585
|
+
enable2faV2(_0) {
|
|
3542
4586
|
return __async(this, arguments, function* ({ verificationCode }) {
|
|
3543
4587
|
const userId = this.assertUserId();
|
|
3544
4588
|
yield this.ctx.client.enable2FA(userId, verificationCode);
|
|
@@ -3553,7 +4597,7 @@ var _ParaCore = class _ParaCore {
|
|
|
3553
4597
|
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
3554
4598
|
* @returns {Wallet} the created wallet.
|
|
3555
4599
|
**/
|
|
3556
|
-
|
|
4600
|
+
createPregenWalletV2(opts) {
|
|
3557
4601
|
return __async(this, null, function* () {
|
|
3558
4602
|
var _a, _b;
|
|
3559
4603
|
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
@@ -3610,14 +4654,14 @@ var _ParaCore = class _ParaCore {
|
|
|
3610
4654
|
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
3611
4655
|
* @returns {Wallet[]} an array containing the created wallets.
|
|
3612
4656
|
**/
|
|
3613
|
-
|
|
4657
|
+
createPregenWalletPerTypeV2(_0) {
|
|
3614
4658
|
return __async(this, arguments, function* ({
|
|
3615
4659
|
types,
|
|
3616
4660
|
pregenId
|
|
3617
4661
|
}) {
|
|
3618
4662
|
const wallets = [];
|
|
3619
4663
|
for (const type of yield this.getTypesToCreate(types)) {
|
|
3620
|
-
const wallet = yield this.
|
|
4664
|
+
const wallet = yield this.createPregenWalletV2({ type, pregenId });
|
|
3621
4665
|
wallets.push(wallet);
|
|
3622
4666
|
}
|
|
3623
4667
|
return wallets;
|
|
@@ -3630,13 +4674,13 @@ var _ParaCore = class _ParaCore {
|
|
|
3630
4674
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
3631
4675
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3632
4676
|
**/
|
|
3633
|
-
|
|
4677
|
+
claimPregenWalletsV2() {
|
|
3634
4678
|
return __async(this, arguments, function* ({
|
|
3635
4679
|
pregenId
|
|
3636
4680
|
} = {}) {
|
|
3637
4681
|
var _a;
|
|
3638
4682
|
this.requireApiKey();
|
|
3639
|
-
const pregenWallets = pregenId ? yield this.
|
|
4683
|
+
const pregenWallets = pregenId ? yield this.getPregenWalletsV2({ pregenId }) : yield this.getPregenWalletsV2();
|
|
3640
4684
|
if (pregenWallets.length === 0) {
|
|
3641
4685
|
return void 0;
|
|
3642
4686
|
}
|
|
@@ -3696,7 +4740,7 @@ var _ParaCore = class _ParaCore {
|
|
|
3696
4740
|
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
3697
4741
|
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
3698
4742
|
**/
|
|
3699
|
-
|
|
4743
|
+
updatePregenWalletIdentifierV2(_0) {
|
|
3700
4744
|
return __async(this, arguments, function* ({
|
|
3701
4745
|
walletId,
|
|
3702
4746
|
newPregenId
|
|
@@ -3723,11 +4767,11 @@ var _ParaCore = class _ParaCore {
|
|
|
3723
4767
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
3724
4768
|
* @returns {boolean} whether the pregen wallet exists
|
|
3725
4769
|
**/
|
|
3726
|
-
|
|
4770
|
+
hasPregenWalletV2(_0) {
|
|
3727
4771
|
return __async(this, arguments, function* ({ pregenId }) {
|
|
3728
4772
|
this.requireApiKey();
|
|
3729
4773
|
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
3730
|
-
const wallets = yield this.
|
|
4774
|
+
const wallets = yield this.getPregenWalletsV2({ pregenId });
|
|
3731
4775
|
const wallet = wallets.find(
|
|
3732
4776
|
(w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType
|
|
3733
4777
|
);
|
|
@@ -3744,8 +4788,10 @@ var _ParaCore = class _ParaCore {
|
|
|
3744
4788
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
3745
4789
|
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
3746
4790
|
**/
|
|
3747
|
-
|
|
3748
|
-
return __async(this, arguments, function* ({
|
|
4791
|
+
getPregenWalletsV2() {
|
|
4792
|
+
return __async(this, arguments, function* ({
|
|
4793
|
+
pregenId
|
|
4794
|
+
} = {}) {
|
|
3749
4795
|
this.requireApiKey();
|
|
3750
4796
|
const res = yield this.ctx.client.getPregenWallets(
|
|
3751
4797
|
pregenId ? toPregenIds(pregenId) : this.pregenIds,
|
|
@@ -3875,8 +4921,8 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3875
4921
|
}) {
|
|
3876
4922
|
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
3877
4923
|
return __spreadValues(__spreadValues(__spreadValues({}, authState), !this.isNativePasskey && loginAuthMethods.includes(AuthMethod.PASSKEY) ? {
|
|
3878
|
-
passkeyUrl: yield this.
|
|
3879
|
-
passkeyKnownDeviceUrl: yield this.
|
|
4924
|
+
passkeyUrl: yield this.getLoginUrlV2({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
4925
|
+
passkeyKnownDeviceUrl: yield this.constructPortalUrlV2("loginAuth", {
|
|
3880
4926
|
sessionId: sessionLookupId,
|
|
3881
4927
|
newDevice: {
|
|
3882
4928
|
sessionId: sessionLookupId,
|
|
@@ -3886,7 +4932,7 @@ prepareLoginState_fn = function(_0, _1) {
|
|
|
3886
4932
|
portalTheme
|
|
3887
4933
|
})
|
|
3888
4934
|
} : {}), loginAuthMethods.includes(AuthMethod.PASSWORD) ? {
|
|
3889
|
-
passwordUrl: yield this.
|
|
4935
|
+
passwordUrl: yield this.constructPortalUrlV2("loginPassword", {
|
|
3890
4936
|
sessionId: sessionLookupId,
|
|
3891
4937
|
shorten,
|
|
3892
4938
|
portalTheme
|
|
@@ -3941,7 +4987,7 @@ import {
|
|
|
3941
4987
|
OnRampPurchaseType,
|
|
3942
4988
|
OnRampProvider,
|
|
3943
4989
|
OnRampPurchaseStatus,
|
|
3944
|
-
OAuthMethod,
|
|
4990
|
+
OAuthMethod as OAuthMethod2,
|
|
3945
4991
|
NON_ED25519,
|
|
3946
4992
|
PREGEN_IDENTIFIER_TYPES
|
|
3947
4993
|
} from "@getpara/user-management-client";
|
|
@@ -3955,7 +5001,7 @@ export {
|
|
|
3955
5001
|
KeyContainer,
|
|
3956
5002
|
NON_ED25519,
|
|
3957
5003
|
Network,
|
|
3958
|
-
OAuthMethod,
|
|
5004
|
+
OAuthMethod2 as OAuthMethod,
|
|
3959
5005
|
OnRampAsset,
|
|
3960
5006
|
OnRampMethod,
|
|
3961
5007
|
OnRampProvider,
|