@getpara/core-sdk 1.4.4 → 1.5.0-dev.0
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 +1929 -1699
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +1930 -1699
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/types/ParaCore.d.ts +0 -6
- package/dist/types/constants.d.ts +0 -1
- package/package.json +3 -3
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,65 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
2
35
|
var __export = (target, all) => {
|
|
3
36
|
for (var name in all)
|
|
4
37
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
38
|
};
|
|
39
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
40
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
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
|
+
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 __async = (__this, __arguments, generator) => {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
var fulfilled = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.next(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var rejected = (value) => {
|
|
53
|
+
try {
|
|
54
|
+
step(generator.throw(value));
|
|
55
|
+
} catch (e) {
|
|
56
|
+
reject(e);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
60
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
61
|
+
});
|
|
62
|
+
};
|
|
6
63
|
|
|
7
64
|
// src/ParaCore.ts
|
|
8
65
|
import { Buffer as NodeBuffer } from "buffer";
|
|
@@ -26,7 +83,7 @@ import forge from "node-forge";
|
|
|
26
83
|
// src/utils/events.ts
|
|
27
84
|
function dispatchEvent(type, data, error) {
|
|
28
85
|
typeof window !== "undefined" && !!window.dispatchEvent && window.dispatchEvent(
|
|
29
|
-
new CustomEvent(type, { detail: { data,
|
|
86
|
+
new CustomEvent(type, { detail: __spreadValues({ data }, error && { error: new Error(error) }) })
|
|
30
87
|
);
|
|
31
88
|
}
|
|
32
89
|
|
|
@@ -93,7 +150,8 @@ function truncateAddress(str, addressType, { prefix = addressType === "COSMOS" ?
|
|
|
93
150
|
return `${str.slice(0, headLength)}...${str.slice(-4)}`;
|
|
94
151
|
}
|
|
95
152
|
function stringToPhoneNumber(str) {
|
|
96
|
-
|
|
153
|
+
var _a;
|
|
154
|
+
return (_a = parsePhoneNumberFromString(str)) == null ? void 0 : _a.formatInternational().replace(/[^\d+]/g, "");
|
|
97
155
|
}
|
|
98
156
|
function normalizePhoneNumber(countryCode, number) {
|
|
99
157
|
return stringToPhoneNumber(`${countryCode[0] !== "+" ? "+" : ""}${countryCode}${number}`);
|
|
@@ -136,15 +194,17 @@ function getOnRampAssets(data, {
|
|
|
136
194
|
}
|
|
137
195
|
|
|
138
196
|
// src/utils/polling.ts
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
197
|
+
function waitUntilTrue(condition, timeoutMs, intervalMs) {
|
|
198
|
+
return __async(this, null, function* () {
|
|
199
|
+
const start = Date.now();
|
|
200
|
+
while (Date.now() - start < timeoutMs) {
|
|
201
|
+
if (yield condition()) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
yield new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
144
205
|
}
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
206
|
+
return false;
|
|
207
|
+
});
|
|
148
208
|
}
|
|
149
209
|
|
|
150
210
|
// src/types/config.ts
|
|
@@ -318,7 +378,10 @@ function isPregenIdentifierMatch(a, b, type) {
|
|
|
318
378
|
}
|
|
319
379
|
}
|
|
320
380
|
function isWalletSupported(types, wallet) {
|
|
321
|
-
return types.some((walletType) =>
|
|
381
|
+
return types.some((walletType) => {
|
|
382
|
+
var _a;
|
|
383
|
+
return !!((_a = WalletSchemeTypeMap[wallet == null ? void 0 : wallet.scheme]) == null ? void 0 : _a[walletType]);
|
|
384
|
+
});
|
|
322
385
|
}
|
|
323
386
|
function getSchemes(types) {
|
|
324
387
|
return Object.keys(WalletSchemeTypeMap).filter((scheme) => {
|
|
@@ -341,12 +404,11 @@ function getEquivalentTypes(types) {
|
|
|
341
404
|
return getWalletTypes(getSchemes((Array.isArray(types) ? types : [types]).map((t) => WalletType[t])));
|
|
342
405
|
}
|
|
343
406
|
function entityToWallet(w) {
|
|
344
|
-
return {
|
|
345
|
-
...w,
|
|
407
|
+
return __spreadProps(__spreadValues({}, w), {
|
|
346
408
|
scheme: w.scheme,
|
|
347
409
|
type: w.type,
|
|
348
410
|
pregenIdentifierType: w.pregenIdentifierType
|
|
349
|
-
};
|
|
411
|
+
});
|
|
350
412
|
}
|
|
351
413
|
function migrateWallet(obj) {
|
|
352
414
|
if (["USER", "PREGEN"].includes(obj.type)) {
|
|
@@ -388,79 +450,87 @@ function decodePrivateKeyPemHex(privateKeyPemHex) {
|
|
|
388
450
|
const pem = Buffer.from(privateKeyPemHex, "hex").toString("utf-8");
|
|
389
451
|
return forge.pki.privateKeyFromPem(pem);
|
|
390
452
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
453
|
+
function encryptPrivateKey(keyPair, key) {
|
|
454
|
+
return __async(this, null, function* () {
|
|
455
|
+
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
456
|
+
const cryptoKey = yield window.crypto.subtle.importKey(
|
|
457
|
+
"raw",
|
|
458
|
+
Buffer.from(key, "base64"),
|
|
459
|
+
{
|
|
460
|
+
name: "AES-GCM",
|
|
461
|
+
length: 256
|
|
462
|
+
},
|
|
463
|
+
true,
|
|
464
|
+
["encrypt", "decrypt"]
|
|
465
|
+
);
|
|
466
|
+
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
467
|
+
const ciphertext = yield window.crypto.subtle.encrypt(
|
|
468
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
469
|
+
cryptoKey,
|
|
470
|
+
encodedPlaintext
|
|
471
|
+
);
|
|
472
|
+
return Buffer.from(ciphertext).toString("base64");
|
|
473
|
+
});
|
|
410
474
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
475
|
+
function decryptPrivateKey(encryptedPrivateKeyPemHex, key) {
|
|
476
|
+
return __async(this, null, function* () {
|
|
477
|
+
const secretKey = yield crypto.subtle.importKey(
|
|
478
|
+
"raw",
|
|
479
|
+
Buffer.from(key, "base64"),
|
|
480
|
+
{
|
|
481
|
+
name: "AES-GCM",
|
|
482
|
+
length: 256
|
|
483
|
+
},
|
|
484
|
+
true,
|
|
485
|
+
["encrypt", "decrypt"]
|
|
486
|
+
);
|
|
487
|
+
const cleartext = yield crypto.subtle.decrypt(
|
|
488
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
489
|
+
secretKey,
|
|
490
|
+
Buffer.from(encryptedPrivateKeyPemHex, "base64")
|
|
491
|
+
);
|
|
492
|
+
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
493
|
+
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
494
|
+
return privateKey;
|
|
495
|
+
});
|
|
430
496
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
497
|
+
function getAsymmetricKeyPair(ctx, seedValue) {
|
|
498
|
+
return __async(this, null, function* () {
|
|
499
|
+
const prng = forge.random.createInstance();
|
|
500
|
+
if (seedValue) {
|
|
501
|
+
prng.seedFileSync = (_n) => seedValue;
|
|
502
|
+
prng.seedFile = (_n, cb) => {
|
|
503
|
+
cb(null, seedValue);
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
const options = {
|
|
507
|
+
bits: 2048,
|
|
508
|
+
e: 65537,
|
|
509
|
+
prng
|
|
437
510
|
};
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
reject(err);
|
|
455
|
-
}
|
|
456
|
-
resolve(keypair);
|
|
457
|
-
})
|
|
458
|
-
);
|
|
511
|
+
if (!ctx.disableWorkers) {
|
|
512
|
+
options.workLoad = 100;
|
|
513
|
+
options.workers = seedValue ? 1 : -1;
|
|
514
|
+
const workerRes = yield fetch(`${getPortalBaseURL(ctx)}/static/js/prime.worker.min.js`);
|
|
515
|
+
const workerBlob = new Blob([yield workerRes.text()], { type: "application/javascript" });
|
|
516
|
+
options.workerScript = URL.createObjectURL(workerBlob);
|
|
517
|
+
}
|
|
518
|
+
return new Promise(
|
|
519
|
+
(resolve, reject) => rsa.generateKeyPair(options, (err, keypair) => {
|
|
520
|
+
if (err) {
|
|
521
|
+
reject(err);
|
|
522
|
+
}
|
|
523
|
+
resolve(keypair);
|
|
524
|
+
})
|
|
525
|
+
);
|
|
526
|
+
});
|
|
459
527
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
528
|
+
function getPublicKeyFromSignature(ctx, userHandle) {
|
|
529
|
+
return __async(this, null, function* () {
|
|
530
|
+
const encodedUserHandle = base64url.encode(userHandle);
|
|
531
|
+
const keyPair = yield getAsymmetricKeyPair(ctx, encodedUserHandle);
|
|
532
|
+
return getPublicKeyHex(keyPair);
|
|
533
|
+
});
|
|
464
534
|
}
|
|
465
535
|
function symmetricKeyEncryptMessage(message) {
|
|
466
536
|
const key = forge.random.getBytesSync(16);
|
|
@@ -488,49 +558,57 @@ function decryptWithPrivateKey(privateKey, encryptedMessageHex, encryptedKeyHex)
|
|
|
488
558
|
const key = privateKey.decrypt(encryptedKey, RSA_ENCRYPTION_SCHEME);
|
|
489
559
|
return decipherEncryptedMessageHex(key, encryptedMessageHex);
|
|
490
560
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
561
|
+
function decryptWithDerivedPrivateKey(_0, _1) {
|
|
562
|
+
return __async(this, arguments, function* (ctx, {
|
|
563
|
+
seedValue,
|
|
564
|
+
encryptedMessageHex,
|
|
565
|
+
encryptedKeyHex
|
|
566
|
+
}) {
|
|
567
|
+
const keyPair = yield getAsymmetricKeyPair(ctx, seedValue);
|
|
568
|
+
return decryptWithPrivateKey(keyPair.privateKey, encryptedMessageHex, encryptedKeyHex);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
function getDerivedPrivateKeyAndDecrypt(ctx, seedValue, encryptedShares) {
|
|
572
|
+
return __async(this, null, function* () {
|
|
573
|
+
return Promise.all(
|
|
574
|
+
encryptedShares.map((share) => __async(this, null, function* () {
|
|
575
|
+
return {
|
|
576
|
+
walletId: share.walletId,
|
|
577
|
+
walletScheme: share.walletScheme,
|
|
578
|
+
partnerId: share.partnerId,
|
|
579
|
+
signer: yield decryptWithDerivedPrivateKey(ctx, {
|
|
580
|
+
seedValue,
|
|
581
|
+
encryptedMessageHex: share.encryptedShare,
|
|
582
|
+
encryptedKeyHex: share.encryptedKey
|
|
583
|
+
}),
|
|
584
|
+
protocolId: share.protocolId
|
|
585
|
+
};
|
|
586
|
+
}))
|
|
587
|
+
);
|
|
588
|
+
});
|
|
498
589
|
}
|
|
499
|
-
|
|
500
|
-
return
|
|
501
|
-
|
|
590
|
+
function decryptPrivateKeyAndDecryptShare(encryptionKey, encryptedShares, encryptedPrivateKey) {
|
|
591
|
+
return __async(this, null, function* () {
|
|
592
|
+
let privateKey;
|
|
593
|
+
try {
|
|
594
|
+
privateKey = yield decryptPrivateKey(encryptedPrivateKey, encryptionKey);
|
|
595
|
+
} catch (e) {
|
|
596
|
+
}
|
|
597
|
+
try {
|
|
598
|
+
privateKey = yield decryptPrivateKeyWithPassword(encryptedPrivateKey, encryptionKey);
|
|
599
|
+
} catch (e) {
|
|
600
|
+
}
|
|
601
|
+
if (!privateKey) {
|
|
602
|
+
throw new Error("Could not decrypt private key");
|
|
603
|
+
}
|
|
604
|
+
return encryptedShares.map((share) => ({
|
|
502
605
|
walletId: share.walletId,
|
|
503
606
|
walletScheme: share.walletScheme,
|
|
504
607
|
partnerId: share.partnerId,
|
|
505
|
-
signer:
|
|
506
|
-
seedValue,
|
|
507
|
-
encryptedMessageHex: share.encryptedShare,
|
|
508
|
-
encryptedKeyHex: share.encryptedKey
|
|
509
|
-
}),
|
|
608
|
+
signer: decryptWithPrivateKey(privateKey, share.encryptedShare, share.encryptedKey),
|
|
510
609
|
protocolId: share.protocolId
|
|
511
|
-
}))
|
|
512
|
-
);
|
|
513
|
-
}
|
|
514
|
-
async function decryptPrivateKeyAndDecryptShare(encryptionKey, encryptedShares, encryptedPrivateKey) {
|
|
515
|
-
let privateKey;
|
|
516
|
-
try {
|
|
517
|
-
privateKey = await decryptPrivateKey(encryptedPrivateKey, encryptionKey);
|
|
518
|
-
} catch (e) {
|
|
519
|
-
}
|
|
520
|
-
try {
|
|
521
|
-
privateKey = await decryptPrivateKeyWithPassword(encryptedPrivateKey, encryptionKey);
|
|
522
|
-
} catch (e) {
|
|
523
|
-
}
|
|
524
|
-
if (!privateKey) {
|
|
525
|
-
throw new Error("Could not decrypt private key");
|
|
526
|
-
}
|
|
527
|
-
return encryptedShares.map((share) => ({
|
|
528
|
-
walletId: share.walletId,
|
|
529
|
-
walletScheme: share.walletScheme,
|
|
530
|
-
partnerId: share.partnerId,
|
|
531
|
-
signer: decryptWithPrivateKey(privateKey, share.encryptedShare, share.encryptedKey),
|
|
532
|
-
protocolId: share.protocolId
|
|
533
|
-
}));
|
|
610
|
+
}));
|
|
611
|
+
});
|
|
534
612
|
}
|
|
535
613
|
function encryptWithDerivedPublicKey(publicKeyHex, message) {
|
|
536
614
|
const { key, encryptedMessageHex } = symmetricKeyEncryptMessage(message);
|
|
@@ -549,49 +627,55 @@ function hashPasswordWithSalt(password) {
|
|
|
549
627
|
function generateSalt(length = 16) {
|
|
550
628
|
return forge.util.bytesToHex(forge.random.getBytesSync(length));
|
|
551
629
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
630
|
+
function deriveCryptoKeyFromPassword(hashedPassword) {
|
|
631
|
+
return __async(this, null, function* () {
|
|
632
|
+
const keyBuffer = Buffer.from(hashedPassword, "hex");
|
|
633
|
+
return yield window.crypto.subtle.importKey(
|
|
634
|
+
"raw",
|
|
635
|
+
keyBuffer,
|
|
636
|
+
{
|
|
637
|
+
name: "AES-GCM",
|
|
638
|
+
length: 256
|
|
639
|
+
},
|
|
640
|
+
true,
|
|
641
|
+
["encrypt", "decrypt"]
|
|
642
|
+
);
|
|
643
|
+
});
|
|
564
644
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
645
|
+
function encryptPrivateKeyWithPassword(keyPair, hashedPassword) {
|
|
646
|
+
return __async(this, null, function* () {
|
|
647
|
+
const cryptoKey = yield deriveCryptoKeyFromPassword(hashedPassword);
|
|
648
|
+
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
649
|
+
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
650
|
+
const ciphertext = yield window.crypto.subtle.encrypt(
|
|
651
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
652
|
+
cryptoKey,
|
|
653
|
+
encodedPlaintext
|
|
654
|
+
);
|
|
655
|
+
return Buffer.from(ciphertext).toString("base64");
|
|
656
|
+
});
|
|
575
657
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
658
|
+
function decryptPrivateKeyWithPassword(encryptedPrivateKeyPemHex, hashedPassword) {
|
|
659
|
+
return __async(this, null, function* () {
|
|
660
|
+
const secretKey = yield crypto.subtle.importKey(
|
|
661
|
+
"raw",
|
|
662
|
+
Buffer.from(hashedPassword, "hex"),
|
|
663
|
+
{
|
|
664
|
+
name: "AES-GCM",
|
|
665
|
+
length: 256
|
|
666
|
+
},
|
|
667
|
+
true,
|
|
668
|
+
["encrypt", "decrypt"]
|
|
669
|
+
);
|
|
670
|
+
const cleartext = yield crypto.subtle.decrypt(
|
|
671
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
672
|
+
secretKey,
|
|
673
|
+
Buffer.from(encryptedPrivateKeyPemHex, "base64")
|
|
674
|
+
);
|
|
675
|
+
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
676
|
+
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
677
|
+
return privateKey;
|
|
678
|
+
});
|
|
595
679
|
}
|
|
596
680
|
|
|
597
681
|
// src/external/userManagementClient.ts
|
|
@@ -753,125 +837,126 @@ var KeyContainer = class _KeyContainer {
|
|
|
753
837
|
};
|
|
754
838
|
|
|
755
839
|
// src/shares/recovery.ts
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
walletId,
|
|
760
|
-
otherEncryptedShares = [],
|
|
761
|
-
userSigner,
|
|
762
|
-
ignoreRedistributingBackupEncryptedShare = false,
|
|
763
|
-
emailProps = {},
|
|
764
|
-
forceRefresh = false
|
|
765
|
-
}) {
|
|
766
|
-
if (ignoreRedistributingBackupEncryptedShare) {
|
|
767
|
-
await ctx.client.uploadUserKeyShares(
|
|
768
|
-
userId,
|
|
769
|
-
otherEncryptedShares.map((share) => ({
|
|
770
|
-
walletId,
|
|
771
|
-
...share
|
|
772
|
-
}))
|
|
773
|
-
);
|
|
774
|
-
return "";
|
|
775
|
-
}
|
|
776
|
-
let userBackupKeyShareOptsArr;
|
|
777
|
-
let recoveryPrivateKeyContainer;
|
|
778
|
-
const { recoveryPublicKeys } = await ctx.client.getRecoveryPublicKeys(userId);
|
|
779
|
-
if (forceRefresh || !recoveryPublicKeys?.length) {
|
|
780
|
-
recoveryPrivateKeyContainer = new KeyContainer(walletId, "", "");
|
|
781
|
-
const { recoveryPublicKeys: recoveryPublicKeys2 } = await ctx.client.persistRecoveryPublicKeys(userId, [
|
|
782
|
-
recoveryPrivateKeyContainer.getPublicEncryptionKeyHex()
|
|
783
|
-
]);
|
|
784
|
-
const encryptedUserBackup = recoveryPrivateKeyContainer.encryptForSelf(userSigner);
|
|
785
|
-
userBackupKeyShareOptsArr = [
|
|
786
|
-
{
|
|
787
|
-
walletId,
|
|
788
|
-
encryptedShare: encryptedUserBackup,
|
|
789
|
-
type: KeyShareType.USER,
|
|
790
|
-
encryptor: EncryptorType.RECOVERY,
|
|
791
|
-
recoveryPublicKeyId: recoveryPublicKeys2[0].id
|
|
792
|
-
}
|
|
793
|
-
];
|
|
794
|
-
} else {
|
|
795
|
-
userBackupKeyShareOptsArr = recoveryPublicKeys.map((recoveryPublicKey) => {
|
|
796
|
-
const { id: recoveryPublicKeyId, publicKey } = recoveryPublicKey;
|
|
797
|
-
const encryptedUserBackup = KeyContainer.encryptWithPublicKey(Buffer.from(publicKey, "hex"), userSigner);
|
|
798
|
-
return {
|
|
799
|
-
walletId,
|
|
800
|
-
encryptedShare: encryptedUserBackup,
|
|
801
|
-
type: KeyShareType.USER,
|
|
802
|
-
encryptor: EncryptorType.RECOVERY,
|
|
803
|
-
recoveryPublicKeyId
|
|
804
|
-
};
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
await ctx.client.uploadUserKeyShares(userId, [
|
|
808
|
-
...otherEncryptedShares.map((share) => ({
|
|
809
|
-
walletId,
|
|
810
|
-
...share
|
|
811
|
-
})),
|
|
812
|
-
...ignoreRedistributingBackupEncryptedShare ? [] : userBackupKeyShareOptsArr
|
|
813
|
-
]);
|
|
814
|
-
await ctx.client.distributeParaShare({
|
|
840
|
+
function sendRecoveryForShare(_0) {
|
|
841
|
+
return __async(this, arguments, function* ({
|
|
842
|
+
ctx,
|
|
815
843
|
userId,
|
|
816
844
|
walletId,
|
|
817
|
-
|
|
818
|
-
|
|
845
|
+
otherEncryptedShares = [],
|
|
846
|
+
userSigner,
|
|
847
|
+
ignoreRedistributingBackupEncryptedShare = false,
|
|
848
|
+
emailProps = {},
|
|
849
|
+
forceRefresh = false
|
|
850
|
+
}) {
|
|
851
|
+
if (ignoreRedistributingBackupEncryptedShare) {
|
|
852
|
+
yield ctx.client.uploadUserKeyShares(
|
|
853
|
+
userId,
|
|
854
|
+
otherEncryptedShares.map((share) => __spreadValues({
|
|
855
|
+
walletId
|
|
856
|
+
}, share))
|
|
857
|
+
);
|
|
858
|
+
return "";
|
|
859
|
+
}
|
|
860
|
+
let userBackupKeyShareOptsArr;
|
|
861
|
+
let recoveryPrivateKeyContainer;
|
|
862
|
+
const { recoveryPublicKeys } = yield ctx.client.getRecoveryPublicKeys(userId);
|
|
863
|
+
if (forceRefresh || !(recoveryPublicKeys == null ? void 0 : recoveryPublicKeys.length)) {
|
|
864
|
+
recoveryPrivateKeyContainer = new KeyContainer(walletId, "", "");
|
|
865
|
+
const { recoveryPublicKeys: recoveryPublicKeys2 } = yield ctx.client.persistRecoveryPublicKeys(userId, [
|
|
866
|
+
recoveryPrivateKeyContainer.getPublicEncryptionKeyHex()
|
|
867
|
+
]);
|
|
868
|
+
const encryptedUserBackup = recoveryPrivateKeyContainer.encryptForSelf(userSigner);
|
|
869
|
+
userBackupKeyShareOptsArr = [
|
|
870
|
+
{
|
|
871
|
+
walletId,
|
|
872
|
+
encryptedShare: encryptedUserBackup,
|
|
873
|
+
type: KeyShareType.USER,
|
|
874
|
+
encryptor: EncryptorType.RECOVERY,
|
|
875
|
+
recoveryPublicKeyId: recoveryPublicKeys2[0].id
|
|
876
|
+
}
|
|
877
|
+
];
|
|
878
|
+
} else {
|
|
879
|
+
userBackupKeyShareOptsArr = recoveryPublicKeys.map((recoveryPublicKey) => {
|
|
880
|
+
const { id: recoveryPublicKeyId, publicKey } = recoveryPublicKey;
|
|
881
|
+
const encryptedUserBackup = KeyContainer.encryptWithPublicKey(Buffer.from(publicKey, "hex"), userSigner);
|
|
882
|
+
return {
|
|
883
|
+
walletId,
|
|
884
|
+
encryptedShare: encryptedUserBackup,
|
|
885
|
+
type: KeyShareType.USER,
|
|
886
|
+
encryptor: EncryptorType.RECOVERY,
|
|
887
|
+
recoveryPublicKeyId
|
|
888
|
+
};
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
yield ctx.client.uploadUserKeyShares(userId, [
|
|
892
|
+
...otherEncryptedShares.map((share) => __spreadValues({
|
|
893
|
+
walletId
|
|
894
|
+
}, share)),
|
|
895
|
+
...ignoreRedistributingBackupEncryptedShare ? [] : userBackupKeyShareOptsArr
|
|
896
|
+
]);
|
|
897
|
+
yield ctx.client.distributeParaShare(__spreadValues({
|
|
898
|
+
userId,
|
|
899
|
+
walletId,
|
|
900
|
+
useDKLS: ctx.useDKLS
|
|
901
|
+
}, emailProps));
|
|
902
|
+
return recoveryPrivateKeyContainer ? JSON.stringify(recoveryPrivateKeyContainer) : "";
|
|
819
903
|
});
|
|
820
|
-
return recoveryPrivateKeyContainer ? JSON.stringify(recoveryPrivateKeyContainer) : "";
|
|
821
904
|
}
|
|
822
905
|
|
|
823
906
|
// src/shares/shareDistribution.ts
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
userId,
|
|
827
|
-
walletId,
|
|
828
|
-
userShare,
|
|
829
|
-
ignoreRedistributingBackupEncryptedShare = false,
|
|
830
|
-
emailProps = {},
|
|
831
|
-
partnerId,
|
|
832
|
-
protocolId
|
|
833
|
-
}) {
|
|
834
|
-
const publicKeysRes = await ctx.client.getSessionPublicKeys(userId);
|
|
835
|
-
const biometricEncryptedShares = publicKeysRes.data.keys.map((key) => {
|
|
836
|
-
if (!key.publicKey) {
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
const { encryptedMessageHex, encryptedKeyHex } = encryptWithDerivedPublicKey(key.sigDerivedPublicKey, userShare);
|
|
840
|
-
return {
|
|
841
|
-
encryptedShare: encryptedMessageHex,
|
|
842
|
-
encryptedKey: encryptedKeyHex,
|
|
843
|
-
type: KeyShareType2.USER,
|
|
844
|
-
encryptor: EncryptorType2.BIOMETRICS,
|
|
845
|
-
biometricPublicKey: key.sigDerivedPublicKey,
|
|
846
|
-
partnerId,
|
|
847
|
-
protocolId
|
|
848
|
-
};
|
|
849
|
-
}).filter(Boolean);
|
|
850
|
-
const passwords = await ctx.client.getPasswords({ userId });
|
|
851
|
-
const passwordEncryptedShares = passwords.map((password) => {
|
|
852
|
-
if (password.status === "PENDING") {
|
|
853
|
-
return;
|
|
854
|
-
}
|
|
855
|
-
const { encryptedMessageHex, encryptedKeyHex } = encryptWithDerivedPublicKey(password.sigDerivedPublicKey, userShare);
|
|
856
|
-
return {
|
|
857
|
-
encryptedShare: encryptedMessageHex,
|
|
858
|
-
encryptedKey: encryptedKeyHex,
|
|
859
|
-
type: KeyShareType2.USER,
|
|
860
|
-
encryptor: EncryptorType2.PASSWORD,
|
|
861
|
-
passwordId: password.id,
|
|
862
|
-
partnerId,
|
|
863
|
-
protocolId
|
|
864
|
-
};
|
|
865
|
-
}).filter(Boolean);
|
|
866
|
-
const allEncryptedShares = [...biometricEncryptedShares, ...passwordEncryptedShares];
|
|
867
|
-
return await sendRecoveryForShare({
|
|
907
|
+
function distributeNewShare(_0) {
|
|
908
|
+
return __async(this, arguments, function* ({
|
|
868
909
|
ctx,
|
|
869
910
|
userId,
|
|
870
911
|
walletId,
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
912
|
+
userShare,
|
|
913
|
+
ignoreRedistributingBackupEncryptedShare = false,
|
|
914
|
+
emailProps = {},
|
|
915
|
+
partnerId,
|
|
916
|
+
protocolId
|
|
917
|
+
}) {
|
|
918
|
+
const publicKeysRes = yield ctx.client.getSessionPublicKeys(userId);
|
|
919
|
+
const biometricEncryptedShares = publicKeysRes.data.keys.map((key) => {
|
|
920
|
+
if (!key.publicKey) {
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
const { encryptedMessageHex, encryptedKeyHex } = encryptWithDerivedPublicKey(key.sigDerivedPublicKey, userShare);
|
|
924
|
+
return {
|
|
925
|
+
encryptedShare: encryptedMessageHex,
|
|
926
|
+
encryptedKey: encryptedKeyHex,
|
|
927
|
+
type: KeyShareType2.USER,
|
|
928
|
+
encryptor: EncryptorType2.BIOMETRICS,
|
|
929
|
+
biometricPublicKey: key.sigDerivedPublicKey,
|
|
930
|
+
partnerId,
|
|
931
|
+
protocolId
|
|
932
|
+
};
|
|
933
|
+
}).filter(Boolean);
|
|
934
|
+
const passwords = yield ctx.client.getPasswords({ userId });
|
|
935
|
+
const passwordEncryptedShares = passwords.map((password) => {
|
|
936
|
+
if (password.status === "PENDING") {
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
const { encryptedMessageHex, encryptedKeyHex } = encryptWithDerivedPublicKey(password.sigDerivedPublicKey, userShare);
|
|
940
|
+
return {
|
|
941
|
+
encryptedShare: encryptedMessageHex,
|
|
942
|
+
encryptedKey: encryptedKeyHex,
|
|
943
|
+
type: KeyShareType2.USER,
|
|
944
|
+
encryptor: EncryptorType2.PASSWORD,
|
|
945
|
+
passwordId: password.id,
|
|
946
|
+
partnerId,
|
|
947
|
+
protocolId
|
|
948
|
+
};
|
|
949
|
+
}).filter(Boolean);
|
|
950
|
+
const allEncryptedShares = [...biometricEncryptedShares, ...passwordEncryptedShares];
|
|
951
|
+
return yield sendRecoveryForShare({
|
|
952
|
+
ctx,
|
|
953
|
+
userId,
|
|
954
|
+
walletId,
|
|
955
|
+
otherEncryptedShares: allEncryptedShares,
|
|
956
|
+
userSigner: userShare,
|
|
957
|
+
ignoreRedistributingBackupEncryptedShare,
|
|
958
|
+
emailProps
|
|
959
|
+
});
|
|
875
960
|
});
|
|
876
961
|
}
|
|
877
962
|
|
|
@@ -880,32 +965,36 @@ import { Encrypt as ECIESEncrypt2, Decrypt as ECIESDecrypt2 } from "@celo/utils/
|
|
|
880
965
|
import { Buffer as Buffer2 } from "buffer";
|
|
881
966
|
import * as eutil2 from "ethereumjs-util";
|
|
882
967
|
import { randomBytes } from "crypto";
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
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
|
+
}
|
|
893
980
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
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
|
+
});
|
|
901
988
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
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
|
+
});
|
|
909
998
|
}
|
|
910
999
|
|
|
911
1000
|
// src/errors.ts
|
|
@@ -932,7 +1021,7 @@ var TransactionReviewTimeout = class extends Error {
|
|
|
932
1021
|
};
|
|
933
1022
|
|
|
934
1023
|
// src/constants.ts
|
|
935
|
-
var PARA_CORE_VERSION = '1.
|
|
1024
|
+
var PARA_CORE_VERSION = '1.5.0';
|
|
936
1025
|
var PREFIX = "@CAPSULE/";
|
|
937
1026
|
var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
938
1027
|
var LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
|
|
@@ -944,7 +1033,6 @@ var LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
|
|
|
944
1033
|
var LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
|
|
945
1034
|
var LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
|
|
946
1035
|
var LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
|
|
947
|
-
var LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES = `${PREFIX}currentExternalWalletAddresses`;
|
|
948
1036
|
var LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
|
|
949
1037
|
var SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
|
|
950
1038
|
var POLLING_INTERVAL_MS = 2e3;
|
|
@@ -955,9 +1043,6 @@ function storageListener(e) {
|
|
|
955
1043
|
if (!e.url.includes(window.location.origin)) {
|
|
956
1044
|
return;
|
|
957
1045
|
}
|
|
958
|
-
if (e.key === LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES) {
|
|
959
|
-
this.updateCurrentExternalWalletAddressesFromStorage();
|
|
960
|
-
}
|
|
961
1046
|
if (e.key === LOCAL_STORAGE_EXTERNAL_WALLETS) {
|
|
962
1047
|
this.updateExternalWalletsFromStorage();
|
|
963
1048
|
}
|
|
@@ -1007,7 +1092,8 @@ if (typeof global !== "undefined") {
|
|
|
1007
1092
|
self.global = self.global || self;
|
|
1008
1093
|
}
|
|
1009
1094
|
var { pki, jsbn } = forge3;
|
|
1010
|
-
var
|
|
1095
|
+
var _supportedWalletTypes, _supportedWalletTypesOpt;
|
|
1096
|
+
var _ParaCore = class _ParaCore {
|
|
1011
1097
|
/**
|
|
1012
1098
|
* Constructs a new `ParaCore` instance.
|
|
1013
1099
|
* @param env - `Environment` to use.
|
|
@@ -1024,8 +1110,8 @@ var ParaCore = class _ParaCore {
|
|
|
1024
1110
|
* 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.
|
|
1025
1111
|
*/
|
|
1026
1112
|
this.currentWalletIds = {};
|
|
1027
|
-
this
|
|
1028
|
-
this
|
|
1113
|
+
__privateAdd(this, _supportedWalletTypes);
|
|
1114
|
+
__privateAdd(this, _supportedWalletTypesOpt);
|
|
1029
1115
|
this.localStorageGetItem = (key) => {
|
|
1030
1116
|
return this.platformUtils.localStorage.get(key);
|
|
1031
1117
|
};
|
|
@@ -1048,14 +1134,14 @@ var ParaCore = class _ParaCore {
|
|
|
1048
1134
|
* Remove all local storage and prefixed session storage.
|
|
1049
1135
|
* @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
|
|
1050
1136
|
*/
|
|
1051
|
-
this.clearStorage =
|
|
1137
|
+
this.clearStorage = (type = "all") => __async(this, null, function* () {
|
|
1052
1138
|
const isAll = type === "all";
|
|
1053
1139
|
(isAll || type === "local") && this.platformUtils.localStorage.clear(PREFIX);
|
|
1054
1140
|
(isAll || type === "session") && this.platformUtils.sessionStorage.clear(PREFIX);
|
|
1055
1141
|
if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
|
|
1056
1142
|
this.platformUtils.secureStorage.clear(PREFIX);
|
|
1057
1143
|
}
|
|
1058
|
-
};
|
|
1144
|
+
});
|
|
1059
1145
|
this.initializeFromStorage = () => {
|
|
1060
1146
|
this.updateEmailFromStorage();
|
|
1061
1147
|
this.updateCountryCodeFromStorage();
|
|
@@ -1067,7 +1153,6 @@ var ParaCore = class _ParaCore {
|
|
|
1067
1153
|
this.updateSessionCookieFromStorage();
|
|
1068
1154
|
this.updateLoginEncryptionKeyPairFromStorage();
|
|
1069
1155
|
this.updateExternalWalletsFromStorage();
|
|
1070
|
-
this.updateCurrentExternalWalletAddressesFromStorage();
|
|
1071
1156
|
};
|
|
1072
1157
|
this.updateTelegramUserIdFromStorage = () => {
|
|
1073
1158
|
this.telegramUserId = this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0;
|
|
@@ -1084,18 +1169,16 @@ var ParaCore = class _ParaCore {
|
|
|
1084
1169
|
this.updateEmailFromStorage = () => {
|
|
1085
1170
|
this.email = this.localStorageGetItem(LOCAL_STORAGE_EMAIL) || void 0;
|
|
1086
1171
|
};
|
|
1087
|
-
this.updateWalletsFromStorage =
|
|
1088
|
-
|
|
1172
|
+
this.updateWalletsFromStorage = () => __async(this, null, function* () {
|
|
1173
|
+
var _a;
|
|
1174
|
+
const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
1089
1175
|
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
1090
1176
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
1091
1177
|
return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
|
|
1092
1178
|
const wallet = Object.values(this.wallets).find(
|
|
1093
1179
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
1094
1180
|
);
|
|
1095
|
-
return {
|
|
1096
|
-
...acc,
|
|
1097
|
-
...wallet && !acc[type] ? { [type]: [wallet.id] } : {}
|
|
1098
|
-
};
|
|
1181
|
+
return __spreadValues(__spreadValues({}, acc), wallet && !acc[type] ? { [type]: [wallet.id] } : {});
|
|
1099
1182
|
}, {}) : fromJson;
|
|
1100
1183
|
})();
|
|
1101
1184
|
this.setCurrentWalletIds(currentWalletIds);
|
|
@@ -1103,34 +1186,25 @@ var ParaCore = class _ParaCore {
|
|
|
1103
1186
|
const _wallets = JSON.parse(stringWallets || "{}");
|
|
1104
1187
|
const stringEd25519Wallets = this.platformUtils.secureStorage ? this.platformUtils.secureStorage.get(LOCAL_STORAGE_ED25519_WALLETS) : this.localStorageGetItem(LOCAL_STORAGE_ED25519_WALLETS);
|
|
1105
1188
|
const _ed25519Wallets = JSON.parse(stringEd25519Wallets || "{}");
|
|
1106
|
-
const wallets = {
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
...Object.keys(_ed25519Wallets).reduce((res, key) => {
|
|
1114
|
-
return {
|
|
1115
|
-
...res,
|
|
1116
|
-
...!res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {}
|
|
1117
|
-
};
|
|
1118
|
-
}, {})
|
|
1119
|
-
};
|
|
1189
|
+
const wallets = __spreadValues(__spreadValues({}, Object.keys(_wallets).reduce((res, key) => {
|
|
1190
|
+
return __spreadProps(__spreadValues({}, res), {
|
|
1191
|
+
[key]: migrateWallet(_wallets[key])
|
|
1192
|
+
});
|
|
1193
|
+
}, {})), Object.keys(_ed25519Wallets).reduce((res, key) => {
|
|
1194
|
+
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
|
|
1195
|
+
}, {}));
|
|
1120
1196
|
this.setWallets(wallets);
|
|
1121
|
-
};
|
|
1197
|
+
});
|
|
1122
1198
|
this.updateWalletIdsFromStorage = () => {
|
|
1123
|
-
|
|
1199
|
+
var _a;
|
|
1200
|
+
const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
1124
1201
|
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
1125
1202
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
1126
1203
|
return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
|
|
1127
1204
|
const wallet = Object.values(this.wallets).find(
|
|
1128
1205
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
1129
1206
|
);
|
|
1130
|
-
return {
|
|
1131
|
-
...acc,
|
|
1132
|
-
...wallet && !acc[type] ? { [type]: [wallet.id] } : {}
|
|
1133
|
-
};
|
|
1207
|
+
return __spreadValues(__spreadValues({}, acc), wallet && !acc[type] ? { [type]: [wallet.id] } : {});
|
|
1134
1208
|
}, {}) : fromJson;
|
|
1135
1209
|
})();
|
|
1136
1210
|
this.setCurrentWalletIds(currentWalletIds);
|
|
@@ -1152,10 +1226,6 @@ var ParaCore = class _ParaCore {
|
|
|
1152
1226
|
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
1153
1227
|
this.setExternalWallets(_externalWallets);
|
|
1154
1228
|
};
|
|
1155
|
-
this.updateCurrentExternalWalletAddressesFromStorage = () => {
|
|
1156
|
-
const _currentExternalWalletAddresses = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES) || void 0;
|
|
1157
|
-
this.currentExternalWalletAddresses = _currentExternalWalletAddresses ? JSON.parse(_currentExternalWalletAddresses) : void 0;
|
|
1158
|
-
};
|
|
1159
1229
|
/**
|
|
1160
1230
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
1161
1231
|
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
@@ -1223,7 +1293,7 @@ var ParaCore = class _ParaCore {
|
|
|
1223
1293
|
this.ctx.mpcComputationClient = initClient2(opts.offloadMPCComputationURL, opts.disableWorkers);
|
|
1224
1294
|
}
|
|
1225
1295
|
try {
|
|
1226
|
-
this
|
|
1296
|
+
__privateSet(this, _supportedWalletTypes, opts.supportedWalletTypes ? (() => {
|
|
1227
1297
|
if (Object.values(opts.supportedWalletTypes).every(
|
|
1228
1298
|
(config) => !!config && typeof config === "object" && config.optional
|
|
1229
1299
|
)) {
|
|
@@ -1232,19 +1302,20 @@ var ParaCore = class _ParaCore {
|
|
|
1232
1302
|
if (!Object.keys(opts.supportedWalletTypes).every((type) => Object.values(WalletType2).includes(type))) {
|
|
1233
1303
|
throw new Error("unsupported wallet type");
|
|
1234
1304
|
}
|
|
1235
|
-
this
|
|
1305
|
+
__privateSet(this, _supportedWalletTypesOpt, opts.supportedWalletTypes);
|
|
1236
1306
|
return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
|
|
1307
|
+
var _a;
|
|
1237
1308
|
if (!value) {
|
|
1238
1309
|
return acc;
|
|
1239
1310
|
}
|
|
1240
1311
|
if (key === WalletType2.COSMOS && typeof value === "object" && !!value.prefix) {
|
|
1241
1312
|
this.cosmosPrefix = value.prefix;
|
|
1242
1313
|
}
|
|
1243
|
-
return [...acc, { type: key, optional: value === true ? false : value.optional
|
|
1314
|
+
return [...acc, { type: key, optional: value === true ? false : (_a = value.optional) != null ? _a : false }];
|
|
1244
1315
|
}, []);
|
|
1245
|
-
})() : void 0;
|
|
1316
|
+
})() : void 0);
|
|
1246
1317
|
} catch (e) {
|
|
1247
|
-
this
|
|
1318
|
+
__privateSet(this, _supportedWalletTypes, void 0);
|
|
1248
1319
|
}
|
|
1249
1320
|
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
1250
1321
|
return;
|
|
@@ -1252,9 +1323,6 @@ var ParaCore = class _ParaCore {
|
|
|
1252
1323
|
this.initializeFromStorage();
|
|
1253
1324
|
setupListeners.bind(this)();
|
|
1254
1325
|
}
|
|
1255
|
-
static {
|
|
1256
|
-
this.version = PARA_CORE_VERSION;
|
|
1257
|
-
}
|
|
1258
1326
|
get isEmail() {
|
|
1259
1327
|
return !!this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.telegramUserId;
|
|
1260
1328
|
}
|
|
@@ -1269,9 +1337,10 @@ var ParaCore = class _ParaCore {
|
|
|
1269
1337
|
}
|
|
1270
1338
|
get currentWalletIdsArray() {
|
|
1271
1339
|
return this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
1340
|
+
var _a;
|
|
1272
1341
|
return [
|
|
1273
1342
|
...acc,
|
|
1274
|
-
...(this.currentWalletIds[type]
|
|
1343
|
+
...((_a = this.currentWalletIds[type]) != null ? _a : []).map((id) => {
|
|
1275
1344
|
return [id, type];
|
|
1276
1345
|
})
|
|
1277
1346
|
];
|
|
@@ -1284,19 +1353,17 @@ var ParaCore = class _ParaCore {
|
|
|
1284
1353
|
* A map of pre-generated wallet identifiers that can be claimed in the current instance.
|
|
1285
1354
|
*/
|
|
1286
1355
|
get pregenIds() {
|
|
1287
|
-
return {
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
[wallet.pregenIdentifierType]: [
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
}, {})
|
|
1299
|
-
};
|
|
1356
|
+
return __spreadValues({}, Object.values(this.wallets).filter((wallet) => !this.userId || this.isPregenWalletClaimable(wallet)).reduce((acc, wallet) => {
|
|
1357
|
+
var _a, _b;
|
|
1358
|
+
if (((_a = acc[wallet.pregenIdentifierType]) != null ? _a : []).includes(wallet.pregenIdentifier)) {
|
|
1359
|
+
return acc;
|
|
1360
|
+
}
|
|
1361
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1362
|
+
[wallet.pregenIdentifierType]: [
|
|
1363
|
+
.../* @__PURE__ */ new Set([...(_b = acc[wallet.pregenIdentifierType]) != null ? _b : [], wallet.pregenIdentifier])
|
|
1364
|
+
]
|
|
1365
|
+
});
|
|
1366
|
+
}, {}));
|
|
1300
1367
|
}
|
|
1301
1368
|
/**
|
|
1302
1369
|
* Whether the instance has multiple wallets connected.
|
|
@@ -1304,14 +1371,13 @@ var ParaCore = class _ParaCore {
|
|
|
1304
1371
|
get isMultiWallet() {
|
|
1305
1372
|
return this.currentWalletIdsArray.length > 1;
|
|
1306
1373
|
}
|
|
1307
|
-
#supportedWalletTypes;
|
|
1308
|
-
#supportedWalletTypesOpt;
|
|
1309
1374
|
get supportedWalletTypes() {
|
|
1310
|
-
|
|
1375
|
+
var _a;
|
|
1376
|
+
return (_a = __privateGet(this, _supportedWalletTypes)) != null ? _a : [];
|
|
1311
1377
|
}
|
|
1312
1378
|
get isWalletTypeEnabled() {
|
|
1313
1379
|
return this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
1314
|
-
return {
|
|
1380
|
+
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
1315
1381
|
}, {});
|
|
1316
1382
|
}
|
|
1317
1383
|
convertBigInt(bigInt) {
|
|
@@ -1340,12 +1406,14 @@ var ParaCore = class _ParaCore {
|
|
|
1340
1406
|
};
|
|
1341
1407
|
}
|
|
1342
1408
|
isPortal(envOverride) {
|
|
1409
|
+
var _a;
|
|
1343
1410
|
if (typeof window === "undefined") return false;
|
|
1344
|
-
return !!window.location
|
|
1411
|
+
return !!((_a = window.location) == null ? void 0 : _a.host) && getPortalBaseURL(envOverride ? { env: envOverride } : this.ctx).includes(window.location.host);
|
|
1345
1412
|
}
|
|
1346
1413
|
isParaConnect() {
|
|
1414
|
+
var _a;
|
|
1347
1415
|
if (typeof window === "undefined") return false;
|
|
1348
|
-
return !!window.location
|
|
1416
|
+
return !!((_a = window.location) == null ? void 0 : _a.host) && getParaConnectBaseUrl(this.ctx).includes(window.location.host);
|
|
1349
1417
|
}
|
|
1350
1418
|
requireApiKey() {
|
|
1351
1419
|
if (!this.ctx.apiKey) {
|
|
@@ -1356,19 +1424,20 @@ var ParaCore = class _ParaCore {
|
|
|
1356
1424
|
}
|
|
1357
1425
|
}
|
|
1358
1426
|
isWalletSupported(wallet) {
|
|
1359
|
-
|
|
1427
|
+
var _a, _b;
|
|
1428
|
+
return !__privateGet(this, _supportedWalletTypes) || isWalletSupported((_b = (_a = this.supportedWalletTypes) == null ? void 0 : _a.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
1360
1429
|
}
|
|
1361
1430
|
isWalletOwned(wallet) {
|
|
1362
|
-
return this.isWalletSupported(wallet) && !wallet
|
|
1431
|
+
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;
|
|
1363
1432
|
}
|
|
1364
1433
|
isPregenWalletUnclaimed(wallet) {
|
|
1365
|
-
return this.isWalletSupported(wallet) && (!wallet
|
|
1434
|
+
return this.isWalletSupported(wallet) && (!(wallet == null ? void 0 : wallet.userId) || (wallet == null ? void 0 : wallet.isPregen) && !!(wallet == null ? void 0 : wallet.pregenIdentifier) && !!(wallet == null ? void 0 : wallet.pregenIdentifierType));
|
|
1366
1435
|
}
|
|
1367
1436
|
isPregenWalletClaimable(wallet) {
|
|
1368
|
-
return this.isWalletSupported(wallet) && this.isPregenWalletUnclaimed(wallet) && (!["EMAIL", "PHONE", "TELEGRAM"].includes(wallet
|
|
1369
|
-
wallet
|
|
1370
|
-
wallet
|
|
1371
|
-
wallet
|
|
1437
|
+
return this.isWalletSupported(wallet) && this.isPregenWalletUnclaimed(wallet) && (!["EMAIL", "PHONE", "TELEGRAM"].includes(wallet == null ? void 0 : wallet.pregenIdentifierType) || isPregenIdentifierMatch(
|
|
1438
|
+
(wallet == null ? void 0 : wallet.pregenIdentifierType) === "EMAIL" ? this.email : (wallet == null ? void 0 : wallet.pregenIdentifierType) === "TELEGRAM" ? this.telegramUserId : this.getPhoneNumber(),
|
|
1439
|
+
wallet == null ? void 0 : wallet.pregenIdentifier,
|
|
1440
|
+
wallet == null ? void 0 : wallet.pregenIdentifierType
|
|
1372
1441
|
));
|
|
1373
1442
|
}
|
|
1374
1443
|
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
@@ -1379,15 +1448,18 @@ var ParaCore = class _ParaCore {
|
|
|
1379
1448
|
const wallet = this.wallets[walletId];
|
|
1380
1449
|
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
1381
1450
|
if (forbidPregen && isUnclaimed) {
|
|
1382
|
-
error = `pre-generated wallet with id ${wallet
|
|
1451
|
+
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
1383
1452
|
} else if (!isOwned && !isUnclaimed) {
|
|
1384
|
-
error = `wallet with id ${wallet
|
|
1453
|
+
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
1385
1454
|
} else if (!this.isWalletSupported(wallet)) {
|
|
1386
|
-
error = `wallet with id ${wallet
|
|
1387
|
-
} else if (types && (!getEquivalentTypes(types).includes(wallet
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1455
|
+
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} is not supported, supported types are: ${this.supportedWalletTypes.map(({ type }) => type).join(", ")}`;
|
|
1456
|
+
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
1457
|
+
var _a, _b;
|
|
1458
|
+
return (_b = (_a = this.currentWalletIds) == null ? void 0 : _a[type]) == null ? void 0 : _b.includes(walletId);
|
|
1459
|
+
}))) {
|
|
1460
|
+
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
|
|
1461
|
+
} else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
|
|
1462
|
+
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and scheme ${wallet == null ? void 0 : wallet.scheme} cannot be selected`;
|
|
1391
1463
|
}
|
|
1392
1464
|
}
|
|
1393
1465
|
if (error) {
|
|
@@ -1407,6 +1479,7 @@ var ParaCore = class _ParaCore {
|
|
|
1407
1479
|
* @returns the formatted address
|
|
1408
1480
|
*/
|
|
1409
1481
|
getDisplayAddress(walletId, options = {}) {
|
|
1482
|
+
var _a;
|
|
1410
1483
|
if (this.externalWallets[walletId]) {
|
|
1411
1484
|
const wallet2 = this.externalWallets[walletId];
|
|
1412
1485
|
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix }) : wallet2.address;
|
|
@@ -1418,7 +1491,7 @@ var ParaCore = class _ParaCore {
|
|
|
1418
1491
|
let str;
|
|
1419
1492
|
switch (wallet.type) {
|
|
1420
1493
|
case WalletType2.COSMOS:
|
|
1421
|
-
str = getCosmosAddress(wallet.publicKey, this.cosmosPrefix
|
|
1494
|
+
str = getCosmosAddress(wallet.publicKey, (_a = this.cosmosPrefix) != null ? _a : "cosmos");
|
|
1422
1495
|
break;
|
|
1423
1496
|
default:
|
|
1424
1497
|
str = wallet.address;
|
|
@@ -1444,89 +1517,87 @@ var ParaCore = class _ParaCore {
|
|
|
1444
1517
|
return this.wallets;
|
|
1445
1518
|
}
|
|
1446
1519
|
getAddress(walletId) {
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1520
|
+
var _a, _b, _c;
|
|
1521
|
+
return walletId ? (_a = this.wallets[walletId]) == null ? void 0 : _a.address : (_c = (_b = Object.values(this.wallets)) == null ? void 0 : _b[0]) == null ? void 0 : _c.address;
|
|
1522
|
+
}
|
|
1523
|
+
constructPortalUrl(_0) {
|
|
1524
|
+
return __async(this, arguments, function* (type, opts = {}) {
|
|
1525
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1526
|
+
const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL(opts.partnerId);
|
|
1527
|
+
let path;
|
|
1528
|
+
switch (type) {
|
|
1529
|
+
case "createPassword": {
|
|
1530
|
+
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
1531
|
+
break;
|
|
1532
|
+
}
|
|
1533
|
+
case "createAuth": {
|
|
1534
|
+
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
1535
|
+
break;
|
|
1536
|
+
}
|
|
1537
|
+
case "loginPassword": {
|
|
1538
|
+
path = "/web/passwords/login";
|
|
1539
|
+
break;
|
|
1540
|
+
}
|
|
1541
|
+
case "loginAuth": {
|
|
1542
|
+
path = "/web/biometrics/login";
|
|
1543
|
+
break;
|
|
1544
|
+
}
|
|
1545
|
+
case "txReview": {
|
|
1546
|
+
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
1547
|
+
break;
|
|
1548
|
+
}
|
|
1549
|
+
case "onRamp": {
|
|
1550
|
+
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
1551
|
+
break;
|
|
1552
|
+
}
|
|
1553
|
+
default: {
|
|
1554
|
+
throw new Error(`invalid URL type ${type}`);
|
|
1555
|
+
}
|
|
1479
1556
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
...isCreate || isLogin ? {
|
|
1502
|
-
...opts.authType === "email" ? { email: this.email } : {},
|
|
1503
|
-
...opts.authType === "phone" ? { phone: this.phone, countryCode: this.countryCode } : {},
|
|
1504
|
-
...opts.authType === "farcaster" ? { farcasterUsername: this.farcasterUsername } : {},
|
|
1505
|
-
...opts.authType === "telegram" ? { telegramUserId: this.telegramUserId } : {}
|
|
1506
|
-
} : {},
|
|
1507
|
-
...isLogin || isOnRamp ? { sessionId: opts.sessionId } : {},
|
|
1508
|
-
...isLogin ? {
|
|
1557
|
+
const [isCreate, isLogin, isOnRamp] = [
|
|
1558
|
+
["createAuth", "createPassword"].includes(type),
|
|
1559
|
+
["loginAuth", "loginPassword"].includes(type),
|
|
1560
|
+
type === "onRamp"
|
|
1561
|
+
];
|
|
1562
|
+
const partner = opts.partnerId ? (_a = (yield this.ctx.client.getPartner(opts.partnerId)).data) == null ? void 0 : _a.partner : void 0;
|
|
1563
|
+
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
1564
|
+
apiKey: this.ctx.apiKey,
|
|
1565
|
+
partnerId: opts.partnerId,
|
|
1566
|
+
portalFont: ((_b = opts.theme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
|
|
1567
|
+
portalBorderRadius: ((_d = opts.theme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
|
|
1568
|
+
portalThemeMode: ((_f = opts.theme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
|
|
1569
|
+
portalAccentColor: ((_h = opts.theme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
|
|
1570
|
+
portalForegroundColor: ((_j = opts.theme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
|
|
1571
|
+
portalBackgroundColor: ((_l = opts.theme) == null ? void 0 : _l.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_m = this.portalTheme) == null ? void 0 : _m.backgroundColor),
|
|
1572
|
+
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
1573
|
+
portalTextColor: this.portalTextColor,
|
|
1574
|
+
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
1575
|
+
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0,
|
|
1576
|
+
supportedWalletTypes: __privateGet(this, _supportedWalletTypesOpt) ? JSON.stringify(__privateGet(this, _supportedWalletTypesOpt)) : void 0
|
|
1577
|
+
}, isCreate || isLogin ? __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, opts.authType === "email" ? { email: this.email } : {}), opts.authType === "phone" ? { phone: this.phone, countryCode: this.countryCode } : {}), opts.authType === "farcaster" ? { farcasterUsername: this.farcasterUsername } : {}), opts.authType === "telegram" ? { telegramUserId: this.telegramUserId } : {}) : {}), isLogin || isOnRamp ? { sessionId: opts.sessionId } : {}), isLogin ? {
|
|
1509
1578
|
encryptionKey: opts.loginEncryptionPublicKey,
|
|
1510
1579
|
newDeviceSessionLookupId: opts.newDeviceSessionId,
|
|
1511
1580
|
newDeviceEncryptionKey: opts.newDeviceEncryptionKey,
|
|
1512
1581
|
pregenIds: JSON.stringify(this.pregenIds),
|
|
1513
1582
|
displayName: opts.displayName,
|
|
1514
1583
|
pfpUrl: opts.pfpUrl
|
|
1515
|
-
} : {},
|
|
1516
|
-
|
|
1517
|
-
};
|
|
1518
|
-
return constructUrl({ base, path, params });
|
|
1584
|
+
} : {}), opts.params || {});
|
|
1585
|
+
return constructUrl({ base, path, params });
|
|
1586
|
+
});
|
|
1519
1587
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1588
|
+
touchSession(regenerate = false) {
|
|
1589
|
+
return __async(this, null, function* () {
|
|
1590
|
+
const res = yield this.ctx.client.touchSession(regenerate);
|
|
1591
|
+
this.setSupportedWalletTypes(res.data.supportedWalletTypes, res.data.cosmosPrefix);
|
|
1592
|
+
return res;
|
|
1593
|
+
});
|
|
1524
1594
|
}
|
|
1525
1595
|
setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
|
|
1526
|
-
if (supportedWalletTypes && !this
|
|
1527
|
-
this
|
|
1596
|
+
if (supportedWalletTypes && !__privateGet(this, _supportedWalletTypes)) {
|
|
1597
|
+
__privateSet(this, _supportedWalletTypes, supportedWalletTypes);
|
|
1528
1598
|
Object.keys(this.currentWalletIds).forEach((type) => {
|
|
1529
|
-
|
|
1599
|
+
var _a;
|
|
1600
|
+
if (!((_a = __privateGet(this, _supportedWalletTypes)) == null ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
|
|
1530
1601
|
delete this.currentWalletIds[type];
|
|
1531
1602
|
}
|
|
1532
1603
|
});
|
|
@@ -1562,166 +1633,168 @@ var ParaCore = class _ParaCore {
|
|
|
1562
1633
|
*
|
|
1563
1634
|
* Init only needs to be called for storage that is async.
|
|
1564
1635
|
*/
|
|
1565
|
-
|
|
1566
|
-
this
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1636
|
+
init() {
|
|
1637
|
+
return __async(this, null, function* () {
|
|
1638
|
+
var _a;
|
|
1639
|
+
this.email = (yield this.localStorageGetItem(LOCAL_STORAGE_EMAIL)) || void 0;
|
|
1640
|
+
this.countryCode = (yield this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE)) || void 0;
|
|
1641
|
+
this.phone = (yield this.localStorageGetItem(LOCAL_STORAGE_PHONE)) || void 0;
|
|
1642
|
+
this.userId = (yield this.localStorageGetItem(LOCAL_STORAGE_USER_ID)) || void 0;
|
|
1643
|
+
this.telegramUserId = (yield this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0;
|
|
1644
|
+
const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_WALLETS);
|
|
1645
|
+
const _wallets = JSON.parse(stringWallets || "{}");
|
|
1646
|
+
const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_ED25519_WALLETS);
|
|
1647
|
+
const _ed25519Wallets = JSON.parse(stringEd25519Wallets || "{}");
|
|
1648
|
+
const wallets = __spreadValues(__spreadValues({}, Object.keys(_wallets).reduce((res, key) => {
|
|
1649
|
+
return __spreadProps(__spreadValues({}, res), {
|
|
1579
1650
|
[key]: migrateWallet(_wallets[key])
|
|
1580
|
-
};
|
|
1581
|
-
}, {}),
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
this.
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
1611
|
-
}
|
|
1612
|
-
const stringExternalWallets = await this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
1613
|
-
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
1614
|
-
await this.setExternalWallets(_externalWallets);
|
|
1615
|
-
const _currentExternalWalletAddresses = await this.localStorageGetItem(LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES) || void 0;
|
|
1616
|
-
this.currentExternalWalletAddresses = _currentExternalWalletAddresses ? JSON.parse(_currentExternalWalletAddresses) : void 0;
|
|
1617
|
-
setupListeners.bind(this)();
|
|
1618
|
-
await this.touchSession();
|
|
1651
|
+
});
|
|
1652
|
+
}, {})), Object.keys(_ed25519Wallets).reduce((res, key) => {
|
|
1653
|
+
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
|
|
1654
|
+
}, {}));
|
|
1655
|
+
yield this.setWallets(wallets);
|
|
1656
|
+
const _currentWalletIds = (_a = yield this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
1657
|
+
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
1658
|
+
const fromJson = JSON.parse(_currentWalletIds);
|
|
1659
|
+
return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
|
|
1660
|
+
const wallet = Object.values(this.wallets).find(
|
|
1661
|
+
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
1662
|
+
);
|
|
1663
|
+
return __spreadValues(__spreadValues({}, acc), wallet && !acc[type] ? { [type]: [wallet.id] } : {});
|
|
1664
|
+
}, {}) : fromJson;
|
|
1665
|
+
})();
|
|
1666
|
+
yield this.setCurrentWalletIds(currentWalletIds);
|
|
1667
|
+
this.sessionCookie = (yield this.localStorageGetItem(LOCAL_STORAGE_SESSION_COOKIE)) || (yield this.sessionStorageGetItem(LOCAL_STORAGE_SESSION_COOKIE)) || void 0;
|
|
1668
|
+
if (Object.values(this.wallets).filter((w) => this.isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
1669
|
+
this.findWalletId(void 0, { forbidPregen: true });
|
|
1670
|
+
}
|
|
1671
|
+
const loginEncryptionKey = yield this.sessionStorageGetItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
1672
|
+
if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
|
|
1673
|
+
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
1674
|
+
}
|
|
1675
|
+
const stringExternalWallets = yield this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
1676
|
+
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
1677
|
+
yield this.setExternalWallets(_externalWallets);
|
|
1678
|
+
setupListeners.bind(this)();
|
|
1679
|
+
yield this.touchSession();
|
|
1680
|
+
});
|
|
1619
1681
|
}
|
|
1620
1682
|
/**
|
|
1621
1683
|
* Sets the email associated with the `ParaCore` instance.
|
|
1622
1684
|
* @param email - Email to set.
|
|
1623
1685
|
*/
|
|
1624
|
-
|
|
1625
|
-
this
|
|
1626
|
-
|
|
1686
|
+
setEmail(email) {
|
|
1687
|
+
return __async(this, null, function* () {
|
|
1688
|
+
this.email = email;
|
|
1689
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_EMAIL, email);
|
|
1690
|
+
});
|
|
1627
1691
|
}
|
|
1628
1692
|
/**
|
|
1629
1693
|
* Sets the Telegram user ID associated with the `ParaCore` instance.
|
|
1630
1694
|
* @param telegramUserId - Telegram user ID to set.
|
|
1631
1695
|
*/
|
|
1632
|
-
|
|
1633
|
-
this
|
|
1634
|
-
|
|
1696
|
+
setTelegramUserId(telegramUserId) {
|
|
1697
|
+
return __async(this, null, function* () {
|
|
1698
|
+
this.telegramUserId = telegramUserId;
|
|
1699
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
|
|
1700
|
+
});
|
|
1635
1701
|
}
|
|
1636
1702
|
/**
|
|
1637
1703
|
* Sets the phone number associated with the `ParaCore` instance.
|
|
1638
1704
|
* @param phone - Phone number to set.
|
|
1639
1705
|
* @param countryCode - Country Code to set.
|
|
1640
1706
|
*/
|
|
1641
|
-
|
|
1642
|
-
this
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1707
|
+
setPhoneNumber(phone, countryCode) {
|
|
1708
|
+
return __async(this, null, function* () {
|
|
1709
|
+
this.phone = phone;
|
|
1710
|
+
this.countryCode = countryCode;
|
|
1711
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_PHONE, phone);
|
|
1712
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_COUNTRY_CODE, countryCode);
|
|
1713
|
+
});
|
|
1646
1714
|
}
|
|
1647
1715
|
/**
|
|
1648
1716
|
* Sets the farcaster username associated with the `ParaCore` instance.
|
|
1649
1717
|
* @param farcasterUsername - Farcaster Username to set.
|
|
1650
1718
|
*/
|
|
1651
|
-
|
|
1652
|
-
this
|
|
1653
|
-
|
|
1719
|
+
setFarcasterUsername(farcasterUsername) {
|
|
1720
|
+
return __async(this, null, function* () {
|
|
1721
|
+
this.farcasterUsername = farcasterUsername;
|
|
1722
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
|
|
1723
|
+
});
|
|
1654
1724
|
}
|
|
1655
1725
|
/**
|
|
1656
1726
|
* Sets the external wallet address and type associated with the `ParaCore` instance.
|
|
1657
1727
|
* @param externalAddress - External wallet address to set.
|
|
1658
1728
|
* @param externalType - Type of external wallet to set.
|
|
1659
1729
|
*/
|
|
1660
|
-
|
|
1661
|
-
this
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1730
|
+
setExternalWallet(_0) {
|
|
1731
|
+
return __async(this, arguments, function* ({ address, type, provider, addressBech32 }) {
|
|
1732
|
+
this.externalWallets = {
|
|
1733
|
+
[address]: {
|
|
1734
|
+
id: address,
|
|
1735
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
1736
|
+
type,
|
|
1737
|
+
name: provider,
|
|
1738
|
+
isExternal: true,
|
|
1739
|
+
signer: ""
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
this.setExternalWallets(this.externalWallets);
|
|
1743
|
+
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1744
|
+
});
|
|
1675
1745
|
}
|
|
1676
1746
|
/**
|
|
1677
1747
|
* Sets the user id associated with the `ParaCore` instance.
|
|
1678
1748
|
* @param userId - User id to set.
|
|
1679
1749
|
*/
|
|
1680
|
-
|
|
1681
|
-
this
|
|
1682
|
-
|
|
1750
|
+
setUserId(userId) {
|
|
1751
|
+
return __async(this, null, function* () {
|
|
1752
|
+
this.userId = userId;
|
|
1753
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_USER_ID, userId);
|
|
1754
|
+
});
|
|
1683
1755
|
}
|
|
1684
1756
|
/**
|
|
1685
1757
|
* Sets the wallets associated with the `ParaCore` instance.
|
|
1686
1758
|
* @param wallets - Wallets to set.
|
|
1687
1759
|
*/
|
|
1688
|
-
|
|
1689
|
-
this
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1760
|
+
setWallets(wallets) {
|
|
1761
|
+
return __async(this, null, function* () {
|
|
1762
|
+
this.wallets = wallets;
|
|
1763
|
+
if (this.platformUtils.secureStorage) {
|
|
1764
|
+
yield this.platformUtils.secureStorage.set(LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1768
|
+
});
|
|
1695
1769
|
}
|
|
1696
1770
|
/**
|
|
1697
1771
|
* Sets the external wallets associated with the `ParaCore` instance.
|
|
1698
1772
|
* @param externalWallets - External wallets to set.
|
|
1699
1773
|
*/
|
|
1700
|
-
|
|
1701
|
-
this
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
this.currentExternalWalletAddresses = currentExternalWalletAddresses;
|
|
1706
|
-
await this.localStorageSetItem(
|
|
1707
|
-
LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES,
|
|
1708
|
-
JSON.stringify(currentExternalWalletAddresses)
|
|
1709
|
-
);
|
|
1774
|
+
setExternalWallets(externalWallets) {
|
|
1775
|
+
return __async(this, null, function* () {
|
|
1776
|
+
this.externalWallets = externalWallets;
|
|
1777
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_EXTERNAL_WALLETS, JSON.stringify(externalWallets));
|
|
1778
|
+
});
|
|
1710
1779
|
}
|
|
1711
1780
|
/**
|
|
1712
1781
|
* Sets the login encryption key pair associated with the `ParaCore` instance.
|
|
1713
1782
|
* @param keyPair - Encryption key pair generated from loginEncryptionKey.
|
|
1714
1783
|
*/
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1784
|
+
setLoginEncryptionKeyPair(keyPair) {
|
|
1785
|
+
return __async(this, null, function* () {
|
|
1786
|
+
if (!keyPair) {
|
|
1787
|
+
keyPair = yield getAsymmetricKeyPair(this.ctx);
|
|
1788
|
+
}
|
|
1789
|
+
this.loginEncryptionKeyPair = keyPair;
|
|
1790
|
+
yield this.sessionStorageSetItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR, JSON.stringify(keyPair));
|
|
1791
|
+
});
|
|
1721
1792
|
}
|
|
1722
|
-
|
|
1723
|
-
this
|
|
1724
|
-
|
|
1793
|
+
deleteLoginEncryptionKeyPair() {
|
|
1794
|
+
return __async(this, null, function* () {
|
|
1795
|
+
this.loginEncryptionKeyPair = void 0;
|
|
1796
|
+
yield this.sessionStorageRemoveItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
1797
|
+
});
|
|
1725
1798
|
}
|
|
1726
1799
|
/**
|
|
1727
1800
|
* Gets the userId associated with the `ParaCore` instance.
|
|
@@ -1761,23 +1834,25 @@ var ParaCore = class _ParaCore {
|
|
|
1761
1834
|
getFarcasterUsername() {
|
|
1762
1835
|
return this.farcasterUsername;
|
|
1763
1836
|
}
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
this.
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1837
|
+
setCurrentWalletIds(_0) {
|
|
1838
|
+
return __async(this, arguments, function* (currentWalletIds, {
|
|
1839
|
+
needsWallet = false,
|
|
1840
|
+
sessionLookupId,
|
|
1841
|
+
newDeviceSessionLookupId
|
|
1842
|
+
} = {}) {
|
|
1843
|
+
this.currentWalletIds = currentWalletIds;
|
|
1844
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS, JSON.stringify(this.currentWalletIds));
|
|
1845
|
+
if (sessionLookupId) {
|
|
1846
|
+
yield this.ctx.client.setCurrentWalletIds(
|
|
1847
|
+
this.getUserId(),
|
|
1848
|
+
this.currentWalletIds,
|
|
1849
|
+
needsWallet,
|
|
1850
|
+
sessionLookupId,
|
|
1851
|
+
newDeviceSessionLookupId
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
dispatchEvent(ParaEvent.WALLETS_CHANGE_EVENT, null);
|
|
1855
|
+
});
|
|
1781
1856
|
}
|
|
1782
1857
|
/**
|
|
1783
1858
|
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
@@ -1831,6 +1906,7 @@ var ParaCore = class _ParaCore {
|
|
|
1831
1906
|
return wallet;
|
|
1832
1907
|
}
|
|
1833
1908
|
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
1909
|
+
var _b, _c;
|
|
1834
1910
|
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
1835
1911
|
return Object.values(this.externalWallets)[0];
|
|
1836
1912
|
}
|
|
@@ -1840,18 +1916,18 @@ var ParaCore = class _ParaCore {
|
|
|
1840
1916
|
try {
|
|
1841
1917
|
const walletId = this.findWalletId(idOrAddress, filter);
|
|
1842
1918
|
if (walletId && !!this.wallets[walletId]) {
|
|
1843
|
-
const { signer: _signer,
|
|
1844
|
-
const type = overrideType
|
|
1845
|
-
return {
|
|
1846
|
-
...wallet,
|
|
1919
|
+
const _a = this.wallets[walletId], { signer: _signer } = _a, wallet = __objRest(_a, ["signer"]);
|
|
1920
|
+
const type = (_c = overrideType != null ? overrideType : (_b = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _b[1]) != null ? _c : wallet.type;
|
|
1921
|
+
return __spreadProps(__spreadValues({}, wallet), {
|
|
1847
1922
|
type: WalletType2[type]
|
|
1848
|
-
};
|
|
1923
|
+
});
|
|
1849
1924
|
}
|
|
1850
1925
|
} catch (e) {
|
|
1851
1926
|
return void 0;
|
|
1852
1927
|
}
|
|
1853
1928
|
}
|
|
1854
1929
|
get availableWallets() {
|
|
1930
|
+
var _a;
|
|
1855
1931
|
return [
|
|
1856
1932
|
...this.currentWalletIdsArray.map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1857
1933
|
const wallet = this.findWallet(id, type);
|
|
@@ -1863,7 +1939,7 @@ var ParaCore = class _ParaCore {
|
|
|
1863
1939
|
name: wallet.name
|
|
1864
1940
|
};
|
|
1865
1941
|
}).filter((obj) => obj !== null),
|
|
1866
|
-
...Object.values(this.externalWallets
|
|
1942
|
+
...Object.values((_a = this.externalWallets) != null ? _a : {})
|
|
1867
1943
|
];
|
|
1868
1944
|
}
|
|
1869
1945
|
/**
|
|
@@ -1877,61 +1953,78 @@ var ParaCore = class _ParaCore {
|
|
|
1877
1953
|
assertIsValidWalletId(walletId, condition = {}) {
|
|
1878
1954
|
this.isWalletUsable(walletId, condition, true);
|
|
1879
1955
|
}
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1956
|
+
assertIsValidWalletType(type, walletTypes) {
|
|
1957
|
+
return __async(this, null, function* () {
|
|
1958
|
+
if (!__privateGet(this, _supportedWalletTypes)) {
|
|
1959
|
+
yield this.touchSession();
|
|
1960
|
+
}
|
|
1961
|
+
if (!type || !Object.values(WalletType2).includes(type) || !(walletTypes != null ? walletTypes : this.supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
1962
|
+
throw new Error(`wallet type ${type} is not supported`);
|
|
1963
|
+
}
|
|
1964
|
+
return type;
|
|
1965
|
+
});
|
|
1888
1966
|
}
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1967
|
+
getMissingTypes() {
|
|
1968
|
+
return __async(this, null, function* () {
|
|
1969
|
+
if (!__privateGet(this, _supportedWalletTypes)) {
|
|
1970
|
+
yield this.touchSession();
|
|
1971
|
+
}
|
|
1972
|
+
return this.supportedWalletTypes.filter(
|
|
1973
|
+
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
|
|
1974
|
+
).map(({ type }) => type);
|
|
1975
|
+
});
|
|
1896
1976
|
}
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
return getSchemes(types ?? await this.getMissingTypes()).map((scheme) => {
|
|
1902
|
-
switch (scheme) {
|
|
1903
|
-
case WalletScheme2.ED25519:
|
|
1904
|
-
return WalletType2.SOLANA;
|
|
1905
|
-
default:
|
|
1906
|
-
return this.supportedWalletTypes.some(({ type, optional }) => type === WalletType2.COSMOS && !optional) ? WalletType2.COSMOS : WalletType2.EVM;
|
|
1977
|
+
getTypesToCreate(types) {
|
|
1978
|
+
return __async(this, null, function* () {
|
|
1979
|
+
if (!__privateGet(this, _supportedWalletTypes)) {
|
|
1980
|
+
yield this.touchSession();
|
|
1907
1981
|
}
|
|
1982
|
+
return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
1983
|
+
switch (scheme) {
|
|
1984
|
+
case WalletScheme2.ED25519:
|
|
1985
|
+
return WalletType2.SOLANA;
|
|
1986
|
+
default:
|
|
1987
|
+
return this.supportedWalletTypes.some(({ type, optional }) => type === WalletType2.COSMOS && !optional) ? WalletType2.COSMOS : WalletType2.EVM;
|
|
1988
|
+
}
|
|
1989
|
+
});
|
|
1908
1990
|
});
|
|
1909
1991
|
}
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1992
|
+
getPartnerURL(partnerId) {
|
|
1993
|
+
return __async(this, null, function* () {
|
|
1994
|
+
const res = yield this.ctx.client.getPartner(partnerId);
|
|
1995
|
+
return res.data.partner.portalUrl;
|
|
1996
|
+
});
|
|
1913
1997
|
}
|
|
1914
1998
|
/**
|
|
1915
1999
|
* URL of the portal, which can be associated with a partner id
|
|
1916
2000
|
* @param partnerId: string - id of the partner to get the portal URL for
|
|
1917
2001
|
* @returns - portal URL
|
|
1918
2002
|
*/
|
|
1919
|
-
|
|
1920
|
-
return
|
|
2003
|
+
getPortalURL(partnerId) {
|
|
2004
|
+
return __async(this, null, function* () {
|
|
2005
|
+
return partnerId && (yield this.getPartnerURL(partnerId)) || getPortalBaseURL(this.ctx);
|
|
2006
|
+
});
|
|
1921
2007
|
}
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
2008
|
+
getWebAuthURLForCreate(_a) {
|
|
2009
|
+
return __async(this, null, function* () {
|
|
2010
|
+
var _b = _a, {
|
|
2011
|
+
webAuthId
|
|
2012
|
+
} = _b, options = __objRest(_b, [
|
|
2013
|
+
"webAuthId"
|
|
2014
|
+
]);
|
|
2015
|
+
return this.constructPortalUrl("createAuth", __spreadProps(__spreadValues({}, options), { pathId: webAuthId }));
|
|
2016
|
+
});
|
|
1927
2017
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
2018
|
+
getPasswordURLForCreate(_c) {
|
|
2019
|
+
return __async(this, null, function* () {
|
|
2020
|
+
var _d = _c, {
|
|
2021
|
+
passwordId
|
|
2022
|
+
} = _d, options = __objRest(_d, [
|
|
2023
|
+
"passwordId"
|
|
2024
|
+
]);
|
|
2025
|
+
return this.constructPortalUrl("createPassword", __spreadProps(__spreadValues({}, options), {
|
|
2026
|
+
pathId: passwordId
|
|
2027
|
+
}));
|
|
1935
2028
|
});
|
|
1936
2029
|
}
|
|
1937
2030
|
getShortUrl(compressedUrl) {
|
|
@@ -1940,35 +2033,42 @@ var ParaCore = class _ParaCore {
|
|
|
1940
2033
|
path: `/short/${compressedUrl}`
|
|
1941
2034
|
});
|
|
1942
2035
|
}
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
2036
|
+
shortenLoginLink(link) {
|
|
2037
|
+
return __async(this, null, function* () {
|
|
2038
|
+
const url = yield upload(link, this.ctx.client);
|
|
2039
|
+
return this.getShortUrl(url);
|
|
2040
|
+
});
|
|
1946
2041
|
}
|
|
1947
2042
|
/**
|
|
1948
2043
|
* Generates a URL for registering a new WebAuth passkey.
|
|
1949
2044
|
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1950
2045
|
* @returns - the URL for creating a new passkey
|
|
1951
2046
|
*/
|
|
1952
|
-
|
|
1953
|
-
return this
|
|
2047
|
+
getWebAuthURLForLogin(opts) {
|
|
2048
|
+
return __async(this, null, function* () {
|
|
2049
|
+
return this.constructPortalUrl("loginAuth", opts);
|
|
2050
|
+
});
|
|
1954
2051
|
}
|
|
1955
2052
|
/**
|
|
1956
2053
|
* Generates a URL for registering a new user password.
|
|
1957
2054
|
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1958
2055
|
* @returns - the URL for creating a new password
|
|
1959
2056
|
*/
|
|
1960
|
-
|
|
1961
|
-
return this
|
|
2057
|
+
getPasswordURLForLogin(opts) {
|
|
2058
|
+
return __async(this, null, function* () {
|
|
2059
|
+
return this.constructPortalUrl("loginPassword", opts);
|
|
2060
|
+
});
|
|
1962
2061
|
}
|
|
1963
2062
|
/**
|
|
1964
2063
|
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
1965
2064
|
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
1966
2065
|
* @returns - web auth url
|
|
1967
2066
|
*/
|
|
1968
|
-
|
|
1969
|
-
return this
|
|
1970
|
-
|
|
1971
|
-
|
|
2067
|
+
getWebAuthURLForLoginForPhone(opts) {
|
|
2068
|
+
return __async(this, null, function* () {
|
|
2069
|
+
return this.constructPortalUrl("loginAuth", __spreadValues({
|
|
2070
|
+
authType: "phone"
|
|
2071
|
+
}, opts));
|
|
1972
2072
|
});
|
|
1973
2073
|
}
|
|
1974
2074
|
/**
|
|
@@ -1976,57 +2076,59 @@ var ParaCore = class _ParaCore {
|
|
|
1976
2076
|
* @param {string } [walletId] id of the wallet to get the private key for. Will default to the first wallet if not provided.
|
|
1977
2077
|
* @returns - the private key string.
|
|
1978
2078
|
*/
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
this.
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
2079
|
+
getPrivateKey(walletId) {
|
|
2080
|
+
return __async(this, null, function* () {
|
|
2081
|
+
const wallets = Object.values(this.wallets);
|
|
2082
|
+
const wallet = walletId ? this.wallets[walletId] : wallets == null ? void 0 : wallets[0];
|
|
2083
|
+
if (!wallet) {
|
|
2084
|
+
throw new Error("wallet not found");
|
|
2085
|
+
}
|
|
2086
|
+
if (wallet.scheme !== WalletScheme2.DKLS) {
|
|
2087
|
+
throw new Error("invalid wallet scheme");
|
|
2088
|
+
}
|
|
2089
|
+
return yield this.platformUtils.getPrivateKey(
|
|
2090
|
+
this.ctx,
|
|
2091
|
+
this.userId,
|
|
2092
|
+
wallet.id,
|
|
2093
|
+
wallet.signer,
|
|
2094
|
+
this.retrieveSessionCookie()
|
|
2095
|
+
);
|
|
2096
|
+
});
|
|
1995
2097
|
}
|
|
1996
2098
|
/**
|
|
1997
2099
|
* Fetches the wallets associated with the user.
|
|
1998
2100
|
* @returns {WalletEntity[]} wallets that were fetched.
|
|
1999
2101
|
*/
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2102
|
+
fetchWallets() {
|
|
2103
|
+
return __async(this, null, function* () {
|
|
2104
|
+
const res = yield this.isPortal() || this.isParaConnect() ? this.ctx.client.getAllWallets(this.userId) : this.ctx.client.getWallets(this.userId, true);
|
|
2105
|
+
return res.data.wallets.filter(
|
|
2106
|
+
(wallet) => !!wallet.address && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported(entityToWallet(wallet)))
|
|
2107
|
+
);
|
|
2108
|
+
});
|
|
2005
2109
|
}
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
this.wallets[entity.id]
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2110
|
+
populateWalletAddresses() {
|
|
2111
|
+
return __async(this, null, function* () {
|
|
2112
|
+
const res = yield this.ctx.client.getWallets(this.userId, true);
|
|
2113
|
+
const wallets = res.data.wallets;
|
|
2114
|
+
wallets.forEach((entity) => {
|
|
2115
|
+
if (this.wallets[entity.id]) {
|
|
2116
|
+
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
2117
|
+
}
|
|
2118
|
+
});
|
|
2119
|
+
yield this.setWallets(this.wallets);
|
|
2016
2120
|
});
|
|
2017
|
-
await this.setWallets(this.wallets);
|
|
2018
2121
|
}
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
this.wallets[entity.id]
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2122
|
+
populatePregenWalletAddresses() {
|
|
2123
|
+
return __async(this, null, function* () {
|
|
2124
|
+
const res = yield this.getPregenWallets();
|
|
2125
|
+
res.forEach((entity) => {
|
|
2126
|
+
if (this.wallets[entity.id]) {
|
|
2127
|
+
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
2128
|
+
}
|
|
2129
|
+
});
|
|
2130
|
+
yield this.setWallets(this.wallets);
|
|
2028
2131
|
});
|
|
2029
|
-
await this.setWallets(this.wallets);
|
|
2030
2132
|
}
|
|
2031
2133
|
/**
|
|
2032
2134
|
* Checks if a user exists for an email address.
|
|
@@ -2034,9 +2136,11 @@ var ParaCore = class _ParaCore {
|
|
|
2034
2136
|
* @param {string} opts.email the email to check.
|
|
2035
2137
|
* @returns true if user exists, false otherwise.
|
|
2036
2138
|
*/
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2139
|
+
checkIfUserExists(_0) {
|
|
2140
|
+
return __async(this, arguments, function* ({ email }) {
|
|
2141
|
+
const res = yield this.ctx.client.checkUserExists({ email });
|
|
2142
|
+
return res.data.exists;
|
|
2143
|
+
});
|
|
2040
2144
|
}
|
|
2041
2145
|
/**
|
|
2042
2146
|
* Checks if a user exists for a phone number.
|
|
@@ -2045,23 +2149,26 @@ var ParaCore = class _ParaCore {
|
|
|
2045
2149
|
* @param {string} opts.countryCode - the country code.
|
|
2046
2150
|
* @returns true if user exists, false otherwise.
|
|
2047
2151
|
*/
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2152
|
+
checkIfUserExistsByPhone(_0) {
|
|
2153
|
+
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
2154
|
+
const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
|
|
2155
|
+
return res.data.exists;
|
|
2156
|
+
});
|
|
2051
2157
|
}
|
|
2052
2158
|
/**
|
|
2053
2159
|
* Creates a new user.
|
|
2054
2160
|
* @param {Object} opts the options object
|
|
2055
2161
|
* @param {string} opts.email the email to use.
|
|
2056
2162
|
*/
|
|
2057
|
-
|
|
2058
|
-
this
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2163
|
+
createUser(_0) {
|
|
2164
|
+
return __async(this, arguments, function* ({ email }) {
|
|
2165
|
+
this.requireApiKey();
|
|
2166
|
+
yield this.setEmail(email);
|
|
2167
|
+
const { userId } = yield this.ctx.client.createUser(__spreadValues({
|
|
2168
|
+
email: this.email
|
|
2169
|
+
}, this.getVerificationEmailProps()));
|
|
2170
|
+
yield this.setUserId(userId);
|
|
2063
2171
|
});
|
|
2064
|
-
await this.setUserId(userId);
|
|
2065
2172
|
}
|
|
2066
2173
|
/**
|
|
2067
2174
|
* Creates a new user with a phone number.
|
|
@@ -2069,14 +2176,16 @@ var ParaCore = class _ParaCore {
|
|
|
2069
2176
|
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
2070
2177
|
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
2071
2178
|
*/
|
|
2072
|
-
|
|
2073
|
-
this
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2179
|
+
createUserByPhone(_0) {
|
|
2180
|
+
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
2181
|
+
this.requireApiKey();
|
|
2182
|
+
yield this.setPhoneNumber(phone, countryCode);
|
|
2183
|
+
const { userId } = yield this.ctx.client.createUser({
|
|
2184
|
+
phone: this.phone,
|
|
2185
|
+
countryCode: this.countryCode
|
|
2186
|
+
});
|
|
2187
|
+
yield this.setUserId(userId);
|
|
2078
2188
|
});
|
|
2079
|
-
await this.setUserId(userId);
|
|
2080
2189
|
}
|
|
2081
2190
|
/**
|
|
2082
2191
|
* Logs in or creates a new user using an external wallet address.
|
|
@@ -2085,17 +2194,19 @@ var ParaCore = class _ParaCore {
|
|
|
2085
2194
|
* @param {WalletType} opts.type type of external wallet to use for identification.
|
|
2086
2195
|
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
2087
2196
|
*/
|
|
2088
|
-
|
|
2089
|
-
this
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2197
|
+
externalWalletLogin(wallet) {
|
|
2198
|
+
return __async(this, null, function* () {
|
|
2199
|
+
this.requireApiKey();
|
|
2200
|
+
const res = yield this.ctx.client.externalWalletLogin({
|
|
2201
|
+
externalAddress: wallet.address,
|
|
2202
|
+
type: wallet.type,
|
|
2203
|
+
externalWalletProvider: wallet.provider,
|
|
2204
|
+
shouldTrackUser: wallet.shouldTrackUser
|
|
2205
|
+
});
|
|
2206
|
+
yield this.setExternalWallet(wallet);
|
|
2207
|
+
yield this.setUserId(res.userId);
|
|
2208
|
+
return res;
|
|
2209
|
+
});
|
|
2099
2210
|
}
|
|
2100
2211
|
/**
|
|
2101
2212
|
* Returns whether or not the user is connected with an external wallet.
|
|
@@ -2109,18 +2220,22 @@ var ParaCore = class _ParaCore {
|
|
|
2109
2220
|
* @param {string} verificationCode the six-digit code to check
|
|
2110
2221
|
* @returns {string} the web auth url for creating a new credential
|
|
2111
2222
|
*/
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2223
|
+
verifyEmail(_0) {
|
|
2224
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2225
|
+
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
2226
|
+
return this.getSetUpBiometricsURL();
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
verifyExternalWallet(_0) {
|
|
2230
|
+
return __async(this, arguments, function* ({
|
|
2231
|
+
address,
|
|
2232
|
+
signedMessage,
|
|
2233
|
+
cosmosPublicKeyHex,
|
|
2234
|
+
cosmosSigner
|
|
2235
|
+
}) {
|
|
2236
|
+
yield this.ctx.client.verifyExternalWallet(this.userId, { address, signedMessage, cosmosPublicKeyHex, cosmosSigner });
|
|
2237
|
+
return this.getSetUpBiometricsURL();
|
|
2238
|
+
});
|
|
2124
2239
|
}
|
|
2125
2240
|
/**
|
|
2126
2241
|
* Passes the phone code obtained from the user for verification.
|
|
@@ -2128,9 +2243,11 @@ var ParaCore = class _ParaCore {
|
|
|
2128
2243
|
* @param {string} verificationCode the six-digit code to check
|
|
2129
2244
|
* @returns {string} the web auth url for creating a new credential
|
|
2130
2245
|
*/
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2246
|
+
verifyPhone(_0) {
|
|
2247
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2248
|
+
yield this.ctx.client.verifyPhone(this.userId, { verificationCode });
|
|
2249
|
+
return this.getSetUpBiometricsURLForPhone();
|
|
2250
|
+
});
|
|
2134
2251
|
}
|
|
2135
2252
|
/**
|
|
2136
2253
|
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
@@ -2138,17 +2255,19 @@ var ParaCore = class _ParaCore {
|
|
|
2138
2255
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
2139
2256
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
2140
2257
|
*/
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2258
|
+
verifyTelegram(authObject) {
|
|
2259
|
+
return __async(this, null, function* () {
|
|
2260
|
+
const res = yield this.ctx.client.verifyTelegram(authObject);
|
|
2261
|
+
if (res.isValid) {
|
|
2262
|
+
yield this.setUserId(res.userId);
|
|
2263
|
+
yield this.setTelegramUserId(res.telegramUserId);
|
|
2264
|
+
yield this.touchSession(true);
|
|
2265
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2266
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2267
|
+
}
|
|
2149
2268
|
}
|
|
2150
|
-
|
|
2151
|
-
|
|
2269
|
+
return res;
|
|
2270
|
+
});
|
|
2152
2271
|
}
|
|
2153
2272
|
/**
|
|
2154
2273
|
* Performs 2FA verification.
|
|
@@ -2157,14 +2276,16 @@ var ParaCore = class _ParaCore {
|
|
|
2157
2276
|
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
2158
2277
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
2159
2278
|
*/
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2279
|
+
verify2FA(_0) {
|
|
2280
|
+
return __async(this, arguments, function* ({ email, verificationCode }) {
|
|
2281
|
+
const res = yield this.ctx.client.verify2FA(email, verificationCode);
|
|
2282
|
+
return {
|
|
2283
|
+
initiatedAt: res.data.initiatedAt,
|
|
2284
|
+
status: res.data.status,
|
|
2285
|
+
userId: res.data.userId,
|
|
2286
|
+
wallets: res.data.wallets
|
|
2287
|
+
};
|
|
2288
|
+
});
|
|
2168
2289
|
}
|
|
2169
2290
|
/**
|
|
2170
2291
|
* Performs 2FA verification.
|
|
@@ -2174,65 +2295,76 @@ var ParaCore = class _ParaCore {
|
|
|
2174
2295
|
* @param {string} opts.verificationCode - verification code to received via 2FA.
|
|
2175
2296
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
2176
2297
|
*/
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2298
|
+
verify2FAForPhone(_0) {
|
|
2299
|
+
return __async(this, arguments, function* ({
|
|
2300
|
+
phone,
|
|
2301
|
+
countryCode,
|
|
2302
|
+
verificationCode
|
|
2303
|
+
}) {
|
|
2304
|
+
const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
|
|
2305
|
+
return {
|
|
2306
|
+
initiatedAt: res.data.initiatedAt,
|
|
2307
|
+
status: res.data.status,
|
|
2308
|
+
userId: res.data.userId,
|
|
2309
|
+
wallets: res.data.wallets
|
|
2310
|
+
};
|
|
2311
|
+
});
|
|
2189
2312
|
}
|
|
2190
2313
|
/**
|
|
2191
2314
|
* Sets up two-factor authentication for the current user.
|
|
2192
2315
|
* @returns {string} uri - uri to use for setting up 2FA
|
|
2193
2316
|
* */
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2317
|
+
setup2FA() {
|
|
2318
|
+
return __async(this, null, function* () {
|
|
2319
|
+
const res = yield this.ctx.client.setup2FA(this.userId);
|
|
2320
|
+
return {
|
|
2321
|
+
uri: res.data.uri
|
|
2322
|
+
};
|
|
2323
|
+
});
|
|
2199
2324
|
}
|
|
2200
2325
|
/**
|
|
2201
2326
|
* Enables 2FA.
|
|
2202
2327
|
* @param {Object} opts the options object
|
|
2203
2328
|
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
2204
2329
|
*/
|
|
2205
|
-
|
|
2206
|
-
|
|
2330
|
+
enable2FA(_0) {
|
|
2331
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2332
|
+
yield this.ctx.client.enable2FA(this.userId, verificationCode);
|
|
2333
|
+
});
|
|
2207
2334
|
}
|
|
2208
2335
|
/**
|
|
2209
2336
|
* Determines if 2FA has been set up.
|
|
2210
2337
|
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
2211
2338
|
*/
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2339
|
+
check2FAStatus() {
|
|
2340
|
+
return __async(this, null, function* () {
|
|
2341
|
+
if (!this.userId) {
|
|
2342
|
+
return { isSetup: false };
|
|
2343
|
+
}
|
|
2344
|
+
const res = yield this.ctx.client.check2FAStatus(this.userId);
|
|
2345
|
+
return {
|
|
2346
|
+
isSetup: res.data.isSetup
|
|
2347
|
+
};
|
|
2348
|
+
});
|
|
2220
2349
|
}
|
|
2221
2350
|
/**
|
|
2222
2351
|
* Resend a verification email for the current user.
|
|
2223
2352
|
*/
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2353
|
+
resendVerificationCode() {
|
|
2354
|
+
return __async(this, null, function* () {
|
|
2355
|
+
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
2356
|
+
userId: this.userId
|
|
2357
|
+
}, this.getVerificationEmailProps()));
|
|
2228
2358
|
});
|
|
2229
2359
|
}
|
|
2230
2360
|
/**
|
|
2231
2361
|
* Resend a verification SMS for the current user.
|
|
2232
2362
|
*/
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2363
|
+
resendVerificationCodeByPhone() {
|
|
2364
|
+
return __async(this, null, function* () {
|
|
2365
|
+
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
2366
|
+
userId: this.userId
|
|
2367
|
+
});
|
|
2236
2368
|
});
|
|
2237
2369
|
}
|
|
2238
2370
|
/**
|
|
@@ -2242,19 +2374,21 @@ var ParaCore = class _ParaCore {
|
|
|
2242
2374
|
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2243
2375
|
* @returns {string} the URL
|
|
2244
2376
|
*/
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2377
|
+
getSetUpBiometricsURL() {
|
|
2378
|
+
return __async(this, arguments, function* ({
|
|
2379
|
+
authType = "email",
|
|
2380
|
+
isForNewDevice = false
|
|
2381
|
+
} = {}) {
|
|
2382
|
+
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2383
|
+
status: PublicKeyStatus.PENDING,
|
|
2384
|
+
type: PublicKeyType.WEB
|
|
2385
|
+
});
|
|
2386
|
+
return this.getWebAuthURLForCreate({
|
|
2387
|
+
authType,
|
|
2388
|
+
isForNewDevice,
|
|
2389
|
+
webAuthId: res.data.id,
|
|
2390
|
+
partnerId: res.data.partnerId
|
|
2391
|
+
});
|
|
2258
2392
|
});
|
|
2259
2393
|
}
|
|
2260
2394
|
/**
|
|
@@ -2263,18 +2397,20 @@ var ParaCore = class _ParaCore {
|
|
|
2263
2397
|
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2264
2398
|
* @returns {string} the URL
|
|
2265
2399
|
*/
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2400
|
+
getSetUpBiometricsURLForPhone() {
|
|
2401
|
+
return __async(this, arguments, function* ({
|
|
2402
|
+
isForNewDevice = false
|
|
2403
|
+
} = {}) {
|
|
2404
|
+
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2405
|
+
status: PublicKeyStatus.PENDING,
|
|
2406
|
+
type: PublicKeyType.WEB
|
|
2407
|
+
});
|
|
2408
|
+
return this.getWebAuthURLForCreate({
|
|
2409
|
+
authType: "phone",
|
|
2410
|
+
isForNewDevice,
|
|
2411
|
+
webAuthId: res.data.id,
|
|
2412
|
+
partnerId: res.data.partnerId
|
|
2413
|
+
});
|
|
2278
2414
|
});
|
|
2279
2415
|
}
|
|
2280
2416
|
/**
|
|
@@ -2285,95 +2421,107 @@ var ParaCore = class _ParaCore {
|
|
|
2285
2421
|
* @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
|
|
2286
2422
|
* @returns {string} the URL
|
|
2287
2423
|
*/
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
} = {}) {
|
|
2293
|
-
const res = await this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
2294
|
-
status: PasswordStatus.PENDING
|
|
2295
|
-
});
|
|
2296
|
-
return this.getPasswordURLForCreate({
|
|
2297
|
-
authType,
|
|
2298
|
-
isForNewDevice,
|
|
2299
|
-
passwordId: res.data.id,
|
|
2300
|
-
partnerId: res.data.partnerId,
|
|
2424
|
+
getSetupPasswordURL() {
|
|
2425
|
+
return __async(this, arguments, function* ({
|
|
2426
|
+
authType = "email",
|
|
2427
|
+
isForNewDevice = false,
|
|
2301
2428
|
theme
|
|
2429
|
+
} = {}) {
|
|
2430
|
+
const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
2431
|
+
status: PasswordStatus.PENDING
|
|
2432
|
+
});
|
|
2433
|
+
return this.getPasswordURLForCreate({
|
|
2434
|
+
authType,
|
|
2435
|
+
isForNewDevice,
|
|
2436
|
+
passwordId: res.data.id,
|
|
2437
|
+
partnerId: res.data.partnerId,
|
|
2438
|
+
theme
|
|
2439
|
+
});
|
|
2302
2440
|
});
|
|
2303
2441
|
}
|
|
2304
2442
|
/**
|
|
2305
2443
|
* Checks if the current session is active.
|
|
2306
2444
|
* @returns `true` if active, `false` otherwise
|
|
2307
2445
|
*/
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2446
|
+
isSessionActive() {
|
|
2447
|
+
return __async(this, null, function* () {
|
|
2448
|
+
if (this.isUsingExternalWallet()) {
|
|
2449
|
+
return true;
|
|
2450
|
+
}
|
|
2451
|
+
const res = yield this.touchSession();
|
|
2452
|
+
return !!res.data.isAuthenticated;
|
|
2453
|
+
});
|
|
2314
2454
|
}
|
|
2315
2455
|
/**
|
|
2316
2456
|
* Checks if a session is active and a wallet exists.
|
|
2317
2457
|
* @returns `true` if active, `false` otherwise
|
|
2318
2458
|
**/
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2459
|
+
isFullyLoggedIn() {
|
|
2460
|
+
return __async(this, null, function* () {
|
|
2461
|
+
if (this.isUsingExternalWallet()) {
|
|
2462
|
+
return true;
|
|
2463
|
+
}
|
|
2464
|
+
const isSessionActive = yield this.isSessionActive();
|
|
2465
|
+
return isSessionActive && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true);
|
|
2466
|
+
});
|
|
2325
2467
|
}
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2468
|
+
supportedAuthMethods(auth) {
|
|
2469
|
+
return __async(this, null, function* () {
|
|
2470
|
+
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
2471
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
2472
|
+
for (const type of supportedAuthMethods) {
|
|
2473
|
+
switch (type) {
|
|
2474
|
+
case "PASSWORD":
|
|
2475
|
+
authMethods.add(AuthMethod.PASSWORD);
|
|
2476
|
+
break;
|
|
2477
|
+
case "BIOMETRIC":
|
|
2478
|
+
authMethods.add(AuthMethod.PASSKEY);
|
|
2479
|
+
break;
|
|
2480
|
+
}
|
|
2337
2481
|
}
|
|
2338
|
-
|
|
2339
|
-
|
|
2482
|
+
return authMethods;
|
|
2483
|
+
});
|
|
2340
2484
|
}
|
|
2341
2485
|
/**
|
|
2342
2486
|
* Get hints associated with the users stored biometrics.
|
|
2343
2487
|
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
2344
2488
|
*/
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2489
|
+
getUserBiometricLocationHints() {
|
|
2490
|
+
return __async(this, null, function* () {
|
|
2491
|
+
if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId) {
|
|
2492
|
+
throw new Error("one of email, phone or farcaster username are required to get biometric location hints");
|
|
2493
|
+
}
|
|
2494
|
+
return yield this.ctx.client.getBiometricLocationHints({
|
|
2495
|
+
email: this.email,
|
|
2496
|
+
phone: this.phone,
|
|
2497
|
+
countryCode: this.countryCode,
|
|
2498
|
+
farcasterUsername: this.farcasterUsername,
|
|
2499
|
+
telegramUserId: this.telegramUserId
|
|
2500
|
+
});
|
|
2355
2501
|
});
|
|
2356
2502
|
}
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2503
|
+
setAuth(auth) {
|
|
2504
|
+
return __async(this, null, function* () {
|
|
2505
|
+
const authInfo = extractAuthInfo(auth);
|
|
2506
|
+
if (!authInfo) {
|
|
2507
|
+
return void 0;
|
|
2508
|
+
}
|
|
2509
|
+
switch (authInfo.authType) {
|
|
2510
|
+
case "email":
|
|
2511
|
+
yield this.setEmail(authInfo.identifier);
|
|
2512
|
+
break;
|
|
2513
|
+
case "phone":
|
|
2514
|
+
yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
|
|
2515
|
+
break;
|
|
2516
|
+
case "farcaster":
|
|
2517
|
+
yield this.setFarcasterUsername(authInfo.identifier);
|
|
2518
|
+
break;
|
|
2519
|
+
case "telegram":
|
|
2520
|
+
yield this.setTelegramUserId(authInfo.identifier);
|
|
2521
|
+
break;
|
|
2522
|
+
}
|
|
2523
|
+
return authInfo;
|
|
2524
|
+
});
|
|
2377
2525
|
}
|
|
2378
2526
|
/**
|
|
2379
2527
|
* Initiates a login.
|
|
@@ -2382,41 +2530,46 @@ var ParaCore = class _ParaCore {
|
|
|
2382
2530
|
* @param {boolean} opts.useShortURL - whether to shorten the link
|
|
2383
2531
|
* @returns - the WebAuth URL for logging in
|
|
2384
2532
|
**/
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2533
|
+
initiateUserLogin(_e) {
|
|
2534
|
+
return __async(this, null, function* () {
|
|
2535
|
+
var _f = _e, { useShortUrl = false } = _f, auth = __objRest(_f, ["useShortUrl"]);
|
|
2536
|
+
const authInfo = yield this.setAuth(auth);
|
|
2537
|
+
if (!authInfo) {
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2540
|
+
const res = yield this.touchSession(true);
|
|
2541
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2542
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2543
|
+
}
|
|
2544
|
+
const webAuthLoginURL = yield this.getWebAuthURLForLogin({
|
|
2545
|
+
authType: authInfo.authType,
|
|
2546
|
+
sessionId: res.data.sessionId,
|
|
2547
|
+
partnerId: res.data.partnerId,
|
|
2548
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
2549
|
+
});
|
|
2550
|
+
if (!useShortUrl) {
|
|
2551
|
+
return webAuthLoginURL;
|
|
2552
|
+
}
|
|
2553
|
+
return this.shortenLoginLink(webAuthLoginURL);
|
|
2554
|
+
});
|
|
2404
2555
|
}
|
|
2405
2556
|
/**
|
|
2406
2557
|
* Initiates a login.
|
|
2407
2558
|
* @param email - the email to login with
|
|
2408
2559
|
* @returns - a set of supported auth methods for the user
|
|
2409
2560
|
**/
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2561
|
+
initiateUserLoginV2(auth) {
|
|
2562
|
+
return __async(this, null, function* () {
|
|
2563
|
+
const authInfo = yield this.setAuth(auth);
|
|
2564
|
+
if (!authInfo) {
|
|
2565
|
+
return;
|
|
2566
|
+
}
|
|
2567
|
+
yield this.touchSession(true);
|
|
2568
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2569
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2570
|
+
}
|
|
2571
|
+
return yield this.supportedAuthMethods(authInfo.auth);
|
|
2572
|
+
});
|
|
2420
2573
|
}
|
|
2421
2574
|
/**
|
|
2422
2575
|
* Initiates a login.
|
|
@@ -2426,113 +2579,124 @@ var ParaCore = class _ParaCore {
|
|
|
2426
2579
|
* @param opts.useShortURL - whether to shorten the link
|
|
2427
2580
|
* @returns - the WebAuth URL for logging in
|
|
2428
2581
|
**/
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2582
|
+
initiateUserLoginForPhone(_g) {
|
|
2583
|
+
return __async(this, null, function* () {
|
|
2584
|
+
var _h = _g, {
|
|
2585
|
+
useShortUrl = false
|
|
2586
|
+
} = _h, auth = __objRest(_h, [
|
|
2587
|
+
"useShortUrl"
|
|
2588
|
+
]);
|
|
2589
|
+
yield this.setAuth(auth);
|
|
2590
|
+
const res = yield this.touchSession(true);
|
|
2591
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2592
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2593
|
+
}
|
|
2594
|
+
const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
|
|
2595
|
+
sessionId: res.data.sessionId,
|
|
2596
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
2597
|
+
partnerId: res.data.partnerId
|
|
2598
|
+
});
|
|
2599
|
+
if (!useShortUrl) {
|
|
2600
|
+
return webAuthLoginURL;
|
|
2601
|
+
}
|
|
2602
|
+
return this.shortenLoginLink(webAuthLoginURL);
|
|
2442
2603
|
});
|
|
2443
|
-
if (!useShortUrl) {
|
|
2444
|
-
return webAuthLoginURL;
|
|
2445
|
-
}
|
|
2446
|
-
return this.shortenLoginLink(webAuthLoginURL);
|
|
2447
2604
|
}
|
|
2448
2605
|
/**
|
|
2449
2606
|
* Waits for the session to be active.
|
|
2450
2607
|
**/
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
this.isAwaitingAccountCreation = false;
|
|
2461
|
-
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
2462
|
-
return true;
|
|
2463
|
-
} else {
|
|
2464
|
-
if (popupWindow?.closed) {
|
|
2608
|
+
waitForAccountCreation() {
|
|
2609
|
+
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
2610
|
+
yield this.touchSession();
|
|
2611
|
+
this.externalWallets = {};
|
|
2612
|
+
this.isAwaitingAccountCreation = true;
|
|
2613
|
+
while (this.isAwaitingAccountCreation) {
|
|
2614
|
+
try {
|
|
2615
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2616
|
+
if (yield this.isSessionActive()) {
|
|
2465
2617
|
this.isAwaitingAccountCreation = false;
|
|
2466
|
-
|
|
2618
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
2619
|
+
return true;
|
|
2620
|
+
} else {
|
|
2621
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2622
|
+
this.isAwaitingAccountCreation = false;
|
|
2623
|
+
return false;
|
|
2624
|
+
}
|
|
2467
2625
|
}
|
|
2626
|
+
} catch (err) {
|
|
2627
|
+
console.error(err);
|
|
2468
2628
|
}
|
|
2469
|
-
} catch (err) {
|
|
2470
|
-
console.error(err);
|
|
2471
2629
|
}
|
|
2472
|
-
|
|
2473
|
-
|
|
2630
|
+
return false;
|
|
2631
|
+
});
|
|
2474
2632
|
}
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2633
|
+
waitForPasskeyAndCreateWallet() {
|
|
2634
|
+
return __async(this, arguments, function* ({
|
|
2635
|
+
popupWindow
|
|
2636
|
+
} = {}) {
|
|
2637
|
+
yield this.waitForAccountCreation({ popupWindow });
|
|
2638
|
+
const pregenWallets = yield this.getPregenWallets();
|
|
2639
|
+
let recoverySecret, walletIds = {};
|
|
2640
|
+
if (pregenWallets.length > 0) {
|
|
2641
|
+
recoverySecret = yield this.claimPregenWallets();
|
|
2642
|
+
walletIds = this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
2643
|
+
var _a;
|
|
2644
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
2645
|
+
[type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
2646
|
+
});
|
|
2647
|
+
}, {});
|
|
2648
|
+
}
|
|
2649
|
+
const created = yield this.createWalletPerType();
|
|
2650
|
+
recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
|
|
2651
|
+
walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
|
|
2652
|
+
const resp = { walletIds, recoverySecret };
|
|
2653
|
+
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
2654
|
+
return resp;
|
|
2655
|
+
});
|
|
2496
2656
|
}
|
|
2497
2657
|
/**
|
|
2498
2658
|
* Initiates a Farcaster login attempt and return the URI for the user to connect.
|
|
2499
2659
|
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
2500
2660
|
* @return {string} the Farcaster connect URI
|
|
2501
2661
|
*/
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2662
|
+
getFarcasterConnectURL() {
|
|
2663
|
+
return __async(this, null, function* () {
|
|
2664
|
+
yield this.logout();
|
|
2665
|
+
yield this.touchSession(true);
|
|
2666
|
+
const {
|
|
2667
|
+
data: { connect_uri }
|
|
2668
|
+
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
2669
|
+
return connect_uri;
|
|
2670
|
+
});
|
|
2509
2671
|
}
|
|
2510
2672
|
/**
|
|
2511
2673
|
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
2512
2674
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
2513
2675
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
2514
2676
|
*/
|
|
2515
|
-
|
|
2516
|
-
this
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2677
|
+
waitForFarcasterStatus() {
|
|
2678
|
+
return __async(this, null, function* () {
|
|
2679
|
+
this.isAwaitingFarcaster = true;
|
|
2680
|
+
while (this.isAwaitingFarcaster) {
|
|
2681
|
+
try {
|
|
2682
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2683
|
+
const res = yield this.ctx.client.getFarcasterAuthStatus();
|
|
2684
|
+
if (res.data.state === "completed") {
|
|
2685
|
+
const { userId, userExists, username, pfpUrl } = res.data;
|
|
2686
|
+
yield this.setUserId(userId);
|
|
2687
|
+
yield this.setFarcasterUsername(username);
|
|
2688
|
+
return {
|
|
2689
|
+
userExists,
|
|
2690
|
+
username,
|
|
2691
|
+
pfpUrl
|
|
2692
|
+
};
|
|
2693
|
+
}
|
|
2694
|
+
} catch (err) {
|
|
2695
|
+
console.error(err);
|
|
2696
|
+
this.isAwaitingFarcaster = false;
|
|
2530
2697
|
}
|
|
2531
|
-
} catch (err) {
|
|
2532
|
-
console.error(err);
|
|
2533
|
-
this.isAwaitingFarcaster = false;
|
|
2534
2698
|
}
|
|
2535
|
-
}
|
|
2699
|
+
});
|
|
2536
2700
|
}
|
|
2537
2701
|
/**
|
|
2538
2702
|
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
@@ -2542,17 +2706,19 @@ var ParaCore = class _ParaCore {
|
|
|
2542
2706
|
* @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
|
|
2543
2707
|
* @returns {string} the URL for the user to log in with OAuth.
|
|
2544
2708
|
*/
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2709
|
+
getOAuthURL(_0) {
|
|
2710
|
+
return __async(this, arguments, function* ({ method, deeplinkUrl }) {
|
|
2711
|
+
yield this.logout();
|
|
2712
|
+
const res = yield this.touchSession(true);
|
|
2713
|
+
return constructUrl({
|
|
2714
|
+
base: method === OAuthMethod.TELEGRAM ? getPortalBaseURL(this.ctx, true) : getBaseOAuthUrl(this.ctx.env),
|
|
2715
|
+
path: `/auth/${method.toLowerCase()}`,
|
|
2716
|
+
params: {
|
|
2717
|
+
apiKey: this.ctx.apiKey,
|
|
2718
|
+
sessionLookupId: res.data.sessionLookupId,
|
|
2719
|
+
deeplinkUrl
|
|
2720
|
+
}
|
|
2721
|
+
});
|
|
2556
2722
|
});
|
|
2557
2723
|
}
|
|
2558
2724
|
/**
|
|
@@ -2563,36 +2729,38 @@ var ParaCore = class _ParaCore {
|
|
|
2563
2729
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
2564
2730
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
2565
2731
|
*/
|
|
2566
|
-
|
|
2567
|
-
this
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2732
|
+
waitForOAuth() {
|
|
2733
|
+
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
2734
|
+
this.isAwaitingOAuth = true;
|
|
2735
|
+
while (this.isAwaitingOAuth) {
|
|
2736
|
+
try {
|
|
2737
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2738
|
+
return { isError: true, userExists: false };
|
|
2739
|
+
}
|
|
2740
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2741
|
+
if (this.isAwaitingOAuth) {
|
|
2742
|
+
const res = yield this.touchSession();
|
|
2743
|
+
if (res.data.userId) {
|
|
2744
|
+
const { userId, email } = res.data;
|
|
2745
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2746
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2747
|
+
}
|
|
2748
|
+
yield this.setUserId(userId);
|
|
2749
|
+
yield this.setEmail(email);
|
|
2750
|
+
const userExists = yield this.checkIfUserExists({ email });
|
|
2751
|
+
this.isAwaitingOAuth = false;
|
|
2752
|
+
return {
|
|
2753
|
+
userExists,
|
|
2754
|
+
email
|
|
2755
|
+
};
|
|
2580
2756
|
}
|
|
2581
|
-
await this.setUserId(userId);
|
|
2582
|
-
await this.setEmail(email);
|
|
2583
|
-
const userExists = await this.checkIfUserExists({ email });
|
|
2584
|
-
this.isAwaitingOAuth = false;
|
|
2585
|
-
return {
|
|
2586
|
-
userExists,
|
|
2587
|
-
email
|
|
2588
|
-
};
|
|
2589
2757
|
}
|
|
2758
|
+
} catch (err) {
|
|
2759
|
+
console.error(err);
|
|
2590
2760
|
}
|
|
2591
|
-
} catch (err) {
|
|
2592
|
-
console.error(err);
|
|
2593
2761
|
}
|
|
2594
|
-
|
|
2595
|
-
|
|
2762
|
+
return { userExists: false };
|
|
2763
|
+
});
|
|
2596
2764
|
}
|
|
2597
2765
|
/**
|
|
2598
2766
|
* Waits for the session to be active and sets up the user.
|
|
@@ -2602,57 +2770,59 @@ var ParaCore = class _ParaCore {
|
|
|
2602
2770
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
2603
2771
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
2604
2772
|
**/
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
if (
|
|
2617
|
-
|
|
2618
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
2619
|
-
return resp2;
|
|
2620
|
-
}
|
|
2621
|
-
continue;
|
|
2622
|
-
}
|
|
2623
|
-
const postLoginData = await this.userSetupAfterLogin();
|
|
2624
|
-
const needsWallet = postLoginData.data.needsWallet ?? false;
|
|
2625
|
-
if (!needsWallet) {
|
|
2626
|
-
if (this.currentWalletIdsArray.length === 0) {
|
|
2627
|
-
if (popupWindow?.closed) {
|
|
2773
|
+
waitForLoginAndSetup() {
|
|
2774
|
+
return __async(this, arguments, function* ({
|
|
2775
|
+
popupWindow,
|
|
2776
|
+
skipSessionRefresh = false
|
|
2777
|
+
} = {}) {
|
|
2778
|
+
var _a;
|
|
2779
|
+
this.externalWallets = {};
|
|
2780
|
+
this.isAwaitingLogin = true;
|
|
2781
|
+
while (this.isAwaitingLogin) {
|
|
2782
|
+
try {
|
|
2783
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2784
|
+
if (!(yield this.isSessionActive())) {
|
|
2785
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2628
2786
|
const resp2 = { isComplete: false, isError: true };
|
|
2629
2787
|
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
2630
2788
|
return resp2;
|
|
2631
|
-
} else {
|
|
2632
|
-
continue;
|
|
2633
2789
|
}
|
|
2790
|
+
continue;
|
|
2634
2791
|
}
|
|
2792
|
+
const postLoginData = yield this.userSetupAfterLogin();
|
|
2793
|
+
const needsWallet = (_a = postLoginData.data.needsWallet) != null ? _a : false;
|
|
2794
|
+
if (!needsWallet) {
|
|
2795
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
2796
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2797
|
+
const resp2 = { isComplete: false, isError: true };
|
|
2798
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
2799
|
+
return resp2;
|
|
2800
|
+
} else {
|
|
2801
|
+
continue;
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
2806
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
2807
|
+
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
2808
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
2809
|
+
yield this.claimPregenWallets();
|
|
2810
|
+
const resp2 = {
|
|
2811
|
+
isComplete: true,
|
|
2812
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
2813
|
+
partnerId: postLoginData.data.partnerId
|
|
2814
|
+
};
|
|
2815
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
|
|
2816
|
+
return resp2;
|
|
2817
|
+
}
|
|
2818
|
+
} catch (err) {
|
|
2819
|
+
console.error(err);
|
|
2635
2820
|
}
|
|
2636
|
-
const fetchedWallets = await this.fetchWallets();
|
|
2637
|
-
const tempSharesRes = await this.getTransmissionKeyShares();
|
|
2638
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
2639
|
-
await this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
2640
|
-
await this.claimPregenWallets();
|
|
2641
|
-
const resp2 = {
|
|
2642
|
-
isComplete: true,
|
|
2643
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
2644
|
-
partnerId: postLoginData.data.partnerId
|
|
2645
|
-
};
|
|
2646
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
|
|
2647
|
-
return resp2;
|
|
2648
|
-
}
|
|
2649
|
-
} catch (err) {
|
|
2650
|
-
console.error(err);
|
|
2651
2821
|
}
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2822
|
+
const resp = { isComplete: false };
|
|
2823
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp, "exitted login without setting up user");
|
|
2824
|
+
return resp;
|
|
2825
|
+
});
|
|
2656
2826
|
}
|
|
2657
2827
|
/**
|
|
2658
2828
|
* Updates the session with the user management server, possibly
|
|
@@ -2662,32 +2832,36 @@ var ParaCore = class _ParaCore {
|
|
|
2662
2832
|
* @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
|
|
2663
2833
|
* @returns a URL for the user to reauthenticate.
|
|
2664
2834
|
**/
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2835
|
+
refreshSession() {
|
|
2836
|
+
return __async(this, arguments, function* ({ shouldOpenPopup = false } = {}) {
|
|
2837
|
+
const res = yield this.touchSession(true);
|
|
2838
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2839
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2840
|
+
}
|
|
2841
|
+
const link = yield this.getWebAuthURLForLogin({
|
|
2842
|
+
sessionId: res.data.sessionId,
|
|
2843
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
2844
|
+
});
|
|
2845
|
+
if (shouldOpenPopup) {
|
|
2846
|
+
this.platformUtils.openPopup(link);
|
|
2847
|
+
}
|
|
2848
|
+
return link;
|
|
2673
2849
|
});
|
|
2674
|
-
if (shouldOpenPopup) {
|
|
2675
|
-
this.platformUtils.openPopup(link);
|
|
2676
|
-
}
|
|
2677
|
-
return link;
|
|
2678
2850
|
}
|
|
2679
2851
|
/**
|
|
2680
2852
|
* Call this method after login to ensure that the user ID is set
|
|
2681
2853
|
* internally.
|
|
2682
2854
|
**/
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2855
|
+
userSetupAfterLogin() {
|
|
2856
|
+
return __async(this, null, function* () {
|
|
2857
|
+
const res = yield this.touchSession();
|
|
2858
|
+
yield this.setUserId(res.data.userId);
|
|
2859
|
+
if (res.data.currentWalletIds && res.data.currentWalletIds !== this.currentWalletIds)
|
|
2860
|
+
yield this.setCurrentWalletIds(res.data.currentWalletIds, {
|
|
2861
|
+
sessionLookupId: this.isPortal() ? res.data.sessionLookupId : void 0
|
|
2862
|
+
});
|
|
2863
|
+
return res;
|
|
2864
|
+
});
|
|
2691
2865
|
}
|
|
2692
2866
|
/**
|
|
2693
2867
|
* Get transmission shares associated with session.
|
|
@@ -2695,10 +2869,12 @@ var ParaCore = class _ParaCore {
|
|
|
2695
2869
|
* @param {boolean} opts.isForNewDevice - true if this device is registering.
|
|
2696
2870
|
* @returns - transmission keyshares.
|
|
2697
2871
|
**/
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2872
|
+
getTransmissionKeyShares() {
|
|
2873
|
+
return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
|
|
2874
|
+
const res = yield this.touchSession();
|
|
2875
|
+
const sessionLookupId = isForNewDevice ? `${res.data.sessionLookupId}-new-device` : res.data.sessionLookupId;
|
|
2876
|
+
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
2877
|
+
});
|
|
2702
2878
|
}
|
|
2703
2879
|
/**
|
|
2704
2880
|
* Call this method after login to perform setup.
|
|
@@ -2706,23 +2882,25 @@ var ParaCore = class _ParaCore {
|
|
|
2706
2882
|
* @param {any[]} opts.temporaryShares optional temporary shares to use for decryption.
|
|
2707
2883
|
* @param {boolean} [opts.skipSessionRefresh] - whether or not to skip refreshing the session.
|
|
2708
2884
|
**/
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2885
|
+
setupAfterLogin() {
|
|
2886
|
+
return __async(this, arguments, function* ({
|
|
2887
|
+
temporaryShares,
|
|
2888
|
+
skipSessionRefresh = false
|
|
2889
|
+
} = {}) {
|
|
2890
|
+
if (!temporaryShares) {
|
|
2891
|
+
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
2892
|
+
}
|
|
2893
|
+
temporaryShares.forEach((share) => {
|
|
2894
|
+
const signer = decryptWithPrivateKey(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
2895
|
+
this.wallets[share.walletId] = {
|
|
2896
|
+
id: share.walletId,
|
|
2897
|
+
signer
|
|
2898
|
+
};
|
|
2899
|
+
});
|
|
2900
|
+
yield this.deleteLoginEncryptionKeyPair();
|
|
2901
|
+
yield this.populateWalletAddresses();
|
|
2902
|
+
yield this.touchSession(!skipSessionRefresh);
|
|
2722
2903
|
});
|
|
2723
|
-
await this.deleteLoginEncryptionKeyPair();
|
|
2724
|
-
await this.populateWalletAddresses();
|
|
2725
|
-
await this.touchSession(!skipSessionRefresh);
|
|
2726
2904
|
}
|
|
2727
2905
|
/**
|
|
2728
2906
|
* Distributes a new wallet recovery share.
|
|
@@ -2733,51 +2911,55 @@ var ParaCore = class _ParaCore {
|
|
|
2733
2911
|
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
2734
2912
|
* @returns {string} the recovery share.
|
|
2735
2913
|
**/
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
userShare,
|
|
2739
|
-
skipBiometricShareCreation = false,
|
|
2740
|
-
forceRefresh = false
|
|
2741
|
-
}) {
|
|
2742
|
-
let userSigner = userShare;
|
|
2743
|
-
if (!userSigner) {
|
|
2744
|
-
userSigner = this.wallets[walletId].signer;
|
|
2745
|
-
}
|
|
2746
|
-
const recoveryShare = skipBiometricShareCreation ? await sendRecoveryForShare({
|
|
2747
|
-
ctx: this.ctx,
|
|
2748
|
-
userId: this.userId,
|
|
2914
|
+
distributeNewWalletShare(_0) {
|
|
2915
|
+
return __async(this, arguments, function* ({
|
|
2749
2916
|
walletId,
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
forceRefresh
|
|
2753
|
-
})
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2917
|
+
userShare,
|
|
2918
|
+
skipBiometricShareCreation = false,
|
|
2919
|
+
forceRefresh = false
|
|
2920
|
+
}) {
|
|
2921
|
+
let userSigner = userShare;
|
|
2922
|
+
if (!userSigner) {
|
|
2923
|
+
userSigner = this.wallets[walletId].signer;
|
|
2924
|
+
}
|
|
2925
|
+
const recoveryShare = skipBiometricShareCreation ? yield sendRecoveryForShare({
|
|
2926
|
+
ctx: this.ctx,
|
|
2927
|
+
userId: this.userId,
|
|
2928
|
+
walletId,
|
|
2929
|
+
userSigner,
|
|
2930
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
2931
|
+
forceRefresh
|
|
2932
|
+
}) : yield distributeNewShare({
|
|
2933
|
+
ctx: this.ctx,
|
|
2934
|
+
userId: this.userId,
|
|
2935
|
+
walletId,
|
|
2936
|
+
userShare: userSigner,
|
|
2937
|
+
emailProps: this.getBackupKitEmailProps()
|
|
2938
|
+
});
|
|
2939
|
+
return recoveryShare;
|
|
2759
2940
|
});
|
|
2760
|
-
return recoveryShare;
|
|
2761
2941
|
}
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2942
|
+
waitForWalletAddress(walletId) {
|
|
2943
|
+
return __async(this, null, function* () {
|
|
2944
|
+
let maxPolls = 0;
|
|
2945
|
+
while (true) {
|
|
2946
|
+
try {
|
|
2947
|
+
if (maxPolls === 10) {
|
|
2948
|
+
break;
|
|
2949
|
+
}
|
|
2950
|
+
++maxPolls;
|
|
2951
|
+
const res = yield this.ctx.client.getWallets(this.userId);
|
|
2952
|
+
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
2953
|
+
if (wallet && wallet.address) {
|
|
2954
|
+
return;
|
|
2955
|
+
}
|
|
2956
|
+
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2957
|
+
} catch (err) {
|
|
2958
|
+
console.error(err);
|
|
2774
2959
|
}
|
|
2775
|
-
await new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2776
|
-
} catch (err) {
|
|
2777
|
-
console.error(err);
|
|
2778
2960
|
}
|
|
2779
|
-
|
|
2780
|
-
|
|
2961
|
+
throw new Error("timed out waiting for wallet address");
|
|
2962
|
+
});
|
|
2781
2963
|
}
|
|
2782
2964
|
/**
|
|
2783
2965
|
* Waits for a pregen wallet address to be created.
|
|
@@ -2787,25 +2969,27 @@ var ParaCore = class _ParaCore {
|
|
|
2787
2969
|
* @param pregenIdentifierType - the identifier type of the user the pregen wallet is associated with.
|
|
2788
2970
|
* @returns - recovery share.
|
|
2789
2971
|
**/
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2972
|
+
waitForPregenWalletAddress(walletId) {
|
|
2973
|
+
return __async(this, null, function* () {
|
|
2974
|
+
let maxPolls = 0;
|
|
2975
|
+
while (true) {
|
|
2976
|
+
try {
|
|
2977
|
+
if (maxPolls === 10) {
|
|
2978
|
+
break;
|
|
2979
|
+
}
|
|
2980
|
+
++maxPolls;
|
|
2981
|
+
const res = yield this.getPregenWallets();
|
|
2982
|
+
const wallet = res.find((w) => w.id === walletId);
|
|
2983
|
+
if (wallet && wallet.address) {
|
|
2984
|
+
return;
|
|
2985
|
+
}
|
|
2986
|
+
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2987
|
+
} catch (err) {
|
|
2988
|
+
console.error(err);
|
|
2802
2989
|
}
|
|
2803
|
-
await new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2804
|
-
} catch (err) {
|
|
2805
|
-
console.error(err);
|
|
2806
2990
|
}
|
|
2807
|
-
|
|
2808
|
-
|
|
2991
|
+
throw new Error("timed out waiting for wallet address");
|
|
2992
|
+
});
|
|
2809
2993
|
}
|
|
2810
2994
|
/**
|
|
2811
2995
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
@@ -2818,24 +3002,26 @@ var ParaCore = class _ParaCore {
|
|
|
2818
3002
|
* @param {WalletType[]} [opts.types] the types of wallets to create.
|
|
2819
3003
|
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
2820
3004
|
**/
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
const
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
3005
|
+
createWalletPerType() {
|
|
3006
|
+
return __async(this, arguments, function* ({
|
|
3007
|
+
skipDistribute = false,
|
|
3008
|
+
types
|
|
3009
|
+
} = {}) {
|
|
3010
|
+
const wallets = [];
|
|
3011
|
+
const walletIds = {};
|
|
3012
|
+
let recoverySecret;
|
|
3013
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
3014
|
+
const [wallet, recoveryShare] = yield this.createWallet({ type, skipDistribute });
|
|
3015
|
+
wallets.push(wallet);
|
|
3016
|
+
getEquivalentTypes(type).filter((t) => !!this.isWalletTypeEnabled[t]).forEach((t) => {
|
|
3017
|
+
walletIds[t] = [wallet.id];
|
|
3018
|
+
});
|
|
3019
|
+
if (recoveryShare) {
|
|
3020
|
+
recoverySecret = recoveryShare;
|
|
3021
|
+
}
|
|
2836
3022
|
}
|
|
2837
|
-
|
|
2838
|
-
|
|
3023
|
+
return { wallets, walletIds, recoverySecret };
|
|
3024
|
+
});
|
|
2839
3025
|
}
|
|
2840
3026
|
/**
|
|
2841
3027
|
* Refresh the current user share for a wallet.
|
|
@@ -2849,35 +3035,37 @@ var ParaCore = class _ParaCore {
|
|
|
2849
3035
|
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
2850
3036
|
* @returns {Object} the new user share and recovery secret.
|
|
2851
3037
|
**/
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
share,
|
|
2855
|
-
oldPartnerId,
|
|
2856
|
-
newPartnerId,
|
|
2857
|
-
keyShareProtocolId,
|
|
2858
|
-
redistributeBackupEncryptedShares
|
|
2859
|
-
}) {
|
|
2860
|
-
const { signer, protocolId } = await this.platformUtils.refresh(
|
|
2861
|
-
this.ctx,
|
|
2862
|
-
this.retrieveSessionCookie(),
|
|
2863
|
-
this.userId,
|
|
3038
|
+
refreshShare(_0) {
|
|
3039
|
+
return __async(this, arguments, function* ({
|
|
2864
3040
|
walletId,
|
|
2865
3041
|
share,
|
|
2866
3042
|
oldPartnerId,
|
|
2867
3043
|
newPartnerId,
|
|
2868
|
-
keyShareProtocolId
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
3044
|
+
keyShareProtocolId,
|
|
3045
|
+
redistributeBackupEncryptedShares
|
|
3046
|
+
}) {
|
|
3047
|
+
const { signer, protocolId } = yield this.platformUtils.refresh(
|
|
3048
|
+
this.ctx,
|
|
3049
|
+
this.retrieveSessionCookie(),
|
|
3050
|
+
this.userId,
|
|
3051
|
+
walletId,
|
|
3052
|
+
share,
|
|
3053
|
+
oldPartnerId,
|
|
3054
|
+
newPartnerId,
|
|
3055
|
+
keyShareProtocolId
|
|
3056
|
+
);
|
|
3057
|
+
const recoverySecret = yield distributeNewShare({
|
|
3058
|
+
ctx: this.ctx,
|
|
3059
|
+
userId: this.userId,
|
|
3060
|
+
walletId,
|
|
3061
|
+
userShare: signer,
|
|
3062
|
+
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
3063
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3064
|
+
partnerId: newPartnerId,
|
|
3065
|
+
protocolId
|
|
3066
|
+
});
|
|
3067
|
+
return { signer, recoverySecret, protocolId };
|
|
2879
3068
|
});
|
|
2880
|
-
return { signer, recoverySecret, protocolId };
|
|
2881
3069
|
}
|
|
2882
3070
|
/**
|
|
2883
3071
|
* Creates a new wallet.
|
|
@@ -2886,71 +3074,73 @@ var ParaCore = class _ParaCore {
|
|
|
2886
3074
|
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
2887
3075
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2888
3076
|
**/
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
this.
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
3077
|
+
createWallet() {
|
|
3078
|
+
return __async(this, arguments, function* ({
|
|
3079
|
+
type: _type,
|
|
3080
|
+
skipDistribute = false
|
|
3081
|
+
} = {}) {
|
|
3082
|
+
var _a, _b;
|
|
3083
|
+
this.requireApiKey();
|
|
3084
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
3085
|
+
_type != null ? _type : (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
3086
|
+
);
|
|
3087
|
+
let signer;
|
|
3088
|
+
let wallet;
|
|
3089
|
+
let keygenRes;
|
|
3090
|
+
switch (walletType) {
|
|
3091
|
+
case WalletType2.SOLANA: {
|
|
3092
|
+
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
3093
|
+
this.ctx,
|
|
3094
|
+
this.userId,
|
|
3095
|
+
this.retrieveSessionCookie(),
|
|
3096
|
+
this.getBackupKitEmailProps()
|
|
3097
|
+
);
|
|
3098
|
+
break;
|
|
3099
|
+
}
|
|
3100
|
+
default: {
|
|
3101
|
+
keygenRes = yield this.platformUtils.keygen(
|
|
3102
|
+
this.ctx,
|
|
3103
|
+
this.userId,
|
|
3104
|
+
walletType,
|
|
3105
|
+
null,
|
|
3106
|
+
this.retrieveSessionCookie(),
|
|
3107
|
+
this.getBackupKitEmailProps()
|
|
3108
|
+
);
|
|
3109
|
+
break;
|
|
3110
|
+
}
|
|
2909
3111
|
}
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
3112
|
+
const walletId = keygenRes.walletId;
|
|
3113
|
+
signer = keygenRes.signer;
|
|
3114
|
+
this.wallets[walletId] = {
|
|
3115
|
+
id: walletId,
|
|
3116
|
+
signer,
|
|
3117
|
+
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
3118
|
+
type: walletType
|
|
3119
|
+
};
|
|
3120
|
+
wallet = this.wallets[walletId];
|
|
3121
|
+
yield this.waitForWalletAddress(wallet.id);
|
|
3122
|
+
yield this.populateWalletAddresses();
|
|
3123
|
+
let recoveryShare = null;
|
|
3124
|
+
if (!skipDistribute) {
|
|
3125
|
+
recoveryShare = yield distributeNewShare({
|
|
3126
|
+
ctx: this.ctx,
|
|
3127
|
+
userId: this.userId,
|
|
3128
|
+
walletId: wallet.id,
|
|
3129
|
+
userShare: signer,
|
|
3130
|
+
emailProps: this.getBackupKitEmailProps()
|
|
3131
|
+
});
|
|
2920
3132
|
}
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
};
|
|
2930
|
-
wallet = this.wallets[walletId];
|
|
2931
|
-
await this.waitForWalletAddress(wallet.id);
|
|
2932
|
-
await this.populateWalletAddresses();
|
|
2933
|
-
let recoveryShare = null;
|
|
2934
|
-
if (!skipDistribute) {
|
|
2935
|
-
recoveryShare = await distributeNewShare({
|
|
2936
|
-
ctx: this.ctx,
|
|
2937
|
-
userId: this.userId,
|
|
2938
|
-
walletId: wallet.id,
|
|
2939
|
-
userShare: signer,
|
|
2940
|
-
emailProps: this.getBackupKitEmailProps()
|
|
3133
|
+
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
3134
|
+
[walletType]: [...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId]
|
|
3135
|
+
}));
|
|
3136
|
+
const walletNoSigner = __spreadValues({}, wallet);
|
|
3137
|
+
delete walletNoSigner.signer;
|
|
3138
|
+
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
3139
|
+
wallet: walletNoSigner,
|
|
3140
|
+
recoverySecret: recoveryShare
|
|
2941
3141
|
});
|
|
2942
|
-
|
|
2943
|
-
await this.setCurrentWalletIds({
|
|
2944
|
-
...this.currentWalletIds,
|
|
2945
|
-
[walletType]: [...this.currentWalletIds[walletType] ?? [], walletId]
|
|
2946
|
-
});
|
|
2947
|
-
const walletNoSigner = { ...wallet };
|
|
2948
|
-
delete walletNoSigner.signer;
|
|
2949
|
-
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
2950
|
-
wallet: walletNoSigner,
|
|
2951
|
-
recoverySecret: recoveryShare
|
|
3142
|
+
return [wallet, recoveryShare];
|
|
2952
3143
|
});
|
|
2953
|
-
return [wallet, recoveryShare];
|
|
2954
3144
|
}
|
|
2955
3145
|
/**
|
|
2956
3146
|
* Creates a new pregenerated wallet.
|
|
@@ -2961,51 +3151,54 @@ var ParaCore = class _ParaCore {
|
|
|
2961
3151
|
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
2962
3152
|
* @returns {Wallet} the created wallet.
|
|
2963
3153
|
**/
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3154
|
+
createPregenWallet(opts) {
|
|
3155
|
+
return __async(this, null, function* () {
|
|
3156
|
+
var _a, _b;
|
|
3157
|
+
const {
|
|
3158
|
+
type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
|
|
3159
|
+
pregenIdentifier,
|
|
3160
|
+
pregenIdentifierType = "EMAIL"
|
|
3161
|
+
} = opts;
|
|
3162
|
+
this.requireApiKey();
|
|
3163
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
3164
|
+
_type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
3165
|
+
);
|
|
3166
|
+
let keygenRes;
|
|
3167
|
+
switch (walletType) {
|
|
3168
|
+
case WalletType2.SOLANA:
|
|
3169
|
+
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
3170
|
+
this.ctx,
|
|
3171
|
+
pregenIdentifier,
|
|
3172
|
+
pregenIdentifierType,
|
|
3173
|
+
this.retrieveSessionCookie()
|
|
3174
|
+
);
|
|
3175
|
+
break;
|
|
3176
|
+
default:
|
|
3177
|
+
keygenRes = yield this.platformUtils.preKeygen(
|
|
3178
|
+
this.ctx,
|
|
3179
|
+
void 0,
|
|
3180
|
+
pregenIdentifier,
|
|
3181
|
+
pregenIdentifierType,
|
|
3182
|
+
walletType,
|
|
3183
|
+
null,
|
|
3184
|
+
this.retrieveSessionCookie()
|
|
3185
|
+
);
|
|
3186
|
+
break;
|
|
3187
|
+
}
|
|
3188
|
+
const { signer, walletId } = keygenRes;
|
|
3189
|
+
this.wallets[walletId] = {
|
|
3190
|
+
id: walletId,
|
|
3191
|
+
signer,
|
|
3192
|
+
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
3193
|
+
type: walletType,
|
|
3194
|
+
isPregen: true,
|
|
3195
|
+
pregenIdentifier,
|
|
3196
|
+
pregenIdentifierType
|
|
3197
|
+
};
|
|
3198
|
+
yield this.waitForPregenWalletAddress(walletId);
|
|
3199
|
+
yield this.populatePregenWalletAddresses();
|
|
3200
|
+
return this.wallets[walletId];
|
|
3201
|
+
});
|
|
3009
3202
|
}
|
|
3010
3203
|
/**
|
|
3011
3204
|
* Creates new pregenerated wallets for each desired type.
|
|
@@ -3017,17 +3210,19 @@ var ParaCore = class _ParaCore {
|
|
|
3017
3210
|
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
3018
3211
|
* @returns {Wallet[]} an array containing the created wallets.
|
|
3019
3212
|
**/
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
const
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3213
|
+
createPregenWalletPerType(_0) {
|
|
3214
|
+
return __async(this, arguments, function* ({
|
|
3215
|
+
types,
|
|
3216
|
+
pregenIdentifier,
|
|
3217
|
+
pregenIdentifierType = "EMAIL"
|
|
3218
|
+
}) {
|
|
3219
|
+
const wallets = [];
|
|
3220
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
3221
|
+
const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
|
|
3222
|
+
wallets.push(wallet);
|
|
3223
|
+
}
|
|
3224
|
+
return wallets;
|
|
3225
|
+
});
|
|
3031
3226
|
}
|
|
3032
3227
|
/**
|
|
3033
3228
|
* Claims a pregenerated wallet.
|
|
@@ -3037,63 +3232,65 @@ var ParaCore = class _ParaCore {
|
|
|
3037
3232
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
3038
3233
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3039
3234
|
**/
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
walletIds
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3235
|
+
claimPregenWallets() {
|
|
3236
|
+
return __async(this, arguments, function* ({
|
|
3237
|
+
pregenIdentifier,
|
|
3238
|
+
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
3239
|
+
} = {}) {
|
|
3240
|
+
var _a;
|
|
3241
|
+
this.requireApiKey();
|
|
3242
|
+
const pregenWallets = pregenIdentifier && pregenIdentifierType ? yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType }) : yield this.getPregenWallets();
|
|
3243
|
+
if (pregenWallets.length === 0) {
|
|
3244
|
+
return void 0;
|
|
3245
|
+
}
|
|
3246
|
+
let newRecoverySecret;
|
|
3247
|
+
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
3248
|
+
userId: this.userId,
|
|
3249
|
+
walletIds: pregenWallets.map((w) => w.id)
|
|
3250
|
+
});
|
|
3251
|
+
for (const walletId of walletIds) {
|
|
3252
|
+
const wallet = this.wallets[walletId];
|
|
3253
|
+
let refreshedShare;
|
|
3254
|
+
if (wallet.scheme === WalletScheme2.ED25519) {
|
|
3255
|
+
const distributeRes = yield distributeNewShare({
|
|
3256
|
+
ctx: this.ctx,
|
|
3257
|
+
userId: this.userId,
|
|
3258
|
+
walletId: wallet.id,
|
|
3259
|
+
userShare: this.wallets[wallet.id].signer,
|
|
3260
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3261
|
+
partnerId: wallet.partnerId
|
|
3262
|
+
});
|
|
3263
|
+
if (distributeRes.length > 0) {
|
|
3264
|
+
newRecoverySecret = distributeRes;
|
|
3265
|
+
}
|
|
3266
|
+
} else {
|
|
3267
|
+
refreshedShare = yield this.refreshShare({
|
|
3268
|
+
walletId: wallet.id,
|
|
3269
|
+
share: this.wallets[wallet.id].signer,
|
|
3270
|
+
oldPartnerId: wallet.partnerId,
|
|
3271
|
+
newPartnerId: wallet.partnerId,
|
|
3272
|
+
redistributeBackupEncryptedShares: true
|
|
3273
|
+
});
|
|
3274
|
+
if (refreshedShare.recoverySecret) {
|
|
3275
|
+
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
|
|
3279
|
+
signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
|
|
3060
3280
|
userId: this.userId,
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
3064
|
-
partnerId: wallet.partnerId
|
|
3281
|
+
pregenIdentifier: void 0,
|
|
3282
|
+
pregenIdentifierType: void 0
|
|
3065
3283
|
});
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
walletId: wallet.id,
|
|
3072
|
-
share: this.wallets[wallet.id].signer,
|
|
3073
|
-
oldPartnerId: wallet.partnerId,
|
|
3074
|
-
newPartnerId: wallet.partnerId,
|
|
3075
|
-
redistributeBackupEncryptedShares: true
|
|
3284
|
+
const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
|
|
3285
|
+
delete walletNoSigner.signer;
|
|
3286
|
+
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
3287
|
+
wallet: walletNoSigner,
|
|
3288
|
+
recoverySecret: newRecoverySecret
|
|
3076
3289
|
});
|
|
3077
|
-
if (refreshedShare.recoverySecret) {
|
|
3078
|
-
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3079
|
-
}
|
|
3080
3290
|
}
|
|
3081
|
-
this.wallets
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
userId: this.userId,
|
|
3085
|
-
pregenIdentifier: void 0,
|
|
3086
|
-
pregenIdentifierType: void 0
|
|
3087
|
-
};
|
|
3088
|
-
const walletNoSigner = { ...this.wallets[wallet.id] };
|
|
3089
|
-
delete walletNoSigner.signer;
|
|
3090
|
-
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
3091
|
-
wallet: walletNoSigner,
|
|
3092
|
-
recoverySecret: newRecoverySecret
|
|
3093
|
-
});
|
|
3094
|
-
}
|
|
3095
|
-
await this.setWallets(this.wallets);
|
|
3096
|
-
return newRecoverySecret;
|
|
3291
|
+
yield this.setWallets(this.wallets);
|
|
3292
|
+
return newRecoverySecret;
|
|
3293
|
+
});
|
|
3097
3294
|
}
|
|
3098
3295
|
/**
|
|
3099
3296
|
* Updates the identifier for a pregen wallet.
|
|
@@ -3102,24 +3299,25 @@ var ParaCore = class _ParaCore {
|
|
|
3102
3299
|
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
3103
3300
|
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
3104
3301
|
**/
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
pregenIdentifierType: newPregenIdentifierType
|
|
3114
|
-
});
|
|
3115
|
-
if (!!this.wallets[walletId]) {
|
|
3116
|
-
this.wallets[walletId] = {
|
|
3117
|
-
...this.wallets[walletId],
|
|
3302
|
+
updatePregenWalletIdentifier(_0) {
|
|
3303
|
+
return __async(this, arguments, function* ({
|
|
3304
|
+
walletId,
|
|
3305
|
+
newPregenIdentifier,
|
|
3306
|
+
newPregenIdentifierType
|
|
3307
|
+
}) {
|
|
3308
|
+
this.requireApiKey();
|
|
3309
|
+
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
3118
3310
|
pregenIdentifier: newPregenIdentifier,
|
|
3119
3311
|
pregenIdentifierType: newPregenIdentifierType
|
|
3120
|
-
};
|
|
3121
|
-
|
|
3122
|
-
|
|
3312
|
+
});
|
|
3313
|
+
if (!!this.wallets[walletId]) {
|
|
3314
|
+
this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3315
|
+
pregenIdentifier: newPregenIdentifier,
|
|
3316
|
+
pregenIdentifierType: newPregenIdentifierType
|
|
3317
|
+
});
|
|
3318
|
+
yield this.setWallets(this.wallets);
|
|
3319
|
+
}
|
|
3320
|
+
});
|
|
3123
3321
|
}
|
|
3124
3322
|
/**
|
|
3125
3323
|
* Checks if a pregen Wallet exists for the given identifier with the current partner.
|
|
@@ -3128,17 +3326,19 @@ var ParaCore = class _ParaCore {
|
|
|
3128
3326
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
3129
3327
|
* @returns {boolean} whether the pregen wallet exists
|
|
3130
3328
|
**/
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3329
|
+
hasPregenWallet(_0) {
|
|
3330
|
+
return __async(this, arguments, function* ({
|
|
3331
|
+
pregenIdentifier,
|
|
3332
|
+
pregenIdentifierType
|
|
3333
|
+
}) {
|
|
3334
|
+
this.requireApiKey();
|
|
3335
|
+
const res = yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType });
|
|
3336
|
+
const wallet = res.find((w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType);
|
|
3337
|
+
if (!wallet) {
|
|
3338
|
+
return false;
|
|
3339
|
+
}
|
|
3340
|
+
return true;
|
|
3341
|
+
});
|
|
3142
3342
|
}
|
|
3143
3343
|
/**
|
|
3144
3344
|
* Get pregen wallets for the given identifier.
|
|
@@ -3147,17 +3347,19 @@ var ParaCore = class _ParaCore {
|
|
|
3147
3347
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
3148
3348
|
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
3149
3349
|
**/
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3350
|
+
getPregenWallets() {
|
|
3351
|
+
return __async(this, arguments, function* ({
|
|
3352
|
+
pregenIdentifier,
|
|
3353
|
+
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
3354
|
+
} = {}) {
|
|
3355
|
+
this.requireApiKey();
|
|
3356
|
+
const res = yield this.ctx.client.getPregenWallets(
|
|
3357
|
+
pregenIdentifier && pregenIdentifierType ? { [pregenIdentifierType]: [pregenIdentifier] } : this.pregenIds,
|
|
3358
|
+
this.isPortal(),
|
|
3359
|
+
this.userId
|
|
3360
|
+
);
|
|
3361
|
+
return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
|
|
3362
|
+
});
|
|
3161
3363
|
}
|
|
3162
3364
|
encodeWalletBase64(wallet) {
|
|
3163
3365
|
const walletJson = JSON.stringify(wallet);
|
|
@@ -3178,45 +3380,54 @@ var ParaCore = class _ParaCore {
|
|
|
3178
3380
|
* Sets the current wallets from a Base 64 string.
|
|
3179
3381
|
* @param {string} base64Wallet the encoded wallet string
|
|
3180
3382
|
**/
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
const
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
}
|
|
3193
|
-
async getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
3194
|
-
const res = await this.touchSession();
|
|
3195
|
-
return this.constructPortalUrl("txReview", {
|
|
3196
|
-
partnerId: res.data.partnerId,
|
|
3197
|
-
pathId: transactionId,
|
|
3198
|
-
params: {
|
|
3199
|
-
email: this.email,
|
|
3200
|
-
timeoutMs: timeoutMs?.toString()
|
|
3383
|
+
setUserShare(base64Wallets) {
|
|
3384
|
+
return __async(this, null, function* () {
|
|
3385
|
+
if (!base64Wallets) {
|
|
3386
|
+
return;
|
|
3387
|
+
}
|
|
3388
|
+
const base64WalletsSplit = base64Wallets.split("-");
|
|
3389
|
+
for (const base64Wallet of base64WalletsSplit) {
|
|
3390
|
+
const walletJson = Buffer.from(base64Wallet, "base64").toString();
|
|
3391
|
+
const wallet = migrateWallet(JSON.parse(walletJson));
|
|
3392
|
+
this.wallets[wallet.id] = wallet;
|
|
3393
|
+
yield this.setWallets(this.wallets);
|
|
3201
3394
|
}
|
|
3202
3395
|
});
|
|
3203
3396
|
}
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3397
|
+
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
3398
|
+
return __async(this, null, function* () {
|
|
3399
|
+
const res = yield this.touchSession();
|
|
3400
|
+
return this.constructPortalUrl("txReview", {
|
|
3401
|
+
partnerId: res.data.partnerId,
|
|
3402
|
+
pathId: transactionId,
|
|
3403
|
+
params: {
|
|
3404
|
+
email: this.email,
|
|
3405
|
+
timeoutMs: timeoutMs == null ? void 0 : timeoutMs.toString()
|
|
3406
|
+
}
|
|
3407
|
+
});
|
|
3408
|
+
});
|
|
3409
|
+
}
|
|
3410
|
+
getOnRampTransactionUrl(_i) {
|
|
3411
|
+
return __async(this, null, function* () {
|
|
3412
|
+
var _j = _i, {
|
|
3413
|
+
purchaseId,
|
|
3414
|
+
providerKey
|
|
3415
|
+
} = _j, walletParams = __objRest(_j, [
|
|
3416
|
+
"purchaseId",
|
|
3417
|
+
"providerKey"
|
|
3418
|
+
]);
|
|
3419
|
+
const res = yield this.touchSession();
|
|
3420
|
+
const [key, identifier] = extractWalletRef(walletParams);
|
|
3421
|
+
return this.constructPortalUrl("onRamp", {
|
|
3422
|
+
partnerId: res.data.partnerId,
|
|
3423
|
+
pathId: purchaseId,
|
|
3424
|
+
sessionId: res.data.sessionId,
|
|
3425
|
+
params: {
|
|
3426
|
+
[key]: identifier,
|
|
3427
|
+
providerKey,
|
|
3428
|
+
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
3429
|
+
}
|
|
3430
|
+
});
|
|
3220
3431
|
});
|
|
3221
3432
|
}
|
|
3222
3433
|
/**
|
|
@@ -3230,91 +3441,95 @@ var ParaCore = class _ParaCore {
|
|
|
3230
3441
|
* @param {number} [opts.timeout] optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
3231
3442
|
* @param {string} [opts.cosmosSignDocBase64] the Cosmos `SignDoc` in base64, if applicable
|
|
3232
3443
|
**/
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
let signRes = await this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
3246
|
-
let timeStart = Date.now();
|
|
3247
|
-
if (signRes.pendingTransactionId) {
|
|
3248
|
-
this.platformUtils.openPopup(
|
|
3249
|
-
await this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
3250
|
-
{ type: cosmosSignDocBase64 ? "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ : "SIGN_MESSAGE_REVIEW" /* SIGN_MESSAGE_REVIEW */ }
|
|
3251
|
-
);
|
|
3252
|
-
} else {
|
|
3253
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
3254
|
-
return signRes;
|
|
3255
|
-
}
|
|
3256
|
-
await new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3257
|
-
while (true) {
|
|
3258
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
3259
|
-
break;
|
|
3260
|
-
}
|
|
3261
|
-
try {
|
|
3262
|
-
await this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3263
|
-
} catch (err) {
|
|
3264
|
-
const error = new TransactionReviewDenied();
|
|
3265
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
3266
|
-
throw error;
|
|
3444
|
+
signMessage(_0) {
|
|
3445
|
+
return __async(this, arguments, function* ({
|
|
3446
|
+
walletId,
|
|
3447
|
+
messageBase64,
|
|
3448
|
+
timeoutMs = 3e4,
|
|
3449
|
+
cosmosSignDocBase64
|
|
3450
|
+
}) {
|
|
3451
|
+
this.assertIsValidWalletId(walletId);
|
|
3452
|
+
const wallet = this.wallets[walletId];
|
|
3453
|
+
let signerId = this.userId;
|
|
3454
|
+
if (wallet.partnerId && !wallet.userId) {
|
|
3455
|
+
signerId = wallet.partnerId;
|
|
3267
3456
|
}
|
|
3268
|
-
signRes =
|
|
3457
|
+
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
3458
|
+
let timeStart = Date.now();
|
|
3269
3459
|
if (signRes.pendingTransactionId) {
|
|
3270
|
-
|
|
3460
|
+
this.platformUtils.openPopup(
|
|
3461
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
3462
|
+
{ type: cosmosSignDocBase64 ? "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ : "SIGN_MESSAGE_REVIEW" /* SIGN_MESSAGE_REVIEW */ }
|
|
3463
|
+
);
|
|
3271
3464
|
} else {
|
|
3272
|
-
|
|
3465
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
3466
|
+
return signRes;
|
|
3273
3467
|
}
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
signerId,
|
|
3298
|
-
wallet.id,
|
|
3299
|
-
wallet.signer,
|
|
3300
|
-
messageBase64,
|
|
3301
|
-
this.retrieveSessionCookie()
|
|
3302
|
-
);
|
|
3303
|
-
break;
|
|
3304
|
-
default:
|
|
3305
|
-
signRes = await this.platformUtils.signMessage(
|
|
3306
|
-
this.ctx,
|
|
3307
|
-
signerId,
|
|
3308
|
-
wallet.id,
|
|
3309
|
-
wallet.signer,
|
|
3310
|
-
messageBase64,
|
|
3311
|
-
this.retrieveSessionCookie(),
|
|
3312
|
-
wallet.scheme === WalletScheme2.DKLS,
|
|
3313
|
-
cosmosSignDocBase64
|
|
3468
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3469
|
+
while (true) {
|
|
3470
|
+
if (Date.now() - timeStart > timeoutMs) {
|
|
3471
|
+
break;
|
|
3472
|
+
}
|
|
3473
|
+
try {
|
|
3474
|
+
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3475
|
+
} catch (err) {
|
|
3476
|
+
const error = new TransactionReviewDenied();
|
|
3477
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
3478
|
+
throw error;
|
|
3479
|
+
}
|
|
3480
|
+
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
3481
|
+
if (signRes.pendingTransactionId) {
|
|
3482
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3483
|
+
} else {
|
|
3484
|
+
break;
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
if (signRes.pendingTransactionId) {
|
|
3488
|
+
const error = new TransactionReviewTimeout(
|
|
3489
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3490
|
+
signRes.pendingTransactionId
|
|
3314
3491
|
);
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3492
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
3493
|
+
throw error;
|
|
3494
|
+
}
|
|
3495
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
3496
|
+
return signRes;
|
|
3497
|
+
});
|
|
3498
|
+
}
|
|
3499
|
+
signMessageInner(_0) {
|
|
3500
|
+
return __async(this, arguments, function* ({
|
|
3501
|
+
wallet,
|
|
3502
|
+
signerId,
|
|
3503
|
+
messageBase64,
|
|
3504
|
+
cosmosSignDocBase64
|
|
3505
|
+
}) {
|
|
3506
|
+
let signRes;
|
|
3507
|
+
switch (wallet.scheme) {
|
|
3508
|
+
case WalletScheme2.ED25519:
|
|
3509
|
+
signRes = yield this.platformUtils.ed25519Sign(
|
|
3510
|
+
this.ctx,
|
|
3511
|
+
signerId,
|
|
3512
|
+
wallet.id,
|
|
3513
|
+
wallet.signer,
|
|
3514
|
+
messageBase64,
|
|
3515
|
+
this.retrieveSessionCookie()
|
|
3516
|
+
);
|
|
3517
|
+
break;
|
|
3518
|
+
default:
|
|
3519
|
+
signRes = yield this.platformUtils.signMessage(
|
|
3520
|
+
this.ctx,
|
|
3521
|
+
signerId,
|
|
3522
|
+
wallet.id,
|
|
3523
|
+
wallet.signer,
|
|
3524
|
+
messageBase64,
|
|
3525
|
+
this.retrieveSessionCookie(),
|
|
3526
|
+
wallet.scheme === WalletScheme2.DKLS,
|
|
3527
|
+
cosmosSignDocBase64
|
|
3528
|
+
);
|
|
3529
|
+
break;
|
|
3530
|
+
}
|
|
3531
|
+
return signRes;
|
|
3532
|
+
});
|
|
3318
3533
|
}
|
|
3319
3534
|
/**
|
|
3320
3535
|
* Signs a transaction.
|
|
@@ -3324,51 +3539,20 @@ var ParaCore = class _ParaCore {
|
|
|
3324
3539
|
* @param {string} [opts.chainId] the EVM chain id of the chain the transaction is being sent on, if applicable
|
|
3325
3540
|
* @param {number} [opts.timeoutMs] the amount of time to wait for the user to sign the transaction, in milliseconds
|
|
3326
3541
|
**/
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
rlpEncodedTxBase64,
|
|
3330
|
-
chainId,
|
|
3331
|
-
timeoutMs = 3e4
|
|
3332
|
-
}) {
|
|
3333
|
-
this.assertIsValidWalletId(walletId);
|
|
3334
|
-
const wallet = this.wallets[walletId];
|
|
3335
|
-
let signerId = this.userId;
|
|
3336
|
-
if (wallet.partnerId && !wallet.userId) {
|
|
3337
|
-
signerId = wallet.partnerId;
|
|
3338
|
-
}
|
|
3339
|
-
let signRes = await this.platformUtils.signTransaction(
|
|
3340
|
-
this.ctx,
|
|
3341
|
-
signerId,
|
|
3542
|
+
signTransaction(_0) {
|
|
3543
|
+
return __async(this, arguments, function* ({
|
|
3342
3544
|
walletId,
|
|
3343
|
-
this.wallets[walletId].signer,
|
|
3344
3545
|
rlpEncodedTxBase64,
|
|
3345
3546
|
chainId,
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
{ type: "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ }
|
|
3354
|
-
);
|
|
3355
|
-
} else {
|
|
3356
|
-
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
3357
|
-
return signRes;
|
|
3358
|
-
}
|
|
3359
|
-
await new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3360
|
-
while (true) {
|
|
3361
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
3362
|
-
break;
|
|
3363
|
-
}
|
|
3364
|
-
try {
|
|
3365
|
-
await this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3366
|
-
} catch (err) {
|
|
3367
|
-
const error = new TransactionReviewDenied();
|
|
3368
|
-
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
3369
|
-
throw error;
|
|
3547
|
+
timeoutMs = 3e4
|
|
3548
|
+
}) {
|
|
3549
|
+
this.assertIsValidWalletId(walletId);
|
|
3550
|
+
const wallet = this.wallets[walletId];
|
|
3551
|
+
let signerId = this.userId;
|
|
3552
|
+
if (wallet.partnerId && !wallet.userId) {
|
|
3553
|
+
signerId = wallet.partnerId;
|
|
3370
3554
|
}
|
|
3371
|
-
signRes =
|
|
3555
|
+
let signRes = yield this.platformUtils.signTransaction(
|
|
3372
3556
|
this.ctx,
|
|
3373
3557
|
signerId,
|
|
3374
3558
|
walletId,
|
|
@@ -3378,22 +3562,55 @@ var ParaCore = class _ParaCore {
|
|
|
3378
3562
|
this.retrieveSessionCookie(),
|
|
3379
3563
|
wallet.scheme === WalletScheme2.DKLS
|
|
3380
3564
|
);
|
|
3565
|
+
let timeStart = Date.now();
|
|
3381
3566
|
if (signRes.pendingTransactionId) {
|
|
3382
|
-
|
|
3567
|
+
this.platformUtils.openPopup(
|
|
3568
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
3569
|
+
{ type: "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ }
|
|
3570
|
+
);
|
|
3383
3571
|
} else {
|
|
3384
|
-
|
|
3572
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
3573
|
+
return signRes;
|
|
3385
3574
|
}
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3575
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3576
|
+
while (true) {
|
|
3577
|
+
if (Date.now() - timeStart > timeoutMs) {
|
|
3578
|
+
break;
|
|
3579
|
+
}
|
|
3580
|
+
try {
|
|
3581
|
+
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3582
|
+
} catch (err) {
|
|
3583
|
+
const error = new TransactionReviewDenied();
|
|
3584
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
3585
|
+
throw error;
|
|
3586
|
+
}
|
|
3587
|
+
signRes = yield this.platformUtils.signTransaction(
|
|
3588
|
+
this.ctx,
|
|
3589
|
+
signerId,
|
|
3590
|
+
walletId,
|
|
3591
|
+
this.wallets[walletId].signer,
|
|
3592
|
+
rlpEncodedTxBase64,
|
|
3593
|
+
chainId,
|
|
3594
|
+
this.retrieveSessionCookie(),
|
|
3595
|
+
wallet.scheme === WalletScheme2.DKLS
|
|
3596
|
+
);
|
|
3597
|
+
if (signRes.pendingTransactionId) {
|
|
3598
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3599
|
+
} else {
|
|
3600
|
+
break;
|
|
3601
|
+
}
|
|
3602
|
+
}
|
|
3603
|
+
if (signRes.pendingTransactionId) {
|
|
3604
|
+
const error = new TransactionReviewTimeout(
|
|
3605
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3606
|
+
signRes.pendingTransactionId
|
|
3607
|
+
);
|
|
3608
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
3609
|
+
throw error;
|
|
3610
|
+
}
|
|
3611
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
3612
|
+
return signRes;
|
|
3613
|
+
});
|
|
3397
3614
|
}
|
|
3398
3615
|
/**
|
|
3399
3616
|
* @deprecated
|
|
@@ -3402,34 +3619,36 @@ var ParaCore = class _ParaCore {
|
|
|
3402
3619
|
* @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
|
|
3403
3620
|
* @param chainId - chain id of the chain the transaction is being sent on.
|
|
3404
3621
|
**/
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
rlpEncodedTxBase64,
|
|
3408
|
-
chainId
|
|
3409
|
-
}) {
|
|
3410
|
-
this.assertIsValidWalletId(walletId);
|
|
3411
|
-
const wallet = this.wallets[walletId];
|
|
3412
|
-
const signRes = await this.platformUtils.sendTransaction(
|
|
3413
|
-
this.ctx,
|
|
3414
|
-
this.userId,
|
|
3622
|
+
sendTransaction(_0) {
|
|
3623
|
+
return __async(this, arguments, function* ({
|
|
3415
3624
|
walletId,
|
|
3416
|
-
this.wallets[walletId].signer,
|
|
3417
3625
|
rlpEncodedTxBase64,
|
|
3418
|
-
chainId
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3626
|
+
chainId
|
|
3627
|
+
}) {
|
|
3628
|
+
this.assertIsValidWalletId(walletId);
|
|
3629
|
+
const wallet = this.wallets[walletId];
|
|
3630
|
+
const signRes = yield this.platformUtils.sendTransaction(
|
|
3631
|
+
this.ctx,
|
|
3632
|
+
this.userId,
|
|
3633
|
+
walletId,
|
|
3634
|
+
this.wallets[walletId].signer,
|
|
3635
|
+
rlpEncodedTxBase64,
|
|
3636
|
+
chainId,
|
|
3637
|
+
this.retrieveSessionCookie(),
|
|
3638
|
+
wallet.scheme === WalletScheme2.DKLS
|
|
3429
3639
|
);
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3640
|
+
if (signRes.pendingTransactionId) {
|
|
3641
|
+
this.platformUtils.openPopup(
|
|
3642
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3643
|
+
{ type: "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ }
|
|
3644
|
+
);
|
|
3645
|
+
const error = new TransactionReviewError(
|
|
3646
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId)
|
|
3647
|
+
);
|
|
3648
|
+
throw error;
|
|
3649
|
+
}
|
|
3650
|
+
return signRes;
|
|
3651
|
+
});
|
|
3433
3652
|
}
|
|
3434
3653
|
isProviderModalDisabled() {
|
|
3435
3654
|
return !!this.disableProviderModal;
|
|
@@ -3442,36 +3661,38 @@ var ParaCore = class _ParaCore {
|
|
|
3442
3661
|
* @param {string} opts.walletId the wallet ID to use for the transaction, where funds will be sent or withdrawn.
|
|
3443
3662
|
* @param {string} opts.externalWalletAddress the external wallet address to send funds to or withdraw funds from, if using an external wallet.
|
|
3444
3663
|
**/
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3664
|
+
initiateOnRampTransaction(options) {
|
|
3665
|
+
return __async(this, null, function* () {
|
|
3666
|
+
var _b;
|
|
3667
|
+
const _a = options, { params, shouldOpenPopup } = _a, walletParams = __objRest(_a, ["params", "shouldOpenPopup"]);
|
|
3668
|
+
const onRampPurchase = yield this.ctx.client.createOnRampPurchase(__spreadValues({
|
|
3669
|
+
userId: this.userId,
|
|
3670
|
+
params: __spreadProps(__spreadValues({}, params), {
|
|
3671
|
+
address: (_b = walletParams.externalWalletAddress) != null ? _b : this.getDisplayAddress(walletParams.walletId, { addressType: params.walletType })
|
|
3672
|
+
})
|
|
3673
|
+
}, walletParams));
|
|
3674
|
+
const portalUrl = yield this.getOnRampTransactionUrl(__spreadValues({
|
|
3675
|
+
purchaseId: onRampPurchase.id,
|
|
3676
|
+
providerKey: onRampPurchase.providerKey
|
|
3677
|
+
}, walletParams));
|
|
3678
|
+
if (shouldOpenPopup) {
|
|
3679
|
+
this.platformUtils.openPopup(portalUrl, { type: "ON_RAMP_TRANSACTION" /* ON_RAMP_TRANSACTION */ });
|
|
3680
|
+
}
|
|
3681
|
+
return { onRampPurchase, portalUrl };
|
|
3459
3682
|
});
|
|
3460
|
-
if (shouldOpenPopup) {
|
|
3461
|
-
this.platformUtils.openPopup(portalUrl, { type: "ON_RAMP_TRANSACTION" /* ON_RAMP_TRANSACTION */ });
|
|
3462
|
-
}
|
|
3463
|
-
return { onRampPurchase, portalUrl };
|
|
3464
3683
|
}
|
|
3465
3684
|
/**
|
|
3466
3685
|
* Returns `true` if session was successfully kept alive, `false` otherwise.
|
|
3467
3686
|
**/
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3687
|
+
keepSessionAlive() {
|
|
3688
|
+
return __async(this, null, function* () {
|
|
3689
|
+
try {
|
|
3690
|
+
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
3691
|
+
return true;
|
|
3692
|
+
} catch (err) {
|
|
3693
|
+
return false;
|
|
3694
|
+
}
|
|
3695
|
+
});
|
|
3475
3696
|
}
|
|
3476
3697
|
/**
|
|
3477
3698
|
* Serialize the current session for import by another Para instance.
|
|
@@ -3496,34 +3717,37 @@ var ParaCore = class _ParaCore {
|
|
|
3496
3717
|
* Imports a session serialized by another Para instance.
|
|
3497
3718
|
* @param {string} serializedInstanceBase64 the serialized session
|
|
3498
3719
|
*/
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3720
|
+
importSession(serializedInstanceBase64) {
|
|
3721
|
+
return __async(this, null, function* () {
|
|
3722
|
+
var _a;
|
|
3723
|
+
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
3724
|
+
const sessionInfo = JSON.parse(serializedInstance);
|
|
3725
|
+
yield this.setEmail(sessionInfo.email);
|
|
3726
|
+
yield this.setTelegramUserId(sessionInfo.telegramUserId);
|
|
3727
|
+
yield this.setFarcasterUsername(sessionInfo.farcasterUsername);
|
|
3728
|
+
yield this.setUserId(sessionInfo.userId);
|
|
3729
|
+
yield this.setWallets(sessionInfo.wallets);
|
|
3730
|
+
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
3731
|
+
for (const walletId of Object.keys(this.wallets)) {
|
|
3732
|
+
if (!this.wallets[walletId].userId) {
|
|
3733
|
+
this.wallets[walletId].userId = this.userId;
|
|
3734
|
+
}
|
|
3511
3735
|
}
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3736
|
+
if (Object.keys(sessionInfo.currentWalletIds).length !== 0) {
|
|
3737
|
+
yield this.setCurrentWalletIds(sessionInfo.currentWalletIds);
|
|
3738
|
+
} else {
|
|
3739
|
+
const currentWalletIds = {};
|
|
3740
|
+
for (const walletId of Object.keys(sessionInfo.wallets)) {
|
|
3741
|
+
currentWalletIds[sessionInfo.wallets[walletId].type] = [
|
|
3742
|
+
...(_a = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _a : [],
|
|
3743
|
+
walletId
|
|
3744
|
+
];
|
|
3745
|
+
}
|
|
3746
|
+
yield this.setCurrentWalletIds(currentWalletIds);
|
|
3522
3747
|
}
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
await this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
3748
|
+
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
3749
|
+
yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
3750
|
+
});
|
|
3527
3751
|
}
|
|
3528
3752
|
exitAccountCreation() {
|
|
3529
3753
|
this.isAwaitingAccountCreation = false;
|
|
@@ -3547,49 +3771,54 @@ var ParaCore = class _ParaCore {
|
|
|
3547
3771
|
* Retrieves a token to verify the current session.
|
|
3548
3772
|
* @returns {Promise<string>} the ID
|
|
3549
3773
|
**/
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3774
|
+
getVerificationToken() {
|
|
3775
|
+
return __async(this, null, function* () {
|
|
3776
|
+
const { data } = yield this.touchSession();
|
|
3777
|
+
return data.sessionLookupId;
|
|
3778
|
+
});
|
|
3553
3779
|
}
|
|
3554
3780
|
/**
|
|
3555
3781
|
* Logs the user out.
|
|
3556
3782
|
* @param {Object} opts the options object.
|
|
3557
3783
|
* @param {boolean} opts.clearPregenWallets if `true`, will remove all pregen wallets from storage
|
|
3558
3784
|
**/
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
supportedAuthMethods
|
|
3591
|
-
|
|
3592
|
-
|
|
3785
|
+
logout() {
|
|
3786
|
+
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3787
|
+
yield this.ctx.client.logout();
|
|
3788
|
+
yield this.clearStorage();
|
|
3789
|
+
if (!clearPregenWallets) {
|
|
3790
|
+
Object.entries(this.wallets).forEach(([id, wallet]) => {
|
|
3791
|
+
if (!wallet.pregenIdentifier) {
|
|
3792
|
+
delete this.wallets[id];
|
|
3793
|
+
}
|
|
3794
|
+
});
|
|
3795
|
+
yield this.setWallets(this.wallets);
|
|
3796
|
+
} else {
|
|
3797
|
+
this.wallets = {};
|
|
3798
|
+
}
|
|
3799
|
+
this.currentWalletIds = {};
|
|
3800
|
+
this.externalWallets = {};
|
|
3801
|
+
this.loginEncryptionKeyPair = void 0;
|
|
3802
|
+
this.email = void 0;
|
|
3803
|
+
this.telegramUserId = void 0;
|
|
3804
|
+
this.phone = void 0;
|
|
3805
|
+
this.countryCode = void 0;
|
|
3806
|
+
this.userId = void 0;
|
|
3807
|
+
this.sessionCookie = void 0;
|
|
3808
|
+
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
3809
|
+
});
|
|
3810
|
+
}
|
|
3811
|
+
getSupportedCreateAuthMethods() {
|
|
3812
|
+
return __async(this, null, function* () {
|
|
3813
|
+
const res = yield this.touchSession();
|
|
3814
|
+
const partnerId = res.data.partnerId;
|
|
3815
|
+
const partnerRes = yield this.ctx.client.getPartner(partnerId);
|
|
3816
|
+
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
3817
|
+
for (const authMethod of partnerRes.data.partner.supportedAuthMethods) {
|
|
3818
|
+
supportedAuthMethods.add(AuthMethod[authMethod]);
|
|
3819
|
+
}
|
|
3820
|
+
return supportedAuthMethods;
|
|
3821
|
+
});
|
|
3593
3822
|
}
|
|
3594
3823
|
/**
|
|
3595
3824
|
* Converts to a string, removing sensitive data when logging this class.
|
|
@@ -3598,12 +3827,10 @@ var ParaCore = class _ParaCore {
|
|
|
3598
3827
|
**/
|
|
3599
3828
|
toString() {
|
|
3600
3829
|
const redactedWallets = Object.keys(this.wallets).reduce(
|
|
3601
|
-
(acc, walletId) => ({
|
|
3602
|
-
|
|
3603
|
-
[walletId]: {
|
|
3604
|
-
...this.wallets[walletId],
|
|
3830
|
+
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
3831
|
+
[walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3605
3832
|
signer: this.wallets[walletId].signer ? "[REDACTED]" : void 0
|
|
3606
|
-
}
|
|
3833
|
+
})
|
|
3607
3834
|
}),
|
|
3608
3835
|
{}
|
|
3609
3836
|
);
|
|
@@ -3634,6 +3861,10 @@ var ParaCore = class _ParaCore {
|
|
|
3634
3861
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
3635
3862
|
}
|
|
3636
3863
|
};
|
|
3864
|
+
_supportedWalletTypes = new WeakMap();
|
|
3865
|
+
_supportedWalletTypesOpt = new WeakMap();
|
|
3866
|
+
_ParaCore.version = PARA_CORE_VERSION;
|
|
3867
|
+
var ParaCore = _ParaCore;
|
|
3637
3868
|
|
|
3638
3869
|
// src/index.ts
|
|
3639
3870
|
import {
|