@getpara/core-sdk 1.7.1 → 2.0.0-alpha.3
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 +1931 -1940
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +1945 -1948
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/types/ParaCore.d.ts +178 -488
- package/dist/types/constants.d.ts +2 -1
- package/dist/types/external/userManagementClient.d.ts +1 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/types/config.d.ts +1 -19
- package/dist/types/types/coreApi.d.ts +437 -0
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/types/methods.d.ts +143 -0
- package/dist/types/types/wallet.d.ts +2 -4
- package/dist/types/utils/autobind.d.ts +1 -0
- package/dist/types/utils/formatting.d.ts +0 -2
- package/dist/types/utils/index.d.ts +5 -0
- package/dist/types/utils/json.d.ts +1 -0
- package/dist/types/utils/phone.d.ts +7 -0
- package/dist/types/utils/types.d.ts +2 -0
- package/dist/types/utils/url.d.ts +2 -1
- package/dist/types/utils/wallet.d.ts +4 -2
- package/package.json +4 -3
- package/dist/cjs/package.json +0 -3
- package/dist/esm/package.json +0 -4
- package/dist/types/types/params.d.ts +0 -66
package/dist/esm/index.js
CHANGED
|
@@ -40,6 +40,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
|
|
|
40
40
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
41
41
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
42
42
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
43
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
43
44
|
var __async = (__this, __arguments, generator) => {
|
|
44
45
|
return new Promise((resolve, reject) => {
|
|
45
46
|
var fulfilled = (value) => {
|
|
@@ -69,10 +70,16 @@ import {
|
|
|
69
70
|
PublicKeyType,
|
|
70
71
|
WalletType as WalletType2,
|
|
71
72
|
WalletScheme as WalletScheme2,
|
|
72
|
-
OAuthMethod,
|
|
73
73
|
extractWalletRef,
|
|
74
74
|
PasswordStatus,
|
|
75
|
-
extractAuthInfo
|
|
75
|
+
extractAuthInfo,
|
|
76
|
+
isEmail,
|
|
77
|
+
isPhone,
|
|
78
|
+
isFarcaster,
|
|
79
|
+
isTelegram,
|
|
80
|
+
toPregenTypeAndId,
|
|
81
|
+
toPregenIds,
|
|
82
|
+
isExternalWallet
|
|
76
83
|
} from "@getpara/user-management-client";
|
|
77
84
|
import forge3 from "node-forge";
|
|
78
85
|
|
|
@@ -80,6 +87,23 @@ import forge3 from "node-forge";
|
|
|
80
87
|
import base64url from "base64url";
|
|
81
88
|
import forge from "node-forge";
|
|
82
89
|
|
|
90
|
+
// src/utils/autobind.ts
|
|
91
|
+
function autoBind(instance) {
|
|
92
|
+
let proto = instance;
|
|
93
|
+
while (proto && proto !== Object.prototype) {
|
|
94
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
95
|
+
const value = instance[key];
|
|
96
|
+
if (typeof value === "function" && key !== "constructor") {
|
|
97
|
+
try {
|
|
98
|
+
instance[key] = value.bind(instance);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
proto = Object.getPrototypeOf(proto);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
83
107
|
// src/utils/events.ts
|
|
84
108
|
function dispatchEvent(type, data, error) {
|
|
85
109
|
typeof window !== "undefined" && !!window.dispatchEvent && window.dispatchEvent(
|
|
@@ -92,7 +116,6 @@ import { toBech32 } from "@cosmjs/encoding";
|
|
|
92
116
|
import { sha256 } from "@noble/hashes/sha256";
|
|
93
117
|
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
94
118
|
import elliptic from "elliptic";
|
|
95
|
-
import parsePhoneNumberFromString from "libphonenumber-js";
|
|
96
119
|
var secp256k1 = new elliptic.ec("secp256k1");
|
|
97
120
|
function hexStringToBase64(hexString) {
|
|
98
121
|
if (hexString.substring(0, 2) === "0x") {
|
|
@@ -149,12 +172,72 @@ function truncateAddress(str, addressType, { prefix = addressType === "COSMOS" ?
|
|
|
149
172
|
const headLength = (addressType === "COSMOS" ? prefix.length : addressType === "SOLANA" ? 0 : 2) + 4;
|
|
150
173
|
return `${str.slice(0, headLength)}...${str.slice(-4)}`;
|
|
151
174
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
175
|
+
|
|
176
|
+
// src/utils/json.ts
|
|
177
|
+
function jsonParse(data, validate) {
|
|
178
|
+
try {
|
|
179
|
+
const res = JSON.parse(data);
|
|
180
|
+
if (validate && !validate(res)) {
|
|
181
|
+
return void 0;
|
|
182
|
+
}
|
|
183
|
+
return res;
|
|
184
|
+
} catch (e) {
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/constants.ts
|
|
190
|
+
var PARA_CORE_VERSION = '2.0.0-alpha.0';
|
|
191
|
+
var PREFIX = "@CAPSULE/";
|
|
192
|
+
var LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
193
|
+
var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
194
|
+
var LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
|
|
195
|
+
var LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
|
|
196
|
+
var LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
|
|
197
|
+
var LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
|
|
198
|
+
var LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
|
|
199
|
+
var LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
|
|
200
|
+
var LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
|
|
201
|
+
var LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
|
|
202
|
+
var LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
|
|
203
|
+
var LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
|
|
204
|
+
var SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
|
|
205
|
+
var POLLING_INTERVAL_MS = 2e3;
|
|
206
|
+
var SHORT_POLLING_INTERVAL_MS = 1e3;
|
|
207
|
+
var POLLING_TIMEOUT_MS = 3e5;
|
|
208
|
+
|
|
209
|
+
// src/utils/listeners.ts
|
|
210
|
+
function storageListener(e) {
|
|
211
|
+
if (!e.url.includes(window.location.origin)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (e.key === LOCAL_STORAGE_EXTERNAL_WALLETS) {
|
|
215
|
+
this.updateExternalWalletsFromStorage();
|
|
216
|
+
}
|
|
217
|
+
if (e.key === SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR) {
|
|
218
|
+
this.updateLoginEncryptionKeyPairFromStorage();
|
|
219
|
+
}
|
|
220
|
+
if (e.key === LOCAL_STORAGE_SESSION_COOKIE) {
|
|
221
|
+
this.updateSessionCookieFromStorage();
|
|
222
|
+
}
|
|
223
|
+
if (e.key === LOCAL_STORAGE_CURRENT_WALLET_IDS) {
|
|
224
|
+
this.updateWalletIdsFromStorage();
|
|
225
|
+
}
|
|
226
|
+
if (e.key === LOCAL_STORAGE_WALLETS || e.key === LOCAL_STORAGE_ED25519_WALLETS) {
|
|
227
|
+
this.updateWalletsFromStorage();
|
|
228
|
+
}
|
|
229
|
+
if (e.key === LOCAL_STORAGE_AUTH_INFO) {
|
|
230
|
+
this.updateAuthInfoFromStorage();
|
|
231
|
+
}
|
|
232
|
+
if (e.key === LOCAL_STORAGE_USER_ID) {
|
|
233
|
+
this.updateUserIdFromStorage();
|
|
234
|
+
}
|
|
155
235
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
236
|
+
function setupListeners() {
|
|
237
|
+
if (typeof window !== "undefined" && window.addEventListener && window.location) {
|
|
238
|
+
window.removeEventListener("storage", storageListener.bind(this));
|
|
239
|
+
window.addEventListener("storage", storageListener.bind(this));
|
|
240
|
+
}
|
|
158
241
|
}
|
|
159
242
|
|
|
160
243
|
// src/utils/onRamps.ts
|
|
@@ -193,6 +276,31 @@ function getOnRampAssets(data, {
|
|
|
193
276
|
];
|
|
194
277
|
}
|
|
195
278
|
|
|
279
|
+
// src/utils/phone.ts
|
|
280
|
+
import parsePhoneNumberFromString from "libphonenumber-js";
|
|
281
|
+
function formatPhoneNumber(phone, countryCode, { forDisplay = false } = {}) {
|
|
282
|
+
phone = phone.toString();
|
|
283
|
+
countryCode = countryCode == null ? void 0 : countryCode.toString();
|
|
284
|
+
let sanitizedNumber, parsedNumber;
|
|
285
|
+
if (!!countryCode) {
|
|
286
|
+
sanitizedNumber = phone.replace(/\D/g, "");
|
|
287
|
+
if (/^\+\d+$/.test(countryCode)) {
|
|
288
|
+
countryCode = countryCode.slice(1);
|
|
289
|
+
}
|
|
290
|
+
parsedNumber = parsePhoneNumberFromString(sanitizedNumber, { defaultCallingCode: countryCode });
|
|
291
|
+
} else {
|
|
292
|
+
sanitizedNumber = `+${phone.replace(/\D/g, "")}`;
|
|
293
|
+
parsedNumber = parsePhoneNumberFromString(sanitizedNumber);
|
|
294
|
+
}
|
|
295
|
+
if (parsedNumber == null ? void 0 : parsedNumber.isValid()) {
|
|
296
|
+
return forDisplay ? parsedNumber.formatInternational() : parsedNumber.formatInternational().replace(/[^\d+]/g, "");
|
|
297
|
+
}
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
function displayPhoneNumber(phone, countryCode) {
|
|
301
|
+
return formatPhoneNumber(phone, countryCode, { forDisplay: true });
|
|
302
|
+
}
|
|
303
|
+
|
|
196
304
|
// src/utils/polling.ts
|
|
197
305
|
function waitUntilTrue(condition, timeoutMs, intervalMs) {
|
|
198
306
|
return __async(this, null, function* () {
|
|
@@ -207,6 +315,48 @@ function waitUntilTrue(condition, timeoutMs, intervalMs) {
|
|
|
207
315
|
});
|
|
208
316
|
}
|
|
209
317
|
|
|
318
|
+
// src/utils/types.ts
|
|
319
|
+
function isServerAuthState(obj) {
|
|
320
|
+
return "stage" in obj && Object.keys(obj).length > 0;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// src/transmission/transmissionUtils.ts
|
|
324
|
+
import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from "@celo/utils/lib/ecies.js";
|
|
325
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
326
|
+
import * as eutil from "ethereumjs-util";
|
|
327
|
+
import { randomBytes } from "crypto";
|
|
328
|
+
function upload(message, userManagementClient) {
|
|
329
|
+
return __async(this, null, function* () {
|
|
330
|
+
let secret;
|
|
331
|
+
let publicKeyUint8Array;
|
|
332
|
+
while (true) {
|
|
333
|
+
try {
|
|
334
|
+
secret = randomBytes(32).toString("hex");
|
|
335
|
+
publicKeyUint8Array = eutil.privateToPublic(Buffer2.from(secret, "hex"));
|
|
336
|
+
break;
|
|
337
|
+
} catch (e) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const pubkey = Buffer2.from(publicKeyUint8Array);
|
|
342
|
+
const data = ECIESEncrypt(pubkey, Buffer2.from(message, "ucs2")).toString("base64");
|
|
343
|
+
const {
|
|
344
|
+
data: { id }
|
|
345
|
+
} = yield userManagementClient.tempTrasmissionInit(data);
|
|
346
|
+
return encodeURIComponent(id + "|" + secret);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function retrieve(uriEncodedMessage, userManagementClient) {
|
|
350
|
+
return __async(this, null, function* () {
|
|
351
|
+
const [id, secret] = decodeURIComponent(uriEncodedMessage).split("|");
|
|
352
|
+
const response = yield userManagementClient.tempTrasmission(id);
|
|
353
|
+
const data = response.data.message;
|
|
354
|
+
const buf = Buffer2.from(data, "base64");
|
|
355
|
+
const res = Buffer2.from(ECIESDecrypt(Buffer2.from(secret, "hex"), buf).buffer).toString("ucs2");
|
|
356
|
+
return res;
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
210
360
|
// src/types/config.ts
|
|
211
361
|
var Environment = /* @__PURE__ */ ((Environment2) => {
|
|
212
362
|
Environment2["DEV"] = "DEV";
|
|
@@ -224,6 +374,49 @@ var EnabledFlow = /* @__PURE__ */ ((EnabledFlow2) => {
|
|
|
224
374
|
return EnabledFlow2;
|
|
225
375
|
})(EnabledFlow || {});
|
|
226
376
|
|
|
377
|
+
// src/types/coreApi.ts
|
|
378
|
+
var PARA_CORE_METHODS = [
|
|
379
|
+
"signUpOrLogIn",
|
|
380
|
+
"verifyNewAccount",
|
|
381
|
+
"waitForLogin",
|
|
382
|
+
"waitForSignup",
|
|
383
|
+
"waitForWalletCreation",
|
|
384
|
+
"verifyOAuth",
|
|
385
|
+
"verifyFarcaster",
|
|
386
|
+
"verifyTelegram",
|
|
387
|
+
"resendVerificationCode",
|
|
388
|
+
"loginExternalWallet",
|
|
389
|
+
"verifyExternalWallet",
|
|
390
|
+
"setup2fa",
|
|
391
|
+
"enable2fa",
|
|
392
|
+
"verify2fa",
|
|
393
|
+
"logout",
|
|
394
|
+
"clearStorage",
|
|
395
|
+
"isSessionActive",
|
|
396
|
+
"isFullyLoggedIn",
|
|
397
|
+
"refreshSession",
|
|
398
|
+
"keepSessionAlive",
|
|
399
|
+
"exportSession",
|
|
400
|
+
"importSession",
|
|
401
|
+
"getVerificationToken",
|
|
402
|
+
"fetchWallets",
|
|
403
|
+
"createWallet",
|
|
404
|
+
"createWalletPerType",
|
|
405
|
+
"getPregenWallets",
|
|
406
|
+
"hasPregenWallet",
|
|
407
|
+
"updatePregenWalletIdentifier",
|
|
408
|
+
"createPregenWallet",
|
|
409
|
+
"createPregenWalletPerType",
|
|
410
|
+
"claimPregenWallets",
|
|
411
|
+
"distributeNewWalletShare",
|
|
412
|
+
"getUserShare",
|
|
413
|
+
"setUserShare",
|
|
414
|
+
"refreshShare",
|
|
415
|
+
"signMessage",
|
|
416
|
+
"signTransaction",
|
|
417
|
+
"initiateOnRampTransaction"
|
|
418
|
+
];
|
|
419
|
+
|
|
227
420
|
// src/types/wallet.ts
|
|
228
421
|
var PregenIdentifierType = /* @__PURE__ */ ((PregenIdentifierType2) => {
|
|
229
422
|
PregenIdentifierType2["EMAIL"] = "EMAIL";
|
|
@@ -252,13 +445,13 @@ var PopupType = /* @__PURE__ */ ((PopupType2) => {
|
|
|
252
445
|
})(PopupType || {});
|
|
253
446
|
|
|
254
447
|
// src/types/recovery.ts
|
|
255
|
-
var RecoveryStatus = /* @__PURE__ */ ((
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return
|
|
448
|
+
var RecoveryStatus = /* @__PURE__ */ ((RecoveryStatus2) => {
|
|
449
|
+
RecoveryStatus2["INITIATED"] = "INITIATED";
|
|
450
|
+
RecoveryStatus2["READY"] = "READY";
|
|
451
|
+
RecoveryStatus2["EXPIRED"] = "EXPIRED";
|
|
452
|
+
RecoveryStatus2["FINISHED"] = "FINISHED";
|
|
453
|
+
RecoveryStatus2["CANCELLED"] = "CANCELLED";
|
|
454
|
+
return RecoveryStatus2;
|
|
262
455
|
})(RecoveryStatus || {});
|
|
263
456
|
|
|
264
457
|
// src/types/events.ts
|
|
@@ -346,9 +539,21 @@ function constructUrl({
|
|
|
346
539
|
});
|
|
347
540
|
return url.toString();
|
|
348
541
|
}
|
|
542
|
+
function shortenUrl(ctx, url) {
|
|
543
|
+
return __async(this, null, function* () {
|
|
544
|
+
const compressedUrl = yield upload(url, ctx.client);
|
|
545
|
+
return constructUrl({
|
|
546
|
+
base: getPortalBaseURL(ctx),
|
|
547
|
+
path: `/short/${compressedUrl}`
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
}
|
|
349
551
|
|
|
350
552
|
// src/utils/wallet.ts
|
|
351
|
-
import {
|
|
553
|
+
import {
|
|
554
|
+
WalletScheme,
|
|
555
|
+
WalletType
|
|
556
|
+
} from "@getpara/user-management-client";
|
|
352
557
|
var WalletSchemeTypeMap = {
|
|
353
558
|
[WalletScheme.DKLS]: {
|
|
354
559
|
[WalletType.EVM]: true,
|
|
@@ -370,7 +575,7 @@ function isPregenIdentifierMatch(a, b, type) {
|
|
|
370
575
|
case "EMAIL":
|
|
371
576
|
return a.toLowerCase() === b.toLowerCase();
|
|
372
577
|
case "PHONE":
|
|
373
|
-
return
|
|
578
|
+
return formatPhoneNumber(a) === formatPhoneNumber(b);
|
|
374
579
|
case "CUSTOM_ID":
|
|
375
580
|
return a === b;
|
|
376
581
|
default:
|
|
@@ -420,6 +625,9 @@ function migrateWallet(obj) {
|
|
|
420
625
|
}
|
|
421
626
|
return obj;
|
|
422
627
|
}
|
|
628
|
+
function supportedWalletTypesEq(a, b) {
|
|
629
|
+
return a.length === b.length && a.every(({ type, optional }, index) => b[index].type === type && b[index].optional === optional);
|
|
630
|
+
}
|
|
423
631
|
|
|
424
632
|
// src/cryptography/utils.ts
|
|
425
633
|
var rsa = forge.pki.rsa;
|
|
@@ -734,7 +942,7 @@ function initClient({
|
|
|
734
942
|
}) {
|
|
735
943
|
return new Client({
|
|
736
944
|
userManagementHost: getBaseUrl(env),
|
|
737
|
-
version: ["DEV" /* DEV */, "SANDBOX" /* SANDBOX */].includes(env) ? "dev" : version,
|
|
945
|
+
version: ["DEV" /* DEV */, "SANDBOX" /* SANDBOX */].includes(env) ? "dev-v2" : version,
|
|
738
946
|
apiKey,
|
|
739
947
|
partnerId,
|
|
740
948
|
opts: { useFetchAdapter },
|
|
@@ -782,8 +990,8 @@ import { EncryptorType as EncryptorType2, KeyShareType as KeyShareType2 } from "
|
|
|
782
990
|
import { EncryptorType, KeyShareType } from "@getpara/user-management-client";
|
|
783
991
|
|
|
784
992
|
// src/shares/KeyContainer.ts
|
|
785
|
-
import { Encrypt as
|
|
786
|
-
import * as
|
|
993
|
+
import { Encrypt as ECIESEncrypt2, Decrypt as ECIESDecrypt2 } from "@celo/utils/lib/ecies.js";
|
|
994
|
+
import * as eutil2 from "ethereumjs-util";
|
|
787
995
|
import * as forge2 from "node-forge";
|
|
788
996
|
var KeyContainer = class _KeyContainer {
|
|
789
997
|
constructor(walletId, keyshare, address) {
|
|
@@ -803,7 +1011,7 @@ var KeyContainer = class _KeyContainer {
|
|
|
803
1011
|
}
|
|
804
1012
|
}
|
|
805
1013
|
getPublicEncryptionKey() {
|
|
806
|
-
return Buffer.from(
|
|
1014
|
+
return Buffer.from(eutil2.privateToPublic(Buffer.from(this.backupDecryptionKey, "hex")));
|
|
807
1015
|
}
|
|
808
1016
|
getPublicEncryptionKeyHex() {
|
|
809
1017
|
return this.getPublicEncryptionKey().toString("hex");
|
|
@@ -811,7 +1019,7 @@ var KeyContainer = class _KeyContainer {
|
|
|
811
1019
|
encryptForSelf(backup) {
|
|
812
1020
|
try {
|
|
813
1021
|
const pubkey = this.getPublicEncryptionKey();
|
|
814
|
-
const data =
|
|
1022
|
+
const data = ECIESEncrypt2(pubkey, Buffer.from(backup, "ucs2")).toString("base64");
|
|
815
1023
|
return data;
|
|
816
1024
|
} catch (error) {
|
|
817
1025
|
throw Error("Error encrypting backup");
|
|
@@ -819,7 +1027,7 @@ var KeyContainer = class _KeyContainer {
|
|
|
819
1027
|
}
|
|
820
1028
|
static encryptWithPublicKey(publicKey, backup) {
|
|
821
1029
|
try {
|
|
822
|
-
const data =
|
|
1030
|
+
const data = ECIESEncrypt2(publicKey, Buffer.from(backup, "ucs2")).toString("base64");
|
|
823
1031
|
return data;
|
|
824
1032
|
} catch (error) {
|
|
825
1033
|
throw Error("Error encrypting backup");
|
|
@@ -828,7 +1036,7 @@ var KeyContainer = class _KeyContainer {
|
|
|
828
1036
|
decrypt(encryptedBackup) {
|
|
829
1037
|
try {
|
|
830
1038
|
const buf = Buffer.from(encryptedBackup, "base64");
|
|
831
|
-
const data =
|
|
1039
|
+
const data = ECIESDecrypt2(Buffer.from(this.backupDecryptionKey, "hex"), buf);
|
|
832
1040
|
return Buffer.from(data.buffer).toString("ucs2");
|
|
833
1041
|
} catch (error) {
|
|
834
1042
|
throw Error("Error decrypting backup");
|
|
@@ -960,43 +1168,6 @@ function distributeNewShare(_0) {
|
|
|
960
1168
|
});
|
|
961
1169
|
}
|
|
962
1170
|
|
|
963
|
-
// src/transmission/transmissionUtils.ts
|
|
964
|
-
import { Encrypt as ECIESEncrypt2, Decrypt as ECIESDecrypt2 } from "@celo/utils/lib/ecies.js";
|
|
965
|
-
import { Buffer as Buffer2 } from "buffer";
|
|
966
|
-
import * as eutil2 from "ethereumjs-util";
|
|
967
|
-
import { randomBytes } from "crypto";
|
|
968
|
-
function upload(message, userManagementClient) {
|
|
969
|
-
return __async(this, null, function* () {
|
|
970
|
-
let secret;
|
|
971
|
-
let publicKeyUint8Array;
|
|
972
|
-
while (true) {
|
|
973
|
-
try {
|
|
974
|
-
secret = randomBytes(32).toString("hex");
|
|
975
|
-
publicKeyUint8Array = eutil2.privateToPublic(Buffer2.from(secret, "hex"));
|
|
976
|
-
break;
|
|
977
|
-
} catch (e) {
|
|
978
|
-
continue;
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
const pubkey = Buffer2.from(publicKeyUint8Array);
|
|
982
|
-
const data = ECIESEncrypt2(pubkey, Buffer2.from(message, "ucs2")).toString("base64");
|
|
983
|
-
const {
|
|
984
|
-
data: { id }
|
|
985
|
-
} = yield userManagementClient.tempTrasmissionInit(data);
|
|
986
|
-
return encodeURIComponent(id + "|" + secret);
|
|
987
|
-
});
|
|
988
|
-
}
|
|
989
|
-
function retrieve(uriEncodedMessage, userManagementClient) {
|
|
990
|
-
return __async(this, null, function* () {
|
|
991
|
-
const [id, secret] = decodeURIComponent(uriEncodedMessage).split("|");
|
|
992
|
-
const response = yield userManagementClient.tempTrasmission(id);
|
|
993
|
-
const data = response.data.message;
|
|
994
|
-
const buf = Buffer2.from(data, "base64");
|
|
995
|
-
const res = Buffer2.from(ECIESDecrypt2(Buffer2.from(secret, "hex"), buf).buffer).toString("ucs2");
|
|
996
|
-
return res;
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
1171
|
// src/errors.ts
|
|
1001
1172
|
var TransactionReviewError = class extends Error {
|
|
1002
1173
|
constructor(transactionReviewUrl) {
|
|
@@ -1020,68 +1191,6 @@ var TransactionReviewTimeout = class extends Error {
|
|
|
1020
1191
|
}
|
|
1021
1192
|
};
|
|
1022
1193
|
|
|
1023
|
-
// src/constants.ts
|
|
1024
|
-
var PARA_CORE_VERSION = '1.7.1';
|
|
1025
|
-
var PREFIX = "@CAPSULE/";
|
|
1026
|
-
var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
1027
|
-
var LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
|
|
1028
|
-
var LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
|
|
1029
|
-
var LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
|
|
1030
|
-
var LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
|
|
1031
|
-
var LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID = `${PREFIX}externalWalletUserId`;
|
|
1032
|
-
var LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
|
|
1033
|
-
var LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
|
|
1034
|
-
var LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
|
|
1035
|
-
var LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
|
|
1036
|
-
var LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
|
|
1037
|
-
var LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
|
|
1038
|
-
var SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
|
|
1039
|
-
var POLLING_INTERVAL_MS = 2e3;
|
|
1040
|
-
var SHORT_POLLING_INTERVAL_MS = 1e3;
|
|
1041
|
-
|
|
1042
|
-
// src/utils/listeners.ts
|
|
1043
|
-
function storageListener(e) {
|
|
1044
|
-
if (!e.url.includes(window.location.origin)) {
|
|
1045
|
-
return;
|
|
1046
|
-
}
|
|
1047
|
-
if (e.key === LOCAL_STORAGE_EXTERNAL_WALLETS) {
|
|
1048
|
-
this.updateExternalWalletsFromStorage();
|
|
1049
|
-
}
|
|
1050
|
-
if (e.key === SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR) {
|
|
1051
|
-
this.updateLoginEncryptionKeyPairFromStorage();
|
|
1052
|
-
}
|
|
1053
|
-
if (e.key === LOCAL_STORAGE_SESSION_COOKIE) {
|
|
1054
|
-
this.updateSessionCookieFromStorage();
|
|
1055
|
-
}
|
|
1056
|
-
if (e.key === LOCAL_STORAGE_CURRENT_WALLET_IDS) {
|
|
1057
|
-
this.updateWalletIdsFromStorage();
|
|
1058
|
-
}
|
|
1059
|
-
if (e.key === LOCAL_STORAGE_WALLETS || e.key === LOCAL_STORAGE_ED25519_WALLETS) {
|
|
1060
|
-
this.updateWalletsFromStorage();
|
|
1061
|
-
}
|
|
1062
|
-
if (e.key === LOCAL_STORAGE_EMAIL) {
|
|
1063
|
-
this.updateEmailFromStorage();
|
|
1064
|
-
}
|
|
1065
|
-
if (e.key === LOCAL_STORAGE_COUNTRY_CODE) {
|
|
1066
|
-
this.updateCountryCodeFromStorage();
|
|
1067
|
-
}
|
|
1068
|
-
if (e.key === LOCAL_STORAGE_PHONE) {
|
|
1069
|
-
this.updatePhoneFromStorage();
|
|
1070
|
-
}
|
|
1071
|
-
if (e.key === LOCAL_STORAGE_USER_ID) {
|
|
1072
|
-
this.updateUserIdFromStorage();
|
|
1073
|
-
}
|
|
1074
|
-
if (e.key === LOCAL_STORAGE_TELEGRAM_USER_ID) {
|
|
1075
|
-
this.updateTelegramUserIdFromStorage();
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
function setupListeners() {
|
|
1079
|
-
if (typeof window !== "undefined" && window.addEventListener && window.location) {
|
|
1080
|
-
window.removeEventListener("storage", storageListener.bind(this));
|
|
1081
|
-
window.addEventListener("storage", storageListener.bind(this));
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
1194
|
// src/ParaCore.ts
|
|
1086
1195
|
if (typeof global !== "undefined") {
|
|
1087
1196
|
global.Buffer = global.Buffer || NodeBuffer;
|
|
@@ -1093,7 +1202,7 @@ if (typeof global !== "undefined") {
|
|
|
1093
1202
|
self.global = self.global || self;
|
|
1094
1203
|
}
|
|
1095
1204
|
var { pki, jsbn } = forge3;
|
|
1096
|
-
var
|
|
1205
|
+
var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, prepareAuthState_fn, prepareLogin_fn, prepareLoginState_fn, prepareSignUpState_fn;
|
|
1097
1206
|
var _ParaCore = class _ParaCore {
|
|
1098
1207
|
/**
|
|
1099
1208
|
* Constructs a new `ParaCore` instance.
|
|
@@ -1103,6 +1212,10 @@ var _ParaCore = class _ParaCore {
|
|
|
1103
1212
|
* @returns - A new ParaCore instance.
|
|
1104
1213
|
*/
|
|
1105
1214
|
constructor(env, apiKey, opts) {
|
|
1215
|
+
__privateAdd(this, _ParaCore_instances);
|
|
1216
|
+
__privateAdd(this, _authInfo);
|
|
1217
|
+
this.isNativePasskey = false;
|
|
1218
|
+
__privateAdd(this, _partner);
|
|
1106
1219
|
this.isAwaitingAccountCreation = false;
|
|
1107
1220
|
this.isAwaitingLogin = false;
|
|
1108
1221
|
this.isAwaitingFarcaster = false;
|
|
@@ -1111,14 +1224,19 @@ var _ParaCore = class _ParaCore {
|
|
|
1111
1224
|
* The IDs of the currently active wallets, for each supported wallet type. Any signer integrations will default to the first viable wallet ID in this dictionary.
|
|
1112
1225
|
*/
|
|
1113
1226
|
this.currentWalletIds = {};
|
|
1114
|
-
|
|
1115
|
-
|
|
1227
|
+
/**
|
|
1228
|
+
* Wallets associated with the `ParaCore` instance.
|
|
1229
|
+
*/
|
|
1230
|
+
this.externalWallets = {};
|
|
1116
1231
|
this.localStorageGetItem = (key) => {
|
|
1117
1232
|
return this.platformUtils.localStorage.get(key);
|
|
1118
1233
|
};
|
|
1119
1234
|
this.localStorageSetItem = (key, value) => {
|
|
1120
1235
|
return this.platformUtils.localStorage.set(key, value);
|
|
1121
1236
|
};
|
|
1237
|
+
this.localStorageRemoveItem = (key) => {
|
|
1238
|
+
return this.platformUtils.localStorage.removeItem(key);
|
|
1239
|
+
};
|
|
1122
1240
|
this.sessionStorageGetItem = (key) => {
|
|
1123
1241
|
return this.platformUtils.sessionStorage.get(key);
|
|
1124
1242
|
};
|
|
@@ -1144,32 +1262,35 @@ var _ParaCore = class _ParaCore {
|
|
|
1144
1262
|
}
|
|
1145
1263
|
});
|
|
1146
1264
|
this.initializeFromStorage = () => {
|
|
1147
|
-
this.
|
|
1148
|
-
this.
|
|
1149
|
-
this.updatePhoneFromStorage();
|
|
1265
|
+
this.updateExternalWalletsFromStorage();
|
|
1266
|
+
this.updateAuthInfoFromStorage();
|
|
1150
1267
|
this.updateUserIdFromStorage();
|
|
1151
|
-
this.updateTelegramUserIdFromStorage();
|
|
1152
1268
|
this.updateWalletsFromStorage();
|
|
1153
1269
|
this.updateWalletIdsFromStorage();
|
|
1154
1270
|
this.updateSessionCookieFromStorage();
|
|
1155
1271
|
this.updateLoginEncryptionKeyPairFromStorage();
|
|
1156
|
-
this.updateExternalWalletsFromStorage();
|
|
1157
1272
|
};
|
|
1158
|
-
this.
|
|
1159
|
-
|
|
1273
|
+
this.updateAuthInfoFromStorage = () => {
|
|
1274
|
+
var _a;
|
|
1275
|
+
const storageAuthInfo = this.localStorageGetItem(LOCAL_STORAGE_AUTH_INFO) || void 0;
|
|
1276
|
+
let authInfo = jsonParse(storageAuthInfo);
|
|
1277
|
+
if (!authInfo) {
|
|
1278
|
+
const authParams = {
|
|
1279
|
+
email: this.localStorageGetItem(LOCAL_STORAGE_EMAIL) || void 0,
|
|
1280
|
+
phone: this.localStorageGetItem(LOCAL_STORAGE_PHONE) || void 0,
|
|
1281
|
+
countryCode: this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE) || void 0,
|
|
1282
|
+
farcasterUsername: this.localStorageGetItem(LOCAL_STORAGE_FARCASTER_USERNAME) || void 0,
|
|
1283
|
+
telegramUserId: this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0,
|
|
1284
|
+
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
1285
|
+
externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
|
|
1286
|
+
};
|
|
1287
|
+
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
1288
|
+
}
|
|
1289
|
+
__privateSet(this, _authInfo, authInfo);
|
|
1160
1290
|
};
|
|
1161
1291
|
this.updateUserIdFromStorage = () => {
|
|
1162
1292
|
this.userId = this.localStorageGetItem(LOCAL_STORAGE_USER_ID) || void 0;
|
|
1163
1293
|
};
|
|
1164
|
-
this.updatePhoneFromStorage = () => {
|
|
1165
|
-
this.phone = this.localStorageGetItem(LOCAL_STORAGE_PHONE) || void 0;
|
|
1166
|
-
};
|
|
1167
|
-
this.updateCountryCodeFromStorage = () => {
|
|
1168
|
-
this.countryCode = this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE) || void 0;
|
|
1169
|
-
};
|
|
1170
|
-
this.updateEmailFromStorage = () => {
|
|
1171
|
-
this.email = this.localStorageGetItem(LOCAL_STORAGE_EMAIL) || void 0;
|
|
1172
|
-
};
|
|
1173
1294
|
this.updateWalletsFromStorage = () => __async(this, null, function* () {
|
|
1174
1295
|
var _a;
|
|
1175
1296
|
const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
@@ -1199,7 +1320,7 @@ var _ParaCore = class _ParaCore {
|
|
|
1199
1320
|
this.updateWalletIdsFromStorage = () => {
|
|
1200
1321
|
var _a;
|
|
1201
1322
|
const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
1202
|
-
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
1323
|
+
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
1203
1324
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
1204
1325
|
return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
|
|
1205
1326
|
const wallet = Object.values(this.wallets).find(
|
|
@@ -1236,6 +1357,9 @@ var _ParaCore = class _ParaCore {
|
|
|
1236
1357
|
* @deprecated alias for `createWalletPerType`
|
|
1237
1358
|
**/
|
|
1238
1359
|
this.createWalletPerMissingType = this.createWalletPerType;
|
|
1360
|
+
if (!apiKey) {
|
|
1361
|
+
throw new Error("A Para API key is required.");
|
|
1362
|
+
}
|
|
1239
1363
|
if (!opts) opts = {};
|
|
1240
1364
|
let isE2E = false;
|
|
1241
1365
|
if (env === "E2E") {
|
|
@@ -1293,83 +1417,98 @@ var _ParaCore = class _ParaCore {
|
|
|
1293
1417
|
useDKLS: opts.useDKLSForCreation || !opts.offloadMPCComputationURL,
|
|
1294
1418
|
disableWebSockets: !!opts.disableWebSockets,
|
|
1295
1419
|
wasmOverride: opts.wasmOverride,
|
|
1296
|
-
cosmosPrefix: this.cosmosPrefix,
|
|
1297
1420
|
isE2E
|
|
1298
1421
|
};
|
|
1299
1422
|
if (opts.offloadMPCComputationURL) {
|
|
1300
1423
|
this.ctx.mpcComputationClient = initClient2(opts.offloadMPCComputationURL, opts.disableWorkers);
|
|
1301
1424
|
}
|
|
1302
|
-
try {
|
|
1303
|
-
__privateSet(this, _supportedWalletTypes, opts.supportedWalletTypes ? (() => {
|
|
1304
|
-
if (Object.values(opts.supportedWalletTypes).every(
|
|
1305
|
-
(config) => !!config && typeof config === "object" && config.optional
|
|
1306
|
-
)) {
|
|
1307
|
-
throw new Error("at least one wallet type must be non-optional");
|
|
1308
|
-
}
|
|
1309
|
-
if (!Object.keys(opts.supportedWalletTypes).every((type) => Object.values(WalletType2).includes(type))) {
|
|
1310
|
-
throw new Error("unsupported wallet type");
|
|
1311
|
-
}
|
|
1312
|
-
__privateSet(this, _supportedWalletTypesOpt, opts.supportedWalletTypes);
|
|
1313
|
-
return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
|
|
1314
|
-
var _a;
|
|
1315
|
-
if (!value) {
|
|
1316
|
-
return acc;
|
|
1317
|
-
}
|
|
1318
|
-
if (key === WalletType2.COSMOS && typeof value === "object" && !!value.prefix) {
|
|
1319
|
-
this.cosmosPrefix = value.prefix;
|
|
1320
|
-
}
|
|
1321
|
-
return [...acc, { type: key, optional: value === true ? false : (_a = value.optional) != null ? _a : false }];
|
|
1322
|
-
}, []);
|
|
1323
|
-
})() : void 0);
|
|
1324
|
-
} catch (e) {
|
|
1325
|
-
__privateSet(this, _supportedWalletTypes, void 0);
|
|
1326
|
-
}
|
|
1327
1425
|
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
1328
1426
|
return;
|
|
1329
1427
|
}
|
|
1330
1428
|
this.initializeFromStorage();
|
|
1331
1429
|
setupListeners.bind(this)();
|
|
1430
|
+
autoBind(this);
|
|
1332
1431
|
}
|
|
1333
|
-
get
|
|
1334
|
-
return
|
|
1432
|
+
get authInfo() {
|
|
1433
|
+
return __privateGet(this, _authInfo);
|
|
1335
1434
|
}
|
|
1336
|
-
get
|
|
1337
|
-
|
|
1435
|
+
get email() {
|
|
1436
|
+
var _a;
|
|
1437
|
+
return isEmail((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.email : void 0;
|
|
1338
1438
|
}
|
|
1339
|
-
get
|
|
1340
|
-
|
|
1439
|
+
get phone() {
|
|
1440
|
+
var _a;
|
|
1441
|
+
return isPhone((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.phone : void 0;
|
|
1341
1442
|
}
|
|
1342
|
-
get
|
|
1343
|
-
|
|
1443
|
+
get farcasterUsername() {
|
|
1444
|
+
var _a;
|
|
1445
|
+
return isFarcaster((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.farcasterUsername : void 0;
|
|
1446
|
+
}
|
|
1447
|
+
get telegramUserId() {
|
|
1448
|
+
var _a;
|
|
1449
|
+
return isTelegram((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.telegramUserId : void 0;
|
|
1344
1450
|
}
|
|
1345
1451
|
get externalWalletWithParaAuth() {
|
|
1346
1452
|
const externalWallets = Object.values(this.externalWallets);
|
|
1347
1453
|
return externalWallets.find((w) => w.isExternalWithParaAuth);
|
|
1348
1454
|
}
|
|
1349
|
-
get
|
|
1350
|
-
|
|
1455
|
+
get externalWalletConnectionType() {
|
|
1456
|
+
if (this.isExternalWalletAuth) {
|
|
1457
|
+
return "AUTHENTICATED";
|
|
1458
|
+
} else if (!!Object.keys(this.externalWallets).length) {
|
|
1459
|
+
return "CONNECTION_ONLY";
|
|
1460
|
+
}
|
|
1461
|
+
return "NONE";
|
|
1351
1462
|
}
|
|
1352
|
-
get
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
return [
|
|
1356
|
-
...acc,
|
|
1357
|
-
...((_a = this.currentWalletIds[type]) != null ? _a : []).map((id) => {
|
|
1358
|
-
return [id, type];
|
|
1359
|
-
})
|
|
1360
|
-
];
|
|
1361
|
-
}, []);
|
|
1463
|
+
get isEmail() {
|
|
1464
|
+
var _a;
|
|
1465
|
+
return isEmail((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
1362
1466
|
}
|
|
1363
|
-
get
|
|
1364
|
-
|
|
1467
|
+
get isPhone() {
|
|
1468
|
+
var _a;
|
|
1469
|
+
return isPhone((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
1365
1470
|
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1471
|
+
get isFarcaster() {
|
|
1472
|
+
var _a;
|
|
1473
|
+
return isFarcaster((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
1474
|
+
}
|
|
1475
|
+
get isTelegram() {
|
|
1476
|
+
var _a;
|
|
1477
|
+
return isTelegram((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
1478
|
+
}
|
|
1479
|
+
get isExternalWalletAuth() {
|
|
1480
|
+
var _a;
|
|
1481
|
+
return isExternalWallet((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
|
|
1482
|
+
}
|
|
1483
|
+
get partnerId() {
|
|
1484
|
+
var _a;
|
|
1485
|
+
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id;
|
|
1486
|
+
}
|
|
1487
|
+
get currentWalletIdsArray() {
|
|
1488
|
+
var _a, _b;
|
|
1489
|
+
return ((_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
1490
|
+
(acc, { type }) => {
|
|
1491
|
+
var _a2;
|
|
1492
|
+
return [
|
|
1493
|
+
...acc,
|
|
1494
|
+
...((_a2 = this.currentWalletIds[type]) != null ? _a2 : []).map((id) => {
|
|
1495
|
+
return [id, type];
|
|
1496
|
+
})
|
|
1497
|
+
];
|
|
1498
|
+
},
|
|
1499
|
+
[]
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
get currentWalletIdsUnique() {
|
|
1503
|
+
return [...new Set(Object.values(this.currentWalletIds).flat())];
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* A map of pre-generated wallet identifiers that can be claimed in the current instance.
|
|
1507
|
+
*/
|
|
1508
|
+
get pregenIds() {
|
|
1509
|
+
return __spreadValues({}, Object.values(this.wallets).filter((wallet) => !this.userId || this.isPregenWalletClaimable(wallet)).reduce((acc, wallet) => {
|
|
1510
|
+
var _a, _b;
|
|
1511
|
+
if (((_a = acc[wallet.pregenIdentifierType]) != null ? _a : []).includes(wallet.pregenIdentifier)) {
|
|
1373
1512
|
return acc;
|
|
1374
1513
|
}
|
|
1375
1514
|
return __spreadProps(__spreadValues({}, acc), {
|
|
@@ -1386,11 +1525,16 @@ var _ParaCore = class _ParaCore {
|
|
|
1386
1525
|
return this.currentWalletIdsArray.length > 1;
|
|
1387
1526
|
}
|
|
1388
1527
|
get supportedWalletTypes() {
|
|
1528
|
+
var _a, _b;
|
|
1529
|
+
return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
1530
|
+
}
|
|
1531
|
+
get cosmosPrefix() {
|
|
1389
1532
|
var _a;
|
|
1390
|
-
return (_a = __privateGet(this,
|
|
1533
|
+
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
|
|
1391
1534
|
}
|
|
1392
1535
|
get isWalletTypeEnabled() {
|
|
1393
|
-
|
|
1536
|
+
var _a;
|
|
1537
|
+
return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
1394
1538
|
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
1395
1539
|
}, {});
|
|
1396
1540
|
}
|
|
@@ -1439,7 +1583,7 @@ var _ParaCore = class _ParaCore {
|
|
|
1439
1583
|
}
|
|
1440
1584
|
isWalletSupported(wallet) {
|
|
1441
1585
|
var _a, _b;
|
|
1442
|
-
return !
|
|
1586
|
+
return !((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = __privateGet(this, _partner).supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
1443
1587
|
}
|
|
1444
1588
|
isWalletOwned(wallet) {
|
|
1445
1589
|
return this.isWalletSupported(wallet) && !(wallet == null ? void 0 : wallet.pregenIdentifier) && !(wallet == null ? void 0 : wallet.pregenIdentifierType) && !!this.userId && (wallet == null ? void 0 : wallet.userId) === this.userId;
|
|
@@ -1455,7 +1599,7 @@ var _ParaCore = class _ParaCore {
|
|
|
1455
1599
|
));
|
|
1456
1600
|
}
|
|
1457
1601
|
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
1458
|
-
var _a;
|
|
1602
|
+
var _a, _b;
|
|
1459
1603
|
let error;
|
|
1460
1604
|
if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
|
|
1461
1605
|
return true;
|
|
@@ -1470,10 +1614,10 @@ var _ParaCore = class _ParaCore {
|
|
|
1470
1614
|
} else if (!isOwned && !isUnclaimed) {
|
|
1471
1615
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
1472
1616
|
} else if (!this.isWalletSupported(wallet)) {
|
|
1473
|
-
error = `wallet with id ${wallet
|
|
1617
|
+
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || []).map(({ type }) => type).join(", ")}`;
|
|
1474
1618
|
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
1475
|
-
var _a2,
|
|
1476
|
-
return (
|
|
1619
|
+
var _a2, _b2;
|
|
1620
|
+
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
1477
1621
|
}))) {
|
|
1478
1622
|
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
|
|
1479
1623
|
} else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
|
|
@@ -1497,10 +1641,10 @@ var _ParaCore = class _ParaCore {
|
|
|
1497
1641
|
* @returns the formatted address
|
|
1498
1642
|
*/
|
|
1499
1643
|
getDisplayAddress(walletId, options = {}) {
|
|
1500
|
-
var _a;
|
|
1644
|
+
var _a, _b, _c, _d;
|
|
1501
1645
|
if (this.externalWallets[walletId]) {
|
|
1502
1646
|
const wallet2 = this.externalWallets[walletId];
|
|
1503
|
-
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix }) : wallet2.address;
|
|
1647
|
+
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix }) : wallet2.address;
|
|
1504
1648
|
}
|
|
1505
1649
|
const wallet = this.findWallet(walletId, options.addressType);
|
|
1506
1650
|
if (!wallet) {
|
|
@@ -1509,13 +1653,13 @@ var _ParaCore = class _ParaCore {
|
|
|
1509
1653
|
let str;
|
|
1510
1654
|
switch (wallet.type) {
|
|
1511
1655
|
case WalletType2.COSMOS:
|
|
1512
|
-
str = getCosmosAddress(wallet.publicKey, (
|
|
1656
|
+
str = getCosmosAddress(wallet.publicKey, (_c = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _c : "cosmos");
|
|
1513
1657
|
break;
|
|
1514
1658
|
default:
|
|
1515
1659
|
str = wallet.address;
|
|
1516
1660
|
break;
|
|
1517
1661
|
}
|
|
1518
|
-
return options.truncate ? truncateAddress(str, wallet.type, { prefix: this.cosmosPrefix }) : str;
|
|
1662
|
+
return options.truncate ? truncateAddress(str, wallet.type, { prefix: (_d = __privateGet(this, _partner)) == null ? void 0 : _d.cosmosPrefix }) : str;
|
|
1519
1663
|
}
|
|
1520
1664
|
/**
|
|
1521
1665
|
* Returns a unique hash for a wallet suitable for use as an identicon seed.
|
|
@@ -1540,8 +1684,25 @@ var _ParaCore = class _ParaCore {
|
|
|
1540
1684
|
}
|
|
1541
1685
|
constructPortalUrl(_0) {
|
|
1542
1686
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
1543
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
1544
|
-
const
|
|
1687
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1688
|
+
const [isCreate, isLogin, isOnRamp] = [
|
|
1689
|
+
["createAuth", "createPassword"].includes(type),
|
|
1690
|
+
["loginAuth", "loginPassword"].includes(type),
|
|
1691
|
+
type === "onRamp"
|
|
1692
|
+
];
|
|
1693
|
+
let auth;
|
|
1694
|
+
if (isCreate || isLogin) {
|
|
1695
|
+
auth = this.assertIsAuthSet().auth;
|
|
1696
|
+
}
|
|
1697
|
+
let sessionId = opts.sessionId;
|
|
1698
|
+
if ((isLogin || isOnRamp) && !sessionId) {
|
|
1699
|
+
const session = yield this.touchSession(true);
|
|
1700
|
+
sessionId = session.sessionId;
|
|
1701
|
+
}
|
|
1702
|
+
if (!this.loginEncryptionKeyPair) {
|
|
1703
|
+
yield this.setLoginEncryptionKeyPair();
|
|
1704
|
+
}
|
|
1705
|
+
const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL();
|
|
1545
1706
|
let path;
|
|
1546
1707
|
switch (type) {
|
|
1547
1708
|
case "createPassword": {
|
|
@@ -1572,61 +1733,50 @@ var _ParaCore = class _ParaCore {
|
|
|
1572
1733
|
throw new Error(`invalid URL type ${type}`);
|
|
1573
1734
|
}
|
|
1574
1735
|
}
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
const partner = opts.partnerId ? (_a = (yield this.ctx.client.getPartner(opts.partnerId)).data) == null ? void 0 : _a.partner : void 0;
|
|
1736
|
+
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1737
|
+
const thisDevice = (_a = opts.thisDevice) != null ? _a : {
|
|
1738
|
+
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
1739
|
+
sessionId
|
|
1740
|
+
};
|
|
1581
1741
|
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
1582
1742
|
apiKey: this.ctx.apiKey,
|
|
1583
|
-
partnerId:
|
|
1584
|
-
portalFont: ((_b = opts.
|
|
1585
|
-
portalBorderRadius: ((_d = opts.
|
|
1586
|
-
portalThemeMode: ((_f = opts.
|
|
1587
|
-
portalAccentColor: ((_h = opts.
|
|
1588
|
-
portalForegroundColor: ((_j = opts.
|
|
1589
|
-
portalBackgroundColor: ((_l = opts.
|
|
1743
|
+
partnerId: partner.id,
|
|
1744
|
+
portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
|
|
1745
|
+
portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
|
|
1746
|
+
portalThemeMode: ((_f = opts.portalTheme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
|
|
1747
|
+
portalAccentColor: ((_h = opts.portalTheme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
|
|
1748
|
+
portalForegroundColor: ((_j = opts.portalTheme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
|
|
1749
|
+
portalBackgroundColor: ((_l = opts.portalTheme) == null ? void 0 : _l.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_m = this.portalTheme) == null ? void 0 : _m.backgroundColor),
|
|
1590
1750
|
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
1591
1751
|
portalTextColor: this.portalTextColor,
|
|
1592
1752
|
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
1593
|
-
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1753
|
+
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
1754
|
+
}, auth && (isCreate || isLogin) ? auth : {}), isOnRamp ? { sessionId } : {}), isLogin ? __spreadProps(__spreadValues({
|
|
1755
|
+
sessionId: thisDevice.sessionId,
|
|
1756
|
+
encryptionKey: thisDevice.encryptionKey
|
|
1757
|
+
}, opts.newDevice ? {
|
|
1758
|
+
newDeviceSessionLookupId: opts.newDevice.sessionId,
|
|
1759
|
+
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
1760
|
+
} : {}), {
|
|
1761
|
+
pregenIds: JSON.stringify(this.pregenIds)
|
|
1762
|
+
}) : {}), opts.params || {});
|
|
1763
|
+
const url = constructUrl({ base, path, params });
|
|
1764
|
+
if (opts.shorten) {
|
|
1765
|
+
return shortenUrl(this.ctx, url);
|
|
1766
|
+
}
|
|
1767
|
+
return url;
|
|
1607
1768
|
});
|
|
1608
1769
|
}
|
|
1609
1770
|
touchSession(regenerate = false) {
|
|
1610
1771
|
return __async(this, null, function* () {
|
|
1611
|
-
|
|
1612
|
-
this.
|
|
1613
|
-
|
|
1772
|
+
var _a, _b, _c;
|
|
1773
|
+
const session = yield this.ctx.client.touchSession(regenerate);
|
|
1774
|
+
if (!__privateGet(this, _partner) || ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) !== session.partnerId || !supportedWalletTypesEq(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
|
|
1775
|
+
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
1776
|
+
}
|
|
1777
|
+
return session;
|
|
1614
1778
|
});
|
|
1615
1779
|
}
|
|
1616
|
-
setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
|
|
1617
|
-
if (supportedWalletTypes && !__privateGet(this, _supportedWalletTypes)) {
|
|
1618
|
-
__privateSet(this, _supportedWalletTypes, supportedWalletTypes);
|
|
1619
|
-
Object.keys(this.currentWalletIds).forEach((type) => {
|
|
1620
|
-
var _a;
|
|
1621
|
-
if (!((_a = __privateGet(this, _supportedWalletTypes)) == null ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
|
|
1622
|
-
delete this.currentWalletIds[type];
|
|
1623
|
-
}
|
|
1624
|
-
});
|
|
1625
|
-
}
|
|
1626
|
-
if (cosmosPrefix && !this.cosmosPrefix) {
|
|
1627
|
-
this.cosmosPrefix = cosmosPrefix;
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
1780
|
getVerificationEmailProps() {
|
|
1631
1781
|
return {
|
|
1632
1782
|
brandColor: this.emailPrimaryColor,
|
|
@@ -1656,12 +1806,26 @@ var _ParaCore = class _ParaCore {
|
|
|
1656
1806
|
*/
|
|
1657
1807
|
init() {
|
|
1658
1808
|
return __async(this, null, function* () {
|
|
1659
|
-
var _a;
|
|
1660
|
-
this.email = (yield this.localStorageGetItem(LOCAL_STORAGE_EMAIL)) || void 0;
|
|
1661
|
-
this.countryCode = (yield this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE)) || void 0;
|
|
1662
|
-
this.phone = (yield this.localStorageGetItem(LOCAL_STORAGE_PHONE)) || void 0;
|
|
1809
|
+
var _a, _b;
|
|
1663
1810
|
this.userId = (yield this.localStorageGetItem(LOCAL_STORAGE_USER_ID)) || void 0;
|
|
1664
|
-
|
|
1811
|
+
const storageAuthInfo = (yield this.localStorageGetItem(LOCAL_STORAGE_AUTH_INFO)) || void 0;
|
|
1812
|
+
const stringExternalWallets = yield this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
1813
|
+
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
1814
|
+
yield this.setExternalWallets(_externalWallets);
|
|
1815
|
+
let authInfo = jsonParse(storageAuthInfo);
|
|
1816
|
+
if (!authInfo) {
|
|
1817
|
+
const authParams = {
|
|
1818
|
+
email: (yield this.localStorageGetItem(LOCAL_STORAGE_EMAIL)) || void 0,
|
|
1819
|
+
phone: (yield this.localStorageGetItem(LOCAL_STORAGE_PHONE)) || void 0,
|
|
1820
|
+
countryCode: (yield this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE)) || void 0,
|
|
1821
|
+
farcasterUsername: (yield this.localStorageGetItem(LOCAL_STORAGE_FARCASTER_USERNAME)) || void 0,
|
|
1822
|
+
telegramUserId: (yield this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0,
|
|
1823
|
+
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
1824
|
+
externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
|
|
1825
|
+
};
|
|
1826
|
+
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
1827
|
+
}
|
|
1828
|
+
__privateSet(this, _authInfo, authInfo);
|
|
1665
1829
|
const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_WALLETS);
|
|
1666
1830
|
const _wallets = JSON.parse(stringWallets || "{}");
|
|
1667
1831
|
const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_ED25519_WALLETS);
|
|
@@ -1674,7 +1838,7 @@ var _ParaCore = class _ParaCore {
|
|
|
1674
1838
|
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
|
|
1675
1839
|
}, {}));
|
|
1676
1840
|
yield this.setWallets(wallets);
|
|
1677
|
-
const _currentWalletIds = (
|
|
1841
|
+
const _currentWalletIds = (_b = yield this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _b : void 0;
|
|
1678
1842
|
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
1679
1843
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
1680
1844
|
return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
|
|
@@ -1693,21 +1857,42 @@ var _ParaCore = class _ParaCore {
|
|
|
1693
1857
|
if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
|
|
1694
1858
|
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
1695
1859
|
}
|
|
1696
|
-
const stringExternalWallets = yield this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
1697
|
-
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
1698
|
-
yield this.setExternalWallets(_externalWallets);
|
|
1699
1860
|
setupListeners.bind(this)();
|
|
1700
1861
|
yield this.touchSession();
|
|
1701
1862
|
});
|
|
1702
1863
|
}
|
|
1864
|
+
setAuth(_0) {
|
|
1865
|
+
return __async(this, arguments, function* (auth, { extras = {}, userId } = {}) {
|
|
1866
|
+
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), extras || {});
|
|
1867
|
+
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
1868
|
+
if (!!userId) {
|
|
1869
|
+
yield this.setUserId(userId);
|
|
1870
|
+
}
|
|
1871
|
+
return __privateGet(this, _authInfo);
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1874
|
+
assertUserId() {
|
|
1875
|
+
if (!this.userId) {
|
|
1876
|
+
throw new Error("no userId is set");
|
|
1877
|
+
}
|
|
1878
|
+
return this.userId;
|
|
1879
|
+
}
|
|
1880
|
+
assertIsAuthSet(allowed) {
|
|
1881
|
+
if (!__privateGet(this, _authInfo)) {
|
|
1882
|
+
throw new Error("auth is not set");
|
|
1883
|
+
}
|
|
1884
|
+
if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
|
|
1885
|
+
throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
|
|
1886
|
+
}
|
|
1887
|
+
return __privateGet(this, _authInfo);
|
|
1888
|
+
}
|
|
1703
1889
|
/**
|
|
1704
1890
|
* Sets the email associated with the `ParaCore` instance.
|
|
1705
1891
|
* @param email - Email to set.
|
|
1706
1892
|
*/
|
|
1707
1893
|
setEmail(email) {
|
|
1708
1894
|
return __async(this, null, function* () {
|
|
1709
|
-
this.email
|
|
1710
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_EMAIL, email);
|
|
1895
|
+
yield this.setAuth({ email });
|
|
1711
1896
|
});
|
|
1712
1897
|
}
|
|
1713
1898
|
/**
|
|
@@ -1716,8 +1901,7 @@ var _ParaCore = class _ParaCore {
|
|
|
1716
1901
|
*/
|
|
1717
1902
|
setTelegramUserId(telegramUserId) {
|
|
1718
1903
|
return __async(this, null, function* () {
|
|
1719
|
-
this.telegramUserId
|
|
1720
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
|
|
1904
|
+
yield this.setAuth({ telegramUserId });
|
|
1721
1905
|
});
|
|
1722
1906
|
}
|
|
1723
1907
|
/**
|
|
@@ -1725,12 +1909,9 @@ var _ParaCore = class _ParaCore {
|
|
|
1725
1909
|
* @param phone - Phone number to set.
|
|
1726
1910
|
* @param countryCode - Country Code to set.
|
|
1727
1911
|
*/
|
|
1728
|
-
|
|
1912
|
+
setPhone(phone, countryCode) {
|
|
1729
1913
|
return __async(this, null, function* () {
|
|
1730
|
-
this.phone
|
|
1731
|
-
this.countryCode = countryCode;
|
|
1732
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_PHONE, phone);
|
|
1733
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_COUNTRY_CODE, countryCode);
|
|
1914
|
+
yield this.setAuth({ phone: formatPhoneNumber(phone, countryCode) });
|
|
1734
1915
|
});
|
|
1735
1916
|
}
|
|
1736
1917
|
/**
|
|
@@ -1739,8 +1920,7 @@ var _ParaCore = class _ParaCore {
|
|
|
1739
1920
|
*/
|
|
1740
1921
|
setFarcasterUsername(farcasterUsername) {
|
|
1741
1922
|
return __async(this, null, function* () {
|
|
1742
|
-
this.farcasterUsername
|
|
1743
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
|
|
1923
|
+
yield this.setAuth({ farcasterUsername });
|
|
1744
1924
|
});
|
|
1745
1925
|
}
|
|
1746
1926
|
/**
|
|
@@ -1832,22 +2012,12 @@ var _ParaCore = class _ParaCore {
|
|
|
1832
2012
|
getEmail() {
|
|
1833
2013
|
return this.email;
|
|
1834
2014
|
}
|
|
1835
|
-
/**
|
|
1836
|
-
* Gets the phone object associated with the `ParaCore` instance.
|
|
1837
|
-
* @returns - phone object with phone number and country code associated with the `ParaCore` instance.
|
|
1838
|
-
*/
|
|
1839
|
-
getPhone() {
|
|
1840
|
-
return { phone: this.phone, countryCode: this.countryCode };
|
|
1841
|
-
}
|
|
1842
2015
|
/**
|
|
1843
2016
|
* Gets the formatted phone number associated with the `ParaCore` instance.
|
|
1844
2017
|
* @returns - formatted phone number associated with the `ParaCore` instance.
|
|
1845
2018
|
*/
|
|
1846
2019
|
getPhoneNumber() {
|
|
1847
|
-
|
|
1848
|
-
return void 0;
|
|
1849
|
-
}
|
|
1850
|
-
return normalizePhoneNumber(this.countryCode, this.phone);
|
|
2020
|
+
return this.phone;
|
|
1851
2021
|
}
|
|
1852
2022
|
/**
|
|
1853
2023
|
* Gets the farcaster username associated with the `ParaCore` instance.
|
|
@@ -1876,23 +2046,6 @@ var _ParaCore = class _ParaCore {
|
|
|
1876
2046
|
dispatchEvent(ParaEvent.WALLETS_CHANGE_EVENT, null);
|
|
1877
2047
|
});
|
|
1878
2048
|
}
|
|
1879
|
-
/**
|
|
1880
|
-
* Fetches the most recent OAuth account metadata for the signed-in user.
|
|
1881
|
-
* If applicable, this will include the user's most recent metadata from their Google, Apple, Facebook, X, Discord, Farcaster, or Telegram account, the last time they signed in to your app.
|
|
1882
|
-
* @returns {Promise<AccountMetadata>} the user's account metadata.
|
|
1883
|
-
*/
|
|
1884
|
-
getAccountMetadata() {
|
|
1885
|
-
return __async(this, null, function* () {
|
|
1886
|
-
if (!(yield this.isSessionActive()) || !this.userId) {
|
|
1887
|
-
throw new Error("no signed-in user");
|
|
1888
|
-
}
|
|
1889
|
-
const {
|
|
1890
|
-
data: { partnerId }
|
|
1891
|
-
} = yield this.touchSession();
|
|
1892
|
-
const { accountMetadata } = yield this.ctx.client.getAccountMetadata(this.userId, partnerId);
|
|
1893
|
-
return accountMetadata;
|
|
1894
|
-
});
|
|
1895
|
-
}
|
|
1896
2049
|
/**
|
|
1897
2050
|
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
1898
2051
|
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
@@ -1946,8 +2099,10 @@ var _ParaCore = class _ParaCore {
|
|
|
1946
2099
|
}
|
|
1947
2100
|
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
1948
2101
|
var _a, _c, _d;
|
|
1949
|
-
if (!this.isExternalWalletAuth
|
|
1950
|
-
|
|
2102
|
+
if (!this.isExternalWalletAuth) {
|
|
2103
|
+
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
2104
|
+
return Object.values(this.externalWallets)[0];
|
|
2105
|
+
}
|
|
1951
2106
|
}
|
|
1952
2107
|
if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
|
|
1953
2108
|
return this.externalWallets[idOrAddress];
|
|
@@ -1994,10 +2149,8 @@ var _ParaCore = class _ParaCore {
|
|
|
1994
2149
|
}
|
|
1995
2150
|
assertIsValidWalletType(type, walletTypes) {
|
|
1996
2151
|
return __async(this, null, function* () {
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
}
|
|
2000
|
-
if (!type || !Object.values(WalletType2).includes(type) || !(walletTypes != null ? walletTypes : this.supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
2152
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2153
|
+
if (!type || !Object.values(WalletType2).includes(type) || !(walletTypes != null ? walletTypes : supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
2001
2154
|
throw new Error(`wallet type ${type} is not supported`);
|
|
2002
2155
|
}
|
|
2003
2156
|
return type;
|
|
@@ -2005,33 +2158,29 @@ var _ParaCore = class _ParaCore {
|
|
|
2005
2158
|
}
|
|
2006
2159
|
getMissingTypes() {
|
|
2007
2160
|
return __async(this, null, function* () {
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
}
|
|
2011
|
-
return this.supportedWalletTypes.filter(
|
|
2161
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2162
|
+
return supportedWalletTypes.filter(
|
|
2012
2163
|
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
|
|
2013
2164
|
).map(({ type }) => type);
|
|
2014
2165
|
});
|
|
2015
2166
|
}
|
|
2016
2167
|
getTypesToCreate(types) {
|
|
2017
2168
|
return __async(this, null, function* () {
|
|
2018
|
-
|
|
2019
|
-
yield this.touchSession();
|
|
2020
|
-
}
|
|
2169
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2021
2170
|
return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
2022
2171
|
switch (scheme) {
|
|
2023
2172
|
case WalletScheme2.ED25519:
|
|
2024
2173
|
return WalletType2.SOLANA;
|
|
2025
2174
|
default:
|
|
2026
|
-
return
|
|
2175
|
+
return supportedWalletTypes.some(({ type, optional }) => type === WalletType2.COSMOS && !optional) ? WalletType2.COSMOS : WalletType2.EVM;
|
|
2027
2176
|
}
|
|
2028
2177
|
});
|
|
2029
2178
|
});
|
|
2030
2179
|
}
|
|
2031
|
-
getPartnerURL(
|
|
2180
|
+
getPartnerURL() {
|
|
2032
2181
|
return __async(this, null, function* () {
|
|
2033
|
-
const
|
|
2034
|
-
return
|
|
2182
|
+
const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2183
|
+
return portalUrl;
|
|
2035
2184
|
});
|
|
2036
2185
|
}
|
|
2037
2186
|
/**
|
|
@@ -2039,75 +2188,9 @@ var _ParaCore = class _ParaCore {
|
|
|
2039
2188
|
* @param partnerId: string - id of the partner to get the portal URL for
|
|
2040
2189
|
* @returns - portal URL
|
|
2041
2190
|
*/
|
|
2042
|
-
getPortalURL(
|
|
2043
|
-
return __async(this, null, function* () {
|
|
2044
|
-
return partnerId && (yield this.getPartnerURL(partnerId)) || getPortalBaseURL(this.ctx);
|
|
2045
|
-
});
|
|
2046
|
-
}
|
|
2047
|
-
getWebAuthURLForCreate(_a) {
|
|
2048
|
-
return __async(this, null, function* () {
|
|
2049
|
-
var _b = _a, {
|
|
2050
|
-
webAuthId
|
|
2051
|
-
} = _b, options = __objRest(_b, [
|
|
2052
|
-
"webAuthId"
|
|
2053
|
-
]);
|
|
2054
|
-
return this.constructPortalUrl("createAuth", __spreadProps(__spreadValues({}, options), { pathId: webAuthId }));
|
|
2055
|
-
});
|
|
2056
|
-
}
|
|
2057
|
-
getPasswordURLForCreate(_c) {
|
|
2058
|
-
return __async(this, null, function* () {
|
|
2059
|
-
var _d = _c, {
|
|
2060
|
-
passwordId
|
|
2061
|
-
} = _d, options = __objRest(_d, [
|
|
2062
|
-
"passwordId"
|
|
2063
|
-
]);
|
|
2064
|
-
return this.constructPortalUrl("createPassword", __spreadProps(__spreadValues({}, options), {
|
|
2065
|
-
pathId: passwordId
|
|
2066
|
-
}));
|
|
2067
|
-
});
|
|
2068
|
-
}
|
|
2069
|
-
getShortUrl(compressedUrl) {
|
|
2070
|
-
return constructUrl({
|
|
2071
|
-
base: getPortalBaseURL(this.ctx),
|
|
2072
|
-
path: `/short/${compressedUrl}`
|
|
2073
|
-
});
|
|
2074
|
-
}
|
|
2075
|
-
shortenLoginLink(link) {
|
|
2076
|
-
return __async(this, null, function* () {
|
|
2077
|
-
const url = yield upload(link, this.ctx.client);
|
|
2078
|
-
return this.getShortUrl(url);
|
|
2079
|
-
});
|
|
2080
|
-
}
|
|
2081
|
-
/**
|
|
2082
|
-
* Generates a URL for registering a new WebAuth passkey.
|
|
2083
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
2084
|
-
* @returns - the URL for creating a new passkey
|
|
2085
|
-
*/
|
|
2086
|
-
getWebAuthURLForLogin(opts) {
|
|
2087
|
-
return __async(this, null, function* () {
|
|
2088
|
-
return this.constructPortalUrl("loginAuth", opts);
|
|
2089
|
-
});
|
|
2090
|
-
}
|
|
2091
|
-
/**
|
|
2092
|
-
* Generates a URL for registering a new user password.
|
|
2093
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
2094
|
-
* @returns - the URL for creating a new password
|
|
2095
|
-
*/
|
|
2096
|
-
getPasswordURLForLogin(opts) {
|
|
2097
|
-
return __async(this, null, function* () {
|
|
2098
|
-
return this.constructPortalUrl("loginPassword", opts);
|
|
2099
|
-
});
|
|
2100
|
-
}
|
|
2101
|
-
/**
|
|
2102
|
-
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
2103
|
-
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
2104
|
-
* @returns - web auth url
|
|
2105
|
-
*/
|
|
2106
|
-
getWebAuthURLForLoginForPhone(opts) {
|
|
2191
|
+
getPortalURL() {
|
|
2107
2192
|
return __async(this, null, function* () {
|
|
2108
|
-
return this.
|
|
2109
|
-
authType: "phone"
|
|
2110
|
-
}, opts));
|
|
2193
|
+
return (yield this.getPartnerURL()) || getPortalBaseURL(this.ctx);
|
|
2111
2194
|
});
|
|
2112
2195
|
}
|
|
2113
2196
|
/**
|
|
@@ -2170,1446 +2253,588 @@ var _ParaCore = class _ParaCore {
|
|
|
2170
2253
|
});
|
|
2171
2254
|
}
|
|
2172
2255
|
/**
|
|
2173
|
-
*
|
|
2174
|
-
* @param {Object} opts the options object
|
|
2175
|
-
* @param {string} opts.email the email to check.
|
|
2176
|
-
* @returns true if user exists, false otherwise.
|
|
2177
|
-
*/
|
|
2178
|
-
checkIfUserExists(_0) {
|
|
2179
|
-
return __async(this, arguments, function* ({ email }) {
|
|
2180
|
-
const res = yield this.ctx.client.checkUserExists({ email });
|
|
2181
|
-
return res.data.exists;
|
|
2182
|
-
});
|
|
2183
|
-
}
|
|
2184
|
-
/**
|
|
2185
|
-
* Checks if a user exists for a phone number.
|
|
2186
|
-
* @param {Object} opts the options object
|
|
2187
|
-
* @param {string} opts.phone - phone number to check.
|
|
2188
|
-
* @param {string} opts.countryCode - the country code.
|
|
2189
|
-
* @returns true if user exists, false otherwise.
|
|
2190
|
-
*/
|
|
2191
|
-
checkIfUserExistsByPhone(_0) {
|
|
2192
|
-
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
2193
|
-
const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
|
|
2194
|
-
return res.data.exists;
|
|
2195
|
-
});
|
|
2196
|
-
}
|
|
2197
|
-
/**
|
|
2198
|
-
* Creates a new user.
|
|
2199
|
-
* @param {Object} opts the options object
|
|
2200
|
-
* @param {string} opts.email the email to use.
|
|
2256
|
+
* Resend a verification email for the current user.
|
|
2201
2257
|
*/
|
|
2202
|
-
|
|
2203
|
-
return __async(this,
|
|
2204
|
-
this.
|
|
2205
|
-
|
|
2206
|
-
const { userId } = yield this.ctx.client.createUser(__spreadValues({
|
|
2207
|
-
email: this.email
|
|
2258
|
+
resendVerificationCode() {
|
|
2259
|
+
return __async(this, null, function* () {
|
|
2260
|
+
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
2261
|
+
userId: this.userId
|
|
2208
2262
|
}, this.getVerificationEmailProps()));
|
|
2209
|
-
yield this.setUserId(userId);
|
|
2210
|
-
});
|
|
2211
|
-
}
|
|
2212
|
-
/**
|
|
2213
|
-
* Creates a new user with a phone number.
|
|
2214
|
-
* @param {Object} opts the options object
|
|
2215
|
-
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
2216
|
-
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
2217
|
-
*/
|
|
2218
|
-
createUserByPhone(_0) {
|
|
2219
|
-
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
2220
|
-
this.requireApiKey();
|
|
2221
|
-
yield this.setPhoneNumber(phone, countryCode);
|
|
2222
|
-
const { userId } = yield this.ctx.client.createUser({
|
|
2223
|
-
phone: this.phone,
|
|
2224
|
-
countryCode: this.countryCode
|
|
2225
|
-
});
|
|
2226
|
-
yield this.setUserId(userId);
|
|
2227
2263
|
});
|
|
2228
2264
|
}
|
|
2229
2265
|
/**
|
|
2230
|
-
*
|
|
2231
|
-
* @
|
|
2232
|
-
* @param {string} opts.address the external wallet address to use for identification.
|
|
2233
|
-
* @param {WalletType} opts.type type of external wallet to use for identification.
|
|
2234
|
-
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
2266
|
+
* Checks if the current session is active.
|
|
2267
|
+
* @returns `true` if active, `false` otherwise
|
|
2235
2268
|
*/
|
|
2236
|
-
|
|
2269
|
+
isSessionActive() {
|
|
2237
2270
|
return __async(this, null, function* () {
|
|
2238
|
-
this.
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
// If the wallet isn't using full Para auth we want to track the login here
|
|
2244
|
-
shouldTrackUser: !wallet.withFullParaAuth
|
|
2245
|
-
});
|
|
2246
|
-
yield this.setExternalWallet(wallet);
|
|
2247
|
-
yield this.setUserId(res.userId);
|
|
2248
|
-
return res;
|
|
2249
|
-
});
|
|
2250
|
-
}
|
|
2251
|
-
/**
|
|
2252
|
-
* Returns whether or not the user is connected with only an external wallet, not an external wallet with Para auth.
|
|
2253
|
-
*/
|
|
2254
|
-
isUsingExternalWallet() {
|
|
2255
|
-
return !this.isExternalWalletAuth && !!Object.keys(this.externalWallets).length;
|
|
2256
|
-
}
|
|
2257
|
-
/**
|
|
2258
|
-
* Passes the email code obtained from the user for verification.
|
|
2259
|
-
* @param {Object} opts the options object
|
|
2260
|
-
* @param {string} verificationCode the six-digit code to check
|
|
2261
|
-
* @returns {string} the web auth url for creating a new credential
|
|
2262
|
-
*/
|
|
2263
|
-
verifyEmail(_0) {
|
|
2264
|
-
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2265
|
-
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
2266
|
-
return this.getSetUpBiometricsURL();
|
|
2267
|
-
});
|
|
2268
|
-
}
|
|
2269
|
-
verifyExternalWallet(_0) {
|
|
2270
|
-
return __async(this, arguments, function* ({
|
|
2271
|
-
address,
|
|
2272
|
-
signedMessage,
|
|
2273
|
-
cosmosPublicKeyHex,
|
|
2274
|
-
cosmosSigner
|
|
2275
|
-
}) {
|
|
2276
|
-
yield this.ctx.client.verifyExternalWallet(this.userId, { address, signedMessage, cosmosPublicKeyHex, cosmosSigner });
|
|
2277
|
-
return this.getSetUpBiometricsURL({ authType: "externalWallet" });
|
|
2271
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
2272
|
+
return true;
|
|
2273
|
+
}
|
|
2274
|
+
const { isAuthenticated } = yield this.touchSession();
|
|
2275
|
+
return !!isAuthenticated;
|
|
2278
2276
|
});
|
|
2279
2277
|
}
|
|
2280
2278
|
/**
|
|
2281
|
-
*
|
|
2282
|
-
* @
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2279
|
+
* Checks if a session is active and a wallet exists.
|
|
2280
|
+
* @returns `true` if active, `false` otherwise
|
|
2281
|
+
**/
|
|
2282
|
+
isFullyLoggedIn() {
|
|
2283
|
+
return __async(this, null, function* () {
|
|
2284
|
+
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
2285
|
+
return true;
|
|
2286
|
+
}
|
|
2287
|
+
const isSessionActive = yield this.isSessionActive();
|
|
2288
|
+
return isSessionActive && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true);
|
|
2290
2289
|
});
|
|
2291
2290
|
}
|
|
2292
|
-
|
|
2293
|
-
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
2294
|
-
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
2295
|
-
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
2296
|
-
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
2297
|
-
*/
|
|
2298
|
-
verifyTelegram(authObject) {
|
|
2291
|
+
supportedAuthMethods(auth) {
|
|
2299
2292
|
return __async(this, null, function* () {
|
|
2300
|
-
const
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2293
|
+
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
2294
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
2295
|
+
for (const type of supportedAuthMethods) {
|
|
2296
|
+
switch (type) {
|
|
2297
|
+
case "PASSWORD":
|
|
2298
|
+
authMethods.add(AuthMethod.PASSWORD);
|
|
2299
|
+
break;
|
|
2300
|
+
case "BIOMETRIC":
|
|
2301
|
+
authMethods.add(AuthMethod.PASSKEY);
|
|
2302
|
+
break;
|
|
2307
2303
|
}
|
|
2308
2304
|
}
|
|
2309
|
-
return
|
|
2305
|
+
return authMethods;
|
|
2310
2306
|
});
|
|
2311
2307
|
}
|
|
2312
2308
|
/**
|
|
2313
|
-
*
|
|
2314
|
-
* @
|
|
2315
|
-
* @
|
|
2316
|
-
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
2317
|
-
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
2309
|
+
* Get hints associated with the users stored biometrics.
|
|
2310
|
+
* @deprecated
|
|
2311
|
+
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
2318
2312
|
*/
|
|
2319
|
-
|
|
2320
|
-
return __async(this,
|
|
2321
|
-
const
|
|
2322
|
-
return
|
|
2323
|
-
initiatedAt: res.data.initiatedAt,
|
|
2324
|
-
status: res.data.status,
|
|
2325
|
-
userId: res.data.userId,
|
|
2326
|
-
wallets: res.data.wallets
|
|
2327
|
-
};
|
|
2313
|
+
getUserBiometricLocationHints() {
|
|
2314
|
+
return __async(this, null, function* () {
|
|
2315
|
+
const { auth } = this.assertIsAuthSet();
|
|
2316
|
+
return yield this.ctx.client.getBiometricLocationHints(auth);
|
|
2328
2317
|
});
|
|
2329
2318
|
}
|
|
2330
2319
|
/**
|
|
2331
|
-
*
|
|
2332
|
-
*
|
|
2333
|
-
*
|
|
2334
|
-
* @param {
|
|
2335
|
-
* @param {
|
|
2336
|
-
* @returns
|
|
2337
|
-
|
|
2338
|
-
|
|
2320
|
+
* Updates the session with the user management server, possibly
|
|
2321
|
+
* opening a popup to refresh the session.
|
|
2322
|
+
*
|
|
2323
|
+
* @param {Object} opts the options object.
|
|
2324
|
+
* @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
|
|
2325
|
+
* @returns a URL for the user to reauthenticate.
|
|
2326
|
+
**/
|
|
2327
|
+
refreshSession() {
|
|
2339
2328
|
return __async(this, arguments, function* ({
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2329
|
+
shouldOpenPopup = false
|
|
2330
|
+
} = {}) {
|
|
2331
|
+
const { sessionId } = yield this.touchSession(true);
|
|
2332
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2333
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2334
|
+
}
|
|
2335
|
+
const link = yield this.getLoginUrl({
|
|
2336
|
+
sessionId
|
|
2337
|
+
});
|
|
2338
|
+
if (shouldOpenPopup) {
|
|
2339
|
+
this.platformUtils.openPopup(link);
|
|
2340
|
+
}
|
|
2341
|
+
return link;
|
|
2351
2342
|
});
|
|
2352
2343
|
}
|
|
2353
2344
|
/**
|
|
2354
|
-
*
|
|
2355
|
-
*
|
|
2356
|
-
|
|
2357
|
-
|
|
2345
|
+
* Call this method after login to ensure that the user ID is set
|
|
2346
|
+
* internally.
|
|
2347
|
+
**/
|
|
2348
|
+
userSetupAfterLogin() {
|
|
2358
2349
|
return __async(this, null, function* () {
|
|
2359
|
-
const
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2350
|
+
const session = yield this.touchSession();
|
|
2351
|
+
yield this.setUserId(session.userId);
|
|
2352
|
+
if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
|
|
2353
|
+
yield this.setCurrentWalletIds(session.currentWalletIds, {
|
|
2354
|
+
sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
|
|
2355
|
+
});
|
|
2356
|
+
return session;
|
|
2363
2357
|
});
|
|
2364
2358
|
}
|
|
2365
2359
|
/**
|
|
2366
|
-
*
|
|
2367
|
-
* @param {Object} opts the options object
|
|
2368
|
-
* @param {
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
* Determines if 2FA has been set up.
|
|
2377
|
-
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
2378
|
-
*/
|
|
2379
|
-
check2FAStatus() {
|
|
2380
|
-
return __async(this, null, function* () {
|
|
2381
|
-
if (!this.userId) {
|
|
2382
|
-
return { isSetup: false };
|
|
2383
|
-
}
|
|
2384
|
-
const res = yield this.ctx.client.check2FAStatus(this.userId);
|
|
2385
|
-
return {
|
|
2386
|
-
isSetup: res.data.isSetup
|
|
2387
|
-
};
|
|
2388
|
-
});
|
|
2389
|
-
}
|
|
2390
|
-
/**
|
|
2391
|
-
* Resend a verification email for the current user.
|
|
2392
|
-
*/
|
|
2393
|
-
resendVerificationCode() {
|
|
2394
|
-
return __async(this, null, function* () {
|
|
2395
|
-
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
2396
|
-
userId: this.userId
|
|
2397
|
-
}, this.getVerificationEmailProps()));
|
|
2398
|
-
});
|
|
2399
|
-
}
|
|
2400
|
-
/**
|
|
2401
|
-
* Resend a verification SMS for the current user.
|
|
2402
|
-
*/
|
|
2403
|
-
resendVerificationCodeByPhone() {
|
|
2404
|
-
return __async(this, null, function* () {
|
|
2405
|
-
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
2406
|
-
userId: this.userId
|
|
2407
|
-
});
|
|
2408
|
-
});
|
|
2409
|
-
}
|
|
2410
|
-
/**
|
|
2411
|
-
* Returns a URL for setting up a new WebAuth passkey.
|
|
2412
|
-
* @param {Object} opts the options object
|
|
2413
|
-
* @param {string} opts.authType - the auth type to use
|
|
2414
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2415
|
-
* @returns {string} the URL
|
|
2416
|
-
*/
|
|
2417
|
-
getSetUpBiometricsURL() {
|
|
2418
|
-
return __async(this, arguments, function* ({
|
|
2419
|
-
authType = "email",
|
|
2420
|
-
isForNewDevice = false
|
|
2421
|
-
} = {}) {
|
|
2422
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2423
|
-
status: PublicKeyStatus.PENDING,
|
|
2424
|
-
type: PublicKeyType.WEB
|
|
2425
|
-
});
|
|
2426
|
-
return this.getWebAuthURLForCreate({
|
|
2427
|
-
authType,
|
|
2428
|
-
isForNewDevice,
|
|
2429
|
-
webAuthId: res.data.id,
|
|
2430
|
-
partnerId: res.data.partnerId
|
|
2431
|
-
});
|
|
2432
|
-
});
|
|
2433
|
-
}
|
|
2434
|
-
/**
|
|
2435
|
-
* Returns a URL for setting up a new WebAuth passkey for a phone number.
|
|
2436
|
-
* @param {Object} opts the options object
|
|
2437
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2438
|
-
* @returns {string} the URL
|
|
2439
|
-
*/
|
|
2440
|
-
getSetUpBiometricsURLForPhone() {
|
|
2441
|
-
return __async(this, arguments, function* ({
|
|
2442
|
-
isForNewDevice = false
|
|
2443
|
-
} = {}) {
|
|
2444
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2445
|
-
status: PublicKeyStatus.PENDING,
|
|
2446
|
-
type: PublicKeyType.WEB
|
|
2447
|
-
});
|
|
2448
|
-
return this.getWebAuthURLForCreate({
|
|
2449
|
-
authType: "phone",
|
|
2450
|
-
isForNewDevice,
|
|
2451
|
-
webAuthId: res.data.id,
|
|
2452
|
-
partnerId: res.data.partnerId
|
|
2453
|
-
});
|
|
2360
|
+
* Get transmission shares associated with session.
|
|
2361
|
+
* @param {Object} opts the options object.
|
|
2362
|
+
* @param {boolean} opts.isForNewDevice - true if this device is registering.
|
|
2363
|
+
* @returns - transmission keyshares.
|
|
2364
|
+
**/
|
|
2365
|
+
getTransmissionKeyShares() {
|
|
2366
|
+
return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
|
|
2367
|
+
const session = yield this.touchSession();
|
|
2368
|
+
const sessionLookupId = isForNewDevice ? `${session.sessionLookupId}-new-device` : session.sessionLookupId;
|
|
2369
|
+
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
2454
2370
|
});
|
|
2455
2371
|
}
|
|
2456
2372
|
/**
|
|
2457
|
-
*
|
|
2458
|
-
* @param {Object} opts the options object
|
|
2459
|
-
* @param {
|
|
2460
|
-
* @param {boolean} opts.
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
*/
|
|
2464
|
-
getSetupPasswordURL() {
|
|
2373
|
+
* Call this method after login to perform setup.
|
|
2374
|
+
* @param {Object} opts the options object.
|
|
2375
|
+
* @param {any[]} opts.temporaryShares optional temporary shares to use for decryption.
|
|
2376
|
+
* @param {boolean} [opts.skipSessionRefresh] - whether or not to skip refreshing the session.
|
|
2377
|
+
**/
|
|
2378
|
+
setupAfterLogin() {
|
|
2465
2379
|
return __async(this, arguments, function* ({
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
theme
|
|
2380
|
+
temporaryShares,
|
|
2381
|
+
skipSessionRefresh = false
|
|
2469
2382
|
} = {}) {
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
});
|
|
2473
|
-
return this.getPasswordURLForCreate({
|
|
2474
|
-
authType,
|
|
2475
|
-
isForNewDevice,
|
|
2476
|
-
passwordId: res.data.id,
|
|
2477
|
-
partnerId: res.data.partnerId,
|
|
2478
|
-
theme
|
|
2479
|
-
});
|
|
2480
|
-
});
|
|
2481
|
-
}
|
|
2482
|
-
/**
|
|
2483
|
-
* Checks if the current session is active.
|
|
2484
|
-
* @returns `true` if active, `false` otherwise
|
|
2485
|
-
*/
|
|
2486
|
-
isSessionActive() {
|
|
2487
|
-
return __async(this, null, function* () {
|
|
2488
|
-
if (this.isUsingExternalWallet()) {
|
|
2489
|
-
return true;
|
|
2490
|
-
}
|
|
2491
|
-
const res = yield this.touchSession();
|
|
2492
|
-
return !!res.data.isAuthenticated;
|
|
2493
|
-
});
|
|
2494
|
-
}
|
|
2495
|
-
/**
|
|
2496
|
-
* Checks if a session is active and a wallet exists.
|
|
2497
|
-
* @returns `true` if active, `false` otherwise
|
|
2498
|
-
**/
|
|
2499
|
-
isFullyLoggedIn() {
|
|
2500
|
-
return __async(this, null, function* () {
|
|
2501
|
-
if (this.isUsingExternalWallet()) {
|
|
2502
|
-
return true;
|
|
2503
|
-
}
|
|
2504
|
-
const isSessionActive = yield this.isSessionActive();
|
|
2505
|
-
return isSessionActive && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true);
|
|
2506
|
-
});
|
|
2507
|
-
}
|
|
2508
|
-
supportedAuthMethods(auth) {
|
|
2509
|
-
return __async(this, null, function* () {
|
|
2510
|
-
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
2511
|
-
const authMethods = /* @__PURE__ */ new Set();
|
|
2512
|
-
for (const type of supportedAuthMethods) {
|
|
2513
|
-
switch (type) {
|
|
2514
|
-
case "PASSWORD":
|
|
2515
|
-
authMethods.add(AuthMethod.PASSWORD);
|
|
2516
|
-
break;
|
|
2517
|
-
case "BIOMETRIC":
|
|
2518
|
-
authMethods.add(AuthMethod.PASSKEY);
|
|
2519
|
-
break;
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
return authMethods;
|
|
2523
|
-
});
|
|
2524
|
-
}
|
|
2525
|
-
/**
|
|
2526
|
-
* Get hints associated with the users stored biometrics.
|
|
2527
|
-
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
2528
|
-
*/
|
|
2529
|
-
getUserBiometricLocationHints() {
|
|
2530
|
-
return __async(this, null, function* () {
|
|
2531
|
-
var _a;
|
|
2532
|
-
if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId && !this.isExternalWalletAuth) {
|
|
2533
|
-
throw new Error(
|
|
2534
|
-
"one of email, phone, farcaster username, telegram user id or external wallet with Para auth are required to get biometric location hints"
|
|
2535
|
-
);
|
|
2383
|
+
if (!temporaryShares) {
|
|
2384
|
+
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
2536
2385
|
}
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
2544
|
-
externalWalletAddress: (_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id
|
|
2386
|
+
temporaryShares.forEach((share) => {
|
|
2387
|
+
const signer = decryptWithPrivateKey(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
2388
|
+
this.wallets[share.walletId] = {
|
|
2389
|
+
id: share.walletId,
|
|
2390
|
+
signer
|
|
2391
|
+
};
|
|
2545
2392
|
});
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
return __async(this, null, function* () {
|
|
2550
|
-
const authInfo = extractAuthInfo(auth);
|
|
2551
|
-
if (!authInfo) {
|
|
2552
|
-
return void 0;
|
|
2553
|
-
}
|
|
2554
|
-
switch (authInfo.authType) {
|
|
2555
|
-
case "email":
|
|
2556
|
-
yield this.setEmail(authInfo.identifier);
|
|
2557
|
-
break;
|
|
2558
|
-
case "phone":
|
|
2559
|
-
yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
|
|
2560
|
-
break;
|
|
2561
|
-
case "farcaster":
|
|
2562
|
-
yield this.setFarcasterUsername(authInfo.identifier);
|
|
2563
|
-
break;
|
|
2564
|
-
case "telegram":
|
|
2565
|
-
yield this.setTelegramUserId(authInfo.identifier);
|
|
2566
|
-
break;
|
|
2567
|
-
}
|
|
2568
|
-
return authInfo;
|
|
2393
|
+
yield this.deleteLoginEncryptionKeyPair();
|
|
2394
|
+
yield this.populateWalletAddresses();
|
|
2395
|
+
yield this.touchSession(!skipSessionRefresh);
|
|
2569
2396
|
});
|
|
2570
2397
|
}
|
|
2571
2398
|
/**
|
|
2572
|
-
*
|
|
2573
|
-
* @param {Object} opts the options object
|
|
2574
|
-
* @param {
|
|
2575
|
-
* @param {
|
|
2576
|
-
* @
|
|
2399
|
+
* Distributes a new wallet recovery share.
|
|
2400
|
+
* @param {Object} opts the options object.
|
|
2401
|
+
* @param {string} opts.walletId the wallet to distribute the recovery share for.
|
|
2402
|
+
* @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
|
|
2403
|
+
* @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
|
|
2404
|
+
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
2405
|
+
* @returns {string} the recovery share.
|
|
2577
2406
|
**/
|
|
2578
|
-
|
|
2579
|
-
return __async(this,
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
if (!
|
|
2587
|
-
|
|
2407
|
+
distributeNewWalletShare(_0) {
|
|
2408
|
+
return __async(this, arguments, function* ({
|
|
2409
|
+
walletId,
|
|
2410
|
+
userShare,
|
|
2411
|
+
skipBiometricShareCreation = false,
|
|
2412
|
+
forceRefresh = false
|
|
2413
|
+
}) {
|
|
2414
|
+
let userSigner = userShare;
|
|
2415
|
+
if (!userSigner) {
|
|
2416
|
+
userSigner = this.wallets[walletId].signer;
|
|
2588
2417
|
}
|
|
2589
|
-
const
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2418
|
+
const recoveryShare = skipBiometricShareCreation ? yield sendRecoveryForShare({
|
|
2419
|
+
ctx: this.ctx,
|
|
2420
|
+
userId: this.userId,
|
|
2421
|
+
walletId,
|
|
2422
|
+
userSigner,
|
|
2423
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
2424
|
+
forceRefresh
|
|
2425
|
+
}) : yield distributeNewShare({
|
|
2426
|
+
ctx: this.ctx,
|
|
2427
|
+
userId: this.userId,
|
|
2428
|
+
walletId,
|
|
2429
|
+
userShare: userSigner,
|
|
2430
|
+
emailProps: this.getBackupKitEmailProps()
|
|
2594
2431
|
});
|
|
2595
|
-
|
|
2596
|
-
return webAuthLoginURL;
|
|
2597
|
-
}
|
|
2598
|
-
return this.shortenLoginLink(webAuthLoginURL);
|
|
2432
|
+
return recoveryShare;
|
|
2599
2433
|
});
|
|
2600
2434
|
}
|
|
2601
|
-
|
|
2602
|
-
* Initiates a login.
|
|
2603
|
-
* @param email - the email to login with
|
|
2604
|
-
* @returns - a set of supported auth methods for the user
|
|
2605
|
-
**/
|
|
2606
|
-
initiateUserLoginV2(auth) {
|
|
2435
|
+
waitForWalletAddress(walletId) {
|
|
2607
2436
|
return __async(this, null, function* () {
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2437
|
+
let maxPolls = 0;
|
|
2438
|
+
while (true) {
|
|
2439
|
+
try {
|
|
2440
|
+
if (maxPolls === 10) {
|
|
2441
|
+
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
|
+
}
|
|
2615
2453
|
}
|
|
2616
|
-
|
|
2454
|
+
throw new Error("timed out waiting for wallet address");
|
|
2617
2455
|
});
|
|
2618
2456
|
}
|
|
2619
2457
|
/**
|
|
2620
|
-
*
|
|
2621
|
-
*
|
|
2622
|
-
* @param
|
|
2623
|
-
* @param
|
|
2624
|
-
* @param
|
|
2625
|
-
* @returns -
|
|
2458
|
+
* Waits for a pregen wallet address to be created.
|
|
2459
|
+
*
|
|
2460
|
+
* @param pregenIdentifier - the identifier of the user the pregen wallet is associated with.
|
|
2461
|
+
* @param walletId - the wallet id
|
|
2462
|
+
* @param pregenIdentifierType - the identifier type of the user the pregen wallet is associated with.
|
|
2463
|
+
* @returns - recovery share.
|
|
2626
2464
|
**/
|
|
2627
|
-
|
|
2465
|
+
waitForPregenWalletAddress(walletId) {
|
|
2628
2466
|
return __async(this, null, function* () {
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
} = _h, auth = __objRest(_h, [
|
|
2632
|
-
"useShortUrl"
|
|
2633
|
-
]);
|
|
2634
|
-
yield this.setAuth(auth);
|
|
2635
|
-
const res = yield this.touchSession(true);
|
|
2636
|
-
if (!this.loginEncryptionKeyPair) {
|
|
2637
|
-
yield this.setLoginEncryptionKeyPair();
|
|
2638
|
-
}
|
|
2639
|
-
const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
|
|
2640
|
-
sessionId: res.data.sessionId,
|
|
2641
|
-
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
2642
|
-
partnerId: res.data.partnerId
|
|
2643
|
-
});
|
|
2644
|
-
if (!useShortUrl) {
|
|
2645
|
-
return webAuthLoginURL;
|
|
2646
|
-
}
|
|
2647
|
-
return this.shortenLoginLink(webAuthLoginURL);
|
|
2648
|
-
});
|
|
2649
|
-
}
|
|
2650
|
-
/**
|
|
2651
|
-
* Waits for the session to be active.
|
|
2652
|
-
**/
|
|
2653
|
-
waitForAccountCreation() {
|
|
2654
|
-
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
2655
|
-
yield this.touchSession();
|
|
2656
|
-
if (!this.isExternalWalletAuth) {
|
|
2657
|
-
this.externalWallets = {};
|
|
2658
|
-
}
|
|
2659
|
-
this.isAwaitingAccountCreation = true;
|
|
2660
|
-
while (this.isAwaitingAccountCreation) {
|
|
2467
|
+
let maxPolls = 0;
|
|
2468
|
+
while (true) {
|
|
2661
2469
|
try {
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
this.isAwaitingAccountCreation = false;
|
|
2665
|
-
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
2666
|
-
return true;
|
|
2667
|
-
} else {
|
|
2668
|
-
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2669
|
-
this.isAwaitingAccountCreation = false;
|
|
2670
|
-
return false;
|
|
2671
|
-
}
|
|
2470
|
+
if (maxPolls === 10) {
|
|
2471
|
+
break;
|
|
2672
2472
|
}
|
|
2473
|
+
++maxPolls;
|
|
2474
|
+
const res = yield this.getPregenWallets();
|
|
2475
|
+
const wallet = res.find((w) => w.id === walletId);
|
|
2476
|
+
if (wallet && wallet.address) {
|
|
2477
|
+
return;
|
|
2478
|
+
}
|
|
2479
|
+
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2673
2480
|
} catch (err) {
|
|
2674
2481
|
console.error(err);
|
|
2675
2482
|
}
|
|
2676
2483
|
}
|
|
2677
|
-
|
|
2484
|
+
throw new Error("timed out waiting for wallet address");
|
|
2678
2485
|
});
|
|
2679
2486
|
}
|
|
2680
|
-
|
|
2487
|
+
/**
|
|
2488
|
+
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
2489
|
+
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
2490
|
+
* object that are not already present. This is automatically called upon account creation to ensure that
|
|
2491
|
+
* the user has a wallet of each required type.
|
|
2492
|
+
*
|
|
2493
|
+
* @param {Object} [opts] the options object.
|
|
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.
|
|
2497
|
+
**/
|
|
2498
|
+
createWalletPerType() {
|
|
2681
2499
|
return __async(this, arguments, function* ({
|
|
2682
|
-
|
|
2500
|
+
skipDistribute = false,
|
|
2501
|
+
types
|
|
2683
2502
|
} = {}) {
|
|
2684
|
-
|
|
2685
|
-
const
|
|
2686
|
-
let recoverySecret
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
}
|
|
2696
|
-
const created = yield this.createWalletPerType();
|
|
2697
|
-
recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
|
|
2698
|
-
walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
|
|
2699
|
-
const resp = { walletIds, recoverySecret };
|
|
2700
|
-
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
2701
|
-
return resp;
|
|
2702
|
-
});
|
|
2703
|
-
}
|
|
2704
|
-
/**
|
|
2705
|
-
* Initiates a Farcaster login attempt and return the URI for the user to connect.
|
|
2706
|
-
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
2707
|
-
* @return {string} the Farcaster connect URI
|
|
2708
|
-
*/
|
|
2709
|
-
getFarcasterConnectURL() {
|
|
2710
|
-
return __async(this, null, function* () {
|
|
2711
|
-
yield this.logout();
|
|
2712
|
-
yield this.touchSession(true);
|
|
2713
|
-
const {
|
|
2714
|
-
data: { connect_uri }
|
|
2715
|
-
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
2716
|
-
return connect_uri;
|
|
2717
|
-
});
|
|
2718
|
-
}
|
|
2719
|
-
/**
|
|
2720
|
-
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
2721
|
-
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
2722
|
-
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
2723
|
-
*/
|
|
2724
|
-
waitForFarcasterStatus() {
|
|
2725
|
-
return __async(this, null, function* () {
|
|
2726
|
-
this.isAwaitingFarcaster = true;
|
|
2727
|
-
while (this.isAwaitingFarcaster) {
|
|
2728
|
-
try {
|
|
2729
|
-
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2730
|
-
const res = yield this.ctx.client.getFarcasterAuthStatus();
|
|
2731
|
-
if (res.data.state === "completed") {
|
|
2732
|
-
const { userId, userExists, username, pfpUrl } = res.data;
|
|
2733
|
-
yield this.setUserId(userId);
|
|
2734
|
-
yield this.setFarcasterUsername(username);
|
|
2735
|
-
return {
|
|
2736
|
-
userExists,
|
|
2737
|
-
username,
|
|
2738
|
-
pfpUrl
|
|
2739
|
-
};
|
|
2740
|
-
}
|
|
2741
|
-
} catch (err) {
|
|
2742
|
-
console.error(err);
|
|
2743
|
-
this.isAwaitingFarcaster = false;
|
|
2503
|
+
const wallets = [];
|
|
2504
|
+
const walletIds = {};
|
|
2505
|
+
let recoverySecret;
|
|
2506
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
2507
|
+
const [wallet, recoveryShare] = yield this.createWallet({ type, skipDistribute });
|
|
2508
|
+
wallets.push(wallet);
|
|
2509
|
+
getEquivalentTypes(type).filter((t) => !!this.isWalletTypeEnabled[t]).forEach((t) => {
|
|
2510
|
+
walletIds[t] = [wallet.id];
|
|
2511
|
+
});
|
|
2512
|
+
if (recoveryShare) {
|
|
2513
|
+
recoverySecret = recoveryShare;
|
|
2744
2514
|
}
|
|
2745
2515
|
}
|
|
2516
|
+
return { wallets, walletIds, recoverySecret };
|
|
2746
2517
|
});
|
|
2747
2518
|
}
|
|
2748
2519
|
/**
|
|
2749
|
-
*
|
|
2520
|
+
* Refresh the current user share for a wallet.
|
|
2750
2521
|
*
|
|
2751
|
-
* @param {Object} opts the options object
|
|
2752
|
-
* @param {
|
|
2753
|
-
* @param {string}
|
|
2754
|
-
* @
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2522
|
+
* @param {Object} opts the options object.
|
|
2523
|
+
* @param {string} opts.walletId the wallet id to refresh.
|
|
2524
|
+
* @param {string} opts.share the current user share.
|
|
2525
|
+
* @param {string} [opts.oldPartnerId] the current partner id.
|
|
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.
|
|
2530
|
+
**/
|
|
2531
|
+
refreshShare(_0) {
|
|
2532
|
+
return __async(this, arguments, function* ({
|
|
2533
|
+
walletId,
|
|
2534
|
+
share,
|
|
2535
|
+
oldPartnerId,
|
|
2536
|
+
newPartnerId,
|
|
2537
|
+
keyShareProtocolId,
|
|
2538
|
+
redistributeBackupEncryptedShares
|
|
2539
|
+
}) {
|
|
2540
|
+
const { signer, protocolId } = yield this.platformUtils.refresh(
|
|
2541
|
+
this.ctx,
|
|
2542
|
+
this.retrieveSessionCookie(),
|
|
2543
|
+
this.userId,
|
|
2544
|
+
walletId,
|
|
2545
|
+
share,
|
|
2546
|
+
oldPartnerId,
|
|
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
|
|
2768
2559
|
});
|
|
2560
|
+
return { signer, recoverySecret, protocolId };
|
|
2769
2561
|
});
|
|
2770
2562
|
}
|
|
2771
2563
|
/**
|
|
2772
|
-
*
|
|
2773
|
-
* If successful, this returns the user's email address and indicates whether the user already exists.
|
|
2774
|
-
*
|
|
2564
|
+
* Creates a new wallet.
|
|
2775
2565
|
* @param {Object} opts the options object.
|
|
2776
|
-
* @param {
|
|
2777
|
-
* @
|
|
2778
|
-
|
|
2779
|
-
waitForOAuth() {
|
|
2780
|
-
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
2781
|
-
this.isAwaitingOAuth = true;
|
|
2782
|
-
while (this.isAwaitingOAuth) {
|
|
2783
|
-
try {
|
|
2784
|
-
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2785
|
-
return { isError: true, userExists: false };
|
|
2786
|
-
}
|
|
2787
|
-
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2788
|
-
if (this.isAwaitingOAuth) {
|
|
2789
|
-
const res = yield this.touchSession();
|
|
2790
|
-
if (res.data.userId) {
|
|
2791
|
-
const { userId, email } = res.data;
|
|
2792
|
-
if (!this.loginEncryptionKeyPair) {
|
|
2793
|
-
yield this.setLoginEncryptionKeyPair();
|
|
2794
|
-
}
|
|
2795
|
-
yield this.setUserId(userId);
|
|
2796
|
-
yield this.setEmail(email);
|
|
2797
|
-
const userExists = yield this.checkIfUserExists({ email });
|
|
2798
|
-
this.isAwaitingOAuth = false;
|
|
2799
|
-
return {
|
|
2800
|
-
userExists,
|
|
2801
|
-
email
|
|
2802
|
-
};
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
} catch (err) {
|
|
2806
|
-
console.error(err);
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
return { userExists: false };
|
|
2810
|
-
});
|
|
2811
|
-
}
|
|
2812
|
-
/**
|
|
2813
|
-
* Waits for the session to be active and sets up the user.
|
|
2814
|
-
*
|
|
2815
|
-
* @param {Object} opts the options object
|
|
2816
|
-
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
2817
|
-
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
2818
|
-
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
2566
|
+
* @param {WalletType} opts.type the type of wallet to create.
|
|
2567
|
+
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
2568
|
+
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2819
2569
|
**/
|
|
2820
|
-
|
|
2570
|
+
createWallet() {
|
|
2821
2571
|
return __async(this, arguments, function* ({
|
|
2822
|
-
|
|
2823
|
-
|
|
2572
|
+
type: _type,
|
|
2573
|
+
skipDistribute = false
|
|
2824
2574
|
} = {}) {
|
|
2825
|
-
var _a;
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
const fetchedWallets = yield this.fetchWallets();
|
|
2855
|
-
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
2856
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
2857
|
-
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
2858
|
-
yield this.claimPregenWallets();
|
|
2859
|
-
const resp2 = {
|
|
2860
|
-
isComplete: true,
|
|
2861
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
2862
|
-
partnerId: postLoginData.data.partnerId
|
|
2863
|
-
};
|
|
2864
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
|
|
2865
|
-
return resp2;
|
|
2866
|
-
}
|
|
2867
|
-
} catch (err) {
|
|
2868
|
-
console.error(err);
|
|
2575
|
+
var _a, _b;
|
|
2576
|
+
this.requireApiKey();
|
|
2577
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2578
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
2579
|
+
_type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
2580
|
+
);
|
|
2581
|
+
let signer;
|
|
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;
|
|
2869
2604
|
}
|
|
2870
2605
|
}
|
|
2871
|
-
const
|
|
2872
|
-
|
|
2873
|
-
|
|
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];
|
|
2874
2637
|
});
|
|
2875
2638
|
}
|
|
2639
|
+
encodeWalletBase64(wallet) {
|
|
2640
|
+
const walletJson = JSON.stringify(wallet);
|
|
2641
|
+
const base64Wallet = Buffer.from(walletJson).toString("base64");
|
|
2642
|
+
return base64Wallet;
|
|
2643
|
+
}
|
|
2876
2644
|
/**
|
|
2877
|
-
*
|
|
2878
|
-
*
|
|
2879
|
-
*
|
|
2880
|
-
* @param {Object} opts the options object.
|
|
2881
|
-
* @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
|
|
2882
|
-
* @returns a URL for the user to reauthenticate.
|
|
2645
|
+
* Encodes the current wallets encoded in Base 64.
|
|
2646
|
+
* @returns {string} the encoded wallet string
|
|
2883
2647
|
**/
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
}
|
|
2890
|
-
const link = yield this.getWebAuthURLForLogin({
|
|
2891
|
-
sessionId: res.data.sessionId,
|
|
2892
|
-
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
2893
|
-
});
|
|
2894
|
-
if (shouldOpenPopup) {
|
|
2895
|
-
this.platformUtils.openPopup(link);
|
|
2896
|
-
}
|
|
2897
|
-
return link;
|
|
2898
|
-
});
|
|
2648
|
+
getUserShare() {
|
|
2649
|
+
if (Object.values(this.wallets).length === 0) {
|
|
2650
|
+
return null;
|
|
2651
|
+
}
|
|
2652
|
+
return Object.values(this.wallets).map((wallet) => this.encodeWalletBase64(wallet)).join("-");
|
|
2899
2653
|
}
|
|
2900
2654
|
/**
|
|
2901
|
-
*
|
|
2902
|
-
*
|
|
2655
|
+
* Sets the current wallets from a Base 64 string.
|
|
2656
|
+
* @param {string} base64Wallet the encoded wallet string
|
|
2903
2657
|
**/
|
|
2904
|
-
|
|
2658
|
+
setUserShare(base64Wallets) {
|
|
2905
2659
|
return __async(this, null, function* () {
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2660
|
+
if (!base64Wallets) {
|
|
2661
|
+
return;
|
|
2662
|
+
}
|
|
2663
|
+
const base64WalletsSplit = base64Wallets.split("-");
|
|
2664
|
+
for (const base64Wallet of base64WalletsSplit) {
|
|
2665
|
+
const walletJson = Buffer.from(base64Wallet, "base64").toString();
|
|
2666
|
+
const wallet = migrateWallet(JSON.parse(walletJson));
|
|
2667
|
+
this.wallets[wallet.id] = wallet;
|
|
2668
|
+
yield this.setWallets(this.wallets);
|
|
2669
|
+
}
|
|
2913
2670
|
});
|
|
2914
2671
|
}
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
const sessionLookupId = isForNewDevice ? `${res.data.sessionLookupId}-new-device` : res.data.sessionLookupId;
|
|
2925
|
-
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
2672
|
+
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
2673
|
+
return __async(this, null, function* () {
|
|
2674
|
+
return this.constructPortalUrl("txReview", {
|
|
2675
|
+
pathId: transactionId,
|
|
2676
|
+
params: {
|
|
2677
|
+
email: this.email,
|
|
2678
|
+
timeoutMs: timeoutMs == null ? void 0 : timeoutMs.toString()
|
|
2679
|
+
}
|
|
2680
|
+
});
|
|
2926
2681
|
});
|
|
2927
2682
|
}
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
};
|
|
2683
|
+
getOnRampTransactionUrl(_a) {
|
|
2684
|
+
return __async(this, null, function* () {
|
|
2685
|
+
var _b = _a, {
|
|
2686
|
+
purchaseId,
|
|
2687
|
+
providerKey
|
|
2688
|
+
} = _b, walletParams = __objRest(_b, [
|
|
2689
|
+
"purchaseId",
|
|
2690
|
+
"providerKey"
|
|
2691
|
+
]);
|
|
2692
|
+
const { sessionId } = yield this.touchSession();
|
|
2693
|
+
const [key, identifier] = extractWalletRef(walletParams);
|
|
2694
|
+
return this.constructPortalUrl("onRamp", {
|
|
2695
|
+
pathId: purchaseId,
|
|
2696
|
+
sessionId,
|
|
2697
|
+
params: {
|
|
2698
|
+
[key]: identifier,
|
|
2699
|
+
providerKey,
|
|
2700
|
+
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
2701
|
+
}
|
|
2948
2702
|
});
|
|
2949
|
-
yield this.deleteLoginEncryptionKeyPair();
|
|
2950
|
-
yield this.populateWalletAddresses();
|
|
2951
|
-
yield this.touchSession(!skipSessionRefresh);
|
|
2952
2703
|
});
|
|
2953
2704
|
}
|
|
2954
2705
|
/**
|
|
2955
|
-
*
|
|
2706
|
+
* Signs a message using one of the current wallets.
|
|
2707
|
+
*
|
|
2708
|
+
* If you want to sign the keccak256 hash of a message, hash the
|
|
2709
|
+
* message first and then pass in the base64 encoded hash.
|
|
2956
2710
|
* @param {Object} opts the options object.
|
|
2957
|
-
* @param {string} opts.walletId the
|
|
2958
|
-
* @param {string} opts.
|
|
2959
|
-
* @param {
|
|
2960
|
-
* @param {
|
|
2961
|
-
* @returns {string} the recovery share.
|
|
2711
|
+
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
2712
|
+
* @param {string} opts.messageBase64 the base64 encoding of exact message that should be signed
|
|
2713
|
+
* @param {number} [opts.timeout] optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
2714
|
+
* @param {string} [opts.cosmosSignDocBase64] the Cosmos `SignDoc` in base64, if applicable
|
|
2962
2715
|
**/
|
|
2963
|
-
|
|
2716
|
+
signMessage(_0) {
|
|
2964
2717
|
return __async(this, arguments, function* ({
|
|
2965
2718
|
walletId,
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2719
|
+
messageBase64,
|
|
2720
|
+
timeoutMs = 3e4,
|
|
2721
|
+
cosmosSignDocBase64,
|
|
2722
|
+
isCanceled = () => false,
|
|
2723
|
+
onCancel,
|
|
2724
|
+
onPoll
|
|
2969
2725
|
}) {
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2726
|
+
this.assertIsValidWalletId(walletId);
|
|
2727
|
+
const wallet = this.wallets[walletId];
|
|
2728
|
+
let signerId = this.userId;
|
|
2729
|
+
if (wallet.partnerId && !wallet.userId) {
|
|
2730
|
+
signerId = wallet.partnerId;
|
|
2973
2731
|
}
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
}
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
walletId,
|
|
2985
|
-
userShare: userSigner,
|
|
2986
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2987
|
-
});
|
|
2988
|
-
return recoveryShare;
|
|
2989
|
-
});
|
|
2990
|
-
}
|
|
2991
|
-
waitForWalletAddress(walletId) {
|
|
2992
|
-
return __async(this, null, function* () {
|
|
2993
|
-
let maxPolls = 0;
|
|
2994
|
-
while (true) {
|
|
2995
|
-
try {
|
|
2996
|
-
if (maxPolls === 10) {
|
|
2997
|
-
break;
|
|
2998
|
-
}
|
|
2999
|
-
++maxPolls;
|
|
3000
|
-
const res = yield this.ctx.client.getWallets(this.userId);
|
|
3001
|
-
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
3002
|
-
if (wallet && wallet.address) {
|
|
3003
|
-
return;
|
|
3004
|
-
}
|
|
3005
|
-
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
3006
|
-
} catch (err) {
|
|
3007
|
-
console.error(err);
|
|
3008
|
-
}
|
|
2732
|
+
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2733
|
+
let timeStart = Date.now();
|
|
2734
|
+
if (signRes.pendingTransactionId) {
|
|
2735
|
+
this.platformUtils.openPopup(
|
|
2736
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2737
|
+
{ type: cosmosSignDocBase64 ? "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ : "SIGN_MESSAGE_REVIEW" /* SIGN_MESSAGE_REVIEW */ }
|
|
2738
|
+
);
|
|
2739
|
+
} else {
|
|
2740
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2741
|
+
return signRes;
|
|
3009
2742
|
}
|
|
3010
|
-
throw new Error("timed out waiting for wallet address");
|
|
3011
|
-
});
|
|
3012
|
-
}
|
|
3013
|
-
/**
|
|
3014
|
-
* Waits for a pregen wallet address to be created.
|
|
3015
|
-
*
|
|
3016
|
-
* @param pregenIdentifier - the identifier of the user the pregen wallet is associated with.
|
|
3017
|
-
* @param walletId - the wallet id
|
|
3018
|
-
* @param pregenIdentifierType - the identifier type of the user the pregen wallet is associated with.
|
|
3019
|
-
* @returns - recovery share.
|
|
3020
|
-
**/
|
|
3021
|
-
waitForPregenWalletAddress(walletId) {
|
|
3022
|
-
return __async(this, null, function* () {
|
|
3023
|
-
let maxPolls = 0;
|
|
3024
2743
|
while (true) {
|
|
2744
|
+
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2745
|
+
onCancel == null ? void 0 : onCancel();
|
|
2746
|
+
break;
|
|
2747
|
+
}
|
|
2748
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3025
2749
|
try {
|
|
3026
|
-
|
|
3027
|
-
break;
|
|
3028
|
-
}
|
|
3029
|
-
++maxPolls;
|
|
3030
|
-
const res = yield this.getPregenWallets();
|
|
3031
|
-
const wallet = res.find((w) => w.id === walletId);
|
|
3032
|
-
if (wallet && wallet.address) {
|
|
3033
|
-
return;
|
|
3034
|
-
}
|
|
3035
|
-
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2750
|
+
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3036
2751
|
} catch (err) {
|
|
3037
|
-
|
|
2752
|
+
const error = new TransactionReviewDenied();
|
|
2753
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2754
|
+
throw error;
|
|
2755
|
+
}
|
|
2756
|
+
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2757
|
+
if (signRes.pendingTransactionId) {
|
|
2758
|
+
onPoll == null ? void 0 : onPoll();
|
|
2759
|
+
continue;
|
|
2760
|
+
} else {
|
|
2761
|
+
break;
|
|
3038
2762
|
}
|
|
3039
2763
|
}
|
|
3040
|
-
|
|
2764
|
+
if (signRes.pendingTransactionId) {
|
|
2765
|
+
const error = new TransactionReviewTimeout(
|
|
2766
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
2767
|
+
signRes.pendingTransactionId
|
|
2768
|
+
);
|
|
2769
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2770
|
+
throw error;
|
|
2771
|
+
}
|
|
2772
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2773
|
+
return signRes;
|
|
3041
2774
|
});
|
|
3042
2775
|
}
|
|
3043
|
-
|
|
3044
|
-
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
3045
|
-
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
3046
|
-
* object that are not already present. This is automatically called upon account creation to ensure that
|
|
3047
|
-
* the user has a wallet of each required type.
|
|
3048
|
-
*
|
|
3049
|
-
* @param {Object} [opts] the options object.
|
|
3050
|
-
* @param {boolean} [opts.skipDistribute] if `true`, the wallets' recovery share will not be distributed.
|
|
3051
|
-
* @param {WalletType[]} [opts.types] the types of wallets to create.
|
|
3052
|
-
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
3053
|
-
**/
|
|
3054
|
-
createWalletPerType() {
|
|
2776
|
+
signMessageInner(_0) {
|
|
3055
2777
|
return __async(this, arguments, function* ({
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
let
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
2778
|
+
wallet,
|
|
2779
|
+
signerId,
|
|
2780
|
+
messageBase64,
|
|
2781
|
+
cosmosSignDocBase64
|
|
2782
|
+
}) {
|
|
2783
|
+
let signRes;
|
|
2784
|
+
switch (wallet.scheme) {
|
|
2785
|
+
case WalletScheme2.ED25519:
|
|
2786
|
+
signRes = yield this.platformUtils.ed25519Sign(
|
|
2787
|
+
this.ctx,
|
|
2788
|
+
signerId,
|
|
2789
|
+
wallet.id,
|
|
2790
|
+
wallet.signer,
|
|
2791
|
+
messageBase64,
|
|
2792
|
+
this.retrieveSessionCookie()
|
|
2793
|
+
);
|
|
2794
|
+
break;
|
|
2795
|
+
default:
|
|
2796
|
+
signRes = yield this.platformUtils.signMessage(
|
|
2797
|
+
this.ctx,
|
|
2798
|
+
signerId,
|
|
2799
|
+
wallet.id,
|
|
2800
|
+
wallet.signer,
|
|
2801
|
+
messageBase64,
|
|
2802
|
+
this.retrieveSessionCookie(),
|
|
2803
|
+
wallet.scheme === WalletScheme2.DKLS,
|
|
2804
|
+
cosmosSignDocBase64
|
|
2805
|
+
);
|
|
2806
|
+
break;
|
|
3071
2807
|
}
|
|
3072
|
-
return
|
|
2808
|
+
return signRes;
|
|
3073
2809
|
});
|
|
3074
2810
|
}
|
|
3075
2811
|
/**
|
|
3076
|
-
*
|
|
3077
|
-
*
|
|
2812
|
+
* Signs a transaction.
|
|
3078
2813
|
* @param {Object} opts the options object.
|
|
3079
|
-
* @param {string} opts.walletId the wallet
|
|
3080
|
-
* @param {string} opts.
|
|
3081
|
-
* @param {string} [opts.
|
|
3082
|
-
* @param {
|
|
3083
|
-
* @param {string} [opts.keyShareProtocolId]
|
|
3084
|
-
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
3085
|
-
* @returns {Object} the new user share and recovery secret.
|
|
2814
|
+
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
2815
|
+
* @param {string} opts.rlpEncodedTxBase64 the transaction to sign, in RLP base64 encoding
|
|
2816
|
+
* @param {string} [opts.chainId] the EVM chain id of the chain the transaction is being sent on, if applicable
|
|
2817
|
+
* @param {number} [opts.timeoutMs] the amount of time to wait for the user to sign the transaction, in milliseconds
|
|
3086
2818
|
**/
|
|
3087
|
-
|
|
2819
|
+
signTransaction(_0) {
|
|
3088
2820
|
return __async(this, arguments, function* ({
|
|
3089
2821
|
walletId,
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
2822
|
+
rlpEncodedTxBase64,
|
|
2823
|
+
chainId,
|
|
2824
|
+
timeoutMs = 3e4,
|
|
2825
|
+
isCanceled = () => false,
|
|
2826
|
+
onCancel,
|
|
2827
|
+
onPoll
|
|
3095
2828
|
}) {
|
|
3096
|
-
|
|
2829
|
+
this.assertIsValidWalletId(walletId);
|
|
2830
|
+
const wallet = this.wallets[walletId];
|
|
2831
|
+
let signerId = this.userId;
|
|
2832
|
+
if (wallet.partnerId && !wallet.userId) {
|
|
2833
|
+
signerId = wallet.partnerId;
|
|
2834
|
+
}
|
|
2835
|
+
let signRes = yield this.platformUtils.signTransaction(
|
|
3097
2836
|
this.ctx,
|
|
3098
|
-
|
|
3099
|
-
this.userId,
|
|
3100
|
-
walletId,
|
|
3101
|
-
share,
|
|
3102
|
-
oldPartnerId,
|
|
3103
|
-
newPartnerId,
|
|
3104
|
-
keyShareProtocolId
|
|
3105
|
-
);
|
|
3106
|
-
const recoverySecret = yield distributeNewShare({
|
|
3107
|
-
ctx: this.ctx,
|
|
3108
|
-
userId: this.userId,
|
|
3109
|
-
walletId,
|
|
3110
|
-
userShare: signer,
|
|
3111
|
-
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
3112
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
3113
|
-
partnerId: newPartnerId,
|
|
3114
|
-
protocolId
|
|
3115
|
-
});
|
|
3116
|
-
return { signer, recoverySecret, protocolId };
|
|
3117
|
-
});
|
|
3118
|
-
}
|
|
3119
|
-
/**
|
|
3120
|
-
* Creates a new wallet.
|
|
3121
|
-
* @param {Object} opts the options object.
|
|
3122
|
-
* @param {WalletType} opts.type the type of wallet to create.
|
|
3123
|
-
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
3124
|
-
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3125
|
-
**/
|
|
3126
|
-
createWallet() {
|
|
3127
|
-
return __async(this, arguments, function* ({
|
|
3128
|
-
type: _type,
|
|
3129
|
-
skipDistribute = false
|
|
3130
|
-
} = {}) {
|
|
3131
|
-
var _a, _b;
|
|
3132
|
-
this.requireApiKey();
|
|
3133
|
-
const walletType = yield this.assertIsValidWalletType(
|
|
3134
|
-
_type != null ? _type : (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
3135
|
-
);
|
|
3136
|
-
let signer;
|
|
3137
|
-
let wallet;
|
|
3138
|
-
let keygenRes;
|
|
3139
|
-
switch (walletType) {
|
|
3140
|
-
case WalletType2.SOLANA: {
|
|
3141
|
-
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
3142
|
-
this.ctx,
|
|
3143
|
-
this.userId,
|
|
3144
|
-
this.retrieveSessionCookie(),
|
|
3145
|
-
this.getBackupKitEmailProps()
|
|
3146
|
-
);
|
|
3147
|
-
break;
|
|
3148
|
-
}
|
|
3149
|
-
default: {
|
|
3150
|
-
keygenRes = yield this.platformUtils.keygen(
|
|
3151
|
-
this.ctx,
|
|
3152
|
-
this.userId,
|
|
3153
|
-
walletType,
|
|
3154
|
-
null,
|
|
3155
|
-
this.retrieveSessionCookie(),
|
|
3156
|
-
this.getBackupKitEmailProps()
|
|
3157
|
-
);
|
|
3158
|
-
break;
|
|
3159
|
-
}
|
|
3160
|
-
}
|
|
3161
|
-
const walletId = keygenRes.walletId;
|
|
3162
|
-
signer = keygenRes.signer;
|
|
3163
|
-
this.wallets[walletId] = {
|
|
3164
|
-
id: walletId,
|
|
3165
|
-
signer,
|
|
3166
|
-
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
3167
|
-
type: walletType
|
|
3168
|
-
};
|
|
3169
|
-
wallet = this.wallets[walletId];
|
|
3170
|
-
yield this.waitForWalletAddress(wallet.id);
|
|
3171
|
-
yield this.populateWalletAddresses();
|
|
3172
|
-
let recoveryShare = null;
|
|
3173
|
-
if (!skipDistribute) {
|
|
3174
|
-
recoveryShare = yield distributeNewShare({
|
|
3175
|
-
ctx: this.ctx,
|
|
3176
|
-
userId: this.userId,
|
|
3177
|
-
walletId: wallet.id,
|
|
3178
|
-
userShare: signer,
|
|
3179
|
-
emailProps: this.getBackupKitEmailProps()
|
|
3180
|
-
});
|
|
3181
|
-
}
|
|
3182
|
-
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
3183
|
-
[walletType]: [...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId]
|
|
3184
|
-
}));
|
|
3185
|
-
const walletNoSigner = __spreadValues({}, wallet);
|
|
3186
|
-
delete walletNoSigner.signer;
|
|
3187
|
-
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
3188
|
-
wallet: walletNoSigner,
|
|
3189
|
-
recoverySecret: recoveryShare
|
|
3190
|
-
});
|
|
3191
|
-
return [wallet, recoveryShare];
|
|
3192
|
-
});
|
|
3193
|
-
}
|
|
3194
|
-
/**
|
|
3195
|
-
* Creates a new pregenerated wallet.
|
|
3196
|
-
*
|
|
3197
|
-
* @param {Object} opts the options object.
|
|
3198
|
-
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
3199
|
-
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
3200
|
-
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
3201
|
-
* @returns {Wallet} the created wallet.
|
|
3202
|
-
**/
|
|
3203
|
-
createPregenWallet(opts) {
|
|
3204
|
-
return __async(this, null, function* () {
|
|
3205
|
-
var _a, _b;
|
|
3206
|
-
const {
|
|
3207
|
-
type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
|
|
3208
|
-
pregenIdentifier,
|
|
3209
|
-
pregenIdentifierType = "EMAIL"
|
|
3210
|
-
} = opts;
|
|
3211
|
-
this.requireApiKey();
|
|
3212
|
-
const walletType = yield this.assertIsValidWalletType(
|
|
3213
|
-
_type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
3214
|
-
);
|
|
3215
|
-
let keygenRes;
|
|
3216
|
-
switch (walletType) {
|
|
3217
|
-
case WalletType2.SOLANA:
|
|
3218
|
-
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
3219
|
-
this.ctx,
|
|
3220
|
-
pregenIdentifier,
|
|
3221
|
-
pregenIdentifierType,
|
|
3222
|
-
this.retrieveSessionCookie()
|
|
3223
|
-
);
|
|
3224
|
-
break;
|
|
3225
|
-
default:
|
|
3226
|
-
keygenRes = yield this.platformUtils.preKeygen(
|
|
3227
|
-
this.ctx,
|
|
3228
|
-
void 0,
|
|
3229
|
-
pregenIdentifier,
|
|
3230
|
-
pregenIdentifierType,
|
|
3231
|
-
walletType,
|
|
3232
|
-
null,
|
|
3233
|
-
this.retrieveSessionCookie()
|
|
3234
|
-
);
|
|
3235
|
-
break;
|
|
3236
|
-
}
|
|
3237
|
-
const { signer, walletId } = keygenRes;
|
|
3238
|
-
this.wallets[walletId] = {
|
|
3239
|
-
id: walletId,
|
|
3240
|
-
signer,
|
|
3241
|
-
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
3242
|
-
type: walletType,
|
|
3243
|
-
isPregen: true,
|
|
3244
|
-
pregenIdentifier,
|
|
3245
|
-
pregenIdentifierType
|
|
3246
|
-
};
|
|
3247
|
-
yield this.waitForPregenWalletAddress(walletId);
|
|
3248
|
-
yield this.populatePregenWalletAddresses();
|
|
3249
|
-
return this.wallets[walletId];
|
|
3250
|
-
});
|
|
3251
|
-
}
|
|
3252
|
-
/**
|
|
3253
|
-
* Creates new pregenerated wallets for each desired type.
|
|
3254
|
-
* If no types are provided, this method will create one for each of the non-optional types
|
|
3255
|
-
* specified in the instance's `supportedWalletTypes` array that are not already present.
|
|
3256
|
-
* @param {Object} opts the options object.
|
|
3257
|
-
* @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
|
|
3258
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
3259
|
-
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
3260
|
-
* @returns {Wallet[]} an array containing the created wallets.
|
|
3261
|
-
**/
|
|
3262
|
-
createPregenWalletPerType(_0) {
|
|
3263
|
-
return __async(this, arguments, function* ({
|
|
3264
|
-
types,
|
|
3265
|
-
pregenIdentifier,
|
|
3266
|
-
pregenIdentifierType = "EMAIL"
|
|
3267
|
-
}) {
|
|
3268
|
-
const wallets = [];
|
|
3269
|
-
for (const type of yield this.getTypesToCreate(types)) {
|
|
3270
|
-
const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
|
|
3271
|
-
wallets.push(wallet);
|
|
3272
|
-
}
|
|
3273
|
-
return wallets;
|
|
3274
|
-
});
|
|
3275
|
-
}
|
|
3276
|
-
/**
|
|
3277
|
-
* Claims a pregenerated wallet.
|
|
3278
|
-
*
|
|
3279
|
-
* @param {Object} opts the options object.
|
|
3280
|
-
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
3281
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
3282
|
-
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3283
|
-
**/
|
|
3284
|
-
claimPregenWallets() {
|
|
3285
|
-
return __async(this, arguments, function* ({
|
|
3286
|
-
pregenIdentifier,
|
|
3287
|
-
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
3288
|
-
} = {}) {
|
|
3289
|
-
var _a;
|
|
3290
|
-
this.requireApiKey();
|
|
3291
|
-
const pregenWallets = pregenIdentifier && pregenIdentifierType ? yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType }) : yield this.getPregenWallets();
|
|
3292
|
-
if (pregenWallets.length === 0) {
|
|
3293
|
-
return void 0;
|
|
3294
|
-
}
|
|
3295
|
-
const missingWallets = pregenWallets.filter((wallet) => !this.wallets[wallet.id]);
|
|
3296
|
-
if (missingWallets.length > 0) {
|
|
3297
|
-
throw new Error(
|
|
3298
|
-
`Cannot claim pregen wallets because wallet data is missing. Please call setUserShare first to load the wallet data for the following wallet IDs: ${missingWallets.map((w) => w.id).join(", ")}`
|
|
3299
|
-
);
|
|
3300
|
-
}
|
|
3301
|
-
let newRecoverySecret;
|
|
3302
|
-
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
3303
|
-
userId: this.userId,
|
|
3304
|
-
walletIds: pregenWallets.map((w) => w.id)
|
|
3305
|
-
});
|
|
3306
|
-
for (const walletId of walletIds) {
|
|
3307
|
-
const wallet = this.wallets[walletId];
|
|
3308
|
-
let refreshedShare;
|
|
3309
|
-
if (wallet.scheme === WalletScheme2.ED25519) {
|
|
3310
|
-
const distributeRes = yield distributeNewShare({
|
|
3311
|
-
ctx: this.ctx,
|
|
3312
|
-
userId: this.userId,
|
|
3313
|
-
walletId: wallet.id,
|
|
3314
|
-
userShare: this.wallets[wallet.id].signer,
|
|
3315
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
3316
|
-
partnerId: wallet.partnerId
|
|
3317
|
-
});
|
|
3318
|
-
if (distributeRes.length > 0) {
|
|
3319
|
-
newRecoverySecret = distributeRes;
|
|
3320
|
-
}
|
|
3321
|
-
} else {
|
|
3322
|
-
refreshedShare = yield this.refreshShare({
|
|
3323
|
-
walletId: wallet.id,
|
|
3324
|
-
share: this.wallets[wallet.id].signer,
|
|
3325
|
-
oldPartnerId: wallet.partnerId,
|
|
3326
|
-
newPartnerId: wallet.partnerId,
|
|
3327
|
-
redistributeBackupEncryptedShares: true
|
|
3328
|
-
});
|
|
3329
|
-
if (refreshedShare.recoverySecret) {
|
|
3330
|
-
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3331
|
-
}
|
|
3332
|
-
}
|
|
3333
|
-
this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
|
|
3334
|
-
signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
|
|
3335
|
-
userId: this.userId,
|
|
3336
|
-
pregenIdentifier: void 0,
|
|
3337
|
-
pregenIdentifierType: void 0
|
|
3338
|
-
});
|
|
3339
|
-
const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
|
|
3340
|
-
delete walletNoSigner.signer;
|
|
3341
|
-
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
3342
|
-
wallet: walletNoSigner,
|
|
3343
|
-
recoverySecret: newRecoverySecret
|
|
3344
|
-
});
|
|
3345
|
-
}
|
|
3346
|
-
yield this.setWallets(this.wallets);
|
|
3347
|
-
return newRecoverySecret;
|
|
3348
|
-
});
|
|
3349
|
-
}
|
|
3350
|
-
/**
|
|
3351
|
-
* Updates the identifier for a pregen wallet.
|
|
3352
|
-
* @param {Object} opts the options object.
|
|
3353
|
-
* @param {string} opts.walletId the pregen wallet ID
|
|
3354
|
-
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
3355
|
-
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
3356
|
-
**/
|
|
3357
|
-
updatePregenWalletIdentifier(_0) {
|
|
3358
|
-
return __async(this, arguments, function* ({
|
|
3359
|
-
walletId,
|
|
3360
|
-
newPregenIdentifier,
|
|
3361
|
-
newPregenIdentifierType
|
|
3362
|
-
}) {
|
|
3363
|
-
this.requireApiKey();
|
|
3364
|
-
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
3365
|
-
pregenIdentifier: newPregenIdentifier,
|
|
3366
|
-
pregenIdentifierType: newPregenIdentifierType
|
|
3367
|
-
});
|
|
3368
|
-
if (!!this.wallets[walletId]) {
|
|
3369
|
-
this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3370
|
-
pregenIdentifier: newPregenIdentifier,
|
|
3371
|
-
pregenIdentifierType: newPregenIdentifierType
|
|
3372
|
-
});
|
|
3373
|
-
yield this.setWallets(this.wallets);
|
|
3374
|
-
}
|
|
3375
|
-
});
|
|
3376
|
-
}
|
|
3377
|
-
/**
|
|
3378
|
-
* Checks if a pregen Wallet exists for the given identifier with the current partner.
|
|
3379
|
-
* @param {Object} opts the options object.
|
|
3380
|
-
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
3381
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
3382
|
-
* @returns {boolean} whether the pregen wallet exists
|
|
3383
|
-
**/
|
|
3384
|
-
hasPregenWallet(_0) {
|
|
3385
|
-
return __async(this, arguments, function* ({
|
|
3386
|
-
pregenIdentifier,
|
|
3387
|
-
pregenIdentifierType
|
|
3388
|
-
}) {
|
|
3389
|
-
this.requireApiKey();
|
|
3390
|
-
const res = yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType });
|
|
3391
|
-
const wallet = res.find((w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType);
|
|
3392
|
-
if (!wallet) {
|
|
3393
|
-
return false;
|
|
3394
|
-
}
|
|
3395
|
-
return true;
|
|
3396
|
-
});
|
|
3397
|
-
}
|
|
3398
|
-
/**
|
|
3399
|
-
* Get pregen wallets for the given identifier.
|
|
3400
|
-
* @param {Object} opts the options object.
|
|
3401
|
-
* @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet
|
|
3402
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
3403
|
-
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
3404
|
-
**/
|
|
3405
|
-
getPregenWallets() {
|
|
3406
|
-
return __async(this, arguments, function* ({
|
|
3407
|
-
pregenIdentifier,
|
|
3408
|
-
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
3409
|
-
} = {}) {
|
|
3410
|
-
this.requireApiKey();
|
|
3411
|
-
const res = yield this.ctx.client.getPregenWallets(
|
|
3412
|
-
pregenIdentifier && pregenIdentifierType ? { [pregenIdentifierType]: [pregenIdentifier] } : this.pregenIds,
|
|
3413
|
-
this.isPortal(),
|
|
3414
|
-
this.userId
|
|
3415
|
-
);
|
|
3416
|
-
return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
|
|
3417
|
-
});
|
|
3418
|
-
}
|
|
3419
|
-
encodeWalletBase64(wallet) {
|
|
3420
|
-
const walletJson = JSON.stringify(wallet);
|
|
3421
|
-
const base64Wallet = Buffer.from(walletJson).toString("base64");
|
|
3422
|
-
return base64Wallet;
|
|
3423
|
-
}
|
|
3424
|
-
/**
|
|
3425
|
-
* Encodes the current wallets encoded in Base 64.
|
|
3426
|
-
* @returns {string} the encoded wallet string
|
|
3427
|
-
**/
|
|
3428
|
-
getUserShare() {
|
|
3429
|
-
if (Object.values(this.wallets).length === 0) {
|
|
3430
|
-
return null;
|
|
3431
|
-
}
|
|
3432
|
-
return Object.values(this.wallets).map((wallet) => this.encodeWalletBase64(wallet)).join("-");
|
|
3433
|
-
}
|
|
3434
|
-
/**
|
|
3435
|
-
* Sets the current wallets from a Base 64 string.
|
|
3436
|
-
* @param {string} base64Wallet the encoded wallet string
|
|
3437
|
-
**/
|
|
3438
|
-
setUserShare(base64Wallets) {
|
|
3439
|
-
return __async(this, null, function* () {
|
|
3440
|
-
if (!base64Wallets) {
|
|
3441
|
-
return;
|
|
3442
|
-
}
|
|
3443
|
-
const base64WalletsSplit = base64Wallets.split("-");
|
|
3444
|
-
for (const base64Wallet of base64WalletsSplit) {
|
|
3445
|
-
const walletJson = Buffer.from(base64Wallet, "base64").toString();
|
|
3446
|
-
const wallet = migrateWallet(JSON.parse(walletJson));
|
|
3447
|
-
this.wallets[wallet.id] = wallet;
|
|
3448
|
-
yield this.setWallets(this.wallets);
|
|
3449
|
-
}
|
|
3450
|
-
});
|
|
3451
|
-
}
|
|
3452
|
-
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
3453
|
-
return __async(this, null, function* () {
|
|
3454
|
-
const res = yield this.touchSession();
|
|
3455
|
-
return this.constructPortalUrl("txReview", {
|
|
3456
|
-
partnerId: res.data.partnerId,
|
|
3457
|
-
pathId: transactionId,
|
|
3458
|
-
params: {
|
|
3459
|
-
email: this.email,
|
|
3460
|
-
timeoutMs: timeoutMs == null ? void 0 : timeoutMs.toString()
|
|
3461
|
-
}
|
|
3462
|
-
});
|
|
3463
|
-
});
|
|
3464
|
-
}
|
|
3465
|
-
getOnRampTransactionUrl(_i) {
|
|
3466
|
-
return __async(this, null, function* () {
|
|
3467
|
-
var _j = _i, {
|
|
3468
|
-
purchaseId,
|
|
3469
|
-
providerKey
|
|
3470
|
-
} = _j, walletParams = __objRest(_j, [
|
|
3471
|
-
"purchaseId",
|
|
3472
|
-
"providerKey"
|
|
3473
|
-
]);
|
|
3474
|
-
const res = yield this.touchSession();
|
|
3475
|
-
const [key, identifier] = extractWalletRef(walletParams);
|
|
3476
|
-
return this.constructPortalUrl("onRamp", {
|
|
3477
|
-
partnerId: res.data.partnerId,
|
|
3478
|
-
pathId: purchaseId,
|
|
3479
|
-
sessionId: res.data.sessionId,
|
|
3480
|
-
params: {
|
|
3481
|
-
[key]: identifier,
|
|
3482
|
-
providerKey,
|
|
3483
|
-
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
3484
|
-
}
|
|
3485
|
-
});
|
|
3486
|
-
});
|
|
3487
|
-
}
|
|
3488
|
-
/**
|
|
3489
|
-
* Signs a message using one of the current wallets.
|
|
3490
|
-
*
|
|
3491
|
-
* If you want to sign the keccak256 hash of a message, hash the
|
|
3492
|
-
* message first and then pass in the base64 encoded hash.
|
|
3493
|
-
* @param {Object} opts the options object.
|
|
3494
|
-
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
3495
|
-
* @param {string} opts.messageBase64 the base64 encoding of exact message that should be signed
|
|
3496
|
-
* @param {number} [opts.timeout] optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
3497
|
-
* @param {string} [opts.cosmosSignDocBase64] the Cosmos `SignDoc` in base64, if applicable
|
|
3498
|
-
**/
|
|
3499
|
-
signMessage(_0) {
|
|
3500
|
-
return __async(this, arguments, function* ({
|
|
3501
|
-
walletId,
|
|
3502
|
-
messageBase64,
|
|
3503
|
-
timeoutMs = 3e4,
|
|
3504
|
-
cosmosSignDocBase64
|
|
3505
|
-
}) {
|
|
3506
|
-
this.assertIsValidWalletId(walletId);
|
|
3507
|
-
const wallet = this.wallets[walletId];
|
|
3508
|
-
let signerId = this.userId;
|
|
3509
|
-
if (wallet.partnerId && !wallet.userId) {
|
|
3510
|
-
signerId = wallet.partnerId;
|
|
3511
|
-
}
|
|
3512
|
-
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
3513
|
-
let timeStart = Date.now();
|
|
3514
|
-
if (signRes.pendingTransactionId) {
|
|
3515
|
-
this.platformUtils.openPopup(
|
|
3516
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
3517
|
-
{ type: cosmosSignDocBase64 ? "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ : "SIGN_MESSAGE_REVIEW" /* SIGN_MESSAGE_REVIEW */ }
|
|
3518
|
-
);
|
|
3519
|
-
} else {
|
|
3520
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
3521
|
-
return signRes;
|
|
3522
|
-
}
|
|
3523
|
-
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3524
|
-
while (true) {
|
|
3525
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
3526
|
-
break;
|
|
3527
|
-
}
|
|
3528
|
-
try {
|
|
3529
|
-
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3530
|
-
} catch (err) {
|
|
3531
|
-
const error = new TransactionReviewDenied();
|
|
3532
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
3533
|
-
throw error;
|
|
3534
|
-
}
|
|
3535
|
-
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
3536
|
-
if (signRes.pendingTransactionId) {
|
|
3537
|
-
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3538
|
-
} else {
|
|
3539
|
-
break;
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
if (signRes.pendingTransactionId) {
|
|
3543
|
-
const error = new TransactionReviewTimeout(
|
|
3544
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3545
|
-
signRes.pendingTransactionId
|
|
3546
|
-
);
|
|
3547
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
3548
|
-
throw error;
|
|
3549
|
-
}
|
|
3550
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
3551
|
-
return signRes;
|
|
3552
|
-
});
|
|
3553
|
-
}
|
|
3554
|
-
signMessageInner(_0) {
|
|
3555
|
-
return __async(this, arguments, function* ({
|
|
3556
|
-
wallet,
|
|
3557
|
-
signerId,
|
|
3558
|
-
messageBase64,
|
|
3559
|
-
cosmosSignDocBase64
|
|
3560
|
-
}) {
|
|
3561
|
-
let signRes;
|
|
3562
|
-
switch (wallet.scheme) {
|
|
3563
|
-
case WalletScheme2.ED25519:
|
|
3564
|
-
signRes = yield this.platformUtils.ed25519Sign(
|
|
3565
|
-
this.ctx,
|
|
3566
|
-
signerId,
|
|
3567
|
-
wallet.id,
|
|
3568
|
-
wallet.signer,
|
|
3569
|
-
messageBase64,
|
|
3570
|
-
this.retrieveSessionCookie()
|
|
3571
|
-
);
|
|
3572
|
-
break;
|
|
3573
|
-
default:
|
|
3574
|
-
signRes = yield this.platformUtils.signMessage(
|
|
3575
|
-
this.ctx,
|
|
3576
|
-
signerId,
|
|
3577
|
-
wallet.id,
|
|
3578
|
-
wallet.signer,
|
|
3579
|
-
messageBase64,
|
|
3580
|
-
this.retrieveSessionCookie(),
|
|
3581
|
-
wallet.scheme === WalletScheme2.DKLS,
|
|
3582
|
-
cosmosSignDocBase64
|
|
3583
|
-
);
|
|
3584
|
-
break;
|
|
3585
|
-
}
|
|
3586
|
-
return signRes;
|
|
3587
|
-
});
|
|
3588
|
-
}
|
|
3589
|
-
/**
|
|
3590
|
-
* Signs a transaction.
|
|
3591
|
-
* @param {Object} opts the options object.
|
|
3592
|
-
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
3593
|
-
* @param {string} opts.rlpEncodedTxBase64 the transaction to sign, in RLP base64 encoding
|
|
3594
|
-
* @param {string} [opts.chainId] the EVM chain id of the chain the transaction is being sent on, if applicable
|
|
3595
|
-
* @param {number} [opts.timeoutMs] the amount of time to wait for the user to sign the transaction, in milliseconds
|
|
3596
|
-
**/
|
|
3597
|
-
signTransaction(_0) {
|
|
3598
|
-
return __async(this, arguments, function* ({
|
|
3599
|
-
walletId,
|
|
3600
|
-
rlpEncodedTxBase64,
|
|
3601
|
-
chainId,
|
|
3602
|
-
timeoutMs = 3e4
|
|
3603
|
-
}) {
|
|
3604
|
-
this.assertIsValidWalletId(walletId);
|
|
3605
|
-
const wallet = this.wallets[walletId];
|
|
3606
|
-
let signerId = this.userId;
|
|
3607
|
-
if (wallet.partnerId && !wallet.userId) {
|
|
3608
|
-
signerId = wallet.partnerId;
|
|
3609
|
-
}
|
|
3610
|
-
let signRes = yield this.platformUtils.signTransaction(
|
|
3611
|
-
this.ctx,
|
|
3612
|
-
signerId,
|
|
2837
|
+
signerId,
|
|
3613
2838
|
walletId,
|
|
3614
2839
|
this.wallets[walletId].signer,
|
|
3615
2840
|
rlpEncodedTxBase64,
|
|
@@ -3627,11 +2852,12 @@ var _ParaCore = class _ParaCore {
|
|
|
3627
2852
|
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
3628
2853
|
return signRes;
|
|
3629
2854
|
}
|
|
3630
|
-
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3631
2855
|
while (true) {
|
|
3632
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
2856
|
+
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2857
|
+
onCancel == null ? void 0 : onCancel();
|
|
3633
2858
|
break;
|
|
3634
2859
|
}
|
|
2860
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3635
2861
|
try {
|
|
3636
2862
|
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3637
2863
|
} catch (err) {
|
|
@@ -3650,289 +2876,1057 @@ var _ParaCore = class _ParaCore {
|
|
|
3650
2876
|
wallet.scheme === WalletScheme2.DKLS
|
|
3651
2877
|
);
|
|
3652
2878
|
if (signRes.pendingTransactionId) {
|
|
3653
|
-
|
|
2879
|
+
onPoll == null ? void 0 : onPoll();
|
|
2880
|
+
continue;
|
|
3654
2881
|
} else {
|
|
3655
2882
|
break;
|
|
3656
2883
|
}
|
|
3657
2884
|
}
|
|
3658
|
-
if (signRes.pendingTransactionId) {
|
|
3659
|
-
const error = new TransactionReviewTimeout(
|
|
3660
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3661
|
-
signRes.pendingTransactionId
|
|
3662
|
-
);
|
|
3663
|
-
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
3664
|
-
throw error;
|
|
3665
|
-
}
|
|
3666
|
-
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
3667
|
-
return signRes;
|
|
2885
|
+
if (signRes.pendingTransactionId) {
|
|
2886
|
+
const error = new TransactionReviewTimeout(
|
|
2887
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
2888
|
+
signRes.pendingTransactionId
|
|
2889
|
+
);
|
|
2890
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
2891
|
+
throw error;
|
|
2892
|
+
}
|
|
2893
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2894
|
+
return signRes;
|
|
2895
|
+
});
|
|
2896
|
+
}
|
|
2897
|
+
isProviderModalDisabled() {
|
|
2898
|
+
return !!this.disableProviderModal;
|
|
2899
|
+
}
|
|
2900
|
+
/**
|
|
2901
|
+
* Starts a on-ramp or off-ramp transaction and returns the Para Portal link for the user to finalize and complete it.
|
|
2902
|
+
* @param {Object} opts the options object
|
|
2903
|
+
* @param {OnRampPurchaseCreateParams} opts.params the transaction settings.
|
|
2904
|
+
* @param {boolean} opts.shouldOpenPopup if `true`, a popup window with the link will be opened.
|
|
2905
|
+
* @param {string} opts.walletId the wallet ID to use for the transaction, where funds will be sent or withdrawn.
|
|
2906
|
+
* @param {string} opts.externalWalletAddress the external wallet address to send funds to or withdraw funds from, if using an external wallet.
|
|
2907
|
+
**/
|
|
2908
|
+
initiateOnRampTransaction(options) {
|
|
2909
|
+
return __async(this, null, function* () {
|
|
2910
|
+
var _b;
|
|
2911
|
+
const _a = options, { params, shouldOpenPopup } = _a, walletParams = __objRest(_a, ["params", "shouldOpenPopup"]);
|
|
2912
|
+
const onRampPurchase = yield this.ctx.client.createOnRampPurchase(__spreadValues({
|
|
2913
|
+
userId: this.userId,
|
|
2914
|
+
params: __spreadProps(__spreadValues({}, params), {
|
|
2915
|
+
address: (_b = walletParams.externalWalletAddress) != null ? _b : this.getDisplayAddress(walletParams.walletId, { addressType: params.walletType })
|
|
2916
|
+
})
|
|
2917
|
+
}, walletParams));
|
|
2918
|
+
const portalUrl = yield this.getOnRampTransactionUrl(__spreadValues({
|
|
2919
|
+
purchaseId: onRampPurchase.id,
|
|
2920
|
+
providerKey: onRampPurchase.providerKey
|
|
2921
|
+
}, walletParams));
|
|
2922
|
+
if (shouldOpenPopup) {
|
|
2923
|
+
this.platformUtils.openPopup(portalUrl, { type: "ON_RAMP_TRANSACTION" /* ON_RAMP_TRANSACTION */ });
|
|
2924
|
+
}
|
|
2925
|
+
return { onRampPurchase, portalUrl };
|
|
2926
|
+
});
|
|
2927
|
+
}
|
|
2928
|
+
/**
|
|
2929
|
+
* Returns `true` if session was successfully kept alive, `false` otherwise.
|
|
2930
|
+
**/
|
|
2931
|
+
keepSessionAlive() {
|
|
2932
|
+
return __async(this, null, function* () {
|
|
2933
|
+
try {
|
|
2934
|
+
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
2935
|
+
return true;
|
|
2936
|
+
} catch (err) {
|
|
2937
|
+
return false;
|
|
2938
|
+
}
|
|
2939
|
+
});
|
|
2940
|
+
}
|
|
2941
|
+
/**
|
|
2942
|
+
* Serialize the current session for import by another Para instance.
|
|
2943
|
+
* @returns {string} the serialized session
|
|
2944
|
+
*/
|
|
2945
|
+
exportSession() {
|
|
2946
|
+
const sessionInfo = {
|
|
2947
|
+
authInfo: __privateGet(this, _authInfo),
|
|
2948
|
+
userId: this.userId,
|
|
2949
|
+
wallets: this.wallets,
|
|
2950
|
+
currentWalletIds: this.currentWalletIds,
|
|
2951
|
+
sessionCookie: this.retrieveSessionCookie(),
|
|
2952
|
+
externalWallets: this.externalWallets
|
|
2953
|
+
};
|
|
2954
|
+
return Buffer.from(JSON.stringify(sessionInfo)).toString("base64");
|
|
2955
|
+
}
|
|
2956
|
+
/**
|
|
2957
|
+
* Imports a session serialized by another Para instance.
|
|
2958
|
+
* @param {string} serializedInstanceBase64 the serialized session
|
|
2959
|
+
*/
|
|
2960
|
+
importSession(serializedInstanceBase64) {
|
|
2961
|
+
return __async(this, null, function* () {
|
|
2962
|
+
var _a, _b;
|
|
2963
|
+
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
2964
|
+
const sessionInfo = jsonParse(serializedInstance);
|
|
2965
|
+
const authInfo = (_a = sessionInfo.authInfo) != null ? _a : __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, sessionInfo);
|
|
2966
|
+
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
2967
|
+
yield this.setUserId(sessionInfo.userId);
|
|
2968
|
+
yield this.setWallets(sessionInfo.wallets);
|
|
2969
|
+
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
2970
|
+
for (const walletId of Object.keys(this.wallets)) {
|
|
2971
|
+
if (!this.wallets[walletId].userId) {
|
|
2972
|
+
this.wallets[walletId].userId = this.userId;
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
if (Object.keys(sessionInfo.currentWalletIds).length !== 0) {
|
|
2976
|
+
yield this.setCurrentWalletIds(sessionInfo.currentWalletIds);
|
|
2977
|
+
} else {
|
|
2978
|
+
const currentWalletIds = {};
|
|
2979
|
+
for (const walletId of Object.keys(sessionInfo.wallets)) {
|
|
2980
|
+
currentWalletIds[sessionInfo.wallets[walletId].type] = [
|
|
2981
|
+
...(_b = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _b : [],
|
|
2982
|
+
walletId
|
|
2983
|
+
];
|
|
2984
|
+
}
|
|
2985
|
+
yield this.setCurrentWalletIds(currentWalletIds);
|
|
2986
|
+
}
|
|
2987
|
+
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
/**
|
|
2991
|
+
* @deprecated
|
|
2992
|
+
*/
|
|
2993
|
+
// protected exitAccountCreation() {
|
|
2994
|
+
// this.isAwaitingAccountCreation = false;
|
|
2995
|
+
// }
|
|
2996
|
+
/**
|
|
2997
|
+
* @deprecated
|
|
2998
|
+
*/
|
|
2999
|
+
// protected exitLogin() {
|
|
3000
|
+
// this.isAwaitingLogin = false;
|
|
3001
|
+
// }
|
|
3002
|
+
/**
|
|
3003
|
+
* @deprecated
|
|
3004
|
+
*/
|
|
3005
|
+
// protected exitFarcaster() {
|
|
3006
|
+
// this.isAwaitingFarcaster = false;
|
|
3007
|
+
// }
|
|
3008
|
+
/**
|
|
3009
|
+
* @deprecated
|
|
3010
|
+
*/
|
|
3011
|
+
// protected exitOAuth() {
|
|
3012
|
+
// this.isAwaitingOAuth = false;
|
|
3013
|
+
// }
|
|
3014
|
+
/**
|
|
3015
|
+
* @deprecated
|
|
3016
|
+
*/
|
|
3017
|
+
// protected exitLoops() {
|
|
3018
|
+
// this.exitAccountCreation();
|
|
3019
|
+
// this.exitLogin();
|
|
3020
|
+
// this.exitFarcaster();
|
|
3021
|
+
// this.exitOAuth();
|
|
3022
|
+
// }
|
|
3023
|
+
/**
|
|
3024
|
+
* Retrieves a token to verify the current session.
|
|
3025
|
+
* @returns {Promise<string>} the ID
|
|
3026
|
+
**/
|
|
3027
|
+
getVerificationToken() {
|
|
3028
|
+
return __async(this, null, function* () {
|
|
3029
|
+
const { sessionLookupId } = yield this.touchSession();
|
|
3030
|
+
return sessionLookupId;
|
|
3031
|
+
});
|
|
3032
|
+
}
|
|
3033
|
+
/**
|
|
3034
|
+
* Logs the user out.
|
|
3035
|
+
* @param {Object} opts the options object.
|
|
3036
|
+
* @param {boolean} opts.clearPregenWallets if `true`, will remove all pregen wallets from storage
|
|
3037
|
+
**/
|
|
3038
|
+
logout() {
|
|
3039
|
+
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3040
|
+
yield this.ctx.client.logout();
|
|
3041
|
+
yield this.clearStorage();
|
|
3042
|
+
if (!clearPregenWallets) {
|
|
3043
|
+
Object.entries(this.wallets).forEach(([id, wallet]) => {
|
|
3044
|
+
if (!wallet.pregenIdentifier) {
|
|
3045
|
+
delete this.wallets[id];
|
|
3046
|
+
}
|
|
3047
|
+
});
|
|
3048
|
+
yield this.setWallets(this.wallets);
|
|
3049
|
+
} else {
|
|
3050
|
+
this.wallets = {};
|
|
3051
|
+
}
|
|
3052
|
+
this.currentWalletIds = {};
|
|
3053
|
+
this.externalWallets = {};
|
|
3054
|
+
this.loginEncryptionKeyPair = void 0;
|
|
3055
|
+
__privateSet(this, _authInfo, void 0);
|
|
3056
|
+
this.userId = void 0;
|
|
3057
|
+
this.sessionCookie = void 0;
|
|
3058
|
+
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
3059
|
+
});
|
|
3060
|
+
}
|
|
3061
|
+
/** @deprecated */
|
|
3062
|
+
getSupportedCreateAuthMethods() {
|
|
3063
|
+
return __async(this, null, function* () {
|
|
3064
|
+
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3065
|
+
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
3066
|
+
for (const authMethod of partner.supportedAuthMethods) {
|
|
3067
|
+
supportedAuthMethods.add(AuthMethod[authMethod]);
|
|
3068
|
+
}
|
|
3069
|
+
return supportedAuthMethods;
|
|
3070
|
+
});
|
|
3071
|
+
}
|
|
3072
|
+
/**
|
|
3073
|
+
* Converts to a string, removing sensitive data when logging this class.
|
|
3074
|
+
*
|
|
3075
|
+
* Doesn't work for all types of logging.
|
|
3076
|
+
**/
|
|
3077
|
+
toString() {
|
|
3078
|
+
var _a, _b, _c;
|
|
3079
|
+
const redactedWallets = Object.keys(this.wallets).reduce(
|
|
3080
|
+
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
3081
|
+
[walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3082
|
+
signer: this.wallets[walletId].signer ? "[REDACTED]" : void 0
|
|
3083
|
+
})
|
|
3084
|
+
}),
|
|
3085
|
+
{}
|
|
3086
|
+
);
|
|
3087
|
+
const redactedExternalWallets = Object.keys(this.externalWallets).reduce(
|
|
3088
|
+
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
3089
|
+
[walletId]: __spreadProps(__spreadValues({}, this.externalWallets[walletId]), {
|
|
3090
|
+
signer: this.externalWallets[walletId].signer ? "[REDACTED]" : void 0
|
|
3091
|
+
})
|
|
3092
|
+
}),
|
|
3093
|
+
{}
|
|
3094
|
+
);
|
|
3095
|
+
const obj = {
|
|
3096
|
+
partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
|
|
3097
|
+
supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
|
|
3098
|
+
cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
|
|
3099
|
+
authInfo: __privateGet(this, _authInfo),
|
|
3100
|
+
userId: this.userId,
|
|
3101
|
+
pregenIds: this.pregenIds,
|
|
3102
|
+
currentWalletIds: this.currentWalletIds,
|
|
3103
|
+
wallets: redactedWallets,
|
|
3104
|
+
externalWallets: redactedExternalWallets,
|
|
3105
|
+
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
3106
|
+
ctx: {
|
|
3107
|
+
apiKey: this.ctx.apiKey,
|
|
3108
|
+
disableWorkers: this.ctx.disableWorkers,
|
|
3109
|
+
disableWebSockets: this.ctx.disableWebSockets,
|
|
3110
|
+
env: this.ctx.env,
|
|
3111
|
+
offloadMPCComputationURL: this.ctx.offloadMPCComputationURL,
|
|
3112
|
+
useLocalFiles: this.ctx.useLocalFiles,
|
|
3113
|
+
useDKLS: this.ctx.useDKLS,
|
|
3114
|
+
cosmosPrefix: this.ctx.cosmosPrefix
|
|
3115
|
+
}
|
|
3116
|
+
};
|
|
3117
|
+
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
3118
|
+
}
|
|
3119
|
+
/** NEW METHODS */
|
|
3120
|
+
getNewCredentialAndUrl() {
|
|
3121
|
+
return __async(this, arguments, function* ({
|
|
3122
|
+
authMethod = "PASSKEY",
|
|
3123
|
+
isForNewDevice = false,
|
|
3124
|
+
portalTheme,
|
|
3125
|
+
shorten = false
|
|
3126
|
+
} = {}) {
|
|
3127
|
+
this.assertIsAuthSet();
|
|
3128
|
+
let credentialId, urlType;
|
|
3129
|
+
switch (authMethod) {
|
|
3130
|
+
case "PASSKEY":
|
|
3131
|
+
({
|
|
3132
|
+
data: { id: credentialId }
|
|
3133
|
+
} = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
3134
|
+
status: PublicKeyStatus.PENDING,
|
|
3135
|
+
type: PublicKeyType.WEB
|
|
3136
|
+
}));
|
|
3137
|
+
urlType = "createAuth";
|
|
3138
|
+
break;
|
|
3139
|
+
case "PASSWORD":
|
|
3140
|
+
({
|
|
3141
|
+
data: { id: credentialId }
|
|
3142
|
+
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3143
|
+
status: PasswordStatus.PENDING
|
|
3144
|
+
}));
|
|
3145
|
+
urlType = "createPassword";
|
|
3146
|
+
break;
|
|
3147
|
+
}
|
|
3148
|
+
const url = yield this.constructPortalUrl(urlType, {
|
|
3149
|
+
isForNewDevice,
|
|
3150
|
+
pathId: credentialId,
|
|
3151
|
+
portalTheme,
|
|
3152
|
+
shorten
|
|
3153
|
+
});
|
|
3154
|
+
return { credentialId, url };
|
|
3155
|
+
});
|
|
3156
|
+
}
|
|
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) {
|
|
3166
|
+
return __async(this, arguments, function* ({
|
|
3167
|
+
authMethod = "PASSKEY",
|
|
3168
|
+
shorten = false,
|
|
3169
|
+
portalTheme,
|
|
3170
|
+
sessionId
|
|
3171
|
+
}) {
|
|
3172
|
+
if (!sessionId) {
|
|
3173
|
+
sessionId = (yield this.touchSession()).sessionLookupId;
|
|
3174
|
+
}
|
|
3175
|
+
this.assertIsAuthSet();
|
|
3176
|
+
let urlType;
|
|
3177
|
+
switch (authMethod) {
|
|
3178
|
+
case "PASSKEY":
|
|
3179
|
+
urlType = "loginAuth";
|
|
3180
|
+
break;
|
|
3181
|
+
case "PASSWORD":
|
|
3182
|
+
urlType = "loginPassword";
|
|
3183
|
+
break;
|
|
3184
|
+
default:
|
|
3185
|
+
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
3186
|
+
}
|
|
3187
|
+
return this.constructPortalUrl(urlType, {
|
|
3188
|
+
sessionId,
|
|
3189
|
+
shorten,
|
|
3190
|
+
portalTheme
|
|
3191
|
+
});
|
|
3192
|
+
});
|
|
3193
|
+
}
|
|
3194
|
+
getOAuthUrl(_0) {
|
|
3195
|
+
return __async(this, arguments, function* ({ method, deeplinkUrl }) {
|
|
3196
|
+
yield this.logout();
|
|
3197
|
+
const { sessionLookupId } = yield this.touchSession(true);
|
|
3198
|
+
return constructUrl({
|
|
3199
|
+
base: getBaseOAuthUrl(this.ctx.env),
|
|
3200
|
+
path: `/auth/${method}`,
|
|
3201
|
+
params: {
|
|
3202
|
+
apiKey: this.ctx.apiKey,
|
|
3203
|
+
sessionLookupId,
|
|
3204
|
+
deeplinkUrl
|
|
3205
|
+
}
|
|
3206
|
+
});
|
|
3207
|
+
});
|
|
3208
|
+
}
|
|
3209
|
+
signUpOrLogIn(_c) {
|
|
3210
|
+
return __async(this, null, function* () {
|
|
3211
|
+
var _d = _c, { auth } = _d, urlOptions = __objRest(_d, ["auth"]);
|
|
3212
|
+
const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
3213
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
verifyNewAccount(_e) {
|
|
3217
|
+
return __async(this, null, function* () {
|
|
3218
|
+
var _f = _e, {
|
|
3219
|
+
verificationCode
|
|
3220
|
+
} = _f, urlOptions = __objRest(_f, [
|
|
3221
|
+
"verificationCode"
|
|
3222
|
+
]);
|
|
3223
|
+
this.assertIsAuthSet(["email", "phone"]);
|
|
3224
|
+
const userId = this.assertUserId();
|
|
3225
|
+
const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
|
|
3226
|
+
verificationCode
|
|
3227
|
+
});
|
|
3228
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3229
|
+
});
|
|
3230
|
+
}
|
|
3231
|
+
verifyOAuth(_g) {
|
|
3232
|
+
return __async(this, null, function* () {
|
|
3233
|
+
var _h = _g, {
|
|
3234
|
+
method,
|
|
3235
|
+
deeplinkUrl,
|
|
3236
|
+
isCanceled = () => false,
|
|
3237
|
+
onCancel,
|
|
3238
|
+
onPoll,
|
|
3239
|
+
onOAuthUrl
|
|
3240
|
+
} = _h, urlOptions = __objRest(_h, [
|
|
3241
|
+
"method",
|
|
3242
|
+
"deeplinkUrl",
|
|
3243
|
+
"isCanceled",
|
|
3244
|
+
"onCancel",
|
|
3245
|
+
"onPoll",
|
|
3246
|
+
"onOAuthUrl"
|
|
3247
|
+
]);
|
|
3248
|
+
const sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
3249
|
+
const oAuthUrl = constructUrl({
|
|
3250
|
+
base: getBaseOAuthUrl(this.ctx.env),
|
|
3251
|
+
path: `/auth/${method}`,
|
|
3252
|
+
params: {
|
|
3253
|
+
apiKey: this.ctx.apiKey,
|
|
3254
|
+
sessionLookupId,
|
|
3255
|
+
deeplinkUrl
|
|
3256
|
+
}
|
|
3257
|
+
});
|
|
3258
|
+
onOAuthUrl(oAuthUrl);
|
|
3259
|
+
const startedAt = Date.now();
|
|
3260
|
+
return new Promise((resolve, reject) => {
|
|
3261
|
+
(() => __async(this, null, function* () {
|
|
3262
|
+
while (true) {
|
|
3263
|
+
try {
|
|
3264
|
+
if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
|
|
3265
|
+
onCancel == null ? void 0 : onCancel();
|
|
3266
|
+
return reject("canceled");
|
|
3267
|
+
}
|
|
3268
|
+
yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
|
|
3269
|
+
const serverAuthState = yield this.ctx.client.verifyOAuth();
|
|
3270
|
+
if (isServerAuthState(serverAuthState)) {
|
|
3271
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
3272
|
+
return resolve(authState);
|
|
3273
|
+
}
|
|
3274
|
+
onPoll == null ? void 0 : onPoll();
|
|
3275
|
+
} catch (err) {
|
|
3276
|
+
console.error(err);
|
|
3277
|
+
onPoll == null ? void 0 : onPoll();
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
}))();
|
|
3281
|
+
});
|
|
3282
|
+
});
|
|
3283
|
+
}
|
|
3284
|
+
verifyFarcaster(_i) {
|
|
3285
|
+
return __async(this, null, function* () {
|
|
3286
|
+
var _j = _i, {
|
|
3287
|
+
isCanceled = () => false,
|
|
3288
|
+
onConnectUri,
|
|
3289
|
+
onCancel,
|
|
3290
|
+
onPoll
|
|
3291
|
+
} = _j, urlOptions = __objRest(_j, [
|
|
3292
|
+
"isCanceled",
|
|
3293
|
+
"onConnectUri",
|
|
3294
|
+
"onCancel",
|
|
3295
|
+
"onPoll"
|
|
3296
|
+
]);
|
|
3297
|
+
const {
|
|
3298
|
+
data: { connect_uri: connectUri }
|
|
3299
|
+
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
3300
|
+
onConnectUri(connectUri);
|
|
3301
|
+
return new Promise((resolve, reject) => {
|
|
3302
|
+
(() => __async(this, null, function* () {
|
|
3303
|
+
const startedAt = Date.now();
|
|
3304
|
+
while (true) {
|
|
3305
|
+
try {
|
|
3306
|
+
if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
|
|
3307
|
+
onCancel == null ? void 0 : onCancel();
|
|
3308
|
+
return reject("canceled");
|
|
3309
|
+
}
|
|
3310
|
+
yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
|
|
3311
|
+
const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
|
|
3312
|
+
if (isServerAuthState(serverAuthState)) {
|
|
3313
|
+
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3314
|
+
return resolve(authState);
|
|
3315
|
+
}
|
|
3316
|
+
onPoll == null ? void 0 : onPoll();
|
|
3317
|
+
} catch (e) {
|
|
3318
|
+
console.error(e);
|
|
3319
|
+
return reject(e);
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
}))();
|
|
3323
|
+
});
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
/**
|
|
3327
|
+
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
3328
|
+
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
3329
|
+
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
3330
|
+
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
3331
|
+
*/
|
|
3332
|
+
verifyTelegram(_k) {
|
|
3333
|
+
return __async(this, null, function* () {
|
|
3334
|
+
var _l = _k, {
|
|
3335
|
+
telegramAuthResponse
|
|
3336
|
+
} = _l, urlOptions = __objRest(_l, [
|
|
3337
|
+
"telegramAuthResponse"
|
|
3338
|
+
]);
|
|
3339
|
+
try {
|
|
3340
|
+
const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
|
|
3341
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3342
|
+
} catch (e) {
|
|
3343
|
+
throw new Error(e.message);
|
|
3344
|
+
}
|
|
3668
3345
|
});
|
|
3669
3346
|
}
|
|
3670
3347
|
/**
|
|
3671
|
-
*
|
|
3672
|
-
*
|
|
3673
|
-
* @param
|
|
3674
|
-
* @param
|
|
3675
|
-
* @param
|
|
3348
|
+
* Waits for the session to be active and sets up the user.
|
|
3349
|
+
*
|
|
3350
|
+
* @param {Object} opts the options object
|
|
3351
|
+
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
3352
|
+
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
3353
|
+
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
3676
3354
|
**/
|
|
3677
|
-
|
|
3355
|
+
waitForLogin() {
|
|
3678
3356
|
return __async(this, arguments, function* ({
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3357
|
+
isCanceled = () => false,
|
|
3358
|
+
onCancel,
|
|
3359
|
+
onPoll,
|
|
3360
|
+
skipSessionRefresh = false
|
|
3361
|
+
} = {}) {
|
|
3362
|
+
const startedAt = Date.now();
|
|
3363
|
+
return new Promise((resolve, reject) => {
|
|
3364
|
+
(() => __async(this, null, function* () {
|
|
3365
|
+
var _a;
|
|
3366
|
+
if (!this.isExternalWalletAuth) {
|
|
3367
|
+
this.externalWallets = {};
|
|
3368
|
+
}
|
|
3369
|
+
while (true) {
|
|
3370
|
+
if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
|
|
3371
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
|
|
3372
|
+
onCancel == null ? void 0 : onCancel();
|
|
3373
|
+
return reject("canceled");
|
|
3374
|
+
}
|
|
3375
|
+
yield new Promise((resolve2) => setTimeout(resolve2, POLLING_INTERVAL_MS));
|
|
3376
|
+
try {
|
|
3377
|
+
let session = yield this.touchSession();
|
|
3378
|
+
if (!session.isAuthenticated) {
|
|
3379
|
+
onPoll == null ? void 0 : onPoll();
|
|
3380
|
+
continue;
|
|
3381
|
+
}
|
|
3382
|
+
session = yield this.userSetupAfterLogin();
|
|
3383
|
+
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
3384
|
+
if (!needsWallet) {
|
|
3385
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
3386
|
+
onPoll == null ? void 0 : onPoll();
|
|
3387
|
+
continue;
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
3391
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
3392
|
+
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
3393
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
3394
|
+
yield this.claimPregenWallets();
|
|
3395
|
+
const resp = {
|
|
3396
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
3397
|
+
partnerId: session.partnerId
|
|
3398
|
+
};
|
|
3399
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp);
|
|
3400
|
+
return resolve(resp);
|
|
3401
|
+
}
|
|
3402
|
+
onPoll == null ? void 0 : onPoll();
|
|
3403
|
+
} catch (err) {
|
|
3404
|
+
console.error(err);
|
|
3405
|
+
onPoll == null ? void 0 : onPoll();
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3408
|
+
}))();
|
|
3409
|
+
});
|
|
3410
|
+
});
|
|
3411
|
+
}
|
|
3412
|
+
waitForSignup(_0) {
|
|
3413
|
+
return __async(this, arguments, function* ({
|
|
3414
|
+
isCanceled = () => false,
|
|
3415
|
+
onCancel,
|
|
3416
|
+
onPoll
|
|
3682
3417
|
}) {
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3418
|
+
const startedAt = Date.now();
|
|
3419
|
+
return new Promise((resolve, reject) => {
|
|
3420
|
+
(() => __async(this, null, function* () {
|
|
3421
|
+
yield this.touchSession();
|
|
3422
|
+
if (!this.isExternalWalletAuth) {
|
|
3423
|
+
this.externalWallets = {};
|
|
3424
|
+
}
|
|
3425
|
+
while (true) {
|
|
3426
|
+
try {
|
|
3427
|
+
if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
|
|
3428
|
+
onCancel == null ? void 0 : onCancel();
|
|
3429
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, false, "failed to sign up user");
|
|
3430
|
+
return reject("canceled");
|
|
3431
|
+
}
|
|
3432
|
+
yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
|
|
3433
|
+
if (yield this.isSessionActive()) {
|
|
3434
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
3435
|
+
return resolve(true);
|
|
3436
|
+
}
|
|
3437
|
+
onPoll == null ? void 0 : onPoll();
|
|
3438
|
+
} catch (err) {
|
|
3439
|
+
console.error(err);
|
|
3440
|
+
onPoll == null ? void 0 : onPoll();
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
}))();
|
|
3444
|
+
});
|
|
3445
|
+
});
|
|
3446
|
+
}
|
|
3447
|
+
waitForWalletCreation() {
|
|
3448
|
+
return __async(this, arguments, function* ({
|
|
3449
|
+
isCanceled = () => false,
|
|
3450
|
+
onCancel
|
|
3451
|
+
} = {}) {
|
|
3452
|
+
yield this.waitForSignup({ isCanceled, onCancel });
|
|
3453
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3454
|
+
const pregenWallets = yield this.getPregenWallets();
|
|
3455
|
+
let recoverySecret, walletIds = {};
|
|
3456
|
+
if (pregenWallets.length > 0) {
|
|
3457
|
+
recoverySecret = yield this.claimPregenWallets();
|
|
3458
|
+
walletIds = supportedWalletTypes.reduce((acc, { type }) => {
|
|
3459
|
+
var _a;
|
|
3460
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
3461
|
+
[type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
3462
|
+
});
|
|
3463
|
+
}, {});
|
|
3704
3464
|
}
|
|
3705
|
-
|
|
3465
|
+
const created = yield this.createWalletPerType();
|
|
3466
|
+
recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
|
|
3467
|
+
walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
|
|
3468
|
+
const resp = { walletIds, recoverySecret };
|
|
3469
|
+
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
3470
|
+
return resp;
|
|
3706
3471
|
});
|
|
3707
3472
|
}
|
|
3708
|
-
|
|
3709
|
-
return
|
|
3473
|
+
loginExternalWallet(_m) {
|
|
3474
|
+
return __async(this, null, function* () {
|
|
3475
|
+
var _n = _m, {
|
|
3476
|
+
externalWallet
|
|
3477
|
+
} = _n, urlOptions = __objRest(_n, [
|
|
3478
|
+
"externalWallet"
|
|
3479
|
+
]);
|
|
3480
|
+
this.requireApiKey();
|
|
3481
|
+
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
|
|
3482
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3483
|
+
});
|
|
3484
|
+
}
|
|
3485
|
+
verifyExternalWallet(_o) {
|
|
3486
|
+
return __async(this, null, function* () {
|
|
3487
|
+
var _p = _o, {
|
|
3488
|
+
externalWallet,
|
|
3489
|
+
signedMessage,
|
|
3490
|
+
cosmosPublicKeyHex,
|
|
3491
|
+
cosmosSigner
|
|
3492
|
+
} = _p, urlOptions = __objRest(_p, [
|
|
3493
|
+
"externalWallet",
|
|
3494
|
+
"signedMessage",
|
|
3495
|
+
"cosmosPublicKeyHex",
|
|
3496
|
+
"cosmosSigner"
|
|
3497
|
+
]);
|
|
3498
|
+
const serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
|
|
3499
|
+
externalWallet,
|
|
3500
|
+
signedMessage,
|
|
3501
|
+
cosmosPublicKeyHex,
|
|
3502
|
+
cosmosSigner
|
|
3503
|
+
});
|
|
3504
|
+
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3505
|
+
});
|
|
3710
3506
|
}
|
|
3711
3507
|
/**
|
|
3712
|
-
*
|
|
3508
|
+
* Performs 2FA verification.
|
|
3713
3509
|
* @param {Object} opts the options object
|
|
3714
|
-
* @param {
|
|
3715
|
-
* @param {
|
|
3716
|
-
* @
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3510
|
+
* @param {string} opts.email the email to use for performing a 2FA verification.
|
|
3511
|
+
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
3512
|
+
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
3513
|
+
*/
|
|
3514
|
+
verify2fa(_0) {
|
|
3515
|
+
return __async(this, arguments, function* ({ auth, verificationCode }) {
|
|
3516
|
+
const res = yield this.ctx.client.verify2FA(auth, verificationCode);
|
|
3517
|
+
return {
|
|
3518
|
+
initiatedAt: res.data.initiatedAt,
|
|
3519
|
+
status: res.data.status,
|
|
3520
|
+
userId: res.data.userId,
|
|
3521
|
+
wallets: res.data.wallets
|
|
3522
|
+
};
|
|
3523
|
+
});
|
|
3524
|
+
}
|
|
3525
|
+
/**
|
|
3526
|
+
* Sets up two-factor authentication for the current user.
|
|
3527
|
+
* @returns {string} uri - uri to use for setting up 2FA
|
|
3528
|
+
* */
|
|
3529
|
+
setup2fa() {
|
|
3720
3530
|
return __async(this, null, function* () {
|
|
3721
|
-
|
|
3722
|
-
const
|
|
3723
|
-
|
|
3724
|
-
userId: this.userId,
|
|
3725
|
-
params: __spreadProps(__spreadValues({}, params), {
|
|
3726
|
-
address: (_b = walletParams.externalWalletAddress) != null ? _b : this.getDisplayAddress(walletParams.walletId, { addressType: params.walletType })
|
|
3727
|
-
})
|
|
3728
|
-
}, walletParams));
|
|
3729
|
-
const portalUrl = yield this.getOnRampTransactionUrl(__spreadValues({
|
|
3730
|
-
purchaseId: onRampPurchase.id,
|
|
3731
|
-
providerKey: onRampPurchase.providerKey
|
|
3732
|
-
}, walletParams));
|
|
3733
|
-
if (shouldOpenPopup) {
|
|
3734
|
-
this.platformUtils.openPopup(portalUrl, { type: "ON_RAMP_TRANSACTION" /* ON_RAMP_TRANSACTION */ });
|
|
3735
|
-
}
|
|
3736
|
-
return { onRampPurchase, portalUrl };
|
|
3531
|
+
const userId = this.assertUserId();
|
|
3532
|
+
const res = yield this.ctx.client.setup2FA(userId);
|
|
3533
|
+
return res;
|
|
3737
3534
|
});
|
|
3738
3535
|
}
|
|
3739
3536
|
/**
|
|
3740
|
-
*
|
|
3537
|
+
* Enables 2FA.
|
|
3538
|
+
* @param {Object} opts the options object
|
|
3539
|
+
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
3540
|
+
*/
|
|
3541
|
+
enable2fa(_0) {
|
|
3542
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
3543
|
+
const userId = this.assertUserId();
|
|
3544
|
+
yield this.ctx.client.enable2FA(userId, verificationCode);
|
|
3545
|
+
});
|
|
3546
|
+
}
|
|
3547
|
+
/**
|
|
3548
|
+
* Creates a new pregenerated wallet.
|
|
3549
|
+
*
|
|
3550
|
+
* @param {Object} opts the options object.
|
|
3551
|
+
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
3552
|
+
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
3553
|
+
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
3554
|
+
* @returns {Wallet} the created wallet.
|
|
3741
3555
|
**/
|
|
3742
|
-
|
|
3556
|
+
createPregenWallet(opts) {
|
|
3743
3557
|
return __async(this, null, function* () {
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3558
|
+
var _a, _b;
|
|
3559
|
+
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3560
|
+
const { type: _type = (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type, pregenId } = opts;
|
|
3561
|
+
this.requireApiKey();
|
|
3562
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
3563
|
+
_type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
3564
|
+
);
|
|
3565
|
+
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
3566
|
+
let keygenRes;
|
|
3567
|
+
switch (walletType) {
|
|
3568
|
+
case WalletType2.SOLANA:
|
|
3569
|
+
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
3570
|
+
this.ctx,
|
|
3571
|
+
pregenIdentifier,
|
|
3572
|
+
pregenIdentifierType,
|
|
3573
|
+
this.retrieveSessionCookie()
|
|
3574
|
+
);
|
|
3575
|
+
break;
|
|
3576
|
+
default:
|
|
3577
|
+
keygenRes = yield this.platformUtils.preKeygen(
|
|
3578
|
+
this.ctx,
|
|
3579
|
+
void 0,
|
|
3580
|
+
pregenIdentifier,
|
|
3581
|
+
pregenIdentifierType,
|
|
3582
|
+
walletType,
|
|
3583
|
+
null,
|
|
3584
|
+
this.retrieveSessionCookie()
|
|
3585
|
+
);
|
|
3586
|
+
break;
|
|
3749
3587
|
}
|
|
3588
|
+
const { signer, walletId } = keygenRes;
|
|
3589
|
+
this.wallets[walletId] = {
|
|
3590
|
+
id: walletId,
|
|
3591
|
+
signer,
|
|
3592
|
+
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
3593
|
+
type: walletType,
|
|
3594
|
+
isPregen: true,
|
|
3595
|
+
pregenIdentifier,
|
|
3596
|
+
pregenIdentifierType
|
|
3597
|
+
};
|
|
3598
|
+
yield this.waitForPregenWalletAddress(walletId);
|
|
3599
|
+
yield this.populatePregenWalletAddresses();
|
|
3600
|
+
return this.wallets[walletId];
|
|
3750
3601
|
});
|
|
3751
3602
|
}
|
|
3752
3603
|
/**
|
|
3753
|
-
*
|
|
3754
|
-
*
|
|
3755
|
-
*
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
for (const wallet of Object.values(sessionInfo.wallets)) {
|
|
3772
|
-
delete wallet.signer;
|
|
3604
|
+
* Creates new pregenerated wallets for each desired type.
|
|
3605
|
+
* If no types are provided, this method will create one for each of the non-optional types
|
|
3606
|
+
* specified in the instance's `supportedWalletTypes` array that are not already present.
|
|
3607
|
+
* @param {Object} opts the options object.
|
|
3608
|
+
* @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
|
|
3609
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
3610
|
+
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
3611
|
+
* @returns {Wallet[]} an array containing the created wallets.
|
|
3612
|
+
**/
|
|
3613
|
+
createPregenWalletPerType(_0) {
|
|
3614
|
+
return __async(this, arguments, function* ({
|
|
3615
|
+
types,
|
|
3616
|
+
pregenId
|
|
3617
|
+
}) {
|
|
3618
|
+
const wallets = [];
|
|
3619
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
3620
|
+
const wallet = yield this.createPregenWallet({ type, pregenId });
|
|
3621
|
+
wallets.push(wallet);
|
|
3773
3622
|
}
|
|
3774
|
-
|
|
3775
|
-
|
|
3623
|
+
return wallets;
|
|
3624
|
+
});
|
|
3776
3625
|
}
|
|
3777
3626
|
/**
|
|
3778
|
-
*
|
|
3779
|
-
* @param {
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3627
|
+
* Claims a pregenerated wallet.
|
|
3628
|
+
* @param {Object} opts the options object.
|
|
3629
|
+
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
3630
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
3631
|
+
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3632
|
+
**/
|
|
3633
|
+
claimPregenWallets() {
|
|
3634
|
+
return __async(this, arguments, function* ({
|
|
3635
|
+
pregenId
|
|
3636
|
+
} = {}) {
|
|
3783
3637
|
var _a;
|
|
3784
|
-
|
|
3785
|
-
const
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
yield this.setFarcasterUsername(sessionInfo.farcasterUsername);
|
|
3789
|
-
yield this.setUserId(sessionInfo.userId);
|
|
3790
|
-
yield this.setWallets(sessionInfo.wallets);
|
|
3791
|
-
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
3792
|
-
for (const walletId of Object.keys(this.wallets)) {
|
|
3793
|
-
if (!this.wallets[walletId].userId) {
|
|
3794
|
-
this.wallets[walletId].userId = this.userId;
|
|
3795
|
-
}
|
|
3638
|
+
this.requireApiKey();
|
|
3639
|
+
const pregenWallets = pregenId ? yield this.getPregenWallets({ pregenId }) : yield this.getPregenWallets();
|
|
3640
|
+
if (pregenWallets.length === 0) {
|
|
3641
|
+
return void 0;
|
|
3796
3642
|
}
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3643
|
+
let newRecoverySecret;
|
|
3644
|
+
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
3645
|
+
userId: this.userId,
|
|
3646
|
+
walletIds: pregenWallets.map((w) => w.id)
|
|
3647
|
+
});
|
|
3648
|
+
for (const walletId of walletIds) {
|
|
3649
|
+
const wallet = this.wallets[walletId];
|
|
3650
|
+
let refreshedShare;
|
|
3651
|
+
if (wallet.scheme === WalletScheme2.ED25519) {
|
|
3652
|
+
const distributeRes = yield distributeNewShare({
|
|
3653
|
+
ctx: this.ctx,
|
|
3654
|
+
userId: this.userId,
|
|
3655
|
+
walletId: wallet.id,
|
|
3656
|
+
userShare: this.wallets[wallet.id].signer,
|
|
3657
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3658
|
+
partnerId: wallet.partnerId
|
|
3659
|
+
});
|
|
3660
|
+
if (distributeRes.length > 0) {
|
|
3661
|
+
newRecoverySecret = distributeRes;
|
|
3662
|
+
}
|
|
3663
|
+
} else {
|
|
3664
|
+
refreshedShare = yield this.refreshShare({
|
|
3665
|
+
walletId: wallet.id,
|
|
3666
|
+
share: this.wallets[wallet.id].signer,
|
|
3667
|
+
oldPartnerId: wallet.partnerId,
|
|
3668
|
+
newPartnerId: wallet.partnerId,
|
|
3669
|
+
redistributeBackupEncryptedShares: true
|
|
3670
|
+
});
|
|
3671
|
+
if (refreshedShare.recoverySecret) {
|
|
3672
|
+
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3673
|
+
}
|
|
3806
3674
|
}
|
|
3807
|
-
|
|
3675
|
+
this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
|
|
3676
|
+
signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
|
|
3677
|
+
userId: this.userId,
|
|
3678
|
+
pregenIdentifier: void 0,
|
|
3679
|
+
pregenIdentifierType: void 0
|
|
3680
|
+
});
|
|
3681
|
+
const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
|
|
3682
|
+
delete walletNoSigner.signer;
|
|
3683
|
+
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
3684
|
+
wallet: walletNoSigner,
|
|
3685
|
+
recoverySecret: newRecoverySecret
|
|
3686
|
+
});
|
|
3808
3687
|
}
|
|
3809
|
-
this.
|
|
3810
|
-
|
|
3811
|
-
});
|
|
3812
|
-
}
|
|
3813
|
-
exitAccountCreation() {
|
|
3814
|
-
this.isAwaitingAccountCreation = false;
|
|
3815
|
-
}
|
|
3816
|
-
exitLogin() {
|
|
3817
|
-
this.isAwaitingLogin = false;
|
|
3818
|
-
}
|
|
3819
|
-
exitFarcaster() {
|
|
3820
|
-
this.isAwaitingFarcaster = false;
|
|
3821
|
-
}
|
|
3822
|
-
exitOAuth() {
|
|
3823
|
-
this.isAwaitingOAuth = false;
|
|
3824
|
-
}
|
|
3825
|
-
exitLoops() {
|
|
3826
|
-
this.exitAccountCreation();
|
|
3827
|
-
this.exitLogin();
|
|
3828
|
-
this.exitFarcaster();
|
|
3829
|
-
this.exitOAuth();
|
|
3830
|
-
}
|
|
3831
|
-
/**
|
|
3832
|
-
* Retrieves a token to verify the current session.
|
|
3833
|
-
* @returns {Promise<string>} the ID
|
|
3834
|
-
**/
|
|
3835
|
-
getVerificationToken() {
|
|
3836
|
-
return __async(this, null, function* () {
|
|
3837
|
-
const { data } = yield this.touchSession();
|
|
3838
|
-
return data.sessionLookupId;
|
|
3688
|
+
yield this.setWallets(this.wallets);
|
|
3689
|
+
return newRecoverySecret;
|
|
3839
3690
|
});
|
|
3840
3691
|
}
|
|
3841
3692
|
/**
|
|
3842
|
-
*
|
|
3693
|
+
* Updates the identifier for a pregen wallet.
|
|
3843
3694
|
* @param {Object} opts the options object.
|
|
3844
|
-
* @param {
|
|
3695
|
+
* @param {string} opts.walletId the pregen wallet ID
|
|
3696
|
+
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
3697
|
+
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
3845
3698
|
**/
|
|
3846
|
-
|
|
3847
|
-
return __async(this, arguments, function* ({
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3699
|
+
updatePregenWalletIdentifier(_0) {
|
|
3700
|
+
return __async(this, arguments, function* ({
|
|
3701
|
+
walletId,
|
|
3702
|
+
newPregenId
|
|
3703
|
+
}) {
|
|
3704
|
+
this.requireApiKey();
|
|
3705
|
+
const [newPregenIdentifierType, newPregenIdentifier] = toPregenTypeAndId(newPregenId);
|
|
3706
|
+
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
3707
|
+
pregenIdentifier: newPregenIdentifier,
|
|
3708
|
+
pregenIdentifierType: newPregenIdentifierType
|
|
3709
|
+
});
|
|
3710
|
+
if (!!this.wallets[walletId]) {
|
|
3711
|
+
this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3712
|
+
pregenIdentifier: newPregenIdentifier,
|
|
3713
|
+
pregenIdentifierType: newPregenIdentifierType
|
|
3855
3714
|
});
|
|
3856
3715
|
yield this.setWallets(this.wallets);
|
|
3857
|
-
} else {
|
|
3858
|
-
this.wallets = {};
|
|
3859
3716
|
}
|
|
3860
|
-
this.currentWalletIds = {};
|
|
3861
|
-
this.externalWallets = {};
|
|
3862
|
-
this.loginEncryptionKeyPair = void 0;
|
|
3863
|
-
this.email = void 0;
|
|
3864
|
-
this.telegramUserId = void 0;
|
|
3865
|
-
this.phone = void 0;
|
|
3866
|
-
this.countryCode = void 0;
|
|
3867
|
-
this.userId = void 0;
|
|
3868
|
-
this.sessionCookie = void 0;
|
|
3869
|
-
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
3870
3717
|
});
|
|
3871
3718
|
}
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3719
|
+
/**
|
|
3720
|
+
* Checks if a pregen Wallet exists for the given identifier with the current partner.
|
|
3721
|
+
* @param {Object} opts the options object.
|
|
3722
|
+
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
3723
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
3724
|
+
* @returns {boolean} whether the pregen wallet exists
|
|
3725
|
+
**/
|
|
3726
|
+
hasPregenWallet(_0) {
|
|
3727
|
+
return __async(this, arguments, function* ({ pregenId }) {
|
|
3728
|
+
this.requireApiKey();
|
|
3729
|
+
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
3730
|
+
const wallets = yield this.getPregenWallets({ pregenId });
|
|
3731
|
+
const wallet = wallets.find(
|
|
3732
|
+
(w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType
|
|
3733
|
+
);
|
|
3734
|
+
if (!wallet) {
|
|
3735
|
+
return false;
|
|
3880
3736
|
}
|
|
3881
|
-
return
|
|
3737
|
+
return true;
|
|
3882
3738
|
});
|
|
3883
3739
|
}
|
|
3884
3740
|
/**
|
|
3885
|
-
*
|
|
3886
|
-
*
|
|
3887
|
-
*
|
|
3741
|
+
* Get pregen wallets for the given identifier.
|
|
3742
|
+
* @param {Object} opts the options object.
|
|
3743
|
+
* @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet
|
|
3744
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
3745
|
+
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
3888
3746
|
**/
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
(
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
3900
|
-
[walletId]: __spreadProps(__spreadValues({}, this.externalWallets[walletId]), {
|
|
3901
|
-
signer: this.externalWallets[walletId].signer ? "[REDACTED]" : void 0
|
|
3902
|
-
})
|
|
3903
|
-
}),
|
|
3904
|
-
{}
|
|
3905
|
-
);
|
|
3906
|
-
const obj = {
|
|
3907
|
-
supportedWalletTypes: this.supportedWalletTypes,
|
|
3908
|
-
cosmosPrefix: this.cosmosPrefix,
|
|
3909
|
-
email: this.email,
|
|
3910
|
-
phone: this.phone,
|
|
3911
|
-
countryCode: this.countryCode,
|
|
3912
|
-
telegramUserId: this.telegramUserId,
|
|
3913
|
-
farcasterUsername: this.farcasterUsername,
|
|
3914
|
-
userId: this.userId,
|
|
3915
|
-
pregenIds: this.pregenIds,
|
|
3916
|
-
currentWalletIds: this.currentWalletIds,
|
|
3917
|
-
wallets: redactedWallets,
|
|
3918
|
-
externalWallets: redactedExternalWallets,
|
|
3919
|
-
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
3920
|
-
ctx: {
|
|
3921
|
-
apiKey: this.ctx.apiKey,
|
|
3922
|
-
disableWorkers: this.ctx.disableWorkers,
|
|
3923
|
-
disableWebSockets: this.ctx.disableWebSockets,
|
|
3924
|
-
env: this.ctx.env,
|
|
3925
|
-
offloadMPCComputationURL: this.ctx.offloadMPCComputationURL,
|
|
3926
|
-
useLocalFiles: this.ctx.useLocalFiles,
|
|
3927
|
-
useDKLS: this.ctx.useDKLS,
|
|
3928
|
-
cosmosPrefix: this.ctx.cosmosPrefix
|
|
3929
|
-
}
|
|
3930
|
-
};
|
|
3931
|
-
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
3747
|
+
getPregenWallets() {
|
|
3748
|
+
return __async(this, arguments, function* ({ pregenId } = {}) {
|
|
3749
|
+
this.requireApiKey();
|
|
3750
|
+
const res = yield this.ctx.client.getPregenWallets(
|
|
3751
|
+
pregenId ? toPregenIds(pregenId) : this.pregenIds,
|
|
3752
|
+
this.isPortal(),
|
|
3753
|
+
this.userId
|
|
3754
|
+
);
|
|
3755
|
+
return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
|
|
3756
|
+
});
|
|
3932
3757
|
}
|
|
3933
3758
|
};
|
|
3934
|
-
|
|
3935
|
-
|
|
3759
|
+
_authInfo = new WeakMap();
|
|
3760
|
+
_partner = new WeakMap();
|
|
3761
|
+
_ParaCore_instances = new WeakSet();
|
|
3762
|
+
assertPartner_fn = function() {
|
|
3763
|
+
return __async(this, null, function* () {
|
|
3764
|
+
var _a, _b;
|
|
3765
|
+
if (!__privateGet(this, _partner)) {
|
|
3766
|
+
yield this.touchSession();
|
|
3767
|
+
}
|
|
3768
|
+
if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
|
|
3769
|
+
this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
|
|
3770
|
+
}
|
|
3771
|
+
return __privateGet(this, _partner);
|
|
3772
|
+
});
|
|
3773
|
+
};
|
|
3774
|
+
toAuthInfo_fn = function({
|
|
3775
|
+
email,
|
|
3776
|
+
phone,
|
|
3777
|
+
countryCode,
|
|
3778
|
+
farcasterUsername,
|
|
3779
|
+
telegramUserId,
|
|
3780
|
+
externalWalletAddress
|
|
3781
|
+
}) {
|
|
3782
|
+
let auth;
|
|
3783
|
+
switch (true) {
|
|
3784
|
+
case !!email:
|
|
3785
|
+
auth = { email };
|
|
3786
|
+
break;
|
|
3787
|
+
case !!phone:
|
|
3788
|
+
{
|
|
3789
|
+
const validPhone = formatPhoneNumber(phone, countryCode);
|
|
3790
|
+
if (validPhone) auth = { phone: formatPhoneNumber(phone, countryCode) };
|
|
3791
|
+
}
|
|
3792
|
+
break;
|
|
3793
|
+
case !!farcasterUsername:
|
|
3794
|
+
auth = { farcasterUsername };
|
|
3795
|
+
break;
|
|
3796
|
+
case !!telegramUserId:
|
|
3797
|
+
auth = { telegramUserId };
|
|
3798
|
+
break;
|
|
3799
|
+
case !!externalWalletAddress:
|
|
3800
|
+
auth = { externalWalletAddress };
|
|
3801
|
+
break;
|
|
3802
|
+
}
|
|
3803
|
+
return extractAuthInfo(auth);
|
|
3804
|
+
};
|
|
3805
|
+
setAuthInfo_fn = function(authInfo) {
|
|
3806
|
+
return __async(this, null, function* () {
|
|
3807
|
+
__privateSet(this, _authInfo, authInfo);
|
|
3808
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_AUTH_INFO, JSON.stringify(authInfo));
|
|
3809
|
+
yield this.localStorageRemoveItem(LOCAL_STORAGE_EMAIL);
|
|
3810
|
+
yield this.localStorageRemoveItem(LOCAL_STORAGE_PHONE);
|
|
3811
|
+
yield this.localStorageRemoveItem(LOCAL_STORAGE_COUNTRY_CODE);
|
|
3812
|
+
yield this.localStorageRemoveItem(LOCAL_STORAGE_FARCASTER_USERNAME);
|
|
3813
|
+
yield this.localStorageRemoveItem(LOCAL_STORAGE_TELEGRAM_USER_ID);
|
|
3814
|
+
});
|
|
3815
|
+
};
|
|
3816
|
+
getPartner_fn = function(partnerId) {
|
|
3817
|
+
return __async(this, null, function* () {
|
|
3818
|
+
const res = yield this.ctx.client.getPartner(partnerId);
|
|
3819
|
+
__privateSet(this, _partner, res.data.partner);
|
|
3820
|
+
return __privateGet(this, _partner);
|
|
3821
|
+
});
|
|
3822
|
+
};
|
|
3823
|
+
prepareAuthState_fn = function(_0) {
|
|
3824
|
+
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
3825
|
+
if (!opts.sessionLookupId && serverAuthState.stage === "login") {
|
|
3826
|
+
opts.sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
3827
|
+
}
|
|
3828
|
+
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
3829
|
+
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), Object.fromEntries(
|
|
3830
|
+
Object.entries({
|
|
3831
|
+
displayName,
|
|
3832
|
+
pfpUrl,
|
|
3833
|
+
username,
|
|
3834
|
+
externalWallet
|
|
3835
|
+
}).filter(([_, v]) => !!v)
|
|
3836
|
+
));
|
|
3837
|
+
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
3838
|
+
yield this.assertIsAuthSet();
|
|
3839
|
+
if (!!externalWallet) {
|
|
3840
|
+
yield this.setExternalWallet(externalWallet);
|
|
3841
|
+
}
|
|
3842
|
+
if (!!userId) {
|
|
3843
|
+
yield this.setUserId(userId);
|
|
3844
|
+
}
|
|
3845
|
+
let authState;
|
|
3846
|
+
switch (serverAuthState.stage) {
|
|
3847
|
+
case "verify":
|
|
3848
|
+
authState = serverAuthState;
|
|
3849
|
+
break;
|
|
3850
|
+
case "login":
|
|
3851
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
|
|
3852
|
+
break;
|
|
3853
|
+
case "signup":
|
|
3854
|
+
authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
|
|
3855
|
+
break;
|
|
3856
|
+
}
|
|
3857
|
+
return authState;
|
|
3858
|
+
});
|
|
3859
|
+
};
|
|
3860
|
+
prepareLogin_fn = function() {
|
|
3861
|
+
return __async(this, null, function* () {
|
|
3862
|
+
yield this.logout();
|
|
3863
|
+
const { sessionLookupId } = yield this.touchSession(true);
|
|
3864
|
+
if (!this.loginEncryptionKeyPair) {
|
|
3865
|
+
yield this.setLoginEncryptionKeyPair();
|
|
3866
|
+
}
|
|
3867
|
+
return sessionLookupId;
|
|
3868
|
+
});
|
|
3869
|
+
};
|
|
3870
|
+
prepareLoginState_fn = function(_0, _1) {
|
|
3871
|
+
return __async(this, arguments, function* (loginState, {
|
|
3872
|
+
useShortUrls: shorten = false,
|
|
3873
|
+
portalTheme,
|
|
3874
|
+
sessionLookupId
|
|
3875
|
+
}) {
|
|
3876
|
+
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
3877
|
+
return __spreadValues(__spreadValues(__spreadValues({}, authState), !this.isNativePasskey && loginAuthMethods.includes(AuthMethod.PASSKEY) ? {
|
|
3878
|
+
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
3879
|
+
passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
|
|
3880
|
+
sessionId: sessionLookupId,
|
|
3881
|
+
newDevice: {
|
|
3882
|
+
sessionId: sessionLookupId,
|
|
3883
|
+
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
3884
|
+
},
|
|
3885
|
+
shorten,
|
|
3886
|
+
portalTheme
|
|
3887
|
+
})
|
|
3888
|
+
} : {}), loginAuthMethods.includes(AuthMethod.PASSWORD) ? {
|
|
3889
|
+
passwordUrl: yield this.constructPortalUrl("loginPassword", {
|
|
3890
|
+
sessionId: sessionLookupId,
|
|
3891
|
+
shorten,
|
|
3892
|
+
portalTheme
|
|
3893
|
+
})
|
|
3894
|
+
} : {});
|
|
3895
|
+
});
|
|
3896
|
+
};
|
|
3897
|
+
prepareSignUpState_fn = function(_0, _1) {
|
|
3898
|
+
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
3899
|
+
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
3900
|
+
const [isPasskey, isPassword] = [
|
|
3901
|
+
signupAuthMethods.includes(AuthMethod.PASSKEY),
|
|
3902
|
+
signupAuthMethods.includes(AuthMethod.PASSWORD)
|
|
3903
|
+
];
|
|
3904
|
+
if (!isPasskey && !isPassword) {
|
|
3905
|
+
throw new Error(
|
|
3906
|
+
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or passwords in your Developer Portal settings."
|
|
3907
|
+
);
|
|
3908
|
+
}
|
|
3909
|
+
const signupState = authState;
|
|
3910
|
+
if (isPasskey) {
|
|
3911
|
+
const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
|
|
3912
|
+
authMethod: "PASSKEY",
|
|
3913
|
+
shorten
|
|
3914
|
+
});
|
|
3915
|
+
signupState.passkeyUrl = passkeyUrl;
|
|
3916
|
+
signupState.passkeyId = passkeyId;
|
|
3917
|
+
}
|
|
3918
|
+
if (isPassword) {
|
|
3919
|
+
const { url: passwordUrl, credentialId: passwordId } = yield this.getNewCredentialAndUrl({
|
|
3920
|
+
authMethod: "PASSWORD",
|
|
3921
|
+
portalTheme,
|
|
3922
|
+
shorten
|
|
3923
|
+
});
|
|
3924
|
+
signupState.passwordUrl = passwordUrl;
|
|
3925
|
+
signupState.passwordId = passwordId;
|
|
3926
|
+
}
|
|
3927
|
+
return signupState;
|
|
3928
|
+
});
|
|
3929
|
+
};
|
|
3936
3930
|
_ParaCore.version = PARA_CORE_VERSION;
|
|
3937
3931
|
var ParaCore = _ParaCore;
|
|
3938
3932
|
|
|
@@ -3947,7 +3941,7 @@ import {
|
|
|
3947
3941
|
OnRampPurchaseType,
|
|
3948
3942
|
OnRampProvider,
|
|
3949
3943
|
OnRampPurchaseStatus,
|
|
3950
|
-
OAuthMethod
|
|
3944
|
+
OAuthMethod,
|
|
3951
3945
|
NON_ED25519,
|
|
3952
3946
|
PREGEN_IDENTIFIER_TYPES
|
|
3953
3947
|
} from "@getpara/user-management-client";
|
|
@@ -3961,12 +3955,13 @@ export {
|
|
|
3961
3955
|
KeyContainer,
|
|
3962
3956
|
NON_ED25519,
|
|
3963
3957
|
Network,
|
|
3964
|
-
|
|
3958
|
+
OAuthMethod,
|
|
3965
3959
|
OnRampAsset,
|
|
3966
3960
|
OnRampMethod,
|
|
3967
3961
|
OnRampProvider,
|
|
3968
3962
|
OnRampPurchaseStatus,
|
|
3969
3963
|
OnRampPurchaseType,
|
|
3964
|
+
PARA_CORE_METHODS,
|
|
3970
3965
|
PREGEN_IDENTIFIER_TYPES,
|
|
3971
3966
|
ParaEvent,
|
|
3972
3967
|
PopupType,
|
|
@@ -3978,6 +3973,7 @@ export {
|
|
|
3978
3973
|
TransactionReviewTimeout,
|
|
3979
3974
|
WalletScheme3 as WalletScheme,
|
|
3980
3975
|
WalletType3 as WalletType,
|
|
3976
|
+
constructUrl,
|
|
3981
3977
|
decimalToHex,
|
|
3982
3978
|
decryptPrivateKey,
|
|
3983
3979
|
decryptPrivateKeyAndDecryptShare,
|
|
@@ -3985,12 +3981,14 @@ export {
|
|
|
3985
3981
|
decryptWithKeyPair,
|
|
3986
3982
|
decryptWithPrivateKey,
|
|
3987
3983
|
src_default as default,
|
|
3984
|
+
displayPhoneNumber,
|
|
3988
3985
|
distributeNewShare,
|
|
3989
3986
|
encodePrivateKeyToPemHex,
|
|
3990
3987
|
encryptPrivateKey,
|
|
3991
3988
|
encryptPrivateKeyWithPassword,
|
|
3992
3989
|
encryptWithDerivedPublicKey,
|
|
3993
3990
|
entityToWallet,
|
|
3991
|
+
formatPhoneNumber,
|
|
3994
3992
|
getAsymmetricKeyPair,
|
|
3995
3993
|
getBaseMPCNetworkUrl,
|
|
3996
3994
|
getBaseOAuthUrl,
|
|
@@ -4012,10 +4010,9 @@ export {
|
|
|
4012
4010
|
initClient,
|
|
4013
4011
|
isWalletSupported,
|
|
4014
4012
|
mpcComputationClient_exports as mpcComputationClient,
|
|
4015
|
-
normalizePhoneNumber,
|
|
4016
4013
|
paraVersion,
|
|
4017
4014
|
publicKeyFromHex,
|
|
4018
|
-
|
|
4015
|
+
shortenUrl,
|
|
4019
4016
|
toAssetInfoArray,
|
|
4020
4017
|
retrieve as transmissionUtilsRetrieve,
|
|
4021
4018
|
truncateAddress,
|