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